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 CLI flag to disconnect all MIDI controllers when loading a project #4883

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ class LMMS_EXPORT Song : public TrackContainer
return false;
}

inline void setDisconnectMidiControllersOnLoad( bool val )
{
m_disconnectMidiControllersOnLoad = val;
}

inline bool getDisconnectMidiControllersOnLoad()
{
return m_disconnectMidiControllersOnLoad;
}

void addController( Controller * c );
void removeController( Controller * c );

Expand Down Expand Up @@ -419,6 +429,8 @@ private slots:
volatile bool m_playing;
volatile bool m_paused;

bool m_disconnectMidiControllersOnLoad;

bool m_loadingProject;
bool m_isCancelled;

Expand Down
12 changes: 11 additions & 1 deletion src/core/ControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,19 @@ void ControllerConnection::saveSettings( QDomDocument & _doc, QDomElement & _thi
void ControllerConnection::loadSettings( const QDomElement & _this )
{
QDomNode node = _this.firstChild();

bool disconnectMidiControllers = Engine::getSong()->getDisconnectMidiControllersOnLoad();

if( !node.isNull() )
{
setController( Controller::create( node.toElement(), Engine::getSong() ) );
if ( disconnectMidiControllers )
{
deleteConnection();
}
else
{
setController( Controller::create( node.toElement(), Engine::getSong() ) );
}
}
else
{
Expand Down
8 changes: 8 additions & 0 deletions src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ void printHelp()
" --allowroot Bypass root user startup check (use with\n"
" caution).\n"
" -c, --config <configfile> Get the configuration from <configfile>\n"
" --disconnect-midi-controllers\n"
" Disconnect all MIDI inputs and controllers.\n"
" -h, --help Show this usage information and exit.\n"
" -v, --version Show version information and exit.\n"
"\nOptions if no action is given:\n"
Expand Down Expand Up @@ -300,6 +302,7 @@ int main( int argc, char * * argv )
bool allowRoot = false;
bool renderLoop = false;
bool renderTracks = false;
bool disconnectMidiControllers = false;
QString fileToLoad, fileToImport, renderOut, profilerOutputFile, configFile;

// first of two command-line parsing stages
Expand Down Expand Up @@ -673,6 +676,10 @@ int main( int argc, char * * argv )

configFile = QString::fromLocal8Bit( argv[i] );
}
else if( arg == "--disconnect-midi-controllers" )
{
disconnectMidiControllers = true;
}
else
{
if( argv[i][0] == '-' )
Expand Down Expand Up @@ -922,6 +929,7 @@ int main( int argc, char * * argv )
}
else
{
Engine::getSong()->setDisconnectMidiControllersOnLoad( disconnectMidiControllers );
Engine::getSong()->loadProject( fileToLoad );
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/midi/MidiPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ void MidiPort::loadSettings( const QDomElement& thisElement )

// restore connections

if( isInputEnabled() )
bool disconnectMidiControllers = Engine::getSong()->getDisconnectMidiControllersOnLoad();

if( isInputEnabled() && !disconnectMidiControllers )
{
QStringList rp = thisElement.attribute( "inports" ).split( ',' );
for( Map::ConstIterator it = m_readablePorts.begin(); it != m_readablePorts.end(); ++it )
Expand Down