home *** CD-ROM | disk | FTP | other *** search
/ Computer Music Interactif…cial Edition 1999 Winter / cd 3.iso / mac / Mac / Shares / Midishare™1.68 / Development Tools / Sources Examples / Other MidiShare Examples / SendNote / SendNote.c next >
Encoding:
C/C++ Source or Header  |  1992-05-16  |  1.6 KB  |  68 lines  |  [TEXT/MPS ]

  1. /*====================== A MIDI SHARE TOOL  (© GRAME 92) =====================
  2.  
  3. NAME
  4.       SendNote -- a very simple MidiShare MPW tool
  5.  
  6. SYNOPSIS
  7.       SendNote [-pitch <k>] [-vel <v>] [-dur <d>] [-port <p>] [-chan <c>]
  8.  
  9. DESCRIPTION
  10.     "SendNote" open a MidiShare session, create and send a single note, and 
  11.     then close the MidiShare session
  12.  
  13. ===============================================================================*/
  14.  
  15.  
  16. #include <String.h>
  17. #include <StdLib.h>
  18. #include <Stdio.h>
  19. #include <MidiShare.h>
  20.  
  21.  
  22. #define nil     0
  23. #define true    1
  24. #define false    0
  25.  
  26.  
  27. //_______________________________________________________________________
  28. long lopt (char *argv[], char *name, long def)
  29. {
  30.     int    i;
  31.     for (i=0; argv[i]; i++) if (!strcmp(argv[i], name)) return atoi(argv[i+1]);
  32.     return def;
  33. }
  34.  
  35.  
  36. //_______________________________________________________________________
  37.  
  38. void wait(long d)
  39. {    d += MidiGetTime();
  40.     while (MidiGetTime() < d);
  41. }
  42.  
  43.  
  44. //_______________________________________________________________________
  45.  
  46. main( int /*argc*/, char *argv[])
  47. {
  48.     short         ref;
  49.     MidiEvPtr     e;
  50.     
  51.     ref = MidiOpen("\pSendNote");                // open a MidiShare session
  52.     MidiConnect(ref, 0, true);                    // connect to physical Midi outputs
  53.     
  54.     if (e = MidiNewEv(typeNote)) {                // allocate a note event
  55.     
  56.         Pitch(e) = lopt(argv, "-pitch", 60);    // fill its fields
  57.         Vel(e) = lopt(argv, "-vel", 80);
  58.         Dur(e) = lopt(argv, "-dur", 250);
  59.         Chan(e) = lopt(argv, "-chan", 0);
  60.         Port(e) = lopt(argv, "-port", 0);
  61.         
  62.         MidiSendIm(ref, e);                        // send it now
  63.         wait(lopt(argv, "-dur", 250));            // wait the duration of the note
  64.     }
  65.     MidiClose (ref);                            // close the MidiShare session
  66. }
  67.  
  68.