Neat project! I'm trying to accomplish something similar. Specifically, I'd like the Arduino to output midi signals to my SparkFun Music Instrument Shield http://www.sparkfun.com/products/10587. Ideally, I'd like to combine some "canned" midi signals (including a variety of different drum loops) with some "live" signals generated from sensors. I had some success using the NewSoftSerial library to feed MIDI data to the shield.

Here's a sketch I did (based on one of the Sparkfun example sketches) which plays a simple beat. It reads the notes from characters in an array ("b" is kick, "t" is hi-hat, "k" is snare, space is a rest). It reads the delays attached to each note from another array, which in this case I've set up to allow swing on the 16ths.

[Continuation of my prior post]That seems to work well enough, but one thing I'd really like to improve is the "feel" of the beat and the ability to plug in more complicated sequences. As currently set up, each beat is locked in a static "grid" and I can't easily add additional subdivisions (such as 32nd notes or triplets), or play notes longer than a 16th. Also, the timing might be a bit off since calculations happen between each delay. I can't tell.

So, for my next step I'd like to play a MIDI file, or perhaps a sanitized, simplified version thereof, using a timer instead of delays. I've seen examples of how to accomplish a single task using a timer, but I get confused when trying to apply to a long list of events. In pseudo-code, I'd like to:

0. Load 2D array with a sequence of { int tick, int note, int velocity } lines, with a noteOn and noteOff for each note1. Loop through the array as a timer counts ticks for each measure. 2. With each array item, check if the tick has passed. If so, trigger the noteOn. If not, wait a bit (1ms?) and check that point in the array again. (I think that triggering within about 10ms of the desired time will be good enough for me.)3. If the timer count hits 384 (384 = 4 beats x 4 subdivisions x 24 ticks; I think that's a tenth as many as the MIDI file I was working from), reset it to zero and go back to step 1.

Is that a sensible way to set it up? How could I optimize it better to allow more cycles for reading and interpreting input?

I've given a first shot at coding this, but I'm getting errors relating to pointers (which I'm trying to learn about) in the loop() section where I look up the note in the array (2nd field) based on the tick in the array (1st field). Should I be setting this up differently, or would it be a simple syntax tweak to fix this?