|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
Creating a SynthDef that only lasts a certain amount of timeI'm using Supercollider for one of my assignments in college. The task is to create a synthesis based instrument and demonstrating how to use it in such a way that a beginner could use what we created with very little difficulty. I've created the instrument patch and even a GUI window but I want it to be set up in such a way that when you hit the play button, it plays for a certain amount of time and then stops (resetting the play button).
For the sake of argument lets say my SynthDef looks like this: ( SynthDef("Instrument", {Out.ar(0, SinOsc.ar(400, 0, 1)}).writeDefFile ) I then have a GUI window and when it's opened it has the following 3 buttons: 1) Starts the server 2) Loads the SynthDef 3) Plays the instrument The Third button says Play and when you press it says stop, however I want to set it up in such a way that when I press play the instrument plays for around 20 seconds then stops and the button resets back to say play once again. I understand how to do scheduling and routines but my problem is that for some reason I can't get SC to do this task via the SynthDef in any way shape or form. Any ideas? |
|
|
Re: Creating a SynthDef that only lasts a certain amount of timeYou need to use an envelope of some sort if
you want the synth free itself after a specified duration. Also, in most cases, you will want to write or store the SynthDef ahead of time rather than by GUI. Once you write the def file you don't have worry about it anymore. It's already accessible. ( SynthDef("Instrument", { arg sus = 2; //sustain argument for duration in seconds var env; env = EnvGen.kr(Env.linen(sustainTime: sus), doneAction: 2); Out.ar(0, SinOsc.ar(400, 0, 1)*env) }).store ) ( w = Window.new.front; SCButton(w, Rect(20, 20, 200, 30)) .states_([["Boot Local Server", Color.black, Color.rand]]) .action_({Server.local.boot}); SCButton(w, Rect(20, 60, 200, 30)) .states_([["Play", Color.black, Color.rand]]) .action_({Synth("Instrument",[\sus, 20])}) ) |
|
|
Re: Creating a SynthDef that only lasts a certain amount of timeor if you don't want to use an envelope you can
stop and start the synth with the same button: ( SynthDef("Instrument", { Out.ar(0, SinOsc.ar(400, 0, 1)) }).store var synth; w = Window.new.front; SCButton(w, Rect(20, 20, 200, 30)) .states_([["Boot Local Server", Color.black, Color.rand]]) .action_({Server.local.boot}); SCButton(w, Rect(20, 60, 200, 30)) .states_([ ["Play", Color.black, Color.green], ["Stop", Color.black, Color.red] ]) .action_({arg button; if (button.value == 1) { synth = Synth("Instrument") }; if(button.value == 0) { synth.free }; }); ) |
|
|
Re: Creating a SynthDef that only lasts a certain amount of timeAnd if you use the GUI wrapper instead of the direct class names, your code
is also runnable on non-OSX machines, as they use e.g. JSCButton instead of SCButton: ( SynthDef("Instrument", { Out.ar(0, SinOsc.ar(400, 0, 1)) }).store var synth; w = GUI.window.new.front; GUI.button.new(w, Rect(20, 20, 200, 30)) .states_([["Boot Local Server", Color.black, Color.rand]]) .action_({Server.local.boot}); GUI.button.new(w, Rect(20, 60, 200, 30)) .states_([ ["Play", Color.black, Color.green], ["Stop", Color.black, Color.red] ]) .action_({arg button; if (button.value == 1) { synth = Synth("Instrument") }; if(button.value == 0) { synth.free }; }); ) Michael G. Cox wrote: > or if you don't want to use an envelope you can > stop and start the synth with the same button: > > ( > > SynthDef("Instrument", { Out.ar(0, SinOsc.ar(400, 0, 1)) }).store > > var synth; > > w = Window.new.front; > > SCButton(w, Rect(20, 20, 200, 30)) > .states_([["Boot Local Server", Color.black, Color.rand]]) > .action_({Server.local.boot}); > > SCButton(w, Rect(20, 60, 200, 30)) > .states_([ > ["Play", Color.black, Color.green], > ["Stop", Color.black, Color.red] > ]) > .action_({arg button; > if (button.value == 1) > { synth = Synth("Instrument") }; > if(button.value == 0) > { synth.free }; > }); > > ) > |
|
|
Re: Creating a SynthDef that only lasts a certain amount of timeSo I've got the instrument timed now. I also set things up that the synth is already saved to the system beforehand. However there's one last thing that in my mind would put the icing on the cake.
How to I get the play button to reset itself? I've got it set up that if you press play, it'll play for 30 seconds and stops and if you want to stop it midway then you press the button again. But how would one set up the button so that it resets back to saying play again after those 30 seconds if the button isn't pressed before time runs out? (I'm not sure if I explained it right) |
|
|
Re: Creating a SynthDef that only lasts a certain amount of timeNeels the GUI. syntax is old style now. this would work : ( SynthDef("Instrument", { Out.ar(0, SinOsc.ar(400, 0, 1)) }).store var synth; w = Window.new.front; Button(w, Rect(20, 20, 200, 30)) .states_([["Boot Local Server", Color.black, Color.rand]]) .action_({Server.local.boot}); Button(w, Rect(20, 60, 200, 30)) .states_([ ["Play", Color.black, Color.green], ["Stop", Color.black, Color.red] ]) .action_({arg button; if (button.value == 1) { synth = Synth("Instrument") }; if(button.value == 0) { synth.free }; }); ) On 19 Apr 2009, at 02:34, Neels Janosch Hofmeyr wrote: > And if you use the GUI wrapper instead of the direct class names, > your code > is also runnable on non-OSX machines, as they use e.g. JSCButton > instead of > SCButton: > > ( > > SynthDef("Instrument", { Out.ar(0, SinOsc.ar(400, 0, 1)) }).store > > var synth; > > w = GUI.window.new.front; > > GUI.button.new(w, Rect(20, 20, 200, 30)) > .states_([["Boot Local Server", Color.black, Color.rand]]) > .action_({Server.local.boot}); > > GUI.button.new(w, Rect(20, 60, 200, 30)) > .states_([ > ["Play", Color.black, Color.green], > ["Stop", Color.black, Color.red] > ]) > .action_({arg button; > if (button.value == 1) > { synth = Synth("Instrument") }; > if(button.value == 0) > { synth.free }; > }); > > ) > > > > Michael G. Cox wrote: >> or if you don't want to use an envelope you can >> stop and start the synth with the same button: >> >> ( >> >> SynthDef("Instrument", { Out.ar(0, SinOsc.ar(400, 0, 1)) }).store >> >> var synth; >> >> w = Window.new.front; >> >> SCButton(w, Rect(20, 20, 200, 30)) >> .states_([["Boot Local Server", Color.black, Color.rand]]) >> .action_({Server.local.boot}); >> >> SCButton(w, Rect(20, 60, 200, 30)) >> .states_([ >> ["Play", Color.black, Color.green], >> ["Stop", Color.black, Color.red] >> ]) >> .action_({arg button; >> if (button.value == 1) >> { synth = Synth("Instrument") }; >> if(button.value == 0) >> { synth.free }; >> }); >> >> ) >> > _______________________________________________ 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: Creating a SynthDef that only lasts a certain amount of timeOut of curiosity.
- Is it old style also in the sense that it is stylistically deprecated? - Is there a style guideline preferring the new syntax, e.g. for docs? Best -a- On 19 Apr 2009, at 10:33, thor wrote:
-------------------------------------------------- Andrea Valle -------------------------------------------------- CIRMA - DAMS Università degli Studi di Torino --> andrea.valle@... -------------------------------------------------- " This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." (Jeffrey 'The Dude' Lebowski) |
|
|
Re: Creating a SynthDef that only lasts a certain amount of timeOn 19 Apr 2009, at 10:28, Andrea Valle wrote:
S.
|
|
|
Re: Creating a SynthDef that only lasts a certain amount of timeOn Sunday 19 April 2009 05:38:17 Scott Wilson wrote:
> On 19 Apr 2009, at 10:28, Andrea Valle wrote: > > Out of curiosity. > > - Is it old style also in the sense that it is stylistically > > deprecated? > > Yes, but only stylistically. It will remain 'in the background'. And right now, until 3.3 is really out, we have to keep in mind that people may still be using 3.2, where the ViewRedirects are not yet in place. sincerely, Marije _______________________________________________ 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: Creating a SynthDef that only lasts a certain amount of time
Agree. I have to to teach right now on win 3.2. So I haven't updated the Italian manual, still using GUI (a pity, in 3.2 there are some issues with Knob complicating the life of mine and of my students). Best -a-
-------------------------------------------------- Andrea Valle -------------------------------------------------- CIRMA - DAMS Università degli Studi di Torino --> andrea.valle@... -------------------------------------------------- " This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." (Jeffrey 'The Dude' Lebowski) |
| Free embeddable forum powered by Nabble | Forum Help |