class Splash;
class TimeInfoBox;
class Meterbridge;
+class LuaWindow;
+class LuaScriptManager;
class MidiTracer;
class NSM_Client;
class LevelMeterHBox;
void toggle_monitor_section_visibility ();
void toggle_keep_tearoffs();
+ void lua_script_manager();
+
static PublicEditor* _instance;
/** Emitted frequently with the audible frame, false, and the edit point as
void start_duplicate_routes ();
+ void add_lua_script ();
+ void remove_lua_script ();
+
void add_video (Gtk::Window* float_window);
void remove_video ();
void start_video_server_menu (Gtk::Window* float_window);
void tabbable_state_change (Gtkmm2ext::Tabbable&);
void toggle_meterbridge ();
+ void toggle_luawindow ();
int setup_windows ();
void setup_transport ();
int create_mixer ();
int create_editor ();
+ int create_meterbridge ();
+ int create_luawindow ();
Meterbridge *meterbridge;
- int create_meterbridge ();
+ LuaWindow *luawindow;
/* Dialogs that can be created via new<T> */
WM::Proxy<RouteParams_UI> route_params;
WM::Proxy<EngineControl> audio_midi_setup;
WM::Proxy<ExportVideoDialog> export_video_dialog;
+ WM::Proxy<LuaScriptManager> lua_script_window;
/* Windows/Dialogs that require a creator method */
--- /dev/null
+/*
+ Copyright (C) 2016 Robin Gareus <robin@gareus.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifdef WAF_BUILD
+#include "gtk2ardour-config.h"
+#endif
+
+#include <gtkmm2ext/gtk_ui.h>
+#include <gtkmm2ext/utils.h>
+#include <gtkmm2ext/window_title.h>
+
+#include "ardour_ui.h"
+#include "gui_thread.h"
+#include "luainstance.h"
+#include "luawindow.h"
+#include "public_editor.h"
+#include "utils.h"
+
+#include "ardour/luabindings.h"
+#include "LuaBridge/LuaBridge.h"
+
+#include "i18n.h"
+
+using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
+using namespace PBD;
+using namespace Gtk;
+using namespace Glib;
+using namespace Gtkmm2ext;
+using namespace std;
+
+
+LuaWindow* LuaWindow::_instance = 0;
+
+LuaWindow*
+LuaWindow::instance ()
+{
+ if (!_instance) {
+ _instance = new LuaWindow;
+ }
+
+ return _instance;
+}
+
+LuaWindow::LuaWindow ()
+ : Window (Gtk::WINDOW_TOPLEVEL)
+ , VisibilityTracker (*((Gtk::Window*) this))
+ , _visible (false)
+{
+ set_name ("Lua");
+
+ update_title ();
+ set_wmclass (X_("ardour_mixer"), PROGRAM_NAME);
+
+ set_border_width (0);
+
+ outtext.set_editable (false);
+ outtext.set_wrap_mode (Gtk::WRAP_WORD);
+
+ signal_delete_event().connect (sigc::mem_fun (*this, &LuaWindow::hide_window));
+ signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
+
+ scrollwin.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
+ scrollwin.add (outtext);
+
+ Gtk::Button *btn_clr = manage (new Button ("Clear"));
+ btn_clr->signal_clicked().connect (sigc::mem_fun(*this, &LuaWindow::clear_output));
+
+ Gtk::HBox *hbox = manage (new HBox());
+
+ hbox->pack_start (entry, true, true, 2);
+ hbox->pack_start (*btn_clr, false, false, 0);
+
+ Gtk::VBox *vbox = manage (new VBox());
+ vbox->pack_start (scrollwin, true, true, 0);
+ vbox->pack_start (*hbox, false, false, 2);
+
+ entry.signal_activate().connect (sigc::mem_fun (*this, &LuaWindow::entry_activated));
+
+ lua.Print.connect (sigc::mem_fun (*this, &LuaWindow::append_text));
+
+ vbox->show_all ();
+ add (*vbox);
+ set_size_request (640, 480); // XXX
+
+ LuaInstance::register_classes (lua.getState());
+ // TODO register some callback functions.
+
+ lua_State* L = lua.getState();
+ luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
+ lua_setglobal (L, "Editor");
+ // TODO
+ // - allow to load files
+ // - allow to run files directly
+ // - history buffer
+ // - multi-line input ??
+}
+
+LuaWindow::~LuaWindow ()
+{
+}
+
+void
+LuaWindow::show_window ()
+{
+ present();
+ _visible = true;
+}
+
+bool
+LuaWindow::hide_window (GdkEventAny *ev)
+{
+ if (!_visible) return 0;
+ _visible = false;
+ return just_hide_it (ev, static_cast<Gtk::Window *>(this));
+}
+
+void LuaWindow::set_session (Session* s)
+{
+ SessionHandlePtr::set_session (s);
+ if (!_session) {
+ return;
+ }
+
+ update_title ();
+ _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&LuaWindow::update_title, this), gui_context());
+
+ // expose "Session" point directly
+ lua_State* L = lua.getState();
+ LuaBindings::set_session (L, _session);
+}
+
+void
+LuaWindow::session_going_away ()
+{
+ ENSURE_GUI_THREAD (*this, &LuaWindow::session_going_away);
+ lua.do_command ("collectgarbage();");
+ //TODO: re-init lua-engine (drop all references) ??
+
+ SessionHandlePtr::session_going_away ();
+ _session = 0;
+ update_title ();
+
+ lua_State* L = lua.getState();
+ LuaBindings::set_session (L, _session);
+}
+
+void
+LuaWindow::update_title ()
+{
+ if (_session) {
+ string n;
+
+ if (_session->snap_name() != _session->name()) {
+ n = _session->snap_name ();
+ } else {
+ n = _session->name ();
+ }
+
+ if (_session->dirty ()) {
+ n = "*" + n;
+ }
+
+ WindowTitle title (n);
+ title += S_("Window|Lua");
+ title += Glib::get_application_name ();
+ set_title (title.get_string());
+
+ } else {
+ WindowTitle title (S_("Window|Lua"));
+ title += Glib::get_application_name ();
+ set_title (title.get_string());
+ }
+}
+
+void
+LuaWindow::scroll_to_bottom ()
+{
+ Gtk::Adjustment *adj;
+ adj = scrollwin.get_vadjustment();
+ adj->set_value (MAX(0,(adj->get_upper() - adj->get_page_size())));
+}
+
+void
+LuaWindow::entry_activated ()
+{
+ std::string cmd = entry.get_text();
+ append_text ("> " + cmd);
+
+ if (0 == lua.do_command (cmd)) {
+ entry.set_text("");
+ }
+}
+
+void
+LuaWindow::append_text (std::string s)
+{
+ Glib::RefPtr<Gtk::TextBuffer> tb (outtext.get_buffer());
+ tb->insert (tb->end(), s + "\n");
+ scroll_to_bottom ();
+}
+
+void
+LuaWindow::clear_output ()
+{
+ Glib::RefPtr<Gtk::TextBuffer> tb (outtext.get_buffer());
+ tb->set_text ("");
+}
--- /dev/null
+/*
+ Copyright (C) 2016 Robin Gareus <robin@gareus.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+#ifndef __ardour_luawindow_h__
+#define __ardour_luawindow_h__
+
+#include <glibmm/thread.h>
+
+#include <gtkmm/box.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/label.h>
+#include <gtkmm/window.h>
+
+#include "ardour/ardour.h"
+#include "ardour/types.h"
+#include "ardour/session_handle.h"
+
+#include "pbd/stateful.h"
+#include "pbd/signals.h"
+
+#include "gtkmm2ext/visibility_tracker.h"
+
+#include "lua/luastate.h"
+
+class LuaWindow :
+ public Gtk::Window,
+ public PBD::ScopedConnectionList,
+ public ARDOUR::SessionHandlePtr,
+ public Gtkmm2ext::VisibilityTracker
+{
+ public:
+ static LuaWindow* instance();
+ ~LuaWindow();
+
+ void show_window ();
+ bool hide_window (GdkEventAny *ev);
+
+ void set_session (ARDOUR::Session* s);
+
+ private:
+ LuaWindow ();
+ static LuaWindow* _instance;
+
+ bool _visible;
+ Gtk::VBox global_vpacker;
+
+ void session_going_away ();
+ void update_title ();
+
+ Gtk::Entry entry;
+ Gtk::TextView outtext;
+ Gtk::ScrolledWindow scrollwin;
+
+ void append_text (std::string s);
+ void scroll_to_bottom ();
+ void clear_output ();
+
+ void entry_activated ();
+
+ LuaState lua;
+};
+
+#endif