home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / Synthesizer Source / Synthesizer Folder / SynthProgressWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  6.9 KB  |  216 lines  |  [TEXT/KAHL]

  1. /* SynthProgressWindow.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Synthesizer:  Digital Music Synthesis on General Purpose Computers     */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "SynthProgressWindow.h"
  31. #include "Memory.h"
  32. #include "Screen.h"
  33. #include "Numbers.h"
  34. #include "DataMunging.h"
  35. #include "EventLoop.h"
  36.  
  37.  
  38. #define WINDOWWIDTH (300)
  39. #define WINDOWHEIGHT (3 + 3 + 4 * GetFontHeight(GetScreenFont(),9))
  40.  
  41.  
  42. struct SynthWinRec
  43.     {
  44.         WinType*                        ScreenID;
  45.         double                            LastTimerValue;
  46.         OrdType                            FontHeight;
  47.         FontType                        ScreenFont;
  48.         long                                CallCountdown;
  49.         long                                CallCountReset;
  50.         MyBoolean                        ShowClippedSamples;
  51.     };
  52.  
  53.  
  54. static void                    WindowUpdateRoutine(SynthWinRec* Window)
  55.     {
  56.         CheckPtrExistence(Window);
  57.     }
  58.  
  59.  
  60. /* create a new synth window record */
  61. SynthWinRec*                NewSynthWindow(long MinCallCount, MyBoolean ShowClippedSamples)
  62.     {
  63.         SynthWinRec*            Window;
  64.  
  65.         Window = (SynthWinRec*)AllocPtrCanFail(sizeof(SynthWinRec),"SynthWinRec");
  66.         if (Window == NIL)
  67.             {
  68.              FailurePoint1:
  69.                 return NIL;
  70.             }
  71.  
  72.         Window->ScreenID = MakeNewWindow(eModelessDialogWindow,eWindowNotClosable,
  73.             eWindowNotZoomable,eWindowNotResizable,DialogLeftEdge(WINDOWWIDTH),
  74.             DialogTopEdge(WINDOWHEIGHT),WINDOWWIDTH,WINDOWHEIGHT,
  75.             (void (*)(void*))&WindowUpdateRoutine,Window);
  76.         if (Window->ScreenID == NIL)
  77.             {
  78.              FailurePoint2:
  79.                 ReleasePtr((char*)Window);
  80.                 goto FailurePoint1;
  81.             }
  82.         SetWindowName(Window->ScreenID,"Progress");
  83.  
  84.         Window->FontHeight = GetFontHeight(GetScreenFont(),9);
  85.         Window->ScreenFont = GetScreenFont();
  86.         Window->LastTimerValue = ReadTimer();
  87.         Window->CallCountdown = 0;
  88.         Window->CallCountReset = MinCallCount;
  89.         Window->ShowClippedSamples = ShowClippedSamples;
  90.  
  91.         PerformDeferredUpdates(); /* update our windows before we start */
  92.         RelinquishCPUCheckCancel(); /* let other programs update too */
  93.  
  94.         return Window;
  95.     }
  96.  
  97.  
  98. /* dispose of a synth window record */
  99. void                                DisposeSynthWindow(SynthWinRec* Window)
  100.     {
  101.         CheckPtrExistence(Window);
  102.         KillWindow(Window->ScreenID);
  103.         ReleasePtr((char*)Window);
  104.     }
  105.  
  106.  
  107. /* update the information in the synth window */
  108. void                                UpdateSynthWindow(SynthWinRec* Window, long SamplingRate,
  109.                                             long TotalSamples, long TotalClippedSamples, MyBoolean ForceRedraw)
  110.     {
  111.         char*                            StringTemp;
  112.         double                        TimerValue;
  113.  
  114.         CheckPtrExistence(Window);
  115.  
  116.         /* delay so we don't call ReadTimer() all the time */
  117.         Window->CallCountdown -= 1;
  118.         if (!ForceRedraw && (Window->CallCountdown >= 0))
  119.             {
  120.                 return;
  121.             }
  122.         Window->CallCountdown = Window->CallCountReset;
  123.  
  124.         /* make sure we were called at least 1 real seconds ago. */
  125.         TimerValue = ReadTimer();
  126.         if (!ForceRedraw && (ReadTimer() - Window->LastTimerValue < 1))
  127.             {
  128.                 return;
  129.             }
  130.         Window->LastTimerValue = TimerValue;
  131.  
  132.         /* we can do this since none of the data is in an inconsistent state (or even */
  133.         /* altered) during playback. */
  134.         PerformDeferredUpdates();
  135.  
  136.         StringTemp = StringToBlockCopy("Elapsed Song Time (Seconds):  ");
  137.         if (StringTemp != NIL)
  138.             {
  139.                 char*                            TimeStr;
  140.  
  141.                 TimeStr = LongDoubleToString((long double)TotalSamples / SamplingRate,5,.01,1e8);
  142.                 if (TimeStr != NIL)
  143.                     {
  144.                         char*                            Combined;
  145.  
  146.                         Combined = ConcatBlockCopy(StringTemp,TimeStr);
  147.                         if (Combined != NIL)
  148.                             {
  149.                                 DrawTextLine(Window->ScreenID,Window->ScreenFont,9,Combined,
  150.                                     PtrSize(Combined),3,3,ePlain);
  151.                                 DrawBoxErase(Window->ScreenID,3 + LengthOfText(Window->ScreenFont,9,
  152.                                     Combined,PtrSize(Combined),ePlain),3,WINDOWWIDTH,Window->FontHeight);
  153.                                 ReleasePtr(Combined);
  154.                             }
  155.                         ReleasePtr(TimeStr);
  156.                     }
  157.                 ReleasePtr(StringTemp);
  158.             }
  159.  
  160.         StringTemp = StringToBlockCopy("Total Generated Frames:  ");
  161.         if (StringTemp != NIL)
  162.             {
  163.                 char*                            SamplesStr;
  164.  
  165.                 SamplesStr = IntegerToString(TotalSamples);
  166.                 if (SamplesStr != NIL)
  167.                     {
  168.                         char*                            Combined;
  169.  
  170.                         Combined = ConcatBlockCopy(StringTemp,SamplesStr);
  171.                         if (Combined != NIL)
  172.                             {
  173.                                 DrawTextLine(Window->ScreenID,Window->ScreenFont,9,Combined,
  174.                                     PtrSize(Combined),3,3 + Window->FontHeight,ePlain);
  175.                                 DrawBoxErase(Window->ScreenID,3 + LengthOfText(Window->ScreenFont,9,
  176.                                     Combined,PtrSize(Combined),ePlain),3 + Window->FontHeight,
  177.                                     WINDOWWIDTH,Window->FontHeight);
  178.                                 ReleasePtr(Combined);
  179.                             }
  180.                         ReleasePtr(SamplesStr);
  181.                     }
  182.                 ReleasePtr(StringTemp);
  183.             }
  184.  
  185.         if (Window->ShowClippedSamples)
  186.             {
  187.                 StringTemp = StringToBlockCopy("Total Clipped Sample Points:  ");
  188.                 if (StringTemp != NIL)
  189.                     {
  190.                         char*                            SamplesStr;
  191.  
  192.                         SamplesStr = IntegerToString(TotalClippedSamples);
  193.                         if (SamplesStr != NIL)
  194.                             {
  195.                                 char*                            Combined;
  196.  
  197.                                 Combined = ConcatBlockCopy(StringTemp,SamplesStr);
  198.                                 if (Combined != NIL)
  199.                                     {
  200.                                         DrawTextLine(Window->ScreenID,Window->ScreenFont,9,Combined,
  201.                                             PtrSize(Combined),3,3 + 2 * Window->FontHeight,ePlain);
  202.                                         DrawBoxErase(Window->ScreenID,3 + LengthOfText(Window->ScreenFont,9,
  203.                                             Combined,PtrSize(Combined),ePlain),3 + 2 * Window->FontHeight,
  204.                                             WINDOWWIDTH,Window->FontHeight);
  205.                                         ReleasePtr(Combined);
  206.                                     }
  207.                                 ReleasePtr(SamplesStr);
  208.                             }
  209.                         ReleasePtr(StringTemp);
  210.                     }
  211.             }
  212.  
  213.         DrawTextLine(Window->ScreenID,Window->ScreenFont,9,"Press Escape To Abort",
  214.             21,3,3 + 3 * Window->FontHeight,eBold);
  215.     }
  216.