/[svn]/gigedit/trunk/src/dimregionchooser.cpp
ViewVC logotype

Annotation of /gigedit/trunk/src/dimregionchooser.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1077 - (hide annotations) (download)
Tue Mar 6 18:34:47 2007 UTC (14 years, 7 months ago) by persson
File size: 15153 byte(s)
- added strings for "smart midi" and "round robin keyboard" dimensions

1 persson 1052 /*
2     * Copyright (C) 2006, 2007 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     #include "dimregionchooser.h"
21    
22     DimRegionChooser::DimRegionChooser()
23     {
24     // get_window() would return 0 because the Gdk::Window has not yet been realized
25     // So we can only allocate the colors here - the rest will happen in on_realize().
26     Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
27    
28     black = Gdk::Color("black");
29     white = Gdk::Color("white");
30     red = Gdk::Color("#8070ff");
31     blue = Gdk::Color("blue");
32     green = Gdk::Color("green");
33    
34     colormap->alloc_color(black);
35     colormap->alloc_color(white);
36     colormap->alloc_color(red);
37     colormap->alloc_color(blue);
38     colormap->alloc_color(green);
39     instrument = 0;
40     region = 0;
41     dimregno = -1;
42     focus_line = 0;
43     set_flags(Gtk::CAN_FOCUS);
44     add_events(Gdk::BUTTON_PRESS_MASK);
45    
46     for (int i = 0 ; i < 256 ; i++) {
47     dimvalue_from[i] = 0;
48     dimvalue_to[i] = 1;
49     }
50     }
51    
52     DimRegionChooser::~DimRegionChooser()
53     {
54     }
55    
56     void DimRegionChooser::on_realize()
57     {
58     // We need to call the base on_realize()
59     Gtk::DrawingArea::on_realize();
60    
61     // Now we can allocate any additional resources we need
62     Glib::RefPtr<Gdk::Window> window = get_window();
63     gc = Gdk::GC::create(window);
64     }
65    
66     bool DimRegionChooser::on_expose_event(GdkEventExpose* event)
67     {
68     if (!region) return true;
69    
70     // This is where we draw on the window
71     Glib::RefPtr<Gdk::Window> window = get_window();
72     Glib::RefPtr<Pango::Context> context = get_pango_context();
73    
74     Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
75    
76     window->clear();
77     const int h = 20;
78     const int w = 800;
79     const int w1 = 100;
80     int y = 0;
81 persson 1071 int bitpos = 0;
82 persson 1052 for (int i = 0 ; i < region->Dimensions ; i++) {
83 persson 1071
84     int nbZones = region->pDimensionDefinitions[i].zones;
85     if (nbZones) {
86 persson 1052 char* dstr;
87 persson 1071 char dstrbuf[10];
88 persson 1052 switch (region->pDimensionDefinitions[i].dimension) {
89     case gig::dimension_none: dstr="none"; break;
90     case gig::dimension_samplechannel: dstr="samplechannel"; break;
91     case gig::dimension_layer: dstr="layer"; break;
92     case gig::dimension_velocity: dstr="velocity"; break;
93     case gig::dimension_channelaftertouch: dstr="channelaftertouch"; break;
94     case gig::dimension_releasetrigger: dstr="releasetrigger"; break;
95     case gig::dimension_keyboard: dstr="keyboard"; break;
96     case gig::dimension_roundrobin: dstr="roundrobin"; break;
97     case gig::dimension_random: dstr="random"; break;
98 persson 1077 case gig::dimension_smartmidi: dstr="smartmidi"; break;
99     case gig::dimension_roundrobinkeyboard: dstr="roundrobinkeyboard"; break;
100 persson 1052 case gig::dimension_modwheel: dstr="modwheel"; break;
101     case gig::dimension_breath: dstr="breath"; break;
102     case gig::dimension_foot: dstr="foot"; break;
103     case gig::dimension_portamentotime: dstr="portamentotime"; break;
104     case gig::dimension_effect1: dstr="effect1"; break;
105     case gig::dimension_effect2: dstr="effect2"; break;
106     case gig::dimension_genpurpose1: dstr="genpurpose1"; break;
107     case gig::dimension_genpurpose2: dstr="genpurpose2"; break;
108     case gig::dimension_genpurpose3: dstr="genpurpose3"; break;
109     case gig::dimension_genpurpose4: dstr="genpurpose4"; break;
110     case gig::dimension_sustainpedal: dstr="sustainpedal"; break;
111     case gig::dimension_portamento: dstr="portamento"; break;
112     case gig::dimension_sostenutopedal: dstr="sostenutopedal"; break;
113     case gig::dimension_softpedal: dstr="softpedal"; break;
114     case gig::dimension_genpurpose5: dstr="genpurpose5"; break;
115     case gig::dimension_genpurpose6: dstr="genpurpose6"; break;
116     case gig::dimension_genpurpose7: dstr="genpurpose7"; break;
117     case gig::dimension_genpurpose8: dstr="genpurpose8"; break;
118     case gig::dimension_effect1depth: dstr="effect1depth"; break;
119     case gig::dimension_effect2depth: dstr="effect2depth"; break;
120     case gig::dimension_effect3depth: dstr="effect3depth"; break;
121     case gig::dimension_effect4depth: dstr="effect4depth"; break;
122     case gig::dimension_effect5depth: dstr="effect5depth"; break;
123 persson 1071 default:
124     sprintf(dstrbuf, "%d",
125     region->pDimensionDefinitions[i].dimension);
126     dstr = dstrbuf;
127     break;
128 persson 1052 }
129     layout->set_text(dstr);
130    
131     Pango::Rectangle rectangle = layout->get_logical_extents();
132     double text_h = double(rectangle.get_height()) / Pango::SCALE;
133     Glib::RefPtr<const Gdk::GC> fg = get_style()->get_fg_gc(get_state());
134     window->draw_layout(fg, 4, int(y + (h - text_h) / 2 + 0.5), layout);
135    
136     if (has_focus() && focus_line == i) {
137     Gdk::Rectangle farea(0, y, 50, 20);
138     get_style()->paint_focus(window, get_state(), farea, *this, "hejsan", 0, y, 50, 20);
139     }
140    
141     Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
142     window->draw_line(black, w1, y, w - 1, y);
143     window->draw_line(black, w - 1, y + h - 1, w1, y + h - 1);
144     window->draw_rectangle(get_style()->get_white_gc(), true, w1 + 1, y + 1, (w - w1 - 2), h - 2);
145    
146 persson 1071 int c = 0;
147     if (dimregno >= 0) {
148     int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos);
149     c = dimregno & mask; // mask away this dimension
150     }
151     bool customsplits =
152     ((region->pDimensionDefinitions[i].split_type == gig::split_type_normal &&
153     region->pDimensionRegions[c]->DimensionUpperLimits[i]) ||
154     (region->pDimensionDefinitions[i].dimension == gig::dimension_velocity &&
155     region->pDimensionRegions[c]->VelocityUpperLimit));
156    
157     if (customsplits) {
158 persson 1052 window->draw_line(black, w1, y + 1, w1, y + h - 2);
159 persson 1071 for (int j = 0 ; j < nbZones ; j++) {
160     gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
161     int upperLimit = d->DimensionUpperLimits[i];
162     if (!upperLimit) upperLimit = d->VelocityUpperLimit;
163     int v = upperLimit + 1;
164 persson 1052 int x = int((w - w1 - 1) * v / 128.0 + 0.5);
165     window->draw_line(black, w1 + x, y + 1, w1 + x, y + h - 2);
166     }
167     } else {
168 persson 1071 for (int j = 0 ; j <= nbZones ; j++) {
169     int x = int((w - w1 - 1) * j / double(nbZones) + 0.5);
170 persson 1052 window->draw_line(black, w1 + x, y + 1, w1 + x, y + h - 2);
171     }
172     }
173    
174     if (dimregno >= 0) {
175     gc->set_foreground(red);
176 persson 1071 int dr = (dimregno >> bitpos) & ((1 << region->pDimensionDefinitions[i].bits) - 1);
177     if (customsplits) {
178     int x1 = 0;
179     for (int j = 0 ; j < nbZones ; j++) {
180     gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)];
181     int upperLimit = d->DimensionUpperLimits[i];
182     if (!upperLimit) upperLimit = d->VelocityUpperLimit;
183     int v = upperLimit + 1;
184 persson 1052 int x2 = int((w - w1 - 1) * v / 128.0 + 0.5);
185 persson 1071 if (j == dr && x1 < x2) {
186 persson 1052 window->draw_rectangle(gc, true, w1 + x1 + 1, y + 1, (x2 - x1) - 1, h - 2);
187     break;
188     }
189     x1 = x2;
190     }
191     } else {
192 persson 1071 if (dr < nbZones) {
193     int x1 = int((w - w1 - 1) * dr / double(nbZones) + 0.5);
194     int x2 = int((w - w1 - 1) * (dr + 1) / double(nbZones) + 0.5);
195 persson 1052 window->draw_rectangle(gc, true, w1 + x1 + 1, y + 1, (x2 - x1) - 1, h - 2);
196     }
197     }
198     }
199    
200     y += h;
201     }
202 persson 1071 bitpos += region->pDimensionDefinitions[i].bits;
203 persson 1052 }
204    
205     return true;
206     }
207    
208    
209     void DimRegionChooser::on_size_request(GtkRequisition* requisition)
210     {
211     printf("DimRegionChooser::on_size_request\n");
212     *requisition = GtkRequisition();
213     requisition->height = region ? region->Dimensions * 20 : 0;
214     requisition->width = 800;
215     }
216    
217     void DimRegionChooser::set_instrument(gig::Instrument* instrument)
218     {
219     this->instrument = instrument;
220     this->region = 0;
221     this->dimregno = -1;
222     queue_draw();
223     }
224    
225     void DimRegionChooser::set_region(gig::Region* region)
226     {
227     this->region = region;
228     dimregno = 0;
229     int bitcount = 0;
230     for (int dim = 0 ; dim < region->Dimensions ; dim++) {
231     int from = dimvalue_from[region->pDimensionDefinitions[dim].dimension];
232     int to = dimvalue_to[region->pDimensionDefinitions[dim].dimension];
233     int z;
234     switch (region->pDimensionDefinitions[dim].split_type) {
235     case gig::split_type_normal:
236     z = int((to + from) / 2.0 / region->pDimensionDefinitions[dim].zone_size);
237     break;
238     case gig::split_type_bit:
239     z = std::min(from, region->pDimensionDefinitions[dim].zones - 1);
240     break;
241     }
242     int mask =
243     ~(((1 << region->pDimensionDefinitions[dim].bits) - 1) <<
244     bitcount);
245     dimregno &= mask;
246     dimregno |= (z << bitcount);
247     bitcount += region->pDimensionDefinitions[dim].bits;
248     }
249     dimreg = region->pDimensionRegions[dimregno];
250     sel_changed_signal.emit();
251     queue_resize();
252     }
253    
254     /*
255     void DimRegionChooser::set_dimregno(int x) {
256     this->dimregno = x;
257     queue_draw();
258     }
259     */
260    
261     bool DimRegionChooser::on_button_press_event(GdkEventButton* event)
262     {
263     const int h = 20;
264     const int w = 800;
265     const int w1 = 100;
266    
267     if (region) {
268     if (event->y < region->Dimensions * h &&
269     event->x >= w1 && event->x < w) {
270    
271     int dim = int(event->y / h);
272 persson 1071 int nbZones = region->pDimensionDefinitions[dim].zones;
273 persson 1052
274     int z = -1;
275 persson 1071 int bitpos = 0;
276     for (int i = 0 ; i < dim ; i++) {
277     bitpos += region->pDimensionDefinitions[i].bits;
278     }
279 persson 1052
280 persson 1071 int i = dim;
281     if (dimregno < 0) dimregno = 0;
282     int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos);
283     int c = dimregno & mask; // mask away this dimension
284 persson 1052
285 persson 1071 bool customsplits =
286     ((region->pDimensionDefinitions[i].split_type == gig::split_type_normal &&
287     region->pDimensionRegions[c]->DimensionUpperLimits[i]) ||
288     (region->pDimensionDefinitions[i].dimension == gig::dimension_velocity &&
289     region->pDimensionRegions[c]->VelocityUpperLimit));
290     if (customsplits) {
291     int val = int((event->x - w1) * 128 / (w - w1 - 1));
292    
293     if (region->pDimensionRegions[c]->DimensionUpperLimits[i]) {
294     for (z = 0 ; z < nbZones ; z++) {
295     gig::DimensionRegion *d = region->pDimensionRegions[c + (z << bitpos)];
296     if (val <= d->DimensionUpperLimits[i]) break;
297 persson 1052 }
298 persson 1071 } else {
299     for (z = 0 ; z < nbZones ; z++) {
300     gig::DimensionRegion *d = region->pDimensionRegions[c + (z << bitpos)];
301     if (val <= d->VelocityUpperLimit) break;
302     }
303 persson 1052 }
304 persson 1071 } else {
305     z = int((event->x - w1) * nbZones / (w - w1 - 1));
306 persson 1052 }
307    
308     printf("dim=%d z=%d dimensionsource=%d split_type=%d zones=%d zone_size=%f\n", dim, z,
309     region->pDimensionDefinitions[dim].dimension,
310     region->pDimensionDefinitions[dim].split_type,
311     region->pDimensionDefinitions[dim].zones,
312     region->pDimensionDefinitions[dim].zone_size);
313 persson 1071 #if 0
314 persson 1052 switch (region->pDimensionDefinitions[dim].split_type) {
315     case gig::split_type_normal:
316     dimvalue_from[region->pDimensionDefinitions[dim].dimension] =
317     int(z * region->pDimensionDefinitions[dim].zone_size);
318     dimvalue_to[region->pDimensionDefinitions[dim].dimension] =
319     int((z + 1) * region->pDimensionDefinitions[dim].zone_size) - 1;
320     break;
321     case gig::split_type_bit:
322     dimvalue_from[region->pDimensionDefinitions[dim].dimension] = z;
323     dimvalue_to[region->pDimensionDefinitions[dim].dimension] = z + 1;
324     break;
325     }
326 persson 1071 #endif
327 persson 1052
328 persson 1071 dimregno = c | (z << bitpos);
329 persson 1052
330     focus_line = dim;
331     if (has_focus()) queue_draw();
332     else grab_focus();
333     dimreg = region->pDimensionRegions[dimregno];
334     sel_changed_signal.emit();
335     }
336     }
337     return true;
338     }
339    
340     sigc::signal<void> DimRegionChooser::signal_sel_changed()
341     {
342     return sel_changed_signal;
343     }
344    
345     bool DimRegionChooser::on_focus(Gtk::DirectionType direction)
346     {
347     // TODO: kolla att region finns osv, dvs att det g�r att s�tta
348     // fokus.
349     if (direction == Gtk::DIR_TAB_FORWARD ||
350     direction == Gtk::DIR_DOWN) {
351     if (!has_focus()) {
352     focus_line = 0;
353     grab_focus();
354     return true;
355     } else {
356     if (focus_line + 1 < region->Dimensions) {
357     focus_line++;
358     queue_draw();
359     return true;
360     } else {
361     return false;
362     }
363     }
364     } else if (direction == Gtk::DIR_TAB_BACKWARD ||
365     direction == Gtk::DIR_UP) {
366     if (!has_focus()) {
367     focus_line = region->Dimensions - 1;
368     grab_focus();
369     return true;
370     } else {
371     if (focus_line > 0) {
372     focus_line--;
373     queue_draw();
374     return true;
375     } else {
376     return false;
377     }
378     }
379     } else if (!has_focus()) {
380     // TODO: kolla att focus_line finns!
381     grab_focus();
382     return true;
383     } else {
384     // TODO: �ka eller minska v�rde!
385     }
386     }

  ViewVC Help
Powered by ViewVC