/[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 1261 by persson, Thu Jul 5 17:12:20 2007 UTC revision 2541 by schoenebeck, Wed Apr 23 16:49:05 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006, 2007 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 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
 #include <libintl.h>  
20  #include <iostream>  #include <iostream>
21    #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>
34  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  #if GTKMM_MAJOR_VERSION < 3
35  #define ABOUT_DIALOG  #include "wrapLabel.hh"
 #include <gtkmm/aboutdialog.h>  
36  #endif  #endif
37    
38    #include "global.h"
39    #include "compat.h"
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    
44  #include "mainwindow.h"  #include "mainwindow.h"
45    #include "Settings.h"
46    #include "../../gfx/status_attached.xpm"
47    #include "../../gfx/status_detached.xpm"
48    
 #define _(String) gettext(String)  
49    
50  template<class T> inline std::string ToString(T o) {  MainWindow::MainWindow() :
51      std::stringstream ss;      dimreg_label(_("Changes apply to:")),
52      ss << o;      dimreg_all_regions(_("all regions")),
53      return ss.str();      dimreg_all_dimregs(_("all dimension splits")),
54  }      dimreg_stereo(_("both channels"))
   
 MainWindow::MainWindow()  
55  {  {
56  //    set_border_width(5);  //    set_border_width(5);
57  //    set_default_size(400, 200);  //    set_default_size(400, 200);
# Line 53  MainWindow::MainWindow() Line 60  MainWindow::MainWindow()
60      add(m_VBox);      add(m_VBox);
61    
62      // Handle selection      // Handle selection
63      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
64          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
65    
66      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 74  MainWindow::MainWindow() Line 80  MainWindow::MainWindow()
80      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
81    
82      m_HPaned.add1(m_TreeViewNotebook);      m_HPaned.add1(m_TreeViewNotebook);
83      m_HPaned.add2(dimreg_edit);      dimreg_hbox.add(dimreg_label);
84        dimreg_hbox.add(dimreg_all_regions);
85        dimreg_hbox.add(dimreg_all_dimregs);
86        dimreg_stereo.set_active();
87        dimreg_hbox.add(dimreg_stereo);
88        dimreg_vbox.add(dimreg_edit);
89        dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
90        m_HPaned.add2(dimreg_vbox);
91    
92        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
93        dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
94        dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
95        dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
96    
97      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
98      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
99    
100    
101      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
# Line 110  MainWindow::MainWindow() Line 127  MainWindow::MainWindow()
127                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
128                       sigc::mem_fun(                       sigc::mem_fun(
129                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
130        actionGroup->add(Gtk::Action::create("MidiRules",
131                                             _("_Midi Rules")),
132                         sigc::mem_fun(
133                             *this, &MainWindow::show_midi_rules));
134      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
135                       sigc::mem_fun(                       sigc::mem_fun(
136                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
137      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
138    
139    
140        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
141    
142        Glib::RefPtr<Gtk::ToggleAction> toggle_action =
143            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
144        toggle_action->set_active(true);
145        actionGroup->add(toggle_action);
146    
147        toggle_action =
148            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
149        toggle_action->set_active(true);
150        actionGroup->add(toggle_action);
151    
152        toggle_action =
153            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
154        toggle_action->set_active(true);
155        actionGroup->add(toggle_action);
156    
157    
158        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
159        toggle_action =
160            Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
161        toggle_action->set_active(true);
162        actionGroup->add(toggle_action,
163                         sigc::mem_fun(
164                             *this, &MainWindow::on_action_view_status_bar));
165    
166      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
167      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
168                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
169      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
170                       sigc::mem_fun(                       sigc::mem_fun(
171                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
172      actionGroup->add(      actionGroup->add(
173          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
174          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
175      );      );
176      actionGroup->add(      actionGroup->add(
177            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
178            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
179        );
180        actionGroup->add(
181          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
182          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
183      );      );
184    
185    
186        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
187        
188        toggle_action =
189            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
190        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
191        actionGroup->add(
192            toggle_action,
193            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
194        );
195    
196    
197      // sample right-click popup actions      // sample right-click popup actions
198      actionGroup->add(      actionGroup->add(
199          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 142  MainWindow::MainWindow() Line 204  MainWindow::MainWindow()
204          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
205      );      );
206      actionGroup->add(      actionGroup->add(
207          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
208          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
209      );      );
210      actionGroup->add(      actionGroup->add(
211          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
212          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
213      );      );
214        actionGroup->add(
215            Gtk::Action::create("ReplaceAllSamplesInAllGroups",
216                                _("Replace All Samples in All Groups...")),
217            sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
218        );
219    
220      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
221      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 168  MainWindow::MainWindow() Line 235  MainWindow::MainWindow()
235          "      <separator/>"          "      <separator/>"
236          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
237          "    </menu>"          "    </menu>"
238            "    <menu action='MenuEdit'>"
239            "      <menuitem action='CopySampleUnity'/>"
240            "      <menuitem action='CopySampleTune'/>"
241            "      <menuitem action='CopySampleLoop'/>"
242            "    </menu>"
243          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
244          "    </menu>"          "    </menu>"
245  #ifdef ABOUT_DIALOG          "    <menu action='MenuView'>"
246            "      <menuitem action='Statusbar'/>"
247            "    </menu>"
248            "    <menu action='MenuSettings'>"
249            "      <menuitem action='WarnUserOnExtensions'/>"
250            "    </menu>"
251          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
252          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
253          "    </menu>"          "    </menu>"
 #endif  
254          "  </menubar>"          "  </menubar>"
255          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
256          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
257            "    <menuitem action='MidiRules'/>"
258          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
259            "    <menuitem action='DupInstrument'/>"
260          "    <separator/>"          "    <separator/>"
261          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
262          "  </popup>"          "  </popup>"
# Line 186  MainWindow::MainWindow() Line 264  MainWindow::MainWindow()
264          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
265          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
266          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
267            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
268          "    <separator/>"          "    <separator/>"
269          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
270          "  </popup>"          "  </popup>"
# Line 193  MainWindow::MainWindow() Line 272  MainWindow::MainWindow()
272      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
273    
274      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
275        
276        // Set tooltips for menu items (for some reason, setting a tooltip on the
277        // respective Gtk::Action objects above will simply be ignored, no matter
278        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
279        // Gtk::Action::create()).
280        {
281            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
282                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
283            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."));
284        }
285        {
286            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
287                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
288            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."));
289        }
290        {
291            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
292                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
293            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."));
294        }
295        {
296            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
297                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
298            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."));
299        }
300    
301        instrument_menu = static_cast<Gtk::MenuItem*>(
302            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
303    
304      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
305      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
306      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
307      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
308        m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
309      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
310        m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
311    
312        set_file_is_shared(false);
313    
314        // Status Bar:
315        m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
316        m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
317        m_StatusBar.show();
318    
319      m_RegionChooser.signal_region_selected().connect(      m_RegionChooser.signal_region_selected().connect(
320          sigc::mem_fun(*this, &MainWindow::region_changed) );          sigc::mem_fun(*this, &MainWindow::region_changed) );
# Line 209  MainWindow::MainWindow() Line 325  MainWindow::MainWindow()
325      // Create the Tree model:      // Create the Tree model:
326      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
327      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
328      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
329        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
330          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
331      );      );
332    
# Line 220  MainWindow::MainWindow() Line 337  MainWindow::MainWindow()
337      // create samples treeview (including its data model)      // create samples treeview (including its data model)
338      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
339      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
340        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."));
341      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
342      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
343      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 231  MainWindow::MainWindow() Line 349  MainWindow::MainWindow()
349      );      );
350    
351      // 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
352      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
353      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
354      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
355        m_TreeViewSamples.signal_drag_begin().connect(
356            sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
357        );
358      m_TreeViewSamples.signal_drag_data_get().connect(      m_TreeViewSamples.signal_drag_data_get().connect(
359          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
360      );      );
# Line 242  MainWindow::MainWindow() Line 363  MainWindow::MainWindow()
363          sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)          sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
364      );      );
365      dimreg_edit.signal_dimreg_changed().connect(      dimreg_edit.signal_dimreg_changed().connect(
366          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
367      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
368          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
369      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
370          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
371      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
372          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
373        propDialog.signal_changed().connect(
374            sigc::mem_fun(*this, &MainWindow::file_changed));
375        midiRules.signal_changed().connect(
376            sigc::mem_fun(*this, &MainWindow::file_changed));
377    
378        dimreg_edit.signal_dimreg_to_be_changed().connect(
379            dimreg_to_be_changed_signal.make_slot());
380        dimreg_edit.signal_dimreg_changed().connect(
381            dimreg_changed_signal.make_slot());
382        dimreg_edit.signal_sample_ref_changed().connect(
383            sample_ref_changed_signal.make_slot());
384    
385        m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
386            sigc::hide(
387                sigc::bind(
388                    file_structure_to_be_changed_signal.make_slot(),
389                    sigc::ref(this->file)
390                )
391            )
392        );
393        m_RegionChooser.signal_instrument_struct_changed().connect(
394            sigc::hide(
395                sigc::bind(
396                    file_structure_changed_signal.make_slot(),
397                    sigc::ref(this->file)
398                )
399            )
400        );
401        m_RegionChooser.signal_region_to_be_changed().connect(
402            region_to_be_changed_signal.make_slot());
403        m_RegionChooser.signal_region_changed_signal().connect(
404            region_changed_signal.make_slot());
405    
406        note_on_signal.connect(
407            sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
408        note_off_signal.connect(
409            sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
410    
411        dimreg_all_regions.signal_toggled().connect(
412            sigc::mem_fun(*this, &MainWindow::update_dimregs));
413        dimreg_all_dimregs.signal_toggled().connect(
414            sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
415        dimreg_stereo.signal_toggled().connect(
416            sigc::mem_fun(*this, &MainWindow::update_dimregs));
417    
418      file = 0;      file = 0;
419      file_is_changed = false;      file_is_changed = false;
420    
421      show_all_children();      show_all_children();
422    
423        // start with a new gig file by default
424        on_action_file_new();
425  }  }
426    
427  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 261  MainWindow::~MainWindow() Line 430  MainWindow::~MainWindow()
430    
431  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
432  {  {
433      return file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
434  }  }
435    
436  void MainWindow::on_action_quit()  void MainWindow::on_action_quit()
437  {  {
438      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
439      hide();      hide();
440  }  }
441    
# Line 275  void MainWindow::region_changed() Line 444  void MainWindow::region_changed()
444      m_DimRegionChooser.set_region(m_RegionChooser.get_region());      m_DimRegionChooser.set_region(m_RegionChooser.get_region());
445  }  }
446    
447    gig::Instrument* MainWindow::get_instrument()
448    {
449        gig::Instrument* instrument = 0;
450        Gtk::TreeModel::const_iterator it =
451            m_TreeView.get_selection()->get_selected();
452        if (it) {
453            Gtk::TreeModel::Row row = *it;
454            instrument = row[m_Columns.m_col_instr];
455        }
456        return instrument;
457    }
458    
459    void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
460    {
461        if (all_dimregs) {
462            for (int i = 0 ; i < region->DimensionRegions ; i++) {
463                if (region->pDimensionRegions[i]) {
464                    dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
465                }
466            }
467        } else {
468            m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
469        }
470    }
471    
472    void MainWindow::update_dimregs()
473    {
474        dimreg_edit.dimregs.clear();
475        bool all_regions = dimreg_all_regions.get_active();
476        bool stereo = dimreg_stereo.get_active();
477        bool all_dimregs = dimreg_all_dimregs.get_active();
478    
479        if (all_regions) {
480            gig::Instrument* instrument = get_instrument();
481            if (instrument) {
482                for (gig::Region* region = instrument->GetFirstRegion() ;
483                     region ;
484                     region = instrument->GetNextRegion()) {
485                    add_region_to_dimregs(region, stereo, all_dimregs);
486                }
487            }
488        } else {
489            gig::Region* region = m_RegionChooser.get_region();
490            if (region) {
491                add_region_to_dimregs(region, stereo, all_dimregs);
492            }
493        }
494    }
495    
496    void MainWindow::dimreg_all_dimregs_toggled()
497    {
498        dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
499        update_dimregs();
500    }
501    
502  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
503  {  {
504        update_dimregs();
505      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());
506  }  }
507    
508  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
509  {  {
510      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      // select item in instrument menu
511        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
512      if (it) {      if (it) {
513          Gtk::TreeModel::Row row = *it;          Gtk::TreePath path(it);
514          std::cout << row[m_Columns.m_col_name] << std::endl;          int index = path[0];
515            const std::vector<Gtk::Widget*> children =
516          m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]);              instrument_menu->get_children();
517      } else {          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
         m_RegionChooser.set_instrument(0);  
518      }      }
519    
520        m_RegionChooser.set_instrument(get_instrument());
521  }  }
522    
523  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 304  void loader_progress_callback(gig::progr Line 529  void loader_progress_callback(gig::progr
529  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
530  {  {
531      {      {
532          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
533          progress = fraction;          progress = fraction;
534      }      }
535      progress_dispatcher();      progress_dispatcher();
# Line 312  void Loader::progress_callback(float fra Line 537  void Loader::progress_callback(float fra
537    
538  void Loader::thread_function()  void Loader::thread_function()
539  {  {
540      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
541      printf("Start %s\n", filename);      printf("Start %s\n", filename);
542      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
543      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 326  void Loader::thread_function() Line 551  void Loader::thread_function()
551  }  }
552    
553  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
554      : thread(0), filename(filename)      : filename(filename), thread(0)
555  {  {
556  }  }
557    
558  void Loader::launch()  void Loader::launch()
559  {  {
560    #ifdef OLD_THREADS
561      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
562    #else
563        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
564    #endif
565      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
566  }  }
567    
# Line 340  float Loader::get_progress() Line 569  float Loader::get_progress()
569  {  {
570      float res;      float res;
571      {      {
572          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
573          res = progress;          res = progress;
574      }      }
575      return res;      return res;
# Line 366  LoadDialog::LoadDialog(const Glib::ustri Line 595  LoadDialog::LoadDialog(const Glib::ustri
595  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
596  // 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.
597  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();  
598      // forget all samples that ought to be imported      // forget all samples that ought to be imported
599      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
600      // clear the samples and instruments tree views      // clear the samples and instruments tree views
601      m_refTreeModel->clear();      m_refTreeModel->clear();
602      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
603      // free libgig's gig::File instance      // remove all entries from "Instrument" menu
604      if (file) {      while (!instrument_menu->get_children().empty()) {
605          delete file;          remove_instrument_from_menu(0);
         file = NULL;  
606      }      }
607        // free libgig's gig::File instance
608        if (file && !file_is_shared) delete file;
609        file = NULL;
610        set_file_is_shared(false);
611  }  }
612    
613  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
614  {  {
615      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
616    
617        if (file_is_shared && !leaving_shared_mode_dialog()) return;
618    
619      // clear all GUI elements      // clear all GUI elements
620      __clear();      __clear();
# Line 396  void MainWindow::on_action_file_new() Line 622  void MainWindow::on_action_file_new()
622      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
623      // already add one new instrument by default      // already add one new instrument by default
624      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
625      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
626      // update GUI with that new gig::File      // update GUI with that new gig::File
627      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
628  }  }
# Line 413  bool MainWindow::close_confirmation_dial Line 639  bool MainWindow::close_confirmation_dial
639      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);
640      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
641      int response = dialog.run();      int response = dialog.run();
642        dialog.hide();
643      if (response == Gtk::RESPONSE_YES) return file_save();      if (response == Gtk::RESPONSE_YES) return file_save();
644      return response != Gtk::RESPONSE_CANCEL;      return response != Gtk::RESPONSE_CANCEL;
645  }  }
646    
647    bool MainWindow::leaving_shared_mode_dialog() {
648        Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
649        Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
650        dialog.set_secondary_text(
651            _("If you proceed to work on another instrument file, it won't be "
652              "used by the sampler until you tell the sampler explicitly to "
653              "load it."));
654        dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
655        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
656        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
657        int response = dialog.run();
658        dialog.hide();
659        return response == Gtk::RESPONSE_YES;
660    }
661    
662  void MainWindow::on_action_file_open()  void MainWindow::on_action_file_open()
663  {  {
664      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
665    
666        if (file_is_shared && !leaving_shared_mode_dialog()) return;
667    
668      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
669      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
670      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
671      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
672    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
673      Gtk::FileFilter filter;      Gtk::FileFilter filter;
674      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
675    #else
676        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
677        filter->add_pattern("*.gig");
678    #endif
679      dialog.set_filter(filter);      dialog.set_filter(filter);
680      if (current_dir != "") {      if (current_gig_dir != "") {
681          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
682      }      }
683      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
684          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
685          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
686          __clear();          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
         printf("on_action_file_open self=%x\n", Glib::Thread::self());  
687          load_file(filename.c_str());          load_file(filename.c_str());
688          current_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
689      }      }
690  }  }
691    
692  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
693  {  {
694      load_dialog = new LoadDialog("Loading...", *this);      __clear();
695        load_dialog = new LoadDialog(_("Loading..."), *this);
696      load_dialog->show_all();      load_dialog->show_all();
697      loader = new Loader(strdup(name));      loader = new Loader(strdup(name));
698      loader->signal_progress().connect(      loader->signal_progress().connect(
# Line 460  void MainWindow::load_instrument(gig::In Line 709  void MainWindow::load_instrument(gig::In
709          msg.run();          msg.run();
710          Gtk::Main::quit();          Gtk::Main::quit();
711      }      }
712        // clear all GUI elements
713        __clear();
714        // load the instrument
715      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
716      load_gig(pFile, 0 /*file name*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
717      //TODO: automatically select the given instrument      //TODO: automatically select the given instrument
718  }  }
719    
# Line 473  void MainWindow::on_loader_progress() Line 725  void MainWindow::on_loader_progress()
725  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
726  {  {
727      printf("Loader finished!\n");      printf("Loader finished!\n");
728      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
729      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
730      load_dialog->hide();      load_dialog->hide();
731  }  }
# Line 483  void MainWindow::on_action_file_save() Line 735  void MainWindow::on_action_file_save()
735      file_save();      file_save();
736  }  }
737    
738  bool MainWindow::file_save()  bool MainWindow::check_if_savable()
739  {  {
740      if (!file) return false;      if (!file) return false;
741      if (!file_has_name) return file_save_as();  
742        if (!file->GetFirstSample()) {
743            Gtk::MessageDialog(*this, _("The file could not be saved "
744                                        "because it contains no samples"),
745                               false, Gtk::MESSAGE_ERROR).run();
746            return false;
747        }
748    
749        for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ;
750             instrument = file->GetNextInstrument()) {
751            if (!instrument->GetFirstRegion()) {
752                Gtk::MessageDialog(*this, _("The file could not be saved "
753                                            "because there are instruments "
754                                            "that have no regions"),
755                                   false, Gtk::MESSAGE_ERROR).run();
756                return false;
757            }
758        }
759        return true;
760    }
761    
762    bool MainWindow::file_save()
763    {
764        if (!check_if_savable()) return false;
765        if (!file_is_shared && !file_has_name) return file_save_as();
766    
767      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
768        file_structure_to_be_changed_signal.emit(this->file);
769      try {      try {
770          file->Save();          file->Save();
771          if (file_is_changed) {          if (file_is_changed) {
# Line 496  bool MainWindow::file_save() Line 773  bool MainWindow::file_save()
773              file_is_changed = false;              file_is_changed = false;
774          }          }
775      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
776          Glib::ustring txt = "Could not save file: " + e.Message;          file_structure_changed_signal.emit(this->file);
777            Glib::ustring txt = _("Could not save file: ") + e.Message;
778          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
779          msg.run();          msg.run();
780          return false;          return false;
781      }      }
782      std::cout << "Saving file done\n" << std::flush;      std::cout << "Saving file done\n" << std::flush;
783      __import_queued_samples();      __import_queued_samples();
784        file_structure_changed_signal.emit(this->file);
785      return true;      return true;
786  }  }
787    
788  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
789  {  {
790        if (!check_if_savable()) return;
791      file_save_as();      file_save_as();
792  }  }
793    
794  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
795  {  {
     if (!file) return false;  
796      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
797      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
798      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
799      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  
800      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
801      // TODO: an overwrite dialog for gtkmm < 2.8  
802  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
803      Gtk::FileFilter filter;      Gtk::FileFilter filter;
804      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
805    #else
806        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
807        filter->add_pattern("*.gig");
808    #endif
809      dialog.set_filter(filter);      dialog.set_filter(filter);
810    
811      if (Glib::path_is_absolute(filename)) {      // set initial dir and filename of the Save As dialog
812          dialog.set_filename(filename);      // and prepare that initial filename as a copy of the gig
813      } else if (current_dir != "") {      {
814          dialog.set_current_folder(current_dir);          std::string basename = Glib::path_get_basename(filename);
815            std::string dir = Glib::path_get_dirname(filename);
816            basename = std::string(_("copy_of_")) + basename;
817            Glib::ustring copyFileName = Glib::build_filename(dir, basename);
818            if (Glib::path_is_absolute(filename)) {
819                dialog.set_filename(copyFileName);
820            } else {
821                if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
822            }
823            dialog.set_current_name(Glib::filename_display_basename(copyFileName));
824      }      }
825      dialog.set_current_name(Glib::filename_display_basename(filename));  
826        // show warning in the dialog
827        Gtk::HBox descriptionArea;
828        descriptionArea.set_spacing(15);
829        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
830        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
831    #if GTKMM_MAJOR_VERSION < 3
832        view::WrapLabel description;
833    #else
834        Gtk::Label description;
835        description.set_line_wrap();
836    #endif
837        description.set_markup(
838            _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
839              "<span style=\"italic\">\"Save\"</span> dialog instead of "
840              "<span style=\"italic\">\"Save As...\"</span> if you want to save "
841              "to the same .gig file. Using "
842              "<span style=\"italic\">\"Save As...\"</span> for writing to the "
843              "same .gig file will end up in corrupted sample wave data!\n")
844        );
845        descriptionArea.pack_start(description);
846        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
847        descriptionArea.show_all();
848    
849      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
850            file_structure_to_be_changed_signal.emit(this->file);
851          try {          try {
852              std::string filename = dialog.get_filename();              std::string filename = dialog.get_filename();
853              if (!Glib::str_has_suffix(filename, ".gig")) {              if (!Glib::str_has_suffix(filename, ".gig")) {
# Line 543  bool MainWindow::file_save_as() Line 856  bool MainWindow::file_save_as()
856              printf("filename=%s\n", filename.c_str());              printf("filename=%s\n", filename.c_str());
857              file->Save(filename);              file->Save(filename);
858              this->filename = filename;              this->filename = filename;
859              current_dir = Glib::path_get_dirname(filename);              current_gig_dir = Glib::path_get_dirname(filename);
860              set_title(Glib::filename_display_basename(filename));              set_title(Glib::filename_display_basename(filename));
861              file_has_name = true;              file_has_name = true;
862              file_is_changed = false;              file_is_changed = false;
863          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
864              Glib::ustring txt = "Could not save file: " + e.Message;              file_structure_changed_signal.emit(this->file);
865                Glib::ustring txt = _("Could not save file: ") + e.Message;
866              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
867              msg.run();              msg.run();
868              return false;              return false;
869          }          }
870          __import_queued_samples();          __import_queued_samples();
871            file_structure_changed_signal.emit(this->file);
872          return true;          return true;
873      }      }
874      return false;      return false;
# Line 570  void MainWindow::__import_queued_samples Line 885  void MainWindow::__import_queued_samples
885          SF_INFO info;          SF_INFO info;
886          info.format = 0;          info.format = 0;
887          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
888            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
889          try {          try {
890              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
891              // determine sample's bit depth              // determine sample's bit depth
892              int bitdepth;              int bitdepth;
893              switch (info.format & 0xff) {              switch (info.format & 0xff) {
894                  case SF_FORMAT_PCM_S8:                  case SF_FORMAT_PCM_S8:
                     bitdepth = 16; // we simply convert to 16 bit for now  
                     break;  
895                  case SF_FORMAT_PCM_16:                  case SF_FORMAT_PCM_16:
896                    case SF_FORMAT_PCM_U8:
897                      bitdepth = 16;                      bitdepth = 16;
898                      break;                      break;
899                  case SF_FORMAT_PCM_24:                  case SF_FORMAT_PCM_24:
                     bitdepth = 32; // we simply convert to 32 bit for now  
                     break;  
900                  case SF_FORMAT_PCM_32:                  case SF_FORMAT_PCM_32:
                     bitdepth = 32;  
                     break;  
                 case SF_FORMAT_PCM_U8:  
                     bitdepth = 16; // we simply convert to 16 bit for now  
                     break;  
901                  case SF_FORMAT_FLOAT:                  case SF_FORMAT_FLOAT:
                     bitdepth = 32;  
                     break;  
902                  case SF_FORMAT_DOUBLE:                  case SF_FORMAT_DOUBLE:
903                      bitdepth = 32; // I guess we will always truncate this to 32 bit                      bitdepth = 24;
904                      break;                      break;
905                  default:                  default:
906                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
907                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
908              }              }
909              // allocate appropriate copy buffer (TODO: for now we copy  
910              // it in one piece, might be tough for very long samples)              const int bufsize = 10000;
             // and copy sample data into buffer  
             int8_t* buffer = NULL;  
911              switch (bitdepth) {              switch (bitdepth) {
912                  case 16:                  case 16: {
913                      buffer = new int8_t[2 * info.channels * info.frames];                      short* buffer = new short[bufsize * info.channels];
914                      // libsndfile does the conversion for us (if needed)                      sf_count_t cnt = info.frames;
915                      sf_readf_short(hFile, (short*) buffer, info.frames);                      while (cnt) {
916                            // libsndfile does the conversion for us (if needed)
917                            int n = sf_readf_short(hFile, buffer, bufsize);
918                            // write from buffer directly (physically) into .gig file
919                            iter->gig_sample->Write(buffer, n);
920                            cnt -= n;
921                        }
922                        delete[] buffer;
923                      break;                      break;
924                  case 32:                  }
925                      buffer = new int8_t[4 * info.channels * info.frames];                  case 24: {
926                      // libsndfile does the conversion for us (if needed)                      int* srcbuf = new int[bufsize * info.channels];
927                      sf_readf_int(hFile, (int*) buffer, info.frames);                      uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels];
928                        sf_count_t cnt = info.frames;
929                        while (cnt) {
930                            // libsndfile returns 32 bits, convert to 24
931                            int n = sf_readf_int(hFile, srcbuf, bufsize);
932                            int j = 0;
933                            for (int i = 0 ; i < n * info.channels ; i++) {
934                                dstbuf[j++] = srcbuf[i] >> 8;
935                                dstbuf[j++] = srcbuf[i] >> 16;
936                                dstbuf[j++] = srcbuf[i] >> 24;
937                            }
938                            // write from buffer directly (physically) into .gig file
939                            iter->gig_sample->Write(dstbuf, n);
940                            cnt -= n;
941                        }
942                        delete[] srcbuf;
943                        delete[] dstbuf;
944                      break;                      break;
945                    }
946              }              }
             // write from buffer directly (physically) into .gig file  
             (*iter).gig_sample->Write(buffer, info.frames);  
947              // cleanup              // cleanup
948              sf_close(hFile);              sf_close(hFile);
949              delete[] buffer;              // let the sampler re-cache the sample if needed
950                sample_changed_signal.emit(iter->gig_sample);
951              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
952              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
953              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 628  void MainWindow::__import_queued_samples Line 955  void MainWindow::__import_queued_samples
955              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
956          } catch (std::string what) {          } catch (std::string what) {
957              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
958              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
959              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
960              ++iter;              ++iter;
961          }          }
962      }      }
963      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
964      if (error_files.size()) {      if (!error_files.empty()) {
965          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;
966          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
967          msg.run();          msg.run();
968      }      }
# Line 647  void MainWindow::on_action_file_properti Line 974  void MainWindow::on_action_file_properti
974      propDialog.deiconify();      propDialog.deiconify();
975  }  }
976    
977    void MainWindow::on_action_warn_user_on_extensions() {
978        Settings::singleton()->warnUserOnExtensions =
979            !Settings::singleton()->warnUserOnExtensions;
980    }
981    
982  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
983  {  {
 #ifdef ABOUT_DIALOG  
984      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
985    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
986        dialog.set_program_name("Gigedit");
987    #else
988        dialog.set_name("Gigedit");
989    #endif
990      dialog.set_version(VERSION);      dialog.set_version(VERSION);
991        dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
992        const std::string sComment =
993            _("Built " __DATE__ "\nUsing ") +
994            ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
995            _(
996                "Gigedit is released under the GNU General Public License.\n"
997                "\n"
998                "Please notice that this is still a very young instrument editor. "
999                "So better backup your Gigasampler files before editing them with "
1000                "this application.\n"
1001                "\n"
1002                "Please report bugs to: http://bugs.linuxsampler.org"
1003            );
1004        dialog.set_comments(sComment.c_str());
1005        dialog.set_website("http://www.linuxsampler.org");
1006        dialog.set_website_label("http://www.linuxsampler.org");
1007      dialog.run();      dialog.run();
 #endif  
1008  }  }
1009    
1010  PropDialog::PropDialog()  PropDialog::PropDialog()
1011      : table(2,1)      : eName(_("Name")),
1012          eCreationDate(_("Creation date")),
1013          eComments(_("Comments")),
1014          eProduct(_("Product")),
1015          eCopyright(_("Copyright")),
1016          eArtists(_("Artists")),
1017          eGenre(_("Genre")),
1018          eKeywords(_("Keywords")),
1019          eEngineer(_("Engineer")),
1020          eTechnician(_("Technician")),
1021          eSoftware(_("Software")),
1022          eMedium(_("Medium")),
1023          eSource(_("Source")),
1024          eSourceForm(_("Source form")),
1025          eCommissioned(_("Commissioned")),
1026          eSubject(_("Subject")),
1027          quitButton(Gtk::Stock::CLOSE),
1028          table(2, 1)
1029  {  {
1030        set_title(_("File Properties"));
1031        eName.set_width_chars(50);
1032    
1033        connect(eName, &DLS::Info::Name);
1034        connect(eCreationDate, &DLS::Info::CreationDate);
1035        connect(eComments, &DLS::Info::Comments);
1036        connect(eProduct, &DLS::Info::Product);
1037        connect(eCopyright, &DLS::Info::Copyright);
1038        connect(eArtists, &DLS::Info::Artists);
1039        connect(eGenre, &DLS::Info::Genre);
1040        connect(eKeywords, &DLS::Info::Keywords);
1041        connect(eEngineer, &DLS::Info::Engineer);
1042        connect(eTechnician, &DLS::Info::Technician);
1043        connect(eSoftware, &DLS::Info::Software);
1044        connect(eMedium, &DLS::Info::Medium);
1045        connect(eSource, &DLS::Info::Source);
1046        connect(eSourceForm, &DLS::Info::SourceForm);
1047        connect(eCommissioned, &DLS::Info::Commissioned);
1048        connect(eSubject, &DLS::Info::Subject);
1049    
1050        table.add(eName);
1051        table.add(eCreationDate);
1052        table.add(eComments);
1053        table.add(eProduct);
1054        table.add(eCopyright);
1055        table.add(eArtists);
1056        table.add(eGenre);
1057        table.add(eKeywords);
1058        table.add(eEngineer);
1059        table.add(eTechnician);
1060        table.add(eSoftware);
1061        table.add(eMedium);
1062        table.add(eSource);
1063        table.add(eSourceForm);
1064        table.add(eCommissioned);
1065        table.add(eSubject);
1066    
1067      table.set_col_spacings(5);      table.set_col_spacings(5);
1068      const char* propLabels[] = {      add(vbox);
1069          "Name:",      table.set_border_width(5);
1070          "CreationDate:",      vbox.add(table);
1071          "Comments:", // TODO: multiline      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
1072          "Product:",      buttonBox.set_layout(Gtk::BUTTONBOX_END);
1073          "Copyright:",      buttonBox.set_border_width(5);
1074          "Artists:",      buttonBox.show();
1075          "Genre:",      buttonBox.pack_start(quitButton);
1076          "Keywords:",      quitButton.set_can_default();
1077          "Engineer:",      quitButton.grab_focus();
1078          "Technician:",      quitButton.signal_clicked().connect(
1079          "Software:", // TODO: readonly          sigc::mem_fun(*this, &PropDialog::hide));
         "Medium:",  
         "Source:",  
         "SourceForm:",  
         "Commissioned:",  
         "Subject:"  
     };  
     for (int i = 0 ; i < sizeof(propLabels) / sizeof(char*) ; i++) {  
         label[i].set_text(propLabels[i]);  
         label[i].set_alignment(Gtk::ALIGN_LEFT);  
         table.attach(label[i], 0, 1, i, i + 1, Gtk::FILL, Gtk::SHRINK);  
         table.attach(entry[i], 1, 2, i, i + 1, Gtk::FILL | Gtk::EXPAND,  
                      Gtk::SHRINK);  
     }  
1080    
1081      add(table);      quitButton.show();
1082      // add_button(Gtk::Stock::CANCEL, 0);      vbox.show();
     // add_button(Gtk::Stock::OK, 1);  
1083      show_all_children();      show_all_children();
1084  }  }
1085    
1086  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1087  {  {
1088      entry[0].set_text(info->Name);      update(info);
     entry[1].set_text(info->CreationDate);  
     entry[2].set_text(Glib::convert(info->Comments, "UTF-8", "ISO-8859-1"));  
     entry[3].set_text(info->Product);  
     entry[4].set_text(info->Copyright);  
     entry[5].set_text(info->Artists);  
     entry[6].set_text(info->Genre);  
     entry[7].set_text(info->Keywords);  
     entry[8].set_text(info->Engineer);  
     entry[9].set_text(info->Technician);  
     entry[10].set_text(info->Software);  
     entry[11].set_text(info->Medium);  
     entry[12].set_text(info->Source);  
     entry[13].set_text(info->SourceForm);  
     entry[14].set_text(info->Commissioned);  
     entry[15].set_text(info->Subject);  
 }  
   
 void InstrumentProps::add_prop(LabelWidget& prop)  
 {  
     table.attach(prop.label, 0, 1, rowno, rowno + 1,  
                  Gtk::FILL, Gtk::SHRINK);  
     table.attach(prop.widget, 1, 2, rowno, rowno + 1,  
                  Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);  
     rowno++;  
     prop.signal_changed_by_user().connect(instrument_changed.make_slot());  
1089  }  }
1090    
1091  InstrumentProps::InstrumentProps()  
1092      : table(2,1),  void InstrumentProps::set_Name(const gig::String& name)
       quitButton(Gtk::Stock::CLOSE),  
       eName("Name"),  
       eIsDrum("IsDrum"),  
       eMIDIBank("MIDIBank", 0, 16383),  
       eMIDIProgram("MIDIProgram"),  
       eAttenuation("Attenuation", 0, 96, 0, 1),  
       eGainPlus6("Gain +6dB", eAttenuation, -6),  
       eEffectSend("EffectSend", 0, 65535),  
       eFineTune("FineTune", -8400, 8400),  
       ePitchbendRange("PitchbendRange", 0, 12),  
       ePianoReleaseMode("PianoReleaseMode"),  
       eDimensionKeyRangeLow("DimensionKeyRangeLow"),  
       eDimensionKeyRangeHigh("DimensionKeyRangeHigh")  
1093  {  {
1094      set_title("Instrument properties");      m->pInfo->Name = name;
1095    }
1096    
1097    void InstrumentProps::update_name()
1098    {
1099        update_model++;
1100        eName.set_value(m->pInfo->Name);
1101        update_model--;
1102    }
1103    
1104    void InstrumentProps::set_IsDrum(bool value)
1105    {
1106        m->IsDrum = value;
1107    }
1108    
1109    void InstrumentProps::set_MIDIBank(uint16_t value)
1110    {
1111        m->MIDIBank = value;
1112    }
1113    
1114    void InstrumentProps::set_MIDIProgram(uint32_t value)
1115    {
1116        m->MIDIProgram = value;
1117    }
1118    
1119    InstrumentProps::InstrumentProps() :
1120        quitButton(Gtk::Stock::CLOSE),
1121        table(2,1),
1122        eName(_("Name")),
1123        eIsDrum(_("Is drum")),
1124        eMIDIBank(_("MIDI bank"), 0, 16383),
1125        eMIDIProgram(_("MIDI program")),
1126        eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1127        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1128        eEffectSend(_("Effect send"), 0, 65535),
1129        eFineTune(_("Fine tune"), -8400, 8400),
1130        ePitchbendRange(_("Pitchbend range"), 0, 12),
1131        ePianoReleaseMode(_("Piano release mode")),
1132        eDimensionKeyRangeLow(_("Keyswitching range low")),
1133        eDimensionKeyRangeHigh(_("Keyswitching range high"))
1134    {
1135        set_title(_("Instrument Properties"));
1136    
1137        eDimensionKeyRangeLow.set_tip(
1138            _("start of the keyboard area which should switch the "
1139              "\"keyswitching\" dimension")
1140        );
1141        eDimensionKeyRangeHigh.set_tip(
1142            _("end of the keyboard area which should switch the "
1143              "\"keyswitching\" dimension")
1144        );
1145    
1146        connect(eName, &InstrumentProps::set_Name);
1147        connect(eIsDrum, &InstrumentProps::set_IsDrum);
1148        connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1149        connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
1150        connect(eAttenuation, &gig::Instrument::Attenuation);
1151        connect(eGainPlus6, &gig::Instrument::Attenuation);
1152        connect(eEffectSend, &gig::Instrument::EffectSend);
1153        connect(eFineTune, &gig::Instrument::FineTune);
1154        connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1155        connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1156        connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1157                &gig::Instrument::DimensionKeyRange);
1158    
1159        eName.signal_value_changed().connect(sig_name_changed.make_slot());
1160    
     rowno = 0;  
1161      table.set_col_spacings(5);      table.set_col_spacings(5);
1162    
1163      add_prop(eName);      table.add(eName);
1164      add_prop(eIsDrum);      table.add(eIsDrum);
1165      add_prop(eMIDIBank);      table.add(eMIDIBank);
1166      add_prop(eMIDIProgram);      table.add(eMIDIProgram);
1167      add_prop(eAttenuation);      table.add(eAttenuation);
1168      add_prop(eGainPlus6);      table.add(eGainPlus6);
1169      add_prop(eEffectSend);      table.add(eEffectSend);
1170      add_prop(eFineTune);      table.add(eFineTune);
1171      add_prop(ePitchbendRange);      table.add(ePitchbendRange);
1172      add_prop(ePianoReleaseMode);      table.add(ePianoReleaseMode);
1173      add_prop(eDimensionKeyRangeLow);      table.add(eDimensionKeyRangeLow);
1174      add_prop(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
   
     eDimensionKeyRangeLow.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed));  
     eDimensionKeyRangeHigh.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed));  
1175    
1176      add(vbox);      add(vbox);
1177      table.set_border_width(5);      table.set_border_width(5);
# Line 770  InstrumentProps::InstrumentProps() Line 1182  InstrumentProps::InstrumentProps()
1182      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1183      buttonBox.show();      buttonBox.show();
1184      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1185      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1186      quitButton.grab_focus();      quitButton.grab_focus();
1187    
1188      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 783  InstrumentProps::InstrumentProps() Line 1195  InstrumentProps::InstrumentProps()
1195    
1196  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1197  {  {
1198      eName.set_ptr(&instrument->pInfo->Name);      update(instrument);
     eIsDrum.set_ptr(&instrument->IsDrum);  
     eMIDIBank.set_ptr(&instrument->MIDIBank);  
     eMIDIProgram.set_ptr(&instrument->MIDIProgram);  
     eAttenuation.set_ptr(&instrument->Attenuation);  
     eGainPlus6.set_ptr(&instrument->Attenuation);  
     eEffectSend.set_ptr(&instrument->EffectSend);  
     eFineTune.set_ptr(&instrument->FineTune);  
     ePitchbendRange.set_ptr(&instrument->PitchbendRange);  
     ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode);  
     eDimensionKeyRangeLow.set_ptr(0);  
     eDimensionKeyRangeHigh.set_ptr(0);  
     eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low);  
     eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high);  
 }  
1199    
1200  void InstrumentProps::key_range_low_changed()      update_model++;
1201  {      eName.set_value(instrument->pInfo->Name);
1202      double l = eDimensionKeyRangeLow.get_value();      eIsDrum.set_value(instrument->IsDrum);
1203      double h = eDimensionKeyRangeHigh.get_value();      eMIDIBank.set_value(instrument->MIDIBank);
1204      if (h < l) eDimensionKeyRangeHigh.set_value(l);      eMIDIProgram.set_value(instrument->MIDIProgram);
1205        update_model--;
1206  }  }
1207    
 void InstrumentProps::key_range_high_changed()  
 {  
     double l = eDimensionKeyRangeLow.get_value();  
     double h = eDimensionKeyRangeHigh.get_value();  
     if (h < l) eDimensionKeyRangeLow.set_value(h);  
 }  
   
 sigc::signal<void> InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1208    
1209  void MainWindow::file_changed()  void MainWindow::file_changed()
1210  {  {
# Line 826  void MainWindow::file_changed() Line 1214  void MainWindow::file_changed()
1214      }      }
1215  }  }
1216    
1217  void MainWindow::load_gig(gig::File* gig, const char* filename)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1218  {  {
1219      file = 0;      file = 0;
1220        set_file_is_shared(isSharedInstrument);
1221    
1222      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename = filename ? filename : _("Unsaved Gig File");
1223      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
# Line 837  void MainWindow::load_gig(gig::File* gig Line 1226  void MainWindow::load_gig(gig::File* gig
1226    
1227      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1228    
1229      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;  
1230      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1231           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1232            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1233    
1234          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1235          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1236          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1237          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1238          // create a menu item for this instrument  
1239          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++;  
1240      }      }
1241      instrument_menu->show();      instrument_name_connection.unblock();
1242      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1243    
1244      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1245          if (group->Name != "") {          if (group->Name != "") {
1246              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1247              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1248              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1249              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1250              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1251              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 875  void MainWindow::load_gig(gig::File* gig Line 1253  void MainWindow::load_gig(gig::File* gig
1253                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1254                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1255                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1256                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1257                        gig_to_utf8(sample->pInfo->Name);
1258                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1259                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1260              }              }
# Line 885  void MainWindow::load_gig(gig::File* gig Line 1264  void MainWindow::load_gig(gig::File* gig
1264      file = gig;      file = gig;
1265    
1266      // select the first instrument      // select the first instrument
1267      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1268      tree_sel_ref->select(Gtk::TreePath("0"));  
1269        instr_props_set_instrument();
1270        gig::Instrument* instrument = get_instrument();
1271        if (instrument) {
1272            midiRules.set_instrument(instrument);
1273        }
1274    }
1275    
1276    bool MainWindow::instr_props_set_instrument()
1277    {
1278        instrumentProps.signal_name_changed().clear();
1279    
1280        Gtk::TreeModel::const_iterator it =
1281            m_TreeView.get_selection()->get_selected();
1282        if (it) {
1283            Gtk::TreeModel::Row row = *it;
1284            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1285    
1286            instrumentProps.set_instrument(instrument);
1287    
1288            // make sure instrument tree is updated when user changes the
1289            // instrument name in instrument properties window
1290            instrumentProps.signal_name_changed().connect(
1291                sigc::bind(
1292                    sigc::mem_fun(*this,
1293                                  &MainWindow::instr_name_changed_by_instr_props),
1294                    it));
1295        } else {
1296            instrumentProps.hide();
1297        }
1298        return it;
1299  }  }
1300    
1301  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
1302  {  {
1303      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      if (instr_props_set_instrument()) {
1304      Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();          instrumentProps.show();
1305      if (it)          instrumentProps.deiconify();
1306        }
1307    }
1308    
1309    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1310    {
1311        Gtk::TreeModel::Row row = *it;
1312        Glib::ustring name = row[m_Columns.m_col_name];
1313    
1314        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1315        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1316        if (gigname != name) {
1317            row[m_Columns.m_col_name] = gigname;
1318        }
1319    }
1320    
1321    void MainWindow::show_midi_rules()
1322    {
1323        if (gig::Instrument* instrument = get_instrument())
1324      {      {
1325          Gtk::TreeModel::Row row = *it;          midiRules.set_instrument(instrument);
1326          if (row[m_Columns.m_col_instr])          midiRules.show();
1327          {          midiRules.deiconify();
             instrumentProps.set_instrument(row[m_Columns.m_col_instr]);  
             instrumentProps.show();  
             instrumentProps.deiconify();  
         }  
1328      }      }
1329  }  }
1330    
1331    void MainWindow::on_action_view_status_bar() {
1332        Gtk::CheckMenuItem* item =
1333            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
1334        if (!item) {
1335            std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n";
1336            return;
1337        }
1338        if (item->get_active()) m_StatusBar.show();
1339        else                    m_StatusBar.hide();
1340    }
1341    
1342    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1343        Gtk::CheckMenuItem* item =
1344            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1345        if (!item) {
1346            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1347            return true;
1348        }
1349        return item->get_active();
1350    }
1351    
1352    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1353        Gtk::CheckMenuItem* item =
1354            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1355        if (!item) {
1356            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1357            return true;
1358        }
1359        return item->get_active();
1360    }
1361    
1362    bool MainWindow::is_copy_samples_loop_enabled() const {
1363        Gtk::CheckMenuItem* item =
1364            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1365        if (!item) {
1366            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1367            return true;
1368        }
1369        return item->get_active();
1370    }
1371    
1372  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1373  {  {
1374      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1375          show_instr_props();          show_instr_props();
1376      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1377            // gig v2 files have no midi rules
1378            static_cast<Gtk::MenuItem*>(
1379                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1380                    !(file->pVersion && file->pVersion->major == 2));
1381          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1382      }      }
1383  }  }
1384    
1385  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1386      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1387            const std::vector<Gtk::Widget*> children =
1388                instrument_menu->get_children();
1389            std::vector<Gtk::Widget*>::const_iterator it =
1390                find(children.begin(), children.end(), item);
1391            if (it != children.end()) {
1392                int index = it - children.begin();
1393                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1394    
1395                m_RegionChooser.set_instrument(file->GetInstrument(index));
1396            }
1397        }
1398  }  }
1399    
1400  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 945  void MainWindow::on_sample_treeview_butt Line 1424  void MainWindow::on_sample_treeview_butt
1424      }      }
1425  }  }
1426    
1427  void MainWindow::on_action_add_instrument() {  
1428      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1429      if (!file) return;      const Glib::ustring& name, int position) {
1430      gig::Instrument* instrument = file->AddInstrument();  
1431      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1432      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1433          "Unnamed Instrument " + ToString(__instrument_indexer);      if (!children.empty()) {
1434            instrument_group =
1435                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1436        }
1437        Gtk::RadioMenuItem* item =
1438            new Gtk::RadioMenuItem(instrument_group, name);
1439        if (position < 0) {
1440            instrument_menu->append(*item);
1441        } else {
1442            instrument_menu->insert(*item, position);
1443        }
1444        item->show();
1445        item->signal_activate().connect(
1446            sigc::bind(
1447                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1448                item));
1449        return item;
1450    }
1451    
1452    void MainWindow::remove_instrument_from_menu(int index) {
1453        const std::vector<Gtk::Widget*> children =
1454            instrument_menu->get_children();
1455        Gtk::Widget* child = children[index];
1456        instrument_menu->remove(*child);
1457        delete child;
1458    }
1459    
1460    void MainWindow::add_instrument(gig::Instrument* instrument) {
1461        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1462    
1463      // update instrument tree view      // update instrument tree view
1464        instrument_name_connection.block();
1465      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1466      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1467      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1468      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1469        instrument_name_connection.unblock();
1470    
1471        add_instrument_to_menu(name);
1472    
1473        m_TreeView.get_selection()->select(iterInstr);
1474    
1475      file_changed();      file_changed();
1476  }  }
1477    
1478    void MainWindow::on_action_add_instrument() {
1479        static int __instrument_indexer = 0;
1480        if (!file) return;
1481        gig::Instrument* instrument = file->AddInstrument();
1482        __instrument_indexer++;
1483        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1484                                                ToString(__instrument_indexer));
1485    
1486        add_instrument(instrument);
1487    }
1488    
1489    void MainWindow::on_action_duplicate_instrument() {
1490        if (!file) return;
1491    
1492        // retrieve the currently selected instrument
1493        // (being the original instrument to be duplicated)
1494        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1495        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1496        if (!itSelection) return;
1497        Gtk::TreeModel::Row row = *itSelection;
1498        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1499        if (!instrOrig) return;
1500    
1501        // duplicate the orginal instrument
1502        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1503        instrNew->pInfo->Name =
1504            instrOrig->pInfo->Name +
1505            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1506    
1507        add_instrument(instrNew);
1508    }
1509    
1510  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1511      if (!file) return;      if (!file) return;
1512        if (file_is_shared) {
1513            Gtk::MessageDialog msg(
1514                *this,
1515                 _("You cannot delete an instrument from this file, since it's "
1516                   "currently used by the sampler."),
1517                 false, Gtk::MESSAGE_INFO
1518            );
1519            msg.run();
1520            return;
1521        }
1522    
1523      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1524      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
1525      if (it) {      if (it) {
1526          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1527          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1528          try {          try {
1529                Gtk::TreePath path(it);
1530                int index = path[0];
1531    
1532              // remove instrument from the gig file              // remove instrument from the gig file
1533              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1534              file_changed();              file_changed();
1535    
1536                remove_instrument_from_menu(index);
1537    
1538                // remove row from instruments tree view
1539                m_refTreeModel->erase(it);
1540    
1541    #if GTKMM_MAJOR_VERSION < 3
1542                // select another instrument (in gtk3 this is done
1543                // automatically)
1544                if (!m_refTreeModel->children().empty()) {
1545                    if (index == m_refTreeModel->children().size()) {
1546                        index--;
1547                    }
1548                    m_TreeView.get_selection()->select(
1549                        Gtk::TreePath(ToString(index)));
1550                }
1551    #endif
1552                instr_props_set_instrument();
1553                instr = get_instrument();
1554                if (instr) {
1555                    midiRules.set_instrument(instr);
1556                } else {
1557                    midiRules.hide();
1558                }
1559          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1560              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1561              msg.run();              msg.run();
# Line 983  void MainWindow::on_action_remove_instru Line 1566  void MainWindow::on_action_remove_instru
1566  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
1567      //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
1568      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
1569          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
1570      );      );
1571      msg.run();      msg.run();
1572  }  }
# Line 992  void MainWindow::on_action_add_group() { Line 1575  void MainWindow::on_action_add_group() {
1575      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1576      if (!file) return;      if (!file) return;
1577      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1578      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
1579      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1580      __sample_indexer++;      __sample_indexer++;
1581      // update sample tree view      // update sample tree view
1582      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1583      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1584      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1585      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1586      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1587      file_changed();      file_changed();
# Line 1026  void MainWindow::on_action_add_sample() Line 1609  void MainWindow::on_action_add_sample()
1609      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1610      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1611      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1612      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1613      const char* supportedFileTypes[] = {      // matches all file types supported by libsndfile
1614    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1615        Gtk::FileFilter soundfilter;
1616    #else
1617        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1618    #endif
1619        const char* const supportedFileTypes[] = {
1620          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1621          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
1622          "*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64",          "*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64",
1623          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1624          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1625      };      };
1626        const char* soundfiles = _("Sound Files");
1627        const char* allfiles = _("All Files");
1628    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1629      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1630          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1631      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
1632      Gtk::FileFilter allpassfilter; // matches every file  
1633        // matches every file
1634        Gtk::FileFilter allpassfilter;
1635      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1636      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
1637    #else
1638        for (int i = 0; supportedFileTypes[i]; i++)
1639            soundfilter->add_pattern(supportedFileTypes[i]);
1640        soundfilter->set_name(soundfiles);
1641    
1642        // matches every file
1643        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1644        allpassfilter->add_pattern("*.*");
1645        allpassfilter->set_name(allfiles);
1646    #endif
1647      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1648      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1649        if (current_sample_dir != "") {
1650            dialog.set_current_folder(current_sample_dir);
1651        }
1652      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1653            current_sample_dir = dialog.get_current_folder();
1654          Glib::ustring error_files;          Glib::ustring error_files;
1655          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1656          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1657               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1658              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1659              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1053  void MainWindow::on_action_add_sample() Line 1661  void MainWindow::on_action_add_sample()
1661              info.format = 0;              info.format = 0;
1662              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1663              try {              try {
1664                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
1665                  int bitdepth;                  int bitdepth;
1666                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
1667                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
                         bitdepth = 16; // we simply convert to 16 bit for now  
                         break;  
1668                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
1669                        case SF_FORMAT_PCM_U8:
1670                          bitdepth = 16;                          bitdepth = 16;
1671                          break;                          break;
1672                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
                         bitdepth = 32; // we simply convert to 32 bit for now  
                         break;  
1673                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
                         bitdepth = 32;  
                         break;  
                     case SF_FORMAT_PCM_U8:  
                         bitdepth = 16; // we simply convert to 16 bit for now  
                         break;  
1674                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
                         bitdepth = 32;  
                         break;  
1675                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
1676                          bitdepth = 32; // I guess we will always truncate this to 32 bit                          bitdepth = 24;
1677                          break;                          break;
1678                      default:                      default:
1679                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
1680                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
1681                  }                  }
1682                  // add a new sample to the .gig file                  // add a new sample to the .gig file
1683                  gig::Sample* sample = file->AddSample();                  gig::Sample* sample = file->AddSample();
1684                  // file name without path                  // file name without path
1685                  sample->pInfo->Name = (*iter).substr((*iter).rfind('/') + 1).raw();                  Glib::ustring filename = Glib::filename_display_basename(*iter);
1686                    // remove file extension if there is one
1687                    for (int i = 0; supportedFileTypes[i]; i++) {
1688                        if (Glib::str_has_suffix(filename, supportedFileTypes[i] + 1)) {
1689                            filename.erase(filename.length() - strlen(supportedFileTypes[i] + 1));
1690                            break;
1691                        }
1692                    }
1693                    sample->pInfo->Name = gig_from_utf8(filename);
1694                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1695                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1696                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
1697                  sample->SamplesPerSecond = info.samplerate;                  sample->SamplesPerSecond = info.samplerate;
1698                    sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond;
1699                    sample->BlockAlign = sample->FrameSize;
1700                    sample->SamplesTotal = info.frames;
1701    
1702                    SF_INSTRUMENT instrument;
1703                    if (sf_command(hFile, SFC_GET_INSTRUMENT,
1704                                   &instrument, sizeof(instrument)) != SF_FALSE)
1705                    {
1706                        sample->MIDIUnityNote = instrument.basenote;
1707                        sample->FineTune      = instrument.detune;
1708    
1709                        if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1710                            sample->Loops = 1;
1711    
1712                            switch (instrument.loops[0].mode) {
1713                            case SF_LOOP_FORWARD:
1714                                sample->LoopType = gig::loop_type_normal;
1715                                break;
1716                            case SF_LOOP_BACKWARD:
1717                                sample->LoopType = gig::loop_type_backward;
1718                                break;
1719                            case SF_LOOP_ALTERNATING:
1720                                sample->LoopType = gig::loop_type_bidirectional;
1721                                break;
1722                            }
1723                            sample->LoopStart = instrument.loops[0].start;
1724                            sample->LoopEnd = instrument.loops[0].end;
1725                            sample->LoopPlayCount = instrument.loops[0].count;
1726                            sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1727                        }
1728                    }
1729    
1730                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
1731                  // physically when File::Save() is called)                  // physically when File::Save() is called)
1732                  sample->Resize(info.frames);                  sample->Resize(info.frames);
# Line 1104  void MainWindow::on_action_add_sample() Line 1742  void MainWindow::on_action_add_sample()
1742                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1743                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1744                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1745                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1746                        gig_to_utf8(sample->pInfo->Name);
1747                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1748                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1749                  // close sound file                  // close sound file
1750                  sf_close(hFile);                  sf_close(hFile);
1751                  file_changed();                  file_changed();
1752              } 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)
1753                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1754                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1755              }              }
1756          }          }
1757          // 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
1758          if (error_files.size()) {          if (!error_files.empty()) {
1759              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;
1760                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1761                msg.run();
1762            }
1763        }
1764    }
1765    
1766    void MainWindow::on_action_replace_all_samples_in_all_groups()
1767    {
1768        if (!file) return;
1769        Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1770                                      Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1771        const char* str =
1772            _("This is a very specific function. It tries to replace all samples "
1773              "in the current gig file by samples located in the chosen "
1774              "directory.\n\n"
1775              "It works like this: For each sample in the gig file, it tries to "
1776              "find a sample file in the selected directory with the same name as "
1777              "the sample in the gig file. Optionally, you can add a filename "
1778              "extension below, which will be added to the filename expected to be "
1779              "found. That is, assume you have a gig file with a sample called "
1780              "'Snare', if you enter '.wav' below (like it's done by default), it "
1781              "expects to find a sample file called 'Snare.wav' and will replace "
1782              "the sample in the gig file accordingly. If you don't need an "
1783              "extension, blank the field below. Any gig sample where no "
1784              "appropriate sample file could be found will be reported and left "
1785              "untouched.\n");
1786    #if GTKMM_MAJOR_VERSION < 3
1787        view::WrapLabel description(str);
1788    #else
1789        Gtk::Label description(str);
1790        description.set_line_wrap();
1791    #endif
1792        Gtk::HBox entryArea;
1793        Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1794        Gtk::Entry postfixEntryBox;
1795        postfixEntryBox.set_text(".wav");
1796        entryArea.pack_start(entryLabel);
1797        entryArea.pack_start(postfixEntryBox);
1798        dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
1799        dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
1800        description.show();
1801        entryArea.show_all();
1802        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1803        dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
1804        dialog.set_select_multiple(false);
1805        if (current_sample_dir != "") {
1806            dialog.set_current_folder(current_sample_dir);
1807        }
1808        if (dialog.run() == Gtk::RESPONSE_OK)
1809        {
1810            current_sample_dir = dialog.get_current_folder();
1811            Glib::ustring error_files;
1812            std::string folder = dialog.get_filename();
1813            for (gig::Sample* sample = file->GetFirstSample();
1814                 sample; sample = file->GetNextSample())
1815            {
1816                std::string filename =
1817                    folder + G_DIR_SEPARATOR_S +
1818                    Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1819                                             postfixEntryBox.get_text());
1820                SF_INFO info;
1821                info.format = 0;
1822                SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
1823                try
1824                {
1825                    if (!hFile) throw std::string(_("could not open file"));
1826                    int bitdepth;
1827                    switch (info.format & 0xff) {
1828                        case SF_FORMAT_PCM_S8:
1829                        case SF_FORMAT_PCM_16:
1830                        case SF_FORMAT_PCM_U8:
1831                            bitdepth = 16;
1832                            break;
1833                        case SF_FORMAT_PCM_24:
1834                        case SF_FORMAT_PCM_32:
1835                        case SF_FORMAT_FLOAT:
1836                        case SF_FORMAT_DOUBLE:
1837                            bitdepth = 24;
1838                            break;
1839                        default:
1840                            sf_close(hFile);
1841                            throw std::string(_("format not supported"));
1842                    }
1843                    SampleImportItem sched_item;
1844                    sched_item.gig_sample  = sample;
1845                    sched_item.sample_path = filename;
1846                    m_SampleImportQueue.push_back(sched_item);
1847                    sf_close(hFile);
1848                    file_changed();
1849                }
1850                catch (std::string what)
1851                {
1852                    if (!error_files.empty()) error_files += "\n";
1853                    error_files += Glib::filename_to_utf8(filename) +
1854                        " (" + what + ")";
1855                }
1856            }
1857            // show error message box when some file(s) could not be opened / added
1858            if (!error_files.empty()) {
1859                Glib::ustring txt =
1860                    _("Could not replace the following sample(s):\n") + error_files;
1861              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1862              msg.run();              msg.run();
1863          }          }
# Line 1136  void MainWindow::on_action_remove_sample Line 1876  void MainWindow::on_action_remove_sample
1876          try {          try {
1877              // remove group or sample from the gig file              // remove group or sample from the gig file
1878              if (group) {              if (group) {
1879                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1880                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1881                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1882                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
1883                       pSample; pSample = group->GetNextSample()) {                       pSample; pSample = group->GetNextSample()) {
1884                      members.push_back(pSample);                      members.push_back(pSample);
1885                  }                  }
1886                    // notify everybody that we're going to remove these samples
1887                    samples_to_be_removed_signal.emit(members);
1888                  // delete the group in the .gig file including the                  // delete the group in the .gig file including the
1889                  // samples that belong to the group                  // samples that belong to the group
1890                  file->DeleteGroup(group);                  file->DeleteGroup(group);
1891                    // notify that we're done with removal
1892                    samples_removed_signal.emit();
1893                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
1894                  // them from the import queue                  // them from the import queue
1895                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
# Line 1162  void MainWindow::on_action_remove_sample Line 1906  void MainWindow::on_action_remove_sample
1906                  }                  }
1907                  file_changed();                  file_changed();
1908              } else if (sample) {              } else if (sample) {
1909                    // notify everybody that we're going to remove this sample
1910                    std::list<gig::Sample*> lsamples;
1911                    lsamples.push_back(sample);
1912                    samples_to_be_removed_signal.emit(lsamples);
1913                  // remove sample from the .gig file                  // remove sample from the .gig file
1914                  file->DeleteSample(sample);                  file->DeleteSample(sample);
1915                    // notify that we're done with removal
1916                    samples_removed_signal.emit();
1917                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
1918                  // the import queue                  // the import queue
1919                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
# Line 1175  void MainWindow::on_action_remove_sample Line 1925  void MainWindow::on_action_remove_sample
1925                          break;                          break;
1926                      }                      }
1927                  }                  }
1928                    dimreg_changed();
1929                  file_changed();                  file_changed();
1930              }              }
1931              // remove respective row(s) from samples tree view              // remove respective row(s) from samples tree view
1932              m_refSamplesTreeModel->erase(it);              m_refSamplesTreeModel->erase(it);
1933          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1934                // pretend we're done with removal (i.e. to avoid dead locks)
1935                samples_removed_signal.emit();
1936                // show error message
1937              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1938              msg.run();              msg.run();
1939          }          }
1940      }      }
1941  }  }
1942    
1943    // For some reason drag_data_get gets called two times for each
1944    // drag'n'drop (at least when target is an Entry). This work-around
1945    // makes sure the code in drag_data_get and drop_drag_data_received is
1946    // only executed once, as drag_begin only gets called once.
1947    void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
1948    {
1949        first_call_to_drag_data_get = true;
1950    }
1951    
1952  void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,  void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
1953                                                    Gtk::SelectionData& selection_data, guint, guint)                                                    Gtk::SelectionData& selection_data, guint, guint)
1954  {  {
1955        if (!first_call_to_drag_data_get) return;
1956        first_call_to_drag_data_get = false;
1957    
1958      // get selected sample      // get selected sample
1959      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
1960      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
# Line 1206  void MainWindow::on_sample_label_drop_dr Line 1972  void MainWindow::on_sample_label_drop_dr
1972      const Glib::RefPtr<Gdk::DragContext>& context, int, int,      const Glib::RefPtr<Gdk::DragContext>& context, int, int,
1973      const Gtk::SelectionData& selection_data, guint, guint time)      const Gtk::SelectionData& selection_data, guint, guint time)
1974  {  {
     gig::DimensionRegion* dimregion = m_DimRegionChooser.get_dimregion();  
1975      gig::Sample* sample = *((gig::Sample**) selection_data.get_data());      gig::Sample* sample = *((gig::Sample**) selection_data.get_data());
1976    
1977      if (sample && dimregion && selection_data.get_length() == sizeof(gig::Sample*)) {      if (sample && selection_data.get_length() == sizeof(gig::Sample*)) {
1978          if (sample != dimregion->pSample) {          std::cout << "Drop received sample \"" <<
1979              dimregion->pSample = sample;              sample->pInfo->Name << "\"" << std::endl;
1980              dimreg_edit.wSample->set_text(dimregion->pSample->pInfo->Name.c_str());          // drop success
1981              std::cout << "Drop received sample \"" <<          context->drop_reply(true, time);
1982                  dimregion->pSample->pInfo->Name.c_str() << "\"" << std::endl;  
1983              // drop success          //TODO: we should better move most of the following code to DimRegionEdit::set_sample()
1984              context->drop_reply(true, time);  
1985              file_changed();          // notify everybody that we're going to alter the region
1986              return;          gig::Region* region = m_RegionChooser.get_region();
1987            region_to_be_changed_signal.emit(region);
1988    
1989            // find the samplechannel dimension
1990            gig::dimension_def_t* stereo_dimension = 0;
1991            for (int i = 0 ; i < region->Dimensions ; i++) {
1992                if (region->pDimensionDefinitions[i].dimension ==
1993                    gig::dimension_samplechannel) {
1994                    stereo_dimension = &region->pDimensionDefinitions[i];
1995                    break;
1996                }
1997            }
1998            bool channels_changed = false;
1999            if (sample->Channels == 1 && stereo_dimension) {
2000                // remove the samplechannel dimension
2001                region->DeleteDimension(stereo_dimension);
2002                channels_changed = true;
2003                region_changed();
2004            }
2005            dimreg_edit.set_sample(
2006                sample,
2007                is_copy_samples_unity_note_enabled(),
2008                is_copy_samples_fine_tune_enabled(),
2009                is_copy_samples_loop_enabled()
2010            );
2011    
2012            if (sample->Channels == 2 && !stereo_dimension) {
2013                // add samplechannel dimension
2014                gig::dimension_def_t dim;
2015                dim.dimension = gig::dimension_samplechannel;
2016                dim.bits = 1;
2017                dim.zones = 2;
2018                region->AddDimension(&dim);
2019                channels_changed = true;
2020                region_changed();
2021          }          }
2022            if (channels_changed) {
2023                // unmap all samples with wrong number of channels
2024                // TODO: maybe there should be a warning dialog for this
2025                for (int i = 0 ; i < region->DimensionRegions ; i++) {
2026                    gig::DimensionRegion* d = region->pDimensionRegions[i];
2027                    if (d->pSample && d->pSample->Channels != sample->Channels) {
2028                        gig::Sample* oldref = d->pSample;
2029                        d->pSample = NULL;
2030                        sample_ref_changed_signal.emit(oldref, NULL);
2031                    }
2032                }
2033            }
2034    
2035            // notify we're done with altering
2036            region_changed_signal.emit(region);
2037    
2038            file_changed();
2039    
2040            return;
2041      }      }
2042      // drop failed      // drop failed
2043      context->drop_reply(false, time);      context->drop_reply(false, time);
# Line 1232  void MainWindow::sample_name_changed(con Line 2050  void MainWindow::sample_name_changed(con
2050      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2051      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2052      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2053        gig::String gigname(gig_from_utf8(name));
2054      if (group) {      if (group) {
2055          if (group->Name != name) {          if (group->Name != gigname) {
2056              group->Name = name;              group->Name = gigname;
2057              printf("group name changed\n");              printf("group name changed\n");
2058              file_changed();              file_changed();
2059          }          }
2060      } else if (sample) {      } else if (sample) {
2061          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2062              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2063              printf("sample name changed\n");              printf("sample name changed\n");
2064              file_changed();              file_changed();
2065          }          }
# Line 1252  void MainWindow::instrument_name_changed Line 2071  void MainWindow::instrument_name_changed
2071      if (!iter) return;      if (!iter) return;
2072      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2073      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2074    
2075        // change name in instrument menu
2076        int index = path[0];
2077        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2078        if (index < children.size()) {
2079    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2080            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2081    #else
2082            remove_instrument_from_menu(index);
2083            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2084            item->set_active();
2085    #endif
2086        }
2087    
2088        // change name in gig
2089      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2090      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2091          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2092            instrument->pInfo->Name = gigname;
2093    
2094            // change name in the instrument properties window
2095            if (instrumentProps.get_instrument() == instrument) {
2096                instrumentProps.update_name();
2097            }
2098    
2099          file_changed();          file_changed();
2100      }      }
2101  }  }
2102    
2103    void MainWindow::set_file_is_shared(bool b) {
2104        this->file_is_shared = b;
2105    
2106        if (file_is_shared) {
2107            m_AttachedStateLabel.set_label(_("live-mode"));
2108            m_AttachedStateImage.set(
2109                Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
2110            );
2111        } else {
2112            m_AttachedStateLabel.set_label(_("stand-alone"));
2113            m_AttachedStateImage.set(
2114                Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
2115            );
2116        }
2117    }
2118    
2119    sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2120        return file_structure_to_be_changed_signal;
2121    }
2122    
2123    sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() {
2124        return file_structure_changed_signal;
2125    }
2126    
2127    sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() {
2128        return samples_to_be_removed_signal;
2129    }
2130    
2131    sigc::signal<void>& MainWindow::signal_samples_removed() {
2132        return samples_removed_signal;
2133    }
2134    
2135    sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() {
2136        return region_to_be_changed_signal;
2137    }
2138    
2139    sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() {
2140        return region_changed_signal;
2141    }
2142    
2143    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2144        return sample_changed_signal;
2145    }
2146    
2147    sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
2148        return sample_ref_changed_signal;
2149    }
2150    
2151    sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() {
2152        return dimreg_to_be_changed_signal;
2153    }
2154    
2155    sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
2156        return dimreg_changed_signal;
2157    }
2158    
2159    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() {
2160        return note_on_signal;
2161    }
2162    
2163    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() {
2164        return note_off_signal;
2165    }
2166    
2167    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() {
2168        return m_RegionChooser.signal_keyboard_key_hit();
2169    }
2170    
2171    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
2172        return m_RegionChooser.signal_keyboard_key_released();
2173    }

Legend:
Removed from v.1261  
changed lines
  Added in v.2541

  ViewVC Help
Powered by ViewVC