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