//=========================================================================== // Mini MIDI // a minimal implementation // Nick Gessler // 1 March 2005 //=========================================================================== #include #pragma hdrstop #include "Unit1.h" #include // we need this //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //=========================================================================== // VARIABLES //=========================================================================== int midiport = 0; HMIDIOUT device; union { public: unsigned long word; unsigned char data[4]; } message; int instrument; int note; //=========================================================================== // FUNCTIONS //=========================================================================== // none //=========================================================================== // EVENT HANDLERS //=========================================================================== //--------------------------------------------------------------- Form Create void __fastcall TForm1::FormCreate(TObject *Sender) { midiOutOpen(&device, midiport, 0, 0, CALLBACK_NULL); } //--------------------------------------------------------------- Play Button void __fastcall TForm1::ButtonPlayClick(TObject *Sender) { note = StrToInt(Form1->EditPlayNote->Text); message.data[0] = 0x90; // note on message.data[1] = note; // note # message.data[2] = 100; // once set, no need to repeat message.data[3] = 0; // once set, no need to repeat midiOutShortMsg(device, message.word); // this works // midiOutShortMsg(device, message.data[0]); // these don't work // midiOutShortMsg(device, message.data[1]); // midiOutShortMsg(device, message.data[2]); // midiOutShortMsg(device, message.data[3]); } //------------------------------------------------------------ Silence Button void __fastcall TForm1::ButtonSilenceClick(TObject *Sender) { note = StrToInt(Form1->EditSilenceNote->Text); message.data[0] = 0x80; // note off message.data[1] = note; // note # message.data[2] = 100; // once set, no need to repeat message.data[3] = 0; // once set, no need to repeat midiOutShortMsg(device, message.word); // this works // midiOutShortMsg(device, message.data[0]); // these also work // midiOutShortMsg(device, message.data[1]); // midiOutShortMsg(device, message.data[2]); // midiOutShortMsg(device, message.data[3]); } //--------------------------------------------------------- Instrument Button void __fastcall TForm1::ButtonInstrumentClick(TObject *Sender) { instrument = StrToInt(Form1->EditInstrument->Text); message.data[0] = 0xC0; // choose instrument message.data[1] = instrument; midiOutShortMsg(device, message.word); // midiOutShortMsg(device, message.data[0]); // these also work // midiOutShortMsg(device, message.data[1]); // these also work } //------------------------------------------------------- MIDI Devices Button void __fastcall TForm1::ButtonMIDIDevicesClick(TObject *Sender) { // returns the number of MIDI output devices available on the system Form1->EditDevices->Text = midiOutGetNumDevs(); } //--------------------------------------------------------------------------- //=========================================================================== // THAT'S ALL FOLKS //===========================================================================