/[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 1831 by persson, Tue Feb 3 19:38:19 2009 UTC revision 2541 by schoenebeck, Wed Apr 23 16:49:05 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2009 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 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #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 "wrapLabel.hh"  #include "wrapLabel.hh"
   
 #include "global.h"  
   
 #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 "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
47  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
48    
 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++;  
 }  
49    
50  MainWindow::MainWindow() :  MainWindow::MainWindow() :
51      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
# Line 99  MainWindow::MainWindow() : Line 60  MainWindow::MainWindow() :
60      add(m_VBox);      add(m_VBox);
61    
62      // Handle selection      // Handle selection
63      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
64          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
65    
66      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 129  MainWindow::MainWindow() : Line 89  MainWindow::MainWindow() :
89      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
90      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
91    
92        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
93        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."));
94        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."));
95        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)."));
96    
97      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
98      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
# Line 163  MainWindow::MainWindow() : Line 127  MainWindow::MainWindow() :
127                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
128                       sigc::mem_fun(                       sigc::mem_fun(
129                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
130        actionGroup->add(Gtk::Action::create("MidiRules",
131                                             _("_Midi Rules")),
132                         sigc::mem_fun(
133                             *this, &MainWindow::show_midi_rules));
134      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
135                       sigc::mem_fun(                       sigc::mem_fun(
136                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
137      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
138    
139      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
140        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
141    
142      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
143            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
144        toggle_action->set_active(true);
145        actionGroup->add(toggle_action);
146    
147        toggle_action =
148            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
149        toggle_action->set_active(true);
150        actionGroup->add(toggle_action);
151    
152        toggle_action =
153            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
154        toggle_action->set_active(true);
155        actionGroup->add(toggle_action);
156    
157    
158        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
159        toggle_action =
160          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
161      toggle_action->set_active(true);      toggle_action->set_active(true);
162      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 179  MainWindow::MainWindow() : Line 166  MainWindow::MainWindow() :
166      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
167      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
168                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
169      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
170                       sigc::mem_fun(                       sigc::mem_fun(
171                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
172      actionGroup->add(      actionGroup->add(
173          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
174          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
175      );      );
176      actionGroup->add(      actionGroup->add(
177            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
178            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
179        );
180        actionGroup->add(
181          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
182          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
183      );      );
184    
185    
186        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
187        
188        toggle_action =
189            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
190        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
191        actionGroup->add(
192            toggle_action,
193            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
194        );
195    
196    
197      // sample right-click popup actions      // sample right-click popup actions
198      actionGroup->add(      actionGroup->add(
199          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 234  MainWindow::MainWindow() : Line 235  MainWindow::MainWindow() :
235          "      <separator/>"          "      <separator/>"
236          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
237          "    </menu>"          "    </menu>"
238            "    <menu action='MenuEdit'>"
239            "      <menuitem action='CopySampleUnity'/>"
240            "      <menuitem action='CopySampleTune'/>"
241            "      <menuitem action='CopySampleLoop'/>"
242            "    </menu>"
243          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
244          "    </menu>"          "    </menu>"
245          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
246          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
247          "    </menu>"          "    </menu>"
248  #ifdef ABOUT_DIALOG          "    <menu action='MenuSettings'>"
249            "      <menuitem action='WarnUserOnExtensions'/>"
250            "    </menu>"
251          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
252          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
253          "    </menu>"          "    </menu>"
 #endif  
254          "  </menubar>"          "  </menubar>"
255          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
256          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
257            "    <menuitem action='MidiRules'/>"
258          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
259            "    <menuitem action='DupInstrument'/>"
260          "    <separator/>"          "    <separator/>"
261          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
262          "  </popup>"          "  </popup>"
# Line 255  MainWindow::MainWindow() : Line 264  MainWindow::MainWindow() :
264          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
265          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
266          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
267          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
268          "    <separator/>"          "    <separator/>"
269          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
270          "  </popup>"          "  </popup>"
# Line 263  MainWindow::MainWindow() : Line 272  MainWindow::MainWindow() :
272      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
273    
274      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
275        
276        // Set tooltips for menu items (for some reason, setting a tooltip on the
277        // respective Gtk::Action objects above will simply be ignored, no matter
278        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
279        // Gtk::Action::create()).
280        {
281            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
282                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
283            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."));
284        }
285        {
286            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
287                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
288            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."));
289        }
290        {
291            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
292                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
293            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."));
294        }
295        {
296            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
297                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
298            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."));
299        }
300    
301        instrument_menu = static_cast<Gtk::MenuItem*>(
302            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
303    
304      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
305      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 272  MainWindow::MainWindow() : Line 309  MainWindow::MainWindow() :
309      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
310      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
311    
312        set_file_is_shared(false);
313    
314      // Status Bar:      // Status Bar:
315      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
316      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 286  MainWindow::MainWindow() : Line 325  MainWindow::MainWindow() :
325      // Create the Tree model:      // Create the Tree model:
326      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
327      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
328      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
329        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
330          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
331      );      );
332    
# Line 297  MainWindow::MainWindow() : Line 337  MainWindow::MainWindow() :
337      // create samples treeview (including its data model)      // create samples treeview (including its data model)
338      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
339      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
340        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."));
341      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
342      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
343      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 308  MainWindow::MainWindow() : Line 349  MainWindow::MainWindow() :
349      );      );
350    
351      // 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
352      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
353      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
354      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
355      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
356          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 327  MainWindow::MainWindow() : Line 368  MainWindow::MainWindow() :
368          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
369      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
370          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
371      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
372            sigc::mem_fun(*this, &MainWindow::file_changed));
373        propDialog.signal_changed().connect(
374          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
375      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
376          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
377    
378      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 374  MainWindow::MainWindow() : Line 417  MainWindow::MainWindow() :
417    
418      file = 0;      file = 0;
419      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
420    
421      show_all_children();      show_all_children();
422    
# Line 405  void MainWindow::region_changed() Line 447  void MainWindow::region_changed()
447  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
448  {  {
449      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
450      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
451            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
452      if (it) {      if (it) {
453          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
454          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 466  void MainWindow::dimreg_changed() Line 507  void MainWindow::dimreg_changed()
507    
508  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
509  {  {
510        // select item in instrument menu
511        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
512        if (it) {
513            Gtk::TreePath path(it);
514            int index = path[0];
515            const std::vector<Gtk::Widget*> children =
516                instrument_menu->get_children();
517            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
518        }
519    
520      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
521  }  }
522    
# Line 478  void loader_progress_callback(gig::progr Line 529  void loader_progress_callback(gig::progr
529  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
530  {  {
531      {      {
532          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
533          progress = fraction;          progress = fraction;
534      }      }
535      progress_dispatcher();      progress_dispatcher();
# Line 486  void Loader::progress_callback(float fra Line 537  void Loader::progress_callback(float fra
537    
538  void Loader::thread_function()  void Loader::thread_function()
539  {  {
540      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
541      printf("Start %s\n", filename);      printf("Start %s\n", filename);
542      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
543      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 500  void Loader::thread_function() Line 551  void Loader::thread_function()
551  }  }
552    
553  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
554      : thread(0), filename(filename)      : filename(filename), thread(0)
555  {  {
556  }  }
557    
558  void Loader::launch()  void Loader::launch()
559  {  {
560    #ifdef OLD_THREADS
561      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
562    #else
563        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
564    #endif
565      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
566  }  }
567    
# Line 514  float Loader::get_progress() Line 569  float Loader::get_progress()
569  {  {
570      float res;      float res;
571      {      {
572          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
573          res = progress;          res = progress;
574      }      }
575      return res;      return res;
# Line 540  LoadDialog::LoadDialog(const Glib::ustri Line 595  LoadDialog::LoadDialog(const Glib::ustri
595  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
596  // 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.
597  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();  
598      // forget all samples that ought to be imported      // forget all samples that ought to be imported
599      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
600      // clear the samples and instruments tree views      // clear the samples and instruments tree views
601      m_refTreeModel->clear();      m_refTreeModel->clear();
602      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
603        // remove all entries from "Instrument" menu
604        while (!instrument_menu->get_children().empty()) {
605            remove_instrument_from_menu(0);
606        }
607      // free libgig's gig::File instance      // free libgig's gig::File instance
608      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
609      file = NULL;      file = NULL;
# Line 571  void MainWindow::on_action_file_new() Line 622  void MainWindow::on_action_file_new()
622      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
623      // already add one new instrument by default      // already add one new instrument by default
624      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
625      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
626      // update GUI with that new gig::File      // update GUI with that new gig::File
627      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
628  }  }
# Line 582  bool MainWindow::close_confirmation_dial Line 633  bool MainWindow::close_confirmation_dial
633                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
634      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
635      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
636      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  
637      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
638      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
639      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 598  bool MainWindow::close_confirmation_dial Line 647  bool MainWindow::close_confirmation_dial
647  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
648      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
649      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  
650      dialog.set_secondary_text(      dialog.set_secondary_text(
651          _("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 "
652            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
653            "load it.")            "load it."));
    );  
 #endif  
654      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
655      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
656      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 623  void MainWindow::on_action_file_open() Line 669  void MainWindow::on_action_file_open()
669      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
670      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
671      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
672    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
673      Gtk::FileFilter filter;      Gtk::FileFilter filter;
674      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
675    #else
676        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
677        filter->add_pattern("*.gig");
678    #endif
679      dialog.set_filter(filter);      dialog.set_filter(filter);
680      if (current_gig_dir != "") {      if (current_gig_dir != "") {
681          dialog.set_current_folder(current_gig_dir);          dialog.set_current_folder(current_gig_dir);
# Line 632  void MainWindow::on_action_file_open() Line 683  void MainWindow::on_action_file_open()
683      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
684          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
685          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
686          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
687          load_file(filename.c_str());          load_file(filename.c_str());
688          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
689      }      }
# Line 674  void MainWindow::on_loader_progress() Line 725  void MainWindow::on_loader_progress()
725  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
726  {  {
727      printf("Loader finished!\n");      printf("Loader finished!\n");
728      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
729      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
730      load_dialog->hide();      load_dialog->hide();
731  }  }
# Line 746  bool MainWindow::file_save_as() Line 797  bool MainWindow::file_save_as()
797      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
798      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
799      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  
800      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
801      // TODO: an overwrite dialog for gtkmm < 2.8  
802  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
803      Gtk::FileFilter filter;      Gtk::FileFilter filter;
804      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
805    #else
806        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
807        filter->add_pattern("*.gig");
808    #endif
809      dialog.set_filter(filter);      dialog.set_filter(filter);
810    
811      // set initial dir and filename of the Save As dialog      // set initial dir and filename of the Save As dialog
# Line 775  bool MainWindow::file_save_as() Line 828  bool MainWindow::file_save_as()
828      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
829      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
830      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
831    #if GTKMM_MAJOR_VERSION < 3
832      view::WrapLabel description;      view::WrapLabel description;
833    #else
834        Gtk::Label description;
835        description.set_line_wrap();
836    #endif
837      description.set_markup(      description.set_markup(
838          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
839            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 827  void MainWindow::__import_queued_samples Line 885  void MainWindow::__import_queued_samples
885          SF_INFO info;          SF_INFO info;
886          info.format = 0;          info.format = 0;
887          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
888            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
889          try {          try {
890              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
891              // determine sample's bit depth              // determine sample's bit depth
# Line 887  void MainWindow::__import_queued_samples Line 946  void MainWindow::__import_queued_samples
946              }              }
947              // cleanup              // cleanup
948              sf_close(hFile);              sf_close(hFile);
949                // let the sampler re-cache the sample if needed
950                sample_changed_signal.emit(iter->gig_sample);
951              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
952              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
953              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 894  void MainWindow::__import_queued_samples Line 955  void MainWindow::__import_queued_samples
955              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
956          } catch (std::string what) {          } catch (std::string what) {
957              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
958              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
959              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
960              ++iter;              ++iter;
961          }          }
962      }      }
963      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
964      if (error_files.size()) {      if (!error_files.empty()) {
965          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;
966          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
967          msg.run();          msg.run();
# Line 913  void MainWindow::on_action_file_properti Line 974  void MainWindow::on_action_file_properti
974      propDialog.deiconify();      propDialog.deiconify();
975  }  }
976    
977    void MainWindow::on_action_warn_user_on_extensions() {
978        Settings::singleton()->warnUserOnExtensions =
979            !Settings::singleton()->warnUserOnExtensions;
980    }
981    
982  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
983  {  {
 #ifdef ABOUT_DIALOG  
984      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
985    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
986        dialog.set_program_name("Gigedit");
987    #else
988        dialog.set_name("Gigedit");
989    #endif
990      dialog.set_version(VERSION);      dialog.set_version(VERSION);
991      dialog.set_copyright("Copyright (C) 2006-2009 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
992      dialog.set_comments(_(      const std::string sComment =
993          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
994          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
995          "Please notice that this is still a very young instrument editor. "          _(
996          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
997          "this application.\n"              "\n"
998          "\n"              "Please notice that this is still a very young instrument editor. "
999          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
1000      );              "this application.\n"
1001                "\n"
1002                "Please report bugs to: http://bugs.linuxsampler.org"
1003            );
1004        dialog.set_comments(sComment.c_str());
1005      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1006      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1007      dialog.run();      dialog.run();
 #endif  
1008  }  }
1009    
1010  PropDialog::PropDialog()  PropDialog::PropDialog()
1011      : table(2,1),      : eName(_("Name")),
       eName(_("Name")),  
1012        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1013        eComments(_("Comments")),        eComments(_("Comments")),
1014        eProduct(_("Product")),        eProduct(_("Product")),
# Line 953  PropDialog::PropDialog() Line 1025  PropDialog::PropDialog()
1025        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1026        eSubject(_("Subject")),        eSubject(_("Subject")),
1027        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1028        update_model(0)        table(2, 1)
1029  {  {
1030      set_title(_("File Properties"));      set_title(_("File Properties"));
1031      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1001  PropDialog::PropDialog() Line 1073  PropDialog::PropDialog()
1073      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1074      buttonBox.show();      buttonBox.show();
1075      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1076      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1077      quitButton.grab_focus();      quitButton.grab_focus();
1078      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1079          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
# Line 1013  PropDialog::PropDialog() Line 1085  PropDialog::PropDialog()
1085    
1086  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1087  {  {
1088      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--;  
1089  }  }
1090    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1091    
1092  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_Name(const gig::String& name)
1093  {  {
1094      instrument->IsDrum = value;      m->pInfo->Name = name;
1095  }  }
1096    
1097  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1098  {  {
1099      instrument->MIDIBank = value;      update_model++;
1100        eName.set_value(m->pInfo->Name);
1101        update_model--;
1102  }  }
1103    
1104  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1105  {  {
1106      instrument->MIDIProgram = value;      m->IsDrum = value;
1107  }  }
1108    
1109  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1110  {  {
1111      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1112  }  }
1113    
1114  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1115  {  {
1116      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1117  }  }
1118    
1119  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1120      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1121        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1122        eName(_("Name")),      eName(_("Name")),
1123        eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
1124        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1125        eMIDIProgram(_("MIDI program")),      eMIDIProgram(_("MIDI program")),
1126        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1127        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1128        eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1129        eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1130        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1131        ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
1132        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1133        eDimensionKeyRangeHigh(_("Keyswitching range high")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1134  {  {
1135      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1136    
# Line 1098  InstrumentProps::InstrumentProps() Line 1143  InstrumentProps::InstrumentProps()
1143            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1144      );      );
1145    
1146        connect(eName, &InstrumentProps::set_Name);
1147      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1148      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1149      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1107  InstrumentProps::InstrumentProps() Line 1153  InstrumentProps::InstrumentProps()
1153      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1154      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1155      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1156      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1157              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1158      connect(eDimensionKeyRangeHigh,  
1159              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1160    
1161      table.set_col_spacings(5);      table.set_col_spacings(5);
1162    
# Line 1136  InstrumentProps::InstrumentProps() Line 1182  InstrumentProps::InstrumentProps()
1182      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1183      buttonBox.show();      buttonBox.show();
1184      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1185      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1186      quitButton.grab_focus();      quitButton.grab_focus();
1187    
1188      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1149  InstrumentProps::InstrumentProps() Line 1195  InstrumentProps::InstrumentProps()
1195    
1196  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1197  {  {
1198      this->instrument = instrument;      update(instrument);
1199    
1200      update_model++;      update_model++;
1201      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1202      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1203      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1204      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);  
1205      update_model--;      update_model--;
1206  }  }
1207    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1208    
1209  void MainWindow::file_changed()  void MainWindow::file_changed()
1210  {  {
# Line 1192  void MainWindow::load_gig(gig::File* gig Line 1226  void MainWindow::load_gig(gig::File* gig
1226    
1227      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1228    
1229      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;  
1230      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1231           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1232            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1233    
1234          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1235          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1236          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1237          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1238          // create a menu item for this instrument  
1239          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++;  
1240      }      }
1241      instrument_menu->show();      instrument_name_connection.unblock();
1242      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1243    
1244      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1245          if (group->Name != "") {          if (group->Name != "") {
1246              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1247              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1248              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1249              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1250              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1251              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1230  void MainWindow::load_gig(gig::File* gig Line 1253  void MainWindow::load_gig(gig::File* gig
1253                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1254                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1255                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1256                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1257                        gig_to_utf8(sample->pInfo->Name);
1258                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1259                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1260              }              }
# Line 1240  void MainWindow::load_gig(gig::File* gig Line 1264  void MainWindow::load_gig(gig::File* gig
1264      file = gig;      file = gig;
1265    
1266      // select the first instrument      // select the first instrument
1267      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1268      tree_sel_ref->select(Gtk::TreePath("0"));  
1269        instr_props_set_instrument();
1270        gig::Instrument* instrument = get_instrument();
1271        if (instrument) {
1272            midiRules.set_instrument(instrument);
1273        }
1274  }  }
1275    
1276  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1277  {  {
1278      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1279      if (instrument)  
1280      {      Gtk::TreeModel::const_iterator it =
1281            m_TreeView.get_selection()->get_selected();
1282        if (it) {
1283            Gtk::TreeModel::Row row = *it;
1284            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1285    
1286          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1287    
1288            // make sure instrument tree is updated when user changes the
1289            // instrument name in instrument properties window
1290            instrumentProps.signal_name_changed().connect(
1291                sigc::bind(
1292                    sigc::mem_fun(*this,
1293                                  &MainWindow::instr_name_changed_by_instr_props),
1294                    it));
1295        } else {
1296            instrumentProps.hide();
1297        }
1298        return it;
1299    }
1300    
1301    void MainWindow::show_instr_props()
1302    {
1303        if (instr_props_set_instrument()) {
1304          instrumentProps.show();          instrumentProps.show();
1305          instrumentProps.deiconify();          instrumentProps.deiconify();
1306      }      }
1307  }  }
1308    
1309    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1310    {
1311        Gtk::TreeModel::Row row = *it;
1312        Glib::ustring name = row[m_Columns.m_col_name];
1313    
1314        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1315        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1316        if (gigname != name) {
1317            row[m_Columns.m_col_name] = gigname;
1318        }
1319    }
1320    
1321    void MainWindow::show_midi_rules()
1322    {
1323        if (gig::Instrument* instrument = get_instrument())
1324        {
1325            midiRules.set_instrument(instrument);
1326            midiRules.show();
1327            midiRules.deiconify();
1328        }
1329    }
1330    
1331  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1332      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1333          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1266  void MainWindow::on_action_view_status_b Line 1339  void MainWindow::on_action_view_status_b
1339      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1340  }  }
1341    
1342    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1343        Gtk::CheckMenuItem* item =
1344            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1345        if (!item) {
1346            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1347            return true;
1348        }
1349        return item->get_active();
1350    }
1351    
1352    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1353        Gtk::CheckMenuItem* item =
1354            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1355        if (!item) {
1356            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1357            return true;
1358        }
1359        return item->get_active();
1360    }
1361    
1362    bool MainWindow::is_copy_samples_loop_enabled() const {
1363        Gtk::CheckMenuItem* item =
1364            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1365        if (!item) {
1366            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1367            return true;
1368        }
1369        return item->get_active();
1370    }
1371    
1372  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1373  {  {
1374      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1375          show_instr_props();          show_instr_props();
1376      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1377            // gig v2 files have no midi rules
1378            static_cast<Gtk::MenuItem*>(
1379                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1380                    !(file->pVersion && file->pVersion->major == 2));
1381          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1382      }      }
1383  }  }
1384    
1385  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1386      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1387            const std::vector<Gtk::Widget*> children =
1388                instrument_menu->get_children();
1389            std::vector<Gtk::Widget*>::const_iterator it =
1390                find(children.begin(), children.end(), item);
1391            if (it != children.end()) {
1392                int index = it - children.begin();
1393                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1394    
1395                m_RegionChooser.set_instrument(file->GetInstrument(index));
1396            }
1397        }
1398  }  }
1399    
1400  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1306  void MainWindow::on_sample_treeview_butt Line 1424  void MainWindow::on_sample_treeview_butt
1424      }      }
1425  }  }
1426    
1427  void MainWindow::on_action_add_instrument() {  
1428      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1429      if (!file) return;      const Glib::ustring& name, int position) {
1430      gig::Instrument* instrument = file->AddInstrument();  
1431      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1432      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1433          _("Unnamed Instrument ") + ToString(__instrument_indexer);      if (!children.empty()) {
1434            instrument_group =
1435                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1436        }
1437        Gtk::RadioMenuItem* item =
1438            new Gtk::RadioMenuItem(instrument_group, name);
1439        if (position < 0) {
1440            instrument_menu->append(*item);
1441        } else {
1442            instrument_menu->insert(*item, position);
1443        }
1444        item->show();
1445        item->signal_activate().connect(
1446            sigc::bind(
1447                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1448                item));
1449        return item;
1450    }
1451    
1452    void MainWindow::remove_instrument_from_menu(int index) {
1453        const std::vector<Gtk::Widget*> children =
1454            instrument_menu->get_children();
1455        Gtk::Widget* child = children[index];
1456        instrument_menu->remove(*child);
1457        delete child;
1458    }
1459    
1460    void MainWindow::add_instrument(gig::Instrument* instrument) {
1461        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1462    
1463      // update instrument tree view      // update instrument tree view
1464        instrument_name_connection.block();
1465      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1466      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1467      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1468      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1469        instrument_name_connection.unblock();
1470    
1471        add_instrument_to_menu(name);
1472    
1473        m_TreeView.get_selection()->select(iterInstr);
1474    
1475      file_changed();      file_changed();
1476  }  }
1477    
1478    void MainWindow::on_action_add_instrument() {
1479        static int __instrument_indexer = 0;
1480        if (!file) return;
1481        gig::Instrument* instrument = file->AddInstrument();
1482        __instrument_indexer++;
1483        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1484                                                ToString(__instrument_indexer));
1485    
1486        add_instrument(instrument);
1487    }
1488    
1489    void MainWindow::on_action_duplicate_instrument() {
1490        if (!file) return;
1491    
1492        // retrieve the currently selected instrument
1493        // (being the original instrument to be duplicated)
1494        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1495        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1496        if (!itSelection) return;
1497        Gtk::TreeModel::Row row = *itSelection;
1498        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1499        if (!instrOrig) return;
1500    
1501        // duplicate the orginal instrument
1502        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1503        instrNew->pInfo->Name =
1504            instrOrig->pInfo->Name +
1505            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1506    
1507        add_instrument(instrNew);
1508    }
1509    
1510  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1511      if (!file) return;      if (!file) return;
1512      if (file_is_shared) {      if (file_is_shared) {
# Line 1340  void MainWindow::on_action_remove_instru Line 1526  void MainWindow::on_action_remove_instru
1526          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1527          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1528          try {          try {
1529                Gtk::TreePath path(it);
1530                int index = path[0];
1531    
1532              // remove instrument from the gig file              // remove instrument from the gig file
1533              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1534              file_changed();              file_changed();
1535    
1536                remove_instrument_from_menu(index);
1537    
1538                // remove row from instruments tree view
1539                m_refTreeModel->erase(it);
1540    
1541    #if GTKMM_MAJOR_VERSION < 3
1542                // select another instrument (in gtk3 this is done
1543                // automatically)
1544                if (!m_refTreeModel->children().empty()) {
1545                    if (index == m_refTreeModel->children().size()) {
1546                        index--;
1547                    }
1548                    m_TreeView.get_selection()->select(
1549                        Gtk::TreePath(ToString(index)));
1550                }
1551    #endif
1552                instr_props_set_instrument();
1553                instr = get_instrument();
1554                if (instr) {
1555                    midiRules.set_instrument(instr);
1556                } else {
1557                    midiRules.hide();
1558                }
1559          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1560              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1561              msg.run();              msg.run();
# Line 1364  void MainWindow::on_action_add_group() { Line 1575  void MainWindow::on_action_add_group() {
1575      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1576      if (!file) return;      if (!file) return;
1577      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1578      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1579      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1580      __sample_indexer++;      __sample_indexer++;
1581      // update sample tree view      // update sample tree view
1582      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1583      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1584      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1585      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1586      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1587      file_changed();      file_changed();
# Line 1398  void MainWindow::on_action_add_sample() Line 1609  void MainWindow::on_action_add_sample()
1609      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1610      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1611      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1612      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1613        // matches all file types supported by libsndfile
1614    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1615        Gtk::FileFilter soundfilter;
1616    #else
1617        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1618    #endif
1619      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1620          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1621          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1406  void MainWindow::on_action_add_sample() Line 1623  void MainWindow::on_action_add_sample()
1623          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1624          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1625      };      };
1626        const char* soundfiles = _("Sound Files");
1627        const char* allfiles = _("All Files");
1628    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1629      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1630          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1631      soundfilter.set_name(_("Sound Files"));      soundfilter.set_name(soundfiles);
1632      Gtk::FileFilter allpassfilter; // matches every file  
1633        // matches every file
1634        Gtk::FileFilter allpassfilter;
1635      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1636      allpassfilter.set_name(_("All Files"));      allpassfilter.set_name(allfiles);
1637    #else
1638        for (int i = 0; supportedFileTypes[i]; i++)
1639            soundfilter->add_pattern(supportedFileTypes[i]);
1640        soundfilter->set_name(soundfiles);
1641    
1642        // matches every file
1643        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1644        allpassfilter->add_pattern("*.*");
1645        allpassfilter->set_name(allfiles);
1646    #endif
1647      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1648      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1649      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 1420  void MainWindow::on_action_add_sample() Line 1652  void MainWindow::on_action_add_sample()
1652      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1653          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1654          Glib::ustring error_files;          Glib::ustring error_files;
1655          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1656          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1657               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1658              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1659              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1458  void MainWindow::on_action_add_sample() Line 1690  void MainWindow::on_action_add_sample()
1690                          break;                          break;
1691                      }                      }
1692                  }                  }
1693                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1694                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1695                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1696                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1472  void MainWindow::on_action_add_sample() Line 1704  void MainWindow::on_action_add_sample()
1704                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1705                  {                  {
1706                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1707                        sample->FineTune      = instrument.detune;
1708    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1709                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1710                          sample->Loops = 1;                          sample->Loops = 1;
1711    
# Line 1493  void MainWindow::on_action_add_sample() Line 1725  void MainWindow::on_action_add_sample()
1725                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1726                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1727                      }                      }
 #endif  
