diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-04-23 15:29:45 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-04-23 15:29:45 +0000 |
commit | 1660f00ff3777b2bd52a4c73fe9aa43050f8ad34 (patch) | |
tree | 83ab8e6b2ee51302372fadb4d7ffe98340cde61f /libs/midi++2/port.cc | |
parent | 4bfdcc18bd5284879d02a4ed9f44905ba84058d4 (diff) |
libmidi++: split apart "base-y" aspects of MIDI::Port into MIDI::PortBase and make MIDI::Port derive from it. This actually makes MIDI::Port effectively into MIDI::JackPort, but i'm not interested in the name changing at that level at this moment in time
git-svn-id: svn://localhost/ardour2/branches/3.0@12064 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/midi++2/port.cc')
-rw-r--r-- | libs/midi++2/port.cc | 118 |
1 files changed, 28 insertions, 90 deletions
diff --git a/libs/midi++2/port.cc b/libs/midi++2/port.cc index b5a16eef01..06db2e14b8 100644 --- a/libs/midi++2/port.cc +++ b/libs/midi++2/port.cc @@ -43,34 +43,30 @@ using namespace PBD; pthread_t Port::_process_thread; Signal0<void> Port::JackHalted; Signal0<void> Port::MakeConnections; -string Port::state_node_name = "MIDI-port"; Port::Port (string const & name, Flags flags, jack_client_t* jack_client) - : _currently_in_cycle (false) + : PortBase (name, flags) + , _currently_in_cycle (false) , _nframes_this_cycle (0) , _jack_client (jack_client) , _jack_port (0) - , _last_read_index (0) , output_fifo (512) , input_fifo (1024) , xthread (true) - , _flags (flags) - , _centrally_parsed (true) { assert (jack_client); init (name, flags); } Port::Port (const XMLNode& node, jack_client_t* jack_client) - : _currently_in_cycle (false) + : PortBase (node) + , _currently_in_cycle (false) , _nframes_this_cycle (0) , _jack_client (jack_client) , _jack_port (0) - , _last_read_index (0) , output_fifo (512) , input_fifo (1024) , xthread (true) - , _centrally_parsed (true) { assert (jack_client); @@ -84,21 +80,7 @@ Port::Port (const XMLNode& node, jack_client_t* jack_client) void Port::init (string const & name, Flags flags) { - _ok = false; /* derived class must set to true if constructor - succeeds. - */ - - _parser = 0; - - _tagname = name; - _flags = flags; - - _parser = new Parser (*this); - - for (int i = 0; i < 16; i++) { - _channel[i] = new Channel (i, *this); - _channel[i]->connect_signals (); - } + PortBase::init (name, flags); if (!create_port ()) { _ok = true; @@ -160,21 +142,6 @@ Port::parse (framecnt_t timestamp) } } -/** Send a clock tick message. - * \return true on success. - */ -bool -Port::clock (timestamp_t timestamp) -{ - static byte clockmsg = 0xf8; - - if (sends_output()) { - return midimsg (&clockmsg, 1, timestamp); - } - - return false; -} - void Port::cycle_start (pframes_t nframes) { @@ -184,8 +151,6 @@ Port::cycle_start (pframes_t nframes) _nframes_this_cycle = nframes; assert(_nframes_this_cycle == nframes); - _last_read_index = 0; - _last_write_timestamp = 0; if (sends_output()) { void *buffer = jack_port_get_buffer (_jack_port, nframes); @@ -222,50 +187,30 @@ Port::cycle_end () _nframes_this_cycle = 0; } -std::ostream & MIDI::operator << ( std::ostream & os, const MIDI::Port & port ) +void +Port::jack_halted () { - using namespace std; - os << "MIDI::Port { "; - os << "name: " << port.name(); - os << "; "; - os << "ok: " << port.ok(); - os << "; "; - os << " }"; - return os; + _jack_client = 0; + _jack_port = 0; } -Port::Descriptor::Descriptor (const XMLNode& node) +void +Port::drain (int check_interval_usecs) { - const XMLProperty *prop; - bool have_tag = false; - bool have_mode = false; + RingBuffer< Evoral::Event<double> >::rw_vector vec = { { 0, 0 }, { 0, 0} }; - if ((prop = node.property ("tag")) != 0) { - tag = prop->value(); - have_tag = true; + if (is_process_thread()) { + error << "Process thread called MIDI::Port::drain() - this cannot work" << endmsg; + return; } - if ((prop = node.property ("mode")) != 0) { - - if (strings_equal_ignore_case (prop->value(), "output") || strings_equal_ignore_case (prop->value(), "out")) { - flags = IsOutput; - } else if (strings_equal_ignore_case (prop->value(), "input") || strings_equal_ignore_case (prop->value(), "in")) { - flags = IsInput; + while (1) { + output_fifo.get_write_vector (&vec); + if (vec.len[0] + vec.len[1] >= output_fifo.bufsize() - 1) { + break; } - - have_mode = true; + usleep (check_interval_usecs); } - - if (!have_tag || !have_mode) { - throw failed_constructor(); - } -} - -void -Port::jack_halted () -{ - _jack_client = 0; - _jack_port = 0; } int @@ -305,6 +250,8 @@ Port::write(byte * msg, size_t msglen, timestamp_t timestamp) ret = msglen; + usleep (5000); + } else { // XXX This had to be temporarily commented out to make export work again @@ -359,7 +306,7 @@ Port::flush (void* jack_port_buffer) output_fifo.get_read_vector (&vec); if (vec.len[0] + vec.len[1]) { - // cerr << "Flush " << vec.len[0] + vec.len[1] << " events from non-process FIFO\n"; + cerr << "Flush " << vec.len[0] + vec.len[1] << " events from non-process FIFO\n"; } if (vec.len[0]) { @@ -417,14 +364,7 @@ Port::create_port () XMLNode& Port::get_state () const { - XMLNode* root = new XMLNode (state_node_name); - root->add_property ("tag", _tagname); - - if (_flags == IsInput) { - root->add_property ("mode", "input"); - } else { - root->add_property ("mode", "output"); - } + XMLNode& root = PortBase::get_state (); #if 0 byte device_inquiry[6]; @@ -454,15 +394,15 @@ Port::get_state () const } if (!connection_string.empty()) { - root->add_property ("connections", connection_string); + root.add_property ("connections", connection_string); } } else { if (!_connections.empty()) { - root->add_property ("connections", _connections); + root.add_property ("connections", _connections); } } - return *root; + return root; } void @@ -470,9 +410,7 @@ Port::set_state (const XMLNode& node) { const XMLProperty* prop; - if ((prop = node.property ("tag")) == 0 || prop->value() != _tagname) { - return; - } + PortBase::set_state (node); if ((prop = node.property ("connections")) != 0 && _jack_port) { _connections = prop->value (); |