[chronojump] DB: 1.54 encoder rhythm by repetitions (default) or phases



commit cd021666ee80215cf82b6d5de2f5dda6cad4b78a
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jan 30 11:12:34 2018 +0100

    DB: 1.54 encoder rhythm by repetitions (default) or phases

 glade/repetitive_conditions.glade |  295 +++++++++++++++++++++++++++++--------
 src/encoderCapture.cs             |   21 ++-
 src/encoderRhythm.cs              |   30 +++-
 src/gui/chronojump.cs             |    3 +-
 src/gui/encoder.cs                |    6 +-
 src/gui/repetitiveConditions.cs   |   23 +++-
 src/preferences.cs                |   44 +++++-
 src/sqlite/main.cs                |   13 ++-
 src/sqlite/preferences.cs         |    9 +
 9 files changed, 355 insertions(+), 89 deletions(-)
---
diff --git a/glade/repetitive_conditions.glade b/glade/repetitive_conditions.glade
index e39ae28..d305e73 100644
--- a/glade/repetitive_conditions.glade
+++ b/glade/repetitive_conditions.glade
@@ -3623,15 +3623,19 @@
                             <property name="can_focus">False</property>
                             <property name="spacing">10</property>
                             <child>
-                              <widget class="GtkHBox" id="hbox38">
+                              <widget class="GtkHBox" id="hbox43">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="spacing">6</property>
+                                <property name="spacing">12</property>
                                 <child>
-                                  <widget class="GtkLabel" id="label29">
+                                  <widget class="GtkRadioButton" id="radio_rhythm_together">
+                                    <property name="label" translatable="yes">Rhythm of the 
repetition</property>
                                     <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="label" translatable="yes">Duration of eccentric 
phase</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="active">True</property>
+                                    <property name="draw_indicator">True</property>
+                                    <signal name="toggled" handler="on_radio_rhythm_together_toggled" 
swapped="no"/>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
@@ -3640,16 +3644,15 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <widget class="GtkSpinButton" id="spin_rhythm_ecc">
+                                  <widget class="GtkRadioButton" id="radio_rhythm_separated">
+                                    <property name="label" translatable="yes">Rhythm by phases</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="invisible_char">●</property>
-                                    <property name="primary_icon_activatable">False</property>
-                                    <property name="secondary_icon_activatable">False</property>
-                                    <property name="primary_icon_sensitive">True</property>
-                                    <property name="secondary_icon_sensitive">True</property>
-                                    <property name="adjustment">0.10000000000000001 0.10000000000000001 10 
0.10000000000000001 1 0</property>
-                                    <property name="digits">2</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="active">True</property>
+                                    <property name="draw_indicator">True</property>
+                                    <property name="group">radio_rhythm_together</property>
+                                    <signal name="toggled" handler="on_radio_rhythm_together_toggled" 
swapped="no"/>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
@@ -3657,18 +3660,6 @@
                                     <property name="position">1</property>
                                   </packing>
                                 </child>
-                                <child>
-                                  <widget class="GtkLabel" id="label41">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="label" translatable="yes">seconds</property>
-                                  </widget>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">2</property>
-                                  </packing>
-                                </child>
                               </widget>
                               <packing>
                                 <property name="expand">False</property>
@@ -3677,51 +3668,221 @@
                               </packing>
                             </child>
                             <child>
-                              <widget class="GtkHBox" id="hbox39">
+                              <widget class="GtkAlignment" id="alignment25">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="spacing">6</property>
-                                <child>
-                                  <widget class="GtkLabel" id="label39">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="label" translatable="yes">Duration of concentric 
phase</property>
-                                  </widget>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">0</property>
-                                  </packing>
-                                </child>
+                                <property name="left_padding">30</property>
                                 <child>
