Ejemplo n.º 1
0
        public void ConvertCsvToMidiFile_NoteLength_Metric(NoteNumberFormat noteNumberFormat, string[] csvLines)
        {
            var midiFile = ConvertCsvToMidiFile(MidiFileCsvLayout.DryWetMidi,
                                                TimeSpanType.Midi,
                                                csvLines,
                                                NoteFormat.Note,
                                                noteNumberFormat,
                                                TimeSpanType.Metric);

            var tempoMap = TempoMap.Default;

            var expectedObjects = new ITimedObject[]
            {
                new Note((SevenBitNumber)50, LengthConverter.ConvertFrom(new MetricTimeSpan(0, 0, 10), 0, tempoMap), 0)
                {
                    Channel     = (FourBitNumber)10,
                    Velocity    = (SevenBitNumber)120,
                    OffVelocity = (SevenBitNumber)70
                },
                new TimedEvent(new TextEvent("Te\"s\"\"t"), 0),
                new Note((SevenBitNumber)70, LengthConverter.ConvertFrom(new MetricTimeSpan(0, 0, 0, 500), 100, tempoMap), 100)
                {
                    Channel     = (FourBitNumber)7,
                    Velocity    = (SevenBitNumber)110,
                    OffVelocity = (SevenBitNumber)80
                }
            };

            Assert.AreEqual(1, midiFile.GetTrackChunks().Count(), "Track chunks count is invalid.");
            Assert.IsTrue(TimedObjectEquality.AreEqual(expectedObjects, midiFile.GetTimedEvents().GetTimedEventsAndNotes(), false),
                          "Invalid objects.");
        }
Ejemplo n.º 2
0
            public int Compare(object x, object y)
            {
                var timedObject1 = x as ITimedObject;
                var timedObject2 = y as ITimedObject;

                if (ReferenceEquals(timedObject1, timedObject2))
                {
                    return(1);
                }

                if (ReferenceEquals(timedObject1, null))
                {
                    return(-1);
                }

                if (ReferenceEquals(timedObject2, null))
                {
                    return(1);
                }

                var timesDifference = timedObject1.Time - timedObject2.Time;

                if (timesDifference != 0)
                {
                    return(Math.Sign(timesDifference));
                }

                return(TimedObjectEquality.AreEqual(timedObject1, timedObject2, false) ? 0 : -1);
            }
Ejemplo n.º 3
0
        public void ConvertCsvToMidiFile_NoteNumberFormat(NoteNumberFormat noteNumberFormat, string[] csvLines)
        {
            var midiFile = ConvertCsvToMidiFile(MidiFileCsvLayout.DryWetMidi, TimeSpanType.Midi, csvLines, NoteFormat.Note, noteNumberFormat);

            var expectedObjects = new ITimedObject[]
            {
                new Note((SevenBitNumber)50, 250, 0)
                {
                    Channel     = (FourBitNumber)10,
                    Velocity    = (SevenBitNumber)120,
                    OffVelocity = (SevenBitNumber)70
                },
                new TimedEvent(new TextEvent("Test"), 0),
                new Note((SevenBitNumber)50, 900, 100)
                {
                    Channel     = (FourBitNumber)7,
                    Velocity    = (SevenBitNumber)110,
                    OffVelocity = (SevenBitNumber)80
                }
            };

            Assert.AreEqual(1, midiFile.GetTrackChunks().Count(), "Track chunks count is invalid.");
            Assert.IsTrue(TimedObjectEquality.AreEqual(expectedObjects, midiFile.GetTimedEvents().GetTimedEventsAndNotes(), false),
                          "Invalid objects.");
        }
Ejemplo n.º 4
0
        public void Notes_Overlapped()
        {
            var trackChunk = new TrackChunk(
                new NoteOnEvent((SevenBitNumber)30, (SevenBitNumber)70),
                new NoteOnEvent((SevenBitNumber)60, (SevenBitNumber)50),
                new NoteOffEvent((SevenBitNumber)60, (SevenBitNumber)0)
            {
                DeltaTime = 100
            },
                new NoteOnEvent((SevenBitNumber)40, (SevenBitNumber)70),
                new NoteOffEvent((SevenBitNumber)40, (SevenBitNumber)0)
            {
                DeltaTime = 100
            },
                new NoteOffEvent((SevenBitNumber)30, (SevenBitNumber)0));

            var expectedNotes = new[]
            {
                new Note((SevenBitNumber)30, 200, 0)
                {
                    Velocity = (SevenBitNumber)70
                },
                new Note((SevenBitNumber)60, 100, 0)
                {
                    Velocity = (SevenBitNumber)50
                },
                new Note((SevenBitNumber)40, 100, 100)
                {
                    Velocity = (SevenBitNumber)70
                }
            };

            using (var notesManager = trackChunk.ManageNotes())
            {
                var notes = notesManager.Notes;
                Assert.IsTrue(TimedObjectEquality.AreEqual(expectedNotes, notes, true));
            }
        }