Beispiel #1
0
 /** A NoteOff event occured.  Find the MidiNote of the corresponding
  * NoteOn event, and update the duration of the MidiNote.
  */
 public void NoteOff(int channel, int notenumber, int endtime)
 {
     for (int i = notes.Count - 1; i >= 0; i--)
     {
         MidiNote note = notes[i];
         if (note.Channel == channel && note.Number == notenumber &&
             note.Duration == 0)
         {
             note.NoteOff(endtime);
             return;
         }
     }
 }
Beispiel #2
0
        /** Create a MidiTrack based on the Midi events.  Extract the NoteOn/NoteOff
         *  events to gather the list of MidiNotes.
         */
        public MidiTrack(List <MidiEvent> events, int tracknum)
        {
            this.tracknum = tracknum;
            notes         = new List <MidiNote>(events.Count);
            instrument    = 0;

            foreach (MidiEvent mevent in events)
            {
                if (mevent.EventFlag == MidiFile.EventNoteOn && mevent.Velocity > 0)
                {
                    MidiNote note = new MidiNote(mevent.StartTime, mevent.Channel, mevent.Notenumber, 0);
                    AddNote(note);
                }
                else if (mevent.EventFlag == MidiFile.EventNoteOn && mevent.Velocity == 0)
                {
                    NoteOff(mevent.Channel, mevent.Notenumber, mevent.StartTime);
                }
                else if (mevent.EventFlag == MidiFile.EventNoteOff)
                {
                    NoteOff(mevent.Channel, mevent.Notenumber, mevent.StartTime);
                }
                else if (mevent.EventFlag == MidiFile.EventProgramChange)
                {
                    instrument = mevent.Instrument;
                }
                else if (mevent.Metaevent == MidiFile.MetaEventLyric)
                {
                    if (lyrics == null)
                    {
                        lyrics = new List <MidiEvent>();
                    }
                    lyrics.Add(mevent);
                }
            }
            if (notes.Count > 0 && notes[0].Channel == 9)
            {
                instrument = 128;  /* Percussion */
            }
            int lyriccount = 0;

            if (lyrics != null)
            {
                lyriccount = lyrics.Count;
            }
        }
Beispiel #3
0
        CreateNoteData(List <MidiNote> midinotes, KeySignature key,
                       TimeSignature time)
        {
            int len = midinotes.Count;

            NoteData[] notedata = new NoteData[len];

            for (int i = 0; i < len; i++)
            {
                MidiNote midi = midinotes[i];
                notedata[i]           = new NoteData();
                notedata[i].number    = midi.Number;
                notedata[i].leftside  = true;
                notedata[i].whitenote = key.GetWhiteNote(midi.Number);
                notedata[i].duration  = time.GetNoteDuration(midi.EndTime - midi.StartTime);
                notedata[i].accid     = key.GetAccidental(midi.Number, midi.StartTime / time.Measure);

                if (i > 0 && (notedata[i].whitenote.Dist(notedata[i - 1].whitenote) == 1))
                {
                    /* This note (notedata[i]) overlaps with the previous note.
                     * Change the side of this note.
                     */

                    if (notedata[i - 1].leftside)
                    {
                        notedata[i].leftside = false;
                    }
                    else
                    {
                        notedata[i].leftside = true;
                    }
                }
                else
                {
                    notedata[i].leftside = true;
                }
            }
            return(notedata);
        }
        public void InsertNote(MidiNote note)
        {
            int measure_start = note.StartTime / measurelength;
            int measure_end   = (note.EndTime - 1) / measurelength + 1;

            while (measures.Count < measure_end)
            {
                measures.Add(null);
            }
            for (int measure = measure_start; measure < measure_end; measure++)
            {
                if (measures[measure] == null)
                {
                    if (timesig.Numerator % 2 == 0)
                    {
                        measures[measure] = new Measure(1);
                    }
                    else if (timesig.Numerator % 3 == 0)
                    {
                        measures[measure] = new Measure(3);
                    }
                    else if (timesig.Numerator % 5 == 0)
                    {
                        measures[measure] = new Measure(5);
                    }
                    else if (timesig.Numerator % 7 == 0)
                    {
                        measures[measure] = new Measure(7);
                    }
                    else if (timesig.Numerator % 11 == 0)
                    {
                        measures[measure] = new Measure(11);
                    }
                }
                int start_in_measure = note.StartTime - measure * measurelength;
                int end_in_measure   = note.EndTime - measure * measurelength;
                measures[measure].AddNote(note.Number, start_in_measure, end_in_measure, measurelength);
            }
        }
Beispiel #5
0
 /** Add a MidiNote to this track.  This is called for each NoteOn event */
 public void AddNote(MidiNote m)
 {
     notes.Add(m);
 }