home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / dtr / waveedit.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-15  |  8.7 KB  |  268 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/DTR/RCS/waveedit.c,v 1.0 92/01/07 14:25:00 drapeau Exp Locker: derek $ */
  25. /* $Log:    waveedit.c,v $
  26.  * Revision 1.0  92/01/07  14:25:00  drapeau
  27.  * Removed unneeded code, due to simplification of the interface.
  28.  * Also, Made a number of cosmetic changes to make code easier to read and
  29.  * to conform to programming specifications.
  30.  * 
  31.  * Revision 0.19  91/09/30  16:13:22  derek
  32.  * DTR will now disconnect from the Port Manager when it quits.  Also,
  33.  * a number of printf statements are removed.
  34.  * 
  35.  * Revision 0.18  91/09/18  22:47:40  derek
  36.  * The following things are done:
  37.  * 1.    The Makefile is changed corresponding to the changes in collab/.
  38.  * 2.    Copyright messages included.
  39.  * 3.    Some minor bugs fixed.
  40.  * 
  41.  * Revision 0.17  91/08/14  16:14:16  derek
  42.  * Fixed a few saving/appending bugs.
  43.  * 
  44.  * Revision 0.16  91/08/07  16:24:53  derek
  45.  * The Edit list part of DTR is done.  OpenPanel is also incorporated.
  46.  * 
  47.  * Revision 0.15  91/07/23  21:25:45  derek
  48.  * This version is not ready for release.  Disk space editing is half-done:
  49.  * the application can play an infinite sound and the canvases can handle
  50.  * infinite sound files.  The app is pretty bug free too, I think.  The
  51.  * weakness is that it cannot record sond infinitely.
  52.  * 
  53.  * Revision 0.14  91/06/26  15:55:58  derek
  54.  * I have reformatted the code to conform coding specs.
  55.  * 
  56.  * Revision 0.13  91/06/25  11:40:12  derek
  57.  * I have added the new protocol items.
  58.  * 
  59.  * Revision 0.12  91/06/20  20:01:25  derek
  60.  * The network part should be working.  Also fixed a number of bugs involving
  61.  * canvases and display.
  62.  * 
  63.  * Revision 0.11  91/06/05  15:00:14  derek
  64.  * checking in after porting the code to collab
  65.  * 
  66.  * Revision 0.10  1991/04/25  01:54:04  derek
  67.  * This version is checked in on 4/24/91
  68.  * */
  69. static char rcsid[] = "$Header: /Source/Media/collab/DTR/RCS/waveedit.c,v 1.0 92/01/07 14:25:00 drapeau Exp Locker: derek $";
  70.  
  71. #include "dtr.h"              
  72. #include "dtr_ui.h"
  73.  
  74. BOOL       CutPortionReady;                        /*  Global variable to indicate that a cut...       */
  75.                                                                     /*  ...portion is currently in memory.              */
  76. BOOL       AboutToCopy;
  77. BOOL       AboutToPaste;
  78.  
  79. void
  80.   InitWaveEditVariables()
  81. {
  82.   CutPortionReady = FALSE;
  83.   AboutToCopy = FALSE;
  84.   AboutToPaste = FALSE;
  85.   CanUndo = FALSE;
  86.   BufferSaved = TRUE;
  87. /*  WaveEditMode = TRUE;*/
  88.   WaveEditMode = FALSE;
  89. }
  90.  
  91.  
  92. /*
  93.  *  Handles "cut" (by edit-menu).
  94.  */
  95. void
  96.   WaveCutHandler()
  97. {
  98.   int             size;
  99.   unsigned char   *newdata;
  100.   int             RightIntMarker;
  101.   int             LeftIntMarker;
  102.   double          saveZoom;
  103.   int             saveScrollbarViewStart;
  104.   extern Scrollbar   WaveCanvasScrollbar;
  105.   
  106.   saveZoom = Zoom;                            /*  Save old values.                                */
  107.   saveScrollbarViewStart = xv_get(WaveCanvasScrollbar, 
  108.                   PANEL_VALUE, 
  109.                   SCROLLBAR_VIEW_START);
  110.   
  111.   if (!WaveCanvasRightMarkerSet ||                    /*  If markers are not set (ie. no wave segment...  */
  112.       !GlobalWaveCanvasRightMarkerSet)                    /*  ...is chosen (highlighted) yet, return...       */
  113.     return;                                /*  ...without doing anything.                      */
  114.   
  115.   RightIntMarker = irint(oldRightFloatMarker);
  116.   LeftIntMarker = irint(oldLeftFloatMarker);
  117.   size = (RightIntMarker - LeftIntMarker)+1;
  118.   
  119.   AllocCutBuffer(size);                            /*  Save the highlighted portion into CutBuffer...  */
  120.   memcpy(CutBuffer.data, &Buffer.data[LeftIntMarker], size);        /*  ...for future use.                              */
  121.   CutPortionReady = TRUE;
  122.   
  123.   newdata = (unsigned char *) malloc(Buffer.hdr.data_size - size);  /*  Delete the highlithged portion from the...      */
  124.   memcpy(newdata, Buffer.data, LeftIntMarker);                /*  ...sound buffer.                                */
  125.   memcpy(&newdata[LeftIntMarker], &Buffer.data[RightIntMarker+1],
  126.      Buffer.hdr.data_size - RightIntMarker - 1); 
  127.   
  128.   Buffer.old_hdr_data_size = Buffer.hdr.data_size;
  129.   Buffer.old_alloc_size = Buffer.alloc_size;
  130.   
  131.   Buffer.hdr.data_size -= size;
  132.   Buffer.alloc_size = (unsigned int) Buffer.hdr.data_size;
  133.   free(Buffer.olddata);
  134.   Buffer.olddata = Buffer.data;
  135.   Buffer.data = newdata;
  136.   
  137.   Buffer.play.start = 0;
  138.   Buffer.play.end = Buffer.hdr.data_size - 1;
  139.   ResetWaveCanvas();
  140.   ResetGlobalWaveCanvas();
  141.   Zoom = saveZoom;
  142.   RepaintWaveCanvas();
  143.   xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START,
  144.      saveScrollbarViewStart, NULL);
  145.   RepaintGlobalWaveCanvas();
  146.   UpdateMessageDisplay();
  147.   UpdateSelection();
  148.   CanUndo = TRUE;
  149.   BufferSaved = FALSE;
  150.   UpdateHeader(TRUE);
  151. }                                    /* end function WaveCutHandler */
  152.  
  153.  
  154. /*
  155.  *  Handles "copy" (by edit-menu).
  156.  */
  157. void
  158.   WaveCopyHandler(insertPoint)
  159. int  insertPoint;
  160. {
  161.   int             size;
  162.   unsigned char   *newdata;
  163.   int             RightIntMarker;
  164.   int             LeftIntMarker;
  165.   
  166.   RightIntMarker = irint(oldRightFloatMarker);
  167.   LeftIntMarker = irint(oldLeftFloatMarker);
  168.   size = (RightIntMarker - LeftIntMarker)+1;
  169.   AllocCutBuffer(size);                            /*  Save the highlighted portion into CutBuffer...  */
  170.   memcpy(CutBuffer.data, &Buffer.data[LeftIntMarker], size);        /*  ...for future use.                              */
  171.   CutBuffer.alloc_size = size;
  172.   CutPortionReady = TRUE;
  173.   newdata = (unsigned char *) malloc(Buffer.hdr.data_size + size);
  174.   memcpy(newdata, Buffer.data, insertPoint);
  175.   memcpy(&newdata[insertPoint], &Buffer.data[LeftIntMarker], size);
  176.   memcpy(&newdata[insertPoint + size], &Buffer.data[insertPoint+1],
  177.      Buffer.hdr.data_size - insertPoint);
  178.   Buffer.old_hdr_data_size = Buffer.hdr.data_size;
  179.   Buffer.old_alloc_size = Buffer.alloc_size;
  180.   Buffer.hdr.data_size += size;
  181.   Buffer.alloc_size = (unsigned int) Buffer.hdr.data_size;
  182.   free(Buffer.olddata);
  183.   Buffer.olddata = Buffer.data;
  184.   Buffer.data = newdata;
  185.   ResetWaveCanvasMarkers();
  186.   ResetGlobalWaveCanvasMarkers();
  187.   RepaintWaveCanvas();
  188.   RepaintGlobalWaveCanvas();
  189.   UpdateMessageDisplay();
  190.   AboutToCopy = FALSE;
  191.   CanUndo = TRUE;
  192.   BufferSaved = FALSE;
  193.   UpdateHeader(TRUE);
  194. }                                    /* end function WaveCopyHandler */
  195.  
  196.  
  197. /*
  198.  *  Handles "paste" (by edit-menu).  It takes a "cut" wave portion and 
  199.  *  inserts it into the current sound buffer.
  200.  */
  201. void
  202.   WavePasteHandler(insertPoint)
  203. int  insertPoint;
  204. {
  205.   unsigned char   *newdata;
  206.   
  207.   newdata = (unsigned char *) malloc(Buffer.hdr.data_size + 
  208.                      CutBuffer.alloc_size);
  209.   memcpy(newdata, Buffer.data, insertPoint);
  210.   memcpy(&newdata[insertPoint], CutBuffer.data, CutBuffer.alloc_size);
  211.   memcpy(&newdata[insertPoint + CutBuffer.alloc_size], 
  212.      &Buffer.data[insertPoint+1], 
  213.      Buffer.hdr.data_size - insertPoint);
  214.   
  215.   Buffer.old_hdr_data_size = Buffer.hdr.data_size;
  216.   Buffer.old_alloc_size = Buffer.alloc_size;
  217.   
  218.   Buffer.hdr.data_size += CutBuffer.alloc_size;
  219.   Buffer.alloc_size = (unsigned int) Buffer.hdr.data_size;
  220.   free(Buffer.olddata);
  221.   
  222.   Buffer.olddata = Buffer.data;
  223.   Buffer.data = newdata;
  224.   
  225.   Buffer.play.start = 0;                        /*  Reset all the sound and display parameters.     */
  226.   Buffer.play.end = Buffer.hdr.data_size - 1;
  227.   ResetWaveCanvas();
  228.   ResetGlobalWaveCanvas();
  229.   RepaintWaveCanvas();
  230.   RepaintGlobalWaveCanvas();
  231.   UpdateMessageDisplay();
  232.   
  233.   AboutToPaste = FALSE;
  234.   CanUndo = TRUE;
  235.   BufferSaved = FALSE;
  236.   UpdateHeader(TRUE);
  237. }                                    /* end function WavePasteHandler */
  238.  
  239.  
  240. void
  241.   AllocCutBuffer(size)
  242. int  size;
  243. {
  244.   if (CutBuffer.data != NULL)
  245.     (void) free((char *)CutBuffer.data);
  246.   CutBuffer.data = (unsigned char *) malloc(size);
  247.   if (CutBuffer.data == (unsigned char*)NULL)
  248.   {
  249.     fprintf(stderr, "Error:  Malloc failure in AllocCutBuffer");
  250.     exit(0);
  251.   }
  252.   CutBuffer.alloc_size = size;
  253. }
  254.  
  255.  
  256. void
  257.   SetWaveEditModeOn()
  258. {
  259.   WaveEditMode = TRUE;
  260. }
  261.  
  262.  
  263. void
  264.   SetWaveEditModeOff()
  265. {
  266.   WaveEditMode = FALSE;
  267. }
  268.