Discussion:
arg and synthDefs
joesh
2014-09-18 20:54:15 UTC
Permalink
Hi

I'd like a little help to understand why you can't (or I can't) change
values in an argument when creating a SynthDef. I'm sure there's a very
simple answer that I just haven' thought of since I'm a beginner. Here's a
simple bit of code to demonstrate what I mean.

(
SynthDef("SH",
{
arg riffA =[60,62,64,67].midicps;
var = out;
out = SinOsc.ar(
Select.kr(
Stepper.kr(Impulse.kr(4), max:riffA.size-1),
riffA),
mul:0.5);
Out.ar(0,out)
}).load
)


a = Synth("SH");
a = Synth("SH", [\riffA,[63,66,68,72].midicps]);

As you can see I thought it would be possible to change the array from
outside of the SynthDef...but what have I missed, or misunderstood.


Big thanks in advance - Joe



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Daniel Mayer
2014-09-18 21:28:14 UTC
Permalink
Hi,

you need a literal array as arg (see SynthDef help) -
btw better take 'add' than 'load'.

(
SynthDef("SH",{
arg riffA = #[60,62,64,67];
var out;
out = SinOsc.ar(
Select.kr(Stepper.kr(Impulse.kr(4), max:riffA.size-1), riffA.midicps),
mul:0.5
);
Out.ar(0,out)
}).add
)


Though a more usual way than using Stepper (if doing server-side sequencing)
would be writing demand ugens.
A practical convention is using NamedControl for args.
Then you don't have to write out literal arrays with larger size:
\riffA.kr is short for a NamedControl

(
SynthDef("SH_demand",{
var riffA = \riffA.kr([60,62,64,67]), out;
out = SinOsc.ar(
Demand.kr(Impulse.kr(4), 1, Dseq(riffA, inf)).midicps,
mul: 0.5
);
Out.ar(0, out * EnvGate.new)
}).add
)

a = Synth("SH_demand");

a.set(\riffA, [63,61,65,70])

a.release


You could also use patterns, here Pmono, for this,
IMO in general a more practical approach for sequencing.


Greetings

Daniel

-----------------------------
www.daniel-mayer.at
-----------------------------


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-18 22:25:53 UTC
Permalink
Hi Daniel

Thanks, I'll look into that tomorrow (it's late here).

The first idea looks fairly straight forward, I'd forgotten the 'add'
command, but what does the '#' do?

As NamedControl I'll look into that also - I'm just a beginner. I'm
following the Cottle book so you can imagine I'm trying to get concepts
working bit by bit, next up is using busses!

I'll try the suggestions and get back to you, thanks for the help.



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613459.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 07:24:13 UTC
Permalink
Hi


I tried out Daniels suggestion which worked fine until I added this:

a.set(\riffA, [60,62,64,70,71]);

The synth goes wild, but why?

Here's the whole code I'm using (same as above):

(
SynthDef("SH",{
arg riffA = #[60,62,64,67], speed = 4;
var out;
out = SinOsc.ar(
Select.kr(Stepper.kr(Impulse.kr(speed), max:riffA.size-1),
riffA.midicps),
mul:0.5
);
Out.ar(0,out)
}).add
)


Here's the variable commands that I'm using to test the whole thing:

a = Synth("SH");
a.set(\riffA, [60,62,64,67]);
a.set(\speed, 2);
a.set(\riffA, [60,62,64,70]);
a.set(\riffA, [60,62,64,70,71]); // this line doesn't work!!!???

Thanks for the help anyone.



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613461.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
r***@public.gmane.org
2014-09-19 08:11:19 UTC
Permalink
Post by joesh
The synth goes wild, but why?
likely the speed is set to 71?

the parameter array is of fixed size (ugen graphs are static).

if you want to change the number of steps you'd need to 'pre-allocate'
the maximum allowed number of steps, and make the 'current number of
steps' a parameter as well.

& then send both the changed step values and sequence length.

rd


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 08:30:47 UTC
Permalink
Where is the speed set to 71?

Thanks for the suggestion.



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613466.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 08:34:58 UTC
Permalink
Sorry Rohan I posted my reply too quickly so here's the rest of the
questions.

How do I change the number of steps? And that leads me to understand how to

"'/pre-allocate' the maximum allowed number of steps, and make the 'current
number of steps' a parameter as well/."

