# HG changeset patch # User Chris Cannam # Date 1417542797 0 # Node ID d1ce7a4a920b80e4525ec4c34f76ffa5e7ffb909 # Parent 1f62a890da58894554062f7cfdfaf850a56439f5 Wire up note/octave stuff diff -r 1f62a890da58 -r d1ce7a4a920b base/Pitch.cpp --- a/base/Pitch.cpp Tue Dec 02 13:50:49 2014 +0000 +++ b/base/Pitch.cpp Tue Dec 02 17:53:17 2014 +0000 @@ -96,13 +96,19 @@ "Ab%1", "A%1", "Bb%1", "B%1" }; -QString -Pitch::getPitchLabel(int midiPitch, - float centsOffset, - bool useFlats) +int +Pitch::getPitchForNoteAndOctave(int note, int octave) { int baseOctave = Preferences::getInstance()->getOctaveOfLowestMIDINote(); - int octave = baseOctave; + return (octave - baseOctave) * 12 + note; +} + +void +Pitch::getNoteAndOctaveForPitch(int midiPitch, int ¬e, int &octave) +{ + int baseOctave = Preferences::getInstance()->getOctaveOfLowestMIDINote(); + + octave = baseOctave; // Note, this only gets the right octave number at octave // boundaries because Cb is enharmonic with B (not B#) and B# is @@ -118,7 +124,18 @@ octave = midiPitch / 12 + baseOctave; } - QString plain = (useFlats ? flatNotes : notes)[midiPitch % 12].arg(octave); + note = midiPitch % 12; +} + +QString +Pitch::getPitchLabel(int midiPitch, + float centsOffset, + bool useFlats) +{ + int note, octave; + getNoteAndOctaveForPitch(midiPitch, note, octave); + + QString plain = (useFlats ? flatNotes : notes)[note].arg(octave); int ic = lrintf(centsOffset); if (ic == 0) return plain; diff -r 1f62a890da58 -r d1ce7a4a920b base/Pitch.h --- a/base/Pitch.h Tue Dec 02 13:50:49 2014 +0000 +++ b/base/Pitch.h Tue Dec 02 17:53:17 2014 +0000 @@ -70,6 +70,22 @@ float concertA = 0.0); /** + * Return the MIDI pitch for the given note number (0-12 where 0 + * is C) and octave number. The octave numbering system is based + * on the application preferences (default is C4 = middle C, + * though in previous SV releases that was C3). + */ + static int getPitchForNoteAndOctave(int note, int octave); + + /** + * Return the note number (0-12 where 0 is C) and octave number + * for the given MIDI pitch. The octave numbering system is based + * on the application preferences (default is C4 = middle C, + * though in previous SV releases that was C3). + */ + static void getNoteAndOctaveForPitch(int midiPitch, int ¬e, int &octave); + + /** * Return a string describing the given MIDI pitch, with optional * cents offset. This consists of the note name, octave number, * and optional cents. The octave numbering system is based on the