1 /*
2  * Copyright (C) 2016-2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _gtk2_ardour_lua_script_manager_h_
20 #define _gtk2_ardour_lua_script_manager_h_
21 
22 #include <gtkmm/button.h>
23 #include <gtkmm/notebook.h>
24 #include <gtkmm/liststore.h>
25 #include <gtkmm/treemodel.h>
26 #include <gtkmm/treeview.h>
27 
28 #include "ardour/luascripting.h"
29 
30 #include "ardour_window.h"
31 #include "luainstance.h"
32 
33 class LuaScriptManager : public ArdourWindow
34 {
35 public:
36 	LuaScriptManager ();
37 	void set_session (ARDOUR::Session *);
38 
39 protected:
40 	void session_going_away();
41 
42 private:
43 	Gtk::Notebook pages;
44 
45 	/* action scripts */
46 	void setup_actions ();
47 	void action_selection_changed ();
48 	void set_action_script_name (int, const std::string&);
49 
50 	void set_action_btn_clicked ();
51 	void del_action_btn_clicked ();
52 	void edit_action_btn_clicked ();
53 	void call_action_btn_clicked ();
54 
55 	class LuaActionScriptModelColumns : public Gtk::TreeModelColumnRecord
56 	{
57 		public:
LuaActionScriptModelColumns()58 			LuaActionScriptModelColumns ()
59 			{
60 				add (id);
61 				add (action);
62 				add (name);
63 				add (enabled);
64 			}
65 
66 			Gtk::TreeModelColumn<int> id;
67 			Gtk::TreeModelColumn<std::string> action;
68 			Gtk::TreeModelColumn<std::string> name;
69 			Gtk::TreeModelColumn<bool> enabled;
70 	};
71 
72 	Gtk::Button _a_set_button;
73 	Gtk::Button _a_del_button;
74 	Gtk::Button _a_edit_button;
75 	Gtk::Button _a_call_button;
76 
77 	Glib::RefPtr<Gtk::ListStore> _a_store;
78 	LuaActionScriptModelColumns _a_model;
79 	Gtk::TreeView _a_view;
80 
81 	/* action callback hooks */
82 	void setup_callbacks ();
83 	void callback_selection_changed ();
84 	void set_callback_script_name (PBD::ID, const std::string&, const ActionHook& ah);
85 
86 	void add_callback_btn_clicked ();
87 	void del_callback_btn_clicked ();
88 
89 	class LuaCallbackScriptModelColumns : public Gtk::TreeModelColumnRecord
90 	{
91 		public:
LuaCallbackScriptModelColumns()92 			LuaCallbackScriptModelColumns ()
93 			{
94 				add (id);
95 				add (name);
96 				add (signals);
97 			}
98 
99 			Gtk::TreeModelColumn<PBD::ID> id;
100 			Gtk::TreeModelColumn<std::string> name;
101 			Gtk::TreeModelColumn<std::string> signals;
102 	};
103 
104 	Glib::RefPtr<Gtk::ListStore> _c_store;
105 	LuaCallbackScriptModelColumns _c_model;
106 	Gtk::TreeView _c_view;
107 
108 	Gtk::Button _c_add_button;
109 	Gtk::Button _c_del_button;
110 
111 	/* Session scripts */
112 	void setup_session_scripts ();
113 	void session_script_selection_changed ();
114 
115 	void add_sess_btn_clicked ();
116 	void del_sess_btn_clicked ();
117 
118 	class LuaSessionScriptModelColumns : public Gtk::TreeModelColumnRecord
119 	{
120 		public:
LuaSessionScriptModelColumns()121 			LuaSessionScriptModelColumns ()
122 			{
123 				add (name);
124 			}
125 
126 			Gtk::TreeModelColumn<std::string> name;
127 	};
128 
129 	Glib::RefPtr<Gtk::ListStore> _s_store;
130 	LuaCallbackScriptModelColumns _s_model;
131 	Gtk::TreeView _s_view;
132 
133 	Gtk::Button _s_add_button;
134 	Gtk::Button _s_del_button;
135 
136 	PBD::ScopedConnection _session_script_connection;
137 };
138 
139 #endif /* _gtk2_ardour_lua_script_manager_h_ */
140