/[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 2398 by persson, Sun Jan 13 09:14:29 2013 UTC revision 2548 by schoenebeck, Tue May 13 12:17:43 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2013 Andreas Persson   * Copyright (C) 2006-2014 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 30  Line 30 
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
 #include <gtkmm/radiomenuitem.h>  
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
35  #include "wrapLabel.hh"  #include "wrapLabel.hh"
# Line 43  Line 42 
42  #include <sndfile.h>  #include <sndfile.h>
43    
44  #include "mainwindow.h"  #include "mainwindow.h"
45    #include "Settings.h"
46    #include "CombineInstrumentsDialog.h"
47  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
48  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
49    
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
   
 Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }  
   
 void Table::add(BoolEntry& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(BoolEntryPlus6& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(LabelWidget& prop)  
 {  
     attach(prop.label, 1, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     attach(prop.widget, 2, 3, rowno, rowno + 1,  
            Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
50    
51  MainWindow::MainWindow() :  MainWindow::MainWindow() :
52      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
# Line 91  MainWindow::MainWindow() : Line 61  MainWindow::MainWindow() :
61      add(m_VBox);      add(m_VBox);
62    
63      // Handle selection      // Handle selection
64      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
65          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
66    
67      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 121  MainWindow::MainWindow() : Line 90  MainWindow::MainWindow() :
90      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
91      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
92    
93        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
94        dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
95        dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
96        dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
97    
98      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
99      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
# Line 155  MainWindow::MainWindow() : Line 128  MainWindow::MainWindow() :
128                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
129                       sigc::mem_fun(                       sigc::mem_fun(
130                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
131        actionGroup->add(Gtk::Action::create("MidiRules",
132                                             _("_Midi Rules")),
133                         sigc::mem_fun(
134                             *this, &MainWindow::show_midi_rules));
135      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
136                       sigc::mem_fun(                       sigc::mem_fun(
137                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
138      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
139    
140      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
141        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
142    
143      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
144            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
145        toggle_action->set_active(true);
146        actionGroup->add(toggle_action);
147    
148        toggle_action =
149            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
150        toggle_action->set_active(true);
151        actionGroup->add(toggle_action);
152    
153        toggle_action =
154            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
155        toggle_action->set_active(true);
156        actionGroup->add(toggle_action);
157    
158    
159        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
160        toggle_action =
161          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
162      toggle_action->set_active(true);      toggle_action->set_active(true);
163      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 187  MainWindow::MainWindow() : Line 183  MainWindow::MainWindow() :
183          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
184      );      );
185    
186    
187        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
188        
189        toggle_action =
190            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
191        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
192        actionGroup->add(
193            toggle_action,
194            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
195        );
196    
197    
198        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
199    
200        actionGroup->add(
201            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
202            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
203        );
204    
205    
206      // sample right-click popup actions      // sample right-click popup actions
207      actionGroup->add(      actionGroup->add(
208          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 228  MainWindow::MainWindow() : Line 244  MainWindow::MainWindow() :
244          "      <separator/>"          "      <separator/>"
245          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
246          "    </menu>"          "    </menu>"
247            "    <menu action='MenuEdit'>"
248            "      <menuitem action='CopySampleUnity'/>"
249            "      <menuitem action='CopySampleTune'/>"
250            "      <menuitem action='CopySampleLoop'/>"
251            "    </menu>"
252          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
253          "    </menu>"          "    </menu>"
254          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
255          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
256          "    </menu>"          "    </menu>"
257            "    <menu action='MenuTools'>"
258            "      <menuitem action='CombineInstruments'/>"
259            "    </menu>"
260            "    <menu action='MenuSettings'>"
261            "      <menuitem action='WarnUserOnExtensions'/>"
262            "    </menu>"
263          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
264          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
265          "    </menu>"          "    </menu>"
266          "  </menubar>"          "  </menubar>"
267          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
268          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
269            "    <menuitem action='MidiRules'/>"
270          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
271          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
272          "    <separator/>"          "    <separator/>"
# Line 248  MainWindow::MainWindow() : Line 276  MainWindow::MainWindow() :
276          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
277          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
278          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
279          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
280          "    <separator/>"          "    <separator/>"
281          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
282          "  </popup>"          "  </popup>"
# Line 256  MainWindow::MainWindow() : Line 284  MainWindow::MainWindow() :
284      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
285    
286      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
287        
288        // Set tooltips for menu items (for some reason, setting a tooltip on the
289        // respective Gtk::Action objects above will simply be ignored, no matter
290        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
291        // Gtk::Action::create()).
292        {
293            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
294                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
295            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action."));
296        }
297        {
298            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
299                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
300            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action."));
301        }
302        {
303            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
304                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
305            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action."));
306        }
307        {
308            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
309                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
310            item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
311        }
312    
313        instrument_menu = static_cast<Gtk::MenuItem*>(
314            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
315    
316      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
317      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 281  MainWindow::MainWindow() : Line 337  MainWindow::MainWindow() :
337      // Create the Tree model:      // Create the Tree model:
338      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
339      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
340      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
341        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
342          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
343      );      );
344    
# Line 292  MainWindow::MainWindow() : Line 349  MainWindow::MainWindow() :
349      // create samples treeview (including its data model)      // create samples treeview (including its data model)
350      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
351      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
352        m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
353      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
354      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
355      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 322  MainWindow::MainWindow() : Line 380  MainWindow::MainWindow() :
380          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
381      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
382          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
383      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
384            sigc::mem_fun(*this, &MainWindow::file_changed));
385        propDialog.signal_changed().connect(
386          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
387      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
388          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
389    
390      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 399  void MainWindow::region_changed() Line 459  void MainWindow::region_changed()
459  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
460  {  {
461      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
462      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
463            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
464      if (it) {      if (it) {
465          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
466          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 460  void MainWindow::dimreg_changed() Line 519  void MainWindow::dimreg_changed()
519    
520  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
521  {  {
522        // select item in instrument menu
523        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
524        if (it) {
525            Gtk::TreePath path(it);
526            int index = path[0];
527            const std::vector<Gtk::Widget*> children =
528                instrument_menu->get_children();
529            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
530        }
531    
532      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
533  }  }
534    
# Line 538  LoadDialog::LoadDialog(const Glib::ustri Line 607  LoadDialog::LoadDialog(const Glib::ustri
607  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
608  // before a new .gig file is to be created or to be loaded.  // before a new .gig file is to be created or to be loaded.
609  void MainWindow::__clear() {  void MainWindow::__clear() {
     // remove all entries from "Instrument" menu  
     Gtk::MenuItem* instrument_menu =  
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
     instrument_menu->hide();  
     Gtk::Menu* menu = instrument_menu->get_submenu();  
     while (menu->get_children().size()) {  
         Gtk::Widget* child = *menu->get_children().begin();  
         menu->remove(*child);  
         delete child;  
     }  
610      // forget all samples that ought to be imported      // forget all samples that ought to be imported
611      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
612      // clear the samples and instruments tree views      // clear the samples and instruments tree views
613      m_refTreeModel->clear();      m_refTreeModel->clear();
614      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
615        // remove all entries from "Instrument" menu
616        while (!instrument_menu->get_children().empty()) {
617            remove_instrument_from_menu(0);
618        }
619      // free libgig's gig::File instance      // free libgig's gig::File instance
620      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
621      file = NULL;      file = NULL;
# Line 571  void MainWindow::on_action_file_new() Line 634  void MainWindow::on_action_file_new()
634      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
635      // already add one new instrument by default      // already add one new instrument by default
636      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
637      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
638      // update GUI with that new gig::File      // update GUI with that new gig::File
639      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
640  }  }
# Line 904  void MainWindow::__import_queued_samples Line 967  void MainWindow::__import_queued_samples
967              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
968          } catch (std::string what) {          } catch (std::string what) {
969              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
970              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
971              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
972              ++iter;              ++iter;
973          }          }
974      }      }
975      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
976      if (error_files.size()) {      if (!error_files.empty()) {
977          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
978          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
979          msg.run();          msg.run();
# Line 923  void MainWindow::on_action_file_properti Line 986  void MainWindow::on_action_file_properti
986      propDialog.deiconify();      propDialog.deiconify();
987  }  }
988    
989    void MainWindow::on_action_warn_user_on_extensions() {
990        Settings::singleton()->warnUserOnExtensions =
991            !Settings::singleton()->warnUserOnExtensions;
992    }
993    
994  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
995  {  {
996      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 932  void MainWindow::on_action_help_about() Line 1000  void MainWindow::on_action_help_about()
1000      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1001  #endif  #endif
1002      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1003      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1004      dialog.set_comments(_(      const std::string sComment =
1005          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1006          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1007          "Please notice that this is still a very young instrument editor. "          _(
1008          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1009          "this application.\n"              "\n"
1010          "\n"              "Please notice that this is still a very young instrument editor. "
1011          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
1012      );              "this application.\n"
1013                "\n"
1014                "Please report bugs to: http://bugs.linuxsampler.org"
1015            );
1016        dialog.set_comments(sComment.c_str());
1017      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1018      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1019      dialog.run();      dialog.run();
# Line 965  PropDialog::PropDialog() Line 1037  PropDialog::PropDialog()
1037        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1038        eSubject(_("Subject")),        eSubject(_("Subject")),
1039        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1040        table(2, 1),        table(2, 1)
       update_model(0)  
1041  {  {
1042      set_title(_("File Properties"));      set_title(_("File Properties"));
1043      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1026  PropDialog::PropDialog() Line 1097  PropDialog::PropDialog()
1097    
1098  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1099  {  {
1100      this->info = info;      update(info);
     update_model++;  
     eName.set_value(info->Name);  
     eCreationDate.set_value(info->CreationDate);  
     eComments.set_value(info->Comments);  
     eProduct.set_value(info->Product);  
     eCopyright.set_value(info->Copyright);  
     eArtists.set_value(info->Artists);  
     eGenre.set_value(info->Genre);  
     eKeywords.set_value(info->Keywords);  
     eEngineer.set_value(info->Engineer);  
     eTechnician.set_value(info->Technician);  
     eSoftware.set_value(info->Software);  
     eMedium.set_value(info->Medium);  
     eSource.set_value(info->Source);  
     eSourceForm.set_value(info->SourceForm);  
     eCommissioned.set_value(info->Commissioned);  
     eSubject.set_value(info->Subject);  
     update_model--;  
1101  }  }
1102    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1103    
1104  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_Name(const gig::String& name)
1105  {  {
1106      instrument->IsDrum = value;      m->pInfo->Name = name;
1107  }  }
1108    
1109  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1110  {  {
1111      instrument->MIDIBank = value;      update_model++;
1112        eName.set_value(m->pInfo->Name);
1113        update_model--;
1114  }  }
1115    
1116  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1117  {  {
1118      instrument->MIDIProgram = value;      m->IsDrum = value;
1119  }  }
1120    
1121  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1122  {  {
1123      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1124  }  }
1125    
1126  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1127  {  {
1128      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1129  }  }
1130    
1131  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1132      : update_model(0),      quitButton(Gtk::Stock::CLOSE),
1133        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1134        table(2,1),      eName(_("Name")),
1135        eName(_("Name")),      eIsDrum(_("Is drum")),
1136        eIsDrum(_("Is drum")),      eMIDIBank(_("MIDI bank"), 0, 16383),
1137        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIProgram(_("MIDI program")),
1138        eMIDIProgram(_("MIDI program")),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1139        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1140        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eEffectSend(_("Effect send"), 0, 65535),
1141        eEffectSend(_("Effect send"), 0, 65535),      eFineTune(_("Fine tune"), -8400, 8400),
1142        eFineTune(_("Fine tune"), -8400, 8400),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1143        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePianoReleaseMode(_("Piano release mode")),
1144        ePianoReleaseMode(_("Piano release mode")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1145        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       eDimensionKeyRangeHigh(_("Keyswitching range high"))  
1146  {  {
1147      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1148    
# Line 1111  InstrumentProps::InstrumentProps() Line 1155  InstrumentProps::InstrumentProps()
1155            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1156      );      );
1157    
1158        connect(eName, &InstrumentProps::set_Name);
1159      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1160      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1161      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1120  InstrumentProps::InstrumentProps() Line 1165  InstrumentProps::InstrumentProps()
1165      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1166      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1167      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1168      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1169              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1170      connect(eDimensionKeyRangeHigh,  
1171              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1172    
1173      table.set_col_spacings(5);      table.set_col_spacings(5);
1174    
# Line 1162  InstrumentProps::InstrumentProps() Line 1207  InstrumentProps::InstrumentProps()
1207    
1208  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1209  {  {
1210      this->instrument = instrument;      update(instrument);
1211    
1212      update_model++;      update_model++;
1213      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1214      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1215      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1216      eMIDIProgram.set_value(instrument->MIDIProgram);      eMIDIProgram.set_value(instrument->MIDIProgram);
     eAttenuation.set_value(instrument->Attenuation);  
     eGainPlus6.set_value(instrument->Attenuation);  
     eEffectSend.set_value(instrument->EffectSend);  
     eFineTune.set_value(instrument->FineTune);  
     ePitchbendRange.set_value(instrument->PitchbendRange);  
     ePianoReleaseMode.set_value(instrument->PianoReleaseMode);  
     eDimensionKeyRangeLow.set_value(instrument->DimensionKeyRange.low);  
     eDimensionKeyRangeHigh.set_value(instrument->DimensionKeyRange.high);  
1217      update_model--;      update_model--;
1218  }  }
1219    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1220    
1221  void MainWindow::file_changed()  void MainWindow::file_changed()
1222  {  {
# Line 1205  void MainWindow::load_gig(gig::File* gig Line 1238  void MainWindow::load_gig(gig::File* gig
1238    
1239      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1240    
1241      Gtk::MenuItem* instrument_menu =      instrument_name_connection.block();
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
   
     int instrument_index = 0;  
     Gtk::RadioMenuItem::Group instrument_group;  
1242      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1243           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1244            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1245    
1246          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1247          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1248          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1249          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1250          // create a menu item for this instrument  
1251          Gtk::RadioMenuItem* item =          add_instrument_to_menu(name);
             new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str());  
         instrument_menu->get_submenu()->append(*item);  
         item->signal_activate().connect(  
             sigc::bind(  
                 sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),  
                 instrument_index  
             )  
         );  
         instrument_index++;  
1252      }      }
1253      instrument_menu->show();      instrument_name_connection.unblock();
1254      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1255    
1256      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1257          if (group->Name != "") {          if (group->Name != "") {
1258              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1259              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1260              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1261              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1262              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1263              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1243  void MainWindow::load_gig(gig::File* gig Line 1265  void MainWindow::load_gig(gig::File* gig
1265                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1266                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1267                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1268                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1269                        gig_to_utf8(sample->pInfo->Name);
1270                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1271                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1272              }              }
# Line 1253  void MainWindow::load_gig(gig::File* gig Line 1276  void MainWindow::load_gig(gig::File* gig
1276      file = gig;      file = gig;
1277    
1278      // select the first instrument      // select the first instrument
1279      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1280      tree_sel_ref->select(Gtk::TreePath("0"));  
1281        instr_props_set_instrument();
1282        gig::Instrument* instrument = get_instrument();
1283        if (instrument) {
1284            midiRules.set_instrument(instrument);
1285        }
1286  }  }
1287    
1288  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1289  {  {
1290      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1291      if (instrument)  
1292      {      Gtk::TreeModel::const_iterator it =
1293            m_TreeView.get_selection()->get_selected();
1294        if (it) {
1295            Gtk::TreeModel::Row row = *it;
1296            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1297    
1298          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1299    
1300            // make sure instrument tree is updated when user changes the
1301            // instrument name in instrument properties window
1302            instrumentProps.signal_name_changed().connect(
1303                sigc::bind(
1304                    sigc::mem_fun(*this,
1305                                  &MainWindow::instr_name_changed_by_instr_props),
1306                    it));
1307        } else {
1308            instrumentProps.hide();
1309        }
1310        return it;
1311    }
1312    
1313    void MainWindow::show_instr_props()
1314    {
1315        if (instr_props_set_instrument()) {
1316          instrumentProps.show();          instrumentProps.show();
1317          instrumentProps.deiconify();          instrumentProps.deiconify();
1318      }      }
1319  }  }
1320    
1321    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1322    {
1323        Gtk::TreeModel::Row row = *it;
1324        Glib::ustring name = row[m_Columns.m_col_name];
1325    
1326        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1327        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1328        if (gigname != name) {
1329            row[m_Columns.m_col_name] = gigname;
1330        }
1331    }
1332    
1333    void MainWindow::show_midi_rules()
1334    {
1335        if (gig::Instrument* instrument = get_instrument())
1336        {
1337            midiRules.set_instrument(instrument);
1338            midiRules.show();
1339            midiRules.deiconify();
1340        }
1341    }
1342    
1343  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1344      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1345          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1279  void MainWindow::on_action_view_status_b Line 1351  void MainWindow::on_action_view_status_b
1351      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1352  }  }
1353    
1354    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1355        Gtk::CheckMenuItem* item =
1356            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1357        if (!item) {
1358            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1359            return true;
1360        }
1361        return item->get_active();
1362    }
1363    
1364    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1365        Gtk::CheckMenuItem* item =
1366            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1367        if (!item) {
1368            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1369            return true;
1370        }
1371        return item->get_active();
1372    }
1373    
1374    bool MainWindow::is_copy_samples_loop_enabled() const {
1375        Gtk::CheckMenuItem* item =
1376            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1377        if (!item) {
1378            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1379            return true;
1380        }
1381        return item->get_active();
1382    }
1383    
1384  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1385  {  {
1386      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1387          show_instr_props();          show_instr_props();
1388      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1389            // gig v2 files have no midi rules
1390            static_cast<Gtk::MenuItem*>(
1391                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1392                    !(file->pVersion && file->pVersion->major == 2));
1393          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1394      }      }
1395  }  }
1396    
1397  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1398      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1399            const std::vector<Gtk::Widget*> children =
1400                instrument_menu->get_children();
1401            std::vector<Gtk::Widget*>::const_iterator it =
1402                find(children.begin(), children.end(), item);
1403            if (it != children.end()) {
1404                int index = it - children.begin();
1405                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1406    
1407                m_RegionChooser.set_instrument(file->GetInstrument(index));
1408            }
1409        }
1410  }  }
1411    
1412  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1319  void MainWindow::on_sample_treeview_butt Line 1436  void MainWindow::on_sample_treeview_butt
1436      }      }
1437  }  }
1438    
1439  void MainWindow::on_action_add_instrument() {  
1440      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1441      if (!file) return;      const Glib::ustring& name, int position) {
1442      gig::Instrument* instrument = file->AddInstrument();  
1443      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1444      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1445          _("Unnamed Instrument ") + ToString(__instrument_indexer);      if (!children.empty()) {
1446            instrument_group =
1447                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1448        }
1449        Gtk::RadioMenuItem* item =
1450            new Gtk::RadioMenuItem(instrument_group, name);
1451        if (position < 0) {
1452            instrument_menu->append(*item);
1453        } else {
1454            instrument_menu->insert(*item, position);
1455        }
1456        item->show();
1457        item->signal_activate().connect(
1458            sigc::bind(
1459                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1460                item));
1461        return item;
1462    }
1463    
1464    void MainWindow::remove_instrument_from_menu(int index) {
1465        const std::vector<Gtk::Widget*> children =
1466            instrument_menu->get_children();
1467        Gtk::Widget* child = children[index];
1468        instrument_menu->remove(*child);
1469        delete child;
1470    }
1471    
1472    void MainWindow::add_instrument(gig::Instrument* instrument) {
1473        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1474    
1475      // update instrument tree view      // update instrument tree view
1476        instrument_name_connection.block();
1477      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1478      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1479      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1480      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1481        instrument_name_connection.unblock();
1482    
1483        add_instrument_to_menu(name);
1484    
1485        m_TreeView.get_selection()->select(iterInstr);
1486    
1487      file_changed();      file_changed();
1488  }  }
1489    
1490    void MainWindow::on_action_add_instrument() {
1491        static int __instrument_indexer = 0;
1492        if (!file) return;
1493        gig::Instrument* instrument = file->AddInstrument();
1494        __instrument_indexer++;
1495        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1496                                                ToString(__instrument_indexer));
1497    
1498        add_instrument(instrument);
1499    }
1500    
1501  void MainWindow::on_action_duplicate_instrument() {  void MainWindow::on_action_duplicate_instrument() {
1502      if (!file) return;      if (!file) return;
1503        
1504      // retrieve the currently selected instrument      // retrieve the currently selected instrument
1505      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
1506      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
# Line 1345  void MainWindow::on_action_duplicate_ins Line 1509  void MainWindow::on_action_duplicate_ins
1509      Gtk::TreeModel::Row row = *itSelection;      Gtk::TreeModel::Row row = *itSelection;
1510      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1511      if (!instrOrig) return;      if (!instrOrig) return;
1512        
1513      // duplicate the orginal instrument      // duplicate the orginal instrument
1514      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1515      instrNew->pInfo->Name =      instrNew->pInfo->Name =
1516          instrOrig->pInfo->Name + " (" + _("Copy") + ")";          instrOrig->pInfo->Name +
1517                    gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1518      // update instrument tree view  
1519      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      add_instrument(instrNew);
     Gtk::TreeModel::Row rowInstr = *iterInstr;  
     rowInstr[m_Columns.m_col_name] = instrNew->pInfo->Name.c_str();  
     rowInstr[m_Columns.m_col_instr] = instrNew;  
     file_changed();  
1520  }  }
1521    
1522  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 1378  void MainWindow::on_action_remove_instru Line 1538  void MainWindow::on_action_remove_instru
1538          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1539          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1540          try {          try {
1541                Gtk::TreePath path(it);
1542                int index = path[0];
1543    
1544              // remove instrument from the gig file              // remove instrument from the gig file
1545              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1546              file_changed();              file_changed();
1547    
1548                remove_instrument_from_menu(index);
1549    
1550                // remove row from instruments tree view
1551                m_refTreeModel->erase(it);
1552    
1553    #if GTKMM_MAJOR_VERSION < 3
1554                // select another instrument (in gtk3 this is done
1555                // automatically)
1556                if (!m_refTreeModel->children().empty()) {
1557                    if (index == m_refTreeModel->children().size()) {
1558                        index--;
1559                    }
1560                    m_TreeView.get_selection()->select(
1561                        Gtk::TreePath(ToString(index)));
1562                }
1563    #endif
1564                instr_props_set_instrument();
1565                instr = get_instrument();
1566                if (instr) {
1567                    midiRules.set_instrument(instr);
1568                } else {
1569                    midiRules.hide();
1570                }
1571          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1572              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1573              msg.run();              msg.run();
# Line 1402  void MainWindow::on_action_add_group() { Line 1587  void MainWindow::on_action_add_group() {
1587      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1588      if (!file) return;      if (!file) return;
1589      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1590      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1591      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1592      __sample_indexer++;      __sample_indexer++;
1593      // update sample tree view      // update sample tree view
1594      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1595      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1596      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1597      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1598      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1599      file_changed();      file_changed();
# Line 1517  void MainWindow::on_action_add_sample() Line 1702  void MainWindow::on_action_add_sample()
1702                          break;                          break;
1703                      }                      }
1704                  }                  }
1705                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1706                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1707                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1708                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1531  void MainWindow::on_action_add_sample() Line 1716  void MainWindow::on_action_add_sample()
1716                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1717                  {                  {
1718                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1719                        sample->FineTune      = instrument.detune;
1720    
1721                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1722                          sample->Loops = 1;                          sample->Loops = 1;
# Line 1568  void MainWindow::on_action_add_sample() Line 1754  void MainWindow::on_action_add_sample()
1754                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1755                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1756                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1757                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1758                        gig_to_utf8(sample->pInfo->Name);
1759                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1760                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1761                  // close sound file                  // close sound file
1762                  sf_close(hFile);                  sf_close(hFile);
1763                  file_changed();                  file_changed();
1764              } catch (std::string what) { // remember the files that made trouble (and their cause)              } catch (std::string what) { // remember the files that made trouble (and their cause)
1765                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1766                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1767              }              }
1768          }          }
1769          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
1770          if (error_files.size()) {          if (!error_files.empty()) {
1771              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;
1772              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1773              msg.run();              msg.run();
# Line 1593  void MainWindow::on_action_replace_all_s Line 1780  void MainWindow::on_action_replace_all_s
1780      if (!file) return;      if (!file) return;
1781      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1782                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1783      const char* str =      const char* str =
1784          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1785            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
1786            "directory.\n\n"            "directory.\n\n"
# Line 1639  void MainWindow::on_action_replace_all_s Line 1826  void MainWindow::on_action_replace_all_s
1826               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1827          {          {
1828              std::string filename =              std::string filename =
1829                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1830                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1831                                             postfixEntryBox.get_text());
1832              SF_INFO info;              SF_INFO info;
1833              info.format = 0;              info.format = 0;
1834              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1673  void MainWindow::on_action_replace_all_s Line 1861  void MainWindow::on_action_replace_all_s
1861              }              }
1862              catch (std::string what)              catch (std::string what)
1863              {              {
1864                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1865                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1866                        " (" + what + ")";
1867              }              }
1868          }          }
1869          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
1870          if (error_files.size()) {          if (!error_files.empty()) {
1871              Glib::ustring txt =              Glib::ustring txt =
1872                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1873              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1699  void MainWindow::on_action_remove_sample Line 1888  void MainWindow::on_action_remove_sample
1888          try {          try {
1889              // remove group or sample from the gig file              // remove group or sample from the gig file
1890              if (group) {              if (group) {
1891                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1892                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1893                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1894                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1825  void MainWindow::on_sample_label_drop_dr Line 2014  void MainWindow::on_sample_label_drop_dr
2014              channels_changed = true;              channels_changed = true;
2015              region_changed();              region_changed();
2016          }          }
2017          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2018                sample,
2019                is_copy_samples_unity_note_enabled(),
2020                is_copy_samples_fine_tune_enabled(),
2021                is_copy_samples_loop_enabled()
2022            );
2023    
2024          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2025              // add samplechannel dimension              // add samplechannel dimension
# Line 1868  void MainWindow::sample_name_changed(con Line 2062  void MainWindow::sample_name_changed(con
2062      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2063      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2064      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2065        gig::String gigname(gig_from_utf8(name));
2066      if (group) {      if (group) {
2067          if (group->Name != name) {          if (group->Name != gigname) {
2068              group->Name = name;              group->Name = gigname;
2069              printf("group name changed\n");              printf("group name changed\n");
2070              file_changed();              file_changed();
2071          }          }
2072      } else if (sample) {      } else if (sample) {
2073          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2074              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2075              printf("sample name changed\n");              printf("sample name changed\n");
2076              file_changed();              file_changed();
2077          }          }
# Line 1888  void MainWindow::instrument_name_changed Line 2083  void MainWindow::instrument_name_changed
2083      if (!iter) return;      if (!iter) return;
2084      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2085      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2086    
2087        // change name in instrument menu
2088        int index = path[0];
2089        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2090        if (index < children.size()) {
2091    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2092            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2093    #else
2094            remove_instrument_from_menu(index);
2095            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2096            item->set_active();
2097    #endif
2098        }
2099    
2100        // change name in gig
2101      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2102      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2103          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2104            instrument->pInfo->Name = gigname;
2105    
2106            // change name in the instrument properties window
2107            if (instrumentProps.get_instrument() == instrument) {
2108                instrumentProps.update_name();
2109            }
2110    
2111          file_changed();          file_changed();
2112      }      }
2113  }  }
2114    
2115    void MainWindow::on_action_combine_instruments() {
2116        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2117        d->show_all();
2118        d->resize(500, 400);
2119        d->run();
2120        if (d->fileWasChanged()) {
2121            // update GUI with new instrument just created
2122            add_instrument(d->newCombinedInstrument());
2123        }
2124        delete d;
2125    }
2126    
2127  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2128      this->file_is_shared = b;      this->file_is_shared = b;
2129    

Legend:
Removed from v.2398  
changed lines
  Added in v.2548

  ViewVC Help
Powered by ViewVC