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

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

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

revision 1382 by schoenebeck, Thu Oct 4 23:29:22 2007 UTC revision 1533 by persson, Sat Dec 1 10:21:07 2007 UTC
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
 #include <libintl.h>  
20  #include <iostream>  #include <iostream>
21    
22  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
# Line 25  Line 24 
24  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
25  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
26  #include <gtkmm/main.h>  #include <gtkmm/main.h>
27    #include <gtkmm/toggleaction.h>
28    
29    #include "global.h"
30    
31  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2
32  #define ABOUT_DIALOG  #define ABOUT_DIALOG
# Line 48  Glib::ustring filename_display_basename( Line 50  Glib::ustring filename_display_basename(
50    
51  #include "mainwindow.h"  #include "mainwindow.h"
52    
53  #define _(String) gettext(String)  #include "../../gfx/status_attached.xpm"
54    #include "../../gfx/status_detached.xpm"
55    
56  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
57      std::stringstream ss;      std::stringstream ss;
# Line 56  template<class T> inline std::string ToS Line 59  template<class T> inline std::string ToS
59      return ss.str();      return ss.str();
60  }  }
61    
62  MainWindow::MainWindow()  MainWindow::MainWindow() :
63        dimreg_label(_("Changes apply to:")),
64        dimreg_all_regions(_("all regions")),
65        dimreg_all_dimregs(_("all dimension splits")),
66        dimreg_stereo(_("both channels"))
67  {  {
68  //    set_border_width(5);  //    set_border_width(5);
69  //    set_default_size(400, 200);  //    set_default_size(400, 200);
# Line 86  MainWindow::MainWindow() Line 93  MainWindow::MainWindow()
93      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
94    
95      m_HPaned.add1(m_TreeViewNotebook);      m_HPaned.add1(m_TreeViewNotebook);
96      m_HPaned.add2(dimreg_edit);      dimreg_hbox.add(dimreg_label);
97        dimreg_hbox.add(dimreg_all_regions);
98        dimreg_hbox.add(dimreg_all_dimregs);
99        dimreg_stereo.set_active();
100        dimreg_hbox.add(dimreg_stereo);
101        dimreg_vbox.add(dimreg_edit);
102        dimreg_vbox.add(dimreg_hbox);
103        m_HPaned.add2(dimreg_vbox);
104    
105    
106      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");
# Line 127  MainWindow::MainWindow() Line 141  MainWindow::MainWindow()
141                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
142      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
143    
144        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
145        Glib::RefPtr<Gtk::ToggleAction> toggle_action =
146            Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
147        toggle_action->set_active(true);
148        actionGroup->add(toggle_action,
149                         sigc::mem_fun(
150                             *this, &MainWindow::on_action_view_status_bar));
151    
152      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
153      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
154                                           action->property_label()));                                           action->property_label()));
# Line 182  MainWindow::MainWindow() Line 204  MainWindow::MainWindow()
204          "    </menu>"          "    </menu>"
205          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
206          "    </menu>"          "    </menu>"
207            "    <menu action='MenuView'>"
208            "      <menuitem action='Statusbar'/>"
209            "    </menu>"
210  #ifdef ABOUT_DIALOG  #ifdef ABOUT_DIALOG
211          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
212          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 211  MainWindow::MainWindow() Line 236  MainWindow::MainWindow()
236      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
237      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
238      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
239        m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
240    
241        // Status Bar:
242        m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
243        m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
244        m_StatusBar.show();
245    
246      m_RegionChooser.signal_region_selected().connect(      m_RegionChooser.signal_region_selected().connect(
247          sigc::mem_fun(*this, &MainWindow::region_changed) );          sigc::mem_fun(*this, &MainWindow::region_changed) );
# Line 293  MainWindow::MainWindow() Line 324  MainWindow::MainWindow()
324      m_RegionChooser.signal_region_changed_signal().connect(      m_RegionChooser.signal_region_changed_signal().connect(
325          region_changed_signal.make_slot());          region_changed_signal.make_slot());
326    
327        dimreg_all_regions.signal_toggled().connect(
328            sigc::mem_fun(*this, &MainWindow::update_dimregs));
329        dimreg_all_dimregs.signal_toggled().connect(
330            sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
331        dimreg_stereo.signal_toggled().connect(
332            sigc::mem_fun(*this, &MainWindow::update_dimregs));
333    
334      file = 0;      file = 0;
335      file_is_changed = false;      file_is_changed = false;
336      file_is_shared  = false;      set_file_is_shared(false);
337    
338      show_all_children();      show_all_children();
339    
# Line 323  void MainWindow::region_changed() Line 361  void MainWindow::region_changed()
361      m_DimRegionChooser.set_region(m_RegionChooser.get_region());      m_DimRegionChooser.set_region(m_RegionChooser.get_region());
362  }  }
363    
364  void MainWindow::dimreg_changed()  gig::Instrument* MainWindow::get_instrument()
 {  
     dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());  
 }  
   
 void MainWindow::on_sel_change()  
