(FILECREATED "22-Jun-84 23:18:27" {PHYLUM}<SPEECH>HALVORSEN>SCALEDWINDOW.FPKG;1 15908  

      changes to:  (FNS SCALED.WINDOW.RESHAPEFN SCALED.WINDOW.SETUP PRINT.SCALE.NUMBERS)

      previous date: "21-Jun-84 23:03:09" {ERIS}<SPEECH>SCALEDWINDOW.FPKG;5)


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

(PRETTYCOMPRINT SCALEDWINDOWCOMS)

(RPAQQ SCALEDWINDOWCOMS ((FNS FIRST.TIC OLD.USER.CREATE.MENU PRINT.SCALE.NUMBERS PRINT.SPEECH.FILE 
			      RESHAPE.SPEECH.DISPLAY.FILE.WINDOW SCALED.WINDOW.REPAINTFN 
			      SCALED.WINDOW.RESHAPEFN SCALED.WINDOW.SCROLLFN SCALED.WINDOW.SETUP SDF 
			      SPEECH.PRINT.WAVE.ARRAY)))
(DEFINEQ

(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])

(PRINT.SCALE.NUMBERS
  [LAMBDA (WINDOW LEFT.X.XPOS TIC.INTERVAL)                  (* pkh: "22-Jun-84 23:16")
                                                             (* 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)
          (DSPRIGHTMARGIN (fetch (REGION WIDTH) of (WINDOWPROP WINDOW 'EXTENT))
			  WINDOW)
          (COND
	    ((NULL TIC.INTERVAL)
	      (SETQ TIC.INTERVAL 20)))
          (SETQ TEMP (FIRST.TIC LEFT.X.XPOS TIC.INTERVAL))
          (for I from TEMP to (IPLUS (WINDOWPROP WINDOW 'WIDTH)
				     LEFT.X.XPOS)
	     by 20 as J first (SETQ FLG 0) from LEFT.X.POS by 20
	     do (SETQ NUMBER.WIDTH (STRINGWIDTH J (DSPFONT NIL WINDOW)))
		(MOVETO (IDIFFERENCE I (IQUOTIENT NUMBER.WIDTH 2))
			(IDIFFERENCE YPOS.FOR.XSCALE 13)
			WINDOW)
		(COND
		  ((ODDP FLG)
		    (PRIN1 J WINDOW)))
		(DRAWLINE I YPOS.FOR.XSCALE I (IPLUS YPOS.FOR.XSCALE 4)
			  1
			  'PAINT WINDOW)
		(SETQ FLG (ADD1 FLG])

(PRINT.SPEECH.FILE
  [LAMBDA (REGION FILE WINDOW)                               (* pkh: " 7-Jan-84 16:19")
    (PROG (STREAM Y Y0 X Y.SCALE.FACTOR BOTTOM.X.SCALE.OFFSET)
          (SETQ Y.SCALE.FACTOR (WINDOWPROP WINDOW 'Y.SCALE.FACTOR))
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
          (SETQ Y0 (FIXR (PLUS (TIMES (ABS (WINDOWPROP WINDOW 'YMIN))
				      Y.SCALE.FACTOR)
			       BOTTOM.X.SCALE.OFFSET)))
          (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 (\BIN STREAM))
		[COND
		  ((ILESSP Y 128)
		    (SETQ Y (IPLUS Y 128)))
		  (T (SETQ Y (IDIFFERENCE 256 Y]             (* Center around Y=0)
		(SETQ Y (IPLUS (FTIMES Y Y.SCALE.FACTOR)
			       BOTTOM.X.SCALE.OFFSET))
		(DRAWLINE X Y0 X 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 LEFT.Y.SCALE.OFFSET)                (* pkh: "21-Jun-84 22:49")
                                                             (* Calls the PRINTFN for the window with the arguments 
							     REGION FILE and WINDOW)
    (PROG (HEIGHT GRAPHHEIGHT WIDTH BOTTOM.X.SCALE.OFFSET YMIN YPOS.FOR.XSCALE Y.SCALE.FACTOR 
		  X.SCALE.FACTOR LEFT.X.POS X Y0 Y REG)      (* We want the WHOLE window redsiplayed;
							     so we throw away REGION and instead we use REG)
          (SETQ REG (DSPCLIPPINGREGION NIL WINDOW))
          (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 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 LEFT.X.POS (COND
	      (REG (fetch (REGION LEFT) of REG))
	      (T 0)))                                        (* 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 REG (WINDOWPROP WINDOW 'FILE)
		       WINDOW))                              (* Draw the bottom x-scale; will be numbered and tacked)
          (DRAWLINE LEFT.X.POS YPOS.FOR.XSCALE (IPLUS (WINDOWPROP WINDOW 'WIDTH)
						      LEFT.X.POS)
		    YPOS.FOR.XSCALE 2 '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 'YMIN)
		     0)                                      (* Y0 in the window coordinate system)
	      (SETQ Y0 (FIXR (PLUS (TIMES (ABS (WINDOWPROP WINDOW 'YMIN))
					  Y.SCALE.FACTOR)
				   BOTTOM.X.SCALE.OFFSET)))
	      (DRAWLINE 0 Y0 (WINDOWPROP WINDOW 'WIDTH)
			Y0 1 'PAINT WINDOW])

(SCALED.WINDOW.RESHAPEFN
  [LAMBDA (WINDOW)                                           (* pkh: "22-Jun-84 22:46")

          (* 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 Y0 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 (EQ YMIN MIN.FIXP)
		    (EQ YMAX MAX.FIXP))                      (* There is a user specified YMIN and YMAX)
		(FQUOTIENT (DIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET)
			   YRANGE))
	      (T 

          (* There is not a user specified YMIN and YMAX%, these have been defaulted to MIN.FIXP and MAX.FIXP;
	  in this case we choose the Y.SCALE.FACTOR to be 1)


		 1)))                                        (* Reset the window property)
          (WINDOWPROP WINDOW 'Y.SCALE.FACTOR Y.SCALE.FACTOR)
                                                             (* Recompute the position for the 0 crossing)
          (SCALED.WINDOW.REPAINTFN WINDOW])

(SCALED.WINDOW.SCROLLFN
  [LAMBDA (WINDOW XDELTA YDELTA CONTINUOUSFLG)               (* pkh: "14-Jun-84 17:50")
                                                             (* standard scrolling function that scrolls by blting 
							     existing bits and then calling the windows repaintfn to 
							     repaint the newly exposed bits.)
    (REDISPLAYW WINDOW])

(SCALED.WINDOW.SETUP
  [LAMBDA (WINDOW REGION TITLE YMIN YMAX BOTTOM.X.SCALE.OFFSET LEFT.Y.SCALE.OFFSET PRINTFN FONT)
                                                             (* pkh: "22-Jun-84 23:06")
    (PROG (WIDTH HEIGHT GRAPHHEIGHT Y0 Y.SCALE.FACTOR YPOS.FOR.XSCALE)
          (WINDOWPROP WINDOW 'PRINTFN PRINTFN)
          (SETQ WIDTH (WINDOWPROP WINDOW 'WIDTH))
          (SETQ HEIGHT (WINDOWPROP WINDOW 'HEIGHT))          (* 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)))
          (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))
			(T (DSPFONT (FONTCREATE 'TIMESROMAN 6)
				    WINDOW]
          (WINDOWPROP WINDOW 'SCROLLFN 'SCROLLBYREPAINTFN)
          (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
                                                             (* 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))
                                                             (* If max and min are not specified then choose some 
							     large number)
          (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 (COND
	      ((NOT (EQ YMIN MIN.FIXP)
		    (EQ YMAX MAX.FIXP))
		(FQUOTIENT (DIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET)
			   YRANGE))
	      (T 1)))
          (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 (PLUS (TIMES (ABS (WINDOWPROP WINDOW 'YMIN))
					  Y.SCALE.FACTOR)
				   BOTTOM.X.SCALE.OFFSET)))
	      (WINDOWPROP WINDOW 'Y0 Y0)                     (* Draw the 0-crossing)
	      (DRAWLINE 0 Y0 (WINDOWPROP WINDOW 'WIDTH)
			Y0 1 'PAINT WINDOW))
	    (T                                               (* There YMIN is 0 or larger;
							     there is no 0 crossing; default Y0 to be 
							     BOTTOM.X.SCALE.OFFSET)
	       (WINDOWPROP WINDOW 'Y0 BOTTOM.X.SCALE.OFFSET)))
                                                             (* Draw the scales)
          (DRAWLINE 0 YPOS.FOR.XSCALE (IPLUS (WINDOWPROP WINDOW 'WIDTH)
					     0)
		    YPOS.FOR.XSCALE 2 'PAINT WINDOW)
          (PRINT.SCALE.NUMBERS WINDOW 0])

(SDF
  [LAMBDA (FILE PTR)                                         (* pkh: "13-Jun-84 17:22")
                                                             (* Alternative to SPEECH.DISPLAY.FILE for displaying a 
							     waveform; gives you a scrollable window)
    (COND
      ((NULL PTR)
	(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))
          (WINDOWPROP WINDOW 'FILE FILE)
          (SCALED.WINDOW.SETUP WINDOW (WINDOWPROP WINDOW 'REGION)
			       (MKSTRING FILE)
			       -128 128 30 30 'PRINT.SPEECH.FILE)
          [WINDOWPROP WINDOW 'EXTENT
		      (create REGION
			      LEFT ← STARTX
			      BOTTOM ← STARTY
			      HEIGHT ← -1
			      WIDTH ← (GETFILEINFO FILE 'LENGTH]
          (SCALED.WINDOW.RESHAPEFN WINDOW])

(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])
)
(PUTPROPS SCALEDWINDOW.FPKG COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (654 15820 (FIRST.TIC 664 . 1085) (OLD.USER.CREATE.MENU 1087 . 1809) (
PRINT.SCALE.NUMBERS 1811 . 3034) (PRINT.SPEECH.FILE 3036 . 4286) (RESHAPE.SPEECH.DISPLAY.FILE.WINDOW 
4288 . 4643) (SCALED.WINDOW.REPAINTFN 4645 . 6992) (SCALED.WINDOW.RESHAPEFN 6994 . 9343) (
SCALED.WINDOW.SCROLLFN 9345 . 9731) (SCALED.WINDOW.SETUP 9733 . 13240) (SDF 13242 . 14203) (
SPEECH.PRINT.WAVE.ARRAY 14205 . 15818)))))
STOP