![]() However, using the array index as a mapping isn't the best approach in my opinion. Return Character.getNumericValue(oct) * 12 + i + accidental // !! read the documentation of Character#getNumericValue !! Return -1 // you should really use Exceptions instead Int accidental = 0 // initialize with default value 0 (i.e. So with the least modification of your code: You can handle the accidentals separately. Is there a way to do this without tearing my method apart? However, I would also like to be able to use convertToPitch() with the alternate note value (Db becomes C#, etc.) for each note with an alternate name. Return Character.getNumericValue(oct) * 12 + i Īnd it works just great. Find the corresponding note in the array. Otherwise, it must be a two-char note. If the length is two, then grab the symbol and number. Public static int convertToPitch(String note) I have written the following method to convert notes (with the octave appended to the end) to the corresponding MIDI pitch: // Converts a note string (MUST HAVE OCTAVE) to an integer pitch.
0 Comments
Leave a Reply. |