Category:SuperCollider: Difference between revisions

mNo edit summary
(more SuperCollider notes 2024-06-21)
 
(2 intermediate revisions by 2 users not shown)
Line 2:
|checking=dynamic
|exec=interpreted
|site=http://supercollider.sourceforgegithub.netio/
|LCT=no}}{{language programming paradigm|object-oriented}}
SuperCollider is an environment and programming language for real time audio synthesis and algorithmic composition. It provides an interpreted object-oriented language (often called sclang) which functions as a network client to a state of the art, realtime sound synthesis server. It is used by musicians, artists, and researchers working with sound.
 
The programming language was originally devised by James McCartney and has been further developed by an interdisciplinary open source community. Its design follows a pure object-oriented design that relies on objects including functions as first -class citizens. It is dynamically typed, and has functions of both lexical and dynamic scope. SuperCollider comes with an interactive programming library for the runtime rewriting of programs, which includes programming as a performance (live coding). There are several purely functional sublanguages embedded in the system. While mostly used for sound, its structure is general purpose.
 
 
[https://github.com/supercollider/supercollider SuperCollider at GitHub]
[http://supercollider.github.io/ SuperCollider Homepage]
 
<!-- ******************************* NEW CONTENT HERE ************************************************* -->
<br><br>
<b>Some additional notes on SuperCollider 2024-06-21</b>
 
From the SuperCollider GitHub website: https://supercollider.github.io/ :<br>
<b>Quote:</b><br>
A PLATFORM FOR AUDIO SYNTHESIS AND ALGORITHMIC COMPOSITION,<br>
&nbsp; &nbsp; &nbsp; USED BY MUSICIANS, ARTISTS AND RESEARCHERS WORKING WITH SOUND.
<br><br>
FREE AND OPEN SOURCE SOFTWARE FOR WINDOWS, MACOS AND LINUX.
<br><br>
SuperCollider features three major components:<br>
scsynth – A real-time audio server<br>
sclang – An interpreted programming language<br>
scide – An editor for sclang with an integrated help system<br>
<b>End-Quote.</b><br>
<br>
Some people try to squeeze a musical composition into 140 characters: (but just for the challenge):<br>
<i>Don't judge SuperCollider or the language by these examples, they are just for fun</i>.<br>
<syntaxhighlight lang="supercollider">
f={|t|Pbind(\note,Pseq([-1,1,6,8,9,1,-1,8,6,1,9,8]+5,319),\dur,t)};Ptpar([0,f.(1/6),12,f.(0.1672)],1).play
</syntaxhighlight>
Listen to the results here: https://supercollider.github.io/assets/audio/sc-140/06_batuhanbozkurt_celesteh.mp3<br>
You can see/hear more at: https://supercollider.github.io/sc-140.html<br>
<br>
<br>
<b>As of today (2024-06-21) the current version of SuperCollider for all supported platforms is: 3.13.0</b>
<br><br>
While SClang (SuperCollider language) and its companion components are designed for the creation of sounds and music, the language is a full featured programming language.
<br><br>
The language is OO, to the extent that everything is an object, even numbers.<br>
In this snippet: <b>123 + 456</b> the <b>123</b> is an object, <b>+</b> is a method on the class of that object, and <b>456</b> is a parameter to that method. <br>
Even though <b>+</b> is a method the syntax of the addition is what you would typically expect.
<br><br>
The print function in SClang is a method called <b>postln</b>, which first appears in the root of the class tree: <b>Object</b>.<br>
<br>
Some examples, showing two possible call formats:
<syntaxhighlight lang="supercollider">
postln("Hello World"); // prints: Hello World
"Hello World".postln; // prints: Hello World
postln(1001); // prints: 1001
1001.postln; // prints: 1001
postln(123 + 456); // prints: 579
(123 + 456).postln; // prints: 579
</syntaxhighlight>
 
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>

Latest revision as of 02:09, 22 June 2024

This page is a stub. It needs more information! You can help Rosetta Code by filling it in!
Language
SuperCollider
This programming language may be used to instruct a computer to perform a task.
Official website
Execution method: Interpreted
Type checking: Dynamic
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using SuperCollider.

SuperCollider is an environment and programming language for real time audio synthesis and algorithmic composition. It provides an interpreted object-oriented language (often called sclang) which functions as a network client to a state of the art, realtime sound synthesis server. It is used by musicians, artists, and researchers working with sound.

The programming language was originally devised by James McCartney and has been further developed by an interdisciplinary open source community. Its design follows a pure object-oriented design that relies on objects including functions as first-class citizens. It is dynamically typed, and has functions of both lexical and dynamic scope. SuperCollider comes with an interactive programming library for the runtime rewriting of programs, which includes programming as a performance (live coding). There are several purely functional sublanguages embedded in the system. While mostly used for sound, its structure is general purpose.


SuperCollider at GitHub SuperCollider Homepage



Some additional notes on SuperCollider 2024-06-21

From the SuperCollider GitHub website: https://supercollider.github.io/ :
Quote:
A PLATFORM FOR AUDIO SYNTHESIS AND ALGORITHMIC COMPOSITION,
      USED BY MUSICIANS, ARTISTS AND RESEARCHERS WORKING WITH SOUND.

FREE AND OPEN SOURCE SOFTWARE FOR WINDOWS, MACOS AND LINUX.

SuperCollider features three major components:
scsynth – A real-time audio server
sclang – An interpreted programming language
scide – An editor for sclang with an integrated help system
End-Quote.

Some people try to squeeze a musical composition into 140 characters: (but just for the challenge):
Don't judge SuperCollider or the language by these examples, they are just for fun.

f={|t|Pbind(\note,Pseq([-1,1,6,8,9,1,-1,8,6,1,9,8]+5,319),\dur,t)};Ptpar([0,f.(1/6),12,f.(0.1672)],1).play

Listen to the results here: https://supercollider.github.io/assets/audio/sc-140/06_batuhanbozkurt_celesteh.mp3
You can see/hear more at: https://supercollider.github.io/sc-140.html


As of today (2024-06-21) the current version of SuperCollider for all supported platforms is: 3.13.0

While SClang (SuperCollider language) and its companion components are designed for the creation of sounds and music, the language is a full featured programming language.

The language is OO, to the extent that everything is an object, even numbers.
In this snippet: 123 + 456 the 123 is an object, + is a method on the class of that object, and 456 is a parameter to that method.
Even though + is a method the syntax of the addition is what you would typically expect.

The print function in SClang is a method called postln, which first appears in the root of the class tree: Object.

Some examples, showing two possible call formats:

postln("Hello World"); // prints: Hello World
"Hello World".postln;  // prints: Hello World
postln(1001);          // prints: 1001
1001.postln;           // prints: 1001
postln(123 + 456);     // prints: 579
(123 + 456).postln;    // prints: 579

The method postln, adds a new-line after printing the text, if you don't want the new-line, use: post.

SuperCollider from the command line (not used much)

SuperCollider scripts are stored in files with an extension of .scd. These are typically referred to as supercollider documents, hence .scd.

99.99% of the time, you will execute code from within the IDE (scide).

It is possible but not typical, to run a script from the command line, for example:
> sclang.exe ABC_problem.scd
This will output the expected results. See code at: https://rosettacode.org/wiki/ABC_problem#SuperCollider

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.

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 exit(0); to the end of your script (.scd file);

SuperCollider comes packaged with QT, and has classes that represent GUI objects, for example:

 > sclang.exe Barnsley_fern.scd

Will open a window and draw the Barnsley Fern.
See code at: https://rosettacode.org/wiki/Barnsley_fern#SuperCollider
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.

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.

You can also run sclang without giving it a file, then it will accept input from the keyboard. > sclang.exe
You will get this prompt sc3> 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:
sc3> var v1=123; var v2=456; postf("v1+v2=%\n", v1+v2);
v1+v2=579
-> v1+v2=579

The line with the arrow: -> v1+v2=579, is sclang printing the value of the last expression executed

Summary: 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?

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.

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.

SuperCollider from the IDE
Start scide, or 'open' a SuperCollider Document (*.scd), if scide is 'associated' with that file type.
See: https://doc.sccode.org/Guides/SCIde.html
After you start scide, it starts sclang, which compiles the SuperCollider classes.
Now you can start coding.

How to execute code (borrowed from the page at the URL above)

To evaluate code, use one of the following keyboard commands:
Ctrl+Return
Most used, "smart" code evaluation:
Normally, the current line will be evaluated (where the cursor is).
If the cursor is within a region, the entire region will be evaluated. See below for explanation of regions.
If some code is selected, the selection will be evaluated.

Shift+Return

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

(
Pbind(
    \degree, Pseries(0, 1, 8),
    \dur, 0.25
).play;
)

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


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.

To stop any running code, use the Ctrl+. shortcut (Ctrl+Period).
This will stop all the code scheduled on the clocks, as well as all the sound processes on the audio server.

... more coming soon ...