/* This javascript and Beatnik algorithm was created by Bob L. Sturm, composerscientist, 1/01/2000. This code may be freely distributed and modified by any person. How's that for open source! */ function compose() { //Since Beatnik uses the 8-bit MIDI system, legal values are of the domain (0,127). notePitch=Math.floor((Math.random()*80)+27) notePitchBend=Math.floor(Math.random()*300) noteVelocity=Math.floor((Math.random()*70)+38) panNote = Math.floor(Math.random()*127) expNote = Math.floor(Math.random()*127) revNote = Math.floor((Math.random()*4)+8) revAmt = Math.floor((Math.random()*77)+50) chorusNote = Math.floor(Math.random()*127) ++voice //Iterating through 14 MIDI channels voice = voice % 14; if (compI < 400) { if (compI < 100 ) { programs = Array(9,12,13,20,47,102,104,119,120,212); //Instruments chosen by myself noteDuration=Math.floor((Math.random()*300)+200) //Length of the note voiceDuration=Math.floor((Math.random()*300)+100) //Time until next voice comes in } else if (compI >= 100 && compI < 125) { programs = Array(7,14,41,79,80,91,107,109,117,127); noteDuration=Math.floor((Math.random()*700)+700) voiceDuration=Math.floor((Math.random()*500)+500) } else if (compI >= 125 && compI < 200) { programs = Array(7,9,12,13,14,20,47,79,80,91,102,104,107,109,119,120,127,212); noteDuration=Math.floor((Math.random()*800)+800) voiceDuration=Math.floor((Math.random()*400)+200) } else if (compI >= 200 && compI < 300) { programs = Array(7,41,50,54,80,86); noteDuration=Math.floor((Math.random()*600)+600) voiceDuration=Math.floor((Math.random()*1000)+800) } else if (compI >=300 && compI < 400) { programs = Array(7,9,12,13,14,20,41,47,50,54,79,80,86,91,102,104,107,109,119,120,127,212); noteDuration=Math.floor((Math.random()*800)+800) voiceDuration=Math.floor((Math.random()*100)+50) } instNum = Math.floor(Math.random()*programs.length); inst = programs[instNum]; //choose instrument eval("science0.setController("+voice+",1,"+notePitchBend+");"); eval("science0.setController("+voice+",10,"+panNote+");"); eval("science0.setController("+voice+",11,"+expNote+");"); eval("science0.setController("+voice+",90,"+revNote+");"); eval("science0.setController("+voice+",91,"+revAmt+");"); eval("science0.setController("+voice+",93,"+chorusNote+");"); ++compI scoreNotes = "science0.playNote("+voice+",1,"+inst+","+notePitch+","+noteVelocity+","+noteDuration+")" eval(scoreNotes); playing = setTimeout("compose();",voiceDuration); } }