Jump to content

Category:SuperCollider: Difference between revisions

more SuperCollider notes 2024-06-21
(Some additional notes on SuperCollider 2024-06-21)
(more SuperCollider notes 2024-06-21)
 
Line 60:
The method <b>postln</b>, adds a new-line after printing the text, if you don't want the new-line, use: <b>post</b>.
<br><br>
 
<u><b>SuperCollider from the command line (not used much)</b></u>
 
SuperCollider scripts are stored in files with an extension of <b>.scd</b>.
These are typically referred to as supercollider documents, hence <b>.scd</b>.
<br><br>
99.99% of the time, you will execute code from within the IDE (scide).<br>
<br>
It is <i>possible</i> but not typical, to run a script from the command line, for example:<br>
<b> > sclang.exe ABC_problem.scd</b><br>
This will output the expected results.
See code at: https://rosettacode.org/wiki/ABC_problem#SuperCollider<br><br>
However, before executing your code, sclang will compile its class library, and you will see all of the messages about the compilation, before you see the output from your code.
<br><br>
Also, once your code is finished, you will be stuck as sclang is still waiting for more input from a file, not the keyboard. The second problem can be solved by adding <b>exit(0);</b> to the end of your script (.scd file);
<br><br>
SuperCollider comes packaged with QT, and has classes that represent GUI objects, for example:<br>
<b> > sclang.exe Barnsley_fern.scd</b><br>
Will open a window and draw the Barnsley Fern.<br>
See code at: https://rosettacode.org/wiki/Barnsley_fern#SuperCollider<br>
You will have to use Ctrl-c to kill the sclang process, you cannot add exit(0) to you script as the exit would happen before the GUI was fully created.
<br><br>
It is theoretically possible to create a thread within your script which waits until all work is done and then for it to execute exit(0); but you are just giving yourself extra work.
<br><br>
You can also run sclang without giving it a file, then it will accept input from the keyboard.
<b> > sclang.exe </b><br>
You will get this prompt <b>sc3></b> now you can type in ONE LINE OF CODE.
For example, the following line of code has three statements, the end result is printing the sum of the two numbers:<br>
<b>sc3> var v1=123; var v2=456; postf("v1+v2=%\n", v1+v2);</b><br>
v1+v2=579<br>
-> v1+v2=579<br>
<br>
The line with the arrow: -> v1+v2=579, is sclang printing the value of the last expression executed
<br><br>
<b>Summary:</b> You can start sclang from the command line and type in some code, or you could give sclang a script to run, both will work, but it is much more productive to use scide.
Using sclang from the command line is like playing your guitar with winter gloves on, you could do it, but why make life difficult?
<br><br>
If you have composed (written code for) a long piece of music, and now you want to execute the code from the command line, yes, you can do it, but it isn't going to sound any different than it would if you execute the code from within scide.<br><br>
Also, scide offers the ability to 'live code', i.e. execute some code to make some music, and change the code as the music is playing, so the music evolves as you change the code.
<br><br>
 
<u><b>SuperCollider from the IDE</b></u><br>
Start scide, or 'open' a SuperCollider Document (*.scd), if scide is 'associated' with that file type.<br>
See: https://doc.sccode.org/Guides/SCIde.html<br>
After you start scide, it starts sclang, which compiles the SuperCollider classes.<br>
Now you can start coding.<br>
<br>
<u>How to execute code (borrowed from the page at the URL above)</u><br>
<br>
To evaluate code, use one of the following keyboard commands:<br>
<b>Ctrl+Return</b><br>
Most used, "smart" code evaluation:<br>
Normally, the current line will be evaluated (where the cursor is).<br>
If the cursor is within a region, the entire region will be evaluated. See below for explanation of regions.<br>
If some code is selected, the selection will be evaluated.<br>
<br>
<b>Shift+Return</b>
<br><br>
Evaluates either the current line, or the selection (if any). Use this to evaluate a single line within a region without the need to select it.<br>
Regions make it quick and easy to evaluate larger portions of code. A region is surrounded by parentheses; to be interpreted as a region, the parenthesis must each be the only character on a line.<br>
<syntaxhighlight lang="supercollider">
(
Pbind(
\degree, Pseries(0, 1, 8),
\dur, 0.25
).play;
)
</syntaxhighlight>
If the cursor is anywhere between the outermost parentheses, pressing Ctrl+Return will automatically evaluate the entire contents within the parentheses, starting with Pbind and ending with play;.<br>
<br><br>
To quickly evaluate a portion of code, you can also double-click on any bracket (round, squared, or curly), which will select everything between this and the other matching bracket, so you can quickly evaluate it.
<br><br>
To stop any running code, use the Ctrl+. shortcut (Ctrl+Period).<br>
This will stop all the code scheduled on the clocks, as well as all the sound processes on the audio server.
<br><br>
 
<i>... more coming soon ...</i>
10

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.