1 /* 2 * Copyright (C) 2006-2014 David Robillard <d@drobilla.net> 3 * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com> 4 * Copyright (C) 2007 Sampo Savolainen <v2@iki.fi> 5 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net> 6 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License along 19 * with this program; if not, write to the Free Software Foundation, Inc., 20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 */ 22 23 #ifndef __ardour_ladspa_plugin_h__ 24 #define __ardour_ladspa_plugin_h__ 25 26 #include <set> 27 #include <vector> 28 #include <string> 29 30 #include <glibmm/module.h> 31 32 #include "pbd/stateful.h" 33 34 #include "ardour/ladspa.h" 35 #include "ardour/plugin.h" 36 37 namespace ARDOUR { 38 class AudioEngine; 39 class Session; 40 41 class LIBARDOUR_API LadspaPlugin : public ARDOUR::Plugin 42 { 43 public: 44 LadspaPlugin (std::string module_path, ARDOUR::AudioEngine&, ARDOUR::Session&, uint32_t index, samplecnt_t sample_rate); 45 LadspaPlugin (const LadspaPlugin &); 46 ~LadspaPlugin (); 47 48 /* Plugin interface */ 49 50 std::string unique_id() const; label()51 const char* label() const { return _descriptor->Label; } name()52 const char* name() const { return _descriptor->Name; } maker()53 const char* maker() const { return _descriptor->Maker; } parameter_count()54 uint32_t parameter_count() const { return _descriptor->PortCount; } default_value(uint32_t port)55 float default_value (uint32_t port) { return _default_value (port); } 56 void set_parameter (uint32_t port, float val, sampleoffset_t); 57 float get_parameter (uint32_t port) const; 58 int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const; 59 uint32_t nth_parameter (uint32_t port, bool& ok) const; 60 61 std::set<Evoral::Parameter> automatable() const; 62 activate()63 void activate () { 64 if (!_was_activated && _descriptor->activate) 65 _descriptor->activate (_handle); 66 67 _was_activated = true; 68 } 69 deactivate()70 void deactivate () { 71 if (_was_activated && _descriptor->deactivate) 72 _descriptor->deactivate (_handle); 73 74 _was_activated = false; 75 } 76 cleanup()77 void cleanup () { 78 activate(); 79 deactivate(); 80 81 if (_descriptor->cleanup) 82 _descriptor->cleanup (_handle); 83 } 84 set_block_size(pframes_t)85 int set_block_size (pframes_t /*nframes*/) { return 0; } 86 87 int connect_and_run (BufferSet& bufs, 88 samplepos_t start, samplepos_t end, double speed, 89 ChanMapping const& in, ChanMapping const& out, 90 pframes_t nframes, samplecnt_t offset); 91 92 std::string describe_parameter (Evoral::Parameter); state_node_name()93 std::string state_node_name() const { return "ladspa"; } 94 95 bool parameter_is_audio(uint32_t) const; 96 bool parameter_is_control(uint32_t) const; 97 bool parameter_is_input(uint32_t) const; 98 bool parameter_is_output(uint32_t) const; 99 bool parameter_is_toggled(uint32_t) const; 100 101 boost::shared_ptr<ScalePoints> 102 get_scale_points(uint32_t port_index) const; 103 104 int set_state (const XMLNode&, int version); 105 106 bool load_preset (PresetRecord); 107 has_editor()108 bool has_editor() const { return false; } 109 110 /* LADSPA extras */ 111 properties()112 LADSPA_Properties properties() const { return _descriptor->Properties; } index()113 uint32_t index() const { return _index; } copyright()114 const char * copyright() const { return _descriptor->Copyright; } 115 LADSPA_PortDescriptor port_descriptor(uint32_t i) const; port_range_hints()116 const LADSPA_PortRangeHint* port_range_hints() const { return _descriptor->PortRangeHints; } port_names()117 const char * const * port_names() const { return _descriptor->PortNames; } 118 set_gain(float gain)119 void set_gain (float gain) { _descriptor->set_run_adding_gain (_handle, gain); } run_adding(uint32_t nsamples)120 void run_adding (uint32_t nsamples) { _descriptor->run_adding (_handle, nsamples); } connect_port(uint32_t port,float * ptr)121 void connect_port (uint32_t port, float *ptr) { _descriptor->connect_port (_handle, port, ptr); } 122 123 private: 124 float _default_value (uint32_t port) const; 125 std::string _module_path; 126 Glib::Module* _module; 127 const LADSPA_Descriptor* _descriptor; 128 LADSPA_Handle _handle; 129 samplecnt_t _sample_rate; 130 LADSPA_Data* _control_data; 131 LADSPA_Data* _shadow_data; 132 LADSPA_Data* _latency_control_port; 133 uint32_t _index; 134 bool _was_activated; 135 136 samplecnt_t plugin_latency() const; 137 void find_presets (); 138 139 void init (std::string module_path, uint32_t index, samplecnt_t rate); 140 void run_in_place (pframes_t nsamples); 141 void latency_compute_run (); 142 int set_state_2X (const XMLNode&, int version); 143 std::string do_save_preset (std::string name); 144 void do_remove_preset (std::string name); 145 std::string preset_envvar () const; 146 std::string preset_source (std::string) const; 147 bool write_preset_file (std::string); 148 void add_state (XMLNode *) const; 149 }; 150 151 class LIBARDOUR_API LadspaPluginInfo : public PluginInfo { 152 public: 153 LadspaPluginInfo (); ~LadspaPluginInfo()154 ~LadspaPluginInfo () { }; 155 is_instrument()156 bool is_instrument () const { return false; } /* ladspa's are never instruments */ 157 #ifdef MIXBUS 158 /* for mixbus, relegate ladspa's to the Utils folder. */ is_effect()159 bool is_effect () const { return false; } is_utility()160 bool is_utility () const { return true; } 161 #endif 162 163 PluginPtr load (Session& session); 164 std::vector<Plugin::PresetRecord> get_presets (bool user_only) const; 165 }; 166 167 typedef boost::shared_ptr<LadspaPluginInfo> LadspaPluginInfoPtr; 168 169 } // namespace ARDOUR 170 171 #endif /* __ardour_ladspa_plugin_h__ */ 172