-                                  <widget class="GtkSpinButton" id="spin_rhythm_con">
+                                  <widget class="GtkNotebook" id="notebook_duration_repetition">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="invisible_char">●</property>
-                                    <property name="primary_icon_activatable">False</property>
-                                    <property name="secondary_icon_activatable">False</property>
-                                    <property name="primary_icon_sensitive">True</property>
-                                    <property name="secondary_icon_sensitive">True</property>
-                                    <property name="adjustment">0.5 0.10000000000000001 10 
0.10000000000000001 1 0</property>
-                                    <property name="digits">2</property>
-                                  </widget>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">1</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <widget class="GtkLabel" id="label42">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="label" translatable="yes">seconds</property>
+                                    <property name="show_tabs">False</property>
+                                    <property name="show_border">False</property>
+                                    <child>
+                                      <widget class="GtkVBox" id="vbox12">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <child>
+                                          <widget class="GtkHBox" id="hbox_duration_repetition">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="spacing">6</property>
+                                            <child>
+                                              <widget class="GtkLabel" id="label50">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label" translatable="yes">Duration of 
repetition</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkSpinButton" id="spin_rhythm_rep">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="invisible_char">●</property>
+                                                <property name="primary_icon_activatable">False</property>
+                                                <property name="secondary_icon_activatable">False</property>
+                                                <property name="primary_icon_sensitive">True</property>
+                                                <property name="secondary_icon_sensitive">True</property>
+                                                <property name="adjustment">2 0.10000000000000001 10 
0.10000000000000001 1 0</property>
+                                                <property name="digits">2</property>
+                                                <property name="numeric">True</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkLabel" id="label51">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label" translatable="yes">seconds</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">2</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkLabel" id="label52">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label" translatable="yes">page 1</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="tab_fill">False</property>
+                                        <property name="type">tab</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkVBox" id="vbox11">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="spacing">10</property>
+                                        <child>
+                                          <widget class="GtkHBox" id="hbox_duration_ecc">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="spacing">6</property>
+                                            <child>
+                                              <widget class="GtkLabel" id="label29">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label" translatable="yes">Duration of 
eccentric phase</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkSpinButton" id="spin_rhythm_ecc">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="invisible_char">●</property>
+                                                <property name="primary_icon_activatable">False</property>
+                                                <property name="secondary_icon_activatable">False</property>
+                                                <property name="primary_icon_sensitive">True</property>
+                                                <property name="secondary_icon_sensitive">True</property>
+                                                <property name="adjustment">1 0.10000000000000001 10 
0.10000000000000001 1 0</property>
+                                                <property name="digits">2</property>
+                                                <property name="numeric">True</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkLabel" id="label41">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label" translatable="yes">seconds</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">2</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">True</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkHBox" id="hbox_duration_con">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="spacing">6</property>
+                                            <child>
+                                              <widget class="GtkLabel" id="label39">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label" translatable="yes">Duration of 
concentric phase</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkSpinButton" id="spin_rhythm_con">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="invisible_char">●</property>
+                                                <property name="primary_icon_activatable">False</property>
+                                                <property name="secondary_icon_activatable">False</property>
+                                                <property name="primary_icon_sensitive">True</property>
+                                                <property name="secondary_icon_sensitive">True</property>
+                                                <property name="adjustment">1 0.10000000000000001 10 
0.10000000000000001 1 0</property>
+                                                <property name="digits">2</property>
+                                                <property name="numeric">True</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkLabel" id="label42">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label" translatable="yes">seconds</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">2</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">True</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkLabel" id="label53">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label" translatable="yes">page 2</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="position">1</property>
+                                        <property name="tab_fill">False</property>
+                                        <property name="type">tab</property>
+                                      </packing>
+                                    </child>
                                   </widget>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">2</property>
-                                  </packing>
                                 </child>
                               </widget>
                               <packing>
@@ -3758,6 +3919,7 @@
                                     <property name="secondary_icon_sensitive">True</property>
                                     <property name="adjustment">1 0 99 0.10000000000000001 1 0</property>
                                     <property name="digits">2</property>
+                                    <property name="numeric">True</property>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
@@ -3839,12 +4001,14 @@
                                             <property name="visible">True</property>
                                             <property name="can_focus">True</property>
                                             <property name="invisible_char">●</property>
