19 #include <QDoubleSpinBox> 21 #include <QDialogButtonBox> 22 #include <QGridLayout> 25 #include "base/Debug.h" 26 #include "base/Pitch.h" 27 #include "base/Preferences.h" 32 "C",
"C# / Db",
"D",
"D# / Eb",
"E",
33 "F",
"F# / Gb",
"G",
"G# / Ab",
"A",
"A# / Bb",
"B" 39 QGridLayout *maingrid =
new QGridLayout;
42 QTabWidget *tabs =
new QTabWidget;
43 maingrid->addWidget(tabs, 0, 0);
45 QDialogButtonBox *bb =
new QDialogButtonBox(QDialogButtonBox::Close);
46 maingrid->addWidget(bb, 1, 0);
47 connect(bb, SIGNAL(rejected()),
this, SLOT(close()));
49 QFrame *frame =
new QFrame;
50 tabs->addTab(frame, tr(
"Pitch"));
52 QGridLayout *grid =
new QGridLayout;
53 frame->setLayout(grid);
55 m_freq =
new QDoubleSpinBox;
56 m_freq->setSuffix(QString(
" Hz"));
61 connect(
m_freq, SIGNAL(valueChanged(
double)),
70 connect(
m_midi, SIGNAL(valueChanged(
int)),
74 for (
int i = 0; i < 12; ++i) {
77 connect(
m_note, SIGNAL(currentIndexChanged(
int)),
83 connect(
m_octave, SIGNAL(valueChanged(
int)),
87 m_cents->setSuffix(tr(
" cents"));
91 connect(
m_cents, SIGNAL(valueChanged(
double)),
96 grid->addWidget(
new QLabel(tr(
"In 12-tone Equal Temperament:")), row, 0, 1, 9);
100 grid->setRowMinimumHeight(row, 8);
104 grid->addWidget(
m_freq, row, 0, 2, 1, Qt::AlignRight | Qt::AlignVCenter);
105 grid->addWidget(
new QLabel(tr(
"=")), row, 1, 2, 1, Qt::AlignHCenter | Qt::AlignVCenter);
107 grid->addWidget(
new QLabel(tr(
"+")), row, 7, 2, 1, Qt::AlignHCenter | Qt::AlignVCenter);
108 grid->addWidget(
m_cents, row, 8, 2, 1, Qt::AlignLeft | Qt::AlignVCenter);
110 grid->addWidget(
new QLabel(tr(
"Piano note")), row, 2, 1, 2);
111 grid->addWidget(
m_note, row, 4);
112 grid->addWidget(
new QLabel(tr(
"in octave")), row, 5);
117 grid->addWidget(
new QLabel(tr(
"MIDI pitch")), row, 2, 1, 2);
118 grid->addWidget(
m_midi, row, 4);
122 grid->setRowStretch(row, 20);
123 grid->setRowMinimumHeight(row, 8);
133 (
new QLabel(tr(
"Note that only pitches in the range 0 to 127 are valid " 134 "in the MIDI protocol.")),
140 tabs->addTab(frame, tr(
"Tempo"));
142 grid =
new QGridLayout;
143 frame->setLayout(grid);
146 m_samples->setSuffix(QString(
" samples"));
151 connect(
m_samples, SIGNAL(valueChanged(
double)),
155 m_period->setSuffix(QString(
" ms"));
160 connect(
m_period, SIGNAL(valueChanged(
double)),
163 m_bpm =
new QDoubleSpinBox;
164 m_bpm->setSuffix(QString(
" bpm"));
165 m_bpm->setDecimals(4);
166 m_bpm->setMinimum(0.1);
167 m_bpm->setMaximum(1e6);
168 m_bpm->setValue(120);
169 connect(
m_bpm, SIGNAL(valueChanged(
double)),
185 for (
int i = 1; i <= 16; i *= 2) {
186 rates << 11025 * i << 12000 * i;
188 foreach (
int r, rates) {
195 connect(Preferences::getInstance(),
196 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
201 grid->setRowStretch(row, 20);
202 grid->setRowMinimumHeight(row, 8);
206 grid->addWidget(
new QLabel(tr(
"Beat period")), row, 0, 2, 1, Qt::AlignVCenter);
208 grid->addWidget(
new QLabel(tr(
"=")), row, 2, 2, 1, Qt::AlignVCenter);
212 grid->addWidget(
new QLabel(tr(
"at")), row, 4, 2, 1, Qt::AlignVCenter);
213 grid->addWidget(
m_samplerate, row, 5, 2, 1, Qt::AlignVCenter);
218 grid->addWidget(
m_bpm, row, 3);
222 grid->setRowStretch(row, 20);
223 grid->setRowMinimumHeight(row, 8);
237 box->blockSignals(
true);
238 if (value < box->minimum() || value > box->maximum()) {
240 p.setColor(QPalette::Text, Qt::red);
243 box->setPalette(QPalette());
245 box->setValue(value);
246 box->blockSignals(
false);
252 box->blockSignals(
true);
253 if (value < box->minimum() || value > box->maximum()) {
255 p.setColor(QPalette::Text, Qt::red);
258 box->setPalette(QPalette());
260 box->setValue(value);
261 box->blockSignals(
false);
275 (tr(
"With concert-A tuning frequency at %1 Hz, and " 276 "middle C residing in octave %2.\n" 277 "(These can be changed in the application preferences.)")
278 .arg(Preferences::getInstance()->getTuningFrequency())
279 .arg(Preferences::getInstance()->getOctaveOfMiddleC()));
291 double freq = Pitch::getFrequencyForPitch(
m_midi->value(),
m_cents->value());
298 int pitch = Pitch::getPitchForNoteAndOctave(
m_note->currentIndex(),
300 double freq = Pitch::getFrequencyForPitch(pitch,
m_cents->value());
307 int pitch = Pitch::getPitchForNoteAndOctave(
m_note->currentIndex(),
309 double freq = Pitch::getFrequencyForPitch(pitch,
m_cents->value());
316 double freq = Pitch::getFrequencyForPitch(
m_midi->value(),
m_cents->value());
324 int pitch = Pitch::getPitchForFrequency(
m_freq->value(), ¢s);
326 Pitch::getNoteAndOctaveForPitch(pitch, note, octave);
334 m_note->blockSignals(
true);
335 m_note->setCurrentIndex(note);
336 m_note->blockSignals(
false);
349 double sec =
m_period->value() / 1000.0;
350 double samples = rate * sec;
358 double sec = 60.0 /
m_bpm->value();
359 double samples = rate * sec;
381 return double(atoi(
m_samplerate->currentText().toLocal8Bit().data()));
392 double sec = samples / rate;
393 double hz = rate / samples;
394 double bpm = 60.0 / sec;
QDoubleSpinBox * m_tempofreq
UnitConverter(QWidget *parent=0)
void updatePitchesFromFreq()
void preferenceChanged(PropertyContainer::PropertyName)
QLabel * m_pitchPrefsLabel
static QString pianoNotes[]
QDoubleSpinBox * m_period
void setTo(QSpinBox *, int)
void updatePitchPrefsLabel()
void updateTempiFromSamples()
QDoubleSpinBox * m_samples