if (NotePitch > MAXGLOCKPITCH) { // are we out of range, too high?etc... etc...
}
I implemented several steps.
1. I try several transposes for the song. For each time I miss a note I reduce the score of that transpose by: LOG( number_of_times_I_missed_this_Note ).
1a. The LOG ensures that I don't give too much weight to a single repetitive note that's being missed.
2. I transpose the entire piece by the transpose with the best score.
3. For every not that's not in the range, I add or reduce octaves until it fits (as suggested above).
The result sounds a bit off-pitch, but it's still pretty good: result
What do you think?
Other pieces sound much better. I purposefully chose the good old "T&F" because it spans a bunch of octaves, and I wanted to push the algorithm to the limit. I think it did pretty well.
I'll upload a recording from my glockenspiel soon. (Need to re-glue some mechanical parts again :-( )