Debian Codegraph @

src/modules/MicrotonalView.cpp

raw
1 // Copyright 2004 "Gilles Degottex"
2
3 // This file is part of "fmit"
4
5 // "fmit" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // "fmit" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 #include "MicrotonalView.h"
20
21 static const unsigned char g_icon_ji[] = {
22 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
23 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
24 0x08, 0x06, 0x00, 0x00, 0x00, 0x73, 0x7a, 0x7a, 0xf4, 0x00, 0x00, 0x05,
25 0xc3, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0xb5, 0x97, 0x4b, 0x6c, 0x24,
26 0xc5, 0x19, 0xc7, 0x7f, 0x55, 0xfd, 0x98, 0x5d, 0x7b, 0x1e, 0x1e, 0xdb,
27 0x0c, 0xb3, 0xbb, 0xf6, 0x78, 0xed, 0xf1, 0xda, 0xe0, 0x85, 0x95, 0x80,
28 0x43, 0x88, 0x90, 0x15, 0xb8, 0x70, 0x88, 0xc0, 0x42, 0xe2, 0x86, 0xc4,
29 0x85, 0xa0, 0x58, 0x4a, 0x4e, 0x44, 0x8a, 0x84, 0x72, 0x8a, 0xb4, 0x70,
30 0x08, 0x91, 0x12, 0x5e, 0x97, 0x91, 0x78, 0x48, 0x51, 0x24, 0x94, 0x70,
31 0xca, 0x04, 0x89, 0x03, 0x52, 0x72, 0x18, 0xe5, 0xc4, 0x29, 0x2c, 0x9b,
32 0x08, 0xd6, 0x6b, 0x0f, 0xcc, 0xcb, 0x5e, 0xcf, 0xf8, 0xbd, 0x9e, 0x99,
33 0x6e, 0x4f, 0x17, 0x87, 0xee, 0x9e, 0x99, 0x6e, 0x8f, 0xd7, 0xcb, 0xeb,
34 0x93, 0x4a, 0xdd, 0x35, 0xea, 0xaf, 0xfe, 0xbf, 0xfa, 0x7f, 0x55, 0xd5,
35 0xd3, 0x82, 0x1f, 0x28, 0x16, 0x97, 0x96, 0x47, 0x80, 0x14, 0x70, 0xaf,
36 0x77, 0xed, 0x6f, 0x6d, 0xe0, 0xdd, 0x42, 0x3e, 0x77, 0x3d, 0x9c, 0x27,
37 0xee, 0x72, 0xf0, 0x33, 0xc0, 0x14, 0x30, 0x3d, 0xa0, 0xa5, 0x81, 0x7b,
38 0x00, 0xf3, 0x94, 0x61, 0x1c, 0x20, 0x5b, 0xc8, 0xe7, 0x8a, 0xfd, 0x3f,
39 0xea, 0x21, 0x21, 0x09, 0xfc, 0x04, 0x78, 0x12, 0xb8, 0x14, 0x12, 0x39,
40 0x06, 0x2b, 0x84, 0x20, 0x16, 0x1d, 0x22, 0x1e, 0x1b, 0x26, 0x11, 0x1b,
41 0x26, 0x1e, 0x8b, 0x32, 0x12, 0x8f, 0x12, 0x8f, 0x0d, 0x13, 0x8f, 0x0f,
42 0x93, 0x88, 0x45, 0x11, 0xc0, 0x87, 0xff, 0xfc, 0x17, 0xc5, 0x52, 0x4d,
43 0x02, 0xbf, 0x04, 0x7e, 0x37, 0x10, 0x60, 0x71, 0x69, 0xf9, 0x37, 0xc0,
44 0xcb, 0xde, 0x6c, 0x10, 0x42, 0x30, 0x79, 0x3e, 0xc5, 0xec, 0xcc, 0x24,
45 0xd9, 0x8b, 0x17, 0x18, 0x1f, 0x1d, 0xe9, 0x8a, 0xc4, 0xa3, 0xc3, 0x98,
46 0x67, 0x86, 0x10, 0x7a, 0x84, 0x96, 0xad,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df, 0xb1, 0x69, 0xec, 0x1f, 0x21, 0x05, 0x98,
62 0x86, 0xc0, 0x51, 0x82, 0x7a, 0xbd, 0xc1, 0xe7, 0xd7, 0x3e, 0xa7, 0x54,
63 0x29, 0x53, 0x2e, 0x95, 0xd9, 0xdc, 0xdc, 0x44, 0x29, 0x05, 0x80, 0x69,
64 0x98, 0x5c, 0x9c, 0x99, 0x21, 0x62, 0x4a, 0x22, 0xba, 0x40, 0x21, 0xe8,
65 0x38, 0x0a, 0xa5, 0x04, 0x8e, 0x82, 0x96, 0xed, 0x90, 0x4a, 0x9c, 0x61,
66 0x6c, 0x34, 0x41, 0x63, 0x6b, 0x17, 0xe0, 0x32, 0x30, 0x18, 0x20, 0x7d,
67 0xcf, 0x28, 0x07, 0xcd, 0x0e, 0xa6, 0x2e, 0x50, 0x4a, 0xa0, 0x70, 0x67,
68 0xb2, 0xb1, 0x5e, 0xe3, 0x1f, 0xf9, 0x3c, 0xa6, 0x61, 0x60, 0xd9, 0x76,
69 0xc0, 0xc2, 0x5f, 0xbc, 0xf8, 0x22, 0x53, 0xd3, 0xd3, 0xae, 0xfd, 0x9e,
70 0x43, 0x4a, 0x09, 0xb7, 0x14, 0x80, 0x7d, 0xe4, 0x82, 0x4e, 0x5d, 0x48,
71 0xfb, 0x00, 0x0b, 0xc0, 0xbf, 0xfd, 0x7c, 0xe9, 0x5d, 0x93, 0x00, 0xe9,
72 0xd4, 0x18, 0xba, 0x26, 0x30, 0x34, 0x81, 0xa1, 0xbb, 0x57, 0x53, 0x13,
73 0x3c, 0x74, 0x65, 0x81, 0x3f, 0xfd, 0xf1, 0x55, 0xde, 0xf8, 0xf3, 0x6b,
74 0x3c, 0x78, 0x39, 0x58, 0xc6, 0x56, 0xf3, 0x36, 0x11, 0x5d, 0x62, 0xea,
75 0x82, 0x88, 0x2e, 0xbb, 0xf7, 0xa6, 0xe1, 0x3a, 0x62, 0x77, 0x5c, 0x80,
76 0xc9, 0x5e, 0x19, 0x2e, 0xf7, 0xe7, 0xfb, 0x00, 0x6d, 0x80, 0xe4, 0x48,
77 0x8c, 0x88, 0xd1, 0x13, 0x37, 0x34, 0x81, 0xae, 0x0b, 0xce, 0x9e, 0x31,
78 0x48, 0xc4, 0x86, 0x31, 0x34, 0xc1, 0xa5, 0xd9, 0x99, 0x00, 0x40, 0xb5,
79 0x5a, 0x71, 0x05, 0x3d, 0x61, 0xa3, 0xef, 0xde, 0xd4, 0x25, 0x1d, 0xc7,
80 0x05, 0xc8, 0x9c, 0x00, 0xe0, 0x97, 0x60, 0x0b, 0x88, 0xb6, 0x5a, 0x16,
81 0xf1, 0xa4, 0x44, 0x29, 0x07, 0x47, 0x81, 0x02, 0xcf, 0xd2, 0x5e, 0xcb,
82 0x4e, 0x4f, 0x06, 0x00, 0xca, 0xa5, 0x12, 0x86, 0x2e, 0x7a, 0xd6, 0xfb,
83 0xbb, 0x41, 0x09, 0x4c, 0x5d, 0x30, 0x16, 0x73, 0x25, 0x32, 0x13, 0x69,
84 0x3f, 0x25, 0x60, 0xa1, 0xef, 0xc0, 0x16, 0xc0, 0xed, 0x66, 0x13, 0x43,
85 0x17, 0x68, 0xd2, 0x73, 0x40, 0xd2, 0x75, 0xc2, 0x77, 0x23, 0x0c, 0xf0,
86 0x75, 0xb9, 0xd2, 0x7b, 0x46, 0x17, 0x18, 0xba, 0x24, 0x76, 0x56, 0x63,
87 0x3a, 0x15, 0xe1, 0xfe, 0x89, 0xb3, 0x8c, 0x0c, 0xeb, 0x61, 0x07, 0xc6,
88 0x17, 0x97, 0x96, 0x53, 0x61, 0x07, 0xb6, 0x01, 0x6e, 0xdf, 0x6e, 0xa2,
89 0x6b, 0x02, 0x5d, 0x73, 0x17, 0x20, 0xfe, 0xcc, 0x7d, 0x27, 0x50, 0x24,
90 0x13, 0x51, 0xc6, 0x46, 0x93, 0x34, 0xb6, 0xb6, 0x01, 0xd8, 0xdf, 0x3f,
91 0x60, 0x7f, 0x6f, 0x87, 0xe4, 0x48, 0x12, 0xd3, 0x10, 0x24, 0x86, 0x74,
92 0x86, 0x22, 0xfe, 0xbc, 0x7a, 0x91, 0x4e, 0x8d, 0x61, 0x9a, 0x06, 0x96,
93 0x65, 0xfb, 0x65, 0xb8, 0x75, 0xdc, 0x81, 0xc3, 0x16, 0x9a, 0x04, 0x5d,
94 0x03, 0x5d, 0x82, 0xa6, 0x09, 0xb7, 0x49, 0x17, 0x4a, 0x97, 0x12, 0x5d,
95 0x1e, 0x77, 0xa1, 0x56, 0xad, 0x92, 0x4e, 0x1a, 0x9c, 0x4b, 0x9a, 0x03,
96 0xc5, 0xc1, 0x3f, 0x59, 0xbb, 0x2e, 0x74, 0xcb, 0x10, 0x2a, 0x41, 0x0b,
97 0x4d, 0x8a, 0x40, 0xd3, 0xa5, 0x40, 0xd7, 0x40, 0x93, 0xa0, 0x69, 0x2e,
98 0xd4, 0x6c, 0x08, 0x60, 0xbd, 0x56, 0x25, 0x62, 0x0c, 0x16, 0xee, 0x8f,
99 0xe9, 0xcc, 0x39, 0xff, 0xb6, 0xbb, 0x10, 0x03, 0x25, 0x38, 0x3c, 0x6c,
100 0x22, 0x05, 0x68, 0x52, 0x74, 0xad, 0x47, 0x29, 0x14, 0xfd, 0x7d, 0x98,
101 0x9b, 0xc9, 0x04, 0x06, 0xfe, 0xf2, 0xe6, 0xd7, 0xa7, 0x8a, 0x03, 0x5c,
102 0x9c, 0x3c, 0x19, 0xa0, 0x0e, 0xb0, 0xb3, 0x77, 0x80, 0x10, 0x02, 0x29,
103 0x14, 0x4a, 0xb8, 0x62, 0x4a, 0xb8, 0x2f, 0x41, 0x1f, 0x40, 0x00, 0x57,
104 0xee, 0x9f, 0x0e, 0x02, 0xac, 0x7e, 0x6b, 0x80, 0x63, 0x25, 0x28, 0x02,
105 0xd4, 0x36, 0xea, 0x08, 0x40, 0x0a, 0x81, 0x26, 0x04, 0x52, 0x0a, 0xa4,
106 0x04, 0x29, 0x40, 0x4a, 0x30, 0x35, 0xc1, 0x50, 0x44, 0x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bc, 0x09, 0x5c, 0x07, 0xfe, 0x06, 0xbc, 0x09, 0xa1, 0x85, 0xbe,
137 0xb8, 0xb4, 0xbc, 0x0a, 0x4c, 0xbf, 0x7e, 0xf5, 0x25, 0x1e, 0xbe, 0x32,
138 0x1f, 0xc8, 0x74, 0x1c, 0x87, 0xca, 0xfa, 0x26, 0x2b, 0x9e, 0xc8, 0xca,
139 0x5a, 0x89, 0x95, 0xb5, 0x32, 0x9b, 0x8d, 0x9d, 0x93, 0xd8, 0x8a, 0xc0,
140 0x67, 0xa1, 0x76, 0xa3, 0x90, 0xcf, 0x05, 0xc8, 0xf4, 0x50, 0xd2, 0xc7,
141 0xc0, 0xaf, 0xfe, 0xf0, 0xd6, 0x5f, 0x78, 0xf2, 0x89, 0x47, 0xe9, 0x74,
142 0x3a, 0xec, 0xee, 0x1d, 0xb0, 0xfa, 0x55, 0x85, 0x9b, 0xc5, 0x0a, 0xad,
143 0xb6, 0x35, 0x48, 0x68, 0x1f, 0xb8, 0x16, 0x12, 0xba, 0x56, 0xc8, 0xe7,
144 0x4e, 0x7f, 0x39, 0x70, 0xdc, 0x81, 0xf3, 0xc0, 0x27, 0x0c, 0xf8, 0x82,
145 0xc1, 0xfd, 0x36, 0x59, 0x19, 0x30, 0xab, 0x62, 0x21, 0x9f, 0x53, 0x77,
146 0x23, 0x76, 0x2a, 0x80, 0x07, 0x61, 0x02, 0x8f, 0x03, 0x4f, 0x7b, 0xa2,
147 0xbe, 0xd0, 0xf5, 0x42, 0x3e, 0x77, 0x18, 0x7e, 0xfe, 0xfb, 0xc6, 0x37,
148 0xa1, 0xfe, 0x5a, 0x08, 0x89, 0xe7, 0x8c, 0xbc, 0x00, 0x00, 0x00, 0x00,
149 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
150 };
151
152 #include <cassert>
153 #include <iostream>
154 #include <fstream>
155 #include <sstream>
156 using namespace std;
157 #include <qlayout.h>
158 #include <qpainter.h>
159 #ifdef QT3_SUPPORT
160 #include <q3filedialog.h>
161 #else
162 #include <qfiledialog.h>
163 #endif
164 #include <qdir.h>
165 #include <qmessagebox.h>
166 // #include <qregexp.h>
167 #include <QActionGroup>
168 #include <QRegularExpression>
169 #include <qimage.h>
170 #include <qevent.h>
171 #include <qwidgetaction.h>
172 #include <Music/Music.h>
173 using namespace Music;
174
175 #include "../qthelper.h"
176
177 // ---------------------- MScale ------------------------------
178
179 void MScale::load_scala(const QString& file_name)
180 {
181 ifstream file(file_name.toLatin1().constData());
182
183 if(!file.is_open())
184 throw MicrotonalView::tr("Unkown filename: '")+file_name+"'";
185
186 int lines_red = 0;
187 int num_line = 1;
188
189 char buff[1024];
190 file.getline(buff, 1024);
191 while(file)
192 {
193 if(buff[0]!='!')
194 {
195 if(lines_red==0)
196 {
197 m_name = QString(buff);
198 m_name = m_name.remove("\r");
199 m_name = m_name.remove("\n");
200 m_name = m_name.simplified();
201 lines_red++;
202 }
203 else if(lines_red==1)
204 {
205 // ignore number of lines ...
206 lines_red++;
207 }
208 else
209 {
210 bool is_ratio = true;
211 for(size_t i=0; is_ratio && i<strlen(buff); i++)
212 is_ratio = buff[i]!='.';
213
214 if(is_ratio)
215 {
216 int num=0, den=0;
217 char slash;
218 stringstream in(buff);
219 in >> num >> slash >> den;
220 if(num<0) throw QString("Line ")+QString::number(num_line)+": Parsed numerator is negative '"+QString::number(num)+"'";
221 if(slash!='/') throw QString("Line ")+QString::number(num_line)+": There is no slash between numerator and denominator"+slash+"'";
222 if(den<=0) throw QString("Line ")+QString::number(num_line)+": Parsed denominator is not positive'"+QString::number(den)+"'";
223 values.push_back(MValue(num, den));
224 }
225 else
226 {
227 float cents=0.0;
228 stringstream in(buff);
229 in >> cents;
230 if(cents<0.0) throw QString("Line ")+QString::number(num_line)+": Parsed cents value is negative '"+QString::number(cents)+"'";
231 values.push_back(MValue(cents));
232 }
233 }
234 }
235 file.getline(buff, 1024);
236 num_line++;
237 }
238 }
239
240 MScale::MScale(const QString& name)
241 : m_name(name)
242 {
243 }
244 MScale::MScale(const QString& file_name, FileType type)
245 {
246 m_path = file_name;
247
248 if(type==SCALA) load_scala(file_name);
249 else
250 {
251 cout << "MicrotonalView::Scale::Scale unsupported file type '" << type << "'" << endl;
252 }
253 }
254
255 bool MScale::operator != (const MScale& scale)
256 {
257 return m_name!=scale.m_name;
258 }
259
260 // ---------------------- QRoot button -------------------------
261
262 QRoot::QRoot(MicrotonalView* view, int ht)
263 : QPushButton(view)
264 , m_ht(ht)
265 {
266 // cout << "QRoot::QRoot " << m_ht << endl;
267
268 // if(ht>8) ht+=12;
269
270 connect(this, SIGNAL(clicked()), this, SLOT(clicked2()));
271 connect(this, SIGNAL(rootClicked(int)), view, SLOT(selectRoot(int)));
272 setFlat(true);
273 setText(QString::fromStdString(h2n(ht, GetNotesName(), GetTransposition(), false)));
274 setCheckable(true);
275 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
276 setMinimumWidth(55); // TODO
277 setFocusPolicy(Qt::NoFocus);
278 }
279 void QRoot::clicked2()
280 {
281 emit(rootClicked(m_ht));
282 }
283
284 // --------------------------- MicrotonalView ----------------------------
285
286 MicrotonalView::MicrotonalView(QWidget* parent)
287 : QFrame(parent)
288 , View(tr("Microtonal"), this)
289 , ui_scale_menu(tr("Used scale"), this)
290 {
291 setting_selectedRoot = -1000;
292 m_AFreq = 440.0f;
293 m_selected_jivalue = NULL;
294 m_tuningFreq = 0.0;
295 setting_selectedScale = NULL;
296
297 // settings
298 QPixmap img;
299 img.loadFromData(g_icon_ji, sizeof(g_icon_ji), "PNG");
300 setting_show->setIcon(QIcon(":/fmit/ui/images/module_microtonal.svg"));
301 setting_show->setChecked(false);
302 hide();
303
304 QHBoxLayout* octaveActionLayout = new QHBoxLayout(&m_popup_menu);
305
306 QLabel* octaveActionTitle = new QLabel(tr("Root's octave"), &m_popup_menu);
307 octaveActionLayout->addWidget(octaveActionTitle);
308
309 setting_octave = new QSpinBox(&m_popup_menu);
310 setting_octave->setMinimum(-3);
311 setting_octave->setMaximum(8);
312 setting_octave->setSingleStep(1);
313 setting_octave->setToolTip(tr("Root's octave"));
314 setting_octave->setValue(3);
315 // m_old_octave = setting_octave->value();
316 // connect(setting_octave, SIGNAL(valueChanged(int)), this, SLOT(octaveChanged(int)));
317 connect(setting_octave, SIGNAL(valueChanged(int)), this, SLOT(emitTuningFreqChanged()));
318 octaveActionLayout->addWidget(setting_octave);
319
320 QWidget* octaveActionWidget = new QWidget(&m_popup_menu);
321 octaveActionWidget->setLayout(octaveActionLayout);
322
323 QWidgetAction* octaveAction = new QWidgetAction(&m_popup_menu);
324 octaveAction->setDefaultWidget(octaveActionWidget);
325 m_popup_menu.addAction(octaveAction);
326
327 setting_keepRootToLeft = new QAction(tr("Keep root to left side"), this);
328 setting_keepRootToLeft->setCheckable(true);
329 connect(setting_keepRootToLeft, SIGNAL(toggled(bool)), this, SLOT(keepRootToLeft(bool)));
330 m_popup_menu.addAction(setting_keepRootToLeft);
331
332 setting_loadScale = new QAction(tr("Load Scala file …"), this);
333 m_popup_menu.addAction(setting_loadScale);
334 connect(setting_loadScale, SIGNAL(triggered()), this, SLOT(loadScale()));
335
336 m_popup_menu.addMenu(&ui_scale_menu);
337
338 QVBoxLayout* layout = new QVBoxLayout(this);
339 // layout->setMargin(0);
340 layout->setContentsMargins(0, 0, 0, 0);
341 layout->setSpacing(0);
342 QHBoxLayout* roots_layout = new QHBoxLayout();
343 roots_layout->setSpacing(0);
344 layout->addLayout(roots_layout);
345 for(int i=0; i<13; i++)
346 {
347 m_roots.push_back(new QRoot(this, i+3));
348 roots_layout->addWidget(m_roots.back());
349 if(i+1<13)
350 roots_layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
351 }
352 m_roots.back()->setDisabled(true);
353 ui_scale = new QScaleLabel(this);
354 layout->addWidget(ui_scale);
355 ui_ratios = new QRatiosLabel(this);
356 layout->addWidget(ui_ratios);
357
358 setMaximumHeight(ui_scale->maximumHeight()+ui_ratios->maximumHeight()+20);
359
360 load_default_scales();
361 load_installed_scales();
362
363 refreshScaleList();
364
365 selectRoot(3);
366 selectScale(0);
367 }
368 void MicrotonalView::save()
369 {
370 s_settings->setValue("octave", setting_octave->value());
371 s_settings->setValue("keepRootToLeft", setting_keepRootToLeft->isChecked());
372 QStringList scale_list;
373 for(size_t i=0; i<setting_scales.size(); i++)
374 if(!setting_scales[i]->getPath().isEmpty())
375 scale_list.push_back(setting_scales[i]->getPath());
376 s_settings->setValue("scales", scale_list);
377 s_settings->setValue("selectedScale", setting_selectedScale->getName());
378 s_settings->setValue("lastScalesDirectory", setting_lastScalesDirectory);
379 s_settings->setValue("selectedRoot", setting_selectedRoot);
380 }
381 void MicrotonalView::load()
382 {
383 setting_octave->setValue(s_settings->value("octave", setting_octave->value()).toInt());
384 setting_keepRootToLeft->setChecked(s_settings->value("keepRootToLeft", setting_keepRootToLeft->isChecked()).toBool());
385 QStringList scale_list = s_settings->value("scales").toStringList();
386 for(QStringList::iterator it=scale_list.begin(); it!=scale_list.end(); ++it)
387 {
388 try
389 {
390 MScale* scale = new MScale(*it, MScale::SCALA);
391 bool new_one = true;
392 for(size_t i=0; new_one && i<setting_scales.size(); i++)
393 new_one = *scale != *(setting_scales[i]);
394 if (new_one)
395 setting_scales.push_back(scale);
396 }
397 catch(QString error){cout << "MicrotonalView::load " << error.toStdString() << endl;}
398 }
399 refreshScaleList();
400
401 QString fmitprefix(STR(PREFIX));
402
403 selectScale(s_settings->value("selectedScale", "default").toString());
404 setting_lastScalesDirectory = s_settings->value("lastScalesDirectory", fmitprefix+"/share/fmit/scales").toString();
405 selectRoot(s_settings->value("selectedRoot", m_roots[0]->m_ht).toInt());
406 }
407 void MicrotonalView::clearSettings()
408 {
409 s_settings->remove("octave");
410 s_settings->remove("keepRootToLeft");
411 s_settings->remove("scales");
412 s_settings->remove("selectedScale");
413 s_settings->remove("lastScalesDirectory");
414 s_settings->remove("selectedRoot");
415 }
416
417 /*void MicrotonalView::octaveChanged(int value)
418 {
419 if(value==0)
420 {
421 if(m_old_octave==1)
422 {
423 m_old_octave = -1;
424 setting_octave->setValue(-1);
425 }
426 else if(m_old_octave==-1)
427 {
428 m_old_octave = 1;
429 setting_octave->setValue(1);
430 }
431 }
432 else
433 m_old_octave = value;
434 }*/
435
436 int MicrotonalView::getOctaveShift()
437 {
438 return 12*(setting_octave->value()-5);
439 }
440
441 QString MicrotonalView::getTuningNoteName()
442 {
443 if(hasTuningFreqSelected())
444 {
445 if(m_selected_jivalue->is_ratio)
446 return QString::fromStdString(h2n(setting_selectedRoot+getOctaveShift()))+":"+QString::number(m_selected_jivalue->num)+"/"+QString::number(m_selected_jivalue->den);
447 else
448 return QString::fromStdString(h2n(setting_selectedRoot+getOctaveShift()))+":"+QString::number(m_selected_jivalue->cents);
449 }
450
451 return "no tuning note selected";
452 }
453
454 void MicrotonalView::scaleActionToggled(bool checked)
455 {
456 if (checked)
457 selectScale(((QAction*)sender())->data().toInt());
458 }
459
460 void MicrotonalView::selectScale(int index)
461 {
462 assert(index>=0 && index<int(setting_scales.size()));
463
464 setting_selectedScale = setting_scales[index];
465
466 QList<QAction*> scaleActions = ui_scale_menu.actions();
467
468 for (int i = 0; i < scaleActions.size(); i++)
469 {
470 if (i == index)
471 scaleActions[i]->setChecked(true);
472 else
473 scaleActions[i]->setChecked(false);
474 }
475
476 ui_ratios->repaint();
477 }
478 void MicrotonalView::selectScale(const QString& name)
479 {
480 int index = -1;
481 for(size_t i=0; index==-1 && i<setting_scales.size(); i++)
482 {
483 if(setting_scales[i]->getName()==name)
484 {
485 setting_selectedScale = setting_scales[i];
486 index = i;
487 }
488 }
489
490 if(index==-1)
491 {
492 cout << "MicrotonalView::selectScale unknown scale '" << name.toStdString() << "'" << endl;
493 return;
494 }
495
496 QList<QAction*> scaleActions = ui_scale_menu.actions();
497
498 for (int i = 0; i < scaleActions.size(); i++)
499 {
500 if (i == index)
501 scaleActions[i]->setChecked(true);
502 else
503 scaleActions[i]->setChecked(false);
504 }
505
506 ui_ratios->repaint();
507 }
508 int MicrotonalView::getIndex(MScale* scale)
509 {
510 for(size_t i=0; i<setting_scales.size(); i++)
511 if(setting_scales[i]==scale)
512 return i;
513
514 return -1;
515 }
516
517 void MicrotonalView::notesNameChanged()
518 {
519 for(int i=0; i<13; i++)
520 m_roots[i]->setText(QString::fromStdString(h2n(m_roots[i]->m_ht, GetNotesName(), GetTransposition(), false)));
521 }
522
523 void MicrotonalView::keepRootToLeft(bool keep)
524 {
525 if(keep)
526 {
527 for(int i=0; i<13; i++)
528 m_roots[i]->m_ht = (setting_selectedRoot+i)%12;
529 notesNameChanged();
530 selectRoot(setting_selectedRoot);
531 ui_ratios->repaint();
532 }
533 else
534 {
535 }
536 }
537
538 void MicrotonalView::setAFreq(float AFreq)
539 {
540 float AFreq_old = m_AFreq;
541
542 m_AFreq = AFreq;
543
544 if(m_AFreq!=AFreq_old)
545 emitTuningFreqChanged();
546 }
547
548 void MicrotonalView::updateCursor(float freq)
549 {
550 ui_scale->m_htf = f2hf(freq, m_AFreq);
551 ui_scale->repaint();
552 }
553
554 void MicrotonalView::selectRoot(int ht)
555 {
556 // cout << "MicrotonalView::selectRoot " << ht << endl;
557
558 if(ht==setting_selectedRoot)
559 {
560 for(int i=0; i<13; i++)
561 m_roots[i]->setChecked(m_roots[i]->m_ht==ht);
562 }
563 else
564 {
565 if(setting_keepRootToLeft->isChecked())
566 {
567 for(int i=0; i<13; i++)
568 m_roots[i]->m_ht = (ht+i)%12;
569 notesNameChanged();
570 }
571
572 for(int i=0; i<13; i++)
573 m_roots[i]->setChecked(m_roots[i]->m_ht==ht);
574
575 setting_selectedRoot = ht;
576
577 ui_ratios->repaint();
578 emitTuningFreqChanged();
579 }
580 }
581 void MicrotonalView::emitTuningFreqChanged()
582 {
583 m_tuningFreq = 0.0;
584 if(m_selected_jivalue!=NULL)
585 {
586 if(m_selected_jivalue->is_ratio)
587 m_tuningFreq = h2f(setting_selectedRoot+getOctaveShift(), m_AFreq)*m_selected_jivalue->ratio;
588 else
589 m_tuningFreq = h2f(setting_selectedRoot+getOctaveShift()+m_selected_jivalue->cents/100.0f, m_AFreq);
590 }
591
592 emit(tuningFreqChanged(m_tuningFreq));
593 }
594
595 MicrotonalView::QScaleLabel::QScaleLabel(MicrotonalView* view)
596 : QLabel(view)
597 , ui_view(view)
598 {
599 setMaximumHeight(15);
600 m_htf = -1000.0f;
601 }
602 void MicrotonalView::QScaleLabel::paintEvent(QPaintEvent* event)
603 {
604 QLabel::paintEvent(event);
605
606 QPainter* p = new QPainter(this);
607
608 int left = ui_view->m_roots[0]->x() + ui_view->m_roots[0]->width()/2;
609 int right = ui_view->m_roots[12]->x() + ui_view->m_roots[12]->width()/2;
610 int w = right - left;
611 p->setBrush(QColor(255,255,255));
612 p->setPen(QColor(128,128,128));
613 p->drawRect(0, 0, left+1, height());
614 p->drawRect(right, 0, width()-(right+1), height());
615 p->setPen(QColor(0,0,0));
616 p->drawRect(left, 0, w+1, height());
617
618 if(m_htf!=-1000.0)
619 {
620 float htw = w*(m_htf-ui_view->m_roots[0]->m_ht)/12.0f;
621 while(htw>=w) htw-=w;
622 while(htw<0) htw+=w;
623 int x = int(left+htw);
624 p->setPen(QColor(0,0,255));
625 p->setBrush(QColor(191,191,255));
626 QPolygon polygon(3);
627 polygon.setPoint(0, x-5, 0);
628 polygon.setPoint(1, x+5, 0);
629 polygon.setPoint(2, x, 2*height()/3);
630 p->drawConvexPolygon(polygon);
631 p->drawLine(x, 2*height()/3, x, height());
632
633 if(htw<(w/12.0f)/4.0f || -(htw-w)<(w/12.0f)/4.0f)
634 {
635 if(htw<(w/12.0f)/4.0f) x += w;
636 else x -= w;
637 polygon.setPoint(0, x-5, 0);
638 polygon.setPoint(1, x+5, 0);
639 polygon.setPoint(2, x, 2*height()/3);
640 p->drawConvexPolygon(polygon);
641 p->drawLine(x, 2*height()/3, x, height());
642 }
643 }
644
645 delete p;
646 }
647
648 MicrotonalView::QRatiosLabel::QRatiosLabel(MicrotonalView* view)
649 : QLabel(view)
650 , ui_view(view)
651 {
652 setMaximumHeight(12+3*(2*fontMetrics().height()+10));
653 }
654 void MicrotonalView::QRatiosLabel::drawTicks(QPainter* p, float r, int h)
655 {
656 int left = ui_view->m_roots[0]->x() + ui_view->m_roots[0]->width()/2;
657 int right = ui_view->m_roots[12]->x() + ui_view->m_roots[12]->width()/2;
658 int w = right - left;
659
660 for(float i=r; i<=12.0f; i+=2*r)
661 {
662 int x = left + int(w*i/12.0f);
663 p->drawLine(x, 0, x, h);
664 }
665 }
666 void MicrotonalView::QRatiosLabel::paintEvent(QPaintEvent* event)
667 {
668 QLabel::paintEvent(event);
669
670 QPainter* p = new QPainter(this);
671
672 // p->eraseRect(rect());
673
674 int left = ui_view->m_roots[0]->x() + ui_view->m_roots[0]->width()/2;
675 int right = ui_view->m_roots[12]->x() + ui_view->m_roots[12]->width()/2;
676 int w = right - left;
677
678 int tick_height = 12;
679 int max_dec = 3;
680
681 // draw ratios
682 p->setPen(QColor(0,0,255));
683 int dec = 0;
684 int dec_h = 2*p->fontMetrics().height()+2;
685 int dec_h2 = (height()-tick_height-p->fontMetrics().height()+2)/3;
686 dec_h = min(dec_h, dec_h2);
687 int ht = ui_view->setting_selectedRoot - ui_view->m_roots[0]->m_ht;
688 if(ui_view->setting_keepRootToLeft->isChecked()) ht = 0;
689 for(list<MScale::MValue>::iterator it=ui_view->setting_selectedScale->values.begin(); it!=ui_view->setting_selectedScale->values.end(); ++it)
690 {
691 float htw = 0.0f;
692
693 if((*it).is_ratio)
694 htw = w*f2hf(h2f(ht)*(*it).ratio)/12.0f;
695 else
696 htw = w*(ht+(*it).cents/100.0f)/12.0f;
697 while(htw>w) htw-=w;
698 while(htw<0) htw+=w;
699
700 int x = left + int(htw);
701 int y = tick_height + 2 + dec_h*dec;
702 p->drawLine(x, 0, x, y+dec_h);
703
704 if((*it).is_ratio)
705 {
706 QRect num_rect = fontMetrics().boundingRect(QString::number((*it).num));
707 num_rect.translate(x+1, y+p->fontMetrics().height());
708 QRect den_rect = fontMetrics().boundingRect(QString::number((*it).den));
709 den_rect.translate(x+1, y+2*p->fontMetrics().height());
710 (*it).bounding_rect = num_rect;
711 (*it).bounding_rect |= den_rect;
712 }
713 else
714 {
715 QRect cents_rect = fontMetrics().boundingRect(QString::number((*it).cents));
716 cents_rect.translate(x+1, y+2*p->fontMetrics().height());
717
718 (*it).bounding_rect = cents_rect;
719 }
720 (*it).bounding_rect.setLeft(x);
721 (*it).bounding_rect.setRight((*it).bounding_rect.right() + 2);
722 (*it).bounding_rect.setTop((*it).bounding_rect.top() - 2);
723 (*it).bounding_rect.setBottom(y+dec_h);
724
725 if(ui_view->m_selected_jivalue==&(*it))
726 {
727 p->setBrush(QColor(210,210,255));
728 p->drawRect((*it).bounding_rect);
729 }
730
731 if((*it).is_ratio)
732 {
733 p->drawText(x+1, y+p->fontMetrics().height(), QString::number((*it).num));
734 p->drawLine(x, y+p->fontMetrics().height()+2, x+p->fontMetrics().horizontalAdvance(QString::number((*it).num)), y+p->fontMetrics().height()+2);
735 p->drawText(x+1, y+2*p->fontMetrics().height(), QString::number((*it).den));
736 }
737 else
738 {
739 p->drawText(x+1, y+2*p->fontMetrics().height(), QString::number((*it).cents));
740 }
741
742 dec++;
743 if(dec>max_dec-1) dec = 0;
744 if(dec<0) dec = max_dec-1;
745 }
746
747 // draw ticks
748 p->setPen(QColor(0,0,0));
749 for(float i=0.0f; i<=12.0f; i+=1.0f)
750 {
751 int x = left + int(w*i/12.0f);
752 p->drawLine(x, 0, x, tick_height);
753 }
754 drawTicks(p, 0.5f, tick_height/2);
755 drawTicks(p, 0.25f, tick_height/3);
756 drawTicks(p, 0.125f, tick_height/4);
757
758 delete p;
759 }
760
761 void MicrotonalView::mouseReleaseEvent(QMouseEvent* e)
762 {
763 if(e->button()==Qt::LeftButton)
764 {
765 MScale::MValue* selected_jivalue_old = m_selected_jivalue;
766 m_selected_jivalue = NULL;
767
768 QPoint mouse_pos = e->pos() - ui_ratios->pos();
769 for(list<MScale::MValue>::iterator it=setting_selectedScale->values.begin(); m_selected_jivalue==NULL && it!=setting_selectedScale->values.end(); ++it)
770 if((*it).bounding_rect.contains(mouse_pos.x(), mouse_pos.y()))
771 m_selected_jivalue = &(*it);
772
773 if(m_selected_jivalue!=selected_jivalue_old)
774 {
775 ui_ratios->repaint();
776 emitTuningFreqChanged();
777 }
778 }
779
780 View::mouseReleaseEvent(e);
781 }
782
783 void MicrotonalView::refreshScaleList()
784 {
785 ui_scale_menu.clear();
786
787 QActionGroup* scaleGroup = new QActionGroup(this);
788
789 for(size_t i=0; i<setting_scales.size(); i++)
790 {
791 QAction* scaleAction = ui_scale_menu.addAction(setting_scales[i]->getName());
792 scaleAction->setCheckable(true);
793 scaleAction->setData((int)i);
794 scaleGroup->addAction(scaleAction);
795
796 if(setting_selectedScale==setting_scales[i])
797 scaleAction->setChecked(true);
798
799 connect(scaleAction, SIGNAL(toggled(bool)), this, SLOT(scaleActionToggled(bool)));
800 }
801 }
802 void MicrotonalView::loadScale()
803 {
804 #ifdef QT3_SUPPORT
805 Q3FileDialog dlg_file(setting_lastScalesDirectory, "Scala files (*.scl *.SCL)", this, "open file dialog", true);
806 dlg_file.setCaption(tr("Open scale file"));
807 dlg_file.setMode(Q3FileDialog::ExistingFile);
808 dlg_file.setInfoPreviewEnabled(true);
809 ScalePreview p(&dlg_file);
810 dlg_file.setInfoPreview(&p,&p);
811 dlg_file.setPreviewMode(Q3FileDialog::Info);
812 #else
813 QFileDialog dlg_file(this, tr("Open scale file"), setting_lastScalesDirectory, "Scala files (*.scl *.SCL)");
814 dlg_file.setFileMode(QFileDialog::ExistingFile);
815 #endif
816
817 dlg_file.exec();
818
819 if(dlg_file.result()==QDialog::Accepted)
820 {
821 #ifdef QT3_SUPPORT
822 setting_lastScalesDirectory = dlg_file.dirPath();
823 #else
824 setting_lastScalesDirectory = dlg_file.directory().path();
825 #endif
826 s_settings->setValue("MicrotonalView_lastScalesDirectory", setting_lastScalesDirectory);
827 // cout << "setting_lastScalesDirectory=" << setting_lastScalesDirectory << endl;
828 try
829 {
830 #ifdef QT3_SUPPORT
831 MScale* scale = new MScale(dlg_file.selectedFile(), MScale::SCALA);
832 #else
833 MScale* scale = new MScale(dlg_file.selectedFiles()[0], MScale::SCALA);
834 #endif
835 bool new_one = true;
836 for(size_t i=0; new_one && i<setting_scales.size(); i++)
837 new_one = *scale != *(setting_scales[i]);
838 if(new_one)
839 {
840 setting_scales.push_back(scale);
841 selectScale(setting_scales.size()-1);
842 refreshScaleList();
843 }
844 else
845 QMessageBox::information(this, tr("Open scale file"), tr("Scale name already exist"), QMessageBox::Ok);
846 }
847 catch(QString error)
848 {
849 QMessageBox::information(this, tr("Open scale file"), tr("Invalid file content !")+"\n("+error+")", QMessageBox::Ok);
850 }
851 }
852
853 ui_ratios->repaint();
854 }
855
856 void MicrotonalView::load_default_scales()
857 {
858 MScale* scale = new MScale("default");
859 scale->values.push_back(MScale::MValue(25,24));
860 scale->values.push_back(MScale::MValue(16,15));
861 scale->values.push_back(MScale::MValue(9,8));
862 scale->values.push_back(MScale::MValue(7,6));
863 scale->values.push_back(MScale::MValue(75,64));
864 scale->values.push_back(MScale::MValue(6,5));
865 scale->values.push_back(MScale::MValue(5,4));
866 scale->values.push_back(MScale::MValue(32,25));
867 scale->values.push_back(MScale::MValue(125,96));
868 scale->values.push_back(MScale::MValue(4,3));
869 scale->values.push_back(MScale::MValue(25,18));
870 scale->values.push_back(MScale::MValue(45,32));
871 scale->values.push_back(MScale::MValue(36,25));
872 scale->values.push_back(MScale::MValue(3,2));
873 scale->values.push_back(MScale::MValue(25,16));
874 scale->values.push_back(MScale::MValue(8,5));
875 scale->values.push_back(MScale::MValue(5,3));
876 scale->values.push_back(MScale::MValue(125,72));
877 scale->values.push_back(MScale::MValue(16,9));
878 scale->values.push_back(MScale::MValue(9,5));
879 scale->values.push_back(MScale::MValue(15,8));
880 scale->values.push_back(MScale::MValue(48,25));
881 scale->values.push_back(MScale::MValue(125,64));
882 setting_scales.push_back(scale);
883 }
884
885 void MicrotonalView::load_installed_scales()
886 {
887 QString fmitprefix(STR(PREFIX));
888 QDir scales_dir(fmitprefix + "/share/fmit/scales");
889
890 QStringList scales_files_list = scales_dir.entryList(QDir::Files);
891 for(QStringList::iterator it=scales_files_list.begin(); it!=scales_files_list.end(); ++it)
892 {
893 if(it->contains(QRegularExpression("\\.scl$")) || it->contains(QRegularExpression("\\.SCL$")))
894 {
895 try
896 {
897 MScale* scale = new MScale(scales_dir.absoluteFilePath(*it), MScale::SCALA);
898 bool new_one = true;
899 for(size_t i=0; new_one && i<setting_scales.size(); i++)
900 new_one = *scale != *(setting_scales[i]);
901 if (new_one)
902 setting_scales.push_back(scale);
903 }
904 catch(QString error){cout << "MicrotonalView::load_installed_scales " << error.toStdString() << endl;}
905 }
906 }
907 }
908
909 // ------------------ MicrotonalView::ScalePreview --------------------
910 #ifdef QT3_SUPPORT
911 MicrotonalView::ScalePreview::ScalePreview(QWidget* parent)
912 : QLabel(parent)
913 {
914 setAlignment(Qt::AlignVCenter);
915 setWordWrap(true);
916 setMinimumWidth(100);
917 }
918 void MicrotonalView::ScalePreview::previewUrl(const Q3Url& url)
919 {
920 if(url.path().contains(QRegExp("\\.scl$"))==0 && url.path().contains(QRegExp("\\.SCL$"))==0)
921 {
922 // setText("");
923 }
924 else
925 {
926 try
927 {
928 MScale* scale = new MScale(url.path(), MScale::SCALA);
929 QString txt;
930 txt += tr("<b>name:</b> ") + scale->getName() + "<p>";
931 txt += tr("<b>number of ratio:</b> ") + QString::number(scale->values.size());
932 setText(txt);
933 delete scale;
934 }
935 catch(QString error)
936 {
937 setText(tr("Invalid Scala file: ")+error);
938 }
939 }
940 }
941 #endif