Пример #1
0
 public void AdvanceTime(IDuration duration)
 {
     lock (_lck)
     {
         currentTime = currentTime.AddDuration(duration);
     }
 }
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     this.Duration         = new Duration(this);
     this.BaseUri          = new Uri("https://localhost");
     SerializationSettings = new JsonSerializerSettings
     {
         Formatting            = Formatting.Indented,
         DateFormatHandling    = DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = DateTimeZoneHandling.Utc,
         NullValueHandling     = NullValueHandling.Ignore,
         ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = DateTimeZoneHandling.Utc,
         NullValueHandling     = NullValueHandling.Ignore,
         ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
 }
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Duration = new Duration(this);
     BaseUri  = new System.Uri("http://localhost:3000");
     SerializationSettings = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new  List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
 }
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     this.Duration         = new Duration(this);
     this.BaseUri          = new System.Uri("https://localhost");
     SerializationSettings = new Newtonsoft.Json.JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new Microsoft.Rest.Serialization.ReadOnlyJsonContractResolver(),
         Converters            = new  System.Collections.Generic.List <Newtonsoft.Json.JsonConverter>
         {
             new Microsoft.Rest.Serialization.Iso8601TimeSpanConverter()
         }
     };
     DeserializationSettings = new Newtonsoft.Json.JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new Microsoft.Rest.Serialization.ReadOnlyJsonContractResolver(),
         Converters            = new System.Collections.Generic.List <Newtonsoft.Json.JsonConverter>
         {
             new Microsoft.Rest.Serialization.Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
 }
Пример #5
0
        public override void SetValue(IDuration d)
        {
            duration_ = d as RampDuration;

            if (duration_ == null)
            {
                timeUp_.Value       = 0;
                timeDown_.Value     = 0;
                min_.Value          = 0;
                max_.Value          = 0;
                hold_.Value         = 0;
                rampUp_.Value       = false;
                rampDown_.Value     = false;
                rampUp_.Parameter   = null;
                rampDown_.Parameter = null;
            }
            else
            {
                timeUp_.Parameter   = duration_.TimeUpParameter;
                timeDown_.Parameter = duration_.TimeDownParameter;
                min_.Parameter      = duration_.MinimumParameter;
                max_.Parameter      = duration_.MaximumParameter;
                hold_.Parameter     = duration_.HoldParameter;
                rampUp_.Parameter   = duration_.RampUpParameter;
                rampDown_.Parameter = duration_.RampDownParameter;
            }

            easing_.Value = duration_.Easing;
        }
