summaryrefslogtreecommitdiff
path: root/libs/surfaces/osc/osc_gui.cc
blob: b32203ceccb93cd28792366919345ab6b35a15f1 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
    Copyright (C) 2016 Robin Gareus <robin@gareus.org
    Copyright (C) 2009-2012 Paul Davis

    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.

*/

#include <iostream>
#include <list>
#include <string>

#include <gtkmm/box.h>
#include <gtkmm/table.h>
#include <gtkmm/label.h>
#include <gtkmm/button.h>
#include <gtkmm/spinbutton.h>
#include <gtkmm/comboboxtext.h>

#include "gtkmm2ext/gtk_ui.h"
#include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/utils.h"

#include "osc.h"

#include "pbd/i18n.h"

namespace ArdourSurface {

class OSC_GUI : public Gtk::VBox
{
	public:
		OSC_GUI (OSC&);
		~OSC_GUI ();

private:
	Gtk::ComboBoxText debug_combo;
	Gtk::ComboBoxText portmode_combo;
	Gtk::SpinButton port_entry;
	Gtk::SpinButton bank_entry;
	Gtk::SpinButton striptypes_spin; // dropdown would be nicer
	Gtk::SpinButton feedback_spin; // dropdown would be nicer
	Gtk::ComboBoxText gainmode_combo;
	void debug_changed ();
	void portmode_changed ();
	void gainmode_changed ();
	void clear_device ();
	void port_changed ();
	void bank_changed ();
	void strips_changed ();
	void feedback_changed ();
	OSC& cp;
};


void*
OSC::get_gui () const
{
	if (!gui) {
		const_cast<OSC*>(this)->build_gui ();
	}
	static_cast<Gtk::VBox*>(gui)->show_all();
	return gui;
}

void
OSC::tear_down_gui ()
{
	if (gui) {
		Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
		if (w) {
			w->hide();
			delete w;
		}
	}
	delete (OSC_GUI*) gui;
	gui = 0;
}

void
OSC::build_gui ()
{
	gui = (void*) new OSC_GUI (*this);
}

} // end namespace

///////////////////////////////////////////////////////////////////////////////

using namespace PBD;
using namespace Gtk;
using namespace Gtkmm2ext;
using namespace ArdourSurface;