+                                            <property name="width_chars">2</property>
+                                            <property name="progress_pulse_step">1</property>
                                             <property name="primary_icon_activatable">False</property>
                                             <property name="secondary_icon_activatable">False</property>
                                             <property name="primary_icon_sensitive">True</property>
                                             <property name="secondary_icon_sensitive">True</property>
                                             <property name="adjustment">5 2 30 1 10 0</property>
-                                            <property name="digits">2</property>
+                                            <property name="numeric">True</property>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>
@@ -3889,6 +4053,7 @@
                                             <property name="adjustment">6 0.10000000000000001 99 
0.10000000000000001 1 0</property>
                                             <property name="climb_rate">1</property>
                                             <property name="digits">2</property>
+                                            <property name="numeric">True</property>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index 8645722..c98c199 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -42,6 +42,7 @@ public abstract class EncoderCapture
 
        //encoderRhythm stuff
        private bool useRhythm;
+       private bool rhythmRepsOrPhases;
        public int RhythmNRep; //used to know rest between clusters
        public bool RhythmEcconUp;
        private Gtk.Button fakeButtonRhythm;
@@ -120,7 +121,7 @@ public abstract class EncoderCapture
        //if cont (continuous mode), then will not end when too much time passed before start
        public void InitGlobal (int widthG, int heightG, int time, int timeEnd,
                        bool cont, string eccon, string port, bool capturingInertialBG, bool showOnlyBars,
-                       bool simulated, bool useRhythm)
+                       bool simulated, bool useRhythm, bool rhythmRepsOrPhases)
        {
                this.widthG = widthG;
                this.heightG = heightG;
@@ -130,6 +131,7 @@ public abstract class EncoderCapture
                this.showOnlyBars = showOnlyBars;
                this.simulated = simulated;
                this.useRhythm = useRhythm;
+               this.rhythmRepsOrPhases = rhythmRepsOrPhases;
 
                if(useRhythm)
                        fakeButtonRhythm = new Gtk.Button();
@@ -585,10 +587,21 @@ public abstract class EncoderCapture
                                                if( useRhythm && (shouldSendCurveBool || (eccon == "c" && ! 
ecc.up)) )
                                                {
                                                        LogB.Information("SSC: " + ecc.up.ToString());
-                                                       if( (eccon == "c" && ecc.up) || (eccon != "c" && ! 
ecc.up))
-                                                               RhythmNRep ++;
                                                        RhythmEcconUp = ecc.up;
-                                                       fakeButtonRhythm.Click();
+
+                                                       if(rhythmRepsOrPhases)
+                                                       {
+                                                               if(eccon == "c" && ecc.up)
+                                                               {
+                                                                       RhythmNRep ++;
+                                                                       fakeButtonRhythm.Click();
+                                                               }
+                                                       } else {
+                                                               if( (eccon == "c" && ecc.up) || (eccon != "c" 
&& ! ecc.up))
+                                                                       RhythmNRep ++;
+
+                                                               fakeButtonRhythm.Click();
+                                                       }
                                                }
                                        }
 
diff --git a/src/encoderRhythm.cs b/src/encoderRhythm.cs
index 587b1c6..c55619c 100644
--- a/src/encoderRhythm.cs
+++ b/src/encoderRhythm.cs
@@ -24,6 +24,8 @@ using System.Data;
 public class EncoderRhythm
 {
        public bool Active;
+       public bool RepsOrPhases; //true is by repetition, using RepSeconds. False is by phases, using 
EccSeconds, ConSeconds
+       public double RepSeconds;
        public double EccSeconds;
        public double ConSeconds;
        public double RestRepsSeconds; //rest between repetitions
@@ -37,18 +39,24 @@ public class EncoderRhythm
                Active = false;
 
                //default values
+               RepsOrPhases = true;
+               RepSeconds = 2;
                EccSeconds = 1;
                ConSeconds = 1;
+
                RestRepsSeconds = 0;
 
                RepsCluster = 1; //1 is default, minimum value and means "no use clusters"
                RestClustersSeconds = 6;
        }
 
