[chronojump] Encoder rhythm with clusters



commit 243ebab36dd5e0c92fe42b8339053b956b882bbe
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Jan 18 14:40:48 2018 +0100

    Encoder rhythm with clusters

 glade/app1.glade   |   40 +++++++++++++++++++++-----
 src/encoder.cs     |   79 ++++++++++++++++++++++++++++++++++++++++------------
 src/gui/encoder.cs |    1 +
 3 files changed, 94 insertions(+), 26 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 2ed1939..8e31ab5 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -16862,25 +16862,31 @@ Concentric</property>
                                                             <property name="spacing">8</property>
                                                             <property name="homogeneous">True</property>
                                                             <child>
+                                                            <widget class="GtkVBox" id="vbox121">
+                                                            <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: 1Hz</property>
+                                                            <property name="label">Rhythm:</property>
                                                             <property name="justify">center</property>
                                                             </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="GtkProgressBar" 
id="encoder_pulsebar_rhythm">
-                                                            <property name="width_request">100</property>
+                                                            <widget class="GtkLabel" id="label286">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
-                                                            <property 
name="pulse_step">0.050000000000000003</property>
+                                                            <property name="xalign">0</property>
+                                                            <property name="label">(0.5e+0.5c)*5 
R3</property>
+                                                            <property name="justify">center</property>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -16888,12 +16894,30 @@ Concentric</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
                                                             <child>
-                                                            <widget class="GtkHBox" id="hbox244">
+                                                            <widget class="GtkHBox" id="hbox243">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
+                                                            <property name="spacing">6</property>
                                                             <child>
-                                                            <placeholder/>
+                                                            <widget class="GtkProgressBar" 
id="encoder_pulsebar_rhythm">
+                                                            <property name="width_request">100</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="pulse_step">0.050000000000000003</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
                                                             </child>
                                                             <child>
                                                             <widget class="GtkImage" 
id="image_encoder_rhythm">
@@ -16912,7 +16936,7 @@ Concentric</property>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">True</property>
-                                                            <property name="position">2</property>
+                                                            <property name="position">1</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
diff --git a/src/encoder.cs b/src/encoder.cs
index 81ab836..0e53515 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -2102,14 +2102,36 @@ public class Rx1y2
        }
 }
 
+public class EncoderRhythmObject
+{
+       public double EccSeconds;
+       public double ConSeconds;
+       public double RepsCluster;
+       public double RestSeconds;
+
+       public EncoderRhythmObject()
+       {
+               //default 0.5 seconds ecc, 0.5 con, 5 repetitions and rest 3 seconds
+               EccSeconds = 0.5;
+               ConSeconds = 0.5;
+               RepsCluster = 5;
+               RestSeconds = 3;
+       }
+}
+
 public class EncoderRhythm
 {
        private DateTime lastRepetitionDT;
+       private EncoderRhythmObject ero;
+       private int nreps;
+       public string Text;
 
        //constructor
        public EncoderRhythm()
        {
                lastRepetitionDT = DateTime.MinValue;
+               ero = new EncoderRhythmObject();
+               nreps = 0;
        }
 
        public bool FirstRepetitionDone()
@@ -2120,35 +2142,56 @@ public class EncoderRhythm
        public void SetLastRepetitionDT()
        {
                lastRepetitionDT = DateTime.Now;
+               nreps ++;
+       }
+
+       private bool resting()
+       {
+               if(nreps > 0 && nreps % ero.RepsCluster == 0)
+                       return true;
+
+               return false;
        }
 
+       //useful for fraction of the repetition and the rest time
        public double GetFraction()
        {
                double fraction = 0;
                TimeSpan span = DateTime.Now - lastRepetitionDT;
                double totalSeconds = span.TotalSeconds;
 
-               //this goes up from 0 to 1 second and beyond
-               //encoder_pulsebar_rhythm.Fraction = Util.DivideSafeFraction(totalSeconds, 1.0);
-               //this simulates ecc and con
-               double phase = Util.DivideSafeFraction(totalSeconds, 1.0);
-               if(phase < 0.5)
+               if(resting())
                {
-                       //totalSeconds == 0 graph will show 1
-                       //totalSeconds == 0.1 graph will show 0.8
-                       //totalSeconds == 0.4 graph will show 0.2
-                       fraction = 1 - (phase * 2);
+                       fraction = GetRestingFraction(totalSeconds);
+                       Text = "Resting " + Convert.ToInt32((ero.RestSeconds - totalSeconds)).ToString() + " 
s";
                }
-               else {
-                       //totalSeconds == 0.5 graph will show 0
-                       //totalSeconds == 0.75 graph will show 0.5
-                       //totalSeconds == 0.9 graph will show 0.8
-                       //totalSeconds >= 1 graph will show 1
-                       double phaseSup = phase - .5;
-                       fraction = phaseSup * 2;
-                       if(fraction > 1)
-                               fraction = 1;
+               else
+               {
+                       fraction = GetRepetitionFraction(totalSeconds);
+                       Text = "";
                }
+
+               if(fraction < 0)
+                       fraction = 0;
+               else if(fraction > 1)
+                       fraction = 1;
+
                return fraction;
        }
+
+       public double GetRepetitionFraction(double totalSeconds)
+       {
+               if(totalSeconds < ero.EccSeconds)
+               {
+                       return 1 - (totalSeconds / ero.EccSeconds);
+               }
+               else {
+                       return (totalSeconds - ero.EccSeconds) / ero.ConSeconds;
+               }
+       }
+
+       public double GetRestingFraction(double totalSeconds)
+       {
+               return totalSeconds / ero.RestSeconds;
+       }
 }
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index b4c3691..c77077d 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -6026,6 +6026,7 @@ public partial class ChronoJumpWindow
                encoder_pulsebar_rhythm.Visible = true;
                double fraction = encoderRhythm.GetFraction();
                encoder_pulsebar_rhythm.Fraction = fraction;
+               encoder_pulsebar_rhythm.Text = encoderRhythm.Text;
 
                if(fraction >= 1)
                        image_encoder_rhythm.Visible = true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]