copy plugin state to all instances when instantiating.
[ardour.git] / libs / ardour / midi_region.cc
index c02caff470ef2a2bc38e222896f0e05885a2ca06..6a9e1cd762ec7e8961c23af46ab83e1e06bf92ac 100644 (file)
@@ -28,7 +28,7 @@
 #include <glibmm/fileutils.h>
 #include <glibmm/miscutils.h>
 
-#include "evoral/types.hpp"
+#include "evoral/Beats.hpp"
 
 #include "pbd/xml++.h"
 #include "pbd/basename.h"
@@ -53,7 +53,6 @@ using namespace PBD;
 
 namespace ARDOUR {
        namespace Properties {
-               PBD::PropertyDescriptor<void*>         midi_data;
                PBD::PropertyDescriptor<Evoral::Beats> start_beats;
                PBD::PropertyDescriptor<Evoral::Beats> length_beats;
        }
@@ -62,8 +61,6 @@ namespace ARDOUR {
 void
 MidiRegion::make_property_quarks ()
 {
-       Properties::midi_data.property_id = g_quark_from_static_string (X_("midi-data"));
-       DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for midi-data = %1\n", Properties::midi_data.property_id));
        Properties::start_beats.property_id = g_quark_from_static_string (X_("start-beats"));
        DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for start-beats = %1\n", Properties::start_beats.property_id));
        Properties::length_beats.property_id = g_quark_from_static_string (X_("length-beats"));
@@ -233,9 +230,15 @@ MidiRegion::set_position_internal (framepos_t pos, bool allow_bbt_recompute)
 }
 
 framecnt_t
-MidiRegion::read_at (Evoral::EventSink<framepos_t>& out, framepos_t position, framecnt_t dur, uint32_t chan_n, NoteMode mode, MidiStateTracker* tracker) const
+MidiRegion::read_at (Evoral::EventSink<framepos_t>& out,
+                     framepos_t                     position,
+                     framecnt_t                     dur,
+                     uint32_t                       chan_n,
+                     NoteMode                       mode,
+                     MidiStateTracker*              tracker,
+                     MidiChannelFilter*             filter) const
 {
-       return _read_at (_sources, out, position, dur, chan_n, mode, tracker);
+       return _read_at (_sources, out, position, dur, chan_n, mode, tracker, filter);
 }
 
 framecnt_t
@@ -245,11 +248,17 @@ MidiRegion::master_read_at (MidiRingBuffer<framepos_t>& out, framepos_t position
 }
 
 framecnt_t
-MidiRegion::_read_at (const SourceList& /*srcs*/, Evoral::EventSink<framepos_t>& dst, framepos_t position, framecnt_t dur, uint32_t chan_n,
-                     NoteMode mode, MidiStateTracker* tracker) const
+MidiRegion::_read_at (const SourceList&              /*srcs*/,
+                      Evoral::EventSink<framepos_t>& dst,
+                      framepos_t                     position,
+                      framecnt_t                     dur,
+                      uint32_t                       chan_n,
+                      NoteMode                       mode,
+                      MidiStateTracker*              tracker,
+                      MidiChannelFilter*             filter) const
 {
        frameoffset_t internal_offset = 0;
-       framecnt_t to_read         = 0;
+       framecnt_t    to_read         = 0;
 
        /* precondition: caller has verified that we cover the desired section */
 
@@ -299,6 +308,7 @@ MidiRegion::_read_at (const SourceList& /*srcs*/, Evoral::EventSink<framepos_t>&
                        _start + internal_offset, // where to start reading in the source
                        to_read, // read duration in frames
                        tracker,
+                       filter,
                        _filtered_parameters
                    ) != to_read) {
                return 0; /* "read nothing" */
@@ -408,24 +418,6 @@ MidiRegion::model_changed ()
        midi_source()->AutomationStateChanged.connect_same_thread (
                _model_connection, boost::bind (&MidiRegion::model_automation_state_changed, this, _1)
                );
-
-       model()->ContentsChanged.connect_same_thread (
-               _model_contents_connection, boost::bind (&MidiRegion::model_contents_changed, this));
-}
-
-void
-MidiRegion::model_contents_changed ()
-{
-       {
-               /* Invalidate source iterator to force reading new contents even if the
-                  calls to read() progress linearly.  Try-lock only to avoid deadlock
-                  when called while writing with the source already locked. */
-               Glib::Threads::Mutex::Lock lm (midi_source(0)->mutex(), Glib::Threads::TRY_LOCK);
-               if (lm.locked()) {
-                       midi_source(0)->invalidate (lm);
-               }
-       }
-       send_change (PropertyChange (Properties::midi_data));
 }
 
 void
@@ -448,6 +440,7 @@ MidiRegion::model_automation_state_changed (Evoral::Parameter const & p)
        */
        Glib::Threads::Mutex::Lock lm (midi_source(0)->mutex(), Glib::Threads::TRY_LOCK);
        if (lm.locked()) {
+               /* TODO: This is too aggressive, we need more fine-grained invalidation. */
                midi_source(0)->invalidate (lm);
        }
 }
@@ -465,14 +458,6 @@ MidiRegion::fix_negative_start ()
        _start_beats = Evoral::Beats();
 }
 
-/** Transpose the notes in this region by a given number of semitones */
-void
-MidiRegion::transpose (int semitones)
-{
-       BeatsFramesConverter c (_session.tempo_map(), _start);
-       model()->transpose (c.from (_start), c.from (_start + _length), semitones);
-}
-
 void
 MidiRegion::set_start_internal (framecnt_t s)
 {