-- LoomControl.mesa Edited by Sweet on June 13, 1979 10:56 AM DIRECTORY CursorDefs: FROM "cursordefs" USING [SetCursor, textPointer], DisplayDefs: FROM "displaydefs" USING [Dimension], LoomDefs: FROM "loomdefs", PBKDefs: FROM "PBKDefs" USING [EnterExit], PBKInputDefs: FROM "PBKInputDefs" USING [SetNopPNRs], ParameterDefs: FROM "ParameterDefs" USING [ DestroyParameterSubwindowEtc, DisplayParameterItem, DisplayParameterSubwindow, ParameterItemDescriptor, ParameterItemHandle], PressMyDefs: FROM "pressmydefs" USING [OutScreen], SegmentDefs: FROM "SegmentDefs" USING [FileNameError], StreamDefs: FROM "StreamDefs" USING [ AccessOptions, Append, NewByteStream, NewWordStream, Read, StreamHandle, Write], StringDefs: FROM "StringDefs" USING [AppendChar, AppendString], SystemDefs: FROM "SystemDefs" USING [ AllocateHeapString, FreeHeapNode, FreeHeapString], ToolsDefs: FROM "ToolsDefs" USING [ FreeToolsNode, FreeToolsString, SetToolsDestroyProc], ToolsFontDefs: FROM "ToolsFontDefs" USING [ ComputeStringWidth, FAptr, GetToolsFont], WindowDefs: FROM "WindowDefs" USING [ CreateSubwindow, CreateWindow, DestroySubwindow, DestroyWindowEtc, DrawWindowFrame, DrawWindowNameFrame, ReplaceStringToPlaceInSubwindow, PaintWindow, RefreshSequencer, ShadeBoxInSubwindow, StandardAdjustProc, SubwindowHandle, SubwindowPlace, WindowBox, WindowHandle, BlackenBoxInSubwindow, WhitenBoxInSubwindow]; LoomControl: PROGRAM IMPORTS CursorDefs, LoomDefs, ParameterDefs, PBKInputDefs, PressMyDefs, SegmentDefs, StreamDefs, StringDefs, SystemDefs, ToolsDefs, ToolsFontDefs, WindowDefs EXPORTS LoomDefs = BEGIN OPEN DisplayDefs, ParameterDefs, WindowDefs, StreamDefs, LoomDefs; StdPedal: PUBLIC PROCEDURE [ sw: SubwindowHandle, items: ParameterItemDescriptor, index: CARDINAL] = BEGIN PostLine[NIL]; poString _ SetString[poString, woString]; [] _ DisplayParameterItem[parameterSW, poParmNum]; END; UpDown: PUBLIC PROCEDURE [ sw: SubwindowHandle, items: ParameterItemDescriptor, index: CARDINAL] = BEGIN i: CARDINAL; l: CARDINAL _ poString.length; PostLine[NIL]; IF 2*l-2 > poString.maxlength THEN BEGIN ns: STRING _ SystemDefs.AllocateHeapString[2*l+10]; StringDefs.AppendString[ns, poString]; SystemDefs.FreeHeapString[poString]; poString _ ns; END; FOR i IN [0..l-2) DO poString[l+i] _ poString[l-2-i]; ENDLOOP; poString.length _ 2*l-2; [] _ DisplayParameterItem[parameterSW, poParmNum]; END; SetString: PROCEDURE [s1, s2: STRING] RETURNS [rs: STRING] = BEGIN IF s1.maxlength >= s2.length THEN rs _ s1 ELSE BEGIN OPEN SystemDefs; FreeHeapString[s1]; rs _ AllocateHeapString[s2.length]; END; rs.length _ 0; StringDefs.AppendString[rs, s2]; END; Repaint: PUBLIC PROCEDURE [ sw: SubwindowHandle, items: ParameterItemDescriptor _ NULL, index: CARDINAL _ NULL] = BEGIN PostLine[NIL]; RepaintAllWeave[]; END; autoRepaint: PUBLIC BOOLEAN _ FALSE; DisplayWeaveWindowContents: PUBLIC PROCEDURE [ window: WindowHandle, wBox: WindowBox, refreshSequencer: RefreshSequencer] RETURNS [WindowBox] = BEGIN sw: SubwindowHandle = window.subwindowChain; font: ToolsFontDefs.FAptr; fontHeight: INTEGER; [font: font, height: fontHeight] _ ToolsFontDefs.GetToolsFont[]; IF window.size = tiny THEN BEGIN name: STRING _ "Weaving"L; DrawWindowFrame[window]; [] _ ReplaceStringToPlaceInSubwindow[ sw, [x: (sw.box.dims.w-ToolsFontDefs.ComputeStringWidth[name, font])/2, y: (sw.box.dims.h-fontHeight)/2], name, font]; sw.box _ [[0,0], [0,0]]; END ELSE BEGIN IF autoRepaint THEN RepaintAllWeave[] ELSE DrawWindowNameFrame[weaveWindow, "Weaving"L]; END; RETURN [wBox]; END; -- control stuff controlWindow: PUBLIC WindowHandle _ CreateWindow[ normal: [[10,0], [500, 210]], tiny: [[128,400], [128, 32]], displayProc: DisplayControlWindowContents, adjustProc: StandardAdjustProc]; Load: PUBLIC PROCEDURE [ sw: SubwindowHandle, items: ParameterItemDescriptor, index: CARDINAL] = BEGIN PostLine[NIL]; ReadFile[ GetFile[name: input, access: Read, size: byte ! NoName => GOTO noInput; SegmentDefs.FileNameError => BEGIN NoFile[input]; GOTO return; END]]; RETURN EXITS noInput => PostLine["No input file specified"]; return => NULL; END; Dump: PUBLIC PROCEDURE [ sw: SubwindowHandle, items: ParameterItemDescriptor, index: CARDINAL] = BEGIN PostLine[NIL]; WriteFile[ GetFile[name: output, access: Write+Append, size: byte ! NoName => GOTO noOutput]]; RETURN EXITS noOutput => PostLine["No output file specified"]; END; Press: PUBLIC PROCEDURE [ sw: SubwindowHandle, items: ParameterItemDescriptor _ NULL, index: CARDINAL _ NULL] = BEGIN PostLine[NIL]; IF output = NIL OR output.length = 0 THEN GO TO noOutput; PressMyDefs.OutScreen[output]; RETURN EXITS noOutput => PostLine["No output file specified"]; END; NoFile: PROCEDURE [name: STRING] = BEGIN OPEN StringDefs; s: STRING _ [60]; AppendString[to: s, from: name]; AppendString[to: s, from: " cannout be found!"L]; PostLine[s]; RETURN END; NoName: SIGNAL = CODE; GetFile: PROCEDURE [name: STRING, access: AccessOptions, size: {byte, word}] RETURNS [StreamHandle] = BEGIN nameAndExt: STRING _ [30]; i: CARDINAL; dotSeen: BOOLEAN _ FALSE; IF name = NIL OR name.length = 0 THEN ERROR NoName; FOR i IN [0..name.length) DO StringDefs.AppendChar[nameAndExt, name[i]]; IF name[i] = '. THEN dotSeen _ TRUE; ENDLOOP; IF ~dotSeen THEN StringDefs.AppendString[nameAndExt, ".weave"]; RETURN[ IF size = byte THEN NewByteStream[nameAndExt,access] ELSE NewWordStream[nameAndExt,access]] END; PostLine: PUBLIC PROCEDURE [s: STRING] = BEGIN font: ToolsFontDefs.FAptr; fontHeight: INTEGER; [font: font, height: fontHeight] _ ToolsFontDefs.GetToolsFont[]; WhitenBoxInSubwindow[msgSW, [[0,0],[msgSW.box.dims.w,fontHeight]]]; IF s # NIL THEN [] _ ReplaceStringToPlaceInSubwindow[msgSW, [3,0], s, font] END; -- Tools Environment Required Procedures DisplayControlWindowContents: PROCEDURE [ window: WindowHandle, wBox: WindowBox, refreshSequencer: RefreshSequencer] RETURNS [WindowBox] = BEGIN sw: SubwindowHandle = window.subwindowChain; font: ToolsFontDefs.FAptr; fontHeight: INTEGER; [font: font, height: fontHeight] _ ToolsFontDefs.GetToolsFont[]; IF window.size = tiny THEN BEGIN name: STRING _ "LoomTool"L; DrawWindowFrame[window]; IF msgSW # NIL THEN MakeToolInactive[]; [] _ ReplaceStringToPlaceInSubwindow[ sw, [x: (sw.box.dims.w-ToolsFontDefs.ComputeStringWidth[name, font])/2, y: (sw.box.dims.h-fontHeight)/2], name, font]; sw.box _ [[0,0], [0,0]]; END ELSE BEGIN DrawWindowNameFrame[window, "Loom Tool 5.0"L]; IF msgSW = NIL THEN MakeToolActive[]; msgSW.box _ sw.box; msgSW.box.dims.h _ fontHeight; graySW.box _ sw.box; graySW.box.place.y _ sw.box.place.y + fontHeight + 2; graySW.box.dims.h _ fontHeight; BlackenBoxInSubwindow[sw, [[0, fontHeight+1], [sw.box.dims.w, 1]]]; DisplayGrays[]; parameterSW.box _ sw.box; parameterSW.box.place.y _ graySW.box.place.y + fontHeight + 2; parameterSW.box.dims.h _ sw.box.dims.h - 2*fontHeight - 4; BlackenBoxInSubwindow[sw, [[0, 2*fontHeight+2], [sw.box.dims.w, 1]]]; DisplayParameterSubwindow[parameterSW]; END; RETURN [wBox]; END; DisplayGrays: PROCEDURE = BEGIN x, dx: CARDINAL; c: ColorName; s: STRING _ [1]; font: ToolsFontDefs.FAptr; fontHeight: INTEGER; [font: font, height: fontHeight] _ ToolsFontDefs.GetToolsFont[]; x _ 1; s.length _ 1; FOR c IN ColorName DO s[0] _ c; dx _ ToolsFontDefs.ComputeStringWidth[s, font]; [] _ ReplaceStringToPlaceInSubwindow[graySW, [x, 0], s, font]; x _ x + dx; BlackenBoxInSubwindow[graySW, [[x, 0], [1, graySW.box.dims.h]]]; ShadeBoxInSubwindow[graySW, [[x+1, 0], [10, fontHeight]], GrayData[c]]; BlackenBoxInSubwindow[graySW, [[x+11, 0], [1, graySW.box.dims.h]]]; x _ x+12; ENDLOOP; END; EnterPNR: PROCEDURE [sw: SubwindowHandle, dir: PBKDefs.EnterExit] = BEGIN IF dir = enter THEN CursorDefs.SetCursor[CursorDefs.textPointer]; END; MakeToolActive: PROCEDURE = BEGIN weaveWindow _ CreateWindow[ normal: [[10,210], [500, 500]], tiny: [[256,400], [128, 32]], displayProc: DisplayWeaveWindowContents, adjustProc: StandardAdjustProc]; MakeMeAParameterSubwindow[]; msgSW _ CreateSubwindow[controlWindow, [[0,0], [10, 10]], NIL]; graySW _ CreateSubwindow[controlWindow, [[0,0], [10, 10]], NIL]; PBKInputDefs.SetNopPNRs[controlWindow.subwindowChain]; PBKInputDefs.SetNopPNRs[msgSW]; PBKInputDefs.SetNopPNRs[graySW]; weaveWindow.subwindowChain.pnrs.cursorPNR _ EnterPNR; MakeMyMenu[]; PaintWindow[weaveWindow]; END; MakeToolInactive: PUBLIC PROCEDURE = BEGIN OPEN SystemDefs; i: CARDINAL; DestroyParameterSubwindowEtc[parameterSW]; FreeMyMenu[]; DestroyWindowEtc[weaveWindow]; FOR i IN [0..nParams) DO FreeHeapString[parameterItems[i].tag]; FreeHeapNode[parameterItems[i]]; ENDLOOP; FreeHeapNode[BASE[parameterItems]]; DestroySubwindow[parameterSW]; DestroySubwindow[msgSW]; DestroySubwindow[graySW]; msgSW _ NIL; titleString _ ToolsDefs.FreeToolsString[titleString]; input _ ToolsDefs.FreeToolsString[input]; output _ ToolsDefs.FreeToolsString[output]; woString _ ToolsDefs.FreeToolsString[woString]; poString _ ToolsDefs.FreeToolsString[poString]; warpSizeString _ ToolsDefs.FreeToolsString[warpSizeString]; weftSizeString _ ToolsDefs.FreeToolsString[weftSizeString]; overlapString _ ToolsDefs.FreeToolsString[overlapString]; BEGIN p: Pedal; FOR p IN Pedal DO tieup[p] _ ToolsDefs.FreeToolsString[tieup[p]]; ENDLOOP; END; woBase _ ToolsDefs.FreeToolsNode[woBase]; poBase _ ToolsDefs.FreeToolsNode[poBase]; END; nParams: PUBLIC CARDINAL; poParmNum: PUBLIC CARDINAL; msgSW: PUBLIC SubwindowHandle _ NIL; parameterSW: PUBLIC SubwindowHandle; graySW: PUBLIC SubwindowHandle; input: PUBLIC STRING _ NIL; output: PUBLIC STRING _ NIL; titleString: PUBLIC STRING _ NIL; -- Mainline code ToolsDefs.SetToolsDestroyProc[DestroyThisTool]; START LoomDisplay; START LoomSetup; END. -- of LoomControl