Example #1
0
        public void SplitByGrid_MultipleSteps_AwayFromZero_Musical()
        {
            var tempoMap = TempoMap.Default;

            var obj1 = ObjectMethods.Create(new MusicalTimeSpan(), MusicalTimeSpan.Whole, tempoMap);
            var obj2 = ObjectMethods.Create(new MusicalTimeSpan(5, 8), 10 * MusicalTimeSpan.Eighth, tempoMap);

            SplitByGrid_MultipleSteps(
                inputObjects: new[] { obj1, obj2 },
                gridStart: MusicalTimeSpan.Half,
                gridSteps: new[]
            {
                MusicalTimeSpan.Eighth,
                MusicalTimeSpan.Whole
            },
                expectedParts: new Dictionary <TObject, IEnumerable <TimeAndLength> >
            {
                [obj1] = new[]
                {
                    new TimeAndLength(new MusicalTimeSpan(), MusicalTimeSpan.Half),
                    new TimeAndLength(MusicalTimeSpan.Half, MusicalTimeSpan.Eighth),
                    new TimeAndLength(MusicalTimeSpan.Half + MusicalTimeSpan.Eighth, 3 * MusicalTimeSpan.Eighth)
                },
                [obj2] = new[]
                {
                    new TimeAndLength(new MusicalTimeSpan(5, 8), MusicalTimeSpan.Whole),
                    new TimeAndLength(13 * MusicalTimeSpan.Eighth, MusicalTimeSpan.Eighth),
                    new TimeAndLength(14 * MusicalTimeSpan.Eighth, MusicalTimeSpan.Eighth)
                }
            },
                tempoMap: tempoMap);
        }
Example #2
0
        private void SplitByGrid_OneStep_SinglePart(ITimeSpan gridStart, ITimeSpan step, TempoMap tempoMap)
        {
            var gridSteps = new[] { step };

            var firstTime = TimeConverter.ConvertFrom(gridStart, tempoMap);

            long secondTime = firstTime;

            for (int i = 0; i < 5; i++)
            {
                secondTime += LengthConverter.ConvertFrom(step, secondTime, tempoMap);
            }

            var inputObjects = new[]
            {
                ObjectMethods.Create(firstTime, LengthConverter.ConvertFrom(step, firstTime, tempoMap)),
                ObjectMethods.Create(secondTime, LengthConverter.ConvertFrom(step, secondTime, tempoMap))
            };

            var data = SplitByGrid_ClonesExpected(inputObjects, gridStart, gridSteps, tempoMap);

            var stepType   = TimeSpanTypes[step.GetType()];
            var partLength = data.ActualObjects.First().LengthAs(stepType, tempoMap);

            Assert.IsTrue(data.ActualObjects.All(o => o.LengthAs(stepType, tempoMap).Equals(partLength)),
                          $"Objects have different length measured as {stepType}.");
        }
