*/
-#include "evoral/MIDIEvent.hpp"
+#include "evoral/Event.hpp"
#include "midi++/channel.h"
#include "midi++/parser.h"
#include "midi++/port.h"
#include "ardour/midi_scene_changer.h"
#include "ardour/session.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
using namespace ARDOUR;
, last_program_message_time (-1)
, last_delivered_program (-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));
}
/** Use the session's list of locations to collect all patch changes.
- *
+ *
* This is called whenever the locations change in anyway.
*/
void
if (msc->bank() >= 0) {
have_seen_bank_changes = true;
}
-
+
scenes.insert (std::make_pair ((*l)->start(), msc));
}
}
void
MIDISceneChanger::rt_deliver (MidiBuffer& mbuf, framepos_t when, boost::shared_ptr<MIDISceneChange> msc)
{
+ if (!msc->active()) {
+ return;
+ }
+
uint8_t buf[4];
size_t cnt;
void
MIDISceneChanger::non_rt_deliver (boost::shared_ptr<MIDISceneChange> msc)
{
+ if (!msc->active()) {
+ return;
+ }
+
uint8_t buf[4];
size_t cnt;
boost::shared_ptr<AsyncMIDIPort> aport = boost::dynamic_pointer_cast<AsyncMIDIPort>(output_port);
non-RT/process context. Using zero means "deliver them as early as
possible" (practically speaking, in the next process callback).
*/
-
+
MIDIOutputActivity (); /* EMIT SIGNAL */
if ((cnt = msc->get_bank_msb_message (buf, sizeof (buf))) > 0) {
}
Glib::Threads::RWLock::ReaderLock lm (scene_lock, Glib::Threads::TRY_LOCK);
-
+
if (!lm.locked()) {
return;
}
if (i->first >= end) {
break;
}
-
+
rt_deliver (mbuf, i->first - start, i->second);
-
+
++i;
}
}
if (scenes.empty()) {
return;
}
-
+
Scenes::const_iterator i = scenes.lower_bound (pos);
-
+
if (i != scenes.end()) {
if (i->first != pos) {
if (msc->program() != last_delivered_program || msc->bank() != last_delivered_bank) {
non_rt_deliver (msc);
}
-}
+}
void
-MIDISceneChanger::set_input_port (MIDI::Port* mp)
+MIDISceneChanger::set_input_port (boost::shared_ptr<MidiPort> mp)
{
- input_port = mp;
-
incoming_connections.drop_connections();
-
- if (input_port) {
-
+ input_port.reset ();
+
+ boost::shared_ptr<AsyncMIDIPort> async = boost::dynamic_pointer_cast<AsyncMIDIPort> (mp);
+
+ if (async) {
+
+ input_port = mp;
+
/* midi port is asynchronous. MIDI parsing will be carried out
* by the MIDI UI thread which will emit the relevant signals
* and thus invoke our callbacks as necessary.
*/
for (int channel = 0; channel < 16; ++channel) {
- input_port->parser()->channel_bank_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::bank_change_input, this, _1, _2, channel));
- input_port->parser()->channel_program_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::program_change_input, this, _1, _2, channel));
+ async->parser()->channel_bank_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::bank_change_input, this, _1, _2, channel));
+ async->parser()->channel_program_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::program_change_input, this, _1, _2, channel));
}
}
}
}
bool
-MIDISceneChanger::recording() const
+MIDISceneChanger::recording() const
{
return _session.transport_rolling() && _session.get_record_enabled();
}
last_program_message_time = time;
if (!recording()) {
+
MIDIInputActivity (); /* EMIT SIGNAL */
- jump_to (input_port->channel (channel)->bank(), program);
+
+ int bank = -1;
+ if (have_seen_bank_changes) {
+ bank = boost::dynamic_pointer_cast<AsyncMIDIPort>(input_port)->channel (channel)->bank();
+ }
+
+ jump_to (bank, program);
return;
}
Locations* locations (_session.locations ());
Location* loc;
bool new_mark = false;
- framecnt_t slop = (framecnt_t) floor ((Config->get_inter_scene_gap_msecs() / 1000.0) * _session.frame_rate());
/* check for marker at current location */
- loc = locations->mark_at (time, slop);
+ loc = locations->mark_at (time, Config->get_inter_scene_gap_frames());
if (!loc) {
/* create a new marker at the desired position */
-
+
std::string new_name;
if (!locations->next_available_name (new_name, _("Scene "))) {
std::cerr << "No new marker name available\n";
return;
}
-
- loc = new Location (_session, time, time, new_name, Location::IsMark);
+
+ loc = new Location (_session, time, time, new_name, Location::IsMark, 0);
new_mark = true;
}
- unsigned short bank;
-
+ int bank = -1;
if (have_seen_bank_changes) {
- bank = input_port->channel (channel)->bank();
- } else {
- bank = -1;
+ bank = boost::dynamic_pointer_cast<AsyncMIDIPort>(input_port)->channel (channel)->bank();
}
MIDISceneChange* msc =new MIDISceneChange (channel, bank, program & 0x7f);
}
loc->set_scene_change (boost::shared_ptr<MIDISceneChange> (msc));
-
+
/* this will generate a "changed" signal to be emitted by locations,
and we will call ::gather() to update our list of MIDI events.
*/