MusicKit
0.0.0
|
A MKMidi object lets you communicate with a MIDI synthesizer by providing a simple interface to the MIDI device driver. More...
#import <MKMidi.h>
A MKMidi object lets you communicate with a MIDI synthesizer by providing a simple interface to the MIDI device driver.
The MKMidi class also provides a mechanism that automatically converts MIDI messages into MKNote objects and vice versa, allowing you to incorporate MIDI data into a MusicKit application with a minimum of effort.
While inheriting neither from MKPerformer nor MKInstrument, the MKMidi class emulates both of them: Like a MKPerformer, it contains a NSArray of MKNoteSenders, and, like an MKInstrument, it contains a NSArray of MKNoteReceivers. A newly created MKMidi object contains 17 MKNoteSenders and 17 MKNoteReceivers, one for each of the 16 Voice Channels and one for the Basic Channel. (Note, however, that the method setMergeInput: allows the option of all messages to be sent via MKNoteSender 0. Similarly, if a MKNote is sent to MKNoteReceiver 0, the MK_midiChan parameter of that MKNote determines on which MIDI channel it is sent.)
Before a MKMidi object can receive messages from or send messages to an external synthesizer, it must be sent the open and run messages:
Balancing these two methods are stop and close:
The state of a MKMidi object with respect to the foregoing methods is described in its deviceStatus instance variable:
(Note that these are the same methods and MKDeviceStatus values used to control and describe the status of an MKOrchestra object.)
The MIDI driver has its own clock that's generally more regular and steadfast than the MKConductor's clock. To take advantage of this, the MKConductor is, by default, synched to incoming MIDI messages: When a MIDI message arrives, the MKConductor's clock is set to the time stated in the message timestamp. You can disable this feature by sending setUseInputTimeStamps: NO to a MKMidi object.
On the other side, as a MKMidi object initiates an outgoing MIDI message, it gives the message a timestamp that indicates when the message should be performed by the external MIDI device. By default, the MIDI driver looks at the timestamp and waits until the appropriate time (as determined by its own clock) to send the message on to the synthesizer. By sending setOutputTimed: NO to a MKMidi object, you can specify that the driver is to ignore the timestamps and send all messages as soon as it receives them.
Note that in all cases the MKConductor that's overseeing the MusicKit performance must be clocked if you want to use a MKMidi object.
As MKMidi receives MIDI messages it creates MKNote objects following these rules:
For each MIDI message that has a Note Number, a MKNote object is created and given a noteTag that corresponds to the combination of the message's Channel Number and Note Number.
If multiple Note Offs are received (for a particular Channel/Note number) without intervening Note Ons, only the first Note Off is converted into a MKNote object. The others are suppressed.
A Note On message with a MIDI Velocity of 0 is turned into a MKNote object of type noteOff.
In sending messages to an external synthesizer, MKMidi converts MKNote objects to MIDI messages:
If two successive noteOns have the same noteTag and the same MK_keyNum value, a Note Off is generated on the same channel and with the same Key Number as those for the Note Ons.
If two successive noteOns have the same noteTag but different MK_keyNum values, the second Note On message is followed by a Note Off with the Key Number of the first Note On. This is to accommodate MIDI Mono Mode.
A number of parameters are provided to accommodate MIDI messages. These are described in the section titled Representation of MIDI in the MusicKit .
A MKMidi object can be used to synchronize a performance to incoming MIDI time code. To do so, send a MKConductor the message setMTCSynch:, with a MKMidi object as the argument. For further information on MIDI time code, see the appendix titled MIDI Time Code in the MusicKit .
The MIDI synthesizer is attached to a serial port at the back of a NeXT computer, to a MPU-401 compatible card installed in a P.C., to a MIDI device defined within Microsoft Windows DirectMusic or to a MIDI device defined within Apple MacOS X CoreMIDI.
See Administration/MidiHardwareInfo.rtf for using MIDI on NeXT hardware.