Ejemplo n.º 1
0
  private int parseNoteElement(String s, int index, StaccatoParserContext parserContext) {
    boolean repeat = false;
    NoteContext noteContext = new NoteContext();
    do {
      // Begin the voyage of creating a note by populating the NoteContext
      index = parseNoteElement(s, index, noteContext, parserContext);

      if (noteContext.isChord) {
        Chord chord = noteContext.createChord(parserContext);
        parserContext.getParser().fireChordParsed(chord);
      } else {
        Note note = noteContext.createNote(parserContext);
        parserContext.getParser().fireNoteParsed(note);
      }

      //            // If the note is a chord, fire all the note events for each note in the chord
      //            if (noteContext.isChord) {
      //            	Note[] notes = new Chord(note, noteContext.intervals).getNotes();
      //            	for (int i=1; i < notes.length; i++) {
      //            		NoteContext context2 = noteContext.createChordNoteContext();
      //            		context2.noteNumber = notes[i].getValue();
      //            		logger.info("Next note in chord is "+context2.noteNumber);
      //            		parserContext.fireNoteParsed(context2.createNote(parserContext));
      //            	}
      //            }

      // Determine if there is another note to parse, and set up the next NoteContext
      repeat = noteContext.thereIsAnother;
      noteContext = noteContext.createNextNoteContext();
    } while (repeat);
    return index;
  }
Ejemplo n.º 2
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);
  }