summaryrefslogtreecommitdiff
path: root/gtk2_ardour/insert_remove_time_dialog.cc
blob: f58bfdbaea0f87de78c7455f62d70f57a6bf8190 (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
/*
    Copyright (C) 2000-2010 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 <gtkmm/table.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/stock.h>
#include <gtkmm/alignment.h>
#include "insert_remove_time_dialog.h"
#include "audio_clock.h"
#include "ardour_ui.h"
#include "main_clock.h"
#include "pbd/i18n.h"

using namespace Gtk;
using namespace Editing;
using namespace ARDOUR;

InsertRemoveTimeDialog::InsertRemoveTimeDialog (PublicEditor& e, bool remove)
	: ArdourDialog (remove ? _("Remove Time") : _("Insert Time"))
	, _editor (e)
	, duration_clock ("insertTimeClock", true, "",
			true,   // editable
			false,  // follows_playhead
			true,   // duration
			false,  // with_info
			true    // accept_on_focus_out
		)
	, position_clock ("insertPosTimeClock", true, "",
			true,   // editable
			false,  // follows_playhead
			false,   // duration
			false,  // with_info
			true    // accept_on_focus_out
		)
{
	set_session (_editor.session ());

	get_vbox()->set_border_width (12);
	get_vbox()->set_spacing (4);

	Table* table = manage (new Table (2, 3));
	table->set_spacings (4);

	Label* time_label = manage (new Label (remove ? _("Remove Time starting at:") : _("Insert Time starting at:")));
	time_label->set_alignment (1, 0.5);
	table->attach (*time_label, 0, 1, 0, 1, FILL | EXPAND);
	position_clock.set_session (_session);
	position_clock.set_mode (ARDOUR_UI::instance()->secondary_clock->mode());
	table->attach (position_clock, 1, 2, 0, 1);

	time_label = manage (new Label (remove ? _("Time to remove:") : _("Time to insert:")));
	time_label->set_alignment (1, 0.5);
	table->attach (*time_label, 0, 1, 1, 2, FILL | EXPAND);
	duration_clock.set_session (_session);
	duration_clock.set_mode (ARDOUR_UI::instance()->secondary_clock->mode());
	table->attach (duration_clock, 1, 2, 1, 2);

	//if a Range is selected, assume the user wants to insert/remove the length of the range
	if ( _editor.get_selection().time.length() != 0 ) {
		position_clock.set ( _editor.get_selection().time.start(), true );
		duration_clock.set ( _editor.get_selection().time.end_frame(), true,  _editor.get_selection().time.start() );
		duration_clock.set_bbt_reference (_editor.get_selection().time.start());
	} else {
		framepos_t const pos = _editor.get_preferred_edit_position (EDIT_IGNORE_MOUSE);
		position_clock.set ( pos, true );
		duration_clock.set_bbt_reference (pos);
		duration_clock.set (0);
	}
	
	if (!remove) {
		Label* intersected_label = manage (new Label (_("Intersected regions should:")));
		intersected_label->set_alignment (1, 0.5);
		table->attach (*intersected_label, 0, 1, 2, 3, FILL | EXPAND);
		_intersected_combo.append_text (_("stay in position"));
		_intersected_combo.append_text (_("move"));
		_intersected_combo.append_text (_("be split"));
		_intersected_combo.set_active (0);
		table->attach (_intersected_combo, 1, 2, 2, 3);
	}

	get_vbox()->pack_start (*table);

	_all_playlists.set_label (_("Apply to all the track's playlists"));
	get_vbox()->pack_start (_all_playlists);

	_move_glued.set_label (_("Move glued-to-musical-time regions (MIDI regions)"));
	_move_glued.set_active();
	get_vbox()->pack_start (_move_glued);
	_move_markers.set_label (_("Move markers"));
	get_vbox()->pack_start (_move_markers);
	_move_markers.signal_toggled().connect (sigc::mem_fun (*this, &InsertRemoveTimeDialog::move_markers_toggled));
	_move_glued_markers.set_label (_("Move glued-to-musical-time markers"));
	_move_glued_markers.set_active();
	Alignment* indent = manage (new Alignment);
	indent->set_padding (0, 0, 12, 0);
	indent->add (_move_glued_markers);
	get_vbox()->pack_start (*indent);
	_move_locked_markers.set_label (_("Move locked markers"));
	indent = manage (new Alignment);
	indent->set_padding (0, 0, 12, 0);
	indent->add (_move_locked_markers);
	get_vbox()->pack_start (*indent);
	tempo_label.set_markup (_("Move tempo and meter changes\n<i>(may cause oddities in the tempo map)</i>"));
	HBox* tempo_box = manage (new HBox);
	tempo_box->set_spacing (6);
	tempo_box->pack_start (_move_tempos, false, false);
	tempo_box->pack_start (tempo_label, false, false);
	get_vbox()->pack_start (*tempo_box);

	add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	Gtk::Button *btn = manage (new Gtk::Button (remove ? _("Remove time") : _("Insert time")));
	btn->signal_clicked().connect (sigc::mem_fun(*this, &InsertRemoveTimeDialog::doit));
	get_action_area()->pack_start (*btn);
	show_all ();

	move_markers_toggled ();
}

InsertTimeOption
InsertRemoveTimeDialog::intersected_region_action ()
{
	/* only setting this to keep GCC quiet */
	InsertTimeOption opt = LeaveIntersected;

	switch (_intersected_combo.get_active_row_number ()) {
	case 0:
		opt = LeaveIntersected;
		break;
	case 1:
		opt = MoveIntersected;
		break;
	case 2:
		opt = SplitIntersected;
		break;
	}

	return opt;
}

bool
InsertRemoveTimeDialog::all_playlists () const
{
	return _all_playlists.get_active ();
}

bool
InsertRemoveTimeDialog::move_glued () const
{
	return _move_glued.get_active ();
}

bool
InsertRemoveTimeDialog::move_tempos () const
{
	return _move_tempos.get_active ();
}

bool
InsertRemoveTimeDialog::move_markers () const
{
	return _move_markers.get_active ();
}

bool
InsertRemoveTimeDialog::move_glued_markers () const
{
	return _move_glued_markers.get_active ();
}

bool
InsertRemoveTimeDialog::move_locked_markers () const
{
	return _move_locked_markers.get_active ();
}

framepos_t
InsertRemoveTimeDialog::position () const
{
	return position_clock.current_time();
}

framepos_t
InsertRemoveTimeDialog::distance () const
{
	return duration_clock.current_duration ( position_clock.current_time() );
}

void
InsertRemoveTimeDialog::doit ()
{
	if (distance () == 0) {
		Gtk::MessageDialog msg (*this, _("Invalid or zero duration entered. Please enter a valid duration"));
		msg.run ();
		return;
	}
	response (RESPONSE_OK);
}

void
InsertRemoveTimeDialog::move_markers_toggled ()
{
	_move_glued_markers.set_sensitive (_move_markers.get_active ());
	_move_locked_markers.set_sensitive (_move_markers.get_active ());
}