[chronojump] EncoderRhythm as object
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] EncoderRhythm as object
- Date: Thu, 18 Jan 2018 12:07:16 +0000 (UTC)
commit 7bab3020578a00a86379075584cf8f0ec5be75d7
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Jan 18 13:06:18 2018 +0100
EncoderRhythm as object
src/encoder.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/gui/encoder.cs | 41 +++++++----------------------------------
2 files changed, 58 insertions(+), 34 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index 7a5c196..81ab836 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -2101,3 +2101,54 @@ public class Rx1y2
y2 = Convert.ToDouble(Util.ChangeDecimalSeparator(sFull[3]));
}
}
+
+public class EncoderRhythm
+{
+ private DateTime lastRepetitionDT;
+
+ //constructor
+ public EncoderRhythm()
+ {
+ lastRepetitionDT = DateTime.MinValue;
+ }
+
+ public bool FirstRepetitionDone()
+ {
+ return (lastRepetitionDT > DateTime.MinValue);
+ }
+
+ public void SetLastRepetitionDT()
+ {
+ lastRepetitionDT = DateTime.Now;
+ }
+
+ 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)
+ {
+ //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);
+ }
+ 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;
+ }
+ return fraction;
+ }
+}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index e718bcd..b4c3691 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -328,7 +328,7 @@ public partial class ChronoJumpWindow
private static bool encoderProcessFinish;
private static bool encoderProcessFinishContMode;
- private static DateTime lastRepetitionDT;
+ private static EncoderRhythm encoderRhythm;
EncoderConfigurationWindow encoder_configuration_win;
@@ -5308,7 +5308,7 @@ public partial class ChronoJumpWindow
encoderRProcCapture.CutByTriggers = reallyCutByTriggers;
//initialize DateTime for rhythm
- lastRepetitionDT = DateTime.MinValue;
+ encoderRhythm = new EncoderRhythm();
image_encoder_rhythm.Visible = false;
encoderThread = new Thread(new ThreadStart(encoderDoCaptureCsharp));
@@ -5788,7 +5788,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)
- lastRepetitionDT = DateTime.Now;
+ encoderRhythm.SetLastRepetitionDT();
image_encoder_rhythm.Visible = false;
//LogB.Error("HERE YES");
@@ -6014,11 +6014,9 @@ public partial class ChronoJumpWindow
}
}
- //TODO: create a class will all encoder rhythm stuff
private void updatePulsebarRhythm()
{
- //at first repetition don't show pulsebar rhythm (wait first repetition ended)
- if(lastRepetitionDT == DateTime.MinValue)
+ if(! encoderRhythm.FirstRepetitionDone())
{
encoder_pulsebar_rhythm.Fraction = 0;
encoder_pulsebar_rhythm.Visible = false;
@@ -6026,38 +6024,13 @@ public partial class ChronoJumpWindow
}
encoder_pulsebar_rhythm.Visible = true;
+ double fraction = encoderRhythm.GetFraction();
+ encoder_pulsebar_rhythm.Fraction = fraction;
- 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)
- {
- //totalSeconds == 0 graph will show 1
- //totalSeconds == 0.1 graph will show 0.8
- //totalSeconds == 0.4 graph will show 0.2
- encoder_pulsebar_rhythm.Fraction = 1 - (phase * 2);
- }
- 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;
- double fraction = phaseSup * 2;
- if(fraction > 1)
- fraction = 1;
- encoder_pulsebar_rhythm.Fraction = fraction;
- }
-
- if(totalSeconds >= 1)
+ if(fraction >= 1)
image_encoder_rhythm.Visible = true;
}
-
// -------------- drawingarea_encoder_analyze_instant
Pixbuf drawingarea_encoder_analyze_cairo_pixbuf;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]