home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15041 < prev    next >
Encoding:
Text File  |  1992-09-08  |  5.0 KB  |  157 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!gatech!willis.cis.uab.edu!utkcs2!utkux1.utk.edu!danny@utkux1.utk.edu
  3. From: danny@utkux1.utk.edu (Danny W. McCampbell)
  4. Subject: Re: Sound Loop in a with a Modal Dialog?
  5. Message-ID: <1992Sep4.123910.4415@utkux1.utk.edu>
  6. Sender: usenet@utkux1.utk.edu (USENET News System)
  7. Organization: University of Tennessee
  8. References: <1992Sep3.145524.8874@utkux1.utk.edu> <1992Sep3.171925.11716@terminator.cc.umich.edu>
  9. Date: Fri, 4 Sep 1992 12:39:10 GMT
  10. Lines: 145
  11.  
  12. In article <1992Sep3.171925.11716@terminator.cc.umich.edu>, potts@itl.itd.umich.edu (Paul Potts) writes:
  13. > In article <1992Sep3.145524.8874@utkux1.utk.edu> danny@utkux1.utk.edu (Danny W. McCampbell) writes:
  14. > >Hi.  I want to play a sound continuously while a modal dialog is 
  15. > >present on the screen.  I have successfully go the loop to work
  16. > >without the modal dialog statement but the loop is only executed
  17. > >twice when I call modal dialog.  Here is  some sample code:
  18. > >
  19. > >dialogtrue := true;
  20. > >while dialogtrue do
  21. > >begin
  22. > >  FlushSndChannel(mySndChan);
  23. > >  if SoundisStopped(mySndChan) then
  24. > >  begin
  25. > >    PlaytheSound(mySndChan);
  26. > >  end;
  27. > >  ModalDialog(nil, itemHit);            {Call Modal Dialog until the user clicks in the dialog}
  28. > >  if itemHit = 1 then
  29. > >    dialogtrue := false;
  30. > >end;
  31. > >StoptheSound(mySndChan);
  32. > >DisposDialog(AboutDialog);                {Dispose of the Dialog}
  33. > >
  34. > >The sound plays only twice then stops playing.  Any ideas how I can
  35. > >do this successfully?  Thanks in advance.
  36. > This seems somewhat convoluted. Can you post the actual code that you use
  37. > to play the sound, and what your dialog should do? It makes a difference.
  38. > Keep in mind also that your sound will restart after each click on a button
  39. > in the dialog, but while the dialog is on the screen, the sound could 
  40. > stop playing and you would then be left sitting there waiting for something
  41. > to happen (for one of the buttons in the dialog to get activated)
  42. > for it to start up again.
  43. > For a dialog in which any of the buttons numbered other than zero
  44. > should dismiss the dialog, I would do something like:
  45. > - start playing sound
  46. > - itemHit =0;
  47. > - while (!itemHit)
  48. >        ModalDialog (nil, &itemHit);
  49. > - Turn off sound
  50. > The technique for playing the sound might influence how you do this; for
  51. > example, are you playing a long sample that might end while the user is
  52. > deciding what to do with the dialog? If so, you could set it to loop. Are
  53. > you dynamically playing notes such that you need to stuff freqDurationCmds
  54. > into the sound queue? If so, you might want to do this from a filter
  55. > procedure to your dialog. It could look at the sound queue during null
  56. > events and if it is nearly empty, stuff some more notes into it.
  57. > You might consider stuffing a copy of the pointer to the sound channel in
  58. > the dialog, so that your filter procedure could look at it when it runs
  59. > without having to access a global. There are various ways to do this kind
  60. > of thing if you are interested.
  61. >  
  62. > >
  63. What I am doing is simply getting a handle to the sound Channel and playing
  64. the sound.  I check to see if the sound has completed in the loop and if it
  65. has I play it again.  The sound is short and I want it to loop as long as the
  66. dialog is displayed.  The dialog only has one button which dismisses it.  Here
  67. is the sound code.
  68.  
  69.  
  70. procedure PlaytheSound (mySndChan: SndChannelPtr);
  71.   const
  72.    kAsync = true;
  73.    soundID = 128;
  74.   var
  75.    err: OSErr;
  76.    mySndHandle: Handle;
  77.  begin
  78.   mySndHandle := GetResource('snd ', soundID);
  79.   if mySndHandle <> nil then
  80.    begin
  81.     err := SndPlay(mySndChan, mySndHandle, kAsync);
  82.     if err <> noErr then
  83.      ExitToShell;
  84.    end;
  85.  end;
  86.  
  87.  function GetmySndChannel: SndChannelPtr;
  88.   var
  89.    err: OSErr;
  90.    mySndChan: SndChannelPtr;
  91.    myCallBackProcedure: ProcPtr;
  92.  begin
  93.   myCallBackProcedure := nil;
  94.   mySndChan := nil;
  95.   err := SndNewChannel(mySndChan, 5, initStereo, myCallBackProcedure);
  96.   if err <> noErr then
  97.    ExitToShell;
  98.   GetmySndChannel := mySndChan;
  99.  end;
  100.  
  101.  procedure StoptheSound (mySndChan: SndChannelPtr);
  102.   var
  103.    err: OSErr;
  104.  begin
  105.   err := SndDisposeChannel(mySndChan, true);
  106.   if err <> noErr then
  107.    ExitToShell;
  108.  end;
  109.  
  110.  function SoundisStopped (chan: SndChannelPtr): boolean;
  111.   var
  112.    myErr: OSErr;
  113.    mySCStatus: SCStatus;
  114.  begin
  115.   SoundisStopped := false;
  116.   myErr := SndChannelStatus(chan, Sizeof(SCStatus), @mySCStatus);
  117.   if myErr = noErr then
  118.    SoundisStopped := mySCStatus.scChannelBusy;
  119.  end;
  120.  
  121.  procedure FlushSndChannel (chan: SndChannelPtr);
  122.   var
  123.    myErr: OSErr;
  124.    mySndCmd: SndCommand;
  125.  begin
  126.   mySndCmd.cmd := flushCmd;
  127.   mySndCmd.param1 := 0;
  128.   mySndCmd.param2 := 0;
  129.   myErr := SndDoImmediate(chan, mySndCmd);
  130.  end;
  131.  
  132. dialogtrue := true;
  133. while dialogtrue do
  134. begin
  135.   FlushSndChannel(mySndChan);
  136.   if SoundisStopped(mySndChan) then
  137.   begin
  138.     PlaytheSound(mySndChan);
  139.   end;
  140.   ModalDialog(nil, itemHit);            {Call Modal Dialog until the user clicks in the dialog}
  141.   if itemHit = 1 then
  142.     dialogtrue := false;
  143. end;
  144. StoptheSound(mySndChan);
  145. DisposDialog(AboutDialog);                {Dispose of the Dialog}
  146.  
  147. thanks
  148.  
  149. Danny
  150.