Exemplo n.º 1
0
        private static TempoMap GenerateComplexTempoMap()
        {
            // 4/4                                     5/8            5/16                          5/8
            //  |----+----+----+----|----+----+----+----|--+--+--+--+--|-+-+-+-+-|-+-+-+-+-|-+-+-+-+-|--+--+--+--+--|
            //  0                   1                   2              3         4         5         6              7

            var steps = new[]
            {
                Tuple.Create(2 * MusicalTimeSpan.Whole, new TimeSignature(5, 8)),
                Tuple.Create(5 * MusicalTimeSpan.Eighth, new TimeSignature(5, 16)),
                Tuple.Create(15 * MusicalTimeSpan.Sixteenth, new TimeSignature(5, 8)),
            };

            using (var tempoMapManager = new TempoMapManager(new TicksPerQuarterNoteTimeDivision(TicksPerQuarterNote)))
            {
                var time = new MusicalTimeSpan();

                foreach (var step in steps)
                {
                    time += step.Item1;
                    tempoMapManager.SetTimeSignature(time, step.Item2);
                }

                tempoMapManager.SetTempo(new MetricTimeSpan(0, 0, 10), Tempo.FromMillisecondsPerQuarterNote(300));
                tempoMapManager.SetTempo(new MetricTimeSpan(0, 1, 30), Tempo.FromMillisecondsPerQuarterNote(600));
                tempoMapManager.SetTempo(new MetricTimeSpan(0, 1, 31), Tempo.FromMillisecondsPerQuarterNote(640));

                return(tempoMapManager.TempoMap);
            }
        }
Exemplo n.º 2
0
        private long GetTempo(MidiFile midiFile)
        {
            TempoMap tempoMap = midiFile.GetTempoMap();
            long     ticks    = 123;

            BarBeatTimeSpan barBeatTimeSpan = TimeConverter.ConvertTo <BarBeatTimeSpan>(ticks, tempoMap);
            MusicalTimeSpan musicalTimeSpan = TimeConverter.ConvertTo <MusicalTimeSpan>(ticks, tempoMap);

            return(barBeatTimeSpan.Bars);
        }
Exemplo n.º 3
0
        private static void Quantize(MidiFile midiFile, MusicalTimeSpan step)
        {
            var tempoMap  = midiFile.GetTempoMap();
            var stepTicks = LengthConverter.ConvertFrom(step, 0, tempoMap);

            midiFile.ProcessNotes(n =>
            {
                var time = n.Time;
                n.Time   = (long)Math.Round(time / (double)stepTicks) * stepTicks;
            });
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
 private static MidiTimeSpan GetDefaultMidiTimeSpan(MusicalTimeSpan timeSpan)
 {
     return(new MidiTimeSpan(4 * TimeSpanTestUtilities.TicksPerQuarterNote * timeSpan.Numerator / timeSpan.Denominator));
 }
Exemplo n.º 6
0
 private static void CheckTimeSpan(MusicalTimeSpan timeSpan, long numerator, long denominator)
 {
     Assert.AreEqual(numerator, timeSpan.Numerator, "Numerator is invalid.");
     Assert.AreEqual(denominator, timeSpan.Denominator, "Denominator is invalid.");
 }
Exemplo n.º 7
0
 private static void CheckChangeDenominator(MusicalTimeSpan timeSpan, long denominator, long numerator)
 {
     CheckTimeSpan(timeSpan.ChangeDenominator(denominator), numerator, denominator);
 }