Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactoring and Timer

  • Loading branch information...
commit 6ed91cba47090b4cdb3333fecf3efc307aa1d75c 1 parent 2993736
Patrick Borgeat authored
18 MandelGUI.sc
View
@@ -10,7 +10,7 @@
MandelGUI
{
- var <window, bpmText, mesText, beatText, bpsText, beatArr, clock, hub;
+ var <window, bpmText, mesText, beatText, timerText, beatArr, clock, hub;
var sj;
var stillOpen = true;
@@ -31,8 +31,8 @@ MandelGUI
window = Window.new("MandelGUI", Rect(pos.x,pos.y,288,65), false);
window.addFlowLayout(10@10,5@5);
- bpmText = StaticText(window, 50@20);
- StaticText(window,45@20).string_("BPM");
+
+ timerText = StaticText(window, 100@20);
mesText = StaticText(window, 45@20);
beatText = StaticText(window, 45@20);
@@ -44,8 +44,8 @@ MandelGUI
window.view.decorator.nextLine;
- bpsText = StaticText(window, 50@20);
- StaticText(window,45@20).string_("BPS");
+ bpmText = StaticText(window, 50@20);
+ StaticText(window,45@20).string_("BPM");
beatArr = nil.dup(4);
@@ -65,6 +65,7 @@ MandelGUI
var tempo = hub.externalTempo;
var color = Color.black;
+ var minutes, seconds;
MandelHub.debug.if {
tempo = hub.tempo;
@@ -79,10 +80,13 @@ MandelGUI
};
bpmText.stringColor_(color);
- bpsText.stringColor_(color);
bpmText.string_((tempo * 60).asString[0..5]);
- bpsText.string_(tempo.asString[0..5]);
+
+ minutes = (hub.timer.elapsedTime / 60).floor.asString.padLeft(2, "0");
+ seconds = (hub.timer.elapsedTime % 60).floor.asString.padLeft(2, "0");
+
+ timerText.string_(minutes ++ ":" ++ seconds);
beatText.string_((clock.beats % 4 + 1).asString[0..4]);
15 MandelHub.sc
View
@@ -68,6 +68,7 @@ MandelHub {
var <tools;
var <platform;
var <time;
+ var <timer;
var <>server;
@@ -172,7 +173,8 @@ MandelHub {
this.prBecomeLeader;
},{
this.prBecomeFollower;
- {this.sendHello}.defer(1);
+ {this.sendRequestSync}.defer(1);
+ {this.sendHello}.defer(1.5);
});
this.prDoCmdPeriod;
@@ -187,6 +189,8 @@ MandelHub {
modules.add(space);
tools = MandelTools(this);
modules.add(tools);
+ timer = MandelTimer(this);
+ modules.add(timer);
// platform specific
Platform.case(
@@ -206,6 +210,10 @@ MandelHub {
modules.do {|module| module.onStartup(this) };
}
+ sendRequestSync {
+ this.net.sendMsgBurst("/requestSync", \critical);
+ }
+
sendHello {
this.net.sendMsgBurst("/hello", \relaxed);
}
@@ -358,7 +366,6 @@ MandelHub {
// responders only for leaders
prLeaderResponders {
-
this.net.addOSCResponder(\leader, "/requestTempo", {|header, payload|
this.post(header.name ++ " requested a tempo change to " ++ payload[0].asFloat ++ " BPS");
@@ -369,6 +376,10 @@ MandelHub {
this.post("Tempochange denied.");
});
});
+
+ this.net.addOSCResponder(\leader, "/requestSync", {|header, payload|
+ modules.do {|module| module.onSyncRequest(this, header);};
+ }, \dropOwn);
}
// responders for leaders and followers
4 MandelModule.sc
View
@@ -34,4 +34,8 @@ MandelModule {
onClear {|hub|
}
+
+ onSyncRequest {|hub|
+
+ }
}
8 MandelNetwork.sc
View
@@ -85,10 +85,10 @@ MandelNetwork : MandelModule {
hub.post(header.name ++ " requested port " ++ payload[0]);
this.sendPublishPorts;
});
-
- this.addOSCResponder(\leader, "/publishPorts", {|header, payload|
- this.sendSystemPorts;
- });
+ }
+
+ onSyncRequest {|hub, header|
+ this.sendSystemPorts;
}
/*
12 MandelSpace.sc
View
@@ -311,9 +311,8 @@ MandelSpace : MandelModule {
^value.asString;
}
- onBecomeLeader {|hub|
- hub.net.addOSCResponder(\leader, "/requestValueSync", {|header, payload|
- {
+ onSyncRequest {|hub|
+ {
0.1.wait;
objects.keys.do {|key|
var value = objects.at(key).bdl;
@@ -328,8 +327,7 @@ MandelSpace : MandelModule {
};
};
};
- }.fork; // delay a little bit and add wait times
- }, \dropOwn);
+ }.fork; // delay a little bit and add wait time
}
onStartup {|hub|
@@ -355,10 +353,6 @@ MandelSpace : MandelModule {
var value = this.deserialize(payload[2], payload[3]);
this.getObject(key).tryHealValue(value, schedBeats, header.name);
}, \dropOwn);
-
- hub.leading.not.if {
- hub.net.sendMsgCmd("/requestValueSync"); // request MandelSpace sync from the leader
- }
}
envir {
52 MandelTimer.sc
View
@@ -0,0 +1,52 @@
+/*
+ MandelTimer
+ (c) 2012 by Patrick Borgeat <patrick@borgeat.de>
+ http://www.cappel-nord.de
+
+ Part of BenoitLib
+ http://github.com/cappelnord/BenoitLib
+ http://www.the-mandelbrots.de
+
+ MandelTimer provides a resetable timer, visible
+ in the GUI.
+*/
+
+MandelTimer : MandelModule {
+
+ var startTime;
+ var <hub;
+
+ *new {|hub|
+ ^super.new.init(hub);
+ }
+
+ init {|a_hub|
+ hub = a_hub;
+ startTime = Process.elapsedTime;
+ }
+
+ elapsedTime {
+ ^(Process.elapsedTime - startTime);
+ }
+
+ reset {
+ hub.leading.if {
+ startTime = Process.elapsedTime;
+ this.sendElapsedTime;
+ };
+ }
+
+ onBecomeFollower {|hub|
+ hub.net.addOSCResponder(\follower, "/timerElapsedTime", {|header, payload|
+ startTime = Process.elapsedTime - payload[0];
+ }, \leaderOnly);
+ }
+
+ onSyncRequest {|hub|
+ this.sendElapsedTime;
+ }
+
+ sendElapsedTime {
+ hub.net.sendMsgBurst("/timerElapsedTime", \timeCritical, this.elapsedTime);
+ }
+}
5 tutorials/01-Getting Started.scd
View
@@ -58,6 +58,11 @@ m.takeLead;
m.gui;
+// There is a timer which shows how long the current MandelHub exists.
+// You can also reset your timer, to know how long you've allready played
+
+m.timer.reset;
+
// You see the Chat and Shout buttons? They make it easy to communicate with
// your fellow live coders.
Please sign in to comment.
Something went wrong with that request. Please try again.