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

Diff of /gigedit/trunk/src/gigedit/regionchooser.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1322 by schoenebeck, Tue Sep 4 11:04:56 2007 UTC revision 1898 by persson, Sun May 10 09:35:56 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006, 2007 Andreas Persson   * Copyright (C) 2006-2009 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
# Line 18  Line 18 
18   */   */
19    
20  #include "regionchooser.h"  #include "regionchooser.h"
21    #include <algorithm>
22  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
23  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
24  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
25  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
 #include <libintl.h>  
26  #include <math.h>  #include <math.h>
27    #include <sstream>
28    
29  #define _(String) gettext(String)  #include "global.h"
30    
31  RegionChooser::RegionChooser()  #define REGION_BLOCK_HEIGHT             20
32    #define KEYBOARD_HEIGHT                 40
33    
34    void SortedRegions::update(gig::Instrument* instrument) {
35        // Usually, the regions in a gig file are ordered after their key
36        // range, but there are files where they are not. The
37        // RegionChooser code needs a sorted list of regions.
38        regions.clear();
39        if (instrument) {
40            for (gig::Region *r = instrument->GetFirstRegion() ;
41                 r ;
42                 r = instrument->GetNextRegion()) {
43                regions.push_back(r);
44            }
45            sort(regions.begin(), regions.end(), *this);
46        }
47    }
48    
49    gig::Region* SortedRegions::first() {
50        region_iterator = regions.begin();
51        return region_iterator == regions.end() ? 0 : *region_iterator;
52    }
53    
54    gig::Region* SortedRegions::next() {
55        region_iterator++;
56        return region_iterator == regions.end() ? 0 : *region_iterator;
57    }
58    
59    
60    
61    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    
67      red = Gdk::Color("#8070ff");      red = Gdk::Color("#8070ff");
68      grey1 = Gdk::Color("#b0b0b0");      grey1 = Gdk::Color("#b0b0b0");
69        activeKeyColor = Gdk::Color("#ff0000");
70        white = Gdk::Color("#ffffff");
71        black = Gdk::Color("#000000");
72    
73      colormap->alloc_color(red);      colormap->alloc_color(red);
74      colormap->alloc_color(grey1);      colormap->alloc_color(grey1);
75        colormap->alloc_color(activeKeyColor);
76        colormap->alloc_color(white);
77        colormap->alloc_color(black);
78      instrument = 0;      instrument = 0;
79      region = 0;      region = 0;
80      resize.active = false;      resize.active = false;
81      move.active = false;      move.active = false;
82      cursor_is_resize = false;      cursor_is_resize = false;
83      h1 = 20;      h1 = REGION_BLOCK_HEIGHT;
84      width = 800;  
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",
# Line 90  RegionChooser::RegionChooser() Line 151  RegionChooser::RegionChooser()
151              sigc::mem_fun(*this, &RegionChooser::on_dimension_manager_changed)              sigc::mem_fun(*this, &RegionChooser::on_dimension_manager_changed)
152          )          )
153      );      );
154        keyboard_key_hit_signal.connect(
155            sigc::mem_fun(*this, &RegionChooser::on_note_on_event)
156        );
157        keyboard_key_released_signal.connect(
158            sigc::mem_fun(*this, &RegionChooser::on_note_off_event)
159        );
160  }  }
161    
162  RegionChooser::~RegionChooser()  RegionChooser::~RegionChooser()
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) {
173        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) {
178        if (is_black_key(key)) {
179            draw_region(key, key+1, black);
180        } else {
181            draw_region(key, key+1, key >= 21 && key <= 108 ? white : grey1);
182        }
183        m_VirtKeybOffVelocityLabel.set_text(ToString(velocity));
184    }
185    
186  void RegionChooser::on_realize()  void RegionChooser::on_realize()
187  {  {
188      // We need to call the base on_realize()      // We need to call the base on_realize()
# Line 111  bool RegionChooser::on_expose_event(GdkE Line 198  bool RegionChooser::on_expose_event(GdkE
198  {  {
199      Glib::RefPtr<Gdk::Window> window = get_window();      Glib::RefPtr<Gdk::Window> window = get_window();
200      window->clear();      window->clear();
201      const int h = 40;      const int h = KEYBOARD_HEIGHT;
202      const int w = width - 1;      const int w = get_width() - 1;
203      const int bh = int(h * 0.55);      const int bh = int(h * 0.55);
204    
205      Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();      Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();
206      Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();      Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();
207    
     Glib::RefPtr<Pango::Context> context = get_pango_context();  
     Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);  
   
208      window->draw_rectangle(black, false, 0, h1, w, h - 1);      window->draw_rectangle(black, false, 0, h1, w, h - 1);
209      gc->set_foreground(grey1);      gc->set_foreground(grey1);
210      int x1 = int(w * 20.5 / 128.0 + 0.5);      int x1 = int(w * 20.5 / 128.0 + 0.5);
# Line 130  bool RegionChooser::on_expose_event(GdkE Line 214  bool RegionChooser::on_expose_event(GdkE
214      window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);      window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);
215      window->draw_rectangle(gc, true, x2 + 1, h1 + 1,      window->draw_rectangle(gc, true, x2 + 1, h1 + 1,
216                             w - x2 - 1, h - 2);                             w - x2 - 1, h - 2);
     int octave = -1;  
217      for (int i = 0 ; i < 128 ; i++) {      for (int i = 0 ; i < 128 ; i++) {
218          int note = (i + 3) % 12;          int note = (i + 3) % 12;
219          int x = int(w * i / 128.0 + 0.5);          int x = int(w * i / 128.0 + 0.5);
# Line 144  bool RegionChooser::on_expose_event(GdkE Line 227  bool RegionChooser::on_expose_event(GdkE
227          } else if (note == 3 || note == 8) {          } else if (note == 3 || note == 8) {
228              window->draw_line(black, x, h1 + 1, x, h1 + h);              window->draw_line(black, x, h1 + 1, x, h1 + h);
229          }          }
230          if (note == 3) {          if (note == 3) draw_digit(i);
             char buf[30];  
             sprintf(buf, "<span size=\"x-small\">%d</span>", octave);  
             layout->set_markup(buf);  
             Pango::Rectangle rectangle = layout->get_logical_extents();  
             double text_w = double(rectangle.get_width()) / Pango::SCALE;  
             double text_h = double(rectangle.get_height()) / Pango::SCALE;  
             double x2 = w * (i + 0.75) / 128.0;  
             window->draw_layout(black, int(x2 - text_w / 2 + 1),  
                                 int(h1 + h - text_h + 0.5), layout);  
             octave++;  
         }  
231      }      }
232    
233      if (instrument) {      if (instrument) {
234          int i = 0;          int i = 0;
235          gig::Region *next_region;          gig::Region *next_region;
236          int x3 = -1;          int x3 = -1;
237          for (gig::Region *r = instrument->GetFirstRegion() ;          for (gig::Region *r = regions.first() ; r ; r = next_region) {
              r ;  
              r = next_region) {  
238    
239              if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5);              if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5);
240              next_region = instrument->GetNextRegion();              next_region = regions.next();
241              if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {              if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {
242                  int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);                  int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);
243                  window->draw_line(black, x3, 0, x2, 0);                  window->draw_line(black, x3, 0, x2, 0);
# Line 179  bool RegionChooser::on_expose_event(GdkE Line 249  bool RegionChooser::on_expose_event(GdkE
249              i++;              i++;
250          }          }
251    
252          for (gig::Region *r = instrument->GetFirstRegion() ;          for (gig::Region *r = regions.first() ; r ; r = regions.next()) {
              r ;  
              r = instrument->GetNextRegion()) {  
253              int x = int(w * (r->KeyRange.low) / 128.0 + 0.5);              int x = int(w * (r->KeyRange.low) / 128.0 + 0.5);
254              window->draw_line(black, x, 1, x, h1 - 2);              window->draw_line(black, x, 1, x, h1 - 2);
255          }          }
# Line 200  bool RegionChooser::on_expose_event(GdkE Line 268  bool RegionChooser::on_expose_event(GdkE
268  void RegionChooser::on_size_request(GtkRequisition* requisition)  void RegionChooser::on_size_request(GtkRequisition* requisition)
269  {  {
270      *requisition = GtkRequisition();      *requisition = GtkRequisition();
271      requisition->height = 40 + 20;      requisition->height = KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT;
272      requisition->width = 500;      requisition->width = 500;
273  }  }
274    
275    bool RegionChooser::is_black_key(int key) {
276        const int note = (key + 3) % 12;
277        return note == 1 || note == 4 || note == 6 || note == 9 || note == 11;
278    }
279    
280    void RegionChooser::draw_digit(int key) {
281        const int h = KEYBOARD_HEIGHT;
282        const int w = get_width() - 1;
283        Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(get_pango_context());
284        char buf[30];
285        sprintf(buf, "<span size=\"8000\">%d</span>", key / 12 - 1);
286        layout->set_markup(buf);
287        Pango::Rectangle rectangle = layout->get_logical_extents();
288        double text_w = double(rectangle.get_width()) / Pango::SCALE;
289        double text_h = double(rectangle.get_height()) / Pango::SCALE;
290        double x = w * (key + 0.75) / 128.0;
291        get_window()->draw_layout(get_style()->get_black_gc(), int(x - text_w / 2 + 1),
292                                  int(h1 + h - text_h + 0.5), layout);
293    }
294    
 // not used  
