home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / videoedt / vddtptns.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  13.2 KB  |  426 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/VideoEditOptions.c,v 0.30 92/06/15 14:35:52 drapeau Exp $ */
  25. /* $Log:    VideoEditOptions.c,v $
  26.  * Revision 0.30  92/06/15  14:35:52  drapeau
  27.  * Minor change, removed declaration of "chosenHost[]" since it is already
  28.  * declared in VideoEdit.h.
  29.  * 
  30.  * Revision 0.29  92/05/13  00:23:10  drapeau
  31.  * Several changes:
  32.  * * Removed function "SetPlayer()", replaced it with function
  33.  *   "SetPlayerHandler()" which is almost identical in function.  This was
  34.  *   done in order to reflect a simplification in the user interface, in
  35.  *   the way a player and serial port are chosen.
  36.  * * Removed function "optionsSetPort()", as the user interface
  37.  *   simplification mentioned above obviates the need for this function.
  38.  * * Minor formatting changes to conform to coding standards.
  39.  * 
  40.  * Revision 0.28  92/01/03  15:47:51  drapeau
  41.  * Modified Audio(): deleted unused variable, and added statements
  42.  * to use defined constants "PlayerAudioMute", etc., from the
  43.  * VideoObject library.  Used these constants to make the code
  44.  * clearer as to its purpose.
  45.  * 
  46.  * Revision 0.27  91/09/29  16:07:02  lim
  47.  * When initialization of player fails or is terminated in any way,
  48.  * player setting is reset to "None".
  49.  * When using default port, the actual setting will be reflected
  50.  * on the port setting after connection is established.
  51.  * 
  52.  * Revision 0.26  91/09/29  14:32:11  lim
  53.  * In setting player, we now check that the player/serial line are chosen
  54.  * correctly.
  55.  * If the initialization returns a NULL video object, the user gets a 
  56.  * notice prompt asking him to check the player/serial line.
  57.  * Also, with the additional choice of 'Default' in the serial line
  58.  * option, the variable 'mySerialPort' is removed.
  59.  * 
  60.  * Revision 0.25  91/09/27  16:53:33  lim
  61.  * 1. Added "None" as default item on optionsPlayerStg.
  62.  * 2. Added notice prompt when player is selected.
  63.  * 
  64.  * Revision 0.24  91/09/26  11:58:24  lim
  65.  * Changed name of currently selected network host from
  66.  * 'host' to 'chosenHost'. Made a global.
  67.  * Changed initialization of 'chosenHost'.
  68.  * 
  69.  * Revision 0.23  91/09/24  21:36:39  lim
  70.  * Changed 'vEdit' to 'VideoEdit' everywhere.
  71.  * 
  72.  * Revision 0.22  91/09/03  10:33:54  lim
  73.  * Checked for valid Sender & Receiver before disconnecting in SetNetworkHost.
  74.  * 
  75.  * Revision 0.21  91/08/29  12:11:27  lim
  76.  * Added 'Default' to serial port.
  77.  * 
  78.  * Revision 0.20  91/08/28  17:06:03  lim
  79.  * Updated status codes.
  80.  * 
  81.  * Revision 0.19  91/08/28  17:03:43  lim
  82.  * Hitting done will also set network host if not already set.
  83.  * 
  84.  * Revision 0.18  91/08/24  17:55:40  lim
  85.  * Implemented PrintDiagnostics. 
  86.  * Using command line flag '-d', the user can choose to launch the
  87.  * app with diagnostic messages. Otherwise, no diag messages will
  88.  * be printed.
  89.  * 
  90.  * Revision 0.17  91/08/21  10:52:13  lim
  91.  * *** empty log message ***
  92.  * 
  93.  * Revision 0.16  91/08/21  10:48:01  lim
  94.  * Fixed bug concerning serial ports. 'mySerialPort' is set whenever the
  95.  * video object has yet to be initialized, so that only upon initialization
  96.  * is SetSerialLine called.
  97.  * This setting overrides both the ~/.Xdefaults setting AND the setting
  98.  * coded in the video library.
  99.  * 
  100.  * Revision 0.15  91/08/16  13:11:08  lim
  101.  * 1. Serial port setting reflected in panel.
  102.  * 2. optionsNetworkHost added so that we are able to choose the Port Manager
  103.  * after app is launched.
  104.  * 3. Info button and function moved here.
  105.  * 
  106.  * Revision 0.14  91/08/07  13:28:33  lim
  107.  * 1. Added instance pointer, "theObject" to all public function calls.
  108.  * 
  109.  * Revision 0.13  91/08/02  13:00:07  lim
  110.  * 1. allDevices has been changed from an array of device configurations to
  111.  * an array of names of all devices supported.
  112.  * 2. GetDeviceMaxSpeed() used to get maximum speed possible with current
  113.  * device.
  114.  * 3. DevSetDefaults called with 4 parameters.
  115.  * 4. CheckImplemented is used to decide what buttons to set inactive.
  116.  * 5. SetSerialLine changed to take in device configuration structure rather
  117.  * than deviceName.
  118.  * 
  119.  * Revision 0.12  91/07/23  15:57:01  lim
  120.  * Added SetPlayer() which allows drivers to be chosen for the app.
  121.  * 
  122.  * Revision 0.11  91/07/17  22:53:41  lim
  123.  * Replaced DevSetSerialPort with SetSerialPort (a call from the
  124.  * videoObject package) in optionsSetPort.
  125.  * 
  126.  * Revision 0.10  91/07/12  16:20:26  lim
  127.  * Initial revision implementing VideoObject.
  128.  *  */
  129.  
  130. #include "VideoEdit.h"
  131.  
  132. static char optrcs[] = "$Header: /Source/Media/collab/VideoEdit/RCS/VideoEditOptions.c,v 0.30 92/06/15 14:35:52 drapeau Exp $";
  133.  
  134.  
  135. /*     OPTIONS FOR CONTROLLING DISPLAY, SEARCH MODE, AUDIO (POPUP WINDOW 1)     */
  136.  
  137.  
  138. /*
  139.  * Notify callback function for `setPlayerButton'.
  140.  */
  141. void
  142.   SetPlayerHandler(Panel_item item, Event *event)
  143. {
  144.   int        maxSpeed;
  145.   int        choice;
  146.   int        portSelection;
  147.   int        value;
  148.   char        chosenPlayerMsg[27+MaxNameLength];
  149.   char        chosenPortMsg[29];
  150.   char*        playPort;
  151.   Display*    display;
  152.   
  153.   value = xv_get(VideoEdit_optionsPopup->optionsPlayerStg, PANEL_VALUE); /* Determine currently-selected player, if any */
  154.   if (value == 0)                            /* Chose "None" => Return immediately */
  155.     return;
  156.   
  157.   sprintf(chosenPlayerMsg, "You have chosen the %s player", 
  158.       allDevices[value-1]);
  159.   portSelection = (int) xv_get(VideoEdit_optionsPopup->optionsPortStg,
  160.                    PANEL_VALUE);
  161.   switch (portSelection)
  162.   {
  163.    case 0:
  164.     strcpy(chosenPortMsg, "and the default serial port.");
  165.     break;
  166.    case 1:
  167.     strcpy(chosenPortMsg, "and serial port A.");
  168.     break;
  169.    case 2:
  170.     strcpy(chosenPortMsg, "and serial port B.");
  171.     break;
  172.   }
  173.   choice = notice_prompt(VideoEdit_optionsPopup->optionsPopup,        /* Let user confirm player and serial port */
  174.              NULL, 
  175.              NOTICE_MESSAGE_STRINGS, chosenPlayerMsg,
  176.              chosenPortMsg,
  177.              "Please confirm player and",
  178.              "serial port selections.",
  179.              NULL,
  180.              NOTICE_BUTTON_YES, "Cancel",
  181.              NOTICE_BUTTON_NO, "OK", 
  182.              NULL);
  183.   if (choice == NOTICE_YES)
  184.   {
  185.     xv_set(VideoEdit_optionsPopup->optionsPlayerStg, PANEL_VALUE, 0, NULL); /* Set player back to "None" */
  186.     return;
  187.   }
  188.   
  189.   strcpy(deviceName, allDevices[value-1]);                /* The 0th item is "None" */
  190.   switch (portSelection)
  191.   {
  192.    case 0:
  193.     myVideo = DevInit(deviceName, NULL);
  194.     break;
  195.    case 1:
  196.     myVideo = DevInit(deviceName, "/dev/ttya");
  197.     break;
  198.    case 2:
  199.     myVideo = DevInit(deviceName, "/dev/ttyb");
  200.     break;
  201.   }
  202.   
  203.   if (myVideo)
  204.   {
  205.     maxSpeed = GetDeviceMaxSpeed(myVideo);                /* Get max speed for current device */
  206.     xv_set(VideoEdit_window1->speedSlider,                /* Set slider values to correspond exactly to the ... */
  207.        PANEL_MIN_VALUE, -(maxSpeed),                /* ... maximum number of frames per second the player ... */
  208.        PANEL_MAX_VALUE, maxSpeed,                    /* ... can play */
  209.        NULL);
  210.     
  211.     DevSetDefaults(myVideo, 3, PlayerFrameMode, FeatureOn,
  212.            DisplayFrameAndChapter);                /* Set device to default settings */
  213.     
  214.     if (CheckImplemented(myVideo, SetAddModeFunction) == No)        /* Set appropriate buttons off */
  215.     {
  216.       xv_set(VideoEdit_optionsPopup->optionsSearchStg, PANEL_INACTIVE, TRUE, NULL);
  217.       xv_set(VideoEdit_window1->revSkipButton, PANEL_INACTIVE, TRUE, NULL);
  218.       xv_set(VideoEdit_window1->fwdSkipButton, PANEL_INACTIVE, TRUE, NULL);
  219.     }
  220.     
  221.     if (portSelection == 0)                        /* Using default serial port */
  222.     {
  223.       display =  (Display*) xv_get(VideoEdit_window1->window1, XV_DISPLAY);    
  224.       playPort = XGetDefault(display, deviceName, "serialPort");
  225.       
  226.       if (playPort == NULL)                        /* There are no Xdefault settings */
  227.       {
  228.     if ((strcmp(myVideo->DevConfig->serialPort, "/dev/ttya") == 0) || 
  229.         (strcmp(myVideo->DevConfig->serialPort, "na") == 0))    /* Defaults to /dev/ttya */
  230.       xv_set(VideoEdit_optionsPopup->optionsPortStg, PANEL_VALUE, 1, NULL); 
  231.     else 
  232.       if (strcmp(myVideo->DevConfig->serialPort, "/dev/ttyb") == 0)
  233.         xv_set(VideoEdit_optionsPopup->optionsPortStg, PANEL_VALUE, 2, NULL); 
  234.       }
  235.       else
  236.     if (strcmp(playPort, "/dev/ttya") == 0)
  237.       xv_set(VideoEdit_optionsPopup->optionsPortStg, PANEL_VALUE, 1, NULL); 
  238.     else
  239.       xv_set(VideoEdit_optionsPopup->optionsPortStg, PANEL_VALUE, 2, NULL); 
  240.     }
  241.   }
  242.   else
  243.   {
  244.     notice_prompt(VideoEdit_optionsPopup->optionsPopup,            /* Player has not responded */
  245.           NULL, 
  246.           NOTICE_MESSAGE_STRINGS, "The player has failed to respond.", " ",
  247.           "Please check that :",
  248.           "1. You have chosen the correct player.                             ",
  249.           "2. The player is connected at the serial port you selected.",
  250.           "3. The baud rate and other player attributes are correct.  ",
  251.           "4. The player is not busy.                                                 ",
  252.           " ",
  253.           "and try again.",
  254.           NULL,
  255.           NOTICE_BUTTON, "OK", 100,
  256.           NULL);
  257.     xv_set(VideoEdit_optionsPopup->optionsPlayerStg, PANEL_VALUE, 0, NULL); /* Set player back to "None" */
  258.   }
  259.   
  260.   /* gxv_start_connections DO NOT EDIT THIS SECTION */
  261.   
  262.   /* gxv_end_connections */
  263.   
  264. }                                    /* end function SetPlayerHandler */
  265.  
  266.  
  267. /*
  268.  * Notify callback function for `optionsNetworkHost'.
  269.  */
  270. void
  271. SetNetworkHost(item, event)
  272.     Panel_item    item;
  273.     Event        *event;
  274. {
  275.  
  276.   char* tmp;
  277.   Port senderPort;
  278.   char diagMsg[30];
  279.   
  280.   tmp = (char *) xv_get(item, PANEL_VALUE);
  281.   if ((strlen(tmp) == 0) || (chosenHost && (strcmp(tmp, chosenHost) == 0)))
  282.     return;
  283.   else
  284.     strcpy(chosenHost, tmp);
  285.  
  286.   if (sender && receiver)
  287.     SenderDisconnectFromPortMgr(sender,&(receiver->receivePort));
  288.   sender = NULL;
  289.   receiver = NULL;
  290.   
  291.   senderPort.hostName = chosenHost;
  292.   senderPort.portNumber = PortMgrPortNumber;
  293.   sender = NewSender(&senderPort);
  294.   if (!sender)
  295.   {
  296.     DisplayError("Host name is not valid", " ");
  297.     return;
  298.   }
  299.   receiver = NewReceiver(sender, "VideoEdit", receiverPort);
  300.   sprintf(diagMsg, "Listening on port %d.\n", receiver->transport->xp_port);
  301.   PrintDiagnostics(diagMsg);
  302.   
  303.   return;
  304. }
  305.  
  306.  
  307. /*
  308.  * Notify callback function for `optionsInfoButton'.
  309.  * Opens info popup window.
  310.  */
  311. void
  312. Info(item, event)
  313.      Panel_item      item;
  314.      Event           *event;
  315. {
  316.   xv_set(VideoEdit_infoPopup->infoPopup, 
  317.      FRAME_CMD_PUSHPIN_IN, TRUE, 
  318.      NULL);
  319.   xv_set(VideoEdit_infoPopup->infoPopup, 
  320.      XV_SHOW, TRUE, 
  321.      NULL);
  322. }
  323.  
  324.  
  325. /*
  326.  * Notify callback function for `optionsDisplayStg'.
  327.  * Select display on/off
  328.  */
  329. void
  330. DisplaySelect(item, value, event)
  331.      Panel_item    item;
  332.      int        value;
  333.      Event        *event;
  334. {
  335.   
  336.   if (value == 1) 
  337.     xv_set(VideoEdit_window1->window1, 
  338.        FRAME_LEFT_FOOTER, "Display : On",
  339.        NULL);
  340.   else 
  341.     xv_set(VideoEdit_window1->window1, 
  342.        FRAME_LEFT_FOOTER, "Display : Off",
  343.        NULL);
  344.  
  345.   DevSetAddressDisplay(myVideo, value, DisplayFrameAndChapter);
  346. }
  347.  
  348. /*
  349.  * Notify callback function for `optionsSearchStg'.
  350.  * Set search mode to frame or chapter
  351.  */
  352. void
  353. SearchSet(item, value, event)
  354.      Panel_item    item;
  355.      int        value;
  356.      Event        *event;
  357. {
  358.   if (value == 0) 
  359.   {
  360.     xv_set (VideoEdit_window1->frameTxt,
  361.         PANEL_LABEL_STRING, "Frame: ",
  362.         NULL);
  363.   }
  364.   else 
  365.   {
  366.     xv_set (VideoEdit_window1->frameTxt,
  367.         PANEL_LABEL_STRING, "Chapter: ",
  368.         NULL);
  369.   }
  370.   xv_set (VideoEdit_window1->frameTxt, PANEL_VALUE, 0, NULL);
  371.   
  372. }
  373.  
  374.  
  375. /*
  376.  * Notify callback function for `optionsAudioStg'.
  377.  * Select audio setting 
  378.  */
  379. void
  380. Audio(item, value, event)
  381.      Panel_item    item;
  382.      int        value;
  383.      Event        *event;
  384. {
  385.   int    audioSetting = PlayerAudioStereo;
  386.   
  387.   switch (value) 
  388.   {
  389.    case 0 : xv_set(VideoEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  390.            "Audio : Off", NULL);
  391.     audioSetting = PlayerAudioMute;
  392.     break;
  393.    case 1 : xv_set(VideoEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  394.            "Audio : Left", NULL);
  395.     audioSetting = PlayerAudioLeft;
  396.     break;
  397.    case 2 : xv_set(VideoEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  398.            "Audio : Right", NULL);
  399.     audioSetting = PlayerAudioRight;
  400.     break;
  401.    case 3 : xv_set(VideoEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  402.            "Audio : Stereo", NULL);
  403.     audioSetting = PlayerAudioStereo;
  404.     break;
  405.   }
  406.   DevSetAudio(myVideo, audioSetting);
  407.   return;
  408. }                                    /* end function Audio */
  409.  
  410.  
  411.  
  412. /*
  413.  * Notify callback function for `optionsDoneButton'.
  414.  * To close the options popup window
  415.  */
  416. void
  417. Done(item, event)
  418.      Panel_item      item;
  419.      Event           *event;
  420. {
  421.   SetNetworkHost(VideoEdit_optionsPopup->optionsNetworkHost, NULL);
  422.   xv_set(VideoEdit_optionsPopup->optionsPopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  423.   xv_set(VideoEdit_optionsPopup->optionsPopup, XV_SHOW, FALSE, NULL);
  424. }
  425.  
  426.