summaryrefslogtreecommitdiff
path: root/gtk2_ardour/luawindow.h
blob: 33d7fd151755ae7e237b7a7e46cb206a5000c8f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
    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 "pbd/signals.h"
#include "pbd/stateful.h"

#include "ardour/ardour.h"
#include "ardour/luascripting.h"
#include "ardour/session_handle.h"
#include "ardour/types.h"

#include "gtkmm2ext/visibility_tracker.h"

#include "lua/luastate.h"

#include "ardour_button.h"
#include "ardour_dropdown.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 edit_script (const std::string&, const std::string&);

	void set_session (ARDOUR::Session* s);

	typedef enum {
		Buffer_NOFLAG     = 0x00,
		Buffer_Valid      = 0x01, ///< script is loaded
		Buffer_HasFile    = 0x02,
		Buffer_ReadOnly   = 0x04,
		Buffer_Dirty      = 0x08,
		Buffer_Scratch    = 0x10,
	} BufferFlags;

	class ScriptBuffer {
	public:
		ScriptBuffer (const std::string&);
		ScriptBuffer (ARDOUR::LuaScriptInfoPtr);
		//ScriptBuffer (const ScriptBuffer& other);
		~ScriptBuffer ();

		bool load ();

		std::string script;
		std::string name;
		std::string path;
		BufferFlags flags;
		ARDOUR::LuaScriptInfo::ScriptType type;
	};

  private:
	LuaWindow ();
	static LuaWindow* _instance;

	LuaState *lua;
	bool _visible;

	Gtk::Menu* _menu_scratch;
	Gtk::Menu* _menu_snippet;
	Gtk::Menu* _menu_actions;

	sigc::connection _script_changed_connection;

	Gtk::TextView entry;
	Gtk::TextView outtext;
	Gtk::ScrolledWindow scrollout;

	ArdourButton _btn_run;
	ArdourButton _btn_clear;
	ArdourButton _btn_open;
	ArdourButton _btn_save;
	ArdourButton _btn_delete;
	ArdourButton _btn_revert;

	ArdourDropdown script_select;

	typedef boost::shared_ptr<ScriptBuffer> ScriptBufferPtr;
	typedef std::vector<ScriptBufferPtr> ScriptBufferList;

	ScriptBufferList script_buffers;
	ScriptBufferPtr _current_buffer;

	void session_going_away ();
	void update_title ();
	void reinit_lua ();

	void setup_buffers ();
	void refresh_scriptlist ();
	void rebuild_menu ();
	uint32_t count_scratch_buffers () const;

	void script_changed ();
	void script_selection_changed (ScriptBufferPtr n, bool force = false);
	void update_gui_state ();

	void append_text (std::string s);
	void scroll_to_bottom ();
	void clear_output ();

	void run_script ();

	void new_script ();
	void delete_script ();
	void revert_script ();
	void import_script ();
	void save_script ();
};


#endif