2 * Copyright (C) 2016-2019 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
4 * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
5 * Copyright (C) 2017-2018 Ben Loftis <ben@harrisonconsoles.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <cairomm/context.h>
23 #include <cairomm/surface.h>
24 #include <pango/pangocairo.h>
26 #include "pbd/file_utils.h"
27 #include "pbd/strsplit.h"
29 #include "gtkmm2ext/bindings.h"
30 #include "gtkmm2ext/gui_thread.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/disk_reader.h"
34 #include "ardour/disk_writer.h"
35 #include "ardour/filesystem_paths.h"
36 #include "ardour/plugin_manager.h"
37 #include "ardour/route.h"
38 #include "ardour/session.h"
39 #include "ardour/system_exec.h"
41 #include "LuaBridge/LuaBridge.h"
43 #include "ardour_http.h"
44 #include "ardour_ui.h"
45 #include "public_editor.h"
46 #include "region_selection.h"
47 #include "luadialog.h"
48 #include "luainstance.h"
49 #include "luasignal.h"
52 #include "region_view.h"
53 #include "processor_box.h"
54 #include "time_axis_view.h"
55 #include "time_axis_view_item.h"
56 #include "selection.h"
57 #include "script_selector.h"
59 #include "utils_videotl.h"
63 static const char* ui_scripts_file_name = "ui_scripts";
66 /** wrap RefPtr< Cairo::ImageSurface >
68 * Image surfaces provide the ability to render to memory buffers either
69 * allocated by cairo or by the calling code. The supported image formats are
70 * those defined in Cairo::Format.
75 * Creates an image surface of the specified format and dimensions. Initially
76 * the surface contents are all 0. (Specifically, within each pixel, each
77 * color or alpha channel belonging to format will be 0. The contents of bits
78 * within a pixel, but not belonging to the given format are undefined).
80 * @param format format of pixels in the surface to create
81 * @param width width of the surface, in pixels
82 * @param height height of the surface, in pixels
84 ImageSurface (Cairo::Format format, int width, int height)
85 : _surface (Cairo::ImageSurface::create (format, width, height))
86 , _ctx (Cairo::Context::create (_surface))
87 , ctx (_ctx->cobj ()) {}
92 * Set this surface as source for another context.
93 * This allows to draw this surface
95 void set_as_source (Cairo::Context* c, int x, int y) {
97 c->set_source (_surface, x, y);
101 * Returns a context object to perform operations on the surface
103 Cairo::Context* context () {
104 return (Cairo::Context *)&ctx;
108 * Returns the stride of the image surface in bytes (or 0 if surface is not
109 * an image surface). The stride is the distance in bytes from the beginning
110 * of one row of the image data to the beginning of the next row.
112 int get_stride () const {
113 return _surface->get_stride ();
116 /** Gets the width of the ImageSurface in pixels */
117 int get_width () const {
118 return _surface->get_width ();
121 /** Gets the height of the ImageSurface in pixels */
122 int get_height () const {
123 return _surface->get_height ();
127 * Get a pointer to the data of the image surface, for direct
128 * inspection or modification.
130 * Return value: a pointer to the image data of this surface or NULL
131 * if @surface is not an image surface.
134 unsigned char* get_data () {
135 return _surface->get_data ();
138 /** Tells cairo to consider the data buffer dirty.
140 * In particular, if you've created an ImageSurface with a data buffer that
141 * you've allocated yourself and you draw to that data buffer using means
142 * other than cairo, you must call mark_dirty() before doing any additional
143 * drawing to that surface with cairo.
145 * Note that if you do draw to the Surface outside of cairo, you must call
146 * flush() before doing the drawing.
149 _surface->mark_dirty ();
152 /** Marks a rectangular area of the given surface dirty.
154 * @param x X coordinate of dirty rectangle
155 * @param y Y coordinate of dirty rectangle
156 * @param width width of dirty rectangle
157 * @param height height of dirty rectangle
159 void mark_dirty (int x, int y, int width, int height) {
160 _surface->mark_dirty (x, y, width, height);
164 Cairo::RefPtr<Cairo::ImageSurface> _surface;
165 Cairo::RefPtr<Cairo::Context> _ctx;
171 /** Create a new PangoLayout Text Display
172 * @param c CairoContext for the layout
173 * @param font_name a font-description e.g. "Mono 8px"
175 PangoLayout (Cairo::Context* c, std::string font_name) {
176 ::PangoLayout* pl = pango_cairo_create_layout (c->cobj ());
177 _layout = Glib::wrap (pl);
178 Pango::FontDescription fd (font_name);
179 _layout->set_font_description (fd);
184 /** Gets the text in the layout. The returned text should not
185 * be freed or modified.
187 * @return The text in the @a layout.
189 std::string get_text () const {
190 return _layout->get_text ();
192 /** Set the text of the layout.
193 * @param text The text for the layout.
195 void set_text (const std::string& text) {
196 _layout->set_text (text);
199 /** Sets the layout text and attribute list from marked-up text (see markup format).
200 * Replaces the current text and attribute list.
201 * @param markup Some marked-up text.
203 void set_markup (const std::string& markup) {
204 _layout->set_markup (markup);
207 /** Sets the width to which the lines of the Pango::Layout should wrap or
208 * ellipsized. The default value is -1: no width set.
210 * @param width The desired width in Pango units, or -1 to indicate that no
211 * wrapping or ellipsization should be performed.
213 void set_width (int width) {
214 _layout->set_width (width * PANGO_SCALE);
217 /** Gets the width to which the lines of the Pango::Layout should wrap.
219 * @return The width in Pango units, or -1 if no width set.
221 int get_width () const {
222 return _layout->get_width () / PANGO_SCALE;
225 /** Sets the type of ellipsization being performed for @a layout.
226 * Depending on the ellipsization mode @a ellipsize text is
227 * removed from the start, middle, or end of text so they
228 * fit within the width and height of layout set with
229 * set_width() and set_height().
231 * If the layout contains characters such as newlines that
232 * force it to be layed out in multiple paragraphs, then whether
233 * each paragraph is ellipsized separately or the entire layout
234 * is ellipsized as a whole depends on the set height of the layout.
235 * See set_height() for details.
237 * @param ellipsize The new ellipsization mode for @a layout.
239 void set_ellipsize (Pango::EllipsizeMode ellipsize) {
240 _layout->set_ellipsize (ellipsize);
243 /** Gets the type of ellipsization being performed for @a layout.
244 * See set_ellipsize()
246 * @return The current ellipsization mode for @a layout.
248 * Use is_ellipsized() to query whether any paragraphs
249 * were actually ellipsized.
251 Pango::EllipsizeMode get_ellipsize () const {
252 return _layout->get_ellipsize ();
255 /** Queries whether the layout had to ellipsize any paragraphs.
257 * This returns <tt>true</tt> if the ellipsization mode for @a layout
258 * is not Pango::ELLIPSIZE_NONE, a positive width is set on @a layout,
259 * and there are paragraphs exceeding that width that have to be
262 * @return <tt>true</tt> if any paragraphs had to be ellipsized, <tt>false</tt>
265 bool is_ellipsized () const {
266 return _layout->is_ellipsized ();
269 /** Sets the alignment for the layout: how partial lines are
270 * positioned within the horizontal space available.
271 * @param alignment The alignment.
273 void set_alignment(Pango::Alignment alignment) {
274 _layout->set_alignment (alignment);
277 /** Gets the alignment for the layout: how partial lines are
278 * positioned within the horizontal space available.
279 * @return The alignment.
281 Pango::Alignment get_alignment() const {
282 return _layout->get_alignment ();
285 /** Sets the wrap mode; the wrap mode only has effect if a width
286 * is set on the layout with set_width().
287 * To turn off wrapping, set the width to -1.
289 * @param wrap The wrap mode.
291 void set_wrap (Pango::WrapMode wrap) {
292 _layout->set_width (wrap);
295 /** Gets the wrap mode for the layout.
297 * Use is_wrapped() to query whether any paragraphs
298 * were actually wrapped.
300 * @return Active wrap mode.
302 Pango::WrapMode get_wrap () const {
303 return _layout->get_wrap ();
306 /** Queries whether the layout had to wrap any paragraphs.
308 * This returns <tt>true</tt> if a positive width is set on @a layout,
309 * ellipsization mode of @a layout is set to Pango::ELLIPSIZE_NONE,
310 * and there are paragraphs exceeding the layout width that have
313 * @return <tt>true</tt> if any paragraphs had to be wrapped, <tt>false</tt>
316 bool is_wrapped () const {
317 return _layout->is_wrapped ();
320 /** Determines the logical width and height of a Pango::Layout
323 int get_pixel_size (lua_State *L) {
325 _layout->get_pixel_size (width, height);
326 luabridge::Stack<int>::push (L, width);
327 luabridge::Stack<int>::push (L, height);
331 /** Draws a Layout in the specified Cairo @a context. The top-left
332 * corner of the Layout will be drawn at the current point of the
335 * @param context A Cairo context.
337 void show_in_cairo_context (Cairo::Context* c) {
338 pango_cairo_update_layout (c->cobj (), _layout->gobj());
339 pango_cairo_show_layout (c->cobj (), _layout->gobj());
342 void layout_cairo_path (Cairo::Context* c) {
343 pango_cairo_update_layout (c->cobj (), _layout->gobj());
344 pango_cairo_layout_path (c->cobj (), _layout->gobj());
348 Glib::RefPtr<Pango::Layout> _layout;
353 ////////////////////////////////////////////////////////////////////////////////
355 namespace LuaSignal {
357 #define STATIC(name,c,p) else if (!strcmp(type, #name)) {return name;}
358 #define SESSION(name,c,p) else if (!strcmp(type, #name)) {return name;}
359 #define ENGINE(name,c,p) else if (!strcmp(type, #name)) {return name;}
362 str2luasignal (const std::string &str) {
363 const char* type = str.c_str();
365 # include "luasignal_syms.h"
367 PBD::fatal << string_compose (_("programming error: %1: %2"), "Impossible LuaSignal type", str) << endmsg;
368 abort(); /*NOTREACHED*/
375 #define STATIC(name,c,p) N_(#name),
376 #define SESSION(name,c,p) N_(#name),
377 #define ENGINE(name,c,p) N_(#name),
378 const char *luasignalstr[] = {
379 # include "luasignal_syms.h"
389 static std::string http_get_unlogged (const std::string& url) { return ArdourCurl::http_get (url, false); }
391 /** special cases for Ardour's Mixer UI */
394 ProcessorBox::ProcSelection
395 processor_selection () {
396 return ProcessorBox::current_processor_selection ();
401 static void mixer_screenshot (const std::string& fn) {
402 Mixer_UI::instance()->screenshot (fn);
405 ////////////////////////////////////////////////////////////////////////////////
407 static PBD::ScopedConnectionList _luaexecs;
409 static void reaper (ARDOUR::SystemExec* x)
415 lua_forkexec (lua_State *L)
417 int argc = lua_gettop (L);
419 return luaL_argerror (L, 1, "invalid number of arguments, forkexec (command, ...)");
421 // args are free()ed in ~SystemExec
422 char** args = (char**) malloc ((argc + 1) * sizeof(char*));
423 for (int i = 0; i < argc; ++i) {
424 args[i] = strdup (luaL_checkstring (L, i + 1));
428 ARDOUR::SystemExec* x = new ARDOUR::SystemExec (args[0], args);
429 x->Terminated.connect (_luaexecs, MISSING_INVALIDATOR, boost::bind (&reaper, x), gui_context());
433 luabridge::Stack<bool>::push (L, false);
436 luabridge::Stack<bool>::push (L, false);
441 #ifndef PLATFORM_WINDOWS
443 lua_exec (std::string cmd)
445 // args are free()ed in ~SystemExec
446 char** args = (char**) malloc (4 * sizeof(char*));
447 args[0] = strdup ("/bin/sh");
448 args[1] = strdup ("-c");
449 args[2] = strdup (cmd.c_str());
451 ARDOUR::SystemExec x ("/bin/sh", args);
460 ////////////////////////////////////////////////////////////////////////////////
463 lua_actionlist (lua_State *L)
467 vector<string> paths;
468 vector<string> labels;
469 vector<string> tooltips;
471 vector<Glib::RefPtr<Gtk::Action> > actions;
472 ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
474 vector<string>::iterator p;
475 vector<string>::iterator l;
477 luabridge::LuaRef action_tbl (luabridge::newTable (L));
479 for (l = labels.begin(), p = paths.begin(); l != labels.end(); ++p, ++l) {
484 vector<string> parts;
485 split (*p, parts, '/');
491 //kinda kludgy way to avoid displaying menu items as mappable
492 if (parts[1] == _("Main_menu"))
494 if (parts[1] == _("JACK"))
496 if (parts[1] == _("redirectmenu"))
498 if (parts[1] == _("RegionList"))
500 if (parts[1] == _("ProcessorMenu"))
503 if (!action_tbl[parts[1]].isTable()) {
504 action_tbl[parts[1]] = luabridge::newTable (L);
506 assert (action_tbl[parts[1]].isTable());
507 luabridge::LuaRef tbl (action_tbl[parts[1]]);
508 assert (tbl.isTable());
512 luabridge::push (L, action_tbl);
516 ////////////////////////////////////////////////////////////////////////////////
518 // ARDOUR_UI and instance() are not exposed.
519 ARDOUR::PresentationInfo::order_t
520 lua_translate_order (RouteDialogs::InsertAt place)
522 return ARDOUR_UI::instance()->translate_order (place);
525 ////////////////////////////////////////////////////////////////////////////////
527 #define xstr(s) stringify(s)
528 #define stringify(s) #s
530 using namespace ARDOUR;
532 PBD::Signal0<void> LuaInstance::LuaTimerS;
533 PBD::Signal0<void> LuaInstance::LuaTimerDS;
534 PBD::Signal0<void> LuaInstance::SetSession;
537 LuaInstance::register_hooks (lua_State* L)
540 #define ENGINE(name,c,p) .addConst (stringify(name), (LuaSignal::LuaSignal)LuaSignal::name)
541 #define STATIC(name,c,p) .addConst (stringify(name), (LuaSignal::LuaSignal)LuaSignal::name)
542 #define SESSION(name,c,p) .addConst (stringify(name), (LuaSignal::LuaSignal)LuaSignal::name)
543 luabridge::getGlobalNamespace (L)
544 .beginNamespace ("LuaSignal")
545 # include "luasignal_syms.h"
551 luabridge::getGlobalNamespace (L)
552 .beginNamespace ("LuaSignal")
553 .beginStdBitSet <LuaSignal::LAST_SIGNAL> ("Set")
557 #if 0 // Dump size -> libs/ardour/luabindings.cc
558 printf ("LuaInstance: registered %d signals\n", LuaSignal::LAST_SIGNAL);
563 LuaInstance::bind_cairo (lua_State* L)
565 /* std::vector<double> for set_dash()
566 * for Windows (DLL, .exe) this needs to be bound in the same memory context as "Cairo".
568 * The std::vector<> argument in set_dash() has a fixed address in ardour.exe, while
569 * the address of the one in libardour.dll is mapped when loading the .dll
571 * see LuaBindings::set_session() for a detailed explanation
573 luabridge::getGlobalNamespace (L)
574 .beginNamespace ("C")
575 .beginStdVector <double> ("DoubleVector")
579 luabridge::getGlobalNamespace (L)
580 .beginNamespace ("Cairo")
581 .beginClass <Cairo::Context> ("Context")
582 .addFunction ("save", &Cairo::Context::save)
583 .addFunction ("restore", &Cairo::Context::restore)
584 .addFunction ("set_operator", &Cairo::Context::set_operator)
585 //.addFunction ("set_source", &Cairo::Context::set_operator) // needs RefPtr
586 .addFunction ("set_source_rgb", &Cairo::Context::set_source_rgb)
587 .addFunction ("set_source_rgba", &Cairo::Context::set_source_rgba)
588 .addFunction ("set_line_width", &Cairo::Context::set_line_width)
589 .addFunction ("set_line_cap", &Cairo::Context::set_line_cap)
590 .addFunction ("set_line_join", &Cairo::Context::set_line_join)
591 .addFunction ("set_dash", (void (Cairo::Context::*)(const std::vector<double>&, double))&Cairo::Context::set_dash)
592 .addFunction ("unset_dash", &Cairo::Context::unset_dash)
593 .addFunction ("translate", &Cairo::Context::translate)
594 .addFunction ("scale", &Cairo::Context::scale)
595 .addFunction ("rotate", &Cairo::Context::rotate)
596 .addFunction ("begin_new_path", &Cairo::Context::begin_new_path)
597 .addFunction ("begin_new_sub_path", &Cairo::Context::begin_new_sub_path)
598 .addFunction ("move_to", &Cairo::Context::move_to)
599 .addFunction ("line_to", &Cairo::Context::line_to)
600 .addFunction ("curve_to", &Cairo::Context::curve_to)
601 .addFunction ("arc", &Cairo::Context::arc)
602 .addFunction ("arc_negative", &Cairo::Context::arc_negative)
603 .addFunction ("rel_move_to", &Cairo::Context::rel_move_to)
604 .addFunction ("rel_line_to", &Cairo::Context::rel_line_to)
605 .addFunction ("rel_curve_to", &Cairo::Context::rel_curve_to)
606 .addFunction ("rectangle", (void (Cairo::Context::*)(double, double, double, double))&Cairo::Context::rectangle)
607 .addFunction ("close_path", &Cairo::Context::close_path)
608 .addFunction ("paint", &Cairo::Context::paint)
609 .addFunction ("paint_with_alpha", &Cairo::Context::paint_with_alpha)
610 .addFunction ("stroke", &Cairo::Context::stroke)
611 .addFunction ("stroke_preserve", &Cairo::Context::stroke_preserve)
612 .addFunction ("fill", &Cairo::Context::fill)
613 .addFunction ("fill_preserve", &Cairo::Context::fill_preserve)
614 .addFunction ("reset_clip", &Cairo::Context::reset_clip)
615 .addFunction ("clip", &Cairo::Context::clip)
616 .addFunction ("clip_preserve", &Cairo::Context::clip_preserve)
617 .addFunction ("set_font_size", &Cairo::Context::set_font_size)
618 .addFunction ("show_text", &Cairo::Context::show_text)
621 // LineCap, LineJoin, Operator
622 .beginNamespace ("LineCap")
623 .addConst ("Butt", CAIRO_LINE_CAP_BUTT)
624 .addConst ("Round", CAIRO_LINE_CAP_ROUND)
625 .addConst ("Square", CAIRO_LINE_CAP_SQUARE)
628 .beginNamespace ("LineJoin")
629 .addConst ("Miter", CAIRO_LINE_JOIN_MITER)
630 .addConst ("Round", CAIRO_LINE_JOIN_ROUND)
631 .addConst ("Bevel", CAIRO_LINE_JOIN_BEVEL)
634 .beginNamespace ("Operator")
635 .addConst ("Clear", CAIRO_OPERATOR_CLEAR)
636 .addConst ("Source", CAIRO_OPERATOR_SOURCE)
637 .addConst ("Over", CAIRO_OPERATOR_OVER)
638 .addConst ("Add", CAIRO_OPERATOR_ADD)
641 .beginNamespace ("Format")
642 .addConst ("ARGB32", CAIRO_FORMAT_ARGB32)
643 .addConst ("RGB24", CAIRO_FORMAT_RGB24)
646 .beginClass <LuaCairo::ImageSurface> ("ImageSurface")
647 .addConstructor <void (*) (Cairo::Format, int, int)> ()
648 .addFunction ("set_as_source", &LuaCairo::ImageSurface::set_as_source)
649 .addFunction ("context", &LuaCairo::ImageSurface::context)
650 .addFunction ("get_stride", &LuaCairo::ImageSurface::get_stride)
651 .addFunction ("get_width", &LuaCairo::ImageSurface::get_width)
652 .addFunction ("get_height", &LuaCairo::ImageSurface::get_height)
653 //.addFunction ("get_data", &LuaCairo::ImageSurface::get_data) // uint8_t* array is n/a
656 .beginClass <LuaCairo::PangoLayout> ("PangoLayout")
657 .addConstructor <void (*) (Cairo::Context*, std::string)> ()
658 .addCFunction ("get_pixel_size", &LuaCairo::PangoLayout::get_pixel_size)
659 .addFunction ("get_text", &LuaCairo::PangoLayout::get_text)
660 .addFunction ("set_text", &LuaCairo::PangoLayout::set_text)
661 .addFunction ("show_in_cairo_context", &LuaCairo::PangoLayout::show_in_cairo_context)
662 .addFunction ("layout_cairo_path", &LuaCairo::PangoLayout::layout_cairo_path)
663 .addFunction ("set_markup", &LuaCairo::PangoLayout::set_markup)
664 .addFunction ("set_width", &LuaCairo::PangoLayout::set_width)
665 .addFunction ("set_ellipsize", &LuaCairo::PangoLayout::set_ellipsize)
666 .addFunction ("get_ellipsize", &LuaCairo::PangoLayout::get_ellipsize)
667 .addFunction ("is_ellipsized", &LuaCairo::PangoLayout::is_ellipsized)
668 .addFunction ("set_alignment", &LuaCairo::PangoLayout::set_alignment)
669 .addFunction ("get_alignment", &LuaCairo::PangoLayout::get_alignment)
670 .addFunction ("set_wrap", &LuaCairo::PangoLayout::set_wrap)
671 .addFunction ("get_wrap", &LuaCairo::PangoLayout::get_wrap)
672 .addFunction ("is_wrapped", &LuaCairo::PangoLayout::is_wrapped)
676 .beginNamespace ("EllipsizeMode")
677 .addConst ("None", Pango::ELLIPSIZE_NONE)
678 .addConst ("Start", Pango::ELLIPSIZE_START)
679 .addConst ("Middle", Pango::ELLIPSIZE_MIDDLE)
680 .addConst ("End", Pango::ELLIPSIZE_END)
683 .beginNamespace ("Alignment")
684 .addConst ("Left", Pango::ALIGN_LEFT)
685 .addConst ("Center", Pango::ALIGN_CENTER)
686 .addConst ("Right", Pango::ALIGN_RIGHT)
689 .beginNamespace ("WrapMode")
690 .addConst ("Word", Pango::WRAP_WORD)
691 .addConst ("Char", Pango::WRAP_CHAR)
692 .addConst ("WordChar", Pango::WRAP_WORD_CHAR)
697 /* Lua/cairo bindings operate on Cairo::Context, there is no Cairo::RefPtr wrapper [yet].
698 one can work around this as follows:
701 LuaInstance::register_classes (lua.getState());
703 "function render (ctx)"
704 " ctx:rectangle (0, 0, 100, 100)"
705 " ctx:set_source_rgba (0.1, 1.0, 0.1, 1.0)"
710 Cairo::RefPtr<Cairo::Context> context = get_window ()->create_cairo_context ();
711 Cairo::Context ctx (context->cobj ());
713 luabridge::LuaRef lua_render = luabridge::getGlobal (lua.getState(), "render");
714 lua_render ((Cairo::Context *)&ctx);
721 LuaInstance::bind_dialog (lua_State* L)
723 luabridge::getGlobalNamespace (L)
724 .beginNamespace ("LuaDialog")
726 .beginClass <LuaDialog::Message> ("Message")
727 .addConstructor <void (*) (std::string const&, std::string const&, LuaDialog::Message::MessageType, LuaDialog::Message::ButtonType)> ()
728 .addFunction ("run", &LuaDialog::Message::run)
731 .beginClass <LuaDialog::Dialog> ("Dialog")
732 .addConstructor <void (*) (std::string const&, luabridge::LuaRef)> ()
733 .addCFunction ("run", &LuaDialog::Dialog::run)
737 .beginNamespace ("MessageType")
738 .addConst ("Info", LuaDialog::Message::Info)
739 .addConst ("Warning", LuaDialog::Message::Warning)
740 .addConst ("Question", LuaDialog::Message::Question)
741 .addConst ("Error", LuaDialog::Message::Error)
744 .beginNamespace ("ButtonType")
745 .addConst ("OK", LuaDialog::Message::OK)
746 .addConst ("Close", LuaDialog::Message::Close)
747 .addConst ("Cancel", LuaDialog::Message::Cancel)
748 .addConst ("Yes_No", LuaDialog::Message::Yes_No)
749 .addConst ("OK_Cancel", LuaDialog::Message::OK_Cancel)
752 .beginNamespace ("Response")
754 .addConst ("Cancel", 1)
755 .addConst ("Close", 2)
758 .addConst ("None", -1)
766 LuaInstance::register_classes (lua_State* L)
768 LuaBindings::stddef (L);
769 LuaBindings::common (L);
770 LuaBindings::session (L);
771 LuaBindings::osc (L);
776 luabridge::getGlobalNamespace (L)
777 .beginNamespace ("ArdourUI")
779 .addFunction ("http_get", &http_get_unlogged)
781 .addFunction ("mixer_screenshot", &mixer_screenshot)
783 .addFunction ("processor_selection", &LuaMixer::processor_selection)
785 .beginStdCPtrList <ArdourMarker> ("ArdourMarkerList")
788 .beginClass <ArdourMarker> ("ArdourMarker")
789 .addFunction ("name", &ArdourMarker::name)
790 .addFunction ("position", &ArdourMarker::position)
791 .addFunction ("_type", &ArdourMarker::type)
794 .beginClass <AxisView> ("AxisView")
797 .deriveClass <TimeAxisView, AxisView> ("TimeAxisView")
800 .deriveClass <StripableTimeAxisView, TimeAxisView> ("StripableTimeAxisView")
803 .beginClass <Selectable> ("Selectable")
806 .deriveClass <TimeAxisViewItem, Selectable> ("TimeAxisViewItem")
809 .deriveClass <RegionView, TimeAxisViewItem> ("RegionView")
812 .deriveClass <RouteUI, Selectable> ("RouteUI")
815 .deriveClass <RouteTimeAxisView, RouteUI> ("RouteTimeAxisView")
816 .addCast<StripableTimeAxisView> ("to_stripabletimeaxisview")
817 .addCast<TimeAxisView> ("to_timeaxisview") // deprecated
820 // std::list<Selectable*>
821 .beginStdCPtrList <Selectable> ("SelectionList")
824 // std::list<TimeAxisView*>
825 .beginStdCPtrList <TimeAxisView> ("TrackViewStdList")
829 .beginClass <RegionSelection> ("RegionSelection")
830 .addFunction ("start", &RegionSelection::start)
831 .addFunction ("end_sample", &RegionSelection::end_sample)
832 .addFunction ("n_midi_regions", &RegionSelection::n_midi_regions)
833 .addFunction ("regionlist", &RegionSelection::regionlist) // XXX check windows binding (libardour)
836 .deriveClass <TimeSelection, std::list<ARDOUR::AudioRange> > ("TimeSelection")
837 .addFunction ("start", &TimeSelection::start)
838 .addFunction ("end_sample", &TimeSelection::end_sample)
839 .addFunction ("length", &TimeSelection::length)
842 .deriveClass <MarkerSelection, std::list<ArdourMarker*> > ("MarkerSelection")
845 .deriveClass <TrackViewList, std::list<TimeAxisView*> > ("TrackViewList")
846 .addFunction ("contains", &TrackViewList::contains)
847 .addFunction ("routelist", &TrackViewList::routelist)
850 .deriveClass <TrackSelection, TrackViewList> ("TrackSelection")
853 .beginClass <Selection> ("Selection")
854 .addFunction ("clear", &Selection::clear)
855 .addFunction ("clear_all", &Selection::clear_all)
856 .addFunction ("empty", &Selection::empty)
857 .addData ("tracks", &Selection::tracks)
858 .addData ("regions", &Selection::regions)
859 .addData ("time", &Selection::time)
860 .addData ("markers", &Selection::markers)
862 .addData ("lines", &Selection::lines)
863 .addData ("playlists", &Selection::playlists)
864 .addData ("points", &Selection::points)
865 .addData ("midi_regions", &Selection::midi_regions)
866 .addData ("midi_notes", &Selection::midi_notes) // cut buffer only
870 .beginClass <PublicEditor> ("Editor")
871 .addFunction ("grid_type", &PublicEditor::grid_type)
872 .addFunction ("snap_mode", &PublicEditor::snap_mode)
873 .addFunction ("set_snap_mode", &PublicEditor::set_snap_mode)
875 .addFunction ("undo", &PublicEditor::undo)
876 .addFunction ("redo", &PublicEditor::redo)
878 .addFunction ("set_mouse_mode", &PublicEditor::set_mouse_mode)
879 .addFunction ("current_mouse_mode", &PublicEditor::current_mouse_mode)
881 .addFunction ("consider_auditioning", &PublicEditor::consider_auditioning)
883 .addFunction ("new_region_from_selection", &PublicEditor::new_region_from_selection)
884 .addFunction ("separate_region_from_selection", &PublicEditor::separate_region_from_selection)
885 .addFunction ("pixel_to_sample", &PublicEditor::pixel_to_sample)
886 .addFunction ("sample_to_pixel", &PublicEditor::sample_to_pixel)
888 .addFunction ("get_selection", &PublicEditor::get_selection)
889 .addFunction ("get_cut_buffer", &PublicEditor::get_cut_buffer)
890 .addRefFunction ("get_selection_extents", &PublicEditor::get_selection_extents)
892 .addFunction ("set_selection", &PublicEditor::set_selection)
894 .addFunction ("play_selection", &PublicEditor::play_selection)
895 .addFunction ("play_with_preroll", &PublicEditor::play_with_preroll)
896 .addFunction ("maybe_locate_with_edit_preroll", &PublicEditor::maybe_locate_with_edit_preroll)
897 .addFunction ("goto_nth_marker", &PublicEditor::goto_nth_marker)
899 .addFunction ("add_location_from_playhead_cursor", &PublicEditor::add_location_from_playhead_cursor)
900 .addFunction ("remove_location_at_playhead_cursor", &PublicEditor::remove_location_at_playhead_cursor)
902 .addFunction ("update_grid", &PublicEditor::update_grid)
903 .addFunction ("remove_tracks", &PublicEditor::remove_tracks)
905 .addFunction ("set_loop_range", &PublicEditor::set_loop_range)
906 .addFunction ("set_punch_range", &PublicEditor::set_punch_range)
908 .addFunction ("effective_mouse_mode", &PublicEditor::effective_mouse_mode)
910 .addRefFunction ("do_import", &PublicEditor::do_import)
911 .addRefFunction ("do_embed", &PublicEditor::do_embed)
913 .addFunction ("export_audio", &PublicEditor::export_audio)
914 .addFunction ("stem_export", &PublicEditor::stem_export)
915 .addFunction ("export_selection", &PublicEditor::export_selection)
916 .addFunction ("export_range", &PublicEditor::export_range)
918 .addFunction ("set_zoom_focus", &PublicEditor::set_zoom_focus)
919 .addFunction ("get_zoom_focus", &PublicEditor::get_zoom_focus)
920 .addFunction ("get_current_zoom", &PublicEditor::get_current_zoom)
921 .addFunction ("reset_zoom", &PublicEditor::reset_zoom)
923 .addFunction ("clear_playlist", &PublicEditor::clear_playlist)
924 .addFunction ("new_playlists", &PublicEditor::new_playlists)
925 .addFunction ("copy_playlists", &PublicEditor::copy_playlists)
926 .addFunction ("clear_playlists", &PublicEditor::clear_playlists)
928 .addFunction ("select_all_tracks", &PublicEditor::select_all_tracks)
929 .addFunction ("deselect_all", &PublicEditor::deselect_all)
931 #if 0 // TimeAxisView& can't be bound (pure virtual fn)
932 .addFunction ("set_selected_track", &PublicEditor::set_selected_track)
933 .addFunction ("set_selected_mixer_strip", &PublicEditor::set_selected_mixer_strip)
934 .addFunction ("ensure_time_axis_view_is_visible", &PublicEditor::ensure_time_axis_view_is_visible)
936 .addFunction ("hide_track_in_display", &PublicEditor::hide_track_in_display)
937 .addFunction ("show_track_in_display", &PublicEditor::show_track_in_display)
938 .addFunction ("set_visible_track_count", &PublicEditor::set_visible_track_count)
939 .addFunction ("fit_selection", &PublicEditor::fit_selection)
941 .addFunction ("regionview_from_region", &PublicEditor::regionview_from_region)
942 .addFunction ("set_stationary_playhead", &PublicEditor::set_stationary_playhead)
943 .addFunction ("stationary_playhead", &PublicEditor::stationary_playhead)
944 .addFunction ("set_follow_playhead", &PublicEditor::set_follow_playhead)
945 .addFunction ("follow_playhead", &PublicEditor::follow_playhead)
947 .addFunction ("dragging_playhead", &PublicEditor::dragging_playhead)
948 .addFunction ("leftmost_sample", &PublicEditor::leftmost_sample)
949 .addFunction ("current_page_samples", &PublicEditor::current_page_samples)
950 .addFunction ("visible_canvas_height", &PublicEditor::visible_canvas_height)
951 .addFunction ("temporal_zoom_step", &PublicEditor::temporal_zoom_step)
952 .addFunction ("override_visible_track_count", &PublicEditor::override_visible_track_count)
954 .addFunction ("scroll_tracks_down_line", &PublicEditor::scroll_tracks_down_line)
955 .addFunction ("scroll_tracks_up_line", &PublicEditor::scroll_tracks_up_line)
956 .addFunction ("scroll_down_one_track", &PublicEditor::scroll_down_one_track)
957 .addFunction ("scroll_up_one_track", &PublicEditor::scroll_up_one_track)
959 .addFunction ("reset_x_origin", &PublicEditor::reset_x_origin)
960 .addFunction ("get_y_origin", &PublicEditor::get_y_origin)
961 .addFunction ("reset_y_origin", &PublicEditor::reset_y_origin)
963 .addFunction ("remove_last_capture", &PublicEditor::remove_last_capture)
965 .addFunction ("maximise_editing_space", &PublicEditor::maximise_editing_space)
966 .addFunction ("restore_editing_space", &PublicEditor::restore_editing_space)
967 .addFunction ("toggle_meter_updating", &PublicEditor::toggle_meter_updating)
969 //.addFunction ("get_preferred_edit_position", &PublicEditor::get_preferred_edit_position)
970 //.addFunction ("split_regions_at", &PublicEditor::split_regions_at)
972 .addRefFunction ("get_nudge_distance", &PublicEditor::get_nudge_distance)
973 .addFunction ("get_paste_offset", &PublicEditor::get_paste_offset)
974 .addFunction ("get_grid_beat_divisions", &PublicEditor::get_grid_beat_divisions)
975 .addRefFunction ("get_grid_type_as_beats", &PublicEditor::get_grid_type_as_beats)
977 .addFunction ("toggle_ruler_video", &PublicEditor::toggle_ruler_video)
978 .addFunction ("toggle_xjadeo_proc", &PublicEditor::toggle_xjadeo_proc)
979 .addFunction ("get_videotl_bar_height", &PublicEditor::get_videotl_bar_height)
980 .addFunction ("set_video_timeline_height", &PublicEditor::set_video_timeline_height)
983 .addFunction ("get_equivalent_regions", &PublicEditor::get_equivalent_regions)
984 .addFunction ("drags", &PublicEditor::drags)
987 .addFunction ("get_stripable_time_axis_by_id", &PublicEditor::get_stripable_time_axis_by_id)
988 .addFunction ("get_track_views", &PublicEditor::get_track_views)
989 .addFunction ("rtav_from_route", &PublicEditor::rtav_from_route)
990 .addFunction ("axis_views_from_routes", &PublicEditor::axis_views_from_routes)
992 .addFunction ("center_screen", &PublicEditor::center_screen)
994 .addFunction ("get_smart_mode", &PublicEditor::get_smart_mode)
995 .addRefFunction ("get_pointer_position", &PublicEditor::get_pointer_position)
997 .addRefFunction ("find_location_from_marker", &PublicEditor::find_location_from_marker)
998 .addFunction ("find_marker_from_location_id", &PublicEditor::find_marker_from_location_id)
999 .addFunction ("mouse_add_new_marker", &PublicEditor::mouse_add_new_marker)
1001 .addFunction ("get_regions_at", &PublicEditor::get_regions_at)
1002 .addFunction ("get_regions_after", &PublicEditor::get_regions_after)
1003 .addFunction ("get_regions_from_selection_and_mouse", &PublicEditor::get_regions_from_selection_and_mouse)
1004 .addFunction ("get_regionviews_by_id", &PublicEditor::get_regionviews_by_id)
1005 .addFunction ("get_per_region_note_selection", &PublicEditor::get_per_region_note_selection)
1009 .addFunction ("mouse_add_new_tempo_event", &PublicEditor::mouse_add_new_tempo_event)
1010 .addFunction ("mouse_add_new_meter_event", &PublicEditor::mouse_add_new_meter_event)
1011 .addFunction ("edit_tempo_section", &PublicEditor::edit_tempo_section)
1012 .addFunction ("edit_meter_section", &PublicEditor::edit_meter_section)
1015 .addFunction ("access_action", &PublicEditor::access_action)
1016 .addFunction ("set_toggleaction", &PublicEditor::set_toggleaction)
1019 .addFunction ("translate_order", &lua_translate_order)
1021 /* ArdourUI enums */
1022 .beginNamespace ("InsertAt")
1023 .addConst ("BeforeSelection", RouteDialogs::InsertAt(RouteDialogs::BeforeSelection))
1024 .addConst ("AfterSelection", RouteDialogs::InsertAt(RouteDialogs::AfterSelection))
1025 .addConst ("First", RouteDialogs::InsertAt(RouteDialogs::First))
1026 .addConst ("Last", RouteDialogs::InsertAt(RouteDialogs::Last))
1029 .beginNamespace ("MarkerType")
1030 .addConst ("Mark", ArdourMarker::Type(ArdourMarker::Mark))
1031 .addConst ("Tempo", ArdourMarker::Type(ArdourMarker::Tempo))
1032 .addConst ("Meter", ArdourMarker::Type(ArdourMarker::Meter))
1033 .addConst ("SessionStart", ArdourMarker::Type(ArdourMarker::SessionStart))
1034 .addConst ("SessionEnd", ArdourMarker::Type(ArdourMarker::SessionEnd))
1035 .addConst ("RangeStart", ArdourMarker::Type(ArdourMarker::RangeStart))
1036 .addConst ("RangeEnd", ArdourMarker::Type(ArdourMarker::RangeEnd))
1037 .addConst ("LoopStart", ArdourMarker::Type(ArdourMarker::LoopStart))
1038 .addConst ("LoopEnd", ArdourMarker::Type(ArdourMarker::LoopEnd))
1039 .addConst ("PunchIn", ArdourMarker::Type(ArdourMarker::PunchIn))
1040 .addConst ("PunchOut", ArdourMarker::Type(ArdourMarker::PunchOut))
1043 .beginNamespace ("SelectionOp")
1044 .addConst ("Toggle", Selection::Operation(Selection::Toggle))
1045 .addConst ("Set", Selection::Operation(Selection::Set))
1046 .addConst ("Extend", Selection::Operation(Selection::Extend))
1047 .addConst ("Add", Selection::Operation(Selection::Add))
1050 .addCFunction ("actionlist", &lua_actionlist)
1052 .endNamespace () // end ArdourUI
1054 .beginNamespace ("os")
1055 #ifndef PLATFORM_WINDOWS
1056 .addFunction ("execute", &lua_exec)
1058 .addCFunction ("forkexec", &lua_forkexec)
1067 #undef DISPLAYCONTROL
1069 #undef IMPORTPOSITION
1070 #undef IMPORTDISPOSITION
1072 #define ZOOMFOCUS(NAME) .addConst (stringify(NAME), (Editing::ZoomFocus)Editing::NAME)
1073 #define GRIDTYPE(NAME) .addConst (stringify(NAME), (Editing::GridType)Editing::NAME)
1074 #define SNAPMODE(NAME) .addConst (stringify(NAME), (Editing::SnapMode)Editing::NAME)
1075 #define MOUSEMODE(NAME) .addConst (stringify(NAME), (Editing::MouseMode)Editing::NAME)
1076 #define DISPLAYCONTROL(NAME) .addConst (stringify(NAME), (Editing::DisplayControl)Editing::NAME)
1077 #define IMPORTMODE(NAME) .addConst (stringify(NAME), (Editing::ImportMode)Editing::NAME)
1078 #define IMPORTPOSITION(NAME) .addConst (stringify(NAME), (Editing::ImportPosition)Editing::NAME)
1079 #define IMPORTDISPOSITION(NAME) .addConst (stringify(NAME), (Editing::ImportDisposition)Editing::NAME)
1080 luabridge::getGlobalNamespace (L)
1081 .beginNamespace ("Editing")
1082 # include "editing_syms.h"
1089 ////////////////////////////////////////////////////////////////////////////////
1091 using namespace ARDOUR;
1092 using namespace ARDOUR_UI_UTILS;
1093 using namespace PBD;
1094 using namespace std;
1096 static void _lua_print (std::string s) {
1098 std::cout << "LuaInstance: " << s << "\n";
1100 PBD::info << "LuaInstance: " << s << endmsg;
1103 LuaInstance* LuaInstance::_instance = 0;
1106 LuaInstance::instance ()
1109 _instance = new LuaInstance;
1116 LuaInstance::destroy_instance ()
1122 LuaInstance::LuaInstance ()
1124 lua.Print.connect (&_lua_print);
1128 LuaInstance::~LuaInstance ()
1130 delete _lua_call_action;
1131 delete _lua_render_icon;
1132 delete _lua_add_action;
1133 delete _lua_del_action;
1134 delete _lua_get_action;
1143 LuaInstance::init ()
1145 lua.sandbox (false);
1147 "function ScriptManager ()"
1148 " local self = { scripts = {}, instances = {}, icons = {} }"
1150 " local remove = function (id)"
1151 " self.scripts[id] = nil"
1152 " self.instances[id] = nil"
1153 " self.icons[id] = nil"
1156 " local addinternal = function (i, n, s, f, c, a)"
1157 " assert(type(i) == 'number', 'id must be numeric')"
1158 " assert(type(n) == 'string', 'Name must be string')"
1159 " assert(type(s) == 'string', 'Script must be string')"
1160 " assert(type(f) == 'function', 'Factory is a not a function')"
1161 " assert(type(a) == 'table' or type(a) == 'nil', 'Given argument is invalid')"
1162 " self.scripts[i] = { ['n'] = n, ['s'] = s, ['f'] = f, ['a'] = a, ['c'] = c }"
1163 " local env = _ENV; env.f = nil"
1164 " self.instances[i] = load (string.dump(f, true), nil, nil, env)(a)"
1165 " if type(c) == 'function' then"
1166 " self.icons[i] = load (string.dump(c, true), nil, nil, env)(a)"
1168 " self.icons[i] = nil"
1172 " local call = function (id)"
1173 " if type(self.instances[id]) == 'function' then"
1174 " local status, err = pcall (self.instances[id])"
1175 " if not status then"
1176 " print ('action \"'.. id .. '\": ', err)" // error out
1183 " local icon = function (id, ...)"
1184 " if type(self.icons[id]) == 'function' then"
1185 " pcall (self.icons[id], ...)"
1190 " local add = function (i, n, s, b, c, a)"
1191 " assert(type(b) == 'string', 'ByteCode must be string')"
1192 " f = nil load (b)()" // assigns f
1193 " icn = nil load (c)()" // may assign "icn"
1194 " assert(type(f) == 'string', 'Assigned ByteCode must be string')"
1195 " addinternal (i, n, s, load(f), type(icn) ~= \"string\" or icn == '' or load(icn), a)"
1198 " local get = function (id)"
1199 " if type(self.scripts[id]) == 'table' then"
1200 " return { ['name'] = self.scripts[id]['n'],"
1201 " ['script'] = self.scripts[id]['s'],"
1202 " ['icon'] = type(self.scripts[id]['c']) == 'function',"
1203 " ['args'] = self.scripts[id]['a'] }"
1208 " local function basic_serialize (o)"
1209 " if type(o) == \"number\" then"
1210 " return tostring(o)"
1212 " return string.format(\"%q\", o)"
1216 " local function serialize (name, value)"
1217 " local rv = name .. ' = '"
1218 " if type(value) == \"number\" or type(value) == \"string\" or type(value) == \"nil\" then"
1219 " return rv .. basic_serialize(value) .. ' '"
1220 " elseif type(value) == \"table\" then"
1222 " for k,v in pairs(value) do"
1223 " local fieldname = string.format(\"%s[%s]\", name, basic_serialize(k))"
1224 " rv = rv .. serialize(fieldname, v) .. ' '"
1227 " elseif type(value) == \"function\" then"
1228 " return rv .. string.format(\"%q\", string.dump(value, true))"
1229 " elseif type(value) == \"boolean\" then"
1230 " return rv .. tostring (value)"
1232 " error('cannot save a ' .. type(value))"
1237 " local save = function ()"
1238 " return (serialize('scripts', self.scripts))"
1241 " local clear = function ()"
1242 " self.scripts = {}"
1243 " self.instances = {}"
1248 " local restore = function (state)"
1251 " for i, s in pairs (scripts) do"
1252 " addinternal (i, s['n'], s['s'], load(s['f']), type (s['c']) ~= \"string\" or s['c'] == '' or load (s['c']), s['a'])"
1257 " return { call = call, add = add, remove = remove, get = get,"
1258 " restore = restore, save = save, clear = clear, icon = icon}"
1261 " manager = ScriptManager ()"
1262 " ScriptManager = nil"
1264 lua_State* L = lua.getState();
1267 luabridge::LuaRef lua_mgr = luabridge::getGlobal (L, "manager");
1268 lua.do_command ("manager = nil"); // hide it.
1269 lua.do_command ("collectgarbage()");
1271 _lua_add_action = new luabridge::LuaRef(lua_mgr["add"]);
1272 _lua_del_action = new luabridge::LuaRef(lua_mgr["remove"]);
1273 _lua_get_action = new luabridge::LuaRef(lua_mgr["get"]);
1274 _lua_call_action = new luabridge::LuaRef(lua_mgr["call"]);
1275 _lua_render_icon = new luabridge::LuaRef(lua_mgr["icon"]);
1276 _lua_save = new luabridge::LuaRef(lua_mgr["save"]);
1277 _lua_load = new luabridge::LuaRef(lua_mgr["restore"]);
1278 _lua_clear = new luabridge::LuaRef(lua_mgr["clear"]);
1280 } catch (luabridge::LuaException const& e) {
1281 fatal << string_compose (_("programming error: %1"),
1282 std::string ("Failed to setup Lua action interpreter") + e.what ())
1284 abort(); /*NOTREACHED*/
1286 fatal << string_compose (_("programming error: %1"),
1287 X_("Failed to setup Lua action interpreter"))
1289 abort(); /*NOTREACHED*/
1292 register_classes (L);
1295 luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
1296 lua_setglobal (L, "Editor");
1300 LuaInstance::load_state ()
1302 std::string uiscripts;
1303 if (!find_file (ardour_config_search_path(), ui_scripts_file_name, uiscripts)) {
1308 info << string_compose (_("Loading user ui scripts file %1"), uiscripts) << endmsg;
1310 if (!tree.read (uiscripts)) {
1311 error << string_compose(_("cannot read ui scripts file \"%1\""), uiscripts) << endmsg;
1315 if (set_state (*tree.root())) {
1316 error << string_compose(_("user ui scripts file \"%1\" not loaded successfully."), uiscripts) << endmsg;
1324 LuaInstance::save_state ()
1327 /* action scripts are un-registered with the session */
1331 std::string uiscripts = Glib::build_filename (user_config_directory(), ui_scripts_file_name);
1333 XMLNode* node = new XMLNode (X_("UIScripts"));
1334 node->add_child_nocopy (get_action_state ());
1335 node->add_child_nocopy (get_hook_state ());
1338 tree.set_root (node);
1340 if (!tree.write (uiscripts.c_str())){
1341 error << string_compose (_("UI script file %1 not saved"), uiscripts) << endmsg;
1348 LuaInstance::set_dirty ()
1350 if (!_session || _session->deletion_in_progress()) {
1354 _session->set_dirty (); // XXX is this reasonable?
1357 void LuaInstance::set_session (Session* s)
1359 SessionHandlePtr::set_session (s);
1366 lua_State* L = lua.getState();
1367 LuaBindings::set_session (L, _session);
1369 for (LuaCallbackMap::iterator i = _callbacks.begin(); i != _callbacks.end(); ++i) {
1370 i->second->set_session (s);
1372 second_connection = Timers::rapid_connect (sigc::mem_fun(*this, & LuaInstance::every_second));
1373 point_one_second_connection = Timers::rapid_connect (sigc::mem_fun(*this, & LuaInstance::every_point_one_seconds));
1374 SetSession (); /* EMIT SIGNAL */
1378 LuaInstance::session_going_away ()
1380 ENSURE_GUI_THREAD (*this, &LuaInstance::session_going_away);
1381 second_connection.disconnect ();
1382 point_one_second_connection.disconnect ();
1385 for (int i = 0; i < MAX_LUA_ACTION_SCRIPTS; ++i) {
1386 ActionChanged (i, ""); /* EMIT SIGNAL */
1388 SessionHandlePtr::session_going_away ();
1391 lua_State* L = lua.getState();
1392 LuaBindings::set_session (L, _session);
1393 lua.do_command ("collectgarbage();");
1397 LuaInstance::every_second ()
1399 LuaTimerS (); // emit signal
1403 LuaInstance::every_point_one_seconds ()
1405 LuaTimerDS (); // emit signal
1409 LuaInstance::set_state (const XMLNode& node)
1413 if ((child = find_named_node (node, "ActionScript"))) {
1414 for (XMLNodeList::const_iterator n = child->children ().begin (); n != child->children ().end (); ++n) {
1415 if (!(*n)->is_content ()) { continue; }
1417 guchar* buf = g_base64_decode ((*n)->content ().c_str (), &size);
1419 (*_lua_load)(std::string ((const char*)buf, size));
1420 } catch (luabridge::LuaException const& e) {
1421 cerr << "LuaException:" << e.what () << endl;
1423 for (int i = 0; i < MAX_LUA_ACTION_SCRIPTS; ++i) {
1425 if (lua_action_name (i, name)) {
1426 ActionChanged (i, name); /* EMIT SIGNAL */
1433 assert (_callbacks.empty());
1434 if ((child = find_named_node (node, "ActionHooks"))) {
1435 for (XMLNodeList::const_iterator n = child->children ().begin (); n != child->children ().end (); ++n) {
1437 LuaCallbackPtr p (new LuaCallback (_session, *(*n)));
1438 _callbacks.insert (std::make_pair(p->id(), p));
1439 p->drop_callback.connect (_slotcon, MISSING_INVALIDATOR, boost::bind (&LuaInstance::unregister_lua_slot, this, p->id()), gui_context());
1440 SlotChanged (p->id(), p->name(), p->signals()); /* EMIT SIGNAL */
1441 } catch (luabridge::LuaException const& e) {
1442 cerr << "LuaException:" << e.what () << endl;
1451 LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id)
1454 std::string param_function = "action_params";
1455 std::vector<std::string> reg;
1458 case LuaScriptInfo::EditorAction:
1459 reg = lua_action_names ();
1460 title = _("Add Shortcut or Lua Script");
1462 case LuaScriptInfo::EditorHook:
1463 reg = lua_slot_names ();
1464 title = _("Add Lua Callback Hook");
1466 case LuaScriptInfo::Session:
1470 reg = _session->registered_lua_functions ();
1471 title = _("Add Lua Session Script");
1472 param_function = "sess_params";
1478 LuaScriptInfoPtr spi;
1479 ScriptSelector ss (title, type);
1480 switch (ss.run ()) {
1481 case Gtk::RESPONSE_ACCEPT:
1489 std::string script = "";
1492 script = Glib::file_get_contents (spi->path);
1493 } catch (Glib::FileError const& e) {
1494 string msg = string_compose (_("Cannot read script '%1': %2"), spi->path, e.what());
1495 Gtk::MessageDialog am (msg);
1501 register_classes (ls.getState ());
1502 LuaScriptParamList lsp = LuaScriptParams::script_params (ls, spi->path, param_function);
1505 for (size_t i = 0; i < lsp.size(); ++i) {
1506 if (lsp[i]->preseeded && lsp[i]->name == "x-script-abort") {
1511 ScriptParameterDialog spd (_("Set Script Parameters"), spi, reg, lsp);
1513 if (spd.need_interation ()) {
1514 switch (spd.run ()) {
1515 case Gtk::RESPONSE_ACCEPT:
1522 LuaScriptParamPtr lspp (new LuaScriptParam("x-script-origin", "", spi->path, false, true));
1523 lsp.push_back (lspp);
1526 case LuaScriptInfo::EditorAction:
1527 return set_lua_action (id, spd.name(), script, lsp);
1529 case LuaScriptInfo::EditorHook:
1530 return register_lua_slot (spd.name(), script, lsp);
1532 case LuaScriptInfo::Session:
1534 _session->register_lua_function (spd.name(), script, lsp);
1535 } catch (luabridge::LuaException const& e) {
1536 string msg = string_compose (_("Session script '%1' instantiation failed: %2"), spd.name(), e.what ());
1537 Gtk::MessageDialog am (msg);
1539 } catch (SessionException const& e) {
1540 string msg = string_compose (_("Loading Session script '%1' failed: %2"), spd.name(), e.what ());
1541 Gtk::MessageDialog am (msg);
1544 string msg = string_compose (_("Loading Session script '%1' failed: %2"), spd.name(), "Unknown Exception");
1545 Gtk::MessageDialog am (msg);
1555 LuaInstance::get_action_state ()
1559 luabridge::LuaRef savedstate ((*_lua_save)());
1560 saved = savedstate.cast<std::string>();
1562 lua.collect_garbage ();
1564 gchar* b64 = g_base64_encode ((const guchar*)saved.c_str (), saved.size ());
1565 std::string b64s (b64);
1568 XMLNode* script_node = new XMLNode (X_("ActionScript"));
1569 script_node->set_property (X_("lua"), LUA_VERSION);
1570 script_node->add_content (b64s);
1572 return *script_node;
1576 LuaInstance::get_hook_state ()
1578 XMLNode* script_node = new XMLNode (X_("ActionHooks"));
1579 for (LuaCallbackMap::const_iterator i = _callbacks.begin(); i != _callbacks.end(); ++i) {
1580 script_node->add_child_nocopy (i->second->get_state ());
1582 return *script_node;
1586 LuaInstance::call_action (const int id)
1589 (*_lua_call_action)(id + 1);
1590 lua.collect_garbage_step ();
1591 } catch (luabridge::LuaException const& e) {
1592 cerr << "LuaException:" << e.what () << endl;
1597 LuaInstance::render_action_icon (cairo_t* cr, int w, int h, uint32_t c, void* i) {
1598 int ii = reinterpret_cast<uintptr_t> (i);
1599 instance()->render_icon (ii, cr, w, h, c);
1603 LuaInstance::render_icon (int i, cairo_t* cr, int w, int h, uint32_t clr)
1605 Cairo::Context ctx (cr);
1607 (*_lua_render_icon)(i + 1, (Cairo::Context *)&ctx, w, h, clr);
1608 } catch (luabridge::LuaException const& e) {
1609 cerr << "LuaException:" << e.what () << endl;
1614 LuaInstance::set_lua_action (
1616 const std::string& name,
1617 const std::string& script,
1618 const LuaScriptParamList& args)
1621 lua_State* L = lua.getState();
1622 // get bytcode of factory-function in a sandbox
1623 // (don't allow scripts to interfere)
1624 const std::string& bytecode = LuaScripting::get_factory_bytecode (script);
1625 const std::string& iconfunc = LuaScripting::get_factory_bytecode (script, "icon", "icn");
1626 luabridge::LuaRef tbl_arg (luabridge::newTable(L));
1627 for (LuaScriptParamList::const_iterator i = args.begin(); i != args.end(); ++i) {
1628 if ((*i)->optional && !(*i)->is_set) { continue; }
1629 tbl_arg[(*i)->name] = (*i)->value;
1631 (*_lua_add_action)(id + 1, name, script, bytecode, iconfunc, tbl_arg);
1632 ActionChanged (id, name); /* EMIT SIGNAL */
1633 } catch (luabridge::LuaException const& e) {
1634 cerr << "LuaException:" << e.what () << endl;
1644 LuaInstance::remove_lua_action (const int id)
1647 (*_lua_del_action)(id + 1);
1648 } catch (luabridge::LuaException const& e) {
1649 cerr << "LuaException:" << e.what () << endl;
1654 ActionChanged (id, ""); /* EMIT SIGNAL */
1660 LuaInstance::lua_action_name (const int id, std::string& rv)
1663 luabridge::LuaRef ref ((*_lua_get_action)(id + 1));
1667 if (ref["name"].isString()) {
1668 rv = ref["name"].cast<std::string>();
1672 } catch (luabridge::LuaException const& e) {
1673 cerr << "LuaException:" << e.what () << endl;
1678 std::vector<std::string>
1679 LuaInstance::lua_action_names ()
1681 std::vector<std::string> rv;
1682 for (int i = 0; i < MAX_LUA_ACTION_SCRIPTS; ++i) {
1684 if (lua_action_name (i, name)) {
1685 rv.push_back (name);
1692 LuaInstance::lua_action_has_icon (const int id)
1695 luabridge::LuaRef ref ((*_lua_get_action)(id + 1));
1699 if (ref["icon"].isBoolean()) {
1700 return ref["icon"].cast<bool>();
1702 } catch (luabridge::LuaException const& e) {
1703 cerr << "LuaException:" << e.what () << endl;
1709 LuaInstance::lua_action (const int id, std::string& name, std::string& script, LuaScriptParamList& args)
1712 luabridge::LuaRef ref ((*_lua_get_action)(id + 1));
1716 if (!ref["name"].isString()) {
1719 if (!ref["script"].isString()) {
1722 if (!ref["args"].isTable()) {
1725 name = ref["name"].cast<std::string>();
1726 script = ref["script"].cast<std::string>();
1729 LuaScriptInfoPtr lsi = LuaScripting::script_info (script);
1733 args = LuaScriptParams::script_params (lsi, "action_params");
1734 luabridge::LuaRef rargs (ref["args"]);
1735 LuaScriptParams::ref_to_params (args, &rargs);
1737 } catch (luabridge::LuaException const& e) {
1738 cerr << "LuaException:" << e.what () << endl;
1744 LuaInstance::register_lua_slot (const std::string& name, const std::string& script, const ARDOUR::LuaScriptParamList& args)
1746 /* parse script, get ActionHook(s) from script */
1750 l.Print.connect (&_lua_print);
1752 lua_State* L = l.getState();
1754 l.do_command ("function ardour () end");
1755 l.do_command (script);
1756 luabridge::LuaRef signals = luabridge::getGlobal (L, "signals");
1757 if (signals.isFunction()) {
1760 } catch (luabridge::LuaException const& e) {
1761 cerr << "LuaException:" << e.what () << endl;
1765 cerr << "Script registered no hooks." << endl;
1769 /* register script w/args, get entry-point / ID */
1772 LuaCallbackPtr p (new LuaCallback (_session, name, script, ah, args));
1773 _callbacks.insert (std::make_pair(p->id(), p));
1774 p->drop_callback.connect (_slotcon, MISSING_INVALIDATOR, boost::bind (&LuaInstance::unregister_lua_slot, this, p->id()), gui_context());
1775 SlotChanged (p->id(), p->name(), p->signals()); /* EMIT SIGNAL */
1778 } catch (luabridge::LuaException const& e) {
1779 cerr << "LuaException:" << e.what () << endl;
1785 LuaInstance::unregister_lua_slot (const PBD::ID& id)
1787 LuaCallbackMap::iterator i = _callbacks.find (id);
1788 if (i != _callbacks.end()) {
1789 SlotChanged (id, "", ActionHook()); /* EMIT SIGNAL */
1790 _callbacks.erase (i);
1797 std::vector<PBD::ID>
1798 LuaInstance::lua_slots () const
1800 std::vector<PBD::ID> rv;
1801 for (LuaCallbackMap::const_iterator i = _callbacks.begin(); i != _callbacks.end(); ++i) {
1802 rv.push_back (i->first);
1808 LuaInstance::lua_slot_name (const PBD::ID& id, std::string& name) const
1810 LuaCallbackMap::const_iterator i = _callbacks.find (id);
1811 if (i != _callbacks.end()) {
1812 name = i->second->name();
1818 std::vector<std::string>
1819 LuaInstance::lua_slot_names () const
1821 std::vector<std::string> rv;
1822 std::vector<PBD::ID> ids = lua_slots();
1823 for (std::vector<PBD::ID>::const_iterator i = ids.begin(); i != ids.end(); ++i) {
1825 if (lua_slot_name (*i, name)) {
1826 rv.push_back (name);
1833 LuaInstance::lua_slot (const PBD::ID& id, std::string& name, std::string& script, ActionHook& ah, ARDOUR::LuaScriptParamList& args)
1835 LuaCallbackMap::const_iterator i = _callbacks.find (id);
1836 if (i == _callbacks.end()) {
1837 return false; // error
1839 return i->second->lua_slot (name, script, ah, args);
1842 ///////////////////////////////////////////////////////////////////////////////
1844 LuaCallback::LuaCallback (Session *s,
1845 const std::string& name,
1846 const std::string& script,
1847 const ActionHook& ah,
1848 const ARDOUR::LuaScriptParamList& args)
1849 : SessionHandlePtr (s)
1854 // TODO: allow to reference object (e.g region)
1857 lua_State* L = lua.getState();
1858 luabridge::LuaRef tbl_arg (luabridge::newTable(L));
1859 for (LuaScriptParamList::const_iterator i = args.begin(); i != args.end(); ++i) {
1860 if ((*i)->optional && !(*i)->is_set) { continue; }
1861 tbl_arg[(*i)->name] = (*i)->value;
1865 const std::string& bytecode = LuaScripting::get_factory_bytecode (script);
1866 (*_lua_add)(name, script, bytecode, tbl_arg);
1867 } catch (luabridge::LuaException const& e) {
1868 cerr << "LuaException:" << e.what () << endl;
1869 throw failed_constructor ();
1871 throw failed_constructor ();
1878 LuaCallback::LuaCallback (Session *s, XMLNode & node)
1879 : SessionHandlePtr (s)
1881 XMLNode* child = NULL;
1882 if (node.name() != X_("LuaCallback")
1883 || !node.property ("signals")
1884 || !node.property ("id")
1885 || !node.property ("name")) {
1886 throw failed_constructor ();
1889 for (XMLNodeList::const_iterator n = node.children ().begin (); n != node.children ().end (); ++n) {
1890 if (!(*n)->is_content ()) { continue; }
1895 throw failed_constructor ();
1900 _id = PBD::ID (node.property ("id")->value ());
1901 _name = node.property ("name")->value ();
1902 _signals = ActionHook (node.property ("signals")->value ());
1905 guchar* buf = g_base64_decode (child->content ().c_str (), &size);
1907 (*_lua_load)(std::string ((const char*)buf, size));
1908 } catch (luabridge::LuaException const& e) {
1909 cerr << "LuaException:" << e.what () << endl;
1916 LuaCallback::~LuaCallback ()
1926 LuaCallback::get_state (void)
1930 luabridge::LuaRef savedstate ((*_lua_save)());
1931 saved = savedstate.cast<std::string>();
1934 lua.collect_garbage (); // this may be expensive:
1935 /* Editor::instant_save() calls Editor::get_state() which
1936 * calls LuaInstance::get_hook_state() which in turn calls
1937 * this LuaCallback::get_state() for every registered hook.
1939 * serialize in _lua_save() allocates many small strings
1940 * on the lua-stack, collecting them all may take a ms.
1943 gchar* b64 = g_base64_encode ((const guchar*)saved.c_str (), saved.size ());
1944 std::string b64s (b64);
1947 XMLNode* script_node = new XMLNode (X_("LuaCallback"));
1948 script_node->set_property (X_("lua"), LUA_VERSION);
1949 script_node->set_property (X_("id"), _id.to_s ());
1950 script_node->set_property (X_("name"), _name);
1951 script_node->set_property (X_("signals"), _signals.to_string ());
1952 script_node->add_content (b64s);
1953 return *script_node;
1957 LuaCallback::init (void)
1959 lua.Print.connect (&_lua_print);
1960 lua.sandbox (false);
1963 "function ScriptManager ()"
1964 " local self = { script = {}, instance = {} }"
1966 " local addinternal = function (n, s, f, a)"
1967 " assert(type(n) == 'string', 'Name must be string')"
1968 " assert(type(s) == 'string', 'Script must be string')"
1969 " assert(type(f) == 'function', 'Factory is a not a function')"
1970 " assert(type(a) == 'table' or type(a) == 'nil', 'Given argument is invalid')"
1971 " self.script = { ['n'] = n, ['s'] = s, ['f'] = f, ['a'] = a }"
1972 " local env = _ENV; env.f = nil"
1973 " self.instance = load (string.dump(f, true), nil, nil, env)(a)"
1976 " local call = function (...)"
1977 " if type(self.instance) == 'function' then"
1978 " local status, err = pcall (self.instance, ...)"
1979 " if not status then"
1980 " print ('callback \"'.. self.script['n'] .. '\": ', err)" // error out
1981 " self.script = nil"
1982 " self.instance = nil"
1990 " local add = function (n, s, b, a)"
1991 " assert(type(b) == 'string', 'ByteCode must be string')"
1992 " load (b)()" // assigns f
1993 " assert(type(f) == 'string', 'Assigned ByteCode must be string')"
1994 " addinternal (n, s, load(f), a)"
1997 " local get = function ()"
1998 " if type(self.instance) == 'function' and type(self.script['n']) == 'string' then"
1999 " return { ['name'] = self.script['n'],"
2000 " ['script'] = self.script['s'],"
2001 " ['args'] = self.script['a'] }"
2008 " local function basic_serialize (o)"
2009 " if type(o) == \"number\" then"
2010 " return tostring(o)"
2012 " return string.format(\"%q\", o)"
2016 " local function serialize (name, value)"
2017 " local rv = name .. ' = '"
2018 " if type(value) == \"number\" or type(value) == \"string\" or type(value) == \"nil\" then"
2019 " return rv .. basic_serialize(value) .. ' '"
2020 " elseif type(value) == \"table\" then"
2022 " for k,v in pairs(value) do"
2023 " local fieldname = string.format(\"%s[%s]\", name, basic_serialize(k))"
2024 " rv = rv .. serialize(fieldname, v) .. ' '"
2027 " elseif type(value) == \"function\" then"
2028 " return rv .. string.format(\"%q\", string.dump(value, true))"
2029 " elseif type(value) == \"boolean\" then"
2030 " return rv .. tostring (value)"
2032 " error('cannot save a ' .. type(value))"
2038 " local save = function ()"
2039 " return (serialize('s', self.script))"
2042 " local restore = function (state)"
2045 " addinternal (s['n'], s['s'], load(s['f']), s['a'])"
2048 " return { call = call, add = add, get = get,"
2049 " restore = restore, save = save}"
2052 " manager = ScriptManager ()"
2053 " ScriptManager = nil"
2056 lua_State* L = lua.getState();
2059 luabridge::LuaRef lua_mgr = luabridge::getGlobal (L, "manager");
2060 lua.do_command ("manager = nil"); // hide it.
2061 lua.do_command ("collectgarbage()");
2063 _lua_add = new luabridge::LuaRef(lua_mgr["add"]);
2064 _lua_get = new luabridge::LuaRef(lua_mgr["get"]);
2065 _lua_call = new luabridge::LuaRef(lua_mgr["call"]);
2066 _lua_save = new luabridge::LuaRef(lua_mgr["save"]);
2067 _lua_load = new luabridge::LuaRef(lua_mgr["restore"]);
2069 } catch (luabridge::LuaException const& e) {
2070 fatal << string_compose (_("programming error: %1"),
2071 std::string ("Failed to setup Lua callback interpreter: ") + e.what ())
2073 abort(); /*NOTREACHED*/
2075 fatal << string_compose (_("programming error: %1"),
2076 X_("Failed to setup Lua callback interpreter"))
2078 abort(); /*NOTREACHED*/
2081 LuaInstance::register_classes (L);
2082 LuaInstance::register_hooks (L);
2084 luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
2085 lua_setglobal (L, "Editor");
2089 LuaCallback::lua_slot (std::string& name, std::string& script, ActionHook& ah, ARDOUR::LuaScriptParamList& args)
2091 // TODO consolidate w/ LuaInstance::lua_action()
2093 luabridge::LuaRef ref = (*_lua_get)();
2097 if (!ref["name"].isString()) {
2100 if (!ref["script"].isString()) {
2103 if (!ref["args"].isTable()) {
2108 name = ref["name"].cast<std::string> ();
2109 script = ref["script"].cast<std::string> ();
2112 LuaScriptInfoPtr lsi = LuaScripting::script_info (script);
2116 args = LuaScriptParams::script_params (lsi, "action_params");
2117 luabridge::LuaRef rargs (ref["args"]);
2118 LuaScriptParams::ref_to_params (args, &rargs);
2120 } catch (luabridge::LuaException const& e) {
2121 cerr << "LuaException:" << e.what () << endl;
2128 LuaCallback::set_session (ARDOUR::Session *s)
2130 SessionHandlePtr::set_session (s);
2136 lua_State* L = lua.getState();
2137 LuaBindings::set_session (L, _session);
2143 LuaCallback::session_going_away ()
2145 ENSURE_GUI_THREAD (*this, &LuaCallback::session_going_away);
2146 lua.do_command ("collectgarbage();");
2148 SessionHandlePtr::session_going_away ();
2151 drop_callback (); /* EMIT SIGNAL */
2155 LuaCallback::reconnect ()
2157 _connections.drop_connections ();
2158 if ((*_lua_get) ().isNil ()) {
2159 drop_callback (); /* EMIT SIGNAL */
2163 // TODO pass object which emits the signal (e.g region)
2165 // save/load bound objects will be tricky.
2166 // Best idea so far is to save/lookup the PBD::ID
2167 // (either use boost::any indirection or templates for bindable
2168 // object types or a switch statement..)
2170 // _session->route_by_id ()
2171 // _session->track_by_diskstream_id ()
2172 // _session->source_by_id ()
2173 // _session->controllable_by_id ()
2174 // _session->processor_by_id ()
2175 // RegionFactory::region_by_id ()
2177 // TODO loop over objects (if any)
2179 reconnect_object ((void*)0);
2182 template <class T> void
2183 LuaCallback::reconnect_object (T obj)
2185 for (uint32_t i = 0; i < LuaSignal::LAST_SIGNAL; ++i) {
2187 #define ENGINE(n,c,p) else if (i == LuaSignal::n) { connect_ ## p (LuaSignal::n, AudioEngine::instance(), &(AudioEngine::instance()->c)); }
2188 #define SESSION(n,c,p) else if (i == LuaSignal::n) { if (_session) { connect_ ## p (LuaSignal::n, _session, &(_session->c)); } }
2189 #define STATIC(n,c,p) else if (i == LuaSignal::n) { connect_ ## p (LuaSignal::n, obj, c); }
2191 # include "luasignal_syms.h"
2193 PBD::fatal << string_compose (_("programming error: %1: %2"), "Impossible LuaSignal type", i) << endmsg;
2194 abort(); /*NOTREACHED*/
2203 template <typename T, typename S> void
2204 LuaCallback::connect_0 (enum LuaSignal::LuaSignal ls, T ref, S *signal) {
2206 _connections, invalidator (*this),
2207 boost::bind (&LuaCallback::proxy_0<T>, this, ls, ref),
2211 template <typename T, typename C1> void
2212 LuaCallback::connect_1 (enum LuaSignal::LuaSignal ls, T ref, PBD::Signal1<void, C1> *signal) {
2214 _connections, invalidator (*this),
2215 boost::bind (&LuaCallback::proxy_1<T, C1>, this, ls, ref, _1),
2219 template <typename T, typename C1, typename C2> void
2220 LuaCallback::connect_2 (enum LuaSignal::LuaSignal ls, T ref, PBD::Signal2<void, C1, C2> *signal) {
2222 _connections, invalidator (*this),
2223 boost::bind (&LuaCallback::proxy_2<T, C1, C2>, this, ls, ref, _1, _2),
2227 template <typename T, typename C1, typename C2, typename C3> void
2228 LuaCallback::connect_3 (enum LuaSignal::LuaSignal ls, T ref, PBD::Signal3<void, C1, C2, C3> *signal) {
2230 _connections, invalidator (*this),
2231 boost::bind (&LuaCallback::proxy_3<T, C1, C2, C3>, this, ls, ref, _1, _2, _3),
2235 template <typename T> void
2236 LuaCallback::proxy_0 (enum LuaSignal::LuaSignal ls, T ref) {
2239 const luabridge::LuaRef& rv ((*_lua_call)((int)ls, ref));
2240 if (! rv.cast<bool> ()) {
2244 /* destroy LuaRef ^^ first before calling drop_callback() */
2246 drop_callback (); /* EMIT SIGNAL */
2250 template <typename T, typename C1> void
2251 LuaCallback::proxy_1 (enum LuaSignal::LuaSignal ls, T ref, C1 a1) {
2254 const luabridge::LuaRef& rv ((*_lua_call)((int)ls, ref, a1));
2255 if (! rv.cast<bool> ()) {
2260 drop_callback (); /* EMIT SIGNAL */
2264 template <typename T, typename C1, typename C2> void
2265 LuaCallback::proxy_2 (enum LuaSignal::LuaSignal ls, T ref, C1 a1, C2 a2) {
2268 const luabridge::LuaRef& rv ((*_lua_call)((int)ls, ref, a1, a2));
2269 if (! rv.cast<bool> ()) {
2274 drop_callback (); /* EMIT SIGNAL */
2278 template <typename T, typename C1, typename C2, typename C3> void
2279 LuaCallback::proxy_3 (enum LuaSignal::LuaSignal ls, T ref, C1 a1, C2 a2, C3 a3) {
2282 const luabridge::LuaRef& rv ((*_lua_call)((int)ls, ref, a1, a2, a3));
2283 if (! rv.cast<bool> ()) {
2288 drop_callback (); /* EMIT SIGNAL */