Import upstream version 0.99.2
[fmit.git] / src / modules / MicrotonalView.h
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
103         vector<QRoot*> m_roots;
104         struct QScaleLabel : QLabel
105         {
106                 MicrotonalView* ui_view;
107                 float m_htf;
108                 QScaleLabel(MicrotonalView* view);
109                 virtual void paintEvent(QPaintEvent* event);
110                 virtual ~QScaleLabel(){}
111         }* ui_scale;
112
113         struct QRatiosLabel : QLabel
114         {
115                 MicrotonalView* ui_view;
116                 void drawTicks(QPainter* p, float r, int h);
117                 QRatiosLabel(MicrotonalView* view);
118                 virtual void paintEvent(QPaintEvent* event);
119                 virtual ~QRatiosLabel(){}
120         }* ui_ratios;
121
122         virtual void mouseReleaseEvent(QMouseEvent* e);
123
124 #ifdef QT3_SUPPORT
125                 struct ScalePreview : QLabel, Q3FilePreview
126         {
127                 ScalePreview(QWidget* parent);
128                 virtual void previewUrl(const Q3Url& url);
129         };
130 #endif
131
132         int m_old_octave;
133         int getOctaveShift();
134
135   protected slots:
136         void refreshScaleList();
137         void loadScale();
138         void scaleActionToggled(bool checked);
139         void selectScale(int index);
140 //      void octaveChanged(int value);
141         void emitTuningFreqChanged();
142
143   public:
144         MicrotonalView(QWidget* parent);
145
146         float getTuningFreq()                                   {return m_tuningFreq;}
147         bool hasTuningFreqSelected()                    {return m_selected_jivalue!=NULL;}
148         QString getTuningNoteName();
149         MScale::MValue* m_selected_jivalue;
150
151         int getIndex(MScale* scale);
152
153         ~MicrotonalView(){}
154
155         // settings
156         QSpinBox* setting_octave;
157         QAction* setting_keepRootToLeft;
158         int setting_selectedRoot;
159         QAction* setting_loadScale;
160         vector<MScale*> setting_scales;
161         MScale* setting_selectedScale;
162         QString setting_lastScalesDirectory;
163         virtual void save();
164         virtual void load();
165         virtual void clearSettings();
166
167   public slots:
168         void setAFreq(float AFreq);
169         void selectScale(const QString& name);
170         void selectRoot(int ht);
171         void updateCursor(float freq);
172         void notesNameChanged();
173         void keepRootToLeft(bool keep);
174
175   signals:
176         void tuningFreqChanged(float freq);
177 };
178
179 #endif // _MicrotonalView_h_