Creating a SynthDef that only lasts a certain amount of time

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

Creating a SynthDef that only lasts a certain amount of time

by Felix Barry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'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 time

by Michael G. Cox :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You 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 time

by Michael G. Cox :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 time

by Neels Janosch Hofmeyr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 };
> });
>
> )
>


signature.asc (204 bytes) Download Attachment

Re: Creating a SynthDef that only lasts a certain amount of time

by Felix Barry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So 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 time

by thor-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Neels 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 time

by andrea valle-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Out 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:


Neels 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


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - DAMS
Università degli Studi di Torino
--------------------------------------------------
" 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 time

by Scott Wilson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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'.

- Is there a style guideline preferring the new syntax, e.g. for docs?

I need to update the style guide, but yes. The syntax is much nicer.

S.



Best

-a-



On 19 Apr 2009, at 10:33, thor wrote:


Neels 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


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - DAMS
Università degli Studi di Torino
--------------------------------------------------
" 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 time

by nescivi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 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

by andrea valle-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

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-




sincerely,
Marije

_______________________________________________
sc-users mailing list


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - DAMS
Università degli Studi di Torino
--------------------------------------------------
" This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)