# HG changeset patch # User Chris Cannam # Date 1418053069 0 # Node ID cb3a3e20634d42ac3b2f8c0221f0cb81b2287076 # Parent 139aad8bb445e1e6c4d6f76f835de8e6b0c4533b Fixes to limits etc in unit converter diff -r 139aad8bb445 -r cb3a3e20634d widgets/UnitConverter.cpp --- a/widgets/UnitConverter.cpp Tue Dec 02 17:53:17 2014 +0000 +++ b/widgets/UnitConverter.cpp Mon Dec 08 15:37:49 2014 +0000 @@ -23,6 +23,7 @@ #include "base/Debug.h" #include "base/Pitch.h" +#include "base/Preferences.h" using namespace std; @@ -40,15 +41,18 @@ m_hz = new QDoubleSpinBox; m_hz->setSuffix(QString(" Hz")); m_hz->setDecimals(6); - m_hz->setMinimum(1e-6); + m_hz->setMinimum(1e-3); m_hz->setMaximum(1e6); m_hz->setValue(440); connect(m_hz, SIGNAL(valueChanged(double)), this, SLOT(hzChanged(double))); + // The min and max range values for all the remaining controls are + // determined by the min and max Hz above + m_midi = new QSpinBox; - m_midi->setMinimum(0); - m_midi->setMaximum(127); + m_midi->setMinimum(-156); + m_midi->setMaximum(203); connect(m_midi, SIGNAL(valueChanged(int)), this, SLOT(midiChanged(int))); @@ -60,8 +64,8 @@ this, SLOT(noteChanged(int))); m_octave = new QSpinBox; - m_octave->setMinimum(-4); - m_octave->setMaximum(12); + m_octave->setMinimum(-14); + m_octave->setMaximum(15); connect(m_octave, SIGNAL(valueChanged(int)), this, SLOT(octaveChanged(int))); @@ -91,11 +95,28 @@ ++row; - grid->addWidget(new QLabel(tr("MIDI note")), row, 2, 1, 2); + grid->addWidget(new QLabel(tr("MIDI pitch")), row, 2, 1, 2); grid->addWidget(m_midi, row, 4); ++row; + grid->addWidget + (new QLabel(tr("With concert A tuning frequency at %1 Hz, and " + "middle C residing in octave %2.\n" + "(These can be changed in the application preferences.)") + .arg(Preferences::getInstance()->getTuningFrequency()) + .arg(Preferences::getInstance()->getOctaveOfMiddleC())), + row, 0, 1, 9); + + ++row; + + grid->addWidget + (new QLabel(tr("Note that only pitches in the range 0 to 127 are valid " + "in the MIDI protocol.")), + row, 0, 1, 9); + + ++row; + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); grid->addWidget(bb, row, 0, 1, 9); connect(bb, SIGNAL(rejected()), this, SLOT(close())); @@ -118,8 +139,9 @@ UnitConverter::midiChanged(int midi) { cerr << "midiChanged: " << midi << endl; - m_hz->setValue(Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value())); - updateAllFromHz(); + double hz = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); + cerr << "hz -> " << hz << endl; + m_hz->setValue(hz); } void @@ -128,21 +150,29 @@ cerr << "noteChanged: " << note << endl; int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), m_octave->value()); - m_hz->setValue(Pitch::getFrequencyForPitch(pitch, m_cents->value())); + double hz = Pitch::getFrequencyForPitch(pitch, m_cents->value()); + cerr << "hz -> " << hz << endl; + m_hz->setValue(hz); } void UnitConverter::octaveChanged(int oct) { cerr << "octaveChanged: " << oct << endl; + int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), + m_octave->value()); + double hz = Pitch::getFrequencyForPitch(pitch, m_cents->value()); + cerr << "hz -> " << hz << endl; + m_hz->setValue(hz); } void UnitConverter::centsChanged(double cents) { cerr << "centsChanged: " << cents << endl; - m_hz->setValue(Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value())); - updateAllFromHz(); + double hz = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); + cerr << "hz -> " << hz << endl; + m_hz->setValue(hz); } void @@ -159,6 +189,8 @@ int note, octave; Pitch::getNoteAndOctaveForPitch(pitch, note, octave); + cerr << "pitch " << pitch << " note " << note << " octave " << octave << " cents " << cents << endl; + m_midi->blockSignals(true); m_cents->blockSignals(true); m_note->blockSignals(true);