示例#1
0
        public Chord CreateChord(string chordString)
        {
            // If the user requested a chord like "C" or "Ab" without providing any additional details, assume it's MAJOR
            if (chordString.Length <= 2)
            {
                chordString = chordString + "MAJ";
            }

            StaccatoParserContext parserContext = new StaccatoParserContext(new StaccatoParser());
            NoteContext           noteContext   = new NoteContext();

            ParseNoteElement(chordString, 0, noteContext, parserContext);
            return(noteContext.CreateChord(parserContext));
        }
示例#2
0
        private int ParseNoteElement(string music, int index, StaccatoParserContext parserContext)
        {
            bool repeat      = false;
            var  noteContext = new NoteContext();

            do
            {
                index = ParseNoteElement(music, index, noteContext, parserContext);
                if (noteContext.IsChord)
                {
                    var chord = noteContext.CreateChord(parserContext);
                    parserContext.Parser.OnChordParsed(chord);
                }
                else
                {
                    var note = noteContext.CreateNote(parserContext);
                    parserContext.Parser.OnNoteParsed(note);
                }
                repeat      = noteContext.IsThereAnother;
                noteContext = noteContext.CreateNextNoteContext();
            } while (repeat);
            return(index);
        }