Mercurial > hg > svcore
changeset 1024:d1ce7a4a920b
Wire up note/octave stuff
author | Chris Cannam |
---|---|
date | Tue, 02 Dec 2014 17:53:17 +0000 |
parents | 1f62a890da58 |
children | 88b54a185a0a |
files | base/Pitch.cpp base/Pitch.h |
diffstat | 2 files changed, 39 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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