DIRECTORY
Commander USING [ CommandProc, Register ],
CommandTool USING [ NextArgument ],
IO,
MBQueue USING [ Create ],
Menus USING [MenuProc],
Process USING [ Detach ],
RefText USING [ ObtainScratch, TrustTextAsRope],
Rope USING [Cat, Equal, Fetch, Find, Length, MakeRope, ROPE, Substr],
TiogaOps USING [ Location, GetRope, GetSelection, ViewerDoc ],
ViewerClasses USING [Viewer],
VoiceRope USING [ Forget, Handle, Open, Play, Record, Retain, Stop, VoiceRope, VoiceRopeInterval ],
VoiceUtils USING [ CurrentRName ],
WalnutDefs USING [ Error ],
WalnutDocumentRope USING [ Create ],
WalnutOps USING [ GetMsgHeaders, MsgHeaders,ParseHeaders, ParseProc ],
WalnutRegistry USING [ MoveProc, MsgGroupProc, MsgGroupSize, Register ],
WalnutSendOpsExtras USING [SenderReport],
WalnutSendOps USING [AddToSendMenu, AppendHeaderLine],
WalnutWindow USING [ AddToMsgMenu, GetMsgName ]
;
Procedures registered with WalnutRegistry
VoiceMoveTo:
ENTRY WalnutRegistry.MoveProc = {
[msgName: ROPE, fromMsgSet: ROPE, toMsgSet: ROPE, clientData: REF ANY]
ENABLE { ABORTED => CONTINUE; UNWIND => NULL; };
headers: WalnutOps.MsgHeaders;
IF voiceHandle=NIL OR toMsgSet=NIL THEN RETURN;
IF (Rope.Equal[toMsgSet, "deleted",FALSE] OR Rope.Equal[toMsgSet, "active", FALSE]) THEN RETURN;
headers ← VoiceHdrsFromGVID[msgName];
FOR hdrs: WalnutOps.MsgHeaders ← headers, hdrs.rest
WHILE hdrs#
NIL
DO
voicerope.ropeID ← hdrs.first.value;
VoiceRope.Retain[handle: voiceHandle, vr: voicerope, refID: Rid[msgName], class: "GVID"];
ENDLOOP;
};
ChangeInterestEntry:
ENTRY WalnutRegistry.MsgGroupProc = {
[msgGroup: REF WalnutRegistry.MsgGroup, event: WalnutRegistry.MsgGroupEvent, clientData: REF ANY]
ENABLE { ABORTED => CONTINUE; UNWIND => NULL; };
IF voiceHandle = NIL THEN RETURN;
FOR i:
CARDINAL
IN [0..WalnutRegistry.MsgGroupSize)
DO
IF msgGroup[i]=NIL THEN LOOP;
SELECT event
FROM
added => NULL; -- Present design calls for no action at message read time.
destroyed => {
voicerope.ropeID ← msgGroup[i];
VoiceRope.Forget[handle: voiceHandle, vr: voicerope, refID: Rid[msgGroup[i]], class: "GVID"];
};
ENDCASE;
ENDLOOP;
};
Utilities, Available from elsewhere
PlayFromSelection:
INTERNAL
PROC[parentViewer: ViewerClasses.Viewer]
RETURNS [played: BOOL←FALSE] = {
parentViewer is viewer containing Play menu entry. If selection is a VoiceFileID node (wherever located), play that and return TRUE. Otherwise ...
selV: ViewerClasses.Viewer;
selStart, selEnd: TiogaOps.Location;
nodeContents: Rope.ROPE;
vfIndex: INT←-1;
[selV, selStart, selEnd] ← TiogaOps.GetSelection[primary];
IF selV#parentViewer OR selStart.node#selEnd.node THEN RETURN;
nodeContents ← TiogaOps.GetRope[selStart.node];
IF (vfIndex←nodeContents.Find["VoiceFileID: "])<0 THEN RETURN;
voicerope.ropeID ← nodeContents.Substr[start: 14];
VoiceRope.Play[handle: voiceHandle, voiceRope: voicerope];
RETURN[TRUE];
};
PlayFromMessageHeaders:
INTERNAL
PROC[headers: WalnutOps.MsgHeaders] = {
Play in reverse order (observe clever recursion), to reverse the effect of ParseHeaders.
IF headers=NIL THEN RETURN;
PlayFromMessageHeaders[headers.rest];
voicerope.ropeID ← headers.first.value;
VoiceRope.Play[handle: voiceHandle, voiceRope: voicerope];
};
VoiceHdrsFromGVID:
INTERNAL PROC[msgID: Rope.ROPE] RETURNS [WalnutOps.MsgHeaders] = {
msgText ← WalnutOps.GetMsgHeaders[msgID, msgText!
WalnutDefs.Error => IF who=$log AND code=$MsgHeadersTooLong THEN msgText.length𡤀];
RETURN[VoiceHdrsFromMsg[RefText.TrustTextAsRope[msgText]]];
};
VoiceHdrsFromMsg:
INTERNAL
PROC[msgHeaders: Rope.
ROPE]
RETURNS [WalnutOps.MsgHeaders] = {
RETURN[
IF msgHeaders.Length[]=0
THEN
NIL
ELSE
WalnutOps.ParseHeaders[msgHeaders, FindVoiceID]];
};
FindVoiceID: WalnutOps.ParseProc = {
[fieldName: ROPE] RETURNS [wantThisOne: BOOL, continue: BOOL]
RETURN[fieldName.Equal["voicefileid", FALSE], TRUE];
};
LowerCaseRope:
PROC[r:
ROPE]
RETURNS [
ROPE] = {
RETURN[Rope.MakeRope[base: r, size: r.Length[], fetch: LCFetch]]};
LCFetch:
SAFE
PROC[data:
REF, index:
INT]
RETURNS [c:
CHAR] =
TRUSTED {
SELECT (c←NARROW[data,ROPE].Fetch[index]) FROM IN ['A..'Z]=>c𡤌+('a-'A); ENDCASE};
Rid:
PROC[msgHeader: Rope.
ROPE]
RETURNS [dbRidValue: Rope.
ROPE] = {
RETURN[Rope.Cat[LowerCaseRope[VoiceUtils.CurrentRName[]], "/", msgHeader]];
};
WalnutComplain:
PROC[complaint: Rope.
ROPE] = {
WalnutSendOpsExtras.SenderReport[complaint]; };
Initialization (Walnut Voice and Finch)
InitializeWalnutVoice:
Commander.CommandProc = {
tunesDBName: Rope.ROPE ← CommandTool.NextArgument[cmd];
instance: Rope.ROPE ← CommandTool.NextArgument[cmd];
voiceHandle ← VoiceRope.Open[Complain: WalnutComplain];
Set up the button procs needed by Walnut.
WalnutSendOps.AddToSendMenu[label: "Record", proc: RecordProc];
WalnutSendOps.AddToSendMenu[label: "STOP!", proc: StopProc];
WalnutSendOps.AddToSendMenu[label: "Play", proc: SenderPlayProc];
WalnutSendOps.AddToSendMenu[label: "Attach", proc: AttachProc];
WalnutWindow.AddToMsgMenu[label: "Play", proc: MessagePlayProc];
WalnutWindow.AddToMsgMenu[label: "STOP!", proc: StopProc];
[]←WalnutRegistry.Register[
[
msgGroupProc: ChangeInterestEntry,
msgGroupData: NIL, -- used to be handle
moveProc: VoiceMoveTo,
moveProcData: NIL -- used to be handle
],
MBQueue.Create[]
];
};
Commander.Register["WalnutVoice", InitializeWalnutVoice,
"WalnutVoice [<tunes db root>] [Instance]\nRegister WalnutVoice with walnut, extend Walnut menus."];
}.
Swinehart, January 30, 1986 3:47:33 pm PST
Now uses Intervoice to manage recording and playback.
changes to: voiceHandle, RecordProc, DoRecordProc, StopProc, PlayFromSelection, PlayFromMessageHeaders, FindVoiceID, WalnutComplain, InitializeWalnutVoice
Doug Terry, July 30, 1986 5:22:57 pm PDT
Upgraded to use VoiceRope instead of Intervoice.
changes to: DIRECTORY, WalnutVoiceImpl, voiceHandle, DoRecordProc, StopProc, VoiceMoveTo, ChangeInterestEntry, PlayFromSelection, PlayFromMessageHeaders, InitializeWalnutVoice, msgText, voicerope