/[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 1661 by schoenebeck, Sun Feb 3 14:10:47 2008 UTC revision 2550 by schoenebeck, Wed May 14 01:31:30 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006 - 2008 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 18  Line 18 
18   */   */
19    
20  #include <iostream>  #include <iostream>
21    #include <cstring>
22    
23    #include <glibmm/convert.h>
24    #include <glibmm/dispatcher.h>
25    #include <glibmm/miscutils.h>
26    #include <glibmm/stringutils.h>
27    #include <gtkmm/aboutdialog.h>
28  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
29  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
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>
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34    #if GTKMM_MAJOR_VERSION < 3
35  #include "global.h"  #include "wrapLabel.hh"
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
 #define ABOUT_DIALOG  
 #include <gtkmm/aboutdialog.h>  
36  #endif  #endif
37    
38  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #include "global.h"
39  namespace Glib {  #include "compat.h"
 Glib::ustring filename_display_basename(const std::string& filename)  
 {  
     gchar* gstr = g_path_get_basename(filename.c_str());  
     Glib::ustring str(gstr);  
     g_free(gstr);  
     return Glib::filename_to_utf8(str);  
 }  
 }  
 #endif  
40    
41  #include <stdio.h>  #include <stdio.h>
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 97  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 127  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"));
100    
101    
102      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
# Line 161  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 177  MainWindow::MainWindow() : Line 167  MainWindow::MainWindow() :
167      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
168      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
169                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
170      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
171                       sigc::mem_fun(                       sigc::mem_fun(
172                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
173      actionGroup->add(      actionGroup->add(
174          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
175          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
176      );      );
177      actionGroup->add(      actionGroup->add(
178            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
179            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
180        );
181        actionGroup->add(
182          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
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 201  MainWindow::MainWindow() : Line 213  MainWindow::MainWindow() :
213          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
214      );      );
215      actionGroup->add(      actionGroup->add(
216          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
217          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
218      );      );
219      actionGroup->add(      actionGroup->add(
220          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
221          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
222      );      );
223        actionGroup->add(
224            Gtk::Action::create("ReplaceAllSamplesInAllGroups",
225                                _("Replace All Samples in All Groups...")),
226            sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
227        );
228    
229      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
230      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 227  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  #ifdef ABOUT_DIALOG          "    <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>"
 #endif  
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'/>"
272          "    <separator/>"          "    <separator/>"
273          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
274          "  </popup>"          "  </popup>"
# 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' />"
280          "    <separator/>"          "    <separator/>"
281          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
282          "  </popup>"          "  </popup>"
# Line 255  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 264  MainWindow::MainWindow() : Line 321  MainWindow::MainWindow() :
321      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
322      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
323    
324        set_file_is_shared(false);
325    
326      // Status Bar:      // Status Bar:
327      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
328      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 278  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 289  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 300  MainWindow::MainWindow() : Line 361  MainWindow::MainWindow() :
361      );      );
362    
363      // establish drag&drop between samples tree view and dimension region 'Sample' text entry      // establish drag&drop between samples tree view and dimension region 'Sample' text entry
364      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
365      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
366      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
367      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
368          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 319  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 366  MainWindow::MainWindow() : Line 429  MainWindow::MainWindow() :
429    
430      file = 0;      file = 0;
431      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
432    
433      show_all_children();      show_all_children();
434    
435      // start with a new gig file by default      // start with a new gig file by default
436      on_action_file_new();      on_action_file_new();
437    
438        // select 'Instruments' tab by default
439        // (gtk allows this only if the tab childs are visible, thats why it's here)
440        m_TreeViewNotebook.set_current_page(1);
441  }  }
442    
443  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 397  void MainWindow::region_changed() Line 463  void MainWindow::region_changed()
463  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
464  {  {
465      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
466      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
467            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
468      if (it) {      if (it) {
469          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
470          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 458  void MainWindow::dimreg_changed() Line 523  void MainWindow::dimreg_changed()
523    
524  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
525  {  {
526        // select item in instrument menu
527        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
528        if (it) {
529            Gtk::TreePath path(it);
530            int index = path[0];
531            const std::vector<Gtk::Widget*> children =
532                instrument_menu->get_children();
533            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
534        }
535    
536      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
537  }  }
538    
# Line 470  void loader_progress_callback(gig::progr Line 545  void loader_progress_callback(gig::progr
545  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
546  {  {
547      {      {
548          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
549          progress = fraction;          progress = fraction;
550      }      }
551      progress_dispatcher();      progress_dispatcher();
# Line 478  void Loader::progress_callback(float fra Line 553  void Loader::progress_callback(float fra
553    
554  void Loader::thread_function()  void Loader::thread_function()
555  {  {
556      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
557      printf("Start %s\n", filename);      printf("Start %s\n", filename);
558      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
559      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 492  void Loader::thread_function() Line 567  void Loader::thread_function()
567  }  }
568    
569  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
570      : thread(0), filename(filename)      : filename(filename), thread(0)
571  {  {
572  }  }
573    
574  void Loader::launch()  void Loader::launch()
575  {  {
576    #ifdef OLD_THREADS
577      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
578    #else
579        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
580    #endif
581      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
582  }  }
583    
# Line 506  float Loader::get_progress() Line 585  float Loader::get_progress()
585  {  {
586      float res;      float res;
587      {      {
588          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
589          res = progress;          res = progress;
590      }      }
591      return res;      return res;
# Line 532  LoadDialog::LoadDialog(const Glib::ustri Line 611  LoadDialog::LoadDialog(const Glib::ustri
611  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
612  // 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.
613  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();  
     for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) {  
         delete &instrument_menu->get_submenu()->items()[i];  
     }  
     instrument_menu->get_submenu()->items().clear();  
614      // forget all samples that ought to be imported      // forget all samples that ought to be imported
615      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
616      // clear the samples and instruments tree views      // clear the samples and instruments tree views
617      m_refTreeModel->clear();      m_refTreeModel->clear();
618      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
619        // remove all entries from "Instrument" menu
620        while (!instrument_menu->get_children().empty()) {
621            remove_instrument_from_menu(0);
622        }
623      // free libgig's gig::File instance      // free libgig's gig::File instance
624      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
625      file = NULL;      file = NULL;
# Line 563  void MainWindow::on_action_file_new() Line 638  void MainWindow::on_action_file_new()
638      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
639      // already add one new instrument by default      // already add one new instrument by default
640      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
641      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
642      // update GUI with that new gig::File      // update GUI with that new gig::File
643      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
644  }  }
# Line 574  bool MainWindow::close_confirmation_dial Line 649  bool MainWindow::close_confirmation_dial
649                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
650      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
651      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
652      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
 #endif  
653      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
654      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
655      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
# Line 590  bool MainWindow::close_confirmation_dial Line 663  bool MainWindow::close_confirmation_dial
663  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
664      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
665      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
666      dialog.set_secondary_text(      dialog.set_secondary_text(
667          _("If you proceed to work on another instrument file, it won't be "          _("If you proceed to work on another instrument file, it won't be "
668            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
669            "load it.")            "load it."));
    );  
 #endif  
670      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
671      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
672      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 615  void MainWindow::on_action_file_open() Line 685  void MainWindow::on_action_file_open()
685      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
686      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
687      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
688    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
689      Gtk::FileFilter filter;      Gtk::FileFilter filter;
690      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
691    #else
692        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
693        filter->add_pattern("*.gig");
694    #endif
695      dialog.set_filter(filter);      dialog.set_filter(filter);
696      if (current_dir != "") {      if (current_gig_dir != "") {
697          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
698      }      }
699      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
700          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
701          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
702          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
703          load_file(filename.c_str());          load_file(filename.c_str());
704          current_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
705      }      }
706  }  }
707    
708  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
709  {  {
710      __clear();      __clear();
711      load_dialog = new LoadDialog("Loading...", *this);      load_dialog = new LoadDialog(_("Loading..."), *this);
712      load_dialog->show_all();      load_dialog->show_all();
713      loader = new Loader(strdup(name));      loader = new Loader(strdup(name));
714      loader->signal_progress().connect(      loader->signal_progress().connect(
# Line 666  void MainWindow::on_loader_progress() Line 741  void MainWindow::on_loader_progress()
741  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
742  {  {
743      printf("Loader finished!\n");      printf("Loader finished!\n");
744      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
745      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
746      load_dialog->hide();      load_dialog->hide();
747  }  }
# Line 738  bool MainWindow::file_save_as() Line 813  bool MainWindow::file_save_as()
813      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
814      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
815      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2  
816      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
817      // TODO: an overwrite dialog for gtkmm < 2.8  
818  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
819      Gtk::FileFilter filter;      Gtk::FileFilter filter;
820      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
821    #else
822        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
823        filter->add_pattern("*.gig");
824    #endif
825      dialog.set_filter(filter);      dialog.set_filter(filter);
826    
827      if (Glib::path_is_absolute(filename)) {      // set initial dir and filename of the Save As dialog
828          dialog.set_filename(filename);      // and prepare that initial filename as a copy of the gig
829      } else if (current_dir != "") {      {
830          dialog.set_current_folder(current_dir);          std::string basename = Glib::path_get_basename(filename);
831            std::string dir = Glib::path_get_dirname(filename);
832            basename = std::string(_("copy_of_")) + basename;
833            Glib::ustring copyFileName = Glib::build_filename(dir, basename);
834            if (Glib::path_is_absolute(filename)) {
835                dialog.set_filename(copyFileName);
836            } else {
837                if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
838            }
839            dialog.set_current_name(Glib::filename_display_basename(copyFileName));
840      }      }
841      dialog.set_current_name(Glib::filename_display_basename(filename));  
842        // show warning in the dialog
843        Gtk::HBox descriptionArea;
844        descriptionArea.set_spacing(15);
845        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
846        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
847    #if GTKMM_MAJOR_VERSION < 3
848        view::WrapLabel description;
849    #else
850        Gtk::Label description;
851        description.set_line_wrap();
852    #endif
853        description.set_markup(
854            _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
855              "<span style=\"italic\">\"Save\"</span> dialog instead of "
856              "<span style=\"italic\">\"Save As...\"</span> if you want to save "
857              "to the same .gig file. Using "
858              "<span style=\"italic\">\"Save As...\"</span> for writing to the "
859              "same .gig file will end up in corrupted sample wave data!\n")
860        );
861        descriptionArea.pack_start(description);
862        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
863        descriptionArea.show_all();
864    
865      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
866          file_structure_to_be_changed_signal.emit(this->file);          file_structure_to_be_changed_signal.emit(this->file);
# Line 764  bool MainWindow::file_save_as() Line 872  bool MainWindow::file_save_as()
872              printf("filename=%s\n", filename.c_str());              printf("filename=%s\n", filename.c_str());
873              file->Save(filename);              file->Save(filename);
874              this->filename = filename;              this->filename = filename;
875              current_dir = Glib::path_get_dirname(filename);              current_gig_dir = Glib::path_get_dirname(filename);
876              set_title(Glib::filename_display_basename(filename));              set_title(Glib::filename_display_basename(filename));
877              file_has_name = true;              file_has_name = true;
878              file_is_changed = false;              file_is_changed = false;
# Line 793  void MainWindow::__import_queued_samples Line 901  void MainWindow::__import_queued_samples
901          SF_INFO info;          SF_INFO info;
902          info.format = 0;          info.format = 0;
903          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
904            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
905          try {          try {
906              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
907              // determine sample's bit depth              // determine sample's bit depth
908              int bitdepth;              int bitdepth;
909              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 811  void MainWindow::__import_queued_samples Line 920  void MainWindow::__import_queued_samples
920                      break;                      break;
921                  default:                  default:
922                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
923                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
924              }              }
925    
926              const int bufsize = 10000;              const int bufsize = 10000;
# Line 853  void MainWindow::__import_queued_samples Line 962  void MainWindow::__import_queued_samples
962              }              }
963              // cleanup              // cleanup
964              sf_close(hFile);              sf_close(hFile);
965                // let the sampler re-cache the sample if needed
966                sample_changed_signal.emit(iter->gig_sample);
967              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
968              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
969              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 860  void MainWindow::__import_queued_samples Line 971  void MainWindow::__import_queued_samples
971              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
972          } catch (std::string what) {          } catch (std::string what) {
973              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
974              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
975              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
976              ++iter;              ++iter;
977          }          }
978      }      }
979      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
980      if (error_files.size()) {      if (!error_files.empty()) {
981          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;
982          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
983          msg.run();          msg.run();
# Line 879  void MainWindow::on_action_file_properti Line 990  void MainWindow::on_action_file_properti
990      propDialog.deiconify();      propDialog.deiconify();
991  }  }
992    
993    void MainWindow::on_action_warn_user_on_extensions() {
994        Settings::singleton()->warnUserOnExtensions =
995            !Settings::singleton()->warnUserOnExtensions;
996    }
997    
998  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
999  {  {
 #ifdef ABOUT_DIALOG  
1000      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
1001    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
1002        dialog.set_program_name("Gigedit");
1003    #else
1004        dialog.set_name("Gigedit");
1005    #endif
1006      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1007      dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1008      dialog.set_comments(      const std::string sComment =
1009          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1010          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1011          "Please notice that this is still a very young instrument editor. "          _(
1012          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1013          "this application.\n"              "\n"
1014          "\n"              "Please notice that this is still a very young instrument editor. "
1015          "Please report bugs to: http://bugs.linuxsampler.org"              "So better backup your Gigasampler files before editing them with "
1016      );              "this application.\n"
1017                "\n"
1018                "Please report bugs to: http://bugs.linuxsampler.org"
1019            );
1020        dialog.set_comments(sComment.c_str());
1021      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1022      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1023      dialog.run();      dialog.run();
 #endif  
1024  }  }
1025    
1026  PropDialog::PropDialog()  PropDialog::PropDialog()
1027      : table(2,1),      : eName(_("Name")),
1028        eName("Name"),        eCreationDate(_("Creation date")),
1029        eCreationDate("Creation date"),        eComments(_("Comments")),
1030        eComments("Comments"),        eProduct(_("Product")),
1031        eProduct("Product"),        eCopyright(_("Copyright")),
1032        eCopyright("Copyright"),        eArtists(_("Artists")),
1033        eArtists("Artists"),        eGenre(_("Genre")),
1034        eGenre("Genre"),        eKeywords(_("Keywords")),
1035        eKeywords("Keywords"),        eEngineer(_("Engineer")),
1036        eEngineer("Engineer"),        eTechnician(_("Technician")),
1037        eTechnician("Technician"),        eSoftware(_("Software")),
1038        eSoftware("Software"),        eMedium(_("Medium")),
1039        eMedium("Medium"),        eSource(_("Source")),
1040        eSource("Source"),        eSourceForm(_("Source form")),
1041        eSourceForm("Source form"),        eCommissioned(_("Commissioned")),
1042        eCommissioned("Commissioned"),        eSubject(_("Subject")),
       eSubject("Subject"),  
