Remove over 500 unnecessary includes (including 54 of session.h).
[ardour.git] / gtk2_ardour / edit_note_dialog.cc
1 /*
2     Copyright (C) 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/stock.h>
21 #include <gtkmm/table.h>
22
23 #include "canvas-note-event.h"
24 #include "edit_note_dialog.h"
25 #include "midi_region_view.h"
26
27 #include "i18n.h"
28
29 using namespace Gtk;
30
31 /**
32  *    EditNoteDialog constructor.
33  *
34  *    @param n Note to edit.
35  */
36
37 EditNoteDialog::EditNoteDialog (MidiRegionView* rv, Gnome::Canvas::CanvasNoteEvent* ev)
38         : ArdourDialog (_("Note"))
39         , _region_view (rv)
40         , _event (ev)
41         , _time_clock (X_("notetime"), true, "", true, false)
42         , _length_clock (X_("notelength"), true, "", true, false, true)
43 {
44         Table* table = manage (new Table (4, 2));
45         table->set_spacings (6);
46
47         int r = 0;
48
49         Label* l = manage (new Label (_("Channel")));
50         l->set_alignment (0, 0.5);
51         table->attach (*l, 0, 1, r, r + 1);
52         table->attach (_channel, 1, 2, r, r + 1);
53         ++r;
54
55         _channel.set_range (1, 16);
56         _channel.set_increments (1, 2);
57         _channel.set_value (ev->note()->channel () + 1);
58
59         l = manage (new Label (_("Pitch")));
60         l->set_alignment (0, 0.5);
61         table->attach (*l, 0, 1, r, r + 1);
62         table->attach (_pitch, 1, 2, r, r + 1);
63         ++r;
64
65         _pitch.set_range (0, 127);
66         _pitch.set_increments (1, 10);
67         _pitch.set_value (ev->note()->note ());
68
69         l = manage (new Label (_("Velocity")));
70         l->set_alignment (0, 0.5);
71         table->attach (*l, 0, 1, r, r + 1);
72         table->attach (_velocity, 1, 2, r, r + 1);
73         ++r;
74
75         _velocity.set_range (0, 127);
76         _velocity.set_increments (1, 10);
77         _velocity.set_value (ev->note()->velocity ());
78
79         l = manage (new Label (_("Time")));
80         l->set_alignment (0, 0.5);
81         table->attach (*l, 0, 1, r, r + 1);
82         table->attach (_time_clock, 1, 2, r, r + 1);
83         ++r;
84
85         _time_clock.set_session (_region_view->get_time_axis_view().session ());
86         _time_clock.set_mode (AudioClock::BBT);
87         _time_clock.set (_region_view->source_relative_time_converter().to (ev->note()->time ()), true);
88
89         l = manage (new Label (_("Length")));
90         l->set_alignment (0, 0.5);
91         table->attach (*l, 0, 1, r, r + 1);
92         table->attach (_length_clock, 1, 2, r, r + 1);
93         ++r;
94
95         _length_clock.set_session (_region_view->get_time_axis_view().session ());
96         _length_clock.set_mode (AudioClock::BBT);
97         _length_clock.set (_region_view->region_relative_time_converter().to (ev->note()->length ()), true);
98
99         get_vbox()->pack_start (*table);
100
101         add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
102         add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_ACCEPT);
103         set_default_response (Gtk::RESPONSE_ACCEPT);
104
105         show_all ();
106 }
107
108 int
109 EditNoteDialog::run ()
110 {
111         int const r = Dialog::run ();
112         if (r != RESPONSE_ACCEPT) {
113                 return r;
114         }
115
116         /* These calls mean that if a value is entered using the keyboard
117            it will be returned by the get_value_as_int()s below.
118         */
119         _channel.update ();
120         _pitch.update ();
121         _velocity.update ();
122
123         _region_view->start_note_diff_command (_("edit note"));
124
125         bool had_change = false;
126
127         if (_channel.get_value_as_int() - 1 != _event->note()->channel()) {
128                 _region_view->change_note_channel (_event, _channel.get_value_as_int () - 1);
129                 had_change = true;
130         }
131
132         if (_pitch.get_value_as_int() != _event->note()->note()) {
133                 _region_view->change_note_note (_event, _pitch.get_value_as_int (), false);
134                 had_change = true;
135         }
136
137         if (_velocity.get_value_as_int() != _event->note()->velocity()) {
138                 _region_view->change_note_velocity (_event, _velocity.get_value_as_int (), false);
139                 had_change = true;
140         }
141
142         double const t = _region_view->source_relative_time_converter().from (_time_clock.current_time ());
143
144         if (t != _event->note()->time()) {
145                 _region_view->change_note_time (_event, t);
146                 had_change = true;
147         }
148
149         double const d = _region_view->region_relative_time_converter().from (_length_clock.current_duration ());
150
151         if (d != _event->note()->length()) {
152                 _region_view->change_note_length (_event, d);
153                 had_change = true;
154         }
155
156         if (!had_change) {
157                 _region_view->abort_command ();
158         }
159
160         _region_view->apply_diff ();
161
162         _event->set_selected (_event->selected()); // change color
163
164         return r;
165 }