home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / MIDI Manager Class Library / CMIDIInputPort.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-05  |  3.9 KB  |  118 lines  |  [TEXT/KAHL]

  1. /*
  2.  *--- CMIDIInputPort.c -----------------------------------------------------------------
  3.  * Copyright © Paul Ferguson, 1990, 1991, 1992.  All rights reserved.
  4.  *
  5.  *    Superclass:     CDataPort
  6.  *    Subclasses:     None
  7.  *
  8.  * Description:
  9.  *    CMIDIInputPort.c defines a MIDI Manager port object.
  10.  *
  11.  *    For use with THINK C 5.0, the accompanying THINK Class Library (TCL), and MIDI
  12.  *    Manager 2.0. Refer to the accompanying Microsoft Word document for complete
  13.  *    details about MIDI Manager objects.
  14.  *
  15.  *    If you have comments or questions about this code, you can reach me on
  16.  *    CompuServe at 70441,3055.
  17.  *
  18.  *--------------------------------------------------------------------------------------
  19.  *---- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE ----
  20.  *--------------------------------------------------------------------------------------
  21.  *    If you are not familiar with programming the Apple MIDI Manager, refer to the
  22.  *    "MIDI Management Tools" Version 2.0, available from APDA.  You MUST have the
  23.  *    software (MIDI.H and the library) from this package in order to use these objects.
  24.  *    It will not work without this.
  25.  *--------------------------------------------------------------------------------------
  26.  *    REVISION HISTORY:
  27.  *        August ??, 1990            - Original release (1.0).
  28.  *        November 5, 1990        - Added checks for midiMgrVer to most methods.
  29.  *        August 1991                - updated for THINK C 5.0 as version 2.0
  30.  *--------------------------------------------------------------------------------------
  31.  */
  32.  
  33. #include "CMIDIInputPort.h"                    // This code's header file
  34.  
  35. #define    midiPoll                104            // From MIDI.a
  36. #define    midiDiscardPacket        176
  37.  
  38. static    pascal void (*CMIDIInputPort::midiDiscardProc) (short theRefNum, MIDIPacketPtr thePacket);
  39. static    pascal void (*CMIDIInputPort::midiPollProc) (short theRefNum, long theOffsetTime);
  40. static    pascal void (*CMIDIInputPort::midiFlushProc) (short theRefNum);
  41.  
  42. /*
  43.  *--- CMIDIInputPort::IMIDIInputPort ------------------------------------------
  44.  * Initialize Input Port. This method sets up the MIDIPortParams data structure
  45.  * and calls CMIDIPort::IMIDIPort().
  46.  *-----------------------------------------------------------------------------
  47.  */
  48. OSErr CMIDIInputPort::IMIDIInputPort(StringPtr            theName,
  49.                                      OSType                thePortID,
  50.                                        Boolean            theVisibleFlag,
  51.                                      CMIDITimePort *    theTimePort,
  52.                                      long               theOffset,
  53.                                      short              theBufSize,
  54.                                      ProcPtr              theReadHook)
  55. {
  56.     MIDIPortParams    portParams;    // MIDI Mgr Init data structure
  57.     OSErr            theResult;
  58.     
  59.     portParams.portID            = thePortID;
  60.     portParams.portType            = midiPortTypeInput;
  61.     if ( (theVisibleFlag == FALSE) && (itsVersion >= 0x0200) )    // Invisible input port, in 2.x
  62.         portParams.portType        |= midiPortInvisible;
  63.  
  64.     portParams.timeBase            = theTimePort ? theTimePort->GetRefNum() : 0;
  65.     portParams.offsetTime        = theOffset;
  66.     portParams.readHook            = (Ptr) theReadHook;
  67.     portParams.refCon            = SetCurrentA5();
  68.     BlockMove(theName, portParams.name, theName[0]+1);
  69.  
  70.     theResult = IMIDIPort(&portParams, theBufSize);
  71.     if (itsVersion >= 0x0200)
  72.     {
  73.         midiDiscardProc = MIDICallAddress(midiDiscardPacket);
  74.         midiPollProc    = MIDICallAddress(midiPoll);
  75.     }
  76.     return theResult;
  77. }
  78.  
  79. void CMIDIInputPort::Flush(void)
  80. {
  81.     if (itsVersion >= 0x0200)
  82.         (*midiFlushProc) (itsRefNum);
  83.     else
  84.         if (itsVersion) MIDIFlush(itsRefNum);
  85. }
  86.  
  87. ProcPtr CMIDIInputPort::GetReadHook(void)
  88. {
  89.     return (itsVersion ? MIDIGetReadHook(itsRefNum) : 0);
  90. }
  91.  
  92. void CMIDIInputPort::SetReadHook(ProcPtr theReadHook)
  93. {
  94.     if (itsVersion)
  95.         MIDISetReadHook(itsRefNum, theReadHook);
  96. }
  97.  
  98. void CMIDIInputPort::Poll(long offsetTime)
  99. {
  100.     if (itsVersion >= 0x0200)
  101.     {
  102.         (*midiPollProc) (itsRefNum, offsetTime);
  103.     }
  104.     else
  105.     {
  106.         if (itsVersion)
  107.             MIDIPoll(itsRefNum, offsetTime);
  108.     }
  109. }
  110.  
  111. void CMIDIInputPort::DiscardPacket(MIDIPacketPtr thePacket)
  112. {
  113.     if (itsVersion >= 0x0200)        // Only valid on MM 2.0 or later!
  114.         (*midiDiscardProc) (itsRefNum, thePacket);
  115. }
  116.  
  117. // end of CMIDIInputPort.c
  118.