13
0

catch up with waves/tracks version of MIDI scene changer code

This commit is contained in:
Paul Davis 2014-11-05 13:14:10 -05:00
parent b02ea3d435
commit 98b66b9f3d
2 changed files with 43 additions and 15 deletions

View File

@ -43,6 +43,13 @@ class MIDISceneChanger : public SceneChanger
void set_recording (bool); void set_recording (bool);
void locate (framepos_t); void locate (framepos_t);
/** Signal emitted whenever any relevant MIDI input is detected.
*/
PBD::Signal0<void> MIDIInputActivity;
/** Signal emitted whenever any relevant MIDI output is sent.
*/
PBD::Signal0<void> MIDIOutputActivity;
private: private:
typedef std::multimap<framepos_t,boost::shared_ptr<MIDISceneChange> > Scenes; typedef std::multimap<framepos_t,boost::shared_ptr<MIDISceneChange> > Scenes;
@ -51,13 +58,13 @@ class MIDISceneChanger : public SceneChanger
Glib::Threads::RWLock scene_lock; Glib::Threads::RWLock scene_lock;
Scenes scenes; Scenes scenes;
bool _recording; bool _recording;
framepos_t last_bank_message_time; bool have_seen_bank_changes;
framepos_t last_program_message_time; framepos_t last_program_message_time;
unsigned short current_bank; unsigned short current_bank;
int last_delivered_program; int last_delivered_program;
int last_delivered_bank; int last_delivered_bank;
void gather (); void gather (const Locations::LocationList&);
bool recording () const; bool recording () const;
void jump_to (int bank, int program); void jump_to (int bank, int program);
void rt_deliver (MidiBuffer&, framepos_t, boost::shared_ptr<MIDISceneChange>); void rt_deliver (MidiBuffer&, framepos_t, boost::shared_ptr<MIDISceneChange>);

View File

@ -36,14 +36,19 @@ using namespace ARDOUR;
MIDISceneChanger::MIDISceneChanger (Session& s) MIDISceneChanger::MIDISceneChanger (Session& s)
: SceneChanger (s) : SceneChanger (s)
, _recording (true) , _recording (true)
, last_bank_message_time (-1) , have_seen_bank_changes (false)
, last_program_message_time (-1) , last_program_message_time (-1)
, last_delivered_program (-1) , last_delivered_program (-1)
, last_delivered_bank (-1) , last_delivered_bank (-1)
{ {
/* catch any add/remove/clear etc. for all Locations */
_session.locations()->changed.connect_same_thread (*this, boost::bind (&MIDISceneChanger::locations_changed, this)); _session.locations()->changed.connect_same_thread (*this, boost::bind (&MIDISceneChanger::locations_changed, this));
Location::scene_changed.connect_same_thread (*this, boost::bind (&MIDISceneChanger::gather, this)); _session.locations()->added.connect_same_thread (*this, boost::bind (&MIDISceneChanger::locations_changed, this));
_session.locations()->removed.connect_same_thread (*this, boost::bind (&MIDISceneChanger::locations_changed, this));
/* catch class-based signal that notifies of us changes in the scene change state of any Location */
Location::scene_changed.connect_same_thread (*this, boost::bind (&MIDISceneChanger::locations_changed, this));
} }
MIDISceneChanger::~MIDISceneChanger () MIDISceneChanger::~MIDISceneChanger ()
@ -53,7 +58,7 @@ MIDISceneChanger::~MIDISceneChanger ()
void void
MIDISceneChanger::locations_changed () MIDISceneChanger::locations_changed ()
{ {
gather (); _session.locations()->apply (*this, &MIDISceneChanger::gather);
} }
/** Use the session's list of locations to collect all patch changes. /** Use the session's list of locations to collect all patch changes.
@ -61,9 +66,8 @@ MIDISceneChanger::locations_changed ()
* This is called whenever the locations change in anyway. * This is called whenever the locations change in anyway.
*/ */
void void
MIDISceneChanger::gather () MIDISceneChanger::gather (const Locations::LocationList& locations)
{ {
const Locations::LocationList& locations (_session.locations()->list());
boost::shared_ptr<SceneChange> sc; boost::shared_ptr<SceneChange> sc;
Glib::Threads::RWLock::WriterLock lm (scene_lock); Glib::Threads::RWLock::WriterLock lm (scene_lock);
@ -77,6 +81,11 @@ MIDISceneChanger::gather ()
boost::shared_ptr<MIDISceneChange> msc = boost::dynamic_pointer_cast<MIDISceneChange> (sc); boost::shared_ptr<MIDISceneChange> msc = boost::dynamic_pointer_cast<MIDISceneChange> (sc);
if (msc) { if (msc) {
if (msc->bank() >= 0) {
have_seen_bank_changes = true;
}
scenes.insert (std::make_pair ((*l)->start(), msc)); scenes.insert (std::make_pair ((*l)->start(), msc));
} }
} }
@ -89,6 +98,8 @@ MIDISceneChanger::rt_deliver (MidiBuffer& mbuf, framepos_t when, boost::shared_p
uint8_t buf[4]; uint8_t buf[4];
size_t cnt; size_t cnt;
MIDIOutputActivity (); /* EMIT SIGNAL */
if ((cnt = msc->get_bank_msb_message (buf, sizeof (buf))) > 0) { if ((cnt = msc->get_bank_msb_message (buf, sizeof (buf))) > 0) {
mbuf.push_back (when, cnt, buf); mbuf.push_back (when, cnt, buf);
@ -118,6 +129,8 @@ MIDISceneChanger::non_rt_deliver (boost::shared_ptr<MIDISceneChange> msc)
possible" (practically speaking, in the next process callback). possible" (practically speaking, in the next process callback).
*/ */
MIDIOutputActivity (); /* EMIT SIGNAL */
if ((cnt = msc->get_bank_msb_message (buf, sizeof (buf))) > 0) { if ((cnt = msc->get_bank_msb_message (buf, sizeof (buf))) > 0) {
aport->write (buf, cnt, 0); aport->write (buf, cnt, 0);
@ -243,13 +256,12 @@ MIDISceneChanger::recording() const
} }
void void
MIDISceneChanger::bank_change_input (MIDI::Parser& parser, unsigned short, int) MIDISceneChanger::bank_change_input (MIDI::Parser& /*parser*/, unsigned short, int)
{ {
if (!recording()) { if (recording()) {
return; have_seen_bank_changes = true;
} }
MIDIInputActivity (); /* EMIT SIGNAL */
last_bank_message_time = parser.get_timestamp ();
} }
void void
@ -260,6 +272,7 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program
last_program_message_time = time; last_program_message_time = time;
if (!recording()) { if (!recording()) {
MIDIInputActivity (); /* EMIT SIGNAL */
jump_to (input_port->channel (channel)->bank(), program); jump_to (input_port->channel (channel)->bank(), program);
return; return;
} }
@ -287,7 +300,13 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program
new_mark = true; new_mark = true;
} }
unsigned short bank = input_port->channel (channel)->bank(); unsigned short bank;
if (have_seen_bank_changes) {
bank = input_port->channel (channel)->bank();
} else {
bank = -1;
}
MIDISceneChange* msc =new MIDISceneChange (channel, bank, program & 0x7f); MIDISceneChange* msc =new MIDISceneChange (channel, bank, program & 0x7f);
@ -300,6 +319,8 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program
if (new_mark) { if (new_mark) {
locations->add (loc); locations->add (loc);
} }
MIDIInputActivity (); /* EMIT SIGNAL */
} }
void void