comparison base/Pitch.cpp @ 26:090c22aa726a

* Add the Note layer for pianoroll-type display of note-type data * Complete the MIDI file importer (well, nearly -- it would be nice to be able to import the non-note data as other sorts of models, and that's not done yet). * Minor refactoring in RealTime etc
author Chris Cannam
date Fri, 10 Feb 2006 17:51:36 +0000
parents a7ed14263fe4
children 39ae3dee27b9
comparison
equal deleted inserted replaced
25:7dad8a310963 26:090c22aa726a
43 "C%1", "C#%1", "D%1", "D#%1", 43 "C%1", "C#%1", "D%1", "D#%1",
44 "E%1", "F%1", "F#%1", "G%1", 44 "E%1", "F%1", "F#%1", "G%1",
45 "G#%1", "A%1", "A#%1", "B%1" 45 "G#%1", "A%1", "A#%1", "B%1"
46 }; 46 };
47 47
48 static QString flatNotes[] = {
49 "C%1", "Db%1", "D%1", "Eb%1",
50 "E%1", "F%1", "Gb%1", "G%1",
51 "Ab%1", "A%1", "Bb%1", "B%1"
52 };
53
48 QString 54 QString
49 Pitch::getPitchLabel(int midiPitch, 55 Pitch::getPitchLabel(int midiPitch,
50 float centsOffset) 56 float centsOffset,
57 bool useFlats)
51 { 58 {
52 int octave = -2; 59 int octave = -2;
53 60
54 if (midiPitch < 0) { 61 if (midiPitch < 0) {
55 while (midiPitch < 0) { 62 while (midiPitch < 0) {
58 } 65 }
59 } else { 66 } else {
60 octave = midiPitch / 12 - 2; 67 octave = midiPitch / 12 - 2;
61 } 68 }
62 69
63 QString plain = notes[midiPitch % 12].arg(octave); 70 QString plain = (useFlats ? flatNotes : notes)[midiPitch % 12].arg(octave);
64 71
65 int ic = lrintf(centsOffset); 72 int ic = lrintf(centsOffset);
66 if (ic == 0) return plain; 73 if (ic == 0) return plain;
67 else if (ic > 0) return QString("%1+%2c").arg(plain).arg(ic); 74 else if (ic > 0) return QString("%1+%2c").arg(plain).arg(ic);
68 else return QString("%1%2c").arg(plain).arg(ic); 75 else return QString("%1%2c").arg(plain).arg(ic);
69 } 76 }
70 77
71 QString 78 QString
72 Pitch::getPitchLabelForFrequency(float frequency, 79 Pitch::getPitchLabelForFrequency(float frequency,
73 float concertA) 80 float concertA,
81 bool useFlats)
74 { 82 {
75 float centsOffset = 0.0; 83 float centsOffset = 0.0;
76 int midiPitch = getPitchForFrequency(frequency, &centsOffset, concertA); 84 int midiPitch = getPitchForFrequency(frequency, &centsOffset, concertA);
77 return getPitchLabel(midiPitch, centsOffset); 85 return getPitchLabel(midiPitch, centsOffset, useFlats);
78 } 86 }
79 87