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

Annotation of /gigedit/trunk/src/gigedit/regionchooser.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3123 - (hide annotations) (download) (as text)
Tue Apr 25 20:45:54 2017 UTC (7 years ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6180 byte(s)
* Implemented fast navigation through regions by keyboard accelerator
  Ctrl+Left and Ctrl+Right (on Mac: Cmd+Left and Cmd+Right).
* Implemented fast navigation through dimension region zones of currently
  selected region by keyboard accelerator Alt+Left, Alt+Right, Alt+Up,
  Alt+Down, as well as simply using the arrow keys alone if the dimension
  region chooser got focus (i.e. when it was selected by mouse previously).
* Bumped version (1.0.0.svn29).

1 schoenebeck 1225 /* -*- c++ -*-
2 schoenebeck 3068 * Copyright (C) 2006-2017 Andreas Persson
3 schoenebeck 1225 *
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     #ifndef GIGEDIT_REGIONCHOOSER_H
21     #define GIGEDIT_REGIONCHOOSER_H
22    
23 persson 1623 #include <vector>
24    
25 persson 2844 #include <gtkmm/box.h>
26 schoenebeck 1225 #include <gtkmm/drawingarea.h>
27     #include <gtkmm/uimanager.h>
28     #include <gdkmm/window.h>
29     #include <gtkmm/menu.h>
30    
31     #include "dimensionmanager.h"
32 schoenebeck 1661 #include "paramedit.h"
33 persson 2169 #include "compat.h"
34 schoenebeck 1225
35 schoenebeck 3068 #ifdef LIBGIG_HEADER_FILE
36     # include LIBGIG_HEADER_FILE(gig.h)
37     #else
38     # include <gig.h>
39     #endif
40 schoenebeck 1225
41 schoenebeck 1661 enum virt_keyboard_mode_t {
42     VIRT_KEYBOARD_MODE_NORMAL,
43     VIRT_KEYBOARD_MODE_CHORD
44     };
45    
46 persson 1623 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 persson 2841 bool operator() (gig::Region* x, gig::Region* y) const {
56 persson 1623 return x->KeyRange.low < y->KeyRange.low;
57     }
58     };
59    
60 schoenebeck 1225 class RegionChooser : public Gtk::DrawingArea
61     {
62     public:
63     RegionChooser();
64     virtual ~RegionChooser();
65    
66     void set_instrument(gig::Instrument* instrument);
67    
68 schoenebeck 1339 sigc::signal<void>& signal_region_selected();
69     sigc::signal<void>& signal_instrument_changed();
70 schoenebeck 1225
71 schoenebeck 1339 sigc::signal<void, gig::Instrument*>& signal_instrument_struct_to_be_changed();
72     sigc::signal<void, gig::Instrument*>& signal_instrument_struct_changed();
73 schoenebeck 1322
74 schoenebeck 1339 sigc::signal<void, gig::Region*>& signal_region_to_be_changed();
75     sigc::signal<void, gig::Region*>& signal_region_changed_signal();
76 schoenebeck 1322
77 schoenebeck 1660 sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_hit();
78     sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_released();
79    
80 schoenebeck 1225 gig::Region* get_region() { return region; }
81 schoenebeck 2695 void set_region(gig::Region* region);
82 schoenebeck 3123 void select_next_region();
83     void select_prev_region();
84 schoenebeck 1225
85 schoenebeck 1654 void on_note_on_event(int key, int velocity);
86     void on_note_off_event(int key, int velocity);
87    
88 schoenebeck 1661 Gtk::HBox m_VirtKeybPropsBox;
89    
90 schoenebeck 1225 protected:
91 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
92 schoenebeck 1225 virtual bool on_expose_event(GdkEventExpose* e);
93 persson 2246 #else
94     virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
95 persson 2169 #endif
96 schoenebeck 1225 virtual bool on_button_press_event(GdkEventButton* event);
97     virtual bool on_button_release_event(GdkEventButton* event);
98     virtual bool on_motion_notify_event(GdkEventMotion* event);
99    
100     gig::Region* get_region(int key);
101    
102 persson 2169 Gdk::RGBA activeKeyColor, red, grey1, white, black;
103 schoenebeck 1225
104 persson 1261 sigc::signal<void> region_selected;
105     sigc::signal<void> instrument_changed;
106 schoenebeck 1225
107 schoenebeck 1322 sigc::signal<void, gig::Instrument*> instrument_struct_to_be_changed_signal;
108     sigc::signal<void, gig::Instrument*> instrument_struct_changed_signal;
109    
110     sigc::signal<void, gig::Region*> region_to_be_changed_signal;
111     sigc::signal<void, gig::Region*> region_changed_signal;
112    
113 schoenebeck 1660 sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_hit_signal;
114     sigc::signal<void, int/*key*/, int/*velocity*/> keyboard_key_released_signal;
115    
116 schoenebeck 1225 gig::Instrument* instrument;
117     gig::Region* region;
118 persson 1623 SortedRegions regions;
119 schoenebeck 1225
120 schoenebeck 1654 bool is_black_key(int key);
121 persson 2246 void draw_keyboard(const Cairo::RefPtr<Cairo::Context>& cr,
122     int clip_low, int clip_high);
123     void draw_regions(const Cairo::RefPtr<Cairo::Context>& cr,
124     int clip_low, int clip_high);
125     void draw_key(const Cairo::RefPtr<Cairo::Context>& cr, int key);
126     void draw_digit(const Cairo::RefPtr<Cairo::Context>& cr, int key);
127 persson 1262 void motion_resize_region(int x, int y);
128     void motion_move_region(int x, int y);
129 persson 2246 void update_after_resize();
130     void update_after_move(int pos);
131     void invalidate_key(int key);
132 persson 1262
133 persson 2246 // returns the leftmost pixel of a key
134     int key_to_x(double k, int w) const {
135     return int(k * w / 128.0 + 0.5);
136     }
137    
138     // returns the key given a pixel
139     int x_to_key(double x, int w) const {
140     return int(x / w * 128.0);
141     }
142    
143     // returns the key given a pixel. If the pixel is the border
144     // between two keys, the key to the r�ght is always returned.
145     int x_to_key_right(double x, int w) const {
146     return int(ceil((x + 0.5) / w * 128.0)) - 1;
147     }
148    
149 schoenebeck 1225 // information needed during a resize
150     struct {
151     bool active;
152     enum {
153     undecided,
154     moving_high_limit,
155     moving_low_limit
156     } mode;
157     int pos;
158     int min;
159     int max;
160     gig::Region* region;
161     gig::Region* prev_region;
162     } resize;
163    
164 persson 1262 // information needed during a region move
165     struct {
166     bool active;
167 persson 2246 int offset;
168 persson 1262 } move;
169    
170 schoenebeck 1225 bool cursor_is_resize;
171     bool is_in_resize_zone(double x, double y);
172    
173     int h1;
174    
175     Gtk::Menu* popup_menu_inside_region;
176     Gtk::Menu* popup_menu_outside_region;
177     void show_region_properties();
178     void add_region();
179     void delete_region();
180     void manage_dimensions();
181     void on_dimension_manager_changed();
182     int new_region_pos;
183    
184     Glib::RefPtr<Gtk::ActionGroup> actionGroup;
185     Glib::RefPtr<Gtk::UIManager> uiManager;
186    
187 persson 2246 // properties of the virtual keyboard
188 schoenebeck 1661 ChoiceEntry<virt_keyboard_mode_t> m_VirtKeybModeChoice;
189     Gtk::Label m_VirtKeybVelocityLabelDescr;
190     Gtk::Label m_VirtKeybVelocityLabel;
191     Gtk::Label m_VirtKeybOffVelocityLabelDescr;
192     Gtk::Label m_VirtKeybOffVelocityLabel;
193     int currentActiveKey;
194 persson 2246 bool key_pressed[128];
195 schoenebeck 1661
196 schoenebeck 1225 DimensionManager dimensionManager;
197     };
198    
199     #endif

  ViewVC Help
Powered by ViewVC