Пример #1
0
        public void handleMessage(ChannelMessage channelMessage, MidiInterpreter midiInterpreter, Score score)
        {
            if (channelMessage.Data2 > 0)
            {
                midiInterpreter.CurrentNote = new MidiNoteFactory().create(channelMessage.Data1);

                midiInterpreter.StartedNoteIsClosed = false;
            }
            else if (!midiInterpreter.StartedNoteIsClosed)
            {
                midiInterpreter.CurrentNote.length = GetNoteLength(
                    midiInterpreter.PreviousNoteAbsoluteTicks,
                    midiInterpreter.MidiEvent.AbsoluteTicks,
                    midiInterpreter.Sequence.Division,
                    (int)midiInterpreter.timeSignatureLengthNote,
                    midiInterpreter.beatsPerMessage, out bool dot);

                midiInterpreter.CurrentNote.dot = dot;

                midiInterpreter.PreviousNoteAbsoluteTicks = midiInterpreter.MidiEvent.AbsoluteTicks;

                midiInterpreter.StartedNoteIsClosed = true;

                score.staffsInScore.Last().bars.Last().notes.Add(midiInterpreter.CurrentNote);
                midiInterpreter.CurrentNote = null;
            }
            else
            {
                score.staffsInScore.Last().bars.Last().notes.Add(new Rest()
                {
                    length = midiInterpreter.CurrentNote.length
                });
                midiInterpreter.StartedNoteIsClosed = false;
            }
        }
Пример #2
0
        public void handleMessage(MetaMessage metaMessage, MidiInterpreter midi, Score score)
        {
            byte[] timeSignatureBytes = metaMessage.GetBytes();
            var    timeSignature      = new TimeSignature(timeSignatureBytes[0], (Length)(int)Math.Pow(2, timeSignatureBytes[1]));

            midi.beatsPerMessage         = timeSignature.beatsPerMeasure;
            midi.timeSignatureLengthNote = timeSignature.lengthOfOneBeat;
            score.staffsInScore.Last().bars.Last().notes.Add(timeSignature);
        }
        public void handleMessage(MetaMessage metaMessage, MidiInterpreter midi, Score score)
        {
            byte[] tempoBytes = metaMessage.GetBytes();
            int    tempo      = (tempoBytes[0] & 0xff) << 16 | (tempoBytes[1] & 0xff) << 8 | (tempoBytes[2] & 0xff);
            var    bpm        = 60000000 / tempo;
            var    metronome  = new Metronome(Length.Quarter, bpm);

            score.staffsInScore.Last().bars.Last().notes.Add(metronome);
        }
Пример #4
0
 public MidiFileHandler(MidiInterpreter interpreter)
 {
     this.interpreter        = interpreter;
     this.fileType           = "Midi";
     this.possibleExtensions = new List <string> {
         ".midi", ".mid"
     };
     CanSave             = true;
     CanLoad             = true;
     CanGenerateSequence = true;
 }
Пример #5
0
        private void elaborate()
        {
            machineSequence.Load(machineFileName);
            machineTrack = machineSequence[1];

            humanSequence.Load(humanFileName);
            humanTrack = humanSequence[1];

            #region Test area

            MidiEvent m          = machineTrack.GetMidiEvent(3);
            byte[]    bytes      = m.MidiMessage.GetBytes();
            byte      firstByte  = (byte)(bytes[0] & 0xF0);
            byte      secondByte = bytes[1];

            //MessageBox.Show(Convert.ToString(firstByte, 2) + " note " + secondByte.ToString() + " at " + m.AbsoluteTicks.ToString());

            if (m.MidiMessage.GetBytes().Length == 0)
            {
                // Start or end track! Coded with length 0
            }
            else
            {
                if (firstByte == (byte)MidiFirstByte.NoteOff)
                {
                    txtTest.Text = "Note off! ";
                }
                else if (firstByte == (byte)MidiFirstByte.NoteOn)
                {
                    txtTest.Text = "Note on! ";
                }
                else
                {
                    txtTest.Text = "Unknown event. ";
                }
            }
            txtTest.Text += " At " + m.AbsoluteTicks.ToString();

            #endregion

            List <MidiNote> machineNotes      = MidiInterpreter.getNotesSequence(machineTrack);
            List <MidiNote> humanNotes        = MidiInterpreter.getNotesSequence(humanTrack);
            List <MidiNote> wrongNotes        = MidiInterpreter.getWrongNotes(machineNotes, humanNotes);
            List <MidiNote> humanCorrectNotes = MidiInterpreter.getCorrectNotes(machineNotes, humanNotes);

            numberHumanNotes   = humanNotes.Count();
            numberMachineNotes = machineNotes.Count();
            numberWrongNotes   = wrongNotes.Count();

            totalJitter = MidiInterpreter.getTotalJitter(machineNotes, humanCorrectNotes);
            avgJitter   = totalJitter / machineNotes.Count();

            txtNumberMachineNotes.Text = numberMachineNotes.ToString();
            txtNumberHumanNotes.Text   = numberHumanNotes.ToString();
            txtNumberWrongNotes.Text   = numberWrongNotes.ToString();
            txtTotalJitter.Text        = totalJitter.ToString();
            txtAverageJitter.Text      = avgJitter.ToString();

            lstMachineNotes.Items.Clear();
            lstMachineNotes.Items.Clear();
            lstWrongNotes.Items.Clear();

            foreach (MidiNote midiNote in machineNotes)
            {
                lstMachineNotes.Items.Add(new ListViewItem(midiNote.Key + " at " + midiNote.Time));
            }

            foreach (MidiNote midiNote in humanNotes)
            {
                lstHumanNotes.Items.Add(new ListViewItem(midiNote.Key + " at " + midiNote.Time));
            }

            foreach (MidiNote midiNote in wrongNotes)
            {
                lstWrongNotes.Items.Add(new ListViewItem(midiNote.Key + " at " + midiNote.Time));
            }
        }