1 /*
2  * Engine.h - engine-system of LMMS
3  *
4  * Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5  *
6  * This file is part of LMMS - https://lmms.io
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program (see COPYING); if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301 USA.
22  *
23  */
24 
25 
26 #ifndef ENGINE_H
27 #define ENGINE_H
28 
29 #include <QtCore/QString>
30 #include <QtCore/QObject>
31 
32 
33 #include "export.h"
34 #include "lmms_basics.h"
35 
36 class BBTrackContainer;
37 class DummyTrackContainer;
38 class FxMixer;
39 class ProjectJournal;
40 class Mixer;
41 class Song;
42 class Ladspa2LMMS;
43 
44 
45 // Note: This class is called 'LmmsCore' instead of 'Engine' because of naming
46 // conflicts caused by ZynAddSubFX. See https://github.com/LMMS/lmms/issues/2269
47 // and https://github.com/LMMS/lmms/pull/2118 for more details.
48 //
49 // The workaround was to rename Lmms' Engine so that it has a different symbol
50 // name in the object files, but typedef it back to 'Engine' and keep it inside
51 // of Engine.h so that the rest of the codebase can be oblivious to this issue
52 // (and it could be fixed without changing every single file).
53 
54 class LmmsCore;
55 typedef LmmsCore Engine;
56 
57 class EXPORT LmmsCore : public QObject
58 {
59 	Q_OBJECT
60 public:
61 	static void init( bool renderOnly );
62 	static void destroy();
63 
64 	// core
mixer()65 	static Mixer *mixer()
66 	{
67 		return s_mixer;
68 	}
69 
fxMixer()70 	static FxMixer * fxMixer()
71 	{
72 		return s_fxMixer;
73 	}
74 
getSong()75 	static Song * getSong()
76 	{
77 		return s_song;
78 	}
79 
getBBTrackContainer()80 	static BBTrackContainer * getBBTrackContainer()
81 	{
82 		return s_bbTrackContainer;
83 	}
84 
projectJournal()85 	static ProjectJournal * projectJournal()
86 	{
87 		return s_projectJournal;
88 	}
89 
getLADSPAManager()90 	static Ladspa2LMMS * getLADSPAManager()
91 	{
92 		return s_ladspaManager;
93 	}
94 
dummyTrackContainer()95 	static DummyTrackContainer * dummyTrackContainer()
96 	{
97 		return s_dummyTC;
98 	}
99 
framesPerTick()100 	static float framesPerTick()
101 	{
102 		return s_framesPerTick;
103 	}
104 
105 	static float framesPerTick(sample_rate_t sample_rate);
106 
107 	static void updateFramesPerTick();
108 
inst()109 	static inline LmmsCore * inst()
110 	{
111 		if( s_instanceOfMe == NULL )
112 		{
113 			s_instanceOfMe = new LmmsCore();
114 		}
115 		return s_instanceOfMe;
116 	}
117 
118 signals:
119 	void initProgress(const QString &msg);
120 
121 
122 private:
123 	// small helper function which sets the pointer to NULL before actually deleting
124 	// the object it refers to
125 	template<class T>
deleteHelper(T ** ptr)126 	static inline void deleteHelper( T * * ptr )
127 	{
128 		T * tmp = *ptr;
129 		*ptr = NULL;
130 		delete tmp;
131 	}
132 
133 	static float s_framesPerTick;
134 
135 	// core
136 	static Mixer *s_mixer;
137 	static FxMixer * s_fxMixer;
138 	static Song * s_song;
139 	static BBTrackContainer * s_bbTrackContainer;
140 	static ProjectJournal * s_projectJournal;
141 	static DummyTrackContainer * s_dummyTC;
142 
143 	static Ladspa2LMMS * s_ladspaManager;
144 
145 	// even though most methods are static, an instance is needed for Qt slots/signals
146 	static LmmsCore * s_instanceOfMe;
147 
148 	friend class GuiApplication;
149 };
150 
151 
152 #endif
153 
154