コード例 #1
0
        public void Parse(string input, int expectedOctaveNumber)
        {
            var parsedOctave   = Octave.Parse(input);
            var expectedOctave = Octave.Get(expectedOctaveNumber);

            Assert.AreEqual(expectedOctave, parsedOctave, "Parsed octave is invalid.");
        }
コード例 #2
0
ファイル: PatternTests.cs プロジェクト: zivillian/drywetmidi
        public void Chord_Interval()
        {
            var defaultNoteLength = MusicalTimeSpan.Quarter;
            var defaultVelocity   = (SevenBitNumber)90;

            var pattern = new PatternBuilder()
                          .SetNoteLength(defaultNoteLength)
                          .SetVelocity(defaultVelocity)
                          .SetRootNote(DryWetMidi.MusicTheory.Note.Get(NoteName.CSharp, 5))

                          .Chord(new[] { Interval.Two, Interval.Five }, Octave.Get(2).A)
                          .Chord(new[] { Interval.Two, -Interval.Ten }, Octave.Get(2).B)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 2, null, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.B, 2, null, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.D, 3, null, defaultNoteLength, defaultVelocity),

                new NoteInfo(NoteName.B, 2, defaultNoteLength, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.CSharp, 3, defaultNoteLength, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.CSharp, 2, defaultNoteLength, defaultNoteLength, defaultVelocity),
            });
        }
コード例 #3
0
        public void ResolveRootNote()
        {
            var chord    = new Chord(NoteName.A, NoteName.ASharp, NoteName.D);
            var rootNote = chord.ResolveRootNote(Octave.Get(4));

            Assert.AreEqual(Notes.A4, rootNote, "Resolved root note is invalid.");
        }
コード例 #4
0
        public void Chord_DefaultOctave()
        {
            var defaultVelocity = (SevenBitNumber)90;
            var defaultOctave   = Octave.Get(2);

            var chordLength = MusicalTimeSpan.Sixteenth.Triplet();
            var chordTime1  = new MetricTimeSpan(0, 1, 12);
            var chordTime2  = chordTime1.Add(chordLength, TimeSpanMode.TimeLength);

            var pattern = new PatternBuilder()
                          .SetVelocity(defaultVelocity)
                          .SetOctave(defaultOctave)

                          .MoveToTime(chordTime1)
                          .Chord(new[]
            {
                NoteName.C,
                NoteName.G
            }, chordLength)
                          .Repeat()

                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.C, defaultOctave.Number, chordTime1, chordLength, defaultVelocity),
                new NoteInfo(NoteName.G, defaultOctave.Number, chordTime1, chordLength, defaultVelocity),
                new NoteInfo(NoteName.C, defaultOctave.Number, chordTime2, chordLength, defaultVelocity),
                new NoteInfo(NoteName.G, defaultOctave.Number, chordTime2, chordLength, defaultVelocity)
            });
        }
コード例 #5
0
        public void ResolveNotes()
        {
            var chord = new Chord(NoteName.A, NoteName.ASharp, NoteName.D);
            var notes = chord.ResolveNotes(Octave.Get(2));

            CollectionAssert.AreEqual(
                new[] { Notes.A2, Notes.ASharp2, Notes.D3 },
                notes,
                "Resolved notes are invalid.");
        }
コード例 #6
0
        public void SetOctave()
        {
            Assert.AreEqual(Octave.Middle, PatternBuilder.DefaultOctave, "Default octave is invalid.");

            var patternBuilder = new PatternBuilder();

            Assert.AreEqual(PatternBuilder.DefaultOctave, patternBuilder.Octave, "Invalid initial octave.");

            var octave = Octave.Get(6);

            patternBuilder.SetOctave(octave);
            Assert.AreEqual(octave, patternBuilder.Octave, "Invalid octave after change.");
        }
コード例 #7
0
        public void SetRootNote()
        {
            Assert.AreEqual(Octave.Middle.C, PatternBuilder.DefaultRootNote, "Default root note is invalid.");

            var patternBuilder = new PatternBuilder();

            Assert.AreEqual(PatternBuilder.DefaultRootNote, patternBuilder.RootNote, "Invalid initial root note.");

            var rootNote = Octave.Get(2).ASharp;

            patternBuilder.SetRootNote(rootNote);
            Assert.AreEqual(rootNote, patternBuilder.RootNote, "Invalid root note after change.");
        }
コード例 #8
0
        public void Chord_Chord_Octave_Length()
        {
            var pattern = new PatternBuilder()
                          .SetNoteLength(MusicalTimeSpan.Whole)
                          .SetOctave(Octave.Get(7))
                          .Chord(new DryWetMidi.MusicTheory.Chord(NoteName.A, NoteName.C), Octave.Get(2), MusicalTimeSpan.Eighth)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 2, null, MusicalTimeSpan.Eighth, PatternBuilder.DefaultVelocity),
                new NoteInfo(NoteName.C, 3, null, MusicalTimeSpan.Eighth, PatternBuilder.DefaultVelocity)
            });
        }
コード例 #9
0
        public void Chord_Chord_Octave_Velocity()
        {
            var pattern = new PatternBuilder()
                          .SetVelocity((SevenBitNumber)80)
                          .SetOctave(Octave.Get(5))
                          .Chord(new DryWetMidi.MusicTheory.Chord(NoteName.A, NoteName.C), Octave.Get(1), (SevenBitNumber)70)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 1, null, PatternBuilder.DefaultNoteLength, (SevenBitNumber)70),
                new NoteInfo(NoteName.C, 2, null, PatternBuilder.DefaultNoteLength, (SevenBitNumber)70)
            });
        }
コード例 #10
0
ファイル: PatternTests.cs プロジェクト: zivillian/drywetmidi
        public void MoveToFirstAnchor_Unkeyed_NoAnchors()
        {
            Assert.Throws <InvalidOperationException>(() =>
                                                      new PatternBuilder()
                                                      .MoveToTime(new MetricTimeSpan(0, 0, 10))
                                                      .StepForward(new MetricTimeSpan(0, 0, 11))
                                                      .MoveToTime(new MetricTimeSpan(0, 0, 30))
                                                      .StepBack(new MetricTimeSpan(0, 0, 5))
                                                      .MoveToFirstAnchor()

                                                      .Note(Octave.Get(0).A)

                                                      .Build());
        }
コード例 #11
0
ファイル: PatternTests.cs プロジェクト: zivillian/drywetmidi
        public void MoveToFirstAnchor_Keyed_NoKeyedAnchors()
        {
            Assert.Throws <ArgumentException>(() =>
                                              new PatternBuilder()
                                              .MoveToTime(new MetricTimeSpan(0, 0, 10))
                                              .StepForward(new MetricTimeSpan(0, 0, 11))
                                              .MoveToTime(new MetricTimeSpan(0, 0, 30))
                                              .Anchor()
                                              .StepBack(new MetricTimeSpan(0, 0, 5))
                                              .MoveToFirstAnchor("Test")

                                              .Note(Octave.Get(0).A)

                                              .Build());
        }
コード例 #12
0
        public void Chord_Chord_Octave_Length_Velocity()
        {
            var pattern = new PatternBuilder()
                          .SetVelocity((SevenBitNumber)80)
                          .SetOctave(Octave.Get(8))
                          .SetNoteLength(MusicalTimeSpan.ThirtySecond)
                          .Chord(new DryWetMidi.MusicTheory.Chord(NoteName.A, NoteName.C), Octave.Get(1), MusicalTimeSpan.Half, (SevenBitNumber)70)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 1, null, MusicalTimeSpan.Half, (SevenBitNumber)70),
                new NoteInfo(NoteName.C, 2, null, MusicalTimeSpan.Half, (SevenBitNumber)70)
            });
        }
コード例 #13
0
ファイル: PatternTests.cs プロジェクト: zivillian/drywetmidi
        public void StepBack_Musical()
        {
            var pattern = new PatternBuilder()
                          .MoveToTime(MusicalTimeSpan.Eighth)
                          .StepForward(MusicalTimeSpan.Whole)
                          .StepBack(MusicalTimeSpan.Half)

                          .Note(Octave.Get(0).A)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, new MusicalTimeSpan(5, 8), MusicalTimeSpan.Quarter)
            });
        }
