BluejayUtilsImpl.mesa
Last Edited by: Swinehart, September 28, 1984 5:30:47 pm PDT
DIRECTORY
BluejaySmarts USING [ handle ],
BluejayUtils,
BluejayUtilsRpcControl USING [ ExportInterface, InterfaceName, UnexportInterface ],
Commander USING [ CommandProc, Register ],
Jukebox USING [ CloseTune, CreateTune, DeleteTune, Error, FirstNoisyIntervalIn, Info, OpenTune, Tune, TuneSize ],
LupineRuntime USING [ BindingError ],
Names USING [ CurrentPasskey ],
Log USING [ Report ],
Thrush USING [ IntervalSpec, IntervalSpecBody, IntervalSpecs, nullTune, Tune, VoiceInterval, VoiceTime ],
ThVersions USING [ JayVR ],
UserProfile USING [ Token ]
;
BluejayUtilsImpl: CEDAR PROGRAM
IMPORTS BluejaySmarts, BluejayUtilsRpcControl, Commander, Jukebox, LupineRuntime, Names, Log, ThVersions, UserProfile
EXPORTS BluejayUtils = {
myName: BluejayUtilsRpcControl.InterfaceName;
utilsExported: BOOLFALSE;
Tune: TYPE = Thrush.Tune;
DescribeTune: PUBLIC PROC[tune: Tune]
RETURNS [exists: BOOLTRUE, size: INT] = TRUSTED {
t: Jukebox.Tune = Jukebox.OpenTune[self: BluejaySmarts.handle, tuneId: tune, write: FALSE!
Jukebox.Error=>GOTO NoTune];
size ← Jukebox.TuneSize[t];
Jukebox.CloseTune[BluejaySmarts.handle, t];
EXITS
NoTune => exists←FALSE;
};
DescribeInterval: PUBLIC PROC[targetTune: Thrush.Tune, targetInterval: Thrush.VoiceInterval,
minSilence: Thrush.VoiceTime ← 1]
RETURNS [exists: BOOLTRUE, intervals: Thrush.IntervalSpecs←NIL] = TRUSTED {
t: Jukebox.Tune = Jukebox.OpenTune[self: BluejaySmarts.handle, tuneId: targetTune, write: FALSE!
Jukebox.Error=>GOTO NoTune];
lastInterval: Thrush.IntervalSpecs←NIL;
start, length, end, nextStart: INT𡤀
start ← targetInterval.start;
end ← IF targetInterval.length>=0 THEN start + targetInterval.length ELSE LAST[INT];
WHILE start<end DO
int: Thrush.IntervalSpecs;
[start, length, nextStart] ← Jukebox.FirstNoisyIntervalIn[BluejaySmarts.handle, t, start, end-start, minSilence];
IF length<=0 THEN EXIT;
int ← LIST[NEW[Thrush.IntervalSpecBody ← [
tune: targetTune, interval: [start, length], direction: play]]];
IF intervals=NIL THEN intervals ← int ELSE lastInterval.rest ← int;
lastInterval ← int;
start ← MAX[nextStart, start+length];
ENDLOOP;
Jukebox.CloseTune[BluejaySmarts.handle, t];
EXITS
NoTune => exists←FALSE;
};
DeleteTune: PUBLIC PROC[tune: Tune] RETURNS [existed: BOOLTRUE] = TRUSTED {
Jukebox.DeleteTune[BluejaySmarts.handle, tune!Jukebox.Error => GOTO NoTune];
EXITS
NoTune => existed←FALSE;
};
NewTune: PUBLIC PROC RETURNS [tune: Tune←Thrush.nullTune] = TRUSTED {
t: Jukebox.Tune = Jukebox.CreateTune[self: BluejaySmarts.handle, tuneId: -1!Jukebox.Error=>GOTO NoTune];
tune ← t.tuneId;
Jukebox.CloseTune[BluejaySmarts.handle, t!Jukebox.Error=>GOTO NoTune];
EXITS
NoTune => NULL;
};
TunesInJukebox: PUBLIC PROC RETURNS [nTunes: INT𡤀] = TRUSTED {
nTunes ← Jukebox.Info[BluejaySmarts.handle!Jukebox.Error=>GOTO Problem].nTunes;
EXITS
Problem => NULL;
};
InitializeJukebox: PUBLIC PROC = TRUSTED {
nTunes: NAT = TunesInJukebox[];
FOR i: NAT IN [0..nTunes) DO
Jukebox.DeleteTune[BluejaySmarts.handle, i!Jukebox.Error=>CONTINUE]; ENDLOOP;
};
Initialize: PUBLIC PROC = {
Uninitialize[];
myName ← [
type: "BluejayUtils.Lark",
instance: UserProfile.Token[key: "BluejayServerInstance", default: "Lampson.Lark"],
version: ThVersions.JayVR
];
BluejayUtilsRpcControl.ExportInterface[
interfaceName: myName,
user: myName.instance,
password: Names.CurrentPasskey[UserProfile.Token[
key: "BluejayServerPassword", default: "MFLFLX"]]];
Log.Report["Bluejay Utility interface Initialized and Exported", $Bluejay];
utilsExported ← TRUE;
};
Uninitialize: PUBLIC PROC = {
IF utilsExported THEN {
BluejayUtilsRpcControl.UnexportInterface[!LupineRuntime.BindingError=>CONTINUE];
Log.Report["Bluejay Utility interface Unexported", $Bluejay];
};
utilsExported ← FALSE;
};
InitCmd: Commander.CommandProc = TRUSTED { Initialize[]; };
UninitCmd: Commander.CommandProc = TRUSTED { Uninitialize[]; };
Commander.Register["JayUtils", InitCmd, "Start Bluejay Utilities (won't work if Ja)"];
Commander.Register["UnJayUtils", UninitCmd, "Terminate Bluejay Utilities (won't work if Ja)"];
}.