first, incomplete pass at step entry dialog, along with various SVG and PNG files...
[ardour.git] / gtk2_ardour / step_entry.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 "midi_time_axis.h"
21 #include "step_entry.h"
22 #include "utils.h"
23
24 #include "i18n.h"
25
26 using namespace Gtk;
27
28 static void
29 _note_off_event_handler (GtkWidget* widget, int note, gpointer arg)
30 {
31         ((StepEntry*)arg)->note_off_event_handler (note);
32 }
33
34
35 StepEntry::StepEntry (MidiTimeAxisView& mtv)
36         : ArdourDialog (_("Step Entry Editor"))
37         , triplet_button ("3")
38         , sustain_button ("sustain")
39         , rest_button ("rest")
40         , channel_adjustment (0, 15, 0, 1, 4)
41         , channel_spinner (channel_adjustment)
42         , _piano (0)
43         , piano (0)
44         , _mtv (&mtv)
45 {
46         RadioButtonGroup length_group = length_1_button.get_group();
47         length_2_button.set_group (length_group);
48         length_4_button.set_group (length_group);
49         length_8_button.set_group (length_group);
50         length_12_button.set_group (length_group);
51         length_16_button.set_group (length_group);
52         length_32_button.set_group (length_group);
53         length_64_button.set_group (length_group);
54
55         Widget* w;
56
57         w = manage (new Image (::get_icon (X_("wholenote"))));
58         w->show();
59         length_1_button.add (*w);
60         w = manage (new Image (::get_icon (X_("halfnote"))));
61         w->show();
62         length_2_button.add (*w);
63         w = manage (new Image (::get_icon (X_("quarternote"))));
64         w->show();
65         length_4_button.add (*w);
66         w = manage (new Image (::get_icon (X_("eighthnote"))));
67         w->show();
68         length_8_button.add (*w);
69         w = manage (new Image (::get_icon (X_("sixteenthnote"))));
70         w->show();
71         length_16_button.add (*w);
72         w = manage (new Image (::get_icon (X_("thirtysecondnote"))));
73         w->show();
74         length_32_button.add (*w);
75         w = manage (new Image (::get_icon (X_("sixtyfourthnote"))));
76         w->show();
77         length_64_button.add (*w);
78
79         length_1_button.property_draw_indicator() = false;
80         length_2_button.property_draw_indicator() = false;
81         length_4_button.property_draw_indicator() = false;
82         length_8_button.property_draw_indicator() = false;
83         length_16_button.property_draw_indicator() = false;
84         length_32_button.property_draw_indicator() = false;
85         length_64_button.property_draw_indicator() = false;
86
87         note_length_box.pack_start (length_1_button, false, false);
88         note_length_box.pack_start (length_2_button, false, false);
89         note_length_box.pack_start (length_4_button, false, false);
90         note_length_box.pack_start (length_8_button, false, false);
91         note_length_box.pack_start (length_16_button, false, false);
92         note_length_box.pack_start (length_32_button, false, false);
93         note_length_box.pack_start (length_64_button, false, false);
94
95         RadioButtonGroup velocity_group = velocity_ppp_button.get_group();
96         velocity_pp_button.set_group (velocity_group);
97         velocity_p_button.set_group (velocity_group);
98         velocity_mp_button.set_group (velocity_group);
99         velocity_mf_button.set_group (velocity_group);
100         velocity_f_button.set_group (velocity_group);
101         velocity_ff_button.set_group (velocity_group);
102         velocity_fff_button.set_group (velocity_group);
103
104         w = manage (new Image (::get_icon (X_("pianississimo"))));
105         w->show();
106         velocity_ppp_button.add (*w);
107         w = manage (new Image (::get_icon (X_("pianissimo"))));
108         w->show();
109         velocity_pp_button.add (*w);
110         w = manage (new Image (::get_icon (X_("piano"))));
111         w->show();
112         velocity_p_button.add (*w);
113         w = manage (new Image (::get_icon (X_("mezzopiano"))));
114         w->show();
115         velocity_mp_button.add (*w);
116         w = manage (new Image (::get_icon (X_("mezzoforte"))));
117         w->show();
118         velocity_mf_button.add (*w);
119         w = manage (new Image (::get_icon (X_("forte"))));
120         w->show();
121         velocity_f_button.add (*w);
122         w = manage (new Image (::get_icon (X_("fortissimo"))));
123         w->show();
124         velocity_ff_button.add (*w);
125         w = manage (new Image (::get_icon (X_("fortississimo"))));
126         w->show();
127         velocity_fff_button.add (*w);
128
129         velocity_ppp_button.property_draw_indicator() = false;
130         velocity_pp_button.property_draw_indicator() = false;
131         velocity_p_button.property_draw_indicator() = false;
132         velocity_mp_button.property_draw_indicator() = false;
133         velocity_mf_button.property_draw_indicator() = false;
134         velocity_f_button.property_draw_indicator() = false;
135         velocity_ff_button.property_draw_indicator() = false;
136         velocity_fff_button.property_draw_indicator() = false;
137
138         note_velocity_box.pack_start (velocity_ppp_button, false, false);
139         note_velocity_box.pack_start (velocity_pp_button, false, false);
140         note_velocity_box.pack_start (velocity_p_button, false, false);
141         note_velocity_box.pack_start (velocity_mp_button, false, false);
142         note_velocity_box.pack_start (velocity_mf_button, false, false);
143         note_velocity_box.pack_start (velocity_f_button, false, false);
144         note_velocity_box.pack_start (velocity_ff_button, false, false);
145         note_velocity_box.pack_start (velocity_fff_button, false, false);
146
147         Label* l = manage (new Label);
148         l->set_markup ("<b><big>.</big></b>");
149         l->show ();
150         dot_button.add (*l);
151
152         w = manage (new Image (::get_icon (X_("chord"))));
153         w->show();
154         chord_button.add (*w);
155
156         upper_box.set_spacing (6);
157         upper_box.pack_start (chord_button, false, false);
158         upper_box.pack_start (note_length_box, false, false, 12);
159         upper_box.pack_start (triplet_button, false, false);
160         upper_box.pack_start (dot_button, false, false);
161         upper_box.pack_start (sustain_button, false, false);
162         upper_box.pack_start (rest_button, false, false);
163         upper_box.pack_start (note_velocity_box, false, false, 12);
164         upper_box.pack_start (channel_spinner, false, false);
165
166         _piano = (PianoKeyboard*) piano_keyboard_new ();
167         piano = Glib::wrap ((GtkWidget*) _piano);
168
169         g_signal_connect(G_OBJECT(_piano), "note-off", G_CALLBACK(_note_off_event_handler), this);
170
171         rest_button.signal_clicked().connect (sigc::mem_fun (*this, &StepEntry::rest_click));
172
173         packer.set_spacing (6);
174         packer.pack_start (upper_box, false, false);
175         packer.pack_start (*piano, false, false);
176         packer.show_all ();
177
178         get_vbox()->add (packer);
179 }
180
181 StepEntry::~StepEntry()
182 {
183 }
184
185 void
186 StepEntry::note_off_event_handler (int note)
187 {
188         Evoral::MusicalTime length = 1.0;
189         uint8_t velocity = 64;
190
191         if (length_64_button.get_active()) {
192                 length = 1.0/64.0;
193         } else if (length_32_button.get_active()) {
194                 length = 1.0/32.0;
195         } else if (length_16_button.get_active()) {
196                 length = 1.0/16.0;
197         } else if (length_8_button.get_active()) {
198                 length = 1.0/8.0;
199         } else if (length_4_button.get_active()) {
200                 length = 1.0/4.0;
201         } else if (length_2_button.get_active()) {
202                 length = 1.0/2.0;
203         } else if (length_1_button.get_active()) {
204                 length = 1.0/1.0;
205         }
206
207         if (dot_button.get_active()) {
208                 length *= 0.5;
209         }
210
211         if (velocity_ppp_button.get_active()) {
212                 velocity = 16;
213         } else if (velocity_pp_button.get_active()) {
214                 velocity = 32;
215         } else if (velocity_p_button.get_active()) {
216                 velocity = 48;
217         } else if (velocity_mp_button.get_active()) {
218                 velocity = 64;
219         } else if (velocity_mf_button.get_active()) {
220                 velocity = 80;
221         } else if (velocity_f_button.get_active()) {
222                 velocity = 96;
223         } else if (velocity_ff_button.get_active()) {
224                 velocity = 112;
225         } else if (velocity_fff_button.get_active()) {
226                 velocity = 127;
227         }
228
229         if (!triplet_button.get_active()) {
230                 _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
231         } else {
232                 length *= 2.0/3.0;
233                 _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
234                 _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
235                 _mtv->step_add_note (channel_adjustment.get_value(), note, velocity, length);
236         }
237 }
238
239 void
240 StepEntry::rest_click ()
241 {
242         _mtv->step_edit_rest ();
243 }