diff --git a/ClockFace.sc b/ClockFace.sc index e3f0746..b01cea7 100644 --- a/ClockFace.sc +++ b/ClockFace.sc @@ -1,21 +1,21 @@ ClockFace { - var inc, inc, onMod, <>onBeat; - *new{ arg starttime = 0, tempo = 1, inc = 0.1, alwaysOnTop=false; - ^super.newCopyArgs(starttime, tempo, inc).init(alwaysOnTop); - } + *new{ arg starttime = 0, tempo = 1, inc = 0.1, alwaysOnTop=false, view; + ^super.newCopyArgs(starttime, tempo, inc, view).init(alwaysOnTop); + } init {|alwaysOnTop = false| cursecs = starttime; this.digitalGUI; this.alwaysOnTop = alwaysOnTop; - } + } start { this.play; } alwaysOnTop_ {|bool| - ^window.alwaysOnTop_(bool); + ^view.alwaysOnTop_(bool); } play { @@ -32,20 +32,20 @@ ClockFace { cur = cur%mod; (cur < last).if({ {onMod.value; - onBeat.value(cur.floor.asInt); + onBeat.value(cur.floor.asInt); }.defer; - }); }); + }); this.cursecs_(cur, false); onBeat.notNil.if({ (((floor = cur.floor) - last.floor) == 1).if({ {onBeat.value(floor.asInt)}.defer; - }); }); + }); last = cur; inc; - }) - } + }) + } cursecs_ {arg curtime, updateStart = true; var curdisp; @@ -54,10 +54,10 @@ ClockFace { curdisp = curdisp[0 .. (curdisp.size-3)]; updateStart.if({starttime = cursecs; (isPlaying).if({ startBeats = clock.elapsedBeats; - }); + }); }); {timeString.string_(curdisp)}.defer; - } + } stop { starttime = cursecs; @@ -65,28 +65,40 @@ ClockFace { clock.clear; CmdPeriod.remove(remFun); clock.stop; - } + } tempo_ {arg newBPS = 1; tempo = newBPS; isPlaying.if({clock.tempo_(tempo)}); - } + } mod_ {arg newMod = 0; (newMod == 0).if({ mod = nil; - }, { + }, { mod = newMod; - }) - } + }) + } + + window { // for backwards compatibility + ^view + } + + asView { + ^view + } digitalGUI { - window = GUI.window.new("Digital Clock", Rect(10, 250, 450, 110)).front; - timeString = GUI.staticText.new(window, Rect(0, 0, 430, 100)) - .string_(cursecs.asTimeString) - .font_(Font("Arial", 40)); - window.onClose_({this.stop}); - } + //window = GUI.window.new("Digital Clock", Rect(10, 250, 450, 110)).front; + view.isNil.if ({ + view = GUI.window.new("Digital Clock", Rect(10, 250, 450, 110)).front; + }); + + timeString = GUI.staticText.new(view, Rect(0, 0, 430, 100)) + .string_(cursecs.asTimeString) + .font_(Font("Arial", 40)); + view.onClose_({"stop".debug(this); this.stop}); + } } diff --git a/HelpSource/Classes/ClockFace.schelp b/HelpSource/Classes/ClockFace.schelp index fb83aed..545bd13 100644 --- a/HelpSource/Classes/ClockFace.schelp +++ b/HelpSource/Classes/ClockFace.schelp @@ -20,6 +20,9 @@ increment amount ARGUMENT:: alwaysOnTop Should the window always be on top +ARGUMENT:: view +An optional View object to hold the clock. If none is provided, a new Window will open. + INSTANCEMETHODS::