mirror of
https://github.com/LMMS/lmms.git
synced 2026-03-05 06:36:14 -05:00
Summary: * `NULL` -> `nullptr` * `gui` -> Function `getGUI()` * `pluginFactory` -> Function `getPluginFactory()` * `assert` (redefinition) -> using `NDEBUG` instead, which standard `assert` respects. * `powf` (C stdlib symbol clash) -> removed and all expansions replaced with calls to `std::pow`. * `exp10` (nonstandard function symbol clash) -> removed and all expansions replaced with calls to `std::pow`. * `PATH_DEV_DSP` -> File-scope QString of identical name and value. * `VST_SNC_SHM_KEY_FILE` -> constexpr char* with identical name and value. * `MM_ALLOC` and `MM_FREE` -> Functions with identical name and implementation. * `INVAL`, `OUTVAL`, etc. for automation nodes -> Functions with identical names and implementations. * BandLimitedWave.h: All integer constant macros replaced with constexpr ints of same name and value. * `FAST_RAND_MAX` -> constexpr int of same name and value. * `QSTR_TO_STDSTR` -> Function with identical name and equivalent implementation. * `CCONST` -> constexpr function template with identical name and implementation. * `F_OPEN_UTF8` -> Function with identical name and equivalent implementation. * `LADSPA_PATH_SEPARATOR` -> constexpr char with identical name and value. * `UI_CTRL_KEY` -> constexpr char* with identical name and value. * `ALIGN_SIZE` -> Renamed to `LMMS_ALIGN_SIZE` and converted from a macro to a constexpr size_t. * `JACK_MIDI_BUFFER_MAX` -> constexpr size_t with identical name and value. * versioninfo.h: `PLATFORM`, `MACHINE` and `COMPILER_VERSION` -> prefixed with `LMMS_BUILDCONF_` and converted from macros to constexpr char* literals. * Header guard _OSCILLOSCOPE -> renamed to OSCILLOSCOPE_H * Header guard _TIME_DISPLAY_WIDGET -> renamed to TIME_DISPLAY_WIDGET_H * C-style typecasts in DrumSynth.cpp have been replaced with `static_cast`. * constexpr numerical constants are initialized with assignment notation instead of curly brace intializers. * In portsmf, `Alg_seq::operator[]` will throw an exception instead of returning null if the operator index is out of range. Additionally, in many places, global constants that were declared as `const T foo = bar;` were changed from const to constexpr, leaving them const and making them potentially evaluable at compile time. Some macros that only appeared in single source files and were unused in those files have been removed entirely.
522 lines
11 KiB
C++
522 lines
11 KiB
C++
/*
|
|
* 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 <memory>
|
|
#include <utility>
|
|
|
|
#include <QtCore/QSharedMemory>
|
|
#include <QtCore/QVector>
|
|
#include <QHash>
|
|
#include <QString>
|
|
|
|
#include "TrackContainer.h"
|
|
#include "AudioEngine.h"
|
|
#include "Controller.h"
|
|
#include "Keymap.h"
|
|
#include "lmms_constants.h"
|
|
#include "MeterModel.h"
|
|
#include "Scale.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 * 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};
|
|
/**
|
|
* Should we save the project as a project bundle? (with resources)
|
|
*/
|
|
BoolModel saveAsProjectBundle{false};
|
|
|
|
void setDefaultOptions() {
|
|
discardMIDIConnections.setValue(false);
|
|
saveAsProjectBundle.setValue(false);
|
|
}
|
|
};
|
|
|
|
void clearErrors();
|
|
void collectError( const QString error );
|
|
bool hasErrors();
|
|
QString errorSummary();
|
|
|
|
class PlayPos : public TimePos
|
|
{
|
|
public:
|
|
PlayPos( const int abs = 0 ) :
|
|
TimePos( abs ),
|
|
m_timeLine( nullptr ),
|
|
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(TimePos const & pos)
|
|
{
|
|
m_elapsedMilliSeconds[m_playMode] = pos.getTimeInMilliseconds(getTempo());
|
|
m_playPos[m_playMode].setTicks(pos.getTicks());
|
|
}
|
|
|
|
inline void setToTime(TimePos const & pos, PlayModes playMode)
|
|
{
|
|
m_elapsedMilliSeconds[playMode] = pos.getTimeInMilliseconds(getTempo());
|
|
m_playPos[playMode].setTicks(pos.getTicks());
|
|
}
|
|
|
|
inline void setToTimeByTicks(tick_t ticks)
|
|
{
|
|
m_elapsedMilliSeconds[m_playMode] = TimePos::ticksToMilliseconds(ticks, getTempo());
|
|
m_playPos[m_playMode].setTicks(ticks);
|
|
}
|
|
|
|
inline void setToTimeByTicks(tick_t ticks, PlayModes playMode)
|
|
{
|
|
m_elapsedMilliSeconds[playMode] = TimePos::ticksToMilliseconds(ticks, getTempo());
|
|
m_playPos[playMode].setTicks(ticks);
|
|
}
|
|
|
|
inline int getBars() const
|
|
{
|
|
return currentBar();
|
|
}
|
|
|
|
inline int ticksPerBar() const
|
|
{
|
|
return TimePos::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 PlayPos & getPlayPos()
|
|
{
|
|
return getPlayPos(m_playMode);
|
|
}
|
|
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;
|
|
}
|
|
|
|
//TODO: Add Q_DECL_OVERRIDE when Qt4 is dropped
|
|
AutomatedValueMap automatedValuesAt(TimePos 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, bool withResources = false);
|
|
|
|
const QString & projectFileName() const
|
|
{
|
|
return m_fileName;
|
|
}
|
|
|
|
bool isLoadingProject() const
|
|
{
|
|
return m_loadingProject;
|
|
}
|
|
|
|
void loadingCancelled()
|
|
{
|
|
m_isCancelled = true;
|
|
Engine::audioEngine()->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 setLoadOnLaunch(bool value) { m_loadOnLaunch = value; }
|
|
SaveOptions &getSaveOptions() {
|
|
return m_saveOptions;
|
|
}
|
|
|
|
bool isSavingProject() const;
|
|
|
|
std::shared_ptr<const Scale> getScale(unsigned int index) const;
|
|
std::shared_ptr<const Keymap> getKeymap(unsigned int index) const;
|
|
void setScale(unsigned int index, std::shared_ptr<Scale> newScale);
|
|
void setKeymap(unsigned int index, std::shared_ptr<Keymap> newMap);
|
|
|
|
public slots:
|
|
void playSong();
|
|
void record();
|
|
void playAndRecord();
|
|
void playBB();
|
|
void playPattern( const Pattern * patternToPlay, bool loop = true );
|
|
void togglePause();
|
|
void stop();
|
|
|
|
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 setPlayPos( tick_t ticks, PlayModes playMode );
|
|
|
|
void saveControllerStates( QDomDocument & doc, QDomElement & element );
|
|
void restoreControllerStates( const QDomElement & element );
|
|
|
|
void removeAllControllers();
|
|
|
|
void saveScaleStates(QDomDocument &doc, QDomElement &element);
|
|
void restoreScaleStates(const QDomElement &element);
|
|
|
|
void saveKeymapStates(QDomDocument &doc, QDomElement &element);
|
|
void restoreKeymapStates(const QDomElement &element);
|
|
|
|
void processAutomations(const TrackList& tracks, TimePos timeStart, fpp_t frames);
|
|
|
|
void setModified(bool value);
|
|
|
|
void setProjectFileName(QString const & projectFileName);
|
|
|
|
AutomationTrack * m_globalAutomationTrack;
|
|
|
|
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;
|
|
|
|
QHash<QString, int> 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;
|
|
TimePos m_exportSongBegin;
|
|
TimePos m_exportLoopBegin;
|
|
TimePos m_exportLoopEnd;
|
|
TimePos m_exportSongEnd;
|
|
TimePos m_exportEffectiveLength;
|
|
|
|
std::shared_ptr<Scale> m_scales[MaxScaleCount];
|
|
std::shared_ptr<Keymap> m_keymaps[MaxKeymapCount];
|
|
|
|
AutomatedValueMap m_oldAutomatedValues;
|
|
|
|
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();
|
|
void scaleListChanged(int index);
|
|
void keymapListChanged(int index);
|
|
} ;
|
|
|
|
|
|
#endif
|