123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- /*
- * 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 "Mixer.h"
- #include "VstSyncController.h"
- #include "Groove.h"
- class AutomationTrack;
- class Pattern;
- class TimeLineWidget;
- class Groove;
- const bpm_t MinTempo = 10;
- const bpm_t DefaultTempo = 140;
- const bpm_t MaxTempo = 999;
- const tick_t MaxSongLength = 9999 * DefaultTicksPerBar;
- class LMMS_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
- } ;
- struct SaveOptions {
- /**
- * Should we discard MIDI ControllerConnections from project files?
- */
- BoolModel discardMIDIConnections{false};
- void setDefaultOptions() {
- discardMIDIConnections.setValue(false);
- }
- };
- 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;
- }
- inline void setJumped( const bool jumped )
- {
- m_jumped = jumped;
- }
- inline bool jumped() const
- {
- return m_jumped;
- }
- TimeLineWidget * m_timeLine;
- private:
- float m_currentFrame;
- bool m_jumped;
- } ;
- void processNextBuffer();
- inline int getLoadingTrackCount() const
- {
- return m_nLoadingTrack;
- }
- inline int getMilliseconds() const
- {
- return m_elapsedMilliSeconds[m_playMode];
- }
- inline int getMilliseconds(PlayModes playMode) const
- {
- return m_elapsedMilliSeconds[playMode];
- }
- inline void setToTime(MidiTime const & midiTime)
- {
- m_elapsedMilliSeconds[m_playMode] = midiTime.getTimeInMilliseconds(getTempo());
- m_playPos[m_playMode].setTicks(midiTime.getTicks());
- }
- inline void setToTime(MidiTime const & midiTime, PlayModes playMode)
- {
- m_elapsedMilliSeconds[playMode] = midiTime.getTimeInMilliseconds(getTempo());
- m_playPos[playMode].setTicks(midiTime.getTicks());
- }
- inline void setToTimeByTicks(tick_t ticks)
- {
- m_elapsedMilliSeconds[m_playMode] = MidiTime::ticksToMilliseconds(ticks, getTempo());
- m_playPos[m_playMode].setTicks(ticks);
- }
- inline void setToTimeByTicks(tick_t ticks, PlayModes playMode)
- {
- m_elapsedMilliSeconds[playMode] = MidiTime::ticksToMilliseconds(ticks, getTempo());
- m_playPos[playMode].setTicks(ticks);
- }
- inline int getBars() const
- {
- return currentBar();
- }
- inline int ticksPerBar() const
- {
- return MidiTime::ticksPerBar(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;
- }
-
- inline void setLoopRenderCount(int count)
- {
- if (count < 1)
- m_loopRenderCount = 1;
- else
- m_loopRenderCount = count;
- m_loopRenderRemaining = m_loopRenderCount;
- }
-
- inline int getLoopRenderCount() const
- {
- return m_loopRenderCount;
- }
- bool isExportDone() const;
- int getExportProgress() 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();
- bar_t length() const
- {
- return m_length;
- }
- bpm_t getTempo();
- AutomationPattern * tempoAutomationPattern() override;
- AutomationTrack * globalAutomationTrack()
- {
- return m_globalAutomationTrack;
- }
- Groove * globalGroove()
- {
- return m_globalGroove;
- }
- //TODO: Add Q_DECL_OVERRIDE when Qt4 is dropped
- AutomatedValueMap automatedValuesAt(MidiTime time, int tcoNum = -1) const override;
- // 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 );
- void setGlobalGroove(Groove * groove);
- const QString & projectFileName() const
- {
- return m_fileName;
- }
- bool isLoadingProject() const
- {
- return m_loadingProject;
- }
- void loadingCancelled()
- {
- m_isCancelled = true;
- Engine::mixer()->clearNewPlayHandles();
- }
- bool isCancelled()
- {
- return m_isCancelled;
- }
- bool isModified() const
- {
- return m_modified;
- }
- QString nodeName() const override
- {
- 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;
- }
- void exportProjectMidi(QString const & exportFileName) const;
- inline void setLoadOnLauch(bool value) { m_loadOnLaunch = value; }
- SaveOptions &getSaveOptions() {
- return m_saveOptions;
- }
- bool isSavingProject() const;
- public slots:
- void playSong();
- void record();
- void playAndRecord();
- void playBB();
- void playPattern( const Pattern * patternToPlay, bool loop = true );
- void togglePause();
- void stop();
- void setPlayPos( tick_t ticks, PlayModes playMode );
- 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 bar_t currentBar() const
- {
- return m_playPos[m_playMode].getBar();
- }
- 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 saveControllerStates( QDomDocument & doc, QDomElement & element );
- void restoreControllerStates( const QDomElement & element );
- void removeAllControllers();
- void processAutomations(const TrackList& tracks, MidiTime timeStart, fpp_t frames);
- void setModified(bool value);
- void setProjectFileName(QString const & projectFileName);
- AutomationTrack * m_globalAutomationTrack;
- Groove * m_globalGroove;
- IntModel m_tempoModel;
- MeterModel m_timeSigModel;
- int m_oldTicksPerBar;
- IntModel m_masterVolumeModel;
- IntModel m_masterPitchModel;
- ControllerVector m_controllers;
- int m_nLoadingTrack;
- 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_savingProject;
- bool m_loadingProject;
- bool m_isCancelled;
- SaveOptions m_saveOptions;
- QStringList m_errors;
- PlayModes m_playMode;
- PlayPos m_playPos[Mode_Count];
- bar_t m_length;
- const Pattern* m_patternToPlay;
- bool m_loopPattern;
- double m_elapsedMilliSeconds[Mode_Count];
- tick_t m_elapsedTicks;
- bar_t m_elapsedBars;
- VstSyncController m_vstSyncController;
-
- int m_loopRenderCount;
- int m_loopRenderRemaining;
- MidiTime m_exportSongBegin;
- MidiTime m_exportLoopBegin;
- MidiTime m_exportLoopEnd;
- MidiTime m_exportSongEnd;
- MidiTime m_exportEffectiveLength;
- friend class LmmsCore;
- friend class SongEditor;
- friend class mainWindow;
- friend class ControllerRackView;
- signals:
- void projectLoaded();
- void playbackStateChanged();
- void playbackPositionChanged();
- void lengthChanged( int bars );
- void tempoChanged( bpm_t newBPM );
- void timeSignatureChanged( int oldTicksPerBar, int ticksPerBar );
- void controllerAdded( Controller * );
- void controllerRemoved( Controller * );
- void updateSampleTracks();
- void stopped();
- void modified();
- void projectFileNameChanged();
- } ;
- #endif
|