Last active
August 29, 2015 14:21
-
-
Save iani/1ba655e506f69f3092c6 to your computer and use it in GitHub Desktop.
Very early almost empty draft for loop player with GUI, as a class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* File 2 in "Loopiera" | |
| 20150512, 19 | |
| Define a class to hold the data and processes (variables and methods) | |
| that are needed for each instance of a loopiera. | |
| The class must be in a file ending in .sc, and placed in the Extensions directory. | |
| Make the Extensions directory, if it does not already exist: | |
| format("mkdir %", Platform.userExtensionDir.asCompileString).unixCmd; | |
| Open the Extensions directory: | |
| format("open %", Platform.userExtensionDir.asCompileString).unixCmd; | |
| Usage: | |
| l = Loopiera(); // create an instance | |
| l.record; // record in the instance | |
| l.play; // playback already recorded buffer in that instance | |
| */ | |
| //========== 0. SETUP ============ | |
| Loopiera { | |
| classvar <sampleRate; | |
| classvar <defaultRecDuration = 4; | |
| var <name, <buffer, <window, <synth; | |
| *initClass { | |
| StartUp add: { | |
| Server.default.boot; | |
| Server.default.doWhenBooted({ | |
| sampleRate = Server.default.sampleRate; | |
| postf("Loopiera was initialized with sampleRate: %\n", sampleRate); | |
| }); | |
| } | |
| } | |
| *new { | name = "LOOPIERA" | | |
| ^super.new.init(name); | |
| } | |
| init { | argName, duration | | |
| name = argName; | |
| buffer = Buffer.alloc(Server.default, sampleRate * (duration ? defaultRecDuration), 1); | |
| } | |
| record { | loop = 0 | | |
| { | |
| RecordBuf.ar( | |
| SoundIn.ar(0), // first input channel | |
| buffer, // store recording in buffer | |
| loop: loop, // loop option. Default: Do not loop | |
| doneAction: 2 // free synth when done. | |
| ); | |
| 0.0; // Output silence | |
| }.play.onEnd (this, { this.recordEnded }); | |
| } | |
| recordEnded { postf("% ended recording\n", name)} | |
| play { | loop = 1 | | |
| { PlayBuf.ar(1, buffer.bufnum, loop: loop, doneAction: 2); } | |
| .play | |
| .onEnd(this, { this.playEnded }) | |
| } | |
| playEnded { postf("% ended playing\n", name) } | |
| } | |
| /* | |
| // Must boot first to get sample rate! | |
| Server.default.boot; | |
| // After the server has booted, we can set up: | |
| ( | |
| ~recduration = 4; | |
| ~sampleRate = Server.default.sampleRate; | |
| // allocate a Buffer | |
| ~buffer1 = Buffer.alloc( | |
| Server.default, | |
| ~sampleRate * ~recduration, // allocate size | |
| 1); // single channel | |
| ) | |
| // Check: Watch input and output levels | |
| ServerMeter(Server.default); | |
| ( | |
| ~recordAndPlayback2 = ( | |
| makeBuffer: { | test | | |
| test.postln; | |
| } | |
| ); | |
| ) | |
| ~recordAndPlayback2.makeBuffer; | |
| //////////////// | |
| ( | |
| // Record audio from the first input channel | |
| ~recordAndPlayback1 = { | |
| var buffer; | |
| buffer = Buffer.alloc(Server.default, ~sampleRate * ~recduration, 1); | |
| { | |
| RecordBuf.ar( | |
| SoundIn.ar(0), // first input channel | |
| buffer, // store recording in buffer | |
| loop: 0, // do not loop | |
| doneAction: 2 // free synth when done. | |
| ); | |
| 0.0; // Output silence | |
| }.play.onEnd(\master, { | |
| { PlayBuf.ar(1, buffer.bufnum, doneAction: 2); } | |
| .play | |
| .onEnd(\master, { buffer.free; }); | |
| }) | |
| }; | |
| ) | |
| // Test the above: | |
| ~recordAndPlayback1.value; | |
| //========== 4. Add GUI to multipe record and playback ============ | |
| ( | |
| ~window1 = Window().front; | |
| ~window1.layout = VLayout( | |
| Button().states_([["RECORD!"]]).action_(~recordAndPlayback1); | |
| ); | |
| ) | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment