Mercurial > hg > svgui
changeset 885:6778a82d6b76
Adding the unit converter code might have enhanced the previous commit a little
author | Chris Cannam |
---|---|
date | Tue, 02 Dec 2014 13:30:24 +0000 |
parents | 8be34e5ef7ff |
children | 01cceacee3da |
files | widgets/UnitConverter.cpp widgets/UnitConverter.h |
diffstat | 2 files changed, 197 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/UnitConverter.cpp Tue Dec 02 13:30:24 2014 +0000 @@ -0,0 +1,146 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "UnitConverter.h" + +#include <QSpinBox> +#include <QComboBox> +#include <QDoubleSpinBox> +#include <QLabel> +#include <QDialogButtonBox> +#include <QGridLayout> + +#include "base/Debug.h" +#include "base/Pitch.h" + +using namespace std; + +UnitConverter::UnitConverter(QWidget *parent) : + QDialog(parent) +{ + QGridLayout *grid = new QGridLayout; + setLayout(grid); + + m_hz = new QDoubleSpinBox; + m_hz->setSuffix(QString(" Hz")); + m_hz->setDecimals(6); + m_hz->setMinimum(1e-6); + m_hz->setMaximum(1e6); + m_hz->setValue(440); + connect(m_hz, SIGNAL(valueChanged(double)), + this, SLOT(hzChanged(double))); + + m_midi = new QSpinBox; + m_midi->setMinimum(0); + m_midi->setMaximum(127); + connect(m_midi, SIGNAL(valueChanged(int)), + this, SLOT(midiChanged(int))); + + m_note = new QComboBox; + //!!! + + m_octave = new QSpinBox; + //!!! + + m_cents = new QDoubleSpinBox; + m_cents->setSuffix(tr(" cents")); + m_cents->setDecimals(4); + m_cents->setMinimum(-50); + m_cents->setMaximum(50); + connect(m_cents, SIGNAL(valueChanged(double)), + this, SLOT(centsChanged(double))); + + m_piano = new QSpinBox; + //!!! + + grid->addWidget(m_hz, 1, 0); + grid->addWidget(new QLabel(tr("=")), 1, 1); + + grid->addWidget(new QLabel(tr("MIDI note")), 1, 2, 1, 2); + grid->addWidget(m_midi, 1, 4); + + grid->addWidget(new QLabel(tr("+")), 1, 5); + grid->addWidget(m_cents, 1, 6); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); + grid->addWidget(bb, 2, 0, 1, 7); + connect(bb, SIGNAL(rejected()), this, SLOT(close())); + + updateAllFromHz(); +} + +UnitConverter::~UnitConverter() +{ +} + +void +UnitConverter::hzChanged(double hz) +{ + cerr << "hzChanged: " << hz << endl; + updateAllFromHz(); +} + +void +UnitConverter::midiChanged(int midi) +{ + cerr << "midiChanged: " << midi << endl; + m_hz->setValue(Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value())); + updateAllFromHz(); +} + +void +UnitConverter::noteChanged(int note) +{ + cerr << "noteChanged: " << note << endl; +} + +void +UnitConverter::octaveChanged(int oct) +{ + cerr << "octaveChanged: " << oct << endl; +} + +void +UnitConverter::centsChanged(double cents) +{ + cerr << "centsChanged: " << cents << endl; + m_hz->setValue(Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value())); + updateAllFromHz(); +} + +void +UnitConverter::pianoChanged(int piano) +{ + cerr << "pianoChanged: " << piano << endl; +} + +void +UnitConverter::updateAllFromHz() +{ + float cents = 0; + int pitch = Pitch::getPitchForFrequency(m_hz->value(), ¢s); + + m_midi->blockSignals(true); + m_cents->blockSignals(true); + + m_midi->setValue(pitch); + m_cents->setValue(cents); + + m_midi->blockSignals(false); + m_cents->blockSignals(false); +} + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/UnitConverter.h Tue Dec 02 13:30:24 2014 +0000 @@ -0,0 +1,51 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef UNIT_CONVERTER_H +#define UNIT_CONVERTER_H + +#include <QDialog> + +class QSpinBox; +class QDoubleSpinBox; +class QComboBox; + +class UnitConverter : public QDialog +{ + Q_OBJECT + +public: + UnitConverter(QWidget *parent = 0); + virtual ~UnitConverter(); + +private slots: + void hzChanged(double); + void midiChanged(int); + void noteChanged(int); + void octaveChanged(int); + void centsChanged(double); + void pianoChanged(int); + +private: + QDoubleSpinBox *m_hz; + QSpinBox *m_midi; + QComboBox *m_note; + QSpinBox *m_octave; + QDoubleSpinBox *m_cents; + QSpinBox *m_piano; + + void updateAllFromHz(); +}; + +#endif