295  void RegionChooser::draw_region(int from, int to, const Gdk::Color& color)  void RegionChooser::draw_region(int from, int to, const Gdk::Color& color)
296  {  {
297      const int h = 40;      const int h = KEYBOARD_HEIGHT;
298      const int w = width;      const int w = get_width() - 1;
299      const int bh = int(h * 0.55);      const int bh = int(h * 0.55);
300    
301      Glib::RefPtr<Gdk::Window> window = get_window();      Glib::RefPtr<Gdk::Window> window = get_window();
# Line 220  void RegionChooser::draw_region(int from Line 306  void RegionChooser::draw_region(int from
306          int x = int(w * i / 128.0 + 0.5) + 1;          int x = int(w * i / 128.0 + 0.5) + 1;
307          int x2 = int(w * (i + 1.5) / 128.0 + 0.5);          int x2 = int(w * (i + 1.5) / 128.0 + 0.5);
308          int x3 = int(w * (i + 1) / 128.0 + 0.5);          int x3 = int(w * (i + 1) / 128.0 + 0.5);
309          int x4 = int(w * (i - 0.5) / 128 + 0.5) + 1;          int x4 = int(w * (i - 0.5) / 128.0 + 0.5);
310          int w1 = x3 - x;          int w1 = x3 - x;
311          switch (note) {          switch (note) {
312          case 0: case 5: case 10:          case 0: case 5: case 10:
313              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
314              window->draw_rectangle(gc, true, x4, h1 + bh + 1, x2 - x4, h - bh - 2);              window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x2 - x4 - 1, h - bh - 2);
315              break;              break;
316          case 2: case 7:          case 2: case 7:
317              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
318              window->draw_rectangle(gc, true, x4, h1 + bh + 1, x3 - x4, h - bh - 2);              window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x3 - x4 - 1, h - bh - 2);
319              break;              break;
320          case 3: case 8:          case 3: case 8:
321              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);
322              window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2);              window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2);
323                if (note == 3) draw_digit(i);
324              break;              break;
325          default:          default:
326              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1);              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1);
# Line 245  void RegionChooser::draw_region(int from Line 332  void RegionChooser::draw_region(int from
332  void RegionChooser::set_instrument(gig::Instrument* instrument)  void RegionChooser::set_instrument(gig::Instrument* instrument)
333  {  {
334      this->instrument = instrument;      this->instrument = instrument;
335      region = instrument ? instrument->GetFirstRegion() : 0;      regions.update(instrument);
336        region = regions.first();
337      queue_draw();      queue_draw();
338      region_selected();      region_selected();
339        dimensionManager.set_region(region);
340  }  }
341    
342  bool RegionChooser::on_button_release_event(GdkEventButton* event)  bool RegionChooser::on_button_release_event(GdkEventButton* event)
343  {  {
344        const int k = int(event->x / (get_width() - 1) * 128.0);
345    
346        // handle-note off on virtual keyboard
347        if (event->type == GDK_BUTTON_RELEASE) {
348            int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
349                           int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;
350            if (velocity <= 0) velocity = 1;
351            switch (m_VirtKeybModeChoice.get_value()) {
352                case VIRT_KEYBOARD_MODE_CHORD:
353                    if (event->y >= REGION_BLOCK_HEIGHT)
354                        keyboard_key_released_signal.emit(k, velocity);
355                    break;
356                case VIRT_KEYBOARD_MODE_NORMAL:
357                default:
358                    if (currentActiveKey >= 0 && currentActiveKey <= 127) {
359                        keyboard_key_released_signal.emit(currentActiveKey, velocity);
360                        currentActiveKey = -1;
361                    }
362                    break;
363            }
364        }
365    
366      if (resize.active) {      if (resize.active) {
367          get_window()->pointer_ungrab(event->time);          get_window()->pointer_ungrab(event->time);
368          resize.active = false;          resize.active = false;
369    
370          if (resize.mode == resize.moving_high_limit) {          if (resize.mode == resize.moving_high_limit) {
371              if (resize.region->KeyRange.high != resize.pos - 1) {              if (resize.region->KeyRange.high != resize.pos - 1) {
372                  resize.region->KeyRange.high = resize.pos - 1;                  instrument_struct_to_be_changed_signal.emit(instrument);
373                  instrument_changed();                  resize.region->SetKeyRange(
374                        resize.region->KeyRange.low, // low
375                        resize.pos - 1 // high
376                    );
377                    regions.update(instrument);
378                    instrument_changed.emit();
379                    instrument_struct_changed_signal.emit(instrument);
380              }              }
381          } else if (resize.mode == resize.moving_low_limit) {          } else if (resize.mode == resize.moving_low_limit) {
382              if (resize.region->KeyRange.low != resize.pos) {              if (resize.region->KeyRange.low != resize.pos) {
383                  resize.region->KeyRange.low = resize.pos;                  instrument_struct_to_be_changed_signal.emit(instrument);
384                  instrument_changed();                  resize.region->SetKeyRange(
385                        resize.pos, // low
386                        resize.region->KeyRange.high // high
387                    );
388                    regions.update(instrument);
389                    instrument_changed.emit();
390                    instrument_struct_changed_signal.emit(instrument);
391              }              }
392          }          }
393    
# Line 277  bool RegionChooser::on_button_release_ev Line 400  bool RegionChooser::on_button_release_ev
400          move.active = false;          move.active = false;
401    
402          if (move.pos) {          if (move.pos) {
403              region->KeyRange.low += move.pos;              instrument_struct_to_be_changed_signal.emit(instrument);
404              region->KeyRange.high += move.pos;              region->SetKeyRange(
405                    region->KeyRange.low  + move.pos,
406              // find the r which is the first one to the right of region                  region->KeyRange.high + move.pos
407              // at its new position              );
408              gig::Region* r;              regions.update(instrument);
409              gig::Region* prev_region = 0;              instrument_changed.emit();
410              for (r = instrument->GetFirstRegion() ; r ; r = instrument->GetNextRegion()) {              instrument_struct_changed_signal.emit(instrument);
                 if (r->KeyRange.low > region->KeyRange.low) break;  
                 prev_region = r;  
             }  
   
             // place region before r if it's not already there  
             if (prev_region != region) {  
                 instrument_struct_to_be_changed_signal.emit(instrument);  
                 instrument->MoveRegion(region, r);  
                 instrument_struct_changed_signal.emit(instrument);  
             }  
411          }          }
412    
413          if (is_in_resize_zone(event->x, event->y)) {          if (is_in_resize_zone(event->x, event->y)) {
# Line 309  bool RegionChooser::on_button_press_even Line 422  bool RegionChooser::on_button_press_even
422  {  {
423      if (!instrument) return true;      if (!instrument) return true;
424    
425      int k = int(event->x / (width - 1) * 128.0);      const int k = int(event->x / (get_width() - 1) * 128.0);
426    
427        if (event->type == GDK_BUTTON_PRESS) {
428            if (event->y >= REGION_BLOCK_HEIGHT) {
429                int velocity = (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
430                               int(float(event->y - REGION_BLOCK_HEIGHT) / float(KEYBOARD_HEIGHT) * 128.0f) + 1;
431                currentActiveKey = k;
432                keyboard_key_hit_signal.emit(k, velocity);
433            }
434        }
435    
436        if (event->y >= REGION_BLOCK_HEIGHT) return true;
437      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
438          gig::Region* r = get_region(k);          gig::Region* r = get_region(k);
439          if (r) {          if (r) {
440              region = r;              region = r;
441              queue_draw();              queue_draw();
442              region_selected();              region_selected();
443                dimensionManager.set_region(region);
444              popup_menu_inside_region->popup(event->button, event->time);              popup_menu_inside_region->popup(event->button, event->time);
445          } else {          } else {
446              new_region_pos = k;              new_region_pos = k;
# Line 336  bool RegionChooser::on_button_press_even Line 460  bool RegionChooser::on_button_press_even
460                  region = r;                  region = r;
461                  queue_draw();                  queue_draw();
462                  region_selected();                  region_selected();
463                    dimensionManager.set_region(region);
464    
465                  get_window()->pointer_grab(false,                  get_window()->pointer_grab(false,
466                                             Gdk::BUTTON_RELEASE_MASK |                                             Gdk::BUTTON_RELEASE_MASK |
# Line 355  gig::Region* RegionChooser::get_region(i Line 480  gig::Region* RegionChooser::get_region(i
480  {  {
481      gig::Region* prev_region = 0;      gig::Region* prev_region = 0;
482      gig::Region* next_region;      gig::Region* next_region;
483      for (gig::Region *r = instrument->GetFirstRegion() ; r ;      for (gig::Region *r = regions.first() ; r ; r = next_region) {
484           r = next_region) {          next_region = regions.next();
         next_region = instrument->GetNextRegion();  
485    
486          if (key < r->KeyRange.low) return 0;          if (key < r->KeyRange.low) return 0;
487          if (key <= r->KeyRange.high) {          if (key <= r->KeyRange.high) {
# Line 372  gig::Region* RegionChooser::get_region(i Line 496  gig::Region* RegionChooser::get_region(i
496    
497  void RegionChooser::motion_resize_region(int x, int y)  void RegionChooser::motion_resize_region(int x, int y)
498  {  {
499      const int w = width - 1;      const int w = get_width() - 1;
500      Glib::RefPtr<Gdk::Window> window = get_window();      Glib::RefPtr<Gdk::Window> window = get_window();
501    
502      int k = int(double(x) / w * 128.0 + 0.5);      int k = int(double(x) / w * 128.0 + 0.5);
# Line 429  void RegionChooser::motion_resize_region Line 553  void RegionChooser::motion_resize_region
553    
554  void RegionChooser::motion_move_region(int x, int y)  void RegionChooser::motion_move_region(int x, int y)
555  {  {
556      const int w = width - 1;      const int w = get_width() - 1;
557      Glib::RefPtr<Gdk::Window> window = get_window();      Glib::RefPtr<Gdk::Window> window = get_window();
558    
559      int k = int(double(x - move.from_x) / w * 128.0 + 0.5);      int k = int(double(x - move.from_x) / w * 128.0 + 0.5);
# Line 439  void RegionChooser::motion_move_region(i Line 563  void RegionChooser::motion_move_region(i
563      bool new_touch_right;      bool new_touch_right;
564      int a = 0;      int a = 0;
565      if (k > move.pos) {      if (k > move.pos) {
566          for (gig::Region* r = instrument->GetFirstRegion() ; ;          for (gig::Region* r = regions.first() ; ; r = regions.next()) {
              r = instrument->GetNextRegion()) {  
567              if (r != region) {              if (r != region) {
568                  int b = r ? r->KeyRange.low : 128;                  int b = r ? r->KeyRange.low : 128;
569    
# Line 470  void RegionChooser::motion_move_region(i Line 593  void RegionChooser::motion_move_region(i
593              }              }
594          }          }
595      } else {      } else {
596          for (gig::Region* r = instrument->GetFirstRegion() ; ;          for (gig::Region* r = regions.first() ; ; r = regions.next()) {
              r = instrument->GetNextRegion()) {  
597              if (r != region) {              if (r != region) {
598                  int b = r ? r->KeyRange.low : 128;                  int b = r ? r->KeyRange.low : 128;
599    
# Line 549  bool RegionChooser::on_motion_notify_eve Line 671  bool RegionChooser::on_motion_notify_eve
671      Gdk::ModifierType state = Gdk::ModifierType(0);      Gdk::ModifierType state = Gdk::ModifierType(0);
672      window->get_pointer(x, y, state);      window->get_pointer(x, y, state);
673    
674        // handle virtual MIDI keyboard
675        if (m_VirtKeybModeChoice.get_value() != VIRT_KEYBOARD_MODE_CHORD &&
676            currentActiveKey > 0 &&
677            event->y >= REGION_BLOCK_HEIGHT &&
678            event->y < REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT)
679        {
680            const int k = int(event->x / (get_width() - 1) * 128.0);
681            if (k != currentActiveKey) {
682                int velocity =
683                    (event->y >= REGION_BLOCK_HEIGHT + KEYBOARD_HEIGHT - 1) ? 127 :
684                    int(float(event->y - REGION_BLOCK_HEIGHT) /
685                        float(KEYBOARD_HEIGHT) * 128.0f) + 1;
686                if (velocity <= 0) velocity = 1;
687                keyboard_key_released_signal.emit(currentActiveKey, velocity);
688                currentActiveKey = k;
689                keyboard_key_hit_signal.emit(k, velocity);
690            }
691        }
692    
693      if (resize.active) {      if (resize.active) {
694          motion_resize_region(x, y);          motion_resize_region(x, y);
695      } else if (move.active) {      } else if (move.active) {
# Line 569  bool RegionChooser::on_motion_notify_eve Line 710  bool RegionChooser::on_motion_notify_eve
710  }  }
711    
712  bool RegionChooser::is_in_resize_zone(double x, double y) {  bool RegionChooser::is_in_resize_zone(double x, double y) {
713      const int w = width - 1;      const int w = get_width() - 1;
714    
715      if (instrument && y >= 0 && y <= h1) {      if (instrument && y >= 0 && y <= h1) {
716          gig::Region* prev_region = 0;          gig::Region* prev_region = 0;
717          gig::Region* next_region;          gig::Region* next_region;
718          for (gig::Region* r = instrument->GetFirstRegion() ; r ; r = next_region) {          for (gig::Region* r = regions.first(); r ; r = next_region) {
719              next_region = instrument->GetNextRegion();              next_region = regions.next();
720    
721              int lo = int(w * (r->KeyRange.low) / 128.0 + 0.5);              int lo = int(w * (r->KeyRange.low) / 128.0 + 0.5);
722              if (x <= lo - 2) break;              if (x <= lo - 2) break;
# Line 591  bool RegionChooser::is_in_resize_zone(do Line 732  bool RegionChooser::is_in_resize_zone(do
732                      resize.mode = resize.undecided;                      resize.mode = resize.undecided;
733                      resize.min = prev_region->KeyRange.low + 1;                      resize.min = prev_region->KeyRange.low + 1;
734                      resize.prev_region = prev_region;                      resize.prev_region = prev_region;
735                      return true;                      return resize.min != resize.max;
736                  }                  }
737    
738                  // edit low limit                  // edit low limit
739                  resize.mode = resize.moving_low_limit;                  resize.mode = resize.moving_low_limit;
740                  resize.min = prev_region ? prev_region->KeyRange.high + 1 : 0;                  resize.min = prev_region ? prev_region->KeyRange.high + 1 : 0;
741                  return true;                  return resize.min != resize.max;
742              }              }
743              if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {              if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {
744                  int hi = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);                  int hi = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);
# Line 609  bool RegionChooser::is_in_resize_zone(do Line 750  bool RegionChooser::is_in_resize_zone(do
750                      resize.mode = resize.moving_high_limit;                      resize.mode = resize.moving_high_limit;
751                      resize.min = r->KeyRange.low + 1;                      resize.min = r->KeyRange.low + 1;
752                      resize.max = next_region ? next_region->KeyRange.low : 128;                      resize.max = next_region ? next_region->KeyRange.low : 128;
753                      return true;                      return resize.min != resize.max;
754                  }                  }
755              }              }
756              prev_region = r;              prev_region = r;
# Line 618  bool RegionChooser::is_in_resize_zone(do Line 759  bool RegionChooser::is_in_resize_zone(do
759      return false;      return false;
760  }  }
761    
762  sigc::signal<void> RegionChooser::signal_region_selected()  sigc::signal<void>& RegionChooser::signal_region_selected()
763  {  {
764      return region_selected;      return region_selected;
765  }  }
766    
767  sigc::signal<void> RegionChooser::signal_instrument_changed()  sigc::signal<void>& RegionChooser::signal_instrument_changed()
768  {  {
769      return instrument_changed;      return instrument_changed;
770  }  }
# Line 631  sigc::signal<void> RegionChooser::signal Line 772  sigc::signal<void> RegionChooser::signal
772  void RegionChooser::show_region_properties()  void RegionChooser::show_region_properties()
773  {  {
774      if (!region) return;      if (!region) return;
775      Gtk::Dialog dialog("Region Properties", true /*modal*/);      Gtk::Dialog dialog(_("Region Properties"), true /*modal*/);
776      // add "Keygroup" checkbox      // add "Keygroup" checkbox
777      Gtk::CheckButton checkBoxKeygroup("Member of a Keygroup (Exclusive Group)");      Gtk::CheckButton checkBoxKeygroup(_("Member of a Keygroup (Exclusive Group)"));
778      checkBoxKeygroup.set_active(region->KeyGroup);      checkBoxKeygroup.set_active(region->KeyGroup);
779      dialog.get_vbox()->pack_start(checkBoxKeygroup);      dialog.get_vbox()->pack_start(checkBoxKeygroup);
780      checkBoxKeygroup.show();      checkBoxKeygroup.show();
# Line 655  void RegionChooser::show_region_properti Line 796  void RegionChooser::show_region_properti
796    
797  void RegionChooser::add_region()  void RegionChooser::add_region()
798  {  {
     gig::Region* r;  
     for (r = instrument->GetFirstRegion() ; r ; r = instrument->GetNextRegion()) {  
         if (r->KeyRange.low > new_region_pos) break;  
     }  
   
799      instrument_struct_to_be_changed_signal.emit(instrument);      instrument_struct_to_be_changed_signal.emit(instrument);
800    
801      region = instrument->AddRegion();      region = instrument->AddRegion();
802      region->KeyRange.low = region->KeyRange.high = new_region_pos;      region->SetKeyRange(new_region_pos, new_region_pos);
   
     instrument->MoveRegion(region, r);  
803    
804      instrument_struct_changed_signal.emit(instrument);      instrument_struct_changed_signal.emit(instrument);
805        regions.update(instrument);
806    
807      queue_draw();      queue_draw();
808      region_selected();      region_selected();
809        dimensionManager.set_region(region);
810      instrument_changed();      instrument_changed();
811  }  }
812    
# Line 679  void RegionChooser::delete_region() Line 815  void RegionChooser::delete_region()
815      instrument_struct_to_be_changed_signal.emit(instrument);      instrument_struct_to_be_changed_signal.emit(instrument);
816      instrument->DeleteRegion(region);      instrument->DeleteRegion(region);
817      instrument_struct_changed_signal.emit(instrument);      instrument_struct_changed_signal.emit(instrument);
818        regions.update(instrument);
819    
820      region = 0;      region = 0;
821      queue_draw();      queue_draw();
822      region_selected();      region_selected();
823        dimensionManager.set_region(region);
824      instrument_changed();      instrument_changed();
825  }  }
826    
# Line 698  void RegionChooser::on_dimension_manager Line 836  void RegionChooser::on_dimension_manager
836      instrument_changed();      instrument_changed();
837  }  }
838    
839  sigc::signal<void, gig::Instrument*> RegionChooser::signal_instrument_struct_to_be_changed() {  sigc::signal<void, gig::Instrument*>& RegionChooser::signal_instrument_struct_to_be_changed() {
840      return instrument_struct_to_be_changed_signal;      return instrument_struct_to_be_changed_signal;
841  }  }
842    
843  sigc::signal<void, gig::Instrument*> RegionChooser::signal_instrument_struct_changed() {  sigc::signal<void, gig::Instrument*>& RegionChooser::signal_instrument_struct_changed() {
844      return instrument_struct_changed_signal;      return instrument_struct_changed_signal;
845  }  }
846    
847  sigc::signal<void, gig::Region*> RegionChooser::signal_region_to_be_changed() {  sigc::signal<void, gig::Region*>& RegionChooser::signal_region_to_be_changed() {
848      return region_to_be_changed_signal;      return region_to_be_changed_signal;
849  }  }
850    
851  sigc::signal<void, gig::Region*> RegionChooser::signal_region_changed_signal() {  sigc::signal<void, gig::Region*>& RegionChooser::signal_region_changed_signal() {
852      return region_changed_signal;      return region_changed_signal;
853  }  }
854    
855    sigc::signal<void, int/*key*/, int/*velocity*/>& RegionChooser::signal_keyboard_key_hit() {
856        return keyboard_key_hit_signal;
857    }
858    
859    sigc::signal<void, int/*key*/, int/*velocity*/>& RegionChooser::signal_keyboard_key_released() {
860        return keyboard_key_released_signal;
861    }

Legend:
Removed from v.1322  
changed lines
  Added in v.1898

  ViewVC Help
Powered by ViewVC