-       public EncoderRhythm(bool active, double eccSeconds, double conSeconds, double restRepsSeconds,
+       public EncoderRhythm(bool active, bool repsOrPhases,
+                       double repSeconds, double eccSeconds, double conSeconds, double restRepsSeconds,
                        int repsCluster, double restClustersSeconds)
        {
                Active = active;
+               RepsOrPhases = repsOrPhases;
+               RepSeconds = repSeconds;
                EccSeconds = eccSeconds;
                ConSeconds = conSeconds;
                RestRepsSeconds = restRepsSeconds;
@@ -132,6 +140,10 @@ public class EncoderRhythmExecute
                return (nreps % encoderRhythm.RepsCluster == 0);
        }
 
+       /*
+        * if RepsOrPhases == true (by phases), then ChangePhase will be called when repetition ends
+        * else will be called when ecc or con ends
+        */
        public void ChangePhase(int nrep, bool up)
        {
                lastRepetitionDT = DateTime.Now;
@@ -203,6 +215,9 @@ public class EncoderRhythmExecute
                        return;
                }
 
+               TextRest = "";
+                       fractionRest = 0;
+
                /*
                 * if we ended con and repetition ends at con, then substract restRepsSeconds to totalSeconds 
to calculate fraction
                 * als when we done ecc and repetition ends at ecc
@@ -210,19 +225,18 @@ public class EncoderRhythmExecute
                if(restRepsSeconds > 0 && lastIsUp == eccon_ec)
                        totalSeconds -= restRepsSeconds;
 
-               if(lastIsUp)
+               if(encoderRhythm.RepsOrPhases)
+               {
+                       TextRepetition = "";
+                       fractionRepetition = (totalSeconds) / encoderRhythm.RepSeconds;
+               }
+               else if(lastIsUp)
                {
                        TextRepetition = "Excentric";
-                       TextRest = "";
                        fractionRepetition = 1 - ((totalSeconds) / encoderRhythm.EccSeconds);
-                       fractionRest = 0;
-                       return;
                } else {
                        TextRepetition = "Concentric";
-                       TextRest = "";
                        fractionRepetition = (totalSeconds) / encoderRhythm.ConSeconds;
-                       fractionRest = 0;
-                       return;
                }
        }
 
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index a0904c9..a57d9b0 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -803,7 +803,8 @@ public partial class ChronoJumpWindow
                configInitFromPreferences();
 
                encoderRhythm = new EncoderRhythm(
-                               preferences.encoderRhythmActive,
+                               preferences.encoderRhythmActive, preferences.encoderRhythmRepsOrPhases,
+                               preferences.encoderRhythmRepSeconds,
                                preferences.encoderRhythmEccSeconds, preferences.encoderRhythmConSeconds,
                                preferences.encoderRhythmRestRepsSeconds,
                                preferences.encoderRhythmRepsCluster, 
preferences.encoderRhythmRestClustersSeconds);
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 8839cac..faaa7d5 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -5289,7 +5289,8 @@ public partial class ChronoJumpWindow
                                                (encoderConfigurationCurrent.has_inertia && 
eCaptureInertialBG != null),
                                                configChronojump.EncoderCaptureShowOnlyBars,
                                                currentSession.Name == Constants.SessionSimulatedName && 
testsActive,
-                                               (encoderRhythm.Active && ! 
encoderConfigurationCurrent.has_inertia) //rhythm only on gravitory now
+                                               (encoderRhythm.Active && ! 
encoderConfigurationCurrent.has_inertia), //rhythm only on gravitory now
+                                               encoderRhythm.RepsOrPhases
                                                );
 
                                if(encoderConfigurationCurrent.has_inertia && eCaptureInertialBG != null)
@@ -5344,7 +5345,8 @@ public partial class ChronoJumpWindow
                                                false,
                                                false,
                                                false,
-                                               false //encoderRhythm.Active
+                                               false, //encoderRhythm.Active
+                                               encoderRhythm.RepsOrPhases
                                                );
 
                                encoderRProcCapture.CutByTriggers = Preferences.TriggerTypes.NO_TRIGGERS; 
//do not cutByTriggers on inertial, yet.
diff --git a/src/gui/repetitiveConditions.cs b/src/gui/repetitiveConditions.cs
index deb99ab..309c892 100644
--- a/src/gui/repetitiveConditions.cs
+++ b/src/gui/repetitiveConditions.cs
@@ -155,9 +155,12 @@ public class RepetitiveConditionsWindow
 
        //encoder rhythm
        [Widget] Gtk.CheckButton check_rhythm_active;
+       [Widget] Gtk.RadioButton radio_rhythm_together;
+       [Widget] Gtk.Notebook notebook_duration_repetition;
        [Widget] Gtk.VBox vbox_rhythm_cluster;
        [Widget] Gtk.Frame frame_rhythm;
        [Widget] Gtk.CheckButton check_rhythm_use_clusters;
+       [Widget] Gtk.SpinButton spin_rhythm_rep;
        [Widget] Gtk.SpinButton spin_rhythm_ecc;
        [Widget] Gtk.SpinButton spin_rhythm_con;
        [Widget] Gtk.SpinButton spin_rhythm_rest_reps;
@@ -581,6 +584,14 @@ public class RepetitiveConditionsWindow
                frame_rhythm.Visible = check_rhythm_active.Active;
        }
 
+       private void on_radio_rhythm_together_toggled (object o, EventArgs args)
+       {
+               if(radio_rhythm_together.Active)
+                       notebook_duration_repetition.CurrentPage = 0;
+               else
+                       notebook_duration_repetition.CurrentPage = 1;
+       }
+
        private void on_check_rhythm_use_clusters_toggled (object o, EventArgs args)
        {
                vbox_rhythm_cluster.Visible = check_rhythm_use_clusters.Active;
@@ -600,6 +611,8 @@ public class RepetitiveConditionsWindow
        private void encoder_rhythm_set_values(EncoderRhythm encoderRhythm)
        {
                check_rhythm_active.Active = encoderRhythm.Active;
+               radio_rhythm_together.Active = encoderRhythm.RepsOrPhases;
+               spin_rhythm_rep.Value = encoderRhythm.RepSeconds;
                spin_rhythm_ecc.Value = encoderRhythm.EccSeconds;
                spin_rhythm_con.Value = encoderRhythm.ConSeconds;
                spin_rhythm_rest_reps.Value = encoderRhythm.RestRepsSeconds;
@@ -608,6 +621,11 @@ public class RepetitiveConditionsWindow
 
                frame_rhythm.Visible = check_rhythm_active.Active;
 
+               if(encoderRhythm.RepsOrPhases)
+                       notebook_duration_repetition.CurrentPage = 0;
+               else
+                       notebook_duration_repetition.CurrentPage = 1;
+
                if(encoderRhythm.UseClusters()) {
                        check_rhythm_use_clusters.Active = true;
                        vbox_rhythm_cluster.Visible = true;
@@ -624,8 +642,9 @@ public class RepetitiveConditionsWindow
                        reps_cluster = 1;
 
                return new EncoderRhythm(
-                               check_rhythm_active.Active,
-                               spin_rhythm_ecc.Value, spin_rhythm_con.Value, spin_rhythm_rest_reps.Value,
+                               check_rhythm_active.Active, radio_rhythm_together.Active,
+                               spin_rhythm_rep.Value, spin_rhythm_ecc.Value, spin_rhythm_con.Value,
+                               spin_rhythm_rest_reps.Value,
                                reps_cluster, spin_rhythm_rest_clusters.Value);
        }
 
diff --git a/src/preferences.cs b/src/preferences.cs
index 6e1cdf2..c489261 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -99,6 +99,8 @@ public class Preferences
 
        //encoder rhythm
        public bool encoderRhythmActive;
+       public bool encoderRhythmRepsOrPhases;
+       public double encoderRhythmRepSeconds;
        public double encoderRhythmEccSeconds;
        public double encoderRhythmConSeconds;
        public double encoderRhythmRestRepsSeconds;
@@ -165,47 +167,77 @@ public class Preferences
 
        public void UpdateEncoderRhythm(EncoderRhythm er)
        {
+               if(
+                               encoderRhythmActive != er.Active ||
+                               encoderRhythmRepsOrPhases != er.RepsOrPhases ||
+                               encoderRhythmRepSeconds != er.RepSeconds ||
+                               encoderRhythmEccSeconds != er.EccSeconds ||
+                               encoderRhythmConSeconds != er.ConSeconds ||
+                               encoderRhythmRestRepsSeconds != er.RestRepsSeconds ||
+                               encoderRhythmRepsCluster != er.RepsCluster ||
+                               encoderRhythmRestClustersSeconds != er.RestClustersSeconds
+                               )
+                       Sqlite.Open();
+               else
+                       return;
+
                if(encoderRhythmActive != er.Active)
                {
                        encoderRhythmActive = er.Active;
                        SqlitePreferences.Update(SqlitePreferences.EncoderRhythmActiveStr,
-                                       er.Active.ToString(), false); //bool
+                                       er.Active.ToString(), true); //bool
+               }
+
+               if(encoderRhythmRepsOrPhases != er.RepsOrPhases)
+               {
+                       encoderRhythmRepsOrPhases = er.RepsOrPhases;
+                       SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRepsOrPhasesStr,
+                                       er.RepsOrPhases.ToString(), true); //bool
+               }
+
+               if(encoderRhythmRepSeconds != er.RepSeconds)
+               {
+                       encoderRhythmRepSeconds = er.RepSeconds;
+                       SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRepSecondsStr,
+                                       Util.ConvertToPoint(er.RepSeconds), true); //double to point
                }
 
                if(encoderRhythmEccSeconds != er.EccSeconds)
                {
                        encoderRhythmEccSeconds = er.EccSeconds;
                        SqlitePreferences.Update(SqlitePreferences.EncoderRhythmEccSecondsStr,
-                                       Util.ConvertToPoint(er.EccSeconds), false); //double to point
+                                       Util.ConvertToPoint(er.EccSeconds), true); //double to point
                }
 
                if(encoderRhythmConSeconds != er.ConSeconds)
                {
                        encoderRhythmConSeconds = er.ConSeconds;
                        SqlitePreferences.Update(SqlitePreferences.EncoderRhythmConSecondsStr,
-                                       Util.ConvertToPoint(er.ConSeconds), false); //double to point
+                                       Util.ConvertToPoint(er.ConSeconds), true); //double to point
                }
 
                if(encoderRhythmRestRepsSeconds != er.RestRepsSeconds)
                {
                        encoderRhythmRestRepsSeconds = er.RestRepsSeconds;
                        SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRestRepsSecondsStr,
-                                       Util.ConvertToPoint(er.RestRepsSeconds), false); //double to point
+                                       Util.ConvertToPoint(er.RestRepsSeconds), true); //double to point
                }
 
                if(encoderRhythmRepsCluster != er.RepsCluster)
                {
                        encoderRhythmRepsCluster = er.RepsCluster;
                        SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRepsClusterStr,
-                                       er.RepsCluster.ToString(), false); //int
+                                       er.RepsCluster.ToString(), true); //int
                }
 
                if(encoderRhythmRestClustersSeconds != er.RestClustersSeconds)
                {
                        encoderRhythmRestClustersSeconds = er.RestClustersSeconds;
                        SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRestClustersSecondsStr,
-                                       Util.ConvertToPoint(er.RestClustersSeconds), false); //double to point
+                                       Util.ConvertToPoint(er.RestClustersSeconds), true); //double to point
                }
+
+               Sqlite.Close();
        }
 
        //force sensor
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 421acc3..4f1d5a0 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -125,7 +125,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "1.53";
+       static string lastChronojumpDatabaseVersion = "1.54";
 
        public Sqlite() {
        }
@@ -2310,7 +2310,17 @@ class Sqlite
 
                                currentVersion = updateVersion("1.53");
                        }
+                       if(currentVersion == "1.53")
+                       {
+                               LogB.SQL("Added encoderRhythm variables: repsOrPhases, repSeconds");
+
+                               EncoderRhythm er = new EncoderRhythm();
+                               SqlitePreferences.Insert (SqlitePreferences.EncoderRhythmRepsOrPhasesStr, 
er.RepsOrPhases.ToString());
+                               SqlitePreferences.Insert (SqlitePreferences.EncoderRhythmRepSecondsStr,
+                                               Util.ConvertToPoint(er.RepSeconds));
 
+                               currentVersion = updateVersion("1.54");
+                       }
 
 
 
@@ -2494,6 +2504,7 @@ class Sqlite
                SqlitePreferences.initializeTable(lastChronojumpDatabaseVersion, creatingBlankDatabase);
 
                //changes [from - to - desc]
+               //1.53 - 1.54 Converted DB to 1.54 Added encoderRhythm variables: repOrPhases, repSeconds
                //1.52 - 1.53 Converted DB to 1.53 Added encoderRhtyhm active variable
                //1.51 - 1.52 Converted DB to 1.52 Added encoderRhtyhm stuff
                //1.50 - 1.51 Converted DB to 1.51 Updated encoderCaptureCutByTriggers variable
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index c4ea83f..67ad5f0 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -43,6 +43,8 @@ class SqlitePreferences : Sqlite
        public const string ForceSensorCalibrationFactorStr = "forceSensorCalibrationFactor";
 
        public const string EncoderRhythmActiveStr = "encoderRhythmActive";
+       public const string EncoderRhythmRepsOrPhasesStr = "encoderRhythmRepsOrPhases";
+       public const string EncoderRhythmRepSecondsStr = "encoderRhythmRepSeconds";
        public const string EncoderRhythmEccSecondsStr = "encoderRhythmEccSeconds";
        public const string EncoderRhythmConSecondsStr = "encoderRhythmConSeconds";
        public const string EncoderRhythmRestRepsSecondsStr = "encoderRhythmRestRepsSeconds";
@@ -155,6 +157,8 @@ class SqlitePreferences : Sqlite
                                //encoderRhythm
                                EncoderRhythm er = new EncoderRhythm();
                                Insert (EncoderRhythmActiveStr, er.Active.ToString(), dbcmdTr);
+                               Insert (EncoderRhythmRepsOrPhasesStr, er.RepsOrPhases.ToString(), dbcmdTr);
+                               Insert (EncoderRhythmRepSecondsStr, Util.ConvertToPoint(er.RepSeconds), 
dbcmdTr);
                                Insert (EncoderRhythmEccSecondsStr, Util.ConvertToPoint(er.EccSeconds), 
dbcmdTr);
                                Insert (EncoderRhythmConSecondsStr, Util.ConvertToPoint(er.ConSeconds), 
dbcmdTr);
                                Insert (EncoderRhythmRestRepsSecondsStr, 
Util.ConvertToPoint(er.RestRepsSeconds), dbcmdTr);
@@ -332,6 +336,11 @@ class SqlitePreferences : Sqlite
                        //encoder rhythm
                        else if(reader[0].ToString() == EncoderRhythmActiveStr)
                                preferences.encoderRhythmActive = reader[1].ToString() == "True"; //bool
+                       else if(reader[0].ToString() == EncoderRhythmRepsOrPhasesStr)
+                               preferences.encoderRhythmRepsOrPhases = reader[1].ToString() == "True"; //bool
+                       else if(reader[0].ToString() == EncoderRhythmRepSecondsStr)
+                               preferences.encoderRhythmRepSeconds = Convert.ToDouble(
+                                               Util.ChangeDecimalSeparator(reader[1].ToString()));
                        else if(reader[0].ToString() == EncoderRhythmEccSecondsStr)
                                preferences.encoderRhythmEccSeconds = Convert.ToDouble(
                                                Util.ChangeDecimalSeparator(reader[1].ToString()));



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