LMMS
Loading...
Searching...
No Matches
Song.h
Go to the documentation of this file.
1/*
2 * Song.h - class song - the root of the model-tree
3 *
4 * Copyright (c) 2004-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#ifndef LMMS_SONG_H
26#define LMMS_SONG_H
27
28#include <array>
29#include <memory>
30
31#include <QString>
32#include <QHash> // IWYU pragma: keep
33
34#include "AudioEngine.h"
35#include "Controller.h"
36#include "Metronome.h"
37#include "lmms_constants.h"
38#include "MeterModel.h"
39#include "Timeline.h"
40#include "TrackContainer.h"
41#include "VstSyncController.h"
42
43namespace lmms
44{
45
46class AutomationTrack;
47class Keymap;
48class MidiClip;
49class Scale;
50
51namespace gui
52{
53class SongEditor;
55}
56
57
58const bpm_t MinTempo = 10;
59const bpm_t DefaultTempo = 140;
60const bpm_t MaxTempo = 999;
62
63
64class LMMS_EXPORT Song : public TrackContainer
65{
66 Q_OBJECT
68 mapPropertyFromModel( int,masterPitch,setMasterPitch,m_masterPitchModel );
69 mapPropertyFromModel( int,masterVolume,setMasterVolume, m_masterVolumeModel );
70public:
71 enum class PlayMode
72 {
75 Pattern,
79 } ;
80 constexpr static auto PlayModeCount = static_cast<std::size_t>(PlayMode::Count);
81
82 struct SaveOptions {
91
93 discardMIDIConnections.setValue(false);
94 saveAsProjectBundle.setValue(false);
95 }
96 };
97
98 void clearErrors();
99 void collectError( const QString error );
100 bool hasErrors();
101 QString errorSummary();
102
103 void processNextBuffer();
104
105 inline int getLoadingTrackCount() const
106 {
107 return m_nLoadingTrack;
108 }
109
110 inline int getMilliseconds() const
111 {
113 }
114
118 {
119 return 1000 * getTimeline(playMode).getElapsedSeconds();
120 }
121
122 inline int getBars() const
123 {
124 return currentBar();
125 }
126
127 inline int ticksPerBar() const
128 {
130 }
131
132 // Returns the beat position inside the bar, 0-based
133 inline int getBeat() const
134 {
135 return getPlayPos().getBeatWithinBar(m_timeSigModel);
136 }
137 // the remainder after bar and beat are removed
138 inline int getBeatTicks() const
139 {
140 return getPlayPos().getTickWithinBeat(m_timeSigModel);
141 }
142 inline int getTicks() const
143 {
144 return currentTick();
145 }
146 inline f_cnt_t getFrames() const
147 {
148 return currentFrame();
149 }
150 inline bool isPaused() const
151 {
152 return m_paused;
153 }
154
155 inline bool isPlaying() const
156 {
157 return m_playing == true && m_exporting == false;
158 }
159
160 inline bool isStopped() const
161 {
162 return m_playing == false && m_paused == false;
163 }
164
165 inline bool isExporting() const
166 {
167 return m_exporting;
168 }
169
170 inline void setExportLoop( bool exportLoop )
171 {
172 m_exportLoop = exportLoop;
173 }
174
175 inline bool isRecording() const
176 {
177 return m_recording;
178 }
179
180 inline void setLoopRenderCount(int count)
181 {
182 if (count < 1)
184 else
187 }
188
189 inline int getLoopRenderCount() const
190 {
191 return m_loopRenderCount;
192 }
193
194 bool isExportDone() const;
195 int getExportProgress() const;
196
197 inline void setRenderBetweenMarkers( bool renderBetweenMarkers )
198 {
199 m_renderBetweenMarkers = renderBetweenMarkers;
200 }
201
202 inline PlayMode playMode() const
203 {
204 return m_playMode;
205 }
206
207 const TimePos& getPlayPos(PlayMode pm) const
208 {
209 return getTimeline(pm).pos();
210 }
211 const TimePos& getPlayPos() const
212 {
213 return getPlayPos(m_playMode);
214 }
215
217 {
218 getTimeline(playMode).setTicks(ticks);
219 }
220 void setPlayPos(tick_t ticks)
221 {
222 setPlayPos(ticks, m_playMode);
223 }
224
225 auto getTimeline(PlayMode mode) -> Timeline& { return m_timelines[static_cast<std::size_t>(mode)]; }
226 auto getTimeline(PlayMode mode) const -> const Timeline& { return m_timelines[static_cast<std::size_t>(mode)]; }
229
230 void updateLength();
231 bar_t length() const
232 {
233 return m_length;
234 }
235
236
237 bpm_t getTempo();
238
243
244 //TODO: Add Q_DECL_OVERRIDE when Qt4 is dropped
245 AutomatedValueMap automatedValuesAt(TimePos time, int clipNum = -1) const override;
246
247 // file management
248 void createNewProject();
249 void createNewProjectFromTemplate( const QString & templ );
250 void loadProject( const QString & filename );
251 bool guiSaveProject();
252 bool guiSaveProjectAs(const QString & filename);
253 bool saveProjectFile(const QString & filename, bool withResources = false);
254
255 const QString & projectFileName() const
256 {
257 return m_fileName;
258 }
259
260 bool isLoadingProject() const
261 {
262 return m_loadingProject;
263 }
264
266 {
267 m_isCancelled = true;
268 Engine::audioEngine()->clearNewPlayHandles();
269 }
270
272 {
273 return m_isCancelled;
274 }
275
276 bool isModified() const
277 {
278 return m_modified;
279 }
280
281 QString nodeName() const override
282 {
283 return "song";
284 }
285
286 virtual bool fixedClips() const
287 {
288 return false;
289 }
290
291 void addController( Controller * c );
292 void removeController( Controller * c );
293
294
296 {
297 return m_controllers;
298 }
299
300
302 {
303 return m_timeSigModel;
304 }
305
307 {
308 return m_tempoModel;
309 }
310
311 void exportProjectMidi(QString const & exportFileName) const;
312
313 inline void setLoadOnLaunch(bool value) { m_loadOnLaunch = value; }
317
318 bool isSavingProject() const;
319
320 std::shared_ptr<const Scale> getScale(unsigned int index) const;
321 std::shared_ptr<const Keymap> getKeymap(unsigned int index) const;
322 void setScale(unsigned int index, std::shared_ptr<Scale> newScale);
323 void setKeymap(unsigned int index, std::shared_ptr<Keymap> newMap);
324
325 const std::string& syncKey() const noexcept { return m_vstSyncController.sharedMemoryKey(); }
326
328
329public slots:
330 void playSong();
331 void record();
332 void playAndRecord();
333 void playPattern();
334 void playMidiClip( const lmms::MidiClip * midiClipToPlay, bool loop = true );
335 void togglePause();
336 void stop();
337
338 void startExport();
339 void stopExport();
340
341
342 void setModified();
343
344 void clearProject();
345
346 void addPatternTrack();
347
348
349private slots:
350 void insertBar();
351 void removeBar();
352 void addSampleTrack();
353 void addAutomationTrack();
354
355 void setTempo();
356 void setTimeSignature();
357
358 void masterVolumeChanged();
359
360 void savePlayStartPosition();
361
362 void updateFramesPerTick();
363
364
365
366private:
367 Song();
368 Song( const Song & );
369 ~Song() override;
370
371
372 inline bar_t currentBar() const
373 {
374 return getPlayPos(m_playMode).getBar();
375 }
376
377 inline tick_t currentTick() const
378 {
379 return getPlayPos(m_playMode).getTicks();
380 }
381
382 inline f_cnt_t currentFrame() const
383 {
384 return getTimeline(m_playMode).ticks() * Engine::framesPerTick() + getTimeline(m_playMode).frameOffset();
385 }
386
387 void saveControllerStates( QDomDocument & doc, QDomElement & element );
388 void restoreControllerStates( const QDomElement & element );
389
390 void removeAllControllers();
391
392 void saveScaleStates(QDomDocument &doc, QDomElement &element);
393 void restoreScaleStates(const QDomElement &element);
394
395 void saveKeymapStates(QDomDocument &doc, QDomElement &element);
396 void restoreKeymapStates(const QDomElement &element);
397
398 void processAutomations(const TrackList& tracks, TimePos timeStart, f_cnt_t frames);
399 void processMetronome(size_t bufferOffset);
400
401 void setModified(bool value);
402
403 void setProjectFileName(QString const & projectFileName);
404
406
412
414
416
417 QString m_fileName;
421
422 volatile bool m_recording;
423 volatile bool m_exporting;
424 volatile bool m_exportLoop;
426 volatile bool m_playing;
427 volatile bool m_paused;
428
432
434
435 QHash<QString, int> m_errors;
436
437 std::array<Timeline, PlayModeCount> m_timelines;
438
441
444
446
454
455 std::shared_ptr<Scale> m_scales[MaxScaleCount];
456 std::shared_ptr<Keymap> m_keymaps[MaxKeymapCount];
457
459
461
462 friend class Engine;
463 friend class gui::SongEditor;
465
466signals:
470 void lengthChanged( int bars );
471 void tempoChanged( lmms::bpm_t newBPM );
472 void timeSignatureChanged( int oldTicksPerBar, int ticksPerBar );
475 void stopped();
476 void modified();
478 void scaleListChanged(int index);
479 void keymapListChanged(int index);
480} ;
481
482
483} // namespace lmms
484
485#endif // LMMS_SONG_H
#define noexcept
Definition DistrhoDefines.h:72
goto loop
Definition Spc_Cpu.h:155
Definition AutomationClip.h:52
Definition AutomationTrack.h:36
Definition AutomatableModel.h:497
Definition Controller.h:51
static float framesPerTick()
Definition Engine.h:96
static AudioEngine * audioEngine()
Definition Engine.h:59
Definition AutomatableModel.h:481
Definition Keymap.h:38
Definition MeterModel.h:35
Definition Metronome.h:32
Definition MidiClip.h:46
Definition Scale.h:67
Definition Song.h:65
const ControllerVector & controllers() const
Definition Song.h:295
int m_loopRenderCount
Definition Song.h:447
PlayMode m_playMode
Definition Song.h:439
Metronome & metronome()
Definition Song.h:327
volatile bool m_playing
Definition Song.h:426
void controllerAdded(lmms::Controller *)
mapPropertyFromModel(int, getTempo, setTempo, m_tempoModel)
Metronome m_metronome
Definition Song.h:460
TimePos m_exportLoopEnd
Definition Song.h:451
void modified()
void setLoadOnLaunch(bool value)
Definition Song.h:313
int getBeatTicks() const
Definition Song.h:138
std::array< Timeline, PlayModeCount > m_timelines
Definition Song.h:437
TimePos m_exportLoopBegin
Definition Song.h:450
void keymapListChanged(int index)
IntModel m_tempoModel
Definition Song.h:407
bool m_loadOnLaunch
Definition Song.h:420
f_cnt_t getFrames() const
Definition Song.h:146
bar_t length() const
Definition Song.h:231
IntModel m_masterPitchModel
Definition Song.h:411
Song(const Song &)
volatile bool m_exporting
Definition Song.h:423
bool m_isCancelled
Definition Song.h:431
QString nodeName() const override
Definition Song.h:281
const std::string & syncKey() const noexcept
Definition Song.h:325
bool isCancelled()
Definition Song.h:271
volatile bool m_renderBetweenMarkers
Definition Song.h:425
void setExportLoop(bool exportLoop)
Definition Song.h:170
int getLoopRenderCount() const
Definition Song.h:189
bool m_loadingProject
Definition Song.h:430
friend class Engine
Definition Song.h:462
std::shared_ptr< Keymap > m_keymaps[MaxKeymapCount]
Definition Song.h:456
void playbackStateChanged()
const QString & projectFileName() const
Definition Song.h:255
void scaleListChanged(int index)
auto getTimeline(PlayMode mode) const -> const Timeline &
Definition Song.h:226
volatile bool m_paused
Definition Song.h:427
bar_t currentBar() const
Definition Song.h:372
void setPlayPos(tick_t ticks, PlayMode playMode)
Definition Song.h:216
bool isLoadingProject() const
Definition Song.h:260
volatile bool m_exportLoop
Definition Song.h:424
const MidiClip * m_midiClipToPlay
Definition Song.h:442
MeterModel & getTimeSigModel()
Definition Song.h:301
mapPropertyFromModel(int, masterPitch, setMasterPitch, m_masterPitchModel)
f_cnt_t currentFrame() const
Definition Song.h:382
auto getTimeline(PlayMode mode) -> Timeline &
Definition Song.h:225
auto getTimeline() const -> const Timeline &
Definition Song.h:228
Song()
Definition Song.cpp:67
QHash< QString, int > m_errors
Definition Song.h:435
TimePos m_exportEffectiveLength
Definition Song.h:453
TimePos m_exportSongBegin
Definition Song.h:449
bool m_savingProject
Definition Song.h:429
tick_t currentTick() const
Definition Song.h:377
int getBeat() const
Definition Song.h:133
std::shared_ptr< Scale > m_scales[MaxScaleCount]
Definition Song.h:455
bool m_loopMidiClip
Definition Song.h:443
void tempoChanged(lmms::bpm_t newBPM)
IntModel m_masterVolumeModel
Definition Song.h:410
QString m_fileName
Definition Song.h:417
void projectFileNameChanged()
bar_t m_length
Definition Song.h:440
bool isExporting() const
Definition Song.h:165
void setRenderBetweenMarkers(bool renderBetweenMarkers)
Definition Song.h:197
TimePos m_exportSongEnd
Definition Song.h:452
bool isStopped() const
Definition Song.h:160
void playbackPositionJumped()
int getMilliseconds(PlayMode playMode) const
Definition Song.h:117
int getLoadingTrackCount() const
Definition Song.h:105
bool isPlaying() const
Definition Song.h:155
bpm_t getTempo()
Definition Song.cpp:834
SaveOptions m_saveOptions
Definition Song.h:433
const TimePos & getPlayPos() const
Definition Song.h:211
IntModel & tempoModel()
Definition Song.h:306
bool m_modified
Definition Song.h:419
bool isModified() const
Definition Song.h:276
static constexpr auto PlayModeCount
Definition Song.h:80
AutomatedValueMap m_oldAutomatedValues
Definition Song.h:458
mapPropertyFromModel(int, masterVolume, setMasterVolume, m_masterVolumeModel)
VstSyncController m_vstSyncController
Definition Song.h:445
void timeSignatureChanged(int oldTicksPerBar, int ticksPerBar)
QString m_oldFileName
Definition Song.h:418
auto getTimeline() -> Timeline &
Definition Song.h:227
virtual bool fixedClips() const
Definition Song.h:286
volatile bool m_recording
Definition Song.h:422
AutomationTrack * globalAutomationTrack()
Definition Song.h:239
const TimePos & getPlayPos(PlayMode pm) const
Definition Song.h:207
AutomationTrack * m_globalAutomationTrack
Definition Song.h:405
void projectLoaded()
PlayMode
Definition Song.h:72
@ Count
Definition Song.h:78
bool isPaused() const
Definition Song.h:150
int getBars() const
Definition Song.h:122
bool isRecording() const
Definition Song.h:175
void setLoopRenderCount(int count)
Definition Song.h:180
int getMilliseconds() const
Definition Song.h:110
void controllerRemoved(lmms::Controller *)
int m_nLoadingTrack
Definition Song.h:415
SaveOptions & getSaveOptions()
Definition Song.h:314
void loadingCancelled()
Definition Song.h:265
ControllerVector m_controllers
Definition Song.h:413
int ticksPerBar() const
Definition Song.h:127
void setTempo()
Definition Song.cpp:158
void setPlayPos(tick_t ticks)
Definition Song.h:220
int m_oldTicksPerBar
Definition Song.h:409
int m_loopRenderRemaining
Definition Song.h:448
MeterModel m_timeSigModel
Definition Song.h:408
PlayMode playMode() const
Definition Song.h:202
void lengthChanged(int bars)
void stopped()
int getTicks() const
Definition Song.h:142
Definition TimePos.h:68
static tick_t ticksPerBar()
Definition TimePos.h:127
Definition Timeline.h:37
TrackContainer()
Definition TrackContainer.cpp:48
Definition VstSyncController.h:38
Definition ControllerRackView.h:48
Definition SongEditor.h:57
static PuglViewHint int value
Definition pugl.h:1708
virtual ASIOError stop()=0
Definition AudioPortAudio.cpp:223
Definition AudioAlsa.cpp:35
const int DefaultTicksPerBar
Definition TimePos.h:38
constexpr unsigned MaxKeymapCount
number of keyboard mappings per project
Definition lmms_constants.h:44
const bpm_t MinTempo
Definition Song.h:58
constexpr unsigned MaxScaleCount
number of scales per project
Definition lmms_constants.h:43
std::int32_t bar_t
Definition LmmsTypes.h:34
const tick_t MaxSongLength
Definition Song.h:61
QMap< AutomatableModel *, float > AutomatedValueMap
Definition AutomatableModel.h:511
std::vector< Controller * > ControllerVector
Definition Controller.h:48
std::int32_t tick_t
Definition LmmsTypes.h:35
@ Count
Definition Sfxr.h:43
const bpm_t MaxTempo
Definition Song.h:60
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
QString filename
Definition HydrogenImport.cpp:42
std::uint16_t bpm_t
Definition LmmsTypes.h:45
const bpm_t DefaultTempo
Definition Song.h:59
png_structrp int mode
Definition png.h:1139
Definition Song.h:82
void setDefaultOptions()
Definition Song.h:92
BoolModel discardMIDIConnections
Definition Song.h:86
BoolModel saveAsProjectBundle
Definition Song.h:90
return c
Definition crypt.c:175
int error
Definition extract.c:1038
static ZCONST char Far None[]
Definition unzip.c:380
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263
#define const
Definition zconf.h:137