comparison widgets/UnitConverter.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents a34a2a25907c
children
comparison
equal deleted inserted replaced
1183:57d192e26331 1324:13d9b422f7fe
57 m_freq->setDecimals(6); 57 m_freq->setDecimals(6);
58 m_freq->setMinimum(1e-3); 58 m_freq->setMinimum(1e-3);
59 m_freq->setMaximum(1e6); 59 m_freq->setMaximum(1e6);
60 m_freq->setValue(440); 60 m_freq->setValue(440);
61 connect(m_freq, SIGNAL(valueChanged(double)), 61 connect(m_freq, SIGNAL(valueChanged(double)),
62 this, SLOT(freqChanged())); 62 this, SLOT(freqChanged()));
63 63
64 // The min and max range values for all the remaining controls are 64 // The min and max range values for all the remaining controls are
65 // determined by the min and max Hz above 65 // determined by the min and max Hz above
66 66
67 m_midi = new QSpinBox; 67 m_midi = new QSpinBox;
68 m_midi->setMinimum(-156); 68 m_midi->setMinimum(-156);
69 m_midi->setMaximum(203); 69 m_midi->setMaximum(203);
70 connect(m_midi, SIGNAL(valueChanged(int)), 70 connect(m_midi, SIGNAL(valueChanged(int)),
71 this, SLOT(midiChanged())); 71 this, SLOT(midiChanged()));
72 72
73 m_note = new QComboBox; 73 m_note = new QComboBox;
74 for (int i = 0; i < 12; ++i) { 74 for (int i = 0; i < 12; ++i) {
75 m_note->addItem(pianoNotes[i]); 75 m_note->addItem(pianoNotes[i]);
76 } 76 }
77 connect(m_note, SIGNAL(currentIndexChanged(int)), 77 connect(m_note, SIGNAL(currentIndexChanged(int)),
78 this, SLOT(noteChanged())); 78 this, SLOT(noteChanged()));
79 79
80 m_octave = new QSpinBox; 80 m_octave = new QSpinBox;
81 m_octave->setMinimum(-14); 81 m_octave->setMinimum(-14);
82 m_octave->setMaximum(15); 82 m_octave->setMaximum(15);
83 connect(m_octave, SIGNAL(valueChanged(int)), 83 connect(m_octave, SIGNAL(valueChanged(int)),
84 this, SLOT(octaveChanged())); 84 this, SLOT(octaveChanged()));
85 85
86 m_cents = new QDoubleSpinBox; 86 m_cents = new QDoubleSpinBox;
87 m_cents->setSuffix(tr(" cents")); 87 m_cents->setSuffix(tr(" cents"));
88 m_cents->setDecimals(4); 88 m_cents->setDecimals(4);
89 m_cents->setMinimum(-50); 89 m_cents->setMinimum(-50);
90 m_cents->setMaximum(50); 90 m_cents->setMaximum(50);
91 connect(m_cents, SIGNAL(valueChanged(double)), 91 connect(m_cents, SIGNAL(valueChanged(double)),
92 this, SLOT(centsChanged())); 92 this, SLOT(centsChanged()));
93 93
94 int row = 0; 94 int row = 0;
95 95
96 grid->addWidget(new QLabel(tr("In 12-tone Equal Temperament:")), row, 0, 1, 9); 96 grid->addWidget(new QLabel(tr("In 12-tone Equal Temperament:")), row, 0, 1, 9);
97 97
128 grid->addWidget(m_pitchPrefsLabel, row, 0, 1, 9); 128 grid->addWidget(m_pitchPrefsLabel, row, 0, 1, 9);
129 129
130 ++row; 130 ++row;
131 131
132 grid->addWidget 132 grid->addWidget
133 (new QLabel(tr("Note that only pitches in the range 0 to 127 are valid " 133 (new QLabel(tr("Note that only pitches in the range 0 to 127 are valid "
134 "in the MIDI protocol.")), 134 "in the MIDI protocol.")),
135 row, 0, 1, 9); 135 row, 0, 1, 9);
136 136
137 ++row; 137 ++row;
138 138
139 frame = new QFrame; 139 frame = new QFrame;
140 tabs->addTab(frame, tr("Tempo")); 140 tabs->addTab(frame, tr("Tempo"));
147 m_samples->setDecimals(2); 147 m_samples->setDecimals(2);
148 m_samples->setMinimum(1); 148 m_samples->setMinimum(1);
149 m_samples->setMaximum(1e8); 149 m_samples->setMaximum(1e8);
150 m_samples->setValue(22050); 150 m_samples->setValue(22050);
151 connect(m_samples, SIGNAL(valueChanged(double)), 151 connect(m_samples, SIGNAL(valueChanged(double)),
152 this, SLOT(samplesChanged())); 152 this, SLOT(samplesChanged()));
153 153
154 m_period = new QDoubleSpinBox; 154 m_period = new QDoubleSpinBox;
155 m_period->setSuffix(QString(" ms")); 155 m_period->setSuffix(QString(" ms"));
156 m_period->setDecimals(4); 156 m_period->setDecimals(4);
157 m_period->setMinimum(1e-3); 157 m_period->setMinimum(1e-3);
158 m_period->setMaximum(100000); 158 m_period->setMaximum(100000);
159 m_period->setValue(500); 159 m_period->setValue(500);
160 connect(m_period, SIGNAL(valueChanged(double)), 160 connect(m_period, SIGNAL(valueChanged(double)),
161 this, SLOT(periodChanged())); 161 this, SLOT(periodChanged()));
162 162
163 m_bpm = new QDoubleSpinBox; 163 m_bpm = new QDoubleSpinBox;
164 m_bpm->setSuffix(QString(" bpm")); 164 m_bpm->setSuffix(QString(" bpm"));
165 m_bpm->setDecimals(4); 165 m_bpm->setDecimals(4);
166 m_bpm->setMinimum(0.1); 166 m_bpm->setMinimum(0.1);
167 m_bpm->setMaximum(1e6); 167 m_bpm->setMaximum(1e6);
168 m_bpm->setValue(120); 168 m_bpm->setValue(120);
169 connect(m_bpm, SIGNAL(valueChanged(double)), 169 connect(m_bpm, SIGNAL(valueChanged(double)),
170 this, SLOT(bpmChanged())); 170 this, SLOT(bpmChanged()));
171 171
172 m_tempofreq = new QDoubleSpinBox; 172 m_tempofreq = new QDoubleSpinBox;
173 m_tempofreq->setSuffix(QString(" beats/sec")); 173 m_tempofreq->setSuffix(QString(" beats/sec"));
174 m_tempofreq->setDecimals(4); 174 m_tempofreq->setDecimals(4);
175 m_tempofreq->setMinimum(1e-3); 175 m_tempofreq->setMinimum(1e-3);
176 m_tempofreq->setMaximum(1e5); 176 m_tempofreq->setMaximum(1e5);
177 m_tempofreq->setValue(0.5); 177 m_tempofreq->setValue(0.5);
178 178
179 connect(m_tempofreq, SIGNAL(valueChanged(double)), 179 connect(m_tempofreq, SIGNAL(valueChanged(double)),
180 this, SLOT(tempofreqChanged())); 180 this, SLOT(tempofreqChanged()));
181 181
182 m_samplerate = new QComboBox; 182 m_samplerate = new QComboBox;
183 QList<int> rates; 183 QList<int> rates;
184 rates << 8000; 184 rates << 8000;
185 for (int i = 1; i <= 16; i *= 2) { 185 for (int i = 1; i <= 16; i *= 2) {
186 rates << 11025 * i << 12000 * i; 186 rates << 11025 * i << 12000 * i;
187 } 187 }
188 foreach (int r, rates) { 188 foreach (int r, rates) {
189 m_samplerate->addItem(QString("%1 Hz").arg(r)); 189 m_samplerate->addItem(QString("%1 Hz").arg(r));
190 } 190 }
191 connect(m_samplerate, SIGNAL(currentIndexChanged(int)), 191 connect(m_samplerate, SIGNAL(currentIndexChanged(int)),
192 this, SLOT(samplerateChanged())); 192 this, SLOT(samplerateChanged()));
193 m_samplerate->setCurrentText("44100 Hz"); 193 m_samplerate->setCurrentText("44100 Hz");
194 194
195 connect(Preferences::getInstance(), 195 connect(Preferences::getInstance(),
196 SIGNAL(propertyChanged(PropertyContainer::PropertyName)), 196 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
197 this, SLOT(preferenceChanged(PropertyContainer::PropertyName))); 197 this, SLOT(preferenceChanged(PropertyContainer::PropertyName)));
198 198
199 row = 0; 199 row = 0;
200 200
201 grid->setRowStretch(row, 20); 201 grid->setRowStretch(row, 20);
202 grid->setRowMinimumHeight(row, 8); 202 grid->setRowMinimumHeight(row, 8);
234 void 234 void
235 UnitConverter::setTo(QSpinBox *box, int value) 235 UnitConverter::setTo(QSpinBox *box, int value)
236 { 236 {
237 box->blockSignals(true); 237 box->blockSignals(true);
238 if (value < box->minimum() || value > box->maximum()) { 238 if (value < box->minimum() || value > box->maximum()) {
239 QPalette p; 239 QPalette p;
240 p.setColor(QPalette::Text, Qt::red); 240 p.setColor(QPalette::Text, Qt::red);
241 box->setPalette(p); 241 box->setPalette(p);
242 } else { 242 } else {
243 box->setPalette(QPalette()); 243 box->setPalette(QPalette());
244 } 244 }
245 box->setValue(value); 245 box->setValue(value);
246 box->blockSignals(false); 246 box->blockSignals(false);
247 } 247 }
248 248
249 void 249 void
250 UnitConverter::setTo(QDoubleSpinBox *box, double value) 250 UnitConverter::setTo(QDoubleSpinBox *box, double value)
251 { 251 {
252 box->blockSignals(true); 252 box->blockSignals(true);
253 if (value < box->minimum() || value > box->maximum()) { 253 if (value < box->minimum() || value > box->maximum()) {
254 QPalette p; 254 QPalette p;
255 p.setColor(QPalette::Text, Qt::red); 255 p.setColor(QPalette::Text, Qt::red);
256 box->setPalette(p); 256 box->setPalette(p);
257 } else { 257 } else {
258 box->setPalette(QPalette()); 258 box->setPalette(QPalette());
259 } 259 }
260 box->setValue(value); 260 box->setValue(value);
261 box->blockSignals(false); 261 box->blockSignals(false);
262 } 262 }
263 263
270 270
271 void 271 void
272 UnitConverter::updatePitchPrefsLabel() 272 UnitConverter::updatePitchPrefsLabel()
273 { 273 {
274 m_pitchPrefsLabel->setText 274 m_pitchPrefsLabel->setText
275 (tr("With concert-A tuning frequency at %1 Hz, and " 275 (tr("With concert-A tuning frequency at %1 Hz, and "
276 "middle C residing in octave %2.\n" 276 "middle C residing in octave %2.\n"
277 "(These can be changed in the application preferences.)") 277 "(These can be changed in the application preferences.)")
278 .arg(Preferences::getInstance()->getTuningFrequency()) 278 .arg(Preferences::getInstance()->getTuningFrequency())
279 .arg(Preferences::getInstance()->getOctaveOfMiddleC())); 279 .arg(Preferences::getInstance()->getOctaveOfMiddleC()));
280 } 280 }
281 281
282 void 282 void
283 UnitConverter::freqChanged() 283 UnitConverter::freqChanged()
284 { 284 {
294 294
295 void 295 void
296 UnitConverter::noteChanged() 296 UnitConverter::noteChanged()
297 { 297 {
298 int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), 298 int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(),
299 m_octave->value()); 299 m_octave->value());
300 double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value()); 300 double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value());
301 m_freq->setValue(freq); 301 m_freq->setValue(freq);
302 } 302 }
303 303
304 void 304 void
305 UnitConverter::octaveChanged() 305 UnitConverter::octaveChanged()
306 { 306 {
307 int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), 307 int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(),
308 m_octave->value()); 308 m_octave->value());
309 double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value()); 309 double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value());
310 m_freq->setValue(freq); 310 m_freq->setValue(freq);
311 } 311 }
312 312
313 void 313 void