Last active
August 29, 2015 14:08
-
-
Save triss/68a9a907825981d29ad8 to your computer and use it in GitHub Desktop.
Louis
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
// run this code first to set up synthDef | |
( | |
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; | |
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; | |
) | |
// run this code second to start the synth, sequencer etc | |
( | |
var file,leftsynth,rightsynth,stepGUI,recursive,freq=441,sr=44100,buffSize=1024,buffTime,left=500,top=500,width,height,backgroundColour,dialColour,stepCount,stepOn,stepOff,stepper,but_step_on,buttonOn,multiVal,boxColour,sliderGUI,stepStatus,adsrBox,tdefStepC,check, | |
stepperC,stepperCSharp,stepperD,stepperDSharp,stepperE,stepperF,buttonHit,stepperFSharp,stepperG,stepperGSharp,stepperA,stepperASharp,stepperB,stepperC2,stepperBox,modTypeChoose,modulatorBuffer,carrierBuffer,bandLimit,sinWave,squareWave,sawWave,whiteNoise,carryWave, modWave,carrierNo=0,modulatorNo=0,modulatorType=0, | |
aText,dText,sText,rText, | |
highlightColour,attackSlider,decaySlider,sustainSlider,releaseSlider,signal,cStepper,mainSynth,runProgram,play; | |
sinWave = Array.fill(44100, {|i| sin(freq*2pi*(i/44100))}); | |
//carrierBuffer = Buffer.alloc(s,buffSize,1); | |
carrierBuffer = Buffer.loadCollection(s,sinWave); | |
//modulatorBuffer = Buffer.alloc(s,buffSize,1); | |
modulatorBuffer = Buffer.loadCollection(s,sinWave); | |
buffTime=buffSize/sr; | |
stepStatus = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | |
TempoClock.default.tempo = 100 / 60; | |
// Eventually Parameters for: | |
// - Select Wave x Select Wave | |
// - Stepper Function | |
// - ADSR | |
// - Volume | |
// - Piano Roll (Sets of stepper triggers) | |
// - Highlights | |
// - Mod Depth | |
// - Rate Dial | |
width=900; | |
height=960; | |
backgroundColour=Color.white(0.4); | |
dialColour=Color.gray(0.5); | |
highlightColour=Color.gray(0.25); | |
stepOn=Color.white; | |
stepOff=Color.black; | |
buttonOn=Color.gray(0.7); | |
buttonHit=Color.red(); | |
Tdef(\tdefStepC, { loop { | |
16.do({ | |
// The current iteration of the loop. | |
arg i; | |
// Set the 'gate' of the SynthDef's envelope to that of the step sequencer. | |
signal.set(\gate, stepStatus[i]); | |
{16.do{ | |
// The current iteration of the (inner) loop. | |
arg x; | |
// Conditional that tests if the inner loop iteration matches the current button. | |
if(i == x, | |
{ | |
if(stepStatus[x] == 1, | |
{ | |
// Set to 'state' 3 i.e. active button and active sequencer step. | |
stepperC[x].value_(3); | |
}, { | |
// Set to 'state' 2 i.e. active sequencer step. | |
stepperC[x].value_(2); | |
} | |
) | |
}, | |
{ | |
if(stepStatus[x] == 1, | |
{ | |
// Set to 'state' 1 i.e. active button. | |
stepperC[x].value_(1); | |
}, { | |
// Set to 'state' 0 i.e. inactive button. | |
stepperC[x].value_(0); | |
} | |
) | |
}); | |
// A 'defer' is necessary to slightly delay the evaluation of this Function. | |
}}.defer; | |
0.25.wait; | |
}); | |
}}); | |
/*{Synth(\mainSynth)}.play*/ | |
w = QWindow("My Synth",Rect(left,top,width,height),false,true).front; | |
w.background=backgroundColour; | |
attackSlider=Slider(w,Rect(10,10,30,120)); | |
decaySlider=Slider(w,Rect(40,10,30,120)); | |
sustainSlider=Slider(w,Rect(70,10,30,120)); | |
releaseSlider=Slider(w,Rect(100,10,30,120)); | |
// ------------------------------- create synth to control before playing the Tdef ------------------------- | |
signal = Synth(\mainSynth); | |
stepperBox = CompositeView(w, Rect(11,153,878,800)); | |
stepperBox.background = highlightColour; | |
stepperC = Array.fill(16,{arg i; | |
Button(stepperBox, Rect(70 + (i*50),10, 50, 60)).states_([ | |
["",Color.black, buttonOn], | |
["",Color.black, stepOn], | |
["",Color.black, buttonHit], | |
]) | |
.action_({ | |
if(stepCount[i] == 0, | |
{ | |
stepCount[i] = 1; | |
},{ | |
stepCount[i] = 0; | |
});});}); | |
modTypeChoose = PopUpMenu(w,Rect(140,10,120,120)) | |
.items_(["RM","AM","FM"]) | |
.background_(highlightColour) | |
.font_(Font(size:63)) | |
.action = { | |
arg current_item; | |
case | |
{current_item.value == 0 }{signal.set(\modulatorType,0);} | |
{current_item.value == 1 }{signal.set(\modulatorType,1);} | |
{current_item.value == 2 }{signal.set(\modulatorType,2);} | |
}; | |
Tdef(\tdefStepC).play; | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment