/
Song.h
391 lines (303 loc) · 7.57 KB
/
Song.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/*
* Song.h - class song - the root of the model-tree
*
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef SONG_H
#define SONG_H
#include <utility>
#include <QtCore/QSharedMemory>
#include <QtCore/QVector>
#include "TrackContainer.h"
#include "Controller.h"
#include "MeterModel.h"
#include "VstSyncController.h"
class AutomationTrack;
class Pattern;
class TimeLineWidget;
const bpm_t MinTempo = 10;
const bpm_t DefaultTempo = 140;
const bpm_t MaxTempo = 999;
const tick_t MaxSongLength = 9999 * DefaultTicksPerTact;
class EXPORT Song : public TrackContainer
{
Q_OBJECT
mapPropertyFromModel( int,getTempo,setTempo,m_tempoModel );
mapPropertyFromModel( int,masterPitch,setMasterPitch,m_masterPitchModel );
mapPropertyFromModel( int,masterVolume,setMasterVolume, m_masterVolumeModel );
public:
enum PlayModes
{
Mode_None,
Mode_PlaySong,
Mode_PlayBB,
Mode_PlayPattern,
Mode_PlayAutomationPattern,
Mode_Count
} ;
void clearErrors();
void collectError( const QString error );
bool hasErrors();
QString* errorSummary();
class PlayPos : public MidiTime
{
public:
PlayPos( const int abs = 0 ) :
MidiTime( abs ),
m_timeLine( NULL ),
m_currentFrame( 0.0f )
{
}
inline void setCurrentFrame( const float f )
{
m_currentFrame = f;
}
inline float currentFrame() const
{
return m_currentFrame;
}
TimeLineWidget * m_timeLine;
private:
float m_currentFrame;
} ;
void processNextBuffer();
inline int getMilliseconds() const
{
return m_elapsedMilliSeconds;
}
inline void setMilliSeconds( float ellapsedMilliSeconds )
{
m_elapsedMilliSeconds = ellapsedMilliSeconds;
}
inline int getTacts() const
{
return currentTact();
}
inline int ticksPerTact() const
{
return MidiTime::ticksPerTact(m_timeSigModel);
}
// Returns the beat position inside the bar, 0-based
inline int getBeat() const
{
return getPlayPos().getBeatWithinBar(m_timeSigModel);
}
// the remainder after bar and beat are removed
inline int getBeatTicks() const
{
return getPlayPos().getTickWithinBeat(m_timeSigModel);
}
inline int getTicks() const
{
return currentTick();
}
inline f_cnt_t getFrames() const
{
return currentFrame();
}
inline bool isPaused() const
{
return m_paused;
}
inline bool isPlaying() const
{
return m_playing == true && m_exporting == false;
}
inline bool isStopped() const
{
return m_playing == false && m_paused == false;
}
inline bool isExporting() const
{
return m_exporting;
}
inline void setExportLoop( bool exportLoop )
{
m_exportLoop = exportLoop;
}
inline bool isRecording() const
{
return m_recording;
}
bool isExportDone() const;
std::pair<MidiTime, MidiTime> getExportEndpoints() const;
inline void setRenderBetweenMarkers( bool renderBetweenMarkers )
{
m_renderBetweenMarkers = renderBetweenMarkers;
}
inline PlayModes playMode() const
{
return m_playMode;
}
inline PlayPos & getPlayPos( PlayModes pm )
{
return m_playPos[pm];
}
inline const PlayPos & getPlayPos( PlayModes pm ) const
{
return m_playPos[pm];
}
inline const PlayPos & getPlayPos() const
{
return getPlayPos(m_playMode);
}
void updateLength();
tact_t length() const
{
return m_length;
}
bpm_t getTempo();
virtual AutomationPattern * tempoAutomationPattern();
AutomationTrack * globalAutomationTrack()
{
return m_globalAutomationTrack;
}
static AutomatedValueMap automatedValuesAt(const Track::tcoVector& tcos, MidiTime time);
// file management
void createNewProject();
void createNewProjectFromTemplate( const QString & templ );
void loadProject( const QString & filename );
bool guiSaveProject();
bool guiSaveProjectAs( const QString & filename );
bool saveProjectFile( const QString & filename );
const QString & projectFileName() const
{
return m_fileName;
}
bool isLoadingProject() const
{
return m_loadingProject;
}
bool isModified() const
{
return m_modified;
}
virtual QString nodeName() const
{
return "song";
}
virtual bool fixedTCOs() const
{
return false;
}
void addController( Controller * c );
void removeController( Controller * c );
const ControllerVector & controllers() const
{
return m_controllers;
}
MeterModel & getTimeSigModel()
{
return m_timeSigModel;
}
public slots:
void playSong();
void record();
void playAndRecord();
void playBB();
void playPattern( const Pattern * patternToPlay, bool loop = true );
void togglePause();
void stop();
void importProject();
void exportProject( bool multiExport = false );
void exportProjectTracks();
void exportProjectMidi();
void startExport();
void stopExport();
void setModified();
void clearProject();
void addBBTrack();
private slots:
void insertBar();
void removeBar();
void addSampleTrack();
void addAutomationTrack();
void setTempo();
void setTimeSignature();
void masterVolumeChanged();
void savePos();
void updateFramesPerTick();
private:
Song();
Song( const Song & );
virtual ~Song();
inline tact_t currentTact() const
{
return m_playPos[m_playMode].getTact();
}
inline tick_t currentTick() const
{
return m_playPos[m_playMode].getTicks();
}
inline f_cnt_t currentFrame() const
{
return m_playPos[m_playMode].getTicks() * Engine::framesPerTick() +
m_playPos[m_playMode].currentFrame();
}
void setPlayPos( tick_t ticks, PlayModes playMode );
void saveControllerStates( QDomDocument & doc, QDomElement & element );
void restoreControllerStates( const QDomElement & element );
void removeAllControllers();
void processAutomations(const TrackList& tracks, MidiTime timeStart, fpp_t frames, int tcoNum);
AutomationTrack * m_globalAutomationTrack;
IntModel m_tempoModel;
MeterModel m_timeSigModel;
int m_oldTicksPerTact;
IntModel m_masterVolumeModel;
IntModel m_masterPitchModel;
ControllerVector m_controllers;
QString m_fileName;
QString m_oldFileName;
bool m_modified;
bool m_loadOnLaunch;
volatile bool m_recording;
volatile bool m_exporting;
volatile bool m_exportLoop;
volatile bool m_renderBetweenMarkers;
volatile bool m_playing;
volatile bool m_paused;
bool m_loadingProject;
QList<QString> * m_errors;
PlayModes m_playMode;
PlayPos m_playPos[Mode_Count];
tact_t m_length;
const Pattern* m_patternToPlay;
bool m_loopPattern;
double m_elapsedMilliSeconds;
tick_t m_elapsedTicks;
tact_t m_elapsedTacts;
VstSyncController m_vstSyncController;
friend class LmmsCore;
friend class SongEditor;
friend class mainWindow;
friend class ControllerRackView;
signals:
void projectLoaded();
void playbackStateChanged();
void playbackPositionChanged();
void lengthChanged( int tacts );
void tempoChanged( bpm_t newBPM );
void timeSignatureChanged( int oldTicksPerTact, int ticksPerTact );
void controllerAdded( Controller * );
void controllerRemoved( Controller * );
void updateSampleTracks();
} ;
#endif