Quantcast

Evaluating functions inside protoEvents?

classic Classic list List threaded Threaded
3 messages Options
ecc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Evaluating functions inside protoEvents?

ecc
Hello!  I'm having trouble and hope someone can help --

I need to evaluate a function each time an event is created by a pattern.  (I'm sending event data to an animation program via OSC).

I believe it needs to happen on the protoEvent level -- I want to send \freq, regardless of whether my pattern defines pitch as \freq or \midinote or \degree.

However I can't get any function that I place in a key of the protoEvent to evaluate, whether I use Pfunc{} or just {}:

---------

(Pdef(\bass,Pbind(
        \octave, Pseq([3,4],inf),
        \degree, 0,
        \amp, 0.8,
        \legato, 1,
        \dur, Pseq([1/4],inf),
))
);



(
~instruments = (
        midi: Event.default.parent.deepCopy.putAll(
                (
                        \type: \midi,
                        \midiout: m,
                        \send:  {|thisEvent| thisEvent.freq.postln;"this works".postln} // Pfunc doesn't work either
                )
        )
)
);
);


Pdef(\bass).play(protoEvent: ~instruments.midi);
Pdef(\bass).stop;


-----------

Why not?  And how should I go about it?

Many thanks!
Elliot
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Evaluating functions inside protoEvents?

Kuivila, Ronald
Hi Elliot,
Assign the function to the key 'finish'. You can do this in the protoevent or directly in the pbind.
This function is evaluated with the event as currentEnvironment, so ~freq.value will return
the freq the event specifies no matter at what level.

So, here is an example event to work out the closest MIDI key to the specified frequency.
(freq: 230, finish: { ~freq.value.cpsmidi.round(1).postln }).play;

RJK


> On Mar 20, 2017, at 11:10 AM, ecc <[hidden email]> wrote:
>
> Hello!  I'm having trouble and hope someone can help --
>
> I need to evaluate a function each time an event is created by a pattern.
> (I'm sending event data to an animation program via OSC).
>
> I believe it needs to happen on the protoEvent level -- I want to send
> \freq, regardless of whether my pattern defines pitch as \freq or \midinote
> or \degree.
>
> However I can't get any function that I place in a key of the protoEvent to
> evaluate, whether I use Pfunc{} or just {}:
>
> ---------
>
> (Pdef(\bass,Pbind(
> \octave, Pseq([3,4],inf),
> \degree, 0,
> \amp, 0.8,
> \legato, 1,
> \dur, Pseq([1/4],inf),
> ))
> );
>
>
>
> (
> ~instruments = (
> midi: Event.default.parent.deepCopy.putAll(
> (
> \type: \midi,
> \midiout: m,
> \send:  {|thisEvent| thisEvent.freq.postln;"this works".postln} // Pfunc
> doesn't work either
> )
> )
> )
> );
> );
>
>
> Pdef(\bass).play(protoEvent: ~instruments.midi);
> Pdef(\bass).stop;
>
>
> -----------
>
> Why not?  And how should I go about it?
>
> Many thanks!
> Elliot
>
>
>
>
> --
> View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Evaluating-functions-inside-protoEvents-tp7631226.html
> Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
ecc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Evaluating functions inside protoEvents?

ecc
Thank you!  That's exactly what I needed.

E

On Mon, Mar 20, 2017 at 2:18 PM Kuivila, Ronald [via New SuperCollider Mailing Lists Forums (Use These!!!)] <[hidden email]> wrote:
Hi Elliot,
Assign the function to the key 'finish'. You can do this in the protoevent or directly in the pbind.
This function is evaluated with the event as currentEnvironment, so ~freq.value will return
the freq the event specifies no matter at what level.

So, here is an example event to work out the closest MIDI key to the specified frequency.
(freq: 230, finish: { ~freq.value.cpsmidi.round(1).postln }).play;

RJK


> On Mar 20, 2017, at 11:10 AM, ecc <[hidden email]> wrote:
>
> Hello!  I'm having trouble and hope someone can help --
>
> I need to evaluate a function each time an event is created by a pattern.
> (I'm sending event data to an animation program via OSC).
>
> I believe it needs to happen on the protoEvent level -- I want to send
> \freq, regardless of whether my pattern defines pitch as \freq or \midinote
> or \degree.
>
> However I can't get any function that I place in a key of the protoEvent to
> evaluate, whether I use Pfunc{} or just {}:
>
> ---------
>
> (Pdef(\bass,Pbind(
> \octave, Pseq([3,4],inf),
> \degree, 0,
> \amp, 0.8,
> \legato, 1,
> \dur, Pseq([1/4],inf),
> ))
> );
>
>
>
> (
> ~instruments = (
> midi: Event.default.parent.deepCopy.putAll(
> (
> \type: \midi,
> \midiout: m,
> \send:  {|thisEvent| thisEvent.freq.postln;"this works".postln} // Pfunc
> doesn't work either
> )
> )
> )
> );
> );
>
>
> Pdef(\bass).play(protoEvent: ~instruments.midi);
> Pdef(\bass).stop;
>
>
> -----------
>
> Why not?  And how should I go about it?
>
> Many thanks!
> Elliot
>
>
>
>
> --
> View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Evaluating-functions-inside-protoEvents-tp7631226.html
> Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/



To unsubscribe from Evaluating functions inside protoEvents?, click here.
NAML
Loading...