home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / MIDI Manager Class Library / CMIDIClient.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-14  |  4.6 KB  |  136 lines  |  [TEXT/KAHL]

  1. /*
  2.  *--- CMIDIClient.c ---------------------------------------------------------------------
  3.  * Copyright © Paul Ferguson, 1990, 1991, 1992.  All rights reserved.
  4.  *
  5.  * Superclass:  CObject
  6.  * Subclasses:  None
  7.  *
  8.  * Description:
  9.  *    CMIDIClient.c defines a MIDI Manager client 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 "CMIDIClient.h"            // This code's header file
  34.  
  35. extern    OSType    gSignature;            // Used to register client
  36.  
  37. /*
  38.  *--- gMIDIClient (global variable) --------------------------------------
  39.  * Because these objects are designed only for a single MIDI client, we
  40.  * define this global to hold it.
  41.  *------------------------------------------------------------------------
  42.  */
  43.  
  44. CMIDIClient * gMIDIClient = (CMIDIClient *) 0;
  45.  
  46.  
  47. /*
  48.  *--- CMIDIClient::IMIDIClient -------------------------------------------
  49.  * Initialize this object.
  50.  *
  51.  * Sign into the MIDI Manager.  Save the midiMgrVerNum.  It signs
  52.  * in with the application's name, and tries to find it's BNDL type.
  53.  * Returns an error code indicating result of initializing and signing
  54.  * into MIDI Manager.
  55.  *
  56.  * NOTE:    Only one instance of a MIDI Manager Client can be made, with
  57.  *            the current design of these objects.  Other methods assume
  58.  *            that the 'gMIDIClient' variable (defined above) points to a
  59.  *            valid CMIDIClient object.
  60.  *------------------------------------------------------------------------
  61.  */
  62. OSErr CMIDIClient::IMIDIClient(short theIconID)
  63. {
  64.     OSErr            err;
  65.     Handle            theIconHndl;        // Used by MIDISignIn
  66.     Str255            theName;            // me too...
  67.     short            i;                    // Junk variables
  68.     Handle            h;
  69.  
  70. // Make sure MIDIMgr is installed and save version number.
  71.  
  72.     midiMgrVerNum   = SndDispVersion(midiToolNum);
  73.  
  74.     if (midiMgrVerNum == 0)                // Damn!  Things were going so well...
  75.     {
  76.         return ErrNoMIDI;                // No MIDI driver seems to be loaded
  77.     }
  78.  
  79. //--- Sign in to the MIDI Manager. -------------------------------
  80.  
  81.     theIconHndl = GetResource('ICN#',theIconID);    // Let's get our icon
  82.     CheckResource(theIconHndl);            // Just checkin'...
  83.     GetAppParms(theName, &i, &h);        // Get the name of this application
  84.  
  85.     err = MIDISignIn(gSignature,         // Use application signature
  86.                         0L,                // Don't need refCon
  87.                         theIconHndl,
  88.                         theName);        // Use theName for this MIDI client
  89.     ReleaseResource(theIconHndl);
  90.     if (err)                            // If unable to sign into MM, treat
  91.         midiMgrVerNum = 0;                // same as if no driver present.
  92.     return err;
  93. }
  94.  
  95. /*
  96.  *--- CMIDIClient::Dispose ----------------------------------------
  97.  * Save connections, sign out of MIDI Manager.
  98.  *-----------------------------------------------------------------
  99.  */
  100. void CMIDIClient::Dispose(void)
  101. {
  102.      if (midiMgrVerNum)                    // If we are signed in to MM
  103.          MIDISignOut(gSignature);
  104.     inherited::Dispose();                // Call CObject method
  105. }                                        // It's Miller Time…
  106.  
  107. /*
  108.  *--- CMIDIClient:: trival methods --------------------------------
  109.  * In a real C++ compiler, these might be implemented as inline
  110.  * functions.
  111.  *-----------------------------------------------------------------
  112.  */
  113. MIDIIDListHdl CMIDIClient::GetPorts(void)
  114. {
  115.     return ((midiMgrVerNum) ? MIDIGetPorts(gSignature) : (MIDIIDListHdl) 0);
  116. }
  117.  
  118. Boolean CMIDIClient::WorldChanged(void)
  119. {
  120.     return ((midiMgrVerNum) ? MIDIWorldChanged(gSignature) : FALSE);
  121. }
  122.  
  123. unsigned long CMIDIClient::GetVerNum(void)
  124. {
  125.     return midiMgrVerNum;
  126. }
  127.  
  128. unsigned short CMIDIClient::GetShortVerNum(void)
  129. {
  130.     register unsigned long version = midiMgrVerNum;
  131.     version >>= 16;
  132.     return (unsigned short) version;
  133. }
  134.  
  135. // end of CMIDIClient.c
  136.