home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / cdedit / rmtcntrl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  14.6 KB  |  575 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/cdEdit/RCS/remoteControl.c,v 2.0 91/10/06 21:01:55 chua Exp $ */
  25. /* $Log:    remoteControl.c,v $
  26.  * Revision 2.0  91/10/06  21:01:55  chua
  27.  * Update to version 2.0
  28.  * 
  29.  * Revision 1.35  91/09/10  13:35:38  chua
  30.  * In eject, if file is untitled and modified, set the edit times to the
  31.  * disc times.
  32.  * 
  33.  * Revision 1.34  91/09/05  18:19:00  chua
  34.  * In Pause, set to pause mode only if the player is currently in play mode.
  35.  * 
  36.  * Revision 1.33  91/09/05  17:56:08  chua
  37.  * In Play, if the player is already in play mode, do not do anything.
  38.  * 
  39.  * Revision 1.32  91/09/04  11:38:24  chua
  40.  * In Eject, remove the status variable (not used).
  41.  * 
  42.  * Revision 1.31  91/09/03  15:26:00  chua
  43.  * Added the copyright header.
  44.  * 
  45.  * The Options popup window has been removed, so the functions for opening and closing it
  46.  * (Options, Done) are also deleted.
  47.  * 
  48.  * In Eject, do not wait till a new disc has been ejected.  Simply eject the disc and dim
  49.  * the buttons.
  50.  * 
  51.  * A new function, InfoHandler, takes the place of the previous Info (notify procedure for
  52.  * the Info button, which has been deleted).  This InfoHandler function will popup the
  53.  * info popup window.
  54.  * 
  55.  * Revision 1.3  91/07/10  11:33:41  chua
  56.  * In the Quit procedure, just call xv_destroy_safe (window).  This will
  57.  * cause the QuitNotify interpose procedure to be called, which will handle
  58.  * the other graceful quitting procedure (like checking if there are unsaved
  59.  * changes etc).
  60.  * 
  61.  * Revision 1.2  91/07/10  11:04:21  chua
  62.  * Removed a debugging printf statement.
  63.  * 
  64.  * Revision 1.1  91/07/09  16:48:09  chua
  65.  * In the quit procedure, set the quit variable to 1 if quit is to be done, indicating that
  66.  * there is no need to call quit anymore after xv_main_loop exits.
  67.  * 
  68.  * Revision 1.0  91/07/08  13:46:35  chua
  69.  * Initial revision
  70.  *  */
  71.  
  72. static char remoteControlrcsid[] = "$Header: /Source/Media/collab/cdEdit/RCS/remoteControl.c,v 2.0 91/10/06 21:01:55 chua Exp $";
  73.  
  74. #include "main.h"
  75.  
  76. int numTracks;                                /* number of tracks in disc */
  77. int startTrack;
  78. int endTrack;
  79. int displayType;                            /* display time as absolute or relative */
  80. static int clearframe = 0;
  81. static int search = 0;
  82.  
  83. /*
  84.  * Notify callback function for `OpenEditPopupButton'.
  85.  * Opens the edit popup window.
  86.  */
  87. void Edit(item, event)
  88.      Panel_item    item;
  89.      Event        *event;
  90. {
  91.   xv_set(cdEdit_EditPopup->EditPopup, FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  92.   xv_set(cdEdit_EditPopup->EditPopup, XV_SHOW, TRUE, NULL);
  93. }
  94.  
  95. /*
  96.  * Notify callback function for `QuitButton'.
  97.  * Quit the application.  The CD is also ejected.
  98.  */
  99. void Quit(item, event)
  100.      Panel_item    item;
  101.      Event        *event;
  102. {
  103.   xv_destroy_safe(cdEdit_window1->window1);
  104. }
  105.  
  106. /* 
  107.  * This function will accept number input on the numeric pad using the mouse.  the current value on the search textfield is shifted to
  108.  * the left as input is made (if 2 digits are exceeded) 
  109.  */
  110. void Num(n)
  111.      int n;
  112. {
  113.   int value;
  114.   
  115.   if (clearframe == 1) 
  116.   {
  117.     xv_set(cdEdit_window1->SearchTrackText, PANEL_VALUE, 0,
  118.        NULL);
  119.   }
  120.   clearframe = 0;
  121.   value = xv_get(cdEdit_window1->SearchTrackText, PANEL_VALUE);
  122.   value = value*10 + n;
  123.   if (value > 99) value = value % 100;                    /* Remove most significant digit */
  124.   xv_set (cdEdit_window1->SearchTrackText, PANEL_VALUE, value, NULL);
  125. }
  126.  
  127. /*
  128.  * Notify callback function for `SearchButton'.
  129.  * This function will cause the CD player to search to the track specified in the search track textfield.
  130.  */
  131. void Search(item, event)
  132.      Panel_item    item;
  133.      Event        *event;
  134. {
  135.   int searchNum;
  136.   
  137.   searchNum = xv_get(cdEdit_window1->SearchTrackText, PANEL_VALUE); /* Get the track to seek to */
  138.   clearframe = 1;
  139.   if (searchNum > endTrack || searchNum < 1)                /* Check if the search track is valid */
  140.   {
  141.     AlertMessage("Illegal track number.", NULL);
  142.     return;
  143.   }
  144.   playerState = PlayMode;
  145.   cdrom_play_track(fd, searchNum, endTrack);
  146. }
  147.  
  148. /*
  149.  * Notify callback function for `SearchTrackText'.
  150.  * If the return key is hit in the search track textfield, call the Search procedure above.  A flag is necessary to keep track of when Search is called 
  151.  * because when the return key is hit, this function is called twice, but we only want to do the search once.
  152.  */
  153. Panel_setting SearchKbd(item, event)
  154.      Panel_item    item;
  155.      Event        *event;
  156. {
  157.   if (event_action(event) == '\r')                    /* Return key is pressed, go to search mode */
  158.   {
  159.     if (search == 0) 
  160.     {
  161.       Search(item, event);
  162.       search = 1;
  163.     }
  164.     else 
  165.     {
  166.       search = 0;
  167.     }
  168.     return PANEL_NONE;
  169.   }
  170.   return PANEL_INSERT;
  171. }
  172.  
  173. /*
  174.  * Notify callback function for `DurationSlider'.
  175.  * This function will calculate the offset into the CD to start play from, depending on where the user released the duration slider, and
  176.  * whether the application was in absolute or relative mode.  It will then seek to that offset and start play from there.
  177.  */
  178. int Duration(item, value, event)
  179.      Panel_item      item;
  180.      int             value;
  181.      Event           *event;
  182. {
  183.   int track, min, sec;
  184.   struct cdrom_msf msf;
  185.   Msf relative, result;
  186.   char s[5];
  187.   
  188.   if (playerState != StopMode)                        /* Only do the seek if the CD is already playing */
  189.   {
  190.     playerState = DurationMode;                        /* So that the timer notify procedure will not set the slider to the current play time */
  191.     sec = value;                            /* Concert the value on the slider to minutes and seconds */
  192.     min = 0;
  193.     while (sec >= 60) 
  194.     {
  195.       sec -= 60;
  196.       min ++;
  197.     }
  198.     sprintf(s, "%02d:%02d", min, sec);
  199.     xv_set(cdEdit_window1->TempDurationMsg,                /* Update the time display on top of the duration slider */
  200.        PANEL_LABEL_STRING, s,
  201.        NULL);
  202.     if (event_is_up(event))                        /* If mouse button is released, start play from the time at the release point */
  203.     {
  204.       if (displayType == Relative)                    /* Check if it is relative or absolute mode */
  205.       {
  206.     track = GetCurrentTrack();                    /* If it is in relative mode, convert the time to absolute time first */
  207.     relative = (Msf) malloc(sizeof(struct msf));
  208.     relative->min = min;
  209.     relative->sec = sec;
  210.     relative->frame = 1;
  211.     result = (Msf) ConvertRelativeToAbsolute(track, relative);
  212.     free (relative);
  213.     msf.cdmsf_min0 = result->min;
  214.     msf.cdmsf_sec0 = result->sec;
  215.     msf.cdmsf_frame0 = result->frame;
  216.       }
  217.       else 
  218.       {
  219.     msf.cdmsf_min0 = min;
  220.     msf.cdmsf_sec0 = sec;
  221.     msf.cdmsf_frame0 = 1;
  222.       }
  223.       msf.cdmsf_min1 = toc->total_msf->min;                /* Play till end of disc */
  224.       msf.cdmsf_sec1 = toc->total_msf->sec; 
  225.       msf.cdmsf_frame1 = toc->total_msf->frame;
  226.       playerState = PlayMode;
  227.       while (cdrom_play_msf(fd, msf) == 0) 
  228.       {
  229.     if (msf.cdmsf_frame1 == 0)                    /* If play doesn't work, reduce the maximum frame number by one until it does. */
  230.     {                                /* This number to be reduced varies from disc to disc.  The reason is because */
  231.       if (msf.cdmsf_sec1 == 0)                    /* the value given by toc->total_msf->frame is not always accurate. */
  232.       {
  233.         msf.cdmsf_sec1 = 59;
  234.         msf.cdmsf_min1--;
  235.       }
  236.       else 
  237.       {
  238.         msf.cdmsf_sec1--;
  239.         msf.cdmsf_frame1 = 74;
  240.       }
  241.     }
  242.     else 
  243.     {
  244.       msf.cdmsf_frame1 --;
  245.     }
  246.       }
  247.     }
  248.   }
  249. }
  250.  
  251. /*
  252.  * Notify callback function for `OneButton'.
  253.  */
  254. void One(item, event)
  255.      Panel_item    item;
  256.      Event        *event;
  257. {
  258.   Num(1);
  259. }
  260.  
  261. /*
  262.  * Notify callback function for `TwoButton'.
  263.  */
  264. void Two(item, event)
  265.      Panel_item    item;
  266.      Event        *event;
  267. {
  268.   Num(2);
  269. }
  270.  
  271. /*
  272.  * Notify callback function for `ThreeButton'.
  273.  */
  274. void Three(item, event)
  275.      Panel_item    item;
  276.      Event        *event;
  277. {
  278.   Num(3);
  279. }
  280.  
  281. /*
  282.  * Notify callback function for `FourButton'.
  283.  */
  284. void Four(item, event)
  285.      Panel_item    item;
  286.      Event        *event;
  287. {
  288.   Num(4);
  289. }
  290.  
  291. /*
  292.  * Notify callback function for `FiveButton'.
  293.  */
  294. void Five(item, event)
  295.      Panel_item    item;
  296.      Event        *event;
  297. {
  298.   Num(5);
  299. }
  300.  
  301. /*
  302.  * Notify callback function for `SixButton'.
  303.  */
  304. void Six(item, event)
  305.      Panel_item    item;
  306.      Event        *event;
  307. {
  308.   Num(6);
  309. }
  310.  
  311. /*
  312.  * Notify callback function for `SevenButton'.
  313.  */
  314. void Seven(item, event)
  315.      Panel_item    item;
  316.      Event        *event;
  317. {
  318.   Num(7);
  319. }
  320.  
  321. /*
  322.  * Notify callback function for `EightButton'.
  323.  */
  324. void Eight(item, event)
  325.      Panel_item    item;
  326.      Event        *event;
  327. {
  328.   Num(8);
  329. }
  330.  
  331. /*
  332.  * Notify callback function for `NineButton'.
  333.  */
  334. void Nine(item, event)
  335.      Panel_item    item;
  336.      Event        *event;
  337. {
  338.   Num(9);
  339. }
  340.  
  341. /*
  342.  * Notify callback function for `ZeroButton'.
  343.  */
  344. void Zero(item, event)
  345.      Panel_item    item;
  346.      Event        *event;
  347. {
  348.   Num(0);
  349. }
  350.  
  351. /*
  352.  * Notify callback function for `PlayButton'.
  353.  * Puts the CD player in play mode.  If the CD player was originally in stop or play mode, start play from track 1. 
  354.  * If the CD player was in pause mode, resume play from the point where the pause was made.
  355.  */
  356. void Play(item, event)
  357.      Panel_item    item;
  358.      Event        *event;
  359. {
  360.   if (playerState == PlayMode)                        /* Do not do anything if the player is already in play mode */
  361.     return;
  362.   if (playerState == PauseMode) 
  363.   {
  364.     cdrom_resume(fd);
  365.   }
  366.   else 
  367.   {
  368.     cdrom_play_track(fd, startTrack, endTrack);
  369.   }
  370.   playerState = PlayMode;
  371. }
  372.  
  373. /*
  374.  * Notify callback function for `ReverseSkipButton'.
  375.  * Skips to the previous track.  If it is at track 1, just play track 1 again.
  376.  * If the player was in stop mode, play track 1.
  377.  */
  378. void ReverseSkip(item, event)
  379.      Panel_item    item;
  380.      Event        *event;
  381. {
  382.   int currentTrack;
  383.   
  384.   currentTrack = GetCurrentTrack() - 1;                   
  385.   playerState = PlayMode;
  386.   if (currentTrack <= 0) 
  387.   {
  388.     currentTrack = 1;
  389.   }
  390.   cdrom_play_track(fd, currentTrack, endTrack);
  391. }
  392.  
  393. /*
  394.  * Notify callback function for `PauseButton'.
  395.  * Set the CD player in pause mode.
  396.  */
  397. void Pause(item, event)
  398.      Panel_item    item;
  399.      Event        *event;
  400. {
  401.   if (playerState == PauseMode) 
  402.   {
  403.     cdrom_resume(fd);
  404.     playerState = PlayMode;
  405.   }
  406.   else if (playerState == PlayMode)
  407.   {
  408.     playerState = PauseMode;
  409.     cdrom_pause(fd);
  410.   }
  411. }
  412.  
  413. /*
  414.  * Notify callback function for `ForwardSkipButton'.
  415.  * Skips to the next track.  If it is at the last track, play the last track again..
  416.  * If the player was in stop mode, play track 1.
  417.  */
  418. void ForwardSkip(item, event)
  419.      Panel_item    item;
  420.      Event        *event;
  421. {
  422.   int currentTrack;
  423.   
  424.   currentTrack = GetCurrentTrack() + 1;
  425.   playerState = PlayMode;
  426.   if (currentTrack == (endTrack + 1)) 
  427.   {
  428.     currentTrack = endTrack;
  429.   }
  430.   cdrom_play_track(fd, currentTrack, endTrack);
  431. }
  432.  
  433. /*
  434.  * Notify callback function for `StopButton'.
  435.  * Put the CD player in stop mode, and update the time display to show the entire time for the whole CD.
  436.  */
  437. void Stop(item, event)
  438.      Panel_item    item;
  439.      Event        *event;
  440. {
  441.   playerState = StopMode;
  442.   cdrom_stop(fd);
  443. }
  444.  
  445. /*
  446.  * Notify callback function for `EjectButton'.
  447.  * Ejects the CD.  As playerState is set to Nothing, the time display will automatically be updated to all zeros when the timer notify procedure
  448.  * is next called.
  449.  * If filename is 'untitled' and there are unsaved changes, update the edit times to be the same as the disc times, so that the times of this disc will
  450.  * be saved should the user save the untitled file.
  451.  */
  452. void Eject(item, event)
  453.      Panel_item      item;
  454.      Event           *event;
  455. {
  456.   playerState = Nothing;
  457.   cdrom_stop(fd);                            /* Stop the CD, then eject it */
  458.   cdrom_eject(fd);
  459.   destroy_toc(toc);                            /* Clear the table of contents */
  460.   discInPlayer = 0;
  461.   DimButtons(TRUE);
  462.   xv_set(cdEdit_window1->window1, 
  463.      FRAME_RIGHT_FOOTER, "No disc in player",
  464.      NULL);
  465.   if (CheckforUntitled(cdfilename) == OK && change == 1 &&        /* If no file loaded, update the edit times with the disc times */
  466.       editTotalTracks == 0)
  467.   {
  468.     editmin = toc->total_msf->min;
  469.     editsec = toc->total_msf->sec;
  470.     editTotalTracks = toc->size;
  471.   }
  472. }
  473.  
  474. /*
  475.  * Sets the volume level according to the current values in the volume and balance sliders.
  476.  */
  477. void SetVolume(volume, balance)
  478.      int volume, balance;
  479. {
  480.   int left, right;
  481.   
  482.   if (balance == -15)                            /* Balance on extreme left */
  483.   {
  484.     right = 0;
  485.   }
  486.   else 
  487.   {
  488.     right = volume + balance;
  489.     if (right > 250) 
  490.     {
  491.       right = 250;
  492.     }
  493.   }
  494.   if (balance == 15)                            /* balance on extreme right */
  495.   {
  496.     left = 0;
  497.   }
  498.   else 
  499.   {
  500.     left = volume - balance;
  501.     if (left > 250) 
  502.     {
  503.       left = 250;
  504.     }
  505.   }
  506.   cdrom_volume (fd, left, right);
  507. }
  508.  
  509. /*
  510.  * Notify callback function for `VolumeSlider'.
  511.  * Call SetVolume to set the appropriate volume with respect to the volume and balance sliders.
  512.  */
  513. int Volume(item, value, event)
  514.      Panel_item      item;
  515.      int             value;
  516.      Event           *event;
  517. {
  518.   int balance;
  519.   
  520.   balance = xv_get (cdEdit_window1->BalanceSlider, PANEL_VALUE);
  521.   SetVolume(value, balance);
  522. }
  523.  
  524. /*
  525.  * Notify callback function for `BalanceSlider'.
  526.  * Call SetVolume to set the appropriate volume with respect to the volume and balance sliders.
  527.  */
  528. int Balance(item, value, event)
  529.      Panel_item      item;
  530.      int             value;
  531.      Event           *event;
  532. {
  533.   int volume;
  534.   
  535.   volume = xv_get (cdEdit_window1->VolumeSlider, PANEL_VALUE);
  536.   SetVolume(volume, value);
  537.   return 0;
  538. }
  539.  
  540. /*
  541.  * Menu handler for `OptionsMenu (About cdEdit ...)'.
  542.  */
  543. Menu_item InfoHandler(item, op)
  544.      Menu_item    item;
  545.      Menu_generate    op;
  546. {
  547.   switch (op) 
  548.   {
  549.    case MENU_DISPLAY:
  550.     break;
  551.    case MENU_DISPLAY_DONE:
  552.     break;
  553.    case MENU_NOTIFY:
  554.     xv_set(cdEdit_InfoPopup->InfoPopup, FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  555.     xv_set(cdEdit_InfoPopup->InfoPopup, XV_SHOW, TRUE, NULL);
  556.     
  557.     break;
  558.    case MENU_NOTIFY_DONE:
  559.     break;
  560.   }
  561.   return item;
  562. }
  563.  
  564. /*
  565.  * Notify callback function for `CloseInfoPopupButton'.
  566.  * Closes the Info popup window.
  567.  */
  568. void InfoDone(item, event)
  569.      Panel_item    item;
  570.      Event        *event;
  571. {
  572.   xv_set(cdEdit_InfoPopup->InfoPopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  573.   xv_set(cdEdit_InfoPopup->InfoPopup, XV_SHOW, FALSE, NULL);
  574. }
  575.