1728                  }                  }
1729    
1730                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1511  void MainWindow::on_action_add_sample() Line 1742  void MainWindow::on_action_add_sample()
1742                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1743                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1744                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1745                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1746                        gig_to_utf8(sample->pInfo->Name);
1747                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1748                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1749                  // close sound file                  // close sound file
1750                  sf_close(hFile);                  sf_close(hFile);
1751                  file_changed();                  file_changed();
1752              } 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)
1753                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1754                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1755              }              }
1756          }          }
1757          // 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
1758          if (error_files.size()) {          if (!error_files.empty()) {
1759              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;
1760              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1761              msg.run();              msg.run();
# Line 1536  void MainWindow::on_action_replace_all_s Line 1768  void MainWindow::on_action_replace_all_s
1768      if (!file) return;      if (!file) return;
1769      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1770                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1771      view::WrapLabel description(      const char* str =
1772          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1773            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
1774            "directory.\n\n"            "directory.\n\n"
# Line 1550  void MainWindow::on_action_replace_all_s Line 1782  void MainWindow::on_action_replace_all_s
1782            "the sample in the gig file accordingly. If you don't need an "            "the sample in the gig file accordingly. If you don't need an "
1783            "extension, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
1784            "appropriate sample file could be found will be reported and left "            "appropriate sample file could be found will be reported and left "
1785            "untouched.\n")            "untouched.\n");
1786      );  #if GTKMM_MAJOR_VERSION < 3
1787        view::WrapLabel description(str);
1788    #else
1789        Gtk::Label description(str);
1790        description.set_line_wrap();
1791    #endif
1792      Gtk::HBox entryArea;      Gtk::HBox entryArea;
1793      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1794      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
1795      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
1796      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1572  void MainWindow::on_action_replace_all_s Line 1809  void MainWindow::on_action_replace_all_s
1809      {      {
1810          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1811          Glib::ustring error_files;          Glib::ustring error_files;
1812          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
1813          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
1814               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1815          {          {
1816              std::string filename =              std::string filename =
1817                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1818                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1819                                             postfixEntryBox.get_text());
1820              SF_INFO info;              SF_INFO info;
1821              info.format = 0;              info.format = 0;
1822              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1611  void MainWindow::on_action_replace_all_s Line 1849  void MainWindow::on_action_replace_all_s
1849              }              }
1850              catch (std::string what)              catch (std::string what)
1851              {              {
1852                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1853                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1854                        " (" + what + ")";
1855              }              }
1856          }          }
1857          // 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
1858          if (error_files.size()) {          if (!error_files.empty()) {
1859              Glib::ustring txt =              Glib::ustring txt =
1860                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1861              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1637  void MainWindow::on_action_remove_sample Line 1876  void MainWindow::on_action_remove_sample
1876          try {          try {
1877              // remove group or sample from the gig file              // remove group or sample from the gig file
1878              if (group) {              if (group) {
1879                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1880                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1881                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1882                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1763  void MainWindow::on_sample_label_drop_dr Line 2002  void MainWindow::on_sample_label_drop_dr
2002              channels_changed = true;              channels_changed = true;
2003              region_changed();              region_changed();
2004          }          }
2005          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2006                sample,
2007                is_copy_samples_unity_note_enabled(),
2008                is_copy_samples_fine_tune_enabled(),
2009                is_copy_samples_loop_enabled()
2010            );
2011    
2012          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2013              // add samplechannel dimension              // add samplechannel dimension
# Line 1806  void MainWindow::sample_name_changed(con Line 2050  void MainWindow::sample_name_changed(con
2050      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2051      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2052      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2053        gig::String gigname(gig_from_utf8(name));
2054      if (group) {      if (group) {
2055          if (group->Name != name) {          if (group->Name != gigname) {
2056              group->Name = name;              group->Name = gigname;
2057              printf("group name changed\n");              printf("group name changed\n");
2058              file_changed();              file_changed();
2059          }          }
2060      } else if (sample) {      } else if (sample) {
2061          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2062              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2063              printf("sample name changed\n");              printf("sample name changed\n");
2064              file_changed();              file_changed();
2065          }          }
# Line 1826  void MainWindow::instrument_name_changed Line 2071  void MainWindow::instrument_name_changed
2071      if (!iter) return;      if (!iter) return;
2072      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2073      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2074    
2075        // change name in instrument menu
2076        int index = path[0];
2077        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2078        if (index < children.size()) {
2079    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2080            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2081    #else
2082            remove_instrument_from_menu(index);
2083            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2084            item->set_active();
2085    #endif
2086        }
2087    
2088        // change name in gig
2089      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2090      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2091          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2092            instrument->pInfo->Name = gigname;
2093    
2094            // change name in the instrument properties window
2095            if (instrumentProps.get_instrument() == instrument) {
2096                instrumentProps.update_name();
2097            }
2098    
2099          file_changed();          file_changed();
2100      }      }
2101  }  }
# Line 1873  sigc::signal<void, gig::Region*>& MainWi Line 2140  sigc::signal<void, gig::Region*>& MainWi
2140      return region_changed_signal;      return region_changed_signal;
2141  }  }
2142    
2143    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2144        return sample_changed_signal;
2145    }
2146    
2147  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() {
2148      return sample_ref_changed_signal;      return sample_ref_changed_signal;
2149  }  }

Legend:
Removed from v.1831  
changed lines
  Added in v.2541

  ViewVC Help
Powered by ViewVC