1 /*
2  * Hydrogen
3  * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4  *
5  * http://www.hydrogen-music.org
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY, without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 
23 #ifndef HYDROGEN_APP_H
24 #define HYDROGEN_APP_H
25 
26 #include <hydrogen/config.h>
27 #include <hydrogen/object.h>
28 #include <hydrogen/globals.h>
29 
30 #include "EventListener.h"
31 
32 #include <iostream>
33 #include <vector>
34 #include <QtGui>
35 #if QT_VERSION >= 0x050000
36 #  include <QtWidgets>
37 #endif
38  #include <QStringList>
39 
40 //#include <QUndoStack>
41 
42 /** Amount of time to pass between successive calls to
43  * HydrogenApp::onEventQueueTimer() in milliseconds.
44  *
45  * This causes the GUI to update at 20 frames per second.*/
46 #define QUEUE_TIMER_PERIOD 50
47 
48 
49 namespace H2Core
50 {
51 	class Song;
52 }
53 
54 class SongEditorPanel;
55 class MainForm;
56 class PlayerControl;
57 class PatternEditorPanel;
58 class InstrumentEditorPanel;
59 class SongEditor;
60 class Mixer;
61 class AudioEngineInfoForm;
62 class SimpleHTMLBrowser;
63 class LadspaFXProperties;
64 class LadspaFXInfo;
65 class LadspaFXGroup;
66 class InstrumentRack;
67 class PlaylistDialog;
68 class SampleEditor;
69 class Director;
70 class InfoBar;
71 
72 class HydrogenApp : public QObject, public EventListener, public H2Core::Object
73 {
74 		H2_OBJECT
75 	Q_OBJECT
76 	public:
77 		HydrogenApp( MainForm* pMainForm, H2Core::Song *pFirstSong );
78 
79 		/// Returns the instance of HydrogenApp class
80 		static HydrogenApp* get_instance();
81 
82 		virtual ~HydrogenApp();
83 
84 		void setSong( H2Core::Song* pSong );
85 
86 		void showPreferencesDialog();
87 		void updateMixerCheckbox();
88 		void showMixer(bool bShow);
89 		void showInstrumentPanel(bool);
90 		void showAudioEngineInfoForm();
91 		void showPlaylistDialog();
92 		void showDirector();
93 		void showSampleEditor( QString name, int mSelectedComponemt, int mSelectedLayer );
94 
95 		Mixer*				getMixer();
96 		MainForm*			getMainForm();
97 		SongEditorPanel*		getSongEditorPanel();
98 		AudioEngineInfoForm*		getAudioEngineInfoForm();
99 		PlaylistDialog*			getPlayListDialog();
100 		Director*			getDirector();
101 		SampleEditor*			getSampleEditor();
102 		SimpleHTMLBrowser*		getHelpBrowser();
103 		PatternEditorPanel*		getPatternEditorPanel();
104 		PlayerControl*			getPlayerControl();
105 		InstrumentRack*			getInstrumentRack();
106 		InfoBar *			getInfoBar() const;
107 
108 		QUndoStack*			m_pUndoStack;
109 
110 		void setStatusBarMessage( const QString& msg, int msec = 0 );
111 		void setScrollStatusBarMessage( const QString& msg, int msec = 0, bool test = true );
112 		void updateWindowTitle();
113 
114 #ifdef H2CORE_HAVE_LADSPA
getLadspaFXProperties(uint nFX)115 		LadspaFXProperties* getLadspaFXProperties(uint nFX) {	return m_pLadspaFXProperties[nFX];	}
116 #endif
117 		void addEventListener( EventListener* pListener );
118 		void removeEventListener( EventListener* pListener );
119 		void closeFXProperties();
120 
121 		void onDrumkitLoad( QString name );
122 		void enableDestructiveRecMode();
123 
124 		void cleanupTemporaryFiles();
125 
126 	public slots:
127 		/**
128 		 * Function called every #QUEUE_TIMER_PERIOD
129 		 * millisecond to pop all Events from the EventQueue
130 		 * and invoke the corresponding functions.
131 		 *
132 		 * Depending on the H2Core::EventType, the following members
133 		 * of EventListener will be called:
134 		 * - H2Core::EVENT_STATE ->
135 		     EventListener::stateChangedEvent()
136 		 * - H2Core::EVENT_PATTERN_CHANGED ->
137 		     EventListener::patternChangedEvent()
138 		 * - H2Core::EVENT_PATTERN_MODIFIED ->
139 		     EventListener::patternModifiedEvent()
140 		 * - H2Core::EVENT_SONG_MODIFIED ->
141 		     EventListener::songModifiedEvent()
142 		 * - H2Core::EVENT_SELECTED_PATTERN_CHANGED ->
143 		     EventListener::selectedPatternChangedEvent()
144 		 * - H2Core::EVENT_SELECTED_INSTRUMENT_CHANGED ->
145 		     EventListener::selectedInstrumentChangedEvent()
146 		 * - H2Core::EVENT_PARAMETERS_INSTRUMENT_CHANGED ->
147 		     EventListener::parametersInstrumentChangedEvent()
148 		 * - H2Core::EVENT_MIDI_ACTIVITY ->
149 		     EventListener::midiActivityEvent()
150 		 * - H2Core::EVENT_NOTEON ->
151 		     EventListener::noteOnEvent()
152 		 * - H2Core::EVENT_ERROR ->
153 		     EventListener::errorEvent()
154 		 * - H2Core::EVENT_XRUN ->
155 		     EventListener::XRunEvent()
156 		 * - H2Core::EVENT_METRONOME ->
157 		     EventListener::metronomeEvent()
158 		 * - H2Core::EVENT_RECALCULATERUBBERBAND ->
159 		     EventListener::rubberbandbpmchangeEvent()
160 		 * - H2Core::EVENT_PROGRESS ->
161 		     EventListener::progressEvent()
162 		 * - H2Core::EVENT_JACK_SESSION ->
163 		     EventListener::jacksessionEvent()
164 		 * - H2Core::EVENT_PLAYLIST_LOADSONG ->
165 		     EventListener::playlistLoadSongEvent()
166 		 * - H2Core::EVENT_UNDO_REDO ->
167 		     EventListener::undoRedoActionEvent()
168 		 * - H2Core::EVENT_TEMPO_CHANGED ->
169 		     EventListener::tempoChangedEvent()
170 		 * - H2Core::EVENT_UPDATE_SONG ->
171 		     EventListener::updateSongEvent()
172 		 * - H2Core::EVENT_NONE -> nothing
173 		 *
174 		 * In addition, all MIDI notes in
175 		 * H2Core::EventQueue::m_addMidiNoteVector will converted into
176 		 * actions via SE_addNoteAction() and deleted from the
177 		 * former array.
178 		*/
179 		void onEventQueueTimer();
180 		void currentTabChanged(int);
181 
182 	private:
183 		static HydrogenApp *		m_pInstance;	///< HydrogenApp instance
184 
185 #ifdef H2CORE_HAVE_LADSPA
186 		LadspaFXProperties *		m_pLadspaFXProperties[MAX_FX];
187 #endif
188 
189 		MainForm *			m_pMainForm;
190 		Mixer *				m_pMixer;
191 		PatternEditorPanel*		m_pPatternEditorPanel;
192 		AudioEngineInfoForm *		m_pAudioEngineInfoForm;
193 		SongEditorPanel *		m_pSongEditorPanel;
194 		SimpleHTMLBrowser *		m_pHelpBrowser;
195 		SimpleHTMLBrowser *		m_pFirstTimeInfo;
196 		InstrumentRack*			m_pInstrumentRack;
197 		PlayerControl *			m_pPlayerControl;
198 		PlaylistDialog *		m_pPlaylistDialog;
199 		SampleEditor *			m_pSampleEditor;
200 		InfoBar *			m_pInfoBar;
201 		Director *			m_pDirector;
202 		QTimer *			m_pEventQueueTimer;
203 		std::vector<EventListener*> 	m_EventListeners;
204 		QTabWidget *			m_pTab;
205 		QSplitter *			m_pSplitter;
206 
207 		// implement EngineListener interface
208 		void engineError(uint nErrorCode);
209 
210 		void setupSinglePanedInterface();
211 		virtual void songModifiedEvent();
212 
213 		/**
214 		 * Refreshes and updates the GUI after the Song was changed in
215 		 * the core part of Hydrogen.
216 		 *
217 		 * When using session management or changing the Song using
218 		 * an OSC message, this command will get core and GUI in sync
219 		 * again.
220 		 *
221 		 * \param nValue unused
222 		 */
223 		virtual void updateSongEvent( int nValue );
224 		/**
225 		 * Calls closeAll() to shutdown Hydrogen.
226 		 *
227 		 * \param nValue unused
228 		 */
229 		virtual void quitEvent( int nValue );
230 };
231 
232 
getMixer()233 inline Mixer* HydrogenApp::getMixer()
234 {
235 	return m_pMixer;
236 }
237 
getMainForm()238 inline MainForm* HydrogenApp::getMainForm()
239 {
240 	return m_pMainForm;
241 }
242 
getSongEditorPanel()243 inline SongEditorPanel* HydrogenApp::getSongEditorPanel()
244 {
245 	return m_pSongEditorPanel;
246 }
247 
getAudioEngineInfoForm()248 inline AudioEngineInfoForm* HydrogenApp::getAudioEngineInfoForm()
249 {
250 	return m_pAudioEngineInfoForm;
251 }
252 
getPlayListDialog()253 inline PlaylistDialog* HydrogenApp::getPlayListDialog()
254 {
255 	return m_pPlaylistDialog;
256 }
257 
getDirector()258 inline Director* HydrogenApp::getDirector()
259 {
260 	return m_pDirector;
261 }
262 
getSampleEditor()263 inline SampleEditor* HydrogenApp::getSampleEditor()
264 {
265 	return m_pSampleEditor;
266 }
267 
getHelpBrowser()268 inline SimpleHTMLBrowser* HydrogenApp::getHelpBrowser()
269 {
270 	return m_pHelpBrowser;
271 }
272 
getPatternEditorPanel()273 inline PatternEditorPanel* HydrogenApp::getPatternEditorPanel()
274 {
275 	return m_pPatternEditorPanel;
276 }
277 
getPlayerControl()278 inline PlayerControl* HydrogenApp::getPlayerControl()
279 {
280 	return m_pPlayerControl;
281 }
282 
getInstrumentRack()283 inline InstrumentRack* HydrogenApp::getInstrumentRack()
284 {
285 	return m_pInstrumentRack;
286 }
287 
getInfoBar()288 inline InfoBar* HydrogenApp::getInfoBar() const
289 {
290 	return m_pInfoBar;
291 }
292 
293 #endif
294