/[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 1725 by persson, Sat Apr 26 08:52:15 2008 UTC revision 2560 by schoenebeck, Sun May 18 18:55:29 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006 - 2008 Andreas Persson   * Copyright (C) 2006-2014 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmm/convert.h>
24    #include <glibmm/dispatcher.h>
25    #include <glibmm/miscutils.h>
26    #include <glibmm/stringutils.h>
27    #include <gtkmm/aboutdialog.h>
28  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
29  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34    #if GTKMM_MAJOR_VERSION < 3
35  #include "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>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46    #include "Settings.h"
47    #include "CombineInstrumentsDialog.h"
48  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
49  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
50    
 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++;  
 }  
51    
52  MainWindow::MainWindow() :  MainWindow::MainWindow() :
53      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
# Line 98  MainWindow::MainWindow() : Line 62  MainWindow::MainWindow() :
62      add(m_VBox);      add(m_VBox);
63    
64      // Handle selection      // Handle selection
65      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
66          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
67    
68      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 128  MainWindow::MainWindow() : Line 91  MainWindow::MainWindow() :
91      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
92      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
93    
94        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
95        dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
96        dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
97        dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
98    
99      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
100      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
101    
102    
103      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
# Line 162  MainWindow::MainWindow() : Line 129  MainWindow::MainWindow() :
129                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
130                       sigc::mem_fun(                       sigc::mem_fun(
131                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
132        actionGroup->add(Gtk::Action::create("MidiRules",
133                                             _("_Midi Rules")),
134                         sigc::mem_fun(
135                             *this, &MainWindow::show_midi_rules));
136      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
137                       sigc::mem_fun(                       sigc::mem_fun(
138                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
139      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
140    
141      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
142        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
143    
144      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
145            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
146        toggle_action->set_active(true);
147        actionGroup->add(toggle_action);
148    
149        toggle_action =
150            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
151        toggle_action->set_active(true);
152        actionGroup->add(toggle_action);
153    
154        toggle_action =
155            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
156        toggle_action->set_active(true);
157        actionGroup->add(toggle_action);
158    
159    
160        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
161        toggle_action =
162          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
163      toggle_action->set_active(true);      toggle_action->set_active(true);
164      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 178  MainWindow::MainWindow() : Line 168  MainWindow::MainWindow() :
168      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
169      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
170                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
171      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
172                       sigc::mem_fun(                       sigc::mem_fun(
173                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
174      actionGroup->add(      actionGroup->add(
175          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
176          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
177      );      );
178      actionGroup->add(      actionGroup->add(
179            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
180            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
181        );
182        actionGroup->add(
183          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
184          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
185      );      );
186    
187    
188        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
189        
190        toggle_action =
191            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
192        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
193        actionGroup->add(
194            toggle_action,
195            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
196        );
197    
198    
199        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
200    
201        actionGroup->add(
202            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
203            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
204        );
205    
206        actionGroup->add(
207            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
208            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
209        );
210    
211    
212      // sample right-click popup actions      // sample right-click popup actions
213      actionGroup->add(      actionGroup->add(
214          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 202  MainWindow::MainWindow() : Line 219  MainWindow::MainWindow() :
219          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
220      );      );
221      actionGroup->add(      actionGroup->add(
222          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
223          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
224      );      );
225      actionGroup->add(      actionGroup->add(
# Line 210  MainWindow::MainWindow() : Line 227  MainWindow::MainWindow() :
227          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
228      );      );
229      actionGroup->add(      actionGroup->add(
230          Gtk::Action::create("ReplaceAllSamplesInAllGroups", _("Replace All Samples In All Groups")),          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
231                                _("Replace All Samples in All Groups...")),
232          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)
233      );      );
234    
# Line 232  MainWindow::MainWindow() : Line 250  MainWindow::MainWindow() :
250          "      <separator/>"          "      <separator/>"
251          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
252          "    </menu>"          "    </menu>"
253            "    <menu action='MenuEdit'>"
254            "      <menuitem action='CopySampleUnity'/>"
255            "      <menuitem action='CopySampleTune'/>"
256            "      <menuitem action='CopySampleLoop'/>"
257            "    </menu>"
258          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
259          "    </menu>"          "    </menu>"
260          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
261          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
262          "    </menu>"          "    </menu>"
263  #ifdef ABOUT_DIALOG          "    <menu action='MenuTools'>"
264            "      <menuitem action='CombineInstruments'/>"
265            "      <menuitem action='MergeFiles'/>"
266            "    </menu>"
267            "    <menu action='MenuSettings'>"
268            "      <menuitem action='WarnUserOnExtensions'/>"
269            "    </menu>"
270          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
271          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
272          "    </menu>"          "    </menu>"
 #endif  
273          "  </menubar>"          "  </menubar>"
274          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
275          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
276            "    <menuitem action='MidiRules'/>"
277          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
278            "    <menuitem action='DupInstrument'/>"
279          "    <separator/>"          "    <separator/>"
280          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
281          "  </popup>"          "  </popup>"
# Line 253  MainWindow::MainWindow() : Line 283  MainWindow::MainWindow() :
283          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
284          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
285          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
286          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
287          "    <separator/>"          "    <separator/>"
288          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
289          "  </popup>"          "  </popup>"
# Line 261  MainWindow::MainWindow() : Line 291  MainWindow::MainWindow() :
291      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
292    
293      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
294        
295        // Set tooltips for menu items (for some reason, setting a tooltip on the
296        // respective Gtk::Action objects above will simply be ignored, no matter
297        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
298        // Gtk::Action::create()).
299        {
300            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
301                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
302            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action."));
303        }
304        {
305            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
306                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
307            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action."));
308        }
309        {
310            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
311                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
312            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action."));
313        }
314        {
315            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
316                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
317            item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
318        }
319        {
320            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
321                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
322            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
323        }
324        {
325            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
326                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
327            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
328        }
329    
330    
331        instrument_menu = static_cast<Gtk::MenuItem*>(
332            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
333    
334      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
335      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 270  MainWindow::MainWindow() : Line 339  MainWindow::MainWindow() :
339      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
340      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
341    
342        set_file_is_shared(false);
343    
344      // Status Bar:      // Status Bar:
345      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
346      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 284  MainWindow::MainWindow() : Line 355  MainWindow::MainWindow() :
355      // Create the Tree model:      // Create the Tree model:
356      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
357      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
358      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
359        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
360          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
361      );      );
362    
# Line 295  MainWindow::MainWindow() : Line 367  MainWindow::MainWindow() :
367      // create samples treeview (including its data model)      // create samples treeview (including its data model)
368      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
369      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
370        m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
371      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
372      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
373      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 306  MainWindow::MainWindow() : Line 379  MainWindow::MainWindow() :
379      );      );
380    
381      // 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
382      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
383      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
384      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
385      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
386          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 398  MainWindow::MainWindow() :
398          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
399      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
400          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
401      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
402            sigc::mem_fun(*this, &MainWindow::file_changed));
403        propDialog.signal_changed().connect(
404          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
405      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
406          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
407    
408      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 372  MainWindow::MainWindow() : Line 447  MainWindow::MainWindow() :
447    
448      file = 0;      file = 0;
449      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
450    
451      show_all_children();      show_all_children();
452    
453      // start with a new gig file by default      // start with a new gig file by default
454      on_action_file_new();      on_action_file_new();
455    
456        // select 'Instruments' tab by default
457        // (gtk allows this only if the tab childs are visible, thats why it's here)
458        m_TreeViewNotebook.set_current_page(1);
459  }  }
460    
461  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 403  void MainWindow::region_changed() Line 481  void MainWindow::region_changed()
481  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
482  {  {
483      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
484      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
485            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
486      if (it) {      if (it) {
487          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
488          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 464  void MainWindow::dimreg_changed() Line 541  void MainWindow::dimreg_changed()
541    
542  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
543  {  {
544        // select item in instrument menu
545        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
546        if (it) {
547            Gtk::TreePath path(it);
548            int index = path[0];
549            const std::vector<Gtk::Widget*> children =
550                instrument_menu->get_children();
551            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
552        }
553    
554      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
555  }  }
556    
# Line 476  void loader_progress_callback(gig::progr Line 563  void loader_progress_callback(gig::progr
563  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
564  {  {
565      {      {
566          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
567          progress = fraction;          progress = fraction;
568      }      }
569      progress_dispatcher();      progress_dispatcher();
# Line 484  void Loader::progress_callback(float fra Line 571  void Loader::progress_callback(float fra
571    
572  void Loader::thread_function()  void Loader::thread_function()
573  {  {
574      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
575      printf("Start %s\n", filename);      printf("Start %s\n", filename);
576      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
577      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 498  void Loader::thread_function() Line 585  void Loader::thread_function()
585  }  }
586    
587  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
588      : thread(0), filename(filename)      : filename(filename), thread(0)
589  {  {
590  }  }
591    
592  void Loader::launch()  void Loader::launch()
593  {  {
594    #ifdef OLD_THREADS
595      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
596    #else
597        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
598    #endif
599      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
600  }  }
601    
# Line 512  float Loader::get_progress() Line 603  float Loader::get_progress()
603  {  {
604      float res;      float res;
605      {      {
606          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
607          res = progress;          res = progress;
608      }      }
609      return res;      return res;
# Line 538  LoadDialog::LoadDialog(const Glib::ustri Line 629  LoadDialog::LoadDialog(const Glib::ustri
629  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
630  // 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.
631  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();  
632      // forget all samples that ought to be imported      // forget all samples that ought to be imported
633      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
634      // clear the samples and instruments tree views      // clear the samples and instruments tree views
635      m_refTreeModel->clear();      m_refTreeModel->clear();
636      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
637        // remove all entries from "Instrument" menu
638        while (!instrument_menu->get_children().empty()) {
639            remove_instrument_from_menu(0);
640        }
641      // free libgig's gig::File instance      // free libgig's gig::File instance
642      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
643      file = NULL;      file = NULL;
644      set_file_is_shared(false);      set_file_is_shared(false);
645  }  }
646    
647    void MainWindow::__refreshEntireGUI() {
648        // clear the samples and instruments tree views
649        m_refTreeModel->clear();
650        m_refSamplesTreeModel->clear();
651        // remove all entries from "Instrument" menu
652        while (!instrument_menu->get_children().empty()) {
653            remove_instrument_from_menu(0);
654        }
655    
656        if (!this->file) return;
657    
658        load_gig(
659            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
660        );
661    }
662    
663  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
664  {  {
665      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 569  void MainWindow::on_action_file_new() Line 672  void MainWindow::on_action_file_new()
672      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
673      // already add one new instrument by default      // already add one new instrument by default
674      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
675      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
676      // update GUI with that new gig::File      // update GUI with that new gig::File
677      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
678  }  }
# Line 580  bool MainWindow::close_confirmation_dial Line 683  bool MainWindow::close_confirmation_dial
683                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
684      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
685      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
686      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  
687      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
688      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
689      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 697  bool MainWindow::close_confirmation_dial
697  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
698      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
699      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  
700      dialog.set_secondary_text(      dialog.set_secondary_text(
701          _("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 "
702            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
703            "load it.")            "load it."));
    );  
 #endif  
704      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
705      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
706      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 621  void MainWindow::on_action_file_open() Line 719  void MainWindow::on_action_file_open()
719      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
720      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
721      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
722    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
723      Gtk::FileFilter filter;      Gtk::FileFilter filter;
724      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
725    #else
726        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
727        filter->add_pattern("*.gig");
728    #endif
729      dialog.set_filter(filter);      dialog.set_filter(filter);
730      if (current_gig_dir != "") {      if (current_gig_dir != "") {
731          dialog.set_current_folder(current_gig_dir);          dialog.set_current_folder(current_gig_dir);
# Line 630  void MainWindow::on_action_file_open() Line 733  void MainWindow::on_action_file_open()
733      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
734          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
735          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
736          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
737          load_file(filename.c_str());          load_file(filename.c_str());
738          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
739      }      }
# Line 639  void MainWindow::on_action_file_open() Line 742  void MainWindow::on_action_file_open()
742  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
743  {  {
744      __clear();      __clear();
745      load_dialog = new LoadDialog("Loading...", *this);      load_dialog = new LoadDialog(_("Loading..."), *this);
746      load_dialog->show_all();      load_dialog->show_all();
747      loader = new Loader(strdup(name));      loader = new Loader(strdup(name));
748      loader->signal_progress().connect(      loader->signal_progress().connect(
# Line 672  void MainWindow::on_loader_progress() Line 775  void MainWindow::on_loader_progress()
775  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
776  {  {
777      printf("Loader finished!\n");      printf("Loader finished!\n");
778      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
779      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
780      load_dialog->hide();      load_dialog->hide();
781  }  }
# Line 744  bool MainWindow::file_save_as() Line 847  bool MainWindow::file_save_as()
847      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
848      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
849      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  
850      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
851      // TODO: an overwrite dialog for gtkmm < 2.8  
852  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
853      Gtk::FileFilter filter;      Gtk::FileFilter filter;
854      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
855    #else
856        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
857        filter->add_pattern("*.gig");
858    #endif
859      dialog.set_filter(filter);      dialog.set_filter(filter);
860    
861      // 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 863  bool MainWindow::file_save_as()
863      {      {
864          std::string basename = Glib::path_get_basename(filename);          std::string basename = Glib::path_get_basename(filename);
865          std::string dir = Glib::path_get_dirname(filename);          std::string dir = Glib::path_get_dirname(filename);
866          basename = std::string("copy_of_") + basename;          basename = std::string(_("copy_of_")) + basename;
867          Glib::ustring copyFileName = Glib::build_filename(dir, basename);          Glib::ustring copyFileName = Glib::build_filename(dir, basename);
868          if (Glib::path_is_absolute(filename)) {          if (Glib::path_is_absolute(filename)) {
869              dialog.set_filename(copyFileName);              dialog.set_filename(copyFileName);
# Line 773  bool MainWindow::file_save_as() Line 878  bool MainWindow::file_save_as()
878      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
879      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));
880      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
881      warningIcon.show();  #if GTKMM_MAJOR_VERSION < 3
882        view::WrapLabel description;
883    #else
884      Gtk::Label description;      Gtk::Label description;
885        description.set_line_wrap();
886    #endif
887      description.set_markup(      description.set_markup(
888          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
889            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 783  bool MainWindow::file_save_as() Line 892  bool MainWindow::file_save_as()
892            "<span style=\"italic\">\"Save As...\"</span> for writing to the "            "<span style=\"italic\">\"Save As...\"</span> for writing to the "
893            "same .gig file will end up in corrupted sample wave data!\n")            "same .gig file will end up in corrupted sample wave data!\n")
894      );      );
895      description.set_line_wrap(true);      descriptionArea.pack_start(description);
     descriptionArea.pack_start(description, Gtk::PACK_SHRINK);  
     description.show();  
896      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
897      descriptionArea.show();      descriptionArea.show_all();
898    
899      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
900          file_structure_to_be_changed_signal.emit(this->file);          file_structure_to_be_changed_signal.emit(this->file);
# Line 828  void MainWindow::__import_queued_samples Line 935  void MainWindow::__import_queued_samples
935          SF_INFO info;          SF_INFO info;
936          info.format = 0;          info.format = 0;
937          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
938            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
939          try {          try {
940              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
941              // determine sample's bit depth              // determine sample's bit depth
942              int bitdepth;              int bitdepth;
943              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 846  void MainWindow::__import_queued_samples Line 954  void MainWindow::__import_queued_samples
954                      break;                      break;
955                  default:                  default:
956                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
957                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
958              }              }
959    
960              const int bufsize = 10000;              const int bufsize = 10000;
# Line 888  void MainWindow::__import_queued_samples Line 996  void MainWindow::__import_queued_samples
996              }              }
997              // cleanup              // cleanup
998              sf_close(hFile);              sf_close(hFile);
999                // let the sampler re-cache the sample if needed
1000                sample_changed_signal.emit(iter->gig_sample);
1001              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1002              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1003              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 895  void MainWindow::__import_queued_samples Line 1005  void MainWindow::__import_queued_samples
1005              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1006          } catch (std::string what) {          } catch (std::string what) {
1007              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1008              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1009              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1010              ++iter;              ++iter;
1011          }          }
1012      }      }
1013      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
1014      if (error_files.size()) {      if (!error_files.empty()) {
1015          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;
1016          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1017          msg.run();          msg.run();
# Line 914  void MainWindow::on_action_file_properti Line 1024  void MainWindow::on_action_file_properti
1024      propDialog.deiconify();      propDialog.deiconify();
1025  }  }
1026    
1027    void MainWindow::on_action_warn_user_on_extensions() {
1028        Settings::singleton()->warnUserOnExtensions =
1029            !Settings::singleton()->warnUserOnExtensions;
1030    }
1031    
1032  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1033  {  {
 #ifdef ABOUT_DIALOG  
1034      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
1035    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
1036        dialog.set_program_name("Gigedit");
1037    #else
1038        dialog.set_name("Gigedit");
1039    #endif
1040      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1041      dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1042      dialog.set_comments(      const std::string sComment =
1043          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1044          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1045          "Please notice that this is still a very young instrument editor. "          _(
1046          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1047          "this application.\n"              "\n"
1048          "\n"              "Please notice that this is still a very young instrument editor. "
1049          "Please report bugs to: http://bugs.linuxsampler.org"              "So better backup your Gigasampler files before editing them with "
1050      );              "this application.\n"
1051                "\n"
1052                "Please report bugs to: http://bugs.linuxsampler.org"
1053            );
1054        dialog.set_comments(sComment.c_str());
1055      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1056      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1057      dialog.run();      dialog.run();
 #endif  
1058  }  }
1059    
1060  PropDialog::PropDialog()  PropDialog::PropDialog()
1061      : table(2,1),      : eFileFormat(_("File Format")),
1062        eName("Name"),        eName(_("Name")),
1063        eCreationDate("Creation date"),        eCreationDate(_("Creation date")),
1064        eComments("Comments"),        eComments(_("Comments")),
1065        eProduct("Product"),        eProduct(_("Product")),
1066        eCopyright("Copyright"),        eCopyright(_("Copyright")),
1067        eArtists("Artists"),        eArtists(_("Artists")),
1068        eGenre("Genre"),        eGenre(_("Genre")),
1069        eKeywords("Keywords"),        eKeywords(_("Keywords")),
1070        eEngineer("Engineer"),        eEngineer(_("Engineer")),
1071        eTechnician("Technician"),        eTechnician(_("Technician")),
1072        eSoftware("Software"),        eSoftware(_("Software")),
1073        eMedium("Medium"),        eMedium(_("Medium")),
1074        eSource("Source"),        eSource(_("Source")),
1075        eSourceForm("Source form"),        eSourceForm(_("Source form")),
1076        eCommissioned("Commissioned"),        eCommissioned(_("Commissioned")),
1077        eSubject("Subject"),        eSubject(_("Subject")),
1078        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1079        update_model(0)        table(2, 1),
1080          m_file(NULL)
1081  {  {
1082      set_title("File Properties");      set_title(_("File Properties"));
1083      eName.set_width_chars(50);      eName.set_width_chars(50);
1084    
1085      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
# Line 976  PropDialog::PropDialog() Line 1099  PropDialog::PropDialog()
1099      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1100      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1101    
1102        table.add(eFileFormat);
1103      table.add(eName);      table.add(eName);
1104      table.add(eCreationDate);      table.add(eCreationDate);
1105      table.add(eComments);      table.add(eComments);
# Line 1002  PropDialog::PropDialog() Line 1126  PropDialog::PropDialog()
1126      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1127      buttonBox.show();      buttonBox.show();
1128      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1129      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1130      quitButton.grab_focus();      quitButton.grab_focus();
1131      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1132          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1133        eFileFormat.signal_value_changed().connect(
1134            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1135    
1136      quitButton.show();      quitButton.show();
1137      vbox.show();      vbox.show();
1138      show_all_children();      show_all_children();
1139  }  }
1140    
1141  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_file(gig::File* file)
1142  {  {
1143      this->info = info;      m_file = file;
1144      update_model++;  
1145      eName.set_value(info->Name);      // update file format version combo box
1146      eCreationDate.set_value(info->CreationDate);      const std::string sGiga = "Gigasampler/GigaStudio v";
1147      eComments.set_value(info->Comments);      const int major = file->pVersion->major;
1148      eProduct.set_value(info->Product);      std::vector<std::string> txts;
1149      eCopyright.set_value(info->Copyright);      std::vector<int> values;
1150      eArtists.set_value(info->Artists);      txts.push_back(sGiga + "2"); values.push_back(2);
1151      eGenre.set_value(info->Genre);      txts.push_back(sGiga + "3"); values.push_back(3);
1152      eKeywords.set_value(info->Keywords);      if (major != 2 && major != 3) {
1153      eEngineer.set_value(info->Engineer);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
1154      eTechnician.set_value(info->Technician);      }
1155      eSoftware.set_value(info->Software);      std::vector<const char*> texts;
1156      eMedium.set_value(info->Medium);      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1157      eSource.set_value(info->Source);      texts.push_back(NULL); values.push_back(NULL);
1158      eSourceForm.set_value(info->SourceForm);      eFileFormat.set_choices(&texts[0], &values[0]);
1159      eCommissioned.set_value(info->Commissioned);      eFileFormat.set_value(major);
1160      eSubject.set_value(info->Subject);  }
1161      update_model--;  
1162    void PropDialog::onFileFormatChanged() {
1163        const int major = eFileFormat.get_value();
1164        if (m_file) m_file->pVersion->major = major;
1165  }  }
1166    
1167  sigc::signal<void>& PropDialog::signal_info_changed()  void PropDialog::set_info(DLS::Info* info)
1168  {  {
1169      return info_changed;      update(info);
1170  }  }
1171    
1172  void InstrumentProps::set_IsDrum(bool value)  
1173    void InstrumentProps::set_Name(const gig::String& name)
1174  {  {
1175      instrument->IsDrum = value;      m->pInfo->Name = name;
1176  }  }
1177    
1178  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1179  {  {
1180      instrument->MIDIBank = value;      update_model++;
1181        eName.set_value(m->pInfo->Name);
1182        update_model--;
1183  }  }
1184    
1185  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1186  {  {
1187      instrument->MIDIProgram = value;      m->IsDrum = value;
1188  }  }
1189    
1190  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1191  {  {
1192      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1193  }  }
1194    
1195  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1196  {  {
1197      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1198  }  }
1199    
1200  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1201      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1202        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1203        eName("Name"),      eName(_("Name")),
1204        eIsDrum("Is drum"),      eIsDrum(_("Is drum")),
1205        eMIDIBank("MIDI bank", 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1206        eMIDIProgram("MIDI program"),      eMIDIProgram(_("MIDI program")),
1207        eAttenuation("Attenuation", 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1208        eGainPlus6("Gain +6dB", eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1209        eEffectSend("Effect send", 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1210        eFineTune("Fine tune", -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1211        ePitchbendRange("Pitchbend range", 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1212        ePianoReleaseMode("Piano release mode"),      ePianoReleaseMode(_("Piano release mode")),
1213        eDimensionKeyRangeLow("Keyswitching range low"),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1214        eDimensionKeyRangeHigh("Keyswitching range high"),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1215  {  {
1216      set_title("Instrument Properties");      set_title(_("Instrument Properties"));
1217    
1218      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
1219          _("start of the keyboard area which should switch the "          _("start of the keyboard area which should switch the "
# Line 1099  InstrumentProps::InstrumentProps() Line 1224  InstrumentProps::InstrumentProps()
1224            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1225      );      );
1226    
1227        connect(eName, &InstrumentProps::set_Name);
1228      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1229      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1230      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1108  InstrumentProps::InstrumentProps() Line 1234  InstrumentProps::InstrumentProps()
1234      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1235      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1236      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1237      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1238              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1239      connect(eDimensionKeyRangeHigh,  
1240              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1241    
1242      table.set_col_spacings(5);      table.set_col_spacings(5);
1243    
# Line 1137  InstrumentProps::InstrumentProps() Line 1263  InstrumentProps::InstrumentProps()
1263      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1264      buttonBox.show();      buttonBox.show();
1265      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1266      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1267      quitButton.grab_focus();      quitButton.grab_focus();
1268    
1269      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1150  InstrumentProps::InstrumentProps() Line 1276  InstrumentProps::InstrumentProps()
1276    
1277  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1278  {  {
1279      this->instrument = instrument;      update(instrument);
1280    
1281      update_model++;      update_model++;
1282      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1283      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1284      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1285      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);  
1286      update_model--;      update_model--;
1287  }  }
1288    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1289    
1290  void MainWindow::file_changed()  void MainWindow::file_changed()
1291  {  {
# Line 1191  void MainWindow::load_gig(gig::File* gig Line 1305  void MainWindow::load_gig(gig::File* gig
1305      file_has_name = filename;      file_has_name = filename;
1306      file_is_changed = false;      file_is_changed = false;
1307    
1308        propDialog.set_file(gig);
1309      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1310    
1311      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;  
1312      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1313           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1314            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1315    
1316          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1317          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1318          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1319          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1320          // create a menu item for this instrument  
1321          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++;  
1322      }      }
1323      instrument_menu->show();      instrument_name_connection.unblock();
1324      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1325    
1326      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1327          if (group->Name != "") {          if (group->Name != "") {
1328              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1329              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1330              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1331              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1332              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1333              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1231  void MainWindow::load_gig(gig::File* gig Line 1335  void MainWindow::load_gig(gig::File* gig
1335                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1336                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1337                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1338                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1339                        gig_to_utf8(sample->pInfo->Name);
1340                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1341                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1342              }              }
# Line 1241  void MainWindow::load_gig(gig::File* gig Line 1346  void MainWindow::load_gig(gig::File* gig
1346      file = gig;      file = gig;
1347    
1348      // select the first instrument      // select the first instrument
1349      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1350      tree_sel_ref->select(Gtk::TreePath("0"));  
1351        instr_props_set_instrument();
1352        gig::Instrument* instrument = get_instrument();
1353        if (instrument) {
1354            midiRules.set_instrument(instrument);
1355        }
1356  }  }
1357    
1358  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1359  {  {
1360      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1361      if (instrument)  
1362      {      Gtk::TreeModel::const_iterator it =
1363            m_TreeView.get_selection()->get_selected();
1364        if (it) {
1365            Gtk::TreeModel::Row row = *it;
1366            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1367    
1368          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1369    
1370            // make sure instrument tree is updated when user changes the
1371            // instrument name in instrument properties window
1372            instrumentProps.signal_name_changed().connect(
1373                sigc::bind(
1374                    sigc::mem_fun(*this,
1375                                  &MainWindow::instr_name_changed_by_instr_props),
1376                    it));
1377        } else {
1378            instrumentProps.hide();
1379        }
1380        return it;
1381    }
1382    
1383    void MainWindow::show_instr_props()
1384    {
1385        if (instr_props_set_instrument()) {
1386          instrumentProps.show();          instrumentProps.show();
1387          instrumentProps.deiconify();          instrumentProps.deiconify();
1388      }      }
1389  }  }
1390    
1391    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1392    {
1393        Gtk::TreeModel::Row row = *it;
1394        Glib::ustring name = row[m_Columns.m_col_name];
1395    
1396        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1397        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1398        if (gigname != name) {
1399            row[m_Columns.m_col_name] = gigname;
1400        }
1401    }
1402    
1403    void MainWindow::show_midi_rules()
1404    {
1405        if (gig::Instrument* instrument = get_instrument())
1406        {
1407            midiRules.set_instrument(instrument);
1408            midiRules.show();
1409            midiRules.deiconify();
1410        }
1411    }
1412    
1413  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1414      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1415          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 1421  void MainWindow::on_action_view_status_b
1421      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1422  }  }
1423    
1424    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1425        Gtk::CheckMenuItem* item =
1426            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1427        if (!item) {
1428            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1429            return true;
1430        }
1431        return item->get_active();
1432    }
1433    
1434    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1435        Gtk::CheckMenuItem* item =
1436            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1437        if (!item) {
1438            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1439            return true;
1440        }
1441        return item->get_active();
1442    }
1443    
1444    bool MainWindow::is_copy_samples_loop_enabled() const {
1445        Gtk::CheckMenuItem* item =
1446            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1447        if (!item) {
1448            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1449            return true;
1450        }
1451        return item->get_active();
1452    }
1453    
1454  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1455  {  {
1456      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1457          show_instr_props();          show_instr_props();
1458      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1459            // gig v2 files have no midi rules
1460            static_cast<Gtk::MenuItem*>(
1461                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1462                    !(file->pVersion && file->pVersion->major == 2));
1463          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1464      }      }
1465  }  }
1466    
1467  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1468      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1469            const std::vector<Gtk::Widget*> children =
1470                instrument_menu->get_children();
1471            std::vector<Gtk::Widget*>::const_iterator it =
1472                find(children.begin(), children.end(), item);
1473            if (it != children.end()) {
1474                int index = it - children.begin();
1475                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1476    
1477                m_RegionChooser.set_instrument(file->GetInstrument(index));
1478            }
1479        }
1480  }  }
1481    
1482  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 1506  void MainWindow::on_sample_treeview_butt
1506      }      }
1507  }  }
1508    
1509  void MainWindow::on_action_add_instrument() {  
1510      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1511      if (!file) return;      const Glib::ustring& name, int position) {
1512      gig::Instrument* instrument = file->AddInstrument();  
1513      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1514      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1515          "Unnamed Instrument " + ToString(__instrument_indexer);      if (!children.empty()) {
1516            instrument_group =
1517                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1518        }
1519        Gtk::RadioMenuItem* item =
1520            new Gtk::RadioMenuItem(instrument_group, name);
1521        if (position < 0) {
1522            instrument_menu->append(*item);
1523        } else {
1524            instrument_menu->insert(*item, position);
1525        }
1526        item->show();
1527        item->signal_activate().connect(
1528            sigc::bind(
1529                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1530                item));
1531        return item;
1532    }
1533    
1534    void MainWindow::remove_instrument_from_menu(int index) {
1535        const std::vector<Gtk::Widget*> children =
1536            instrument_menu->get_children();
1537        Gtk::Widget* child = children[index];
1538        instrument_menu->remove(*child);
1539        delete child;
1540    }
1541    
1542    void MainWindow::add_instrument(gig::Instrument* instrument) {
1543        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1544    
1545      // update instrument tree view      // update instrument tree view
1546        instrument_name_connection.block();
1547      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1548      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1549      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1550      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1551        instrument_name_connection.unblock();
1552    
1553        add_instrument_to_menu(name);
1554    
1555        m_TreeView.get_selection()->select(iterInstr);
1556    
1557      file_changed();      file_changed();
1558  }  }
1559    
1560    void MainWindow::on_action_add_instrument() {
1561        static int __instrument_indexer = 0;
1562        if (!file) return;
1563        gig::Instrument* instrument = file->AddInstrument();
1564        __instrument_indexer++;
1565        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1566                                                ToString(__instrument_indexer));
1567    
1568        add_instrument(instrument);
1569    }
1570    
1571    void MainWindow::on_action_duplicate_instrument() {
1572        if (!file) return;
1573    
1574        // retrieve the currently selected instrument
1575        // (being the original instrument to be duplicated)
1576        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1577        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1578        if (!itSelection) return;
1579        Gtk::TreeModel::Row row = *itSelection;
1580        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1581        if (!instrOrig) return;
1582    
1583        // duplicate the orginal instrument
1584        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1585        instrNew->pInfo->Name =
1586            instrOrig->pInfo->Name +
1587            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1588    
1589        add_instrument(instrNew);
1590    }
1591    
1592  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1593      if (!file) return;      if (!file) return;
1594      if (file_is_shared) {      if (file_is_shared) {
# Line 1341  void MainWindow::on_action_remove_instru Line 1608  void MainWindow::on_action_remove_instru
1608          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1609          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1610          try {          try {
1611                Gtk::TreePath path(it);
1612                int index = path[0];
1613    
1614              // remove instrument from the gig file              // remove instrument from the gig file
1615              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1616              file_changed();              file_changed();
1617    
1618                remove_instrument_from_menu(index);
1619    
1620                // remove row from instruments tree view
1621                m_refTreeModel->erase(it);
1622    
1623    #if GTKMM_MAJOR_VERSION < 3
1624                // select another instrument (in gtk3 this is done
1625                // automatically)
1626                if (!m_refTreeModel->children().empty()) {
1627                    if (index == m_refTreeModel->children().size()) {
1628                        index--;
1629                    }
1630                    m_TreeView.get_selection()->select(
1631                        Gtk::TreePath(ToString(index)));
1632                }
1633    #endif
1634                instr_props_set_instrument();
1635                instr = get_instrument();
1636                if (instr) {
1637                    midiRules.set_instrument(instr);
1638                } else {
1639                    midiRules.hide();
1640                }
1641          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1642              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1643              msg.run();              msg.run();
# Line 1356  void MainWindow::on_action_remove_instru Line 1648  void MainWindow::on_action_remove_instru
1648  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
1649      //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
1650      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
1651          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
1652      );      );
1653      msg.run();      msg.run();
1654  }  }
# Line 1365  void MainWindow::on_action_add_group() { Line 1657  void MainWindow::on_action_add_group() {
1657      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1658      if (!file) return;      if (!file) return;
1659      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1660      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
1661      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1662      __sample_indexer++;      __sample_indexer++;
1663      // update sample tree view      // update sample tree view
1664      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1665      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1666      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1667      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1668      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1669      file_changed();      file_changed();
# Line 1399  void MainWindow::on_action_add_sample() Line 1691  void MainWindow::on_action_add_sample()
1691      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1692      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1693      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1694      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1695        // matches all file types supported by libsndfile
1696    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1697        Gtk::FileFilter soundfilter;
1698    #else
1699        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1700    #endif
1701      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1702          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1703          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1407  void MainWindow::on_action_add_sample() Line 1705  void MainWindow::on_action_add_sample()
1705          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1706          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1707      };      };
1708        const char* soundfiles = _("Sound Files");
1709        const char* allfiles = _("All Files");
1710    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1711      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1712          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1713      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
1714      Gtk::FileFilter allpassfilter; // matches every file  
1715        // matches every file
1716        Gtk::FileFilter allpassfilter;
1717      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1718      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
1719    #else
1720        for (int i = 0; supportedFileTypes[i]; i++)
1721            soundfilter->add_pattern(supportedFileTypes[i]);
1722        soundfilter->set_name(soundfiles);
1723    
1724        // matches every file
1725        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1726        allpassfilter->add_pattern("*.*");
1727        allpassfilter->set_name(allfiles);
1728    #endif
1729      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1730      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1731      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 1421  void MainWindow::on_action_add_sample() Line 1734  void MainWindow::on_action_add_sample()
1734      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1735          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1736          Glib::ustring error_files;          Glib::ustring error_files;
1737          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1738          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1739               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1740              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1741              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1430  void MainWindow::on_action_add_sample() Line 1743  void MainWindow::on_action_add_sample()
1743              info.format = 0;              info.format = 0;
1744              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1745              try {              try {
1746                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
1747                  int bitdepth;                  int bitdepth;
1748                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
1749                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1446  void MainWindow::on_action_add_sample() Line 1759  void MainWindow::on_action_add_sample()
1759                          break;                          break;
1760                      default:                      default:
1761                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
1762                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
1763                  }                  }
1764                  // add a new sample to the .gig file                  // add a new sample to the .gig file
1765                  gig::Sample* sample = file->AddSample();                  gig::Sample* sample = file->AddSample();
# Line 1459  void MainWindow::on_action_add_sample() Line 1772  void MainWindow::on_action_add_sample()
1772                          break;                          break;
1773                      }                      }
1774                  }                  }
1775                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1776                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1777                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1778                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1473  void MainWindow::on_action_add_sample() Line 1786  void MainWindow::on_action_add_sample()
1786                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1787                  {                  {
1788                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1789                        sample->FineTune      = instrument.detune;
1790    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1791                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1792                          sample->Loops = 1;                          sample->Loops = 1;
1793    
# Line 1494  void MainWindow::on_action_add_sample() Line 1807  void MainWindow::on_action_add_sample()
1807                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1808                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1809                      }                      }
 #endif  
1810                  }                  }
1811    
1812                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1512  void MainWindow::on_action_add_sample() Line 1824  void MainWindow::on_action_add_sample()
1824                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1825                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1826                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1827                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1828                        gig_to_utf8(sample->pInfo->Name);
1829                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1830                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1831                  // close sound file                  // close sound file
1832                  sf_close(hFile);                  sf_close(hFile);
1833                  file_changed();                  file_changed();
1834              } 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)
1835                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1836                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1837              }              }
1838          }          }
1839          // 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
1840          if (error_files.size()) {          if (!error_files.empty()) {
1841              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;
1842              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1843              msg.run();              msg.run();
# Line 1537  void MainWindow::on_action_replace_all_s Line 1850  void MainWindow::on_action_replace_all_s
1850      if (!file) return;      if (!file) return;
1851      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1852                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1853      Gtk::Label description(      const char* str =
1854          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1855            "in the current gig file by samples located in the directory chosen "            "in the current gig file by samples located in the chosen "
1856            "by you above.\n\n"            "directory.\n\n"
1857            "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 "
1858            "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 "
1859            "the sample in the gig file. Optionally you can add a filename "            "the sample in the gig file. Optionally, you can add a filename "
1860            "postfix below, which will be added to the filename expected to be "            "extension below, which will be added to the filename expected to be "
1861            "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 "
1862            "'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 "
1863            "assumes to find a sample file called 'Snare.wav' and will replace "            "expects to find a sample file called 'Snare.wav' and will replace "
1864            "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 "
1865            "postfix, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
1866            "appropriate sample file could be found, will be reported and left "            "appropriate sample file could be found will be reported and left "
1867            "untouched.\n\n")            "untouched.\n");
1868      );  #if GTKMM_MAJOR_VERSION < 3
1869      description.set_line_wrap(true);      view::WrapLabel description(str);
1870    #else
1871        Gtk::Label description(str);
1872        description.set_line_wrap();
1873    #endif
1874      Gtk::HBox entryArea;      Gtk::HBox entryArea;
1875      Gtk::Label entryLabel( _("Add Filename Extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1876      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
1877      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
1878      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1563  void MainWindow::on_action_replace_all_s Line 1880  void MainWindow::on_action_replace_all_s
1880      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
1881      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
1882      description.show();      description.show();
1883      entryLabel.show();      entryArea.show_all();
     postfixEntryBox.show();  
     entryArea.show();  
1884      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1885      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
1886      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
1887      if (current_sample_dir != "") {      if (current_sample_dir != "") {
1888          dialog.set_current_folder(current_sample_dir);          dialog.set_current_folder(current_sample_dir);
1889      }      }
     // fix label width (because Gtk by design doesn't  
     // know anything about the parent's size)  
 #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  
1890      if (dialog.run() == Gtk::RESPONSE_OK)      if (dialog.run() == Gtk::RESPONSE_OK)
1891      {      {
1892          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
1893          Glib::ustring error_files;          Glib::ustring error_files;
1894          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
1895          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
1896               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1897          {          {
1898              std::string filename =              std::string filename =
1899                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1900                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1901                                             postfixEntryBox.get_text());
1902              SF_INFO info;              SF_INFO info;
1903              info.format = 0;              info.format = 0;
1904              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
1905              try              try
1906              {              {
1907                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
1908                  int bitdepth;                  int bitdepth;
1909                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
1910                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1613  void MainWindow::on_action_replace_all_s Line 1920  void MainWindow::on_action_replace_all_s
1920                          break;                          break;
1921                      default:                      default:
1922                          sf_close(hFile);                          sf_close(hFile);
1923                          throw std::string("format not supported");                          throw std::string(_("format not supported"));
1924                  }                  }
1925                  SampleImportItem sched_item;                  SampleImportItem sched_item;
1926                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
# Line 1624  void MainWindow::on_action_replace_all_s Line 1931  void MainWindow::on_action_replace_all_s
1931              }              }
1932              catch (std::string what)              catch (std::string what)
1933              {              {
1934                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1935                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1936                        " (" + what + ")";
1937              }              }
1938          }          }
1939          // 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
1940          if (error_files.size()) {          if (!error_files.empty()) {
1941              Glib::ustring txt =              Glib::ustring txt =
1942                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1943              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1650  void MainWindow::on_action_remove_sample Line 1958  void MainWindow::on_action_remove_sample
1958          try {          try {
1959              // remove group or sample from the gig file              // remove group or sample from the gig file
1960              if (group) {              if (group) {
1961                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1962                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1963                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1964                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1772  void MainWindow::on_sample_label_drop_dr Line 2080  void MainWindow::on_sample_label_drop_dr
2080          bool channels_changed = false;          bool channels_changed = false;
2081          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2082              // remove the samplechannel dimension              // remove the samplechannel dimension
2083    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2084              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2085              channels_changed = true;              channels_changed = true;
2086              region_changed();              region_changed();
2087    */
2088          }          }
2089          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2090                sample,
2091                is_copy_samples_unity_note_enabled(),
2092                is_copy_samples_fine_tune_enabled(),
2093                is_copy_samples_loop_enabled()
2094            );
2095    
2096          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2097              // add samplechannel dimension              // add samplechannel dimension
# Line 1819  void MainWindow::sample_name_changed(con Line 2134  void MainWindow::sample_name_changed(con
2134      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2135      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2136      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2137        gig::String gigname(gig_from_utf8(name));
2138      if (group) {      if (group) {
2139          if (group->Name != name) {          if (group->Name != gigname) {
2140              group->Name = name;              group->Name = gigname;
2141              printf("group name changed\n");              printf("group name changed\n");
2142              file_changed();              file_changed();
2143          }          }
2144      } else if (sample) {      } else if (sample) {
2145          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2146              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2147              printf("sample name changed\n");              printf("sample name changed\n");
2148              file_changed();              file_changed();
2149          }          }
# Line 1839  void MainWindow::instrument_name_changed Line 2155  void MainWindow::instrument_name_changed
2155      if (!iter) return;      if (!iter) return;
2156      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2157      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2158    
2159        // change name in instrument menu
2160        int index = path[0];
2161        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2162        if (index < children.size()) {
2163    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2164            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2165    #else
2166            remove_instrument_from_menu(index);
2167            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2168            item->set_active();
2169    #endif
2170        }
2171    
2172        // change name in gig
2173      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2174      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2175          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2176            instrument->pInfo->Name = gigname;
2177    
2178            // change name in the instrument properties window
2179            if (instrumentProps.get_instrument() == instrument) {
2180                instrumentProps.update_name();
2181            }
2182    
2183          file_changed();          file_changed();
2184      }      }
2185  }  }
2186    
2187    void MainWindow::on_action_combine_instruments() {
2188        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2189        d->show_all();
2190        d->resize(500, 400);
2191        d->run();
2192        if (d->fileWasChanged()) {
2193            // update GUI with new instrument just created
2194            add_instrument(d->newCombinedInstrument());
2195        }
2196        delete d;
2197    }
2198    
2199    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2200        struct _Source {
2201            std::vector<RIFF::File*> riffs;
2202            std::vector<gig::File*> gigs;
2203            
2204            ~_Source() {
2205                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2206                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2207                riffs.clear();
2208                gigs.clear();
2209            }
2210        } sources;
2211    
2212        if (filenames.empty())
2213            throw RIFF::Exception(_("No files selected, so nothing done."));
2214    
2215        // first open all input files (to avoid output file corruption)
2216        int i;
2217        try {
2218            for (i = 0; i < filenames.size(); ++i) {
2219                const std::string& filename = filenames[i];
2220                printf("opening file=%s\n", filename.c_str());
2221    
2222                RIFF::File* riff = new RIFF::File(filename);
2223                sources.riffs.push_back(riff);
2224    
2225                gig::File* gig = new gig::File(riff);
2226                sources.gigs.push_back(gig);
2227            }
2228        } catch (RIFF::Exception e) {
2229            throw RIFF::Exception(
2230                _("Error occurred while opening '") +
2231                filenames[i] +
2232                "': " +
2233                e.Message
2234            );
2235        } catch (...) {
2236            throw RIFF::Exception(
2237                _("Unknown exception occurred while opening '") +
2238                filenames[i] + "'"
2239            );
2240        }
2241    
2242        // now merge the opened .gig files to the main .gig file currently being
2243        // open in gigedit
2244        try {
2245            for (i = 0; i < filenames.size(); ++i) {
2246                const std::string& filename = filenames[i];
2247                printf("merging file=%s\n", filename.c_str());
2248                assert(i < sources.gigs.size());
2249    
2250                this->file->AddContentOf(sources.gigs[i]);
2251            }
2252        } catch (RIFF::Exception e) {
2253            throw RIFF::Exception(
2254                _("Error occurred while merging '") +
2255                filenames[i] +
2256                "': " +
2257                e.Message
2258            );
2259        } catch (...) {
2260            throw RIFF::Exception(
2261                _("Unknown exception occurred while merging '") +
2262                filenames[i] + "'"
2263            );
2264        }
2265    
2266        // Note: requires that this file already has a filename !
2267        this->file->Save();
2268    }
2269    
2270    void MainWindow::on_action_merge_files() {
2271        if (this->file->GetFileName().empty()) {
2272            Glib::ustring txt = _(
2273                "You seem to have a new .gig file open that has not been saved "
2274                "yet. You must save it somewhere before starting to merge it with "
2275                "other .gig files though, because during the merge operation the "
2276                "other files' sample data must be written on file level to the "
2277                "target .gig file."
2278            );
2279            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2280            msg.run();
2281            return;
2282        }
2283    
2284        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2285        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2286        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2287        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2288    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2289        Gtk::FileFilter filter;
2290        filter.add_pattern("*.gig");
2291    #else
2292        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2293        filter->add_pattern("*.gig");
2294    #endif
2295        dialog.set_filter(filter);
2296        if (current_gig_dir != "") {
2297            dialog.set_current_folder(current_gig_dir);
2298        }
2299        dialog.set_select_multiple(true);
2300    
2301        // show warning in the file picker dialog
2302        Gtk::HBox descriptionArea;
2303        descriptionArea.set_spacing(15);
2304        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2305        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2306    #if GTKMM_MAJOR_VERSION < 3
2307        view::WrapLabel description;
2308    #else
2309        Gtk::Label description;
2310        description.set_line_wrap();
2311    #endif
2312        description.set_markup(_(
2313            "\nSelect at least one .gig file that shall be merged to the .gig file "
2314            "currently being open in gigedit.\n\n"
2315            "<b>Please Note:</b> Merging with other files will modify your "
2316            "currently open .gig file on file level! And be aware that the current "
2317            "merge algorithm does not detect duplicate samples yet. So if you are "
2318            "merging files which are using equivalent sample data, those "
2319            "equivalent samples will currently be treated as separate samples and "
2320            "will accordingly be stored separately in the target .gig file!"
2321        ));
2322        descriptionArea.pack_start(description);
2323        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2324        descriptionArea.show_all();
2325    
2326        if (dialog.run() == Gtk::RESPONSE_OK) {
2327            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2328            std::vector<std::string> filenames = dialog.get_filenames();
2329    
2330            // merge the selected files to the currently open .gig file
2331            try {
2332                mergeFiles(filenames);
2333            } catch (RIFF::Exception e) {
2334                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2335                msg.run();
2336            }
2337    
2338            // update GUI
2339            __refreshEntireGUI();        
2340        }
2341    }
2342    
2343  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2344      this->file_is_shared = b;      this->file_is_shared = b;
2345    
# Line 1886  sigc::signal<void, gig::Region*>& MainWi Line 2380  sigc::signal<void, gig::Region*>& MainWi
2380      return region_changed_signal;      return region_changed_signal;
2381  }  }
2382    
2383    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2384        return sample_changed_signal;
2385    }
2386    
2387  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() {
2388      return sample_ref_changed_signal;      return sample_ref_changed_signal;
2389  }  }

Legend:
Removed from v.1725  
changed lines
  Added in v.2560

  ViewVC Help
Powered by ViewVC