365  {  {
366        gig::Instrument* instrument = 0;
367      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();
368    
369      Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();      Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();
370      if (it) {      if (it) {
371          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
372          std::cout << row[m_Columns.m_col_name] << std::endl;          instrument = row[m_Columns.m_col_instr];
373        }
374        return instrument;
375    }
376    
377          m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]);  void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
378    {
379        if (all_dimregs) {
380            for (int i = 0 ; i < region->DimensionRegions ; i++) {
381                if (region->pDimensionRegions[i]) {
382                    dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
383                }
384            }
385      } else {      } else {
386          m_RegionChooser.set_instrument(0);          m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
387      }      }
388  }  }
389    
390    void MainWindow::update_dimregs()
391    {
392        dimreg_edit.dimregs.clear();
393        bool all_regions = dimreg_all_regions.get_active();
394        bool stereo = dimreg_stereo.get_active();
395        bool all_dimregs = dimreg_all_dimregs.get_active();
396    
397        if (all_regions) {
398            gig::Instrument* instrument = get_instrument();
399            if (instrument) {
400                for (gig::Region* region = instrument->GetFirstRegion() ;
401                     region ;
402                     region = instrument->GetNextRegion()) {
403                    add_region_to_dimregs(region, stereo, all_dimregs);
404                }
405            }
406        } else {
407            gig::Region* region = m_RegionChooser.get_region();
408            if (region) {
409                add_region_to_dimregs(region, stereo, all_dimregs);
410            }
411        }
412    }
413    
414    void MainWindow::dimreg_all_dimregs_toggled()
415    {
416        dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
417        update_dimregs();
418    }
419    
420    void MainWindow::dimreg_changed()
421    {
422        update_dimregs();
423        dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());
424    }
425    
426    void MainWindow::on_sel_change()
427    {
428        m_RegionChooser.set_instrument(get_instrument());
429    }
430    
431  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
432  {  {
433      Loader* loader = static_cast<Loader*>(progress->custom);      Loader* loader = static_cast<Loader*>(progress->custom);
# Line 430  void MainWindow::__clear() { Line 515  void MainWindow::__clear() {
515      // free libgig's gig::File instance      // free libgig's gig::File instance
516      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
517      file = NULL;      file = NULL;
518      file_is_shared = false;      set_file_is_shared(false);
519  }  }
520    
521  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
# Line 766  void MainWindow::on_action_help_about() Line 851  void MainWindow::on_action_help_about()
851  #ifdef ABOUT_DIALOG  #ifdef ABOUT_DIALOG
852      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
853      dialog.set_version(VERSION);      dialog.set_version(VERSION);
854        dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");
855        dialog.set_comments(
856            "Released under the GNU General Public License.\n"
857            "\n"
858            "Please notice that this is still a very young instrument editor. "
859            "So better backup your Gigasampler files before editing them with "
860            "this application.\n"
861            "\n"
862            "Please report bugs to: http://bugs.linuxsampler.org"
863        );
864        dialog.set_website("http://www.linuxsampler.org");
865        dialog.set_website_label("http://www.linuxsampler.org");
866      dialog.run();      dialog.run();
867  #endif  #endif
868  }  }
# Line 826  void PropDialog::set_info(DLS::Info* inf Line 923  void PropDialog::set_info(DLS::Info* inf
923      entry[15].set_text(info->Subject);      entry[15].set_text(info->Subject);
924  }  }
925    
926    void InstrumentProps::set_IsDrum(bool value)
927    {
928        instrument->IsDrum = value;
929    }
930    
931    void InstrumentProps::set_MIDIBank(uint16_t value)
932    {
933        instrument->MIDIBank = value;
934    }
935    
936    void InstrumentProps::set_MIDIProgram(uint32_t value)
937    {
938        instrument->MIDIProgram = value;
939    }
940    
941    void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)
942    {
943        instrument->DimensionKeyRange.low = value;
944        if (value > instrument->DimensionKeyRange.high) {
945            eDimensionKeyRangeHigh.set_value(value);
946        }
947    }
948    
949    void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)
950    {
951        instrument->DimensionKeyRange.high = value;
952        if (value < instrument->DimensionKeyRange.low) {
953            eDimensionKeyRangeLow.set_value(value);
954        }
955    }
956    
957  void InstrumentProps::add_prop(BoolEntry& boolentry)  void InstrumentProps::add_prop(BoolEntry& boolentry)
958  {  {
959      table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,      table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,
960                   Gtk::FILL, Gtk::SHRINK);                   Gtk::FILL, Gtk::SHRINK);
961      rowno++;      rowno++;
     boolentry.signal_changed_by_user().connect(instrument_changed.make_slot());  
