change API for shadow ports and filters
Filter functor needs to be set before registering port, so provide it when adding the port.
This commit is contained in:
parent
62d2d86b88
commit
8565d61444
@ -73,8 +73,9 @@ class LIBARDOUR_API AsyncMIDIPort : public ARDOUR::MidiPort, public MIDI::Port {
|
|||||||
int selectable() const { return -1; }
|
int selectable() const { return -1; }
|
||||||
void set_timer (boost::function<framecnt_t (void)>&);
|
void set_timer (boost::function<framecnt_t (void)>&);
|
||||||
|
|
||||||
void set_inbound_filter (boost::function<bool(MidiBuffer&,MidiBuffer&)>);
|
typedef boost::function<bool(MidiBuffer&,MidiBuffer&)> MidiFilter;
|
||||||
int add_shadow_port (std::string const &);
|
void set_inbound_filter (MidiFilter);
|
||||||
|
int add_shadow_port (std::string const &, MidiFilter);
|
||||||
|
|
||||||
static void set_process_thread (pthread_t);
|
static void set_process_thread (pthread_t);
|
||||||
static pthread_t get_process_thread () { return _process_thread; }
|
static pthread_t get_process_thread () { return _process_thread; }
|
||||||
@ -104,8 +105,10 @@ class LIBARDOUR_API AsyncMIDIPort : public ARDOUR::MidiPort, public MIDI::Port {
|
|||||||
|
|
||||||
void flush_output_fifo (pframes_t);
|
void flush_output_fifo (pframes_t);
|
||||||
|
|
||||||
|
MidiFilter inbound_midi_filter;
|
||||||
|
|
||||||
boost::shared_ptr<MidiPort> shadow_port;
|
boost::shared_ptr<MidiPort> shadow_port;
|
||||||
boost::function<bool(MidiBuffer&,MidiBuffer&)> inbound_midi_filter;
|
MidiFilter shadow_midi_filter;
|
||||||
|
|
||||||
static pthread_t _process_thread;
|
static pthread_t _process_thread;
|
||||||
};
|
};
|
||||||
|
@ -41,30 +41,6 @@ pthread_t AsyncMIDIPort::_process_thread;
|
|||||||
|
|
||||||
#define port_engine AudioEngine::instance()->port_engine()
|
#define port_engine AudioEngine::instance()->port_engine()
|
||||||
|
|
||||||
static bool
|
|
||||||
filter_relax (MidiBuffer& in, MidiBuffer& out)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
filter_copy (MidiBuffer& in, MidiBuffer& out)
|
|
||||||
{
|
|
||||||
out.copy (in);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
filter_notes_only (MidiBuffer& in, MidiBuffer& out)
|
|
||||||
{
|
|
||||||
for (MidiBuffer::iterator b = in.begin(); b != in.end(); ++b) {
|
|
||||||
if ((*b).is_note_on() || (*b).is_note_off()) {
|
|
||||||
out.push_back (*b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncMIDIPort::AsyncMIDIPort (string const & name, PortFlags flags)
|
AsyncMIDIPort::AsyncMIDIPort (string const & name, PortFlags flags)
|
||||||
: MidiPort (name, flags)
|
: MidiPort (name, flags)
|
||||||
, MIDI::Port (name, MIDI::Port::Flags (0))
|
, MIDI::Port (name, MIDI::Port::Flags (0))
|
||||||
@ -74,7 +50,6 @@ AsyncMIDIPort::AsyncMIDIPort (string const & name, PortFlags flags)
|
|||||||
, output_fifo (2048)
|
, output_fifo (2048)
|
||||||
, input_fifo (1024)
|
, input_fifo (1024)
|
||||||
, _xthread (true)
|
, _xthread (true)
|
||||||
, inbound_midi_filter (boost::bind (filter_notes_only, _1, _2))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,11 +146,13 @@ AsyncMIDIPort::cycle_start (MIDI::pframes_t nframes)
|
|||||||
_xthread.wakeup ();
|
_xthread.wakeup ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shadow_port) {
|
if (inbound_midi_filter) {
|
||||||
inbound_midi_filter (mb, shadow_port->get_midi_buffer (nframes));
|
|
||||||
} else {
|
|
||||||
inbound_midi_filter (mb, mb);
|
inbound_midi_filter (mb, mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shadow_port) {
|
||||||
|
shadow_midi_filter (mb, shadow_port->get_midi_buffer (nframes));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +350,7 @@ AsyncMIDIPort::is_process_thread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
AsyncMIDIPort::add_shadow_port (string const & name)
|
AsyncMIDIPort::add_shadow_port (string const & name, MidiFilter mf)
|
||||||
{
|
{
|
||||||
if (!ARDOUR::Port::receives_input()) {
|
if (!ARDOUR::Port::receives_input()) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -383,6 +360,8 @@ AsyncMIDIPort::add_shadow_port (string const & name)
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shadow_midi_filter = mf;
|
||||||
|
|
||||||
/* shadow port is not async. */
|
/* shadow port is not async. */
|
||||||
|
|
||||||
if (!(shadow_port = boost::dynamic_pointer_cast<MidiPort> (AudioEngine::instance()->register_output_port (DataType::MIDI, name, false)))) {
|
if (!(shadow_port = boost::dynamic_pointer_cast<MidiPort> (AudioEngine::instance()->register_output_port (DataType::MIDI, name, false)))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user