/[svn]/gigedit/trunk/src/gigedit/regionchooser.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/regionchooser.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1262 - (show annotations) (download)
Sun Jul 22 15:07:08 2007 UTC (13 years ago) by persson
File size: 24219 byte(s)
* regions can now be moved, not just resized
* improved labels in instrument properties dialog
* remove file extensions from file names when importing samples
* fixed some more checkbox layouts

1 /*
2 * Copyright (C) 2006, 2007 Andreas Persson
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with program; see the file COPYING. If not, write to the Free
16 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include "regionchooser.h"
21 #include <gdkmm/cursor.h>
22 #include <gtkmm/stock.h>
23 #include <gtkmm/spinbutton.h>
24 #include <gtkmm/dialog.h>
25 #include <libintl.h>
26 #include <math.h>
27
28 #define _(String) gettext(String)
29
30 RegionChooser::RegionChooser()
31 {
32 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
33
34 red = Gdk::Color("#8070ff");
35 grey1 = Gdk::Color("#b0b0b0");
36
37 colormap->alloc_color(red);
38 colormap->alloc_color(grey1);
39 instrument = 0;
40 region = 0;
41 resize.active = false;
42 cursor_is_resize = false;
43 h1 = 20;
44 width = 800;
45
46 actionGroup = Gtk::ActionGroup::create();
47 actionGroup->add(Gtk::Action::create("Properties",
48 Gtk::Stock::PROPERTIES),
49 sigc::mem_fun(*this,
50 &RegionChooser::show_region_properties));
51 actionGroup->add(Gtk::Action::create("Remove", Gtk::Stock::REMOVE),
52 sigc::mem_fun(*this, &RegionChooser::delete_region));
53 actionGroup->add(Gtk::Action::create("Add", Gtk::Stock::ADD),
54 sigc::mem_fun(*this, &RegionChooser::add_region));
55 actionGroup->add(Gtk::Action::create("Dimensions", _("Dimensions...")),
56 sigc::mem_fun(*this, &RegionChooser::manage_dimensions));
57
58 uiManager = Gtk::UIManager::create();
59 uiManager->insert_action_group(actionGroup);
60 Glib::ustring ui_info =
61 "<ui>"
62 " <popup name='PopupMenuInsideRegion'>"
63 " <menuitem action='Properties'/>"
64 " <menuitem action='Dimensions'/>"
65 " <menuitem action='Remove'/>"
66 " </popup>"
67 " <popup name='PopupMenuOutsideRegion'>"
68 " <menuitem action='Add'/>"
69 " </popup>"
70 "</ui>";
71 uiManager->add_ui_from_string(ui_info);
72
73 popup_menu_inside_region = dynamic_cast<Gtk::Menu*>(
74 uiManager->get_widget("/PopupMenuInsideRegion"));
75 popup_menu_outside_region = dynamic_cast<Gtk::Menu*>(
76 uiManager->get_widget("/PopupMenuOutsideRegion"));
77
78 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK |
79 Gdk::POINTER_MOTION_MASK | Gdk::POINTER_MOTION_HINT_MASK);
80
81 dimensionManager.articulation_changed_signal.connect(
82 sigc::mem_fun(*this, &RegionChooser::on_dimension_manager_changed)
83 );
84 }
85
86 RegionChooser::~RegionChooser()
87 {
88 }
89
90 void RegionChooser::on_realize()
91 {
92 // We need to call the base on_realize()
93 Gtk::DrawingArea::on_realize();
94
95 // Now we can allocate any additional resources we need
96 Glib::RefPtr<Gdk::Window> window = get_window();
97 gc = Gdk::GC::create(window);
98 window->clear();
99 }
100
101 bool RegionChooser::on_expose_event(GdkEventExpose* event)
102 {
103 Glib::RefPtr<Gdk::Window> window = get_window();
104 window->clear();
105 const int h = 40;
106 const int w = width - 1;
107 const int bh = int(h * 0.55);
108
109 Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
110 Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();
111
112 Glib::RefPtr<Pango::Context> context = get_pango_context();
113 Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
114
115 window->draw_rectangle(black, false, 0, h1, w, h - 1);
116 gc->set_foreground(grey1);
117 int x1 = int(w * 20.5 / 128.0 + 0.5);
118 int x2 = int(w * 109.5 / 128.0 + 0.5);
119 window->draw_rectangle(gc, true, 1, h1 + 1,
120 x1 - 1, h - 2);
121 window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);
122 window->draw_rectangle(gc, true, x2 + 1, h1 + 1,
123 w - x2 - 1, h - 2);
124 int octave = -1;
125 for (int i = 0 ; i < 128 ; i++) {
126 int note = (i + 3) % 12;
127 int x = int(w * i / 128.0 + 0.5);
128
129 if (note == 1 || note == 4 || note == 6 || note == 9 || note == 11) {
130 int x2 = int(w * (i + 0.5) / 128.0 + 0.5);
131 window->draw_line(black, x2, h1 + bh, x2, h1 + h);
132
133 int x3 = int(w * (i + 1) / 128.0 + 0.5);
134 window->draw_rectangle(black, true, x, h1 + 1, x3 - x + 1, bh);
135 } else if (note == 3 || note == 8) {
136 window->draw_line(black, x, h1 + 1, x, h1 + h);
137 }
138 if (note == 3) {
139 char buf[30];
140 sprintf(buf, "<span size=\"x-small\">%d</span>", octave);
141 layout->set_markup(buf);
142 Pango::Rectangle rectangle = layout->get_logical_extents();
143 double text_w = double(rectangle.get_width()) / Pango::SCALE;
144 double text_h = double(rectangle.get_height()) / Pango::SCALE;
145 double x2 = w * (i + 0.75) / 128.0;
146 window->draw_layout(black, int(x2 - text_w / 2 + 1),
147 int(h1 + h - text_h + 0.5), layout);
148 octave++;
149 }
150 }
151
152 if (instrument) {
153 int i = 0;
154 gig::Region *next_region;
155 int x3 = -1;
156 for (gig::Region *r = instrument->GetFirstRegion() ;
157 r ;
158 r = next_region) {
159
160 if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5);
161 next_region = instrument->GetNextRegion();
162 if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {
163 int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);
164 window->draw_line(black, x3, 0, x2, 0);
165 window->draw_line(black, x3, h1 - 1, x2, h1 - 1);
166 window->draw_line(black, x2, 1, x2, h1 - 2);
167 window->draw_rectangle(white, true, x3 + 1, 1, x2 - x3 - 1, h1 - 2);
168 x3 = -1;
169 }
170 i++;
171 }
172
173 for (gig::Region *r = instrument->GetFirstRegion() ;
174 r ;
175 r = instrument->GetNextRegion()) {
176 int x = int(w * (r->KeyRange.low) / 128.0 + 0.5);
177 window->draw_line(black, x, 1, x, h1 - 2);
178 }
179
180 if (region) {
181 int x1 = int(w * (region->KeyRange.low) / 128.0 + 0.5);
182 int x2 = int(w * (region->KeyRange.high + 1) / 128.0 + 0.5);
183 gc->set_foreground(red);
184 window->draw_rectangle(gc, true, x1 + 1, 1, x2 - x1 - 1, h1 - 2);
185 }
186 }
187 return true;
188 }
189
190
191 void RegionChooser::on_size_request(GtkRequisition* requisition)
192 {
193 *requisition = GtkRequisition();
194 requisition->height = 40 + 20;
195 requisition->width = 500;
196 }
197
198
199 // not used
200 void RegionChooser::draw_region(int from, int to, const Gdk::Color& color)
201 {
202 const int h = 40;
203 const int w = width;
204 const int bh = int(h * 0.55);
205
206 Glib::RefPtr<Gdk::Window> window = get_window();
207 gc->set_foreground(color);
208
209 for (int i = from ; i < to ; i++) {
210 int note = (i + 3) % 12;
211 int x = int(w * i / 128.0 + 0.5) + 1;
212 int x2 = int(w * (i + 1.5) / 128.0 + 0.5);
213 int x3 = int(w * (i + 1) / 128.0 + 0.5);
214 int x4 = int(w * (i - 0.5) / 128 + 0.5) + 1;
215 int w1 = x3 - x;
216 switch (note) {
217 case 0: case 5: case 10:
218 window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
219 window->draw_rectangle(gc, true, x4, h1 + bh + 1, x2 - x4, h - bh - 2);
220 break;
221 case 2: case 7:
222 window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
223 window->draw_rectangle(gc, true, x4, h1 + bh + 1, x3 - x4, h - bh - 2);
224 break;
225 case 3: case 8:
226 window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
227 window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2);
228 break;
229 default:
230 window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1);
231 break;
232 }
233 }
234 }
235
236 void RegionChooser::set_instrument(gig::Instrument* instrument)
237 {
238 this->instrument = instrument;
239 region = instrument ? instrument->GetFirstRegion() : 0;
240 queue_draw();
241 region_selected();
242 }
243
244 bool RegionChooser::on_button_release_event(GdkEventButton* event)
245 {
246 if (resize.active) {
247 get_window()->pointer_ungrab(event->time);
248 resize.active = false;
249
250 if (resize.mode == resize.moving_high_limit) {
251 if (resize.region->KeyRange.high != resize.pos - 1) {
252 resize.region->KeyRange.high = resize.pos - 1;
253 instrument_changed();
254 }
255 } else if (resize.mode == resize.moving_low_limit) {
256 if (resize.region->KeyRange.low != resize.pos) {
257 resize.region->KeyRange.low = resize.pos;
258 instrument_changed();
259 }
260 }
261
262 if (!is_in_resize_zone(event->x, event->y) && cursor_is_resize) {
263 get_window()->set_cursor();
264 cursor_is_resize = false;
265 }
266 } else if (move.active) {
267 get_window()->pointer_ungrab(event->time);
268 move.active = false;
269
270 if (move.pos) {
271 region->KeyRange.low += move.pos;
272 region->KeyRange.high += move.pos;
273
274 // find the r which is the first one to the right of region
275 // at its new position
276 gig::Region* r;
277 gig::Region* prev_region = 0;
278 for (r = instrument->GetFirstRegion() ; r ; r = instrument->GetNextRegion()) {
279 if (r->KeyRange.low > region->KeyRange.low) break;
280 prev_region = r;
281 }
282
283 // place region before r if it's not already there
284 if (prev_region != region) {
285 instrument->MoveRegion(region, r);
286 }
287 }
288
289 if (is_in_resize_zone(event->x, event->y)) {
290 get_window()->set_cursor(Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW));
291 cursor_is_resize = true;
292 }
293 }
294 return true;
295 }
296
297 bool RegionChooser::on_button_press_event(GdkEventButton* event)
298 {
299 if (!instrument) return true;
300
301 int k = int(event->x / (width - 1) * 128.0);
302
303 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
304 gig::Region* r = get_region(k);
305 if (r) {
306 region = r;
307 queue_draw();
308 region_selected();
309 popup_menu_inside_region->popup(event->button, event->time);
310 } else {
311 new_region_pos = k;
312 popup_menu_outside_region->popup(event->button, event->time);
313 }
314 } else {
315 if (is_in_resize_zone(event->x, event->y)) {
316 get_window()->pointer_grab(false,
317 Gdk::BUTTON_RELEASE_MASK |
318 Gdk::POINTER_MOTION_MASK |
319 Gdk::POINTER_MOTION_HINT_MASK,
320 Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW), event->time);
321 resize.active = true;
322 } else {
323 gig::Region* r = get_region(k);
324 if (r) {
325 region = r;
326 queue_draw();
327 region_selected();
328
329 get_window()->pointer_grab(false,
330 Gdk::BUTTON_RELEASE_MASK |
331 Gdk::POINTER_MOTION_MASK |
332 Gdk::POINTER_MOTION_HINT_MASK,
333 Gdk::Cursor(Gdk::FLEUR), event->time);
334 move.active = true;
335 move.from_x = event->x;
336 move.pos = 0;
337 }
338 }
339 }
340 return true;
341 }
342
343 gig::Region* RegionChooser::get_region(int key)
344 {
345 gig::Region* prev_region = 0;
346 gig::Region* next_region;
347 for (gig::Region *r = instrument->GetFirstRegion() ; r ;
348 r = next_region) {
349 next_region = instrument->GetNextRegion();
350
351 if (key < r->KeyRange.low) return 0;
352 if (key <= r->KeyRange.high) {
353 move.touch_left = prev_region && prev_region->KeyRange.high + 1 == r->KeyRange.low;
354 move.touch_right = next_region && r->KeyRange.high + 1 == next_region->KeyRange.low;
355 return r;
356 }
357 prev_region = r;
358 }
359 return 0;
360 }
361
362 void RegionChooser::motion_resize_region(int x, int y)
363 {
364 const int w = width - 1;
365 Glib::RefPtr<Gdk::Window> window = get_window();
366
367 int k = int(double(x) / w * 128.0 + 0.5);
368
369 if (k < resize.min) k = resize.min;
370 else if (k > resize.max) k = resize.max;
371
372 if (k != resize.pos) {
373 if (resize.mode == resize.undecided) {
374 if (k < resize.pos) {
375 // edit high limit of prev_region
376 resize.max = resize.region->KeyRange.low;
377 resize.region = resize.prev_region;
378 resize.mode = resize.moving_high_limit;
379 } else {
380 // edit low limit of region
381 resize.min = resize.prev_region->KeyRange.high + 1;
382 resize.mode = resize.moving_low_limit;
383 }
384 }
385 Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
386 Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();
387 if (region == resize.region) {
388 gc->set_foreground(red);
389 white = gc;
390 }
391 Glib::RefPtr<const Gdk::GC> bg = get_style()->get_bg_gc(Gtk::STATE_NORMAL);
392 int prevx = int(w * resize.pos / 128.0 + 0.5);
393 x = int(w * k / 128.0 + 0.5);
394
395 if (resize.mode == resize.moving_high_limit) {
396 if (k > resize.pos) {
397 window->draw_rectangle(white, true, prevx, 1, x - prevx, h1 - 2);
398 window->draw_line(black, prevx, 0, x, 0);
399 window->draw_line(black, prevx, h1 - 1, x, h1 - 1);
400 } else {
401 int xx = ((resize.pos == resize.max && resize.max != 128) ? 1 : 0);
402 window->draw_rectangle(bg, true, x + 1, 0, prevx - x - xx, h1);
403 }
404 } else {
405 if (k < resize.pos) {
406 window->draw_rectangle(white, true, x + 1, 1, prevx - x, h1 - 2);
407 window->draw_line(black, x, 0, prevx, 0);
408 window->draw_line(black, x, h1 - 1, prevx, h1 - 1);
409 } else {
410 int xx = ((resize.pos == resize.min && resize.min != 0) ? 1 : 0);
411 window->draw_rectangle(bg, true, prevx + xx, 0, x - prevx - xx, h1);
412 }
413 }
414 window->draw_line(black, x, 1, x, h1 - 2);
415 resize.pos = k;
416 }
417 }
418
419 void RegionChooser::motion_move_region(int x, int y)
420 {
421 const int w = width - 1;
422 Glib::RefPtr<Gdk::Window> window = get_window();
423
424 int k = int(double(x - move.from_x) / w * 128.0 + 0.5);
425 if (k == move.pos) return;
426 int new_k;
427 bool new_touch_left;
428 bool new_touch_right;
429 int a = 0;
430 if (k > move.pos) {
431 for (gig::Region* r = instrument->GetFirstRegion() ; ;
432 r = instrument->GetNextRegion()) {
433 if (r != region) {
434 int b = r ? r->KeyRange.low : 128;
435
436 // gap: from a to b (not inclusive b)
437
438 if (region->KeyRange.high + move.pos >= b) {
439 // not found the current gap yet, just continue
440 } else {
441
442 if (a > region->KeyRange.low + k) {
443 // this gap is too far to the right, break
444 break;
445 }
446
447 int newhigh = std::min(region->KeyRange.high + k, b - 1);
448 int newlo = newhigh - (region->KeyRange.high - region->KeyRange.low);
449
450 if (newlo >= a) {
451 // yes it fits - it's a candidate
452 new_k = newlo - region->KeyRange.low;
453 new_touch_left = a > 0 && a == newlo;
454 new_touch_right = b < 128 && newhigh + 1 == b;
455 }
456 }
457 if (!r) break;
458 a = r->KeyRange.high + 1;
459 }
460 }
461 } else {
462 for (gig::Region* r = instrument->GetFirstRegion() ; ;
463 r = instrument->GetNextRegion()) {
464 if (r != region) {
465 int b = r ? r->KeyRange.low : 128;
466
467 // gap from a to b (not inclusive b)
468
469 if (region->KeyRange.high + k >= b) {
470 // not found the current gap yet, just continue
471 } else {
472
473 if (a > region->KeyRange.low + move.pos) {
474 // this gap is too far to the right, break
475 break;
476 }
477
478 int newlo = std::max(region->KeyRange.low + k, a);
479 int newhigh = newlo + (region->KeyRange.high - region->KeyRange.low);
480
481 if (newhigh < b) {
482 // yes it fits - break as the first one is the best
483 new_k = newlo - region->KeyRange.low;
484 new_touch_left = a > 0 && a == newlo;
485 new_touch_right = b < 128 && newhigh + 1 == b;
486 break;
487 }
488 }
489 if (!r) break;
490 a = r->KeyRange.high + 1;
491 }
492 }
493 }
494 k = new_k;
495 if (k == move.pos) return;
496
497 Glib::RefPtr<const Gdk::GC> bg = get_style()->get_bg_gc(Gtk::STATE_NORMAL);
498 int prevx = int(w * (move.pos + region->KeyRange.low) / 128.0 + 0.5);
499 x = int(w * (k + region->KeyRange.low) / 128.0 + 0.5);
500 int prevx2 = int(w * (move.pos + region->KeyRange.high + 1) / 128.0 + 0.5);
501 int x2 = int(w * (k + region->KeyRange.high + 1) / 128.0 + 0.5);
502 Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
503 gc->set_foreground(red);
504
505 if (!new_touch_left) window->draw_line(black, x, 1, x, h1 - 2);
506 if (!new_touch_right) window->draw_line(black, x2, 1, x2, h1 - 2);
507
508 if (k > move.pos) {
509 window->draw_rectangle(bg, true, prevx + (move.touch_left ? 1 : 0), 0,
510 std::min(x, prevx2 + 1 - (move.touch_right ? 1 : 0)) -
511 (prevx + (move.touch_left ? 1 : 0)), h1);
512
513 window->draw_line(black, std::max(x, prevx2 + 1), 0, x2, 0);
514 window->draw_line(black, std::max(x, prevx2 + 1), h1 - 1, x2, h1 - 1);
515 window->draw_rectangle(gc, true, std::max(x + 1, prevx2), 1,
516 x2 - std::max(x + 1, prevx2), h1 - 2);
517 } else {
518 window->draw_rectangle(bg, true, std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), 0,
519 prevx2 + 1 - (move.touch_right ? 1 : 0) -
520 std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), h1);
521
522 window->draw_line(black, x, 0, std::min(x2, prevx - 1), 0);
523 window->draw_line(black, x, h1 - 1, std::min(x2, prevx - 1), h1 - 1);
524
525 window->draw_rectangle(gc, true, x + 1, 1, std::min(x2 - 1, prevx) - x, h1 - 2);
526 }
527
528 move.pos = k;
529 move.touch_left = new_touch_left;
530 move.touch_right = new_touch_right;
531 }
532
533
534 bool RegionChooser::on_motion_notify_event(GdkEventMotion* event)
535 {
536 Glib::RefPtr<Gdk::Window> window = get_window();
537 int x, y;
538 Gdk::ModifierType state = Gdk::ModifierType(0);
539 window->get_pointer(x, y, state);
540
541 if (resize.active) {
542 motion_resize_region(x, y);
543 } else if (move.active) {
544 motion_move_region(x, y);
545 } else {
546 if (is_in_resize_zone(x, y)) {
547 if (!cursor_is_resize) {
548 window->set_cursor(Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW));
549 cursor_is_resize = true;
550 }
551 } else if (cursor_is_resize) {
552 window->set_cursor();
553 cursor_is_resize = false;
554 }
555 }
556
557 return true;
558 }
559
560 bool RegionChooser::is_in_resize_zone(double x, double y) {
561 const int w = width - 1;
562
563 if (instrument && y >= 0 && y <= h1) {
564 gig::Region* prev_region = 0;
565 gig::Region* next_region;
566 for (gig::Region* r = instrument->GetFirstRegion() ; r ; r = next_region) {
567 next_region = instrument->GetNextRegion();
568
569 int lo = int(w * (r->KeyRange.low) / 128.0 + 0.5);
570 if (x <= lo - 2) break;
571 if (x < lo + 2) {
572 resize.region = r;
573 resize.pos = r->KeyRange.low;
574 resize.max = r->KeyRange.high;
575
576 if (prev_region && prev_region->KeyRange.high + 1 == r->KeyRange.low) {
577 // we don't know yet if it's the high limit of
578 // prev_region or the low limit of r that's going
579 // to be edited
580 resize.mode = resize.undecided;
581 resize.min = prev_region->KeyRange.low + 1;
582 resize.prev_region = prev_region;
583 return true;
584 }
585
586 // edit low limit
587 resize.mode = resize.moving_low_limit;
588 resize.min = prev_region ? prev_region->KeyRange.high + 1 : 0;
589 return true;
590 }
591 if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {
592 int hi = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);
593 if (x <= hi - 2) break;
594 if (x < hi + 2) {
595 // edit high limit
596 resize.region = r;
597 resize.pos = r->KeyRange.high + 1;
598 resize.mode = resize.moving_high_limit;
599 resize.min = r->KeyRange.low + 1;
600 resize.max = next_region ? next_region->KeyRange.low : 128;
601 return true;
602 }
603 }
604 prev_region = r;
605 }
606 }
607 return false;
608 }
609
610 sigc::signal<void> RegionChooser::signal_region_selected()
611 {
612 return region_selected;
613 }
614
615 sigc::signal<void> RegionChooser::signal_instrument_changed()
616 {
617 return instrument_changed;
618 }
619
620 void RegionChooser::show_region_properties()
621 {
622 if (!region) return;
623 Gtk::Dialog dialog("Region Properties", true /*modal*/);
624 // add "Keygroup" checkbox
625 Gtk::CheckButton checkBoxKeygroup("Member of a Keygroup (Exclusive Group)");
626 checkBoxKeygroup.set_active(region->KeyGroup);
627 dialog.get_vbox()->pack_start(checkBoxKeygroup);
628 checkBoxKeygroup.show();
629 // add "Keygroup" spinbox
630 Gtk::Adjustment adjustment(1, 1, pow(2,32));
631 Gtk::SpinButton spinBox(adjustment);
632 if (region->KeyGroup) spinBox.set_value(region->KeyGroup);
633 dialog.get_vbox()->pack_start(spinBox);
634 spinBox.show();
635 // add OK and CANCEL buttons to the dialog
636 dialog.add_button(Gtk::Stock::OK, 0);
637 dialog.add_button(Gtk::Stock::CANCEL, 1);
638 dialog.show_all_children();
639 if (!dialog.run()) { // OK selected ...
640 region->KeyGroup =
641 (checkBoxKeygroup.get_active()) ? spinBox.get_value_as_int() : 0;
642 }
643 }
644
645 void RegionChooser::add_region()
646 {
647 gig::Region* r;
648 for (r = instrument->GetFirstRegion() ; r ; r = instrument->GetNextRegion()) {
649 if (r->KeyRange.low > new_region_pos) break;
650 }
651
652 region = instrument->AddRegion();
653 region->KeyRange.low = region->KeyRange.high = new_region_pos;
654
655 instrument->MoveRegion(region, r);
656 queue_draw();
657 region_selected();
658 instrument_changed();
659 }
660
661 void RegionChooser::delete_region()
662 {
663 instrument->DeleteRegion(region);
664 region = 0;
665 queue_draw();
666 region_selected();
667 instrument_changed();
668 }
669
670 void RegionChooser::manage_dimensions()
671 {
672 gig::Region* region = get_region();
673 if (!region) return;
674 dimensionManager.show(region);
675 }
676
677 void RegionChooser::on_dimension_manager_changed() {
678 region_selected();
679 instrument_changed();
680 }

  ViewVC Help
Powered by ViewVC