[chronojump] Encoder: Substracted triggers (removed initial time), remove if < 0



commit 66f778ffd9a265309a7527fa3d8064cdfa574416
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Dec 12 12:18:21 2017 +0100

    Encoder: Substracted triggers (removed initial time), remove if < 0

 src/trigger.cs |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/trigger.cs b/src/trigger.cs
index 1f5b848..b309435 100644
--- a/src/trigger.cs
+++ b/src/trigger.cs
@@ -95,6 +95,10 @@ public class Trigger
                get { return ms; }
        }
 
+       public bool IsNegative {
+               get { return ms < 0; }
+       }
+
        public bool InOut {
                get { return inOut; }
        }
@@ -128,8 +132,15 @@ public class TriggerList
 
        public void Substract(int msToSubstract)
        {
-               foreach(Trigger trigger in l)
-                       trigger.Substract(msToSubstract);
+               //iterate negative to not fail enumeration if an element is substracted
+               for(int i = l.Count -1 ; i >= 0; i --)
+               {
+                       l[i].Substract(msToSubstract);
+
+                       //triggers cannot be negative
+                       if(l[i].IsNegative)
+                               l.RemoveAt(i);
+               }
        }
 
        //just to debug


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