Created
December 15, 2012 05:33
-
-
Save soundkitchen/4291533 to your computer and use it in GitHub Desktop.
オルゴール的な自動演奏するなにか
This file contains 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
// boot default server. | |
s.boot; | |
// define synth. | |
( | |
SynthDef(\pong, {|freq=440, amp=0.2, mod=0| | |
var src, env, out; | |
src = SinOsc.ar(freq, 0, 1, 0); | |
env = EnvGen.kr( | |
Env([0, 1, 0.3, 0.2, 0], [0.02, 0.1, 0.2, 1.2]), | |
levelScale: amp, | |
doneAction: 2 | |
); | |
out = Pan2.ar(src*env, SinOsc.ar(mod, 0, 0.7, 0)); | |
Out.ar(0, out); | |
}).send(s); | |
) | |
// define sequencer. | |
( | |
var bpm = 60 / 126; | |
var notes = [0, 2, 4, 5, 7, 9, 11] + 69; | |
var duration = [0.25, 0.5, 1, 2, 4]; | |
var activeNotes = []; | |
Routine({ | |
var note, node, isEnableNote; | |
{ | |
// choose next note. | |
isEnableNote = false; | |
while ({isEnableNote.not}, { | |
note = notes.choose; | |
if (0.2.coin, { | |
note = note + 12; | |
}); | |
isEnableNote = activeNotes.includes(note).not; | |
}); | |
activeNotes = activeNotes.addFirst(note); | |
// create new synth. | |
node = Synth.tail(nil, \pong, [ | |
\freq, note.midicps, | |
\amp, (0.05.rand2 + 0.1) * 0.5, | |
\mod, 0.7.rand2, | |
]); | |
// reduce note length. | |
if (activeNotes.size > 5, { | |
activeNotes.pop; | |
}); | |
// for debug. | |
activeNotes.postln; | |
// waiting for next note. | |
(duration.at(duration.size.rand) * bpm).wait; | |
}.loop; | |
}).play; | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment