27 if (concertA <= 0.0) {
30 float p = float(midiPitch) + (centsOffset / 100);
31 return concertA * powf(2.0, (p - 69.0) / 12.0);
36 float *centsOffsetReturn,
39 if (concertA <= 0.0) {
42 float p = 12.0 * (log(frequency / (concertA / 2.0)) / log(2.0)) + 57.0;
44 int midiPitch = int(p + 0.00001);
45 float centsOffset = (p - midiPitch) * 100.0;
47 if (centsOffset >= 50.0) {
48 midiPitch = midiPitch + 1;
49 centsOffset = -(100.0 - centsOffset);
52 if (centsOffsetReturn) *centsOffsetReturn = centsOffset;
59 float *centsOffsetReturn,
62 if (concertA <= 0.0) {
66 if (frequencyA > frequencyB) {
67 std::swap(frequencyA, frequencyB);
70 float pA = 12.0 * (log(frequencyA / (concertA / 2.0)) / log(2.0)) + 57.0;
71 float pB = 12.0 * (log(frequencyB / (concertA / 2.0)) / log(2.0)) + 57.0;
75 int midiPitch = int(p + 0.00001);
76 float centsOffset = (p - midiPitch) * 100.0;
78 if (centsOffset >= 50.0) {
79 midiPitch = midiPitch + 1;
80 centsOffset = -(100.0 - centsOffset);
83 if (centsOffsetReturn) *centsOffsetReturn = centsOffset;
88 "C%1",
"C#%1",
"D%1",
"D#%1",
89 "E%1",
"F%1",
"F#%1",
"G%1",
90 "G#%1",
"A%1",
"A#%1",
"B%1" 94 "C%1",
"Db%1",
"D%1",
"Eb%1",
95 "E%1",
"F%1",
"Gb%1",
"G%1",
96 "Ab%1",
"A%1",
"Bb%1",
"B%1" 105 int octave = baseOctave;
113 while (midiPitch < 0) {
118 octave = midiPitch / 12 + baseOctave;
121 QString plain = (useFlats ?
flatNotes :
notes)[midiPitch % 12].arg(octave);
123 int ic = lrintf(centsOffset);
124 if (ic == 0)
return plain;
125 else if (ic > 0)
return QString(
"%1+%2c").arg(plain).arg(ic);
126 else return QString(
"%1%2c").arg(plain).arg(ic);
134 if (concertA <= 0.0) {
137 float centsOffset = 0.0;
146 while (cents < 0.f) {
152 while (cents > 0.f) {
158 int ic = lrintf(cents);
162 return QString(
"%1'%2").arg(semis/12).arg(semis - 12*(semis/12));
164 return QString(
"%1").arg(semis);
169 return QString(
"%1'%2+%3c").arg(semis/12).arg(semis - 12*(semis/12)).arg(ic);
171 return QString(
"%1+%3c").arg(semis).arg(ic);
175 return QString(
"%1'%2%3c").arg(semis/12).arg(semis - 12*(semis/12)).arg(ic);
177 return QString(
"%1%3c").arg(semis).arg(ic);
187 float centsOffset = 0.0;
189 return (midiPitch >= 0 && midiPitch < 128);
float getTuningFrequency() const
static QString getPitchLabelForFrequency(float frequency, float concertA=0.0, bool useFlats=false)
Return a string describing the nearest MIDI pitch to the given frequency, with cents offset.
static Preferences * getInstance()
static QString getPitchLabel(int midiPitch, float centsOffset=0, bool useFlats=false)
Return a string describing the given MIDI pitch, with optional cents offset.
static int getPitchForFrequency(float frequency, float *centsOffsetReturn=0, float concertA=0.0)
Return the nearest MIDI pitch to the given frequency.
static QString flatNotes[]
static int getPitchForFrequencyDifference(float frequencyA, float frequencyB, float *centsOffsetReturn=0, float concertA=0.0)
Return the nearest MIDI pitch range to the given frequency range, that is, the difference in MIDI pit...
static QString getLabelForPitchRange(int semis, float cents=0)
Return a string describing the given pitch range in octaves, semitones and cents.
static float getFrequencyForPitch(int midiPitch, float centsOffset=0, float concertA=0.0)
Return the frequency at the given MIDI pitch plus centsOffset cents (1/100ths of a semitone).
static bool isFrequencyInMidiRange(float frequency, float concertA=0.0)
Return true if the given frequency falls within the range of MIDI note pitches, plus or minus half a ...
int getOctaveOfLowestMIDINote() const