1 |
/* -*- c++ -*- |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2017 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 |
20 |
#ifndef GIGEDIT_REGIONCHOOSER_H |
#ifndef GIGEDIT_REGIONCHOOSER_H |
21 |
#define GIGEDIT_REGIONCHOOSER_H |
#define GIGEDIT_REGIONCHOOSER_H |
22 |
|
|
23 |
|
#include <vector> |
24 |
|
|
25 |
|
#include <gtkmm/box.h> |
26 |
#include <gtkmm/drawingarea.h> |
#include <gtkmm/drawingarea.h> |
|
#include <gdkmm/colormap.h> |
|
27 |
#include <gtkmm/uimanager.h> |
#include <gtkmm/uimanager.h> |
28 |
#include <gdkmm/window.h> |
#include <gdkmm/window.h> |
29 |
#include <gtkmm/menu.h> |
#include <gtkmm/menu.h> |
30 |
|
|
31 |
#include "dimensionmanager.h" |
#include "dimensionmanager.h" |
32 |
|
#include "paramedit.h" |
33 |
|
#include "compat.h" |
34 |
|
|
35 |
|
#ifdef LIBGIG_HEADER_FILE |
36 |
|
# include LIBGIG_HEADER_FILE(gig.h) |
37 |
|
#else |
38 |
|
# include <gig.h> |
39 |
|
#endif |
40 |
|
|
41 |
|
enum virt_keyboard_mode_t { |
42 |
|
VIRT_KEYBOARD_MODE_NORMAL, |
43 |
|
VIRT_KEYBOARD_MODE_CHORD |
44 |
|
}; |
45 |
|
|
46 |
#include <gig.h> |
class SortedRegions { |
47 |
|
private: |
48 |
|
std::vector<gig::Region*> regions; |
49 |
|
std::vector<gig::Region*>::iterator region_iterator; |
50 |
|
|
51 |
|
public: |
52 |
|
void update(gig::Instrument* instrument); |
53 |
|
gig::Region* first(); |
54 |
|
gig::Region* next(); |
55 |
|
bool operator() (gig::Region* x, gig::Region* y) const { |
56 |
|
return x->KeyRange.low < y->KeyRange.low; |
57 |
|
} |
58 |
|
}; |
59 |
|
|
60 |
class RegionChooser : public Gtk::DrawingArea |
class RegionChooser : public Gtk::DrawingArea |
61 |
{ |
{ |
65 |
|
|
66 |
void set_instrument(gig::Instrument* instrument); |
void set_instrument(gig::Instrument* instrument); |
67 |
|
|
68 |
sigc::signal<void> signal_region_selected(); |
// ATM only used for painting auto selected regions with gray hatched pattern |
69 |
sigc::signal<void> signal_instrument_changed(); |
void setModifyAllRegions(bool b); |
70 |
|
|
71 |
|
sigc::signal<void>& signal_region_selected(); |
72 |
|
sigc::signal<void>& signal_instrument_changed(); |
73 |
|
|
74 |
|
sigc::signal<void, gig::Instrument*>& signal_instrument_struct_to_be_changed(); |
75 |
|
sigc::signal<void, gig::Instrument*>& signal_instrument_struct_changed(); |
76 |
|
|
77 |
|
sigc::signal<void, gig::Region*>& signal_region_to_be_changed(); |
78 |
|
sigc::signal<void, gig::Region*>& signal_region_changed_signal(); |
79 |
|
|
80 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_hit(); |
81 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_released(); |
82 |
|
|
83 |
gig::Region* get_region() { return region; } |
gig::Region* get_region() { return region; } |
84 |
|
void set_region(gig::Region* region); |
85 |
|
void select_next_region(); |
86 |
|
void select_prev_region(); |
87 |
|
|
88 |
|
void on_note_on_event(int key, int velocity); |
89 |
|
void on_note_off_event(int key, int velocity); |
90 |
|
|
91 |
|
Gtk::HBox m_VirtKeybPropsBox; |
92 |
|
|
93 |
protected: |
protected: |
94 |
virtual void on_realize(); |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
95 |
virtual bool on_expose_event(GdkEventExpose* e); |
virtual bool on_expose_event(GdkEventExpose* e); |
96 |
virtual void on_size_request(GtkRequisition* requisition); |
#else |
97 |
|
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr); |
98 |
|
#endif |
99 |
virtual bool on_button_press_event(GdkEventButton* event); |
virtual bool on_button_press_event(GdkEventButton* event); |
100 |
virtual bool on_button_release_event(GdkEventButton* event); |
virtual bool on_button_release_event(GdkEventButton* event); |
101 |
virtual bool on_motion_notify_event(GdkEventMotion* event); |
virtual bool on_motion_notify_event(GdkEventMotion* event); |
102 |
|
|
103 |
gig::Region* get_region(int key); |
gig::Region* get_region(int key); |
104 |
|
|
105 |
Glib::RefPtr<Gdk::GC> gc; |
Gdk::RGBA activeKeyColor, blue, grey1, white, black; |
106 |
Gdk::Color blue, red, grey1; |
Glib::RefPtr<Gdk::Pixbuf> grayBlueHatchedPatternARGB; |
107 |
|
Cairo::RefPtr<Cairo::SurfacePattern> grayBlueHatchedSurfacePattern; |
|
void draw_region(int from, int to, const Gdk::Color& color); |
|
108 |
|
|
109 |
sigc::signal<void> region_selected; |
sigc::signal<void> region_selected; |
110 |
sigc::signal<void> instrument_changed; |
sigc::signal<void> instrument_changed; |
111 |
|
|
112 |
|
sigc::signal<void, gig::Instrument*> instrument_struct_to_be_changed_signal; |
113 |
|
sigc::signal<void, gig::Instrument*> instrument_struct_changed_signal; |
114 |
|
|
115 |
|
sigc::signal<void, gig::Region*> region_to_be_changed_signal; |
116 |
|
sigc::signal<void, gig::Region*> region_changed_signal; |
117 |
|
|
118 |
|
sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_hit_signal; |
119 |
|
sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_released_signal; |
120 |
|
|
121 |
gig::Instrument* instrument; |
gig::Instrument* instrument; |
122 |
gig::Region* region; |
gig::Region* region; |
123 |
|
SortedRegions regions; |
124 |
|
|
125 |
|
bool is_black_key(int key); |
126 |
|
void draw_keyboard(const Cairo::RefPtr<Cairo::Context>& cr, |
127 |
|
int clip_low, int clip_high); |
128 |
|
void draw_regions(const Cairo::RefPtr<Cairo::Context>& cr, |
129 |
|
int clip_low, int clip_high); |
130 |
|
void draw_key(const Cairo::RefPtr<Cairo::Context>& cr, int key); |
131 |
|
void draw_digit(const Cairo::RefPtr<Cairo::Context>& cr, int key); |
132 |
void motion_resize_region(int x, int y); |
void motion_resize_region(int x, int y); |
133 |
void motion_move_region(int x, int y); |
void motion_move_region(int x, int y); |
134 |
|
void update_after_resize(); |
135 |
|
void update_after_move(int pos); |
136 |
|
void invalidate_key(int key); |
137 |
|
|
138 |
|
// returns the leftmost pixel of a key |
139 |
|
int key_to_x(double k, int w) const { |
140 |
|
return int(k * w / 128.0 + 0.5); |
141 |
|
} |
142 |
|
|
143 |
|
// returns the key given a pixel |
144 |
|
int x_to_key(double x, int w) const { |
145 |
|
return int(x / w * 128.0); |
146 |
|
} |
147 |
|
|
148 |
|
// returns the key given a pixel. If the pixel is the border |
149 |
|
// between two keys, the key to the ríght is always returned. |
150 |
|
int x_to_key_right(double x, int w) const { |
151 |
|
return int(ceil((x + 0.5) / w * 128.0)) - 1; |
152 |
|
} |
153 |
|
|
154 |
// information needed during a resize |
// information needed during a resize |
155 |
struct { |
struct { |
169 |
// information needed during a region move |
// information needed during a region move |
170 |
struct { |
struct { |
171 |
bool active; |
bool active; |
172 |
double from_x; |
int offset; |
|
int pos; |
|
|
bool touch_left; |
|
|
bool touch_right; |
|
173 |
} move; |
} move; |
174 |
|
|
175 |
bool cursor_is_resize; |
bool cursor_is_resize; |
176 |
bool is_in_resize_zone(double x, double y); |
bool is_in_resize_zone(double x, double y); |
177 |
|
|
178 |
int h1; |
int h1; |
179 |
int width; |
|
180 |
|
// ATM only used for painting auto selected regions with gray hatched pattern |
181 |
|
bool modifyallregions; |
182 |
|
|
183 |
Gtk::Menu* popup_menu_inside_region; |
Gtk::Menu* popup_menu_inside_region; |
184 |
Gtk::Menu* popup_menu_outside_region; |
Gtk::Menu* popup_menu_outside_region; |
192 |
Glib::RefPtr<Gtk::ActionGroup> actionGroup; |
Glib::RefPtr<Gtk::ActionGroup> actionGroup; |
193 |
Glib::RefPtr<Gtk::UIManager> uiManager; |
Glib::RefPtr<Gtk::UIManager> uiManager; |
194 |
|
|
195 |
|
// properties of the virtual keyboard |
196 |
|
ChoiceEntry<virt_keyboard_mode_t> m_VirtKeybModeChoice; |
197 |
|
Gtk::Label m_VirtKeybVelocityLabelDescr; |
198 |
|
Gtk::Label m_VirtKeybVelocityLabel; |
199 |
|
Gtk::Label m_VirtKeybOffVelocityLabelDescr; |
200 |
|
Gtk::Label m_VirtKeybOffVelocityLabel; |
201 |
|
int currentActiveKey; |
202 |
|
bool key_pressed[128]; |
203 |
|
|
204 |
DimensionManager dimensionManager; |
DimensionManager dimensionManager; |
205 |
}; |
}; |
206 |
|
|