Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Demo: Loading a MIDI file, playing it with your own SynthDef
name
code content
// you can create your midi file using MuseScore, Finale, Sibelius, Logic, etc. // TIP: create one separate midi file per layer (melodies, chords, etc). // =========================================== // THE FOLLOWING TWO THINGS YOU ONLY DO ONCE // =========================================== // Install quark (do only once -- may take a few seconds) Quarks.install("wslib"); // Recompile class library (need to do only once) thisProcess.recompile // if the above does not work, you need to install git on your computer: // Mac: https://git-scm.com/download/mac // PC: https://git-scm.com/download/win // =========================== // LOAD MIDI FILE AND TEST IT // =========================== // adjust the path // download MIDI file, select it in your file browser (one click only), "copy" it (ctrl+C), paste (ctrl+V) path here: ~melody = SimpleMIDIFile.read( "/home/sclork/Downloads/melody.mid" ); // you can load as many midi files as you want, just create other variables for them (~melody1, ~melody2, ~chords, ~thingy, etc) // remember to boot server! s.boot; // play it (cmd-. to stop) ~melody.p.play; // ================================== // PLAY WITH A DIFFERENT INSTRUMENT // ================================== // another SynthDef: ( SynthDef("plucking", {arg amp = 0.1, freq = 440, decay = 2, dampen = 0.1, pan = 0; var env, snd; env = Env.linen(0, decay, 0).kr(doneAction: 2); snd = Pluck.ar( in: WhiteNoise.ar(amp), trig: Impulse.kr(0), maxdelaytime: 0.1, delaytime: freq.reciprocal, decaytime: decay, coef: dampen); snd = Pan2.ar(snd, pan); Out.ar(0, snd); }).add; ~bpm = TempoClock.new(120/60).permanent_(true); ) // Playing through Pbindf // Specifying synth-specific parameters: // ex. 1 ( Pbindf(~melody.p, \instrument, "plucking", \decay, 15, \dampen, 0.12, \amp, 1, ).play(~bpm); ) // ex. 2 ( Pbindf(~melody.p, \instrument, "plucking", \decay, Pwhite(0.1, 15), \ctranspose, Pwhite(0, 1) + [-12, -7], // mess it up! \dampen, Pwhite(0.1, 0.6), \amp, Pwhite(0.3, 1) ).trace.play(~bpm); ) // ex. 3 ( Pstretch(0.5, Pbindf(~melody.p, // Pstretch duratins (speed up or slow down); \instrument, "plucking", \decay, 1, \dampen, 0.1, \amp, 1, \ctranspose, [-24, -21, -17], \amp, Pseq([0.1, 0.1, 0.2, 0.3, 0.4, 0.5, 0.8, 1, 2], inf) )).trace.play(~bpm); ) // ex. 4 ( Pstretch(Pn(Pgeom(0.5, 1.1, 14)), // can also stretch by pattern! Pbindf(~melody.p, \instrument, "plucking", \decay, 1, \dampen, 0.1, \amp, 1, \ctranspose, [-24, -21, -17], \amp, Pwhite(0.5, 2) )).trace.play(~bpm); ) // ex. 5 ( Pbindf(~melody.p, \instrument, "plucking", \decay, 15, \dampen, 0.12, \amp, 1, \delta, Pseq([1/3, 1, 1/3, 1/4], inf) // CREATE NEW RHYTHM (ignoring original durs -- note we have to use \delta to override the original durations from the midi file ).play(~bpm); )
code description
Load a MIDI file and play it with your own SynthDef. Examples of how to use it with Pbindf
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change