Move insert time dialog to its own file.
[ardour.git] / gtk2_ardour / insert_time_dialog.cc
1 /*
2     Copyright (C) 2000-2010 Paul Davis
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
20 #include <gtkmm/table.h>
21 #include <gtkmm/comboboxtext.h>
22 #include <gtkmm/stock.h>
23 #include "insert_time_dialog.h"
24 #include "audio_clock.h"
25 #include "i18n.h"
26
27 using namespace Gtk;
28 using namespace Editing;
29
30 InsertTimeDialog::InsertTimeDialog (PublicEditor& e)
31         : ArdourDialog (_("Insert Time"))
32         , _editor (e)
33         , _clock ("insertTimeClock", true, X_("InsertTimeClock"), true, false, true, true)
34 {
35         set_session (_editor.session ());
36         
37         nframes64_t const pos = _editor.get_preferred_edit_position ();
38
39         get_vbox()->set_border_width (12);
40         get_vbox()->set_spacing (4);
41
42         Table* table = manage (new Table (2, 2));
43         table->set_spacings (4);
44
45         Label* time_label = manage (new Label (_("Time to insert:")));
46         time_label->set_alignment (1, 0.5);
47         table->attach (*time_label, 0, 1, 0, 1, FILL | EXPAND);
48         _clock.set (0);
49         _clock.set_session (_session);
50         _clock.set_bbt_reference (pos);
51         table->attach (_clock, 1, 2, 0, 1);
52
53         Label* intersected_label = manage (new Label (_("Intersected regions should:")));
54         intersected_label->set_alignment (1, 0.5);
55         table->attach (*intersected_label, 0, 1, 1, 2, FILL | EXPAND);
56         _intersected_combo.append_text (_("stay in position"));
57         _intersected_combo.append_text (_("move"));
58         _intersected_combo.append_text (_("be split"));
59         _intersected_combo.set_active (0);
60         table->attach (_intersected_combo, 1, 2, 1, 2);
61
62         get_vbox()->pack_start (*table);
63
64         _move_glued.set_label (_("Move glued regions"));
65         get_vbox()->pack_start (_move_glued);
66         _move_markers.set_label (_("Move markers"));
67         get_vbox()->pack_start (_move_markers);
68         _move_tempos.set_label (_("Move tempo and meter changes"));
69         get_vbox()->pack_start (_move_tempos);
70
71         add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
72         add_button (_("Insert time"), Gtk::RESPONSE_OK);
73         show_all ();
74 }
75
76 InsertTimeOption
77 InsertTimeDialog::intersected_region_action ()
78 {
79         /* only setting this to keep GCC quiet */
80         InsertTimeOption opt = LeaveIntersected;
81
82         switch (_intersected_combo.get_active_row_number ()) {
83         case 0:
84                 opt = LeaveIntersected;
85                 break;
86         case 1:
87                 opt = MoveIntersected;
88                 break;
89         case 2:
90                 opt = SplitIntersected;
91                 break;
92         }
93
94         return opt;
95 }
96
97 bool
98 InsertTimeDialog::move_glued () const
99 {
100         return _move_glued.get_active ();
101 }
102
103 bool
104 InsertTimeDialog::move_tempos () const
105 {
106         return _move_tempos.get_active ();
107 }
108
109 bool
110 InsertTimeDialog::move_markers () const
111 {
112         return _move_markers.get_active ();
113 }
114
115 nframes64_t
116 InsertTimeDialog::distance () const
117 {
118         return _clock.current_duration (_editor.get_preferred_edit_position ());
119 }