comparison base/Pitch.cpp @ 892:451f7f3ab6e7

Make octave numbering configurable, and change default to C4 = middle C
author Chris Cannam
date Thu, 27 Mar 2014 13:32:56 +0000
parents bdc9bb371a9f
children d1ce7a4a920b
comparison
equal deleted inserted replaced
889:7f97a4d9d14f 892:451f7f3ab6e7
99 QString 99 QString
100 Pitch::getPitchLabel(int midiPitch, 100 Pitch::getPitchLabel(int midiPitch,
101 float centsOffset, 101 float centsOffset,
102 bool useFlats) 102 bool useFlats)
103 { 103 {
104 int octave = -2; 104 int baseOctave = Preferences::getInstance()->getOctaveOfLowestMIDINote();
105 int octave = baseOctave;
106
107 // Note, this only gets the right octave number at octave
108 // boundaries because Cb is enharmonic with B (not B#) and B# is
109 // enharmonic with C (not Cb). So neither B# nor Cb will be
110 // spelled from a MIDI pitch + flats flag in isolation.
105 111
106 if (midiPitch < 0) { 112 if (midiPitch < 0) {
107 while (midiPitch < 0) { 113 while (midiPitch < 0) {
108 midiPitch += 12; 114 midiPitch += 12;
109 --octave; 115 --octave;
110 } 116 }
111 } else { 117 } else {
112 octave = midiPitch / 12 - 2; 118 octave = midiPitch / 12 + baseOctave;
113 } 119 }
114 120
115 QString plain = (useFlats ? flatNotes : notes)[midiPitch % 12].arg(octave); 121 QString plain = (useFlats ? flatNotes : notes)[midiPitch % 12].arg(octave);
116 122
117 int ic = lrintf(centsOffset); 123 int ic = lrintf(centsOffset);