/[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 1679 by schoenebeck, Tue Feb 12 14:13:46 2008 UTC revision 2691 by schoenebeck, Sun Jan 4 19:46:54 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006 - 2008 Andreas Persson   * Copyright (C) 2006-2015 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 18  Line 18 
18   */   */
19    
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>  #include <gtkmm/toggleaction.h>
34    #if GTKMM_MAJOR_VERSION < 3
35  #include "global.h"  #include "wrapLabel.hh"
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
 #define ABOUT_DIALOG  
 #include <gtkmm/aboutdialog.h>  
36  #endif  #endif
37    
38  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #include "global.h"
39  namespace Glib {  #include "compat.h"
 Glib::ustring filename_display_basename(const std::string& filename)  
 {  
     gchar* gstr = g_path_get_basename(filename.c_str());  
     Glib::ustring str(gstr);  
     g_free(gstr);  
     return Glib::filename_to_utf8(str);  
 }  
 }  
 #endif  
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46    #include "Settings.h"
47    #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49    #include "scriptslots.h"
50    #include "ReferencesView.h"
51  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
52  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
53    
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
   
 Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }  
   
 void Table::add(BoolEntry& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(BoolEntryPlus6& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(LabelWidget& prop)  
 {  
     attach(prop.label, 1, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     attach(prop.widget, 2, 3, rowno, rowno + 1,  
            Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
54    
55  MainWindow::MainWindow() :  MainWindow::MainWindow() :
56        m_DimRegionChooser(*this),
57      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
58      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
59      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
# Line 97  MainWindow::MainWindow() : Line 66  MainWindow::MainWindow() :
66      add(m_VBox);      add(m_VBox);
67    
68      // Handle selection      // Handle selection
69      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
70          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
71    
72      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 114  MainWindow::MainWindow() : Line 82  MainWindow::MainWindow() :
82      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
83      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
84    
85        m_ScrolledWindowScripts.add(m_TreeViewScripts);
86        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
87    
88    
89      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
90    
# Line 127  MainWindow::MainWindow() : Line 98  MainWindow::MainWindow() :
98      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
99      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
100    
101        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
102      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");      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."));
103      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");      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."));
104        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)."));
105    
106        m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
107        m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
108        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
109    
110      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
111    
# Line 161  MainWindow::MainWindow() : Line 136  MainWindow::MainWindow() :
136                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
137                       sigc::mem_fun(                       sigc::mem_fun(
138                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
139        actionGroup->add(Gtk::Action::create("MidiRules",
140                                             _("_Midi Rules...")),
141                         sigc::mem_fun(
142                             *this, &MainWindow::show_midi_rules));
143        actionGroup->add(Gtk::Action::create("ScriptSlots",
144                                             _("_Script Slots...")),
145                         sigc::mem_fun(
146                             *this, &MainWindow::show_script_slots));
147      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
148                       sigc::mem_fun(                       sigc::mem_fun(
149                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
150      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
151            Gtk::Action::create("MenuSample", _("_Sample")),
152            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
153        );
154        actionGroup->add(
155            Gtk::Action::create("MenuInstrument", _("_Instrument")),
156            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
157        );
158        actionGroup->add(
159            Gtk::Action::create("MenuScript", _("S_cript")),
160            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
161        );
162        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
163    
164        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
165    
     actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
166      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
167            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
168        toggle_action->set_active(true);
169        actionGroup->add(toggle_action);
170    
171        toggle_action =
172            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
173        toggle_action->set_active(true);
174        actionGroup->add(toggle_action);
175    
176        toggle_action =
177            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
178        toggle_action->set_active(true);
179        actionGroup->add(toggle_action);
180    
181    
182        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
183        toggle_action =
184          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
185      toggle_action->set_active(true);      toggle_action->set_active(true);
186      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 177  MainWindow::MainWindow() : Line 190  MainWindow::MainWindow() :
190      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
191      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
192                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
193      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
194                       sigc::mem_fun(                       sigc::mem_fun(
195                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
196      actionGroup->add(      actionGroup->add(
197          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
198          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
199      );      );
200      actionGroup->add(      actionGroup->add(
201            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
202            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
203        );
204        actionGroup->add(
205          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
206          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
207      );      );
208    
209    
210        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
211        
212        toggle_action =
213            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
214        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
215        actionGroup->add(
216            toggle_action,
217            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
218        );
219    
220        toggle_action =
221            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
222        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
223        actionGroup->add(
224            toggle_action,
225            sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
226        );
227    
228    
229        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
230    
231        actionGroup->add(
232            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
233            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
234        );
235    
236        actionGroup->add(
237            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
238            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
239        );
240    
241    
242      // sample right-click popup actions      // sample right-click popup actions
243      actionGroup->add(      actionGroup->add(
244          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 201  MainWindow::MainWindow() : Line 249  MainWindow::MainWindow() :
249          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
250      );      );
251      actionGroup->add(      actionGroup->add(
252          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
253          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
254      );      );
255      actionGroup->add(      actionGroup->add(
# Line 209  MainWindow::MainWindow() : Line 257  MainWindow::MainWindow() :
257          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
258      );      );
259      actionGroup->add(      actionGroup->add(
260          Gtk::Action::create("ReplaceAllSamplesInAllGroups", _("Replace All Samples In All Groups")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
261            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
262        );
263        actionGroup->add(
264            Gtk::Action::create("ReplaceAllSamplesInAllGroups",
265                                _("Replace All Samples in All Groups...")),
266          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
267      );      );
268        
269        // script right-click popup actions
270        actionGroup->add(
271            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
272            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
273        );
274        actionGroup->add(
275            Gtk::Action::create("AddScript", _("Add _Script")),
276            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
277        );
278        actionGroup->add(
279            Gtk::Action::create("EditScript", _("_Edit Script...")),
280            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
281        );
282        actionGroup->add(
283            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
284            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
285        );
286    
287      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
288      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 231  MainWindow::MainWindow() : Line 302  MainWindow::MainWindow() :
302          "      <separator/>"          "      <separator/>"
303          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
304          "    </menu>"          "    </menu>"
305            "    <menu action='MenuEdit'>"
306            "      <menuitem action='CopySampleUnity'/>"
307            "      <menuitem action='CopySampleTune'/>"
308            "      <menuitem action='CopySampleLoop'/>"
309            "    </menu>"
310            "    <menu action='MenuSample'>"
311            "      <menuitem action='SampleProperties'/>"
312            "      <menuitem action='AddGroup'/>"
313            "      <menuitem action='AddSample'/>"
314            "      <menuitem action='ShowSampleRefs'/>"
315            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
316            "      <separator/>"
317            "      <menuitem action='RemoveSample'/>"
318            "    </menu>"
319          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
320            "      <menu action='AllInstruments'>"
321            "      </menu>"
322            "      <separator/>"
323            "      <menuitem action='InstrProperties'/>"
324            "      <menuitem action='MidiRules'/>"
325            "      <menuitem action='ScriptSlots'/>"
326            "      <menuitem action='AddInstrument'/>"
327            "      <menuitem action='DupInstrument'/>"
328            "      <separator/>"
329            "      <menuitem action='RemoveInstrument'/>"
330            "    </menu>"
331            "    <menu action='MenuScript'>"
332            "      <menuitem action='AddScriptGroup'/>"
333            "      <menuitem action='AddScript'/>"
334            "      <menuitem action='EditScript'/>"
335            "      <separator/>"
336            "      <menuitem action='RemoveScript'/>"
337          "    </menu>"          "    </menu>"
338          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
339          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
340          "    </menu>"          "    </menu>"
341  #ifdef ABOUT_DIALOG          "    <menu action='MenuTools'>"
342            "      <menuitem action='CombineInstruments'/>"
343            "      <menuitem action='MergeFiles'/>"
344            "    </menu>"
345            "    <menu action='MenuSettings'>"
346            "      <menuitem action='WarnUserOnExtensions'/>"
347            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
348            "    </menu>"
349          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
350          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
351          "    </menu>"          "    </menu>"
 #endif  
352          "  </menubar>"          "  </menubar>"
353          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
354          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
355            "    <menuitem action='MidiRules'/>"
356            "    <menuitem action='ScriptSlots'/>"
357          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
358            "    <menuitem action='DupInstrument'/>"
359          "    <separator/>"          "    <separator/>"
360          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
361          "  </popup>"          "  </popup>"
# Line 252  MainWindow::MainWindow() : Line 363  MainWindow::MainWindow() :
363          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
364          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
365          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
366          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ShowSampleRefs'/>"
367            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
368          "    <separator/>"          "    <separator/>"
369          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
370          "  </popup>"          "  </popup>"
371            "  <popup name='ScriptPopupMenu'>"
372            "    <menuitem action='AddScriptGroup'/>"
373            "    <menuitem action='AddScript'/>"
374            "    <menuitem action='EditScript'/>"
375            "    <separator/>"
376            "    <menuitem action='RemoveScript'/>"
377            "  </popup>"
378          "</ui>";          "</ui>";
379      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
380    
381      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
382        
383        // Set tooltips for menu items (for some reason, setting a tooltip on the
384        // respective Gtk::Action objects above will simply be ignored, no matter
385        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
386        // Gtk::Action::create()).
387        {
388            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
389                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
390            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."));
391        }
392        {
393            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
394                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
395            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."));
396        }
397        {
398            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
399                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
400            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."));
401        }
402        {
403            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
404                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
405            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."));
406        }
407        {
408            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
409                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
410            item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
411        }
412        {
413            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
414                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
415            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
416        }
417        {
418            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
419                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
420            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
421        }
422    
423    
424        instrument_menu = static_cast<Gtk::MenuItem*>(
425            uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
426    
427      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
428      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 269  MainWindow::MainWindow() : Line 432  MainWindow::MainWindow() :
432      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
433      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
434    
435        set_file_is_shared(false);
436    
437      // Status Bar:      // Status Bar:
438      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
439      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 283  MainWindow::MainWindow() : Line 448  MainWindow::MainWindow() :
448      // Create the Tree model:      // Create the Tree model:
449      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
450      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
451      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
452        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
453          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
454      );      );
455    
# Line 294  MainWindow::MainWindow() : Line 460  MainWindow::MainWindow() :
460      // create samples treeview (including its data model)      // create samples treeview (including its data model)
461      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
462      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
463        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."));
464      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
465      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
466      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
467        {
468            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
469            Gtk::CellRendererText* cellrenderer =
470                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
471            column->add_attribute(
472                cellrenderer->property_foreground(), m_SamplesModel.m_color
473            );
474        }
475        {
476            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
477            Gtk::CellRendererText* cellrenderer =
478                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
479            column->add_attribute(
480                cellrenderer->property_foreground(), m_SamplesModel.m_color
481            );
482        }
483        m_TreeViewSamples.set_headers_visible(true);
484      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
485          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
486      );      );
# Line 304  MainWindow::MainWindow() : Line 488  MainWindow::MainWindow() :
488          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
489      );      );
490    
491        // create scripts treeview (including its data model)
492        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
493        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
494        m_TreeViewScripts.set_tooltip_text(_(
495            "Use CTRL + double click for editing a script."
496            "\n\n"
497            "Note: instrument scripts are a LinuxSampler extension of the gig "
498            "format. This feature will not work with the GigaStudio software!"
499        ));
500        // m_TreeViewScripts.set_reorderable();
501        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
502        m_TreeViewScripts.set_headers_visible(false);
503        m_TreeViewScripts.signal_button_press_event().connect_notify(
504            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
505        );
506        //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?
507        m_TreeViewScripts.signal_row_activated().connect(
508            sigc::mem_fun(*this, &MainWindow::script_double_clicked)
509        );
510        m_refScriptsTreeModel->signal_row_changed().connect(
511            sigc::mem_fun(*this, &MainWindow::script_name_changed)
512        );
513    
514        // establish drag&drop between scripts tree view and ScriptSlots window
515        std::vector<Gtk::TargetEntry> drag_target_gig_script;
516        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
517        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
518        m_TreeViewScripts.signal_drag_begin().connect(
519            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
520        );
521        m_TreeViewScripts.signal_drag_data_get().connect(
522            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
523        );
524    
525      // 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
526      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
527      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
528      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
529      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
530          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 324  MainWindow::MainWindow() : Line 542  MainWindow::MainWindow() :
542          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
543      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
544          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
545      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
546            sigc::mem_fun(*this, &MainWindow::file_changed));
547        propDialog.signal_changed().connect(
548          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
549      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
550          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
551    
552      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 335  MainWindow::MainWindow() : Line 555  MainWindow::MainWindow() :
555          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
556      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
557          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
558        sample_ref_changed_signal.connect(
559            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
560        );
561        samples_to_be_removed_signal.connect(
562            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
563        );
564    
565        dimreg_edit.signal_select_sample().connect(
566            sigc::mem_fun(*this, &MainWindow::select_sample)
567        );
568    
569      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
570          sigc::hide(          sigc::hide(
# Line 371  MainWindow::MainWindow() : Line 601  MainWindow::MainWindow() :
601    
602      file = 0;      file = 0;
603      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
604    
605      show_all_children();      show_all_children();
606    
607      // start with a new gig file by default      // start with a new gig file by default
608      on_action_file_new();      on_action_file_new();
609    
610        // select 'Instruments' tab by default
611        // (gtk allows this only if the tab childs are visible, thats why it's here)
612        m_TreeViewNotebook.set_current_page(1);
613  }  }
614    
615  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 402  void MainWindow::region_changed() Line 635  void MainWindow::region_changed()
635  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
636  {  {
637      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
638      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
639            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
640      if (it) {      if (it) {
641          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
642          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 458  void MainWindow::dimreg_all_dimregs_togg Line 690  void MainWindow::dimreg_all_dimregs_togg
690  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
691  {  {
692      update_dimregs();      update_dimregs();
693      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
694  }  }
695    
696  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
697  {  {
698        // select item in instrument menu
699        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
700        if (it) {
701            Gtk::TreePath path(it);
702            int index = path[0];
703            const std::vector<Gtk::Widget*> children =
704                instrument_menu->get_children();
705            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
706        }
707    
708      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
709    
710        if (Settings::singleton()->syncSamplerInstrumentSelection) {
711            switch_sampler_instrument_signal.emit(get_instrument());
712        }
713  }  }
714    
715  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 475  void loader_progress_callback(gig::progr Line 721  void loader_progress_callback(gig::progr
721  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
722  {  {
723      {      {
724          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
725          progress = fraction;          progress = fraction;
726      }      }
727      progress_dispatcher();      progress_dispatcher();
# Line 483  void Loader::progress_callback(float fra Line 729  void Loader::progress_callback(float fra
729    
730  void Loader::thread_function()  void Loader::thread_function()
731  {  {
732      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
733      printf("Start %s\n", filename);      printf("Start %s\n", filename.c_str());
734      RIFF::File* riff = new RIFF::File(filename);      try {
735      gig = new gig::File(riff);          RIFF::File* riff = new RIFF::File(filename);
736      gig::progress_t progress;          gig = new gig::File(riff);
737      progress.callback = loader_progress_callback;          gig::progress_t progress;
738      progress.custom = this;          progress.callback = loader_progress_callback;
739            progress.custom = this;
740      gig->GetInstrument(0, &progress);  
741      printf("End\n");          gig->GetInstrument(0, &progress);
742      finished_dispatcher();          printf("End\n");
743            finished_dispatcher();
744        } catch (RIFF::Exception e) {
745            error_message = e.Message;
746            error_dispatcher.emit();
747        } catch (...) {
748            error_message = _("Unknown exception occurred");
749            error_dispatcher.emit();
750        }
751  }  }
752    
753  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
754      : thread(0), filename(filename)      : filename(filename), thread(0), progress(0.f)
755  {  {
756  }  }
757    
758  void Loader::launch()  void Loader::launch()
759  {  {
760    #ifdef OLD_THREADS
761      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
762    #else
763        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
764    #endif
765      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
766  }  }
767    
# Line 511  float Loader::get_progress() Line 769  float Loader::get_progress()
769  {  {
770      float res;      float res;
771      {      {
772          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
773          res = progress;          res = progress;
774      }      }
775      return res;      return res;
# Line 527  Glib::Dispatcher& Loader::signal_finishe Line 785  Glib::Dispatcher& Loader::signal_finishe
785      return finished_dispatcher;      return finished_dispatcher;
786  }  }
787    
788  LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)  Glib::Dispatcher& Loader::signal_error()
789    {
790        return error_dispatcher;
791    }
792    
793    void saver_progress_callback(gig::progress_t* progress)
794    {
795        Saver* saver = static_cast<Saver*>(progress->custom);
796        saver->progress_callback(progress->factor);
797    }
798    
799    void Saver::progress_callback(float fraction)
800    {
801        {
802            Glib::Threads::Mutex::Lock lock(progressMutex);
803            progress = fraction;
804        }
805        progress_dispatcher.emit();
806    }
807    
808    void Saver::thread_function()
809    {
810        printf("thread_function self=%x\n", Glib::Threads::Thread::self());
811        printf("Start %s\n", filename.c_str());
812        try {
813            gig::progress_t progress;
814            progress.callback = saver_progress_callback;
815            progress.custom = this;
816    
817            // if no filename was provided, that means "save", if filename was provided means "save as"
818            if (filename.empty()) {
819                gig->Save(&progress);
820            } else {
821                gig->Save(filename, &progress);
822            }
823    
824            printf("End\n");
825            finished_dispatcher.emit();
826        } catch (RIFF::Exception e) {
827            error_message = e.Message;
828            error_dispatcher.emit();
829        } catch (...) {
830            error_message = _("Unknown exception occurred");
831            error_dispatcher.emit();
832        }
833    }
834    
835    Saver::Saver(gig::File* file, Glib::ustring filename)
836        : gig(file), filename(filename), thread(0), progress(0.f)
837    {
838    }
839    
840    void Saver::launch()
841    {
842    #ifdef OLD_THREADS
843        thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
844    #else
845        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
846    #endif
847        printf("launch thread=%x\n", thread);
848    }
849    
850    float Saver::get_progress()
851    {
852        float res;
853        {
854            Glib::Threads::Mutex::Lock lock(progressMutex);
855            res = progress;
856        }
857        return res;
858    }
859    
860    Glib::Dispatcher& Saver::signal_progress()
861    {
862        return progress_dispatcher;
863    }
864    
865    Glib::Dispatcher& Saver::signal_finished()
866    {
867        return finished_dispatcher;
868    }
869    
870    Glib::Dispatcher& Saver::signal_error()
871    {
872        return error_dispatcher;
873    }
874    
875    ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
876      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
877  {  {
878      get_vbox()->pack_start(progressBar);      get_vbox()->pack_start(progressBar);
879      show_all_children();      show_all_children();
880        resize(600,50);
881  }  }
882    
883  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
884  // 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.
885  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();  
886      // forget all samples that ought to be imported      // forget all samples that ought to be imported
887      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
888      // clear the samples and instruments tree views      // clear the samples and instruments tree views
889      m_refTreeModel->clear();      m_refTreeModel->clear();
890      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
891        m_refScriptsTreeModel->clear();
892        // remove all entries from "Instrument" menu
893        while (!instrument_menu->get_children().empty()) {
894            remove_instrument_from_menu(0);
895        }
896      // free libgig's gig::File instance      // free libgig's gig::File instance
897      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
898      file = NULL;      file = NULL;
899      set_file_is_shared(false);      set_file_is_shared(false);
900  }  }
901    
902    void MainWindow::__refreshEntireGUI() {
903        // clear the samples and instruments tree views
904        m_refTreeModel->clear();
905        m_refSamplesTreeModel->clear();
906        m_refScriptsTreeModel->clear();
907        // remove all entries from "Instrument" menu
908        while (!instrument_menu->get_children().empty()) {
909            remove_instrument_from_menu(0);
910        }
911    
912        if (!this->file) return;
913    
914        load_gig(
915            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
916        );
917    }
918    
919  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
920  {  {
921      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 568  void MainWindow::on_action_file_new() Line 928  void MainWindow::on_action_file_new()
928      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
929      // already add one new instrument by default      // already add one new instrument by default
930      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
931      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
932      // update GUI with that new gig::File      // update GUI with that new gig::File
933      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
934  }  }
# Line 579  bool MainWindow::close_confirmation_dial Line 939  bool MainWindow::close_confirmation_dial
939                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
940      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
941      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
942      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
 #endif  
943      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
944      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
945      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);
946      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
947      int response = dialog.run();      int response = dialog.run();
948      dialog.hide();      dialog.hide();
949      if (response == Gtk::RESPONSE_YES) return file_save();  
950      return response != Gtk::RESPONSE_CANCEL;      // TODO: the following return valid is disabled and hard coded instead for
951        // now, due to the fact that saving with progress bar is now implemented
952        // asynchronously, as a result the app does not close automatically anymore
953        // after saving the file has completed
954        //
955        //   if (response == Gtk::RESPONSE_YES) return file_save();
956        //   return response != Gtk::RESPONSE_CANCEL;
957        //
958        if (response == Gtk::RESPONSE_YES) file_save();
959        return false; // always prevent closing the app for now (see comment above)
960  }  }
961    
962  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
963      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
964      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
965      dialog.set_secondary_text(      dialog.set_secondary_text(
966          _("If you proceed to work on another instrument file, it won't be "          _("If you proceed to work on another instrument file, it won't be "
967            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
968            "load it.")            "load it."));
    );  
 #endif  
969      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
970      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
971      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 620  void MainWindow::on_action_file_open() Line 984  void MainWindow::on_action_file_open()
984      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
985      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
986      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
987    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
988      Gtk::FileFilter filter;      Gtk::FileFilter filter;
989      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
990    #else
991        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
992        filter->add_pattern("*.gig");
993    #endif
994      dialog.set_filter(filter);      dialog.set_filter(filter);
995      if (current_dir != "") {      if (current_gig_dir != "") {
996          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
997      }      }
998      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
999          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1000          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1001          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
1002          load_file(filename.c_str());          load_file(filename.c_str());
1003          current_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1004      }      }
1005  }  }
1006    
1007  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
1008  {  {
1009      __clear();      __clear();
1010      load_dialog = new LoadDialog("Loading...", *this);  
1011      load_dialog->show_all();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1012      loader = new Loader(strdup(name));          _("Loading") +  Glib::ustring(" '") +
1013            Glib::filename_display_basename(name) + "' ...",
1014            *this
1015        );
1016        progress_dialog->show_all();
1017        loader = new Loader(name); //FIXME: memory leak!
1018      loader->signal_progress().connect(      loader->signal_progress().connect(
1019          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
1020      loader->signal_finished().connect(      loader->signal_finished().connect(
1021          sigc::mem_fun(*this, &MainWindow::on_loader_finished));          sigc::mem_fun(*this, &MainWindow::on_loader_finished));
1022        loader->signal_error().connect(
1023            sigc::mem_fun(*this, &MainWindow::on_loader_error));
1024      loader->launch();      loader->launch();
1025  }  }
1026    
# Line 660  void MainWindow::load_instrument(gig::In Line 1036  void MainWindow::load_instrument(gig::In
1036      // load the instrument      // load the instrument
1037      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
1038      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
1039      //TODO: automatically select the given instrument      // automatically select the given instrument
1040        int i = 0;
1041        for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
1042             instrument = pFile->GetNextInstrument(), ++i)
1043        {
1044            if (instrument == instr) {
1045                // select item in "instruments" tree view
1046                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
1047                // make sure the selected item in the "instruments" tree view is
1048                // visible (scroll to it)
1049                m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
1050                // select item in instrument menu
1051                {
1052                    const std::vector<Gtk::Widget*> children =
1053                        instrument_menu->get_children();
1054                    static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
1055                }
1056                // update region chooser and dimension region chooser
1057                m_RegionChooser.set_instrument(instr);
1058                break;
1059            }
1060        }
1061  }  }
1062    
1063  void MainWindow::on_loader_progress()  void MainWindow::on_loader_progress()
1064  {  {
1065      load_dialog->set_fraction(loader->get_progress());      progress_dialog->set_fraction(loader->get_progress());
1066  }  }
1067    
1068  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1069  {  {
1070      printf("Loader finished!\n");      printf("Loader finished!\n");
1071      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
1072      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename.c_str());
1073      load_dialog->hide();      progress_dialog->hide();
1074    }
1075    
1076    void MainWindow::on_loader_error()
1077    {
1078        Glib::ustring txt = _("Could not load file: ") + loader->error_message;
1079        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1080        msg.run();
1081        progress_dialog->hide();
1082  }  }
1083    
1084  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
# Line 712  bool MainWindow::file_save() Line 1117  bool MainWindow::file_save()
1117    
1118      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
1119      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
1120      try {  
1121          file->Save();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1122          if (file_is_changed) {          _("Saving") +  Glib::ustring(" '") +
1123              set_title(get_title().substr(1));          Glib::filename_display_basename(this->filename) + "' ...",
1124              file_is_changed = false;          *this
1125          }      );
1126      } catch (RIFF::Exception e) {      progress_dialog->show_all();
1127          file_structure_changed_signal.emit(this->file);      saver = new Saver(this->file); //FIXME: memory leak!
1128          Glib::ustring txt = _("Could not save file: ") + e.Message;      saver->signal_progress().connect(
1129          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1130          msg.run();      saver->signal_finished().connect(
1131          return false;          sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1132      }      saver->signal_error().connect(
1133      std::cout << "Saving file done\n" << std::flush;          sigc::mem_fun(*this, &MainWindow::on_saver_error));
1134        saver->launch();
1135    
1136        return true;
1137    }
1138    
1139    void MainWindow::on_saver_progress()
1140    {
1141        progress_dialog->set_fraction(saver->get_progress());
1142    }
1143    
1144    void MainWindow::on_saver_error()
1145    {
1146        file_structure_changed_signal.emit(this->file);
1147        Glib::ustring txt = _("Could not save file: ") + saver->error_message;
1148        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1149        msg.run();
1150    }
1151    
1152    void MainWindow::on_saver_finished()
1153    {
1154        this->file = saver->gig;
1155        this->filename = saver->filename;
1156        current_gig_dir = Glib::path_get_dirname(filename);
1157        set_title(Glib::filename_display_basename(filename));
1158        file_has_name = true;
1159        file_is_changed = false;
1160        std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
1161      __import_queued_samples();      __import_queued_samples();
1162        std::cout << "Importing queued samples done.\n" << std::flush;
1163    
1164      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1165      return true;  
1166        load_gig(this->file, this->filename.c_str());
1167        progress_dialog->hide();
1168  }  }
1169    
1170  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
# Line 743  bool MainWindow::file_save_as() Line 1179  bool MainWindow::file_save_as()
1179      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1180      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1181      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  
1182      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1183      // TODO: an overwrite dialog for gtkmm < 2.8  
1184  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1185      Gtk::FileFilter filter;      Gtk::FileFilter filter;
1186      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
1187    #else
1188        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
1189        filter->add_pattern("*.gig");
1190    #endif
1191      dialog.set_filter(filter);      dialog.set_filter(filter);
1192    
1193      // set initial dir and filename of the Save As dialog      // set initial dir and filename of the Save As dialog
# Line 757  bool MainWindow::file_save_as() Line 1195  bool MainWindow::file_save_as()
1195      {      {
1196          std::string basename = Glib::path_get_basename(filename);          std::string basename = Glib::path_get_basename(filename);
1197          std::string dir = Glib::path_get_dirname(filename);          std::string dir = Glib::path_get_dirname(filename);
1198          basename = std::string("copy_of_") + basename;          basename = std::string(_("copy_of_")) + basename;
1199          Glib::ustring copyFileName = Glib::build_filename(dir, basename);          Glib::ustring copyFileName = Glib::build_filename(dir, basename);
1200          if (Glib::path_is_absolute(filename)) {          if (Glib::path_is_absolute(filename)) {
1201              dialog.set_filename(copyFileName);              dialog.set_filename(copyFileName);
1202          } else {          } else {
1203              if (current_dir != "") dialog.set_current_folder(current_dir);              if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
1204          }          }
1205          dialog.set_current_name(Glib::filename_display_basename(copyFileName));          dialog.set_current_name(Glib::filename_display_basename(copyFileName));
1206      }      }
# Line 772  bool MainWindow::file_save_as() Line 1210  bool MainWindow::file_save_as()
1210      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1211      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1212      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1213      warningIcon.show();  #if GTKMM_MAJOR_VERSION < 3
1214        view::WrapLabel description;
1215    #else
1216      Gtk::Label description;      Gtk::Label description;
1217        description.set_line_wrap();
1218    #endif
1219      description.set_markup(      description.set_markup(
1220          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
1221            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 782  bool MainWindow::file_save_as() Line 1224  bool MainWindow::file_save_as()
1224            "<span style=\"italic\">\"Save As...\"</span> for writing to the "            "<span style=\"italic\">\"Save As...\"</span> for writing to the "
1225            "same .gig file will end up in corrupted sample wave data!\n")            "same .gig file will end up in corrupted sample wave data!\n")
1226      );      );
1227      description.set_line_wrap(true);      descriptionArea.pack_start(description);
     descriptionArea.pack_start(description, Gtk::PACK_SHRINK);  
     description.show();  
