remove long-lived bug that tried to make a non-existent action insensitive
[ardour.git] / gtk2_ardour / luawindow.h
1 /*
2     Copyright (C) 2016 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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19 #ifndef __ardour_luawindow_h__
20 #define __ardour_luawindow_h__
21
22 #include <glibmm/thread.h>
23
24 #include <gtkmm/box.h>
25 #include <gtkmm/scrolledwindow.h>
26 #include <gtkmm/label.h>
27 #include <gtkmm/textview.h>
28 #include <gtkmm/window.h>
29
30 #include "pbd/signals.h"
31 #include "pbd/stateful.h"
32
33 #include "ardour/ardour.h"
34 #include "ardour/luascripting.h"
35 #include "ardour/session_handle.h"
36 #include "ardour/types.h"
37
38 #include "gtkmm2ext/visibility_tracker.h"
39
40 #include "lua/luastate.h"
41
42 #include "widgets/ardour_button.h"
43 #include "widgets/ardour_dropdown.h"
44
45 class LuaWindow :
46         public Gtk::Window,
47         public PBD::ScopedConnectionList,
48         public ARDOUR::SessionHandlePtr,
49         public Gtkmm2ext::VisibilityTracker
50 {
51 public:
52         static LuaWindow* instance();
53         ~LuaWindow();
54
55         void show_window ();
56         bool hide_window (GdkEventAny *ev);
57         void edit_script (const std::string&, const std::string&);
58
59         void set_session (ARDOUR::Session* s);
60
61         typedef enum {
62                 Buffer_NOFLAG     = 0x00,
63                 Buffer_Valid      = 0x01, ///< script is loaded
64                 Buffer_HasFile    = 0x02,
65                 Buffer_ReadOnly   = 0x04,
66                 Buffer_Dirty      = 0x08,
67                 Buffer_Scratch    = 0x10,
68         } BufferFlags;
69
70         class ScriptBuffer
71         {
72         public:
73                 ScriptBuffer (const std::string&);
74                 ScriptBuffer (ARDOUR::LuaScriptInfoPtr);
75                 //ScriptBuffer (const ScriptBuffer& other);
76                 ~ScriptBuffer ();
77
78                 bool load ();
79
80                 std::string script;
81                 std::string name;
82                 std::string path;
83                 BufferFlags flags;
84                 ARDOUR::LuaScriptInfo::ScriptType type;
85         };
86
87 private:
88         LuaWindow ();
89         static LuaWindow* _instance;
90
91         LuaState *lua;
92         bool _visible;
93
94         Gtk::Menu* _menu_scratch;
95         Gtk::Menu* _menu_snippet;
96         Gtk::Menu* _menu_actions;
97
98         sigc::connection _script_changed_connection;
99
100         Gtk::TextView entry;
101         Gtk::TextView outtext;
102         Gtk::ScrolledWindow scrollout;
103
104         ArdourWidgets::ArdourButton _btn_run;
105         ArdourWidgets::ArdourButton _btn_clear;
106         ArdourWidgets::ArdourButton _btn_open;
107         ArdourWidgets::ArdourButton _btn_save;
108         ArdourWidgets::ArdourButton _btn_delete;
109         ArdourWidgets::ArdourButton _btn_revert;
110
111         ArdourWidgets::ArdourDropdown script_select;
112
113         typedef boost::shared_ptr<ScriptBuffer> ScriptBufferPtr;
114         typedef std::vector<ScriptBufferPtr> ScriptBufferList;
115
116         ScriptBufferList script_buffers;
117         ScriptBufferPtr _current_buffer;
118
119         void session_going_away ();
120         void update_title ();
121         void reinit_lua ();
122
123         void setup_buffers ();
124         void refresh_scriptlist ();
125         void rebuild_menu ();
126         uint32_t count_scratch_buffers () const;
127
128         void script_changed ();
129         void script_selection_changed (ScriptBufferPtr n, bool force = false);
130         void update_gui_state ();
131
132         void append_text (std::string s);
133         void scroll_to_bottom ();
134         void clear_output ();
135
136         void run_script ();
137
138         void new_script ();
139         void delete_script ();
140         void revert_script ();
141         void import_script ();
142         void save_script ();
143 };
144
145
146 #endif