Mercurial > hg > svcore
comparison base/Pitch.h @ 274:e412f65884ee
* Fix piano keyboard in spectrum, add pitch labels to frequency displays in
measurement rect (clunkily done) and harmonic cursor in spectrum
author | Chris Cannam |
---|---|
date | Tue, 03 Jul 2007 18:47:39 +0000 |
parents | 4f26f623a8bc |
children | 0a44caddd9fe |
comparison
equal
deleted
inserted
replaced
273:f1f47660483d | 274:e412f65884ee |
---|---|
19 #include <QString> | 19 #include <QString> |
20 | 20 |
21 class Pitch | 21 class Pitch |
22 { | 22 { |
23 public: | 23 public: |
24 /* If concertA <= 0, it will be taken from current preferences */ | 24 /** |
25 | 25 * Return the frequency at the given MIDI pitch plus centsOffset |
26 * cents (1/100ths of a semitone). centsOffset does not have to | |
27 * be in any particular range or sign. | |
28 * | |
29 * If concertA is non-zero, use that as the reference frequency | |
30 * for the A at MIDI pitch 69; otherwise use the tuning frequency | |
31 * specified in the application preferences (default 440Hz). | |
32 */ | |
26 static float getFrequencyForPitch(int midiPitch, | 33 static float getFrequencyForPitch(int midiPitch, |
27 float centsOffset = 0, | 34 float centsOffset = 0, |
28 float concertA = 0.0); | 35 float concertA = 0.0); |
29 | 36 |
37 /** | |
38 * Return the nearest MIDI pitch to the given frequency. | |
39 * | |
40 * If centsOffsetReturn is non-NULL, return in *centsOffsetReturn | |
41 * the number of cents (1/100ths of a semitone) difference between | |
42 * the given frequency and that of the returned MIDI pitch. The | |
43 * cents offset will be in the range [-50,50). | |
44 * | |
45 * If concertA is non-zero, use that as the reference frequency | |
46 * for the A at MIDI pitch 69; otherwise use the tuning frequency | |
47 * specified in the application preferences (default 440Hz). | |
48 */ | |
30 static int getPitchForFrequency(float frequency, | 49 static int getPitchForFrequency(float frequency, |
31 float *centsOffsetReturn = 0, | 50 float *centsOffsetReturn = 0, |
32 float concertA = 0.0); | 51 float concertA = 0.0); |
33 | 52 |
53 /** | |
54 * Return a string describing the given MIDI pitch, with optional | |
55 * cents offset. This consists of the note name, octave number | |
56 * (with MIDI pitch 0 having octave number -2), and optional | |
57 * cents. | |
58 * | |
59 * For example, "A#3" (A# in octave 3) or "C2-12c" (C in octave 2, | |
60 * minus 12 cents). | |
61 * | |
62 * If useFlats is true, spell notes with flats instead of sharps, | |
63 * e.g. Bb3 instead of A#3. | |
64 */ | |
34 static QString getPitchLabel(int midiPitch, | 65 static QString getPitchLabel(int midiPitch, |
35 float centsOffset = 0, | 66 float centsOffset = 0, |
36 bool useFlats = false); | 67 bool useFlats = false); |
37 | 68 |
69 /** | |
70 * Return a string describing the nearest MIDI pitch to the given | |
71 * frequency, with cents offset. | |
72 * | |
73 * If concertA is non-zero, use that as the reference frequency | |
74 * for the A at MIDI pitch 69; otherwise use the tuning frequency | |
75 * specified in the application preferences (default 440Hz). | |
76 * | |
77 * If useFlats is true, spell notes with flats instead of sharps, | |
78 * e.g. Bb3 instead of A#3. | |
79 */ | |
38 static QString getPitchLabelForFrequency(float frequency, | 80 static QString getPitchLabelForFrequency(float frequency, |
39 float concertA = 0.0, | 81 float concertA = 0.0, |
40 bool useFlats = false); | 82 bool useFlats = false); |
83 | |
84 /** | |
85 * Return true if the given frequency falls within the range of | |
86 * MIDI note pitches, plus or minus half a semitone. This is | |
87 * equivalent to testing whether getPitchForFrequency returns a | |
88 * pitch in the MIDI range (0 to 127 inclusive) with any cents | |
89 * offset. | |
90 * | |
91 * If concertA is non-zero, use that as the reference frequency | |
92 * for the A at MIDI pitch 69; otherwise use the tuning frequency | |
93 * specified in the application preferences (default 440Hz). | |
94 */ | |
95 static bool isFrequencyInMidiRange(float frequency, | |
96 float concertA = 0.0); | |
41 }; | 97 }; |
42 | 98 |
43 | 99 |
44 #endif | 100 #endif |