1228      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
1229      descriptionArea.show();      descriptionArea.show_all();
1230    
1231      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1232          file_structure_to_be_changed_signal.emit(this->file);          std::string filename = dialog.get_filename();
1233          try {          if (!Glib::str_has_suffix(filename, ".gig")) {
1234              std::string filename = dialog.get_filename();              filename += ".gig";
             if (!Glib::str_has_suffix(filename, ".gig")) {  
                 filename += ".gig";  
             }  
             printf("filename=%s\n", filename.c_str());  
             file->Save(filename);  
             this->filename = filename;  
             current_dir = Glib::path_get_dirname(filename);  
             set_title(Glib::filename_display_basename(filename));  
             file_has_name = true;  
             file_is_changed = false;  
         } catch (RIFF::Exception e) {  
             file_structure_changed_signal.emit(this->file);  
             Glib::ustring txt = _("Could not save file: ") + e.Message;  
             Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);  
             msg.run();  
             return false;  
1235          }          }
1236          __import_queued_samples();          printf("filename=%s\n", filename.c_str());
1237          file_structure_changed_signal.emit(this->file);  
1238            progress_dialog = new ProgressDialog( //FIXME: memory leak!
1239                _("Saving") +  Glib::ustring(" '") +
1240                Glib::filename_display_basename(filename) + "' ...",
1241                *this
1242            );
1243            progress_dialog->show_all();
1244    
1245            saver = new Saver(file, filename); //FIXME: memory leak!
1246            saver->signal_progress().connect(
1247                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1248            saver->signal_finished().connect(
1249                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1250            saver->signal_error().connect(
1251                sigc::mem_fun(*this, &MainWindow::on_saver_error));
1252            saver->launch();
1253    
1254          return true;          return true;
1255      }      }
1256      return false;      return false;
# Line 827  void MainWindow::__import_queued_samples Line 1267  void MainWindow::__import_queued_samples
1267          SF_INFO info;          SF_INFO info;
1268          info.format = 0;          info.format = 0;
1269          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
1270            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1271          try {          try {
1272              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
1273              // determine sample's bit depth              // determine sample's bit depth
1274              int bitdepth;              int bitdepth;
1275              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 845  void MainWindow::__import_queued_samples Line 1286  void MainWindow::__import_queued_samples
1286                      break;                      break;
1287                  default:                  default:
1288                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
1289                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1290              }              }
1291    
1292              const int bufsize = 10000;              const int bufsize = 10000;
# Line 887  void MainWindow::__import_queued_samples Line 1328  void MainWindow::__import_queued_samples
1328              }              }
1329              // cleanup              // cleanup
1330              sf_close(hFile);              sf_close(hFile);
1331                // let the sampler re-cache the sample if needed
1332                sample_changed_signal.emit(iter->gig_sample);
1333              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1334              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1335              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 894  void MainWindow::__import_queued_samples Line 1337  void MainWindow::__import_queued_samples
1337              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1338          } catch (std::string what) {          } catch (std::string what) {
1339              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1340              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1341              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1342              ++iter;              ++iter;
1343          }          }
1344      }      }
1345      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
1346      if (error_files.size()) {      if (!error_files.empty()) {
1347          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;
1348          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1349          msg.run();          msg.run();
# Line 913  void MainWindow::on_action_file_properti Line 1356  void MainWindow::on_action_file_properti
1356      propDialog.deiconify();      propDialog.deiconify();
1357  }  }
1358    
1359    void MainWindow::on_action_warn_user_on_extensions() {
1360        Settings::singleton()->warnUserOnExtensions =
1361            !Settings::singleton()->warnUserOnExtensions;
1362    }
1363    
1364    void MainWindow::on_action_sync_sampler_instrument_selection() {
1365        Settings::singleton()->syncSamplerInstrumentSelection =
1366            !Settings::singleton()->syncSamplerInstrumentSelection;
1367    }
1368    
1369  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1370  {  {
 #ifdef ABOUT_DIALOG  
1371      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
1372    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
1373        dialog.set_program_name("Gigedit");
1374    #else
1375        dialog.set_name("Gigedit");
1376    #endif
1377      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1378      dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");
1379      dialog.set_comments(      const std::string sComment =
1380          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1381          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1382          "Please notice that this is still a very young instrument editor. "          _(
1383          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1384          "this application.\n"              "\n"
1385          "\n"              "This program is distributed WITHOUT ANY WARRANTY; So better "
1386          "Please report bugs to: http://bugs.linuxsampler.org"              "backup your Gigasampler/GigaStudio files before editing them with "
1387      );              "this application.\n"
1388                "\n"
1389                "Please report bugs to: http://bugs.linuxsampler.org"
1390            );
1391        dialog.set_comments(sComment.c_str());
1392      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1393      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1394      dialog.run();      dialog.run();
 #endif  
1395  }  }
1396    
1397  PropDialog::PropDialog()  PropDialog::PropDialog()
1398      : table(2,1),      : eFileFormat(_("File Format")),
1399        eName("Name"),        eName(_("Name")),
1400        eCreationDate("Creation date"),        eCreationDate(_("Creation date")),
1401        eComments("Comments"),        eComments(_("Comments")),
1402        eProduct("Product"),        eProduct(_("Product")),
1403        eCopyright("Copyright"),        eCopyright(_("Copyright")),
1404        eArtists("Artists"),        eArtists(_("Artists")),
1405        eGenre("Genre"),        eGenre(_("Genre")),
1406        eKeywords("Keywords"),        eKeywords(_("Keywords")),
1407        eEngineer("Engineer"),        eEngineer(_("Engineer")),
1408        eTechnician("Technician"),        eTechnician(_("Technician")),
1409        eSoftware("Software"),        eSoftware(_("Software")),
1410        eMedium("Medium"),        eMedium(_("Medium")),
1411        eSource("Source"),        eSource(_("Source")),
1412        eSourceForm("Source form"),        eSourceForm(_("Source form")),
1413        eCommissioned("Commissioned"),        eCommissioned(_("Commissioned")),
1414        eSubject("Subject"),        eSubject(_("Subject")),
1415        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1416        update_model(0)        table(2, 1),
1417          m_file(NULL)
1418  {  {
1419      set_title("File Properties");      set_title(_("File Properties"));
1420      eName.set_width_chars(50);      eName.set_width_chars(50);
1421    
1422      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
# Line 975  PropDialog::PropDialog() Line 1436  PropDialog::PropDialog()
1436      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1437      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1438    
1439        table.add(eFileFormat);
1440      table.add(eName);      table.add(eName);
1441      table.add(eCreationDate);      table.add(eCreationDate);
1442      table.add(eComments);      table.add(eComments);
# Line 1001  PropDialog::PropDialog() Line 1463  PropDialog::PropDialog()
1463      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1464      buttonBox.show();      buttonBox.show();
1465      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1466      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1467      quitButton.grab_focus();      quitButton.grab_focus();
1468      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1469          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1470        eFileFormat.signal_value_changed().connect(
1471            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1472    
1473      quitButton.show();      quitButton.show();
1474      vbox.show();      vbox.show();
1475      show_all_children();      show_all_children();
1476  }  }
1477    
1478  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_file(gig::File* file)
1479  {  {
1480      this->info = info;      m_file = file;
1481      update_model++;  
1482      eName.set_value(info->Name);      // update file format version combo box
1483      eCreationDate.set_value(info->CreationDate);      const std::string sGiga = "Gigasampler/GigaStudio v";
1484      eComments.set_value(info->Comments);      const int major = file->pVersion->major;
1485      eProduct.set_value(info->Product);      std::vector<std::string> txts;
1486      eCopyright.set_value(info->Copyright);      std::vector<int> values;
1487      eArtists.set_value(info->Artists);      txts.push_back(sGiga + "2"); values.push_back(2);
1488      eGenre.set_value(info->Genre);      txts.push_back(sGiga + "3/v4"); values.push_back(3);
1489      eKeywords.set_value(info->Keywords);      if (major != 2 && major != 3) {
1490      eEngineer.set_value(info->Engineer);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
1491      eTechnician.set_value(info->Technician);      }
1492      eSoftware.set_value(info->Software);      std::vector<const char*> texts;
1493      eMedium.set_value(info->Medium);      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1494      eSource.set_value(info->Source);      texts.push_back(NULL); values.push_back(0);
1495      eSourceForm.set_value(info->SourceForm);      eFileFormat.set_choices(&texts[0], &values[0]);
1496      eCommissioned.set_value(info->Commissioned);      eFileFormat.set_value(major);
1497      eSubject.set_value(info->Subject);  }
1498      update_model--;  
1499    void PropDialog::onFileFormatChanged() {
1500        const int major = eFileFormat.get_value();
1501        if (m_file) m_file->pVersion->major = major;
1502  }  }
1503    
1504  sigc::signal<void>& PropDialog::signal_info_changed()  void PropDialog::set_info(DLS::Info* info)
1505  {  {
1506      return info_changed;      update(info);
1507  }  }
1508    
1509  void InstrumentProps::set_IsDrum(bool value)  
1510    void InstrumentProps::set_Name(const gig::String& name)
1511  {  {
1512      instrument->IsDrum = value;      m->pInfo->Name = name;
1513  }  }
1514    
1515  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1516  {  {
1517      instrument->MIDIBank = value;      update_model++;
1518        eName.set_value(m->pInfo->Name);
1519        update_model--;
1520  }  }
1521    
1522  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1523  {  {
1524      instrument->MIDIProgram = value;      m->IsDrum = value;
1525  }  }
1526    
1527  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1528  {  {
1529      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1530  }  }
1531    
1532  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1533  {  {
1534      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1535  }  }
1536    
1537  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1538      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1539        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1540        eName("Name"),      eName(_("Name")),
1541        eIsDrum("Is drum"),      eIsDrum(_("Is drum")),
1542        eMIDIBank("MIDI bank", 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1543        eMIDIProgram("MIDI program"),      eMIDIProgram(_("MIDI program")),
1544        eAttenuation("Attenuation", 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1545        eGainPlus6("Gain +6dB", eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1546        eEffectSend("Effect send", 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1547        eFineTune("Fine tune", -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1548        ePitchbendRange("Pitchbend range", 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1549        ePianoReleaseMode("Piano release mode"),      ePianoReleaseMode(_("Piano release mode")),
1550        eDimensionKeyRangeLow("Keyswitching range low"),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1551        eDimensionKeyRangeHigh("Keyswitching range high"),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1552  {  {
1553      set_title("Instrument Properties");      set_title(_("Instrument Properties"));
1554    
1555      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
1556          _("start of the keyboard area which should switch the "          _("start of the keyboard area which should switch the "
# Line 1098  InstrumentProps::InstrumentProps() Line 1561  InstrumentProps::InstrumentProps()
1561            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1562      );      );
1563    
1564        connect(eName, &InstrumentProps::set_Name);
1565      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1566      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1567      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1107  InstrumentProps::InstrumentProps() Line 1571  InstrumentProps::InstrumentProps()
1571      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1572      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1573      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1574      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1575              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1576      connect(eDimensionKeyRangeHigh,  
1577              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1578    
1579      table.set_col_spacings(5);      table.set_col_spacings(5);
1580    
# Line 1136  InstrumentProps::InstrumentProps() Line 1600  InstrumentProps::InstrumentProps()
1600      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1601      buttonBox.show();      buttonBox.show();
1602      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1603      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1604      quitButton.grab_focus();      quitButton.grab_focus();
1605    
1606      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1149  InstrumentProps::InstrumentProps() Line 1613  InstrumentProps::InstrumentProps()
1613    
1614  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1615  {  {
1616      this->instrument = instrument;      update(instrument);
1617    
1618      update_model++;      update_model++;
1619      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1620      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1621      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1622      eMIDIProgram.set_value(instrument->MIDIProgram);      eMIDIProgram.set_value(instrument->MIDIProgram);
     eAttenuation.set_value(instrument->Attenuation);  
     eGainPlus6.set_value(instrument->Attenuation);  
     eEffectSend.set_value(instrument->EffectSend);  
     eFineTune.set_value(instrument->FineTune);  
     ePitchbendRange.set_value(instrument->PitchbendRange);  
     ePianoReleaseMode.set_value(instrument->PianoReleaseMode);  
     eDimensionKeyRangeLow.set_value(instrument->DimensionKeyRange.low);  
     eDimensionKeyRangeHigh.set_value(instrument->DimensionKeyRange.high);  
1623      update_model--;      update_model--;
1624  }  }
1625    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1626    
1627  void MainWindow::file_changed()  void MainWindow::file_changed()
1628  {  {
# Line 1180  void MainWindow::file_changed() Line 1632  void MainWindow::file_changed()
1632      }      }
1633  }  }
1634    
1635    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1636        sample_ref_count.clear();
1637        
1638        if (!gig) return;
1639    
1640        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1641             instrument = gig->GetNextInstrument())
1642        {
1643            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1644                 rgn = instrument->GetNextRegion())
1645            {
1646                for (int i = 0; i < 256; ++i) {
1647                    if (!rgn->pDimensionRegions[i]) continue;
1648                    if (rgn->pDimensionRegions[i]->pSample) {
1649                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1650                    }
1651                }
1652            }
1653        }
1654    }
1655    
1656  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1657  {  {
1658      file = 0;      file = 0;
# Line 1190  void MainWindow::load_gig(gig::File* gig Line 1663  void MainWindow::load_gig(gig::File* gig
1663      file_has_name = filename;      file_has_name = filename;
1664      file_is_changed = false;      file_is_changed = false;
1665    
1666        propDialog.set_file(gig);
1667      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1668    
1669      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;  
1670      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1671           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1672            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1673    
1674          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1675          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1676          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1677          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1678          // create a menu item for this instrument  
1679          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++;  
1680      }      }
1681      instrument_menu->show();      instrument_name_connection.unblock();
1682      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1683    
1684        updateSampleRefCountMap(gig);
1685    
1686      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1687          if (group->Name != "") {          if (group->Name != "") {
1688              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1689              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1690              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1691              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1692              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1693              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1230  void MainWindow::load_gig(gig::File* gig Line 1695  void MainWindow::load_gig(gig::File* gig
1695                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1696                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1697                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1698                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1699                        gig_to_utf8(sample->pInfo->Name);
1700                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1701                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1702                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1703                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1704                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1705              }              }
1706          }          }
1707      }      }
1708        
1709        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1710            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1711    
1712            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1713            Gtk::TreeModel::Row rowGroup = *iterGroup;
1714            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1715            rowGroup[m_ScriptsModel.m_col_group]  = group;
1716            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1717            for (int s = 0; group->GetScript(s); ++s) {
1718                gig::Script* script = group->GetScript(s);
1719    
1720                Gtk::TreeModel::iterator iterScript =
1721                    m_refScriptsTreeModel->append(rowGroup.children());
1722                Gtk::TreeModel::Row rowScript = *iterScript;
1723                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1724                rowScript[m_ScriptsModel.m_col_script] = script;
1725                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1726            }
1727        }
1728        // unfold all sample groups & script groups by default
1729        m_TreeViewSamples.expand_all();
1730        m_TreeViewScripts.expand_all();
1731    
1732      file = gig;      file = gig;
1733    
1734      // select the first instrument      // select the first instrument
1735      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1736      tree_sel_ref->select(Gtk::TreePath("0"));  
1737        instr_props_set_instrument();
1738        gig::Instrument* instrument = get_instrument();
1739        if (instrument) {
1740            midiRules.set_instrument(instrument);
1741        }
1742  }  }
1743    
1744  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1745  {  {
1746      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1747      if (instrument)  
1748      {      Gtk::TreeModel::const_iterator it =
1749            m_TreeView.get_selection()->get_selected();
1750        if (it) {
1751            Gtk::TreeModel::Row row = *it;
1752            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1753    
1754          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1755    
1756            // make sure instrument tree is updated when user changes the
1757            // instrument name in instrument properties window
1758            instrumentProps.signal_name_changed().connect(
1759                sigc::bind(
1760                    sigc::mem_fun(*this,
1761                                  &MainWindow::instr_name_changed_by_instr_props),
1762                    it));
1763        } else {
1764            instrumentProps.hide();
1765        }
1766        return it;
1767    }
1768    
1769    void MainWindow::show_instr_props()
1770    {
1771        if (instr_props_set_instrument()) {
1772          instrumentProps.show();          instrumentProps.show();
1773          instrumentProps.deiconify();          instrumentProps.deiconify();
1774      }      }
1775  }  }
1776    
1777    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1778    {
1779        Gtk::TreeModel::Row row = *it;
1780        Glib::ustring name = row[m_Columns.m_col_name];
1781    
1782        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1783        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1784        if (gigname != name) {
1785            row[m_Columns.m_col_name] = gigname;
1786        }
1787    }
1788    
1789    void MainWindow::show_midi_rules()
1790    {
1791        if (gig::Instrument* instrument = get_instrument())
1792        {
1793            midiRules.set_instrument(instrument);
1794            midiRules.show();
1795            midiRules.deiconify();
1796        }
1797    }
1798    
1799    void MainWindow::show_script_slots() {
1800        if (!file) return;
1801        // get selected instrument
1802        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1803        Gtk::TreeModel::iterator it = sel->get_selected();
1804        if (!it) return;
1805        Gtk::TreeModel::Row row = *it;
1806        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1807        if (!instrument) return;
1808    
1809        ScriptSlots* window = new ScriptSlots;
1810        window->setInstrument(instrument);
1811        //window->reparent(*this);
1812        window->show();
1813    }
1814    
1815  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1816      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1817          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1266  void MainWindow::on_action_view_status_b Line 1823  void MainWindow::on_action_view_status_b
1823      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1824  }  }
1825    
1826    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1827        Gtk::CheckMenuItem* item =
1828            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1829        if (!item) {
1830            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1831            return true;
1832        }
1833        return item->get_active();
1834    }
1835    
1836    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1837        Gtk::CheckMenuItem* item =
1838            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1839        if (!item) {
1840            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1841            return true;
1842        }
1843        return item->get_active();
1844    }
1845    
1846    bool MainWindow::is_copy_samples_loop_enabled() const {
1847        Gtk::CheckMenuItem* item =
1848            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1849        if (!item) {
1850            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1851            return true;
1852        }
1853        return item->get_active();
1854    }
1855    
1856  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1857  {  {
1858      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1859          show_instr_props();          show_instr_props();
1860      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1861            // gig v2 files have no midi rules
1862            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1863            static_cast<Gtk::MenuItem*>(
1864                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1865                    bEnabled
1866                );
1867            static_cast<Gtk::MenuItem*>(
1868                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1869                    bEnabled
1870                );
1871          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1872      }      }
1873  }  }
1874    
1875  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1876      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1877            const std::vector<Gtk::Widget*> children =
1878                instrument_menu->get_children();
1879            std::vector<Gtk::Widget*>::const_iterator it =
1880                find(children.begin(), children.end(), item);
1881            if (it != children.end()) {
1882                int index = it - children.begin();
1883                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1884    
1885                m_RegionChooser.set_instrument(file->GetInstrument(index));
1886            }
1887        }
1888    }
1889    
1890    void MainWindow::select_sample(gig::Sample* sample) {
1891        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
1892        for (int g = 0; g < model->children().size(); ++g) {
1893            Gtk::TreeModel::Row rowGroup = model->children()[g];
1894            for (int s = 0; s < rowGroup.children().size(); ++s) {
1895                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
1896                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
1897                    show_samples_tab();
1898                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
1899                    Gtk::TreePath path(
1900                        m_TreeViewSamples.get_selection()->get_selected()
1901                    );
1902                    m_TreeViewSamples.scroll_to_row(path);
1903                    return;
1904                }
1905            }
1906        }
1907  }  }
1908    
1909  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1293  void MainWindow::on_sample_treeview_butt Line 1920  void MainWindow::on_sample_treeview_butt
1920              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
1921              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
1922          }          }
1923            
1924                
1925          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
1926              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1927          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
1928              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1929          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1930              set_sensitive(file);              set_sensitive(file);
1931            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
1932                set_sensitive(sample_selected);
1933          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1934              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1935          // show sample popup          // show sample popup
1936          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
1937    
1938            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
1939                set_sensitive(group_selected || sample_selected);
1940            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
1941                set_sensitive(group_selected || sample_selected);
1942            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
1943                set_sensitive(file);
1944            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
1945                set_sensitive(sample_selected);
1946            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
1947                set_sensitive(group_selected || sample_selected);
1948      }      }
1949  }  }
1950    
1951  void MainWindow::on_action_add_instrument() {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1952      static int __instrument_indexer = 0;      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1953      if (!file) return;          Gtk::Menu* script_popup =
1954      gig::Instrument* instrument = file->AddInstrument();              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1955      __instrument_indexer++;          // update enabled/disabled state of sample popup items
1956      instrument->pInfo->Name =          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1957          "Unnamed Instrument " + ToString(__instrument_indexer);          Gtk::TreeModel::iterator it = sel->get_selected();
1958            bool group_selected  = false;
1959            bool script_selected = false;
1960            if (it) {
1961                Gtk::TreeModel::Row row = *it;
1962                group_selected  = row[m_ScriptsModel.m_col_group];
1963                script_selected = row[m_ScriptsModel.m_col_script];
1964            }
1965            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1966                set_sensitive(group_selected || script_selected);
1967            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1968                set_sensitive(file);
1969            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1970                set_sensitive(script_selected);    
1971            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1972                set_sensitive(group_selected || script_selected);
1973            // show sample popup
1974            script_popup->popup(button->button, button->time);
1975    
1976            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
1977                set_sensitive(group_selected || script_selected);
1978            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
1979                set_sensitive(file);
1980            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
1981                set_sensitive(script_selected);    
1982            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
1983                set_sensitive(group_selected || script_selected);
1984        }
1985    }
1986    
1987    Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1988        const Glib::ustring& name, int position) {
1989    
1990        Gtk::RadioMenuItem::Group instrument_group;
1991        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1992        if (!children.empty()) {
1993            instrument_group =
1994                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1995        }
1996        Gtk::RadioMenuItem* item =
1997            new Gtk::RadioMenuItem(instrument_group, name);
1998        if (position < 0) {
1999            instrument_menu->append(*item);
2000        } else {
2001            instrument_menu->insert(*item, position);
2002        }
2003        item->show();
2004        item->signal_activate().connect(
2005            sigc::bind(
2006                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
2007                item));
2008        return item;
2009    }
2010    
2011    void MainWindow::remove_instrument_from_menu(int index) {
2012        const std::vector<Gtk::Widget*> children =
2013            instrument_menu->get_children();
2014        Gtk::Widget* child = children[index];
2015        instrument_menu->remove(*child);
2016        delete child;
2017    }
2018    
2019    void MainWindow::add_instrument(gig::Instrument* instrument) {
2020        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2021    
2022      // update instrument tree view      // update instrument tree view
2023        instrument_name_connection.block();
2024      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2025      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2026      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
2027      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2028        instrument_name_connection.unblock();
2029    
2030        add_instrument_to_menu(name);
2031    
2032        m_TreeView.get_selection()->select(iterInstr);
2033    
2034      file_changed();      file_changed();
2035  }  }
2036    
2037    void MainWindow::on_action_add_instrument() {
2038        static int __instrument_indexer = 0;
2039        if (!file) return;
2040        gig::Instrument* instrument = file->AddInstrument();
2041        __instrument_indexer++;
2042        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
2043                                                ToString(__instrument_indexer));
2044    
2045        add_instrument(instrument);
2046    }
2047    
2048    void MainWindow::on_action_duplicate_instrument() {
2049        if (!file) return;
2050    
2051        // retrieve the currently selected instrument
2052        // (being the original instrument to be duplicated)
2053        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2054        Gtk::TreeModel::iterator itSelection = sel->get_selected();
2055        if (!itSelection) return;
2056        Gtk::TreeModel::Row row = *itSelection;
2057        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2058        if (!instrOrig) return;
2059    
2060        // duplicate the orginal instrument
2061        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2062        instrNew->pInfo->Name =
2063            instrOrig->pInfo->Name +
2064            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2065    
2066        add_instrument(instrNew);
2067    }
2068    
2069  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
2070      if (!file) return;      if (!file) return;
2071      if (file_is_shared) {      if (file_is_shared) {
# Line 1340  void MainWindow::on_action_remove_instru Line 2085  void MainWindow::on_action_remove_instru
2085          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2086          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2087          try {          try {
2088                Gtk::TreePath path(it);
2089                int index = path[0];
2090    
2091              // remove instrument from the gig file              // remove instrument from the gig file
2092              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
2093              file_changed();              file_changed();
2094    
2095                remove_instrument_from_menu(index);
2096    
2097                // remove row from instruments tree view
2098                m_refTreeModel->erase(it);
2099    
2100    #if GTKMM_MAJOR_VERSION < 3
2101                // select another instrument (in gtk3 this is done
2102                // automatically)
2103                if (!m_refTreeModel->children().empty()) {
2104                    if (index == m_refTreeModel->children().size()) {
2105                        index--;
2106                    }
2107                    m_TreeView.get_selection()->select(
2108                        Gtk::TreePath(ToString(index)));
2109                }
2110    #endif
2111                instr_props_set_instrument();
2112                instr = get_instrument();
2113                if (instr) {
2114                    midiRules.set_instrument(instr);
2115                } else {
2116                    midiRules.hide();
2117                }
2118          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
2119              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2120              msg.run();              msg.run();
# Line 1355  void MainWindow::on_action_remove_instru Line 2125  void MainWindow::on_action_remove_instru
2125  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
2126      //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
2127      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
2128          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
2129      );      );
2130      msg.run();      msg.run();
2131  }  }
2132    
2133    void MainWindow::on_action_add_script_group() {
2134        static int __script_indexer = 0;
2135        if (!file) return;
2136        gig::ScriptGroup* group = file->AddScriptGroup();
2137        group->Name = gig_from_utf8(_("Unnamed Group"));
2138        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
2139        __script_indexer++;
2140        // update sample tree view
2141        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
2142        Gtk::TreeModel::Row rowGroup = *iterGroup;
2143        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
2144        rowGroup[m_ScriptsModel.m_col_script] = NULL;
2145        rowGroup[m_ScriptsModel.m_col_group] = group;
2146        file_changed();
2147    }
2148    
2149    void MainWindow::on_action_add_script() {
2150        if (!file) return;
2151        // get selected group
2152        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2153        Gtk::TreeModel::iterator it = sel->get_selected();
2154        if (!it) return;
2155        Gtk::TreeModel::Row row = *it;
2156        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2157        if (!group) { // not a group, but a script is selected (probably)
2158            gig::Script* script = row[m_ScriptsModel.m_col_script];
2159            if (!script) return;
2160            it = row.parent(); // resolve parent (that is the script's group)
2161            if (!it) return;
2162            row = *it;
2163            group = row[m_ScriptsModel.m_col_group];
2164            if (!group) return;
2165        }
2166    
2167        // add a new script to the .gig file
2168        gig::Script* script = group->AddScript();    
2169        Glib::ustring name = _("Unnamed Script");
2170        script->Name = gig_from_utf8(name);
2171    
2172        // add script to the tree view
2173        Gtk::TreeModel::iterator iterScript =
2174            m_refScriptsTreeModel->append(row.children());
2175        Gtk::TreeModel::Row rowScript = *iterScript;
2176        rowScript[m_ScriptsModel.m_col_name] = name;
2177        rowScript[m_ScriptsModel.m_col_script] = script;
2178        rowScript[m_ScriptsModel.m_col_group]  = NULL;
2179    
2180        // unfold group of new script item in treeview
2181        Gtk::TreeModel::Path path(iterScript);
2182        m_TreeViewScripts.expand_to_path(path);
2183    }
2184    
2185    void MainWindow::on_action_edit_script() {
2186        if (!file) return;
2187        // get selected script
2188        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2189        Gtk::TreeModel::iterator it = sel->get_selected();
2190        if (!it) return;
2191        Gtk::TreeModel::Row row = *it;
2192        gig::Script* script = row[m_ScriptsModel.m_col_script];
2193        if (!script) return;
2194    
2195        ScriptEditor* editor = new ScriptEditor;
2196        editor->setScript(script);
2197        //editor->reparent(*this);
2198        editor->show();
2199    }
2200    
2201    void MainWindow::on_action_remove_script() {
2202        if (!file) return;
2203        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2204        Gtk::TreeModel::iterator it = sel->get_selected();
2205        if (it) {
2206            Gtk::TreeModel::Row row = *it;
2207            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2208            gig::Script* script     = row[m_ScriptsModel.m_col_script];
2209            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2210            try {
2211                // remove script group or script from the gig file
2212                if (group) {
2213                    // notify everybody that we're going to remove these samples
2214    //TODO:         scripts_to_be_removed_signal.emit(members);
2215                    // delete the group in the .gig file including the
2216                    // samples that belong to the group
2217                    file->DeleteScriptGroup(group);
2218                    // notify that we're done with removal
2219    //TODO:         scripts_removed_signal.emit();
2220                    file_changed();
2221                } else if (script) {
2222                    // notify everybody that we're going to remove this sample
2223    //TODO:         std::list<gig::Script*> lscripts;
2224    //TODO:         lscripts.push_back(script);
2225    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2226                    // remove sample from the .gig file
2227                    script->GetGroup()->DeleteScript(script);
2228                    // notify that we're done with removal
2229    //TODO:         scripts_removed_signal.emit();
2230                    dimreg_changed();
2231                    file_changed();
2232                }
2233                // remove respective row(s) from samples tree view
2234                m_refScriptsTreeModel->erase(it);
2235            } catch (RIFF::Exception e) {
2236                // pretend we're done with removal (i.e. to avoid dead locks)
2237    //TODO:     scripts_removed_signal.emit();
2238                // show error message
2239                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2240                msg.run();
2241            }
2242        }
2243    }
2244    
2245  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2246      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2247      if (!file) return;      if (!file) return;
2248      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
2249      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
2250      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
2251      __sample_indexer++;      __sample_indexer++;
2252      // update sample tree view      // update sample tree view
2253      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
2254      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
2255      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
2256      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
2257      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
2258      file_changed();      file_changed();
# Line 1398  void MainWindow::on_action_add_sample() Line 2280  void MainWindow::on_action_add_sample()
2280      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2281      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2282      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
2283      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
2284        // matches all file types supported by libsndfile
2285    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2286        Gtk::FileFilter soundfilter;
2287    #else
2288        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
2289    #endif
2290      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
2291          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
2292          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1406  void MainWindow::on_action_add_sample() Line 2294  void MainWindow::on_action_add_sample()
2294          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
2295          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
2296      };      };
2297        const char* soundfiles = _("Sound Files");
2298        const char* allfiles = _("All Files");
2299    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2300      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
2301          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
2302      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
2303      Gtk::FileFilter allpassfilter; // matches every file  
2304        // matches every file
2305        Gtk::FileFilter allpassfilter;
2306      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
2307      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
2308    #else
2309        for (int i = 0; supportedFileTypes[i]; i++)
2310            soundfilter->add_pattern(supportedFileTypes[i]);
2311        soundfilter->set_name(soundfiles);
2312    
2313        // matches every file
2314        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
2315        allpassfilter->add_pattern("*.*");
2316        allpassfilter->set_name(allfiles);
2317    #endif
2318      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
2319      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
2320        if (current_sample_dir != "") {
2321            dialog.set_current_folder(current_sample_dir);
2322        }
2323      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2324            current_sample_dir = dialog.get_current_folder();
2325          Glib::ustring error_files;          Glib::ustring error_files;
2326          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
2327          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
2328               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
2329              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
2330              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1425  void MainWindow::on_action_add_sample() Line 2332  void MainWindow::on_action_add_sample()
2332              info.format = 0;              info.format = 0;
2333              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
2334              try {              try {
2335                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
2336                  int bitdepth;                  int bitdepth;
2337                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2338                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1441  void MainWindow::on_action_add_sample() Line 2348  void MainWindow::on_action_add_sample()
2348                          break;                          break;
2349                      default:                      default:
2350                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2351                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2352                  }                  }
2353                  // add a new sample to the .gig file                  // add a new sample to the .gig file
2354                  gig::Sample* sample = file->AddSample();                  gig::Sample* sample = file->AddSample();
# Line 1454  void MainWindow::on_action_add_sample() Line 2361  void MainWindow::on_action_add_sample()
2361                          break;                          break;
2362                      }                      }
2363                  }                  }
2364                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
2365                  sample->Channels = info.channels;                  sample->Channels = info.channels;
2366                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
2367                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1468  void MainWindow::on_action_add_sample() Line 2375  void MainWindow::on_action_add_sample()
2375                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
2376                  {                  {
2377                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
2378                        sample->FineTune      = instrument.detune;
2379    
 #if HAVE_SF_INSTRUMENT_LOOPS  
2380                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
2381                          sample->Loops = 1;                          sample->Loops = 1;
2382    
# Line 1489  void MainWindow::on_action_add_sample() Line 2396  void MainWindow::on_action_add_sample()
2396                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
2397                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
2398                      }                      }
 #endif  
