MusicKit  0.0.0
MKMidi.h
00001 /*
00002   $Id$
00003   Defined In: The MusicKit
00004 
00005   Description: 
00006     The MKMidi object provides MIDI input/output access. It emulates some of the
00007     behavior of a MKPerformer: It contains a NSMutableArray of MKNoteSenders, one per MIDI
00008     channel (as well as an extra one for MIDI system and channel mode messages).
00009     You can receive MKNotes derived from MIDI input by connecting an MKInstrument's
00010     MKNoteReceivers to the MKNoteSenders of a MKMidi instance.
00011    
00012     Similarly, MKMidi emulates some of the behavior of an MKInstrument: It contains
00013     an array of MKNoteReceivers, one per MIDI channel (as well as the extra one).
00014     You can send MKNotes to MIDI output by connecting a MKPerformer's MKNoteSenders
00015     to the MKNoteReceivers of a MKMidi instance.
00016    
00017     However, the MKMidi object is unlike a MKPerformer in that it represents a 
00018     real-time  device. In this manner, MKMidi is somewhat like MKOrchestra, 
00019     which represents the DSP. The protocol for controlling MKMidi is the same 
00020     as that for the MKOrchestra. This protocol is described in the file 
00021     <MusicKit/MKDeviceStatus.h>.
00022     
00023     The conversion between MusicKit and MIDI semantics is described in the
00024     MusicKit documentation.
00025 
00026   Original Author: David A. Jaffe
00027 
00028   Copyright (c) 1988-1992, NeXT Computer, Inc.
00029   Portions Copyright (c) 1994 NeXT Computer, Inc. and reproduced under license from NeXT
00030   Portions Copyright (c) 1994 CCRMA, Stanford University
00031   Portions (Time code extensions) Copyright (c) 1993 Pinnacle Research
00032   Portions Copyright (c) 1999-2000, The MusicKit Project.
00033 */
00034 @class MKConductor;
00035 
00154 #ifndef __MK_Midi_H___
00155 #define __MK_Midi_H___
00156 
00157 #import <Foundation/NSObject.h>
00158 #import <MKPerformSndMIDI/PerformMIDI.h>
00159 #import "MKDeviceStatus.h"
00160 #import "params.h"
00161 #import "_midi.h"  // for _MKMidiInStruct and _MKMidiOutStruct definitions
00162 
00163 /* sbrandon: 10/05/2001
00164  * get around the fact that GNUstep does not have NSMach ports, but does respond to -machPort
00165  * and +portWithMachPort
00166  */
00167 #ifdef GNUSTEP
00168 #define NSMachPort NSPort
00169 #endif
00170 
00171 @interface MKMidi: NSObject
00172 {
00173     NSMutableArray *noteSenders;         
00174     NSMutableArray *noteReceivers;       
00175     MKDeviceStatus deviceStatus;         
00176     NSString *midiDevName;               
00177     BOOL useInputTimeStamps;             
00178     BOOL outputIsTimed;                  
00179     double localDeltaT;                  
00181 @private
00182     /* systemIgnoreBits A bit map indicating which MIDI system messages to ignore from input */
00183     unsigned int systemIgnoreBits;
00184     _MKMidiInStruct *_pIn;               // determines input source
00185     _MKMidiOutStruct *_pOut;             // determines output sink
00186     double timeOffset;
00187     enum MKMidiDirection {MKMidiInputOnly, MKMidiOutputOnly, MKMidiInputOutput} ioMode; 
00188     BOOL isOwner;
00189     // These are handles used to identify the MIDI communication channel.
00190     // We pretend they are Mach-like ports even though they function only as references.
00191     MKMDPort devicePort;         // Device port
00192     MKMDOwnerPort ownerPort;     // Owner port, as for the device port.
00193     MKMDReplyPort recvPort;      // Port on which we receive midiIn messages
00194     MKMDReplyPort queuePort;     // Port on which we notify when there is space on the playback queue.
00195     BOOL mergeInput;
00196     NSString *hostname;          // for MIDI communicated across hosts.
00198     int inputUnit;
00200     int outputUnit;
00201     int queueSize;
00203     MKConductor *conductor;      // Used by conductor and setConductor: methods
00205     MKConductor *synchConductor;
00206     NSMachPort *exceptionPort;   // Exception port.  Only one unit per device may have one.
00207     NSMachPort *alarmPort;       // Alarm port.  Only one unit per device may have one.
00209     MKMidi *mtcMidiObj;
00211     BOOL displayReceivedMIDI;
00212     double alarmTime;
00213     int intAlarmTime;
00214     BOOL alarmTimeValid;
00215     BOOL alarmPending;
00216 }
00217 
00218 #define MK_MAXMIDIS 16  /* Maximum number of Intel-based Midi objects */
00219 
00226 - (MKConductor *) conductor;
00227 
00234 - setConductor: (MKConductor *) aConductor;
00235 
00252 + midiOnDevice: (NSString *) devName host: (NSString *) hostName;
00253 
00270 + midiOnDevice: (NSString *) devName;
00271  /* Allocates and initializes a new object, if one doesn't exist already, for
00272     specified device. 
00273     For the NeXT hardware, "midi1" is serial port B and "midi0" is port A.
00274     For Intel hardware, "midi0" corresponds to MIDI0 in the defaults
00275     data base, "midi1" corresponds to MIDI1, etc.  You may also specify the
00276     driver/unit name explicitly as "Mididriver0", "Mididriver1", etc., in 
00277     which case no indirection via the defaults data base is done.
00278   */
00279 
00280 
00290 + midi;
00291 
00298 - initOnDevice: (NSString *) devName hostName: (NSString *) hostName;
00299 
00305 - initOnDevice: (NSString *) devName;
00306 
00311 - init;
00312 
00316 - (void) dealloc;
00317 
00322 - (MKDeviceStatus) deviceStatus;
00323 
00334 - open;
00335 
00344 - openInputOnly;
00345 
00354 - openOutputOnly;
00355 
00364 - run;
00365 
00374 - stop;
00375 
00381 - (void) close;
00382 
00389 - abort;
00390 
00403 - setOutputTimed: (BOOL) yesOrNo;
00404 
00418 - (BOOL) outputIsTimed;
00419 
00434 - (MKNoteSender *) channelNoteSender: (unsigned) channel;
00435 
00450 - (MKNoteReceiver *) channelNoteReceiver: (unsigned) channel;
00451 
00456 - (MKNoteReceiver *) noteReceiver;
00457 
00465 - (NSArray *) noteReceivers;
00466 
00471 - (MKNoteSender *) noteSender;
00472 
00480 - (NSArray *) noteSenders;
00481   
00482 /* sb: added 30/6/98 to replace MidiIn function */
00483 - (void) handleMachMessage: (void *) machMessage;
00484 
00495 - setUseInputTimeStamps: (BOOL) yesOrNo;
00496 
00523 - (BOOL) useInputTimeStamps;
00524 
00535 - ignoreSys: (MKMidiParVal) param;
00536 
00558 - acceptSys: (MKMidiParVal) param;
00559 
00564 - (double) localDeltaT;
00565 
00577 - setLocalDeltaT: (double) value;
00578 
00589 - setMergeInput: (BOOL) yesOrNo;
00590 
00596 - awaitQueueDrain;
00597 
00606 - allNotesOffBlast;
00607 
00614 - allNotesOff;
00615 
00630 - (double) time;
00631 
00649 - getMTCFormat: (short *) format
00650          hours: (short *) h
00651            min: (short *) m
00652            sec: (short *) s
00653         frames: (short *) f;
00654 
00660 - synchConductor;
00661 
00670 + (NSArray *) getDriverNames;
00671 
00678 + (NSArray *) getDriverNamesForInput;
00679 
00686 + (NSArray *) getDriverNamesForOutput;
00687 
00692 - (NSString *) driverName;
00693 
00699 - (NSString *) description;
00700 
00704 - (void) downloadDLS: (NSArray *) dlsPatches;
00705 
00706 @end
00707 
00708 #endif