//=========================================================================== // Revised 21 January 2012 MIDIRAMP FUNCTION //=========================================================================== // PUT THIS WITH THE INCLUDES AT THE TOP: #include // enables MIDI // PUT THESE WITH THE VARIABLE DECLARATIONS: int midiport = 0; HMIDIOUT device; union { public: unsigned long word; unsigned char data[4]; } message; int instrument = 12; // "marimba" but sounds like 13 xylophone int note; // FUNCTION: //------------------------------------------------------- 2012.01.21 midiRamp // Be aware that the range of notes is different for different instruments. // This code does not take that into account. int midiRamp(int part, int whole) { // only using the 47 MIDI notes which range from 35 to 81 if (whole == 0) whole = 1; // prevent divide by zero part = part % whole; // keep part less than whole note = (part * 47) / whole; note = note + 35; return note; } // FUNCTION CALL: Sleep(milliseconds); // interval between notes if (part == 0) continue; // if we want 0 to be silent note = midiRamp(part, whole); // the call message.data[0] = 0x90; // note on message.data[1] = note; // note # midiOutShortMsg(device, message.word); // do it // PUT ONLY THE CONTENTS IN THIS FIRST EVENT HANDLER __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { midiOutOpen(&device, midiport, 0, 0, CALLBACK_NULL); message.data[0] = 0xC0; // choose instrument command message.data[1] = instrument; // instrument message.data[2] = 100; // once set, no need to repeat message.data[3] = 0; // once set, no need to repeat midiOutShortMsg(device, message.word); }