summaryrefslogtreecommitdiff
path: root/gtk2_ardour/visual_time_axis.cc
blob: b4b613042b99cbcd96152a506bc4f9f0c1015bdc (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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/*
    Copyright (C) 2003 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 <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>

#include "pbd/error.h"
#include "pbd/stl_delete.h"
#include "pbd/whitespace.h"

#include <gtkmm2ext/utils.h>
#include <gtkmm2ext/selector.h>
#include <gtkmm2ext/gtk_ui.h>
#include <gtkmm2ext/stop_signal.h>
#include <gtkmm2ext/choice.h>

#include "ardour/session.h"
#include "ardour/utils.h"
#include "ardour/processor.h"
#include "ardour/location.h"

#include "ardour_ui.h"
#include "public_editor.h"
#include "imageframe_time_axis.h"
#include "imageframe_time_axis_view.h"
#include "marker_time_axis_view.h"
#include "imageframe_view.h"
#include "marker_time_axis.h"
#include "marker_view.h"
#include "utils.h"
#include "prompter.h"
#include "rgb_macros.h"
#include "canvas_impl.h"

#include "i18n.h"

using namespace ARDOUR;
using namespace PBD;
using namespace Gtk;

/**
 * Abstract Constructor for base visual time axis classes
 *
 * @param name the name/Id of thie TimeAxis
 * @param ed the Ardour PublicEditor
 * @param sess the current session
 * @param canvas the parent canvas object
 */
VisualTimeAxis::VisualTimeAxis(const string & name, PublicEditor& ed, ARDOUR::Session* sess, Canvas& canvas)
	: AxisView(sess),
	  TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
	  visual_button (_("v")),
	  size_button (_("h"))
{
	time_axis_name = name ;
	_color = unique_random_color() ;

	name_entry.signal_activate().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_changed)) ;
	name_entry.signal_button_press_event().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_button_press_handler)) ;
	name_entry.signal_button_release_event().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_button_release_handler)) ;
	name_entry.signal_key_release_event().connect(sigc::mem_fun(*this, &VisualTimeAxis::name_entry_key_release_handler)) ;

	size_button.set_name("TrackSizeButton") ;
	visual_button.set_name("TrackVisualButton") ;
	hide_button.set_name("TrackRemoveButton") ;
	hide_button.add(*(Gtk::manage(new Gtk::Image(get_xpm("small_x.xpm")))));
	size_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VisualTimeAxis::size_click)) ;
	visual_button.signal_clicked().connect (sigc::mem_fun (*this, &VisualTimeAxis::visual_click)) ;
	hide_button.signal_clicked().connect (sigc::mem_fun (*this, &VisualTimeAxis::hide_click)) ;
	ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height")) ;
	ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options")) ;
	ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track")) ;

	controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
	controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
	controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);

	/* remove focus from the buttons */
	size_button.unset_flags(Gtk::CAN_FOCUS) ;
	hide_button.unset_flags(Gtk::CAN_FOCUS) ;
	visual_button.unset_flags(Gtk::CAN_FOCUS) ;

	set_height (hNormal) ;
}

/**
 * VisualTimeAxis Destructor
 *
 */
VisualTimeAxis::~VisualTimeAxis()
{
}


//---------------------------------------------------------------------------------------//
// Name/Id Accessors/Mutators

void
VisualTimeAxis::set_time_axis_name(const string & name, void* src)
{
	std::string old_name = time_axis_name ;

	if(name != time_axis_name)
	{
		time_axis_name = name ;
		label_view() ;
		editor.route_name_changed(this) ;

		 NameChanged(time_axis_name, old_name, src) ; /* EMIT_SIGNAL */
	}
}

std::string
VisualTimeAxis::name() const
{
	return(time_axis_name) ;
}


//---------------------------------------------------------------------------------------//
// ui methods & data

/**
 * Sets the height of this TrackView to one of the defined TrackHeghts
 *
 * @param h
 */
void
VisualTimeAxis::set_height(uint32_t h)
{
	TimeAxisView::set_height(h);

	if (h >= hNormal) {
		hide_name_label ();
		show_name_entry ();
		other_button_hbox.show_all() ;
	} else if (h >= hSmaller) {
		hide_name_label ();
		show_name_entry ();
		other_button_hbox.hide_all() ;
	} else if (h >= hSmall) {
		hide_name_entry ();
		show_name_label ();
		other_button_hbox.hide_all() ;
	}
}

/**
 * Handle the visuals button click
 *
 */
void
VisualTimeAxis::visual_click()
{
	popup_display_menu(0);
}


/**
 * Handle the hide buttons click
 *
 */
void
VisualTimeAxis::hide_click()
{
	// LAME fix for hide_button display refresh
	hide_button.set_sensitive(false);

	editor.hide_track_in_display (*this);

	hide_button.set_sensitive(true);
}


/**
 * Allows the selection of a new color for this TimeAxis
 *
 */
void
VisualTimeAxis::select_track_color ()
{
	if(choose_time_axis_color())
	{
		//Does nothing at this abstract point
	}
}

/**
 * Provides a color chooser for the selection of a new time axis color.
 *
 */
