mirror of
https://github.com/LMMS/lmms.git
synced 2026-03-04 22:26:07 -05:00
* Adds a baseDir for the local path
Adds a new Base for paths called "local:", which will translate to the dir where the currently opened project file is at. In the future this will allow us to make project bundles and make it easier to export and transfer projects to other people without breaking the paths to samples, presets, plugins and others.
* Starts implementing the makeBundle functionality
For now, to make a bundle LMMS has to be run through CLI with the makeBundle/--makeBundle command, followed by an input file and an output file ('lmms --makeBundle input.mmp output.mmp'). DataFile::writeBundle() is then called. For now, it only saves the mmp/mmpz file normally and also creates a "resources" folder if it doesn't exists. Later it will also manipulate the DataFile so all paths are local and copy all files to the resources folder.
TODO:
-Remove warnings.
-Implement the logic to manipulate the DataFile and copy files.
* Starts implementing logic to go through resources
Starts implementing the logic that will go through all the resources of the project file and add them to the bundle. We use a std::map of QString to std::vector<QString>: The first string is the DOM element tagname that is going to be searched for. The vector of strings holds all attributes this element can have that accesses resources. For now we just print those to the screen.
* Adds logic to copy files and update the project
The raw logic for creating the bundle is finished. It now copies the resource files and update the project to use "local:" paths to the new file now.
Now it's a matter of organizing things and adding safety checks for file operation errors basically.
* Makes the writeBundle method more organized
Improves comments and debugging warnings to make the writeBundle a bit more organized for review.
* Adds a project bundle folder
Adds a project bundle folder, inside which the bundles will be created. Instead of receiving an output project file name, the makeBundle command now receives a bundle name that will be used as the name of the bundle's folder.
Uses a typedef for the std::map with the tags and attributes with resources.
TODO:
- Fix the local: prefix so it works when we don't have the project file open (for CLI usage, or find another way to deal with it).
- Sanitize the bundle name.
- Allow overwriting bundles?
* Handles local paths when a project isn't open
The PathUtil base prefix conversion for "local:" uses the loaded song file name. When we are running the makebundle command from the CLI there isn't a loaded project, so those prefixes aren't converted properly. Now, when there isn't a project open PathUtil will return "local:" again when it tries to convert this base prefix. DataFile can then check if the base prefix is still there, and if it is it knows the conversion wasn't possible, so it does the conversion itself. To do that, a member called m_fileName was added to DataFile, which will hold the file being manipulated if that's where the DataFile originated from, and the local path can be retrieved from it.
* Sanitizes the bundle name
The bundle name is now sanitized. Since it's going to be used as a folder name, we need to keep the user from giving invalid folder names as a bundle's name. The rules for the name are:
1) It must start with a word character (either a digit or letter)
2) It can be followed by any number of letters, digits, whitespaces or hyphens
3) It must end with a word character (either a digit or letter)
A Regexp is used to check for the name validity.
* Moves away from projectbundle folder concept
This commit regresses some functionality. Project bundles will be saved just as any other project, except they will also have the resources folder. It will be up to the user to organize the bundles on their own folders. It's currently not allowed to save a bundle on a folder where there's one already though (if there's a resources folder already). Later it might be allowed to overwrite bundles in that case.
The projectbundles folder was dropped. The user can save project bundles anywhere in the system.
The DataFile::writeBundle was removed. It's functionality was merged into the DataFile::writeFile method, by adding a boolean on the parameters defining whether it should be saved with resources. The logic of copying the resource files and changing the paths inside the project DataFile was moved to DataFile::copyResources, making the methods a little bit less dense.
* Adds an option to save project as bundle
The "Save As" dialog now has an option to save project as a project bundle (with resources), which will save the file as a bundle.
Known bug:
- Because the "local:" base prefix is translated to the filename from the Engine::getSong(), it breaks when Song::guiSaveProjectAs is called, because that method changes the project name before saving. Urgent fix!
* Fix local: prefix saving bug
There was a bug where "local:" prefixes weren't resolved properly during saving because Song::guiSaveProjectAs() changed the project name to the destiny file name before saving. This resulted in the local paths using the destination file as a reference. Both Song::guiSaveProject() and Song::guiSaveProjectAs() were rewritten, and now they only rename the project after it's saved.
* Adds a warning message box
When the user tries to save a project bundle on a folder that already has a project bundle (contains a resources folder) a message box pops up telling the user it's not permitted and that another path should be chosen.
* Removes unused header
Forgot to remove <QRegExp> header when I removed the code that used it.
* Removes Vestige plugins bundling
For safety reasons, remove the possibility to bundle VSTs loaded
through vestige. Also runs a safety check during the project being
loaded (Song::loadProject) to check if either Vestige plugins or effect
plugins are using local paths, and abort the project load if so. That is
to avoid malicious code being run because of bad DLLs being shipped with
a project file.
* Extracts code from loadProject to another method
Extracts code that checks if a DataFile contains local paths to
plugins to another method inside DataFile.
* Removes debug warnings
Removes warnings previously used for debugging. Improves a
warning message on PathUtil.
* Fixes small bug with error logging
Fixes small bug, where a QMessageBox was being used to prompt an
error without checking if the gui is loaded first. Now we check for the
GUI and if we are in CLI mode we use a QTextStream instead.
* Saves the bundle in a newly created folder
Now a folder with the project name is created inside which the
bundle will be saved. This makes the process more convenient.
Some save errors that previously only triggered qWarnings now
trigger message boxes to warn the user of what happened (using a lambda
function that either shows message boxes or trigger qWarnings depending
whether a gui is present).
Makes it so saving a bundle doesn't change the loaded project
path, that way the user won't be able to accidentally "Save" over a
bundle which should not be done for now.
* Enhances the name conflict workaround
Now, instead of replacing the resource names with meaningless
numbers, the bundle save will just append a counter to the end of
filenames that have been repeated.
* Starts addressing Johannes review
* Adds makebundle action to bash completion file
Adds the bash completion code for the made bundle action.
* Improves safety check on project files
Now, instead of checking certain XML tags for local paths,
DataFile::hasLocalPlugin() will return true if ANY tag that isn't on the
RESOURCE_ELEMENTS list contains an attribute that starts with "local:".
The method is now recursive so it can go through all XML tags
during this check.
* Addresses Spekular change request
Uses basePrefix(Base::LocalDir) instead of "local:" on the
return of unresolved local paths.
* Makes hasLocalPlugins method const
* Replaces literal uses of "local:"
Instead of using "local:" we are now retrieving the base prefix
from PathUtil, so if we change the prefix on the future we don't need to
replace every mention to it as well.
* Fix some comments on the header and cpp file
* Changes variable on PathUtil to const
Changes the retrieved pointer to the song object to a const
pointer.
* Leave doxygen comment on CPP file only
There was 2 doxygen comments for the same method, on the header
and CPP file. The latter was kept since it goes into more details about
the functionality of the method.
* Fix doxygen comment @param
Fixes the doxygen comment from hasLocalPlugin().
* Remove assert statements
Some assert statements were being done wrong and are probably
even unnecessary for that piece of code, so they were removed.
* Skips local paths when looking for shortest path
PathUtil::toShortestRelative() was including the local paths on
the candidate paths, which could lead to a unallowed resource (i.e.:
vst plugin) to be assigned a local path even on a regular save.
The local paths are now skipped when looking for the shortest
relative path, since they should only be used by the bundle save on the
allowed resources.
* Address Spekular's review
Changes some of the PathUtil methods to allow a boolean pointer
to be used to return the status of the method, setting it to false if it
failed somewhere.
Also adds a parameter to toShortestRelative to either allow or
forbid local paths in the search for the shortest relative path.
* Replaces "ok" with "error"
502 lines
10 KiB
C++
502 lines
10 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 <utility>
|
|
|
|
#include <QtCore/QSharedMemory>
|
|
#include <QtCore/QVector>
|
|
#include <QHash>
|
|
#include <QString>
|
|
|
|
#include "TrackContainer.h"
|
|
#include "Controller.h"
|
|
#include "MeterModel.h"
|
|
#include "Mixer.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( 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(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::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 setLoadOnLaunch(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 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 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;
|
|
|
|
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();
|
|
} ;
|
|
|
|
|
|
#endif
|