NIL
47←(FOR FN IN (FILECOMSLST 'SCALEDWINDOW.FPKG)
    DO (SETQ L (GETD FN))
    (SETQ FORMALS (CADR L))
    (SETQ BODY (CDDR L))
    (PRINTDEF `(DEFEXPR (,FN ,@FORMALS) ,@BODY) 0 'FNS)
	(TERPRI))
(DEFEXPR (DRAWDOTTEDLINE 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)))
(DEFEXPR (FIRST.TIC 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
           ((>= TIC.INTERVAL LEFT.X.POS)
             LEFT.X.POS)
           (T (+ LEFT.X.POS (- TIC.INTERVAL (\ LEFT.X.POS TIC.INTERVAL))))))
(DEFEXPR (OLD.USER.CREATE.MENU)                        (* 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 (MENU.IMAGEWIDTH
                                                                           MENU)
                                                                         (MENU.IMAGEHEIGHT
                                                                           MENU)
                                                                         NIL NIL NIL 
                                                                    "Position USER MENU"))
               (GETBOXPOSITION (MENU.IMAGEWIDTH MENU)
                               (MENU.IMAGEHEIGHT MENU)
                               NIL NIL NIL "Position USER MENU")
               (RETURN MENU)))
(DEFEXPR (SCALED.WINDOW.PRINT.SCALES WINDOW)           (* pkh: " 2-Jul-84 18:50")
                                                       (* Clears a scaled window and repaints the scales)
         (PROG (YPOS.FOR.XSCALE YMIN Y.SCALE.FACTOR BOTTOM.X.SCALE.OFFSET WIDTH)
               (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 (REGION.WIDTH (WINDOWPROP WINDOW 'REGION)))
               (MOVETO (WINDOWPROP WINDOW 'PPORIGX)
                       (WINDOWPROP WINDOW 'PPORIGY)
                       WINDOW)
               (DRAWLINE LEFT.X.POS YPOS.FOR.XSCALE (+ (WINDOWPROP WINDOW 'WIDTH)
                                                       LEFT.X.POS)
                         YPOS.FOR.XSCALE 2 'PAINT WINDOW)
               (PRINT.SCALE.NUMBERS WINDOW LEFT.X.POS)
               (COND
                 ((< (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)))     (* DRAWLINE 0 Y0 WIDTH Y0 1 
                                                       (QUOTE PAINT) SCOPE.WINDOW)
           ))
(DEFEXPR (SCALED.WINDOW.CLEARW WINDOW)                 (* pkh: " 2-Jul-84 19:29")
                                                       (* 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 (REGION.WIDTH (WINDOWPROP WINDOW 'REGION)))
               (SETQ LEFT.X.POS 0)
               (CLEARW WINDOW)
               (MOVETO (WINDOWPROP WINDOW 'PPORIGX)
                       (WINDOWPROP WINDOW 'PPORIGY)
                       WINDOW)
               (DRAWLINE LEFT.X.POS YPOS.FOR.XSCALE (+ (WINDOWPROP WINDOW 'WIDTH)
                                                       LEFT.X.POS)
                         YPOS.FOR.XSCALE 2 'PAINT WINDOW)
               (PRINT.SCALE.NUMBERS WINDOW LEFT.X.POS)
               (COND
                 ((< (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)))     (* DRAWLINE 0 Y0 WIDTH Y0 1 
                                                       (QUOTE PAINT) SCOPE.WINDOW)
               (SCALED.WINDOW.REPAINTFN WINDOW)))
(DEFEXPR (PRINT.SCALE.NUMBERS WINDOW LEFT.X.XPOS TIC.INTERVAL)
                                                       (* pkh: "28-Jun-84 12:38")
                                                       (* Draws lines for tic marks;
                                                       and print numbers by the tics)
                                                       (* IF (NOT (EQ 0 LEFT.X.POS)) THEN 
                                                       (+ LEFT.X.POS (\ LEFT.X.POS TIC.INTERVAL)) ELSE 0)
         (PROG (NUMBER.WIDTH TEMP FLG)
               (DSPRIGHTMARGIN (REGION.WIDTH (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 (+ (WINDOWPROP WINDOW 'WIDTH)
                                      LEFT.X.XPOS)
                  by 20 as J first (SETQ FLG 0) from LEFT.X.XPOS by 20
                  do (SETQ NUMBER.WIDTH (STRINGWIDTH J (DSPFONT NIL WINDOW)))
                     (MOVETO (- I (/ NUMBER.WIDTH 2))
                             (- YPOS.FOR.XSCALE 13)
                             WINDOW)
                     (COND
                       ((ODDP FLG)
                         (PRIN1 J WINDOW)))
                     (DRAWLINE I YPOS.FOR.XSCALE I (+ YPOS.FOR.XSCALE 4)
                               1
                               'PAINT WINDOW)
                     (SETQ FLG (1+ FLG)))))
(DEFEXPR (PRINT.SPEECH.FILE REGION FILE WINDOW)        (* pkh: "26-Jun-84 18:28")
         (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 (WINDOWPROP WINDOW 'Y0))
               (SETQ STREAM (OPENSTREAM (WINDOWPROP WINDOW 'FILE)
                                        'INPUT
                                        'OLD))
               (SETFILEPTR STREAM (COND
                             (REGION (REGION.LEFT REGION))
                             (T 0)))
               (while (NOT (EOFP STREAM)) as X from (COND
                                                      (REGION (REGION.LEFT REGION))
                                                      (T 0))
                  to (COND
                       (REGION (+ (REGION.LEFT REGION)
                                  (REGION.WIDTH REGION)))
                       (T (WINDOWPROP WINDOW 'WIDTH)))
                  do (SETQ Y (\BIN STREAM))
                     (COND
                       ((< Y 128)
                         (SETQ Y (+ Y 128)))
                       (T (SETQ Y (- 256 Y))))         (* Center around Y=0)
                     (SETQ Y (+ (x$ Y Y.SCALE.FACTOR)
                                BOTTOM.X.SCALE.OFFSET))
                     (DRAWLINE X Y0 X Y 1 'PAINT WINDOW))
               (CLOSEF STREAM)))
(DEFEXPR (RESHAPE.SPEECH.DISPLAY.FILE.WINDOW 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)))
(DEFEXPR (SCALED.WINDOW.REPAINTFN WINDOW REGION LEFT.Y.SCALE.OFFSET)
                                                       (* pkh: "26-Jun-84 12:53")
                                                       (* 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 Y0 (WINDOWPROP WINDOW 'Y0))
               (SETQ LEFT.X.POS (COND
                   (REG (REGION.LEFT 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 (+ (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
                 ((< (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 
                                                       (QUOTE WIDTH)) Y0 1 (QUOTE PAINT) WINDOW)
                   (DRAWDOTTEDLINE 0 Y0 (WINDOWPROP WINDOW 'WIDTH)
                                   Y0 1 WINDOW 3)))))
(DEFEXPR (SCALED.WINDOW.RESHAPEFN WINDOW)              (* pkh: "27-Jun-84 12:27")

          (* 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 (- 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)) 
          (/$ (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)))
(DEFEXPR (SCALED.WINDOW.SCROLLFN 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))
(DEFEXPR (SCALED.WINDOW.SETUP WINDOW YMIN YMAX BOTTOM.X.SCALE.OFFSET LEFT.Y.SCALE.OFFSET 
                              PRINTFN FONT)            (* pkh: " 2-Jul-84 18:34")
         (PROG (WIDTH HEIGHT GRAPHHEIGHT Y0 Y.SCALE.FACTOR YPOS.FOR.XSCALE)
               (WINDOWPROP WINDOW 'PRINTFN PRINTFN)
               (SETQ WIDTH (REGION.WIDTH (WINDOWPROP WINDOW 'REGION)))
               (SETQ HEIGHT (REGION.HEIGHT (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)))
               (COND
                 ((NULL LEFT.Y.SCALE.OFFSET)
                   (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET 30))
                 (T (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET 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 (REGION.WIDTH (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))
               (SETQ LEFT.Y.SCALE.OFFSET (WINDOWPROP WINDOW 'LEFT.Y.SCALE.OFFSET))
                                                       (* Height of the region the graph occupies)
               (SETQ GRAPHHEIGHT (- HEIGHT BOTTOM.X.SCALE.OFFSET))
               (WINDOWPROP WINDOW 'GRAPHHEIGHT GRAPHHEIGHT)
                                                       (* Where the bottom x-scale is to be drawn)
               (WINDOWPROP WINDOW 'YPOS.FOR.XSCALE (/ 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 (/$ (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
                 ((< (WINDOWPROP WINDOW 'YMIN)
                     0)
                   (SETQ Y0 (FIXR (PLUS (TIMES (ABS (WINDOWPROP WINDOW 'YMIN))
                                               Y.SCALE.FACTOR)
                                        BOTTOM.X.SCALE.OFFSET)))
                   (DRAWDOTTEDLINE 0 Y0 (WINDOWPROP WINDOW 'WIDTH)
                                   Y0 1 WINDOW 3)      (* Draw the 0-crossing)
                   (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 BOTTOM.X.SCALE.OFFSET)))
                                                       (* Draw the scales)

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


               (SCALED.WINDOW.REPAINTFN WINDOW)
               (RETURN WINDOW)))
(DEFEXPR (SCOPE.PRINT REGION ARRAY WINDOW)             (* pkh: " 2-Jul-84 18:53")
         (PROG (Y0 Y.POS.FOR.XSCALE BOTTOM.X.SCALE.OFFSET YMAX YMIN Y.SCALE.FACTOR)
               (COND
                 ((NULL ARRAY)
                   (RETURN)))
               (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))
               (SETQ Y0 (WINDOWPROP WINDOW 'Y0))

          (* 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 (1+ (REGION.LEFT REGION)))
                                          (T 1))
                  to (IMIN (COND
                             (REGION (+ (REGION.LEFT REGION)
                                        (REGION.WIDTH REGION)
                                        1))
                             (T (1+ (WINDOWPROP WINDOW 'WIDTH))))
                           (ARRAYSIZE ARRAY))
                  do (SETQ Y (ELT ARRAY X))            (* In the SPEECH.*WAVE* array elements greater than 127 are elements which should be plotted as negative values in the scope)
                     (COND
                       ((> Y 127)
                         (SETQ Y (MINUS (- Y 127)))))
                     (COND
                       ((<$ Y YMIN)
                         (printout PROMPTWINDOW "SCOPE: " Y " ")
                         (SETQ Y (WINDOWPROP WINDOW 'YMIN)))
                       ((>$ Y YMAX)
                         (printout PROMPTWINDOW "SCOPE: " Y " ")
                         (SETQ Y (WINDOWPROP WINDOW 'YMAX)))
                       (T (SETQ Y (x$ Y Y.SCALE.FACTOR))
                                                       (* Center around the 0 crossing)
                          (SETQ Y (+ Y0 Y))
                          (COND
                            (OLD.X (DRAWLINE OLD.X OLD.Y X Y 1 'PAINT SCOPE.WINDOW)))
                          (SETQ OLD.Y Y)
                          (SETQ OLD.X X))))))
(DEFEXPR (SDF FILE PTR)                                (* pkh: "27-Jun-84 11:50")
                                                       (* 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)
               (WINDOWPROP WINDOW 'EXTENT
                           (create REGION
                                   LEFT ← STARTX
                                   BOTTOM ← STARTY
                                   HEIGHT ← -1
                                   WIDTH ← (GETFILEINFO FILE 'LENGTH)))
               (SCALED.WINDOW.RESHAPEFN WINDOW)))
(DEFEXPR (SETY0 WINDOW Y.SCALE.FACTOR YMIN YMAX)       (* pkh: "27-Jun-84 12:02")
         (PROG (Y0)
               (SETQ Y0 (COND
                   ((NOT (EQ YMIN MIN.FIXP))           (* There is a user specified YMIN and YMAX)
                                                       (* Recompute the position for the 0 crossing)
                     (+ (FIXR (x$ Y.SCALE.FACTOR (ABS YMIN)))
                        BOTTOM.X.SCALE.OFFSET))
                   (T                                  (* There is not a user specified YMIN and YMAX)
                      (+ (FIXR (x$ (WINDOWPROP WINDOW 'Y0)
                                   Y.SCALE.FACTOR))
                         BOTTOM.X.SCALE.OFFSET))))
               (WINDOWPROP WINDOW 'Y0 Y0)
               (RETURN Y0)))
(DEFEXPR (SET.Y.SCALE.FACTOR WINDOW HEIGHT)            (* pkh: "27-Jun-84 17:10")
         (PROG (BOTTOM.X.SCALE.OFFSET)
               (SETQ BOTTOM.X.SCALE.OFFSET (WINDOWPROP WINDOW 'BOTTOM.X.SCALE.OFFSET))
               (SETQ Y.SCALE.FACTOR (/$ (DIFFERENCE HEIGHT BOTTOM.X.SCALE.OFFSET)
                                        YRANGE))
               (WINDOWPROP WINDOW 'Y.SCALE.FACTOR Y.SCALE.FACTOR)))
(DEFEXPR (SPEECH.PRINT.WAVE.ARRAY 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 (1+ (REGION.LEFT REGION)))
                                          (T 1))
                  to (IMIN (COND
                             (REGION (1+ (+ (REGION.LEFT REGION)
                                            (REGION.WIDTH REGION))))
                             (T (1+ (WINDOWPROP WINDOW 'WIDTH))))
                           (ARRAYSIZE ARRAY))
                  do (SETQ Y (ELT ARRAY X))
                     (COND
                       ((<$ Y YMIN)
                         (printout PROMPTWINDOW "SCOPE: " Y " ")
                         (SETQ Y (WINDOWPROP WINDOW 'YMIN)))
                       ((>$ Y YMAX)
                         (printout PROMPTWINDOW "SCOPE: " Y " ")
                         (SETQ Y (WINDOWPROP WINDOW 'YMAX)))
                       (T (SETQ Y (SETQ Y (+ (x$ 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))))))
NIL
48← (DRIBBLE)