(FILECREATED "30-Jul-84 12:36:18" {ERIS}<SPEECH>SCALEDWINDOW.FPKG;31 32329  

      changes to:  (FNS PRINT.SPEECH.FILE DISPLAY.FILE)

      previous date: "17-Jul-84 12:40:00" {ERIS}<SPEECH>SCALEDWINDOW.FPKG;29)


(* Copyright (c) 1984 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT SCALEDWINDOWCOMS)

(RPAQQ SCALEDWINDOWCOMS ((FNS DISPLAY.FILE DRAWDOTTEDLINE FIRST.TIC OLD.USER.CREATE.MENU 
			      SCALED.WINDOW.PRINT.SCALES SCROLL SCALED.WINDOW.CLEARW 
			      PRINT.SCALE.NUMBERS PRINT.SPEECH.FILE 
			      RESHAPE.SPEECH.DISPLAY.FILE.WINDOW SCALED.WINDOW.REPAINTFN 
			      SCALED.WINDOW.RESHAPEFN SCALED.WINDOW.SCROLLFN SCALED.WINDOW.SETUP SDF 
			      SETY0 SET.Y.SCALE.FACTOR SPEECH.COPY.ARRAY.TO.WAVE 
			      SPEECH.PRINT.WAVE.ARRAY)
	(VARS Y.AXIS.LINE.WIDTH)))
