DIRECTORY Commander USING [CommandProc, Register], Convert USING [RopeFromInt], Icons USING [IconFlavor, NewIconFromFile], IO USING [PutFR, int, rope], MBQueue USING [CreateMenuEntry], Menus USING [Menu, AppendMenuEntry, CreateEntry, MenuProc, CreateMenu], MessageWindow USING [Append, Blink, Clear], Rope USING [ROPE, Concat, FromChar, FromRefText, Substr], TEditDocument USING [SelectionId], TEditInput USING [CommandProc, Register, UnRegister, editState, RecordRef], TEditInputImpl USING [editObject, pdelState, pDel, sel, selState, mouseColor, editMessage, InterpInput], TEditInputOps USING [Delete, Copy, CopyFormat, CopyLooks, SetStyleName, Transpose, TransposeLooks, TransposeFormat], TEditSelection USING [pSel, sSel, MakeSelection], TextEdit USING [ChangeLooks, Size], TextLooks USING [allLooks, RopeToLooks ], TiogaButtons USING [TextNodeRef], TiogaOps USING [CallWithLocks, CancelSelection, FirstChild, GetRope, GetSelection, Location, Root, SelectPoint, ViewerDoc], TiogaOpsDefs USING [Location, Ref, SelectionGrain, WhichSelection], TiogaVoicePrivate USING [ AddCharMark, AddVoiceProc, AgeAllViewers, BackSpace, BackWord, CancelProc, DebugRope, DeleteCharMarks, DeleteSourceMarkers, DictationMachine, DictationOps, DisplayCharMarks, EditAges, EditCharMarks, EditTextMarks, ExtractCharMarks, ExtractSoundList, ExtractTextMarks, oldest, PlayBackMenuProc, ReColorViewer, RedrawTextMarkers, RedrawViewer, RegisterViewer, RemoveViewerReferences, ReplaceSoundList, RopeFromTextList, SaveRopeAtSourceMarkers, Selection, SelectionRec, Sound, SoundChars, SoundList, SoundInterval, SoundIntervalRec, SoundListFromIntervalSpecs, soundRopeCharDivisions, soundRopeCharLength, soundRopeResolution, StoreVoiceAtSelection, TextInput, TextListFromRope, thrushHandle, TrackDeletes, voiceButtonQueue, VoiceViewerInfo, VoiceViewerInfoList, VoiceViewerInfoRec, youngest ], TIPUser USING [InstantiateNewTIPTable, TIPTable], ViewerClasses USING [Viewer, NotifyProc, ViewerClass], ViewerEvents USING [EventRegistration, RegisterEventProc, UnRegisterEventProc, EventProc], ViewerLocks USING [CallUnderWriteLock], ViewerOps USING [AddProp, CreateViewer, DestroyViewer, FetchProp, FetchViewerClass, PaintViewer, SetMenu], ViewerTools USING [TiogaContents, TiogaContentsRec, SetTiogaContents], VoiceRope USING [ DescribeRope, IntervalSpecs, Length, Replace, VoiceRopeInterval ], WindowManager USING [colorDisplayOn] ; VoiceViewersImpl: CEDAR MONITOR IMPORTS Commander, Convert, Icons, IO, MBQueue, Menus, MessageWindow, Rope, TEditInput, TEditInputImpl, TEditInputOps, TEditSelection, TextEdit, TextLooks, TiogaButtons, TiogaOps, TiogaVoicePrivate, TIPUser, ViewerEvents, ViewerLocks, ViewerOps, ViewerTools, VoiceRope, WindowManager EXPORTS TiogaVoicePrivate SHARES TEditInputImpl = { voiceViewerMenu: PUBLIC Menus.Menu; CreateVoiceViewerMenu: PROC = { voiceViewerMenu _ Menus.CreateMenu[]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "Add", TiogaVoicePrivate.AddVoiceProc]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "Play", TiogaVoicePrivate.PlayBackMenuProc]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "STOP", TiogaVoicePrivate.CancelProc]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "Save", SaveVoice]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "Store", StoreVoice]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "Redraw", RedrawViewerMenuProc]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "Mark", TiogaVoicePrivate.AddCharMark]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "DeleteMarks", TiogaVoicePrivate.DeleteCharMarks]]; Menus.AppendMenuEntry[voiceViewerMenu, MBQueue.CreateMenuEntry[TiogaVoicePrivate.voiceButtonQueue, "DictationMachine", TiogaVoicePrivate.DictationMachine]]; Menus.AppendMenuEntry[voiceViewerMenu, Menus.CreateEntry["DictationOps", TiogaVoicePrivate.DictationOps]]; }; VoiceViewerInfo: TYPE = TiogaVoicePrivate.VoiceViewerInfo; VoiceViewerInfoList: TYPE = TiogaVoicePrivate.VoiceViewerInfoList; VoiceViewerInfoRec: TYPE = TiogaVoicePrivate.VoiceViewerInfoRec; voiceViewerInfoList: VoiceViewerInfoList _ NIL; nextVoiceViewerNumber: INT _ 1; voiceTIPTable: TIPUser.TIPTable _ NIL; soundViewerIcon: Icons.IconFlavor _ unInit; dirtySoundViewerIcon: Icons.IconFlavor _ unInit; BuildVoiceViewer: PUBLIC PROC [ voiceID: Rope.ROPE, textInVoice: Rope.ROPE, youngVoice: BOOLEAN] RETURNS [viewer: ViewerClasses.Viewer, viewerInfo: VoiceViewerInfo, viewerNumber: INT] = { viewerInfo _ InsertVoiceViewerInfo[]; viewer _ ViewerOps.CreateViewer[ flavor: $Text, info: [name: Rope.Concat["Sound Viewer #", Convert.RopeFromInt[viewerInfo.viewerNumber]], column: IF WindowManager.colorDisplayOn THEN color ELSE left, iconic: FALSE ], paint: TRUE]; viewer.inhibitDestroy _ FALSE; viewer.icon _ soundViewerIcon; viewer.tipTable _ voiceTIPTable; viewerNumber _ viewerInfo.viewerNumber; ViewerOps.AddProp[viewer, $voiceViewerInfo, viewerInfo]; viewerInfo.viewer _ viewer; viewerInfo.color _ viewer.column = color; ViewerOps.SetMenu[viewer, voiceViewerMenu]; viewerInfo.destroyEvent _ ViewerEvents.RegisterEventProc[ proc: DestroyViewerEvent, event: destroy, filter: viewer, before: TRUE]; viewerInfo.changeColumnEvent _ ViewerEvents.RegisterEventProc[ proc: ChangeColumnEvent, event: changeColumn, filter: viewer, before: FALSE]; SetViewerContents[viewer, viewerInfo, voiceID, textInVoice, youngVoice]; MakeVoiceNotEdited[viewer]; }; SetVoiceRopeInfo: PROC [viewerInfo: VoiceViewerInfo, voiceID: Rope.ROPE, textInVoice: Rope.ROPE, youngVoice: BOOLEAN] RETURNS [soundRope: Rope.ROPE] ~ { intervals: VoiceRope.IntervalSpecs; viewerInfo.soundList _ NIL; IF voiceID # NIL THEN { viewerInfo.ropeInterval _ [voiceID, 0, VoiceRope.Length[TiogaVoicePrivate.thrushHandle, NEW [VoiceRope.VoiceRopeInterval _ [voiceID, 0, 0]]]]; intervals _ VoiceRope.DescribeRope[TiogaVoicePrivate.thrushHandle, NEW [VoiceRope.VoiceRopeInterval _ viewerInfo.ropeInterval]]; viewerInfo.soundList _ TiogaVoicePrivate.SoundListFromIntervalSpecs[intervals, viewerInfo.ropeInterval.length]; [soundRope: soundRope, remnant: viewerInfo.remnant] _ TiogaVoicePrivate.SoundChars[viewerInfo]; viewerInfo.textMarkList _ TiogaVoicePrivate.TextListFromRope[textInVoice]; viewerInfo.ageList _ CONS [[0, IF youngVoice THEN TiogaVoicePrivate.youngest-1 ELSE TiogaVoicePrivate.oldest], NIL]; } ELSE { soundRope _ " "; viewerInfo.ropeInterval _ [NIL, 0, 0]; }; }; SetViewerContents: PUBLIC PROC [viewer: ViewerClasses.Viewer, viewerInfo: VoiceViewerInfo, voiceID: Rope.ROPE, textInVoice: Rope.ROPE, youngVoice: BOOLEAN] = { soundRope: Rope.ROPE _ SetVoiceRopeInfo[viewerInfo, voiceID, textInVoice, youngVoice]; [] _ SetTiogaViewerParams[viewer, soundRope]; IF voiceID # NIL AND viewerInfo.ageList.first.age = TiogaVoicePrivate.youngest-1 THEN TiogaVoicePrivate.AgeAllViewers[viewer] ELSE TiogaVoicePrivate.ReColorViewer[viewer, viewerInfo]; viewerInfo.editInProgress _ (voiceID = NIL) -- can do this because the viewer is created with editInProgress = TRUE, so nobody else can have grabbed the lock }; SetTiogaViewerParams: PUBLIC PROC [viewer: ViewerClasses.Viewer, newcontents: Rope.ROPE] RETURNS [voiceNode: TiogaOpsDefs.Ref] = { rootNode: TiogaOpsDefs.Ref; viewercontents: ViewerTools.TiogaContents _ NEW[ViewerTools.TiogaContentsRec _ [contents: newcontents, formatting: NIL]]; ViewerTools.SetTiogaContents[viewer, viewercontents]; rootNode _ TiogaOps.ViewerDoc[viewer]; TEditInputOps.SetStyleName["voiceProfile", TiogaButtons.TextNodeRef[rootNode]]; voiceNode _ TiogaOps.FirstChild[rootNode]; SetVoiceLooks[voiceNode, 0, LAST[INT], "v"]; TiogaVoicePrivate.RedrawTextMarkers[viewer, voiceNode]; }; SetVoiceLooks: PUBLIC PROC [node: TiogaOpsDefs.Ref, start, len: INT, looks: Rope.ROPE] ~ { DoIt: PROC [root: TiogaOpsDefs.Ref] ~ { TextEdit.ChangeLooks[root: TiogaButtons.TextNodeRef[root], text: TiogaButtons.TextNodeRef[node], remove: TextLooks.allLooks, add: TextLooks.RopeToLooks[looks], start: start, len: len, event: NIL] }; TiogaOps.CallWithLocks[DoIt, TiogaOps.Root[node]]; }; MakeVoiceEdited: PUBLIC PROC [viewer: ViewerClasses.Viewer] = { DoIt: PROC = { viewerInfo.edited _ viewer.newVersion _ TRUE; viewer.icon _ dirtySoundViewerIcon; ViewerOps.PaintViewer[viewer, caption, FALSE]; }; viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; IF NOT viewerInfo.edited THEN ViewerLocks.CallUnderWriteLock[DoIt, viewer] }; MakeVoiceNotEdited: PROC [viewer: ViewerClasses.Viewer] = { DoIt: PROC = { viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; viewerInfo.edited _ viewer.newVersion _ viewer.newFile _ FALSE; viewer.icon _ soundViewerIcon; ViewerOps.PaintViewer[viewer, caption, FALSE]; }; ViewerLocks.CallUnderWriteLock[DoIt, viewer] }; SetVoiceViewerEditStatus: PUBLIC PROC [viewer: ViewerClasses.Viewer] = { DoIt: PROC = { viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; IF viewerInfo.edited # viewer.newVersion THEN { viewer.newVersion _ viewerInfo.edited; IF ~viewerInfo.edited THEN { viewer.newFile _ FALSE; viewer.icon _ soundViewerIcon; } ELSE viewer.icon _ dirtySoundViewerIcon; ViewerOps.PaintViewer[viewer, caption, FALSE]; } }; ViewerLocks.CallUnderWriteLock[DoIt, viewer] }; SameViewerDoc: PUBLIC PROC [v1, v2: ViewerClasses.Viewer] RETURNS [BOOL] = { FOR v: ViewerClasses.Viewer _ v1, v1.link DO IF v=v2 THEN RETURN[TRUE]; IF v=v1 THEN EXIT; ENDLOOP; RETURN[FALSE]; }; SetParentViewer: PUBLIC PROC [viewerInfo: VoiceViewerInfo, parentViewer: ViewerClasses.Viewer, positionInParent: TiogaOpsDefs.Location] = { viewerInfo.parentViewer _ parentViewer; viewerInfo.positionInParent _ positionInParent; TiogaVoicePrivate.RegisterViewer[parentViewer]; }; FindAttachedVoiceViewers: PUBLIC PROC [viewer: ViewerClasses.Viewer] RETURNS [viewerInfoList: VoiceViewerInfoList] = { FOR vList: VoiceViewerInfoList _ voiceViewerInfoList, vList.rest WHILE vList # NIL DO IF vList.first.parentViewer = viewer THEN viewerInfoList _ CONS[vList.first, viewerInfoList] ENDLOOP; }; RemoveParentPointersTo: PUBLIC PROC [viewer: ViewerClasses.Viewer, findSplits: BOOLEAN] = { FOR vList: VoiceViewerInfoList _ voiceViewerInfoList, vList.rest WHILE vList # NIL DO info: VoiceViewerInfo _ vList.first; IF info.parentViewer = viewer THEN { splitLink: ViewerClasses.Viewer _ info.parentViewer.link; IF findSplits AND splitLink # NIL THEN { info.parentViewer _ splitLink; TiogaVoicePrivate.RegisterViewer[splitLink]; } ELSE { info.parentViewer _ NIL; MessageWindow.Append[IO.PutFR["Detaching parent link for voice viewer %d\n", IO.int[info.viewerNumber]], TRUE] -- was DebugRope; may be too verbose }; } ENDLOOP }; RemoveParentViewer: PUBLIC PROC [viewerInfo: VoiceViewerInfo] = { viewerInfo.parentViewer _ NIL; }; GetVoiceViewerInfo: PUBLIC PROC [n: INT] RETURNS [viewerInfo: VoiceViewerInfo] = { FOR vList: VoiceViewerInfoList _ voiceViewerInfoList, vList.rest WHILE vList#NIL DO IF vList.first.viewerNumber=n THEN RETURN[vList.first]; ENDLOOP; }; GetVoiceViewerInfoList: PUBLIC PROC RETURNS [vList: VoiceViewerInfoList] = { RETURN[voiceViewerInfoList]; }; InsertVoiceViewerInfo: PROC RETURNS [newViewerInfo: VoiceViewerInfo] = { newViewerInfo _ NEW[VoiceViewerInfoRec]; newViewerInfo.viewerNumber _ nextVoiceViewerNumber; nextVoiceViewerNumber _ nextVoiceViewerNumber + 1; voiceViewerInfoList _ CONS[newViewerInfo, voiceViewerInfoList]; }; StoreVoice: Menus.MenuProc = { viewer: ViewerClasses.Viewer _ NARROW[parent]; viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; oldParentViewer: ViewerClasses.Viewer _ viewerInfo.parentViewer; IF TiogaVoicePrivate.StoreVoiceAtSelection[viewerInfo] THEN { MakeVoiceNotEdited[viewer]; IF oldParentViewer # NIL THEN TiogaVoicePrivate.DeleteSourceMarkers[oldParentViewer, viewerInfo.viewerNumber, viewerInfo.positionInParent]; }; }; SaveVoice: Menus.MenuProc = { viewer: ViewerClasses.Viewer _ NARROW[parent]; viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; IF ~viewerInfo.edited THEN { MessageWindow.Append["Voice viewer is not edited", TRUE]; RETURN }; IF viewerInfo.parentViewer = NIL THEN { MessageWindow.Append["Voice viewer has no parent text viewer", TRUE]; MessageWindow.Blink[]; RETURN }; IF ~TiogaVoicePrivate.SaveRopeAtSourceMarkers[viewerInfo.parentViewer, viewerInfo.viewerNumber, viewerInfo.ropeInterval.ropeID, TiogaVoicePrivate.RopeFromTextList[viewerInfo.textMarkList]] THEN { MessageWindow.Append["Unable to find source marker for voice window: voice not saved", TRUE]; MessageWindow.Blink[]; RETURN }; MakeVoiceNotEdited[viewer] }; RemoveVoiceViewerInfo: PROC [viewerInfo: VoiceViewerInfo] = { IF voiceViewerInfoList # NIL THEN { IF voiceViewerInfoList.first = viewerInfo THEN {voiceViewerInfoList _ voiceViewerInfoList.rest; RETURN}; FOR vList: VoiceViewerInfoList _ voiceViewerInfoList, vList.rest WHILE vList#NIL DO IF vList.rest.first = viewerInfo THEN {vList.rest _ vList.rest.rest; RETURN} ENDLOOP; }; ERROR; -- not in list! }; DestroyViewerEvent: ViewerEvents.EventProc = { RETURN [~DestroyVoiceInfo[viewer]] }; DestroyVoiceInfo: PROC [ viewer: ViewerClasses.Viewer] RETURNS [didIt: BOOLEAN _ TRUE] = { viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; IF ~TiogaVoicePrivate.RemoveViewerReferences[viewer] THEN { MessageWindow.Append["Wait until voice cue disappears before destroying viewer", TRUE]; MessageWindow.Blink[]; RETURN [FALSE] }; IF viewerInfo.editInProgress THEN { MessageWindow.Append["Finish edit in progress before destroying viewer", TRUE]; MessageWindow.Blink[]; RETURN [FALSE] }; ViewerEvents.UnRegisterEventProc[viewerInfo.destroyEvent, destroy]; ViewerEvents.UnRegisterEventProc[viewerInfo.changeColumnEvent, changeColumn]; IF viewerInfo.parentViewer = NIL THEN TiogaVoicePrivate.DebugRope[IO.PutFR["Voice viewer %d had no parent\n", IO.int[viewerInfo.viewerNumber]]] ELSE TiogaVoicePrivate.DeleteSourceMarkers[viewerInfo.parentViewer, viewerInfo.viewerNumber, [NIL, -1]]; RemoveVoiceViewerInfo[viewerInfo]; }; RedrawViewerMenuProc: Menus.MenuProc = { viewer: ViewerClasses.Viewer _ NARROW[parent]; viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; IF GetVoiceLock[viewerInfo] THEN { trueContents: Rope.ROPE _ TiogaVoicePrivate.SoundChars[viewerInfo].soundRope; [] _ TiogaVoicePrivate.RedrawViewer[viewer, trueContents, 0, 0, 0, viewerInfo.remnant, FALSE, unAltered]; SetVoiceViewerEditStatus[viewer]; viewerInfo.editInProgress _ FALSE } }; ChangeColumnEvent: ViewerEvents.EventProc = { viewerInfo: VoiceViewerInfo _ NARROW[ViewerOps.FetchProp[viewer, $voiceViewerInfo], VoiceViewerInfo]; IF (viewer.column = color) # viewerInfo.color THEN { viewerInfo.color _ viewer.column = color; IF GetVoiceLock[viewerInfo] THEN { trueContents: Rope.ROPE _ TiogaVoicePrivate.SoundChars[viewerInfo].soundRope; [] _ TiogaVoicePrivate.RedrawViewer[viewer, trueContents, 0, 0, 0, viewerInfo.remnant, FALSE, unAltered]; SetVoiceViewerEditStatus[viewer]; viewerInfo.editInProgress _ FALSE } ELSE { MessageWindow.Append["Cannot repaint viewer during edit: click REDRAW to change window between color and monchrome if the wrong state persists", TRUE]; MessageWindow.Blink[] } } }; GetVoiceLock: PUBLIC ENTRY PROC [ info: VoiceViewerInfo] RETURNS [gotIt: BOOLEAN] = { gotIt _ ~ info.editInProgress; IF info.editInProgress THEN MessageWindow.Append["Try again when the viewer's contents are stable", TRUE] ELSE info.editInProgress _ TRUE; }; InterceptAllInput: ViewerClasses.NotifyProc = { IF ViewerOps.FetchProp[self, $voiceViewerInfo] = NIL THEN TEditInputImpl.InterpInput[self, input] -- just what the real one does ELSE { passOnList, endOfPassOnList: LIST OF REF ANY _ NIL; FOR currItem: LIST OF REF ANY _ input, currItem.rest WHILE currItem # NIL DO WITH currItem.first SELECT FROM z: REF CHAR => { IF passOnList # NIL THEN { TEditInputImpl.InterpInput[self, passOnList]; passOnList _ NIL }; TiogaVoicePrivate.TextInput[self, Rope.FromChar[z^]] }; z: Rope.ROPE => { IF passOnList # NIL THEN { TEditInputImpl.InterpInput[self, passOnList]; passOnList _ NIL }; TiogaVoicePrivate.TextInput[self, z] }; z: REF TEXT => { IF passOnList # NIL THEN { TEditInputImpl.InterpInput[self, passOnList]; passOnList _ NIL }; TiogaVoicePrivate.TextInput[self, Rope.FromRefText[z]] }; ENDCASE => IF passOnList = NIL THEN { passOnList _ CONS[currItem.first, NIL]; endOfPassOnList _ passOnList } ELSE { endOfPassOnList.rest _ CONS[currItem.first, NIL]; endOfPassOnList _ endOfPassOnList.rest } ENDLOOP; IF passOnList # NIL THEN TEditInputImpl.InterpInput[self, passOnList] } }; InterceptBackSpace: TEditInput.CommandProc = { IF TestPrimary[] = normal THEN RETURN; TiogaVoicePrivate.BackSpace[viewer]; RETURN [quit: TRUE] }; InterceptBackWord: TEditInput.CommandProc = { IF TestPrimary[] = normal THEN RETURN; TiogaVoicePrivate.BackWord[viewer]; RETURN [quit: TRUE] }; InterceptDelete: TEditInput.CommandProc = { IF TestPrimary[] = normal THEN TiogaVoicePrivate.TrackDeletes[] ELSE { Delete[]; RETURN [quit: TRUE] }; }; InterceptEdit: TEditInput.CommandProc = { quit _ TRUE; IF TEditSelection.pSel.viewer = NIL THEN { IF TEditSelection.sSel.viewer # NIL THEN TEditSelection.MakeSelection[NIL,secondary]; -- get rid of secondary recordAtom _ FALSE } ELSE IF TEditInput.editState = tolimbo THEN { recordAtom _ FALSE; TEditInput.RecordRef[$Delete]; CheckDelete[TRUE] } ELSE IF TEditSelection.sSel.viewer = NIL THEN recordAtom _ FALSE ELSE { RecordEditObject: PROC = { TEditInput.RecordRef[SELECT TEditInputImpl.editObject FROM text => $EditText, looks => $EditLooks, format => $EditFormat, ENDCASE => ERROR] }; recordAtom _ TRUE; SELECT TEditInput.editState FROM reset, abort => recordAtom _ FALSE; toprimary => { TEditInput.RecordRef[$GetSecondary]; TEditInput.RecordRef[$ToPrimary]; RecordEditObject[]; SELECT TEditInputImpl.editObject FROM text => { IF TEditSelection.pSel.pendingDelete THEN TEditInput.RecordRef[$MakePDel]; CheckCopy[primary] }; looks => CheckCopyLooks[primary]; format => CheckCopyFormat[primary]; ENDCASE => ERROR }; tosecondary => { TEditInput.RecordRef[$GetSecondary]; TEditInput.RecordRef[$ToSecondary]; RecordEditObject[]; SELECT TEditInputImpl.editObject FROM text => { IF TEditSelection.pSel.pendingDelete THEN TEditInput.RecordRef[$MakePDel]; CheckCopy[secondary] }; looks => CheckCopyLooks[secondary]; format => CheckCopyFormat[secondary]; ENDCASE => ERROR }; toboth => { TEditInput.RecordRef[$GetSecondary]; TEditInput.RecordRef[$ToBoth]; RecordEditObject[]; SELECT TEditInputImpl.editObject FROM text => CheckTranspose[]; looks => CheckTransposeLooks[]; format => CheckTransposeFormat[]; ENDCASE => ERROR }; ENDCASE => ERROR }; TEditInput.editState _ reset; TEditInputImpl.editObject _ text; TEditInputImpl.pdelState _ reset; TEditInputImpl.pDel _ FALSE; TEditInputImpl.selState _ reset; TEditInputImpl.sel _ primary; TEditInputImpl.mouseColor _ red; -- put these back to normal IF TEditInputImpl.editMessage # NIL THEN MessageWindow.Clear[]; TEditInputImpl.editMessage _ NIL }; selectionTypes: TYPE = {bothNormal, primaryVoice, secondaryVoice, bothVoice}; TestSelections: PROC RETURNS [types: selectionTypes] = { types _ IF ViewerOps.FetchProp[TiogaOps.GetSelection[primary].viewer, $voiceViewerInfo] = NIL THEN ( IF ViewerOps.FetchProp[TiogaOps.GetSelection[secondary].viewer, $voiceViewerInfo] = NIL THEN bothNormal ELSE secondaryVoice ) ELSE ( IF ViewerOps.FetchProp[TiogaOps.GetSelection[secondary].viewer, $voiceViewerInfo] = NIL THEN primaryVoice ELSE bothVoice ) }; primaryType: TYPE = {normal, voice}; TestPrimary: PROC RETURNS [type: primaryType] = { type _ IF ViewerOps.FetchProp[TiogaOps.GetSelection[primary].viewer, $voiceViewerInfo] = NIL THEN normal ELSE voice }; CheckDelete: PROC [saveForPaste: BOOL _ TRUE] = { SELECT TestPrimary[] FROM normal => { TiogaVoicePrivate.TrackDeletes[]; TEditInputOps.Delete[saveForPaste] }; voice => Delete[] ENDCASE }; CheckCopy: PROC [target: TEditDocument.SelectionId _ primary] = { SELECT TestSelections[] FROM bothNormal => { IF VoiceInSourceDocument[target] THEN TrackTextCopy[target]; TEditInputOps.Copy[target]; }; bothVoice => Copy[target]; ENDCASE => Mumble["Copy", "voice and text"] }; VoiceInSourceDocument: PROC [target: TEditDocument.SelectionId _ primary] RETURNS [BOOLEAN _ FALSE] = { }; TrackTextCopy: PROC [target: TEditDocument.SelectionId _ primary] = { }; CheckCopyFormat: PROC [target: TEditDocument.SelectionId _ primary] = { SELECT TestSelections[] FROM bothNormal => TEditInputOps.CopyFormat[target]; bothVoice => Mumble["Copy format", "two voice"] ENDCASE => Mumble["Copy format", "voice and text"] }; CheckCopyLooks: PROC [target: TEditDocument.SelectionId _ primary] = { SELECT TestSelections[] FROM bothNormal => TEditInputOps.CopyLooks[target]; bothVoice => Mumble["Copy looks", "two voice"] ENDCASE => Mumble["Copy looks", "voice and text"] }; CheckTranspose: PROC [target: TEditDocument.SelectionId _ primary] = { SELECT TestSelections[] FROM bothNormal => TEditInputOps.Transpose[target]; bothVoice => Transpose[target]; ENDCASE => Mumble["Transpose", "voice and text"] }; CheckTransposeFormat: PROC [target: TEditDocument.SelectionId _ primary] = { SELECT TestSelections[] FROM bothNormal => TEditInputOps.TransposeFormat[target]; bothVoice => Mumble["Transpose format", "two voice"] ENDCASE => Mumble["Transpose format", "voice and text"] }; CheckTransposeLooks: PROC [target: TEditDocument.SelectionId _ primary] = { SELECT TestSelections[] FROM bothNormal => TEditInputOps.TransposeLooks[target]; bothVoice => Mumble["Transpose looks", "two voice"] ENDCASE => Mumble["Transpose looks", "voice and text"] }; textClassDescriptor: ViewerClasses.ViewerClass _ ViewerOps.FetchViewerClass[$Text]; realNotifyProc: ViewerClasses.NotifyProc _ textClassDescriptor.notify; HereWeGoAgain: Commander.CommandProc = { textClassDescriptor: ViewerClasses.ViewerClass _ ViewerOps.FetchViewerClass[$Text]; textClassDescriptor.notify _ realNotifyProc; TEditInput.UnRegister[$BackSpace, InterceptBackSpace]; TEditInput.UnRegister[$BackWord, InterceptBackWord]; TEditInput.UnRegister[$Delete, InterceptDelete]; TEditInput.UnRegister[$DoEdit, InterceptEdit]; }; BadVoiceViewerDisplay: ERROR [viewer: ViewerClasses.Viewer]; Mumble: PUBLIC PROC [opAttempted: Rope.ROPE, viewerTypes: Rope.ROPE] = { MessageWindow.Append[IO.PutFR["%g is not a valid operation between %g viewers", IO.rope[opAttempted], IO.rope[viewerTypes]], TRUE]; MessageWindow.Blink[] }; DescribeSelection: PUBLIC PROC [ which: TiogaOpsDefs.WhichSelection, forceDelete: BOOLEAN, returnSoundInterval: BOOLEAN, viewerAlreadyLocked: ViewerClasses.Viewer _ NIL] RETURNS [failed: BOOLEAN _ FALSE, selection: TiogaVoicePrivate.Selection, soundInterval: TiogaVoicePrivate.SoundInterval _ NIL] = { selStart, selEnd: TiogaOps.Location; caretBefore, pendingDelete: BOOL; level: TiogaOpsDefs.SelectionGrain; selection _ NEW[TiogaVoicePrivate.SelectionRec]; [viewer: selection.viewer, start: selStart, end: selEnd, level: level, caretBefore: caretBefore, pendingDelete: pendingDelete] _ TiogaOps.GetSelection[which]; selection.voiceViewerInfo _ NARROW[ViewerOps.FetchProp[selection.viewer, $voiceViewerInfo], VoiceViewerInfo]; IF ~( viewerAlreadyLocked = selection.viewer OR GetVoiceLock[selection.voiceViewerInfo] ) THEN {failed _ TRUE; RETURN}; IF selStart.node # selEnd.node THEN ERROR BadVoiceViewerDisplay[selection.viewer]; selection.displayNode _ selStart.node; selection.ropeInterval _ [selection.voiceViewerInfo.ropeInterval.ropeID, selStart.where*TiogaVoicePrivate.soundRopeCharLength, (selEnd.where+(IF level=point THEN 0 ELSE 1))*TiogaVoicePrivate.soundRopeCharLength -selStart.where*TiogaVoicePrivate.soundRopeCharLength]; IF selection.ropeInterval.start + selection.ropeInterval.length > selection.voiceViewerInfo.ropeInterval.length THEN ERROR BadVoiceViewerDisplay[selection.viewer]; IF returnSoundInterval THEN { soundInterval _ NEW [TiogaVoicePrivate.SoundIntervalRec _ [ropeInterval: selection.ropeInterval]]; TiogaVoicePrivate.ExtractSoundList[selection.voiceViewerInfo, soundInterval]; TiogaVoicePrivate.ExtractCharMarks[selection.voiceViewerInfo, soundInterval]; TiogaVoicePrivate.ExtractTextMarks[selection.voiceViewerInfo, soundInterval] -- the width/displayChars fields in this will not necessarily be valid at the end of the list }; IF ~(pendingDelete OR forceDelete) THEN { IF ~caretBefore THEN selection.ropeInterval.start _ selection.ropeInterval.start + selection.ropeInterval.length; selection.ropeInterval.length _ 0 } }; ReplaceSelectionWithSavedInterval: PUBLIC PROC [ selection: TiogaVoicePrivate.Selection, soundInterval: TiogaVoicePrivate.SoundInterval, leaveSelected: BOOL, destroyOK: BOOL _ TRUE] RETURNS [viewerDeleted: BOOLEAN, insertChars, positionAfterInsert: INT] = { newViewerContents: Rope.ROPE; displayCutPoint, deleteChars: INT; IF selection.ropeInterval.length = 0 AND soundInterval = NIL THEN RETURN; TiogaVoicePrivate.ReplaceSoundList[voiceViewerInfo: selection.voiceViewerInfo, cutStart: selection.ropeInterval.start, cutLength: selection.ropeInterval.length, replacement: IF soundInterval = NIL THEN NIL ELSE soundInterval.soundList]; displayCutPoint _ selection.ropeInterval.start/TiogaVoicePrivate.soundRopeCharLength; deleteChars _ selection.ropeInterval.length/TiogaVoicePrivate.soundRopeCharLength; insertChars _ IF soundInterval = NIL THEN 0 ELSE soundInterval.ropeInterval.length/TiogaVoicePrivate.soundRopeCharLength; positionAfterInsert _ displayCutPoint + insertChars + 1; TiogaVoicePrivate.EditCharMarks[selection.voiceViewerInfo, displayCutPoint, deleteChars, insertChars, soundInterval]; TiogaVoicePrivate.EditTextMarks[selection.voiceViewerInfo, displayCutPoint, deleteChars, insertChars, soundInterval]; TiogaVoicePrivate.EditAges[selection.voiceViewerInfo, displayCutPoint, deleteChars, insertChars]; [newViewerContents, selection.voiceViewerInfo.remnant] _ TiogaVoicePrivate.SoundChars[selection.voiceViewerInfo, displayCutPoint]; newViewerContents _ Rope.Concat[(TiogaOps.GetRope[selection.displayNode]).Substr[0, displayCutPoint], newViewerContents]; selection.displayNode _ TiogaVoicePrivate.RedrawViewer[selection.viewer, newViewerContents, displayCutPoint, deleteChars, insertChars, selection.voiceViewerInfo.remnant, TRUE, IF leaveSelected THEN primaryOnInsert ELSE deSelected]; viewerDeleted _ destroyOK AND TextEdit.Size[TiogaButtons.TextNodeRef[selection.displayNode]] = 0; IF viewerDeleted THEN { MessageWindow.Append["Voice viewer now completely empty - destroying", TRUE]; ViewerOps.DestroyViewer[selection.viewer]; } ELSE { selection.voiceViewerInfo.ropeInterval _ VoiceRope.Replace[handle: TiogaVoicePrivate.thrushHandle, vr: NEW [VoiceRope.VoiceRopeInterval _ selection.voiceViewerInfo.ropeInterval], start: selection.ropeInterval.start, len: selection.ropeInterval.length, with: IF soundInterval = NIL THEN NIL ELSE NEW [VoiceRope.VoiceRopeInterval _ soundInterval.ropeInterval]]^ } }; Delete: PUBLIC PROC = { charAfterDelete: INT; viewerDeleted: BOOLEAN; selectionLocked: BOOLEAN; selection: TiogaVoicePrivate.Selection; [selection: selection, failed: selectionLocked] _ DescribeSelection[which: primary, forceDelete: TRUE, returnSoundInterval: FALSE]; IF selectionLocked THEN RETURN; MakeVoiceEdited[selection.viewer]; [positionAfterInsert: charAfterDelete, viewerDeleted: viewerDeleted] _ ReplaceSelectionWithSavedInterval[selection: selection, soundInterval: NIL, leaveSelected: TRUE]; IF ~viewerDeleted THEN { TiogaOps.SelectPoint[viewer: selection.viewer, caret: [selection.displayNode, MIN [charAfterDelete, TextEdit.Size[TiogaButtons.TextNodeRef[selection.displayNode]]-1]], which: primary]; selection.voiceViewerInfo.editInProgress _ FALSE } }; Copy: PUBLIC PROC [target: TEditDocument.SelectionId _ primary] = { sourceSelection, destSelection: TiogaVoicePrivate.Selection; sourceInterval: TiogaVoicePrivate.SoundInterval; selectionLocked: BOOLEAN; destMovesForward: INT _ 0; [selection: sourceSelection, soundInterval: sourceInterval, failed: selectionLocked] _ DescribeSelection[which: (IF target=primary THEN secondary ELSE primary), forceDelete: FALSE, returnSoundInterval: TRUE]; IF ~selectionLocked THEN { [selection: destSelection, failed: selectionLocked] _ DescribeSelection[which: (IF target=primary THEN primary ELSE secondary), forceDelete: FALSE, returnSoundInterval: FALSE, viewerAlreadyLocked: sourceSelection.viewer]; IF selectionLocked THEN sourceSelection.voiceViewerInfo.editInProgress _ FALSE }; TiogaOps.CancelSelection[primary]; TiogaOps.CancelSelection[secondary]; IF selectionLocked THEN RETURN; MakeVoiceEdited[destSelection.viewer]; IF sourceSelection.ropeInterval.length # 0 THEN { MakeVoiceEdited[sourceSelection.viewer]; IF sourceSelection.viewer = destSelection.viewer THEN { -- special case: same viewer IF (sourceSelection.ropeInterval.start< destSelection.ropeInterval.start+destSelection.ropeInterval.length) = (destSelection.ropeInterval.start< sourceSelection.ropeInterval.start+sourceSelection.ropeInterval.length) THEN { firstStart: INT _ destSelection.ropeInterval.start; firstLength: INT _ MAX [sourceSelection.ropeInterval.start -destSelection.ropeInterval.start, 0]; secondStart: INT _ sourceSelection.ropeInterval.start + sourceSelection.ropeInterval.length; secondLength: INT _ MAX [(destSelection.ropeInterval.start+destSelection.ropeInterval.length) - (sourceSelection.ropeInterval.start+sourceSelection.ropeInterval.length), 0]; sourceSelection.ropeInterval.start _ firstStart; sourceSelection.ropeInterval.length _ firstLength; destSelection.ropeInterval.start _ secondStart; destSelection.ropeInterval.length _ secondLength; sourceInterval _ NIL }; IF sourceSelection.ropeInterval.start lastSoundEnd THEN soundList _ AppendSound[soundList, [lengthOfRopeInterval-lastSoundEnd, 0]] }; ExtractSoundList: PUBLIC PROC [ voiceViewerInfo: VoiceViewerInfo, soundInterval: TiogaVoicePrivate.SoundInterval] = { soughtStart: INT _ soundInterval.ropeInterval.start; soughtEnd: INT _ soughtStart + soundInterval.ropeInterval.length; currStart, currEnd: INT _ 0; thisSilence, thisSound: INT; FOR l: TiogaVoicePrivate.SoundList _ voiceViewerInfo.soundList, l.rest WHILE l # NIL AND soughtEnd > currEnd DO currStart _ currEnd; thisSilence _ l.first.silence; thisSound _ l.first.sound; currEnd _ currStart + thisSilence + thisSound; IF soughtStart < currEnd THEN { IF soughtStart > currStart THEN { thisSound _ thisSound - MAX [soughtStart-currStart-thisSilence, 0]; thisSilence _ thisSilence - MIN [soughtStart-currStart, thisSilence] }; IF soughtEnd < currEnd THEN { thisSilence _ thisSilence - MAX [currEnd-soughtEnd-thisSound, 0]; thisSound _ thisSound - MIN [ currEnd-soughtEnd, thisSound] }; AppendSoundToSoundInterval[soundInterval, [thisSilence, thisSound]] } ENDLOOP }; ReplaceSoundList: PUBLIC PROC [ voiceViewerInfo: VoiceViewerInfo, cutStart: INT, cutLength: INT, replacement: TiogaVoicePrivate.SoundList] = { tail, workingPtr: TiogaVoicePrivate.SoundList; endCurrSound, startCurrSound: INT _ 0; IF cutStart = 0 THEN { tail _ voiceViewerInfo.soundList; voiceViewerInfo.soundList _ NIL } ELSE { FOR workingPtr _ voiceViewerInfo.soundList, workingPtr.rest DO endCurrSound _ endCurrSound + workingPtr.first.silence + workingPtr.first.sound; IF endCurrSound >= cutStart THEN EXIT ENDLOOP; tail _ workingPtr.rest; workingPtr.rest _ NIL; IF endCurrSound > cutStart THEN -- Have to 'move sound from workingPtr to tail' { silenceToMove: INT _ MAX [endCurrSound-cutStart-workingPtr.first.sound, 0]; soundToMove: INT _ MIN [endCurrSound-cutStart, workingPtr.first.sound]; tail _ CONS[[silenceToMove, soundToMove], tail]; workingPtr.first.silence _ workingPtr.first.silence - silenceToMove; workingPtr.first.sound _ workingPtr.first.sound - soundToMove } }; endCurrSound _ 0; DO startCurrSound _ endCurrSound; IF startCurrSound = cutLength THEN EXIT; endCurrSound _ endCurrSound + tail.first.silence + tail.first.sound; IF endCurrSound > cutLength THEN EXIT; tail _ tail.rest; ENDLOOP; IF startCurrSound < cutLength THEN -- delete some of the sound in the head of the list { silenceToSave: INT _ MAX [endCurrSound-cutLength-tail.first.sound, 0]; soundToSave: INT _ MIN [endCurrSound-cutLength, tail.first.sound]; tail.first.silence _ silenceToSave; tail.first.sound _ soundToSave }; IF replacement = NIL THEN replacement _ tail ELSE AppendSoundListToSoundList[replacement, tail]; IF voiceViewerInfo.soundList = NIL THEN voiceViewerInfo.soundList _ replacement ELSE AppendSoundListToSoundList[voiceViewerInfo.soundList, replacement] }; SoundChars: PUBLIC PROC [ viewerInfo: VoiceViewerInfo, skipChars: INT _ 0] RETURNS [soundRope: Rope.ROPE _ NIL, remnant: INT] = { soundList: TiogaVoicePrivate.SoundList _ viewerInfo.soundList; partiallyFilled: BOOLEAN _ FALSE; partsFilled: [0..TiogaVoicePrivate.soundRopeCharDivisions] _ 0; soundMajority: ARRAY [0..TiogaVoicePrivate.soundRopeCharDivisions) OF BOOLEAN; samplesAccounted, soundComponents: [0..TiogaVoicePrivate.soundRopeResolution] _ 0; skipping: BOOLEAN _ skipChars>0; skipSamples: INT _ skipChars*TiogaVoicePrivate.soundRopeCharLength; AddChars: PROC [length: INT, sound: BOOLEAN] = { AddToPartChar: PROC [availableSamples: INT, sound: BOOLEAN] RETURNS [usedSamples: [0..TiogaVoicePrivate.soundRopeResolution]] = { partiallyFilled _ TRUE; usedSamples _ MIN[availableSamples, TiogaVoicePrivate.soundRopeResolution-samplesAccounted]; samplesAccounted _ samplesAccounted + usedSamples; IF sound THEN soundComponents _ soundComponents + usedSamples; IF samplesAccounted = TiogaVoicePrivate.soundRopeResolution THEN { soundMajority[partsFilled] _ soundComponents >= TiogaVoicePrivate.soundRopeResolution/2; samplesAccounted _ 0; soundComponents _ 0; partsFilled _ partsFilled + 1; IF partsFilled = TiogaVoicePrivate.soundRopeCharDivisions THEN { binaryOfChar: INT _ 0; partsFilled _ 0; partiallyFilled _ FALSE; FOR i: INT IN [0..TiogaVoicePrivate.soundRopeCharDivisions) DO binaryOfChar _ binaryOfChar*2 + (IF soundMajority[i] THEN 1 ELSE 0) ENDLOOP; soundRope _ soundRope.Concat[Rope.FromChar[IF binaryOfChar # 0 THEN ('A + binaryOfChar) ELSE '!]] -- 'A is the base type of the sound font [i.e. all segments clear] but the 'all clear' character is actually ! so as to make 'word selections' work in normal tioga terms } } }; WHILE partiallyFilled AND length>0 DO taken: INT _ AddToPartChar[length, sound]; length _ length - taken ENDLOOP; WHILE length >= TiogaVoicePrivate.soundRopeCharLength DO soundRope _ soundRope.Concat[Rope.FromChar[IF sound THEN ('A + 15) ELSE '!]]; length _ length - TiogaVoicePrivate.soundRopeCharLength ENDLOOP; WHILE length>0 DO taken: INT _ AddToPartChar[length, sound]; length _ length - taken ENDLOOP }; FOR l: TiogaVoicePrivate.SoundList _ soundList, l.rest WHILE l # NIL DO silence: INT _ l.first.silence; sound: INT _ l.first.sound; IF skipping THEN { IF silence >= skipSamples THEN { silence _ silence - skipSamples; skipping _ FALSE; AddChars[length: silence, sound: FALSE]; AddChars[length: sound, sound: TRUE] } ELSE { skipSamples _ skipSamples - silence; IF sound >= skipSamples THEN { sound _ sound - skipSamples; skipping _ FALSE; AddChars[length: sound, sound: TRUE] } ELSE skipSamples _ skipSamples - sound; } } ELSE { AddChars[length: silence, sound: FALSE]; AddChars[length: sound, sound: TRUE] } ENDLOOP; remnant _ IF partiallyFilled THEN partsFilled*TiogaVoicePrivate.soundRopeResolution+samplesAccounted ELSE 0; soundRope _ TiogaVoicePrivate.DisplayCharMarks[soundRope, viewerInfo.charMarkList, skipChars] }; LastSilenceInSoundList: PUBLIC PROC [ soundList: TiogaVoicePrivate.SoundList, lengthGreaterThan: INT _ 0] RETURNS [startsAt: INT, lasts: INT _ -1] = { l: TiogaVoicePrivate.SoundList _ soundList; currSilenceStart: INT _ 0; WHILE l # NIL DO IF l.first.silence > lengthGreaterThan THEN { startsAt _ currSilenceStart; lasts _ l.first.silence }; currSilenceStart _ currSilenceStart + l.first.silence + l.first.sound; l _ l.rest ENDLOOP }; AppendSound: PROC [ list: TiogaVoicePrivate.SoundList, entry: TiogaVoicePrivate.Sound] RETURNS [TiogaVoicePrivate.SoundList] = { oneElementList: TiogaVoicePrivate.SoundList _ CONS[entry, NIL]; hangOffPoint: TiogaVoicePrivate.SoundList _ list; IF list = NIL THEN RETURN [oneElementList]; WHILE hangOffPoint.rest # NIL DO hangOffPoint _ hangOffPoint.rest ENDLOOP; hangOffPoint.rest _ oneElementList; RETURN [list] }; AppendSoundToSoundInterval: PROC [ soundInterval: TiogaVoicePrivate.SoundInterval, entry: TiogaVoicePrivate.Sound] = { oneElementList: TiogaVoicePrivate.SoundList _ CONS[entry, NIL]; hangOffPoint: TiogaVoicePrivate.SoundList _ soundInterval.soundList; IF hangOffPoint = NIL THEN {soundInterval.soundList _ oneElementList; RETURN}; WHILE hangOffPoint.rest # NIL DO hangOffPoint _ hangOffPoint.rest ENDLOOP; hangOffPoint.rest _ oneElementList }; AppendSoundListToSoundList: PROC [ head, tail: TiogaVoicePrivate.SoundList] = { hangOffPoint: TiogaVoicePrivate.SoundList _ head; IF tail = NIL THEN RETURN; WHILE hangOffPoint.rest # NIL DO hangOffPoint _ hangOffPoint.rest ENDLOOP; IF hangOffPoint.first.sound = 0 OR tail.first.silence = 0 THEN -- these two can be amalgamated { hangOffPoint.first.sound _ hangOffPoint.first.sound + tail.first.sound; hangOffPoint.first.silence _ hangOffPoint.first.silence + tail.first.silence; tail _ tail.rest }; hangOffPoint.rest _ tail }; CreateVoiceViewerMenu[]; voiceTIPTable _ TIPUser.InstantiateNewTIPTable["TiogaVoice.tip"]; soundViewerIcon _ Icons.NewIconFromFile["Finch.icons", 15]; dirtySoundViewerIcon _ Icons.NewIconFromFile["Finch.icons", 16]; Commander.Register[key: "ReadyToRoll", proc: HereWeGoAgain, doc: "ReadyToRoll: do it before running this again!"]; TEditInput.Register[$BackSpace, InterceptBackSpace]; TEditInput.Register[$BackWord, InterceptBackWord]; TEditInput.Register[$Delete, InterceptDelete]; TEditInput.Register[$DoEdit, InterceptEdit]; textClassDescriptor.notify _ InterceptAllInput; }. ,´VoiceViewersImpl.mesa Copyright Ó 1987 by Xerox Corporation. All rights reserved. Ades, May 1, 1986 1:34:00 pm PDT Swinehart, April 9, 1987 9:39:24 am PDT Polle Zellweger (PTZ) July 14, 1987 3:58:09 pm PDT Voice Viewers Do this after the call to CreateViewer because the init proc for $Text class viewers sets the tip table explicitly, so the tip table input param is effectively ignored. Viewer locking?? ** ought to check here that the rope actually exists ** **** the Plass-bug: shouldn't be necessary and he says he'll have a look at it IF viewerInfo.textMarkList # NIL THEN ViewerOps.PaintViewer[viewer: viewer, hint: client, clearClient: TRUE, whatChanged: NIL]; Set the contents, style, and looks for a voice viewer. Used to set looks to provide voice playback feedback. Note: all voice viewers contain only one node. This procedure marks a voice viewer as edited: viewer, viewerInfo, and icon. this procedure will make a voice viewer think itself unedited, when we wish to assert that there is no voice rope held only in it - use carefully!! this is similar to the above, except that it ensures that the viewer has the same idea about whether the voice is edited as the VoiceInfo record. For use by functions [such as moving a visual cue along a voice viewer during playback] that need to edit the viewer but not the voice and then want to reflect this fact in the viewer's status Check for same or split viewer. Returns a list of voiceViewerInfo describing all voice viewers whose parent is the viewer. Removes the parentViewer pointers for all voice viewers pointing to this viewer. If findSplits is TRUE, will replace with a pointer to a split of the viewer if one exists. The text viewer being destroyed has been split, so this isn't really the last one. **** locking against edits in this and the next one? Now need to remove all old links from doc to this viewer ($voiceWindow charprops). Don't want to remove the one we just put in, but we wanted to be sure it would succeed before removing the old ones. Do this by excepting the location we just added (could also check for the new rope value as the associated $voice property). Voice Edit Intercept Routines to pick up edit events affecting voice viewers and pass control from normal Tioga ops. This code stinks for a number of reasons i) it only picks up a subset of the events which could affect a voice viewer ii) it SHARES an Impl !!!!!!! - TEditInputImpl to be precise. This occurs only in InterceptEdit, for reasons explained above that procedure iii) it redefines the 'notify proc' for the $Text class!! - it does exactly what the ousted notify proc would do in the case of non-voice viewers, by calling a TEditInputImpl procedure. At the cost of another procedure call it could be more clean my saving the ousted procedure and calling that, but since I've had to import the Impl anyhow . . . . The way things should be is that either an equivalent package to tioga is produced specially for voice editing windows or TEditInputOps is rewritten to call TiogaVoice code for viewers managed by TiogaVoice [detectable from the properties that those viewers have]. this part of the code is extremely sordid: it really needs to be in TEditInputImpl and for that reason it references private variables from TEditInputImpl 23 times: it gets called in front of the Tioga DoEdit procedure and returns quit=TRUE under all circumstances in order to prevent the real one ever being called this and the following series of 'Check' procedures test if the proposed edit is applied to normal text: if so they first call the appropriate SourceMarkerTracking routine and then pass control to TEditInputOps [just like TEditInputImpl.DoEdit always would], otherwise they pass control to Voice Edit Ops needs to be filled in -- PTZ, June 12, 1987 7:49:54 pm PDT needs to be filled in -- PTZ, June 12, 1987 7:49:54 pm PDT This just whilste under development . . . Voice Edit Ops Routines to edit voice viewers, plus some routines to intercept operations deemed inapplicable for voice or voice/text viewer combinations. this routine will characterise the voice corresponding to a selection: if the selection is pendingDelete [or if forceDelete] then the selection.ropeInterval will have non-zero length; if returnSoundInterval then the sound interval corresponding to the whole selection will be characterised - to be saved and inserted somewhere else selections can only be described if the voiceLock can be taken out on them: this routine returns failed if it cannot get the lock; otherwise it returns with the lock still held. However the caller may pass a viewer in viewerAlreadyLocked to say that he already has that one locked and if this selection is in the same viewer then we may proceed work out the VoiceRopeInterval corresponding to the whole selection it is here that policy about trimming the sound selection e.g. to silence/sound boundaries could be implemented this routine actually does all the editing work for voice: it is passed a selection specification and a sound specification: if the selection is of non-zero length it is deleted; then if the sound is non-nil it is inserted this routine (i) works out what the updated voice viewer sound list and contents will be (ii) calls TiogaVoicePrivate to redraw the viewer [done there since the viewer may be somewhere in the queue of sounds to be played back] (iii) interacts with the voice rope data base to update the rope specification corresponding to the viewer it may turn out that there is nothing left in the viewer at the end of this action, in which case the viewer will simply be deleted (unless Copy/Transpose with both selections in the same viewer). However this is not done until after TiogaVoicePrivate.RedrawViewer has been called since a viewer cannot be destroyed whilst the playback caret is in it: after a call to RedrawViewer the playback caret cannot be in it!! those three need only be [and are only] approximate done for efficiency - no need to recalculate the first characters again redrawing is done in TiogaVoicePrivate for synch with any playback cues the last but one parameter governs whether this edit will cause all previous edits to age [only if insertChars # 0]. It is simply set TRUE here: if there were any use for such a facility a parameter could be passed by caller of ReplaceSelectionWithSavedInterval to pass on here this will cause the event proc which clears down the voiceViewerInfo etc. to be called delete the primary selection if source selection is pending delete and ahead of the destination selection in the same viewer, then after the first action of deleting source the destination will be nearer the start of the sound we drop the selections here because after a ReplaceSelectionWithSavedInterval call a viewer may not exist! If a selection above failed we should also drop the selections here as well - if selections are left around after an aborted tioga editing operation unpleasant thing tend to happen source is pending delete: this means two edit operations that is the test for overlapping selections: if source is pending delete the copy operation then reduces to "delete the region(s) lying in the destination but not in the source selection" - done here as a special case done by substituting first and second regions for source and destination selections and setting soundInterval to NIL: note that either of these regions may now have zero length don't let the viewer be destroyed yet, because hopefully we are about to add to it ReplaceSelectionWithSavedInterval redraws the viewer, which makes a new version of the internal node. Update destSelection to point to the new node. SoundList Sound lists are descriptions of the silence/sound profiles of a ropeInterval and form part of the data structure behind a voice viewer. voiceViewerInfo contains the sound list for a complete rope. Use the interval specification from soundInterval.ropeInterval to create a new sound list for that interval, placing it in soundInterval.soundList. voiceViewerInfo contains the sound list for a complete rope. Cut out the specified portion and at the cutting point insert the replacement soundlist. No tests for shooting off the end in this routine. If we get an error then our caller has gone badly wrong and there is no obvious way to recover. With the head of the old rope in voiceViewerInfo.soundList, delete the unwanted sound from the tail. We can now join up our three lists. Produce the graphical representation of the SoundList within a VoiceViewerInfo record. The caller already has the first skipChars of the representation in his hand, so omit these from the returned rope. If the sound list does not exactly fill a whole number of characters, return as remnant the number of samples left over. Any marker characters indicated in the VoiceViewerInfo are inserted. 15 represents 'all bits are sound' - i.e. 2**soundRopeCharDivisions-1 All INTs are values in samples, as for the rest of this interface. lasts=-1 indicates that there are no silence intervals in the list of lengthGreaterThan that specified. Utilities Head is assumed non-nil. Initialization stand back - this is the dangerous bit . . . Swinehart, April 8, 1987 11:59:57 am PDT Cedar 7. Merge many files. changes to: DIRECTORY, VoiceViewersImpl, voiceViewerMenu, CreateVoiceViewerMenu, SetViewerContents, ViewerTools, SetParentViewer, IF, {, SaveVoice, DestroyVoiceInfo, RedrawViewer, ChangeColumnEvent, }, END Polle Zellweger (PTZ), June 7, 1987 7:01:17 pm PDT Tip table for voice viewers, to handle CR correctly and to allow for accelerators later; also inhibits bad things like CTRL-CR so that users can't edit voice viewers into multiple nodes. Also a new icon for voice viewers. changes to: DIRECTORY, VoiceViewersImpl, MakeVoiceNotEdited, SetVoiceViewerEditStatus, BuildVoiceViewer, initialization Polle Zellweger (PTZ), June 8, 1987 7:04:09 pm PDT New routines exploit commonality & remove selection-based changing of looks. new: SetTiogaViewerParams, SetVoiceRopeInfo, SetVoiceLooks changes to: DIRECTORY, SetViewerContents Polle Zellweger (PTZ), June 16, 1987 6:12:33 pm PDT Check for voice edit in progress before destroying voice viewer. changes to: DestroyVoiceInfo Polle Zellweger (PTZ), June 17, 1987 1:10:44 pm PDT Set dirty sound icon. changes to: MakeVoiceEdited, Delete, Copy Polle Zellweger (PTZ), June 19, 1987 12:17:02 pm PDT Utilities for new policy: voice markers in text viewers are only a hint; must be validated. Can't be copied or moved across doc boundaries. new: SameViewerDoc, GetVoiceViewerInfo changes to: RemoveParentViewer, DestroyVoiceInfo Polle Zellweger (PTZ), June 22, 1987 7:04:25 pm PDT Problems with copying pending-delete voice when source and dest are in the same voice viewer, caused by redrawing in the middle and thus destroying the dest node. changes to: Copy, ReplaceSelectionWithSavedInterval Polle Zellweger (PTZ) July 10, 1987 1:09:26 pm PDT Make voice viewer numbers monotonically increasing throughout a session so a copied text loc can't have a $voiceWindow "pointer" to the wrong viewer after destroy;edit. Make voiceViewerInfoList into a real list; make private to VoiceViewersImpl. changes to: DIRECTORY, voiceViewerInfoList, nextVoiceViewerNumber, FindAttachedVoiceViewers, RemoveParentPointersTo, GetVoiceViewerInfo, InsertVoiceViewerInfo, RemoveVoiceViewerInfo + others w/ type renames Ê%蘚œ™Icode™šœ ˜Jšœ˜——Jšœœ˜ —Jšœœ˜Jšœ˜šœ ˜ Jšœ©Ïtœ¡™»—J˜Jšœ'˜'Jšœ8˜8J˜J˜)J˜Jšœ+˜+J™Jšœ€œ˜†Jšœ‰œ˜J˜JšœH˜HJ˜šœ˜J˜——š œœ-œœœœœ˜˜Jšœ#˜#Jšœœ˜šœ œœ˜Kš¡œ7¡™9KšœXœ3˜ŽKšœCœ:˜€Kšœo˜oKšœ_˜_KšœJ˜JKš œœœ œœœ˜tK˜—šœ˜Kšœ˜Kšœœ˜&J˜—J˜K˜—š  œœœKœœœ˜ŸK˜KšœœB˜VKšœ-˜-šœ œœ=˜UJšœ'˜'—Jšœ5˜9J™J™NJš œœœBœœ™J˜Jšœ'œÏcr˜ž˜J˜——š  œœœ2œœ"˜‚K™6Kšœ˜šœ+˜+KšœDœ˜M—Jšœ5˜5Kšœ&˜&KšœO˜OKšœ*˜*Kšœœœ˜,Kšœ7˜7˜J˜——š   œœœ&œœ˜ZK™5š œœ˜'K™.K•StartOfExpansion¹[root: TextEdit.RefTextNode, text: TextEdit.RefTextNode, remove: TextLooks.Looks, add: TextLooks.Looks, start: INT _ 0, len: INT _ 2147483647, event: TextEdit.Event _ NIL]šœÃ˜ÃK˜—Kšœ2˜2K˜K˜—š œ œ#˜?J™Lš œœ˜Jšœ(œ˜-K˜#Kšœ'œ˜.K˜—JšœœA˜eKšœœœ-˜J˜K˜——š œœ#˜;J™“š œœ˜JšœœA˜eJšœ9œ˜?K˜Kšœ'œ˜.K˜—Kšœ,˜,˜K˜——š œœœ#˜HK™Òš œœ˜JšœœA˜ešœ'œ˜/Jšœ&˜&šœœ˜Jšœœ˜J˜J˜—Jšœ#˜(Jšœ'œ˜.J˜—K˜—Kšœ,˜,˜J˜——š   œœœ œœ˜LK™šœ'˜,Kšœœœœ˜Kšœœœ˜Kšœ˜—Jšœœ˜šœ˜J˜——š œœœp˜ŒJšœ'˜'Jšœ/˜/Jšœ/˜/šœ˜J˜——š œœœ œ*˜vJ™Zšœ>œ œ˜Ušœ#˜)Jšœœ˜2—Jšœ˜—˜J˜——š œœœ,œ˜[J™¬šœ>œ œ˜UJšœ$˜$šœœ˜$Kšœ9˜9šœ œ œœ˜(J™RJšœ˜Kšœ,˜,J˜—šœ˜Jšœœ˜Jš œœ6œœ¢Ðct¢!£˜•J˜—J˜—Jš˜—J˜J˜—š œœœ"˜AJšœœ˜˜J˜——š  œœœœœ"˜Ršœ>œœ˜SKšœœœ˜7Kšœ˜—šœ˜J˜——š œ œœ!˜LJšœ˜J˜J˜—š œœœ%˜HJšœœ˜(Jšœ3˜3Jšœ2˜2Jšœœ%˜?˜J˜——š  œ˜J™4Jšœœ ˜.JšœœA˜eJšœ@˜@šœ4œ˜=Jš¡œÈ¡™ÈJšœ˜Jšœœœn˜‹J˜—˜J˜——š  œ˜Jšœœ ˜.JšœœA˜eJ˜Jšœ˜šœ6œ˜œœ˜SKšœœ!œ˜MKšœ˜—K˜—Kšœ¢˜˜J˜——š œœ˜TJ˜—š œœ˜Jšœœ œœ˜AKšœœA˜eJ˜šœ3œ˜;KšœPœ˜WJšœ˜Jšœœ˜J˜—šœœ˜#KšœHœ˜OJšœ˜Jšœœ˜J˜—J˜JšœC˜CJšœM˜MJ˜šœœ˜%Kšœœ*œ˜i—š˜KšœYœ˜c—J˜Jšœ"˜"J˜J˜—š œ˜(Jšœœ ˜.JšœœA˜eJšœ˜Jšœ˜šœœ6˜OJšœWœ ˜iJšœ!˜!Jšœ˜!—Jšœ˜šœ˜J˜——š œ˜-JšœœA˜eJšœ,˜2šœ,˜,Jšœ˜Jšœ˜šœœ6˜OJšœWœ ˜iJšœ!˜!Jšœ˜!—Jšœ˜Jš˜šœ“œ˜™J˜—J˜—J˜˜J˜——š  œœœœ˜!Jšœœ œ˜3Jšœ˜Jšœ˜JšœIœ˜RJšœœ˜ J˜—J˜—šŸ™J™J™_™(J™LJšœœ~™‹šœÜ™ÜJ™——šœ‰™‰J™—š œ˜/Jšœ/œ˜5Jšœ)¢˜LJšœ˜š œ œœœœœ˜6šœ œœœœœ œ˜Lšœœ˜Kšœœœ˜šœœœœ˜šœ/˜/Kšœ ˜—K˜Kšœ4˜4—K˜Kšœœ˜šœœœœ˜šœ/˜/Kšœ ˜—K˜Kšœ$˜$—K˜Kšœœœ˜šœœœœ˜šœ/˜/Kšœ ˜—K˜Kšœ6˜6—K˜šœ˜ Kšœœ˜Kšœ˜šœœœ˜*Kšœ˜—K˜Kšœ˜šœœœ˜4Kšœ&˜&—K˜———Kšœ˜Kšœœœ-˜E—K˜˜J˜——š œ˜.Jšœœœ˜&Jšœ$˜$Jšœœ˜˜J˜——š œ˜-Jšœœœ˜&Jšœ#˜#Jšœœ˜˜J˜——š œ˜+Jšœ˜Jšœ!˜%Jš˜šœ ˜ Jšœœ˜—J˜˜J˜——š  œ˜*JšœìœK™»Jšœœ˜ šœœœ˜*Kš œœœœ ¢˜mKšœ œ˜—šœœ œ˜-Kšœ œ-œ˜F—Kš œœœœ˜@šœ˜š œœ˜šœœ˜:K˜K˜K˜Kšœœ˜——Kšœ œ˜šœ˜ Kšœœ˜#˜Kšœ$˜$Kšœ!˜!Kšœ˜Kšœ˜%˜ Kšœ#œ!˜JK˜—K˜!K˜#Kšœœ˜—˜Kšœ$˜$Kšœ#˜#K˜Kšœ˜%˜ Kšœ#œ!˜JK˜—K˜#K˜%Kšœœ˜—˜ Kšœ$˜$Kšœ˜K˜Kšœ˜%K˜K˜K˜!Kšœœ˜—Kšœœ˜——Kšœ?˜?Kšœ8œ@˜}Kšœ!¢˜œœ+œ˜}Jšœœ˜šœ4œœ˜GJšœS˜SJšœ-˜-—Jšœ˜Jšœ%œK˜v˜J˜——š œœœ˜JšœU˜UJšœÐ™ÐJšœ œ$˜4Jšœ œ3˜AJšœœ˜Jšœœ˜J˜š œDœœœ˜oJšœ˜Jšœ˜Jšœ˜Jšœ.˜.Jšœœ˜šœœ˜Jšœ˜šœœ(˜FJšœœ%˜D—J˜Jšœ˜Jšœ˜šœœ"˜DJšœœ ˜;—J˜JšœC˜C—J˜—Jš˜˜J˜——š œœœ˜Jšœ,œ œ/˜nJšœ—™—Jšœ.˜.Jšœœ˜&Jšœ˜šœ˜Jšœ!˜!Jšœ˜—šœœ˜Jšœ9˜>šœ“™“JšœP˜PJšœœ˜%—Jšœ˜Jšœ˜Jšœœ˜J˜Jšœœ¢/˜Ošœœœ3˜NJšœ œœ1˜GJšœœ%˜0JšœD˜DJšœ=˜=—J˜—˜J˜—Jšœd™dšœ˜Jšœ˜Jšœœœ˜(JšœD˜DJšœœœ˜&Jšœ˜—Jšœ˜J˜Jšœœ¢4˜Wšœœœ.˜HJšœ œœ,˜BJšœ#˜#Jšœ˜—J˜J˜J™$Jšœœœœ/˜`Jšœœœ)œC˜—šœ˜J˜——š  œœœ˜Jš œ(œœœœ œ˜gJšœˆ™ˆJ˜>Jšœœœ˜!Jšœ?˜?Jšœœ/œœ˜NJšœR˜RJšœ œ˜ Jšœ œ3˜CJ˜š œœ œ œ˜0J˜š   œœœ œœ>˜Jšœœ˜JšœœK˜\J˜2Jšœœ1˜>Jšœ9˜;Jš˜šœ[˜[J˜J˜J˜Jšœ7˜9Jš˜Jšœœ˜˜J˜Jšœœ˜šœœœ/˜>Jšœ!œœœ˜C—Jšœ˜Jšœ+œœœ¢©˜‹—J˜—J˜—J˜šœœ ˜%Jšœœ ˜*Jšœ˜—Jšœ˜J˜šœ1˜8Jšœ+œœ œ˜MJšœF™FJšœ7˜7—Jšœ˜J˜šœ ˜Jšœœ ˜*Jšœ˜—Jš˜—J˜J˜šœ4œœ˜GJšœ œ˜Jšœœ˜Jšœ ˜ Jš˜šœœ˜Jš˜šœ#˜#Jšœ œ˜Jšœ!œ˜(Jšœœ˜$—J˜Jš˜šœ'˜'šœ˜Jš˜šœ˜Jšœ œ˜Jšœœ˜$—J˜Jšœ#˜'——J˜—J˜Jš˜šœ$œ˜+Jšœœ˜$—J˜—Jšœ˜Jšœ œœDœ˜lJšœ]˜]˜Jšœ˜——š œœœ˜%Jš œ;œœ œ œ ˜pKšœª™ªKšœ+˜+Kšœœ˜šœœ˜Kšœ%˜+šœ˜Kšœ˜—K˜KšœF˜FK˜ —Kš˜˜K˜——™ J™—š  œœ˜JšœCœ"˜lJšœ.œœ˜?Jšœ1˜1Jšœœœœ˜+Jšœœœ"œ˜JJ˜#Jšœ˜ ˜J˜——š œœ˜"JšœS˜SJšœ.œœ˜?JšœD˜DJšœœœ,œ˜OJšœœœ"œ˜JJ˜"˜J˜——š œœ˜"Jšœ,˜,J™Jšœ1˜1Jšœœœœ˜Jšœœœ"œ˜JJšœœœ¢˜^šœJ˜JJšœM˜MJ˜—J˜Jšœ˜˜J˜——J˜—šŸ™J™J˜J˜AKšœ;˜;Kšœ@˜@Kšœr˜rJ˜Jšœ4˜4Jšœ2˜2Jšœ.˜.Jšœ,˜,J˜J™,Jšœ/˜/J˜—Jšœ˜J˜šœ%™(K™Kšœ Ðkr Ïrm¤¥F¤™Í—šœ2™2K™ÞKšœ ¤ ¥b™w—šœ2™2K™LKšœ¥5™:Kšœ ¤ ¥™(—šœ3™3K™@Kšœ ¥™—šœ3™3K™Kšœ ¥™)—šœ4™4KšœZ¥œ0™‹Kšœ¥!™&Kšœ ¥$™0—šœ3™3K™¢Kšœ ¥'™3—™2K™öKšœ ¥Â™Î——…—âð~