(you must be careful when assigning values to the arrays, of course).
If the song name is entered by the user, e.g. via serial port, then you have to find a way to convert from string to integer. A not quite elegant but conceptually simple solution could be:
int songIndex;
if (strcmp(songName, "HAPPY BIRTHDAY") == 0) {
songIndex = SONG_HAPPYBIRTHDAY;
}
else if (strcmp(songName, "YOUR SONG") == 0) {
songIndex = SONG_YOURSONG;
}
// etc.
Note: you must declare the second index (max stringlen +1) to a fixed number, and use the first to "search".
Better solution might be to use an array of structs. In every struct there is all info about one piece of music. Then you only need one index.
typedef struct {
char name[20];
int notes[100];
int beat[100];
} Music ;
Music M[10] =
{
{
"hello",
{1,2,3},
{4,5,6},
},
{
"goodbye",
{12,23,34},
{99,88,77}
},
... // etc
};
Note that in the example above the sizes of the fields of the struct are fixed. This causes quite some overhead. A more elaborated version uses pointers for the fields, then the sizes of the fields can be allocated as needed.
Each struct member would not be an array but a pointer to the appropriate data type. For example:
typedef struct {
char* name;
int* notes;
int num_notes;
int* beat;
int num_beats;
} Music ;
Then you have to dynamically allocate memory for the arrays via malloc(), and remember to free() every pointer when you don't use it anymore. I haven't used malloc()/free() on the Arduino so far, so I can't tell how well it works.
The num_beats and num_notes could be avoided by taking an int number which is not a valid note nor a valid beat value and giving it the role of "array terminator", like 0x00 is used as "string terminator".
My feeling is that malloc() and friends are a "rich boy" thing (as a friend of mine would say). You seem to confirm this. I'll have to do some research sooner or later on this subject...