Thanks for the comments and help.



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613467.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Daniel Mayer
2014-09-19 10:52:27 UTC
Permalink
As Rohan said, speed is set to 71.
The reason is that 'array args' is rather
the naming for the concept than how it's working
behind the scenes.
Not going into details, but 'setting' a synth means
sending a dedicated OSC message to the server
and the array is just split into consecutive items.
As the synth is a fixed structure, the fifth arg of the passed
array is just taken as 'speed' by the synth.

Your question how to change the size of the array within the synth
is very legitimate! It's one of the most often posted
questions here, probably it would need a dedicated tutorial file.

Rohan has given the answer, actually it's not possible, size is fixed,
you need a trick: define a max size and make a kind of zeropadding
(filling with zeros = ignoring unused positions of the array).

E.g. see this thread (first part)

http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/setting-arrays-as-Synth-args-td5796799.html


But, the much better concept than poking aroung like this (unless you have a strong specific
reason to do it server-side, e.g. sequencing with extremely short durations),
is using the more comfortable and flexible way from the beginning: Patterns !


// synth definition


(
SynthDef(\sine, { |freq = 400, amp = 0.2|
Out.ar(0, SinOsc.ar(freq, mul: amp))
}).add
)

// run pattern, a played Pmono runs one single synth, setting it with every midinote

(
x = Pmono(\sine,
\dur, 1/4,
\midinote, Pseq([60,62,64,67], inf)
).play
)

x.stop;


This syntax is crystal-clear, no ?


If you want dynamic replacement there are also several ways,
the JITlib part of SC (Pdef, Pdefn, Pbindef etc.) is one of them:

(
a = [60,62,64,67];

x = Pmono(\sine,
\dur, 1/4,
\midinote, Pdefn(\x, Pseq(a, inf))
).play
)


// replace with a Pseq with extended array

Pdefn(\x, Pseq(a ++ 71, inf))


// replace with a new Pseq

Pdefn(\x, Pseq([65, 67, 53], inf))


// replace with a random sequence without repetitions

Pdefn(\x, Pxrand([65, 67, 53], inf))


x.stop


Trying to get this flexibility with server-side sequencing
(Stepper, Demand etc) you end up with clumsy solutions.


Greetings

Daniel

-----------------------------
www.daniel-mayer.at
-----------------------------







_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 11:02:35 UTC
Permalink
Thanks Daniel that's fantastic.

I tried out the changing the 71 within the array and realised it was
controlling the speed. I'll try to follow up some of what you've said and
see what I can get going.

In reality - as already mentioned - I'm working my way through the Cottle
book and trying to do something with each section to understand how the
concept explained works. Here I was trying to combine controlling arguments
from outside a loop. But of course I hadn't realised that an array is a
fixed length...although I do now! As usual I find it best to move through
the various concepts explained in this book gradually, unfortunately
sometimes you end up trying to bend a code to do something that is probably
clumsy - not really the best way to do things. I find this is a great way to
learn as mistakes always help you understand what you didn't understand, if
you follow my meaning.

Thanks again - Joe





--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613472.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Edward Nixon
2014-09-19 11:44:49 UTC
Permalink
You seem to be changing the dimension / size of the array, riffA. You can’t do that in this context a) because you’ve defined a literal, 4 member array and b) in any event it’s an argument, the synth is defined and static on the server by the time you try the problem line.

It would really pay to come to understand the second version he provided and then the subsequent note about Pmono. The result might be more straight forward and _would_ be more flexible.

…edN
Post by joesh
Hi
a.set(\riffA, [60,62,64,70,71]);
The synth goes wild, but why?
(
SynthDef("SH",{
arg riffA = #[60,62,64,67], speed = 4;
var out;
out = SinOsc.ar(
Select.kr(Stepper.kr(Impulse.kr(speed), max:riffA.size-1),
riffA.midicps),
mul:0.5
);
Out.ar(0,out)
}).add
)
a = Synth("SH");
a.set(\riffA, [60,62,64,67]);
a.set(\speed, 2);
a.set(\riffA, [60,62,64,70]);
a.set(\riffA, [60,62,64,70,71]); // this line doesn't work!!!???
Thanks for the help anyone.
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613461.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 12:27:50 UTC
Permalink
Thanks Edward, you're right. I didn't know that an array once defined was
static - in this situation at least. It's one of those things that doesn't
seem to be explained clearly in the manual I've been reading.

