/[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 2442 by persson, Sun Apr 14 07:29:59 2013 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2009 Andreas Persson   * Copyright (C) 2006-2013 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 179  MainWindow::MainWindow() : Line 139  MainWindow::MainWindow() :
139      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
140      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
141                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
142      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
143                       sigc::mem_fun(                       sigc::mem_fun(
144                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
145      actionGroup->add(      actionGroup->add(
146          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
147          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
148      );      );
149      actionGroup->add(      actionGroup->add(
150            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
151            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
152        );
153        actionGroup->add(
154          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
155          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
156      );      );
# Line 239  MainWindow::MainWindow() : Line 201  MainWindow::MainWindow() :
201          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
202          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
203          "    </menu>"          "    </menu>"
 #ifdef ABOUT_DIALOG  
204          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
205          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
206          "    </menu>"          "    </menu>"
 #endif  
207          "  </menubar>"          "  </menubar>"
208          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
209          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
210          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
211            "    <menuitem action='DupInstrument'/>"
212          "    <separator/>"          "    <separator/>"
213          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
214          "  </popup>"          "  </popup>"
# Line 255  MainWindow::MainWindow() : Line 216  MainWindow::MainWindow() :
216          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
217          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
218          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
219          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
220          "    <separator/>"          "    <separator/>"
221          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
222          "  </popup>"          "  </popup>"
# Line 264  MainWindow::MainWindow() : Line 225  MainWindow::MainWindow() :
225    
226      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
227    
228        instrument_menu = static_cast<Gtk::MenuItem*>(
229            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
230    
231      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
232      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
233      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
# Line 272  MainWindow::MainWindow() : Line 236  MainWindow::MainWindow() :
236      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
237      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
238    
239        set_file_is_shared(false);
240    
241      // Status Bar:      // Status Bar:
242      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
243      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 286  MainWindow::MainWindow() : Line 252  MainWindow::MainWindow() :
252      // Create the Tree model:      // Create the Tree model:
253      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
254      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
255      m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
256          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
257      );      );
258    
# Line 308  MainWindow::MainWindow() : Line 274  MainWindow::MainWindow() :
274      );      );
275    
276      // 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
277      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
278      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
279      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
280      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
281          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 293  MainWindow::MainWindow() :
293          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
294      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
295          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
296      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
297          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
298      propDialog.signal_info_changed().connect(      propDialog.signal_changed().connect(
299          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
300    
301      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 374  MainWindow::MainWindow() : Line 340  MainWindow::MainWindow() :
340    
341      file = 0;      file = 0;
342      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
343    
344      show_all_children();      show_all_children();
345    
# Line 405  void MainWindow::region_changed() Line 370  void MainWindow::region_changed()
370  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
371  {  {
372      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
373      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
374            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
375      if (it) {      if (it) {
376          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
377          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 466  void MainWindow::dimreg_changed() Line 430  void MainWindow::dimreg_changed()
430    
431  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
432  {  {
433        // select item in instrument menu
434        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
435        if (it) {
436            Gtk::TreePath path(it);
437            int index = path[0];
438            const std::vector<Gtk::Widget*> children =
439                instrument_menu->get_children();
440            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
441        }
442    
443      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
444  }  }
445    
# Line 478  void loader_progress_callback(gig::progr Line 452  void loader_progress_callback(gig::progr
452  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
453  {  {
454      {      {
455          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
456          progress = fraction;          progress = fraction;
457      }      }
458      progress_dispatcher();      progress_dispatcher();
# Line 486  void Loader::progress_callback(float fra Line 460  void Loader::progress_callback(float fra
460    
461  void Loader::thread_function()  void Loader::thread_function()
462  {  {
463      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
464      printf("Start %s\n", filename);      printf("Start %s\n", filename);
465      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
466      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 500  void Loader::thread_function() Line 474  void Loader::thread_function()
474  }  }
475    
476  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
477      : thread(0), filename(filename)      : filename(filename), thread(0)
478  {  {
479  }  }
480    
481  void Loader::launch()  void Loader::launch()
482  {  {
483    #ifdef OLD_THREADS
484      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
485    #else
486        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
487    #endif
488      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
489  }  }
490    
# Line 514  float Loader::get_progress() Line 492  float Loader::get_progress()
492  {  {
493      float res;      float res;
494      {      {
495          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
496          res = progress;          res = progress;
497      }      }
498      return res;      return res;
# Line 540  LoadDialog::LoadDialog(const Glib::ustri Line 518  LoadDialog::LoadDialog(const Glib::ustri
518  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
519  // 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.
520  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();  
521      // forget all samples that ought to be imported      // forget all samples that ought to be imported
522      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
523      // clear the samples and instruments tree views      // clear the samples and instruments tree views
524      m_refTreeModel->clear();      m_refTreeModel->clear();
525      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
526        // remove all entries from "Instrument" menu
527        while (!instrument_menu->get_children().empty()) {
528            remove_instrument_from_menu(0);
529        }
530      // free libgig's gig::File instance      // free libgig's gig::File instance
531      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
532      file = NULL;      file = NULL;
# Line 582  bool MainWindow::close_confirmation_dial Line 556  bool MainWindow::close_confirmation_dial
556                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
557      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
558      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
559      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  
560      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
561      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
562      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 570  bool MainWindow::close_confirmation_dial
570  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
571      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
572      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  
573      dialog.set_secondary_text(      dialog.set_secondary_text(
574          _("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 "
575            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
576            "load it.")            "load it."));
    );  
 #endif  
577      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
578      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
579      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 623  void MainWindow::on_action_file_open() Line 592  void MainWindow::on_action_file_open()
592      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
593      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
594      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
595    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
596      Gtk::FileFilter filter;      Gtk::FileFilter filter;
597      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
598    #else
599        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
600        filter->add_pattern("*.gig");
601    #endif
602      dialog.set_filter(filter);      dialog.set_filter(filter);
603      if (current_gig_dir != "") {      if (current_gig_dir != "") {
604          dialog.set_current_folder(current_gig_dir);          dialog.set_current_folder(current_gig_dir);
# Line 632  void MainWindow::on_action_file_open() Line 606  void MainWindow::on_action_file_open()
606      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
607          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
608          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
609          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
610          load_file(filename.c_str());          load_file(filename.c_str());
611          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
612      }      }
# Line 674  void MainWindow::on_loader_progress() Line 648  void MainWindow::on_loader_progress()
648  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
649  {  {
650      printf("Loader finished!\n");      printf("Loader finished!\n");
651      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
652      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
653      load_dialog->hide();      load_dialog->hide();
654  }  }
# Line 746  bool MainWindow::file_save_as() Line 720  bool MainWindow::file_save_as()
720      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
721      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
722      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  
723      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
724      // TODO: an overwrite dialog for gtkmm < 2.8  
725  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
726      Gtk::FileFilter filter;      Gtk::FileFilter filter;
727      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
728    #else
729        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
730        filter->add_pattern("*.gig");
731    #endif
732      dialog.set_filter(filter);      dialog.set_filter(filter);
733    
734      // 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 751  bool MainWindow::file_save_as()
751      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
752      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));
753      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
754    #if GTKMM_MAJOR_VERSION < 3
755      view::WrapLabel description;      view::WrapLabel description;
756    #else
757        Gtk::Label description;
758        description.set_line_wrap();
759    #endif
760      description.set_markup(      description.set_markup(
761          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
762            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 827  void MainWindow::__import_queued_samples Line 808  void MainWindow::__import_queued_samples
808          SF_INFO info;          SF_INFO info;
809          info.format = 0;          info.format = 0;
810          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
811            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
812          try {          try {
813              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
814              // determine sample's bit depth              // determine sample's bit depth
# Line 896  void MainWindow::__import_queued_samples Line 878  void MainWindow::__import_queued_samples
878              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
879          } catch (std::string what) {          } catch (std::string what) {
880              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
881              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
882              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
883              ++iter;              ++iter;
884          }          }
885      }      }
886      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
887      if (error_files.size()) {      if (!error_files.empty()) {
888          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;
889          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
890          msg.run();          msg.run();
# Line 917  void MainWindow::on_action_file_properti Line 899  void MainWindow::on_action_file_properti
899    
900  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
901  {  {
 #ifdef ABOUT_DIALOG  
902      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
903  #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
904      dialog.set_program_name("Gigedit");      dialog.set_program_name("Gigedit");
# Line 925  void MainWindow::on_action_help_about() Line 906  void MainWindow::on_action_help_about()
906      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
907  #endif  #endif
908      dialog.set_version(VERSION);      dialog.set_version(VERSION);
909      dialog.set_copyright("Copyright (C) 2006-2009 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");
910      dialog.set_comments(_(      dialog.set_comments(_(
911          "Released under the GNU General Public License.\n"          "Released under the GNU General Public License.\n"
912          "\n"          "\n"
# Line 938  void MainWindow::on_action_help_about() Line 919  void MainWindow::on_action_help_about()
919      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
920      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
921      dialog.run();      dialog.run();
 #endif  
922  }  }
923    
924  PropDialog::PropDialog()  PropDialog::PropDialog()
925      : table(2,1),      : eName(_("Name")),
       eName(_("Name")),  
926        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
927        eComments(_("Comments")),        eComments(_("Comments")),
928        eProduct(_("Product")),        eProduct(_("Product")),
# Line 960  PropDialog::PropDialog() Line 939  PropDialog::PropDialog()
939        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
940        eSubject(_("Subject")),        eSubject(_("Subject")),
941        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
942        update_model(0)        table(2, 1)
943  {  {
944      set_title(_("File Properties"));      set_title(_("File Properties"));
945      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1008  PropDialog::PropDialog() Line 987  PropDialog::PropDialog()
987      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
988      buttonBox.show();      buttonBox.show();
989      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
990      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
991      quitButton.grab_focus();      quitButton.grab_focus();
992      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
993          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
# Line 1020  PropDialog::PropDialog() Line 999  PropDialog::PropDialog()
999    
1000  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1001  {  {
1002      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--;  
1003  }  }
1004    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1005    
1006  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_IsDrum(bool value)
1007  {  {
1008      instrument->IsDrum = value;      m->IsDrum = value;
1009  }  }
1010    
1011  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1012  {  {
1013      instrument->MIDIBank = value;      m->MIDIBank = value;
1014  }  }
1015    
1016  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1017  {  {
1018      instrument->MIDIProgram = value;      m->MIDIProgram = value;
1019  }  }
1020    
1021  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  InstrumentProps::InstrumentProps() :
1022  {      quitButton(Gtk::Stock::CLOSE),
1023      instrument->DimensionKeyRange.low = value;      table(2,1),
1024      if (value > instrument->DimensionKeyRange.high) {      eName(_("Name")),
1025          eDimensionKeyRangeHigh.set_value(value);      eIsDrum(_("Is drum")),
1026      }      eMIDIBank(_("MIDI bank"), 0, 16383),
1027  }      eMIDIProgram(_("MIDI program")),
1028        eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1029  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1030  {      eEffectSend(_("Effect send"), 0, 65535),
1031      instrument->DimensionKeyRange.high = value;      eFineTune(_("Fine tune"), -8400, 8400),
1032      if (value < instrument->DimensionKeyRange.low) {      ePitchbendRange(_("Pitchbend range"), 0, 12),
1033          eDimensionKeyRangeLow.set_value(value);      ePianoReleaseMode(_("Piano release mode")),
1034      }      eDimensionKeyRangeLow(_("Keyswitching range low")),
1035  }      eDimensionKeyRangeHigh(_("Keyswitching range high"))
   
 InstrumentProps::InstrumentProps()  
     : table(2,1),  
       quitButton(Gtk::Stock::CLOSE),  
       eName(_("Name")),  
       eIsDrum(_("Is drum")),  
       eMIDIBank(_("MIDI bank"), 0, 16383),  
       eMIDIProgram(_("MIDI program")),  
       eAttenuation(_("Attenuation"), 0, 96, 0, 1),  
       eGainPlus6(_("Gain +6dB"), eAttenuation, -6),  
       eEffectSend(_("Effect send"), 0, 65535),  
       eFineTune(_("Fine tune"), -8400, 8400),  
       ePitchbendRange(_("Pitchbend range"), 0, 12),  
       ePianoReleaseMode(_("Piano release mode")),  
       eDimensionKeyRangeLow(_("Keyswitching range low")),  
       eDimensionKeyRangeHigh(_("Keyswitching range high")),  
       update_model(0)  
1036  {  {
1037      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1038    
# Line 1114  InstrumentProps::InstrumentProps() Line 1054  InstrumentProps::InstrumentProps()
1054      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1055      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1056      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1057      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1058              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
     connect(eDimensionKeyRangeHigh,  
             &InstrumentProps::set_DimensionKeyRange_high);  
1059    
1060      table.set_col_spacings(5);      table.set_col_spacings(5);
1061    
# Line 1143  InstrumentProps::InstrumentProps() Line 1081  InstrumentProps::InstrumentProps()
1081      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1082      buttonBox.show();      buttonBox.show();
1083      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1084      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1085      quitButton.grab_focus();      quitButton.grab_focus();
1086    
1087      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1156  InstrumentProps::InstrumentProps() Line 1094  InstrumentProps::InstrumentProps()
1094    
1095  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1096  {  {
1097      this->instrument = instrument;      update(instrument);
1098    
1099      update_model++;      update_model++;
     eName.set_value(instrument->pInfo->Name);  
1100      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1101      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1102      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);  
1103      update_model--;      update_model--;
1104  }  }
1105    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1106    
1107  void MainWindow::file_changed()  void MainWindow::file_changed()
1108  {  {
# Line 1199  void MainWindow::load_gig(gig::File* gig Line 1124  void MainWindow::load_gig(gig::File* gig
1124    
1125      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1126    
1127      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;  
1128      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1129           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1130            Glib::ustring name(instrument->pInfo->Name);
1131    
1132          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1133          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1134          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1135          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1136          // create a menu item for this instrument  
1137          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++;  
1138      }      }
1139      instrument_menu->show();      instrument_name_connection.unblock();
1140      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1141    
1142      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1143          if (group->Name != "") {          if (group->Name != "") {
# Line 1247  void MainWindow::load_gig(gig::File* gig Line 1161  void MainWindow::load_gig(gig::File* gig
1161      file = gig;      file = gig;
1162    
1163      // select the first instrument      // select the first instrument
1164      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1165      tree_sel_ref->select(Gtk::TreePath("0"));  
1166        gig::Instrument* instrument = get_instrument();
1167        if (instrument) {
1168            instrumentProps.set_instrument(instrument);
1169        }
1170  }  }
1171    
1172  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
# Line 1282  void MainWindow::on_button_release(GdkEv Line 1200  void MainWindow::on_button_release(GdkEv
1200      }      }
1201  }  }
1202    
1203  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1204      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1205            const std::vector<Gtk::Widget*> children =
1206                instrument_menu->get_children();
1207            std::vector<Gtk::Widget*>::const_iterator it =
1208                find(children.begin(), children.end(), item);
1209            if (it != children.end()) {
1210                int index = it - children.begin();
1211                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1212    
1213                m_RegionChooser.set_instrument(file->GetInstrument(index));
1214            }
1215        }
1216  }  }
1217    
1218  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 1242  void MainWindow::on_sample_treeview_butt
1242      }      }
1243  }  }
1244    
1245    
1246    Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1247        const Glib::ustring& name, int position) {
1248    
1249        Gtk::RadioMenuItem::Group instrument_group;
1250        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1251        if (!children.empty()) {
1252            instrument_group =
1253                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1254        }
1255        Gtk::RadioMenuItem* item =
1256            new Gtk::RadioMenuItem(instrument_group, name);
1257        if (position < 0) {
1258            instrument_menu->append(*item);
1259        } else {
1260            instrument_menu->insert(*item, position);
1261        }
1262        item->show();
1263        item->signal_activate().connect(
1264            sigc::bind(
1265                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1266                item));
1267        return item;
1268    }
1269    
1270    void MainWindow::remove_instrument_from_menu(int index) {
1271        const std::vector<Gtk::Widget*> children =
1272            instrument_menu->get_children();
1273        Gtk::Widget* child = children[index];
1274        instrument_menu->remove(*child);
1275        delete child;
1276    }
1277    
1278    void MainWindow::add_instrument(gig::Instrument* instrument) {
1279        const char* name = instrument->pInfo->Name.c_str();
1280    
1281        // update instrument tree view
1282        instrument_name_connection.block();
1283        Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1284        Gtk::TreeModel::Row rowInstr = *iterInstr;
1285        rowInstr[m_Columns.m_col_name] = name;
1286        rowInstr[m_Columns.m_col_instr] = instrument;
1287        instrument_name_connection.unblock();
1288    
1289        add_instrument_to_menu(name);
1290    
1291        m_TreeView.get_selection()->select(iterInstr);
1292    
1293        file_changed();
1294    }
1295    
1296  void MainWindow::on_action_add_instrument() {  void MainWindow::on_action_add_instrument() {
1297      static int __instrument_indexer = 0;      static int __instrument_indexer = 0;
1298      if (!file) return;      if (!file) return;
# Line 1320  void MainWindow::on_action_add_instrumen Line 1300  void MainWindow::on_action_add_instrumen
1300      __instrument_indexer++;      __instrument_indexer++;
1301      instrument->pInfo->Name =      instrument->pInfo->Name =
1302          _("Unnamed Instrument ") + ToString(__instrument_indexer);          _("Unnamed Instrument ") + ToString(__instrument_indexer);
1303      // update instrument tree view  
1304      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      add_instrument(instrument);
1305      Gtk::TreeModel::Row rowInstr = *iterInstr;  }
1306      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();  
1307      rowInstr[m_Columns.m_col_instr] = instrument;  void MainWindow::on_action_duplicate_instrument() {
1308      file_changed();      if (!file) return;
1309    
1310        // retrieve the currently selected instrument
1311        // (being the original instrument to be duplicated)
1312        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1313        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1314        if (!itSelection) return;
1315        Gtk::TreeModel::Row row = *itSelection;
1316        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1317        if (!instrOrig) return;
1318    
1319        // duplicate the orginal instrument
1320        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1321        instrNew->pInfo->Name =
1322            instrOrig->pInfo->Name + " (" + _("Copy") + ")";
1323    
1324        add_instrument(instrNew);
1325  }  }
1326    
1327  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 1347  void MainWindow::on_action_remove_instru Line 1343  void MainWindow::on_action_remove_instru
1343          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1344          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1345          try {          try {
1346                Gtk::TreePath path(it);
1347                int index = path[0];
1348    
1349              // remove instrument from the gig file              // remove instrument from the gig file
1350              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1351              file_changed();              file_changed();
1352    
1353                remove_instrument_from_menu(index);
1354    
1355                // remove row from instruments tree view
1356                m_refTreeModel->erase(it);
1357    
1358    #if GTKMM_MAJOR_VERSION < 3
1359                // select another instrument (in gtk3 this is done
1360                // automatically)
1361                if (!m_refTreeModel->children().empty()) {
1362                    if (index == m_refTreeModel->children().size()) {
1363                        index--;
1364                    }
1365                    m_TreeView.get_selection()->select(
1366                        Gtk::TreePath(ToString(index)));
1367                }
1368    #endif
1369                instr = get_instrument();
1370                if (instr) {
1371                    instrumentProps.set_instrument(instr);
1372                } else {
1373                    instrumentProps.hide();
1374                }
1375          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1376              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1377              msg.run();              msg.run();
# Line 1405  void MainWindow::on_action_add_sample() Line 1425  void MainWindow::on_action_add_sample()
1425      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1426      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1427      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1428      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1429        // matches all file types supported by libsndfile
1430    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1431        Gtk::FileFilter soundfilter;
1432    #else
1433        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1434    #endif
1435      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1436          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1437          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1413  void MainWindow::on_action_add_sample() Line 1439  void MainWindow::on_action_add_sample()
1439          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1440          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1441      };      };
1442        const char* soundfiles = _("Sound Files");
1443        const char* allfiles = _("All Files");
1444    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1445      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1446          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1447      soundfilter.set_name(_("Sound Files"));      soundfilter.set_name(soundfiles);
1448      Gtk::FileFilter allpassfilter; // matches every file  
1449        // matches every file
1450        Gtk::FileFilter allpassfilter;
1451      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1452      allpassfilter.set_name(_("All Files"));      allpassfilter.set_name(allfiles);
1453    #else
1454        for (int i = 0; supportedFileTypes[i]; i++)
1455            soundfilter->add_pattern(supportedFileTypes[i]);
1456        soundfilter->set_name(soundfiles);
1457    
1458        // matches every file
1459        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1460        allpassfilter->add_pattern("*.*");
1461        allpassfilter->set_name(allfiles);
1462    #endif
1463      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1464      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1465      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 1427  void MainWindow::on_action_add_sample() Line 1468  void MainWindow::on_action_add_sample()
1468      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1469          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1470          Glib::ustring error_files;          Glib::ustring error_files;
1471          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1472          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1473               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1474              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1475              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1480  void MainWindow::on_action_add_sample() Line 1521  void MainWindow::on_action_add_sample()
1521                  {                  {
1522                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1523    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1524                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1525                          sample->Loops = 1;                          sample->Loops = 1;
1526    
# Line 1500  void MainWindow::on_action_add_sample() Line 1540  void MainWindow::on_action_add_sample()
1540                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1541                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1542                      }                      }
 #endif  
1543                  }                  }
1544    
1545                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1525  void MainWindow::on_action_add_sample() Line 1564  void MainWindow::on_action_add_sample()
1564                  sf_close(hFile);                  sf_close(hFile);
1565                  file_changed();                  file_changed();
1566              } 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)
1567                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1568                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1569              }              }
1570          }          }
1571          // 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
1572          if (error_files.size()) {          if (!error_files.empty()) {
1573              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;
1574              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1575              msg.run();              msg.run();
# Line 1543  void MainWindow::on_action_replace_all_s Line 1582  void MainWindow::on_action_replace_all_s
1582      if (!file) return;      if (!file) return;
1583      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1584                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1585      view::WrapLabel description(      const char* str =
1586          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1587            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
1588            "directory.\n\n"            "directory.\n\n"
# Line 1557  void MainWindow::on_action_replace_all_s Line 1596  void MainWindow::on_action_replace_all_s
1596            "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 "
1597            "extension, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
1598            "appropriate sample file could be found will be reported and left "            "appropriate sample file could be found will be reported and left "
1599            "untouched.\n")            "untouched.\n");
1600      );  #if GTKMM_MAJOR_VERSION < 3
1601        view::WrapLabel description(str);
1602    #else
1603        Gtk::Label description(str);
1604        description.set_line_wrap();
1605    #endif
1606      Gtk::HBox entryArea;      Gtk::HBox entryArea;
1607      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1608      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
1609      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
1610      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1579  void MainWindow::on_action_replace_all_s Line 1623  void MainWindow::on_action_replace_all_s
1623      {      {
1624          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1625          Glib::ustring error_files;          Glib::ustring error_files;
1626          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
1627          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
1628               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1629          {          {
# Line 1618  void MainWindow::on_action_replace_all_s Line 1662  void MainWindow::on_action_replace_all_s
1662              }              }
1663              catch (std::string what)              catch (std::string what)
1664              {              {
1665                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1666                      error_files += filename += " (" + what + ")";                      error_files += filename += " (" + what + ")";
1667              }              }
1668          }          }
1669          // 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
1670          if (error_files.size()) {          if (!error_files.empty()) {
1671              Glib::ustring txt =              Glib::ustring txt =
1672                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1673              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1833  void MainWindow::instrument_name_changed Line 1877  void MainWindow::instrument_name_changed
1877      if (!iter) return;      if (!iter) return;
1878      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
1879      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
1880    
1881        // change name in instrument menu
1882        int index = path[0];
1883        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1884        if (index < children.size()) {
1885    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
1886            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
1887    #else
1888            remove_instrument_from_menu(index);
1889            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
1890            item->set_active();
1891    #endif
1892        }
1893    
1894        // change name in gig
1895      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
1896      if (instrument && instrument->pInfo->Name != name.raw()) {      if (instrument && instrument->pInfo->Name != name.raw()) {
1897          instrument->pInfo->Name = name.raw();          instrument->pInfo->Name = name.raw();

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

  ViewVC Help
Powered by ViewVC