1043        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1044        update_model(0)        table(2, 1)
1045  {  {
1046      set_title("File Properties");      set_title(_("File Properties"));
1047      eName.set_width_chars(50);      eName.set_width_chars(50);
1048    
1049      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
# Line 967  PropDialog::PropDialog() Line 1089  PropDialog::PropDialog()
1089      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1090      buttonBox.show();      buttonBox.show();
1091      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1092      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1093      quitButton.grab_focus();      quitButton.grab_focus();
1094      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1095          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
# Line 979  PropDialog::PropDialog() Line 1101  PropDialog::PropDialog()
1101    
1102  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1103  {  {
1104      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--;  
1105  }  }
1106    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1107    
1108  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_Name(const gig::String& name)
1109  {  {
1110      instrument->IsDrum = value;      m->pInfo->Name = name;
1111  }  }
1112    
1113  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1114  {  {
1115      instrument->MIDIBank = value;      update_model++;
1116        eName.set_value(m->pInfo->Name);
1117        update_model--;
1118  }  }
1119    
1120  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1121  {  {
1122      instrument->MIDIProgram = value;      m->IsDrum = value;
1123  }  }
1124    
1125  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1126  {  {
1127      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1128  }  }
1129    
1130  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1131  {  {
1132      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1133  }  }
1134    
1135  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1136      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1137        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1138        eName("Name"),      eName(_("Name")),
1139        eIsDrum("Is drum"),      eIsDrum(_("Is drum")),
1140        eMIDIBank("MIDI bank", 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1141        eMIDIProgram("MIDI program"),      eMIDIProgram(_("MIDI program")),
1142        eAttenuation("Attenuation", 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1143        eGainPlus6("Gain +6dB", eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1144        eEffectSend("Effect send", 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1145        eFineTune("Fine tune", -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1146        ePitchbendRange("Pitchbend range", 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1147        ePianoReleaseMode("Piano release mode"),      ePianoReleaseMode(_("Piano release mode")),
1148        eDimensionKeyRangeLow("Keyswitching range low"),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1149        eDimensionKeyRangeHigh("Keyswitching range high"),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1150  {  {
1151      set_title("Instrument Properties");      set_title(_("Instrument Properties"));
1152    
1153      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
1154          _("start of the keyboard area which should switch the "          _("start of the keyboard area which should switch the "
# Line 1064  InstrumentProps::InstrumentProps() Line 1159  InstrumentProps::InstrumentProps()
1159            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1160      );      );
1161    
1162        connect(eName, &InstrumentProps::set_Name);
1163      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1164      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1165      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1073  InstrumentProps::InstrumentProps() Line 1169  InstrumentProps::InstrumentProps()
1169      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1170      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1171      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1172      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1173              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1174      connect(eDimensionKeyRangeHigh,  
1175              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1176    
1177      table.set_col_spacings(5);      table.set_col_spacings(5);
1178    
# Line 1102  InstrumentProps::InstrumentProps() Line 1198  InstrumentProps::InstrumentProps()
1198      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1199      buttonBox.show();      buttonBox.show();
1200      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1201      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1202      quitButton.grab_focus();      quitButton.grab_focus();
1203    
1204      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1115  InstrumentProps::InstrumentProps() Line 1211  InstrumentProps::InstrumentProps()
1211    
1212  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1213  {  {
1214      this->instrument = instrument;      update(instrument);
1215    
1216      update_model++;      update_model++;
1217      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1218      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1219      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1220      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);  
1221      update_model--;      update_model--;
1222  }  }
1223    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1224    
1225  void MainWindow::file_changed()  void MainWindow::file_changed()
1226  {  {
# Line 1158  void MainWindow::load_gig(gig::File* gig Line 1242  void MainWindow::load_gig(gig::File* gig
1242    
1243      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1244    
1245      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;  
1246      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1247           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1248            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1249    
1250          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1251          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1252          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1253          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1254          // create a menu item for this instrument  
1255          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++;  
1256      }      }
1257      instrument_menu->show();      instrument_name_connection.unblock();
1258      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1259    
1260      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1261          if (group->Name != "") {          if (group->Name != "") {
1262              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1263              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1264              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1265              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1266              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1267              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1196  void MainWindow::load_gig(gig::File* gig Line 1269  void MainWindow::load_gig(gig::File* gig
1269                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1270                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1271                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1272                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1273                        gig_to_utf8(sample->pInfo->Name);
1274                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1275                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1276              }              }
# Line 1206  void MainWindow::load_gig(gig::File* gig Line 1280  void MainWindow::load_gig(gig::File* gig
1280      file = gig;      file = gig;
1281    
1282      // select the first instrument      // select the first instrument
1283      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1284      tree_sel_ref->select(Gtk::TreePath("0"));  
1285        instr_props_set_instrument();
1286        gig::Instrument* instrument = get_instrument();
1287        if (instrument) {
1288            midiRules.set_instrument(instrument);
1289        }
1290  }  }
1291    
1292  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1293  {  {
1294      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1295      if (instrument)  
1296      {      Gtk::TreeModel::const_iterator it =
1297            m_TreeView.get_selection()->get_selected();
1298        if (it) {
1299            Gtk::TreeModel::Row row = *it;
1300            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1301    
1302          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1303    
1304            // make sure instrument tree is updated when user changes the
1305            // instrument name in instrument properties window
1306            instrumentProps.signal_name_changed().connect(
1307                sigc::bind(
1308                    sigc::mem_fun(*this,
1309                                  &MainWindow::instr_name_changed_by_instr_props),
1310                    it));
1311        } else {
1312            instrumentProps.hide();
1313        }
1314        return it;
1315    }
1316    
1317    void MainWindow::show_instr_props()
1318    {
1319        if (instr_props_set_instrument()) {
1320          instrumentProps.show();          instrumentProps.show();
1321          instrumentProps.deiconify();          instrumentProps.deiconify();
1322      }      }
1323  }  }
1324    
1325    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1326    {
1327        Gtk::TreeModel::Row row = *it;
1328        Glib::ustring name = row[m_Columns.m_col_name];
1329    
1330        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1331        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1332        if (gigname != name) {
1333            row[m_Columns.m_col_name] = gigname;
1334        }
1335    }
1336    
1337    void MainWindow::show_midi_rules()
1338    {
1339        if (gig::Instrument* instrument = get_instrument())
1340        {
1341            midiRules.set_instrument(instrument);
1342            midiRules.show();
1343            midiRules.deiconify();
1344        }
1345    }
1346    
1347  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1348      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1349          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1232  void MainWindow::on_action_view_status_b Line 1355  void MainWindow::on_action_view_status_b
1355      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1356  }  }
1357    
1358    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1359        Gtk::CheckMenuItem* item =
1360            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1361        if (!item) {
1362            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1363            return true;
1364        }
1365        return item->get_active();
1366    }
1367    
1368    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1369        Gtk::CheckMenuItem* item =
1370            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1371        if (!item) {
1372            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1373            return true;
1374        }
1375        return item->get_active();
1376    }
1377    
1378    bool MainWindow::is_copy_samples_loop_enabled() const {
1379        Gtk::CheckMenuItem* item =
1380            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1381        if (!item) {
1382            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1383            return true;
1384        }
1385        return item->get_active();
1386    }
1387    
1388  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1389  {  {
1390      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1391          show_instr_props();          show_instr_props();
1392      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1393            // gig v2 files have no midi rules
1394            static_cast<Gtk::MenuItem*>(
1395                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1396                    !(file->pVersion && file->pVersion->major == 2));
1397          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1398      }      }
1399  }  }
1400    
1401  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1402      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1403            const std::vector<Gtk::Widget*> children =
1404                instrument_menu->get_children();
1405            std::vector<Gtk::Widget*>::const_iterator it =
1406                find(children.begin(), children.end(), item);
1407            if (it != children.end()) {
1408                int index = it - children.begin();
1409                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1410    
1411                m_RegionChooser.set_instrument(file->GetInstrument(index));
1412            }
1413        }
1414  }  }
1415    
1416  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1272  void MainWindow::on_sample_treeview_butt Line 1440  void MainWindow::on_sample_treeview_butt
1440      }      }
1441  }  }
1442    
1443  void MainWindow::on_action_add_instrument() {  
1444      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1445      if (!file) return;      const Glib::ustring& name, int position) {
1446      gig::Instrument* instrument = file->AddInstrument();  
1447      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1448      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1449          "Unnamed Instrument " + ToString(__instrument_indexer);      if (!children.empty()) {
1450            instrument_group =
1451                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1452        }
1453        Gtk::RadioMenuItem* item =
1454            new Gtk::RadioMenuItem(instrument_group, name);
1455        if (position < 0) {
1456            instrument_menu->append(*item);
1457        } else {
1458            instrument_menu->insert(*item, position);
1459        }
1460        item->show();
1461        item->signal_activate().connect(
1462            sigc::bind(
1463                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1464                item));
1465        return item;
1466    }
1467    
1468    void MainWindow::remove_instrument_from_menu(int index) {
1469        const std::vector<Gtk::Widget*> children =
1470            instrument_menu->get_children();
1471        Gtk::Widget* child = children[index];
1472        instrument_menu->remove(*child);
1473        delete child;
1474    }
1475    
1476    void MainWindow::add_instrument(gig::Instrument* instrument) {
1477        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1478    
1479      // update instrument tree view      // update instrument tree view
1480        instrument_name_connection.block();
1481      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1482      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1483      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1484      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1485        instrument_name_connection.unblock();
1486    
1487        add_instrument_to_menu(name);
1488    
1489        m_TreeView.get_selection()->select(iterInstr);
1490    
1491      file_changed();      file_changed();
1492  }  }
1493    
1494    void MainWindow::on_action_add_instrument() {
1495        static int __instrument_indexer = 0;
1496        if (!file) return;
1497        gig::Instrument* instrument = file->AddInstrument();
1498        __instrument_indexer++;
1499        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1500                                                ToString(__instrument_indexer));
1501    
1502        add_instrument(instrument);
1503    }
1504    
1505    void MainWindow::on_action_duplicate_instrument() {
1506        if (!file) return;
1507    
1508        // retrieve the currently selected instrument
1509        // (being the original instrument to be duplicated)
1510        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1511        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1512        if (!itSelection) return;
1513        Gtk::TreeModel::Row row = *itSelection;
1514        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1515        if (!instrOrig) return;
1516    
1517        // duplicate the orginal instrument
1518        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1519        instrNew->pInfo->Name =
1520            instrOrig->pInfo->Name +
1521            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1522    
1523        add_instrument(instrNew);
1524    }
1525    
1526  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1527      if (!file) return;      if (!file) return;
1528      if (file_is_shared) {      if (file_is_shared) {
# Line 1306  void MainWindow::on_action_remove_instru Line 1542  void MainWindow::on_action_remove_instru
1542          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1543          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1544          try {          try {
1545                Gtk::TreePath path(it);
1546                int index = path[0];
1547    
1548              // remove instrument from the gig file              // remove instrument from the gig file
1549              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1550              file_changed();              file_changed();
1551    
1552                remove_instrument_from_menu(index);
1553    
1554                // remove row from instruments tree view
1555                m_refTreeModel->erase(it);
1556    
1557    #if GTKMM_MAJOR_VERSION < 3
1558                // select another instrument (in gtk3 this is done
1559                // automatically)
1560                if (!m_refTreeModel->children().empty()) {
1561                    if (index == m_refTreeModel->children().size()) {
1562                        index--;
1563                    }
1564                    m_TreeView.get_selection()->select(
1565                        Gtk::TreePath(ToString(index)));
1566                }
1567    #endif
1568                instr_props_set_instrument();
1569                instr = get_instrument();
1570                if (instr) {
1571                    midiRules.set_instrument(instr);
1572                } else {
1573                    midiRules.hide();
1574                }
1575          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1576              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1577              msg.run();              msg.run();
# Line 1321  void MainWindow::on_action_remove_instru Line 1582  void MainWindow::on_action_remove_instru
1582  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
1583      //TODO: show a dialog where the selected sample's properties can be edited      //TODO: show a dialog where the selected sample's properties can be edited
1584      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
1585          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
1586      );      );
1587      msg.run();      msg.run();
1588  }  }
# Line 1330  void MainWindow::on_action_add_group() { Line 1591  void MainWindow::on_action_add_group() {
1591      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1592      if (!file) return;      if (!file) return;
1593      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1594      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
1595      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1596      __sample_indexer++;      __sample_indexer++;
1597      // update sample tree view      // update sample tree view
1598      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1599      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1600      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1601      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1602      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1603      file_changed();      file_changed();
# Line 1364  void MainWindow::on_action_add_sample() Line 1625  void MainWindow::on_action_add_sample()
1625      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1626      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1627      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1628      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1629        // matches all file types supported by libsndfile
1630    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1631        Gtk::FileFilter soundfilter;
1632    #else
1633        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1634    #endif
1635      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1636          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1637          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1372  void MainWindow::on_action_add_sample() Line 1639  void MainWindow::on_action_add_sample()
1639          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1640          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1641      };      };
1642        const char* soundfiles = _("Sound Files");
1643        const char* allfiles = _("All Files");
1644    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1645      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1646          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1647      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
1648      Gtk::FileFilter allpassfilter; // matches every file  
1649        // matches every file
1650        Gtk::FileFilter allpassfilter;
1651      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1652      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
1653    #else
1654        for (int i = 0; supportedFileTypes[i]; i++)
1655            soundfilter->add_pattern(supportedFileTypes[i]);
1656        soundfilter->set_name(soundfiles);
1657    
1658        // matches every file
1659        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1660        allpassfilter->add_pattern("*.*");
1661        allpassfilter->set_name(allfiles);
1662    #endif
1663      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1664      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1665        if (current_sample_dir != "") {
1666            dialog.set_current_folder(current_sample_dir);
1667        }
1668      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1669            current_sample_dir = dialog.get_current_folder();
1670          Glib::ustring error_files;          Glib::ustring error_files;
1671          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1672          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1673               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1674              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1675              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1391  void MainWindow::on_action_add_sample() Line 1677  void MainWindow::on_action_add_sample()
1677              info.format = 0;              info.format = 0;
1678              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1679              try {              try {
1680                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
1681                  int bitdepth;                  int bitdepth;
1682                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
1683                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1407  void MainWindow::on_action_add_sample() Line 1693  void MainWindow::on_action_add_sample()
1693                          break;                          break;
1694                      default:                      default:
1695                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
1696                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
1697                  }                  }
1698                  // add a new sample to the .gig file                  // add a new sample to the .gig file
1699                  gig::Sample* sample = file->AddSample();                  gig::Sample* sample = file->AddSample();
# Line 1420  void MainWindow::on_action_add_sample() Line 1706  void MainWindow::on_action_add_sample()
1706                          break;                          break;
1707                      }                      }
1708                  }                  }
1709                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1710                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1711                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1712                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1434  void MainWindow::on_action_add_sample() Line 1720  void MainWindow::on_action_add_sample()
1720                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1721                  {                  {
1722                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1723                        sample->FineTune      = instrument.detune;
1724    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1725                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1726                          sample->Loops = 1;                          sample->Loops = 1;
1727    
# Line 1455  void MainWindow::on_action_add_sample() Line 1741  void MainWindow::on_action_add_sample()
1741                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1742                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1743                      }                      }
 #endif  
