private void setDefaultOctave(NoteContext context) { logger.info("No octave string found, setting default octave"); if (context.isChord) { context.octaveNumber = DefaultNoteSettingsManager.getInstance().getDefaultBassOctave() + context.octaveBias; } else { context.octaveNumber = DefaultNoteSettingsManager.getInstance().getDefaultOctave() + context.octaveBias; } }
/** * Returns the index with which to start parsing the next part of the string, once this method is * done with its part */ private int parseOctave(String s, int index, NoteContext context) { context.isOctaveExplicitlySet = false; // Don't parse an octave for a rest or a numeric note if (context.isRest || context.isNumericNote) { return index; } // Check for octave. Remember that octaves are optional. // Octaves can be two digits, which is what this next bit is testing for. // But, there could be no octave here as well. char possibleOctave1 = '.'; char possibleOctave2 = '.'; if (index < s.length()) { possibleOctave1 = s.charAt(index); } if (index + 1 < s.length()) { possibleOctave2 = s.charAt(index + 1); } byte definiteOctaveLength = 0; if ((possibleOctave1 >= '0') && (possibleOctave1 <= '9')) { definiteOctaveLength = 1; if (possibleOctave2 == '0') { definiteOctaveLength = 2; } // if ((possibleOctave1 == '-') && (definiteOctaveLength == 1)) { // // That '-' isn't representing a -1 octave, it's probably representing the // end of a tie! // // It's a duration character, not an octave character! // return index; // } logger.info("Octave is " + definiteOctaveLength + " digits long"); String octaveNumberString = s.substring(index, index + definiteOctaveLength); logger.info("Octave string value is " + octaveNumberString); try { context.octaveNumber = Integer.parseInt(octaveNumberString) + context.octaveBias; context.isOctaveExplicitlySet = true; } catch (NumberFormatException e) { throw new ParserException(StaccatoMessages.OCTAVE_OUT_OF_RANGE, s); } if (context.octaveNumber > Note.MAX_OCTAVE) { throw new ParserException(StaccatoMessages.OCTAVE_OUT_OF_RANGE, s); } if (context.octaveNumber < Note.MIN_OCTAVE) { throw new ParserException(StaccatoMessages.OCTAVE_OUT_OF_RANGE, s); } context.originalString = context.originalString + octaveNumberString; } return index + definiteOctaveLength; }