962  }  }
963    
964  void InstrumentProps::add_prop(BoolEntryPlus6& boolentry)  void InstrumentProps::add_prop(BoolEntryPlus6& boolentry)
# Line 839  void InstrumentProps::add_prop(BoolEntry Line 966  void InstrumentProps::add_prop(BoolEntry
966      table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,      table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,
967                   Gtk::FILL, Gtk::SHRINK);                   Gtk::FILL, Gtk::SHRINK);
968      rowno++;      rowno++;
     boolentry.signal_changed_by_user().connect(instrument_changed.make_slot());  
969  }  }
970    
971  void InstrumentProps::add_prop(LabelWidget& prop)  void InstrumentProps::add_prop(LabelWidget& prop)
# Line 849  void InstrumentProps::add_prop(LabelWidg Line 975  void InstrumentProps::add_prop(LabelWidg
975      table.attach(prop.widget, 1, 2, rowno, rowno + 1,      table.attach(prop.widget, 1, 2, rowno, rowno + 1,
976                   Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);                   Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
977      rowno++;      rowno++;
     prop.signal_changed_by_user().connect(instrument_changed.make_slot());  
978  }  }
979    
980  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps()
# Line 866  InstrumentProps::InstrumentProps() Line 991  InstrumentProps::InstrumentProps()
991        ePitchbendRange("Pitchbend range", 0, 12),        ePitchbendRange("Pitchbend range", 0, 12),
992        ePianoReleaseMode("Piano release mode"),        ePianoReleaseMode("Piano release mode"),
993        eDimensionKeyRangeLow("Dimension key range low"),        eDimensionKeyRangeLow("Dimension key range low"),
994        eDimensionKeyRangeHigh("Dimension key range high")        eDimensionKeyRangeHigh("Dimension key range high"),
995          update_model(0)
996  {  {
997      set_title("Instrument properties");      set_title("Instrument properties");
998    
999        connect(eIsDrum, &InstrumentProps::set_IsDrum);
1000        connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1001        connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
1002        connect(eAttenuation, &gig::Instrument::Attenuation);
1003        connect(eGainPlus6, &gig::Instrument::Attenuation);
1004        connect(eEffectSend, &gig::Instrument::EffectSend);
1005        connect(eFineTune, &gig::Instrument::FineTune);
1006        connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1007        connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1008        connect(eDimensionKeyRangeLow,
1009                &InstrumentProps::set_DimensionKeyRange_low);
1010        connect(eDimensionKeyRangeHigh,
1011                &InstrumentProps::set_DimensionKeyRange_high);
1012    
1013      rowno = 0;      rowno = 0;
1014      table.set_col_spacings(5);      table.set_col_spacings(5);
1015    
# Line 886  InstrumentProps::InstrumentProps() Line 1026  InstrumentProps::InstrumentProps()
1026      add_prop(eDimensionKeyRangeLow);      add_prop(eDimensionKeyRangeLow);
1027      add_prop(eDimensionKeyRangeHigh);      add_prop(eDimensionKeyRangeHigh);
1028    
     eDimensionKeyRangeLow.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed));  
     eDimensionKeyRangeHigh.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed));  
   