bool
VisualTimeAxis::choose_time_axis_color()
{
	bool picked ;
	Gdk::Color color ;
	gdouble current[4] ;
	Gdk::Color current_color ;

	current[0] = _color.get_red() / 65535.0 ;
	current[1] = _color.get_green() / 65535.0 ;
	current[2] = _color.get_blue() / 65535.0 ;
	current[3] = 1.0 ;

	current_color.set_rgb_p (current[0],current[1],current[2]);
	color = Gtkmm2ext::UI::instance()->get_color(_("ardour: color selection"),picked, &current_color) ;

	if (picked)
	{
		set_time_axis_color(color) ;
	}
	return(picked) ;
}

/**
 * Sets the color of this TimeAxis to the specified color c
 *
 * @param c the new TimeAxis color
 */
void
VisualTimeAxis::set_time_axis_color(Gdk::Color c)
{
	_color = c ;
}

void
VisualTimeAxis::set_selected_regionviews (RegionSelection& regions)
{
	// Not handled by purely visual TimeAxis
}

//---------------------------------------------------------------------------------------//
// Handle time axis removal

/**
 * Handles the Removal of this VisualTimeAxis
 *
 * @param src the identity of the object that initiated the change
 */
void
VisualTimeAxis::remove_this_time_axis(void* src)
{
	vector<string> choices;

	std::string prompt  = string_compose (_("Do you really want to remove track \"%1\" ?\n(cannot be undone)"), time_axis_name);

	choices.push_back (_("No, do nothing."));
	choices.push_back (_("Yes, remove it."));

	Gtkmm2ext::Choice prompter (prompt, choices);

	if (prompter.run () == 1) {
		/*
		  defer to idle loop, otherwise we'll delete this object
		  while we're still inside this function ...
		*/
		Glib::signal_idle().connect(sigc::bind(sigc::ptr_fun(&VisualTimeAxis::idle_remove_this_time_axis), this, src));
	}
}

/**
 * Callback used to remove this time axis during the gtk idle loop
 * This is used to avoid deleting the obejct while inside the remove_this_time_axis
 * method
 *
 * @param ta the VisualTimeAxis to remove
 * @param src the identity of the object that initiated the change
 */
gint
VisualTimeAxis::idle_remove_this_time_axis(VisualTimeAxis* ta, void* src)
{
	 ta->VisualTimeAxisRemoved(ta->name(), src) ; /* EMIT_SIGNAL */
	delete ta ;
	ta = 0 ;
	return(false) ;
}




//---------------------------------------------------------------------------------------//
// Handle TimeAxis rename

/**
 * Construct a new prompt to receive a new name for this TimeAxis
 *
 * @see finish_time_axis_rename()
 */
void
VisualTimeAxis::start_time_axis_rename()
{
	ArdourPrompter name_prompter;

	name_prompter.set_prompt (_("new name: ")) ;
	name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
	name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
	name_prompter.show_all() ;

	switch (name_prompter.run ()) {
	case Gtk::RESPONSE_ACCEPT:
	  string result;
	  name_prompter.get_result (result);
	  if (result.length()) {
		  if (editor.get_named_time_axis(result) != 0) {
		    ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
		    return ;
		  }

		  set_time_axis_name(result, this) ;
	  }
	}
	label_view() ;
}

/**
 * Handles the new name for this TimeAxis from the name prompt
 *
 * @see start_time_axis_rename()
 */

void
VisualTimeAxis::label_view()
{
	name_label.set_text(time_axis_name) ;
	name_entry.set_text(time_axis_name) ;
	ARDOUR_UI::instance()->tooltips().set_tip(name_entry, time_axis_name) ;
}


//---------------------------------------------------------------------------------------//
// Handle name entry signals

void
VisualTimeAxis::name_entry_changed()
{
	string x = name_entry.get_text ();

	if (x == time_axis_name) {
		return;
	}

	strip_whitespace_edges(x);

	if (x.length() == 0) {
		name_entry.set_text (time_axis_name);
		return;
	}

	if (!editor.get_named_time_axis(x)) {
		set_time_axis_name(x, this);
	} else {
		ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
		name_entry.set_text(time_axis_name);
	}
}

gint
VisualTimeAxis::name_entry_button_press_handler(GdkEventButton *ev)
{
	if (ev->button == 3) {
		return stop_signal (name_entry, "button_press_event");
	}
	return FALSE;
}

gint
VisualTimeAxis::name_entry_button_release_handler(GdkEventButton *ev)
{
	return FALSE;
}

gint
VisualTimeAxis::name_entry_key_release_handler(GdkEventKey* ev)
{
	switch (ev->keyval) {
	case GDK_Tab:
	case GDK_Up:
	case GDK_Down:
		name_entry_changed ();
		return TRUE;

	default:
		return FALSE;
	}
}


//---------------------------------------------------------------------------------------//
// Super class methods not handled by VisualTimeAxis

void
VisualTimeAxis::show_timestretch (nframes_t start, nframes_t end)
{
  // Not handled by purely visual TimeAxis
}

void
VisualTimeAxis::hide_timestretch()
{
  // Not handled by purely visual TimeAxis
}