(DEFINEQ

(DISPLAY.FILE
  [LAMBDA (FILE PTR)                                         (* pkh: "13-Jul-84 05:42")
                                                             (* Alternative to SPEECH.DISPLAY.FILE for displaying a 
							     waveform; gives you a scrollable window)
    (COND
      ((NULL PTR)                                            (* If no info about where to start printing in the file 
							     go to the beginning)
	(SETQ PTR 0)))
    (PROG (STARTX STARTY WIDTH HEIGHT WINDOW)
          (SETQ FILE (FULLNAME FILE 'OLD))
          (SETQ WINDOW (CREATEW NIL FILE))
          (SETQ STARTX (DSPXPOSITION NIL WINDOW))
          (SETQ STARTY (DSPYPOSITION NIL WINDOW))            (* Associate the file with the window)
          (WINDOWPROP WINDOW 'FILE FILE)
          (SCALED.WINDOW.SETUP WINDOW -128 128 30 30 'PRINT.SPEECH.FILE NIL 2)
                                                             (* Set the extent so we can scroll)
                                                             (* SCALED.WINDOW.RESHAPEFN WINDOW)
          (WINDOWPROP WINDOW 'EXTENT
		      (create REGION
			      LEFT ← STARTX
			      BOTTOM ← STARTY
			      HEIGHT ← -1
			      WIDTH ← (GETFILEINFO FILE 'LENGTH])

(DRAWDOTTEDLINE
  [LAMBDA (X1 Y1 X2 Y2 WIDTH WINDOW DOTDISTANCE)             (* pkh: "26-Jun-84 12:53")
    (for POINT from X1 to X2 by (COND
				  (DOTDISTANCE DOTDISTANCE)
				  (T 2))
       do (DRAWLINE POINT Y1 POINT Y1 WIDTH 'PAINT WINDOW])

(FIRST.TIC
  [LAMBDA (LEFT.X.POS TIC.INTERVAL)                          (* pkh: "13-Jan-84 14:27")
                                                             (* Find where to draw the first tic;
							     ensure it is a multiple of the tic.interval)
    (COND
      ((IGEQ TIC.INTERVAL LEFT.X.POS)
	LEFT.X.POS)
      (T (IPLUS LEFT.X.POS (IDIFFERENCE TIC.INTERVAL (IREMAINDER LEFT.X.POS TIC.INTERVAL])

(OLD.USER.CREATE.MENU
  [LAMBDA NIL                                                (* pkh: "27-Dec-83 16:45")
    (PROG (MENU)
          (SETQ MENU (create MENU
			     TITLE ← "USER MENU"
			     ITEMS ← USER.PNAMES
			     MENUCOLUMNS ← 6
			     WHENSELECTEDFN ← 'USER.WHENSELECTEDFN))
          (ATTACHMENU MENU USER.WINDOW 'CENTER 'TOP (GETBOXPOSITION (fetch (MENU IMAGEWIDTH)
								       of MENU)
								    (fetch (MENU IMAGEHEIGHT)
								       of MENU)
								    NIL NIL NIL "Position USER MENU"))
          (GETBOXPOSITION (fetch (MENU IMAGEWIDTH) of MENU)
			  (fetch (MENU IMAGEHEIGHT) of MENU)
			  NIL NIL NIL "Position USER MENU")
          (RETURN MENU])

(SCALED.WINDOW.PRINT.SCALES
  [LAMBDA (WINDOW REG)                                       (* pkh: "13-Jul-84 02:43")
                                                             (* Clears a scaled window and repaints the scales)
    (PROG (LEFT.Y.SCALE.OFFSET YPOS.FOR.XSCALE YMIN Y.SCALE.FACTOR BOTTOM.X.SCALE.OFFSET WIDTH 
			       LEFT.START.POS NUMBER.FONT)   (* Get the parameters)
          (SETQ NUMBER.FONT (WINDOWPROP WINDOW 'NUMBER.FONT))
          (SETQ YMIN (WINDOWPROP WINDOW 'YMIN))
          (SETQ YMAX (WINDOWPROP WINDOW 'YMAX))
          (SETQ Y.SCALE.FACTOR (WINDOWPROP WINDOW 'Y.SCALE.FACTOR))
          (SETQ YPOS.FOR.XSCALE (WINDOWPROP WINDOW 'YPOS.FOR.XSCALE))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ LEFT.Y.SCALE.OFFSET (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET))
          [SETQ WIDTH (fetch (REGION WIDTH) of (WINDOWPROP WINDOW 'REGION]
                                                             (* Move to beginning of window)
                                                             (* MOVETO (WINDOWPROP WINDOW 
							     (QUOTE PPORIGX)) (WINDOWPROP WINDOW 
							     (QUOTE PPORIGY)) WINDOW)
                                                             (* Draw the x-scale)
                                                             (* IPLUS LEFT.Y.SCALE.OFFSET 
							     (OR (WINDOWPROP WINDOW (QUOTE PPORIGX)) 0))
          (SETQ LEFT.START.POS (COND
	      (REG (IPLUS LEFT.Y.SCALE.OFFSET (fetch (REGION LEFT) of REG)))
	      (T LEFT.Y.SCALE.OFFSET)))
          (DRAWLINE LEFT.START.POS YPOS.FOR.XSCALE (IPLUS (WINDOWPROP WINDOW 'WIDTH)
							  LEFT.START.POS)
		    YPOS.FOR.XSCALE 2 'PAINT WINDOW)         (* Print the numbers and tics on the x-scale)
          (PRINT.SCALE.NUMBERS WINDOW LEFT.START.POS)        (* Draw the y-axis)
          (DRAWLINE LEFT.START.POS YPOS.FOR.XSCALE LEFT.START.POS (WINDOWPROP WINDOW 'HEIGHT)
		    2
		    'PAINT WINDOW)                           (* Draw a 0-crossing if there is one)
          (COND
	    ((ILESSP (WINDOWPROP WINDOW 'YMIN)
		     0)                                      (* Y0 in the window coordinate system)
	      (SETQ Y0 (WINDOWPROP WINDOW 'Y0))
	      (DRAWDOTTEDLINE LEFT.START.POS Y0 (WINDOWPROP WINDOW 'WIDTH)
			      Y0 1 WINDOW 3)))               (* Print info pertaining to Y-scale)
          (COND
	    ((OR (NOT (EQUAL YMIN MIN.FIXP))
		 (NOT (EQUAL YMAX MAX.FIXP)))                (* Print YMAX)
	      (MOVETO (IDIFFERENCE LEFT.START.POS (IPLUS (STRINGWIDTH YMAX NUMBER.FONT)
							 2))
		      (IDIFFERENCE (WINDOWPROP WINDOW 'HEIGHT)
				   6)
		      WINDOW)                                (* TBW *)
	      (PRINT YMAX WINDOW)                            (* Print YMIN)
	      (MOVETO (IDIFFERENCE LEFT.START.POS (IPLUS (STRINGWIDTH YMIN NUMBER.FONT)
							 2))
		      YPOS.FOR.XSCALE WINDOW)
	      (PRINT YMIN WINDOW))
	    (T NIL])

(SCROLL
  [LAMBDA (WINDOW XDELTA YDELTA CONTINUOUSFLG)               (* hdj "12-Jul-84 18:15")
                                                             (* standard scrolling function that scrolls by blting 
							     existing bits and then calling the windows repaintfn to 
							     repaint the newly exposed bits.)
    (PROG ((DSP (WINDOWPROP WINDOW 'DSP))
	   (EXTENT (WINDOWPROP WINDOW 'EXTENT))
	   X CRHEIGHT CRWIDTH CRLEFT CRBOTTOM WHOLEHEIGHT WHOLEWIDTH)
          (SETQ X (DSPCLIPPINGREGION NIL DSP))
          (SETQ WHOLEWIDTH (fetch (REGION WIDTH) of X))
          (SETQ WHOLEHEIGHT (fetch (REGION HEIGHT) of X))
          [COND
	    ([NOT (SUBREGIONP WHOLEDISPLAY (WINDOWPROP WINDOW 'REGION]
                                                             (* reduce clipping region to be that part of the window 
							     that is on the screen.)
	      (SETQ X (INTERSECTREGIONS X (\DSPUNTRANSFORMREGION WHOLEDISPLAY (fetch IMAGEDATA
										 of DSP]
          (SETQ CRLEFT (fetch (REGION LEFT) of X))
          (SETQ CRBOTTOM (fetch (REGION BOTTOM) of X))
          (SETQ CRWIDTH (fetch (REGION WIDTH) of X))
          (SETQ CRHEIGHT (fetch (REGION HEIGHT) of X))

          (* only one of XDELTA or YDELTA should be non-zero but do both anyway. When both can be non-zero%, this code 
	  should avoid calling the repaintfn on the part of the object that is scrolled on by X but then scrolled off by Y.)

                                                             (* do X first because in the common case of printing it 
							     is faster to do it first.)
          [COND
	    ((FLOATP XDELTA)                                 (* thumb scroll%, XDELTA gives the fraction of the way 
							     from the left margin the cursor was.)
	      (COND
		[(AND EXTENT (NEQ (fetch (REGION WIDTH) of EXTENT)
				  -1))
		  (PROG (OLDX NEWX)                          (* if there is an extent%, calculate a value of XDELTA 
							     that moves to the proper place.
							     If there is not%, Don%'t do anything.)
		        [SETQ NEWX (IPLUS (fetch (REGION LEFT) of EXTENT)
					  (FIXR (FTIMES XDELTA (IDIFFERENCE (fetch (REGION WIDTH)
									       of EXTENT)
									    WHOLEWIDTH]
		        (SETQ OLDX (WXOFFSET NIL DSP))
		        (SETQ XDELTA (IDIFFERENCE OLDX NEWX]
		(T (SETQ XDELTA 0]
          [COND
	    (CONTINUOUSFLG                                   (* if continuous set it scroll by the linefeed height 
							     {no particularly good reason why the linefeed height but
							     why not}.)
			   (COND
			     ((EQ XDELTA 0))
			     [(IGREATERP XDELTA 0)           (* linefeed height is normally negative.)
			       (SETQ XDELTA (IMINUS (DSPLINEFEED NIL DSP]
			     (T (SETQ XDELTA (DSPLINEFEED NIL DSP]
          (COND
	    ((AND (NEQ XDELTA 0)
		  (COND
		    ((AND EXTENT (NEQ (fetch (REGION WIDTH) of EXTENT)
				      -1))                   (* limit amount by the extent)
                                                             (* for now limit right extent to right of window ETC. ie
							     keep it always visible.)
		      (SETQ XDELTA (IMIN (IDIFFERENCE CRLEFT (fetch (REGION LEFT) of EXTENT))
					 (IMAX (IDIFFERENCE (IPLUS CRLEFT CRWIDTH)
							    (fetch (REGION PRIGHT) of EXTENT))
					       XDELTA)))     (* make sure it is still not 0)
		      (NEQ XDELTA 0))
		    (T T)))                                  (* BITBLT WINDOW CRLEFT CRBOTTOM WINDOW 
							     (IPLUS XDELTA CRLEFT) CRBOTTOM CRWIDTH CRHEIGHT 
							     (QUOTE INPUT) (QUOTE REPLACE))
	      (WXOFFSET XDELTA DSP)
	      (SETQ CRLEFT (IDIFFERENCE CRLEFT XDELTA))

          (* REDISPLAYW WINDOW (COND ((IGREATERP XDELTA 0) (* moving to right%, create new region on left for repaintfn) 
	  (CREATEREGION CRLEFT CRBOTTOM (IMIN XDELTA CRWIDTH) CRHEIGHT)) (T (* moving to left.) (CREATEREGION 
	  (IMAX (IPLUS CRLEFT CRWIDTH XDELTA) CRLEFT) CRBOTTOM (IMIN (IMINUS XDELTA) CRWIDTH) CRHEIGHT))) T)


	      ))
          [COND
	    ((FLOATP YDELTA)                                 (* thumb scroll%, YDELTA gives the fraction of the way 
							     from the top margin the cursor was.)
	      (COND
		[(AND EXTENT (NEQ (fetch (REGION HEIGHT) of EXTENT)
				  -1))
		  (PROG (OLDY NEWY)                          (* if there is an extent%, calculate a value of YDELTA 
							     that moves to the proper place.
							     If there is not%, Don%'t do anything.)
		        (SETQ NEWY (IPLUS (IDIFFERENCE (FIXR (FTIMES (FDIFFERENCE 1.0 YDELTA)
								     (fetch (REGION HEIGHT)
									of EXTENT)))
						       WHOLEHEIGHT)
					  (fetch (REGION BOTTOM) of EXTENT)))
		        (SETQ OLDY (WYOFFSET NIL DSP))
		        (SETQ YDELTA (IDIFFERENCE OLDY NEWY]
		(T (SETQ YDELTA 0]
          [COND
	    (CONTINUOUSFLG                                   (* if continuous set it scroll by the linefeed height)
			   (COND
			     ((EQ YDELTA 0))
			     [(IGREATERP YDELTA 0)           (* linefeed height is normally negative.)
			       (SETQ YDELTA (IMINUS (DSPLINEFEED NIL DSP]
			     (T (SETQ YDELTA (DSPLINEFEED NIL DSP]
          (COND
	    ((AND (NEQ YDELTA 0)
		  (COND
		    ((AND EXTENT (NEQ (fetch (REGION HEIGHT) of EXTENT)
				      -1))                   (* limit amount by the extent)
		      (SETQ YDELTA (IMAX (IDIFFERENCE (SETQ X (PLUS CRBOTTOM CRHEIGHT))
						      (fetch (REGION PTOP) of EXTENT))
					 (IMIN (IDIFFERENCE (SUB1 X)
							    (fetch (REGION BOTTOM) of EXTENT))
					       YDELTA)))     (* make sure its still not 0)
		      (NEQ YDELTA 0))
		    (T T)))                                  (* move the current image if any of it is still in 
							     view.)
                                                             (* BITBLT WINDOW CRLEFT CRBOTTOM WINDOW CRLEFT 
							     (IPLUS YDELTA CRBOTTOM) CRWIDTH CRHEIGHT 
							     (QUOTE INPUT) (QUOTE REPLACE))
	      (WYOFFSET YDELTA DSP)                          (* use X as pointer to bottom in scrolled clipping 
							     region.)
	      (SETQ X (IDIFFERENCE CRBOTTOM YDELTA))

          (* REDISPLAYW WINDOW (COND ((IGREATERP YDELTA 0) (* moving up.) (CREATEREGION CRLEFT X CRWIDTH 
	  (IMIN YDELTA CRHEIGHT))) (T (* moving down%, fill in top) (CREATEREGION CRLEFT (IMAX (IPLUS CRHEIGHT X YDELTA) X) 
	  CRWIDTH (IMIN (IMINUS YDELTA) CRHEIGHT)))) T)


	      ))
          (RETURN])

(SCALED.WINDOW.CLEARW
  [LAMBDA (WINDOW)                                           (* pkh: "10-Jul-84 23:01")
                                                             (* Clears a scaled window and repaints the scales)
    (PROG (YPOS.FOR.XSCALE YMIN Y.SCALE.FACTOR BOTTOM.X.SCALE.OFFSET WIDTH LEFT.X.POS)
          (SETQ YMIN (WINDOWPROP WINDOW 'YMIN))
          (SETQ Y.SCALE.FACTOR (WINDOWPROP WINDOW 'Y.SCALE.FACTOR))
          (SETQ YPOS.FOR.XSCALE (WINDOWPROP WINDOW 'YPOS.FOR.XSCALE))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ WIDTH (WINDOWPROP WINDOW 'WIDTH))
          (SETQ LEFT.X.POS (OR (WINDOWPROP WINDOW 'PPORIGX)
			       0))
          (CLEARW WINDOW)
          (MOVETO (WINDOWPROP WINDOW 'PPORIGX)
		  (WINDOWPROP WINDOW 'PPORIGY)
		  WINDOW)                                    (* Draw X-scale)
                                                             (* DRAWLINE 0 Y0 WIDTH Y0 1 (QUOTE PAINT) SCOPE.WINDOW)
          (SCALED.WINDOW.PRINT.SCALES WINDOW])

(PRINT.SCALE.NUMBERS
  [LAMBDA (WINDOW LEFT.X.XPOS TIC.INTERVAL)                  (* pkh: "13-Jul-84 05:47")
                                                             (* Draws lines for tic marks;
							     and print numbers by the tics)
                                                             (* IF (NEQ 0 LEFT.X.POS) THEN 
							     (IPLUS LEFT.X.POS (IREMAINDER LEFT.X.POS TIC.INTERVAL)) 
							     ELSE 0)
    (PROG (NUMBER.WIDTH TEMP FLG LEFT.Y.SCALE.OFFSET INCREASEBETWEENTICS)
          (SETQ INCREASEBETWEENTICS (WINDOWPROP WINDOW 'INCREASEBETWEENTICS))
          (SETQ LEFT.Y.SCALE.OFFSET (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET))
          (DSPRIGHTMARGIN (fetch (REGION WIDTH) of (WINDOWPROP WINDOW 'EXTENT))
			  WINDOW)
          (COND
	    ((NULL TIC.INTERVAL)
	      (SETQ TIC.INTERVAL 20)))
          (SETQ TEMP (FIRST.TIC (IDIFFERENCE LEFT.X.XPOS LEFT.Y.SCALE.OFFSET)
				TIC.INTERVAL))
          (for I from TEMP to (IPLUS (WINDOWPROP WINDOW 'WIDTH)
				     LEFT.X.XPOS)
	     by 20 as J first (SETQ FLG 0) from (IDIFFERENCE LEFT.X.XPOS LEFT.Y.SCALE.OFFSET)
	     by (OR INCREASEBETWEENTICS 20)
	     do (SETQ NUMBER.WIDTH (STRINGWIDTH J (DSPFONT NIL WINDOW)))
		(MOVETO (IDIFFERENCE (IPLUS I LEFT.Y.SCALE.OFFSET)
				     (IQUOTIENT NUMBER.WIDTH 2))
			(IDIFFERENCE YPOS.FOR.XSCALE 13)
			WINDOW)
		(COND
		  ((ODDP FLG)
		    (PRIN1 J WINDOW)))
		(DRAWLINE (IPLUS I LEFT.Y.SCALE.OFFSET)
			  YPOS.FOR.XSCALE
			  (IPLUS I LEFT.Y.SCALE.OFFSET)
			  (IPLUS YPOS.FOR.XSCALE 4)
			  1
			  'PAINT WINDOW)
		(SETQ FLG (ADD1 FLG])

(PRINT.SPEECH.FILE
  [LAMBDA (WINDOW REGION FILE)                               (* pkh: "28-Jul-84 17:40")
    (PROG (STREAM Y Y0 X Y.SCALE.FACTOR BOTTOM.X.SCALE.OFFSET FILE)
          (SETQ FILE (WINDOWPROP WINDOW 'FILE))
          (SETQ Y.SCALE.FACTOR (WINDOWPROP WINDOW 'Y.SCALE.FACTOR))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ Y0 (WINDOWPROP WINDOW 'Y0))
          (SETQ STREAM (OPENSTREAM (WINDOWPROP WINDOW 'FILE)
				   'INPUT
				   'OLD))
          (SETFILEPTR STREAM (COND
			(REGION (fetch (REGION LEFT) of REGION))
			(T 0)))
          (while (NOT (EOFP STREAM)) as X from (COND
						 (REGION (fetch (REGION LEFT) of REGION))
						 (T 0))
	     to [COND
		  (REGION (IPLUS (fetch (REGION LEFT) of REGION)
				 (fetch (REGION WIDTH) of REGION)))
		  (T (WINDOWPROP WINDOW 'WIDTH]
	     do (SETQ Y (SPEECH.BIN STREAM))                 (* SETQ Y (CORRECT Y))
                                                             (* Center around Y=0)
		(DRAWLINE X Y0 X (IDIFFERENCE Y0 Y)
			  1
			  'PAINT WINDOW))
          (CLOSEF STREAM])

(RESHAPE.SPEECH.DISPLAY.FILE.WINDOW
  [LAMBDA (WINDOW)                                           (* pkh: "28-Dec-83 22:50")
    (PROG (BTM)
          (DSPRESET WINDOW)
          (WINDOWPROP WINDOW 'PPORIGX (DSPXPOSITION NIL WINDOW))
          (WINDOWPROP WINDOW 'PPORIGY (DSPYPOSITION NIL WINDOW))
          (SPEECH.DISPLAY.FILE.REPAINTFN WINDOW])

(SCALED.WINDOW.REPAINTFN
  [LAMBDA (WINDOW REGION)                                    (* hdj "17-Jul-84 12:19")
                                                             (* Calls the PRINTFN for the window with the arguments 
							     REGION FILE and WINDOW)
    (PROG ((FASTREDISPLAY? (GETWINDOWPROP WINDOW 'CONTINUOUSREDISPLAY))
	   HEIGHT GRAPHHEIGHT WIDTH BOTTOM.X.SCALE.OFFSET YMIN YPOS.FOR.XSCALE Y.SCALE.FACTOR 
	   X.SCALE.FACTOR LEFT.X.POS X Y0 Y REG LEFT.Y.SCALE.OFFSET)
                                                             (* We want the WHOLE window redisplayed;
							     so we throw away REGION and instead we use REG)
          (SETQ HEIGHT (WINDOWPROP WINDOW 'HEIGHT))
          (SETQ GRAPHHEIGHT (WINDOWPROP WINDOW 'GRAPHHEIGHT))
          (SETQ WIDTH (WINDOWPROP WINDOW 'WIDTH))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ LEFT.Y.SCALE.OFFSET (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET))
          (SETQ YMIN (WINDOWPROP WINDOW 'YMIN))
          (SETQ YPOS.FOR.XSCALE (WINDOWPROP WINDOW 'YPOS.FOR.XSCALE))
          (SETQ Y.SCALE.FACTOR (WINDOWPROP WINDOW 'Y.SCALE.FACTOR))
          (SETQ X.SCALE.FACTOR (WINDOWPROP WINDOW 'X.SCALE.FACTOR))
          (SETQ Y0 (WINDOWPROP WINDOW 'Y0))
          (SETQ REG (COPY (DSPCLIPPINGREGION NIL WINDOW)))
          (replace (REGION LEFT) of REG with (IPLUS LEFT.Y.SCALE.OFFSET (fetch (REGION LEFT)
									   of REG)))
          (replace (REGION WIDTH) of REG with (IDIFFERENCE (fetch (REGION WIDTH) of REG)
							   LEFT.Y.SCALE.OFFSET))
          (SETQ LEFT.X.POS (COND
	      (REG (fetch (REGION LEFT) of REG))
	      (T LEFT.Y.SCALE.OFFSET)))                      (* On first call when window is set up REGION = NIL is 
							     OK here; PPORGIX and PPORIGY are set by 
							     SCALED.WINDOW.RESHAPEFN)
          (MOVETO (WINDOWPROP WINDOW LEFT.X.POS)
		  (WINDOWPROP WINDOW 'PPORIGY)
		  WINDOW)                                    (* Perform the printing operations)
          (APPLY (WINDOWPROP WINDOW 'PRINTFN)
		 (LIST WINDOW REG))                          (* CHANGED -
							     to bring into line with REPAINTFN conventions)
                                                             (* Draw the bottom x-scale; will be numbered and tacked)

          (* (DRAWLINE LEFT.X.POS YPOS.FOR.XSCALE (IPLUS (WINDOWPROP WINDOW (QUOTE WIDTH)) LEFT.X.POS) YPOS.FOR.XSCALE 2 
	  (QUOTE PAINT) WINDOW) (PRINT.SCALE.NUMBERS WINDOW LEFT.X.POS) (* Draw the x-axis at Y=0 if there is a 0 crossing) 
	  (COND ((ILESSP (WINDOWPROP WINDOW (QUOTE YMIN)) 0) (* Y0 in the window coordinate system) 
	  (SETQ Y0 (WINDOWPROP WINDOW (QUOTE Y0))) (* DRAWLINE 0 Y0 (WINDOWPROP WINDOW (QUOTE WIDTH)) Y0 1 
	  (QUOTE PAINT) WINDOW) (DRAWDOTTEDLINE 0 Y0 (WINDOWPROP WINDOW (QUOTE WIDTH)) Y0 1 WINDOW 3))))


          (if (NOT FASTREDISPLAY?)
	      then (SCALED.WINDOW.PRINT.SCALES WINDOW (DSPCLIPPINGREGION NIL WINDOW])

(SCALED.WINDOW.RESHAPEFN
  [LAMBDA (WINDOW)                                           (* pkh: "12-Jul-84 02:29")

          (* This function should see to repainting and rescaling of scales in a scaled window when it it reshaped;
	  calls the REPAINTFN for the window so it can replot the data)


    (PROG (WIDTH HEIGHT GRAPHHEIGHT Y.SCALE.FACTOR YPOS.FOR.XSCALE BOTTOM.X.SCALE.OFFSET YMIN YMAX)
                                                             (* Get the relevant parameters;
							     these haven%'t changed because of the reshaping)
          (SETQ YMIN (WINDOWPROP WINDOW 'YMIN))
          (SETQ YMAX (WINDOWPROP WINDOW 'YMAX))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ YPOS.FOR.XSCALE (WINDOWPROP WINDOW 'YPOS.FOR.XSCALE))
          (DSPRESET WINDOW)                                  (* Move to the beginning of window)
          (WINDOWPROP WINDOW 'PPORIGX (DSPXPOSITION NIL WINDOW))
          (WINDOWPROP WINDOW 'PPORIGY (DSPYPOSITION NIL WINDOW))
                                                             (* New width and height)
          (SETQ WIDTH (WINDOWPROP WINDOW 'WIDTH))
          (SETQ HEIGHT (WINDOWPROP WINDOW 'HEIGHT))          (* Compute afresh the number of pixels which the data 
							     may be plotted into)
          (SETQ GRAPHHEIGHT (IDIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET))
          (WINDOWPROP WINDOW 'GRAPHHEIGHT GRAPHHEIGHT)       (* Recompute the Y.SCALE.FACTOR)
                                                             (* Scale factor is 1 if no max or min)

          (* SETQ Y.SCALE.FACTOR (COND ((NOT (EQUAL YMIN MIN.FIXP) (EQUAL YMAX MAX.FIXP)) (FQUOTIENT 
	  (DIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET) YRANGE)) (T (SHOULDNT))))


          (SET.Y.SCALE.FACTOR WINDOW HEIGHT)                 (* Reset the window property;
							     Recompute the position for the 0 crossing)
          (SETY0 WINDOW (WINDOWPROP WINDOW 'Y.SCALE.FACTOR)
		 YMIN YMAX)
          (SCALED.WINDOW.REPAINTFN WINDOW])

(SCALED.WINDOW.SCROLLFN
  [LAMBDA (WINDOW XDELTA YDELTA CONTINUOUSFLG)               (* hdj "17-Jul-84 10:38")
                                                             (* standard scrolling function that scrolls by blting 
							     existing bits and then calling the windows repaintfn to 
							     repaint the newly exposed bits.)
    (PROG ((REG (DSPCLIPPINGREGION NIL WINDOW)))             (* SCROLLBYREPAINTFN WINDOW XDELTA YDELTA CONTINUOUSFLG)
          (NEWSCROLL WINDOW XDELTA YDELTA CONTINUOUSFLG)     (* REDISPLAYW WINDOW REG)
      ])

(SCALED.WINDOW.SETUP
  [LAMBDA (WINDOW YMIN YMAX BOTTOM.X.SCALE.OFFSET LEFT.Y.SCALE.OFFSET PRINTFN FONT 
		  INCREASEBETWEENTICS SCROLLFN)              (* pkh: "16-Jul-84 14:59")
    (PROG (WIDTH HEIGHT GRAPHHEIGHT Y0 Y.SCALE.FACTOR YPOS.FOR.XSCALE YRANGE)
          (PUTWINDOWPROP WINDOW 'SCROLLFN 'SCALED.WINDOW.SCROLLFN)
          (PUTWINDOWPROP WINDOW 'PRINTFN PRINTFN)
          (PUTWINDOWPROP WINDOW 'YMIN YMIN)
          (PUTWINDOWPROP WINDOW 'YMAX YMAX)
          (PUTWINDOWPROP WINDOW 'INCREASEBETWEENTICS INCREASEBETWEENTICS)
          (PUTWINDOWPROP WINDOW 'SCROLLFN SCROLLFN)
          [COND
	    ((AND YMIN YMAX)
	      (WINDOWPROP WINDOW 'YRANGE (IDIFFERENCE YMAX YMIN]
          [SETQ WIDTH (fetch WIDTH of (WINDOWPROP WINDOW 'REGION]
          [SETQ HEIGHT (fetch HEIGHT of (WINDOWPROP WINDOW 'REGION]
                                                             (* Let the bottom region be for the scale)
          (COND
	    ((NULL BOTTOM.X.SCALE.OFFSET)
	      (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET 30))
	    (T (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET BOTTOM.X.SCALE.OFFSET)))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (COND
	    ((NULL LEFT.Y.SCALE.OFFSET)
	      (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET 30))
	    (T (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET LEFT.Y.SCALE.OFFSET)))
          (SETQ LEFT.Y.SCALE.OFFSET (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET))
          (WINDOWPROP WINDOW 'REPAINTFN 'SCALED.WINDOW.REPAINTFN)
          (WINDOWPROP WINDOW 'RESHAPEFN 'SCALED.WINDOW.RESHAPEFN)
                                                             (* Set the right margin of the window so PRIN will 
							     print)
          (DSPRIGHTMARGIN (fetch (REGION WIDTH) of (WINDOWPROP WINDOW 'EXTENT))
			  WINDOW)
          [WINDOWPROP WINDOW 'NUMBER.FONT (COND
			(FONT (DSPFONT FONT WINDOW)
			      FONT)
			(T (DSPFONT (FONTCREATE 'TIMESROMAN 6)
				    WINDOW)
			   (FONTCREATE 'TIMESROMAN 6]
          (WINDOWPROP WINDOW 'SCROLLFN 'SCROLLBYREPAINTFN)   (* Height of the region the graph occupies)
          (SETQ GRAPHHEIGHT (IDIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET))
          (WINDOWPROP WINDOW 'GRAPHHEIGHT GRAPHHEIGHT)       (* Where the bottom x-scale is to be drawn)
          (WINDOWPROP WINDOW 'YPOS.FOR.XSCALE (IQUOTIENT BOTTOM.X.SCALE.OFFSET 2))
          (SETQ YPOS.FOR.XSCALE (WINDOWPROP WINDOW 'YPOS.FOR.XSCALE))
          (COND
	    ((NOT YMIN)
	      (SETQ YMIN MIN.FIXP)))
          (COND
	    ((NOT YMAX)
	      (SETQ YMAX MAX.FIXP)))
          (WINDOWPROP WINDOW 'YMIN YMIN)
          (WINDOWPROP WINDOW 'YMAX YMAX)                     (* Let the bottom points be for the scale)
          (SETQ YRANGE (PLUS (ABS YMIN)
			     (ABS YMAX)))                    (* Scale factor is 1 if no max or min)
          (SETQ Y.SCALE.FACTOR (FQUOTIENT (DIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET)
					  YRANGE))
          (WINDOWPROP WINDOW 'Y.SCALE.FACTOR Y.SCALE.FACTOR)
                                                             (* Find where the 0 crossing cuts into the Y-axis)
          (COND
	    ((ILESSP (WINDOWPROP WINDOW 'YMIN)
		     0)
	      [SETQ Y0 (FIXR (FPLUS (FTIMES (ABS (WINDOWPROP WINDOW 'YMIN))
					    Y.SCALE.FACTOR)
				    (FQUOTIENT BOTTOM.X.SCALE.OFFSET 2]
                                                             (* Draw the 0-crossing)
                                                             (* DRAWDOTTEDLINE 0 Y0 (WINDOWPROP WINDOW 
							     (QUOTE WIDTH)) Y0 1 WINDOW 3)
	      (WINDOWPROP WINDOW 'Y0 Y0))
	    (T                                               (* There YMIN is 0 or larger;
							     there is no 0 crossing; default Y0 to be 
							     BOTTOM.X.SCALE.OFFSET)
	       (WINDOWPROP WINDOW 'Y0 YPOS.FOR.XSCALE)
	       (WINDOWPROP WINDOW 'Y0 Y0)))
          (SCALED.WINDOW.PRINT.SCALES WINDOW)                (* If max and min are not specified then choose some 
							     large number)
                                                             (* Draw the scales)

          (* (SCALEDWINDOW.REPAINT.FN WINDOW) (DRAWLINE 0 YPOS.FOR.XSCALE (IPLUS (WINDOWPROP WINDOW 
	  (QUOTE WIDTH)) 0) YPOS.FOR.XSCALE 2 (QUOTE PAINT) WINDOW) (DRAWLINE 0 LEFT.Y.SCALE.OFFSET 0 
	  (IPLUS (WINDOWPROP WINDOW (QUOTE WIDTH)) 0) YPOS.FOR.XSCALE 2 (QUOTE PAINT) WINDOW) (PRINT.SCALE.NUMBERS WINDOW 0)
)


          (SCALED.WINDOW.REPAINTFN WINDOW)
          (PUTWINDOWPROP WINDOW 'SCROLLFN 'SCALED.WINDOW.SCROLLFN)
          (RETURN WINDOW])

(SDF
  [LAMBDA (FILE PTR)                                         (* pkh: "12-Jul-84 22:42")
                                                             (* Alternative to SPEECH.DISPLAY.FILE for displaying a 
							     waveform; gives you a scrollable window)
    (COND
      ((NULL PTR)                                            (* If no info about where to start printing in the file 
							     go to the beginning)
	(SETQ PTR 0)))
    (PROG (STARTX STARTY WIDTH HEIGHT WINDOW)
          (SETQ FILE (FULLNAME FILE 'OLD))
          (SETQ WINDOW (CREATEW NIL FILE))
          (SETQ STARTX (DSPXPOSITION NIL WINDOW))
          (SETQ STARTY (DSPYPOSITION NIL WINDOW))            (* Associate the file with the window)
          (WINDOWPROP WINDOW 'FILE FILE)
          (SCALED.WINDOW.SETUP WINDOW -128 128 30 30 'PRINT.SPEECH.FILE)
                                                             (* Set the extent so we can scroll)
                                                             (* SCALED.WINDOW.RESHAPEFN WINDOW)
          (WINDOWPROP WINDOW 'EXTENT
		      (create REGION
			      LEFT ← STARTX
			      BOTTOM ← STARTY
			      HEIGHT ← -1
			      WIDTH ← (GETFILEINFO FILE 'LENGTH])

(SETY0
  [LAMBDA (WINDOW Y.SCALE.FACTOR YMIN YMAX)                  (* pkh: "10-Jul-84 22:27")
    (PROG (Y0)
          (COND
	    ((ILESSP (WINDOWPROP WINDOW 'YMIN)
		     0)
	      [SETQ Y0 (FIXR (FPLUS (FTIMES (ABS (WINDOWPROP WINDOW 'YMIN))
					    Y.SCALE.FACTOR)
				    (FQUOTIENT BOTTOM.X.SCALE.OFFSET 2]
	      (WINDOWPROP WINDOW 'Y0 Y0)                     (* Draw the 0-crossing)
	      )
	    (T                                               (* There YMIN is 0 or larger;
							     there is no 0 crossing; default Y0 to be 
							     BOTTOM.X.SCALE.OFFSET)
	       (WINDOWPROP WINDOW 'Y0 YPOS.FOR.XSCALE)))
          (RETURN Y0])

(SET.Y.SCALE.FACTOR
  [LAMBDA (WINDOW HEIGHT)                                    (* pkh: "11-Jul-84 22:55")
    (PROG (BOTTOM.X.SCALE.OFFSET YRANGE)
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ YRANGE (WINDOWPROP WINDOW 'YRANGE))
          (SETQ Y.SCALE.FACTOR (COND
	      (YRANGE (FQUOTIENT (IDIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET)
				 YRANGE))
	      (T 1)))
          (WINDOWPROP WINDOW 'Y.SCALE.FACTOR Y.SCALE.FACTOR])

(SPEECH.COPY.ARRAY.TO.WAVE
  [LAMBDA (WORD ARRAY)                                       (* pkh: "13-Jul-84 05:04")
    (PROG (STREAM)
          (SETQ STREAM (OPENSTREAM (PACKFILENAME 'HOST '{ERIS} 'DIRECTORY '<SPEECH>WAVE>
						 'NAME WORD 'EXTENSION 'WAVE)
				   'OUTPUT
				   'OLD/NEW))
          (for I from 1 to (SUB1 (ARRAYSIZE ARRAY)) do (BOUT STREAM (ELT ARRAY I)))
          (CLOSEF STREAM])

(SPEECH.PRINT.WAVE.ARRAY
  [LAMBDA (REGION ARRAY WINDOW)                              (* pkh: "21-Jun-84 23:01")
    (PROG (Y.SCALE.FACTOR Y.POS.FOR.XSCALE BOTTOM.X.SCALE.OFFSET YMAX YMIN)
          (SETQ Y.SCALE.FACTOR (WINDOWPROP WINDOW 'Y.SCALE.FACTOR))
          (SETQ Y.POS.FOR.XSCALE (WINDOWPROP WINDOW 'YPOS.FOR.X.SCALE))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ YMAX (WINDOWPROP WINDOW 'YMAX))
          (SETQ YMIN (WINDOWPROP WINDOW 'YMIN))

          (* Read elements in the array from the part of the array corresponding to the region being displayed;
	  check that it isn%'t out of bounds; convert the value according the the scaling factor; draw line from previous x 
	  and y position to the new one)


          (as X Y OLD.X OLD.Y from (COND
				     (REGION (ADD1 (fetch (REGION LEFT) of REGION)))
				     (T 1))
	     to (IMIN [COND
			[REGION (ADD1 (IPLUS (fetch (REGION LEFT) of REGION)
					     (fetch (REGION WIDTH) of REGION]
			(T (ADD1 (WINDOWPROP WINDOW 'WIDTH]
		      (ARRAYSIZE ARRAY))
	     do (SETQ Y (ELT ARRAY X))
		(COND
		  [(FLESSP Y YMIN)
		    (printout PROMPTWINDOW "SCOPE: " Y " ")
		    (SETQ Y (WINDOWPROP WINDOW 'YMIN]
		  [(FGREATERP Y YMAX)
		    (printout PROMPTWINDOW "SCOPE: " Y " ")
		    (SETQ Y (WINDOWPROP WINDOW 'YMAX]
		  (T (SETQ Y (SETQ Y (IPLUS (FTIMES Y Y.SCALE.FACTOR)
					    BOTTOM.X.SCALE.OFFSET)))
		     (COND
		       (OLD.X (DRAWLINE OLD.X OLD.Y X Y 1 'PAINT SCOPE.WINDOW)))
		     (SETQ OLD.Y Y)
		     (SETQ OLD.X X])
)

(RPAQQ Y.AXIS.LINE.WIDTH 2)
(PUTPROPS SCALEDWINDOW.FPKG COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (801 32208 (DISPLAY.FILE 811 . 2072) (DRAWDOTTEDLINE 2074 . 2348) (FIRST.TIC 2350 . 2771
) (OLD.USER.CREATE.MENU 2773 . 3495) (SCALED.WINDOW.PRINT.SCALES 3497 . 6513) (SCROLL 6515 . 13175) (
SCALED.WINDOW.CLEARW 13177 . 14235) (PRINT.SCALE.NUMBERS 14237 . 15872) (PRINT.SPEECH.FILE 15874 . 
17045) (RESHAPE.SPEECH.DISPLAY.FILE.WINDOW 17047 . 17402) (SCALED.WINDOW.REPAINTFN 17404 . 20474) (
SCALED.WINDOW.RESHAPEFN 20476 . 22568) (SCALED.WINDOW.SCROLLFN 22570 . 23152) (SCALED.WINDOW.SETUP 
23154 . 27754) (SDF 27756 . 29002) (SETY0 29004 . 29674) (SET.Y.SCALE.FACTOR 29676 . 30163) (
SPEECH.COPY.ARRAY.TO.WAVE 30165 . 30591) (SPEECH.PRINT.WAVE.ARRAY 30593 . 32206)))))
STOP