1029      add(vbox);      add(vbox);
1030      table.set_border_width(5);      table.set_border_width(5);
1031      vbox.pack_start(table);      vbox.pack_start(table);
# Line 913  InstrumentProps::InstrumentProps() Line 1048  InstrumentProps::InstrumentProps()
1048    
1049  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1050  {  {
1051        this->instrument = instrument;
1052    
1053        update_model++;
1054      eName.set_ptr(&instrument->pInfo->Name);      eName.set_ptr(&instrument->pInfo->Name);
1055      eIsDrum.set_ptr(&instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1056      eMIDIBank.set_ptr(&instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1057      eMIDIProgram.set_ptr(&instrument->MIDIProgram);      eMIDIProgram.set_value(instrument->MIDIProgram);
1058      eAttenuation.set_ptr(&instrument->Attenuation);      eAttenuation.set_value(instrument->Attenuation);
1059      eGainPlus6.set_ptr(&instrument->Attenuation);      eGainPlus6.set_value(instrument->Attenuation);
1060      eEffectSend.set_ptr(&instrument->EffectSend);      eEffectSend.set_value(instrument->EffectSend);
1061      eFineTune.set_ptr(&instrument->FineTune);      eFineTune.set_value(instrument->FineTune);
1062      ePitchbendRange.set_ptr(&instrument->PitchbendRange);      ePitchbendRange.set_value(instrument->PitchbendRange);
1063      ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode);      ePianoReleaseMode.set_value(instrument->PianoReleaseMode);
1064      eDimensionKeyRangeLow.set_ptr(0);      eDimensionKeyRangeLow.set_value(instrument->DimensionKeyRange.low);
1065      eDimensionKeyRangeHigh.set_ptr(0);      eDimensionKeyRangeHigh.set_value(instrument->DimensionKeyRange.high);
1066      eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low);      update_model--;
     eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high);  
 }  
   
 void InstrumentProps::key_range_low_changed()  
 {  
     double l = eDimensionKeyRangeLow.get_value();  
     double h = eDimensionKeyRangeHigh.get_value();  
     if (h < l) eDimensionKeyRangeHigh.set_value(l);  
 }  
   
 void InstrumentProps::key_range_high_changed()  
 {  
     double l = eDimensionKeyRangeLow.get_value();  
     double h = eDimensionKeyRangeHigh.get_value();  
     if (h < l) eDimensionKeyRangeLow.set_value(h);  
1067  }  }
1068    
1069  sigc::signal<void>& InstrumentProps::signal_instrument_changed()  sigc::signal<void>& InstrumentProps::signal_instrument_changed()
# Line 959  void MainWindow::file_changed() Line 1082  void MainWindow::file_changed()
1082  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1083  {  {
1084      file = 0;      file = 0;
1085      file_is_shared = isSharedInstrument;      set_file_is_shared(isSharedInstrument);
1086    
1087      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename = filename ? filename : _("Unsaved Gig File");
1088      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
# Line 1022  void MainWindow::load_gig(gig::File* gig Line 1145  void MainWindow::load_gig(gig::File* gig
1145    
1146  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
1147  {  {
1148      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      gig::Instrument* instrument = get_instrument();
1149      Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();      if (instrument)
     if (it)  
1150      {      {
1151          Gtk::TreeModel::Row row = *it;          instrumentProps.set_instrument(instrument);
1152          if (row[m_Columns.m_col_instr])          instrumentProps.show();
1153          {          instrumentProps.deiconify();
             instrumentProps.set_instrument(row[m_Columns.m_col_instr]);  
             instrumentProps.show();  
             instrumentProps.deiconify();  
         }  
1154      }      }
1155  }  }
1156    
1157    void MainWindow::on_action_view_status_bar() {
1158        Gtk::CheckMenuItem* item =
1159            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
1160        if (!item) {
1161            std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n";
1162            return;
1163        }
1164        if (item->get_active()) m_StatusBar.show();
1165        else                    m_StatusBar.hide();
1166    }
1167    
1168  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1169  {  {
1170      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
# Line 1463  void MainWindow::on_sample_label_drop_dr Line 1592  void MainWindow::on_sample_label_drop_dr
1592          // notify we're done with altering          // notify we're done with altering
1593          region_changed_signal.emit(region);          region_changed_signal.emit(region);
1594    
1595            file_changed();
1596    
1597          return;          return;
1598      }      }
1599      // drop failed      // drop failed
# Line 1503  void MainWindow::instrument_name_changed Line 1634  void MainWindow::instrument_name_changed
1634      }      }
1635  }  }
1636    
1637    void MainWindow::set_file_is_shared(bool b) {
1638        this->file_is_shared = b;
1639    
1640        if (file_is_shared) {
1641            m_AttachedStateLabel.set_label(_("live-mode"));
1642            m_AttachedStateImage.set(
1643                Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
1644            );
1645        } else {
1646            m_AttachedStateLabel.set_label(_("stand-alone"));
1647            m_AttachedStateImage.set(
1648                Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
1649            );
1650        }
1651    }
1652    
1653  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
1654      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
1655  }  }

Legend:
Removed from v.1382  
changed lines
  Added in v.1533

  ViewVC Help
Powered by ViewVC