Use a C++ bool constant
[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/window.h>
28
29 #include "pbd/signals.h"
30 #include "pbd/stateful.h"
31
32 #include "ardour/ardour.h"
33 #include "ardour/luascripting.h"
34 #include "ardour/session_handle.h"
35 #include "ardour/types.h"
36
37 #include "gtkmm2ext/visibility_tracker.h"
38
39 #include "lua/luastate.h"
40
41 #include "ardour_button.h"
42 #include "ardour_dropdown.h"
43
44 class LuaWindow :
45         public Gtk::Window,
46         public PBD::ScopedConnectionList,
47         public ARDOUR::SessionHandlePtr,
48         public Gtkmm2ext::VisibilityTracker
49 {
50   public:
51         static LuaWindow* instance();
52         ~LuaWindow();
53
54         void show_window ();
55         bool hide_window (GdkEventAny *ev);
56
57         void set_session (ARDOUR::Session* s);
58
59         typedef enum {
60                 Buffer_NOFLAG     = 0x00,
61                 Buffer_Valid      = 0x01, ///< script is loaded
62                 Buffer_HasFile    = 0x02,
63                 Buffer_ReadOnly   = 0x04,
64                 Buffer_Dirty      = 0x08,
65                 Buffer_Scratch    = 0x10,
66         } BufferFlags;
67
68         class ScriptBuffer {
69         public:
70                 ScriptBuffer (const std::string&);
71                 ScriptBuffer (ARDOUR::LuaScriptInfoPtr);
72                 //ScriptBuffer (const ScriptBuffer& other);
73                 ~ScriptBuffer ();
74
75                 bool load ();
76
77                 std::string script;
78                 std::string name;
79                 std::string path;
80                 BufferFlags flags;
81                 ARDOUR::LuaScriptInfo::ScriptType type;
82         };
83
84   private:
85         LuaWindow ();
86         static LuaWindow* _instance;
87
88         LuaState *lua;
89         bool _visible;
90
91         Gtk::Menu* _menu_scratch;
92         Gtk::Menu* _menu_snippet;
93         Gtk::Menu* _menu_actions;
94
95         sigc::connection _script_changed_connection;
96
97         Gtk::TextView entry;
98         Gtk::TextView outtext;
99         Gtk::ScrolledWindow scrollout;
100
101         ArdourButton _btn_run;
102         ArdourButton _btn_clear;
103         ArdourButton _btn_open;
104         ArdourButton _btn_save;
105         ArdourButton _btn_delete;
106         ArdourButton _btn_revert;
107
108         ArdourDropdown script_select;
109
110         typedef boost::shared_ptr<ScriptBuffer> ScriptBufferPtr;
111         typedef std::vector<ScriptBufferPtr> ScriptBufferList;
112
113         ScriptBufferList script_buffers;
114         ScriptBufferPtr _current_buffer;
115
116         void session_going_away ();
117         void update_title ();
118         void reinit_lua ();
119
120         void setup_buffers ();
121         void refresh_scriptlist ();
122         void rebuild_menu ();
123         uint32_t count_scratch_buffers () const;
124
125         void script_changed ();
126         void script_selection_changed (ScriptBufferPtr n, bool force = false);
127         void update_gui_state ();
128
129         void append_text (std::string s);
130         void scroll_to_bottom ();
131         void clear_output ();
132
133         void run_script ();
134
135         void new_script ();
136         void delete_script ();
137         void revert_script ();
138         void import_script ();
139         void save_script ();
140 };
141
142
143 #endif