aboutsummaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rwxr-xr-xmain.cpp112
1 files changed, 48 insertions, 64 deletions
diff --git a/main.cpp b/main.cpp
index e3e50cb..5cfdb74 100755
--- a/main.cpp
+++ b/main.cpp
@@ -1,81 +1,65 @@
#include "maximilian.h"
-//This shows how to use maximilian to build a polyphonic synth.
-
-//These are the synthesiser bits
-maxiOsc VCO1[6],VCO2[6],LFO1[6],LFO2[6];
-maxiFilter VCF[6];
-maxiEnv ADSR[6];
-
-//This is a bunch of control signals so that we can hear something
-
-maxiOsc timer;//this is the metronome
-int currentCount,lastCount,voice=0;//these values are used to check if we have a new beat this sample
-
-//and these are some variables we can use to pass stuff around
-
-double VCO1out[6],VCO2out[6],LFO1out[6],LFO2out[6],VCFout[6],ADSRout[6],mix,pitch[6];
-
+double outputs[2],moreoutputs[2]; //some track outputs
+double filtered,patch1,patch2,tune,delayed,
+mixed,ramp,filtered2,noise,pan,more;//a bunch of patch cables
+int beat,lastbeat,morebeats,lastmorebeats;//some rhythmic elemts
+double env[4]={200,0,0,50};//the kick drum pitch envelope data
+double env2[6]={10000,0,9000,5,0,5};//the hi hat pitch envelope dat
+double melody[14]={600,0,0,650,0,0,400,0,0,425,0,300,0,315};//the melody data
+int rhythm1[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0};//another way of doing a rhythm
+maxiOsc a,c,d,e,g,h,i,j,squarewave;//some oscillators
+maxiEnvelope b,f;//two envelopers
+maxiDelayline delay;//a delay line
+maxiFilter myfilter,antia;// a FAT filter
+maxiMix mymix,bobbins;//some panning busses
+maxiSample beats;
void setup() {//some inits
+ b.amplitude=env[0];//starting value for envelope b
+ f.amplitude=env2[0];//same for f
+ beats.load("/Users/michaelgrierson/Documents/workspace/Maximilian/beat2.wav");//put a path to a soundfile here. Wav format only.
- for (int i=0;i<6;i++) {
-
- ADSR[i].setAttack(0);
- ADSR[i].setDecay(200);
- ADSR[i].setSustain(0.2);
- ADSR[i].setRelease(2000);
-
- }
}
-void play(double *output) {
-
- mix=0;//we're adding up the samples each update and it makes sense to clear them each time first.
-
- //so this first bit is just a basic metronome so we can hear what we're doing.
+void play(double *output) {//this is where the magic happens. Very slow magic.
+ beat=((int) c.phasor(8));//this oscillator is now a counter
+ morebeats=((int) e.phasor(0.5,0,16));//so is this one
+ patch1=b.line(4,env);//here's envelope b
+ patch2=f.line(6,env2);//here's envelop f
+ tune=g.saw(melody[morebeats]*0.25);//here's the melody, which occurs at certain times
- currentCount=(int)timer.phasor(8);//this sets up a metronome that ticks 8 times a second
-
- if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
-
- if (voice==6) {
- voice=0;
- }
+ if (lastbeat!=beat) {//this is a nice sample and hold routine for the kick drum
+ f.trigger(0, env2[0]);//it runs off the hi hat.
- ADSR[voice].trigger=1;//trigger the envelope from the start
- pitch[voice]=voice+1;
- voice++;
+ if (rhythm1[morebeats]==1) {
+ b.trigger(0, env[0]);//and gets played when it's time.
+ }
}
+ lastbeat=beat;//let's start again. It's a loop
+ ramp=i.phasor(0.5,1,2048);//create a basic ramp
+ pan=j.phasor(0.25);//some panning from a phasor (object is equal power)
+ delayed=delay.dl(tune, ramp, 0.9)*0.125;//the delay line
+ //then it all gets mixed.
+ mixed=((a.sinewave(patch1)*0.5)+((d.saw(patch2))*0.125)+(delayed*0.3)*0.5);
+ //add some noise
+ noise=i.noise()*0.25;
+ filtered2=beats.play(1*(1./16.),0,beats.length);
+ // filtered2=beats.play(-1);
- //and this is where we build the synth
+ more=squarewave.pulse(melody[morebeats],pan)*0.05;
+ //filter the noise! this lores takes values between 1 and 100 for res, and freq for cutoff.
+ filtered=myfilter.lores(filtered2, 1+(pan*10000), 10)*0.4;
- for (int i=0; i<6; i++) {
-
-
- ADSRout[i]=ADSR[i].adsr(1.,ADSR[i].trigger);//our ADSR env is passed a constant signal of 1 to generate the transient.
-
- LFO1out[i]=LFO1[i].sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
-
- VCO1out[i]=VCO1[i].pulse(55*pitch[i],0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
- VCO2out[i]=VCO2[i].pulse((110*pitch[i])+LFO1out[i],0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
-
-
- VCFout[i]=VCF[i].lores((VCO1out[i]+VCO2out[i])*0.5, 250+((pitch[i]+LFO1out[i])*1000), 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
-
- mix+=VCFout[i]*ADSRout[i]/6;//finally we add the ADSR as an amplitude modulator
-
-
- }
+ //now we send the sounds to some stereo busses.
+ mymix.stereo(more+mixed+delayed, outputs, 1-pan);
+ bobbins.stereo(filtered, moreoutputs, pan);//invert the pan
- output[0]=mix*0.5;//left channel
- output[1]=mix*0.5;//right channel
-
+ //mixing
- // This just sends note-off messages.
- for (int i=0; i<6; i++) {
- ADSR[i].trigger=0;
- }
+ output[0]=outputs[0]+moreoutputs[0]/10;//stick it in the out!!
+ output[1]=outputs[1]+moreoutputs[1]/10;
}
+