//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
var sound = new maxiLib.maxiOsc();
var bass = new maxiLib.maxiOsc();
var timer = new maxiLib.maxiOsc();
var mod = new maxiLib.maxiOsc();
var lead = new maxiLib.maxiOsc();
var lead2 = new maxiLib.maxiOsc();
var leadmod = new maxiLib.maxiOsc();
var envelope = new maxiLib.maxiEnv();
var leadenvelope = new maxiLib.maxiEnv();
var filter = new maxiLib.maxiFilter();
var filter2 = new maxiLib.maxiFilter();
var delay = new maxiLib.maxiDelayline();
var mtof = new maxiLib.convert();
var bassout,leadout, delayout;//some variables to hold the data and pass it around
var trigger, trigger2, newnote = 0;//some control variables
var currentCount,lastCount,playHead=0, currentChord=0;//some other control variables
var pitch = [57,57,59,60];//the bassline for the arpeggio
var chord = [0,0,7,2,5,5,0,0];//the root chords for the arpeggio
var currentPitch,leadPitch;//the final pitch variables
//here's the lead line trigger array, followed by the pitches
var leadLineTrigger=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var leadLinePitch=[69,67,65,64,67,66,64,62,65,64,62,57,55,60,57];
audio.play = function(){
currentCount=Math.floor(timer.phasor(9));//this sets up a metronome that ticks every so often
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
trigger=1;//play the arpeggiator line
trigger2=leadLineTrigger[playHead%256];//play the lead line
if (trigger2==1) {//if we are going to play a note
leadPitch=mtof.mtof(leadLinePitch[newnote]);//get the next pitch val
newnote++;//and iterate
if (newnote>14) {
newnote=0;//make sure we don't go over the edge of the array
}
}
currentPitch=mtof.mtof(pitch[(playHead%4)]+chord[currentChord%8]);//write the frequency val into currentPitch