Example #3
0
        public void SplitByGrid_MultipleSteps_AwayFromZero_Metric()
        {
            //              0:0:1.500
            // │######║#################║########│
            // .      .                                0:0:2.250
            // .      .             │###║###########║#################║###########║#│
            // .      .             |   .        |  .                 .           . |
            // .      .         0:0:1.150    0:0:1.500                .         0:0:3.400
            // .      .             |   .        |  .                 .           . |
            // .      |=================|===========|=================|===========|=================|
            // .      |      0:0:1      | 0:0:0.350 |      0:0:1      | 0:0:0.350 |      0:0:1      |
            // |      |                 |           |                 |           |                 |
            // 0  0:0:0.300         0:0:1.300   0:0:1.650         0:0:2.650     0:0:3             0:0:4

            var tempoMap = TempoMap.Default;

            var obj1 = ObjectMethods.Create(new MetricTimeSpan(),
                                            new MetricTimeSpan(0, 0, 1, 500),
                                            tempoMap);
            var obj2 = ObjectMethods.Create(new MetricTimeSpan(0, 0, 1, 150),
                                            new MetricTimeSpan(0, 0, 2, 250),
                                            tempoMap);

            SplitByGrid_MultipleSteps(
                inputObjects: new[] { obj1, obj2 },
                gridStart: new MetricTimeSpan(0, 0, 0, 300),
                gridSteps: new[]
            {
                new MetricTimeSpan(0, 0, 1),
                new MetricTimeSpan(0, 0, 0, 350)
            },
                expectedParts: new Dictionary <TObject, IEnumerable <TimeAndLength> >
            {
                [obj1] = new[]
                {
                    new TimeAndLength(new MetricTimeSpan(), new MetricTimeSpan(0, 0, 0, 300)),
                    new TimeAndLength(new MetricTimeSpan(0, 0, 0, 300), new MetricTimeSpan(0, 0, 1)),
                    new TimeAndLength(new MetricTimeSpan(0, 0, 1, 300), new MetricTimeSpan(0, 0, 0, 200))
                },
                [obj2] = new[]
                {
                    new TimeAndLength(new MetricTimeSpan(0, 0, 1, 150), new MetricTimeSpan(0, 0, 0, 150)),
                    new TimeAndLength(new MetricTimeSpan(0, 0, 1, 300), new MetricTimeSpan(0, 0, 0, 350)),
                    new TimeAndLength(new MetricTimeSpan(0, 0, 1, 650), new MetricTimeSpan(0, 0, 1)),
                    new TimeAndLength(new MetricTimeSpan(0, 0, 2, 650), new MetricTimeSpan(0, 0, 0, 350)),
                    new TimeAndLength(new MetricTimeSpan(0, 0, 3), new MetricTimeSpan(0, 0, 0, 400))
                }
            },
                tempoMap: tempoMap);
        }
        public void Randomize_Start_Constant_SizeGreaterThanTime_Metric()
        {
            var tempoMap = TempoMap.Default;

            Randomize_Start(
                new[]
            {
                ObjectMethods.Create(new MetricTimeSpan(0, 1, 23), (MidiTimeSpan)1000, tempoMap),
                ObjectMethods.Create(0, 10000),
            },
                new ConstantBounds(new MetricTimeSpan(0, 2, 0)),
                new[]
            {
                new TimeBounds((MidiTimeSpan)0, new MetricTimeSpan(0, 3, 23)),
                new TimeBounds((MidiTimeSpan)0, new MetricTimeSpan(0, 2, 0))
            },
                tempoMap);
        }
        public void Randomize_Start_Constant_SizeGreaterThanTime_Midi()
        {
            var tempoMap = TempoMap.Default;

            Randomize_Start(
                new[]
            {
                ObjectMethods.Create(1000, 1000),
                ObjectMethods.Create(0, 10000),
            },
                new ConstantBounds((MidiTimeSpan)10000),
                new[]
            {
                new TimeBounds((MidiTimeSpan)0, (MidiTimeSpan)11000),
                new TimeBounds((MidiTimeSpan)0, (MidiTimeSpan)10000)
            },
                tempoMap);
        }
        public void Randomize_Start_Filter()
        {
            var tempoMap = TempoMap.Default;

            Randomize_Start(
                new[]
            {
                ObjectMethods.Create(1000, 1000),
                ObjectMethods.Create(0, 10000),
                ObjectMethods.Create(20, 30)
            },
                new ConstantBounds((MidiTimeSpan)10000),
                new[]
            {
                new TimeBounds((MidiTimeSpan)0, (MidiTimeSpan)11000),
                new TimeBounds((MidiTimeSpan)0, (MidiTimeSpan)10000),
                new TimeBounds((MidiTimeSpan)20, (MidiTimeSpan)20)
            },
                tempoMap,
                filter: o => o.Time != 20);
        }
Example #7
0
        public void SplitByGrid_MultipleSteps_AwayFromZero_Midi()
        {
            //        200
            // │####║#######║##│
            // .    .           240
            // .    .  │####║####║#######║#│
            // .    .  |    .  | .       . |
            // .    . 100   . 200.       .340
            // .    .  |    .  | .       . |
            // .    |=======|====|=======|====|
            // .    |  100  | 67 |  100  | 67 |
            // |    |       |    |       |    |
            // 0   50      150  217     317  384

            var obj1 = ObjectMethods.Create(0, 200);
            var obj2 = ObjectMethods.Create(100, 240);

            SplitByGrid_MultipleSteps(
                inputObjects: new[] { obj1, obj2 },
                gridStart: (MidiTimeSpan)50,
                gridSteps: new[] { (MidiTimeSpan)100, (MidiTimeSpan)67 },
                expectedParts: new Dictionary <TObject, IEnumerable <TimeAndLength> >
            {
                [obj1] = new[]
                {
                    new TimeAndLength((MidiTimeSpan)0, (MidiTimeSpan)50),
                    new TimeAndLength((MidiTimeSpan)50, (MidiTimeSpan)100),
                    new TimeAndLength((MidiTimeSpan)150, (MidiTimeSpan)50)
                },
                [obj2] = new[]
                {
                    new TimeAndLength((MidiTimeSpan)100, (MidiTimeSpan)50),
                    new TimeAndLength((MidiTimeSpan)150, (MidiTimeSpan)67),
                    new TimeAndLength((MidiTimeSpan)217, (MidiTimeSpan)100),
                    new TimeAndLength((MidiTimeSpan)317, (MidiTimeSpan)23)
                },
            },
                tempoMap: TempoMap.Default);
        }