OSC_GUI::OSC_GUI (OSC& p)
	: cp (p)
{
	int n = 0; // table row
	Table* table = manage (new Table);
	Label* label;
	Button* button;

	// show our url
	label = manage (new Gtk::Label(_("Connection:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	label = manage (new Gtk::Label(cp.get_server_url()));
	table->attach (*label, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	++n;

	// show and set port to auto (default) or manual (one surface only)
	label = manage (new Gtk::Label(_("Port Mode:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	table->attach (portmode_combo, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
	std::vector<std::string> portmode_options;
	portmode_options.push_back (_("Auto"));
	portmode_options.push_back (_("Manual"));

	set_popdown_strings (portmode_combo, portmode_options);
	portmode_combo.set_active ((int)cp.get_portmode());
	++n;

	// port entry box
	label = manage (new Gtk::Label(_("Manual Port:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	table->attach (port_entry, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
	port_entry.set_range(1024, 0xffff);
	port_entry.set_increments (1, 100);
	port_entry.set_text(cp.get_remote_port().c_str());
	if (!cp.get_portmode()) {
		port_entry.set_sensitive (false);
	}
	++n;

	// default banksize setting
	label = manage (new Gtk::Label(_("Bank Size:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	table->attach (bank_entry, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
	bank_entry.set_range (0, 0xffff);
	bank_entry.set_increments (1, 8);
	bank_entry.set_value (cp.get_banksize());

	++n;

	// Default strip types
	label = manage (new Gtk::Label(_("Strip Types:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	table->attach (striptypes_spin, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
	striptypes_spin.set_range (0, 0x3ff);
	striptypes_spin.set_increments (1, 10);
	striptypes_spin.set_value (cp.get_defaultstrip());

/*	std::vector<std::string> strip_options;
	strip_options.push_back (_("Audio Tracks"));
	strip_options.push_back (_("Midi Tracks"));
	strip_options.push_back (_("Audio Buses"));
	strip_options.push_back (_("Midi Buses"));
	strip_options.push_back (_("Control Masters"));
	strip_options.push_back (_("Master"));
	strip_options.push_back (_("Monitor"));
	strip_options.push_back (_("Selected"));
	strip_options.push_back (_("Hidden"));*/

	++n;

	// default feedback settings
	label = manage (new Gtk::Label(_("Feedback:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	table->attach (feedback_spin, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
	feedback_spin.set_range (0, 0x3fff);
	feedback_spin.set_increments (1, 10);
	feedback_spin.set_value (cp.get_defaultfeedback());
	/*std::vector<std::string> feedback_options;
	feedback_options.push_back (_("Strip Buttons"));
	feedback_options.push_back (_("Strip Controls"));
	feedback_options.push_back (_("Use SSID as Path Extension"));
	feedback_options.push_back (_("Send heart beat"));
	feedback_options.push_back (_("Master and Transport Feedback"));
	feedback_options.push_back (_("Send Bar and Beat"));
	feedback_options.push_back (_("Send SMPTE Time"));
	feedback_options.push_back (_("Send metering"));
	feedback_options.push_back (_("Send  LED strip metering"));
	feedback_options.push_back (_("Signal Present"));
	feedback_options.push_back (_("Strip Controls"));
	feedback_options.push_back (_("Playhead Position as Samples"));
	feedback_options.push_back (_("Playhead Position as Minutes Seconds"));
	feedback_options.push_back (_("Playhead Position as per GUI Clock"));
	feedback_options.push_back (_("Extra Select Channel Controls"));*/

	++n;

	// Gain Mode
	label = manage (new Gtk::Label(_("Gain Mode:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	table->attach (gainmode_combo, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
	std::vector<std::string> gainmode_options;
	gainmode_options.push_back (_("dB"));
	gainmode_options.push_back (_("Position"));

	set_popdown_strings (gainmode_combo, gainmode_options);
	gainmode_combo.set_active ((int)cp.get_gainmode());
	++n;

	// debug setting
	label = manage (new Gtk::Label(_("Debug:")));
	table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
	table->attach (debug_combo, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);

	std::vector<std::string> debug_options;
	debug_options.push_back (_("Off"));
	debug_options.push_back (_("Log invalid messages"));
	debug_options.push_back (_("Log all messages"));

	set_popdown_strings (debug_combo, debug_options);
	debug_combo.set_active ((int)cp.get_debug_mode());
	++n;

	// refresh button
	button = manage (new Gtk::Button(_("Clear OSC Devices")));
	table->attach (*button, 0, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));

	table->show_all ();
	pack_start (*table, false, false);

	debug_combo.signal_changed().connect (sigc::mem_fun (*this, &OSC_GUI::debug_changed));
	portmode_combo.signal_changed().connect (sigc::mem_fun (*this, &OSC_GUI::portmode_changed));
	gainmode_combo.signal_changed().connect (sigc::mem_fun (*this, &OSC_GUI::gainmode_changed));
	button->signal_clicked().connect (sigc::mem_fun (*this, &OSC_GUI::clear_device));
	port_entry.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::port_changed));
	bank_entry.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::bank_changed));
	striptypes_spin.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::strips_changed));
	feedback_spin.signal_activate().connect (sigc::mem_fun (*this, &OSC_GUI::feedback_changed));
}

OSC_GUI::~OSC_GUI ()
{
}

void
OSC_GUI::debug_changed ()
{
	std::string str = debug_combo.get_active_text ();
	if (str == _("Off")) {
		cp.set_debug_mode (OSC::Off);
	}
	else if (str == _("Log invalid messages")) {
		cp.set_debug_mode (OSC::Unhandled);
	}
	else if (str == _("Log all messages")) {
		cp.set_debug_mode (OSC::All);
	}
	else {
		std::cerr << "Invalid OSC Debug Mode\n";
		assert (0);
	}
}

void
OSC_GUI::portmode_changed ()
{
	std::string str = portmode_combo.get_active_text ();
	if (str == _("Auto")) {
		cp.set_portmode (0);
		port_entry.set_sensitive (false);
	}
	else if (str == _("Manual")) {
		cp.set_portmode (1);
		port_entry.set_sensitive (true);
	}
	else {
		std::cerr << "Invalid OSC Port Mode\n";
		assert (0);
	}
}

void
OSC_GUI::port_changed ()
{
	std::string str = port_entry.get_text ();
	cp.set_remote_port (str);
}

void
OSC_GUI::bank_changed ()
{
	uint32_t bsize = bank_entry.get_value ();
	cp.set_banksize (bsize);

}

void
OSC_GUI::strips_changed ()
{
	uint32_t st = striptypes_spin.get_value ();
	cp.set_defaultstrip (st);
}

void
OSC_GUI::feedback_changed ()
{
	uint32_t fb = feedback_spin.get_value ();
	cp.set_defaultfeedback (fb);
}

void
OSC_GUI::gainmode_changed ()
{
	std::string str = gainmode_combo.get_active_text ();
	if (str == _("dB")) {
		cp.set_gainmode (0);
	}
	else if (str == _("Position")) {
		cp.set_gainmode (1);
	}
	else {
		std::cerr << "Invalid OSC Gain Mode\n";
		assert (0);
	}
}

void
OSC_GUI::clear_device ()
{
	cp.clear_devices();
}