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 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
RegionChooser::RegionChooser() |
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 |
|
|
82 |
cursor_is_resize = false; |
cursor_is_resize = false; |
83 |
h1 = REGION_BLOCK_HEIGHT; |
h1 = REGION_BLOCK_HEIGHT; |
84 |
|
|
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", |
110 |
Gtk::Stock::PROPERTIES), |
Gtk::Stock::PROPERTIES), |
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) { |
void RegionChooser::on_note_on_event(int key, int velocity) { |
173 |
draw_region(key, key+1, activeKeyColor); |
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) { |
void RegionChooser::on_note_off_event(int key, int velocity) { |
179 |
draw_region(key, key+1, black); |
draw_region(key, key+1, black); |
180 |
else |
else |
181 |
draw_region(key, key+1, white); |
draw_region(key, key+1, white); |
182 |
|
m_VirtKeybOffVelocityLabel.set_text(ToString(velocity)); |
183 |
} |
} |
184 |
|
|
185 |
void RegionChooser::on_realize() |
void RegionChooser::on_realize() |
341 |
{ |
{ |
342 |
const int k = int(event->x / (get_width() - 1) * 128.0); |
const int k = int(event->x / (get_width() - 1) * 128.0); |
343 |
|
|
344 |
|
// handle-note off on virtual keyboard |
345 |
if (event->type == GDK_BUTTON_RELEASE) { |
if (event->type == GDK_BUTTON_RELEASE) { |
346 |
if (event->y >= REGION_BLOCK_HEIGHT) { |
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
347 |
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
348 |
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
if (velocity <= 0) velocity = 1; |
349 |
keyboard_key_released_signal.emit(k, velocity); |
switch (m_VirtKeybModeChoice.get_value()) { |
350 |
|
case VIRT_KEYBOARD_MODE_CHORD: |
351 |
|
if (event->y >= REGION_BLOCK_HEIGHT) |
352 |
|
keyboard_key_released_signal.emit(k, velocity); |
353 |
|
break; |
354 |
|
case VIRT_KEYBOARD_MODE_NORMAL: |
355 |
|
default: |
356 |
|
if (currentActiveKey >= 0 && currentActiveKey <= 127) { |
357 |
|
keyboard_key_released_signal.emit(currentActiveKey, velocity); |
358 |
|
currentActiveKey = -1; |
359 |
|
} |
360 |
|
break; |
361 |
} |
} |
362 |
} |
} |
363 |
|
|
426 |
if (event->y >= REGION_BLOCK_HEIGHT) { |
if (event->y >= REGION_BLOCK_HEIGHT) { |
427 |
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
428 |
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
429 |
|
currentActiveKey = k; |
430 |
keyboard_key_hit_signal.emit(k, velocity); |
keyboard_key_hit_signal.emit(k, velocity); |
431 |
} |
} |
432 |
} |
} |
667 |
Gdk::ModifierType state = Gdk::ModifierType(0); |
Gdk::ModifierType state = Gdk::ModifierType(0); |
668 |
window->get_pointer(x, y, state); |
window->get_pointer(x, y, state); |
669 |
|
|
670 |
|
// handle virtual MIDI keyboard |
671 |
|
if (m_VirtKeybModeChoice.get_value() != VIRT_KEYBOARD_MODE_CHORD && |
672 |
|
currentActiveKey > 0 && |
673 |
|
event->y >= REGION_BLOCK_HEIGHT && |
674 |
|
event->y < REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT) |
675 |
|
{ |
676 |
|
const int k = int(event->x / (get_width() - 1) * 128.0); |
677 |
|
int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 : |
678 |
|
int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1; |
679 |
|
if (velocity <= 0) velocity = 1; |
680 |
|
keyboard_key_released_signal.emit(currentActiveKey, velocity); |
681 |
|
currentActiveKey = k; |
682 |
|
keyboard_key_hit_signal.emit(k, velocity); |
683 |
|
} |
684 |
|
|
685 |
if (resize.active) { |
if (resize.active) { |
686 |
motion_resize_region(x, y); |
motion_resize_region(x, y); |
687 |
} else if (move.active) { |
} else if (move.active) { |