Optimize plugin-processing for non-automated params
[ardour.git] / libs / ardour / ardour / plugin_insert.h
index 1076c5198f31b6869765fd82c121313bb924e6c3..64b2bd875d21353b069259071f4e3edc1575a13d 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <boost/weak_ptr.hpp>
 
+#include "pbd/timing.h"
+
 #include "ardour/ardour.h"
 #include "ardour/libardour_visibility.h"
 #include "ardour/chan_mapping.h"
@@ -50,14 +52,12 @@ class Plugin;
  */
 class LIBARDOUR_API PluginInsert : public Processor
 {
-  public:
+public:
        PluginInsert (Session&, boost::shared_ptr<Plugin> = boost::shared_ptr<Plugin>());
        ~PluginInsert ();
 
        static const std::string port_automation_node_name;
 
-       XMLNode& state(bool);
-       XMLNode& get_state(void);
        int set_state(const XMLNode&, int version);
        void update_id (PBD::ID);
        void set_owner (SessionObject*);
@@ -79,6 +79,9 @@ class LIBARDOUR_API PluginInsert : public Processor
 
        bool write_immediate_event (size_t size, const uint8_t* buf);
 
+       void automation_run (samplepos_t, pframes_t, bool only_active = false);
+       bool find_next_event (double, double, Evoral::ControlEvent&, bool only_active = true) const;
+
        int set_block_size (pframes_t nframes);
 
        ChanMapping input_map (uint32_t num) const {
@@ -112,6 +115,10 @@ class LIBARDOUR_API PluginInsert : public Processor
 
 #ifdef MIXBUS
        bool is_channelstrip () const;
+       bool is_nonbypassable () const;
+#else
+       bool is_channelstrip () const { return false; }
+       bool is_nonbypassable () const { return false; }
 #endif
 
        void set_input_map (uint32_t, ChanMapping);
@@ -163,7 +170,7 @@ class LIBARDOUR_API PluginInsert : public Processor
        bool set_preset_out (const ChanCount&);
        bool add_sidechain  (uint32_t n_audio = 1, uint32_t n_midi = 0);
        bool del_sidechain ();
-       void set_sidechain_latency (uint32_t, uint32_t);
+       void update_sidechain_name ();
        boost::shared_ptr<SideChain> sidechain () const { return _sidechain; }
        // end C++ class slavery!
 
@@ -176,7 +183,9 @@ class LIBARDOUR_API PluginInsert : public Processor
 
        bool has_no_inputs() const;
        bool has_no_audio_inputs() const;
+
        bool is_instrument () const;
+
        bool has_output_presets (
                        ChanCount in = ChanCount (DataType::MIDI, 1),
                        ChanCount out = ChanCount (DataType::AUDIO, 2)
@@ -188,6 +197,10 @@ class LIBARDOUR_API PluginInsert : public Processor
 
        bool load_preset (Plugin::PresetRecord);
 
+       bool provides_stats () const;
+       bool get_stats (uint64_t& min, uint64_t& max, double& avg, double& dev) const;
+       void clear_stats ();
+
        /** A control that manipulates a plugin parameter (control port). */
        struct PluginControl : public AutomationControl
        {
@@ -215,7 +228,7 @@ class LIBARDOUR_API PluginInsert : public Processor
 
                double get_value (void) const;
                XMLNode& get_state();
-        protected:
+       protected:
                void actually_set_value (double value, PBD::Controllable::GroupControlDisposition);
 
        private:
@@ -301,7 +314,10 @@ class LIBARDOUR_API PluginInsert : public Processor
                bool custom_cfg;       ///< custom config (if not strict)
        };
 
-  private:
+protected:
+       XMLNode& state ();
+
+private:
        /* disallow copy construction */
        PluginInsert (const PluginInsert&);
 
@@ -352,7 +368,24 @@ class LIBARDOUR_API PluginInsert : public Processor
        /** details of the match currently being used */
        Match _match;
 
-       typedef std::map <uint32_t, ARDOUR::ChanMapping> PinMappings;
+       /* ordered map [plugin instance ID] => ARDOUR::ChanMapping
+        * TODO: consider replacing with boost::flat_map<> or std::vector<>.
+        */
+       class PinMappings : public std::map <uint32_t, ARDOUR::ChanMapping> {
+               public:
+                       /* this emulates C++11's  std::map::at()
+                        * return mapping for given plugin instance */
+                       inline ARDOUR::ChanMapping const& p (const uint32_t i) const {
+#ifndef NDEBUG
+                               const_iterator x = find (i);
+                               assert (x != end ());
+                               return x->second;
+#else
+                               return find(i)->second;
+#endif
+                       }
+       };
+
        PinMappings _in_map;
        PinMappings _out_map;
        ChanMapping _thru_map; // out-idx <=  in-idx
@@ -373,6 +406,8 @@ class LIBARDOUR_API PluginInsert : public Processor
        boost::shared_ptr<Plugin> plugin_factory (boost::shared_ptr<Plugin>);
        void add_plugin (boost::shared_ptr<Plugin>);
 
+       void add_sidechain_from_xml (const XMLNode& node, int version);
+
        void start_touch (uint32_t param_id);
        void end_touch (uint32_t param_id);
 
@@ -384,6 +419,9 @@ class LIBARDOUR_API PluginInsert : public Processor
        CtrlOutMap _control_outputs;
 
        void preset_load_set_value (uint32_t, float);
+
+       PBD::TimingStats _timing_stats;
+       volatile gint _stat_reset;
 };
 
 } // namespace ARDOUR