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

  1. /*
  2.  *--- CMIDIDataPort.c ------------------------------------------------------------------
  3.  * Copyright © Paul Ferguson, 1990, 1991, 1992.  All rights reserved.
  4.  *
  5.  * Superclass:  CMIDIPort
  6.  * Subclasses:  CInputPort
  7.  *                COutputPort
  8.  *
  9.  * Description:
  10.  *    CMIDIDataPort.c defines a MIDI Manager port object.  CMIDIDataPort is an abstract
  11.  *    type, containing variables and methods common to input and output port types.
  12.  *
  13.  *    For use with THINK C 5.0, the accompanying THINK Class Library (TCL), and MIDI
  14.  *    Manager 2.0. Refer to the accompanying Microsoft Word document for complete
  15.  *    details about MIDI Manager objects.
  16.  *
  17.  *    If you have comments or questions about this code, you can reach me on
  18.  *    CompuServe at 70441,3055.
  19.  *
  20.  *--------------------------------------------------------------------------------------
  21.  *---- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE ----
  22.  *--------------------------------------------------------------------------------------
  23.  *    If you are not familiar with programming the Apple MIDI Manager, refer to the
  24.  *    "MIDI Management Tools" Version 2.0, available from APDA.  You MUST have the
  25.  *    software (MIDI.H and the library) from this package in order to use these objects.
  26.  *    It will not work without this.
  27.  *--------------------------------------------------------------------------------------
  28.  *    REVISION HISTORY:
  29.  *        August ??, 1990            - Original release (1.0).
  30.  *        November 5, 1990        - Added checks for midiMgrVer to most methods.
  31.  *        August 1991                - updated for THINK C 5.0 as version 2.0
  32.  *--------------------------------------------------------------------------------------
  33.  */
  34.  
  35. #include "CMIDIDataPort.h"                    // This code's header file
  36.  
  37. extern    OSType            gSignature;            // Used to register client
  38. extern CMIDIClient *     gMIDIClient;
  39.  
  40. /*
  41.  *--- NOTE --------------------------------------------------------
  42.  * Note that there is no initialization method for this class.
  43.  * The subclasses CMIDIInputPort and CMIDIOutputPort initialization
  44.  * methods call IMIDIPort() directly.  There is not really any
  45.  * need for an initializer here.
  46.  *-----------------------------------------------------------------
  47.  */
  48.  
  49. /*
  50.  *--- CMIDIDataPort::LoadPatches ----------------------------------
  51.  * Read in patch information from a specified resource. This may
  52.  * also return resNotFound error, which should be handled by the
  53.  * application.
  54.  *-----------------------------------------------------------------
  55.  */
  56. OSErr CMIDIDataPort::LoadPatches(ResType theResType, short theResID)
  57. {
  58.     MIDIPortInfoHdl    rsrcPortInfoH, ourPortInfoH;
  59.     short            i;
  60.     OSErr            theErr = noErr;
  61.  
  62.     if ( ! itsVersion )
  63.         return ErrNoMIDI;
  64.  
  65.     ourPortInfoH = GetPortInfo();
  66.     
  67.     switch (itsResult)        // This was set during initialization
  68.     {
  69.     case midiVConnectMade:
  70.         if ((**ourPortInfoH).numConnects > 0)
  71.             break;
  72.                                     // else fall through to next case...
  73.                                     // (only have a time base connection)
  74.         itsResult = noErr;            //  cheat a little bit... FALL THROUGH!
  75.     case noErr:
  76.     
  77. // Check for virtual connections stored in the specified resource.
  78.  
  79.         rsrcPortInfoH = (MIDIPortInfoHdl) GetResource(theResType, theResID);
  80.         if ( rsrcPortInfoH == (MIDIPortInfoHdl) 0 )
  81.             return resNotFound;
  82.  
  83. // Lock resource and call MIDIConnectData
  84.  
  85.         HLock((Handle) rsrcPortInfoH);
  86.         if ((**ourPortInfoH).type == (**rsrcPortInfoH).type)
  87.         {
  88.             for (i = 0; i < (**rsrcPortInfoH).numConnects; i++)
  89.             {
  90.                 theErr = MIDIConnectData(gSignature,
  91.                             itsPortID,
  92.                             (**rsrcPortInfoH).cList[i].clientID,
  93.                             (**rsrcPortInfoH).cList[i].portID);
  94.             }
  95.         }
  96.         HUnlock((Handle) rsrcPortInfoH);
  97.         ReleaseResource((Handle) rsrcPortInfoH);
  98.         break;
  99.     default:                        // Not likely to see this case
  100.         break;
  101.     }
  102.     return theErr;
  103. }
  104.  
  105. /*
  106.  *--- CMIDIDataPort::Get/SetTCFormat -----------------------------
  107.  * Retrieve or set the time code format.  Constants for valid
  108.  * formats are in MIDI.h
  109.  *----------------------------------------------------------------
  110.  */
  111. short CMIDIDataPort::GetTCFormat(void)
  112. {
  113.     return (itsVersion ? MIDIGetTCFormat(itsRefNum) : -1);
  114. }
  115.  
  116. void CMIDIDataPort::SetTCFormat(short theFormat)
  117. {
  118.     if (itsVersion)
  119.         MIDISetTCFormat(itsRefNum, theFormat);
  120. }
  121.  
  122. // end of CMIDIDataPort.c
  123.