/[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 2507 by persson, Sun Jan 12 19:37:55 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 163  MainWindow::MainWindow() : Line 123  MainWindow::MainWindow() :
123                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
124                       sigc::mem_fun(                       sigc::mem_fun(
125                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
126        actionGroup->add(Gtk::Action::create("MidiRules",
127                                             _("_Midi Rules")),
128                         sigc::mem_fun(
129                             *this, &MainWindow::show_midi_rules));
130      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
131                       sigc::mem_fun(                       sigc::mem_fun(
132                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
133      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
134    
135      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
136        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
137    
138      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
139            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"), "ffaga");
140        toggle_action->set_active(true);
141        //FIXME: doesn't work, why?
142        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
143        actionGroup->add(toggle_action);
144    
145        toggle_action =
146            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
147        toggle_action->set_active(true);
148        //FIXME: doesn't work, why?
149        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
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        //FIXME: doesn't work, why?
156        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
157        actionGroup->add(toggle_action);
158    
159    
160        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
161        toggle_action =
162          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
163      toggle_action->set_active(true);      toggle_action->set_active(true);
164      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 179  MainWindow::MainWindow() : Line 168  MainWindow::MainWindow() :
168      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
169      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
170                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
171      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
172                       sigc::mem_fun(                       sigc::mem_fun(
173                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
174      actionGroup->add(      actionGroup->add(
175          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
176          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
177      );      );
178      actionGroup->add(      actionGroup->add(
179            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
180            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
181        );
182        actionGroup->add(
183          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
184          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
185      );      );
# Line 234  MainWindow::MainWindow() : Line 225  MainWindow::MainWindow() :
225          "      <separator/>"          "      <separator/>"
226          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
227          "    </menu>"          "    </menu>"
228            "    <menu action='MenuEdit'>"
229            "      <menuitem action='CopySampleUnity'/>"
230            "      <menuitem action='CopySampleTune'/>"
231            "      <menuitem action='CopySampleLoop'/>"
232            "    </menu>"
233          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
234          "    </menu>"          "    </menu>"
235          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
236          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
237          "    </menu>"          "    </menu>"
 #ifdef ABOUT_DIALOG  
238          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
239          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
240          "    </menu>"          "    </menu>"
 #endif  
241          "  </menubar>"          "  </menubar>"
242          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
243          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
244            "    <menuitem action='MidiRules'/>"
245          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
246            "    <menuitem action='DupInstrument'/>"
247          "    <separator/>"          "    <separator/>"
248          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
249          "  </popup>"          "  </popup>"
# Line 255  MainWindow::MainWindow() : Line 251  MainWindow::MainWindow() :
251          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
252          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
253          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
254          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
255          "    <separator/>"          "    <separator/>"
256          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
257          "  </popup>"          "  </popup>"
# Line 264  MainWindow::MainWindow() : Line 260  MainWindow::MainWindow() :
260    
261      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
262    
263        instrument_menu = static_cast<Gtk::MenuItem*>(
264            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
265    
266      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
267      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
268      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
# Line 272  MainWindow::MainWindow() : Line 271  MainWindow::MainWindow() :
271      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
272      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
273    
274        set_file_is_shared(false);
275    
276      // Status Bar:      // Status Bar:
277      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
278      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 286  MainWindow::MainWindow() : Line 287  MainWindow::MainWindow() :
287      // Create the Tree model:      // Create the Tree model:
288      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
289      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
290      m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
291          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
292      );      );
293    
# Line 308  MainWindow::MainWindow() : Line 309  MainWindow::MainWindow() :
309      );      );
310    
311      // 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
312      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
313      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
314      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
315      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
316          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 328  MainWindow::MainWindow() :
328          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
329      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
330          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
331      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
332            sigc::mem_fun(*this, &MainWindow::file_changed));
333        propDialog.signal_changed().connect(
334          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
335      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
336          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
337    
338      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 374  MainWindow::MainWindow() : Line 377  MainWindow::MainWindow() :
377    
378      file = 0;      file = 0;
379      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
380    
381      show_all_children();      show_all_children();
382    
# Line 405  void MainWindow::region_changed() Line 407  void MainWindow::region_changed()
407  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
408  {  {
409      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
410      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
411            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
412      if (it) {      if (it) {
413          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
414          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 466  void MainWindow::dimreg_changed() Line 467  void MainWindow::dimreg_changed()
467    
468  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
469  {  {
470        // select item in instrument menu
471        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
472        if (it) {
473            Gtk::TreePath path(it);
474            int index = path[0];
475            const std::vector<Gtk::Widget*> children =
476                instrument_menu->get_children();
477            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
478        }
479    
480      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
481  }  }
482    
# Line 478  void loader_progress_callback(gig::progr Line 489  void loader_progress_callback(gig::progr
489  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
490  {  {
491      {      {
492          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
493          progress = fraction;          progress = fraction;
494      }      }
495      progress_dispatcher();      progress_dispatcher();
# Line 486  void Loader::progress_callback(float fra Line 497  void Loader::progress_callback(float fra
497    
498  void Loader::thread_function()  void Loader::thread_function()
499  {  {
500      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
501      printf("Start %s\n", filename);      printf("Start %s\n", filename);
502      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
503      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 500  void Loader::thread_function() Line 511  void Loader::thread_function()
511  }  }
512    
513  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
514      : thread(0), filename(filename)      : filename(filename), thread(0)
515  {  {
516  }  }
517    
518  void Loader::launch()  void Loader::launch()
519  {  {
520    #ifdef OLD_THREADS
521      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
522    #else
523        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
524    #endif
525      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
526  }  }
527    
# Line 514  float Loader::get_progress() Line 529  float Loader::get_progress()
529  {  {
530      float res;      float res;
531      {      {
532          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
533          res = progress;          res = progress;
534      }      }
535      return res;      return res;
# Line 540  LoadDialog::LoadDialog(const Glib::ustri Line 555  LoadDialog::LoadDialog(const Glib::ustri
555  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
556  // 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.
557  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();  
558      // forget all samples that ought to be imported      // forget all samples that ought to be imported
559      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
560      // clear the samples and instruments tree views      // clear the samples and instruments tree views
561      m_refTreeModel->clear();      m_refTreeModel->clear();
562      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
563        // remove all entries from "Instrument" menu
564        while (!instrument_menu->get_children().empty()) {
565            remove_instrument_from_menu(0);
566        }
567      // free libgig's gig::File instance      // free libgig's gig::File instance
568      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
569      file = NULL;      file = NULL;
# Line 571  void MainWindow::on_action_file_new() Line 582  void MainWindow::on_action_file_new()
582      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
583      // already add one new instrument by default      // already add one new instrument by default
584      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
585      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
586      // update GUI with that new gig::File      // update GUI with that new gig::File
587      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
588  }  }
# Line 582  bool MainWindow::close_confirmation_dial Line 593  bool MainWindow::close_confirmation_dial
593                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
594      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
595      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
596      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  
597      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
598      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
599      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 607  bool MainWindow::close_confirmation_dial
607  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
608      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
609      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  
610      dialog.set_secondary_text(      dialog.set_secondary_text(
611          _("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 "
612            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
613            "load it.")            "load it."));
    );  
 #endif  
614      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
615      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
616      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 623  void MainWindow::on_action_file_open() Line 629  void MainWindow::on_action_file_open()
629      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
630      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
631      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
632    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
633      Gtk::FileFilter filter;      Gtk::FileFilter filter;
634      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
635    #else
636        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
637        filter->add_pattern("*.gig");
638    #endif
639      dialog.set_filter(filter);      dialog.set_filter(filter);
640      if (current_gig_dir != "") {      if (current_gig_dir != "") {
641          dialog.set_current_folder(current_gig_dir);          dialog.set_current_folder(current_gig_dir);
# Line 632  void MainWindow::on_action_file_open() Line 643  void MainWindow::on_action_file_open()
643      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
644          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
645          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
646          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
647          load_file(filename.c_str());          load_file(filename.c_str());
648          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
649      }      }
# Line 674  void MainWindow::on_loader_progress() Line 685  void MainWindow::on_loader_progress()
685  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
686  {  {
687      printf("Loader finished!\n");      printf("Loader finished!\n");
688      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
689      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
690      load_dialog->hide();      load_dialog->hide();
691  }  }
# Line 746  bool MainWindow::file_save_as() Line 757  bool MainWindow::file_save_as()
757      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
758      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
759      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  
760      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
761      // TODO: an overwrite dialog for gtkmm < 2.8  
762  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
763      Gtk::FileFilter filter;      Gtk::FileFilter filter;
764      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
765    #else
766        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
767        filter->add_pattern("*.gig");
768    #endif
769      dialog.set_filter(filter);      dialog.set_filter(filter);
770    
771      // 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 788  bool MainWindow::file_save_as()
788      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
789      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));
790      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
791    #if GTKMM_MAJOR_VERSION < 3
792      view::WrapLabel description;      view::WrapLabel description;
793    #else
794        Gtk::Label description;
795        description.set_line_wrap();
796    #endif
797      description.set_markup(      description.set_markup(
798          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
799            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 827  void MainWindow::__import_queued_samples Line 845  void MainWindow::__import_queued_samples
845          SF_INFO info;          SF_INFO info;
846          info.format = 0;          info.format = 0;
847          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
848            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
849          try {          try {
850              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
851              // determine sample's bit depth              // determine sample's bit depth
# Line 896  void MainWindow::__import_queued_samples Line 915  void MainWindow::__import_queued_samples
915              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
916          } catch (std::string what) {          } catch (std::string what) {
917              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
918              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
919              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
920              ++iter;              ++iter;
921          }          }
922      }      }
923      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
924      if (error_files.size()) {      if (!error_files.empty()) {
925          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;
926          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
927          msg.run();          msg.run();
# Line 917  void MainWindow::on_action_file_properti Line 936  void MainWindow::on_action_file_properti
936    
937  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
938  {  {
 #ifdef ABOUT_DIALOG  
939      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
940  #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
941      dialog.set_program_name("Gigedit");      dialog.set_program_name("Gigedit");
# Line 925  void MainWindow::on_action_help_about() Line 943  void MainWindow::on_action_help_about()
943      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
944  #endif  #endif
945      dialog.set_version(VERSION);      dialog.set_version(VERSION);
946      dialog.set_copyright("Copyright (C) 2006-2009 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
947      dialog.set_comments(_(      const std::string sComment =
948          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
949          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
950          "Please notice that this is still a very young instrument editor. "          _(
951          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
952          "this application.\n"              "\n"
953          "\n"              "Please notice that this is still a very young instrument editor. "
954          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
955      );              "this application.\n"
956                "\n"
957                "Please report bugs to: http://bugs.linuxsampler.org"
958            );
959        dialog.set_comments(sComment.c_str());
960      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
961      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
962      dialog.run();      dialog.run();
 #endif  
963  }  }
964    
965  PropDialog::PropDialog()  PropDialog::PropDialog()
966      : table(2,1),      : eName(_("Name")),
       eName(_("Name")),  
967        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
968        eComments(_("Comments")),        eComments(_("Comments")),
969        eProduct(_("Product")),        eProduct(_("Product")),
# Line 960  PropDialog::PropDialog() Line 980  PropDialog::PropDialog()
980        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
981        eSubject(_("Subject")),        eSubject(_("Subject")),
982        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
983        update_model(0)        table(2, 1)
984  {  {
985      set_title(_("File Properties"));      set_title(_("File Properties"));
986      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1008  PropDialog::PropDialog() Line 1028  PropDialog::PropDialog()
1028      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1029      buttonBox.show();      buttonBox.show();
1030      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1031      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1032      quitButton.grab_focus();      quitButton.grab_focus();
1033      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1034          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
# Line 1020  PropDialog::PropDialog() Line 1040  PropDialog::PropDialog()
1040    
1041  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1042  {  {
1043      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--;  
1044  }  }
1045    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1046    
1047  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_Name(const gig::String& name)
1048  {  {
1049      instrument->IsDrum = value;      m->pInfo->Name = name;
1050  }  }
1051    
1052  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1053  {  {
1054      instrument->MIDIBank = value;      update_model++;
1055        eName.set_value(m->pInfo->Name);
1056        update_model--;
1057  }  }
1058    
1059  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1060  {  {
1061      instrument->MIDIProgram = value;      m->IsDrum = value;
1062  }  }
1063    
1064  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1065  {  {
1066      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1067  }  }
1068    
1069  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1070  {  {
1071      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1072  }  }
1073    
1074  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1075      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1076        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1077        eName(_("Name")),      eName(_("Name")),
1078        eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
1079        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1080        eMIDIProgram(_("MIDI program")),      eMIDIProgram(_("MIDI program")),
1081        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1082        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1083        eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1084        eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1085        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1086        ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
1087        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1088        eDimensionKeyRangeHigh(_("Keyswitching range high")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1089  {  {
1090      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1091    
# Line 1105  InstrumentProps::InstrumentProps() Line 1098  InstrumentProps::InstrumentProps()
1098            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1099      );      );
1100    
1101        connect(eName, &InstrumentProps::set_Name);
1102      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1103      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1104      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1114  InstrumentProps::InstrumentProps() Line 1108  InstrumentProps::InstrumentProps()
1108      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1109      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1110      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1111      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1112              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1113      connect(eDimensionKeyRangeHigh,  
1114              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1115    
1116      table.set_col_spacings(5);      table.set_col_spacings(5);
1117    
# Line 1143  InstrumentProps::InstrumentProps() Line 1137  InstrumentProps::InstrumentProps()
1137      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1138      buttonBox.show();      buttonBox.show();
1139      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1140      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1141      quitButton.grab_focus();      quitButton.grab_focus();
1142    
1143      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1156  InstrumentProps::InstrumentProps() Line 1150  InstrumentProps::InstrumentProps()
1150    
1151  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1152  {  {
1153      this->instrument = instrument;      update(instrument);
1154    
1155      update_model++;      update_model++;
1156      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1157      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1158      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1159      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);  
1160      update_model--;      update_model--;
1161  }  }
1162    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1163    
1164  void MainWindow::file_changed()  void MainWindow::file_changed()
1165  {  {
# Line 1199  void MainWindow::load_gig(gig::File* gig Line 1181  void MainWindow::load_gig(gig::File* gig
1181    
1182      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1183    
1184      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;  
1185      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1186           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1187            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1188    
1189          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1190          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1191          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1192          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1193          // create a menu item for this instrument  
1194          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++;  
1195      }      }
1196      instrument_menu->show();      instrument_name_connection.unblock();
1197      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1198    
1199      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1200          if (group->Name != "") {          if (group->Name != "") {
1201              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1202              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1203              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1204              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1205              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1206              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1237  void MainWindow::load_gig(gig::File* gig Line 1208  void MainWindow::load_gig(gig::File* gig
1208                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1209                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1210                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1211                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1212                        gig_to_utf8(sample->pInfo->Name);
1213                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1214                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1215              }              }
# Line 1247  void MainWindow::load_gig(gig::File* gig Line 1219  void MainWindow::load_gig(gig::File* gig
1219      file = gig;      file = gig;
1220    
1221      // select the first instrument      // select the first instrument
1222      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1223      tree_sel_ref->select(Gtk::TreePath("0"));  
1224        instr_props_set_instrument();
1225        gig::Instrument* instrument = get_instrument();
1226        if (instrument) {
1227            midiRules.set_instrument(instrument);
1228        }
1229  }  }
1230    
1231  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1232  {  {
1233      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1234      if (instrument)  
1235      {      Gtk::TreeModel::const_iterator it =
1236            m_TreeView.get_selection()->get_selected();
1237        if (it) {
1238            Gtk::TreeModel::Row row = *it;
1239            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1240    
1241          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1242    
1243            // make sure instrument tree is updated when user changes the
1244            // instrument name in instrument properties window
1245            instrumentProps.signal_name_changed().connect(
1246                sigc::bind(
1247                    sigc::mem_fun(*this,
1248                                  &MainWindow::instr_name_changed_by_instr_props),
1249                    it));
1250        } else {
1251            instrumentProps.hide();
1252        }
1253        return it;
1254    }
1255    
1256    void MainWindow::show_instr_props()
1257    {
1258        if (instr_props_set_instrument()) {
1259          instrumentProps.show();          instrumentProps.show();
1260          instrumentProps.deiconify();          instrumentProps.deiconify();
1261      }      }
1262  }  }
1263    
1264    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1265    {
1266        Gtk::TreeModel::Row row = *it;
1267        Glib::ustring name = row[m_Columns.m_col_name];
1268    
1269        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1270        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1271        if (gigname != name) {
1272            row[m_Columns.m_col_name] = gigname;
1273        }
1274    }
1275    
1276    void MainWindow::show_midi_rules()
1277    {
1278        if (gig::Instrument* instrument = get_instrument())
1279        {
1280            midiRules.set_instrument(instrument);
1281            midiRules.show();
1282            midiRules.deiconify();
1283        }
1284    }
1285    
1286  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1287      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1288          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 1294  void MainWindow::on_action_view_status_b
1294      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1295  }  }
1296    
1297    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1298        Gtk::CheckMenuItem* item =
1299            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1300        if (!item) {
1301            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1302            return true;
1303        }
1304        return item->get_active();
1305    }
1306    
1307    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1308        Gtk::CheckMenuItem* item =
1309            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1310        if (!item) {
1311            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1312            return true;
1313        }
1314        return item->get_active();
1315    }
1316    
1317    bool MainWindow::is_copy_samples_loop_enabled() const {
1318        Gtk::CheckMenuItem* item =
1319            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1320        if (!item) {
1321            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1322            return true;
1323        }
1324        return item->get_active();
1325    }
1326    
1327  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1328  {  {
1329      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1330          show_instr_props();          show_instr_props();
1331      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1332            // gig v2 files have no midi rules
1333            static_cast<Gtk::MenuItem*>(
1334                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1335                    !(file->pVersion && file->pVersion->major == 2));
1336          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1337      }      }
1338  }  }
1339    
1340  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1341      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1342            const std::vector<Gtk::Widget*> children =
1343                instrument_menu->get_children();
1344            std::vector<Gtk::Widget*>::const_iterator it =
1345                find(children.begin(), children.end(), item);
1346            if (it != children.end()) {
1347                int index = it - children.begin();
1348                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1349    
1350                m_RegionChooser.set_instrument(file->GetInstrument(index));
1351            }
1352        }
1353  }  }
1354    
1355  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 1379  void MainWindow::on_sample_treeview_butt
1379      }      }
1380  }  }
1381    
1382  void MainWindow::on_action_add_instrument() {  
1383      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1384      if (!file) return;      const Glib::ustring& name, int position) {
1385      gig::Instrument* instrument = file->AddInstrument();  
1386      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1387      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1388          _("Unnamed Instrument ") + ToString(__instrument_indexer);      if (!children.empty()) {
1389            instrument_group =
1390                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1391        }
1392        Gtk::RadioMenuItem* item =
1393            new Gtk::RadioMenuItem(instrument_group, name);
1394        if (position < 0) {
1395            instrument_menu->append(*item);
1396        } else {
1397            instrument_menu->insert(*item, position);
1398        }
1399        item->show();
1400        item->signal_activate().connect(
1401            sigc::bind(
1402                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1403                item));
1404        return item;
1405    }
1406    
1407    void MainWindow::remove_instrument_from_menu(int index) {
1408        const std::vector<Gtk::Widget*> children =
1409            instrument_menu->get_children();
1410        Gtk::Widget* child = children[index];
1411        instrument_menu->remove(*child);
1412        delete child;
1413    }
1414    
1415    void MainWindow::add_instrument(gig::Instrument* instrument) {
1416        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1417    
1418      // update instrument tree view      // update instrument tree view
1419        instrument_name_connection.block();
1420      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1421      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1422      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1423      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1424        instrument_name_connection.unblock();
1425    
1426        add_instrument_to_menu(name);
1427    
1428        m_TreeView.get_selection()->select(iterInstr);
1429    
1430      file_changed();      file_changed();
1431  }  }
1432    
1433    void MainWindow::on_action_add_instrument() {
1434        static int __instrument_indexer = 0;
1435        if (!file) return;
1436        gig::Instrument* instrument = file->AddInstrument();
1437        __instrument_indexer++;
1438        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1439                                                ToString(__instrument_indexer));
1440    
1441        add_instrument(instrument);
1442    }
1443    
1444    void MainWindow::on_action_duplicate_instrument() {
1445        if (!file) return;
1446    
1447        // retrieve the currently selected instrument
1448        // (being the original instrument to be duplicated)
1449        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1450        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1451        if (!itSelection) return;
1452        Gtk::TreeModel::Row row = *itSelection;
1453        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1454        if (!instrOrig) return;
1455    
1456        // duplicate the orginal instrument
1457        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1458        instrNew->pInfo->Name =
1459            instrOrig->pInfo->Name +
1460            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1461    
1462        add_instrument(instrNew);
1463    }
1464    
1465  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1466      if (!file) return;      if (!file) return;
1467      if (file_is_shared) {      if (file_is_shared) {
# Line 1347  void MainWindow::on_action_remove_instru Line 1481  void MainWindow::on_action_remove_instru
1481          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1482          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1483          try {          try {
1484                Gtk::TreePath path(it);
1485                int index = path[0];
1486    
1487              // remove instrument from the gig file              // remove instrument from the gig file
1488              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1489              file_changed();              file_changed();
1490    
1491                remove_instrument_from_menu(index);
1492    
1493                // remove row from instruments tree view
1494                m_refTreeModel->erase(it);
1495    
1496    #if GTKMM_MAJOR_VERSION < 3
1497                // select another instrument (in gtk3 this is done
1498                // automatically)
1499                if (!m_refTreeModel->children().empty()) {
1500                    if (index == m_refTreeModel->children().size()) {
1501                        index--;
1502                    }
1503                    m_TreeView.get_selection()->select(
1504                        Gtk::TreePath(ToString(index)));
1505                }
1506    #endif
1507                instr_props_set_instrument();
1508                instr = get_instrument();
1509                if (instr) {
1510                    midiRules.set_instrument(instr);
1511                } else {
1512                    midiRules.hide();
1513                }
1514          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1515              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1516              msg.run();              msg.run();
# Line 1371  void MainWindow::on_action_add_group() { Line 1530  void MainWindow::on_action_add_group() {
1530      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1531      if (!file) return;      if (!file) return;
1532      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1533      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1534      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1535      __sample_indexer++;      __sample_indexer++;
1536      // update sample tree view      // update sample tree view
1537      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1538      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1539      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1540      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1541      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1542      file_changed();      file_changed();
# Line 1405  void MainWindow::on_action_add_sample() Line 1564  void MainWindow::on_action_add_sample()
1564      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1565      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1566      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1567      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1568        // matches all file types supported by libsndfile
1569    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1570        Gtk::FileFilter soundfilter;
1571    #else
1572        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1573    #endif
1574      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1575          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1576          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1413  void MainWindow::on_action_add_sample() Line 1578  void MainWindow::on_action_add_sample()
1578          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1579          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1580      };      };
1581        const char* soundfiles = _("Sound Files");
1582        const char* allfiles = _("All Files");
1583    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1584      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1585          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1586      soundfilter.set_name(_("Sound Files"));      soundfilter.set_name(soundfiles);
1587      Gtk::FileFilter allpassfilter; // matches every file  
1588        // matches every file
1589        Gtk::FileFilter allpassfilter;
1590      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1591      allpassfilter.set_name(_("All Files"));      allpassfilter.set_name(allfiles);
1592    #else
1593        for (int i = 0; supportedFileTypes[i]; i++)
1594            soundfilter->add_pattern(supportedFileTypes[i]);
1595        soundfilter->set_name(soundfiles);
1596    
1597        // matches every file
1598        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1599        allpassfilter->add_pattern("*.*");
1600        allpassfilter->set_name(allfiles);
1601    #endif
1602      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1603      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1604      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 1427  void MainWindow::on_action_add_sample() Line 1607  void MainWindow::on_action_add_sample()
1607      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1608          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1609          Glib::ustring error_files;          Glib::ustring error_files;
1610          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1611          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1612               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1613              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1614              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1465  void MainWindow::on_action_add_sample() Line 1645  void MainWindow::on_action_add_sample()
1645                          break;                          break;
1646                      }                      }
1647                  }                  }
1648                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1649                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1650                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1651                  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 1659  void MainWindow::on_action_add_sample()
1659                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1660                  {                  {
1661                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1662                        sample->FineTune      = instrument.detune;
1663    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1664                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1665                          sample->Loops = 1;                          sample->Loops = 1;
1666    
# Line 1500  void MainWindow::on_action_add_sample() Line 1680  void MainWindow::on_action_add_sample()
1680                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1681                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1682                      }                      }
 #endif  
