[chronojump] encoder rhythm with clusters and rests
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] encoder rhythm with clusters and rests
- Date: Thu, 18 Jan 2018 17:33:40 +0000 (UTC)
commit 49b4038ae889153caf5e565bb1440bbbf4944ec9
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Jan 18 18:31:21 2018 +0100
encoder rhythm with clusters and rests
glade/app1.glade | 50 ++++++++++++++---------------------
src/encoder.cs | 73 +++++++++++++++++++++++++++++++++++++++------------
src/gui/encoder.cs | 27 ++++++++++++-------
3 files changed, 93 insertions(+), 57 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 8e31ab5..9af2004 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1580,6 +1580,9 @@
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
<widget class="GtkLabel"
id="label_start_selector_jumps">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -16862,16 +16865,15 @@ Concentric</property>
<property name="spacing">8</property>
<property name="homogeneous">True</property>
<child>
- <widget class="GtkVBox" id="vbox121">
+ <widget class="GtkHBox" id="hbox244">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">4</property>
<child>
<widget class="GtkLabel" id="label289">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label">Rhythm:</property>
+ <property name="label">Rhythm</property>
<property name="justify">center</property>
</widget>
<packing>
@@ -16881,34 +16883,27 @@ Concentric</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label286">
+ <widget class="GtkImage"
id="image_encoder_rhythm_alert">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label">(0.5e+0.5c)*5
R3</property>
- <property name="justify">center</property>
+ <property
name="stock">gtk-dialog-warning</property>
</widget>
<packing>
<property name="expand">False</property>
- <property name="fill">True</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <widget class="GtkHBox" id="hbox243">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="spacing">6</property>
- <child>
- <widget class="GtkProgressBar"
id="encoder_pulsebar_rhythm">
- <property name="width_request">100</property>
+ <widget class="GtkProgressBar"
id="encoder_pulsebar_rhythm_eccon">
+ <property name="width_request">120</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property
name="pulse_step">0.050000000000000003</property>
@@ -16916,27 +16911,19 @@ Concentric</property>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
- <widget class="GtkImage"
id="image_encoder_rhythm">
- <property name="visible">True</property>
+ <widget class="GtkProgressBar"
id="encoder_pulsebar_rhythm_wait">
+ <property name="width_request">120</property>
<property name="can_focus">False</property>
- <property
name="stock">gtk-dialog-warning</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="pack_type">end</property>
- <property name="position">1</property>
- </packing>
- </child>
+ <property
name="pulse_step">0.050000000000000003</property>
</widget>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</widget>
@@ -22651,6 +22638,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index 0e53515..e4535f8 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -2106,32 +2106,45 @@ public class EncoderRhythmObject
{
public double EccSeconds;
public double ConSeconds;
+ public double RestRepsSeconds; //rest between repetitions
+
+ //cluster stuff
public double RepsCluster;
- public double RestSeconds;
+ public double RestClustersSeconds; //rest between clusters
public EncoderRhythmObject()
{
//default 0.5 seconds ecc, 0.5 con, 5 repetitions and rest 3 seconds
EccSeconds = 0.5;
ConSeconds = 0.5;
+ RestRepsSeconds = 1;
+
RepsCluster = 5;
- RestSeconds = 3;
+ RestClustersSeconds = 6;
}
}
-
public class EncoderRhythm
{
+ public string Text;
+ public bool ShowRestingSpinner;
+
private DateTime lastRepetitionDT;
private EncoderRhythmObject ero;
private int nreps;
- public string Text;
+ //private bool restingBetweenClustersFlag; //to manage lastRepetitionDT when rest finished
+ private bool restClusterTimeEndedFlag;
+
//constructor
public EncoderRhythm()
{
+ Text = "";
+ ShowRestingSpinner = false;
+
lastRepetitionDT = DateTime.MinValue;
ero = new EncoderRhythmObject();
nreps = 0;
+ restClusterTimeEndedFlag = false;
}
public bool FirstRepetitionDone()
@@ -2143,12 +2156,26 @@ public class EncoderRhythm
{
lastRepetitionDT = DateTime.Now;
nreps ++;
+ restClusterTimeEndedFlag = false;
}
- private bool resting()
+ private bool checkIfRestingBetweenClusters(double totalSeconds)
{
+ if(restClusterTimeEndedFlag)
+ return false;
+
if(nreps > 0 && nreps % ero.RepsCluster == 0)
- return true;
+ {
+ if(totalSeconds < ero.RestClustersSeconds)
+ return true;
+ else {
+ //resting time passed, force finish rest,
+ //mark change of lastRepetitionDT to calculate fraction correctly below
+ lastRepetitionDT = DateTime.Now;
+ restClusterTimeEndedFlag = true;
+ return false;
+ }
+ }
return false;
}
@@ -2160,16 +2187,10 @@ public class EncoderRhythm
TimeSpan span = DateTime.Now - lastRepetitionDT;
double totalSeconds = span.TotalSeconds;
- if(resting())
- {
+ if(checkIfRestingBetweenClusters(totalSeconds))
fraction = GetRestingFraction(totalSeconds);
- Text = "Resting " + Convert.ToInt32((ero.RestSeconds - totalSeconds)).ToString() + "
s";
- }
else
- {
fraction = GetRepetitionFraction(totalSeconds);
- Text = "";
- }
if(fraction < 0)
fraction = 0;
@@ -2181,17 +2202,35 @@ public class EncoderRhythm
public double GetRepetitionFraction(double totalSeconds)
{
- if(totalSeconds < ero.EccSeconds)
+ if(totalSeconds < ero.RestRepsSeconds)
+ {
+ Text = "Resting " +
+ Util.TrimDecimals((ero.RestRepsSeconds - totalSeconds),1) +
+ " s";
+ ShowRestingSpinner = true;
+ return 0;
+ //return totalSeconds / ero.RestRepsSeconds;
+ }
+ else if((totalSeconds - ero.RestRepsSeconds) < ero.EccSeconds)
{
- return 1 - (totalSeconds / ero.EccSeconds);
+ Text = "Excentric";
+ ShowRestingSpinner = false;
+ return 1 - ((totalSeconds - ero.RestRepsSeconds) / ero.EccSeconds);
}
else {
- return (totalSeconds - ero.EccSeconds) / ero.ConSeconds;
+ Text = "Concentric";
+ ShowRestingSpinner = false;
+ return (totalSeconds - (ero.RestRepsSeconds + ero.EccSeconds)) / ero.ConSeconds;
}
}
public double GetRestingFraction(double totalSeconds)
{
- return totalSeconds / ero.RestSeconds;
+ ShowRestingSpinner = true;
+ Text = "Resting " +
+ Convert.ToInt32((ero.RestClustersSeconds - totalSeconds)).ToString() +
+ " s";
+ //return totalSeconds / ero.RestClustersSeconds;
+ return 0;
}
}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index c77077d..c70564a 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -99,8 +99,9 @@ public partial class ChronoJumpWindow
[Widget] Gtk.Viewport viewport_image_encoder_capture;
[Widget] Gtk.Image image_encoder_capture;
[Widget] Gtk.ProgressBar encoder_pulsebar_capture;
- [Widget] Gtk.ProgressBar encoder_pulsebar_rhythm;
- [Widget] Gtk.Image image_encoder_rhythm;
+ [Widget] Gtk.ProgressBar encoder_pulsebar_rhythm_eccon;
+ [Widget] Gtk.ProgressBar encoder_pulsebar_rhythm_wait;
+ [Widget] Gtk.Image image_encoder_rhythm_alert;
[Widget] Gtk.VBox vbox_encoder_signal_comment;
[Widget] Gtk.Notebook notebook_encoder_signal_comment_rhythm_and_triggers;
[Widget] Gtk.TextView textview_encoder_signal_comment;
@@ -5309,7 +5310,7 @@ public partial class ChronoJumpWindow
//initialize DateTime for rhythm
encoderRhythm = new EncoderRhythm();
- image_encoder_rhythm.Visible = false;
+ image_encoder_rhythm_alert.Visible = false;
encoderThread = new Thread(new ThreadStart(encoderDoCaptureCsharp));
GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCaptureAndCurves));
@@ -5789,7 +5790,7 @@ public partial class ChronoJumpWindow
//TODO: is better to do this before when the curves was sent,
//not when needToRefreshTreeviewCapture (because this is too later because
it's returning from R)
encoderRhythm.SetLastRepetitionDT();
- image_encoder_rhythm.Visible = false;
+ image_encoder_rhythm_alert.Visible = false;
//LogB.Error("HERE YES");
//LogB.Error(encoderCaptureStringR);
@@ -6018,18 +6019,24 @@ public partial class ChronoJumpWindow
{
if(! encoderRhythm.FirstRepetitionDone())
{
- encoder_pulsebar_rhythm.Fraction = 0;
- encoder_pulsebar_rhythm.Visible = false;
+ encoder_pulsebar_rhythm_eccon.Fraction = 0;
+ encoder_pulsebar_rhythm_wait.Fraction = 0;
+ encoder_pulsebar_rhythm_eccon.Text = "Waiting 1st rep.";
return;
}
- encoder_pulsebar_rhythm.Visible = true;
double fraction = encoderRhythm.GetFraction();
- encoder_pulsebar_rhythm.Fraction = fraction;
- encoder_pulsebar_rhythm.Text = encoderRhythm.Text;
+ encoder_pulsebar_rhythm_eccon.Fraction = fraction;
+ encoder_pulsebar_rhythm_eccon.Text = encoderRhythm.Text;
+
+ //image_encoder_rhythm_wait.Visible = encoderRhythm.ShowRestingSpinner;
+ /*
+ if(encoderRhythm.ShowRestingSpinner)
+ spinner_encoder_rhythm_wait.Spin();
+ */
if(fraction >= 1)
- image_encoder_rhythm.Visible = true;
+ image_encoder_rhythm_alert.Visible = true;
}
// -------------- drawingarea_encoder_analyze_instant
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]