コード例 #14
0
ファイル: PatternTests.cs プロジェクト: zivillian/drywetmidi
        public void StepBack_Musical_BeyondZero()
        {
            var pattern = new PatternBuilder()
                          .MoveToTime(new MetricTimeSpan(0, 0, 10))
                          .StepForward(new MetricTimeSpan(0, 0, 30))
                          .StepBack(1000 * MusicalTimeSpan.Quarter)

                          .Note(Octave.Get(0).A)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, new MetricTimeSpan(0, 0, 0), MusicalTimeSpan.Quarter)
            });
        }
コード例 #15
0
        public void GetDescendingNotes_NotFromTonic()
        {
            var scale       = GetCMajorScale();
            var actualNotes = scale.GetDescendingNotes(Octave.Get(3).E).Take(7);

            CollectionAssert.AreEqual(new[]
            {
                Octave.Get(3).E,
                Octave.Get(3).D,
                Octave.Get(3).C,
                Octave.Get(2).B,
                Octave.Get(2).A,
                Octave.Get(2).G,
                Octave.Get(2).F,
            },
                                      actualNotes);
        }
コード例 #16
0
        public void Chord_Intervals_RootNote_Length_Velocity()
        {
            var defaultOctave = Octave.Get(2);

            var chordVelocity = (SevenBitNumber)70;
            var chordLength   = (MidiTimeSpan)300;

            var pattern = new PatternBuilder()
                          .SetOctave(defaultOctave)
                          .Chord(new[] { Interval.FromHalfSteps(2), Interval.FromHalfSteps(4) }, Notes.D3, chordLength, chordVelocity)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.D, 3, null, chordLength, chordVelocity),
                new NoteInfo(NoteName.E, 3, null, chordLength, chordVelocity),
                new NoteInfo(NoteName.FSharp, 3, null, chordLength, chordVelocity)
            });
        }
コード例 #17
0
        public void Chord_Notes_Length_Velocity()
        {
            var defaultOctave = Octave.Get(2);

            var chordVelocity = (SevenBitNumber)70;
            var chordLength   = (MidiTimeSpan)300;

            var pattern = new PatternBuilder()
                          .SetOctave(defaultOctave)
                          .Chord(new[] { Notes.D3, Notes.E3, Notes.FSharp4 }, chordLength, chordVelocity)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.D, 3, null, chordLength, chordVelocity),
                new NoteInfo(NoteName.E, 3, null, chordLength, chordVelocity),
                new NoteInfo(NoteName.FSharp, 4, null, chordLength, chordVelocity)
            });
        }
コード例 #18
0
        public void Note_Multiple_MetricLengths()
        {
            var pattern = new PatternBuilder()
                          .SetOctave(Octave.Get(2))

                          .Note(NoteName.G, new MetricTimeSpan(0, 0, 24))
                          .Note(NoteName.A, new MetricTimeSpan(0, 1, 0))
                          .Note(NoteName.B, new MetricTimeSpan(0, 0, 5))

                          .Build();

            var midiFile = PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.G, 2, null, new MetricTimeSpan(0, 0, 24)),
                new NoteInfo(NoteName.A, 2, new MetricTimeSpan(0, 0, 24), new MetricTimeSpan(0, 1, 0)),
                new NoteInfo(NoteName.B, 2, new MetricTimeSpan(0, 1, 24), new MetricTimeSpan(0, 0, 5)),
            });

            Assert.AreEqual(new MetricTimeSpan(0, 1, 29), midiFile.GetDuration <MetricTimeSpan>());
        }
コード例 #19
0
ファイル: PatternTests.cs プロジェクト: zivillian/drywetmidi
        public void MoveToFirstAnchor_Keyed_OneUnkeyedAndOneKeyed()
        {
            var anchorTime = new MetricTimeSpan(0, 0, 30);

            var pattern = new PatternBuilder()
                          .MoveToTime(new MetricTimeSpan(0, 0, 10))
                          .StepForward(new MetricTimeSpan(0, 0, 11))
                          .Anchor()
                          .MoveToTime(anchorTime)
                          .Anchor("Test")
                          .StepBack(new MetricTimeSpan(0, 0, 5))
                          .MoveToFirstAnchor("Test")

                          .Note(Octave.Get(0).A)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, anchorTime, MusicalTimeSpan.Quarter)
            });
        }
コード例 #20
0
        public void SplitByNotes_DifferentChannels()
        {
            var tempoMap = TempoMap.Default;
            var channel1 = (FourBitNumber)10;
            var channel2 = (FourBitNumber)4;

            var trackChunk1 = new PatternBuilder()
                              .SetNoteLength(MusicalTimeSpan.Quarter)
                              .SetOctave(Octave.Get(2))

                              .Note(NoteName.A)
                              .Note(NoteName.C)

                              .Build()
                              .ToTrackChunk(tempoMap, channel1);

            var trackChunk2 = new PatternBuilder()
                              .SetNoteLength(MusicalTimeSpan.Eighth)
                              .SetOctave(Octave.Get(3))
                              .StepForward(MusicalTimeSpan.ThirtySecond)

                              .Note(NoteName.D)
                              .Note(NoteName.DSharp)

                              .Build()
                              .ToTrackChunk(tempoMap, channel2);

            var midiFile = new MidiFile(trackChunk1, trackChunk2);
            var notes    = midiFile.GetNotes().ToList();

            var filesByNotes = midiFile.SplitByNotes().ToList();

            Assert.AreEqual(4, filesByNotes.Count, "New files count is invalid.");

            Assert.IsTrue(NoteEquality.AreEqual(filesByNotes[0].GetNotes(), new[] { notes[0] }));
            Assert.IsTrue(NoteEquality.AreEqual(filesByNotes[1].GetNotes(), new[] { notes[1] }));
            Assert.IsTrue(NoteEquality.AreEqual(filesByNotes[2].GetNotes(), new[] { notes[2] }));
            Assert.IsTrue(NoteEquality.AreEqual(filesByNotes[3].GetNotes(), new[] { notes[3] }));
        }
コード例 #21
0
ファイル: PatternTests.cs プロジェクト: zivillian/drywetmidi
        public void Note_MixedLengthAndVelocity()
        {
            var defaultNoteLength = MusicalTimeSpan.Quarter;
            var defaultVelocity   = (SevenBitNumber)90;

            var specifiedLength   = new MetricTimeSpan(0, 0, 10);
            var specifiedVelocity = (SevenBitNumber)95;

            var pattern = new PatternBuilder()
                          .SetNoteLength(defaultNoteLength)
                          .SetVelocity(defaultVelocity)

                          .Note(Octave.Get(0).A)
                          .Note(Octave.Get(1).C, specifiedLength, specifiedVelocity)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, null, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.C, 1, MusicalTimeSpan.Quarter, specifiedLength, specifiedVelocity)
            });
        }
コード例 #22
0
        public void Chord_Intervals_RootNoteName()
        {
            var defaultVelocity   = (SevenBitNumber)90;
            var defaultOctave     = Octave.Get(2);
            var defaultNoteLength = (MidiTimeSpan)300;

            var chordTime = MusicalTimeSpan.Eighth;

            var pattern = new PatternBuilder()
                          .SetVelocity(defaultVelocity)
                          .SetOctave(defaultOctave)
                          .SetNoteLength(defaultNoteLength)
                          .MoveToTime(chordTime)
                          .Chord(new[] { Interval.FromHalfSteps(2), Interval.FromHalfSteps(4) }, NoteName.D)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.D, defaultOctave.Number, chordTime, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.E, defaultOctave.Number, chordTime, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.FSharp, defaultOctave.Number, chordTime, defaultNoteLength, defaultVelocity)
            });
        }
コード例 #23
0
        public void Chord_Notes()
        {
            var defaultVelocity   = (SevenBitNumber)90;
            var defaultOctave     = Octave.Get(2);
            var defaultNoteLength = (MidiTimeSpan)300;

            var chordTime = MusicalTimeSpan.Eighth;

            var pattern = new PatternBuilder()
                          .SetVelocity(defaultVelocity)
                          .SetOctave(defaultOctave)
                          .SetNoteLength(defaultNoteLength)
                          .MoveToTime(chordTime)
                          .Chord(new[] { Notes.D3, Notes.E3, Notes.FSharp4 })
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.D, 3, chordTime, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.E, 3, chordTime, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.FSharp, 4, chordTime, defaultNoteLength, defaultVelocity)
            });
        }
コード例 #24
0
        public void SplitByNotes_SingleChannel()
        {
            var tempoMap = TempoMap.Default;

            var midiFile = new PatternBuilder()
                           .SetNoteLength(MusicalTimeSpan.Quarter)
                           .SetOctave(Octave.Get(2))

                           .Note(NoteName.A)

                           .ProgramChange((SevenBitNumber)20)
                           .Note(NoteName.C)

                           .Build()
                           .ToFile(tempoMap);

            var filesByNotes = midiFile.SplitByNotes().ToList();

            Assert.AreEqual(2, filesByNotes.Count, "New files count is invalid.");

            var notes = midiFile.GetNotes().ToList();

            Assert.IsTrue(NoteEquality.AreEqual(filesByNotes[0].GetNotes(), new[] { notes[0] }));
            Assert.IsTrue(NoteEquality.AreEqual(filesByNotes[1].GetNotes(), new[] { notes[1] }));

            var timedEvents = midiFile.GetTimedEvents().Where(e => !(e.Event is NoteEvent)).ToList();

            Assert.IsTrue(TimedEventEquality.AreEqual(filesByNotes[0].GetTimedEvents()
                                                      .Where(e => !(e.Event is NoteEvent)),
                                                      timedEvents,
                                                      false));
            Assert.IsTrue(TimedEventEquality.AreEqual(filesByNotes[1].GetTimedEvents()
                                                      .Where(e => !(e.Event is NoteEvent)),
                                                      timedEvents,
                                                      false));
        }
コード例 #25
0
        public void Note_Multiple_MetricLengths_TempoChanged()
        {
            var pattern = new PatternBuilder()
                          .SetOctave(Octave.Get(2))

                          .Note(NoteName.G, new MetricTimeSpan(0, 0, 24))
                          .Note(NoteName.A, new MetricTimeSpan(0, 1, 0))
                          .Note(NoteName.B, new MetricTimeSpan(0, 0, 5))

                          .Build();

            var midiFile = PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.G, 2, null, new MetricTimeSpan(0, 0, 24)),
                new NoteInfo(NoteName.A, 2, new MetricTimeSpan(0, 0, 24), new MetricTimeSpan(0, 1, 0)),
                new NoteInfo(NoteName.B, 2, new MetricTimeSpan(0, 1, 24), new MetricTimeSpan(0, 0, 5)),
            },
                                                          Enumerable.Range(0, 7)
                                                          .Select(i => Tuple.Create(i * 1000L, new Tempo(i * 100 + 10)))
                                                          .ToArray());

            Assert.AreEqual(new MetricTimeSpan(0, 1, 29).TotalMicroseconds,
                            midiFile.GetDuration <MetricTimeSpan>().TotalMicroseconds);
        }
コード例 #26
0
 public void Parse_Sharps_Flats_2()
 {
     Parse("C#b##4", Octave.Get(4).D);
 }
コード例 #27
0
 public void Parse_Sharps_Flats_3()
 {
     Parse("C#bbb4", Octave.Get(4).ASharp);
 }
コード例 #28
0
ファイル: NoteTests.cs プロジェクト: zhidao101/drywetmidi
 public void Parse_Valid_SharpWord()
 {
     Parse("F sharp 3", Octave.Get(3).FSharp);
 }
コード例 #29
0
ファイル: NoteTests.cs プロジェクト: zhidao101/drywetmidi
 public void Parse_Valid_ZeroOctave()
 {
     Parse("C#0", Octave.Get(0).CSharp);
 }
コード例 #30
0
ファイル: NoteTests.cs プロジェクト: zhidao101/drywetmidi
 public void Parse_Valid_NegativeOctave()
 {
     Parse("B-1", Octave.Get(-1).B);
 }