Discussion:
array arguments in SynthDefs
James McCartney
2004-06-14 04:30:45 UTC
Permalink
You can now specify a literal array as a SynthDef argument. The
argument must be a literal array.
For more complex things like defining an envelope you should still use
Control.names('name').kr(values)
I had to make a couple of changes in crucial to not break it. The
examples I tried work. felix might want to check the diff in
InstrSynthDef.sc.


example:

(
SynthDef("arrayarg", { arg amp = 0.1, freqs = #[300, 490, 587, 741],
gate = 1;
var env;
env = Linen.kr(gate, 0.1, 1, 1, 2) * amp;
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
}, [0, 0.1, 0]).send(s).dumpUGens;
)

(
fork {
z = Synth("arrayarg");

2.wait;
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};

z.set(\amp, -40.dbamp);

10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
2.wait;

z.release;
};
)
--
--- james mccartney james-***@public.gmane.org <http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language
Till Bovermann
2004-06-14 08:58:08 UTC
Permalink
Hey,


Thanks for this, I'll use it really much I think.
And the readability of a SynthDef is really better, than when using
Control...
Post by James McCartney
fork {
Whats that? Does it create a new thread, running the function inserted?


Till
vince
2004-06-16 12:55:20 UTC
Permalink
Hi James,
I get this error, when i try to test your example, what I'm doing wrong?
I'm using the latest snapshot of sc3 (built june 8)


ERROR:
Primitive '_BasicPut' failed.

Index not an Integer
RECEIVER:
Instance of Array { (0510E750, gc=78, fmt=01, flg=00, set=02)
indexed slots [3]
0 : instance of Array (010882C0, size=3, set=02)
1 : instance of Array (01289EC0, size=3, set=02)
2 : instance of Array (0160E4B0, size=3, set=02)
}
CALL STACK:
Object-verboseHalt
arg this = [*3]
Object-primitiveFailed
arg this = [*3]
ArrayedCollection-put
arg this = [*3]
arg index = nil
arg item = [*3]
< FunctionDef in Method SynthDef-buildControls >
arg control = [*3]
arg i = 3
ArrayedCollection-do
arg this = [*4]
arg function = <instance of Function>
var size = nil
var i = 3
SynthDef-buildControls
arg this = <instance of SynthDef>
var outputProxies = [*3]
SynthDef-buildUgenGraph
arg this = <instance of SynthDef>
arg func = <instance of Function>
arg rates = [*3]
arg prependArgs = [*0]
SynthDef-build
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
Meta_SynthDef-new
arg this = class SynthDef
arg name = "arrayarg"
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter-interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
Process-interpretPrintCmdLine
arg this = <instance of Main>
Post by James McCartney
You can now specify a literal array as a SynthDef argument. The
argument must be a literal array.
For more complex things like defining an envelope you should still use
Control.names('name').kr(values)
I had to make a couple of changes in crucial to not break it. The
examples I tried work. felix might want to check the diff in
InstrSynthDef.sc.
(
SynthDef("arrayarg", { arg amp = 0.1, freqs = #[300, 490, 587, 741],
gate = 1;
var env;
env = Linen.kr(gate, 0.1, 1, 1, 2) * amp;
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
}, [0, 0.1, 0]).send(s).dumpUGens;
)
(
fork {
z = Synth("arrayarg");
2.wait;
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
z.set(\amp, -40.dbamp);
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
2.wait;
z.release;
};
)
--
<http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
Till Bovermann
2004-06-16 14:39:59 UTC
Permalink
I think, your snapshot is outdated...
Use cvs-build (self comiled) instead...

Till
Post by vince
Hi James,
I get this error, when i try to test your example, what I'm doing wrong?
I'm using the latest snapshot of sc3 (built june 8)
Primitive '_BasicPut' failed.
Index not an Integer
Instance of Array { (0510E750, gc=78, fmt=01, flg=00, set=02)
indexed slots [3]
0 : instance of Array (010882C0, size=3, set=02)
1 : instance of Array (01289EC0, size=3, set=02)
2 : instance of Array (0160E4B0, size=3, set=02)
}
Object-verboseHalt
arg this = [*3]
Object-primitiveFailed
arg this = [*3]
ArrayedCollection-put
arg this = [*3]
arg index = nil
arg item = [*3]
< FunctionDef in Method SynthDef-buildControls >
arg control = [*3]
arg i = 3
ArrayedCollection-do
arg this = [*4]
arg function = <instance of Function>
var size = nil
var i = 3
SynthDef-buildControls
arg this = <instance of SynthDef>
var outputProxies = [*3]
SynthDef-buildUgenGraph
arg this = <instance of SynthDef>
arg func = <instance of Function>
arg rates = [*3]
arg prependArgs = [*0]
SynthDef-build
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
Meta_SynthDef-new
arg this = class SynthDef
arg name = "arrayarg"
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter-interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
Process-interpretPrintCmdLine
arg this = <instance of Main>
Post by James McCartney
You can now specify a literal array as a SynthDef argument. The
argument must be a literal array.
For more complex things like defining an envelope you should still
use Control.names('name').kr(values)
I had to make a couple of changes in crucial to not break it. The
examples I tried work. felix might want to check the diff in
InstrSynthDef.sc.
(
SynthDef("arrayarg", { arg amp = 0.1, freqs = #[300, 490, 587, 741],
gate = 1;
var env;
env = Linen.kr(gate, 0.1, 1, 1, 2) * amp;
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
}, [0, 0.1, 0]).send(s).dumpUGens;
)
(
fork {
z = Synth("arrayarg");
2.wait;
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
z.set(\amp, -40.dbamp);
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
2.wait;
z.release;
};
)
--
<http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
vince
2004-06-16 14:48:57 UTC
Permalink
I'll try to complie
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I think, your snapshot is outdated...
Use cvs-build (self comiled) instead...
Till
Post by vince
Hi James,
I get this error, when i try to test your example, what I'm doing wrong?
I'm using the latest snapshot of sc3 (built june 8)
Primitive '_BasicPut' failed.
Index not an Integer
Instance of Array { (0510E750, gc=78, fmt=01, flg=00, set=02)
indexed slots [3]
0 : instance of Array (010882C0, size=3, set=02)
1 : instance of Array (01289EC0, size=3, set=02)
2 : instance of Array (0160E4B0, size=3, set=02)
}
Object-verboseHalt
arg this = [*3]
Object-primitiveFailed
arg this = [*3]
ArrayedCollection-put
arg this = [*3]
arg index = nil
arg item = [*3]
< FunctionDef in Method SynthDef-buildControls >
arg control = [*3]
arg i = 3
ArrayedCollection-do
arg this = [*4]
arg function = <instance of Function>
var size = nil
var i = 3
SynthDef-buildControls
arg this = <instance of SynthDef>
var outputProxies = [*3]
SynthDef-buildUgenGraph
arg this = <instance of SynthDef>
arg func = <instance of Function>
arg rates = [*3]
arg prependArgs = [*0]
SynthDef-build
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
Meta_SynthDef-new
arg this = class SynthDef
arg name = "arrayarg"
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter-interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
Process-interpretPrintCmdLine
arg this = <instance of Main>
Post by James McCartney
You can now specify a literal array as a SynthDef argument. The
argument must be a literal array.
For more complex things like defining an envelope you should still
use Control.names('name').kr(values)
I had to make a couple of changes in crucial to not break it. The
examples I tried work. felix might want to check the diff in
InstrSynthDef.sc.
(
SynthDef("arrayarg", { arg amp = 0.1, freqs = #[300, 490, 587, 741],
gate = 1;
var env;
env = Linen.kr(gate, 0.1, 1, 1, 2) * amp;
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
}, [0, 0.1, 0]).send(s).dumpUGens;
)
(
fork {
z = Synth("arrayarg");
2.wait;
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
z.set(\amp, -40.dbamp);
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
2.wait;
z.release;
};
)
--
<http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (Darwin)
iD8DBQFA0FvAdULuWLxlveYRAryoAJ4jHzkNuCVaH+FocGvvGm1ET4F01QCeNzJ0
XZdf+mDnPpDkNTKvxvYxoI0=
=ukjw
-----END PGP SIGNATURE-----
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
Till Bovermann
2004-06-16 15:11:08 UTC
Permalink
You know, what u need for this?
Else look at

http://swiki.hfbk-hamburg.de:8888/MusicTechnology/554
for OS X

http://swiki.hfbk-hamburg.de:8888/MusicTechnology/478
for LinuX

regards
Till
Post by vince
I'll try to complie
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I think, your snapshot is outdated...
Use cvs-build (self comiled) instead...
Till
Post by vince
Hi James,
I get this error, when i try to test your example, what I'm doing wrong?
I'm using the latest snapshot of sc3 (built june 8)
Primitive '_BasicPut' failed.
Index not an Integer
Instance of Array { (0510E750, gc=78, fmt=01, flg=00, set=02)
indexed slots [3]
0 : instance of Array (010882C0, size=3, set=02)
1 : instance of Array (01289EC0, size=3, set=02)
2 : instance of Array (0160E4B0, size=3, set=02)
}
Object-verboseHalt
arg this = [*3]
Object-primitiveFailed
arg this = [*3]
ArrayedCollection-put
arg this = [*3]
arg index = nil
arg item = [*3]
< FunctionDef in Method SynthDef-buildControls >
arg control = [*3]
arg i = 3
ArrayedCollection-do
arg this = [*4]
arg function = <instance of Function>
var size = nil
var i = 3
SynthDef-buildControls
arg this = <instance of SynthDef>
var outputProxies = [*3]
SynthDef-buildUgenGraph
arg this = <instance of SynthDef>
arg func = <instance of Function>
arg rates = [*3]
arg prependArgs = [*0]
SynthDef-build
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
Meta_SynthDef-new
arg this = class SynthDef
arg name = "arrayarg"
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter-interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
Process-interpretPrintCmdLine
arg this = <instance of Main>
Post by James McCartney
You can now specify a literal array as a SynthDef argument. The
argument must be a literal array.
For more complex things like defining an envelope you should still
use Control.names('name').kr(values)
I had to make a couple of changes in crucial to not break it. The
examples I tried work. felix might want to check the diff in
InstrSynthDef.sc.
(
SynthDef("arrayarg", { arg amp = 0.1, freqs = #[300, 490, 587,
741], gate = 1;
var env;
env = Linen.kr(gate, 0.1, 1, 1, 2) * amp;
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
}, [0, 0.1, 0]).send(s).dumpUGens;
)
(
fork {
z = Synth("arrayarg");
2.wait;
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
z.set(\amp, -40.dbamp);
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
2.wait;
z.release;
};
)
--
<http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (Darwin)
iD8DBQFA0FvAdULuWLxlveYRAryoAJ4jHzkNuCVaH+FocGvvGm1ET4F01QCeNzJ0
XZdf+mDnPpDkNTKvxvYxoI0=
=ukjw
-----END PGP SIGNATURE-----
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
vince
2004-06-16 16:32:05 UTC
Permalink
thanx for the info, but to late,
i've just compiled it, i works fine, the james example too, for the
compiling expierience had a little help from a friend of mine, he is a
linux "pfuscher"
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You know, what u need for this?
Else look at
http://swiki.hfbk-hamburg.de:8888/MusicTechnology/554
for OS X
http://swiki.hfbk-hamburg.de:8888/MusicTechnology/478
for LinuX
regards
Till
Post by vince
I'll try to complie
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I think, your snapshot is outdated...
Use cvs-build (self comiled) instead...
Till
Post by vince
Hi James,
I get this error, when i try to test your example, what I'm doing wrong?
I'm using the latest snapshot of sc3 (built june 8)
Primitive '_BasicPut' failed.
Index not an Integer
Instance of Array { (0510E750, gc=78, fmt=01, flg=00, set=02)
indexed slots [3]
0 : instance of Array (010882C0, size=3, set=02)
1 : instance of Array (01289EC0, size=3, set=02)
2 : instance of Array (0160E4B0, size=3, set=02)
}
Object-verboseHalt
arg this = [*3]
Object-primitiveFailed
arg this = [*3]
ArrayedCollection-put
arg this = [*3]
arg index = nil
arg item = [*3]
< FunctionDef in Method SynthDef-buildControls >
arg control = [*3]
arg i = 3
ArrayedCollection-do
arg this = [*4]
arg function = <instance of Function>
var size = nil
var i = 3
SynthDef-buildControls
arg this = <instance of SynthDef>
var outputProxies = [*3]
SynthDef-buildUgenGraph
arg this = <instance of SynthDef>
arg func = <instance of Function>
arg rates = [*3]
arg prependArgs = [*0]
SynthDef-build
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
Meta_SynthDef-new
arg this = class SynthDef
arg name = "arrayarg"
arg ugenGraphFunc = <instance of Function>
arg rates = [*3]
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter-interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
Process-interpretPrintCmdLine
arg this = <instance of Main>
Post by James McCartney
You can now specify a literal array as a SynthDef argument. The
argument must be a literal array.
For more complex things like defining an envelope you should still
use Control.names('name').kr(values)
I had to make a couple of changes in crucial to not break it. The
examples I tried work. felix might want to check the diff in
InstrSynthDef.sc.
(
SynthDef("arrayarg", { arg amp = 0.1, freqs = #[300, 490, 587,
741], gate = 1;
var env;
env = Linen.kr(gate, 0.1, 1, 1, 2) * amp;
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
}, [0, 0.1, 0]).send(s).dumpUGens;
)
(
fork {
z = Synth("arrayarg");
2.wait;
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
z.set(\amp, -40.dbamp);
10.do {
z.setn(\freqs, {exprand(200,800.0)} ! 4);
(2 ** (0..3).choose * 0.2).wait;
};
2.wait;
z.release;
};
)
--
<http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (Darwin)
iD8DBQFA0FvAdULuWLxlveYRAryoAJ4jHzkNuCVaH+FocGvvGm1ET4F01QCeNzJ0
XZdf+mDnPpDkNTKvxvYxoI0=
=ukjw
-----END PGP SIGNATURE-----
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (Darwin)
iD8DBQFA0GMMdULuWLxlveYRAl8YAJwIQvSyqOatSggJ08nnqpVj2goTagCfQu7w
/7LlqX/ZeIPsQaQ03cxj9SQ=
=eSci
-----END PGP SIGNATURE-----
_______________________________________________
sc-users mailing list
http://www.create.ucsb.edu/mailman/listinfo/sc-users
Takeko Akamatsu
2004-06-19 05:00:43 UTC
Permalink
Hi.

Args of array works very fine.

But I'm wondering what dose "+ .t[0, 0.5]" mean syntactically in James's
nice example?
Post by James McCartney
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
thanks :-)
Takeko Kawamura(tn8)


On 04.6.13 9:30 PM, James McCartney wrote:
Subject: [sc-users] array arguments in SynthDefs
Post by James McCartney
(
SynthDef("arrayarg", { arg amp = 0.1, freqs = #[300, 490, 587, 741],
gate = 1;
var env;
env = Linen.kr(gate, 0.1, 1, 1, 2) * amp;
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
}, [0, 0.1, 0]).send(s).dumpUGens;
)
James McCartney
2004-06-19 07:08:02 UTC
Permalink
Post by Takeko Akamatsu
Hi.
Args of array works very fine.
But I'm wondering what dose "+ .t[0, 0.5]" mean syntactically in James's
nice example?
Post by James McCartney
Out.ar(0, SinOsc.ar(freqs +.t [0,0.5]).cubed.sum * env);
thanks :-)
Takeko Kawamura(tn8)
See the help files for "Adverbs" and "J_concepts_in_SC"

normally, adding two arrays causes the elements to be added one by one,
wrapping around if one array is shorter

[300, 490, 587, 741] + [0, 0.5]

returns this:

[ 300, 490.5, 587, 741.5 ]

