1 |
/* |
/* |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2009 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
18 |
*/ |
*/ |
19 |
|
|
20 |
#include "regionchooser.h" |
#include "regionchooser.h" |
21 |
|
#include <algorithm> |
22 |
#include <gdkmm/cursor.h> |
#include <gdkmm/cursor.h> |
23 |
#include <gtkmm/stock.h> |
#include <gtkmm/stock.h> |
24 |
#include <gtkmm/spinbutton.h> |
#include <gtkmm/spinbutton.h> |
25 |
#include <gtkmm/dialog.h> |
#include <gtkmm/dialog.h> |
26 |
#include <math.h> |
#include <math.h> |
27 |
|
#include <sstream> |
28 |
|
|
29 |
#include "global.h" |
#include "global.h" |
30 |
|
|
31 |
RegionChooser::RegionChooser() |
#define REGION_BLOCK_HEIGHT 20 |
32 |
|
#define KEYBOARD_HEIGHT 40 |
33 |
|
|
34 |
|
void SortedRegions::update(gig::Instrument* instrument) { |
35 |
|
// Usually, the regions in a gig file are ordered after their key |
36 |
|
// range, but there are files where they are not. The |
37 |
|
// RegionChooser code needs a sorted list of regions. |
38 |
|
regions.clear(); |
39 |
|
if (instrument) { |
40 |
|
for (gig::Region *r = instrument->GetFirstRegion() ; |
41 |
|
r ; |
42 |
|
r = instrument->GetNextRegion()) { |
43 |
|
regions.push_back(r); |
44 |
|
} |
45 |
|
sort(regions.begin(), regions.end(), *this); |
46 |
|
} |
47 |
|
} |
48 |
|
|
49 |
|
gig::Region* SortedRegions::first() { |
50 |
|
region_iterator = regions.begin(); |
51 |
|
return region_iterator == regions.end() ? 0 : *region_iterator; |
52 |
|
} |
53 |
|
|
54 |
|
gig::Region* SortedRegions::next() { |
55 |
|
region_iterator++; |
56 |
|
return region_iterator == regions.end() ? 0 : *region_iterator; |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
RegionChooser::RegionChooser() : |
62 |
|
m_VirtKeybModeChoice(_("Virtual Keyboard Mode")), |
63 |
|
currentActiveKey(-1) |
64 |
{ |
{ |
65 |
Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap(); |
Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap(); |
66 |
|
|
67 |
red = Gdk::Color("#8070ff"); |
red = Gdk::Color("#8070ff"); |
68 |
grey1 = Gdk::Color("#b0b0b0"); |
grey1 = Gdk::Color("#b0b0b0"); |
69 |
|
activeKeyColor = Gdk::Color("#ff0000"); |
70 |
|
white = Gdk::Color("#ffffff"); |
71 |
|
black = Gdk::Color("#000000"); |
72 |
|
|
73 |
colormap->alloc_color(red); |
colormap->alloc_color(red); |
74 |
colormap->alloc_color(grey1); |
colormap->alloc_color(grey1); |
75 |
|
colormap->alloc_color(activeKeyColor); |
76 |
|
colormap->alloc_color(white); |
77 |
|
colormap->alloc_color(black); |
78 |
instrument = 0; |
instrument = 0; |
79 |
region = 0; |
region = 0; |
80 |
resize.active = false; |
resize.active = false; |
81 |
move.active = false; |
move.active = false; |
82 |
cursor_is_resize = false; |
cursor_is_resize = false; |
83 |
h1 = 20; |
h1 = REGION_BLOCK_HEIGHT; |
84 |
width = 800; |
|
85 |
|
// properties of the virtual keyboard |
86 |
|
{ |
87 |
|
const char* choices[] = { _("normal"), _("chord"), NULL }; |
88 |
|
static const virt_keyboard_mode_t values[] = { |
89 |
|
VIRT_KEYBOARD_MODE_NORMAL, |
90 |
|
VIRT_KEYBOARD_MODE_CHORD |
91 |
|
}; |
92 |
|
m_VirtKeybModeChoice.set_choices(choices, values); |
93 |
|
m_VirtKeybModeChoice.set_value(VIRT_KEYBOARD_MODE_NORMAL); |
94 |
|
} |
95 |
|
m_VirtKeybVelocityLabelDescr.set_text(_("Note-On Velocity:")); |
96 |
|
m_VirtKeybVelocityLabel.set_text("-"); |
97 |
|
m_VirtKeybOffVelocityLabelDescr.set_text(_("Note-Off Velocity:")); |
98 |
|
m_VirtKeybOffVelocityLabel.set_text("-"); |
99 |
|
m_VirtKeybPropsBox.pack_start(m_VirtKeybModeChoice.label, Gtk::PACK_SHRINK); |
100 |
|
m_VirtKeybPropsBox.pack_start(m_VirtKeybModeChoice.widget, Gtk::PACK_SHRINK); |
101 |
|
m_VirtKeybPropsBox.pack_start(m_VirtKeybVelocityLabelDescr, Gtk::PACK_SHRINK); |
102 |
|
m_VirtKeybPropsBox.pack_start(m_VirtKeybVelocityLabel, Gtk::PACK_SHRINK); |
103 |
|
m_VirtKeybPropsBox.pack_start(m_VirtKeybOffVelocityLabelDescr, Gtk::PACK_SHRINK); |
104 |
|
m_VirtKeybPropsBox.pack_start(m_VirtKeybOffVelocityLabel, Gtk::PACK_SHRINK); |
105 |
|
m_VirtKeybPropsBox.set_spacing(10); |
106 |
|
m_VirtKeybPropsBox.show(); |
107 |
|
|
108 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
109 |
actionGroup->add(Gtk::Action::create("Properties", |
actionGroup->add(Gtk::Action::create("Properties", |
151 |
sigc::mem_fun(*this, &RegionChooser::on_dimension_manager_changed) |
sigc::mem_fun(*this, &RegionChooser::on_dimension_manager_changed) |
152 |
) |
) |
153 |
); |
); |
154 |
|
keyboard_key_hit_signal.connect( |
155 |
|
sigc::mem_fun(*this, &RegionChooser::on_note_on_event) |
156 |
|
); |
157 |
|
keyboard_key_released_signal.connect( |
158 |
|
sigc::mem_fun(*this, &RegionChooser::on_note_off_event) |
159 |
|
); |
160 |
} |
} |
161 |
|
|
162 |
RegionChooser::~RegionChooser() |
RegionChooser::~RegionChooser() |
163 |
{ |
{ |
164 |
} |
} |
165 |
|
|
166 |
|
template<class T> inline std::string ToString(T o) { |
167 |
|
std::stringstream ss; |
168 |
|
ss << o; |
169 |
|
return ss.str(); |
170 |
|
} |
171 |
|
|
172 |
|
void RegionChooser::on_note_on_event(int key, int velocity) { |
173 |
|
draw_region(key, key+1, activeKeyColor); |
174 |
|
m_VirtKeybVelocityLabel.set_text(ToString(velocity)); |
175 |
|
} |
176 |
|
|
177 |
|
void RegionChooser::on_note_off_event(int key, int velocity) { |
178 |
|
if (is_black_key(key)) |
179 |
|
draw_region(key, key+1, black); |
180 |
|
else |
181 |
|
draw_region(key, key+1, white); |
182 |
|
m_VirtKeybOffVelocityLabel.set_text(ToString(velocity)); |
183 |
|
} |
184 |
|
|
185 |
void RegionChooser::on_realize() |
void RegionChooser::on_realize() |
186 |
{ |
{ |
187 |
// We need to call the base on_realize() |
// We need to call the base on_realize() |
197 |
{ |
{ |
198 |
Glib::RefPtr<Gdk::Window> window = get_window(); |
Glib::RefPtr<Gdk::Window> window = get_window(); |
199 |
window->clear(); |
window->clear(); |
200 |
const int h = 40; |
const int h = KEYBOARD_HEIGHT; |
201 |
const int w = width - 1; |
const int w = get_width() - 1; |
202 |
const int bh = int(h * 0.55); |
const int bh = int(h * 0.55); |
203 |
|
|
204 |
Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc(); |
Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc(); |
205 |
Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc(); |
Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc(); |
206 |
|
|
|
Glib::RefPtr<Pango::Context> context = get_pango_context(); |
|
|
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); |
|
|
|
|
207 |
window->draw_rectangle(black, false, 0, h1, w, h - 1); |
window->draw_rectangle(black, false, 0, h1, w, h - 1); |
208 |
gc->set_foreground(grey1); |
gc->set_foreground(grey1); |
209 |
int x1 = int(w * 20.5 / 128.0 + 0.5); |
int x1 = int(w * 20.5 / 128.0 + 0.5); |
213 |
window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2); |
window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2); |
214 |
window->draw_rectangle(gc, true, x2 + 1, h1 + 1, |
window->draw_rectangle(gc, true, x2 + 1, h1 + 1, |
215 |
w - x2 - 1, h - 2); |
w - x2 - 1, h - 2); |
|
int octave = -1; |
|
216 |
for (int i = 0 ; i < 128 ; i++) { |
for (int i = 0 ; i < 128 ; i++) { |
217 |
int note = (i + 3) % 12; |
int note = (i + 3) % 12; |
218 |
int x = int(w * i / 128.0 + 0.5); |
int x = int(w * i / 128.0 + 0.5); |
226 |
} else if (note == 3 || note == 8) { |
} else if (note == 3 || note == 8) { |
227 |
window->draw_line(black, x, h1 + 1, x, h1 + h); |
window->draw_line(black, x, h1 + 1, x, h1 + h); |
228 |
} |
} |
229 |
if (note == 3) { |
if (note == 3) draw_digit(i); |
|
char buf[30]; |
|
|
sprintf(buf, "<span size=\"8000\">%d</span>", octave); |
|
|
layout->set_markup(buf); |
|
|
Pango::Rectangle rectangle = layout->get_logical_extents(); |
|
|
double text_w = double(rectangle.get_width()) / Pango::SCALE; |
|
|
double text_h = double(rectangle.get_height()) / Pango::SCALE; |
|
|
double x2 = w * (i + 0.75) / 128.0; |
|
|
window->draw_layout(black, int(x2 - text_w / 2 + 1), |
|
|
int(h1 + h - text_h + 0.5), layout); |
|
|
octave++; |
|
|
} |
|
230 |
} |
} |
231 |
|
|
232 |
if (instrument) { |
if (instrument) { |
233 |
int i = 0; |
int i = 0; |
234 |
gig::Region *next_region; |
gig::Region *next_region; |
235 |
int x3 = -1; |
int x3 = -1; |
236 |
for (gig::Region *r = instrument->GetFirstRegion() ; |
for (gig::Region *r = regions.first() ; r ; r = next_region) { |
|
r ; |
|
|
r = next_region) { |
|
237 |
|
|
238 |
if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5); |
if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5); |
239 |
next_region = instrument->GetNextRegion(); |
next_region = regions.next(); |
240 |
if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) { |
if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) { |
241 |
int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5); |
int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5); |
242 |
window->draw_line(black, x3, 0, x2, 0); |
window->draw_line(black, x3, 0, x2, 0); |
248 |
i++; |
i++; |
249 |
} |
} |
250 |
|
|
251 |
for (gig::Region *r = instrument->GetFirstRegion() ; |
for (gig::Region *r = regions.first() ; r ; r = regions.next()) { |
|
r ; |
|
|
r = instrument->GetNextRegion()) { |
|
252 |
int x = int(w * (r->KeyRange.low) / 128.0 + 0.5); |
int x = int(w * (r->KeyRange.low) / 128.0 + 0.5); |
253 |
window->draw_line(black, x, 1, x, h1 - 2); |
window->draw_line(black, x, 1, x, h1 - 2); |
254 |
} |
} |
267 |
void RegionChooser::on_size_request(GtkRequisition* requisition) |
void RegionChooser::on_size_request(GtkRequisition* requisition) |
268 |
{ |
{ |
269 |
*requisition = GtkRequisition(); |
*requisition = GtkRequisition(); |
270 |
requisition->height = 40 + 20; |
requisition->height = KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT; |
271 |
requisition->width = 500; |
requisition->width = 500; |
272 |
} |
} |
273 |
|
|
274 |
|
bool RegionChooser::is_black_key(int key) { |
275 |
|
const int note = (key + 3) % 12; |
276 |
|
return note == 1 || note == 4 || note == 6 || note == 9 || note == 11; |
277 |
|
} |
278 |
|
|
279 |
|
void RegionChooser::draw_digit(int key) { |
280 |
|
const int h = KEYBOARD_HEIGHT; |
281 |
|
const int w = get_width() - 1; |
282 |
|
Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(get_pango_context()); |
283 |
|
char buf[30]; |
284 |
|
sprintf(buf, "<span size=\"8000\">%d</span>", key / 12 - 1); |
285 |
|
layout->set_markup(buf); |
286 |
|
Pango::Rectangle rectangle = layout->get_logical_extents(); |
287 |
|
double text_w = double(rectangle.get_width()) / Pango::SCALE; |
288 |
|
double text_h = double(rectangle.get_height()) / Pango::SCALE; |
289 |
|
double x = w * (key + 0.75) / 128.0; |
290 |
|
get_window()->draw_layout(get_style()->get_black_gc(), int(x - text_w / 2 + 1), |
291 |
|
int(h1 + h - text_h + 0.5), layout); |
292 |
|
} |
293 |
|
|
|
// not used |
|
294 |
void RegionChooser::draw_region(int from, int to, const Gdk::Color& color) |
void RegionChooser::draw_region(int from, int to, const Gdk::Color& color) |
295 |
{ |
{ |
296 |
const int h = 40; |
const int h = KEYBOARD_HEIGHT; |
297 |
const int w = width; |
const int w = get_width() - 1; |
298 |
const int bh = int(h * 0.55); |
const int bh = int(h * 0.55); |
299 |
|
|
300 |
Glib::RefPtr<Gdk::Window> window = get_window(); |
Glib::RefPtr<Gdk::Window> window = get_window(); |
305 |
int x = int(w * i / 128.0 + 0.5) + 1; |
int x = int(w * i / 128.0 + 0.5) + 1; |
306 |
int x2 = int(w * (i + 1.5) / 128.0 + 0.5); |
int x2 = int(w * (i + 1.5) / 128.0 + 0.5); |
307 |
int x3 = int(w * (i + 1) / 128.0 + 0.5); |
int x3 = int(w * (i + 1) / 128.0 + 0.5); |
308 |
int x4 = int(w * (i - 0.5) / 128 + 0.5) + 1; |
int x4 = int(w * (i - 0.5) / 128.0 + 0.5); |
309 |
int w1 = x3 - x; |
int w1 = x3 - x; |
310 |
switch (note) { |
switch (note) { |
311 |
case 0: case 5: case 10: |
case 0: case 5: case 10: |
312 |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); |
313 |
window->draw_rectangle(gc, true, x4, h1 + bh + 1, x2 - x4, h - bh - 2); |
window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x2 - x4 - 1, h - bh - 2); |
314 |
break; |
break; |
315 |
case 2: case 7: |
case 2: case 7: |
316 |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); |
317 |
window->draw_rectangle(gc, true, x4, h1 + bh + 1, x3 - x4, h - bh - 2); |
window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x3 - x4 - 1, h - bh - 2); |
318 |
break; |
break; |
319 |
case 3: case 8: |
case 3: case 8: |
320 |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); |
321 |
window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2); |
window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2); |
322 |
|
if (note == 3) draw_digit(i); |
323 |
break; |
break; |
324 |
default: |
default: |
325 |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1); |
window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1); |
331 |
void RegionChooser::set_instrument(gig::Instrument* instrument) |
void RegionChooser::set_instrument(gig::Instrument* instrument) |
332 |
{ |
{ |
333 |
this->instrument = instrument; |
this->instrument = instrument; |
334 |
region = instrument ? instrument->GetFirstRegion() : 0; |
regions.update(instrument); |
335 |
|
region = regions.first(); |
336 |
queue_draw(); |
queue_draw(); |
337 |
region_selected(); |
region_selected(); |
338 |
|
dimensionManager.set_region(region); |
339 |
} |
} |
340 |
|
|
341 |
bool RegionChooser::on_button_release_event(GdkEventButton* event) |
bool RegionChooser::on_button_release_event(GdkEventButton* event) |
342 |
{ |
{ |
343 |
|
const int k = int(event->x / (get_width() - 1) * 128.0); |
344 |
|
|
345 |
|
// handle-note off on virtual keyboard |
346 |
|
if (event->type == GDK_BUTTON_RELEASE) { |
347 |
|
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
348 |
|
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
349 |
|
if (velocity <= 0) velocity = 1; |
350 |
|
switch (m_VirtKeybModeChoice.get_value()) { |
351 |
|
case VIRT_KEYBOARD_MODE_CHORD: |
352 |
|
if (event->y >= REGION_BLOCK_HEIGHT) |
353 |
|
keyboard_key_released_signal.emit(k, velocity); |
354 |
|
break; |
355 |
|
case VIRT_KEYBOARD_MODE_NORMAL: |
356 |
|
default: |
357 |
|
if (currentActiveKey >= 0 && currentActiveKey <= 127) { |
358 |
|
keyboard_key_released_signal.emit(currentActiveKey, velocity); |
359 |
|
currentActiveKey = -1; |
360 |
|
} |
361 |
|
break; |
362 |
|
} |
363 |
|
} |
364 |
|
|
365 |
if (resize.active) { |
if (resize.active) { |
366 |
get_window()->pointer_ungrab(event->time); |
get_window()->pointer_ungrab(event->time); |
367 |
resize.active = false; |
resize.active = false; |
373 |
resize.region->KeyRange.low, // low |
resize.region->KeyRange.low, // low |
374 |
resize.pos - 1 // high |
resize.pos - 1 // high |
375 |
); |
); |
376 |
|
regions.update(instrument); |
377 |
instrument_changed.emit(); |
instrument_changed.emit(); |
378 |
instrument_struct_changed_signal.emit(instrument); |
instrument_struct_changed_signal.emit(instrument); |
379 |
} |
} |
384 |
resize.pos, // low |
resize.pos, // low |
385 |
resize.region->KeyRange.high // high |
resize.region->KeyRange.high // high |
386 |
); |
); |
387 |
|
regions.update(instrument); |
388 |
instrument_changed.emit(); |
instrument_changed.emit(); |
389 |
instrument_struct_changed_signal.emit(instrument); |
instrument_struct_changed_signal.emit(instrument); |
390 |
} |
} |
404 |
region->KeyRange.low + move.pos, |
region->KeyRange.low + move.pos, |
405 |
region->KeyRange.high + move.pos |
region->KeyRange.high + move.pos |
406 |
); |
); |
407 |
|
regions.update(instrument); |
408 |
instrument_changed.emit(); |
instrument_changed.emit(); |
409 |
instrument_struct_changed_signal.emit(instrument); |
instrument_struct_changed_signal.emit(instrument); |
410 |
} |
} |
421 |
{ |
{ |
422 |
if (!instrument) return true; |
if (!instrument) return true; |
423 |
|
|
424 |
int k = int(event->x / (width - 1) * 128.0); |
const int k = int(event->x / (get_width() - 1) * 128.0); |
425 |
|
|
426 |
|
if (event->type == GDK_BUTTON_PRESS) { |
427 |
|
if (event->y >= REGION_BLOCK_HEIGHT) { |
428 |
|
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
429 |
|
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
430 |
|
currentActiveKey = k; |
431 |
|
keyboard_key_hit_signal.emit(k, velocity); |
432 |
|
} |
433 |
|
} |
434 |
|
|
435 |
|
if (event->y >= REGION_BLOCK_HEIGHT) return true; |
436 |
if (event->type == GDK_BUTTON_PRESS && event->button == 3) { |
if (event->type == GDK_BUTTON_PRESS && event->button == 3) { |
437 |
gig::Region* r = get_region(k); |
gig::Region* r = get_region(k); |
438 |
if (r) { |
if (r) { |
439 |
region = r; |
region = r; |
440 |
queue_draw(); |
queue_draw(); |
441 |
region_selected(); |
region_selected(); |
442 |
|
dimensionManager.set_region(region); |
443 |
popup_menu_inside_region->popup(event->button, event->time); |
popup_menu_inside_region->popup(event->button, event->time); |
444 |
} else { |
} else { |
445 |
new_region_pos = k; |
new_region_pos = k; |
459 |
region = r; |
region = r; |
460 |
queue_draw(); |
queue_draw(); |
461 |
region_selected(); |
region_selected(); |
462 |
|
dimensionManager.set_region(region); |
463 |
|
|
464 |
get_window()->pointer_grab(false, |
get_window()->pointer_grab(false, |
465 |
Gdk::BUTTON_RELEASE_MASK | |
Gdk::BUTTON_RELEASE_MASK | |
479 |
{ |
{ |
480 |
gig::Region* prev_region = 0; |
gig::Region* prev_region = 0; |
481 |
gig::Region* next_region; |
gig::Region* next_region; |
482 |
for (gig::Region *r = instrument->GetFirstRegion() ; r ; |
for (gig::Region *r = regions.first() ; r ; r = next_region) { |
483 |
r = next_region) { |
next_region = regions.next(); |
|
next_region = instrument->GetNextRegion(); |
|
484 |
|
|
485 |
if (key < r->KeyRange.low) return 0; |
if (key < r->KeyRange.low) return 0; |
486 |
if (key <= r->KeyRange.high) { |
if (key <= r->KeyRange.high) { |
495 |
|
|
496 |
void RegionChooser::motion_resize_region(int x, int y) |
void RegionChooser::motion_resize_region(int x, int y) |
497 |
{ |
{ |
498 |
const int w = width - 1; |
const int w = get_width() - 1; |
499 |
Glib::RefPtr<Gdk::Window> window = get_window(); |
Glib::RefPtr<Gdk::Window> window = get_window(); |
500 |
|
|
501 |
int k = int(double(x) / w * 128.0 + 0.5); |
int k = int(double(x) / w * 128.0 + 0.5); |
552 |
|
|
553 |
void RegionChooser::motion_move_region(int x, int y) |
void RegionChooser::motion_move_region(int x, int y) |
554 |
{ |
{ |
555 |
const int w = width - 1; |
const int w = get_width() - 1; |
556 |
Glib::RefPtr<Gdk::Window> window = get_window(); |
Glib::RefPtr<Gdk::Window> window = get_window(); |
557 |
|
|
558 |
int k = int(double(x - move.from_x) / w * 128.0 + 0.5); |
int k = int(double(x - move.from_x) / w * 128.0 + 0.5); |
562 |
bool new_touch_right; |
bool new_touch_right; |
563 |
int a = 0; |
int a = 0; |
564 |
if (k > move.pos) { |
if (k > move.pos) { |
565 |
for (gig::Region* r = instrument->GetFirstRegion() ; ; |
for (gig::Region* r = regions.first() ; ; r = regions.next()) { |
|
r = instrument->GetNextRegion()) { |
|
566 |
if (r != region) { |
if (r != region) { |
567 |
int b = r ? r->KeyRange.low : 128; |
int b = r ? r->KeyRange.low : 128; |
568 |
|
|
592 |
} |
} |
593 |
} |
} |
594 |
} else { |
} else { |
595 |
for (gig::Region* r = instrument->GetFirstRegion() ; ; |
for (gig::Region* r = regions.first() ; ; r = regions.next()) { |
|
r = instrument->GetNextRegion()) { |
|
596 |
if (r != region) { |
if (r != region) { |
597 |
int b = r ? r->KeyRange.low : 128; |
int b = r ? r->KeyRange.low : 128; |
598 |
|
|
670 |
Gdk::ModifierType state = Gdk::ModifierType(0); |
Gdk::ModifierType state = Gdk::ModifierType(0); |
671 |
window->get_pointer(x, y, state); |
window->get_pointer(x, y, state); |
672 |
|
|
673 |
|
// handle virtual MIDI keyboard |
674 |
|
if (m_VirtKeybModeChoice.get_value() != VIRT_KEYBOARD_MODE_CHORD && |
675 |
|
currentActiveKey > 0 && |
676 |
|
event->y >= REGION_BLOCK_HEIGHT && |
677 |
|
event->y < REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT) |
678 |
|
{ |
679 |
|
const int k = int(event->x / (get_width() - 1) * 128.0); |
680 |
|
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
681 |
|
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
682 |
|
if (velocity <= 0) velocity = 1; |
683 |
|
keyboard_key_released_signal.emit(currentActiveKey, velocity); |
684 |
|
currentActiveKey = k; |
685 |
|
keyboard_key_hit_signal.emit(k, velocity); |
686 |
|
} |
687 |
|
|
688 |
if (resize.active) { |
if (resize.active) { |
689 |
motion_resize_region(x, y); |
motion_resize_region(x, y); |
690 |
} else if (move.active) { |
} else if (move.active) { |
705 |
} |
} |
706 |
|
|
707 |
bool RegionChooser::is_in_resize_zone(double x, double y) { |
bool RegionChooser::is_in_resize_zone(double x, double y) { |
708 |
const int w = width - 1; |
const int w = get_width() - 1; |
709 |
|
|
710 |
if (instrument && y >= 0 && y <= h1) { |
if (instrument && y >= 0 && y <= h1) { |
711 |
gig::Region* prev_region = 0; |
gig::Region* prev_region = 0; |
712 |
gig::Region* next_region; |
gig::Region* next_region; |
713 |
for (gig::Region* r = instrument->GetFirstRegion() ; r ; r = next_region) { |
for (gig::Region* r = regions.first(); r ; r = next_region) { |
714 |
next_region = instrument->GetNextRegion(); |
next_region = regions.next(); |
715 |
|
|
716 |
int lo = int(w * (r->KeyRange.low) / 128.0 + 0.5); |
int lo = int(w * (r->KeyRange.low) / 128.0 + 0.5); |
717 |
if (x <= lo - 2) break; |
if (x <= lo - 2) break; |
727 |
resize.mode = resize.undecided; |
resize.mode = resize.undecided; |
728 |
resize.min = prev_region->KeyRange.low + 1; |
resize.min = prev_region->KeyRange.low + 1; |
729 |
resize.prev_region = prev_region; |
resize.prev_region = prev_region; |
730 |
return true; |
return resize.min != resize.max; |
731 |
} |
} |
732 |
|
|
733 |
// edit low limit |
// edit low limit |
734 |
resize.mode = resize.moving_low_limit; |
resize.mode = resize.moving_low_limit; |
735 |
resize.min = prev_region ? prev_region->KeyRange.high + 1 : 0; |
resize.min = prev_region ? prev_region->KeyRange.high + 1 : 0; |
736 |
return true; |
return resize.min != resize.max; |
737 |
} |
} |
738 |
if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) { |
if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) { |
739 |
int hi = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5); |
int hi = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5); |
745 |
resize.mode = resize.moving_high_limit; |
resize.mode = resize.moving_high_limit; |
746 |
resize.min = r->KeyRange.low + 1; |
resize.min = r->KeyRange.low + 1; |
747 |
resize.max = next_region ? next_region->KeyRange.low : 128; |
resize.max = next_region ? next_region->KeyRange.low : 128; |
748 |
return true; |
return resize.min != resize.max; |
749 |
} |
} |
750 |
} |
} |
751 |
prev_region = r; |
prev_region = r; |
767 |
void RegionChooser::show_region_properties() |
void RegionChooser::show_region_properties() |
768 |
{ |
{ |
769 |
if (!region) return; |
if (!region) return; |
770 |
Gtk::Dialog dialog("Region Properties", true /*modal*/); |
Gtk::Dialog dialog(_("Region Properties"), true /*modal*/); |
771 |
// add "Keygroup" checkbox |
// add "Keygroup" checkbox |
772 |
Gtk::CheckButton checkBoxKeygroup("Member of a Keygroup (Exclusive Group)"); |
Gtk::CheckButton checkBoxKeygroup(_("Member of a Keygroup (Exclusive Group)")); |
773 |
checkBoxKeygroup.set_active(region->KeyGroup); |
checkBoxKeygroup.set_active(region->KeyGroup); |
774 |
dialog.get_vbox()->pack_start(checkBoxKeygroup); |
dialog.get_vbox()->pack_start(checkBoxKeygroup); |
775 |
checkBoxKeygroup.show(); |
checkBoxKeygroup.show(); |
797 |
region->SetKeyRange(new_region_pos, new_region_pos); |
region->SetKeyRange(new_region_pos, new_region_pos); |
798 |
|
|
799 |
instrument_struct_changed_signal.emit(instrument); |
instrument_struct_changed_signal.emit(instrument); |
800 |
|
regions.update(instrument); |
801 |
|
|
802 |
queue_draw(); |
queue_draw(); |
803 |
region_selected(); |
region_selected(); |
804 |
|
dimensionManager.set_region(region); |
805 |
instrument_changed(); |
instrument_changed(); |
806 |
} |
} |
807 |
|
|
810 |
instrument_struct_to_be_changed_signal.emit(instrument); |
instrument_struct_to_be_changed_signal.emit(instrument); |
811 |
instrument->DeleteRegion(region); |
instrument->DeleteRegion(region); |
812 |
instrument_struct_changed_signal.emit(instrument); |
instrument_struct_changed_signal.emit(instrument); |
813 |
|
regions.update(instrument); |
814 |
|
|
815 |
region = 0; |
region = 0; |
816 |
queue_draw(); |
queue_draw(); |
817 |
region_selected(); |
region_selected(); |
818 |
|
dimensionManager.set_region(region); |
819 |
instrument_changed(); |
instrument_changed(); |
820 |
} |
} |
821 |
|
|
846 |
sigc::signal<void, gig::Region*>& RegionChooser::signal_region_changed_signal() { |
sigc::signal<void, gig::Region*>& RegionChooser::signal_region_changed_signal() { |
847 |
return region_changed_signal; |
return region_changed_signal; |
848 |
} |
} |
849 |
|
|
850 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& RegionChooser::signal_keyboard_key_hit() { |
851 |
|
return keyboard_key_hit_signal; |
852 |
|
} |
853 |
|
|
854 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& RegionChooser::signal_keyboard_key_released() { |
855 |
|
return keyboard_key_released_signal; |
856 |
|
} |