Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a save option to discard MIDI connections #5021

Merged
merged 10 commits into from
Jun 9, 2019
19 changes: 19 additions & 0 deletions include/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ class LMMS_EXPORT Song : public TrackContainer
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();
Expand Down Expand Up @@ -322,6 +333,11 @@ class LMMS_EXPORT Song : public TrackContainer
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();
Expand Down Expand Up @@ -419,9 +435,12 @@ private slots:
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;
Expand Down
10 changes: 10 additions & 0 deletions include/VersionedSaveDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@
#define VERSIONEDSAVEDIALOG_H

#include "FileDialog.h"
#include "Song.h"

class QLineEdit;
class LedCheckBox;

class SaveOptionsWidget : public QWidget {
public:
SaveOptionsWidget(Song::SaveOptions &saveOptions);

private:
LedCheckBox *m_discardMIDIConnectionsCheckbox;
};

class VersionedSaveDialog : public FileDialog
{
Q_OBJECT
public:
explicit VersionedSaveDialog( QWidget *parent = 0,
QWidget *saveOptionsWidget = nullptr,
const QString &caption = QString(),
const QString &directory = QString(),
const QString &filter = QString() );
Expand Down
12 changes: 10 additions & 2 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "LocaleHelper.h"
#include "Mixer.h"
#include "ProjectJournal.h"
#include "Song.h"

long AutomatableModel::s_periodCounter = 0;

Expand Down Expand Up @@ -131,8 +132,15 @@ void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, co
}
}

if( m_controllerConnection && m_controllerConnection->getController()->type()
!= Controller::DummyController )
// Skip saving MIDI connections if we're saving project and
// the discardMIDIConnections option is true.
auto controllerType = m_controllerConnection
? m_controllerConnection->getController()->type()
: Controller::DummyController;
bool skipMidiController = Engine::getSong()->isSavingProject()
&& Engine::getSong()->getSaveOptions().discardMIDIConnections.value();
if (m_controllerConnection && controllerType != Controller::DummyController
&& !(skipMidiController && controllerType == Controller::MidiController))
{
QDomElement controllerElement;

Expand Down
13 changes: 12 additions & 1 deletion src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ void Song::loadProject( const QString & fileName )
bool Song::saveProjectFile( const QString & filename )
{
DataFile dataFile( DataFile::SongProject );
m_savingProject = true;

m_tempoModel.saveSettings( dataFile, dataFile.head(), "bpm" );
m_timeSigModel.saveSettings( dataFile, dataFile.head(), "timesig" );
Expand All @@ -1233,6 +1234,8 @@ bool Song::saveProjectFile( const QString & filename )

saveControllerStates( dataFile, dataFile.content() );

m_savingProject = false;

return dataFile.writeFile( filename );
}

Expand Down Expand Up @@ -1265,7 +1268,11 @@ bool Song::guiSaveProjectAs( const QString & _file_name )
m_oldFileName = m_fileName;
setProjectFileName(_file_name);

if(!guiSaveProject())
bool saveResult = guiSaveProject();
// After saving as, restore default save options.
m_saveOptions.setDefaultOptions();

if(!saveResult)
{
// Saving failed. Restore old filenames.
setProjectFileName(m_oldFileName);
Expand Down Expand Up @@ -1434,3 +1441,7 @@ QString Song::errorSummary()

return errors;
}

bool Song::isSavingProject() const {
return m_savingProject;
}
3 changes: 2 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,8 @@ bool MainWindow::saveProject()

bool MainWindow::saveProjectAs()
{
VersionedSaveDialog sfd( this, tr( "Save Project" ), "",
auto optionsWidget = new SaveOptionsWidget(Engine::getSong()->getSaveOptions());
VersionedSaveDialog sfd( this, optionsWidget, tr( "Save Project" ), "",
tr( "LMMS Project" ) + " (*.mmpz *.mmp);;" +
tr( "LMMS Project Template" ) + " (*.mpt)" );
QString f = Engine::getSong()->projectFileName();
Expand Down
28 changes: 26 additions & 2 deletions src/gui/dialogs/VersionedSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QGroupBox>
#include <QLabel>

#include "VersionedSaveDialog.h"


#include "LedCheckbox.h"


VersionedSaveDialog::VersionedSaveDialog( QWidget *parent,
QWidget *saveOptionsWidget,
const QString &caption,
const QString &directory,
const QString &filter ) :
Expand Down Expand Up @@ -63,6 +65,17 @@ VersionedSaveDialog::VersionedSaveDialog( QWidget *parent,
hLayout->addWidget( minusButton );
layout->addLayout( hLayout, 2, 1 );

if (saveOptionsWidget) {
auto groupBox = new QGroupBox(tr("Save Options"));
auto optionsLayout = new QGridLayout;

optionsLayout->addWidget(saveOptionsWidget, 0, 0, Qt::AlignLeft);

groupBox->setLayout(optionsLayout);

layout->addWidget(groupBox, layout->rowCount() + 1, 0, 1, -1);
}

// Connect + and - buttons
connect( plusButton, SIGNAL( clicked() ), this, SLOT( incrementVersion() ));
connect( minusButton, SIGNAL( clicked() ), this, SLOT( decrementVersion() ));
Expand Down Expand Up @@ -160,3 +173,14 @@ bool VersionedSaveDialog::fileExistsQuery( QString FileName, QString WindowTitle
}
return fileExists;
}

SaveOptionsWidget::SaveOptionsWidget(Song::SaveOptions &saveOptions) {
auto *layout = new QVBoxLayout();

m_discardMIDIConnectionsCheckbox = new LedCheckBox(nullptr);
m_discardMIDIConnectionsCheckbox->setText(tr("Discard MIDI connections"));
m_discardMIDIConnectionsCheckbox->setModel(&saveOptions.discardMIDIConnections);
layout->addWidget(m_discardMIDIConnectionsCheckbox);

setLayout(layout);
}
9 changes: 8 additions & 1 deletion src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,14 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement
m_soundShaping.saveState( doc, thisElement );
m_noteStacking.saveState( doc, thisElement );
m_arpeggio.saveState( doc, thisElement );
m_midiPort.saveState( doc, thisElement );

// Don't save midi port info if the user chose to.
if (Engine::getSong()->isSavingProject()
&& !Engine::getSong()->getSaveOptions().discardMIDIConnections.value())
{
m_midiPort.saveState( doc, thisElement );
Reflexe marked this conversation as resolved.
Show resolved Hide resolved
}

m_audioPort.effects()->saveState( doc, thisElement );
}

Expand Down