home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / timeline / timeline.c < prev    next >
Encoding:
Text File  |  1993-06-15  |  29.7 KB  |  740 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/TimeLine/RCS/TimeLine.c,v 1.15 92/10/30 16:20:48 drapeau Exp $ */
  25. /* $Log:    TimeLine.c,v $
  26.  * Revision 1.15  92/10/30  16:20:48  drapeau
  27.  * Modified the UpdateHeader() function to indicate whether synchronization
  28.  * hints are available for the current document.
  29.  * 
  30.  * Revision 1.14  92/10/07  15:48:33  drapeau
  31.  * Added function Usage() to describe command-line options to the application.
  32.  * 
  33.  * Revision 1.13  92/10/07  15:14:38  drapeau
  34.  * New version of TimeLine adds two command-line options: "-autoPlay" and
  35.  * "-autoQuit".  "-autoPlay" indicates that TimeLine should immediately begin
  36.  * performance of the document given on the command line (if there is one).
  37.  * "-autoQuit" indicates that TimeLine should quit immediately after
  38.  * completion of performance of the document given on the command line.
  39.  * The "-autoQuit" flag is only valid if "-autoPlay" is also specified.
  40.  * These two options were added to support automated demos using TimeLine.
  41.  * 
  42.  * Revision 1.12  92/09/24  17:01:11  drapeau
  43.  * One minor code change; the rest are cosmetic.
  44.  * * A new document format has been added, to accommodate documents with
  45.  *   synchronization information.  The new header for these documents
  46.  *   is "#TimeLine Edit Document, Version 2#".  Now TimeLine will be able to
  47.  *   load both older-style documents and the new style.
  48.  * * The cosmetic changes are to improve readability.
  49.  * 
  50.  * Revision 1.11  92/09/15  14:12:00  drapeau
  51.  * Removed extraneous include file: "<gdd.h>", since it does not seem to be used
  52.  * by anything in the application.
  53.  * 
  54.  * Revision 1.10  92/01/03  17:25:50  drapeau
  55.  * Minor change to GetUnknownIcon() to reflect new location of the
  56.  * include file containing the icon data.
  57.  * 
  58.  * Revision 1.0  91/09/30  16:46:47  chua
  59.  * Update to version 1.0
  60.  * 
  61.  * Add TimeLinePort as a member of the tlFrame structure.
  62.  * 
  63.  * In CheckChanges, include a new case, ConnectPM (when connecting with a 
  64.  * new port manager), and delete the UpdateApps case.
  65.  * 
  66.  * Revision 0.81  91/09/25  13:45:08  chua
  67.  * In QuitNotify, proceed to destroy other TimeLine frames if quitAll was set to 1.
  68.  * 
  69.  * Revision 0.80  91/09/23  16:59:42  chua
  70.  * Introduced a new variable, noteInstrument, which keeps track of which instrument
  71.  * contains the currently selected note (there can only be ONE currently selected note).
  72.  * 
  73.  * Got rid of the stop menu and replaced it by a stop and pause button represented
  74.  * by icon symbols.
  75.  * 
  76.  * Revision 0.79  91/09/20  15:04:14  chua
  77.  * Initialize the cursor type to normal.
  78.  * 
  79.  * Revision 0.78  91/09/19  18:32:32  chua
  80.  * Changed the parent of the Region popup to the TimeLine frame.
  81.  * 
  82.  * Revision 0.77  91/09/19  17:27:49  chua
  83.  * Make sure that variables are initialized properly.  Change formatting slightly,
  84.  * so that (if, for, while) statements with only one statement in them will not have
  85.  * braces.
  86.  * 
  87.  * Revision 0.76  91/09/17  17:11:24  chua
  88.  * In TimeLineInit, in the call to OpenAppsInitialize, add a new parameter, to indicate
  89.  * if unassigned apps in the list from the port manager should be added to the 
  90.  * instrument list.
  91.  * 
  92.  * Revision 0.75  91/09/16  14:35:36  chua
  93.  * Include the Browse.h file and do the gethostname here instead of in
  94.  * OpenAppsInitialize (need only do it once).
  95.  * 
  96.  * Revision 0.74  91/09/06  17:31:14  chua
  97.  * In TimeLineInit, initialize TimeLineSender to NULL.
  98.  * 
  99.  * Revision 0.73  91/09/04  17:59:05  chua
  100.  * Add a new function, GetUnknownIcon, which will create the server image
  101.  * for the unknown icon from the icon file.
  102.  * 
  103.  * Revision 0.72  91/09/04  15:07:16  chua
  104.  * Include the getopt.h file from the ~collab/GetOpt directory rather than
  105.  * in the local directory.
  106.  * 
  107.  * Revision 0.71  91/09/04  15:01:12  chua
  108.  * Removed the TIMELINE_HOME environment necessity, since all the media 
  109.  * applications now support the GetAppIcon protocol message.
  110.  * 
  111.  * In TimeLineInit, check that a sender is not NULL before attempting to
  112.  * create a new receiver.
  113.  * 
  114.  * Use frame_set_rect to position the TimeLine frame so that it is always
  115.  * at the same position at startup.
  116.  * 
  117.  * Added a new function, AlertMessage, which simply calls a notice_prompt
  118.  * to display the messages that are passed in as parameters.
  119.  * 
  120.  * Revision 0.70  91/08/26  14:20:50  chua
  121.  * Deleted the actualApps variable from the tlFrame structure.
  122.  * 
  123.  * Revision 0.69  91/08/22  14:59:16  chua
  124.  * In TimeLineInit (line 428), substitute the call to OpenHandler with a call to
  125.  * Browse (with parameter BrowseCheckOpen), which will do the job of checking if the
  126.  * file is valid.
  127.  * 
  128.  * Make the declaration of startFilename static.
  129.  * 
  130.  * Revision 0.68  91/08/16  16:54:22  chua
  131.  * Changed the name of the CreateOpenPanel call to CreateBrowse.
  132.  * 
  133.  * Revision 0.67  91/08/12  15:51:19  chua
  134.  * In TimeLineInit (line 390), change Untitled to untitled.
  135.  * In the CheckChanges routine, add a new option, CloseFile.
  136.  * 
  137.  * Revision 0.66  91/08/08  14:20:16  chua
  138.  * In TimeLineInit, as the object handler to OpenPopup has been removed, just make a
  139.  * call to CreateOpenPanel and not assign the return value to anything.
  140.  * 
  141.  * Revision 0.65  91/07/30  11:19:45  chua
  142.  * Incorporated the file browser.  In TimeLineInit, create the file browser popup
  143.  * window.
  144.  * 
  145.  * Revision 0.64  91/07/26  17:19:55  chua
  146.  * In TimeLineInit, include the initialization of the Region popup window and the
  147.  * variables associated with the annotated regions.
  148.  * 
  149.  * Revision 0.63  91/07/22  15:13:49  chua
  150.  * In TimeLineInit, include the initialization of the Pause popup window and the variables
  151.  * associated with the pause markers.
  152.  * 
  153.  * Revision 0.62  91/07/18  15:03:14  chua
  154.  * In the TimeLineInit routine, initialize the new variable, gridSpacing to 0.
  155.  * 
  156.  * Revision 0.61  91/07/17  16:29:19  chua
  157.  * In the TimeLineInit routine, also initialize the Info popup window.
  158.  * 
  159.  * Revision 0.60  91/07/17  10:12:54  chua
  160.  * Changed the canvas length to 1800 pixels instead of 6000 previously.  The capability
  161.  * to handle infinitely long TimeLine documents is now incorporated.
  162.  * 
  163.  * Revision 0.59  91/07/09  16:52:02  chua
  164.  * Added a new procedure, QuitNotify, which is called when we are trying to destroy a 
  165.  * frame, either using the frame's quit menu, or by choosing the quit menu button from
  166.  * the TimeLine.
  167.  * 
  168.  * Revision 0.58  91/06/26  16:49:18  chua
  169.  * Added a new function CheckOptions, which will take the command line and parse the commands.
  170.  * The user can specify the hostname and portnumber (the latter is not done at the moment).
  171.  * 
  172.  * Revision 0.57  91/06/24  16:28:29  chua
  173.  * Changed the error message for reminding the user to set the TIMELINE_HOME environment. (It was 
  174.  * previously TimeLineHome instead).
  175.  * 
  176.  * The TimeLineLength field in the TimeLineFrame structure now refers to length in pixels, instead of
  177.  * in seconds.
  178.  * 
  179.  * In the TimeLineInit function, add code to disable to stop button (until play is activated).
  180.  * 
  181.  * Minor wording changes to the UpdateHeader function.
  182.  * 
  183.  * Revision 0.56  91/06/05  16:11:25  chua
  184.  * Added some additional comments.  No new code.
  185.  * 
  186.  * Revision 0.55  91/06/04  17:36:47  chua
  187.  * Added the copyright comments in the beginning of the file.
  188.  * 
  189.  * Revision 0.54  91/06/04  17:16:14  chua
  190.  * Added code to differentiate between a Clipboard frame and a Document frame in the 
  191.  * TimeLineInit and UpdateHeader routines.
  192.  * 
  193.  * Revision 0.53  91/06/04  10:40:12  chua
  194.  * Added a new function, UpdateHeader to set the header of a frame.  This
  195.  * is to distinguish between the multiple documents of a TimeLine.
  196.  * The filename currently being edited will be displayed in the header, as
  197.  * well as whether it has been modified.
  198.  * 
  199.  * Revision 0.52  91/05/31  16:05:54  chua
  200.  * Created a new function TimeLineInit to facilitate the forming of multiple documents.
  201.  * Make changes to the data structure in main.h so that all the data required by the
  202.  * TimeLine document is encapsulated in a struct.
  203.  * 
  204.  * Revision 0.51  91/05/28  12:08:22  chua
  205.  * 
  206.  * 
  207.  * Revision 0.50  91/05/24  16:31:23  chua
  208.  * In the CheckChanges procedure, check also that the number of applications
  209.  * is greater than zero before displaying the notice prompt.
  210.  * 
  211.  * Revision 0.49  91/05/23  17:27:42  chua
  212.  * Included the initialization for the Insert Blank Time pop-up window.
  213.  * Also changed the length of the TimeLine to one hour instead of ten minutes.
  214.  * 
  215.  * Revision 0.48  91/05/22  16:37:26  chua
  216.  * *** empty log message ***
  217.  * 
  218.  * Revision 0.47  91/05/22  13:53:45  chua
  219.  * *** empty log message ***
  220.  * 
  221.  * Revision 0.46  91/05/22  11:35:13  chua
  222.  * *** empty log message ***
  223.  * 
  224.  * Revision 0.45  91/05/17  16:58:39  chua
  225.  * *** empty log message ***
  226.  * 
  227.  * Revision 0.44  91/05/17  16:57:33  chua
  228.  * *** empty log message ***
  229.  * 
  230.  * Revision 0.43  91/05/17  16:56:33  chua
  231.  * *** empty log message ***
  232.  * 
  233.  * Revision 0.42  91/05/16  15:18:59  chua
  234.  * Moved the Quit procedure to file.c  (file.c contains all the menu handlers for the Document
  235.  * menu button).
  236.  * 
  237.  * Revision 0.41  1991/04/24  00:46:49  chua
  238.  * Added a new line to initialize the global variable 'areaSelected'.
  239.  *
  240.  * Revision 0.40  1991/03/29  01:23:08  chua
  241.  * This file contains the main procedure of the TimeLine application and two short procedures.
  242.  * The main procedure will initialize XView, check that the TIMELINE_HOME environment variable has been set, and
  243.  * that the user has passed in a hostname for the PortManager.
  244.  * It will then connect with the PortManager and initialize both a sender and receiver.
  245.  * Next, the XView user interface components are initialized as well as some global variables.  The TimeLine
  246.  * application is next initialized by calling OpenAppsInitialize to get the applications currently registered with
  247.  * the PortManager and calling CanvasInit to initialize the canvases.
  248.  * After enabling the TimeLine application to detect RPC events, the xv_main_loop function is called which
  249.  * essentially turns over control of the program to XView.  Now it is up to the user to 'trigger' off any of the
  250.  * functions in the TimeLine application depending on which button was pressed, where the mouse was clicked etc.
  251.  *
  252.  * The two other functions in this file are CheckChanges and Quit.
  253.  * */
  254.  
  255. static char TimeLinercsid[] = "$Header: /Source/Media/collab/TimeLine/RCS/TimeLine.c,v 1.15 92/10/30 16:20:48 drapeau Exp $";
  256.  
  257. #include <sys/types.h>
  258. #include <xview/notify.h>
  259. #include <xview/xv_xrect.h>
  260. #include <xview/textsw.h>
  261. #include "main.h"
  262. #include <Browse.h>
  263. #include <getopt.h>
  264.  
  265. #ifdef MAIN
  266.  
  267. int            WindowFree[MaxWindows + 1];
  268. int            numberOfWindows;                            
  269. int            ReceiverPortNumber;    
  270. int            quitAll;
  271. int            autoPlay;
  272. int            autoQuit;
  273. char            TimeLineHostname[MAXHOSTNAMELEN];                    
  274. TimeLineFramePtr    TimeLineWindow[MaxWindows + 1];
  275. Server_image        unknownIcon;
  276.  
  277. static int initialStart;                        /* Indicates whether the first frame is to be created */
  278. static char *startFilename;
  279.  
  280. /*
  281.  * Instance XV_KEY_DATA key.  An instance is a set of related
  282.  * user interface objects.  A pointer to an object's instance
  283.  * is stored under this key in every object.  This must be a
  284.  * global variable.
  285.  */
  286. Attr_attribute    INSTANCE;
  287.  
  288. void main(int argc, char** argv)
  289. {
  290.   int i;
  291.  
  292.   xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0);            /* Initialize XView */
  293.   INSTANCE = xv_unique_key();
  294.   gethostname(TimeLineHost, MAXHOSTNAMELEN);                /* Get name of host on which the TimeLine Editor is running */
  295.   strcpy (TimeLineHostname, "localhost");                /* Set the default PortManager hostname to localhost */
  296.   ReceiverPortNumber = AnyPort;                        /* Set the default port number to AnyPort */
  297.   startFilename = NULL;
  298.   autoPlay = False;
  299.   autoQuit = False;
  300.   CheckOptions(argc, argv);                        /* Check for any options on the command line */
  301.   numberOfWindows = 0;                            /* Initialization of variables */
  302.   scrollHorStart = 0;
  303.   scrollHorEnd = 0;
  304.   scrollVerStart = 0;
  305.   scrollVerEnd = 0;
  306.   paletteName = 0;
  307.   initialStart = 1;
  308.   clipDuration = 0;
  309.   quitAll = 1;
  310.   for (i=0; i < MaxWindows; i++) 
  311.   {
  312.     TimeLineWindow[i] = (TimeLineFramePtr) malloc (sizeof (struct TimeLineFrame));
  313.     WindowFree[i] = 0;
  314.   }
  315.   GetUnknownIcon();
  316.   CreateCursor();
  317.   TimeLineInit(TimeLineWindow[1], 1);                    /* Create the first TimeLine window */
  318.   exit(0);
  319. }
  320. #endif
  321.  
  322. /* 
  323.  * This function parses the command line and retrieves all the known options and their arguments.
  324.  * Currently, the two options are hostname and portnumber.
  325.  * After parsing the options, the variable optind will point to the start of those non-option arguments.  In this case, it will be the filename to be
  326.  * loaded.  At present, only one filename will be handled.  So if there are multiple filenames typed, the last one will be loaded.
  327.  */
  328. void CheckOptions(argc, argv)
  329.      int     argc;
  330.      char     **argv;
  331. {
  332.   int optionChar;  
  333.   int option_index = 0;
  334.   static struct option long_options[] =
  335.   {
  336.     {"hostname", 1, 0, 'h'},
  337.     {"portnumber", 1, 0, 'p'},
  338.     {"autoPlay", 0, 0, 'P'},
  339.     {"autoQuit", 0, 0, 'Q'},
  340.     {0, 0, 0, 0}
  341.   };
  342.  
  343.   while (1)                                /* Start parsing all known options */
  344.   {
  345.     optionChar = getopt_long_only (argc, argv, "h:p:PQ",
  346.                   long_options, &option_index);
  347.     if (optionChar == EOF)                        /* Done with all known options */
  348.       break;
  349.     switch (optionChar)
  350.     {
  351.      case 'h':
  352.       if (optarg) 
  353.     strcpy (TimeLineHostname, optarg);
  354.       break;
  355.      case 'p':
  356.       if (optarg) 
  357.     ReceiverPortNumber = atoi(optarg);
  358.       break;
  359.      case 'P':
  360.       autoPlay = True;
  361.       break;
  362.      case 'Q':
  363.       autoQuit = True;
  364.       break;
  365.      default:
  366.       Usage();
  367.       exit(1);
  368.       break;
  369.     }
  370.   }
  371.   if (optind < argc)                            /* Check if a filename has been specified */
  372.   {
  373.     startFilename = (char *) malloc (256);
  374.     strcpy (startFilename, argv[optind]);
  375.   }
  376. }
  377.  
  378. /* 
  379.  * This is the interpose function for the frame destroy procedure.  It is called when the quit button is pressed, or when the frame's "Quit"
  380.  * menu selection is chosen.
  381.  * The frame destroying process happens in two phases (meaning this function will be called twice).  The first time it is called, status =
  382.  * DESTROY_CHECKING (this is done automatically by XView).  At this point, the interpose function can choose to veto the destruction, or 
  383.  * let it proceed to phase two, where the actual destruction occurs.
  384.  * If it is the clipboard, veto the destruction (just hide it).
  385.  * If there are unsaved changes and the user chooses to abort the quit operation, also veto the destruction.
  386.  * If a destruction is to happen, update the window count variable (numberOfWindows) and check if it is the last existing window to be destroyed.
  387.  * If so, destroy the clipboard as well.
  388.  * If quitAll == 1, destroy all other frames as well.  This is done 'recursively'.  The frame being destroyed will destroy the next frame.  This
  389.  * next frame will then destroy the following one and so on.
  390.  *
  391.  */
  392. Notify_value QuitNotify(client, status)
  393.      Notify_client client;
  394.      Destroy_status status;
  395. {
  396.   int whichWindow;
  397.   TimeLineFramePtr tlFrame;
  398.   TimeLine_window_objects * ip = (TimeLine_window_objects *) xv_get(client, XV_KEY_DATA, INSTANCE);
  399.  
  400.   whichWindow = xv_get(ip->controls, PANEL_CLIENT_DATA);
  401.   tlFrame = TimeLineWindow[whichWindow];
  402.   if (status == DESTROY_CHECKING)                    /* Check to see if we really want to destroy the frame */
  403.   {
  404.     if (whichWindow == 0 && numberOfWindows > 0)            /* If it is the clipboard, do not destroy, just hide it */
  405.     {
  406.       xv_set(tlFrame->TimeLine_window->window, XV_SHOW, FALSE, NULL);
  407.       return notify_veto_destroy(client);
  408.     }
  409.     if (CheckChanges(QuitTimeLine, tlFrame) == NOTICE_YES)   /* check if unsaved changes exist */
  410.       return notify_veto_destroy(client);
  411.   }
  412.   else                                    /* Second phase. Proceed to destroy */
  413.   {
  414.     if (whichWindow != 0)                        /* Update the count of windows still existing */
  415.     {
  416.       numberOfWindows --;
  417.       WindowFree[whichWindow] = 0;
  418.     }
  419.     if (numberOfWindows > 0 && quitAll == 1)                /* Destroy the next window in use. */
  420.     {
  421.       while (WindowFree[whichWindow] == 0) 
  422.       {
  423.     if (whichWindow == MaxWindows - 1)
  424.       whichWindow = 1;
  425.     else
  426.       whichWindow ++;
  427.       }
  428.       xv_destroy_safe(TimeLineWindow[whichWindow]->TimeLine_window->window);
  429.     }
  430.     else 
  431.       quitAll = 1;
  432.     if (numberOfWindows == 0 && whichWindow != 0)            /* Destroy the clipboard if it is the only window left open */
  433.       xv_destroy_safe(TimeLineWindow[0]->TimeLine_window->window);  
  434.     if (tlFrame->TimeLineSender && tlFrame->TimeLineReceiver)        /* Check that sender exists before attempting to disconnect */
  435.       SenderDisconnectFromPortMgr(tlFrame->TimeLineSender, 
  436.                   &(tlFrame->TimeLineReceiver->receivePort)); /* Disconnect the TimeLine frame from the PortManager */
  437.     return notify_next_destroy_func(client, status);
  438.   }
  439.   return NOTIFY_DONE;
  440.     
  441.  
  442. /*
  443.  * This function initializes a TimeLine frame window.  It first forms
  444.  * a connection with the Port Manager and creates a sender and receiver.
  445.  * The Insert Blank Time, Info, Pause, and Region popup windows are then
  446.  * initialized.  Next, the variables used for controlling the TimeLine
  447.  * are initialized.  The stop menu button is made inactive.  The
  448.  * OpenAppsInitialize function is called to get the list of open
  449.  * applications from the Port Manager.  This is done only if the frame is
  450.  * not the Clipboard, that is, whichFrame != 0.  If the frame is the
  451.  * clipboard, call the DimButtons procedure twice to disable some of the
  452.  * menu functions.  Canvas Init is now called to set the size of the
  453.  * canvases and also the colormap.  Check if a file is to be loaded if
  454.  * this is the first TimeLine frame to be opened.  xv_main_loop is called
  455.  * if it is the first frame created, else it is just necessary to make
  456.  * XV_SHOW to TRUE for the frame, as the Notifier would already have been
  457.  * started.  If it is the first frame created, call the TimeLineInit
  458.  * function again to create the clipboard frame.  Called by main
  459.  * (TimeLine.c) and NewHandler (file.c)
  460.  */
  461. void TimeLineInit(tlFrame, whichFrame)
  462.      TimeLineFramePtr tlFrame;
  463.      int whichFrame;
  464. {
  465.   Rect rect;
  466.   char buf[40];
  467.  
  468.   tlFrame->TimeLine_window = TimeLine_window_objects_initialize(NULL, NULL); /* Initialize user interface components. */
  469.   xv_set(tlFrame->TimeLine_window->controls,                /* To distinguish this frame from the others */
  470.      PANEL_CLIENT_DATA, whichFrame, NULL);
  471.   notify_interpose_destroy_func(tlFrame->TimeLine_window->window,   /* Interpose the destroy function */
  472.                 QuitNotify);
  473.   tlFrame->TimeLineSender = NULL;
  474.   if (whichFrame != 0)                            /* Register with Port Manager if this is not the clipboard */
  475.   {
  476.     tlFrame->TimeLinePort.hostName = TimeLineHostname;            /* Initialize link with Port Manager */
  477.     tlFrame->TimeLinePort.portNumber = PortMgrPortNumber;
  478.     tlFrame->TimeLineSender = NewSender(&(tlFrame->TimeLinePort));
  479.     if (!tlFrame->TimeLineSender) 
  480.     {
  481.       AlertMessage(tlFrame, "The PortManager is not running.", 
  482.            "Please check that it is running and try again.", NULL);
  483.       return;
  484.     }
  485.     tlFrame->TimeLineReceiver = NewReceiver(tlFrame->TimeLineSender, TimeLineName, ReceiverPortNumber);
  486.   }
  487.   tlFrame->InsertBlankTimePopup = 
  488.     BlankTime_InsertBlankTimePopup_objects_initialize(NULL,        /* Initialize insert blank time popup window */
  489.                               tlFrame->TimeLine_window->window);
  490.   tlFrame->InfoPopup = Info_InfoPopup_objects_initialize(NULL, tlFrame->TimeLine_window->window);
  491.   tlFrame->PausePopup = Pause_PausePopup_objects_initialize(NULL, tlFrame->TimeLine_window->window);
  492.   tlFrame->RegionPopup = Region_RegionPopup_objects_initialize(NULL, tlFrame->TimeLine_window->window);
  493.   tlFrame->PortManagerPopup = ConnectPortManager_PortManagerPopup_objects_initialize(NULL, tlFrame->TimeLine_window->window);
  494.   if (whichFrame != 0)                        
  495.   {
  496.     sprintf(buf, "Current Port Manager : %s\n", tlFrame->TimeLinePort.hostName);
  497.     xv_set(tlFrame->PortManagerPopup->CurrentPortManagerMsg, PANEL_LABEL_STRING, buf, NULL);
  498.   }
  499.   CreateBrowse(OpenHandler, SaveHandler, tlFrame->TimeLine_window->window);
  500.   NormalCursor(tlFrame);
  501.   rect.r_left = 100;                            /* Set the position of the main frame */
  502.   rect.r_top = 250;
  503.   rect.r_width = (int) xv_get(tlFrame->TimeLine_window->window, XV_WIDTH);
  504.   rect.r_height = (int) xv_get(tlFrame->TimeLine_window->window, XV_HEIGHT) ;
  505.   frame_set_rect(tlFrame->TimeLine_window->window, &rect);        
  506.   xv_set(tlFrame->InfoPopup->InfoPopup,                    /* Set the position of the info popup window */
  507.      XV_X, 250,
  508.      XV_Y, 250,
  509.      NULL);
  510.   xv_set(tlFrame->PortManagerPopup->PortManagerPopup,            /* Set the position of the port manager popup window */
  511.      XV_X, 250,
  512.      XV_Y, 250,
  513.      NULL);
  514.   xv_set(tlFrame->InsertBlankTimePopup->InsertBlankTimeChoice,        /* Set choice item in insert blank time panel to exclusive */
  515.      PANEL_CHOOSE_NONE, FALSE,
  516.      PANEL_CHOOSE_ONE, TRUE, 
  517.      PANEL_VALUE, 1, NULL);
  518.   xv_set(tlFrame->PausePopup->PauseChoice,                /* Set choice item in pause marker info window to exclusive */
  519.      PANEL_CHOOSE_NONE, FALSE,
  520.      PANEL_CHOOSE_ONE, TRUE, 
  521.      PANEL_VALUE, 0, NULL);
  522.   if (whichFrame == 0) 
  523.     sprintf(buf, "Clipboard");
  524.   else 
  525.     sprintf (buf, "Document %d\n", whichFrame);
  526.   xv_set(tlFrame->InsertBlankTimePopup->TimeLineDocMsg,            /* Indicate which TimeLine document popup windows belong to */
  527.      PANEL_LABEL_STRING, buf, NULL);
  528.   xv_set(tlFrame->PausePopup->TimeLineDocMsg,    
  529.      PANEL_LABEL_STRING, buf, NULL);
  530.   xv_set(tlFrame->RegionPopup->TimeLineDocMsg,    
  531.      PANEL_LABEL_STRING, buf, NULL);
  532.   tlFrame->TimeLineLength = 1800;                    /* Set length of canvas to 1800 pixels long */
  533.   tlFrame->canvasStart = 0;                        /* Initialization of tlFrame variables */
  534.   tlFrame->areaSelected = 0;
  535.   tlFrame->noteSelected = 0;
  536.   tlFrame->gridSpacing = 0;
  537.   tlFrame->change = 0;
  538.   tlFrame->numberOfApps = 0;
  539.   tlFrame->chosenApp = -1;
  540.   tlFrame->lastX = -1;
  541.   tlFrame->startX = tlFrame->endX = 0;
  542.   tlFrame->startY = tlFrame->endY = 0;
  543.   tlFrame->startnoteX = tlFrame->endnoteX = 0;
  544.   tlFrame->startnoteY = tlFrame->endnoteY = 0;
  545.   tlFrame->zoomLevel = 1;
  546.   tlFrame->selectedInstrument = NULL;
  547.   tlFrame->noteInstrument = NULL;
  548.   tlFrame->instHead = NULL;
  549.   tlFrame->pauseHead = NULL;
  550.   tlFrame->selectedPause = NULL;
  551.   tlFrame->donePause = NULL;
  552.   tlFrame->numPause = 0;
  553.   tlFrame->pauseEdit = -1;
  554.   tlFrame->status = StopMode;
  555.   tlFrame->regionHead = NULL;
  556.   tlFrame->selectedRegion = NULL;
  557.   tlFrame->numRegion = 0;
  558.   tlFrame->regionEdit = -1;
  559.   tlFrame->syncHints = NoSyncHintsAvailable;                /* No synchronization hints are available for this document */
  560.   xv_set(tlFrame->TimeLine_window->stopButton, PANEL_INACTIVE, TRUE, NULL);
  561.   xv_set(tlFrame->TimeLine_window->pauseButton, PANEL_INACTIVE, TRUE, NULL);
  562.   strcpy (tlFrame->filename, "untitled");
  563.   UpdateHeader(tlFrame, 0);
  564.   CanvasInit(tlFrame);                            /* Initialize the canvases */
  565.   if (whichFrame != 0) 
  566.     OpenAppsInitialize(tlFrame, 1);                    /* Check with the PortManager for the open applications */
  567.   else 
  568.   {
  569.     DimButtons(1, TimeLineWindow[0]);
  570.     DimButtons(0, TimeLineWindow[0]);                    /* Disable some of the menu functions */
  571.   }    
  572.   WindowFree[whichFrame] = 1;
  573.   if (initialStart == 1)
  574.   {
  575.     initialStart = 0;
  576.     numberOfWindows++;
  577.     TimeLineInit(TimeLineWindow[0], 0);                    /* Create the clipboard frame */
  578.     (void) notify_enable_rpc_svc (TRUE);                /* Enable XView to detect RPC events */
  579.     if (startFilename != NULL)                        /* Check if a file is to be loaded */
  580.     {
  581.       Browse(startFilename, BrowseCheckOpen, 1,
  582.          "#TimeLine Edit Document", "TimeLine Editor");
  583.       if (autoPlay == True)                        /* Was a command-line option set to begin playback... */
  584.     Play(tlFrame->TimeLine_window->controls, MENU_NOTIFY);        /* ...immediately?  If so, begin playback now. */
  585.     }
  586.     xv_main_loop(tlFrame->TimeLine_window->window);            /* Turn control over to XView */
  587.   }
  588.   else if (whichFrame != 0)
  589.   {
  590.     numberOfWindows++;
  591.     xv_set(tlFrame->TimeLine_window->window, XV_SHOW, TRUE, NULL);  /* Notify already started, just show the frame */
  592.   }
  593. }
  594.  
  595. /*
  596.  * Checks if there are any unsaved changes to the current TimeLine document.  If so, it warns the user by using a notice prompt, and
  597.  * gives the user the choice of either going ahead with the operation or cancelling the operation.
  598.  * Called by Quit (TimeLine.c), ClearAllHandler (edit.c), Load (file.c) and UpdateAppsHandler (openApps.c) 
  599.  */
  600. int CheckChanges (optype, tlFrame)
  601.      int     optype;
  602.      TimeLineFramePtr tlFrame;
  603. {
  604.   int     result, whichWindow;
  605.   char     buf[100], buf1[100], buf2[100];
  606.  
  607.   result = NOTICE_NO;
  608.   if (tlFrame->change && tlFrame->numberOfApps > 0)            /* Perform the following only if there are unsaved changes and there are apps open */
  609.   {  
  610.     switch (optype) 
  611.     {
  612.      case LoadFile :                            /* Loading a new document */
  613.       sprintf (buf, "Loading a file will cause all changes to be lost.");
  614.       sprintf (buf1, "Go ahead and load the file?");
  615.       break;
  616.      case ClearAll :                            /* Clearing the TimeLine */
  617.       sprintf (buf, "This clear all operation will cause all changes to be lost.");
  618.       sprintf (buf1, "Go ahead and clear the TimeLine?");
  619.       break;
  620.      case ConnectPM :                            /* Check in with a new port manager */
  621.       sprintf (buf, "Checking in with a new port manager will cause all changes to be lost.");
  622.       sprintf (buf1, "Go ahead and check in with new port manager?");
  623.       break;
  624.      case QuitTimeLine :                        /* Quit the TimeLine application */
  625.       sprintf (buf, "Quiting the TimeLine Editor will cause all changes to be lost.");
  626.       sprintf (buf1, "Go ahead and quit?");
  627.       break;
  628.      case CloseFile :
  629.       sprintf (buf, "Closing the file will cause all changes to be lost.");
  630.       sprintf (buf1, "Go ahead and close?");
  631.       break;       
  632.      default : 
  633.       break;
  634.     }
  635.     whichWindow = xv_get(tlFrame->TimeLine_window->controls, PANEL_CLIENT_DATA);
  636.     sprintf (buf2, "Unsaved changes exist in TimeLine Document %d.", whichWindow);
  637.     result = notice_prompt(tlFrame->TimeLine_window->window, NULL,
  638.                NOTICE_MESSAGE_STRINGS,
  639.                buf2, buf, buf1, NULL,
  640.                NOTICE_BUTTON_NO,       "Yes",
  641.                NOTICE_BUTTON_YES,      "No",
  642.                NULL);
  643.   }
  644.   return (result);
  645. }
  646.  
  647. /*
  648.  * This function will update the header of the TimeLine Editor frame to either the current document name, or untitled.
  649.  * It will also specify the status of the file, if it has been modified.
  650.  * Called by TimeLineInit (TimeLine.c)
  651.  */
  652. void UpdateHeader(TimeLineFramePtr    tlFrame,
  653.           int            modified)
  654. {
  655.   char    label[100];
  656.   char    synchronizedLabel[32];
  657.   char    modifiedLabel[32];
  658.   int    whichFrame;
  659.   
  660.   whichFrame = xv_get(tlFrame->TimeLine_window->controls, PANEL_CLIENT_DATA);
  661.   if (whichFrame == 0)                            /* Request to show clipboard */
  662.     sprintf(label, "TimeLine Editor Clipboard");
  663.   else
  664.   {
  665.     if (tlFrame->syncHints == SyncHintsAvailable)
  666.       sprintf(synchronizedLabel, " (synchronized)");
  667.     else
  668.       sprintf(synchronizedLabel, "");
  669.     if (modified != 0)
  670.       sprintf(modifiedLabel, " (modified)");
  671.     else
  672.       sprintf(modifiedLabel, "");
  673.  
  674.       sprintf(label, "TimeLine Editor Document %d :  \"%s\"%s%s",
  675.           whichFrame, tlFrame->filename,
  676.           modifiedLabel, synchronizedLabel);
  677.   }
  678.   xv_set(tlFrame->TimeLine_window->window,                /* Set the frame header */
  679.      XV_LABEL, label,
  680.      NULL);
  681. }                                    /* end function UpdateHeader */
  682.  
  683.  
  684.  
  685. /*
  686.  * This function will displace a notice prompt, which is used to alert the user that something is wrong.
  687.  */
  688. void AlertMessage(tlFrame, msg1, msg2, msg3)
  689.      TimeLineFramePtr tlFrame;
  690.      char *msg1;
  691.      char *msg2;
  692.      char *msg3;
  693. {
  694.   notice_prompt(tlFrame->TimeLine_window->window, NULL,
  695.         NOTICE_MESSAGE_STRINGS,
  696.         msg1, msg2, msg3,
  697.         NULL,
  698.         NOTICE_BUTTON, "OK", 100,
  699.         NULL);
  700.   
  701. }
  702.  
  703. /*
  704.  * This function will get the bits of the unknown icon, create a server image of it and store it in the unknownIcon variable.
  705.  */
  706. void GetUnknownIcon()
  707. {
  708.   static unsigned short iconBits[] = 
  709.   {
  710. #include "icons/UnknownIcon"
  711.   };
  712.  
  713.   unknownIcon = (Server_image) xv_create(NULL, SERVER_IMAGE,
  714.                   SERVER_IMAGE_BITS, iconBits,
  715.                   SERVER_IMAGE_DEPTH, 1,
  716.                   XV_WIDTH, 64,
  717.                   XV_HEIGHT, 64,
  718.                   NULL);
  719. }
  720.  
  721.  
  722. void Usage()
  723. {
  724.   fprintf(stderr, "Usage: TimeLine <documentName> <options>\n");
  725.   fprintf(stderr, "\tOptions include:\n");
  726.   fprintf(stderr, "\t-autoPlay : When a documentName is specified, this option\n");
  727.   fprintf(stderr, "\t            tells TimeLine to begin playback of the document\n");
  728.   fprintf(stderr, "\t            immediately after it has been opened.\n");
  729.   fprintf(stderr, "\t-autoQuit : When a documentName is specified, this option\n");
  730.   fprintf(stderr, "\t            tells TimeLine to quit immediately after playback\n");
  731.   fprintf(stderr, "\t            of that document has ended.\n");
  732.   fprintf(stderr, "\t            Note: This option is only valid if the -autoPlay\n");
  733.   fprintf(stderr, "\t                  option has also been set.\n");
  734.   fprintf(stderr, "\t-hostname : name of the computer with which TimeLine will\n");
  735.   fprintf(stderr, "\t            register itself and ask the PortManager for\n");
  736.   fprintf(stderr, "\t            other media editors.\n");
  737.   return;
  738. }                                    /* end function Usage */
  739.