I’ve been playing with a computer generating music. This is my first iteration – it does one very specific thing, and it is starting to sound okay. I taught it drumming myself with some VERY simple rules. It seems to be working out okay.
var counter = 2;
var accents = [9,1,2,1,8,2,3,2,9,2,1,2,8,3,5,4];
function HandleMIDI(event)
{
var keeper = getRandomIntInclusive(1,3);
var dropper = getRandomIntInclusive(1,9);
var variations = getRandomIntInclusive(-20,40);
if (event instanceof NoteOn && keeper < accents[counter] ){
event.velocity += accents[counter]*2;
if (dropper <= accents[counter])
{
event.pitch = 38;
}
else {event.pitch = 40}
event.send();
event.trace();
}
if (event instanceof NoteOff ){
event.send();
}
if (event instanceof NoteOn ){++counter;}
if (counter == 16){counter = 0;}
}
I'm going to be making this more general, and it will shortly have the ability to do crescendos, drops, and melodies... so - I don't need comments on my code quite yet. :-)