2399                  }                  }
2400    
2401                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1507  void MainWindow::on_action_add_sample() Line 2413  void MainWindow::on_action_add_sample()
2413                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
2414                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
2415                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
2416                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
2417                        gig_to_utf8(sample->pInfo->Name);
2418                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
2419                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
2420                  // close sound file                  // close sound file
2421                  sf_close(hFile);                  sf_close(hFile);
2422                  file_changed();                  file_changed();
2423              } 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)
2424                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2425                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
2426              }              }
2427          }          }
2428          // 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
2429          if (error_files.size()) {          if (!error_files.empty()) {
2430              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;
2431              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2432              msg.run();              msg.run();
# Line 1532  void MainWindow::on_action_replace_all_s Line 2439  void MainWindow::on_action_replace_all_s
2439      if (!file) return;      if (!file) return;
2440      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
2441                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
2442      Gtk::Label description(      const char* str =
2443          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
2444            "in the current gig file by samples located in the directory chosen "            "in the current gig file by samples located in the chosen "
2445            "by you above.\n\n"            "directory.\n\n"
2446            "It works like this: For each sample in the gig file it tries to "            "It works like this: For each sample in the gig file, it tries to "
2447            "find a sample file in the selected directory with the same name as "            "find a sample file in the selected directory with the same name as "
2448            "the sample in the gig file. Optionally you can add a filename "            "the sample in the gig file. Optionally, you can add a filename "
2449            "postfix below, which will be added to the filename expected to be "            "extension below, which will be added to the filename expected to be "
2450            "found. That is, assume you have a gig file with a sample called "            "found. That is, assume you have a gig file with a sample called "
2451            "'Snare', if you enter '.wav' below (like it's done by default), it "            "'Snare', if you enter '.wav' below (like it's done by default), it "
2452            "assumes to find a sample file called 'Snare.wav' and will replace "            "expects to find a sample file called 'Snare.wav' and will replace "
2453            "the sample in the gig file accordingly. If you don't need such a "            "the sample in the gig file accordingly. If you don't need an "
2454            "postfix, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
2455            "appropriate sample file could be found, will be reported and left "            "appropriate sample file could be found will be reported and left "
2456            "untouched.\n\n")            "untouched.\n");
2457      );  #if GTKMM_MAJOR_VERSION < 3
2458      description.set_line_wrap(true);      view::WrapLabel description(str);
2459    #else
2460        Gtk::Label description(str);
2461        description.set_line_wrap();
2462    #endif
2463      Gtk::HBox entryArea;      Gtk::HBox entryArea;
2464      Gtk::Label entryLabel( _("Add Filename Extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
2465      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
2466      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
2467      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1558  void MainWindow::on_action_replace_all_s Line 2469  void MainWindow::on_action_replace_all_s
2469      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
2470      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2471      description.show();      description.show();
2472      entryLabel.show();      entryArea.show_all();
     postfixEntryBox.show();  
     entryArea.show();  
2473      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2474      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2475      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2476      // fix label width (because Gtk by design doesn't      if (current_sample_dir != "") {
2477      // know anything about the parent's size)          dialog.set_current_folder(current_sample_dir);
2478  #if 0 //FIXME: doesn't work      }
     int dialogW, dialogH, labelW, labelH;  
     dialog.get_size_request(dialogW, dialogH);  
     description.get_size_request(labelW, labelH);  
     std::cout << "dialog(" << dialogW << "," << dialogH << ")\nlabel(" << labelW << "," << labelH << ")\n" << std::flush;  
     description.set_size_request(dialogW, labelH);  
 #endif  
2479      if (dialog.run() == Gtk::RESPONSE_OK)      if (dialog.run() == Gtk::RESPONSE_OK)
2480      {      {
2481            current_sample_dir = dialog.get_current_folder();
2482          Glib::ustring error_files;          Glib::ustring error_files;
2483          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
2484          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
2485               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
2486          {          {
2487              std::string filename =              std::string filename =
2488                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
2489                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2490                                             postfixEntryBox.get_text());
2491              SF_INFO info;              SF_INFO info;
2492              info.format = 0;              info.format = 0;
2493              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
2494              try              try
2495              {              {
2496                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
2497                  int bitdepth;                  int bitdepth;
2498                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2499                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1604  void MainWindow::on_action_replace_all_s Line 2509  void MainWindow::on_action_replace_all_s
2509                          break;                          break;
2510                      default:                      default:
2511                          sf_close(hFile);                          sf_close(hFile);
2512                          throw std::string("format not supported");                          throw std::string(_("format not supported"));
2513                  }                  }
2514                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2515                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
# Line 1615  void MainWindow::on_action_replace_all_s Line 2520  void MainWindow::on_action_replace_all_s
2520              }              }
2521              catch (std::string what)              catch (std::string what)
2522              {              {
2523                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2524                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
2525                        " (" + what + ")";
2526              }              }
2527          }          }
2528          // 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
2529          if (error_files.size()) {          if (!error_files.empty()) {
2530              Glib::ustring txt =              Glib::ustring txt =
2531                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
2532              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1641  void MainWindow::on_action_remove_sample Line 2547  void MainWindow::on_action_remove_sample
2547          try {          try {
2548              // remove group or sample from the gig file              // remove group or sample from the gig file
2549              if (group) {              if (group) {
2550                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2551                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2552                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2553                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1705  void MainWindow::on_action_remove_sample Line 2611  void MainWindow::on_action_remove_sample
2611      }      }
2612  }  }
2613    
2614    // see comment on on_sample_treeview_drag_begin()
2615    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2616    {
2617        first_call_to_drag_data_get = true;
2618    }
2619    
2620    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2621                                                       Gtk::SelectionData& selection_data, guint, guint)
2622    {
2623        if (!first_call_to_drag_data_get) return;
2624        first_call_to_drag_data_get = false;
2625    
2626        // get selected script
2627        gig::Script* script = NULL;
2628        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2629        Gtk::TreeModel::iterator it = sel->get_selected();
2630        if (it) {
2631            Gtk::TreeModel::Row row = *it;
2632            script = row[m_ScriptsModel.m_col_script];
2633        }
2634        // pass the gig::Script as pointer
2635        selection_data.set(selection_data.get_target(), 0/*unused*/,
2636                           (const guchar*)&script,
2637                           sizeof(script)/*length of data in bytes*/);
2638    }
2639    
2640  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2641  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
2642  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 1763  void MainWindow::on_sample_label_drop_dr Line 2695  void MainWindow::on_sample_label_drop_dr
2695          bool channels_changed = false;          bool channels_changed = false;
2696          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2697              // remove the samplechannel dimension              // remove the samplechannel dimension
2698    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2699              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2700              channels_changed = true;              channels_changed = true;
2701              region_changed();              region_changed();
2702    */
2703          }          }
2704          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2705                sample,
2706                is_copy_samples_unity_note_enabled(),
2707                is_copy_samples_fine_tune_enabled(),
2708                is_copy_samples_loop_enabled()
2709            );
2710    
2711          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2712              // add samplechannel dimension              // add samplechannel dimension
# Line 1810  void MainWindow::sample_name_changed(con Line 2749  void MainWindow::sample_name_changed(con
2749      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2750      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2751      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2752        gig::String gigname(gig_from_utf8(name));
2753      if (group) {      if (group) {
2754          if (group->Name != name) {          if (group->Name != gigname) {
2755              group->Name = name;              group->Name = gigname;
2756              printf("group name changed\n");              printf("group name changed\n");
2757              file_changed();              file_changed();
2758          }          }
2759      } else if (sample) {      } else if (sample) {
2760          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2761              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2762              printf("sample name changed\n");              printf("sample name changed\n");
2763              file_changed();              file_changed();
2764          }          }
2765      }      }
2766  }  }
2767    
2768    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2769                                         const Gtk::TreeModel::iterator& iter) {
2770        if (!iter) return;
2771        Gtk::TreeModel::Row row = *iter;
2772        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2773        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2774        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2775        gig::String gigname(gig_from_utf8(name));
2776        if (group) {
2777            if (group->Name != gigname) {
2778                group->Name = gigname;
2779                printf("script group name changed\n");
2780                file_changed();
2781            }
2782        } else if (script) {
2783            if (script->Name != gigname) {
2784                script->Name = gigname;
2785                printf("script name changed\n");
2786                file_changed();
2787            }
2788        }
2789    }
2790    
2791    void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
2792                                           Gtk::TreeViewColumn* column)
2793    {
2794        Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
2795        if (!iter) return;
2796        Gtk::TreeModel::Row row = *iter;
2797        gig::Script* script = row[m_ScriptsModel.m_col_script];
2798        if (!script) return;
2799    
2800        ScriptEditor* editor = new ScriptEditor;
2801        editor->setScript(script);
2802        //editor->reparent(*this);
2803        editor->show();
2804    }
2805    
2806  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2807                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2808      if (!iter) return;      if (!iter) return;
2809      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2810      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2811    
2812        // change name in instrument menu
2813        int index = path[0];
2814        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2815        if (index < children.size()) {
2816    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2817            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2818    #else
2819            remove_instrument_from_menu(index);
2820            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2821            item->set_active();
2822    #endif
2823        }
2824    
2825        // change name in gig
2826      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2827      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2828          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2829            instrument->pInfo->Name = gigname;
2830    
2831            // change name in the instrument properties window
2832            if (instrumentProps.get_instrument() == instrument) {
2833                instrumentProps.update_name();
2834            }
2835    
2836          file_changed();          file_changed();
2837      }      }
2838  }  }
2839    
2840    void MainWindow::on_action_combine_instruments() {
2841        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2842        d->show_all();
2843        d->resize(500, 400);
2844        d->run();
2845        if (d->fileWasChanged()) {
2846            // update GUI with new instrument just created
2847            add_instrument(d->newCombinedInstrument());
2848        }
2849        delete d;
2850    }
2851    
2852    void MainWindow::on_action_view_references() {
2853        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2854        Gtk::TreeModel::iterator it = sel->get_selected();
2855        if (!it) return;
2856        Gtk::TreeModel::Row row = *it;
2857        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2858        if (!sample) return;
2859    
2860        ReferencesView* d = new ReferencesView(*this);
2861        d->setSample(sample);
2862        d->show_all();
2863        d->resize(500, 400);
2864        d->run();
2865        delete d;
2866    }
2867    
2868    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2869        struct _Source {
2870            std::vector<RIFF::File*> riffs;
2871            std::vector<gig::File*> gigs;
2872            
2873            ~_Source() {
2874                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2875                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2876                riffs.clear();
2877                gigs.clear();
2878            }
2879        } sources;
2880    
2881        if (filenames.empty())
2882            throw RIFF::Exception(_("No files selected, so nothing done."));
2883    
2884        // first open all input files (to avoid output file corruption)
2885        int i;
2886        try {
2887            for (i = 0; i < filenames.size(); ++i) {
2888                const std::string& filename = filenames[i];
2889                printf("opening file=%s\n", filename.c_str());
2890    
2891                RIFF::File* riff = new RIFF::File(filename);
2892                sources.riffs.push_back(riff);
2893    
2894                gig::File* gig = new gig::File(riff);
2895                sources.gigs.push_back(gig);
2896            }
2897        } catch (RIFF::Exception e) {
2898            throw RIFF::Exception(
2899                _("Error occurred while opening '") +
2900                filenames[i] +
2901                "': " +
2902                e.Message
2903            );
2904        } catch (...) {
2905            throw RIFF::Exception(
2906                _("Unknown exception occurred while opening '") +
2907                filenames[i] + "'"
2908            );
2909        }
2910    
2911        // now merge the opened .gig files to the main .gig file currently being
2912        // open in gigedit
2913        try {
2914            for (i = 0; i < filenames.size(); ++i) {
2915                const std::string& filename = filenames[i];
2916                printf("merging file=%s\n", filename.c_str());
2917                assert(i < sources.gigs.size());
2918    
2919                this->file->AddContentOf(sources.gigs[i]);
2920            }
2921        } catch (RIFF::Exception e) {
2922            throw RIFF::Exception(
2923                _("Error occurred while merging '") +
2924                filenames[i] +
2925                "': " +
2926                e.Message
2927            );
2928        } catch (...) {
2929            throw RIFF::Exception(
2930                _("Unknown exception occurred while merging '") +
2931                filenames[i] + "'"
2932            );
2933        }
2934    
2935        // Finally save gig file persistently to disk ...
2936        //NOTE: requires that this gig file already has a filename !
2937        {
2938            std::cout << "Saving file\n" << std::flush;
2939            file_structure_to_be_changed_signal.emit(this->file);
2940    
2941            progress_dialog = new ProgressDialog( //FIXME: memory leak!
2942                _("Saving") +  Glib::ustring(" '") +
2943                Glib::filename_display_basename(this->filename) + "' ...",
2944                *this
2945            );
2946            progress_dialog->show_all();
2947            saver = new Saver(this->file); //FIXME: memory leak!
2948            saver->signal_progress().connect(
2949                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2950            saver->signal_finished().connect(
2951                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2952            saver->signal_error().connect(
2953                sigc::mem_fun(*this, &MainWindow::on_saver_error));
2954            saver->launch();
2955        }
2956    }
2957    
2958    void MainWindow::on_action_merge_files() {
2959        if (this->file->GetFileName().empty()) {
2960            Glib::ustring txt = _(
2961                "You seem to have a new .gig file open that has not been saved "
2962                "yet. You must save it somewhere before starting to merge it with "
2963                "other .gig files though, because during the merge operation the "
2964                "other files' sample data must be written on file level to the "
2965                "target .gig file."
2966            );
2967            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2968            msg.run();
2969            return;
2970        }
2971    
2972        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2973        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2974        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2975        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2976    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2977        Gtk::FileFilter filter;
2978        filter.add_pattern("*.gig");
2979    #else
2980        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2981        filter->add_pattern("*.gig");
2982    #endif
2983        dialog.set_filter(filter);
2984        if (current_gig_dir != "") {
2985            dialog.set_current_folder(current_gig_dir);
2986        }
2987        dialog.set_select_multiple(true);
2988    
2989        // show warning in the file picker dialog
2990        Gtk::HBox descriptionArea;
2991        descriptionArea.set_spacing(15);
2992        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2993        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2994    #if GTKMM_MAJOR_VERSION < 3
2995        view::WrapLabel description;
2996    #else
2997        Gtk::Label description;
2998        description.set_line_wrap();
2999    #endif
3000        description.set_markup(_(
3001            "\nSelect at least one .gig file that shall be merged to the .gig file "
3002            "currently being open in gigedit.\n\n"
3003            "<b>Please Note:</b> Merging with other files will modify your "
3004            "currently open .gig file on file level! And be aware that the current "
3005            "merge algorithm does not detect duplicate samples yet. So if you are "
3006            "merging files which are using equivalent sample data, those "
3007            "equivalent samples will currently be treated as separate samples and "
3008            "will accordingly be stored separately in the target .gig file!"
3009        ));
3010        descriptionArea.pack_start(description);
3011        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
3012        descriptionArea.show_all();
3013    
3014        if (dialog.run() == Gtk::RESPONSE_OK) {
3015            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
3016            std::vector<std::string> filenames = dialog.get_filenames();
3017    
3018            // merge the selected files to the currently open .gig file
3019            try {
3020                mergeFiles(filenames);
3021            } catch (RIFF::Exception e) {
3022                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
3023                msg.run();
3024            }
3025    
3026            // update GUI
3027            __refreshEntireGUI();        
3028        }
3029    }
3030    
3031  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
3032      this->file_is_shared = b;      this->file_is_shared = b;
3033    
# Line 1851  void MainWindow::set_file_is_shared(bool Line 3042  void MainWindow::set_file_is_shared(bool
3042              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
3043          );          );
3044      }      }
3045    
3046        {
3047            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
3048                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
3049            if (item) item->set_sensitive(b);
3050        }
3051    }
3052    
3053    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
3054        if (!sample) return;
3055        sample_ref_count[sample] += offset;
3056        const int refcount = sample_ref_count[sample];
3057    
3058        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3059        for (int g = 0; g < model->children().size(); ++g) {
3060            Gtk::TreeModel::Row rowGroup = model->children()[g];
3061            for (int s = 0; s < rowGroup.children().size(); ++s) {
3062                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3063                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
3064                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
3065                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
3066            }
3067        }
3068    }
3069    
3070    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
3071        on_sample_ref_count_incremented(oldSample, -1);
3072        on_sample_ref_count_incremented(newSample, +1);
3073    }
3074    
3075    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
3076        // just in case a new sample is added later with exactly the same memory
3077        // address, which would lead to incorrect refcount if not deleted here
3078        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
3079             it != samples.end(); ++it)
3080        {
3081            sample_ref_count.erase(*it);
3082        }
3083    }
3084    
3085    void MainWindow::show_samples_tab() {
3086        m_TreeViewNotebook.set_current_page(0);
3087    }
3088    
3089    void MainWindow::show_intruments_tab() {
3090        m_TreeViewNotebook.set_current_page(1);
3091    }
3092    
3093    void MainWindow::show_scripts_tab() {
3094        m_TreeViewNotebook.set_current_page(2);
3095  }  }
3096    
3097  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
# Line 1877  sigc::signal<void, gig::Region*>& MainWi Line 3118  sigc::signal<void, gig::Region*>& MainWi
3118      return region_changed_signal;      return region_changed_signal;
3119  }  }
3120    
3121    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
3122        return sample_changed_signal;
3123    }
3124    
3125  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
3126      return sample_ref_changed_signal;      return sample_ref_changed_signal;
3127  }  }
# Line 1904  sigc::signal<void, int/*key*/, int/*velo Line 3149  sigc::signal<void, int/*key*/, int/*velo
3149  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
3150      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
3151  }  }
3152    
3153    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
3154        return switch_sampler_instrument_signal;
3155    }

Legend:
Removed from v.1679  
changed lines
  Added in v.2691

  ViewVC Help
Powered by ViewVC