using MIDI inside .drawFunc

View: New views
4 Messages — Rating Filter:   Alert me  

using MIDI inside .drawFunc

by djeho youn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hello,

I've been away from SC for a while, and I must miss some stuff here.
Below is a simplified code from SC visual workshop, that I'd like to control freq from my MIDI contorller.

MIDIClient.init;
MIDIIn.connect

(
var width = 500, height = 500, win, usr, syn;

win = GUI.window.new("title", Rect(600, 400, width, height),false, false);
win.front;
CmdPeriod.doOnce({win.close});

usr = GUI.userView.new(win, Rect(0,0,width, height));

syn = SynthDef(\midi,{ | freq = 400, pan = 0 |
    var snd = SinOsc.ar(freq, 0, 0.4);
    Out.ar(0, Pan2.ar(snd,pan));
}).play(s);

usr.drawFunc = {
       
        MIDIIn.control = { |src, chan, num, val |
        if(chan == 0, {syn.set(\freq, val.linlin(0, 127, 0, 1000))});
        GUI.pen.fillColor = Color.new255(val.linlin(0, 127, 0, 255), 0, 0, 255);
        GUI.pen.fillOval(Rect(0,0,200,200 ));
       
        };
        };

Routine({
    inf.do{
        win.refresh;
        (1/40).wait;
        }
        }).play(AppClock);
)

if I run this code, it gives an error says,

ERROR: Primitive '_Color_SetFill' failed.
Operation cannot be called from this Process. Try using AppClock instead of SystemClock.

I feel that it's not the way at all to use MIDI like this. But I just can't find the right way to do it.

'sorry, it is a bit lazy question, I know. But can anybody give me a hint?
I remember that I've learned how to use MIDI in workshop, but I just can't remember....

thanks

--
--------------------------------------------------------------------

Jae Ho YOUN

0033 (0)6 30 71 51 06



Re: using MIDI inside .drawFunc

by nescivi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hiho,

On Wednesday 15 April 2009 14:14:42 Djého Youn wrote:
> hello,
>
> I've been away from SC for a while, and I must miss some stuff here.
> Below is a simplified code from SC visual workshop, that I'd like to
> control freq from my MIDI contorller.

You should not put the MIDIIn function inside the draw function.
Rather define that function outside of it (so independent), and have it store
the result in a var.
Then have a routine which regularly updates the GUI (or use SkipJack for
that), and have the drawFunc read the variable for drawing it in the GUI.

sincerely,
Marije

>
> MIDIClient.init;
> MIDIIn.connect
>
> (
> var width = 500, height = 500, win, usr, syn;
>
> win = GUI.window.new("title", Rect(600, 400, width, height),false, false);
> win.front;
> CmdPeriod.doOnce({win.close});
>
> usr = GUI.userView.new(win, Rect(0,0,width, height));
>
> syn = SynthDef(\midi,{ | freq = 400, pan = 0 |
>     var snd = SinOsc.ar(freq, 0, 0.4);
>     Out.ar(0, Pan2.ar(snd,pan));
> }).play(s);
>
> usr.drawFunc = {
>
>         MIDIIn.control = { |src, chan, num, val |
>         if(chan == 0, {syn.set(\freq, val.linlin(0, 127, 0, 1000))});
>         GUI.pen.fillColor = Color.new255(val.linlin(0, 127, 0, 255), 0, 0,
> 255);
>         GUI.pen.fillOval(Rect(0,0,200,200 ));
>
>         };
>         };
>
> Routine({
>     inf.do{
>         win.refresh;
>         (1/40).wait;
>         }
>         }).play(AppClock);
> )
>
> if I run this code, it gives an error says,
>
> ERROR: Primitive '_Color_SetFill' failed.
> Operation cannot be called from this Process. Try using AppClock instead of
> SystemClock.
>
> I feel that it's not the way at all to use MIDI like this. But I just can't
> find the right way to do it.
>
> 'sorry, it is a bit lazy question, I know. But can anybody give me a hint?
> I remember that I've learned how to use MIDI in workshop, but I just can't
> remember....
>
> thanks



_______________________________________________
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/

Re: using MIDI inside .drawFunc

by djeho youn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

thank you for the reply,

I've got the concept of it, but I don't see how I can get the result from the function.
I've tried .value and .poll, but it doesn't work at all.
Do I have to use OSC?



On Wed, Apr 15, 2009 at 9:42 PM, nescivi <nescivi@...> wrote:
Hiho,

On Wednesday 15 April 2009 14:14:42 Djého Youn wrote:
> hello,
>
> I've been away from SC for a while, and I must miss some stuff here.
> Below is a simplified code from SC visual workshop, that I'd like to
> control freq from my MIDI contorller.

You should not put the MIDIIn function inside the draw function.
Rather define that function outside of it (so independent), and have it store
the result in a var.
Then have a routine which regularly updates the GUI (or use SkipJack for
that), and have the drawFunc read the variable for drawing it in the GUI.

sincerely,
Marije

