Derived from: public BObject
Declared in: <midi/MidiPort.h>
The BMidiPort class provides the mechanisms for reading MIDI data from the MIDI-In ports, and for writing MIDI data to the MIDI-Out ports. The BeBox has two pairs of MIDI-In and MIDI-Out hardware ports, stacked vertically on the back panel:
You can use a single BMidiPort object to communicate with both halves (the input side and the output side) of a single in/out pair. Thus, to talk to all four ports, you only need two BMidiPort objects. However, you can create and use any number of BMidiPort objects in your application--multiple BMidiPort objects can open and use the same hardware ports at the same time.
To obtain data from a MIDI-In port or send data to a MIDI-Out port, you must first open the ports by calling BMidiPort's Open() functions. The function's single argument is a string that names the identifies the in/out pair that you're opening. The two pairs of MIDI ports are named "midi1" and "midi2". For example, to open the MIDI-In 1 and MIDI-Out 1 pair, you invoke Open() thus:
BMidiPort *m_port = new BMidiPort(); m_port->Open("midi1");
When you're finished with the ports, you can close them through the Close() function. The ports are closed automatically when the BMidiPort object is destroyed.
According to the BMidi rules, a BMidi-derived class implementation of Run() should create and spray MIDI messages. Furthermore, the implementations of the input functions should realize the messages they receive.
The BMidiPort implementation of Run() produces messages by reading them from the MIDI-In port and spraying them to the connected objects. The input functions send MIDI messages to the MIDI-Out port. Linguistically, this might seem backwards, but it makes sense if you think of a BMidiPort as representing not only the hardware port, but whatever is connected to the port. For example, if you're reading data that's generated by an external synthesizer, the Run() function can be thought of as encapsulating the synthesizer itself. From this perspective, the message-generation description of Run() is reasonable. Similarly, the input functions fulfill their message-realization promise when you consider them to be (for example) the synthesizer that's connected to the MIDI-Out port.
It's possible to use the same BMidiPort object to accept data from MIDI-In and broadcast different data to MIDI-Out. You can even connect a BMidiPort object to itself to create a "MIDI through" effect: Anything that shows up at the MIDI-In port will automatically be sent out the MIDI-Out port.
BMidiPort(void)
Connects the object to the MIDI-In and MIDI-Out ports. The MIDI-Out connection is active from the moment the object is constructed Messages that arrive through the input functions are automatically sent to the MIDI-Out port. To begin reading from the MIDI-In port, you have to invoke the object's Start() function.
virtual ~BMidiPort(void)
Closes the connections to the MIDI ports.
bool AllNotesOff(bool controlOnly, ulong time = B_NOW)
Commands the BMidiPort object to issue an All Notes Off MIDI message to the MIDI- Out port. If controlOnly is TRUE, only the All Notes Off message is sent. If it's FALSE, a Note Off message is also sent for every key number on every channel.
void Close(void)
Closes the object's MIDI ports. The ports should have been previously opened through a call to Open().
long Open(const char *name)
Opens a pair of MIDI ports, as identified by name, so the object can read and write MIDI data. The names that correspond to the two set of MIDI ports are "midi1" and "midi2". The object isn't given exclusive access to the ports that it has opened--other BMidiPort objects, potentially from other applications, can open the same MIDI ports. When you're finished with the ports, you should close them through a (single) call to Close().
The function returns B_NO_ERROR if the ports were successfully opened.
The Be Book, HTML Edition, for Developer Release 8 of the Be Operating System.
Copyright © 1996 Be, Inc. All rights reserved.
Be, the Be logo, BeBox, BeOS, BeWare, and GeekPort are trademarks of Be, Inc.
Last modified September 6, 1996.