Discussion:
Using MIDIdef inside SynthDef?
booth
2014-09-16 12:07:47 UTC
Permalink
Probably a silly question, but I'm new to this. . .
I would like to control some parameters in my SynthDefs with a midi
controller. I can get the desired effect by instantiating a Synth and using
the set method controlled from a separate MidiDef, for example:

MIDIClient.init;
MIDIIn.connectAll

(
SynthDef (\noise,
{|freq =100|
var sig;
sig = BPF.ar(WhiteNoise.ar(), freq);
Out.ar(0, sig)
}).add;

a = Synth(\noise);
b = MIDIdef.cc(\f, { |val, ctr| if (ctr == 0,{ a.set(\freq,
val.linexp(0,127, 50, 5000))})});
)

Of course I can include the MIDIDef in the SynthDef body, and can use postln
to see that I am receiving the proper midi signals - but my question is how
can I use the internal MIDIdef to set values in the Synth? I seem unable to
do this by assigning arg or var values directly. Thanks



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Using-MIDIdef-inside-SynthDef-tp7613419.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-16 13:16:50 UTC
Permalink
Hi,

your code works fine for me.
You can test e.g. with

// args: src, chan, num, val

MIDIIn.doControlAction(1, 1, 0, 40); // spoof a cc


Maybe what didin't work for you was putting all defs
in one parenthesis - which you shouldn't do,
as Synth should be called after (asynchronous)
synthdef generation has been completed.

Or something didn't work with your MIDI connection
(on OSX there's MIDI monitor: http://www.snoize.com/MIDIMonitor)
Post by booth
Of course I can include the MIDIDef in the SynthDef body,
That doesn't make sense, it has nothing to do with SynthDef body.
Code would be evaluated, but you are going to refer to a Synth built according
to *this* SynthDef - it could be built according to a SynthDef defined
earlier, but then again it doesn't make sense to write the lines
within SynthDef.

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/
booth
2014-09-16 22:10:04 UTC
Permalink
Thanks for the response Daniel.

I think I phrased my question badly. The code I posted above does work on my
machine. What I would like to do is something like this:

MIDIClient.init;
MIDIIn.connectAll

(
SynthDef (\noise,
{|freq =100, slider|
var sig;
MIDIdef.cc(\f, { |val, ctr| if (ctr == slider,{ freq =
val.linexp(0,127, 50, 5000))})});
sig = BPF.ar(WhiteNoise.ar(), freq);
Out.ar(0, sig)
}).add;

a = Synth(\noise,[\slider,0]);
)
. . .which doesn't do anything.

I.e., I want to encapsulate the Midi control into the same object as the
synth (maybe SynthDef isn't what I want?), so that I can pass the slider
number of the controller I want to use as an argument when I instantiate the
synth. But when the MIDIdef is in the SynthDef body, all I can get it to do
is post values to the console (i.e., the MIDIdef is working but I can't
change vars or args that are relevant for the sound chain). Is there
someway to do this? Sorry and thanks.

Jeff



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Using-MIDIdef-inside-SynthDef-tp7613419p7613431.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-16 22:51:31 UTC
Permalink
Post by booth
I.e., I want to encapsulate the Midi control into the same object as the
synth (maybe SynthDef isn't what I want?),
so that I can pass the slider
number of the controller I want to use as an argument when I instantiate the
synth.
Ah ok, I missed your main point.
Though as said MIDIdef within the SynthDef is a misconception,
you can't pass a synth arg to a language operation defined in MIDIdef,
see the server vs. language help files.
Post by booth
But when the MIDIdef is in the SynthDef body, all I can get it to do
is post values to the console (i.e., the MIDIdef is working but I can't
change vars or args that are relevant for the sound chain).
As said working totally independant from SynthDef,
it was defined while the process of building the synthdef,
but isn't connected with it.

What you want is a sequence of operations to be done in language
and a typical way to do that is defining a Function.


MIDIClient.init;
MIDIIn.connectAll

(
SynthDef (\noise,
{|freq =100|
var sig;
sig = BPF.ar(WhiteNoise.ar(), freq);
Out.ar(0, sig * EnvGate.new)
}).add;

// Function starts Synth (could also be defined to be silent) and defines MIDIdef.
// It also returns the Synth object so that you can refer to it later on.
// You can refer to the MIDIdef by its name anyway.
// Function could also be extended to pass Synth args

f = { |synthName, defName, sliderNum|
var synth = Synth(synthName), midiDef;
midiDef = MIDIdef.cc(defName, { |val, ctr|
if (ctr == sliderNum) {
synth.set(\freq, val.linexp(0,127, 50, 5000))
}
});
synth
}
)


// start synth and define MIDIdef with name and ctrNum

x = f.(\noise, \f, 0)


// spoof a cc

MIDIIn.doControlAction(1, 1, 0, 40);


// free MIDIdef

MIDIdef(\f).free


// no effect now

MIDIIn.doControlAction(1, 1, 0, 60);


// free synth

x.release



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/
booth
2014-09-17 02:35:53 UTC
Permalink
Thanks Daniel.
That clears things up. I was starting to suspect that a function might be
the way to go.
Cheers,
Jeff



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Using-MIDIdef-inside-SynthDef-tp7613419p7613434.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/

Loading...