// // Programmer: Craig Stuart Sapp // Creation Date: Sat Jan 1 20:29:45 PST 2005 // Last Modified: Sat Jan 1 21:14:04 PST 2005 // Filename: ...midiio/doc/windowsmidi/keymidi/keymidi2.cpp // URL: http://midiio.sapp.org/doc/windowsmidi/keymidi2/keymidi2.cpp // Syntax: C; Visual C/C++ 5/6 // // Description: The example program shows how to open MIDI output, // send a MIDI message, and close MIDI output using the // MidiIO C++ library instead of accessing the Windows // multimedia library directly. // #include /* MIDI interface when using the MidiIO library */ #include /* include for kbhit() and getch() functions */ #include int main(int argc, char** argv) { int ckey; // storage for the current keyboard key being pressed int midiport; // select which MIDI output port to open int notekey = 60; // MIDI note key number to play int velocity = 100; // MIDI note velocity parameter value // MidiIO class variables: MidiOutput midiout; // MIDI output interface Voice voice; // Used to keep track of note on/off status // Assign the MIDI output port number (from input or default to 0) if (argc < 2) { midiport = 0; } else { midiport = atoi(argv[1]); } printf("MIDI output port set to %d.\n", midiport); // Open the MIDI output port midiout.setPort(midiport); midiout.open(); voice.setPort(midiout.getPort()); // Main event loop printf("Press \"q\" to quit.\n"); while (1) { if (kbhit()) { ckey = getch(); if (ckey == 'q') break; if (voice.status()) { voice.off(); printf("Note turned OFF.\n"); } else { voice.play(0, notekey, velocity); printf("Note turned ON.\n"); } } } // Turn off the MIDI note (if currently playing): voice.off(); // Close the MIDI Output port midiout.close(); return 0; }