1744                  }                  }
1745    
1746                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1473  void MainWindow::on_action_add_sample() Line 1758  void MainWindow::on_action_add_sample()
1758                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1759                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1760                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1761                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1762                        gig_to_utf8(sample->pInfo->Name);
1763                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1764                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1765                  // close sound file                  // close sound file
1766                  sf_close(hFile);                  sf_close(hFile);
1767                  file_changed();                  file_changed();
1768              } 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)
1769                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1770                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1771              }              }
1772          }          }
1773          // 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
1774          if (error_files.size()) {          if (!error_files.empty()) {
1775              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;
1776              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1777              msg.run();              msg.run();
# Line 1493  void MainWindow::on_action_add_sample() Line 1779  void MainWindow::on_action_add_sample()
1779      }      }
1780  }  }
1781    
1782    void MainWindow::on_action_replace_all_samples_in_all_groups()
1783    {
1784        if (!file) return;
1785        Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1786                                      Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1787        const char* str =
1788            _("This is a very specific function. It tries to replace all samples "
1789              "in the current gig file by samples located in the chosen "
1790              "directory.\n\n"
1791              "It works like this: For each sample in the gig file, it tries to "
1792              "find a sample file in the selected directory with the same name as "
1793              "the sample in the gig file. Optionally, you can add a filename "
1794              "extension below, which will be added to the filename expected to be "
1795              "found. That is, assume you have a gig file with a sample called "
1796              "'Snare', if you enter '.wav' below (like it's done by default), it "
1797              "expects to find a sample file called 'Snare.wav' and will replace "
1798              "the sample in the gig file accordingly. If you don't need an "
1799              "extension, blank the field below. Any gig sample where no "
1800              "appropriate sample file could be found will be reported and left "
1801              "untouched.\n");
1802    #if GTKMM_MAJOR_VERSION < 3
1803        view::WrapLabel description(str);
1804    #else
1805        Gtk::Label description(str);
1806        description.set_line_wrap();
1807    #endif
1808        Gtk::HBox entryArea;
1809        Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1810        Gtk::Entry postfixEntryBox;
1811        postfixEntryBox.set_text(".wav");
1812        entryArea.pack_start(entryLabel);
1813        entryArea.pack_start(postfixEntryBox);
1814        dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
1815        dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
1816        description.show();
1817        entryArea.show_all();
1818        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1819        dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
1820        dialog.set_select_multiple(false);
1821        if (current_sample_dir != "") {
1822            dialog.set_current_folder(current_sample_dir);
1823        }
1824        if (dialog.run() == Gtk::RESPONSE_OK)
1825        {
1826            current_sample_dir = dialog.get_current_folder();
1827            Glib::ustring error_files;
1828            std::string folder = dialog.get_filename();
1829            for (gig::Sample* sample = file->GetFirstSample();
1830                 sample; sample = file->GetNextSample())
1831            {
1832                std::string filename =
1833                    folder + G_DIR_SEPARATOR_S +
1834                    Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1835                                             postfixEntryBox.get_text());
1836                SF_INFO info;
1837                info.format = 0;
1838                SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
1839                try
1840                {
1841                    if (!hFile) throw std::string(_("could not open file"));
1842                    int bitdepth;
1843                    switch (info.format & 0xff) {
1844                        case SF_FORMAT_PCM_S8:
1845                        case SF_FORMAT_PCM_16:
1846                        case SF_FORMAT_PCM_U8:
1847                            bitdepth = 16;
1848                            break;
1849                        case SF_FORMAT_PCM_24:
1850                        case SF_FORMAT_PCM_32:
1851                        case SF_FORMAT_FLOAT:
1852                        case SF_FORMAT_DOUBLE:
1853                            bitdepth = 24;
1854                            break;
1855                        default:
1856                            sf_close(hFile);
1857                            throw std::string(_("format not supported"));
1858                    }
1859                    SampleImportItem sched_item;
1860                    sched_item.gig_sample  = sample;
1861                    sched_item.sample_path = filename;
1862                    m_SampleImportQueue.push_back(sched_item);
1863                    sf_close(hFile);
1864                    file_changed();
1865                }
1866                catch (std::string what)
1867                {
1868                    if (!error_files.empty()) error_files += "\n";
1869                    error_files += Glib::filename_to_utf8(filename) +
1870                        " (" + what + ")";
1871                }
1872            }
1873            // show error message box when some file(s) could not be opened / added
1874            if (!error_files.empty()) {
1875                Glib::ustring txt =
1876                    _("Could not replace the following sample(s):\n") + error_files;
1877                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1878                msg.run();
1879            }
1880        }
1881    }
1882    
1883  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
1884      if (!file) return;      if (!file) return;
1885      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
# Line 1505  void MainWindow::on_action_remove_sample Line 1892  void MainWindow::on_action_remove_sample
1892          try {          try {
1893              // remove group or sample from the gig file              // remove group or sample from the gig file
1894              if (group) {              if (group) {
1895                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1896                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1897                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1898                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1627  void MainWindow::on_sample_label_drop_dr Line 2014  void MainWindow::on_sample_label_drop_dr
2014          bool channels_changed = false;          bool channels_changed = false;
2015          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2016              // remove the samplechannel dimension              // remove the samplechannel dimension
2017    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2018              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2019              channels_changed = true;              channels_changed = true;
2020              region_changed();              region_changed();
2021    */
2022          }          }
2023          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2024                sample,
2025                is_copy_samples_unity_note_enabled(),
2026                is_copy_samples_fine_tune_enabled(),
2027                is_copy_samples_loop_enabled()
2028            );
2029    
2030          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2031              // add samplechannel dimension              // add samplechannel dimension
# Line 1674  void MainWindow::sample_name_changed(con Line 2068  void MainWindow::sample_name_changed(con
2068      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2069      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2070      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2071        gig::String gigname(gig_from_utf8(name));
2072      if (group) {      if (group) {
2073          if (group->Name != name) {          if (group->Name != gigname) {
2074              group->Name = name;              group->Name = gigname;
2075              printf("group name changed\n");              printf("group name changed\n");
2076              file_changed();              file_changed();
2077          }          }
2078      } else if (sample) {      } else if (sample) {
2079          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2080              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2081              printf("sample name changed\n");              printf("sample name changed\n");
2082              file_changed();              file_changed();
2083          }          }
# Line 1694  void MainWindow::instrument_name_changed Line 2089  void MainWindow::instrument_name_changed
2089      if (!iter) return;      if (!iter) return;
2090      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2091      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2092    
2093        // change name in instrument menu
2094        int index = path[0];
2095        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2096        if (index < children.size()) {
2097    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2098            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2099    #else
2100            remove_instrument_from_menu(index);
2101            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2102            item->set_active();
2103    #endif
2104        }
2105    
2106        // change name in gig
2107      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2108      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2109          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2110            instrument->pInfo->Name = gigname;
2111    
2112            // change name in the instrument properties window
2113            if (instrumentProps.get_instrument() == instrument) {
2114                instrumentProps.update_name();
2115            }
2116    
2117          file_changed();          file_changed();
2118      }      }
2119  }  }
2120    
2121    void MainWindow::on_action_combine_instruments() {
2122        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2123        d->show_all();
2124        d->resize(500, 400);
2125        d->run();
2126        if (d->fileWasChanged()) {
2127            // update GUI with new instrument just created
2128            add_instrument(d->newCombinedInstrument());
2129        }
2130        delete d;
2131    }
2132    
2133  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2134      this->file_is_shared = b;      this->file_is_shared = b;
2135    
# Line 1741  sigc::signal<void, gig::Region*>& MainWi Line 2170  sigc::signal<void, gig::Region*>& MainWi
2170      return region_changed_signal;      return region_changed_signal;
2171  }  }
2172    
2173    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2174        return sample_changed_signal;
2175    }
2176    
2177  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
2178      return sample_ref_changed_signal;      return sample_ref_changed_signal;
2179  }  }

Legend:
Removed from v.1661  
changed lines
  Added in v.2550

  ViewVC Help
Powered by ViewVC