summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-06-28 16:55:41 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-06-28 16:55:41 +0000
commit84be4eafc5228eacfed02f78489fa82d401c2947 (patch)
tree4dab87b4691919375ab3a867a011b5caf9ce2e59 /libs
parent4388556923da8b174fdbea445ea20a8eb72189c6 (diff)
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
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/midi_port.h8
-rw-r--r--libs/ardour/ardour/midi_track.h4
-rw-r--r--libs/ardour/midi_diskstream.cc4
-rw-r--r--libs/ardour/midi_port.cc71
-rw-r--r--libs/ardour/midi_track.cc43
5 files changed, 99 insertions, 31 deletions
diff --git a/libs/ardour/ardour/midi_port.h b/libs/ardour/ardour/midi_port.h
index 69e17ca08e..a4d2f53806 100644
--- a/libs/ardour/ardour/midi_port.h
+++ b/libs/ardour/ardour/midi_port.h
@@ -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);
};
diff --git a/libs/ardour/ardour/midi_track.h b/libs/ardour/ardour/midi_track.h
index 6bb959a9a5..5ceeefd307 100644
--- a/libs/ardour/ardour/midi_track.h
+++ b/libs/ardour/ardour/midi_track.h
@@ -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);
diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc
index 1c34ff9c03..e3eef62107 100644
--- a/libs/ardour/midi_diskstream.cc
+++ b/libs/ardour/midi_diskstream.cc
@@ -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) {
diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc
index a8bff5bfa7..c27332fce1 100644
--- a/libs/ardour/midi_port.cc
+++ b/libs/ardour/midi_port.cc
@@ -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);
-
- 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 (_input_active) {
+
+ 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";
+ }
+ }
- 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;
+}
diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc
index 52a0cac27e..2dcee645a9 100644
--- a/libs/ardour/midi_track.cc
+++ b/libs/ardour/midi_track.cc
@@ -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 ();
+}