Mixer: Because disconnecting/connecting JACK ports is slow, when handling a change of strip auto input setting, avoid disconnecting a port and then reconnecting it later.

pull/119/merge
Jonathan Moore Liles 2020-12-13 14:46:46 -08:00
parent 20dce6c6e6
commit 9f3181b9c7
3 changed files with 58 additions and 0 deletions

View File

@ -940,6 +940,9 @@ Mixer_Strip::menu_cb ( Fl_Widget *w, void *v )
void void
Mixer_Strip::auto_input ( const char *s ) Mixer_Strip::auto_input ( const char *s )
{ {
/* break old connections */
disconnect_auto_inputs(s);
if ( _auto_input ) if ( _auto_input )
free( _auto_input ); free( _auto_input );
@ -948,6 +951,7 @@ Mixer_Strip::auto_input ( const char *s )
if ( s ) if ( s )
_auto_input = strdup( s ); _auto_input = strdup( s );
/* make new connections */
mixer->auto_connect(); mixer->auto_connect();
} }
@ -1024,6 +1028,42 @@ Mixer_Strip::has_group_affinity ( void ) const
return _auto_input && strncmp( _auto_input, "*/", 2 ); return _auto_input && strncmp( _auto_input, "*/", 2 );
} }
void
Mixer_Strip::disconnect_auto_inputs ( const char *exclude_pattern )
{
if ( chain() )
{
JACK_Module *m = (JACK_Module*)chain()->module(0);
if ( m )
{
for ( unsigned int i = 0; i < m->aux_audio_input.size(); ++i )
{
Module::Port *p1 = &m->aux_audio_input[i];
if ( _auto_input && exclude_pattern )
{
/* avoid disconnecting a port that we'll immediately be reconnecting */
for ( unsigned int j = 0; j < p1->nconnected(); ++j )
{
Module::Port *p2 = p1->connected_port( j );
if ( !matches_pattern( exclude_pattern, p2 ) )
{
p1->disconnect( p2 );
j--; /* keep our place in the iteration */
}
}
}
else
{
m->aux_audio_input[i].disconnect();
}
}
}
}
}
bool bool
Mixer_Strip::maybe_auto_connect_output ( Module::Port *p ) Mixer_Strip::maybe_auto_connect_output ( Module::Port *p )
{ {
@ -1071,6 +1111,9 @@ Mixer_Strip::maybe_auto_connect_output ( Module::Port *p )
return false; return false;
} }
if ( ! m->aux_audio_input[n].connected_to( p ) )
m->aux_audio_input[n].connect_to( p );
m->aux_audio_input[n].connect_to( p ); m->aux_audio_input[n].connect_to( p );
if ( p->module()->is_default() ) if ( p->module()->is_default() )

View File

@ -161,6 +161,7 @@ public:
void manual_connection ( bool b ); void manual_connection ( bool b );
bool has_group_affinity ( void ) const; bool has_group_affinity ( void ) const;
void disconnect_auto_inputs ( const char *exclude_pattern );
void auto_connect_outputs ( void ); void auto_connect_outputs ( void );
bool maybe_auto_connect_output ( Module::Port *p ); bool maybe_auto_connect_output ( Module::Port *p );

View File

@ -264,6 +264,9 @@ public:
/* control and external audio ports belong to a graph */ /* control and external audio ports belong to a graph */
return _connected.size() > 0; return _connected.size() > 0;
} }
unsigned int nconnected ( void ) const { return _connected.size(); }
bool connected_osc ( void ) const; bool connected_osc ( void ) const;
Port *connected_port ( void ) const Port *connected_port ( void ) const
@ -271,6 +274,17 @@ public:
return _connected.size() == 0 ? NULL : _connected.front(); return _connected.size() == 0 ? NULL : _connected.front();
} }
Port *connected_port ( int n ) const
{
int j = 0;
for ( std::list<Module::Port*>::const_iterator i = _connected.begin();
i != _connected.end(); ++i, ++j )
if ( j == n )
return *i;
return NULL;
}
void connect_to ( Port *to ) void connect_to ( Port *to )
{ {
if ( _type != Port::AUX_AUDIO ) if ( _type != Port::AUX_AUDIO )