home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / cdedit / edit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  11.1 KB  |  346 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/edit.c,v 2.0 91/10/06 21:01:18 chua Exp $ */
  25. /* $Log:    edit.c,v $
  26.  * Revision 2.0  91/10/06  21:01:18  chua
  27.  * Update to version 2.0
  28.  * 
  29.  * Revision 1.22  91/09/24  16:29:23  chua
  30.  * The duration array stores time in milliseconds instead of seconds.  So in line
  31.  * 122, do the appropriate division to obtain seconds for the duration display.
  32.  * 
  33.  * Revision 1.21  91/09/03  14:57:09  chua
  34.  * Added the copyright header.
  35.  * Added new arrays to store the volume, balance and duration for each edit.
  36.  * 
  37.  * Added a notify procedure for the label textfield, so that hitting return on it has
  38.  * the same effect as hitting the add button.
  39.  * 
  40.  * Changed the name of the edit list from EditPopupList to EditList.
  41.  * 
  42.  * In the edit notify functions (add, delete, modify, delete), make a call to UpdateHeader
  43.  * to indicate that the file has been modified.
  44.  * 
  45.  * Revision 1.2  91/07/11  18:30:38  chua
  46.  * In the panel list notify procedure, if an item is deselected, set 
  47.  * editnum to -1.  
  48.  * 
  49.  * Revision 1.1  91/07/09  16:46:48  chua
  50.  * 
  51.  * 
  52.  * Revision 1.0  91/07/08  13:45:47  chua
  53.  * Initial revision
  54.  *  */
  55.  
  56. static char editrcsid[] = "$Header: /Source/Media/collab/cdEdit/RCS/edit.c,v 2.0 91/10/06 21:01:18 chua Exp $";
  57.  
  58. #include "main.h"
  59.  
  60. Xv_font* font;                                /* Font used in the panel list */
  61. int starttrack[MaxListSize];                        /* variables to store the edit list information */
  62. int startmin[MaxListSize];
  63. int startsec[MaxListSize];
  64. int startframe[MaxListSize];
  65. int endtrack[MaxListSize];
  66. int endmin[MaxListSize];
  67. int endsec[MaxListSize];
  68. int endframe[MaxListSize];
  69. int volume[MaxListSize];
  70. int balance[MaxListSize];
  71. int duration[MaxListSize];
  72. char label[MaxListSize][MaxLabelLength];                /* array to store the label of each entry in the edit list */
  73.                                        
  74. /*
  75.  * Formats an edit entry for the panel list.
  76.  * current indicates which entry is to be formatted.
  77.  * buf will contain the formatted entry.
  78.  */
  79. void PrintOnList(current, buf)
  80.      int current;
  81.      char buf[70];
  82. {
  83.   sprintf (buf, " %5d.  %-29.27s%02d:%02d:%02d:%02d  %02d:%02d:%02d:%02d", current+1,
  84.        label[current], starttrack[current], startmin[current],
  85.        startsec[current], startframe[current], 
  86.        endtrack[current], endmin[current], 
  87.        endsec[current], endframe[current]); 
  88. }
  89.  
  90. /*
  91.  * Print the number of edit entries on the list.
  92.  */
  93. void PrintNumEdit()
  94. {
  95.   char edit[20];
  96.   
  97.   sprintf(edit, "No. of Edits : %d", lines);
  98.   xv_set(cdEdit_EditPopup->EditListNumEditsMsg, PANEL_LABEL_STRING,
  99.      edit, NULL);
  100. }
  101.  
  102. /*
  103.  * Notify callback function for `EditPopupList'.
  104.  * On a Deselect operation, this function will update the WhichEdit message to indicate "New Edit". It will also make the modify and delete buttons inactive.
  105.  * On a Select operation,  it will load in the chosen selection onto the current selection textfields.
  106.  */
  107. int List(item, string, client_data, op, event)
  108.      Panel_item    item;
  109.      char        *string;
  110.      Xv_opaque    client_data;
  111.      Panel_list_op    op;
  112.      Event        *event;
  113. {
  114.   int selection;
  115.   char buf[80];
  116.   
  117.   switch(op) {
  118.    case PANEL_LIST_OP_DESELECT:
  119.     xv_set(cdEdit_EditPopup->CurrentSelectionMsg, PANEL_LABEL_STRING, "Current Selection : None",
  120.        NULL);
  121.     editnum = -1;
  122.     xv_set(cdEdit_EditPopup->ModifyButton, PANEL_INACTIVE, TRUE, NULL);    /* Make the modify and delete buttons inactive */
  123.     xv_set(cdEdit_EditPopup->DeleteButton, PANEL_INACTIVE, TRUE, NULL);
  124.     break;
  125.    case PANEL_LIST_OP_SELECT:
  126.     sscanf(string, "%d", &selection);
  127.     editnum = selection - 1;
  128.     LoadStartEnd();                            /* Load the current selection onto the current selection textfields */
  129.     sprintf(buf, "%d", (duration[editnum] + 500) / 1000);
  130.     xv_set(cdEdit_EditPopup->EditPopupDurationText, PANEL_VALUE, buf, NULL); /* Display the duration in the duration textfield */
  131.     break;
  132.   }
  133.   return XV_OK;
  134. }
  135.  
  136. /*
  137.  * Notify callback function for `EditPopupLabelText'.
  138.  * Calls the EditAdd function to add a new edit on the edit list.
  139.  */
  140. Panel_setting LabelText(item, event)
  141.      Panel_item    item;
  142.      Event        *event;
  143. {
  144.   if (discInPlayer == 1)                        /* Add only if there is a disc in the player, since editing functions are */
  145.   {                                    /* disabled when there is no disc */
  146.     EditAdd(item, NULL);
  147.   }
  148.   return panel_text_notify(item, event);
  149. }
  150.  
  151. /*
  152.  * Notify callback function for `AddButton'.
  153.  * Adds the current selection to the edit list.
  154.  */
  155. void EditAdd(item, event)
  156.      Panel_item        item;
  157.      Event        *event;
  158. {
  159.   char buf[100];
  160.   
  161.   if (SetDuration(lines) == Error)                    /* Display the duration of the current selection */
  162.   {
  163.     return;
  164.   }
  165.   GetStartEnd(lines);                            /* Gets the start and end times from the selection textfields and set it */
  166.                                     /* to the next free element in the edit list arrays */
  167.   PrintOnList(lines, buf);                        /* Format the new entry to be inserted on the edit list */
  168.   xv_set(cdEdit_EditPopup->EditList,
  169.      PANEL_LIST_INSERT, lines,
  170.      PANEL_LIST_STRING, lines, buf,
  171.      PANEL_LIST_FONT, lines, font,
  172.      NULL);
  173.   if (editnum != -1)                            /* Deselect any previously selected entry */
  174.   {
  175.     xv_set(cdEdit_EditPopup->EditList,
  176.        PANEL_LIST_SELECT, editnum, FALSE,
  177.        NULL);
  178.   }
  179.   xv_set(cdEdit_EditPopup->EditList,                    /* Select the new entry */
  180.      PANEL_LIST_SELECT, lines, TRUE,
  181.      NULL);
  182.   editnum = lines;
  183.   lines++;
  184.   if (discInPlayer == 1) 
  185.   {
  186.     xv_set(cdEdit_EditPopup->ModifyButton, PANEL_INACTIVE, FALSE, NULL); /* Make the modify and delete buttons active */
  187.     xv_set(cdEdit_EditPopup->DeleteButton, PANEL_INACTIVE, FALSE, NULL); /* only if there is a disc in the player */
  188.   }
  189.   sprintf(buf, "Current Selection : %d", lines);            /* Update the edit status information */
  190.   xv_set(cdEdit_EditPopup->CurrentSelectionMsg, PANEL_LABEL_STRING, buf, NULL);
  191.   PrintNumEdit();
  192.   change = 1;
  193.   UpdateHeader(1);
  194. }
  195.  
  196. /*
  197.  * Notify callback function for `ModifyButton'.
  198.  * Modifies the currently selected entry in the edit list with the values in the current selection textfields.
  199.  */
  200. void EditModify(item, event)
  201.      Panel_item    item;
  202.      Event        *event;
  203. {
  204.   char buf[100];
  205.   
  206.   if (SetDuration(editnum) == Error)                    /* Display the duration of the current selection */
  207.   {
  208.     return;
  209.   }
  210.   GetStartEnd(editnum);                            /* Gets the start and end times from the selection textfields */
  211.   PrintOnList(editnum, buf);                        /* Format the modified entry to be replaced on the edit list */
  212.   xv_set(cdEdit_EditPopup->EditList,
  213.      PANEL_LIST_STRING, editnum, buf,
  214.      PANEL_LIST_FONT, editnum, font,
  215.      NULL);
  216.   change = 1;
  217.   UpdateHeader(1);
  218. }
  219.  
  220. /*
  221.  * Notify callback function for `DeleteButton'.
  222.  * Delete the currently selected entry from the edit list.
  223.  */
  224. void EditDelete(item, event)
  225.      Panel_item    item;
  226.      Event        *event;
  227. {
  228.   int i;
  229.   char buf[100];
  230.   
  231.   xv_set(cdEdit_EditPopup->EditList,                /* Deselect the current selection */
  232.      PANEL_LIST_SELECT, editnum, FALSE,
  233.      NULL);
  234.   if (editnum != 0) 
  235.   {
  236.     xv_set(cdEdit_EditPopup->EditList,                /* Due to some strange XView (?) bug, we have to select another entry first */
  237.        PANEL_LIST_SELECT, editnum - 1, TRUE,            /* before doing the deletion. */
  238.        NULL);
  239.   }
  240.   xv_set(cdEdit_EditPopup->EditList,                /* Delete the entry */
  241.      PANEL_LIST_DELETE, editnum,
  242.      NULL);
  243.   lines --;    
  244.   for (i=editnum; i < lines;i++)                     /* Now, move all the entries following the deleted one up by one */
  245.   {
  246.     starttrack[i] = starttrack[i+1];
  247.     startmin[i] = startmin[i+1];
  248.     startsec[i] = startsec[i+1];
  249.     startframe[i] = startframe[i+1];
  250.     endtrack[i] = endtrack[i+1];
  251.     endmin[i] = endmin[i+1];
  252.     endsec[i] = endsec[i+1];
  253.     endframe[i] = endframe[i+1];
  254.     volume[i] = volume[i+1];
  255.     balance[i] = balance[i+1];
  256.     duration[i] = duration[i+1];
  257.     strcpy(label[i], label[i+1]);
  258.     PrintOnList(i, buf);
  259.     xv_set(cdEdit_EditPopup->EditList,
  260.        PANEL_LIST_STRING, i, buf,
  261.        PANEL_LIST_FONT, i, font,
  262.        NULL);
  263.   }
  264.   if (editnum != 0)                            /* Deselect any selected entry.  After the delete operation, no entry should be */
  265.   {                                    /* selected. */
  266.     xv_set(cdEdit_EditPopup->EditList,
  267.        PANEL_LIST_SELECT, editnum - 1, FALSE,
  268.        NULL);
  269.   }
  270.   xv_set(cdEdit_EditPopup->CurrentSelectionMsg, PANEL_LABEL_STRING, "Current Selection : None", NULL); /* Update the edit status information */
  271.   PrintNumEdit();
  272.   editnum = -1;
  273.  
  274.   xv_set(cdEdit_EditPopup->ModifyButton, PANEL_INACTIVE, TRUE, NULL); /* Make the delete and modify buttons inactive */
  275.   xv_set(cdEdit_EditPopup->DeleteButton, PANEL_INACTIVE, TRUE, NULL);
  276.   change = 1;
  277.   UpdateHeader(1);
  278. }
  279.  
  280. /*
  281.  * Notify callback function for `DeleteAllButton'.
  282.  * This function will clear the whole edit list.
  283.  */
  284. void EditDeleteAll(item, event)
  285.      Panel_item    item;
  286.      Event        *event;
  287. {
  288.   int i;
  289.   char edit[20];
  290.  
  291.   if (CheckChanges (DeleteAll) == NOTICE_YES)                /* Check if there are unsaved changes */
  292.   {
  293.     return;
  294.   }
  295.   for (i=0; i < lines; i++)                        /* Delete all the entries in the list */
  296.   {
  297.     xv_set(cdEdit_EditPopup->EditList,
  298.        PANEL_LIST_DELETE, 0,
  299.        NULL);
  300.   }
  301.   lines  = 0;
  302.   editnum = -1;                                /* Update the edit status information */
  303.   PrintNumEdit();
  304.   change = 1;
  305.   UpdateHeader(1);
  306.   sprintf(edit, "No. of Edits : 0");
  307.   xv_set(cdEdit_EditPopup->EditListNumEditsMsg, PANEL_LABEL_STRING,
  308.      edit, NULL);
  309.   xv_set(cdEdit_EditPopup->CurrentSelectionMsg, PANEL_LABEL_STRING, "Current Selection : None", NULL);
  310.   xv_set(cdEdit_EditPopup->ModifyButton, PANEL_INACTIVE, TRUE, NULL); /* Make the modify and delete buttons inactive */
  311.   xv_set(cdEdit_EditPopup->DeleteButton, PANEL_INACTIVE, TRUE, NULL);
  312. }
  313.  
  314. /*
  315.  * Menu handler for `DocumentMenu (Close this window)'.
  316.  */
  317. Menu_item CloseEditPopupHandler(item, op)
  318.      Menu_item    item;
  319.      Menu_generate    op;
  320. {
  321.   switch (op) 
  322.   {
  323.    case MENU_DISPLAY:
  324.     break;
  325.    case MENU_DISPLAY_DONE:
  326.     break;
  327.    case MENU_NOTIFY:
  328.     xv_set(cdEdit_PreviewPopup->PreviewPopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  329.     xv_set(cdEdit_PreviewPopup->PreviewPopup, XV_SHOW, FALSE, NULL);
  330.     xv_set(cdEdit_EditPopup->EditPopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  331.     xv_set(cdEdit_EditPopup->EditPopup, XV_SHOW, FALSE, NULL);
  332.     break;
  333.    case MENU_NOTIFY_DONE:
  334.     break;
  335.   }
  336.   return item;
  337. }
  338.  
  339. /*
  340.  * Frame done proc for the edit popup window pushpin.
  341.  */
  342. void EditDone()
  343. {
  344.   CloseEditPopupHandler(NULL, MENU_NOTIFY);
  345. }
  346.