2 Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3 Copyright (C) 2006 Paul Davis
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "pbd/gstdio_compat.h"
23 #include "pbd/pthread_utils.h"
25 #include "ardour/audio_buffer.h"
26 #include "ardour/buffer_set.h"
27 #include "ardour/luabindings.h"
28 #include "ardour/luaproc.h"
29 #include "ardour/luascripting.h"
30 #include "ardour/midi_buffer.h"
31 #include "ardour/plugin.h"
32 #include "ardour/session.h"
36 using namespace ARDOUR;
39 LuaProc::LuaProc (AudioEngine& engine,
41 const std::string &script)
42 : Plugin (engine, session)
43 , _mempool ("LuaProc", 1048576) // 1 MB is plenty. (64K would be enough)
44 , lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool))
48 , _lua_does_channelmapping (false)
51 , _has_midi_input (false)
52 , _has_midi_output (false)
56 /* when loading a session, or pasing a processor,
57 * the script is set during set_state();
59 if (!_script.empty () && load_script ()) {
60 throw failed_constructor ();
64 LuaProc::LuaProc (const LuaProc &other)
66 , _mempool ("LuaProc", 1048576) // 1 MB is plenty. (64K would be enough)
67 , lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool))
70 , _script (other.script ())
71 , _lua_does_channelmapping (false)
74 , _has_midi_input (false)
75 , _has_midi_output (false)
80 throw failed_constructor ();
83 for (uint32_t i = 0; i < parameter_count (); ++i) {
84 _control_data[i] = other._shadow_data[i];
85 _shadow_data[i] = other._shadow_data[i];
89 LuaProc::~LuaProc () {
90 #ifdef WITH_LUAPROC_STATS
91 if (_info && _stats_cnt > 0) {
92 printf ("LuaProc: '%s' run() avg: %.3f max: %.3f [ms]\n",
94 0.0001f * _stats_avg[0] / (float) _stats_cnt,
95 0.0001f * _stats_max[0]);
96 printf ("LuaProc: '%s' gc() avg: %.3f max: %.3f [ms]\n",
98 0.0001f * _stats_avg[1] / (float) _stats_cnt,
99 0.0001f * _stats_max[1]);
102 lua.do_command ("collectgarbage();");
104 delete (_lua_params);
105 delete [] _control_data;
106 delete [] _shadow_data;
112 #ifdef WITH_LUAPROC_STATS
113 _stats_avg[0] = _stats_avg[1] = _stats_max[0] = _stats_max[1] = _stats_cnt = 0;
117 lua.Print.connect (sigc::mem_fun (*this, &LuaProc::lua_print));
119 // register session object
120 lua_State* L = lua.getState ();
121 LuaBindings::stddef (L);
122 LuaBindings::common (L);
123 LuaBindings::dsp (L);
125 luabridge::getGlobalNamespace (L)
126 .beginNamespace ("Ardour")
127 .beginClass <LuaProc> ("LuaProc")
128 .addFunction ("queue_draw", &LuaProc::queue_draw)
129 .addFunction ("shmem", &LuaProc::instance_shm)
133 // add session to global lua namespace
134 luabridge::push <Session *> (L, &_session);
135 lua_setglobal (L, "Session");
138 luabridge::push <LuaProc *> (L, this);
139 lua_setglobal (L, "self");
142 lua.do_command ("io = nil os = nil loadfile = nil require = nil dofile = nil package = nil debug = nil");
144 lua.do_command ("for n in pairs(_G) do print(n) end print ('----')"); // print global env
146 lua.do_command ("function ardour () end");
150 LuaProc::lua_print (std::string s) {
151 std::cout <<"LuaProc: " << s << "\n";
155 LuaProc::load_script ()
157 assert (!_lua_dsp); // don't allow to re-initialize
159 // TODO: refine APIs; function arguments..
160 // - perform channel-map in ardour (silent/scratch buffers) ?
161 // - control-port API (explicit get/set functions ??)
162 // - latency reporting (global var? ctrl-port? set-function ?)
163 // - MIDI -> sparse table of events
164 // { [sample] => { Event }, .. }
165 // or { { sample, Event }, .. }
168 LuaScriptInfoPtr lsi = LuaScripting::script_info (_script);
169 LuaPluginInfoPtr lpi (new LuaPluginInfo (lsi));
172 _mempool.set_name ("LuaProc: " + lsi->name);
173 _docs = lsi->description;
174 } catch (failed_constructor& err) {
178 lua_State* L = lua.getState ();
179 lua.do_command (_script);
181 // check if script has a DSP callback
182 luabridge::LuaRef lua_dsp_run = luabridge::getGlobal (L, "dsp_run");
183 luabridge::LuaRef lua_dsp_map = luabridge::getGlobal (L, "dsp_runmap");
185 if ((lua_dsp_run.type () != LUA_TFUNCTION) == (lua_dsp_map.type () != LUA_TFUNCTION)) {
189 if (lua_dsp_run.type () == LUA_TFUNCTION) {
190 _lua_dsp = new luabridge::LuaRef (lua_dsp_run);
192 else if (lua_dsp_map.type () == LUA_TFUNCTION) {
193 _lua_dsp = new luabridge::LuaRef (lua_dsp_map);
194 _lua_does_channelmapping = true;
200 // initialize the DSP if needed
201 luabridge::LuaRef lua_dsp_init = luabridge::getGlobal (L, "dsp_init");
202 if (lua_dsp_init.type () == LUA_TFUNCTION) {
204 lua_dsp_init (_session.nominal_frame_rate ());
205 } catch (luabridge::LuaException const& e) {
210 luabridge::LuaRef lua_dsp_midi_in = luabridge::getGlobal (L, "dsp_midi_input");
211 if (lua_dsp_midi_in.type () == LUA_TFUNCTION) {
213 _has_midi_input = lua_dsp_midi_in ();
214 } catch (luabridge::LuaException const& e) {
219 _ctrl_params.clear ();
221 luabridge::LuaRef lua_render = luabridge::getGlobal (L, "render_inline");
222 if (lua_render.isFunction ()) {
223 _lua_has_inline_display = true;
226 luabridge::LuaRef lua_params = luabridge::getGlobal (L, "dsp_params");
227 if (lua_params.isFunction ()) {
229 // call function // add try {} catch (luabridge::LuaException const& e)
230 luabridge::LuaRef params = lua_params ();
232 if (params.isTable ()) {
234 _lua_params = new luabridge::LuaRef (params);
236 for (luabridge::Iterator i (params); !i.isNil (); ++i) {
238 if (!i.key ().isNumber ()) { return false; }
239 if (!i.value ().isTable ()) { return false; }
240 if (!i.value ()["type"].isString ()) { return false; }
241 if (!i.value ()["name"].isString ()) { return false; }
242 if (!i.value ()["min"].isNumber ()) { return false; }
243 if (!i.value ()["max"].isNumber ()) { return false; }
245 std::string type = i.value ()["type"].cast<std::string> ();
246 if (type == "input") {
247 if (!i.value ()["default"].isNumber ()) { return false; }
248 _ctrl_params.push_back (std::make_pair (false, i.key ().cast<int> ()));
250 else if (type == "output") {
251 _ctrl_params.push_back (std::make_pair (true, i.key ().cast<int> ()));
255 assert (i.key ().cast<int> () == (int) _ctrl_params.size ());
260 _control_data = new float[parameter_count ()];
261 _shadow_data = new float[parameter_count ()];
263 for (uint32_t i = 0; i < parameter_count (); ++i) {
264 if (parameter_is_input (i)) {
265 _control_data[i] = _shadow_data[i] = default_value (i);
269 // expose ctrl-ports to global lua namespace
270 luabridge::push <float *> (L, _control_data);
271 lua_setglobal (L, "CtrlPorts");
273 return false; // no error
277 LuaProc::can_support_io_configuration (const ChanCount& in, ChanCount& out)
279 if (in.n_midi() > 0 && !_has_midi_input) {
283 lua_State* L = lua.getState ();
284 luabridge::LuaRef ioconfig = luabridge::getGlobal (L, "dsp_ioconfig");
285 if (!ioconfig.isFunction ()) {
289 luabridge::LuaRef table = luabridge::getGlobal (L, "table"); //lua std lib
290 luabridge::LuaRef tablesort = table["sort"];
291 assert (tablesort.isFunction ());
293 luabridge::LuaRef *_iotable = NULL; // can't use reference :(
295 luabridge::LuaRef iotable = ioconfig ();
297 if (iotable.isTable ()) {
298 _iotable = new luabridge::LuaRef (iotable);
300 } catch (luabridge::LuaException const& e) {
308 // now we can reference it.
309 luabridge::LuaRef iotable (*_iotable);
312 if ((iotable).length () < 1) {
316 int32_t audio_in = in.n_audio ();
319 if (in.n_midi() > 0 && audio_in == 0) {
320 audio_out = 2; // prefer stereo version if available.
322 audio_out = audio_in;
325 for (luabridge::Iterator i (iotable); !i.isNil (); ++i) {
326 assert (i.value ().type () == LUA_TTABLE);
327 luabridge::LuaRef io (i.value ());
329 int possible_in = io["audio_in"];
330 int possible_out = io["audio_out"];
333 if ((possible_in == audio_in) && (possible_out == audio_out)) {
334 out.set (DataType::MIDI, 0);
335 out.set (DataType::AUDIO, audio_out);
340 /* now allow potentially "imprecise" matches */
344 for (luabridge::Iterator i (iotable); !i.isNil (); ++i) {
345 assert (i.value ().type () == LUA_TTABLE);
346 luabridge::LuaRef io (i.value ());
348 int possible_in = io["audio_in"];
349 int possible_out = io["audio_out"];
351 if (possible_out == 0) {
354 if (possible_in == 0) {
355 /* no inputs, generators & instruments */
356 if (possible_out == -1) {
357 /* any configuration possible, provide stereo output */
360 } else if (possible_out == -2) {
361 /* invalid, should be (0, -1) */
364 } else if (possible_out < -2) {
365 /* variable number of outputs. -> whatever */
369 /* exact number of outputs */
370 audio_out = possible_out;
375 if (possible_in == -1) {
376 /* wildcard for input */
377 if (possible_out == -1) {
378 /* out much match in */
379 audio_out = audio_in;
381 } else if (possible_out == -2) {
382 /* any configuration possible, pick matching */
383 audio_out = audio_in;
385 } else if (possible_out < -2) {
386 /* explicitly variable number of outputs, pick maximum */
387 audio_out = -possible_out;
390 /* exact number of outputs */
391 audio_out = possible_out;
396 if (possible_in == -2) {
398 if (possible_out == -1) {
399 /* any configuration possible, pick matching */
400 audio_out = audio_in;
402 } else if (possible_out == -2) {
403 /* invalid. interpret as (-1, -1) */
404 audio_out = audio_in;
406 } else if (possible_out < -2) {
407 /* explicitly variable number of outputs, pick maximum */
408 audio_out = -possible_out;
411 /* exact number of outputs */
412 audio_out = possible_out;
417 if (possible_in < -2) {
418 /* explicit variable number of inputs */
419 if (audio_in > -possible_in) {
420 /* request is too large */
422 if (possible_out == -1) {
423 /* any output configuration possible, provide stereo out */
426 } else if (possible_out == -2) {
427 /* invalid. interpret as (<-2, -1) */
430 } else if (possible_out < -2) {
431 /* explicitly variable number of outputs, pick stereo */
435 /* exact number of outputs */
436 audio_out = possible_out;
441 if (possible_in && (possible_in == audio_in)) {
442 /* exact number of inputs ... must match obviously */
443 if (possible_out == -1) {
444 /* any output configuration possible, provide stereo output */
447 } else if (possible_out == -2) {
448 /* invalid. interpret as (>0, -1) */
451 } else if (possible_out < -2) {
452 /* explicitly variable number of outputs, pick maximum */
453 audio_out = -possible_out;
456 /* exact number of outputs */
457 audio_out = possible_out;
471 out.set (DataType::MIDI, 0);
472 out.set (DataType::AUDIO, audio_out);
477 LuaProc::configure_io (ChanCount in, ChanCount out)
480 _configured_out = out;
482 _configured_in.set (DataType::MIDI, _has_midi_input ? 1 : 0);
483 _configured_out.set (DataType::MIDI, _has_midi_output ? 1 : 0);
485 // configure the DSP if needed
486 lua_State* L = lua.getState ();
487 luabridge::LuaRef lua_dsp_configure = luabridge::getGlobal (L, "dsp_configure");
488 if (lua_dsp_configure.type () == LUA_TFUNCTION) {
490 lua_dsp_configure (&in, &out);
491 } catch (luabridge::LuaException const& e) {
496 _info->n_inputs = _configured_in;
497 _info->n_outputs = _configured_out;
502 LuaProc::connect_and_run (BufferSet& bufs,
503 ChanMapping in, ChanMapping out,
504 pframes_t nframes, framecnt_t offset)
510 Plugin::connect_and_run (bufs, in, out, nframes, offset);
512 // This is needed for ARDOUR::Session requests :(
513 if (! SessionEvent::has_per_thread_pool ()) {
515 snprintf (name, 64, "Proc-%p", this);
516 pthread_set_name (name);
517 SessionEvent::create_per_thread_pool (name, 64);
518 PBD::notify_event_loops_about_thread_creation (pthread_self(), name, 64);
521 uint32_t const n = parameter_count ();
522 for (uint32_t i = 0; i < n; ++i) {
523 if (parameter_is_control (i) && parameter_is_input (i)) {
524 _control_data[i] = _shadow_data[i];
528 #ifdef WITH_LUAPROC_STATS
529 int64_t t0 = g_get_monotonic_time ();
533 if (_lua_does_channelmapping) {
534 // run the DSP function
535 (*_lua_dsp)(&bufs, in, out, nframes, offset);
538 BufferSet& silent_bufs = _session.get_silent_buffers (ChanCount (DataType::AUDIO, 1));
539 BufferSet& scratch_bufs = _session.get_scratch_buffers (ChanCount (DataType::AUDIO, 1));
541 lua_State* L = lua.getState ();
542 luabridge::LuaRef in_map (luabridge::newTable (L));
543 luabridge::LuaRef out_map (luabridge::newTable (L));
545 const uint32_t audio_in = _configured_in.n_audio ();
546 const uint32_t audio_out = _configured_out.n_audio ();
547 const uint32_t midi_in = _configured_in.n_midi ();
549 for (uint32_t ap = 0; ap < audio_in; ++ap) {
551 const uint32_t buf_index = in.get(DataType::AUDIO, ap, &valid);
553 in_map[ap + 1] = bufs.get_audio (buf_index).data (offset);
555 in_map[ap + 1] = silent_bufs.get_audio (0).data (offset);
558 for (uint32_t ap = 0; ap < audio_out; ++ap) {
560 const uint32_t buf_index = out.get(DataType::AUDIO, ap, &valid);
562 out_map[ap + 1] = bufs.get_audio (buf_index).data (offset);
564 out_map[ap + 1] = scratch_bufs.get_audio (0).data (offset);
568 luabridge::LuaRef lua_midi_tbl (luabridge::newTable (L));
569 int e = 1; // > 1 port, we merge events (unsorted)
570 for (uint32_t mp = 0; mp < midi_in; ++mp) {
572 const uint32_t idx = in.get(DataType::MIDI, mp, &valid);
574 for (MidiBuffer::iterator m = bufs.get_midi(idx).begin();
575 m != bufs.get_midi(idx).end(); ++m, ++e) {
576 const Evoral::MIDIEvent<framepos_t> ev(*m, false);
577 luabridge::LuaRef lua_midi_data (luabridge::newTable (L));
578 const uint8_t* data = ev.buffer();
579 for (uint32_t i = 0; i < ev.size(); ++i) {
580 lua_midi_data [i + 1] = data[i];
582 luabridge::LuaRef lua_midi_event (luabridge::newTable (L));
583 lua_midi_event["time"] = 1 + (*m).time();
584 lua_midi_event["data"] = lua_midi_data;
585 lua_midi_tbl[e] = lua_midi_event;
590 if (_has_midi_input) {
591 // XXX TODO This needs a better solution than global namespace
592 luabridge::push (L, lua_midi_tbl);
593 lua_setglobal (L, "mididata");
597 // run the DSP function
598 (*_lua_dsp)(in_map, out_map, nframes);
600 } catch (luabridge::LuaException const& e) {
602 printf ("LuaException: %s\n", e.what ());
606 #ifdef WITH_LUAPROC_STATS
607 int64_t t1 = g_get_monotonic_time ();
609 lua.collect_garbage (); // rt-safe, slight *regular* performance overhead
610 #ifdef WITH_LUAPROC_STATS
612 int64_t t2 = g_get_monotonic_time ();
613 int64_t ela0 = t1 - t0;
614 int64_t ela1 = t2 - t1;
615 if (ela0 > _stats_max[0]) _stats_max[0] = ela0;
616 if (ela1 > _stats_max[1]) _stats_max[1] = ela1;
617 _stats_avg[0] += ela0;
618 _stats_avg[1] += ela1;
625 LuaProc::add_state (XMLNode* root) const
627 gchar* b64 = g_base64_encode ((const guchar*)_script.c_str (), _script.size ());
628 std::string b64s (b64);
630 XMLNode* script_node = new XMLNode (X_("script"));
631 script_node->add_property (X_("lua"), LUA_VERSION);
632 script_node->add_content (b64s);
633 root->add_child_nocopy (*script_node);
637 LuaProc::set_script_from_state (const XMLNode& node)
640 if (node.name () != state_node_name ()) {
644 if ((child = node.child (X_("script"))) != 0) {
645 for (XMLNodeList::const_iterator n = child->children ().begin (); n != child->children ().end (); ++n) {
646 if (!(*n)->is_content ()) { continue; }
648 guchar* buf = g_base64_decode ((*n)->content ().c_str (), &size);
649 _script = std::string ((const char*)buf, size);
651 if (load_script ()) {
652 PBD::error << _("Failed to load Lua script from session state.") << endmsg;
654 std::cerr << "Failed Lua Script: " << _script << std::endl;
661 if (_script.empty ()) {
662 PBD::error << _("Session State for LuaProcessor did not include a Lua script.") << endmsg;
666 PBD::error << _("Invalid/incompatible Lua script found for LuaProcessor.") << endmsg;
673 LuaProc::set_state (const XMLNode& node, int version)
675 if (_script.empty ()) {
676 if (set_script_from_state (node)) {
680 return Plugin::set_state (node, version);
684 LuaProc::parameter_count () const
686 return _ctrl_params.size ();
690 LuaProc::default_value (uint32_t port)
692 if (_ctrl_params[port].first) {
696 int lp = _ctrl_params[port].second;
697 luabridge::LuaRef lr = (*_lua_params)[lp];
698 return (lr["default"]).cast<float> ();
702 LuaProc::set_parameter (uint32_t port, float val)
704 assert (port < parameter_count ());
705 if (get_parameter (port) == val) {
708 _shadow_data[port] = val;
709 Plugin::set_parameter (port, val);
713 LuaProc::get_parameter (uint32_t port) const
715 if (parameter_is_input (port)) {
716 return _shadow_data[port];
718 return _control_data[port];
723 LuaProc::get_parameter_descriptor (uint32_t port, ParameterDescriptor& desc) const
725 assert (port <= parameter_count ());
726 int lp = _ctrl_params[port].second;
728 luabridge::LuaRef lr = (*_lua_params)[lp];
729 desc.lower = (lr["min"]).cast<float> ();
730 desc.upper = (lr["max"]).cast<float> ();
732 if (_ctrl_params[port].first) {
733 desc.normal = desc.lower; // output-port, no default
735 desc.normal = (lr["default"]).cast<float> ();
738 desc.toggled = lr["toggled"].isBoolean () && (lr["toggled"]).cast<bool> ();
739 desc.logarithmic = lr["logarithmic"].isBoolean () && (lr["logarithmic"]).cast<bool> ();
740 desc.integer_step = lr["integer"].isBoolean () && (lr["integer"]).cast<bool> ();
741 desc.sr_dependent = lr["ratemult"].isBoolean () && (lr["ratemult"]).cast<bool> ();
742 desc.enumeration = lr["enum"].isBoolean () && (lr["enum"]).cast<bool> ();
744 // TODO check if assignments make sense, e.g
745 assert (!(desc.toggled && desc.logarithmic));
747 if (lr["unit"].isString ()) {
748 std::string unit = lr["unit"].cast<std::string> ();
749 if (unit == "dB") { desc.unit = ParameterDescriptor::DB; }
750 else if (unit == "Hz") { desc.unit = ParameterDescriptor::HZ; }
751 else if (unit == "Midi Note") { desc.unit = ParameterDescriptor::MIDI_NOTE; }
754 desc.label = (lr["name"]).cast<std::string> ();
755 desc.scale_points = get_scale_points (port);
756 desc.update_steps ();
761 LuaProc::get_parameter_docs (uint32_t port) const {
762 assert (port <= parameter_count ());
763 int lp = _ctrl_params[port].second;
764 luabridge::LuaRef lr = (*_lua_params)[lp];
765 luabridge::LuaRef doc = lr["doc"];
766 if (doc.isString ()) {
767 return doc.cast<std::string> ();
773 LuaProc::nth_parameter (uint32_t port, bool& ok) const
775 if (port < _ctrl_params.size ()) {
784 LuaProc::parameter_is_input (uint32_t port) const
786 assert (port < _ctrl_params.size ());
787 return (!_ctrl_params[port].first);
791 LuaProc::parameter_is_output (uint32_t port) const
793 assert (port < _ctrl_params.size ());
794 return (_ctrl_params[port].first);
797 std::set<Evoral::Parameter>
798 LuaProc::automatable () const
800 std::set<Evoral::Parameter> automatables;
801 for (uint32_t i = 0; i < _ctrl_params.size (); ++i) {
802 if (parameter_is_input (i)) {
803 automatables.insert (automatables.end (), Evoral::Parameter (PluginAutomation, 0, i));
810 LuaProc::describe_parameter (Evoral::Parameter param)
812 if (param.type () == PluginAutomation && param.id () < parameter_count ()) {
813 int lp = _ctrl_params[param.id ()].second;
814 luabridge::LuaRef lr = (*_lua_params)[lp];
815 return (lr["name"]).cast<std::string> ();
822 LuaProc::print_parameter (uint32_t param, char* buf, uint32_t len) const
825 if (param < parameter_count ()) {
826 snprintf (buf, len, "%.3f", get_parameter (param));
833 boost::shared_ptr<ScalePoints>
834 LuaProc::get_scale_points (uint32_t port) const
836 int lp = _ctrl_params[port].second;
837 luabridge::LuaRef lr = (*_lua_params)[lp];
839 if (!lr["scalepoints"].isTable()) {
840 return boost::shared_ptr<ScalePoints> ();
844 boost::shared_ptr<ScalePoints> rv = boost::shared_ptr<ScalePoints>(new ScalePoints());
845 luabridge::LuaRef scalepoints (lr["scalepoints"]);
847 for (luabridge::Iterator i (scalepoints); !i.isNil (); ++i) {
848 if (!i.key ().isString ()) { continue; }
849 if (!i.value ().isNumber ()) { continue; }
850 rv->insert(make_pair(i.key ().cast<std::string> (),
851 i.value ().cast<float> ()));
855 if (rv->size() > 0) {
858 return boost::shared_ptr<ScalePoints> ();
863 LuaProc::setup_lua_inline_gui (LuaState *lua_gui)
865 lua_State* LG = lua_gui->getState ();
866 LuaBindings::stddef (LG);
867 LuaBindings::common (LG);
868 LuaBindings::dsp (LG);
871 lua_gui->Print.connect (sigc::mem_fun (*this, &LuaProc::lua_print));
874 lua_gui->do_command ("function ardour () end");
875 lua_gui->do_command (_script);
877 // TODO think: use a weak-pointer here ?
878 // (the GUI itself uses a shared ptr to this plugin, so we should be good)
879 luabridge::getGlobalNamespace (LG)
880 .beginNamespace ("Ardour")
881 .beginClass <LuaProc> ("LuaProc")
882 .addFunction ("shmem", &LuaProc::instance_shm)
886 luabridge::push <LuaProc *> (LG, this);
887 lua_setglobal (LG, "self");
889 luabridge::push <float *> (LG, _shadow_data);
890 lua_setglobal (LG, "CtrlPorts");
893 ////////////////////////////////////////////////////////////////////////////////
894 #include <glibmm/miscutils.h>
895 #include <glibmm/fileutils.h>
897 LuaPluginInfo::LuaPluginInfo (LuaScriptInfoPtr lsi) {
898 if (lsi->type != LuaScriptInfo::DSP) {
899 throw failed_constructor ();
904 creator = lsi->author;
905 category = lsi->category;
906 unique_id = "luascript"; // the interpreter is not unique.
908 n_inputs.set (DataType::AUDIO, 1);
909 n_outputs.set (DataType::AUDIO, 1);
914 LuaPluginInfo::load (Session& session)
916 std::string script = "";
917 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
922 script = Glib::file_get_contents (path);
923 } catch (Glib::FileError err) {
927 if (script.empty ()) {
932 PluginPtr plugin (new LuaProc (session.engine (), session, script));
934 } catch (failed_constructor& err) {
940 std::vector<Plugin::PresetRecord>
941 LuaPluginInfo::get_presets (bool /*user_only*/) const
943 std::vector<Plugin::PresetRecord> p;