Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
1023:1f62a890da58 | 1024:d1ce7a4a920b |
---|---|
94 "C%1", "Db%1", "D%1", "Eb%1", | 94 "C%1", "Db%1", "D%1", "Eb%1", |
95 "E%1", "F%1", "Gb%1", "G%1", | 95 "E%1", "F%1", "Gb%1", "G%1", |
96 "Ab%1", "A%1", "Bb%1", "B%1" | 96 "Ab%1", "A%1", "Bb%1", "B%1" |
97 }; | 97 }; |
98 | 98 |
99 QString | 99 int |
100 Pitch::getPitchLabel(int midiPitch, | 100 Pitch::getPitchForNoteAndOctave(int note, int octave) |
101 float centsOffset, | |
102 bool useFlats) | |
103 { | 101 { |
104 int baseOctave = Preferences::getInstance()->getOctaveOfLowestMIDINote(); | 102 int baseOctave = Preferences::getInstance()->getOctaveOfLowestMIDINote(); |
105 int octave = baseOctave; | 103 return (octave - baseOctave) * 12 + note; |
104 } | |
105 | |
106 void | |
107 Pitch::getNoteAndOctaveForPitch(int midiPitch, int ¬e, int &octave) | |
108 { | |
109 int baseOctave = Preferences::getInstance()->getOctaveOfLowestMIDINote(); | |
110 | |
111 octave = baseOctave; | |
106 | 112 |
107 // Note, this only gets the right octave number at octave | 113 // Note, this only gets the right octave number at octave |
108 // boundaries because Cb is enharmonic with B (not B#) and B# is | 114 // 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 | 115 // enharmonic with C (not Cb). So neither B# nor Cb will be |
110 // spelled from a MIDI pitch + flats flag in isolation. | 116 // spelled from a MIDI pitch + flats flag in isolation. |
116 } | 122 } |
117 } else { | 123 } else { |
118 octave = midiPitch / 12 + baseOctave; | 124 octave = midiPitch / 12 + baseOctave; |
119 } | 125 } |
120 | 126 |
121 QString plain = (useFlats ? flatNotes : notes)[midiPitch % 12].arg(octave); | 127 note = midiPitch % 12; |
128 } | |
129 | |
130 QString | |
131 Pitch::getPitchLabel(int midiPitch, | |
132 float centsOffset, | |
133 bool useFlats) | |
134 { | |
135 int note, octave; | |
136 getNoteAndOctaveForPitch(midiPitch, note, octave); | |
137 | |
138 QString plain = (useFlats ? flatNotes : notes)[note].arg(octave); | |
122 | 139 |
123 int ic = lrintf(centsOffset); | 140 int ic = lrintf(centsOffset); |
124 if (ic == 0) return plain; | 141 if (ic == 0) return plain; |
125 else if (ic > 0) return QString("%1+%2c").arg(plain).arg(ic); | 142 else if (ic > 0) return QString("%1+%2c").arg(plain).arg(ic); |
126 else return QString("%1%2c").arg(plain).arg(ic); | 143 else return QString("%1%2c").arg(plain).arg(ic); |