/[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 2536 by schoenebeck, Mon Apr 21 17:49:17 2014 UTC revision 3106 by schoenebeck, Sat Feb 11 17:04:48 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2015 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 24  Line 24 
24  #include <cairomm/context.h>  #include <cairomm/context.h>
25  #include <gdkmm/general.h>  #include <gdkmm/general.h>
26  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
27  #include <gtkmm/stock.h>  #include <gdkmm/pixbuf.h>
28  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
29  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
30    
31  #include "global.h"  #include "global.h"
32    #include "Settings.h"
33    #include "gfx/builtinpix.h"
34    
35  #define REGION_BLOCK_HEIGHT             20  #define REGION_BLOCK_HEIGHT             30
36  #define KEYBOARD_HEIGHT                 40  #define KEYBOARD_HEIGHT                 40
37    
38    struct RegionFeatures {
39        int sampleRefs;
40        int loops;
41    
42        RegionFeatures() {
43            sampleRefs = loops = 0;
44        }
45    };
46    
47    static RegionFeatures regionFeatures(gig::Region* rgn) {
48        RegionFeatures f;
49        for (int i = 0; i < rgn->DimensionRegions; ++i) {
50            gig::DimensionRegion* dr = rgn->pDimensionRegions[i];
51            if (dr->pSample) f.sampleRefs++;
52            // the user doesn't care about loop if there is no valid sample reference
53            if (dr->pSample && dr->SampleLoops) f.loops++;
54        }
55        return f;
56    }
57    
58  void SortedRegions::update(gig::Instrument* instrument) {  void SortedRegions::update(gig::Instrument* instrument) {
59      // Usually, the regions in a gig file are ordered after their key      // Usually, the regions in a gig file are ordered after their key
60      // range, but there are files where they are not. The      // range, but there are files where they are not. The
# Line 54  gig::Region* SortedRegions::first() { Line 76  gig::Region* SortedRegions::first() {
76  }  }
77    
78  gig::Region* SortedRegions::next() {  gig::Region* SortedRegions::next() {
79      region_iterator++;      ++region_iterator;
80      return region_iterator == regions.end() ? 0 : *region_iterator;      return region_iterator == regions.end() ? 0 : *region_iterator;
81  }  }
82    
# Line 71  RegionChooser::RegionChooser() : Line 93  RegionChooser::RegionChooser() :
93  {  {
94      set_size_request(500, KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT);      set_size_request(500, KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT);
95    
96        loadBuiltInPix();
97    
98      instrument = 0;      instrument = 0;
99      region = 0;      region = 0;
100      resize.active = false;      resize.active = false;
# Line 103  RegionChooser::RegionChooser() : Line 127  RegionChooser::RegionChooser() :
127      for (int i = 0 ; i < 128 ; i++) key_pressed[i] = false;      for (int i = 0 ; i < 128 ; i++) key_pressed[i] = false;
128    
129      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
130      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties", _("_Properties")),
                                          Gtk::Stock::PROPERTIES),  
131                       sigc::mem_fun(*this,                       sigc::mem_fun(*this,
132                                     &RegionChooser::show_region_properties));                                     &RegionChooser::show_region_properties));
133      actionGroup->add(Gtk::Action::create("Remove", Gtk::Stock::REMOVE),      actionGroup->add(Gtk::Action::create("Remove", _("_Remove")),
134                       sigc::mem_fun(*this, &RegionChooser::delete_region));                       sigc::mem_fun(*this, &RegionChooser::delete_region));
135      actionGroup->add(Gtk::Action::create("Add", Gtk::Stock::ADD),      actionGroup->add(Gtk::Action::create("Add", _("_Add")),
136                       sigc::mem_fun(*this, &RegionChooser::add_region));                       sigc::mem_fun(*this, &RegionChooser::add_region));
137      actionGroup->add(Gtk::Action::create("Dimensions", _("Dimensions...")),      actionGroup->add(Gtk::Action::create("Dimensions", _("Dimensions...")),
138                       sigc::mem_fun(*this, &RegionChooser::manage_dimensions));                       sigc::mem_fun(*this, &RegionChooser::manage_dimensions));
# Line 322  void RegionChooser::draw_regions(const C Line 345  void RegionChooser::draw_regions(const C
345    
346      for (gig::Region* r = regions.first() ; r ; r = regions.next()) {      for (gig::Region* r = regions.first() ; r ; r = regions.next()) {
347          int x = key_to_x(r->KeyRange.low, w);          int x = key_to_x(r->KeyRange.low, w);
348            int x2 = key_to_x(r->KeyRange.high + 1, w);
349    
350            RegionFeatures features = regionFeatures(r);
351    
352            const bool bShowLoopSymbol = features.loops > 0;
353            const bool bShowSampleRefSymbol = features.sampleRefs < r->DimensionRegions;
354            if (bShowLoopSymbol || bShowSampleRefSymbol) {
355                const int margin = 2;
356                const int wRgn = x2 - x;
357                //printf("x=%d x2=%d wRgn=%d\n", x, x2, wRgn);
358    
359                cr->save();
360                cr->set_line_width(1);
361                cr->rectangle(x, 1, wRgn, h1 - 1);
362                cr->clip();
363                if (bShowSampleRefSymbol) {
364                    const int wPic = 8;
365                    const int hPic = 8;
366                    Gdk::Cairo::set_source_pixbuf(
367                        cr, (features.sampleRefs) ? yellowDot : redDot,
368                        x + (wRgn-wPic)/2.f,
369                        (bShowLoopSymbol) ? margin : (h1-hPic)/2.f
370                    );
371                    cr->paint();
372                }
373                if (bShowLoopSymbol) {
374                    const int wPic = 12;
375                    const int hPic = 14;
376                    Gdk::Cairo::set_source_pixbuf(
377                        cr, (features.loops == r->DimensionRegions) ? blackLoop : grayLoop,
378                        x + (wRgn-wPic)/2.f,
379                        (bShowSampleRefSymbol) ? h1 - hPic - margin : (h1-hPic)/2.f
380                    );
381                    cr->paint();
382                }
383                cr->restore();
384            }
385        }
386    
387        for (gig::Region* r = regions.first() ; r ; r = regions.next()) {
388            int x = key_to_x(r->KeyRange.low, w);
389    
390          if (x < clip_low) continue;          if (x < clip_low) continue;
391          if (x >= clip_high) break;          if (x >= clip_high) break;
# Line 339  void RegionChooser::draw_regions(const C Line 403  void RegionChooser::draw_regions(const C
403          layout->set_alignment(Pango::ALIGN_CENTER);          layout->set_alignment(Pango::ALIGN_CENTER);
404          layout->set_text(Glib::ustring("*** ") + _("Right click here to create a region.") + " ***");          layout->set_text(Glib::ustring("*** ") + _("Right click here to create a region.") + " ***");
405          layout->set_width(get_width() * Pango::SCALE);          layout->set_width(get_width() * Pango::SCALE);
406          Gdk::Cairo::set_source_rgba(cr, red);          //layout->set_height(get_height() * Pango::SCALE);
407            layout->set_spacing(10);
408            Gdk::Cairo::set_source_rgba(cr, red);        
409            // get the text dimensions
410            int text_width, text_height;
411            layout->get_pixel_size(text_width, text_height);
412            cr->move_to(0, (REGION_BLOCK_HEIGHT - text_height) / 2);
413  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
414          pango_cairo_show_layout(cr->cobj(), layout->gobj());          pango_cairo_show_layout(cr->cobj(), layout->gobj());
415  #else  #else
# Line 508  void RegionChooser::update_after_resize( Line 578  void RegionChooser::update_after_resize(
578  void RegionChooser::update_after_move(int pos)  void RegionChooser::update_after_move(int pos)
579  {  {
580      instrument_struct_to_be_changed_signal.emit(instrument);      instrument_struct_to_be_changed_signal.emit(instrument);
581      region->SetKeyRange(pos, pos + region->KeyRange.high -      const int range = region->KeyRange.high - region->KeyRange.low;
582                          region->KeyRange.low);      const int diff  = pos - int(region->KeyRange.low);
583        region->SetKeyRange(pos, pos + range);
584        if (Settings::singleton()->moveRootNoteWithRegionMoved) {
585            for (int i = 0; i < 256; ++i) {
586                gig::DimensionRegion* dimrgn = region->pDimensionRegions[i];
587                if (!dimrgn || !dimrgn->pSample || !dimrgn->PitchTrack) continue;
588                dimrgn->UnityNote += diff;
589            }
590        }
591      regions.update(instrument);      regions.update(instrument);
592      instrument_changed.emit();      instrument_changed.emit();
593      instrument_struct_changed_signal.emit(instrument);      instrument_struct_changed_signal.emit(instrument);
# Line 531  bool RegionChooser::on_button_press_even Line 609  bool RegionChooser::on_button_press_even
609          }          }
610      }      }
611    
612        // left mouse button double click
613        if (event->type == GDK_2BUTTON_PRESS && event->button == 1) {
614            if (event->y < REGION_BLOCK_HEIGHT) {
615                // show dimension manager dialog for this region
616                manage_dimensions();
617            }
618        }
619    
620      if (event->y >= REGION_BLOCK_HEIGHT) return true;      if (event->y >= REGION_BLOCK_HEIGHT) return true;
621      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
622          gig::Region* r = get_region(k);          gig::Region* r = get_region(k);
# Line 606  gig::Region* RegionChooser::get_region(i Line 692  gig::Region* RegionChooser::get_region(i
692      return 0;      return 0;
693  }  }
694    
695    void RegionChooser::set_region(gig::Region* region) {
696        this->region = region;
697        queue_draw();
698        region_selected();
699        dimensionManager.set_region(region);
700    }
701    
702  void RegionChooser::motion_resize_region(int x, int y)  void RegionChooser::motion_resize_region(int x, int y)
703  {  {
704      const int w = get_width() - 1;      const int w = get_width() - 1;
# Line 654  void RegionChooser::motion_resize_region Line 747  void RegionChooser::motion_resize_region
747    
748          update_after_resize();          update_after_resize();
749    
750          get_window()->invalidate_rect(rect, false);          //get_window()->invalidate_rect(rect, false);
751            get_window()->invalidate(false); // repaint entire region, otherwise it would create visual artifacts
752      }      }
753  }  }
754    
# Line 868  void RegionChooser::show_region_properti Line 962  void RegionChooser::show_region_properti
962      dialog.get_vbox()->pack_start(spinBox);      dialog.get_vbox()->pack_start(spinBox);
963      spinBox.show();      spinBox.show();
964      // add OK and CANCEL buttons to the dialog      // add OK and CANCEL buttons to the dialog
965      dialog.add_button(Gtk::Stock::OK, 0);      dialog.add_button(_("_OK"), 0);
966      dialog.add_button(Gtk::Stock::CANCEL, 1);      dialog.add_button(_("_Cancel"), 1);
967      dialog.show_all_children();      dialog.show_all_children();
968      if (!dialog.run()) { // OK selected ...      if (!dialog.run()) { // OK selected ...
969          region->KeyGroup =          region->KeyGroup =

Legend:
Removed from v.2536  
changed lines
  Added in v.3106

  ViewVC Help
Powered by ViewVC