### Stupid Pan Example Setup Source: https://docs.supercollider.online/Classes/QuartzComposerView.html Set up a window and QuartzComposerView for an audio panning example. The composition 'Stupid Pan.qtz' is loaded. ```SuperCollider w = Window("Stupid Pan Example", Rect(0, 20, 600, 150)).front; m = QuartzComposerView(w, Rect(0, 20, 600, 100)); m.path = Platform.helpDir +/+ "QC/Stupid Pan.qtz"; m.resize = 5; m.start; ``` -------------------------------- ### Initialize and Setup Source: https://docs.supercollider.online/Reference/playN.html Boots the SuperCollider server, pushes a ProxySpace, and sets up an 8-channel scope for monitoring. This is a common setup for audio examples. ```SuperCollider s.boot; p = ProxySpace.push; s.scope(8); ``` -------------------------------- ### Basic SoundFileView Setup Source: https://docs.supercollider.online/Classes/SoundFileView.html A step-by-step example of creating and configuring a SoundFileView. This includes setting the sound file, reading its content, and refreshing the view. ```SuperCollider // make a simple SoundFileView y = Window.screenBounds.height - 120; w = Window.new("soundfile test", Rect(200, y, 740, 100)).alwaysOnTop_(true); w.front; a = SoundFileView.new(w, Rect(20, 20, 700, 60)); f = SoundFile.new; f.openRead(ExampleFiles.child); // f.inspect; a.soundfile = f; // set soundfile a.read(0, f.numFrames); // read in the entire file. a.refresh; // refresh to display the file. ``` -------------------------------- ### Sonogram Example Setup Source: https://docs.supercollider.online/Classes/QuartzComposerView.html Set up a window and QuartzComposerView for a sonogram visualization. The composition 'SCQCsonogramCount2.qtz' is loaded, and input parameters are set. ```SuperCollider s.boot; w = Window("Sonogram", Rect(0, 20, 600, 300)).front; m = QuartzComposerView(w, Rect(0, 20, 600, 256)); m.path = Platform.helpDir +/+ "QC/SCQCsonogramCount2.qtz"; m.start; m.setInputValue(\"framesPerView, 300); m.setInputValue(\"magnitudes, (0, 0.01..1)); ``` -------------------------------- ### Configuring and Using Recorder Source: https://docs.supercollider.online/Classes/Recorder.html This example shows how to instantiate the Recorder class, set the directory for recordings, specify the file format (FLAC) and sample format (24-bit integer), set a file prefix, and then start and stop the recording. ```scsynth thisProcess.platform.recordingsDir = "/home/user/"; // instantiate the Recorder r = Recorder.new(s); // record into a flac file r.recHeaderFormat = "flac"; // default 'float' is incompatible with flac. set to 24bit: r.recSampleFormat = "int24"; // set very obvious prefix for files r.filePrefix = "SuperCollider_"; // start recording: r.record; // stop recording r.stopRecording; ``` -------------------------------- ### Boot and Quit Server Instance Source: https://docs.supercollider.online/Tutorials/Getting-Started/03-Start-Your-Engines.html Use 's.quit;' to stop the server and 's.boot;' to start it. Ensure the server is running before executing audio examples. ```SuperCollider s.quit; ``` ```SuperCollider s.boot; ``` -------------------------------- ### Basic Dpoll Usage Source: https://docs.supercollider.online/Classes/Dpoll.html This example shows a basic Dpoll setup. It posts a value when the condition is met. ```scsynth { Duty.kr(0.5, 0, Dpoll(Dseries(0, 1, inf) * 2)); 0.0 }.play; ``` -------------------------------- ### Interactive ScopeView Example Source: https://docs.supercollider.online/Classes/ScopeView.html This example demonstrates how to set up and use ScopeView with interactive controls. It includes creating a ScopeView, linking it to a buffer, and controlling its parameters like zoom and position via sliders and buttons. It also shows how to start and stop sound generation that feeds into the scope. ```scsynth ( s.waitForBoot({ var func, sdef1, sdef2, syn1, syn2, startButton ; f = Buffer.alloc(s, 1024, 2); b = Bus.audio(s, 1); w = Window("Scope", Rect(150, Window.screenBounds.height-500, 790, 400)).front; c = ScopeView(w, Rect(10, 10, 380, 380)); // this is SCScope c.bufnum = f.bufnum; // IMPORTANT c.server = s; v = CompositeView(w, Rect(400, 10, 380, 380)).background_(Color.rand(0.7)); v.decorator = n = FlowLayout(v.bounds, margin: 0@0, gap: 5@5); a = StaticText(v, Rect(20, 70, 90, 20)).string_(" xZoom = 1").background_(Color.rand); m = Slider(v, Rect(20, 60, 285, 20)).background_(a.background).action_({ func.value }).value_(0.5); d = StaticText(v, Rect(20, 70, 90, 20)).string_(" yZoom = 1").background_(Color.rand); g = Slider(v, Rect(20, 60, 285, 20)).background_(d.background).action_({ func.value }).value_(0.5); h = StaticText(v, Rect(20, 70, 90, 20)).string_(" x = 0").background_(Color.rand); i = Slider(v, Rect(20, 60, 285, 20)).background_(h.background).action_({ func.value }).value_(0.5); Button(v, Rect(0, 0, 380, 20)) .states_([["waveColors = [Color.rand, ...]", Color.black, Color.rand]]) .action_({ c.waveColors = [Color.rand, Color.rand] }); Button(v, Rect(0, 0, 380, 20)) .states_([[" background = Color.rand(0.1, 0.3) ", Color.black, Color.rand]]) .action_({ c.background = Color.rand(0.1, 0.3) }); t = Button(v, Rect(0, 0, 380, 20)) .states_([["Current style is 0", Color.black, Color.rand], ["Current style is 1", Color.black, Color.rand], ["Current style is 2", Color.black, Color.rand]]) .action_({ func.value }); func = { c.xZoom = ([0.25, 10, \exp, 1/8, 1].asSpec.map(m.value)); a.string = " xZoom = %".format(c.xZoom); c.yZoom = ([0.25, 10, \exp, 1/8, 1].asSpec.map(g.value)); d.string = " yZoom = %".format(c.yZoom); c.x = ([-1024, 1024, \linear, 1/8, 1].asSpec.map(i.value)); h.string = " x = %".format(c.x); c.style = t.value }; startButton = Button.new(v, Rect(0, 0, 380, 50)) .states_([["Start Sound", Color.black, Color.green], ["Stop Sound", Color.black, Color.red]]).action_({ }); startButton.action_({ (startButton.value == 1).if({ syn1 = SynthDef("test1", { |bus, bufnum| var z; z = In.ar(bus, 2); // ScopeOut2 writes the audio to the buffer // IMPORTANT - ScopeOut2, not ScopeOut ScopeOut2.ar(z, bufnum); Out.ar(0, z); }).play( RootNode(s), [\bus, b.index, \bufnum, f.bufnum], \addToTail // make sure it goes after what you are scoping ); // making noise onto the buffer syn2 = SynthDef("test2", { |bus| var z; z = PMOsc.ar([300, 250], *SinOsc.ar([0.027, 0.017])*pi) * 0.1; Out.ar(bus, z); }).play(s, [\bus, b.index]); } { syn1.free; syn2.free }; }); // IMPORTANT c.start; w.onClose = { syn1.free; syn2.free; b.free; f.free }; CmdPeriod.doOnce({ w.close }); }) ) ``` -------------------------------- ### Basic DC Offset Example Source: https://docs.supercollider.online/Classes/DC.html Demonstrates the basic usage of the DC UGen to create a constant DC offset. This can cause clicks at the start and end of playback if not managed. ```scsynth { DC.ar(0.5) + SinOsc.ar(440, 0, 0.1) }.play; ``` -------------------------------- ### Get Selection Start Example Source: https://docs.supercollider.online/Classes/Document.html Retrieves and posts the starting index of the current text selection. ```SuperCollider Document.current.selectionStart.postln; ``` -------------------------------- ### Initialize and Record Audio with RecNodeProxy Source: https://docs.supercollider.online/Classes/RecNodeProxy.html Boots the server, creates a RecNodeProxy for audio input, and opens a file for recording. Use this to set up the recording environment. ```scsynth s.boot; a = RecNodeProxy.audio(s, 2); b = a.index; // get the bus index; a.play; // monitor; a.open("xproxySpace.aif"); a.record; a.unpause; ``` -------------------------------- ### Using ExampleFiles Shortcut Source: https://docs.supercollider.online/Classes/ExampleFiles.html Demonstrates the shortcut provided by ExampleFiles to access bundled audio files, contrasting it with manual path construction. ```SuperCollider Platform.resourceDir +/+ "sounds" +/+ "a11wlk01-44_1.aiff"; ``` ```SuperCollider ExampleFiles.apollo11; ``` -------------------------------- ### ServerBoot Example Source: https://docs.supercollider.online/Classes/AbstractServerAction.html Demonstrates how to add and remove a function to be executed when the default server boots. The function receives the server object as an argument. ```scsynth s.boot; ServerBoot.add({ |server| "------------The server '%' has booted.------------\n".postf(server) }, \default); s.quit; s.boot; ServerBoot.remove({ |server| "------------The server '%' has booted.------------\n".postf(server) }, \default); s.quit; s.boot; ServerBoot.add({ |server| "------------The server '%' has booted.------------\n".postf(server) }, Server.internal); Server.internal.quit; Server.internal.boot; ServerBoot.removeAll; ``` -------------------------------- ### Starting Synths and Tasks with JITLib Source: https://docs.supercollider.online/Tutorials/JITLib/jitlib_efficiency.html These examples show how to initialize synths and tasks. Ensure the synthdef is already loaded on the server before starting. ```SuperCollider ~a = \synthDefName; ``` ```SuperCollider ~a = Pbind(\instrument, name, \freq, ...); ``` ```SuperCollider ~a = Routine({ loop({ s.sendMsg("/s_new", name, ...)}) }); ``` ```SuperCollider ~a.refresh; ~a.wakeUp; // waking up a stopped proxy does not require a resend ``` -------------------------------- ### Basic ListView Example Source: https://docs.supercollider.online/Classes/ListView.html Demonstrates the creation and basic configuration of a ListView. It sets up a window, a ListView with a list of strings, and defines an action to be performed when an item is selected. ```scsynth w = Window.new.front; v = ListView(w, Rect(10, 10, 120, 70)) .items_(["SinOsc", "Saw", "LFSaw", "WhiteNoise", "PinkNoise", "BrownNoise", "Osc"]) .background_(Color.clear) .hiliteColor_(Color.green(alpha: 0.6)) .action_({ |sbs| [sbs.value, v.items[sbs.value]].postln; // .value returns the integer }); ``` -------------------------------- ### Get Start Page Number Source: https://docs.supercollider.online/Classes/QPenPrinter.html Retrieves the starting page number selected by the user in the print dialog. Returns 0 if 'print all' is selected. ```APIDOC ## .fromPage Get the start page. #### Returns: an Integer ``` -------------------------------- ### .selectionSize Source: https://docs.supercollider.online/Classes/MultiSliderView.html Gets the number of sliders in the current selection, starting from the -index. ```APIDOC ## .selectionSize ### Description The amount of sliders in the selection (starting at -index). ``` -------------------------------- ### Cheap Level Meter Setup Source: https://docs.supercollider.online/Classes/QuartzComposerView.html Sets up two QuartzComposerView instances to act as level meters. It creates a window and two QuartzComposerView objects, assigns them a 'SCLevelMeter.qtz' composition, sets their frame rate, starts them, and stores them in a global variable '~meters'. ```supercollider w = Window("Level Meters", Rect(128, 64, 200, 400)).front; m = QuartzComposerView(w, Rect(20, 20, 50, 360)); n = QuartzComposerView(w, Rect(130, 20, 50, 360)); m.path = Platform.helpDir +/+ "QC/SCLevelMeter.qtz"; n.path = Platform.helpDir +/+ "QC/SCLevelMeter.qtz"; m.maxFPS_(20); n.maxFPS_(20); m.start; n.start; ~meters = [m, n]; ``` -------------------------------- ### VDiskIn via OSC Messaging - Basic Setup Source: https://docs.supercollider.online/Classes/VDiskIn.html Shows how to allocate a buffer, open a sound file for reading, and create a VDiskIn node using OSC messages. It's crucial to close the file after reading. ```scsynth s.sendMsg("/b_alloc", 0, 65536, 1); ``` ```scsynth s.sendMsg("/b_read", 0, ExampleFiles.apollo11, 0, 65536, 0, 1); ``` ```scsynth s.sendMsg("/s_new", "help-VDiskin", x = s.nextNodeID, 1, 1); ``` ```scsynth s.sendMsg("/b_close", 0); ``` -------------------------------- ### Paddpre Example with Sinegrain SynthDef Source: https://docs.supercollider.online/Classes/Paddpre.html This example shows how to use Paddpre to prepend a frequency pattern to a Pbind that uses a sinegrain SynthDef. The 'b.play' command then starts the musical sequence. ```supercollider SynthDef(\"sinegrain\", { |out = 0, freq = 440, sustain = 0.02| var env; env = EnvGen.kr(Env.perc(0.001, sustain), 1, doneAction: Done.freeSelf); Out.ar(out, SinOsc.ar(freq, 0, env * 0.1)) }).add; ``` ```supercollider ( a = Pbind(\"dur\", 0.5, \"instrument\", \"sinegrain\"); b = Paddpre(\"freq\", Pseq([10, 30, 100], inf), a); b.play; ) ``` -------------------------------- ### Basic Sonogram Example Source: https://docs.supercollider.online/Classes/QuartzComposerView.html Demonstrates loading and displaying a Sonogram Quartz Composer composition. It sets up a window, creates a QuartzComposerView, loads a .qtz file, and starts the view. Input values for frames per view and magnitudes are also set. ```supercollider w = Window("Sonogram", Rect(0, 20, 600, 300)).front; m = QuartzComposerView(w, Rect(0, 20, 600, 256)); m.path = Platform.helpDir +/+ "QC/SCQCsonogramCount2.qtz"; m.start; m.setInputValue( ramesPerView, 300); m.setInputValue(\magnitudes, (0, 0.01..1)); ``` -------------------------------- ### Delaying an Envelope's Start Time Source: https://docs.supercollider.online/Classes/Env.html This example demonstrates the .delay method to create a new envelope that starts after a specified delay. It plots both the original and delayed envelopes for comparison. ```supercollider a = Env.perc(0.05, 1, 1, -4); b = a.delay(2); a.test.plot; b.test.plot; ``` ```supercollider a = Env([0.5, 1, 0], [1, 1]).plot; a.delay(1).plot; ``` -------------------------------- ### Basic UnitTest Structure Source: https://docs.supercollider.online/Classes/UnitTest.html Define a test class by subclassing UnitTest. Implement setUp and tearDown methods for setup and cleanup before/after each test. Test methods must start with 'test_'. ```sc TestYourClass : UnitTest { setUp { // this will be called before each test } tearDown { // this will be called after each test } test_yourMethod { // every method whose name begins with "test_" will be run var synth; this.assert(6 == 6, "6 should equal 6"); this.assertEquals(9, 9, "9 should equal 9"); this.assertFloatEquals(4.0, 1.0 * 4.0 / 4.0 * 4.0, "floating point math should be close to equal"); // we are inside a Routine, you may wait 1.0.wait; // this will wait until the server is booted // if the server is already booted it will free all nodes // and create new allocators, giving you a clean slate this.bootServer; synth = { SinOsc.ar / 10 }.play; synth.register; // will wait until the condition is true // will be considered a failure after 10 seconds this.wait({ synth.isPlaying }, "waiting for synth to play", 10); } } ``` -------------------------------- ### Create and Populate OSCBundle Source: https://docs.supercollider.online/Classes/OSCBundle.html Demonstrates creating a new OSCBundle and adding both asynchronous preparation messages (like SynthDef receiving) and synchronous messages (like starting a synth). Use addPrepare for operations that require server confirmation before proceeding, and add for immediate, synchronous operations. ```scsynth a = OSCBundle.new; x = SynthDef("test", { OffsetOut.ar(0, BPF.ar(Impulse.ar(4) * 10, Rand(9000, 1000), 0.1)) }); a.addPrepare(["/d_recv", x.asBytes]); a.add(["/s_new", "test", -1]); ``` -------------------------------- ### Basic Ndef control operations Source: https://docs.supercollider.online/Classes/NdefGui.html Provides examples of starting, stopping, and adjusting the volume of an Ndef. ```supercollider Ndef(\a).stop; ``` ```supercollider Ndef(\a).play; ``` ```supercollider Ndef(\a).vol_(0.3); ``` ```supercollider Ndef(\a).stop; ``` -------------------------------- ### ServerTree Example Source: https://docs.supercollider.online/Classes/AbstractServerAction.html Illustrates adding actions to be evaluated when the server's internal tree is initialized. This includes booting the server and observing the order of actions, as well as clearing all registered actions. ```scsynth s.quit; f = { |server| "-------The server '%' has initialised tree.-------\n".postf(server) }; g = { |server| 10.do { Group(server).postln } }; ServerBoot.add(f, \default); ServerTree.add(g, \default); s.boot; ServerBoot.removeAll; ServerTree.removeAll; ``` -------------------------------- ### Basic Window Setup with FlowLayout Source: https://docs.supercollider.online/Classes/FlowView.html Demonstrates the fundamental setup for a window using FlowLayout, which FlowView extends. This shows the initial creation of a window and assigning a FlowLayout decorator. ```SuperCollider w = GUI.window.new; w.view.decorator = FlowLayout.new(w.bounds); w.front; ``` -------------------------------- ### Get Selection Size Example Source: https://docs.supercollider.online/Classes/Document.html Selects a range of text and then retrieves and posts the size of that selection. ```SuperCollider ( var doc; doc = Document.current; doc.selectRange(doc.selectionStart - 40, 10); doc.selectionSize.postln; ) ``` -------------------------------- ### Example: Synchronized GUI and Audio with TempoClock Source: https://docs.supercollider.online/Classes/Server.html Demonstrates using TempoClock for precise timing to synchronize GUI updates and audio playback, including booting the server if necessary. ```javascript t = TempoClock; t.tempo = 1; s.waitForBoot({ var win, routine; defer { win = Window(); win.background_(Color.grey(0, 0)).onClose_({ routine.stop }).front; }; outine = fork { 9.do { |i| 1.wait; { win.background_(Color.rand) }.defer; i = if (i % 4 == 0) { 93 } { 81 }; x = { SinOsc.ar(i.midicps) * Env.perc.ar(Done.freeSelf) * [0.1, -0.1] }.play }; defer { win.close } } }, clock: t) ) t.tempo = 30/60 ``` -------------------------------- ### Impulse.kr Example Source: https://docs.supercollider.online/Classes/Impulse.html Demonstrates the use of Impulse.kr for generating control-rate impulses. Requires no special setup. ```supercollider Impulse.kr(freq: 1.0) ``` -------------------------------- ### Impulse.ar Example Source: https://docs.supercollider.online/Classes/Impulse.html Demonstrates the use of Impulse.ar for generating audio-rate impulses. Requires no special setup. ```supercollider Impulse.ar(freq: 440.0) ``` -------------------------------- ### Condition Wait Example Setup Source: https://docs.supercollider.online/Classes/Condition.html Initializes a Condition and a forked Routine that will wait for the condition to be met. ```SuperCollider c = Condition(false); fork { 0.5.wait; "started ...".postln; c.wait; "... and finished.".postln }; ``` -------------------------------- ### .startupFiles Source: https://docs.supercollider.online/Classes/Platform.html Gets the list of files to be loaded on startup. ```APIDOC ## .startupFiles ### Description Returns a list of files that are to be loaded on startup. ### Method Instance Method ### Endpoint N/A (Instance Method) ### Parameters None ### Response - **files** (Array of strings) - An array containing the paths of startup files. ``` -------------------------------- ### Record from NodeProxy using its .record method Source: https://docs.supercollider.online/Classes/RecNodeProxy.html This example demonstrates a more concise way to start recording from a NodeProxy by directly calling its .record method, which returns a RecNodeProxy. It shows starting, unpausing, and closing the recording. ```SuperCollider b = NodeProxy.audio(s, 2); ``` ```SuperCollider b.play; // listen to b ``` ```SuperCollider b.source = { SinOsc.ar([400, 500], 0, 0.1) }; // play something ``` ```SuperCollider r = b.record("recproxy101.aiff"); // start recorder (paused) ``` ```SuperCollider r.unpause; // start recording ``` ```SuperCollider r.close; // end recording, close file ``` ```SuperCollider b.stop; // stop listen ``` -------------------------------- ### Select Range Example Source: https://docs.supercollider.online/Classes/Document.html Selects a range of text within the document based on a starting index and length. ```SuperCollider ( Document.current.selectRange(Document.current.selectLine(355), 150); ) ``` -------------------------------- ### Booting the Internal Server Source: https://docs.supercollider.online/Classes/SharedIn.html Initializes the internal server, which is required for SharedIn examples to function correctly. ```scsynth s = Server.internal; s.boot; ``` -------------------------------- ### Get Selected String Example Source: https://docs.supercollider.online/Classes/Document.html Selects a range of text and then retrieves and posts the string content of that selection. ```SuperCollider ( var doc; doc = Document.current; doc.selectRange(doc.selectionStart - 40, 10); doc.selectedString.postln; ) ``` -------------------------------- ### Boot Server and Play Buffer Example Source: https://docs.supercollider.online/Classes/PlayBuf.html Boots the server and plays a sound from a buffer. The synth frees itself when the buffer playback is complete. ```SuperCollider s.boot ``` ```SuperCollider p = ExampleFiles.child ``` ```SuperCollider p.postln ``` ```SuperCollider b = Buffer.read(s, p) ``` ```SuperCollider SynthDef("help_PlayBuf", { |out = 0, bufnum = 0| Out.ar(out, PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), doneAction: Done.freeSelf) ) }).play(s, ["out", 0, "bufnum", b]) ``` -------------------------------- ### Dump Class Subtree Source: https://docs.supercollider.online/Classes/FilterPattern.html Use this command to display the class hierarchy starting from FilterPattern. No setup is required. ```SuperCollider FilterPattern.dumpClassSubtree; ``` -------------------------------- ### Boot Server with Options Source: https://docs.supercollider.online/Classes/Server.html Boots the remote server and initializes allocators. Options include starting an alive thread for status updates and recovering allocators if the server process did not stop. ```SuperCollider s.boot(startAliveThread: true, recover: false) ``` -------------------------------- ### VDiskIn with Instance Method Source: https://docs.supercollider.online/Classes/VDiskIn.html Shows an alternative way to cue a sound file using an instance method, followed by playback. Remember to free associated resources. ```scsynth b.cueSoundFile(ExampleFiles.apollo11, 0); ``` ```scsynth x.free; b.close; b.free; ``` -------------------------------- ### BufRd.kr Example Source: https://docs.supercollider.online/Classes/BufRd.html Reads control-rate samples from a buffer. Suitable for non-audio-rate control signals or setup parameters. ```supercollider BufRd.kr(numChannels: 1, bufnum: bufnum, phase: Phasor.kr(0, BufRateScale.kr(bufnum), 0, BufFrames.kr(bufnum), loop: 1), loop: 1, interpolation: 2) ``` -------------------------------- ### Simple Usage Example Source: https://docs.supercollider.online/Classes/ServerMeterView.html Demonstrates how to create a window and embed a ServerMeterView within it. ```APIDOC ## Example: Simple Usage ```supercollider w = Window.new("Server Levels"); ServerMeterView.new(s, w, 0@0, 2, 2); w.front; // show the window ``` ``` -------------------------------- ### String Class Instance Source: https://docs.supercollider.online/Classes/String.html Demonstrates how to get the class of a string literal. This is a basic example to show string instantiation. ```SuperCollider "my string".class ``` -------------------------------- ### Create and Initialize SoundFileView Source: https://docs.supercollider.online/Classes/SoundFileView.html Demonstrates the basic steps to create a new SoundFileView, open a sound file, and display it. Ensure the 'ExampleFiles' path is valid. ```supercollider ( // make a simple SoundFileView y = Window.screenBounds.height - 120; w = Window.new("soundfile test", Rect(200, y, 740, 100)).alwaysOnTop_(true); w.front; a = SoundFileView.new(w, Rect(20, 20, 700, 60)); f = SoundFile.new; f.openRead(ExampleFiles.child); // f.inspect; a.soundfile = f; // set soundfile a.read(0, f.numFrames); a.refresh; ) ``` -------------------------------- ### Get Current Line Example Source: https://docs.supercollider.online/Classes/Document.html Selects a range of text and then retrieves and posts the string content of the current line. ```SuperCollider ( var doc; doc = Document.current; doc.selectRange(doc.selectionStart - 40, 10); doc.currentLine.postln; ) ``` -------------------------------- ### .start Source: https://docs.supercollider.online/Classes/SkipJack.html Start this skipjack. ```APIDOC ## .start ### Description Start this skipjack. ### Method POST ### Endpoint `/start` ``` -------------------------------- ### Create Project Folder with Load File Source: https://docs.supercollider.online/Guides/standalones.html Sets up an example project folder with a load file and a startup file that points to it. This is useful for larger projects to organize loading sequences and configurations. ```supercollider ~projDirName = ~newAppName ++ "_files"; ~projDir = ~newAppResDir +/+ ~projDirName; File.mkdir(~projDir); ~projDir.openOS; ~loadFileCode = "\"*** startup file for % loading.\".postln; \"*** My Platform.userAppSupportDir is: \".postln; Platform.userAppSupportDir.postcs; thisProcess.nowExecutingPath.openOS; // configure server options here if needed: s.options.memSize = 8192 * 16; // move server port away from default (57110) // to avoid interference/clashes with SuperCollider itself: s.addr.port = 57105; s.waitForBoot { \"*** server booted, plays ping.\".postln; Env.perc.test; \"*** loading files next ? \".postln; // put your loading sequence here: // \"loadX.scd\".loadRelative; // s.sync; // e.g. when loading buffers // 1.wait; // \"loadY.scd\".loadRelative; };" .format(~newAppName); ~loadfilepath = ~projDir +/+ "00_loadMe.scd"; ~writeText.value(~loadfilepath, ~loadFileCode); ~loadfilepath.openOS; // write a startupFile that points to the load file: ~startupCode = "// example startup file for osx standalone. // running loadfile in this project folder: %.loadRelative; ".format((~projDirName +/+ ~loadfilepath.basename).cs); ~writeText.(~newAppResDir +/+ "startup.scd", ~startupCode); (~newAppResDir +/+ "startup.scd").openOS; ``` -------------------------------- ### Getting a Specific SynthDesc Source: https://docs.supercollider.online/Classes/ControlName.html Fetches a specific SynthDesc from the global library by its name. This example retrieves the default SynthDesc. ```supercollider x = a.synthDescs.at("default"); // get the default SynthDesc ``` -------------------------------- ### Hang Condition Example Setup Source: https://docs.supercollider.online/Classes/Condition.html Creates a new Condition and forks a Routine that will pause execution using c.hang. ```SuperCollider c = Condition.new; fork { 0.5.wait; "started ...".postln; c.hang; "... and finished.".postln }; ``` -------------------------------- ### Cueing a SoundFile for Playback Source: https://docs.supercollider.online/Classes/SoundFile.html Demonstrates how to cue a SoundFile for playback. The first example cues a file with default parameters, while the second shows how to customize playback using event parameters like addAction and group. ```sc f = SoundFile.collect("sounds/*"); e = f[1].cue; ``` ```sc e = f[1].cue((addAction: 2, group: 1));    // synth will play ahead of the default group ``` -------------------------------- ### Boot Server and Use Scope Source: https://docs.supercollider.online/Reference/default_group.html This example boots the server, creates a synth using the scope function, and then queries all nodes to show the synth within the default group and the scope node following it. ```SuperCollider s.boot; { SinOsc.ar(mul: 0.2) }.scope(1); // watch the post window; s.queryAllNodes; // our SinOsc synth is within the default group (ID 1) // the scope node comes after the default group, so no problems s.quit; ``` -------------------------------- ### Get Selected Lines Example Source: https://docs.supercollider.online/Classes/Document.html Selects a range of text and then retrieves and posts all full lines within a specified range. ```SuperCollider ( var doc; doc = Document.current; doc.selectRange(doc.selectionStart - 40, 10); doc.getSelectedLines(doc.selectionStart - 40, 130).postln; ) ``` -------------------------------- ### Setting Button String Source: https://docs.supercollider.online/Classes/Button.html Sets or gets the text displayed on the button. This example demonstrates initializing a button with specific text. ```supercollider w = Window.new("but", Rect(300, 300, 200, 200)).front; b = Button(w, Rect(30, 40, 140, 50)); b.string = "hello button"; ``` -------------------------------- ### AbstractOpPlug Examples Section Source: https://docs.supercollider.online/Classes/AbstractOpPlug.html This section of the AbstractOpPlug documentation template is for providing code examples. ```schelp EXAMPLES:: code:: (some example code) :: ``` -------------------------------- ### Create a Complex GUI with Multiple ServerMeterViews Source: https://docs.supercollider.online/Classes/ServerMeterView.html Illustrates creating a GUI to monitor multiple servers simultaneously. This example boots two servers, calculates the required window size, and embeds ServerMeterViews for each server. ```supercollider s = Server.local; q = Server.internal; s.boot; q.boot; // wait a moment for the servers to boot ``` ```supercollider r = Rect(0, 0, ServerMeterView.getWidth(2, 2) * 2, ServerMeterView.height) w = Window.new("Local | Internal", r); ``` ```supercollider ServerMeterView.new(s, w, Point(0, 0), 2, 2); ServerMeterView.new(q, w, Point(ServerMeterView.getWidth(2, 2), 0), 2, 2); w.front; // show the window ``` -------------------------------- ### Set and Get Range of Values in Buffer Source: https://docs.supercollider.online/Tutorials/Getting-Started/13-Buffers.html Utilize Buffer.setn and Buffer.getn for setting and retrieving contiguous ranges of values. 'setn' takes a starting index and an array of values, while 'getn' takes a starting index, the number of values, and an action function. ```supercollider b = Buffer.alloc(s,16); b.setn(0, [1, 2, 3]); // set the first 3 values b.getn(0, 3, {|msg| msg.postln}); // get them ``` ```supercollider b.setn(0, Array.fill(b.numFrames, {1.0.rand})); // fill the buffer with random values b.getn(0, b.numFrames, {|msg| msg.postln}); // get them b.free; ``` -------------------------------- ### Download Example Source: https://docs.supercollider.online/Classes/Download.html An example demonstrating how to create and manage a download. ```APIDOC ## Example ```supercollider var url = "https://scottwilson.ca/files/flame.mp3"; var localPath = Platform.defaultTempDir +/+ url.split($/).last; d = Download( url, localPath, { "downloaded to %".format(localPath).postln; }, { "error".postln; }, { |receivedBytes, totalBytes| "Downloaded %\%".format((receivedBytes/totalBytes*100.0).round(1e-2)).postln; } ); d.cancel; // cancel this ``` ``` -------------------------------- ### Start a Noise Patch Source: https://docs.supercollider.online/Classes/RandSeed.html Initializes a basic noise-based audio patch with a resonant filter. This serves as a foundational example for sound generation. ```supercollider { var noise, filterfreq; noise = WhiteNoise.ar(0.05 ! 2) + Dust2.ar(70 ! 2); filterfreq = LFNoise1.kr(3, 5500, 6000); Resonz.ar(noise * 5, filterfreq, 0.5) + (noise * 0.5) }.play; ``` -------------------------------- ### Create and Use PdefGui Source: https://docs.supercollider.online/Classes/PdefGui.html Demonstrates the creation and basic usage of PdefGui to watch and control a Pdef object. Includes examples of setting properties, playing, stopping, pausing, and resuming the Pdef. ```sc3 Pdef("a", Pbind("freq", Prand((1..16) * 55, inf))); ``` ```sc3 Pdef("a").play; ``` ```sc3 t = PdefGui(Pdef("a"), 4); ``` ```sc3 Pdef("a").set("dur", 0.125, "amp", 0.05); ``` ```sc3 Pdef("a").stop; ``` ```sc3 Pdef("a").play; ``` ```sc3 Pdef("a").pause; ``` ```sc3 Pdef("a").resume; ``` ```sc3 t.object_(nil); ``` ```sc3 t.object_(Pdef("a")); ``` -------------------------------- ### StartUp.run Source: https://docs.supercollider.online/Classes/StartUp.html Manually triggers the execution of all registered startup actions in order. ```APIDOC ## StartUp.run ### Description Calls the registered objects or functions in order. ### Method Class method ``` -------------------------------- ### ContiguousBlock Initialization Example Source: https://docs.supercollider.online/Classes/ContiguousBlock.html Creates a ContiguousBlock instance representing a range of addresses. The block spans from the start address for the specified size. ```SuperCollider ContiguousBlock(10, 2) ``` -------------------------------- ### Find all occurrences of a substring Source: https://docs.supercollider.online/Classes/String.html Use .findAll to get the starting indices of all occurrences of a substring within a string. Returns nil if not found. ```SuperCollider "These are several words which are fish".findAll("are").postln; ``` ```SuperCollider "These are several words which are fish".findAll("fish").postln; ``` -------------------------------- ### Initialize ProxySpace and Audio Sources Source: https://docs.supercollider.online/Tutorials/JITLib/jitlib_efficiency.html Boot the server and set up a ProxySpace. Define initial audio rate sources (~s1, ~s2, ~s3) and an output bus (~out) that uses a mix bus (~mix). ```SuperCollider s.boot; p = ProxySpace.push(s); ``` ```SuperCollider ~out.play; ``` ```SuperCollider ~s1 = { Blip.ar(Rand(32,15), 100, 0.5) }; ``` ```SuperCollider ~s2 = { SinOsc.ar(740, 0, 0.1) }; ``` ```SuperCollider ~s3 = { Pulse.ar(140, 0.2, 0.1) }; ``` ```SuperCollider ~out = { Pan2.ar(~mix.ar(1), MouseX.kr(-1,1)) }; ``` ```SuperCollider ~mix.read(~s1); ``` ```SuperCollider ~mix.read(~s2); ``` ```SuperCollider ~mix.read(~s3); ``` -------------------------------- ### Initialize and Configure NodeProxyEditor Source: https://docs.supercollider.online/Classes/NodeProxyEditor.html Demonstrates the basic setup of NodeProxyEditor, including booting the server, pushing a ProxySpace, defining a test proxy function, and creating an editor instance. It also shows how to set the proxy and configure the number of sliders. ```supercollider s.boot; ``` ```supercollider p = ProxySpace.push(s); ``` ```supercollider (~test = { |freq = 300, dens = 20, amp = 0.1, pan| Pan2.ar(Ringz.ar(Dust.ar(dens, amp / (dens.max(1).sqrt)), freq, 0.2), pan) };) ``` ```supercollider n = NodeProxyEditor(); ``` ```supercollider n.proxy_(~test); ``` ```supercollider n = NodeProxyEditor(~test, 6); ``` -------------------------------- ### TextView - .selectionStart Source: https://docs.supercollider.online/Classes/TextView.html Gets the starting position of the current text selection. If no text is selected, this property returns the current cursor position. ```APIDOC ## .selectionStart ### Description The starting position of the selection. If no text is selected this variable represents the cursor position. ### Returns (Integer) - An Integer position within the text, in characters. ``` -------------------------------- ### Basic Recording with SynthDef Source: https://docs.supercollider.online/Classes/Recorder.html This snippet demonstrates how to define a SynthDef, create a synth instance, prepare the server for recording, and then start, pause, resume, and stop the recording process. It also includes freeing the synth after recording. ```scsynth s.prepareForRecord; // if you want to start recording on a precise moment in time, you have to call this first. s.record; // start recording. This can also be called directly, if it isn't imprtant when precisely you need to start. s.pauseRecording; // pausable s.record // start again s.stopRecording; // this closes the file and deallocates the buffer recording node, etc. x.free; // stop the synths // look in your recordings folder and you'll find a file named for this date and time ``` -------------------------------- ### Get Scale Size Source: https://docs.supercollider.online/Classes/Scale.html Retrieves the number of notes in a scale. Examples show the size for Ionian, minorPentatonic, ajam, and partch_o1 scales. ```scsynth Scale.ionian.size; // 7 ``` ```scsynth Scale.minorPentatonic.size; // 5 ``` ```scsynth Scale.ajam.size; // 7 ``` ```scsynth Scale.partch_o1.size; // 6 ``` -------------------------------- ### Configure Server Options at Startup Source: https://docs.supercollider.online/Reference/StartupFile.html Modify server options such as audio channels, device, block size, and sample rate by placing these expressions in your startup.scd file. Ensure your hardware supports the selected sample rate. ```sclang Server.local.options.numOutputBusChannels = 4; Server.local.options.numInputBusChannels = 4; Server.internal.options.numOutputBusChannels = 4; Server.internal.options.numInputBusChannels = 4; ``` ```sclang Server.local.options.device = "Built-in Audio"; Server.local.options.device = "MOTU Traveler"; Server.local.options.device = "TASCAM US-122"; Server.local.options.device = "Jack Router"; Server.local.options.device = nil; ``` ```sclang Server.local.options.blockSize = 128; Server.internal.options.blockSize = 128; ``` ```sclang Server.local.options.sampleRate = 96000; Server.internal.options.sampleRate = 96000; Server.internal.options.sampleRate = nil; ``` -------------------------------- ### Play a Synth with a settable frequency argument Source: https://docs.supercollider.online/Reference/play.html This example shows how to define a SynthDef with an argument (frequency) and then set that argument after the synth has started playing. ```SuperCollider a = { |freq = 500| HPF.ar(PinkNoise.ar([1, 1] * 0.4), freq) }.play; a.set( req, 1000) a.release; ``` -------------------------------- ### .play Source: https://docs.supercollider.online/Classes/SkipJack.html Start this skipjack. This is an alias for the `start` method. ```APIDOC ## .play ### Description Start this skipjack. Same as `start`. ### Method POST ### Endpoint `/play` ``` -------------------------------- ### Override Main Run Method Source: https://docs.supercollider.online/Classes/Main.html Extend the Main class to execute custom logic when the application starts. This example loads an RTF file. ```sclang + Main { run {"myPatch.rtf".load} } ``` -------------------------------- ### Cue and Play Immediately with DiskIn (Object Style) Source: https://docs.supercollider.online/Classes/DiskIn.html Shows how to cue a sound file and immediately play it using DiskIn. This approach uses a completion message to trigger the Synth creation once the buffer is ready. ```scsynth SynthDef("help-Diskin", { |out, bufnum = 0| Out.ar(out, DiskIn.ar(1, bufnum)); }).add; ``` ```scsynth x = Synth.basicNew("help-Diskin"); m = { |buf| x.addToHeadMsg(nil, [\bufnum, buf.bufnum]) }; b = Buffer.cueSoundFile(s, ExampleFiles.apollo11, 0, 1, completionMessage: m); ``` -------------------------------- ### Initialize and Configure ScopeView Source: https://docs.supercollider.online/Classes/ScopeView.html Boots the server and sets up a ScopeView instance within a new window. It allocates a buffer, creates an audio bus, and assigns them to the ScopeView. Ensure the ScopeView is assigned to a server. ```supercollider s.boot; ( f = Buffer.alloc(s, 1024, 2); b = Bus.audio(s, 1); w = Window.new.front; w.onClose = { // free everything when finished c.stop; a.free; d.free; f.free; b.free; "SynthDefs, busses and buffers have all been freed.".postln; }; c = ScopeView(w.view, w.view.bounds.insetAll(10, 10, 10, 10)); c.bufnum = f.bufnum; c.server = s; // Important: one must assign the ScopeView to a server ) ``` -------------------------------- ### Convolution with Longer Crossfade Source: https://docs.supercollider.online/Classes/Convolution2L.html This example uses a similar setup but with a longer crossfade time (5) in the Convolution2L UGen, demonstrating how to adjust this parameter. ```supercollider SynthDef("conv_test2", { |out, kernel, t_trig = 0| var input = Impulse.ar(1); var framesize = 2048; // must have power of two var result = Convolution2L.ar(input, kernel, t_trig, 2048, 5, 0.5); Out.ar(out, result); }).add; x = Synth("conv_test2", ["kernel", b]); // changing the buffer number: x.set("kernel", c); x.set("t_trig", 1); // after this trigger, the change will take effect. x.set("kernel", d); x.set("t_trig", 1); // after this trigger, the change will take effect. d.zero; 40.do { |it| d.set(20 * it + 10, 1) }; // changing the buffers' contents x.set("t_trig", 1); // after this trigger, the change will take effect. x.set("kernel", b); x.set("t_trig", 1); // after this trigger, the change will take effect. x.free; ``` -------------------------------- ### Allocate a Buffer for Caching Example Source: https://docs.supercollider.online/Classes/Buffer.html Allocates a buffer with specific dimensions, which will then be cached by the server. This is a setup step for demonstrating cached buffer access. ```SuperCollider b = Buffer.alloc(s, 2048, 1); ``` -------------------------------- ### Initialize and Use MonitorGui Source: https://docs.supercollider.online/Classes/MonitorGui.html Demonstrates initializing a MonitorGui, assigning it to different Ndef proxies (kr and ar), and controlling its playback and volume. Note that shift-clicking the play button opens a playN dialog. ```supercollider s.boot; Ndef("a").ar; Ndef("k").kr; // make a MonitorGui with all bells and whistles m = MonitorGui.new(bounds: 500@40, options: [\name, \level, \fade]); // when it has a kr proxy, it is visible, but disabled m.object_(Ndef("k")); // with an ar proxy, it is enabled m.object_(Ndef("a")); // show its play state Ndef("a").play; // and volume Ndef("a").vol_(0.25); // NOTE: shift-clicking the play button opens a playN dialog! Ndef("a").stop; Ndef("a").play(0); ``` -------------------------------- ### Recording Proxyspace Output Source: https://docs.supercollider.online/Tutorials/JITLib/proxyspace_examples.html Provides examples for recording the output of a proxyspace to an audio file. It covers starting, pausing, resuming, and stopping the recording process. ```SuperCollider r = p.record("out", "proxySpace.aiff"); // start recording r.unpause; // pause recording r.pause; // stop recording r.close; ``` -------------------------------- ### ServerQuit Example Source: https://docs.supercollider.online/Classes/AbstractServerAction.html Demonstrates how to add and remove a function to be executed when the default server quits. The function receives the server object as an argument. ```scsynth s.boot; f = { |server| "------------The server '%' has quit.------------\n".postf(server) }; ServerQuit.add(f, \default); s.quit; s.boot; ServerQuit.remove(f, \default); s.quit; ServerQuit.add(f, Server.internal); Server.internal.boot; Server.internal.quit; ServerQuit.removeAll; ```