diff base/Pitch.cpp @ 1024:d1ce7a4a920b

Wire up note/octave stuff
author Chris Cannam
date Tue, 02 Dec 2014 17:53:17 +0000
parents 451f7f3ab6e7
children 88b54a185a0a
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 &note, 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;