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