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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1658 - (show annotations) (download) (as text)
Sat Feb 2 08:52:48 2008 UTC (16 years, 1 month ago) by persson
File MIME type: text/x-c++hdr
File size: 4328 byte(s)
* fixed the inaccurate drawing of pressed keys

1 /* -*- c++ -*-
2 * Copyright (C) 2006-2008 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 #ifndef GIGEDIT_REGIONCHOOSER_H
21 #define GIGEDIT_REGIONCHOOSER_H
22
23 #include <vector>
24
25 #include <gtkmm/drawingarea.h>
26 #include <gdkmm/colormap.h>
27 #include <gtkmm/uimanager.h>
28 #include <gdkmm/window.h>
29 #include <gtkmm/menu.h>
30
31 #include "dimensionmanager.h"
32
33 #include <gig.h>
34
35 class SortedRegions {
36 private:
37 std::vector<gig::Region*> regions;
38 std::vector<gig::Region*>::iterator region_iterator;
39
40 public:
41 void update(gig::Instrument* instrument);
42 gig::Region* first();
43 gig::Region* next();
44 bool operator() (gig::Region* x, gig::Region* y) {
45 return x->KeyRange.low < y->KeyRange.low;
46 }
47 };
48
49 class RegionChooser : public Gtk::DrawingArea
50 {
51 public:
52 RegionChooser();
53 virtual ~RegionChooser();
54
55 void set_instrument(gig::Instrument* instrument);
56
57 sigc::signal<void>& signal_region_selected();
58 sigc::signal<void>& signal_instrument_changed();
59
60 sigc::signal<void, gig::Instrument*>& signal_instrument_struct_to_be_changed();
61 sigc::signal<void, gig::Instrument*>& signal_instrument_struct_changed();
62
63 sigc::signal<void, gig::Region*>& signal_region_to_be_changed();
64 sigc::signal<void, gig::Region*>& signal_region_changed_signal();
65
66 gig::Region* get_region() { return region; }
67
68 void on_note_on_event(int key, int velocity);
69 void on_note_off_event(int key, int velocity);
70
71 protected:
72 virtual void on_realize();
73 virtual bool on_expose_event(GdkEventExpose* e);
74 virtual void on_size_request(GtkRequisition* requisition);
75 virtual bool on_button_press_event(GdkEventButton* event);
76 virtual bool on_button_release_event(GdkEventButton* event);
77 virtual bool on_motion_notify_event(GdkEventMotion* event);
78
79 gig::Region* get_region(int key);
80
81 Glib::RefPtr<Gdk::GC> gc;
82 Gdk::Color activeKeyColor, red, grey1, white, black;
83
84 sigc::signal<void> region_selected;
85 sigc::signal<void> instrument_changed;
86
87 sigc::signal<void, gig::Instrument*> instrument_struct_to_be_changed_signal;
88 sigc::signal<void, gig::Instrument*> instrument_struct_changed_signal;
89
90 sigc::signal<void, gig::Region*> region_to_be_changed_signal;
91 sigc::signal<void, gig::Region*> region_changed_signal;
92
93 gig::Instrument* instrument;
94 gig::Region* region;
95 SortedRegions regions;
96
97 bool is_black_key(int key);
98 void draw_region(int from, int to, const Gdk::Color& color);
99 void draw_digit(int key);
100 void motion_resize_region(int x, int y);
101 void motion_move_region(int x, int y);
102
103 // information needed during a resize
104 struct {
105 bool active;
106 enum {
107 undecided,
108 moving_high_limit,
109 moving_low_limit
110 } mode;
111 int pos;
112 int min;
113 int max;
114 gig::Region* region;
115 gig::Region* prev_region;
116 } resize;
117
118 // information needed during a region move
119 struct {
120 bool active;
121 double from_x;
122 int pos;
123 bool touch_left;
124 bool touch_right;
125 } move;
126
127 bool cursor_is_resize;
128 bool is_in_resize_zone(double x, double y);
129
130 int h1;
131
132 Gtk::Menu* popup_menu_inside_region;
133 Gtk::Menu* popup_menu_outside_region;
134 void show_region_properties();
135 void add_region();
136 void delete_region();
137 void manage_dimensions();
138 void on_dimension_manager_changed();
139 int new_region_pos;
140
141 Glib::RefPtr<Gtk::ActionGroup> actionGroup;
142 Glib::RefPtr<Gtk::UIManager> uiManager;
143
144 DimensionManager dimensionManager;
145 };
146
147 #endif

  ViewVC Help
Powered by ViewVC