| 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 |
|
| 20 |
#ifndef _MicrotonalView_h_ |
| 21 |
#define _MicrotonalView_h_ |
| 22 |
|
| 23 |
#include <deque> |
| 24 |
#include <vector> |
| 25 |
#include <list> |
| 26 |
using namespace std; |
| 27 |
#include <qwidget.h> |
| 28 |
#include <qlabel.h> |
| 29 |
#include <qspinbox.h> |
| 30 |
#include <qpushbutton.h> |
| 31 |
#include <qaction.h> |
| 32 |
#ifdef QT3_SUPPORT |
| 33 |
#include <q3filedialog.h> |
| 34 |
#else |
| 35 |
#include <qfiledialog.h> |
| 36 |
#endif |
| 37 |
#include <qtooltip.h> |
| 38 |
#include "View.h" |
| 39 |
|
| 40 |
class MicrotonalView; |
| 41 |
|
| 42 |
class MScale |
| 43 |
{ |
| 44 |
void load_scala(const QString& file_name); |
| 45 |
|
| 46 |
QString m_name; |
| 47 |
QString m_path; |
| 48 |
|
| 49 |
public: |
| 50 |
struct MValue |
| 51 |
{ |
| 52 |
bool is_ratio; |
| 53 |
int num; |
| 54 |
int den; |
| 55 |
float ratio; |
| 56 |
float cents; |
| 57 |
QRect bounding_rect; |
| 58 |
MValue(int n, int d) : is_ratio(true), num(n), den(d), ratio(float(num)/den) {} |
| 59 |
MValue(float c) : is_ratio(false), cents(c) {} |
| 60 |
}; |
| 61 |
|
| 62 |
QString getName() {return m_name;} |
| 63 |
QString getPath() {return m_path;} |
| 64 |
|
| 65 |
enum FileType {AUTO,SCALA}; |
| 66 |
MScale(const QString& name); |
| 67 |
MScale(const QString& file_name, FileType type); |
| 68 |
|
| 69 |
list<MValue> values; |
| 70 |
|
| 71 |
bool operator != (const MScale& scale); |
| 72 |
}; |
| 73 |
|
| 74 |
class QRoot : public QPushButton |
| 75 |
{ |
| 76 |
Q_OBJECT |
| 77 |
|
| 78 |
private slots: |
| 79 |
void clicked2(); |
| 80 |
|
| 81 |
signals: |
| 82 |
void rootClicked(int); |
| 83 |
|
| 84 |
public: |
| 85 |
QRoot(MicrotonalView* view, int ht); |
| 86 |
|
| 87 |
int m_ht; |
| 88 |
|
| 89 |
virtual ~QRoot(){} |
| 90 |
}; |
| 91 |
|
| 92 |
class MicrotonalView : public QFrame, public View |
| 93 |
{ |
| 94 |
Q_OBJECT |
| 95 |
|
| 96 |
QMenu ui_scale_menu; |
| 97 |
|
| 98 |
float m_AFreq; |
| 99 |
float m_tuningFreq; |
| 100 |
|
| 101 |
void load_default_scales(); |
| 102 |
void load_installed_scales(); |
| 103 |
|
| 104 |
vector<QRoot*> m_roots; |
| 105 |
struct QScaleLabel : QLabel |
| 106 |
{ |
| 107 |
MicrotonalView* ui_view; |
| 108 |
float m_htf; |
| 109 |
QScaleLabel(MicrotonalView* view); |
| 110 |
virtual void paintEvent(QPaintEvent* event); |
| 111 |
virtual ~QScaleLabel(){} |
| 112 |
}* ui_scale; |
| 113 |
|
| 114 |
struct QRatiosLabel : QLabel |
| 115 |
{ |
| 116 |
MicrotonalView* ui_view; |
| 117 |
void drawTicks(QPainter* p, float r, int h); |
| 118 |
QRatiosLabel(MicrotonalView* view); |
| 119 |
virtual void paintEvent(QPaintEvent* event); |
| 120 |
virtual ~QRatiosLabel(){} |
| 121 |
}* ui_ratios; |
| 122 |
|
| 123 |
virtual void mouseReleaseEvent(QMouseEvent* e); |
| 124 |
|
| 125 |
#ifdef QT3_SUPPORT |
| 126 |
struct ScalePreview : QLabel, Q3FilePreview |
| 127 |
{ |
| 128 |
ScalePreview(QWidget* parent); |
| 129 |
virtual void previewUrl(const Q3Url& url); |
| 130 |
}; |
| 131 |
#endif |
| 132 |
|
| 133 |
int m_old_octave; |
| 134 |
int getOctaveShift(); |
| 135 |
|
| 136 |
protected slots: |
| 137 |
void refreshScaleList(); |
| 138 |
void loadScale(); |
| 139 |
void scaleActionToggled(bool checked); |
| 140 |
void selectScale(int index); |
| 141 |
// void octaveChanged(int value); |
| 142 |
void emitTuningFreqChanged(); |
| 143 |
|
| 144 |
public: |
| 145 |
MicrotonalView(QWidget* parent); |
| 146 |
|
| 147 |
float getTuningFreq() {return m_tuningFreq;} |
| 148 |
bool hasTuningFreqSelected() {return m_selected_jivalue!=NULL;} |
| 149 |
QString getTuningNoteName(); |
| 150 |
MScale::MValue* m_selected_jivalue; |
| 151 |
|
| 152 |
int getIndex(MScale* scale); |
| 153 |
|
| 154 |
~MicrotonalView(){} |
| 155 |
|
| 156 |
// settings |
| 157 |
QSpinBox* setting_octave; |
| 158 |
QAction* setting_keepRootToLeft; |
| 159 |
int setting_selectedRoot; |
| 160 |
QAction* setting_loadScale; |
| 161 |
vector<MScale*> setting_scales; |
| 162 |
MScale* setting_selectedScale; |
| 163 |
QString setting_lastScalesDirectory; |
| 164 |
virtual void save(); |
| 165 |
virtual void load(); |
| 166 |
virtual void clearSettings(); |
| 167 |
|
| 168 |
public slots: |
| 169 |
void setAFreq(float AFreq); |
| 170 |
void selectScale(const QString& name); |
| 171 |
void selectRoot(int ht); |
| 172 |
void updateCursor(float freq); |
| 173 |
void notesNameChanged(); |
| 174 |
void keepRootToLeft(bool keep); |
| 175 |
|
| 176 |
signals: |
| 177 |
void tuningFreqChanged(float freq); |
| 178 |
}; |
| 179 |
|
| 180 |
#endif // _MicrotonalView_h_ |