home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / MADH Pascal 4.5 / Example.p < prev    next >
Encoding:
Text File  |  1997-03-18  |  3.3 KB  |  143 lines  |  [TEXT/CWIE]

  1. {
  2. ********************************************************
  3.  
  4.     Player PRO 4.5.2 -- Music Driver EXAMPLE
  5.  
  6.     Library Version 4.5
  7.  
  8.     To use with CodeWarrior
  9.  
  10.     Antoine ROSSET
  11.     16 Tranchees
  12.     1206 GENEVA
  13.     SWITZERLAND
  14.     
  15.     FAX: (+41 22) 346 11 97
  16.     PHONE: (+41 89) 203 74 62
  17.     Email: rosset@dial.eunet.ch
  18.     
  19.     Ported to Pascal by Federico Filipponi (March 1997)
  20.     e-mail:    fedefil@fub.it
  21.                     fedefil@kagi.com
  22.     
  23. ********************************************************
  24. }
  25.  
  26. program Example;
  27.  
  28. uses
  29.     Dialogs, Files, Fonts, GestaltEqu, OSUtils, QuickDraw, Resources, Sound, StandardFile, 
  30.     Strings, ToolUtils, Types, Windows, 
  31.     MAD, RDriver;
  32.     
  33. type
  34.     MADDriverRecHdl = ^MADDriverRecPtr;
  35.     
  36. var
  37.     plugFolderName: Str255;
  38.     fileSpec: FSSPec;
  39.     plugType: MADPlugType;
  40.     where: point;
  41.     reply: SFReply;
  42.     aType: SFTypeList;
  43.     iErr: OSErr;
  44.     done: Boolean;
  45.     init: MADDriverSettings;
  46.     canPlay: Boolean;
  47.  
  48. begin
  49. {
  50. /***************                    ****************/
  51. /******          Toolbox Initialization      **********/
  52. /***************                    ****************/
  53. }
  54.     InitGraf(@qd.thePort);
  55.     InitFonts;
  56.     InitWindows;
  57.     TEInit;
  58.     InitMenus;
  59.     InitCursor;
  60.     MaxApplZone;
  61.     MoreMasters;
  62.     
  63.     FlushEvents(everyEvent, -1);
  64.  
  65. {
  66. /*******************************************************************************************/
  67. /****** MAD Library Initialisation : choose the best driver for the current hardware ******/
  68. /******                                                                                  ******/
  69. /****** Standard initialization with 4 tracks...                                      ******/
  70. /*******************************************************************************************/
  71. }
  72.  
  73.     MADGetBestDriver(@init);
  74.  
  75.     plugFolderName := 'Music';
  76.     iErr := MADInitLibrary(P2CStr(@plugFolderName), init.sysMemory);
  77.     if (iErr <> noErr) then
  78.         DebugStr('can''t initialize MADLibrary!');
  79.         
  80.     iErr := MADCreateDriver(@init);
  81.     if (iErr <> noErr) then
  82.         DebugStr('can''t create MAD Driver!');
  83.  
  84. {
  85. /*********************************/
  86. /*********************************/
  87. /*********************************/
  88. }
  89.  
  90.     Done := FALSE;
  91.     while not Done do
  92.         begin
  93.             FlushEvents(everyEvent, 0);
  94.             aType[0] := 'MADH';
  95.             aType[1] := 'STrk';
  96.             SetPt(where, -1, -1);
  97.             SFGetFile(where, '', nil, 2, @aType, nil, reply);
  98.             
  99.             if not reply.good then
  100.                 Done := true
  101.             else
  102.                 begin
  103.                     canPlay := true;
  104.                     
  105.                     iErr := FSMakeFSSpec(reply.vRefNum, 0, reply.fName, fileSpec);
  106.  
  107.         { Convert the OSType to MADPlugType }
  108.                     OSType2MADPlugType(reply.fType, plugType);
  109.                     
  110.         { Is available a plug to open this file? }
  111.                     canPlay := MADPlugAvailable(@plugType);
  112.                     
  113.                     if canPlay then
  114.                         begin
  115.         { Load this music with help of Plugs in application folder, in 'Plugs' folder 
  116.             or internal resources }
  117.                             iErr := MADLoadMusicFSpFile(@plugType, @fileSpec);
  118.                             canPlay := (iErr = noErr);
  119.                         end;
  120.                     
  121.                     if canPlay then
  122.                         begin
  123.                             iErr := MADStartDriver;     { Turn interrupt driver function ON }
  124.                             iErr := MADPlayMusic;            { Read the current partition in memory }
  125.                             
  126.                             while not Button do
  127.                                 ;
  128.                                 
  129.                             iErr := MADStopMusic;            { Stop reading current partition }
  130.                             iErr := MADStopDriver;        { Stop driver interrupt function }
  131.                             
  132.                             iErr := MADDisposeMusic;    { Dispose the current music }
  133.                         end;
  134.                 end;
  135.         end;
  136.     
  137.     iErr := MADDisposeDriver;                            { Dispose music driver }
  138.     iErr := MADDisposeLibrary;                        { Close music library }
  139.     
  140.     FlushEvents(everyEvent, 0);
  141. end.
  142.     
  143.