Example #8
0
        public void SplitByGrid_MultipleSteps_FromZero_Midi()
        {
            //        200
            // │####### #### ##│
            // .                240
            // .       │####║#######║####║#│
            // .       .    .  |    .      |
            // .       .    . 200   .     340
            // .       .    .  |    .      |
            // |=======|====|=======|====|=======|
            // |  100  | 67 |  100  | 67 |  100  |
            // |       |    |       |    |       |
            // 0      100  167     267  334     434

            var obj1 = ObjectMethods.Create(0, 200);
            var obj2 = ObjectMethods.Create(100, 240);

            SplitByGrid_MultipleSteps(
                new[] { obj1, obj2 },
                (MidiTimeSpan)0,
                new[] { (MidiTimeSpan)100, (MidiTimeSpan)67 },
                new Dictionary <TObject, IEnumerable <TimeAndLength> >
            {
                [obj1] = new[]
                {
                    new TimeAndLength((MidiTimeSpan)0, (MidiTimeSpan)100),
                    new TimeAndLength((MidiTimeSpan)100, (MidiTimeSpan)67),
                    new TimeAndLength((MidiTimeSpan)167, (MidiTimeSpan)33)
                },
                [obj2] = new[]
                {
                    new TimeAndLength((MidiTimeSpan)100, (MidiTimeSpan)67),
                    new TimeAndLength((MidiTimeSpan)167, (MidiTimeSpan)100),
                    new TimeAndLength((MidiTimeSpan)267, (MidiTimeSpan)67),
                    new TimeAndLength((MidiTimeSpan)334, (MidiTimeSpan)6)
                }
            },
                TempoMap.Default);
        }
Example #9
0
        public void SplitByGrid_MultipleSteps_FromZero_Mixed()
        {
            var tempoMap = TempoMap.Default;

            var obj1 = ObjectMethods.Create(new MidiTimeSpan(), MusicalTimeSpan.Whole, tempoMap);
            var obj2 = ObjectMethods.Create(new MetricTimeSpan(0, 0, 0, 210), new BarBeatTicksTimeSpan(1, 1), tempoMap);

            var step1 = MusicalTimeSpan.ThirtySecond;
            var step2 = new MetricTimeSpan(0, 0, 1);

            SplitByGrid_MultipleSteps(
                inputObjects: new[] { obj1, obj2 },
                gridStart: (MidiTimeSpan)0,
                gridSteps: new ITimeSpan[] { step1, step2 },
                expectedParts: new Dictionary <TObject, IEnumerable <TimeAndLength> >
            {
                [obj1] = new[]
                {
                    new TimeAndLength(new MusicalTimeSpan(), step1),
                    new TimeAndLength(step1, step2),
                    new TimeAndLength(step1.Add(step2, TimeSpanMode.TimeLength), step1),
                    new TimeAndLength((2 * step1).Add(step2, TimeSpanMode.TimeLength),
                                      (MusicalTimeSpan.Whole - 2 * step1).Subtract(step2, TimeSpanMode.LengthLength))
                },
                [obj2] = new[]
                {
                    new TimeAndLength(new MetricTimeSpan(0, 0, 0, 210),
                                      step1.Add(step2, TimeSpanMode.TimeLength).Subtract(new MetricTimeSpan(0, 0, 0, 210), TimeSpanMode.LengthLength)),
                    new TimeAndLength(step1.Add(step2, TimeSpanMode.TimeLength), step1),
                    new TimeAndLength((2 * step1).Add(step2, TimeSpanMode.TimeLength), step2),
                    new TimeAndLength((2 * step1).Add(step2 + step2, TimeSpanMode.TimeLength), step1),
                    new TimeAndLength((3 * step1).Add(step2 + step2, TimeSpanMode.TimeLength),
                                      new MetricTimeSpan(0, 0, 0, 210).Add(new BarBeatTicksTimeSpan(1, 1), TimeSpanMode.TimeLength).Subtract((3 * step1).Add(step2 + step2, TimeSpanMode.TimeLength), TimeSpanMode.TimeTime)),
                }
            },
                tempoMap: tempoMap);
        }