Пример #6
0
 /// <summary>
 /// Get a positive duration value
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <System.TimeSpan?> GetPositiveDurationAsync(this IDuration operations, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetPositiveDurationWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #7
0
        public override List <IWidget> GetWidgets(IDuration d)
        {
            return(new List <IWidget>()
            {
                start_,
                end_,
                timeUp_,
                timeDown_,
                hold_,

                firstHalfProgress_,
                secondHalfProgress_,
                inFirstHalf_,
                totalProgress_,
                inFirstHalfTotal_,
                firstHalfFinished_,
                finished_,
                timeRemaining_,
                timeRemainingInHalf_,

                current_,
                elapsed_,
                totalElapsed_,
                progress_,

                holdingProgress_,
                holdingElapsed_
            });
        }
Пример #8
0
 private void HalfwayDelayTypeChanged(IDuration d)
 {
     if (currentDelay_ != null)
     {
         currentDelay_.HalfwayDuration = d;
         Synergy.Instance.UI.NeedsReset("halfway delay type changed");
     }
 }
Пример #9
0
 private void DurationTypeChanged(IDuration d)
 {
     if (currentStep_ != null)
     {
         currentStep_.Duration = d;
         Synergy.Instance.UI.NeedsReset("step duration type changed");
     }
 }
Пример #10
0
 private void EndBackwardsDelayTypeChanged(IDuration d)
 {
     if (currentDelay_ != null)
     {
         currentDelay_.EndBackwardsDuration = d;
         Synergy.Instance.UI.NeedsReset("end backwards delay type changed");
     }
 }
Пример #11
0
 private void DelayTypeChanged(IDuration d)
 {
     if (modifier_ != null)
     {
         modifier_.Delay = d;
         Synergy.Instance.UI.NeedsReset("audio delay type changed");
     }
 }
Пример #12
0
 private void SingleDelayTypeChanged(IDuration d)
 {
     if (currentDelay_ != null)
     {
         currentDelay_.SingleDuration = d;
         Synergy.Instance.UI.NeedsReset("single delay type changed");
     }
 }
Пример #13
0
 /// <summary>
 /// Constructs a bar instance based on the given <paramref name="timeSignature"/>,
 /// <paramref name="chords"/> and <paramref name="notes"/>.
 /// </summary>
 /// <param name="timeSignature">Time signature of this bar.</param>
 /// <param name="chords"> Chord progression harmony for this bar.</param>
 /// <param name="notes"> Melody notes for this bar. </param>
 public Bar(IDuration timeSignature, IList <IChord> chords, IList <INote> notes)
 {
     this.TimeSignature  = timeSignature;
     this._beatsPerBar   = TimeSignature.Numerator;
     this._beatsDuration = TimeSignature.Denominator;
     this.Chords         = chords;
     this.Notes          = notes;
 }
Пример #14
0
        public static void DurationExpire(this IDuration obj, Effect effect)
        {
            obj.Duration--;

            if (obj.Duration <= 0)
            {
                effect.Remove();
            }
        }
Пример #15
0
        /// <summary>
        /// Simplifies the fraction of the duration by reducing the numerator
        /// and denominator by their greatest common divisor.
        /// For example, 6/8 would be reduced to 3/4.
        /// </summary>
        internal static IDuration ReduceFractionToLowestTerms(this IDuration duration)
        {
            byte gcd = (byte)Duration.GreatestCommonDivisor(duration.Numerator, duration.Denominator);

            duration.Numerator   /= gcd;
            duration.Denominator /= gcd;

            return(duration);
        }
Пример #16
0
        private void DurationTypeChanged(IDuration d)
        {
            if (unsynced_ == null)
            {
                return;
            }

            unsynced_.Duration = d;
            Synergy.Instance.UI.NeedsReset("modifier sync duration changed");
        }
Пример #17
0
        private void DurationTypeChanged(IDuration d)
        {
            if (progression_ == null)
            {
                return;
            }

            progression_.Duration = d;
            Synergy.Instance.UI.NeedsReset("morph natpro duration changed");
        }
Пример #18
0
        public int CompareTo(IDuration other)
        {
            int cmp = (Seconds < other.Seconds) ? -1 : ((Seconds > other.Seconds) ? 1 : 0);

            if (cmp != 0)
            {
                return(cmp);
            }
            return((Nanos < other.Nanos) ? -1 : ((Nanos > other.Nanos) ? 1 : 0));
        }
Пример #19
0
        public override void AddToUI(IDuration d)
        {
            duration_ = d as RampDuration;
            if (duration_ == null)
            {
                return;
            }

            foreach (var w in GetWidgets(d))
            {
                widgets_.AddToUI(w);
            }
        }
Пример #20
0
 private IDurationUI CreateDurationUI(IDuration d)
 {
     if (d is RandomDuration)
     {
         return(new RandomDurationUI(name_, flags_));
     }
     else if (d is RampDuration)
     {
         return(new RampDurationUI(name_, flags_));
     }
     else
     {
         return(null);
     }
 }
Пример #21
0
        public static TimeSpan CombinedDuration(List <MyFile> fileList)
        {
            TimeSpan combinedDuration = new TimeSpan();

            foreach (var file in fileList)
            {
                IDuration duration = file as IDuration;

                if (duration != null)
                {
                    combinedDuration += duration.Duration;
                }
            }
            return(combinedDuration);
        }
Пример #22
0
 public static IDurationMonitor CreateDurationMonitor(
     string name, IDuration d, int flags = 0)
 {
     if (d is RandomDuration)
     {
         return(new RandomDurationMonitor(name, flags));
     }
     else if (d is RampDuration)
     {
         return(new RampDurationMonitor(name, flags));
     }
     else
     {
         return(null);
     }
 }
Пример #23
0
        public Delay(IDuration d, bool halfway, bool endForwards)
        {
            if (d == null)
            {
                HalfwayDuration = new RandomDuration();
            }
            else
            {
                HalfwayDuration = d;
            }

            EndForwardsDuration  = new RandomDuration();
            EndBackwardsDuration = new RandomDuration();
            halfway_.Value       = halfway;
            endForwards_.Value   = endForwards;
        }
Пример #24
0
        public static DateTime Add(this DateTime dt, IDuration duration)
        {
            if (duration is FixedDuration)
            {
                return(dt.Add((duration as FixedDuration).TimeSpan));
            }
            else if (duration is MonthDuration)
            {
                return(dt.AddMonths((duration as MonthDuration).Count));
            }
            else if (duration is YearDuration)
            {
                return(dt.AddYears((duration as YearDuration).Count));
            }

            throw new ArgumentOutOfRangeException();
        }
Пример #25
0
        public void SetValue(IDuration d)
        {
            durationType_.Value = d;

            if (d != null)
            {
                if (durationUI_ == null ||
                    durationUI_.DurationType != d.GetFactoryTypeName())
                {
                    durationUI_ = CreateDurationUI(d);
                }
            }

            if (durationUI_ != null)
            {
                durationUI_.SetValue(d);
            }
        }
Пример #26
0
        public bool FromJSON(J.Node n)
        {
            Clear();

            var o = n.AsObject("Step");

            if (o == null)
            {
                return(false);
            }

            o.Opt("enabled", enabled_);
            o.Opt("paused", ref paused_);
            o.Opt("name", ref name_);
            o.Opt("halfMove", halfMove_);
            o.Opt("modifiers", ref modifiers_);

            {
                IDuration d = null;
                o.Opt <DurationFactory, IDuration>("duration", ref d);
                Duration = d;
            }

            {
                RandomizableTime t = null;
                o.Opt("repeat", ref t);
                Repeat = t;
            }

            {
                Delay d = null;
                o.Opt("delay", ref d);
                Delay = d;
            }

            foreach (var m in modifiers_)
            {
                m.ParentStep = this;
            }

            return(true);
        }
Пример #27
0
        public UnsyncedModifier(IDuration d, Delay delay = null)
        {
            if (d == null)
            {
                Duration = new RandomDuration(1);
            }
            else
            {
                Duration = d;
            }

            if (delay == null)
            {
                Delay = new Delay();
            }
            else
            {
                Delay = delay;
            }
        }
Пример #28
0
        public List <IWidget> GetWidgets(IDuration d)
        {
            duration_ = d;

            if (duration_ != null)
            {
                if (ui_ == null || ui_.DurationType != d.GetFactoryTypeName())
                {
                    ui_ = MonitorUI.CreateDurationMonitor(
                        name_, duration_, flags_);
                }
            }

            if (ui_ == null)
            {
                return(new List <IWidget>());
            }

            return(ui_.GetWidgets(d));
        }
Пример #29
0
        /// <summary>
        /// Calculates durations that are the result of adding and/or subtracting
        /// length of existing durations.
        /// </summary>
        /// <param name="operation"> The requested arithmetic operaton (add, subtract). </param>
        /// <param name="duration1"> The first duration operand. </param>
        /// <param name="duration2"> The second duration operand. </param>
        /// <returns> The result duration of the operation (sum or difference). </returns>
        internal static IDuration DurationArithmetic(ArithmeticOperation operation, IDuration duration1, IDuration duration2)
        {
            MusicalTimeSpan timeSpan1   = new MusicalTimeSpan(duration1.Numerator, duration1.Denominator, true);
            MusicalTimeSpan timeSpan2   = new MusicalTimeSpan(duration2.Numerator, duration2.Denominator, true);
            MusicalTimeSpan newTimeSpan = null;

            switch (operation)
            {
            case ArithmeticOperation.Add:
                newTimeSpan = timeSpan1.Add(timeSpan2, TimeSpanMode.LengthLength) as MusicalTimeSpan;
                break;

            case ArithmeticOperation.Subtract:
                newTimeSpan = timeSpan1.Subtract(timeSpan2, TimeSpanMode.LengthLength) as MusicalTimeSpan;
                break;

            default:
                throw new NotSupportedException($"{nameof(operation)} is currently unsupported");
            }
            return(MusicTheoryFactory.CreateDuration((byte)newTimeSpan?.Numerator, (byte)newTimeSpan?.Denominator));
        }
Пример #30
0
        /// <summary>
        /// Checks that bar structure of the musical peace is compatible between it's description in the
        /// MIDI file and it's description in the chord progression read from the chords file.
        /// </summary>
        /// <param name="chordProgression"> Bar sequence which contains the chord progressionn from chords file. </param>
        /// <param name="midiFile"> MIDI file instance containning the bars music peace description. </param>
        /// <param name="errorMessage"> Returned error message in case the bars are not compatible. </param>
        /// <returns></returns>
        public static bool AreBarsCompatible(IList <IBar> chordProgression, IMidiFile midiFile, out string errorMessage)
        {
            // validate that total num of bars in MIDI matches num of bars in chord progression
            if (chordProgression?.Count != midiFile?.NumberOfBars)
            {
                errorMessage = $"Error: Number of bars mismatch: \n" +
                               $"chord file has {chordProgression?.Count} bars," +
                               $" while midi file has {midiFile?.NumberOfBars}!";
                return(false);
            }

            // validate that each bar duration from CHORD progression matches the duration in MIDI
            IDuration midiDuration   = null;
            byte      barNumerator   = 0;
            byte      barDenominator = 0;

            for (int barIndex = 0; barIndex < chordProgression.Count; barIndex++)
            {
                // get bar's duration from chord progression
                barNumerator   = chordProgression[barIndex].TimeSignature.Numerator;
                barDenominator = chordProgression[barIndex].TimeSignature.Denominator;

                // get bar's duration from midi file
                midiDuration = midiFile.GetBarDuration(barIndex);

                // validate equality
                if (barNumerator != midiDuration.Numerator || barDenominator != midiDuration.Denominator)
                {
                    errorMessage = $"Error: Time signature '{barNumerator}/{barDenominator}' " +
                                   $"of bar number {barIndex + 1} in the chord progression " +
                                   $"does not match the corresponding time signature " +
                                   $"'{midiDuration.Numerator}/{midiDuration.Denominator}' " +
                                   $"in the midi file.";
                }
            }

            errorMessage = null;
            return(true);
        }
 private static SimpleTimeInterval NewTimeInterval(ITimePoint startingPoint, IDuration duration)
 {
     return new SimpleTimeInterval(startingPoint, duration);
 }
 public SimpleTimeInterval(ITimePoint timeCoordinate, IDuration duration)
 {
     TimePosition = timeCoordinate;
     TimeSpanValue = duration.AsTimeSpan();
 }
 /// <summary>Creates an instance at the specified <paramref name="position"/> and <paramref name="time"/></summary>
 public SimplePlaneTimeInterval(IPlanePoint position, IDuration time) : base(position)
 {
     Duration = time;
 }