/[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 1959 by persson, Fri Jul 31 10:15:27 2009 UTC revision 2536 by schoenebeck, Mon Apr 21 17:49:17 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>
# Line 55  Glib::ustring filename_display_basename( Line 46  Glib::ustring filename_display_basename(
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      );      );
# Line 234  MainWindow::MainWindow() : Line 223  MainWindow::MainWindow() :
223          "      <separator/>"          "      <separator/>"
224          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
225          "    </menu>"          "    </menu>"
226            "    <menu action='MenuEdit'>"
227            "      <menuitem action='CopySampleUnity'/>"
228            "      <menuitem action='CopySampleTune'/>"
229            "      <menuitem action='CopySampleLoop'/>"
230            "    </menu>"
231          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
232          "    </menu>"          "    </menu>"
233          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
234          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
235          "    </menu>"          "    </menu>"
 #ifdef ABOUT_DIALOG  
236          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
237          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
238          "    </menu>"          "    </menu>"
 #endif  
239          "  </menubar>"          "  </menubar>"
240          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
241          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
242            "    <menuitem action='MidiRules'/>"
243          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
244            "    <menuitem action='DupInstrument'/>"
245          "    <separator/>"          "    <separator/>"
246          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
247          "  </popup>"          "  </popup>"
# Line 255  MainWindow::MainWindow() : Line 249  MainWindow::MainWindow() :
249          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
250          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
251          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
252          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
253          "    <separator/>"          "    <separator/>"
254          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
255          "  </popup>"          "  </popup>"
# Line 263  MainWindow::MainWindow() : Line 257  MainWindow::MainWindow() :
257      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
258    
259      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
260        
261        // Set tooltips for menu items (for some reason, setting a tooltip on the
262        // respective Gtk::Action objects above will simply be ignored, no matter
263        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
264        // Gtk::Action::create()).
265        {
266            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
267                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
268            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."));
269        }
270        {
271            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
272                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
273            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."));
274        }
275        {
276            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
277                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
278            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."));
279        }
280    
281        instrument_menu = static_cast<Gtk::MenuItem*>(
282            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
283    
284      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
285      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 272  MainWindow::MainWindow() : Line 289  MainWindow::MainWindow() :
289      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
290      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
291    
292        set_file_is_shared(false);
293    
294      // Status Bar:      // Status Bar:
295      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
296      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 286  MainWindow::MainWindow() : Line 305  MainWindow::MainWindow() :
305      // Create the Tree model:      // Create the Tree model:
306      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
307      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
308      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
309        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
310          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
311      );      );
312    
# Line 297  MainWindow::MainWindow() : Line 317  MainWindow::MainWindow() :
317      // create samples treeview (including its data model)      // create samples treeview (including its data model)
318      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
319      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
320        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."));
321      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
322      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
323      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 308  MainWindow::MainWindow() : Line 329  MainWindow::MainWindow() :
329      );      );
330    
331      // 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
332      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
333      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
334      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
335      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
336          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 348  MainWindow::MainWindow() :
348          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
349      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
350          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
351      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
352            sigc::mem_fun(*this, &MainWindow::file_changed));
353        propDialog.signal_changed().connect(
354          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
355      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
356          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
357    
358      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 374  MainWindow::MainWindow() : Line 397  MainWindow::MainWindow() :
397    
398      file = 0;      file = 0;
399      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
400    
401      show_all_children();      show_all_children();
402    
# Line 405  void MainWindow::region_changed() Line 427  void MainWindow::region_changed()
427  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
428  {  {
429      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
430      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
431            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
432      if (it) {      if (it) {
433          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
434          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 466  void MainWindow::dimreg_changed() Line 487  void MainWindow::dimreg_changed()
487    
488  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
489  {  {
490        // select item in instrument menu
491        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
492        if (it) {
493            Gtk::TreePath path(it);
494            int index = path[0];
495            const std::vector<Gtk::Widget*> children =
496                instrument_menu->get_children();
497            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
498        }
499    
500      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
501  }  }
502    
# Line 478  void loader_progress_callback(gig::progr Line 509  void loader_progress_callback(gig::progr
509  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
510  {  {
511      {      {
512          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
513          progress = fraction;          progress = fraction;
514      }      }
515      progress_dispatcher();      progress_dispatcher();
# Line 486  void Loader::progress_callback(float fra Line 517  void Loader::progress_callback(float fra
517    
518  void Loader::thread_function()  void Loader::thread_function()
519  {  {
520      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
521      printf("Start %s\n", filename);      printf("Start %s\n", filename);
522      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
523      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 500  void Loader::thread_function() Line 531  void Loader::thread_function()
531  }  }
532    
533  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
534      : thread(0), filename(filename)      : filename(filename), thread(0)
535  {  {
536  }  }
537    
538  void Loader::launch()  void Loader::launch()
539  {  {
540    #ifdef OLD_THREADS
541      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
542    #else
543        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
544    #endif
545      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
546  }  }
547    
# Line 514  float Loader::get_progress() Line 549  float Loader::get_progress()
549  {  {
550      float res;      float res;
551      {      {
552          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
553          res = progress;          res = progress;
554      }      }
555      return res;      return res;
# Line 540  LoadDialog::LoadDialog(const Glib::ustri Line 575  LoadDialog::LoadDialog(const Glib::ustri
575  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
576  // 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.
577  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();  
578      // forget all samples that ought to be imported      // forget all samples that ought to be imported
579      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
580      // clear the samples and instruments tree views      // clear the samples and instruments tree views
581      m_refTreeModel->clear();      m_refTreeModel->clear();
582      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
583        // remove all entries from "Instrument" menu
584        while (!instrument_menu->get_children().empty()) {
585            remove_instrument_from_menu(0);
586        }
587      // free libgig's gig::File instance      // free libgig's gig::File instance
588      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
589      file = NULL;      file = NULL;
# Line 571  void MainWindow::on_action_file_new() Line 602  void MainWindow::on_action_file_new()
602      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
603      // already add one new instrument by default      // already add one new instrument by default
604      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
605      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
606      // update GUI with that new gig::File      // update GUI with that new gig::File
607      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
608  }  }
# Line 582  bool MainWindow::close_confirmation_dial Line 613  bool MainWindow::close_confirmation_dial
613                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
614      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
615      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
616      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  
617      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
618      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
619      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 627  bool MainWindow::close_confirmation_dial
627  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
628      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
629      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  
630      dialog.set_secondary_text(      dialog.set_secondary_text(
631          _("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 "
632            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
633            "load it.")            "load it."));
    );  
 #endif  
634      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
635      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
636      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 623  void MainWindow::on_action_file_open() Line 649  void MainWindow::on_action_file_open()
649      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
650      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
651      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
652    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
653      Gtk::FileFilter filter;      Gtk::FileFilter filter;
654      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
655    #else
656        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
657        filter->add_pattern("*.gig");
658    #endif
659      dialog.set_filter(filter);      dialog.set_filter(filter);
660      if (current_gig_dir != "") {      if (current_gig_dir != "") {
661          dialog.set_current_folder(current_gig_dir);          dialog.set_current_folder(current_gig_dir);
# Line 632  void MainWindow::on_action_file_open() Line 663  void MainWindow::on_action_file_open()
663      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
664          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
665          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
666          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
667          load_file(filename.c_str());          load_file(filename.c_str());
668          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
669      }      }
# Line 674  void MainWindow::on_loader_progress() Line 705  void MainWindow::on_loader_progress()
705  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
706  {  {
707      printf("Loader finished!\n");      printf("Loader finished!\n");
708      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
709      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
710      load_dialog->hide();      load_dialog->hide();
711  }  }
# Line 746  bool MainWindow::file_save_as() Line 777  bool MainWindow::file_save_as()
777      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
778      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
779      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  
780      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
781      // TODO: an overwrite dialog for gtkmm < 2.8  
782  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
783      Gtk::FileFilter filter;      Gtk::FileFilter filter;
784      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
785    #else
786        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
787        filter->add_pattern("*.gig");
788    #endif
789      dialog.set_filter(filter);      dialog.set_filter(filter);
790    
791      // 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 808  bool MainWindow::file_save_as()
808      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
809      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));
810      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
811    #if GTKMM_MAJOR_VERSION < 3
812      view::WrapLabel description;      view::WrapLabel description;
813    #else
814        Gtk::Label description;
815        description.set_line_wrap();
816    #endif
817      description.set_markup(      description.set_markup(
818          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
819            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 827  void MainWindow::__import_queued_samples Line 865  void MainWindow::__import_queued_samples
865          SF_INFO info;          SF_INFO info;
866          info.format = 0;          info.format = 0;
867          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
868            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
869          try {          try {
870              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
871              // determine sample's bit depth              // determine sample's bit depth
# Line 896  void MainWindow::__import_queued_samples Line 935  void MainWindow::__import_queued_samples
935              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
936          } catch (std::string what) {          } catch (std::string what) {
937              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
938              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
939              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
940              ++iter;              ++iter;
941          }          }
942      }      }
943      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
944      if (error_files.size()) {      if (!error_files.empty()) {
945          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;
946          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
947          msg.run();          msg.run();
# Line 917  void MainWindow::on_action_file_properti Line 956  void MainWindow::on_action_file_properti
956    
957  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
958  {  {
 #ifdef ABOUT_DIALOG  
959      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
960  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
961      dialog.set_program_name("Gigedit");      dialog.set_program_name("Gigedit");
# Line 925  void MainWindow::on_action_help_about() Line 963  void MainWindow::on_action_help_about()
963      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
964  #endif  #endif
965      dialog.set_version(VERSION);      dialog.set_version(VERSION);
966      dialog.set_copyright("Copyright (C) 2006-2009 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
967      dialog.set_comments(_(      const std::string sComment =
968          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
969          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
970          "Please notice that this is still a very young instrument editor. "          _(
971          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
972          "this application.\n"              "\n"
973          "\n"              "Please notice that this is still a very young instrument editor. "
974          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
975      );              "this application.\n"
976                "\n"
977                "Please report bugs to: http://bugs.linuxsampler.org"
978            );
979        dialog.set_comments(sComment.c_str());
980      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
981      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
982      dialog.run();      dialog.run();
 #endif  
983  }  }
984    
985  PropDialog::PropDialog()  PropDialog::PropDialog()
986      : table(2,1),      : eName(_("Name")),
       eName(_("Name")),  
987        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
988        eComments(_("Comments")),        eComments(_("Comments")),
989        eProduct(_("Product")),        eProduct(_("Product")),
# Line 960  PropDialog::PropDialog() Line 1000  PropDialog::PropDialog()
1000        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1001        eSubject(_("Subject")),        eSubject(_("Subject")),
1002        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1003        update_model(0)        table(2, 1)
1004  {  {
1005      set_title(_("File Properties"));      set_title(_("File Properties"));
1006      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1008  PropDialog::PropDialog() Line 1048  PropDialog::PropDialog()
1048      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1049      buttonBox.show();      buttonBox.show();
1050      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1051      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1052      quitButton.grab_focus();      quitButton.grab_focus();
1053      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1054          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
# Line 1020  PropDialog::PropDialog() Line 1060  PropDialog::PropDialog()
1060    
1061  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1062  {  {
1063      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--;  
1064  }  }
1065    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1066    
1067  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_Name(const gig::String& name)
1068  {  {
1069      instrument->IsDrum = value;      m->pInfo->Name = name;
1070  }  }
1071    
1072  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1073  {  {
1074      instrument->MIDIBank = value;      update_model++;
1075        eName.set_value(m->pInfo->Name);
1076        update_model--;
1077  }  }
1078    
1079  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1080  {  {
1081      instrument->MIDIProgram = value;      m->IsDrum = value;
1082  }  }
1083    
1084  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1085  {  {
1086      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1087  }  }
1088    
1089  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1090  {  {
1091      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1092  }  }
1093    
1094  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1095      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1096        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1097        eName(_("Name")),      eName(_("Name")),
1098        eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
1099        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1100        eMIDIProgram(_("MIDI program")),      eMIDIProgram(_("MIDI program")),
1101        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1102        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1103        eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1104        eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1105        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1106        ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
1107        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1108        eDimensionKeyRangeHigh(_("Keyswitching range high")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1109  {  {
1110      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1111    
# Line 1105  InstrumentProps::InstrumentProps() Line 1118  InstrumentProps::InstrumentProps()
1118            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1119      );      );
1120    
1121        connect(eName, &InstrumentProps::set_Name);
1122      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1123      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1124      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1114  InstrumentProps::InstrumentProps() Line 1128  InstrumentProps::InstrumentProps()
1128      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1129      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1130      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1131      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1132              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1133      connect(eDimensionKeyRangeHigh,  
1134              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1135    
1136      table.set_col_spacings(5);      table.set_col_spacings(5);
1137    
# Line 1143  InstrumentProps::InstrumentProps() Line 1157  InstrumentProps::InstrumentProps()
1157      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1158      buttonBox.show();      buttonBox.show();
1159      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1160      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1161      quitButton.grab_focus();      quitButton.grab_focus();
1162    
1163      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1156  InstrumentProps::InstrumentProps() Line 1170  InstrumentProps::InstrumentProps()
1170    
1171  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1172  {  {
1173      this->instrument = instrument;      update(instrument);
1174    
1175      update_model++;      update_model++;
1176      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1177      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1178      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1179      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);  
1180      update_model--;      update_model--;
1181  }  }
1182    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1183    
1184  void MainWindow::file_changed()  void MainWindow::file_changed()
1185  {  {
# Line 1199  void MainWindow::load_gig(gig::File* gig Line 1201  void MainWindow::load_gig(gig::File* gig
1201    
1202      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1203    
1204      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;  
1205      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1206           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1207            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1208    
1209          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1210          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1211          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1212          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1213          // create a menu item for this instrument  
1214          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++;  
1215      }      }
1216      instrument_menu->show();      instrument_name_connection.unblock();
1217      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1218    
1219      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1220          if (group->Name != "") {          if (group->Name != "") {
1221              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1222              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1223              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1224              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1225              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1226              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1237  void MainWindow::load_gig(gig::File* gig Line 1228  void MainWindow::load_gig(gig::File* gig
1228                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1229                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1230                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1231                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1232                        gig_to_utf8(sample->pInfo->Name);
1233                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1234                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1235              }              }
# Line 1247  void MainWindow::load_gig(gig::File* gig Line 1239  void MainWindow::load_gig(gig::File* gig
1239      file = gig;      file = gig;
1240    
1241      // select the first instrument      // select the first instrument
1242      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1243      tree_sel_ref->select(Gtk::TreePath("0"));  
1244        instr_props_set_instrument();
1245        gig::Instrument* instrument = get_instrument();
1246        if (instrument) {
1247            midiRules.set_instrument(instrument);
1248        }
1249  }  }
1250    
1251  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1252  {  {
1253      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1254      if (instrument)  
1255      {      Gtk::TreeModel::const_iterator it =
1256            m_TreeView.get_selection()->get_selected();
1257        if (it) {
1258            Gtk::TreeModel::Row row = *it;
1259            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1260    
1261          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1262    
1263            // make sure instrument tree is updated when user changes the
1264            // instrument name in instrument properties window
1265            instrumentProps.signal_name_changed().connect(
1266                sigc::bind(
1267                    sigc::mem_fun(*this,
1268                                  &MainWindow::instr_name_changed_by_instr_props),
1269                    it));
1270        } else {
1271            instrumentProps.hide();
1272        }
1273        return it;
1274    }
1275    
1276    void MainWindow::show_instr_props()
1277    {
1278        if (instr_props_set_instrument()) {
1279          instrumentProps.show();          instrumentProps.show();
1280          instrumentProps.deiconify();          instrumentProps.deiconify();
1281      }      }
1282  }  }
1283    
1284    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1285    {
1286        Gtk::TreeModel::Row row = *it;
1287        Glib::ustring name = row[m_Columns.m_col_name];
1288    
1289        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1290        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1291        if (gigname != name) {
1292            row[m_Columns.m_col_name] = gigname;
1293        }
1294    }
1295    
1296    void MainWindow::show_midi_rules()
1297    {
1298        if (gig::Instrument* instrument = get_instrument())
1299        {
1300            midiRules.set_instrument(instrument);
1301            midiRules.show();
1302            midiRules.deiconify();
1303        }
1304    }
1305    
1306  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1307      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1308          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1273  void MainWindow::on_action_view_status_b Line 1314  void MainWindow::on_action_view_status_b
1314      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1315  }  }
1316    
1317    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1318        Gtk::CheckMenuItem* item =
1319            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1320        if (!item) {
1321            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1322            return true;
1323        }
1324        return item->get_active();
1325    }
1326    
1327    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1328        Gtk::CheckMenuItem* item =
1329            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1330        if (!item) {
1331            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1332            return true;
1333        }
1334        return item->get_active();
1335    }
1336    
1337    bool MainWindow::is_copy_samples_loop_enabled() const {
1338        Gtk::CheckMenuItem* item =
1339            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1340        if (!item) {
1341            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1342            return true;
1343        }
1344        return item->get_active();
1345    }
1346    
1347  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1348  {  {
1349      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1350          show_instr_props();          show_instr_props();
1351      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1352            // gig v2 files have no midi rules
1353            static_cast<Gtk::MenuItem*>(
1354                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1355                    !(file->pVersion && file->pVersion->major == 2));
1356          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1357      }      }
1358  }  }
1359    
1360  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1361      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1362            const std::vector<Gtk::Widget*> children =
1363                instrument_menu->get_children();
1364            std::vector<Gtk::Widget*>::const_iterator it =
1365                find(children.begin(), children.end(), item);
1366            if (it != children.end()) {
1367                int index = it - children.begin();
1368                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1369    
1370                m_RegionChooser.set_instrument(file->GetInstrument(index));
1371            }
1372        }
1373  }  }
1374    
1375  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1313  void MainWindow::on_sample_treeview_butt Line 1399  void MainWindow::on_sample_treeview_butt
1399      }      }
1400  }  }
1401    
1402  void MainWindow::on_action_add_instrument() {  
1403      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1404      if (!file) return;      const Glib::ustring& name, int position) {
1405      gig::Instrument* instrument = file->AddInstrument();  
1406      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1407      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1408          _("Unnamed Instrument ") + ToString(__instrument_indexer);      if (!children.empty()) {
1409            instrument_group =
1410                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1411        }
1412        Gtk::RadioMenuItem* item =
1413            new Gtk::RadioMenuItem(instrument_group, name);
1414        if (position < 0) {
1415            instrument_menu->append(*item);
1416        } else {
1417            instrument_menu->insert(*item, position);
1418        }
1419        item->show();
1420        item->signal_activate().connect(
1421            sigc::bind(
1422                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1423                item));
1424        return item;
1425    }
1426    
1427    void MainWindow::remove_instrument_from_menu(int index) {
1428        const std::vector<Gtk::Widget*> children =
1429            instrument_menu->get_children();
1430        Gtk::Widget* child = children[index];
1431        instrument_menu->remove(*child);
1432        delete child;
1433    }
1434    
1435    void MainWindow::add_instrument(gig::Instrument* instrument) {
1436        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1437    
1438      // update instrument tree view      // update instrument tree view
1439        instrument_name_connection.block();
1440      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1441      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1442      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1443      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1444        instrument_name_connection.unblock();
1445    
1446        add_instrument_to_menu(name);
1447    
1448        m_TreeView.get_selection()->select(iterInstr);
1449    
1450      file_changed();      file_changed();
1451  }  }
1452    
1453    void MainWindow::on_action_add_instrument() {
1454        static int __instrument_indexer = 0;
1455        if (!file) return;
1456        gig::Instrument* instrument = file->AddInstrument();
1457        __instrument_indexer++;
1458        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1459                                                ToString(__instrument_indexer));
1460    
1461        add_instrument(instrument);
1462    }
1463    
1464    void MainWindow::on_action_duplicate_instrument() {
1465        if (!file) return;
1466    
1467        // retrieve the currently selected instrument
1468        // (being the original instrument to be duplicated)
1469        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1470        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1471        if (!itSelection) return;
1472        Gtk::TreeModel::Row row = *itSelection;
1473        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1474        if (!instrOrig) return;
1475    
1476        // duplicate the orginal instrument
1477        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1478        instrNew->pInfo->Name =
1479            instrOrig->pInfo->Name +
1480            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1481    
1482        add_instrument(instrNew);
1483    }
1484    
1485  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1486      if (!file) return;      if (!file) return;
1487      if (file_is_shared) {      if (file_is_shared) {
# Line 1347  void MainWindow::on_action_remove_instru Line 1501  void MainWindow::on_action_remove_instru
1501          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1502          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1503          try {          try {
1504                Gtk::TreePath path(it);
1505                int index = path[0];
1506    
1507              // remove instrument from the gig file              // remove instrument from the gig file
1508              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1509              file_changed();              file_changed();
1510    
1511                remove_instrument_from_menu(index);
1512    
1513                // remove row from instruments tree view
1514                m_refTreeModel->erase(it);
1515    
1516    #if GTKMM_MAJOR_VERSION < 3
1517                // select another instrument (in gtk3 this is done
1518                // automatically)
1519                if (!m_refTreeModel->children().empty()) {
1520                    if (index == m_refTreeModel->children().size()) {
1521                        index--;
1522                    }
1523                    m_TreeView.get_selection()->select(
1524                        Gtk::TreePath(ToString(index)));
1525                }
1526    #endif
1527                instr_props_set_instrument();
1528                instr = get_instrument();
1529                if (instr) {
1530                    midiRules.set_instrument(instr);
1531                } else {
1532                    midiRules.hide();
1533                }
1534          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1535              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1536              msg.run();              msg.run();
# Line 1371  void MainWindow::on_action_add_group() { Line 1550  void MainWindow::on_action_add_group() {
1550      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1551      if (!file) return;      if (!file) return;
1552      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1553      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1554      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1555      __sample_indexer++;      __sample_indexer++;
1556      // update sample tree view      // update sample tree view
1557      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1558      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1559      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1560      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1561      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1562      file_changed();      file_changed();
# Line 1405  void MainWindow::on_action_add_sample() Line 1584  void MainWindow::on_action_add_sample()
1584      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1585      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1586      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1587      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1588        // matches all file types supported by libsndfile
1589    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1590        Gtk::FileFilter soundfilter;
1591    #else
1592        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1593    #endif
1594      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1595          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1596          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1413  void MainWindow::on_action_add_sample() Line 1598  void MainWindow::on_action_add_sample()
1598          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1599          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1600      };      };
1601        const char* soundfiles = _("Sound Files");
1602        const char* allfiles = _("All Files");
1603    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1604      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1605          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1606      soundfilter.set_name(_("Sound Files"));      soundfilter.set_name(soundfiles);
1607      Gtk::FileFilter allpassfilter; // matches every file  
1608        // matches every file
1609        Gtk::FileFilter allpassfilter;
1610      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1611      allpassfilter.set_name(_("All Files"));      allpassfilter.set_name(allfiles);
1612    #else
1613        for (int i = 0; supportedFileTypes[i]; i++)
1614            soundfilter->add_pattern(supportedFileTypes[i]);
1615        soundfilter->set_name(soundfiles);
1616    
1617        // matches every file
1618        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1619        allpassfilter->add_pattern("*.*");
1620        allpassfilter->set_name(allfiles);
1621    #endif
1622      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1623      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1624      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 1427  void MainWindow::on_action_add_sample() Line 1627  void MainWindow::on_action_add_sample()
1627      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1628          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1629          Glib::ustring error_files;          Glib::ustring error_files;
1630          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1631          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1632               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1633              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1634              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1465  void MainWindow::on_action_add_sample() Line 1665  void MainWindow::on_action_add_sample()
1665                          break;                          break;
1666                      }                      }
1667                  }                  }
1668                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1669                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1670                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1671                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1479  void MainWindow::on_action_add_sample() Line 1679  void MainWindow::on_action_add_sample()
1679                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1680                  {                  {
1681                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1682                        sample->FineTune      = instrument.detune;
1683    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1684                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1685                          sample->Loops = 1;                          sample->Loops = 1;
1686    
# Line 1500  void MainWindow::on_action_add_sample() Line 1700  void MainWindow::on_action_add_sample()
1700                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1701                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1702                      }                      }
 #endif  
1703                  }                  }
1704    
1705                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1518  void MainWindow::on_action_add_sample() Line 1717  void MainWindow::on_action_add_sample()
1717                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1718                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1719                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1720                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1721                        gig_to_utf8(sample->pInfo->Name);
1722                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1723                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1724                  // close sound file                  // close sound file
1725                  sf_close(hFile);                  sf_close(hFile);
1726                  file_changed();                  file_changed();
1727              } 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)
1728                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1729                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1730              }              }
1731          }          }
1732          // 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
1733          if (error_files.size()) {          if (!error_files.empty()) {
1734              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;
1735              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1736              msg.run();              msg.run();
# Line 1543  void MainWindow::on_action_replace_all_s Line 1743  void MainWindow::on_action_replace_all_s
1743      if (!file) return;      if (!file) return;
1744      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1745                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1746      view::WrapLabel description(      const char* str =
1747          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1748            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
1749            "directory.\n\n"            "directory.\n\n"
# Line 1557  void MainWindow::on_action_replace_all_s Line 1757  void MainWindow::on_action_replace_all_s
1757            "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 "
1758            "extension, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
1759            "appropriate sample file could be found will be reported and left "            "appropriate sample file could be found will be reported and left "
1760            "untouched.\n")            "untouched.\n");
1761      );  #if GTKMM_MAJOR_VERSION < 3
1762        view::WrapLabel description(str);
1763    #else
1764        Gtk::Label description(str);
1765        description.set_line_wrap();
1766    #endif
1767      Gtk::HBox entryArea;      Gtk::HBox entryArea;
1768      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1769      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
1770      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
1771      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1579  void MainWindow::on_action_replace_all_s Line 1784  void MainWindow::on_action_replace_all_s
1784      {      {
1785          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1786          Glib::ustring error_files;          Glib::ustring error_files;
1787          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
1788          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
1789               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1790          {          {
1791              std::string filename =              std::string filename =
1792                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1793                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1794                                             postfixEntryBox.get_text());
1795              SF_INFO info;              SF_INFO info;
1796              info.format = 0;              info.format = 0;
1797              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1618  void MainWindow::on_action_replace_all_s Line 1824  void MainWindow::on_action_replace_all_s
1824              }              }
1825              catch (std::string what)              catch (std::string what)
1826              {              {
1827                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1828                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1829                        " (" + what + ")";
1830              }              }
1831          }          }
1832          // 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
1833          if (error_files.size()) {          if (!error_files.empty()) {
1834              Glib::ustring txt =              Glib::ustring txt =
1835                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1836              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1644  void MainWindow::on_action_remove_sample Line 1851  void MainWindow::on_action_remove_sample
1851          try {          try {
1852              // remove group or sample from the gig file              // remove group or sample from the gig file
1853              if (group) {              if (group) {
1854                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1855                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1856                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1857                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1770  void MainWindow::on_sample_label_drop_dr Line 1977  void MainWindow::on_sample_label_drop_dr
1977              channels_changed = true;              channels_changed = true;
1978              region_changed();              region_changed();
1979          }          }
1980          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
1981                sample,
1982                is_copy_samples_unity_note_enabled(),
1983                is_copy_samples_fine_tune_enabled(),
1984                is_copy_samples_loop_enabled()
1985            );
1986    
1987          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
1988              // add samplechannel dimension              // add samplechannel dimension
# Line 1813  void MainWindow::sample_name_changed(con Line 2025  void MainWindow::sample_name_changed(con
2025      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2026      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2027      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2028        gig::String gigname(gig_from_utf8(name));
2029      if (group) {      if (group) {
2030          if (group->Name != name) {          if (group->Name != gigname) {
2031              group->Name = name;              group->Name = gigname;
2032              printf("group name changed\n");              printf("group name changed\n");
2033              file_changed();              file_changed();
2034          }          }
2035      } else if (sample) {      } else if (sample) {
2036          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2037              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2038              printf("sample name changed\n");              printf("sample name changed\n");
2039              file_changed();              file_changed();
2040          }          }
# Line 1833  void MainWindow::instrument_name_changed Line 2046  void MainWindow::instrument_name_changed
2046      if (!iter) return;      if (!iter) return;
2047      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2048      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2049    
2050        // change name in instrument menu
2051        int index = path[0];
2052        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2053        if (index < children.size()) {
2054    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2055            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2056    #else
2057            remove_instrument_from_menu(index);
2058            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2059            item->set_active();
2060    #endif
2061        }
2062    
2063        // change name in gig
2064      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2065      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2066          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2067            instrument->pInfo->Name = gigname;
2068    
2069            // change name in the instrument properties window
2070            if (instrumentProps.get_instrument() == instrument) {
2071                instrumentProps.update_name();
2072            }
2073    
2074          file_changed();          file_changed();
2075      }      }
2076  }  }

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

  ViewVC Help
Powered by ViewVC