Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions ClockFace.sc
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
ClockFace {
var <starttime, <tempo, <>inc, <cursecs, isPlaying = false, <clock, <window, timeString;
var <starttime, <tempo, <>inc, <view, <cursecs, isPlaying = false, <clock, timeString;
var remFun, <mod, startBeats, <>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 {
Expand All @@ -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;
Expand All @@ -54,39 +54,51 @@ ClockFace {
curdisp = curdisp[0 .. (curdisp.size-3)];
updateStart.if({starttime = cursecs; (isPlaying).if({
startBeats = clock.elapsedBeats;
});
});
});
{timeString.string_(curdisp)}.defer;
}
}

stop {
starttime = cursecs;
isPlaying = false;
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});
}

}

3 changes: 3 additions & 0 deletions HelpSource/Classes/ClockFace.schelp
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down