Skip to content

Instantly share code, notes, and snippets.

@triss
Created November 5, 2014 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triss/ca4edf169c64d0853bab to your computer and use it in GitHub Desktop.
Save triss/ca4edf169c64d0853bab to your computer and use it in GitHub Desktop.
Very simple step sequencer
s.boot;
// set up the Synth
(
SynthDef(\mainSynth, {
arg attack=0.5,decay=0.5,sustain=0.5,release=0.5,gate=1,modulation_rate=1,depth=50,rate=100;
var envelope,modulator,frequencyModCarrier,amplitudeModCarrier,ringModCarrier,signal,
// -------- I've had to add a modulatorType argument to the synth - the way things were it'd be impossible to change
modulatorType ;
envelope = EnvGen.ar(Env.adsr(attack, decay, sustain, release), gate);
modulator=BufRd.ar(1,modulatorBuffer,Phasor.ar(0,BufRateScale.kr(modulatorBuffer)*modulation_rate*buffTime,0,BufFrames.kr(modulatorBuffer)),1)*depth;
ringModCarrier = BufRd.ar(1, carrierBuffer, Phasor.ar(0, BufRateScale.kr(carrierBuffer) *
rate * buffTime, 0, BufFrames.kr(carrierBuffer)),1, 4) * modulator;
amplitudeModCarrier = BufRd.ar(1, carrierBuffer, Phasor.ar(0, BufRateScale.kr(carrierBuffer) *
rate * buffTime, 0, BufFrames.kr(carrierBuffer)),1, 4) *(modulator.unipolar);
frequencyModCarrier = BufRd.ar(1, carrierBuffer, Phasor.ar(0, BufRateScale.kr(carrierBuffer)*(modulator + rate)* buffTime, 0, BufFrames.kr(carrierBuffer)),1, 4);
signal = Select.ar(modulatorType, [ringModCarrier, amplitudeModCarrier, frequencyModCarrier]);
Out.ar(0, signal * envelope);
}).add;
)
(
// somewhere to store our sequence
~sequence = Array.fill(16, 0);
// store a pointer to our synth
~synth = Synth(\mainSynth);
// step through sequence
Tdef(\sequencePlayer, {
loop {
16.do {
arg i;
// if step is on trigger synth, otherwise close synths gate
if(~sequence[i] == 1) {
~synth.set(\gate, 1);
} {
~synth.set(\gate, 0);
};
0.25.wait;
}
}
});
// create a window
~window = Window("Sequencer", Rect(0, 0, 400, 40));
// create a toggle button for each step -- we don't need these again so we don't store the array anywhere
// and just add the buttons to the window
Array.fill(16, {
arg i;
Button(~window, Rect(i * 20, 0, 20, 30))
// button has two states - one for on one for off
.states_([
["O", Color.red, Color.black],
["X", Color.black, Color.red]
])
// button has action that sets sequence value
.action_({ |button|
~sequence[i] = button.value;
})
});
// shows the window
~window.front;
// start the sequencer
Tdef(\sequencePlayer).play
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment