/[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 1714 by persson, Thu Mar 6 20:50:04 2008 UTC revision 2476 by schoenebeck, Mon Sep 16 13:20:46 2013 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006 - 2008 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 "global.h"  #include "wrapLabel.hh"
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
 #define ABOUT_DIALOG  
 #include <gtkmm/aboutdialog.h>  
36  #endif  #endif
37    
38  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #include "global.h"
39  namespace Glib {  #include "compat.h"
 Glib::ustring filename_display_basename(const std::string& filename)  
 {  
     gchar* gstr = g_path_get_basename(filename.c_str());  
     Glib::ustring str(gstr);  
     g_free(gstr);  
     return Glib::filename_to_utf8(str);  
 }  
 }  
 #endif  
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
# Line 54  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 98  MainWindow::MainWindow() : Line 60  MainWindow::MainWindow() :
60      add(m_VBox);      add(m_VBox);
61    
62      // Handle selection      // Handle selection
63      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
64          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
65    
66      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 129  MainWindow::MainWindow() : Line 90  MainWindow::MainWindow() :
90      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
91    
92    
93      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
94      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
95    
96    
97      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
# Line 167  MainWindow::MainWindow() : Line 128  MainWindow::MainWindow() :
128                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
129      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
130    
131      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
132        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
133    
134      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
135            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"), "ffaga");
136        toggle_action->set_active(true);
137        //FIXME: doesn't work, why?
138        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
139        actionGroup->add(toggle_action);
140    
141        toggle_action =
142            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
143        toggle_action->set_active(true);
144        //FIXME: doesn't work, why?
145        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
146        actionGroup->add(toggle_action);
147    
148        toggle_action =
149            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
150        toggle_action->set_active(true);
151        //FIXME: doesn't work, why?
152        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
153        actionGroup->add(toggle_action);
154    
155    
156        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
157        toggle_action =
158          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
159      toggle_action->set_active(true);      toggle_action->set_active(true);
160      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 178  MainWindow::MainWindow() : Line 164  MainWindow::MainWindow() :
164      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
165      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
166                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
167      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
168                       sigc::mem_fun(                       sigc::mem_fun(
169                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
170      actionGroup->add(      actionGroup->add(
171          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
172          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
173      );      );
174      actionGroup->add(      actionGroup->add(
175            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
176            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
177        );
178        actionGroup->add(
179          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
180          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
181      );      );
# Line 202  MainWindow::MainWindow() : Line 190  MainWindow::MainWindow() :
190          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
191      );      );
192      actionGroup->add(      actionGroup->add(
193          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
194          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
195      );      );
196      actionGroup->add(      actionGroup->add(
# Line 210  MainWindow::MainWindow() : Line 198  MainWindow::MainWindow() :
198          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
199      );      );
200      actionGroup->add(      actionGroup->add(
201          Gtk::Action::create("ReplaceAllSamplesInAllGroups", _("Replace All Samples In All Groups")),          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
202                                _("Replace All Samples in All Groups...")),
203          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
204      );      );
205    
# Line 232  MainWindow::MainWindow() : Line 221  MainWindow::MainWindow() :
221          "      <separator/>"          "      <separator/>"
222          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
223          "    </menu>"          "    </menu>"
224            "    <menu action='MenuEdit'>"
225            "      <menuitem action='CopySampleUnity'/>"
226            "      <menuitem action='CopySampleTune'/>"
227            "      <menuitem action='CopySampleLoop'/>"
228            "    </menu>"
229          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
230          "    </menu>"          "    </menu>"
231          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
232          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
233          "    </menu>"          "    </menu>"
 #ifdef ABOUT_DIALOG  
234          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
235          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
236          "    </menu>"          "    </menu>"
 #endif  
237          "  </menubar>"          "  </menubar>"
238          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
239          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
240          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
241            "    <menuitem action='DupInstrument'/>"
242          "    <separator/>"          "    <separator/>"
243          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
244          "  </popup>"          "  </popup>"
# Line 253  MainWindow::MainWindow() : Line 246  MainWindow::MainWindow() :
246          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
247          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
248          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
249          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
250          "    <separator/>"          "    <separator/>"
251          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
252          "  </popup>"          "  </popup>"
# Line 262  MainWindow::MainWindow() : Line 255  MainWindow::MainWindow() :
255    
256      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
257    
258        instrument_menu = static_cast<Gtk::MenuItem*>(
259            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
260    
261      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
262      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
263      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
# Line 270  MainWindow::MainWindow() : Line 266  MainWindow::MainWindow() :
266      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
267      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
268    
269        set_file_is_shared(false);
270    
271      // Status Bar:      // Status Bar:
272      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
273      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 284  MainWindow::MainWindow() : Line 282  MainWindow::MainWindow() :
282      // Create the Tree model:      // Create the Tree model:
283      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
284      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
285      m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
286          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
287      );      );
288    
# Line 306  MainWindow::MainWindow() : Line 304  MainWindow::MainWindow() :
304      );      );
305    
306      // 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
307      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
308      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
309      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
310      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
311          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 325  MainWindow::MainWindow() : Line 323  MainWindow::MainWindow() :
323          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
324      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
325          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
326      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
327          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
328      propDialog.signal_info_changed().connect(      propDialog.signal_changed().connect(
329          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
330    
331      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 372  MainWindow::MainWindow() : Line 370  MainWindow::MainWindow() :
370    
371      file = 0;      file = 0;
372      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
373    
374      show_all_children();      show_all_children();
375    
# Line 403  void MainWindow::region_changed() Line 400  void MainWindow::region_changed()
400  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
401  {  {
402      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
403      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
404            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
405      if (it) {      if (it) {
406          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
407          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 464  void MainWindow::dimreg_changed() Line 460  void MainWindow::dimreg_changed()
460    
461  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
462  {  {
463        // select item in instrument menu
464        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
465        if (it) {
466            Gtk::TreePath path(it);
467            int index = path[0];
468            const std::vector<Gtk::Widget*> children =
469                instrument_menu->get_children();
470            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
471        }
472    
473      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
474  }  }
475    
# Line 476  void loader_progress_callback(gig::progr Line 482  void loader_progress_callback(gig::progr
482  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
483  {  {
484      {      {
485          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
486          progress = fraction;          progress = fraction;
487      }      }
488      progress_dispatcher();      progress_dispatcher();
# Line 484  void Loader::progress_callback(float fra Line 490  void Loader::progress_callback(float fra
490    
491  void Loader::thread_function()  void Loader::thread_function()
492  {  {
493      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
494      printf("Start %s\n", filename);      printf("Start %s\n", filename);
495      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
496      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 498  void Loader::thread_function() Line 504  void Loader::thread_function()
504  }  }
505    
506  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
507      : thread(0), filename(filename)      : filename(filename), thread(0)
508  {  {
509  }  }
510    
511  void Loader::launch()  void Loader::launch()
512  {  {
513    #ifdef OLD_THREADS
514      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
515    #else
516        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
517    #endif
518      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
519  }  }
520    
# Line 512  float Loader::get_progress() Line 522  float Loader::get_progress()
522  {  {
523      float res;      float res;
524      {      {
525          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
526          res = progress;          res = progress;
527      }      }
528      return res;      return res;
# Line 538  LoadDialog::LoadDialog(const Glib::ustri Line 548  LoadDialog::LoadDialog(const Glib::ustri
548  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
549  // 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.
550  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();  
551      // forget all samples that ought to be imported      // forget all samples that ought to be imported
552      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
553      // clear the samples and instruments tree views      // clear the samples and instruments tree views
554      m_refTreeModel->clear();      m_refTreeModel->clear();
555      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
556        // remove all entries from "Instrument" menu
557        while (!instrument_menu->get_children().empty()) {
558            remove_instrument_from_menu(0);
559        }
560      // free libgig's gig::File instance      // free libgig's gig::File instance
561      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
562      file = NULL;      file = NULL;
# Line 569  void MainWindow::on_action_file_new() Line 575  void MainWindow::on_action_file_new()
575      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
576      // already add one new instrument by default      // already add one new instrument by default
577      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
578      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
579      // update GUI with that new gig::File      // update GUI with that new gig::File
580      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
581  }  }
# Line 580  bool MainWindow::close_confirmation_dial Line 586  bool MainWindow::close_confirmation_dial
586                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
587      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
588      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
589      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  
590      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
591      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
592      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 596  bool MainWindow::close_confirmation_dial Line 600  bool MainWindow::close_confirmation_dial
600  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
601      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
602      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  
603      dialog.set_secondary_text(      dialog.set_secondary_text(
604          _("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 "
605            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
606            "load it.")            "load it."));
    );  
 #endif  
607      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
608      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
609      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 621  void MainWindow::on_action_file_open() Line 622  void MainWindow::on_action_file_open()
622      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
623      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
624      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
625    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
626      Gtk::FileFilter filter;      Gtk::FileFilter filter;
627      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
628    #else
629        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
630        filter->add_pattern("*.gig");
631    #endif
632      dialog.set_filter(filter);      dialog.set_filter(filter);
633      if (current_dir != "") {      if (current_gig_dir != "") {
634          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
635      }      }
636      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
637          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
638          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
639          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
640          load_file(filename.c_str());          load_file(filename.c_str());
641          current_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
642      }      }
643  }  }
644    
645  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
646  {  {
647      __clear();      __clear();
648      load_dialog = new LoadDialog("Loading...", *this);      load_dialog = new LoadDialog(_("Loading..."), *this);
649      load_dialog->show_all();      load_dialog->show_all();
650      loader = new Loader(strdup(name));      loader = new Loader(strdup(name));
651      loader->signal_progress().connect(      loader->signal_progress().connect(
# Line 672  void MainWindow::on_loader_progress() Line 678  void MainWindow::on_loader_progress()
678  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
679  {  {
680      printf("Loader finished!\n");      printf("Loader finished!\n");
681      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
682      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
683      load_dialog->hide();      load_dialog->hide();
684  }  }
# Line 744  bool MainWindow::file_save_as() Line 750  bool MainWindow::file_save_as()
750      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
751      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
752      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  
753      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
754      // TODO: an overwrite dialog for gtkmm < 2.8  
755  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
756      Gtk::FileFilter filter;      Gtk::FileFilter filter;
757      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
758    #else
759        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
760        filter->add_pattern("*.gig");
761    #endif
762      dialog.set_filter(filter);      dialog.set_filter(filter);
763    
764      // set initial dir and filename of the Save As dialog      // set initial dir and filename of the Save As dialog
# Line 758  bool MainWindow::file_save_as() Line 766  bool MainWindow::file_save_as()
766      {      {
767          std::string basename = Glib::path_get_basename(filename);          std::string basename = Glib::path_get_basename(filename);
768          std::string dir = Glib::path_get_dirname(filename);          std::string dir = Glib::path_get_dirname(filename);
769          basename = std::string("copy_of_") + basename;          basename = std::string(_("copy_of_")) + basename;
770          Glib::ustring copyFileName = Glib::build_filename(dir, basename);          Glib::ustring copyFileName = Glib::build_filename(dir, basename);
771          if (Glib::path_is_absolute(filename)) {          if (Glib::path_is_absolute(filename)) {
772              dialog.set_filename(copyFileName);              dialog.set_filename(copyFileName);
773          } else {          } else {
774              if (current_dir != "") dialog.set_current_folder(current_dir);              if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
775          }          }
776          dialog.set_current_name(Glib::filename_display_basename(copyFileName));          dialog.set_current_name(Glib::filename_display_basename(copyFileName));
777      }      }
# Line 773  bool MainWindow::file_save_as() Line 781  bool MainWindow::file_save_as()
781      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
782      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));
783      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
784      warningIcon.show();  #if GTKMM_MAJOR_VERSION < 3
785        view::WrapLabel description;
786    #else
787      Gtk::Label description;      Gtk::Label description;
788        description.set_line_wrap();
789    #endif
790      description.set_markup(      description.set_markup(
791          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
792            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 783  bool MainWindow::file_save_as() Line 795  bool MainWindow::file_save_as()
795            "<span style=\"italic\">\"Save As...\"</span> for writing to the "            "<span style=\"italic\">\"Save As...\"</span> for writing to the "
796            "same .gig file will end up in corrupted sample wave data!\n")            "same .gig file will end up in corrupted sample wave data!\n")
797      );      );
798      description.set_line_wrap(true);      descriptionArea.pack_start(description);
     descriptionArea.pack_start(description, Gtk::PACK_SHRINK);  
     description.show();  
799      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
800      descriptionArea.show();      descriptionArea.show_all();
801    
802      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
803          file_structure_to_be_changed_signal.emit(this->file);          file_structure_to_be_changed_signal.emit(this->file);
# Line 799  bool MainWindow::file_save_as() Line 809  bool MainWindow::file_save_as()
809              printf("filename=%s\n", filename.c_str());              printf("filename=%s\n", filename.c_str());
810              file->Save(filename);              file->Save(filename);
811              this->filename = filename;              this->filename = filename;
812              current_dir = Glib::path_get_dirname(filename);              current_gig_dir = Glib::path_get_dirname(filename);
813              set_title(Glib::filename_display_basename(filename));              set_title(Glib::filename_display_basename(filename));
814              file_has_name = true;              file_has_name = true;
815              file_is_changed = false;              file_is_changed = false;
# Line 828  void MainWindow::__import_queued_samples Line 838  void MainWindow::__import_queued_samples
838          SF_INFO info;          SF_INFO info;
839          info.format = 0;          info.format = 0;
840          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
841            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
842          try {          try {
843              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
844              // determine sample's bit depth              // determine sample's bit depth
845              int bitdepth;              int bitdepth;
846              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 846  void MainWindow::__import_queued_samples Line 857  void MainWindow::__import_queued_samples
857                      break;                      break;
858                  default:                  default:
859                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
860                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
861              }              }
862    
863              const int bufsize = 10000;              const int bufsize = 10000;
# Line 888  void MainWindow::__import_queued_samples Line 899  void MainWindow::__import_queued_samples
899              }              }
900              // cleanup              // cleanup
901              sf_close(hFile);              sf_close(hFile);
902                // let the sampler re-cache the sample if needed
903                sample_changed_signal.emit(iter->gig_sample);
904              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
905              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
906              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 895  void MainWindow::__import_queued_samples Line 908  void MainWindow::__import_queued_samples
908              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
909          } catch (std::string what) {          } catch (std::string what) {
910              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
911              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
912              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
913              ++iter;              ++iter;
914          }          }
915      }      }
916      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
917      if (error_files.size()) {      if (!error_files.empty()) {
918          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;
919          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
920          msg.run();          msg.run();
# Line 916  void MainWindow::on_action_file_properti Line 929  void MainWindow::on_action_file_properti
929    
930  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
931  {  {
 #ifdef ABOUT_DIALOG  
932      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
933    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
934        dialog.set_program_name("Gigedit");
935    #else
936        dialog.set_name("Gigedit");
937    #endif
938      dialog.set_version(VERSION);      dialog.set_version(VERSION);
939      dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");
940      dialog.set_comments(      const std::string sComment =
941          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
942          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
943          "Please notice that this is still a very young instrument editor. "          _(
944          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
945          "this application.\n"              "\n"
946          "\n"              "Please notice that this is still a very young instrument editor. "
947          "Please report bugs to: http://bugs.linuxsampler.org"              "So better backup your Gigasampler files before editing them with "
948      );              "this application.\n"
949                "\n"
950                "Please report bugs to: http://bugs.linuxsampler.org"
951            );
952        dialog.set_comments(sComment.c_str());
953      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
954      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
955      dialog.run();      dialog.run();
 #endif  
956  }  }
957    
958  PropDialog::PropDialog()  PropDialog::PropDialog()
959      : table(2,1),      : eName(_("Name")),
960        eName("Name"),        eCreationDate(_("Creation date")),
961        eCreationDate("Creation date"),        eComments(_("Comments")),
962        eComments("Comments"),        eProduct(_("Product")),
963        eProduct("Product"),        eCopyright(_("Copyright")),
964        eCopyright("Copyright"),        eArtists(_("Artists")),
965        eArtists("Artists"),        eGenre(_("Genre")),
966        eGenre("Genre"),        eKeywords(_("Keywords")),
967        eKeywords("Keywords"),        eEngineer(_("Engineer")),
968        eEngineer("Engineer"),        eTechnician(_("Technician")),
969        eTechnician("Technician"),        eSoftware(_("Software")),
970        eSoftware("Software"),        eMedium(_("Medium")),
971        eMedium("Medium"),        eSource(_("Source")),
972        eSource("Source"),        eSourceForm(_("Source form")),
973        eSourceForm("Source form"),        eCommissioned(_("Commissioned")),
974        eCommissioned("Commissioned"),        eSubject(_("Subject")),
       eSubject("Subject"),  
975        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
976        update_model(0)        table(2, 1)
977  {  {
978      set_title("File Properties");      set_title(_("File Properties"));
979      eName.set_width_chars(50);      eName.set_width_chars(50);
980    
981      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
# Line 1002  PropDialog::PropDialog() Line 1021  PropDialog::PropDialog()
1021      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1022      buttonBox.show();      buttonBox.show();
1023      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1024      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1025      quitButton.grab_focus();      quitButton.grab_focus();
1026      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1027          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
# Line 1014  PropDialog::PropDialog() Line 1033  PropDialog::PropDialog()
1033    
1034  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1035  {  {
1036      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--;  
1037  }  }
1038    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1039    
1040  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_Name(const gig::String& name)
1041  {  {
1042      instrument->IsDrum = value;      m->pInfo->Name = name;
1043  }  }
1044    
1045  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1046  {  {
1047      instrument->MIDIBank = value;      update_model++;
1048        eName.set_value(m->pInfo->Name);
1049        update_model--;
1050  }  }
1051    
1052  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1053  {  {
1054      instrument->MIDIProgram = value;      m->IsDrum = value;
1055  }  }
1056    
1057  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1058  {  {
1059      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1060  }  }
1061    
1062  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1063  {  {
1064      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1065  }  }
1066    
1067  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1068      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1069        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1070        eName("Name"),      eName(_("Name")),
1071        eIsDrum("Is drum"),      eIsDrum(_("Is drum")),
1072        eMIDIBank("MIDI bank", 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1073        eMIDIProgram("MIDI program"),      eMIDIProgram(_("MIDI program")),
1074        eAttenuation("Attenuation", 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1075        eGainPlus6("Gain +6dB", eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1076        eEffectSend("Effect send", 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1077        eFineTune("Fine tune", -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1078        ePitchbendRange("Pitchbend range", 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1079        ePianoReleaseMode("Piano release mode"),      ePianoReleaseMode(_("Piano release mode")),
1080        eDimensionKeyRangeLow("Keyswitching range low"),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1081        eDimensionKeyRangeHigh("Keyswitching range high"),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1082  {  {
1083      set_title("Instrument Properties");      set_title(_("Instrument Properties"));
1084    
1085      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
1086          _("start of the keyboard area which should switch the "          _("start of the keyboard area which should switch the "
# Line 1099  InstrumentProps::InstrumentProps() Line 1091  InstrumentProps::InstrumentProps()
1091            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1092      );      );
1093    
1094        connect(eName, &InstrumentProps::set_Name);
1095      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1096      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1097      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1108  InstrumentProps::InstrumentProps() Line 1101  InstrumentProps::InstrumentProps()
1101      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1102      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1103      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1104      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1105              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1106      connect(eDimensionKeyRangeHigh,  
1107              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1108    
1109      table.set_col_spacings(5);      table.set_col_spacings(5);
1110    
# Line 1137  InstrumentProps::InstrumentProps() Line 1130  InstrumentProps::InstrumentProps()
1130      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1131      buttonBox.show();      buttonBox.show();
1132      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1133      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1134      quitButton.grab_focus();      quitButton.grab_focus();
1135    
1136      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1150  InstrumentProps::InstrumentProps() Line 1143  InstrumentProps::InstrumentProps()
1143    
1144  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1145  {  {
1146      this->instrument = instrument;      update(instrument);
1147    
1148      update_model++;      update_model++;
1149      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1150      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1151      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1152      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);  
1153      update_model--;      update_model--;
1154  }  }
1155    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1156    
1157  void MainWindow::file_changed()  void MainWindow::file_changed()
1158  {  {
# Line 1193  void MainWindow::load_gig(gig::File* gig Line 1174  void MainWindow::load_gig(gig::File* gig
1174    
1175      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1176    
1177      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;  
1178      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1179           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1180            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1181    
1182          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1183          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1184          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1185          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1186          // create a menu item for this instrument  
1187          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++;  
1188      }      }
1189      instrument_menu->show();      instrument_name_connection.unblock();
1190      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1191    
1192      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1193          if (group->Name != "") {          if (group->Name != "") {
1194              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1195              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1196              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1197              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1198              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1199              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1231  void MainWindow::load_gig(gig::File* gig Line 1201  void MainWindow::load_gig(gig::File* gig
1201                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1202                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1203                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1204                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1205                        gig_to_utf8(sample->pInfo->Name);
1206                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1207                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1208              }              }
# Line 1241  void MainWindow::load_gig(gig::File* gig Line 1212  void MainWindow::load_gig(gig::File* gig
1212      file = gig;      file = gig;
1213    
1214      // select the first instrument      // select the first instrument
1215      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1216      tree_sel_ref->select(Gtk::TreePath("0"));  
1217        instr_props_set_instrument();
1218  }  }
1219    
1220  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1221  {  {
1222      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1223      if (instrument)  
1224      {      Gtk::TreeModel::const_iterator it =
1225            m_TreeView.get_selection()->get_selected();
1226        if (it) {
1227            Gtk::TreeModel::Row row = *it;
1228            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1229    
1230          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1231    
1232            // make sure instrument tree is updated when user changes the
1233            // instrument name in instrument properties window
1234            instrumentProps.signal_name_changed().connect(
1235                sigc::bind(
1236                    sigc::mem_fun(*this,
1237                                  &MainWindow::instr_name_changed_by_instr_props),
1238                    it));
1239        } else {
1240            instrumentProps.hide();
1241        }
1242        return it;
1243    }
1244    
1245    void MainWindow::show_instr_props()
1246    {
1247        if (instr_props_set_instrument()) {
1248          instrumentProps.show();          instrumentProps.show();
1249          instrumentProps.deiconify();          instrumentProps.deiconify();
1250      }      }
1251  }  }
1252    
1253    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1254    {
1255        Gtk::TreeModel::Row row = *it;
1256        Glib::ustring name = row[m_Columns.m_col_name];
1257    
1258        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1259        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1260        if (gigname != name) {
1261            row[m_Columns.m_col_name] = gigname;
1262        }
1263    }
1264    
1265  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1266      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1267          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1267  void MainWindow::on_action_view_status_b Line 1273  void MainWindow::on_action_view_status_b
1273      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1274  }  }
1275    
1276    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1277        Gtk::CheckMenuItem* item =
1278            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1279        if (!item) {
1280            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1281            return true;
1282        }
1283        return item->get_active();
1284    }
1285    
1286    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1287        Gtk::CheckMenuItem* item =
1288            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1289        if (!item) {
1290            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1291            return true;
1292        }
1293        return item->get_active();
1294    }
1295    
1296    bool MainWindow::is_copy_samples_loop_enabled() const {
1297        Gtk::CheckMenuItem* item =
1298            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1299        if (!item) {
1300            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1301            return true;
1302        }
1303        return item->get_active();
1304    }
1305    
1306  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1307  {  {
1308      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
# Line 1276  void MainWindow::on_button_release(GdkEv Line 1312  void MainWindow::on_button_release(GdkEv
1312      }      }
1313  }  }
1314    
1315  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1316      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1317            const std::vector<Gtk::Widget*> children =
1318                instrument_menu->get_children();
1319            std::vector<Gtk::Widget*>::const_iterator it =
1320                find(children.begin(), children.end(), item);
1321            if (it != children.end()) {
1322                int index = it - children.begin();
1323                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1324    
1325                m_RegionChooser.set_instrument(file->GetInstrument(index));
1326            }
1327        }
1328  }  }
1329    
1330  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1307  void MainWindow::on_sample_treeview_butt Line 1354  void MainWindow::on_sample_treeview_butt
1354      }      }
1355  }  }
1356    
1357  void MainWindow::on_action_add_instrument() {  
1358      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1359      if (!file) return;      const Glib::ustring& name, int position) {
1360      gig::Instrument* instrument = file->AddInstrument();  
1361      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1362      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1363          "Unnamed Instrument " + ToString(__instrument_indexer);      if (!children.empty()) {
1364            instrument_group =
1365                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1366        }
1367        Gtk::RadioMenuItem* item =
1368            new Gtk::RadioMenuItem(instrument_group, name);
1369        if (position < 0) {
1370            instrument_menu->append(*item);
1371        } else {
1372            instrument_menu->insert(*item, position);
1373        }
1374        item->show();
1375        item->signal_activate().connect(
1376            sigc::bind(
1377                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1378                item));
1379        return item;
1380    }
1381    
1382    void MainWindow::remove_instrument_from_menu(int index) {
1383        const std::vector<Gtk::Widget*> children =
1384            instrument_menu->get_children();
1385        Gtk::Widget* child = children[index];
1386        instrument_menu->remove(*child);
1387        delete child;
1388    }
1389    
1390    void MainWindow::add_instrument(gig::Instrument* instrument) {
1391        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1392    
1393      // update instrument tree view      // update instrument tree view
1394        instrument_name_connection.block();
1395      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1396      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1397      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1398      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1399        instrument_name_connection.unblock();
1400    
1401        add_instrument_to_menu(name);
1402    
1403        m_TreeView.get_selection()->select(iterInstr);
1404    
1405      file_changed();      file_changed();
1406  }  }
1407    
1408    void MainWindow::on_action_add_instrument() {
1409        static int __instrument_indexer = 0;
1410        if (!file) return;
1411        gig::Instrument* instrument = file->AddInstrument();
1412        __instrument_indexer++;
1413        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1414                                                ToString(__instrument_indexer));
1415    
1416        add_instrument(instrument);
1417    }
1418    
1419    void MainWindow::on_action_duplicate_instrument() {
1420        if (!file) return;
1421    
1422        // retrieve the currently selected instrument
1423        // (being the original instrument to be duplicated)
1424        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1425        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1426        if (!itSelection) return;
1427        Gtk::TreeModel::Row row = *itSelection;
1428        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1429        if (!instrOrig) return;
1430    
1431        // duplicate the orginal instrument
1432        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1433        instrNew->pInfo->Name =
1434            instrOrig->pInfo->Name +
1435            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1436    
1437        add_instrument(instrNew);
1438    }
1439    
1440  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1441      if (!file) return;      if (!file) return;
1442      if (file_is_shared) {      if (file_is_shared) {
# Line 1341  void MainWindow::on_action_remove_instru Line 1456  void MainWindow::on_action_remove_instru
1456          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1457          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1458          try {          try {
1459                Gtk::TreePath path(it);
1460                int index = path[0];
1461    
1462              // remove instrument from the gig file              // remove instrument from the gig file
1463              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1464              file_changed();              file_changed();
1465    
1466                remove_instrument_from_menu(index);
1467    
1468                // remove row from instruments tree view
1469                m_refTreeModel->erase(it);
1470    
1471    #if GTKMM_MAJOR_VERSION < 3
1472                // select another instrument (in gtk3 this is done
1473                // automatically)
1474                if (!m_refTreeModel->children().empty()) {
1475                    if (index == m_refTreeModel->children().size()) {
1476                        index--;
1477                    }
1478                    m_TreeView.get_selection()->select(
1479                        Gtk::TreePath(ToString(index)));
1480                }
1481    #endif
1482                instr_props_set_instrument();
1483          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1484              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1485              msg.run();              msg.run();
# Line 1356  void MainWindow::on_action_remove_instru Line 1490  void MainWindow::on_action_remove_instru
1490  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
1491      //TODO: show a dialog where the selected sample's properties can be edited      //TODO: show a dialog where the selected sample's properties can be edited
1492      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
1493          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
1494      );      );
1495      msg.run();      msg.run();
1496  }  }
# Line 1365  void MainWindow::on_action_add_group() { Line 1499  void MainWindow::on_action_add_group() {
1499      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1500      if (!file) return;      if (!file) return;
1501      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1502      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
1503      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1504      __sample_indexer++;      __sample_indexer++;
1505      // update sample tree view      // update sample tree view
1506      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1507      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1508      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1509      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1510      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1511      file_changed();      file_changed();
# Line 1399  void MainWindow::on_action_add_sample() Line 1533  void MainWindow::on_action_add_sample()
1533      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1534      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1535      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1536      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1537        // matches all file types supported by libsndfile
1538    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1539        Gtk::FileFilter soundfilter;
1540    #else
1541        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1542    #endif
1543      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1544          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1545          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1407  void MainWindow::on_action_add_sample() Line 1547  void MainWindow::on_action_add_sample()
1547          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1548          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1549      };      };
1550        const char* soundfiles = _("Sound Files");
1551        const char* allfiles = _("All Files");
1552    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1553      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1554          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1555      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
1556      Gtk::FileFilter allpassfilter; // matches every file  
1557        // matches every file
1558        Gtk::FileFilter allpassfilter;
1559      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1560      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
1561    #else
1562        for (int i = 0; supportedFileTypes[i]; i++)
1563            soundfilter->add_pattern(supportedFileTypes[i]);
1564        soundfilter->set_name(soundfiles);
1565    
1566        // matches every file
1567        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1568        allpassfilter->add_pattern("*.*");
1569        allpassfilter->set_name(allfiles);
1570    #endif
1571      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1572      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1573        if (current_sample_dir != "") {
1574            dialog.set_current_folder(current_sample_dir);
1575        }
1576      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1577            current_sample_dir = dialog.get_current_folder();
1578          Glib::ustring error_files;          Glib::ustring error_files;
1579          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1580          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1581               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1582              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1583              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1426  void MainWindow::on_action_add_sample() Line 1585  void MainWindow::on_action_add_sample()
1585              info.format = 0;              info.format = 0;
1586              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1587              try {              try {
1588                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
1589                  int bitdepth;                  int bitdepth;
1590                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
1591                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1442  void MainWindow::on_action_add_sample() Line 1601  void MainWindow::on_action_add_sample()
1601                          break;                          break;
1602                      default:                      default:
1603                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
1604                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
1605                  }                  }
1606                  // add a new sample to the .gig file                  // add a new sample to the .gig file
1607                  gig::Sample* sample = file->AddSample();                  gig::Sample* sample = file->AddSample();
# Line 1455  void MainWindow::on_action_add_sample() Line 1614  void MainWindow::on_action_add_sample()
1614                          break;                          break;
1615                      }                      }
1616                  }                  }
1617                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1618                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1619                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1620                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1469  void MainWindow::on_action_add_sample() Line 1628  void MainWindow::on_action_add_sample()
1628                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1629                  {                  {
1630                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1631                        sample->FineTune      = instrument.detune;
1632    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1633                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1634                          sample->Loops = 1;                          sample->Loops = 1;
1635    
# Line 1490  void MainWindow::on_action_add_sample() Line 1649  void MainWindow::on_action_add_sample()
1649                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1650                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1651                      }                      }
 #endif  
