Mercurial > hg > svgui
comparison widgets/UnitConverter.cpp @ 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 | |
children | 01cceacee3da |
comparison
equal
deleted
inserted
replaced
884:8be34e5ef7ff | 885:6778a82d6b76 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #include "UnitConverter.h" | |
16 | |
17 #include <QSpinBox> | |
18 #include <QComboBox> | |
19 #include <QDoubleSpinBox> | |
20 #include <QLabel> | |
21 #include <QDialogButtonBox> | |
22 #include <QGridLayout> | |
23 | |
24 #include "base/Debug.h" | |
25 #include "base/Pitch.h" | |
26 | |
27 using namespace std; | |
28 | |
29 UnitConverter::UnitConverter(QWidget *parent) : | |
30 QDialog(parent) | |
31 { | |
32 QGridLayout *grid = new QGridLayout; | |
33 setLayout(grid); | |
34 | |
35 m_hz = new QDoubleSpinBox; | |
36 m_hz->setSuffix(QString(" Hz")); | |
37 m_hz->setDecimals(6); | |
38 m_hz->setMinimum(1e-6); | |
39 m_hz->setMaximum(1e6); | |
40 m_hz->setValue(440); | |
41 connect(m_hz, SIGNAL(valueChanged(double)), | |
42 this, SLOT(hzChanged(double))); | |
43 | |
44 m_midi = new QSpinBox; | |
45 m_midi->setMinimum(0); | |
46 m_midi->setMaximum(127); | |
47 connect(m_midi, SIGNAL(valueChanged(int)), | |
48 this, SLOT(midiChanged(int))); | |
49 | |
50 m_note = new QComboBox; | |
51 //!!! | |
52 | |
53 m_octave = new QSpinBox; | |
54 //!!! | |
55 | |
56 m_cents = new QDoubleSpinBox; | |
57 m_cents->setSuffix(tr(" cents")); | |
58 m_cents->setDecimals(4); | |
59 m_cents->setMinimum(-50); | |
60 m_cents->setMaximum(50); | |
61 connect(m_cents, SIGNAL(valueChanged(double)), | |
62 this, SLOT(centsChanged(double))); | |
63 | |
64 m_piano = new QSpinBox; | |
65 //!!! | |
66 | |
67 grid->addWidget(m_hz, 1, 0); | |
68 grid->addWidget(new QLabel(tr("=")), 1, 1); | |
69 | |
70 grid->addWidget(new QLabel(tr("MIDI note")), 1, 2, 1, 2); | |
71 grid->addWidget(m_midi, 1, 4); | |
72 | |
73 grid->addWidget(new QLabel(tr("+")), 1, 5); | |
74 grid->addWidget(m_cents, 1, 6); | |
75 | |
76 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); | |
77 grid->addWidget(bb, 2, 0, 1, 7); | |
78 connect(bb, SIGNAL(rejected()), this, SLOT(close())); | |
79 | |
80 updateAllFromHz(); | |
81 } | |
82 | |
83 UnitConverter::~UnitConverter() | |
84 { | |
85 } | |
86 | |
87 void | |
88 UnitConverter::hzChanged(double hz) | |
89 { | |
90 cerr << "hzChanged: " << hz << endl; | |
91 updateAllFromHz(); | |
92 } | |
93 | |
94 void | |
95 UnitConverter::midiChanged(int midi) | |
96 { | |
97 cerr << "midiChanged: " << midi << endl; | |
98 m_hz->setValue(Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value())); | |
99 updateAllFromHz(); | |
100 } | |
101 | |
102 void | |
103 UnitConverter::noteChanged(int note) | |
104 { | |
105 cerr << "noteChanged: " << note << endl; | |
106 } | |
107 | |
108 void | |
109 UnitConverter::octaveChanged(int oct) | |
110 { | |
111 cerr << "octaveChanged: " << oct << endl; | |
112 } | |
113 | |
114 void | |
115 UnitConverter::centsChanged(double cents) | |
116 { | |
117 cerr << "centsChanged: " << cents << endl; | |
118 m_hz->setValue(Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value())); | |
119 updateAllFromHz(); | |
120 } | |
121 | |
122 void | |
123 UnitConverter::pianoChanged(int piano) | |
124 { | |
125 cerr << "pianoChanged: " << piano << endl; | |
126 } | |
127 | |
128 void | |
129 UnitConverter::updateAllFromHz() | |
130 { | |
131 float cents = 0; | |
132 int pitch = Pitch::getPitchForFrequency(m_hz->value(), ¢s); | |
133 | |
134 m_midi->blockSignals(true); | |
135 m_cents->blockSignals(true); | |
136 | |
137 m_midi->setValue(pitch); | |
138 m_cents->setValue(cents); | |
139 | |
140 m_midi->blockSignals(false); | |
141 m_cents->blockSignals(false); | |
142 } | |
143 | |
144 | |
145 | |
146 |