the .t adverb causes a binary operator to create a table where each of
the elements are combined.

[300, 490, 587, 741] +.t [0, 0.5]

returns this:

[ [ 300, 300.5 ], [ 490, 490.5 ], [ 587, 587.5 ], [ 741, 741.5 ] ]

thus:

SinOsc.ar([300, 490, 587, 741] +.t [0,0.5])

returns this by multichannel expansion:

[ [ SinOsc(300), SinOsc(300.5) ], [ SinOsc(490), SinOsc(490.5) ], [
SinOsc(587), SinOsc(587.5) ], [ SinOsc(741), SinOsc(741.5) ] ]

This is an array of four stereo pairs where the right oscillator is
detuned by one half hertz.
When I do .sum, then all of these stereo pairs are mixed to a single
stereo pair.

adverbs work for all of the binary operators.

[7, 8, 9] *.t [1, 10, 100]

returns:

[ [ 7, 70, 700 ], [ 8, 80, 800 ], [ 9, 90, 900 ] ]


[2, 4, 6] min:.t [1, 3, 5, 7]

returns:

[ [ 1, 2, 2, 2 ], [ 1, 3, 4, 4 ], [ 1, 3, 5, 6 ] ]
Takeko Akamatsu
2004-06-19 15:33:15 UTC
Permalink
Hi, James.

Thanks!!

:-)
TakekoKawamura(tn8)

Loading...