>
> MIDIClient.init;
> MIDIIn.connect
>
> (
> var width = 500, height = 500, win, usr, syn;
>
> win = GUI.window.new("title", Rect(600, 400, width, height),false, false);
> win.front;
> CmdPeriod.doOnce({win.close});
>
> usr = GUI.userView.new(win, Rect(0,0,width, height));
>
> syn = SynthDef(\midi,{ | freq = 400, pan = 0 |
>     var snd = SinOsc.ar(freq, 0, 0.4);
>     Out.ar(0, Pan2.ar(snd,pan));
> }).play(s);
>
> usr.drawFunc = {
>
>         MIDIIn.control = { |src, chan, num, val |
>         if(chan == 0, {syn.set(\freq, val.linlin(0, 127, 0, 1000))});
>         GUI.pen.fillColor = Color.new255(val.linlin(0, 127, 0, 255), 0, 0,
> 255);
>         GUI.pen.fillOval(Rect(0,0,200,200 ));
>
>         };
>         };
>
> Routine({
>     inf.do{
>         win.refresh;
>         (1/40).wait;
>         }
>         }).play(AppClock);
> )
>
> if I run this code, it gives an error says,
>
> ERROR: Primitive '_Color_SetFill' failed.
> Operation cannot be called from this Process. Try using AppClock instead of
> SystemClock.
>
> I feel that it's not the way at all to use MIDI like this. But I just can't
> find the right way to do it.
>
> 'sorry, it is a bit lazy question, I know. But can anybody give me a hint?
> I remember that I've learned how to use MIDI in workshop, but I just can't
> remember....
>
> thanks



_______________________________________________
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/



--
--------------------------------------------------------------------

Jae Ho YOUN

0033 (0)6 30 71 51 06



Re: using MIDI inside .drawFunc

by Fredrik Olofsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi Djého,
try this (just as marije suggested).


MIDIClient.init;
MIDIIn.connect

(
var vCtrl= 0, vLast= -1; //variable for midi controller
var width = 500, height = 500, win, usr, syn;

win = GUI.window.new("title", Rect(600, 400, width, height),false,  
false);
win.front;
CmdPeriod.doOnce({win.close});

usr = GUI.userView.new(win, Rect(0,0,width, height));

syn = SynthDef(\midi,{ | freq = 400, pan = 0 |
     var snd = SinOsc.ar(freq, 0, 0.4);
     Out.ar(0, Pan2.ar(snd,pan));
}).play(s);

MIDIIn.control = { |src, chan, num, val |
        [src, chan, num, val].postln;
        if(chan == 0, {
                vCtrl= val;
        });
};

usr.drawFunc = {
        if(vCtrl!=vLast, {
                syn.set(\freq, vCtrl.linlin(0, 127, 0, 1000));
                vLast= vCtrl;
        });
        GUI.pen.fillColor = Color.new255(vCtrl.linlin(0, 127, 0, 255), 0, 0,  
255);
        GUI.pen.fillOval(Rect(0,0,200,200 ));
};

Routine({
     inf.do{
         win.refresh;
         (1/40).wait;
         }
         }).play(AppClock);
)



15 apr 2009 kl. 22.13 skrev Djého Youn:

> thank you for the reply,
>
> I've got the concept of it, but I don't see how I can get the result  
> from the function.
> I've tried .value and .poll, but it doesn't work at all.
> Do I have to use OSC?
>
>
>
> On Wed, Apr 15, 2009 at 9:42 PM, nescivi <nescivi@...> wrote:
> Hiho,
>
> On Wednesday 15 April 2009 14:14:42 Djého Youn wrote:
> > hello,
> >
> > I've been away from SC for a while, and I must miss some stuff here.
> > Below is a simplified code from SC visual workshop, that I'd like to
> > control freq from my MIDI contorller.
>
> You should not put the MIDIIn function inside the draw function.
> Rather define that function outside of it (so independent), and have  
> it store
> the result in a var.
> Then have a routine which regularly updates the GUI (or use SkipJack  
> for
> that), and have the drawFunc read the variable for drawing it in the  
> GUI.
>
> sincerely,
> Marije
>
> >
> > MIDIClient.init;
> > MIDIIn.connect
> >
> > (
> > var width = 500, height = 500, win, usr, syn;
> >
> > win = GUI.window.new("title", Rect(600, 400, width, height),false,  
> false);
> > win.front;
> > CmdPeriod.doOnce({win.close});
> >
> > usr = GUI.userView.new(win, Rect(0,0,width, height));
> >
> > syn = SynthDef(\midi,{ | freq = 400, pan = 0 |
> >     var snd = SinOsc.ar(freq, 0, 0.4);
> >     Out.ar(0, Pan2.ar(snd,pan));
> > }).play(s);
> >
> > usr.drawFunc = {
> >
> >         MIDIIn.control = { |src, chan, num, val |
> >         if(chan == 0, {syn.set(\freq, val.linlin(0, 127, 0,  
> 1000))});
> >         GUI.pen.fillColor = Color.new255(val.linlin(0, 127, 0,  
> 255), 0, 0,
> > 255);
> >         GUI.pen.fillOval(Rect(0,0,200,200 ));
> >
> >         };
> >         };
> >
> > Routine({
> >     inf.do{
> >         win.refresh;
> >         (1/40).wait;
> >         }
> >         }).play(AppClock);
> > )
> >
> > if I run this code, it gives an error says,
> >
> > ERROR: Primitive '_Color_SetFill' failed.
> > Operation cannot be called from this Process. Try using AppClock  
> instead of
> > SystemClock.
> >
> > I feel that it's not the way at all to use MIDI like this. But I  
> just can't
> > find the right way to do it.
> >
> > 'sorry, it is a bit lazy question, I know. But can anybody give me  
> a hint?
> > I remember that I've learned how to use MIDI in workshop, but I  
> just can't
> > remember....
> >
> > thanks
>
>
>
> _______________________________________________
> 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/
>
>
>
> --
> --------------------------------------------------------------------
>
> Jae Ho YOUN
>
> 0033 (0)6 30 71 51 06
>
>


   #|
      fredrikolofsson.com     klippav.org     musicalfieldsforever.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/