mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-04 20:55:48 +01:00
infrastructure for MIDI-input-follows-selection
This commit is contained in:
parent
0a8ab08e5f
commit
f96b698234
5 changed files with 88 additions and 20 deletions
|
|
@ -134,6 +134,10 @@ class LIBARDOUR_API PortManager
|
|||
void add_to_midi_selection_ports (std::string const&);
|
||||
void remove_from_midi_selection_ports (std::string const&);
|
||||
void clear_midi_selection_ports ();
|
||||
bool port_is_for_midi_selection (std::string const&);
|
||||
|
||||
/** Emitted if the list of ports to be used for MIDI selection tracking changes */
|
||||
PBD::Signal0<void> MidiSelectionPortsChanged;
|
||||
|
||||
/** Emitted if the backend notifies us of a graph order event */
|
||||
PBD::Signal0<void> GraphReordered;
|
||||
|
|
|
|||
|
|
@ -2037,6 +2037,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
|
|||
|
||||
void midi_track_presentation_info_changed (PBD::PropertyChange const &, boost::weak_ptr<MidiTrack>);
|
||||
void rewire_selected_midi (boost::shared_ptr<MidiTrack>);
|
||||
void rewire_midi_selection_ports ();
|
||||
boost::weak_ptr<MidiTrack> current_midi_target;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -852,6 +852,13 @@ PortManager::port_is_control_only (std::string const& name)
|
|||
return regexec (&compiled_pattern, name.c_str(), 0, 0, 0) == 0;
|
||||
}
|
||||
|
||||
bool
|
||||
PortManager::port_is_for_midi_selection (std::string const & name)
|
||||
{
|
||||
Glib::Threads::Mutex::Lock lm (midi_selection_ports_mutex);
|
||||
return find (_midi_selection_ports.begin(), _midi_selection_ports.end(), name) != _midi_selection_ports.end();
|
||||
}
|
||||
|
||||
void
|
||||
PortManager::get_midi_selection_ports (MidiSelectionPorts& copy) const
|
||||
{
|
||||
|
|
@ -862,25 +869,47 @@ PortManager::get_midi_selection_ports (MidiSelectionPorts& copy) const
|
|||
void
|
||||
PortManager::add_to_midi_selection_ports (string const & port)
|
||||
{
|
||||
Glib::Threads::Mutex::Lock lm (midi_selection_ports_mutex);
|
||||
if (find (_midi_selection_ports.begin(), _midi_selection_ports.end(), port) == _midi_selection_ports.end()) {
|
||||
_midi_selection_ports.push_back (port);
|
||||
bool emit = false;
|
||||
|
||||
{
|
||||
Glib::Threads::Mutex::Lock lm (midi_selection_ports_mutex);
|
||||
if (find (_midi_selection_ports.begin(), _midi_selection_ports.end(), port) == _midi_selection_ports.end()) {
|
||||
_midi_selection_ports.push_back (port);
|
||||
emit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (emit) {
|
||||
MidiSelectionPortsChanged (); /* EMIT SIGNAL */
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PortManager::remove_from_midi_selection_ports (string const & port)
|
||||
{
|
||||
Glib::Threads::Mutex::Lock lm (midi_selection_ports_mutex);
|
||||
MidiSelectionPorts::iterator x = find (_midi_selection_ports.begin(), _midi_selection_ports.end(), port);
|
||||
if (x != _midi_selection_ports.end()) {
|
||||
_midi_selection_ports.erase (x);
|
||||
bool emit = false;
|
||||
|
||||
{
|
||||
Glib::Threads::Mutex::Lock lm (midi_selection_ports_mutex);
|
||||
MidiSelectionPorts::iterator x = find (_midi_selection_ports.begin(), _midi_selection_ports.end(), port);
|
||||
if (x != _midi_selection_ports.end()) {
|
||||
_midi_selection_ports.erase (x);
|
||||
emit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (emit) {
|
||||
MidiSelectionPortsChanged (); /* EMIT SIGNAL */
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PortManager::clear_midi_selection_ports ()
|
||||
{
|
||||
Glib::Threads::Mutex::Lock lm (midi_selection_ports_mutex);
|
||||
_midi_selection_ports.clear ();
|
||||
{
|
||||
Glib::Threads::Mutex::Lock lm (midi_selection_ports_mutex);
|
||||
_midi_selection_ports.clear ();
|
||||
}
|
||||
|
||||
MidiSelectionPortsChanged (); /* EMIT SIGNAL */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -737,6 +737,7 @@ Session::midi_track_presentation_info_changed (PropertyChange const& what_change
|
|||
boost::shared_ptr<MidiTrack> new_midi_target (mt.lock ());
|
||||
|
||||
if (new_midi_target->presentation_info().selected()) {
|
||||
cerr << "Rewiring " << new_midi_target->name() << endl;
|
||||
rewire_selected_midi (new_midi_target);
|
||||
}
|
||||
}
|
||||
|
|
@ -755,22 +756,54 @@ Session::rewire_selected_midi (boost::shared_ptr<MidiTrack> new_midi_target)
|
|||
}
|
||||
|
||||
PortManager::MidiSelectionPorts msp;
|
||||
|
||||
AudioEngine::instance()->get_midi_selection_ports (msp);
|
||||
|
||||
if (msp.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (old_midi_target) {
|
||||
for (PortManager::MidiSelectionPorts::const_iterator p = msp.begin(); p != msp.end(); ++p) {
|
||||
old_midi_target->input()->disconnect (old_midi_target->input()->nth (0), (*p), this);
|
||||
if (!msp.empty()) {
|
||||
if (old_midi_target) {
|
||||
for (PortManager::MidiSelectionPorts::const_iterator p = msp.begin(); p != msp.end(); ++p) {
|
||||
old_midi_target->input()->disconnect (old_midi_target->input()->nth (0), (*p), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PortManager::MidiSelectionPorts::const_iterator p = msp.begin(); p != msp.end(); ++p) {
|
||||
new_midi_target->input()->connect (new_midi_target->input()->nth(0), (*p), this);
|
||||
for (PortManager::MidiSelectionPorts::const_iterator p = msp.begin(); p != msp.end(); ++p) {
|
||||
new_midi_target->input()->connect (new_midi_target->input()->nth(0), (*p), this);
|
||||
}
|
||||
}
|
||||
|
||||
current_midi_target = new_midi_target;
|
||||
}
|
||||
|
||||
void
|
||||
Session::rewire_midi_selection_ports ()
|
||||
{
|
||||
cerr << "RMSP\n";
|
||||
|
||||
if (!Config->get_midi_input_follows_selection()) {
|
||||
cerr << "nope\n";
|
||||
return;
|
||||
}
|
||||
|
||||
boost::shared_ptr<MidiTrack> target = current_midi_target.lock();
|
||||
|
||||
if (!target) {
|
||||
cerr << "no target\n";
|
||||
return;
|
||||
}
|
||||
|
||||
PortManager::MidiSelectionPorts msp;
|
||||
AudioEngine::instance()->get_midi_selection_ports (msp);
|
||||
|
||||
if (msp.empty()) {
|
||||
cerr << "no MSP\n";
|
||||
return;
|
||||
}
|
||||
|
||||
cerr << "2. Rewiring " << target->name() << endl;
|
||||
|
||||
target->input()->disconnect (this);
|
||||
|
||||
for (PortManager::MidiSelectionPorts::const_iterator p = msp.begin(); p != msp.end(); ++p) {
|
||||
cerr << "\tconnect to " << *p << endl;
|
||||
target->input()->connect (target->input()->nth (0), (*p), this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,6 +270,7 @@ Session::post_engine_init ()
|
|||
|
||||
SndFileSource::setup_standard_crossfades (*this, frame_rate());
|
||||
_engine.GraphReordered.connect_same_thread (*this, boost::bind (&Session::graph_reordered, this));
|
||||
_engine.MidiSelectionPortsChanged.connect_same_thread (*this, boost::bind (&Session::rewire_midi_selection_ports, this));
|
||||
|
||||
AudioDiskstream::allocate_working_buffers();
|
||||
refresh_disk_space ();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue