VoiceBrowserImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Doug Terry, July 28, 1987 4:43:14 pm PDT
A modified LoganBerry browser that allows one to play voice ropes using Tioga buttons.
DIRECTORY
Commander USING [CommandProc, Handle, Register],
Convert USING [RopeFromInt],
FS USING [ComponentPositions, ExpandName],
IO,
LoganBerry USING [AttributeType, AttributeValue, Entry, Error, Open, OpenDB, ReadEntry],
LoganBerryBrowser USING [CreateTool, DBInfo, DBInfoRec, DetailsProc, HistoryProc, ReadEntryForm, Tool, ToolBody, StopProc, BrowseProc, UpdateProc, DeleteProc, UnDeleteProc],
LoganBerryBrowserExtras USING [AdminOpsProc, DisplayProc, PrintEntryAsButton, RegisterDisplayProc],
LoganQuery USING [AttributePatterns],
Menus USING [AppendMenuEntry, ClickProc, CreateEntry, CreateMenu, Menu, MenuLine],
Rope USING [Concat, ROPE],
TiogaButtons USING [TiogaButtonProc],
VoiceRope USING [DescribeRope, IntervalSpecs, Length, Play, Record, Stop, VoiceRope, VoiceRopeInterval];
VoiceBrowserImpl: CEDAR PROGRAM
IMPORTS Commander, Convert, FS, IO, LoganBerry, LoganBerryBrowser, LoganBerryBrowserExtras, Menus, Rope, VoiceRope
~ BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
BrowserTool: TYPE ~ LoganBerryBrowser.Tool;
vr: VoiceRope.VoiceRope ← NEW[VoiceRope.VoiceRopeInterval ← [ropeID: NIL, start: 0, length: LAST[INT]]];
RecordProc: Menus.ClickProc = {
[parent: ViewerClasses.Viewer, clientData: REF ANY ← NIL, mouseButton: ViewerClasses.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
entry: LoganBerry.Entry;
newvr: VoiceRope.VoiceRope ← VoiceRope.Record[];
query voice rope just recorded
entry ← LoganBerry.ReadEntry[db: tool.databases.first.db, key: $VRID, value: newvr.ropeID].entry;
IF entry=NIL THEN entry ← LIST[[$WARNING, "Voice rope not recorded in this database."]];
LoganBerryBrowserExtras.PrintEntryAsButton[entry: entry, tool: tool, proc: PlayButton, clientData: newvr.ropeID];
};
PlayProc: Menus.ClickProc = {
[parent: ViewerClasses.Viewer, clientData: REF ANY ← NIL, mouseButton: ViewerClasses.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
form: LoganQuery.AttributePatterns ← LoganBerryBrowser.ReadEntryForm[tool].form;
vr.ropeID ← GetFormValue[form, $VRID];
VoiceRope.Play[voiceRope: vr];
};
StopProc: Menus.ClickProc = {
[parent: ViewerClasses.Viewer, clientData: REF ANY ← NIL, mouseButton: ViewerClasses.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
VoiceRope.Stop[];
};
LengthProc: Menus.ClickProc = {
[parent: ViewerClasses.Viewer, clientData: REF ANY ← NIL, mouseButton: ViewerClasses.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
form: LoganQuery.AttributePatterns ← LoganBerryBrowser.ReadEntryForm[tool].form;
len: INT;
vr.ropeID ← GetFormValue[form, $VRID];
len ← VoiceRope.Length[vr: vr];
LoganBerryBrowserExtras.PrintEntryAsButton[entry: LIST[[$VRID, vr.ropeID], [$Length, Convert.RopeFromInt[len]]], tool: tool, proc: PlayButton, clientData: vr.ropeID];
};
DescribeProc: Menus.ClickProc = {
[parent: ViewerClasses.Viewer, clientData: REF ANY ← NIL, mouseButton: ViewerClasses.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
tool: BrowserTool ← NARROW[clientData];
form: LoganQuery.AttributePatterns ← LoganBerryBrowser.ReadEntryForm[tool].form;
entry: LoganBerry.Entry;
noise: VoiceRope.IntervalSpecs;
vr.ropeID ← GetFormValue[form, $VRID];
noise ← VoiceRope.DescribeRope[vr: vr];
entry ← LIST[[$VRID, vr.ropeID]];
FOR i: VoiceRope.IntervalSpecs ← noise, i.rest WHILE i#NIL DO
entry ← CONS[[$start, Convert.RopeFromInt[i.first.start]], entry];
entry ← CONS[[$length, Convert.RopeFromInt[i.first.length]], entry];
ENDLOOP;
entry ← ReverseEntry[entry];
LoganBerryBrowserExtras.PrintEntryAsButton[entry: entry, tool: tool, proc: PlayButton, clientData: vr.ropeID];
};
GetAttributeValue: PROC [entry: LoganBerry.Entry, type: LoganBerry.AttributeType] RETURNS [LoganBerry.AttributeValue] ~ {
FOR e: LoganBerry.Entry ← entry, e.rest WHILE e # NIL DO
IF e.first.type = type THEN
RETURN[e.first.value];
ENDLOOP;
RETURN[NIL];
};
GetFormValue: PROC [form: LoganQuery.AttributePatterns, type: LoganBerry.AttributeType] RETURNS [LoganBerry.AttributeValue] ~ {
FOR e: LoganQuery.AttributePatterns ← form, e.rest WHILE e # NIL DO
IF e.first.attr.type = type THEN
RETURN[e.first.attr.value];
ENDLOOP;
RETURN[NIL];
};
ReverseEntry: PROC [entry: LoganBerry.Entry] RETURNS [LoganBerry.Entry] = {
Destructively reverses the order of the entry's attributes. Taken from LispImpl.DReverse.
l1, l2, l3: LoganBerry.Entry ← NIL;
IF entry = NIL THEN RETURN[NIL];
l3 ← entry;
UNTIL (l1 ← l3) = NIL DO
l3 ← l3.rest;
l1.rest ← l2;
l2 ← l1;
ENDLOOP;
RETURN[l2];
};
PlayButton: TiogaButtons.TiogaButtonProc = {
[button: TiogaButtons.TiogaButton, clientData: REF ANYNIL, mouseButton: ViewerClasses.MouseButton ← red, shift: BOOLFALSE, control: BOOLFALSE]
vr.ropeID ← NARROW[clientData];
IF vr.ropeID=NIL THEN RETURN;
VoiceRope.Play[voiceRope: vr];
};
MakePlayButton: LoganBerryBrowserExtras.DisplayProc = {
[entry: LoganBerry.Entry, tool: LoganBerryBrowser.Tool]
LoganBerryBrowserExtras.PrintEntryAsButton[entry, tool, PlayButton, GetAttributeValue[entry, $VRID]];
};
MakeMainMenu: PROC [tool: LoganBerryBrowser.Tool] RETURNS [menu: Menus.Menu] ~ {
AppendMenu: PROC[menu: Menus.Menu, name: ROPE, proc: Menus.ClickProc, line: Menus.MenuLine ← 0, guarded: BOOLFALSE] = {
Menus.AppendMenuEntry[ 
menu: menu,
entry: Menus.CreateEntry[name: name, proc: proc, clientData: tool, guarded: guarded],
line: line
];
};
menu ← Menus.CreateMenu[];
AppendMenu[menu, "STOP!", LoganBerryBrowser.StopProc];
AppendMenu[menu, "Browse", LoganBerryBrowser.BrowseProc];
AppendMenu[menu, "Update", LoganBerryBrowser.UpdateProc];
AppendMenu[menu, "Delete", LoganBerryBrowser.DeleteProc, 0, TRUE];
AppendMenu[menu, "UnDelete", LoganBerryBrowser.UnDeleteProc, 0, TRUE];
AppendMenu[menu, "History", LoganBerryBrowser.HistoryProc];
AppendMenu[menu, "Details", LoganBerryBrowser.DetailsProc];
AppendMenu[menu, "VoiceOps", LoganBerryBrowserExtras.AdminOpsProc];
--second line--
AppendMenu[menu, "Record", RecordProc, 1];
AppendMenu[menu, "Play", PlayProc, 1];
AppendMenu[menu, "Stop", StopProc, 1];
AppendMenu[menu, "Length", LengthProc, 1];
AppendMenu[menu, "Describe", DescribeProc, 1];
};
MakeBrowserTool: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
ENABLE LoganBerry.Error => {
IO.PutF[cmd.err, "Error: %g - %g\n", IO.atom[ec], IO.rope[explanation]];
GOTO End;
};
Open: PROC [dbname: ROPE] RETURNS [db: LoganBerry.OpenDB] ~ {
cp: FS.ComponentPositions;
fullDBName: ROPE;
[fullDBName, cp] ← FS.ExpandName[dbname];
IF cp.ext.length = 0 AND cp.ver.length = 0 THEN
fullDBName ← Rope.Concat[fullDBName, ".df"];
db ← LoganBerry.Open[dbName: fullDBName];
};
dbname: ROPE;
tool: LoganBerryBrowser.Tool ← NEW[LoganBerryBrowser.ToolBody];
argStream: IO.STREAMIO.RIS[cmd.commandLine];
DO
dbname ← IO.GetTokenRope[argStream, IO.IDProc ! IO.EndOfStream => EXIT].token;
tool.databases ← CONS[NEW[LoganBerryBrowser.DBInfoRec ← [db: Open[dbname]]], tool.databases];
ENDLOOP;
IF tool.databases = NIL THEN RETURN[result: NIL, msg: "No database name supplied.\n"];
tool.name ← Rope.Concat["Voice Browser: ", dbname];
tool.menu ← MakeMainMenu[tool];
tool.innerFlavor ← $TiogaButtons;
LoganBerryBrowserExtras.RegisterDisplayProc[proc: MakePlayButton, tool: tool];
LoganBerryBrowser.CreateTool[tool: tool];
EXITS
End => RETURN;
};
Commander.Register[key: "VoiceBrowser", proc: MakeBrowserTool,
doc: "Create a voice rope browser.\n usage: VoiceBrowser <dbname> <dbname> ..." ];
END.