I've already tried the second version and see how much simpler it is,
thanks.



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613474.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Daniel Mayer
2014-09-19 13:01:46 UTC
Permalink
Just an additional note on this: the Array (meant Array object, thus capital) itself
isn't (necessarily) static in size. This is a language-side question (see List etc).

What's static is the structure of synthdefs/synths server-side.
They have been defined with language-side Arrays, but once SynthDef has been 'added'
it's compiled and a server-side synthdef can act as a little machine producing synths on demand.
Server-side there isn't any knowledge of those kind of arrays used for synthdef definition ('Arrays'),
they only exist in the language.

Sincerly

Daniel

-----------------------------
www.daniel-mayer.at
-----------------------------




_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 13:38:28 UTC
Permalink
Thanks Daniel, I'm busy playing with this version at the present. One (extra)
question is to understand how to change other arguments from outside the
function. I see how this works:

Pdefn(\x, Pseq([60,62,64,67], inf))

But what happens if you wish to change the \dur? Since Pmono is defined as
'x' I tried the regular:

x.set(\dur, newValue);

but nothing happens! What am I missing?




--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613477.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Daniel Mayer
2014-09-19 13:50:06 UTC
Permalink
Post by joesh
Thanks Daniel, I'm busy playing with this version at the present. One (extra)
question is to understand how to change other arguments from outside the
Pdefn(\x, Pseq([60,62,64,67], inf))
But what happens if you wish to change the \dur? Since Pmono is defined as
x.set(\dur, newValue);
but nothing happens! What am I missing?
You can define dur similar with a Pdefn

(
a = [60,62,64,67];

x = Pmono(\sine,
\dur, Pdefn(\d, 1/4),
\midinote, Pdefn(\m, Pseq(a, inf))
).play
)



Pdefn(\d, Prand([1/4, 1/8], inf))

x.stop;


If you have a pattern with a lot of key/value pairs
and you want to replace several params like this
there is a dedicated object: Pbindef.


Greetings

Daniel

-----------------------------
www.daniel-mayer.at
-----------------------------



_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 15:11:37 UTC
Permalink
Using this set up, the amp(litude) doesn't seem to have any effect, no matter
what you do. Is that normal?

(
SynthDef(\sine, { |freq = 400, amp = 0.5|
Out.ar(0, SinOsc.ar(freq, mul: amp))
}).add
)

// triggered by:

(
a = [60,62,64,67];
x = Pmono(\sine,
\dur, Pdefn(\d,1/6),
\midinote, Pdefn(\x, Pseq(a, inf))
).play
)

Thanks



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613479.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Daniel Mayer
2014-09-19 18:31:06 UTC
Permalink
As setting amp isn't defined in Pmono
it's simply not done.

You'd have to write a key value pair for it, e.g.

(
a = [60,62,64,67];
x = Pmono(\sine,
\amp, Pdefn(\a, Prand([0.05, 0.2], inf)),
\dur, Pdefn(\d, 1/6),
\midinote, Pdefn(\x, Pseq(a, inf))
).play
)

... do replacements ...

x.stop


Greetings

Daniel

-----------------------------
www.daniel-mayer.at
-----------------------------


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
joesh
2014-09-19 21:08:42 UTC
Permalink
Okay, so this means that all (almost) functions have to be declared.

I looked at the Pbindef which looks very interesting, thanks.



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/arg-and-synthDefs-tp7613457p7613481.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Stefan Nussbaumer
2014-09-19 13:03:00 UTC
Permalink
Post by joesh
Thanks Edward, you're right. I didn't know that an array once defined was
static - in this situation at least. It's one of those things that doesn't
seem to be explained clearly in the manual I've been reading.
it's the # in front of the array that makes it a literal array (resp. an
array of literals):

#[1, 2, 3] // literal array

or e.g.

a = [re, ra, yu] // throws an error
a = #[re, ra, yu] // an array of literals

a.do{ |it| [it, it.class.postln] } // 'it' is a Symbol

or

a = #[1, 2, 3]
a.do{ |it| [it, it.class.postln] } // 'it' is an Integer

both, Integers and Symbols, qualify as literals

stefan


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Loading...