1683                  }                  }
1684    
1685                  // 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 1697  void MainWindow::on_action_add_sample()
1697                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1698                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1699                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1700                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1701                        gig_to_utf8(sample->pInfo->Name);
1702                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1703                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1704                  // close sound file                  // close sound file
1705                  sf_close(hFile);                  sf_close(hFile);
1706                  file_changed();                  file_changed();
1707              } 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)
1708                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1709                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1710              }              }
1711          }          }
1712          // 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
1713          if (error_files.size()) {          if (!error_files.empty()) {
1714              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;
1715              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1716              msg.run();              msg.run();
# Line 1543  void MainWindow::on_action_replace_all_s Line 1723  void MainWindow::on_action_replace_all_s
1723      if (!file) return;      if (!file) return;
1724      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1725                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1726      view::WrapLabel description(      const char* str =
1727          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1728            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
1729            "directory.\n\n"            "directory.\n\n"
# Line 1557  void MainWindow::on_action_replace_all_s Line 1737  void MainWindow::on_action_replace_all_s
1737            "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 "
1738            "extension, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
1739            "appropriate sample file could be found will be reported and left "            "appropriate sample file could be found will be reported and left "
1740            "untouched.\n")            "untouched.\n");
1741      );  #if GTKMM_MAJOR_VERSION < 3
1742        view::WrapLabel description(str);
1743    #else
1744        Gtk::Label description(str);
1745        description.set_line_wrap();
1746    #endif
1747      Gtk::HBox entryArea;      Gtk::HBox entryArea;
1748      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1749      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
1750      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
1751      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1579  void MainWindow::on_action_replace_all_s Line 1764  void MainWindow::on_action_replace_all_s
1764      {      {
1765          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1766          Glib::ustring error_files;          Glib::ustring error_files;
1767          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
1768          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
1769               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1770          {          {
1771              std::string filename =              std::string filename =
1772                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1773                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1774                                             postfixEntryBox.get_text());
1775              SF_INFO info;              SF_INFO info;
1776              info.format = 0;              info.format = 0;
1777              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 1804  void MainWindow::on_action_replace_all_s
1804              }              }
1805              catch (std::string what)              catch (std::string what)
1806              {              {
1807                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1808                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1809                        " (" + what + ")";
1810              }              }
1811          }          }
1812          // 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
1813          if (error_files.size()) {          if (!error_files.empty()) {
1814              Glib::ustring txt =              Glib::ustring txt =
1815                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1816              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 1831  void MainWindow::on_action_remove_sample
1831          try {          try {
1832              // remove group or sample from the gig file              // remove group or sample from the gig file
1833              if (group) {              if (group) {
1834                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1835                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1836                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1837                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1770  void MainWindow::on_sample_label_drop_dr Line 1957  void MainWindow::on_sample_label_drop_dr
1957              channels_changed = true;              channels_changed = true;
1958              region_changed();              region_changed();
1959          }          }
1960          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
1961                sample,
1962                is_copy_samples_unity_note_enabled(),
1963                is_copy_samples_fine_tune_enabled(),
1964                is_copy_samples_loop_enabled()
1965            );
1966    
1967          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
1968              // add samplechannel dimension              // add samplechannel dimension
# Line 1813  void MainWindow::sample_name_changed(con Line 2005  void MainWindow::sample_name_changed(con
2005      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2006      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2007      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2008        gig::String gigname(gig_from_utf8(name));
2009      if (group) {      if (group) {
2010          if (group->Name != name) {          if (group->Name != gigname) {
2011              group->Name = name;              group->Name = gigname;
2012              printf("group name changed\n");              printf("group name changed\n");
2013              file_changed();              file_changed();
2014          }          }
2015      } else if (sample) {      } else if (sample) {
2016          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2017              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2018              printf("sample name changed\n");              printf("sample name changed\n");
2019              file_changed();              file_changed();
2020          }          }
# Line 1833  void MainWindow::instrument_name_changed Line 2026  void MainWindow::instrument_name_changed
2026      if (!iter) return;      if (!iter) return;
2027      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2028      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2029    
2030        // change name in instrument menu
2031        int index = path[0];
2032        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2033        if (index < children.size()) {
2034    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2035            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2036    #else
2037            remove_instrument_from_menu(index);
2038            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2039            item->set_active();
2040    #endif
2041        }
2042    
2043        // change name in gig
2044      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2045      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2046          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2047            instrument->pInfo->Name = gigname;
2048    
2049            // change name in the instrument properties window
2050            if (instrumentProps.get_instrument() == instrument) {
2051                instrumentProps.update_name();
2052            }
2053    
2054          file_changed();          file_changed();
2055      }      }
2056  }  }

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

  ViewVC Help
Powered by ViewVC