Esempio n. 1
0
 public static bool TryParse(List <MidiEvent> messages, BaseNoteRetriever retriever, out Chord chord)
 {
     if (messages == null || retriever == null)
     {
         chord = null;
         return(false);
     }
     chord = new Chord(messages,
                       messages
                       .Where(x => x.MidiMessage is ChannelMessage)
                       .Select(x => x.MidiMessage as ChannelMessage)
                       .Where(x => x.Command == ChannelCommand.NoteOn && retriever.ValidNoteId(x))
                       .Select(x => retriever.RetrieveNote(x)).ToList());
     return(true);
 }
Esempio n. 2
0
        public static List <Chord> RetrieveChords(IEnumerable <MidiEvent> track, BaseNoteRetriever retriever)
        {
            track.NullCheck();

            var individualMidiEvents = track.ToList();
            var indexes    = Chord.GetIndexes(individualMidiEvents);
            var pureChords = Chord.GetAllFullChords(individualMidiEvents, indexes);

            var start = individualMidiEvents.FindIndex(x => x.MidiMessage is ChannelMessage);
            var last  = individualMidiEvents.FindLastIndex(x => x.MidiMessage is ChannelMessage);

            List <Chord> chords = new List <Chord>();

            for (int pureChordCounter = 0; start < last && pureChordCounter < pureChords.Count; start++)
            {
                if (start < pureChords[pureChordCounter].Item1)
                {
                    var pair = Chord.FindPairCount(start, pureChords[pureChordCounter].Item2, individualMidiEvents);

                    if (pair.HasValue)
                    {
                        Chord outChord;
                        if (Chord.TryParse(individualMidiEvents.GetRange(start, pair.Value - start + 1), retriever, out outChord))
                        {
                            chords.Add(outChord);
                        }
                    }
                }
                else
                {
                    var   item = pureChords[pureChordCounter];
                    Chord outChord;
                    if (Chord.TryParse(individualMidiEvents.GetRange(item.Item1, item.Item2 - item.Item1 + 1), retriever, out outChord))
                    {
                        chords.Add(outChord);
                    }
                    start = item.Item2;
                    pureChordCounter++;
                }
            }
            return(chords.ToList());
        }