1652                  }                  }
1653    
1654                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1508  void MainWindow::on_action_add_sample() Line 1666  void MainWindow::on_action_add_sample()
1666                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1667                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1668                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1669                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1670                        gig_to_utf8(sample->pInfo->Name);
1671                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1672                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1673                  // close sound file                  // close sound file
1674                  sf_close(hFile);                  sf_close(hFile);
1675                  file_changed();                  file_changed();
1676              } 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)
1677                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1678                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1679              }              }
1680          }          }
1681          // 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
1682          if (error_files.size()) {          if (!error_files.empty()) {
1683              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;
1684              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1685              msg.run();              msg.run();
# Line 1533  void MainWindow::on_action_replace_all_s Line 1692  void MainWindow::on_action_replace_all_s
1692      if (!file) return;      if (!file) return;
1693      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1694                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1695      Gtk::Label description(      const char* str =
1696          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1697            "in the current gig file by samples located in the directory chosen "            "in the current gig file by samples located in the chosen "
1698            "by you above.\n\n"            "directory.\n\n"
1699            "It works like this: For each sample in the gig file it tries to "            "It works like this: For each sample in the gig file, it tries to "
1700            "find a sample file in the selected directory with the same name as "            "find a sample file in the selected directory with the same name as "
1701            "the sample in the gig file. Optionally you can add a filename "            "the sample in the gig file. Optionally, you can add a filename "
1702            "postfix below, which will be added to the filename expected to be "            "extension below, which will be added to the filename expected to be "
1703            "found. That is, assume you have a gig file with a sample called "            "found. That is, assume you have a gig file with a sample called "
1704            "'Snare', if you enter '.wav' below (like it's done by default), it "            "'Snare', if you enter '.wav' below (like it's done by default), it "
1705            "assumes to find a sample file called 'Snare.wav' and will replace "            "expects to find a sample file called 'Snare.wav' and will replace "
1706            "the sample in the gig file accordingly. If you don't need such a "            "the sample in the gig file accordingly. If you don't need an "
1707            "postfix, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
1708            "appropriate sample file could be found, will be reported and left "            "appropriate sample file could be found will be reported and left "
1709            "untouched.\n\n")            "untouched.\n");
1710      );  #if GTKMM_MAJOR_VERSION < 3
1711      description.set_line_wrap(true);      view::WrapLabel description(str);
1712    #else
1713        Gtk::Label description(str);
1714        description.set_line_wrap();
1715    #endif
1716      Gtk::HBox entryArea;      Gtk::HBox entryArea;
1717      Gtk::Label entryLabel( _("Add Filename Extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1718      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
1719      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
1720      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1559  void MainWindow::on_action_replace_all_s Line 1722  void MainWindow::on_action_replace_all_s
1722      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
1723      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
1724      description.show();      description.show();
1725      entryLabel.show();      entryArea.show_all();
     postfixEntryBox.show();  
     entryArea.show();  
1726      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1727      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
1728      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
1729      // fix label width (because Gtk by design doesn't      if (current_sample_dir != "") {
1730      // know anything about the parent's size)          dialog.set_current_folder(current_sample_dir);
1731  #if 0 //FIXME: doesn't work      }
     int dialogW, dialogH, labelW, labelH;  
     dialog.get_size_request(dialogW, dialogH);  
     description.get_size_request(labelW, labelH);  
     std::cout << "dialog(" << dialogW << "," << dialogH << ")\nlabel(" << labelW << "," << labelH << ")\n" << std::flush;  
     description.set_size_request(dialogW, labelH);  
 #endif  
1732      if (dialog.run() == Gtk::RESPONSE_OK)      if (dialog.run() == Gtk::RESPONSE_OK)
1733      {      {
1734            current_sample_dir = dialog.get_current_folder();
1735          Glib::ustring error_files;          Glib::ustring error_files;
1736          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
1737          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
1738               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1739          {          {
1740              std::string filename =              std::string filename =
1741                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1742                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1743                                             postfixEntryBox.get_text());
1744              SF_INFO info;              SF_INFO info;
1745              info.format = 0;              info.format = 0;
1746              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
1747              try              try
1748              {              {
1749                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
1750                  int bitdepth;                  int bitdepth;
1751                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
1752                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1605  void MainWindow::on_action_replace_all_s Line 1762  void MainWindow::on_action_replace_all_s
1762                          break;                          break;
1763                      default:                      default:
1764                          sf_close(hFile);                          sf_close(hFile);
1765                          throw std::string("format not supported");                          throw std::string(_("format not supported"));
1766                  }                  }
1767                  SampleImportItem sched_item;                  SampleImportItem sched_item;
1768                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
# Line 1616  void MainWindow::on_action_replace_all_s Line 1773  void MainWindow::on_action_replace_all_s
1773              }              }
1774              catch (std::string what)              catch (std::string what)
1775              {              {
1776                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1777                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1778                        " (" + what + ")";
1779              }              }
1780          }          }
1781          // 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
1782          if (error_files.size()) {          if (!error_files.empty()) {
1783              Glib::ustring txt =              Glib::ustring txt =
1784                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1785              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1642  void MainWindow::on_action_remove_sample Line 1800  void MainWindow::on_action_remove_sample
1800          try {          try {
1801              // remove group or sample from the gig file              // remove group or sample from the gig file
1802              if (group) {              if (group) {
1803                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1804                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1805                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1806                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1768  void MainWindow::on_sample_label_drop_dr Line 1926  void MainWindow::on_sample_label_drop_dr
1926              channels_changed = true;              channels_changed = true;
1927              region_changed();              region_changed();
1928          }          }
1929          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
1930                sample,
1931                is_copy_samples_unity_note_enabled(),
1932                is_copy_samples_fine_tune_enabled(),
1933                is_copy_samples_loop_enabled()
1934            );
1935    
1936          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
1937              // add samplechannel dimension              // add samplechannel dimension
# Line 1811  void MainWindow::sample_name_changed(con Line 1974  void MainWindow::sample_name_changed(con
1974      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
1975      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
1976      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1977        gig::String gigname(gig_from_utf8(name));
1978      if (group) {      if (group) {
1979          if (group->Name != name) {          if (group->Name != gigname) {
1980              group->Name = name;              group->Name = gigname;
1981              printf("group name changed\n");              printf("group name changed\n");
1982              file_changed();              file_changed();
1983          }          }
1984      } else if (sample) {      } else if (sample) {
1985          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
1986              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
1987              printf("sample name changed\n");              printf("sample name changed\n");
1988              file_changed();              file_changed();
1989          }          }
# Line 1831  void MainWindow::instrument_name_changed Line 1995  void MainWindow::instrument_name_changed
1995      if (!iter) return;      if (!iter) return;
1996      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
1997      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
1998    
1999        // change name in instrument menu
2000        int index = path[0];
2001        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2002        if (index < children.size()) {
2003    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2004            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2005    #else
2006            remove_instrument_from_menu(index);
2007            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2008            item->set_active();
2009    #endif
2010        }
2011    
2012        // change name in gig
2013      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2014      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2015          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2016            instrument->pInfo->Name = gigname;
2017    
2018            // change name in the instrument properties window
2019            if (instrumentProps.get_instrument() == instrument) {
2020                instrumentProps.update_name();
2021            }
2022    
2023          file_changed();          file_changed();
2024      }      }
2025  }  }
# Line 1878  sigc::signal<void, gig::Region*>& MainWi Line 2064  sigc::signal<void, gig::Region*>& MainWi
2064      return region_changed_signal;      return region_changed_signal;
2065  }  }
2066    
2067    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2068        return sample_changed_signal;
2069    }
2070    
2071  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
2072      return sample_ref_changed_signal;      return sample_ref_changed_signal;
2073  }  }

Legend:
Removed from v.1714  
changed lines
  Added in v.2476

  ViewVC Help
Powered by ViewVC