home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / videoedt / vddtprtc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  14.1 KB  |  484 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/VideoEdit/RCS/VideoEditProtocol.c,v 0.37 92/05/29 12:38:57 drapeau Exp $ */
  25. /* $Log:    VideoEditProtocol.c,v $
  26.  * Revision 0.37  92/05/29  12:38:57  drapeau
  27.  * Modified code to track new name of the MAEstro "Selection" structure;
  28.  * it is now named "MAESelection".
  29.  * 
  30.  * Revision 0.36  92/05/13  00:22:10  drapeau
  31.  * Minor changes:
  32.  * * Minor formatting changes to conform to coding standards.
  33.  * * Changed case of the document "Untitled".
  34.  * 
  35.  * Revision 0.35  92/01/07  14:11:35  drapeau
  36.  * Minor cosmetic change to make code easier to read.
  37.  * 
  38.  * Revision 0.34  92/01/03  15:51:16  drapeau
  39.  * Changed occurrances of "NULL" in calls to Browse() to use "0" instead.
  40.  * This is due to the ANSI definition of NULL as "(void*)0".
  41.  * 
  42.  * Revision 0.33  91/11/14  10:14:41  collab
  43.  * Modified GetAppIcon() to reflect new location of the application icon, in
  44.  * the "icons/" directory.
  45.  * 
  46.  * Revision 0.32  91/09/26  12:58:20  lim
  47.  * *** empty log message ***
  48.  * 
  49.  * Revision 0.31  91/09/26  12:29:09  lim
  50.  * *** empty log message ***
  51.  * 
  52.  * Revision 0.30  91/09/26  11:59:32  lim
  53.  * Returns from protocol functions immediately if there
  54.  * is no initialized driver.
  55.  * 
  56.  * Revision 0.29  91/09/24  21:37:07  lim
  57.  * Changed 'vEdit' to 'VideoEdit' everywhere.
  58.  * 
  59.  * Revision 0.28  91/08/30  15:44:24  lim
  60.  * Don't send error message if sender is NULL.
  61.  * Create receiver only when sender not null.
  62.  * 
  63.  * Revision 0.27  91/08/24  17:55:45  lim
  64.  * Implemented PrintDiagnostics. 
  65.  * Using command line flag '-d', the user can choose to launch the
  66.  * app with diagnostic messages. Otherwise, no diag messages will
  67.  * be printed.
  68.  * 
  69.  * Revision 0.26  91/08/23  17:16:43  lim
  70.  * Document format has been changed.
  71.  * 
  72.  * Revision 0.25  91/08/21  14:31:32  lim
  73.  * Implemented GetAppIcon().
  74.  * 
  75.  * Revision 0.24  91/08/20  16:31:15  lim
  76.  * Now SetSelection blanks out screen and the screen wil
  77.  * show only on Perform selection.
  78.  * 
  79.  * Revision 0.23  91/08/20  16:30:33  lim
  80.  * Parameters for SetVideo : 0 - Video mute
  81.  *                      1 - Video on
  82.  * 
  83.  * Revision 0.22  91/08/20  15:46:46  lim
  84.  *  Get selection now returns a duration of -1 if no edit has been selected.
  85.  * 
  86.  * 
  87.  * Revision 0.21  91/08/20  10:07:53  lim
  88.  * HaltSelection and PauseSelection now call DevStop() and DevStill()
  89.  * directly.
  90.  * 
  91.  * Revision 0.20  91/08/17  20:52:11  lim
  92.  * 1. All stops and pauses are capable of interrupt.
  93.  * 2. OpenPanel is now Browse.
  94.  * 
  95.  * Revision 0.19  91/08/16  13:12:23  lim
  96.  * 1. No more editFilename. Filename now put in title bar. 
  97.  * 2. Call Browse() with OPENPANEL_CHECK for open doc.
  98.  * 3. Functions check for validity before proceeding.
  99.  * 
  100.  * Revision 0.18  91/08/08  17:19:10  lim
  101.  * 1. CalcSpeed() - one parameter added, 'playMode'. If playMode is 1, it is used to calculate
  102.  *    device speed for segment play. If playMode is 0, it is used to calculate device speed for
  103.  *    normal play.
  104.  * 
  105.  * Revision 0.17  91/08/07  13:29:36  lim
  106.  * 1.Added instance pointer, "theObject" to all public function calls.
  107.  * 2. Added 'Round' (same as 'MyRound')
  108.  * 
  109.  * Revision 0.16  91/07/29  22:31:44  lim
  110.  * Updated status codes to conform with specs.
  111.  * 
  112.  * Revision 0.15  91/07/27  22:29:51  lim
  113.  * Changed speed from double to int.
  114.  * 
  115.  * Revision 0.14  91/07/23  15:57:32  lim
  116.  * 1. Offset corrected to take into account the speed at which the
  117.  * segment will be played.
  118.  * 2. Fixed duration calculation.
  119.  * 3. For PauseSelection and HaltSelection, we check if the device
  120.  * has interruptible segment play. If so, then the regular Pause/Halt 
  121.  * operation is performed. Otherwise, we have to interrupt the player.
  122.  * In such devices, ClearMarker will not exist (this is what allows
  123.  * devices to be interruptible, by setting a stop marker and returning)
  124.  * and so we use ClearMarker to perform the interrupt action.
  125.  * 
  126.  * Revision 0.13  91/07/20  10:06:58  lim
  127.  * SetSelection now places new start (according to offset) on the
  128.  * textfield "editStartTxt" rather than what is in startframe[editnum].
  129.  * 
  130.  * Revision 0.12  91/07/19  14:15:27  lim
  131.  * Added audio and speed settings.
  132.  * 
  133.  * Revision 0.11  91/07/12  17:29:21  lim
  134.  * Set icon for TimeLine.
  135.  * 
  136.  * Revision 0.10  91/07/12  16:22:01  lim
  137.  * Initial revision implementing VideoObject.
  138.  *  */
  139.  
  140. #include "VideoEdit.h"
  141. #define Round(n, d)          ((n%d)/d > 0.5? (n/d+1) : (n/d))
  142.  
  143. void OpenDoc();
  144. void SetSelection();
  145. void PerformSelection();
  146. char** GetDoc();
  147. MAESelection* GetSelection();
  148. void HaltSelection();
  149. void PauseSelection();
  150. void ResumeSelection();
  151. void HideApplication();
  152. void ShowApplication();
  153. IconData* GetAppIcon();
  154.  
  155. static char* canonFilename;
  156. static char lrcsid[] = "$Header: /Source/Media/collab/VideoEdit/RCS/VideoEditProtocol.c,v 0.37 92/05/29 12:38:57 drapeau Exp $";
  157.  
  158. Sender* sender;
  159. Receiver* receiver;
  160.  
  161. void 
  162. InitNetwork(h) 
  163.      char* h;
  164. {
  165.   Port senderPort;
  166.   char diagMsg[30];
  167.   
  168.   static DispatchTable  DT = 
  169.   {
  170.     OpenDoc,
  171.     GetDoc,
  172.     GetSelection,
  173.     SetSelection,
  174.     PerformSelection,
  175.     NULL,
  176.     NULL,
  177.     NULL,
  178.     NULL,
  179.     NULL,
  180.     NULL,
  181.     HaltSelection,
  182.     PauseSelection,
  183.     ResumeSelection,
  184.     HideApplication,
  185.     ShowApplication,
  186.     GetAppIcon
  187.     };
  188.   
  189.   lines = 0;
  190.   clearframe = 0;
  191.   change = 0;
  192.   search = 0;
  193.   editnum = -1;
  194.   
  195.   /* Networking stuff */
  196.   
  197.   senderPort.hostName = h;
  198.   senderPort.portNumber = PortMgrPortNumber;
  199.   sender = NewSender(&senderPort);
  200.   if (sender)                                /* Create receiver only if sender is alive */
  201.   {
  202.     receiver = NewReceiver(sender, "VideoEdit", receiverPort);
  203.     sprintf(diagMsg, "Listening on port %d.\n", receiver->transport->xp_port);
  204.     PrintDiagnostics(diagMsg);
  205.   
  206.     BuildDispatchTable (&DT);
  207.   }
  208.   
  209.   canonFilename = (char*) malloc(MAX_PATHLENGTH);
  210.   
  211.   (void) notify_enable_rpc_svc (TRUE);
  212.   
  213. }
  214.  
  215.  
  216.  
  217. void
  218.   OpenDoc(filename)
  219. char** filename;
  220. {
  221.   int result;
  222.   char fullFilename[MAX_PATHLENGTH];
  223.   char* currentFile = (char*) xv_get(VideoEdit_editPopup->editPopup,
  224.                      XV_LABEL);
  225.   
  226.   if (strcmp(*filename, "Untitled") != 0) 
  227.   {                                    /* check that filename is not 'untitled' */
  228.     if (strlen(currentFile) == 0) strcpy (currentFile, ".");        /* If no filename specified in panel, set to '.' (directory) */
  229.     
  230.     if (realpath(currentFile, fullFilename) != NULL)
  231.       strcpy(fullFilename, (char*) realpath(currentFile, fullFilename));
  232.     else 
  233.       strcpy(fullFilename, ".");
  234.     
  235.     if (strcmp(fullFilename, *filename) != 0 &&                /* check if filename given by link editor is the same... */
  236.     strcmp(currentFile, *filename) != 0)                /* ... as that on on the panel textfield */
  237.     {                                    
  238.       result = NOTICE_NO;
  239.       if ((change) && (lines > 0))                    /* check for changes in edit list */
  240.       {
  241.     result = notice_prompt(VideoEdit_editPopup->editPopup, NULL,
  242.                    NOTICE_MESSAGE_STRINGS,
  243.                    "Unsaved changes exist in the video edit list.",
  244.                    "Loading a file will erase all changes.",
  245.                    "Go ahead and load the file?",
  246.                    NULL,
  247.                    NOTICE_BUTTON_NO,       "Yes",
  248.                    NOTICE_BUTTON_YES,      "No",
  249.                    NULL);
  250.       }
  251.       if (result == NOTICE_NO) 
  252.       {
  253.     change = 0;
  254.     Browse(*filename, BrowseCheckOpen, 0, "#Video Edit Document#", "VideoEdit");
  255.       }
  256.     }                                    /* end of if (strcmp(fullFilename, *filename) != 0 && ...
  257.                                        ... strcmp(currentFile, *filename) != 0) */
  258.   }                                    /* end of if (strcmp(*filename, "untitled") != 0)  */
  259. }
  260.  
  261.  
  262. void
  263. SetSelection(MAESelection* selection)
  264. {
  265.   int start;  
  266.   char s[30];
  267.   char audio[7];
  268.   int speedInDevice;
  269.   char diagMsg[30];
  270.   
  271.   if (myVideo == NULL)                            /* Do nothing if no device selected */
  272.     return;
  273.   
  274.   if ((selection->start > 0) && (selection->start <= lines))
  275.   {
  276.     if (editnum != -1)                            /* Deselect any current selection */
  277.       xv_set(VideoEdit_editPopup->editScrollList,
  278.          PANEL_LIST_SELECT, editnum, FALSE,
  279.          NULL);
  280.     
  281.     editnum = selection->start - 1;
  282.     sprintf(s, "Current Selection : Edit #%d", editnum+1);
  283.     speedInDevice = DevCalcSpeed(myVideo, speedStg[editnum], 1);
  284.     sprintf(diagMsg, "SpeedInDevice = %d\n", speedInDevice);
  285.     PrintDiagnostics(diagMsg);
  286.     
  287.     start = startframe[editnum] + 
  288.       (selection->offset)/1000*speedInDevice;                /* Add offset and get new start address */
  289.    
  290.     /* load the appropriate values into the textfields */
  291.     xv_set(VideoEdit_editPopup->editNewEditMsg, PANEL_LABEL_STRING, s, NULL);
  292.     xv_set(VideoEdit_editPopup->editStartTxt, PANEL_VALUE, start, NULL);
  293.     xv_set(VideoEdit_editPopup->editEndTxt, PANEL_VALUE, endframe[editnum], NULL);
  294.     xv_set(VideoEdit_editPopup->editLabelTxt, PANEL_VALUE, label[editnum], NULL);
  295.     xv_set(VideoEdit_editPopup->editSpeedTxt, PANEL_VALUE, speedStg[editnum], NULL);
  296.     switch (audioStg[editnum])
  297.     {
  298.      case Stereo:
  299.       strcpy(audio, "Stereo");
  300.       break;
  301.      case Right:
  302.       strcpy(audio, "Right");
  303.       break;
  304.      case Left:
  305.       strcpy(audio, "Left");
  306.       break;
  307.      case Mute:
  308.       strcpy(audio, "Mute");
  309.       break;
  310.     }
  311.     xv_set(VideoEdit_editPopup->editAudioMenuButton, PANEL_LABEL_STRING, audio, NULL);
  312.     SetDuration();
  313.        
  314.     PlayMode(PlayerFrameMode, start, start);                /* Seek to correct position */
  315.     DevSetVideo(myVideo, 0);                        /* Video muted */
  316.     
  317.     /* make the modify, delete buttons active */
  318.     xv_set(VideoEdit_editPopup->editModButton, PANEL_INACTIVE, FALSE, NULL);
  319.     xv_set(VideoEdit_editPopup->editDelButton, PANEL_INACTIVE, FALSE, NULL);
  320.     
  321.     xv_set(VideoEdit_editPopup->editScrollList,
  322.        PANEL_LIST_SELECT, editnum, TRUE,
  323.        NULL);
  324.     
  325.     
  326.   }                                    /* end of if ((selection->start > 0) &&
  327.                                        (selection->start <= lines)) */
  328.   
  329. }                                    /* end function SetSelection */
  330.  
  331. void
  332. PerformSelection()
  333. {
  334.   int value;
  335.   
  336.   if ((editnum == -1) || (!lines) || (!myVideo))
  337.     return;
  338.  
  339.   DevSetVideo(myVideo, 1);                        /* Video mute off */
  340.   PlayMode(PlayerFrameMode, NULL, endframe[editnum]);            /* Play to end with correct settings */
  341.    
  342.   /* check if search status is frame or chapter */
  343.   value = xv_get(VideoEdit_optionsPopup->optionsSearchStg, 
  344.          PANEL_VALUE);
  345.   if (value == 1) 
  346.     DevSetAddMode(myVideo, PlayerChapterMode);
  347.   
  348. }
  349.  
  350. char**
  351. GetDoc(unusedArg)
  352.      void* unusedArg;
  353. {
  354.   static char* doc;
  355.   
  356.   doc = (char*) xv_get(VideoEdit_editPopup->editPopup, XV_LABEL);
  357.   if ((strlen(doc) == 0) || (realpath(doc, canonFilename) == NULL))
  358.     strcpy(canonFilename, "Untitled");
  359.   else
  360.     strcpy(canonFilename, (char*) realpath(doc, canonFilename));
  361.   return (&canonFilename);
  362. }
  363.  
  364. MAESelection*
  365. GetSelection(unusedArg)
  366.      void *unusedArg;
  367. {
  368.   static MAESelection select;
  369.   int speedInDevice;
  370.   
  371.   if ((editnum == -1) || (!lines))    
  372.   {
  373.     select.duration = -1;                
  374.     return (&select);
  375.   }
  376.   
  377.   select.start = editnum + 1;
  378.   select.end = editnum + 1; 
  379.   if (myVideo)
  380.     speedInDevice = DevCalcSpeed(myVideo, speedStg[editnum], 1);    
  381.   else
  382.     speedInDevice = speedStg[editnum];
  383.   
  384.   if (speedInDevice)
  385.     select.duration = (1000 * Round((endframe[editnum] - startframe[editnum]), speedInDevice));
  386.   else
  387.     select.duration = -1;
  388.  
  389.   select.offset = 0;
  390.   if (strlen(label[editnum]))
  391.     strcpy(select.label, label[editnum]);   
  392.   else
  393.     strcpy(select.label, "NO LABEL");
  394.   
  395.   return (&select);
  396. }
  397.  
  398.  
  399. /* Halts playback of Selection as directed by TimeLine */
  400. void
  401. HaltSelection()
  402. {
  403.   if ((editnum == -1) || (!lines) || (!myVideo))
  404.     return;
  405.   
  406.   DevStop(myVideo);
  407. }
  408.  
  409. /* Pauses playback of Selection as directed by TimeLine */
  410. void
  411. PauseSelection()
  412. {
  413.   if ((editnum == -1) || (!lines) || (!myVideo))
  414.     return;
  415.   
  416.   DevStill(myVideo);
  417. }
  418.  
  419. /* Resumes playback of Selection as directed by TimeLine */
  420. void
  421. ResumeSelection()
  422. {
  423.   if ((editnum == -1) || (!lines) || (!myVideo))
  424.     return;
  425.   paused = 0;
  426.   
  427.   DevPlayFromTo(myVideo, NULL, endframe[editnum], speedStg[editnum]);
  428.   
  429. }
  430.  
  431. /* Iconifies application as directed by TimeLine */
  432. void
  433. HideApplication()
  434. {
  435.   xv_set(VideoEdit_window1->window1, FRAME_CLOSED, TRUE, NULL);
  436.   XFlush((Display*) xv_get(VideoEdit_window1->window1, XV_DISPLAY));
  437.   
  438. }
  439.  
  440. /* Deiconifies application as directed by TimeLine */
  441. void
  442. ShowApplication()
  443. {
  444.   xv_set(VideoEdit_window1->window1, FRAME_CLOSED, FALSE, NULL);
  445.   xv_set(VideoEdit_window1->window1, XV_SHOW, TRUE, NULL);           
  446.   
  447.   /* Show all popups that were up originally */
  448.  
  449.   if (xv_get(VideoEdit_optionsPopup->optionsPopup, XV_SHOW) == TRUE)            
  450.   {
  451.     xv_set(VideoEdit_optionsPopup->optionsPopup, XV_SHOW, TRUE, NULL);
  452.   }
  453.   if (xv_get(VideoEdit_previewPopup->previewPopup, XV_SHOW) == TRUE) 
  454.   {
  455.     xv_set(VideoEdit_previewPopup->previewPopup, XV_SHOW, TRUE, NULL);
  456.   }
  457.   if (xv_get(VideoEdit_editPopup->editPopup, XV_SHOW) == TRUE) 
  458.   {
  459.     xv_set(VideoEdit_editPopup->editPopup, XV_SHOW, TRUE, NULL);
  460.   }  
  461.   if (xv_get(VideoEdit_infoPopup->infoPopup, XV_SHOW) == TRUE) 
  462.   {
  463.     xv_set(VideoEdit_infoPopup->infoPopup, XV_SHOW, TRUE, NULL);
  464.   }
  465.  
  466.   XFlush((Display*) xv_get(VideoEdit_window1->window1, XV_DISPLAY));    
  467. }
  468.  
  469. IconData *
  470. GetAppIcon()
  471. {
  472.   static IconData returnVal;
  473.   static unsigned short baseWindow_bits[] = {
  474. #include "icons/VideoEditIcon"
  475.         };
  476.  
  477.   returnVal.iconData = (char *)malloc(sizeof(baseWindow_bits));
  478.   bcopy(baseWindow_bits, returnVal.iconData, sizeof(baseWindow_bits));
  479.   if (returnVal.iconData)
  480.     returnVal.dataLength = sizeof(baseWindow_bits);
  481.   return(&returnVal);
  482. }
  483.  
  484.