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 
21 #ifndef _CustomInstrumentTunerForm_h_
22 #define _CustomInstrumentTunerForm_h_
23 
24 #include "ui_InstrumentTunerForm.h"
25 
26 // #include "config.h"
27 
28 #include <deque>
29 using namespace std;
30 #include <qtimer.h>
31 #include <qdial.h>
32 #include <qsettings.h>
33 #include <Music/Music.h>
34 #include <Music/TimeAnalysis.h>
35 #include <Music/FreqAnalysis.h>
36 #include <Music/MultiCumulativeDiffAlgo.h>
37 #include <Music/CumulativeDiffAlgo.h>
38 #include <Music/CombedFT.h>
39 #include <Music/Filter.h>
40 using namespace Music;
41 #include "AutoQSettings.h"
42 #include "CaptureThread.h"
43 #include "ui_ConfigForm.h"
44 #include "LatencyMonoQuantizer.h"
45 #include "DummyMonoQuantizer.h"
46 #include "modules/DialView.h"
47 #include "modules/GLGraph.h"
48 #include "modules/GLErrorHistory.h"
49 #include "modules/GLVolumeHistory.h"
50 #include "modules/MicrotonalView.h"
51 #include "modules/GLSample.h"
52 #include "modules/GLFreqStruct.h"
53 #include "modules/GLFT.h"
54 #include "modules/GLStatistics.h"
55 
56 class CustomConfigForm : public QDialog, public Ui_ConfigForm
57 {
58 	Q_OBJECT
59 
60 public:
61 	CustomConfigForm(QWidget* parent = 0)
62 	{
63         Q_UNUSED(parent)
64 		setupUi(this);
65 	}
66 };
67 
68 class CustomInstrumentTunerForm : public QMainWindow, public Ui_InstrumentTunerForm
69 {
70 	Q_OBJECT
71 
72   public:
73 	CustomConfigForm m_config_form;
74 
75 	CaptureThread m_capture_thread;
76 	CombedFT* m_algo_combedfft;
77 
78 	DialView* m_dialTune;
79 	GLGraph* m_glGraph;
80 	GLErrorHistory* m_glErrorHistory;
81 	GLVolumeHistory* m_glVolumeHistory;
82 	GLSample* m_glSample;
83 	GLFreqStruct* m_glFreqStruct;
84 	GLFT* m_glFT;
85 	MicrotonalView* m_microtonalView;
86 	GLStatistics* m_glStatistics;
87 
88 	deque<double> m_queue;
89 	double m_freq;
90 	double m_compared_freq;
91 	double m_error;
92 
93 	QTime m_time;
94 
95 	CustomInstrumentTunerForm();
96 	AutoQSettings m_settings;
97 	void loadSettings();
98 
99 	virtual void resizeEvent(QResizeEvent* e);
100 	virtual void keyPressEvent(QKeyEvent * e);
101 
102 	void toggleFullScreen();
103 
104 	QTime m_time_refresh;
105 	QTime m_time_refresh_views;
106 	QTimer m_timer_refresh;
107 	double m_last_refresh;
108 
109 	// Range filters
110 	RectangularHighPassRTFilter m_rect_range_filter;
111 	FIRRTFilter m_fir_range_filter;
112 	DummyRTFilter m_dummy_range_filter;
113 	RTFilter* m_range_filter;
114 
115 	// Time quantizers
116 	LatencyMonoQuantizer m_latency_quantizer;
117 	DummyMonoQuantizer m_dummy_quantizer;
118 	MonoQuantizer* m_quantizer;
119 
120 	virtual void refresh_views();
121 	void refresh_data_sample();
122 	void refresh_data_harmonics();
123 
124 	// the main function
125 public slots:
126 	virtual void helpAbout();
127 	virtual void configure();
128 	virtual void pause(bool on);
129 	virtual void ui_spinAFreq_valueChanged(int);
130 	virtual void ui_spinAOffset_valueChanged(int);
131 	virtual void saveSettings();
132 	virtual void samplingRateChanged(int sampling_rate);
133 	virtual void errorRaised(const QString& error);
134 	virtual void transportChanged(const QString& name);
135 	virtual void noteStarted(double freq, double dt);
136 	virtual void noteFinished(double freq, double dt);
137 	virtual void update_views();
138 	virtual void tuningFreqChanged(float);
139 	virtual void configure_ok();
140     virtual void configure_cancel();
141 	virtual void restoreFactorySettings();
142 	virtual void noteRangeChanged();
143 	virtual void transpositionChanged();
144 	virtual void selectTransport(const QString & name);
145 	virtual void autoDetectTransport();
146 	void refresh();
147 	void update_localized_note_names();
148 
149     void closeEvent(QCloseEvent* event);
150 
151 public:
152 	~CustomInstrumentTunerForm();
153 };
154 
155 #endif // _CustomInstrumentTunerForm_h_
156