Пример #1
0
  /**
   * Returns the index with which to start parsing the next part of the string, once this method is
   * done with its part
   */
  private int parseChord(String s, int index, NoteContext context) {
    // Don't parse chord for a rest
    if (context.isRest) {
      return index;
    }

    int lengthOfChordString = 0;
    boolean chordFound = false;
    String[] chordNames = Chord.getChordNames();
    for (String chordName : chordNames) {
      if (!chordFound
          && (s.length() >= index + chordName.length())
          && chordName.equals(s.substring(index, index + chordName.length()))) {
        chordFound = true;
        lengthOfChordString = chordName.length();
        context.isChord = true;
        context.intervals = Chord.getIntervals(chordName);
        context.chordName = chordName;
        logger.info(
            "Chord: " + chordName + "   Interval Pattern: " + Chord.getIntervals(chordName));
        break;
      }
    }
    return index + lengthOfChordString;
  }
Пример #2
0
 @Test
 public void testSimpleChord2() {
   assertTrue(
       compare(
           "AMIN/1.5",
           CHORD_PARSED,
           new Chord(new Note(57).setDuration(1.5d), Chord.getIntervals("MIN"))));
 }
Пример #3
0
    /**
     * Creates a Note based on the settings in this NoteContext
     *
     * @return Note
     */
    public Chord createChord(StaccatoParserContext parserContext) {
      if (noteValueAsString != null) {
        noteNumber = (Byte) parserContext.getDictionary().get(noteValueAsString);
      }
      if (durationValueAsString != null) {
        decimalDuration = (Byte) parserContext.getDictionary().get(durationValueAsString);
      }

      Note rootNote = createNote(parserContext);
      if (isChord) {
        Chord chord = new Chord(rootNote, intervals);
        if (!(inversionBassNote == null)) {
          chord.setBassNote(inversionBassNote);
        } else if (inversionCount > 0) {
          chord.setInversion(inversionCount);
        }
        return chord;
      }
      return null;
    }
Пример #4
0
 @Test
 public void testChordInversions() {
   assertTrue(compare("C4maj", CHORD_PARSED, new Chord(new Note(48), Chord.getIntervals("MAJ"))));
 }
Пример #5
0
 @Test
 public void testDefaultChordOctave() {
   assertTrue(compare("Cmaj", CHORD_PARSED, new Chord(new Note(48), Chord.getIntervals("MAJ"))));
 }