Opens a MIDI output device for playback.
Namespace: radio42.Multimedia.Midi
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.2
Syntax
public static MIDIError MIDI_OutOpen( ref IntPtr handle, int deviceID, MIDIOUTPROC proc, IntPtr user )
Parameters
- handle
- Type: SystemIntPtr
Returns the MIDI output handle. The handle is used to identify the device in calls to other MIDI output functions. - deviceID
- Type: SystemInt32
Identifier of the MIDI output device to be opened (see MIDI_OutGetDevCaps(Int32, MIDI_OUTCAPS) for details). - proc
- Type: radio42.Multimedia.MidiMIDIOUTPROC
The MIDIOUTPROC callback delegate to use. Called during MIDI playback to process messages related to the progress of the playback. If no callback is desired, specify for this parameter. For more information on the callback function, see MIDIOUTPROC. - user
- Type: SystemIntPtr
User instance data passed to the callback function.
Return Value
Type: MIDIErrorReturns 0 if successful or an error code otherwise. For possible error values see MIDIError.
Remarks
The flags are automatically set according to the given proc (thats why this method does not contain any flags parameter).
To determine the number of MIDI output devices present in the system, use the MIDI_OutGetNumDevs function. The device identifier specified by deviceID varies from zero to one less than the number of devices present.
If a function is chosen to receive callback information, the following messages are sent to the function to indicate the progress of MIDI output: MOM_OPEN, MOM_CLOSE, and MOM_DONE.
Examples
private MIDIOUTPROC _midiProc; private IntPtr _midiOutHandle; ... // Open the Midi device #2 _midiProc = new MIDIOUTPROC(MyMidiProc); MIDIError ret = Midi.MIDI_OutOpen(ref _midiOutHandle, 2, _midiProc, 0); if (ret == MIDIError.MIDI_OK) { // device opened and ready } ... // When not needed anymore...stop the device Midi.MIDI_OutReset(_midiOutHandle); // and close the device Midi.MIDI_OutClose(_midiOutHandle); ... private void SendShortMessage(int message) { MIDI_OutShortMsg(_midiOutHandle, message); } private void SendSysExMessage(byte[] data) { MIDI_HEADER header = new MIDI_HEADER(data); header.Prepare(false, _midiOutHandle); // If the header was perpared successfully. if (header.HeaderPtr != IntPtr.Zero) { // send a system-exclusive message to the output device Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr); } } public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2) { // handle all Midi messages here if (msg == MIDIMessage.MOM_OPEN) { // nothing to do } else if (msg == MIDIMessage.MOM_CLOSE) { // handle is from now on invalid } else if (msg == MIDIMessage.MOM_DONE) { // process the message... // param1 will contain the pointer to the MIDI_HEADER MIDI_HEADER header = new MIDI_HEADER(param1); // process the header if needed ... // and finally unprepare the header header.Unprepare(false, handle); } }
See Also