basic infrastructure for enabling/disabling MIDI input to a given track
git-svn-id: svn://localhost/ardour2/branches/3.0@9772 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
@@ -46,6 +46,9 @@ class MidiPort : public Port {
|
||||
void realtime_locate ();
|
||||
void reset ();
|
||||
|
||||
bool input_active() const { return _input_active; }
|
||||
void set_input_active (bool yn);
|
||||
|
||||
Buffer& get_buffer (pframes_t nframes) {
|
||||
return get_midi_buffer (nframes);
|
||||
}
|
||||
@@ -59,8 +62,9 @@ class MidiPort : public Port {
|
||||
|
||||
private:
|
||||
MidiBuffer* _buffer;
|
||||
bool _has_been_mixed_down;
|
||||
bool _resolve_required;
|
||||
bool _has_been_mixed_down;
|
||||
bool _resolve_required;
|
||||
bool _input_active;
|
||||
|
||||
void resolve_notes (void* jack_buffer, MidiBuffer::TimeType when);
|
||||
};
|
||||
|
||||
@@ -105,6 +105,10 @@ public:
|
||||
|
||||
PBD::Signal2<void, boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource> > DataRecorded;
|
||||
|
||||
void set_input_active (bool);
|
||||
bool input_active () const;
|
||||
PBD::Signal0<void> InputActiveChanged;
|
||||
|
||||
protected:
|
||||
XMLNode& state (bool full);
|
||||
|
||||
|
||||
@@ -532,6 +532,10 @@ MidiDiskstream::process (framepos_t transport_frame, pframes_t nframes, bool can
|
||||
}
|
||||
|
||||
if (buf.size() != 0) {
|
||||
/* XXX this needs fixing - realtime new() call for
|
||||
every time we get MIDI data in a process callback!
|
||||
*/
|
||||
|
||||
/* Make a copy of this data and emit it for the GUI to see */
|
||||
boost::shared_ptr<MidiBuffer> copy (new MidiBuffer (buf.capacity ()));
|
||||
for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) {
|
||||
|
||||
@@ -30,6 +30,7 @@ MidiPort::MidiPort (const std::string& name, Flags flags)
|
||||
: Port (name, DataType::MIDI, flags)
|
||||
, _has_been_mixed_down (false)
|
||||
, _resolve_required (false)
|
||||
, _input_active (true)
|
||||
{
|
||||
_buffer = new MidiBuffer (AudioEngine::instance()->raw_buffer_size (DataType::MIDI));
|
||||
}
|
||||
@@ -62,36 +63,42 @@ MidiPort::get_midi_buffer (pframes_t nframes)
|
||||
|
||||
if (receives_input ()) {
|
||||
|
||||
void* jack_buffer = jack_port_get_buffer (_jack_port, nframes);
|
||||
const pframes_t event_count = jack_midi_get_event_count (jack_buffer);
|
||||
if (_input_active) {
|
||||
|
||||
assert (event_count < _buffer->capacity());
|
||||
void* jack_buffer = jack_port_get_buffer (_jack_port, nframes);
|
||||
const pframes_t event_count = jack_midi_get_event_count (jack_buffer);
|
||||
|
||||
assert (event_count < _buffer->capacity());
|
||||
|
||||
/* suck all relevant MIDI events from the JACK MIDI port buffer
|
||||
into our MidiBuffer
|
||||
*/
|
||||
|
||||
for (pframes_t i = 0; i < event_count; ++i) {
|
||||
|
||||
jack_midi_event_t ev;
|
||||
|
||||
jack_midi_event_get (&ev, jack_buffer, i);
|
||||
|
||||
if (ev.buffer[0] == 0xfe) {
|
||||
/* throw away active sensing */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check that the event is in the acceptable time range */
|
||||
|
||||
if ((ev.time >= (_global_port_buffer_offset + _port_buffer_offset)) &&
|
||||
(ev.time < (_global_port_buffer_offset + _port_buffer_offset + nframes))) {
|
||||
_buffer->push_back (ev);
|
||||
} else {
|
||||
cerr << "Dropping incoming MIDI at time " << ev.time << "; offset="
|
||||
<< _global_port_buffer_offset << " limit="
|
||||
<< (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/* suck all relevant MIDI events from the JACK MIDI port buffer
|
||||
into our MidiBuffer
|
||||
*/
|
||||
|
||||
for (pframes_t i = 0; i < event_count; ++i) {
|
||||
|
||||
jack_midi_event_t ev;
|
||||
|
||||
jack_midi_event_get (&ev, jack_buffer, i);
|
||||
|
||||
if (ev.buffer[0] == 0xfe) {
|
||||
/* throw away active sensing */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check that the event is in the acceptable time range */
|
||||
|
||||
if ((ev.time >= (_global_port_buffer_offset + _port_buffer_offset)) &&
|
||||
(ev.time < (_global_port_buffer_offset + _port_buffer_offset + nframes))) {
|
||||
_buffer->push_back (ev);
|
||||
} else {
|
||||
cerr << "Dropping incoming MIDI at time " << ev.time << "; offset="
|
||||
<< _global_port_buffer_offset << " limit="
|
||||
<< (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n";
|
||||
}
|
||||
} else {
|
||||
_buffer->silence (nframes);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -205,3 +212,9 @@ MidiPort::reset ()
|
||||
delete _buffer;
|
||||
_buffer = new MidiBuffer (AudioEngine::instance()->raw_buffer_size (DataType::MIDI));
|
||||
}
|
||||
|
||||
void
|
||||
MidiPort::set_input_active (bool yn)
|
||||
{
|
||||
_input_active = yn;
|
||||
}
|
||||
|
||||
@@ -676,3 +676,46 @@ MidiTrack::send_silence () const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
MidiTrack::set_input_active (bool yn)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if (!_input) {
|
||||
return;
|
||||
}
|
||||
|
||||
PortSet& ports (_input->ports());
|
||||
|
||||
for (PortSet::iterator p = ports.begin(DataType::MIDI); p != ports.end(DataType::MIDI); ++p) {
|
||||
MidiPort* mp = dynamic_cast<MidiPort*> (&*p);
|
||||
if (yn != mp->input_active()) {
|
||||
mp->set_input_active (yn);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
InputActiveChanged (); /* EMIT SIGNAL */
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
MidiTrack::input_active () const
|
||||
{
|
||||
if (!_input) {
|
||||
cerr << " no input\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_input->ports().count().n_midi() == 0) {
|
||||
cerr << "no input MIDI ports, " << _input->ports().count() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
PortSet::iterator p = _input->ports().begin(DataType::MIDI);
|
||||
MidiPort* mp = dynamic_cast<MidiPort*> (&*p);
|
||||
cerr << "first port is active: " << mp->input_active() << endl;
|
||||
return mp->input_active ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user