The new class 'ARDOUR::CoreSelection' needs to be exportable (since it gets used...
[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         void edit_script (const std::string&, const std::string&);
57
58         void set_session (ARDOUR::Session* s);
59
60         typedef enum {
61                 Buffer_NOFLAG     = 0x00,
62                 Buffer_Valid      = 0x01, ///< script is loaded
63                 Buffer_HasFile    = 0x02,
64                 Buffer_ReadOnly   = 0x04,
65                 Buffer_Dirty      = 0x08,
66                 Buffer_Scratch    = 0x10,
67         } BufferFlags;
68
69         class ScriptBuffer {
70         public:
71                 ScriptBuffer (const std::string&);
72                 ScriptBuffer (ARDOUR::LuaScriptInfoPtr);
73                 //ScriptBuffer (const ScriptBuffer& other);
74                 ~ScriptBuffer ();
75
76                 bool load ();
77
78                 std::string script;
79                 std::string name;
80                 std::string path;
81                 BufferFlags flags;
82                 ARDOUR::LuaScriptInfo::ScriptType type;
83         };
84
85   private:
86         LuaWindow ();
87         static LuaWindow* _instance;
88
89         LuaState *lua;
90         bool _visible;
91
92         Gtk::Menu* _menu_scratch;
93         Gtk::Menu* _menu_snippet;
94         Gtk::Menu* _menu_actions;
95
96         sigc::connection _script_changed_connection;
97
98         Gtk::TextView entry;
99         Gtk::TextView outtext;
100         Gtk::ScrolledWindow scrollout;
101
102         ArdourButton _btn_run;
103         ArdourButton _btn_clear;
104         ArdourButton _btn_open;
105         ArdourButton _btn_save;
106         ArdourButton _btn_delete;
107         ArdourButton _btn_revert;
108
109         ArdourDropdown script_select;
110
111         typedef boost::shared_ptr<ScriptBuffer> ScriptBufferPtr;
112         typedef std::vector<ScriptBufferPtr> ScriptBufferList;
113
114         ScriptBufferList script_buffers;
115         ScriptBufferPtr _current_buffer;
116
117         void session_going_away ();
118         void update_title ();
119         void reinit_lua ();
120
121         void setup_buffers ();
122         void refresh_scriptlist ();
123         void rebuild_menu ();
124         uint32_t count_scratch_buffers () const;
125
126         void script_changed ();
127         void script_selection_changed (ScriptBufferPtr n, bool force = false);
128         void update_gui_state ();
129
130         void append_text (std::string s);
131         void scroll_to_bottom ();
132         void clear_output ();
133
134         void run_script ();
135
136         void new_script ();
137         void delete_script ();
138         void revert_script ();
139         void import_script ();
140         void save_script ();
141 };
142
143
144 #endif