Arduino + Musical Instrument Shield

cooper_hu:
If it's so easy could you please just show me!

I will explain in pseudocode. It's 'plain English' that describes program flow, but without being syntax-specific, and can be translated into any programming language.

I will annotate a bit. With your inexperience you don't know how to glean the clues that the Grump wrote.

First thing though, don't use 'millis' directly, not in numbers. You should define variables that give your constants names. You should define a constant only once. If you use a 'number' in 4,000 places to play 4,000 notes, and you need to change it, that's a lotta search/replace. It' also easier to read English than numbers.

For example, you do a few tests, and figure out how many millis a whole note should be for the tempo. Here's a whole note, a half note, quarter, and triplet. Notice how the -number- is used only -once- to define the timing for 4 variables.

wnote = 1000;
hnote = wnote / 2;
qnote = wnote / 4;
tnote = wnote / 3;

'Priceless,' eh? :smiley:

Next you need to name your tone frequencies. I don't know what that board uses but for pseudocode purposes I'll pick a format such as Na2 For Note-A-2nd octave. Nbfl3 = b-flat-3rd octave.

Next you need to define your instrument names in English. I don't know what the board uses in terms of ports, channels, voices or whatever but the point is to make 'typing music' as painless as possible. You might set up voice names piano, cello, and frenchhorn. BUT you need to SHORTEN them to avoid typing, such as pno, clo, and fhn.

For each voice you need a timer, that does all the millis work behind the scenes, such as pnomil and clomil. those are the variables that you will set that when you turn a note -on- it will know 'when in the future' to turn it off.

Next you need a two functions. One turns a note on, and another turns it off. You'll need to translate this description ito whatever format the board uses.

To turn on a note you define a function for each voice, that accepts a note, and a time. Example...

pno (afl4, qnt) {} // I just amended what I said, shortened the typing by leaving off the N, and cutting qnote down to qnt.

The function does two things:

  1. Puts the frequency into the voice note register (however the board does that).

  2. Calculates the -ending- -millis- for the note, and puts that into the variable you created, such as pnomil - millis() + qnt.

Got that part? You're setting up something -now- that says turn -off- that voice at a certain time.

Personally I think I'd write this in caps because it's easier for these tired old eyes to see, but it's easy for me because I can type continuously by leaning the pinkie on the shift key and using the rest of my fingers to type:

PNO (AFL4, QNT) {appropriate code here}; // Whatever you prefer.

The function that turns a note off looks like PNOOFF() {appropriate code here};

In any case after aaaaaallllllll that setup work you now have all the Plain English interface all defined, constants, variables, and functions. 90% of ease of use of software is the UI. 90% of ease of -writing- the software is the prep work.

Grumpy_Mike:
Your code should be
Start loop
Has the thing that triggers the note happened ... -> send note on message, set up note off pending time

What that MEANS is that for EACH NOTE you're gonna have a few lines of...

CLO (A3, HNT);
PNO (A2, QNT);
PNO (B2, QNT);

That plays three notes. That's it, keep going.

This is a HUGE PAIN IN THE ASS!!!!!!!!!!!!!! to write any significant amount of notes!!! I find it hard to believe that you're even asking about this, that there isn't already something to translates Mixcraft Piano Roll or whatever into a standard format that can be imported into a music shield sketch. This really really sucks. I'd rather spend 40 hours writing a translator than 40 hours to write just -one- song that -could- have been done on 4 hours plus a translator.

Regardless.

Is a note off pending and is it time to turn off ...... -> send note off and clear pending indicator

For each voice you test to see if the current note is ended.

if (millis() >= pnomil) {
Call function to turn off the piano.
}

End loop

Get it? Got it? Good. :slight_smile: