Ejemplo n.º 1
0
        public void TwoNotes()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, "C#4", 100));
            midiEvents.Add(new NoteOn(120, 1, "C#4", 0));
            midiEvents.Add(new NoteOn(0, 1, "G#3", 100));
            midiEvents.Add(new NoteOn(120, 1, "G#3", 0));

            var midiImporter = new MidiImporter(midiEvents, 120);

            Assert.AreEqual(2, midiImporter.ScoreNotes.Count);

            {
                var scoreNote = midiImporter.ScoreNotes.ElementAt(0).Value;

                Assert.AreEqual(1, scoreNote.Beat);
                Assert.AreEqual(0, scoreNote.Tick);
                Assert.AreEqual(NoteValue.Db, scoreNote.Note.Value);
                Assert.AreEqual(4, scoreNote.Note.Number);
            }

            {
                var scoreNote = midiImporter.ScoreNotes.ElementAt(1).Value;

                Assert.AreEqual(2, scoreNote.Beat);
                Assert.AreEqual(0, scoreNote.Tick);
                Assert.AreEqual(NoteValue.Ab, scoreNote.Note.Value);
                Assert.AreEqual(3, scoreNote.Note.Number);
            }
        }
Ejemplo n.º 2
0
        public void NoteDuration_NewInitializationWithoutFinalization()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, "C4", 100));
            midiEvents.Add(new NoteOn(0, 1, "C4", 100));

            var midiImporter = new GuitarMidiImporter(midiEvents, 120);
        }
Ejemplo n.º 3
0
        public void NoteDuration_NotFinalizedNotes()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, "C4", 100));
            midiEvents.Add(new NoteOn(120, 1, "C4", 0));

            midiEvents.Add(new NoteOn(0, 1, "C4", 100)); //not finalized

            var midiImporter = new MidiImporter(midiEvents, 120);
        }
Ejemplo n.º 4
0
        public void NoteDuration_NoteOnNotFound()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, "C4", 100));
            midiEvents.Add(new NoteOn(120, 1, "C4", 0));

            midiEvents.Add(new NoteOn(120, 1, "C4", 0));

            var midiImporter = new MidiImporter(midiEvents, 120);
        }
Ejemplo n.º 5
0
        public void Skip3Beats()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, "C4", 100));
            midiEvents.Add(new NoteOn(120, 1, "C4", 0));

            var midiImporter = new GuitarMidiImporter(midiEvents, 120, 3);

            var firstScoreNote = midiImporter.ScoreNotes.ElementAt(0).Value;

            Assert.AreEqual(1 + 3, firstScoreNote.Beat);
            Assert.AreEqual(0, firstScoreNote.Tick);
        }
Ejemplo n.º 6
0
        //private static string MIDI_for_whom_the_bell_tolls = TestConfig.AudioPath + "metallica-for_whom_the_bell_tolls.mid";

        private void TestFirstNotePosition(NoteValue pNoteValue, string pNoteId, int pString, int pPosition)
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, pNoteId, 100));
            midiEvents.Add(new NoteOn(120, 1, pNoteId, 0));

            var midiImporter = new GuitarMidiImporter(midiEvents, 120);

            var firstScoreNote = midiImporter.ScoreNotes.ElementAt(0).Value;

            Assert.AreEqual(pNoteValue, firstScoreNote.Note.Value, firstScoreNote.NoteId);
            Assert.AreEqual(pString, firstScoreNote.NotePositions.ElementAt(0).Value.String, firstScoreNote.NoteId);
            Assert.AreEqual(pPosition, firstScoreNote.NotePositions.ElementAt(0).Value.Fret, firstScoreNote.NoteId);
        }
Ejemplo n.º 7
0
        public void NoteDuration_AdmitTheSameNote()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, "C4", 100));
            midiEvents.Add(new NoteOn(0, 1, "C4", 100));

            midiEvents.Add(new NoteOn(120, 1, "C4", 0));
            midiEvents.Add(new NoteOn(120, 1, "C4", 0));

            var midiImporter = new GuitarMidiImporter(midiEvents, 120);

            Assert.AreEqual(2, midiImporter.ScoreNotes.Count);

            var firstChord = midiImporter.ScoreNotes.Where(p => (p.Value.Beat == 1) &&
                                                           (p.Value.Tick == 0)).ToList();

            Assert.AreEqual(2, firstChord.Count);
        }
Ejemplo n.º 8
0
        static MidiSequence CreateScaleSequence()
        {
            MidiSequence        sequence = new MidiSequence();
            MidiEventCollection events   = sequence.Tracks.AddNewTrack().Events;

            string[] notes = new[] { "C5", "D5", "E5", "F5", "G5", "A5", "B5", "C6", "C6", "B5", "A5", "G5", "F5", "E5", "D5", "C5" };
            events.AddRange(notes.SelectMany(note => NoteVoiceMidiEvent.Complete(null, 100, 0, note, 127, 100)));
            events.Add(new EndOfTrackMetaMidiEvent(null, notes.Length * 100));

            return(sequence);
        }
Ejemplo n.º 9
0
        public void OneNote()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(480, 1, "C#4", 100)); //480 = 4 x 120 (4 beats)
            midiEvents.Add(new NoteOn(120, 1, "C#4", 0));

            var midiImporter = new MidiImporter(midiEvents, 120);

            Assert.AreEqual(1, midiImporter.ScoreNotes.Count);

            var firstScoreNote = midiImporter.ScoreNotes.ElementAt(0).Value;

            //Time is 5:0 (beat:tick)
            Assert.AreEqual(5, firstScoreNote.Beat);
            Assert.AreEqual(0, firstScoreNote.Tick);

            //Note is C#4
            Assert.AreEqual(NoteValue.Db, firstScoreNote.Note.Value);
            Assert.AreEqual(4, firstScoreNote.Note.Number);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates the midi track to add to the sequence.
        /// </summary>
        /// <param name="trackName"></param>
        /// <param name="instrument"></param>
        /// <param name="tempo"></param>
        /// <param name="time"></param>
        /// <param name="noteEvents"></param>
        /// <returns></returns>
        private static MidiTrack CreateTrack(string trackName, GeneralMidiInstrument instrument, int tempo, TimeSignature time, List <MidiEvent> noteEvents)
        {
            MidiTrack           track  = new MidiTrack();
            MidiEventCollection events = track.Events;

            // Set the track name
            events.Add(SetTrackName(trackName));

            // Set the instrument
            events.Add(SetInstrument(instrument));

            // Set the tempo
            events.Add(SetTempo(tempo));

            // Set the time signature
            events.Add(SetTimeSignature(time));

            // add on off note events to track
            foreach (var note in noteEvents)
            {
                events.Add(note);
            }

            // Set the end of track flag
            events.Add(SetEndOfTrack());

            return(track);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates the midi track to add to the sequence.
        /// </summary>
        /// <param name="noteEvents"></param>
        /// <returns></returns>
        private MidiTrack CreateTrack(List <MidiEvent> noteEvents)
        {
            MidiTrack           track  = new MidiTrack();
            MidiEventCollection events = track.Events;

            // Set the track name
            events.Add(SetTrackName(_trackName));

            // Set the instrument
            events.Add(SetInstrument(_instrument));

            // Set the tempo
            events.Add(SetTempo(_tempo));

            // Set the time signature
            events.Add(SetTimeSignature(_timeSignature));

            // add on off note events to track
            foreach (var note in noteEvents)
            {
                events.Add(note);
            }

            // Set the end of track flag
            events.Add(SetEndOfTrack());

            return(track);
        }
Ejemplo n.º 12
0
        public void NoteDuration_OneNote_OneBeat()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(0, 1, "C#4", 100));
            midiEvents.Add(new NoteOn(120, 1, "C#4", 0));

            var midiImporter = new MidiImporter(midiEvents, 120);

            Assert.AreEqual(1, midiImporter.ScoreNotes.Count);

            {
                var scoreNote = midiImporter.ScoreNotes.ElementAt(0).Value;

                Assert.AreEqual(1, scoreNote.Beat);
                Assert.AreEqual(0, scoreNote.Tick);
                Assert.AreEqual(NoteValue.Db, scoreNote.Note.Value);
                Assert.AreEqual(4, scoreNote.Note.Number);

                //Duration in Beats
                Assert.AreEqual(480, scoreNote.DurationInTicks);
            }
        }
Ejemplo n.º 13
0
        public void NoteDuration_OneNote_TwoChords()
        {
            var midiEvents = new MidiEventCollection();

            midiEvents.Add(new NoteOn(480, 1, "C4", 100));
            midiEvents.Add(new NoteOn(0, 1, "G4", 100));
            midiEvents.Add(new NoteOn(0, 1, "C5", 100));

            midiEvents.Add(new NoteOn(30, 1, "C4", 0));
            midiEvents.Add(new NoteOn(0, 1, "G4", 0));
            midiEvents.Add(new NoteOn(0, 1, "C5", 0));

            midiEvents.Add(new NoteOn(30, 1, "G3", 100));
            midiEvents.Add(new NoteOn(0, 1, "D4", 100));
            midiEvents.Add(new NoteOn(0, 1, "G4", 100));

            midiEvents.Add(new NoteOn(180, 1, "G3", 0));
            midiEvents.Add(new NoteOn(0, 1, "D4", 0));
            midiEvents.Add(new NoteOn(0, 1, "G4", 0));

            var midiImporter = new MidiImporter(midiEvents, 120);

            Assert.AreEqual(6, midiImporter.ScoreNotes.Count);

            //Get the first chord (and test the position/duration)
            var firstChord = midiImporter.ScoreNotes.Where(
                p => (p.Value.Beat == 5) &&
                (p.Value.Tick == 0) &&
                (p.Value.DurationInTicks == 120)).ToList();

            Assert.AreEqual(3, firstChord.Count);

            //Get the second chord (and test the position/duration)
            var secondChord = midiImporter.ScoreNotes.Where(
                p => (p.Value.Beat == 5) &&
                (p.Value.Tick == 240) &&
                (p.Value.DurationInTicks == 480 + 240)).ToList();

            Assert.AreEqual(3, secondChord.Count);
        }