/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1714 by persson, Thu Mar 6 20:50:04 2008 UTC revision 2877 by schoenebeck, Fri Apr 15 13:45:12 2016 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006 - 2008 Andreas Persson   * Copyright (C) 2006-2016 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmmconfig.h>
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31    #include <glibmm/convert.h>
32    #include <glibmm/dispatcher.h>
33    #include <glibmm/miscutils.h>
34    #include <glibmm/stringutils.h>
35    #include <gtkmm/aboutdialog.h>
36  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
 #include <gtkmm/stock.h>  
38  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
39  #include <gtkmm/main.h>  #include <gtkmm/main.h>
40  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
41    #if GTKMM_MAJOR_VERSION < 3
42  #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>  
43  #endif  #endif
44    
45  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #include "global.h"
46  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  
47    
48  #include <stdio.h>  #include <stdio.h>
49  #include <sndfile.h>  #include <sndfile.h>
50    #include <assert.h>
51    
52  #include "mainwindow.h"  #include "mainwindow.h"
53    #include "Settings.h"
54    #include "CombineInstrumentsDialog.h"
55    #include "scripteditor.h"
56    #include "scriptslots.h"
57    #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    
 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++;  
 }  
61    
62  MainWindow::MainWindow() :  MainWindow::MainWindow() :
63        m_DimRegionChooser(*this),
64      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
65      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
66      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
# Line 98  MainWindow::MainWindow() : Line 73  MainWindow::MainWindow() :
73      add(m_VBox);      add(m_VBox);
74    
75      // Handle selection      // Handle selection
76      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
77          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
78    
79      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 115  MainWindow::MainWindow() : Line 89  MainWindow::MainWindow() :
89      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
90      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
91    
92        m_ScrolledWindowScripts.add(m_TreeViewScripts);
93        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
94    
95    
96      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
97    
# Line 128  MainWindow::MainWindow() : Line 105  MainWindow::MainWindow() :
105      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
106      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
107    
108        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
109      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."));
110      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."));
111        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)."));
112    
113        m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
114        m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
115        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
116    
117      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
118    
119      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
120      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),      actionGroup->add(Gtk::Action::create("New", _("_New")),
121                         Gtk::AccelKey("<control>n"),
122                       sigc::mem_fun(                       sigc::mem_fun(
123                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
124      Glib::RefPtr<Gtk::Action> action =      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),
125          Gtk::Action::create("Open", Gtk::Stock::OPEN);                       Gtk::AccelKey("<control>o"),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
126                       sigc::mem_fun(                       sigc::mem_fun(
127                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
128      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),      actionGroup->add(Gtk::Action::create("Save", _("_Save")),
129                         Gtk::AccelKey("<control>s"),
130                       sigc::mem_fun(                       sigc::mem_fun(
131                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
132      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
133                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
134                       sigc::mem_fun(                       sigc::mem_fun(
135                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
136      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
137                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
138                       sigc::mem_fun(                       sigc::mem_fun(
139                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
140      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
141                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
142                       sigc::mem_fun(                       sigc::mem_fun(
143                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
144      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("MidiRules",
145                                             _("_Midi Rules...")),
146                         sigc::mem_fun(
147                             *this, &MainWindow::show_midi_rules));
148        actionGroup->add(Gtk::Action::create("ScriptSlots",
149                                             _("_Script Slots...")),
150                         sigc::mem_fun(
151                             *this, &MainWindow::show_script_slots));
152        actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),
153                         Gtk::AccelKey("<control>q"),
154                       sigc::mem_fun(                       sigc::mem_fun(
155                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
156      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
157            Gtk::Action::create("MenuSample", _("_Sample")),
158            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
159        );
160        actionGroup->add(
161            Gtk::Action::create("MenuInstrument", _("_Instrument")),
162            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
163        );
164        actionGroup->add(
165            Gtk::Action::create("MenuScript", _("S_cript")),
166            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
167        );
168        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
169    
170        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
171    
     actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
172      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
173            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
174        toggle_action->set_active(true);
175        actionGroup->add(toggle_action);
176    
177        toggle_action =
178            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
179        toggle_action->set_active(true);
180        actionGroup->add(toggle_action);
181    
182        toggle_action =
183            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
184        toggle_action->set_active(true);
185        actionGroup->add(toggle_action);
186    
187    
188        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
189        toggle_action =
190          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
191      toggle_action->set_active(true);      toggle_action->set_active(true);
192      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
193                       sigc::mem_fun(                       sigc::mem_fun(
194                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
195        actionGroup->add(
196            Gtk::Action::create("RefreshAll", _("_Refresh All")),
197            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
198        );                
199    
200      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
201      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("About", _("_About")),
                                          action->property_label()));  
 #ifdef ABOUT_DIALOG  
     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),  
202                       sigc::mem_fun(                       sigc::mem_fun(
203                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
204      actionGroup->add(      actionGroup->add(
205          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
206          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
207      );      );
208      actionGroup->add(      actionGroup->add(
209          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
210            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
211        );
212        actionGroup->add(
213            Gtk::Action::create("RemoveInstrument", _("_Remove")),
214          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
215      );      );
216    
217    
218        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
219        
220        toggle_action =
221            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
222        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
223        actionGroup->add(
224            toggle_action,
225            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
226        );
227    
228        toggle_action =
229            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
230        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
231        actionGroup->add(
232            toggle_action,
233            sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
234        );
235    
236        toggle_action =
237            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
238        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
239        actionGroup->add(
240            toggle_action,
241            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
242        );
243    
244    
245        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
246    
247        actionGroup->add(
248            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
249            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
250        );
251    
252        actionGroup->add(
253            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
254            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
255        );
256    
257    
258      // sample right-click popup actions      // sample right-click popup actions
259      actionGroup->add(      actionGroup->add(
260          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
261          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
262      );      );
263      actionGroup->add(      actionGroup->add(
# Line 202  MainWindow::MainWindow() : Line 265  MainWindow::MainWindow() :
265          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
266      );      );
267      actionGroup->add(      actionGroup->add(
268          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
269          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
270      );      );
271      actionGroup->add(      actionGroup->add(
272          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
273          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
274      );      );
275      actionGroup->add(      actionGroup->add(
276          Gtk::Action::create("ReplaceAllSamplesInAllGroups", _("Replace All Samples In All Groups")),          Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
277            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
278        );
279        actionGroup->add(
280            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
281            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
282        );
283        actionGroup->add(
284            Gtk::Action::create("ReplaceSample",
285                                _("Replace Sample...")),
286            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
287        );
288        actionGroup->add(
289            Gtk::Action::create("ReplaceAllSamplesInAllGroups",
290                                _("Replace All Samples in All Groups...")),
291          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)
292      );      );
293        
294        // script right-click popup actions
295        actionGroup->add(
296            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
297            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
298        );
299        actionGroup->add(
300            Gtk::Action::create("AddScript", _("Add _Script")),
301            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
302        );
303        actionGroup->add(
304            Gtk::Action::create("EditScript", _("_Edit Script...")),
305            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
306        );
307        actionGroup->add(
308            Gtk::Action::create("RemoveScript", _("_Remove")),
309            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
310        );
311    
312      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
313      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 232  MainWindow::MainWindow() : Line 327  MainWindow::MainWindow() :
327          "      <separator/>"          "      <separator/>"
328          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
329          "    </menu>"          "    </menu>"
330            "    <menu action='MenuEdit'>"
331            "      <menuitem action='CopySampleUnity'/>"
332            "      <menuitem action='CopySampleTune'/>"
333            "      <menuitem action='CopySampleLoop'/>"
334            "    </menu>"
335            "    <menu action='MenuSample'>"
336            "      <menuitem action='SampleProperties'/>"
337            "      <menuitem action='AddGroup'/>"
338            "      <menuitem action='AddSample'/>"
339            "      <menuitem action='ShowSampleRefs'/>"
340            "      <menuitem action='ReplaceSample' />"
341            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
342            "      <separator/>"
343            "      <menuitem action='RemoveSample'/>"
344            "      <menuitem action='RemoveUnusedSamples'/>"
345            "    </menu>"
346          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
347            "      <menu action='AllInstruments'>"
348            "      </menu>"
349            "      <separator/>"
350            "      <menuitem action='InstrProperties'/>"
351            "      <menuitem action='MidiRules'/>"
352            "      <menuitem action='ScriptSlots'/>"
353            "      <menuitem action='AddInstrument'/>"
354            "      <menuitem action='DupInstrument'/>"
355            "      <separator/>"
356            "      <menuitem action='RemoveInstrument'/>"
357            "    </menu>"
358            "    <menu action='MenuScript'>"
359            "      <menuitem action='AddScriptGroup'/>"
360            "      <menuitem action='AddScript'/>"
361            "      <menuitem action='EditScript'/>"
362            "      <separator/>"
363            "      <menuitem action='RemoveScript'/>"
364          "    </menu>"          "    </menu>"
365          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
366          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
367            "      <separator/>"
368            "      <menuitem action='RefreshAll'/>"
369            "    </menu>"
370            "    <menu action='MenuTools'>"
371            "      <menuitem action='CombineInstruments'/>"
372            "      <menuitem action='MergeFiles'/>"
373            "    </menu>"
374            "    <menu action='MenuSettings'>"
375            "      <menuitem action='WarnUserOnExtensions'/>"
376            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
377            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
378          "    </menu>"          "    </menu>"
 #ifdef ABOUT_DIALOG  
379          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
380          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
381          "    </menu>"          "    </menu>"
 #endif  
382          "  </menubar>"          "  </menubar>"
383          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
384          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
385            "    <menuitem action='MidiRules'/>"
386            "    <menuitem action='ScriptSlots'/>"
387          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
388            "    <menuitem action='DupInstrument'/>"
389          "    <separator/>"          "    <separator/>"
390          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
391          "  </popup>"          "  </popup>"
# Line 253  MainWindow::MainWindow() : Line 393  MainWindow::MainWindow() :
393          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
394          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
395          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
396          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ShowSampleRefs'/>"
397            "    <menuitem action='ReplaceSample' />"
398            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
399          "    <separator/>"          "    <separator/>"
400          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
401            "    <menuitem action='RemoveUnusedSamples'/>"
402            "  </popup>"
403            "  <popup name='ScriptPopupMenu'>"
404            "    <menuitem action='AddScriptGroup'/>"
405            "    <menuitem action='AddScript'/>"
406            "    <menuitem action='EditScript'/>"
407            "    <separator/>"
408            "    <menuitem action='RemoveScript'/>"
409          "  </popup>"          "  </popup>"
410          "</ui>";          "</ui>";
411      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
412    
413      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
414        
415        // Set tooltips for menu items (for some reason, setting a tooltip on the
416        // respective Gtk::Action objects above will simply be ignored, no matter
417        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
418        // Gtk::Action::create()).
419        {
420            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
421                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
422            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."));
423        }
424        {
425            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
426                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
427            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."));
428        }
429        {
430            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
431                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
432            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."));
433        }
434        {
435            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
436                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
437            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."));
438        }
439        {
440            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
441                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
442            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)."));
443        }
444        {
445            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
446                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
447            item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
448        }
449        {
450            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
451                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
452            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
453            // copy tooltip to popup menu
454            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
455                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
456            item2->set_tooltip_text(item->get_tooltip_text());
457        }
458        {
459            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
460                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
461            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
462        }
463        {
464            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
465                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
466            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
467        }
468        {
469            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
470                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
471            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
472        }
473    
474    
475        instrument_menu = static_cast<Gtk::MenuItem*>(
476            uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
477    
478      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
479      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 270  MainWindow::MainWindow() : Line 483  MainWindow::MainWindow() :
483      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
484      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
485    
486        set_file_is_shared(false);
487    
488      // Status Bar:      // Status Bar:
489      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
490      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 284  MainWindow::MainWindow() : Line 499  MainWindow::MainWindow() :
499      // Create the Tree model:      // Create the Tree model:
500      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
501      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
502      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
503        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
504          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
505      );      );
506    
507      // Add the TreeView's view columns:      // Add the TreeView's view columns:
508      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);
509      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
510        
511        // establish drag&drop within the instrument tree view, allowing to reorder
512        // the sequence of instruments within the gig file
513        {
514            std::vector<Gtk::TargetEntry> drag_target_instrument;
515            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
516            m_TreeView.drag_source_set(drag_target_instrument);
517            m_TreeView.drag_dest_set(drag_target_instrument);
518            m_TreeView.signal_drag_begin().connect(
519                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
520            );
521            m_TreeView.signal_drag_data_get().connect(
522                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
523            );
524            m_TreeView.signal_drag_data_received().connect(
525                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
526            );
527        }
528    
529      // create samples treeview (including its data model)      // create samples treeview (including its data model)
530      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
531      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
532        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."));
533      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
534      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
535      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
536        {
537            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
538            Gtk::CellRendererText* cellrenderer =
539                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
540            column->add_attribute(
541                cellrenderer->property_foreground(), m_SamplesModel.m_color
542            );
543        }
544        {
545            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
546            Gtk::CellRendererText* cellrenderer =
547                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
548            column->add_attribute(
549                cellrenderer->property_foreground(), m_SamplesModel.m_color
550            );
551        }
552        m_TreeViewSamples.set_headers_visible(true);
553      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
554          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
555      );      );
# Line 305  MainWindow::MainWindow() : Line 557  MainWindow::MainWindow() :
557          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
558      );      );
559    
560        // create scripts treeview (including its data model)
561        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
562        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
563        m_TreeViewScripts.set_tooltip_text(_(
564            "Use CTRL + double click for editing a script."
565            "\n\n"
566            "Note: instrument scripts are a LinuxSampler extension of the gig "
567            "format. This feature will not work with the GigaStudio software!"
568        ));
569        // m_TreeViewScripts.set_reorderable();
570        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
571        m_TreeViewScripts.set_headers_visible(false);
572        m_TreeViewScripts.signal_button_press_event().connect_notify(
573            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
574        );
575        //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
576        m_TreeViewScripts.signal_row_activated().connect(
577            sigc::mem_fun(*this, &MainWindow::script_double_clicked)
578        );
579        m_refScriptsTreeModel->signal_row_changed().connect(
580            sigc::mem_fun(*this, &MainWindow::script_name_changed)
581        );
582    
583        // establish drag&drop between scripts tree view and ScriptSlots window
584        std::vector<Gtk::TargetEntry> drag_target_gig_script;
585        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
586        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
587        m_TreeViewScripts.signal_drag_begin().connect(
588            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
589        );
590        m_TreeViewScripts.signal_drag_data_get().connect(
591            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
592        );
593    
594      // 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
595      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
596      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
597      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
598      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
599          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 323  MainWindow::MainWindow() : Line 609  MainWindow::MainWindow() :
609          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
610      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
611          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
612        m_RegionChooser.signal_instrument_changed().connect(
613            sigc::mem_fun(*this, &MainWindow::region_changed));
614      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
615          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
616      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
617            sigc::mem_fun(*this, &MainWindow::file_changed));
618        propDialog.signal_changed().connect(
619          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
620      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
621          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
622    
623      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 336  MainWindow::MainWindow() : Line 626  MainWindow::MainWindow() :
626          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
627      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
628          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
629        sample_ref_changed_signal.connect(
630            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
631        );
632        samples_to_be_removed_signal.connect(
633            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
634        );
635    
636        dimreg_edit.signal_select_sample().connect(
637            sigc::mem_fun(*this, &MainWindow::select_sample)
638        );
639    
640      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
641          sigc::hide(          sigc::hide(
# Line 372  MainWindow::MainWindow() : Line 672  MainWindow::MainWindow() :
672    
673      file = 0;      file = 0;
674      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
675    
676      show_all_children();      show_all_children();
677    
678      // start with a new gig file by default      // start with a new gig file by default
679      on_action_file_new();      on_action_file_new();
680    
681        // select 'Instruments' tab by default
682        // (gtk allows this only if the tab childs are visible, thats why it's here)
683        m_TreeViewNotebook.set_current_page(1);
684  }  }
685    
686  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 403  void MainWindow::region_changed() Line 706  void MainWindow::region_changed()
706  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
707  {  {
708      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
709      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
710            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
711      if (it) {      if (it) {
712          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
713          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 459  void MainWindow::dimreg_all_dimregs_togg Line 761  void MainWindow::dimreg_all_dimregs_togg
761  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
762  {  {
763      update_dimregs();      update_dimregs();
764      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
765  }  }
766    
767  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
768  {  {
769        // select item in instrument menu
770        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
771        if (it) {
772            Gtk::TreePath path(it);
773            int index = path[0];
774            const std::vector<Gtk::Widget*> children =
775                instrument_menu->get_children();
776            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
777        }
778    
779      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
780    
781        if (Settings::singleton()->syncSamplerInstrumentSelection) {
782            switch_sampler_instrument_signal.emit(get_instrument());
783        }
784  }  }
785    
786  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 476  void loader_progress_callback(gig::progr Line 792  void loader_progress_callback(gig::progr
792  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
793  {  {
794      {      {
795          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
796          progress = fraction;          progress = fraction;
797      }      }
798      progress_dispatcher();      progress_dispatcher();
# Line 484  void Loader::progress_callback(float fra Line 800  void Loader::progress_callback(float fra
800    
801  void Loader::thread_function()  void Loader::thread_function()
802  {  {
803      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%p\n",
804      printf("Start %s\n", filename);             static_cast<void*>(Glib::Threads::Thread::self()));
805      RIFF::File* riff = new RIFF::File(filename);      printf("Start %s\n", filename.c_str());
806      gig = new gig::File(riff);      try {
807      gig::progress_t progress;          RIFF::File* riff = new RIFF::File(filename);
808      progress.callback = loader_progress_callback;          gig = new gig::File(riff);
809      progress.custom = this;          gig::progress_t progress;
810            progress.callback = loader_progress_callback;
811      gig->GetInstrument(0, &progress);          progress.custom = this;
812      printf("End\n");  
813      finished_dispatcher();          gig->GetInstrument(0, &progress);
814            printf("End\n");
815            finished_dispatcher();
816        } catch (RIFF::Exception e) {
817            error_message = e.Message;
818            error_dispatcher.emit();
819        } catch (...) {
820            error_message = _("Unknown exception occurred");
821            error_dispatcher.emit();
822        }
823  }  }
824    
825  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
826      : thread(0), filename(filename)      : filename(filename), gig(0), thread(0), progress(0.f)
827  {  {
828  }  }
829    
830  void Loader::launch()  void Loader::launch()
831  {  {
832    #ifdef OLD_THREADS
833      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
834      printf("launch thread=%x\n", thread);  #else
835        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
836    #endif
837        printf("launch thread=%p\n", static_cast<void*>(thread));
838  }  }
839    
840  float Loader::get_progress()  float Loader::get_progress()
841  {  {
842      float res;      float res;
843      {      {
844          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
845          res = progress;          res = progress;
846      }      }
847      return res;      return res;
# Line 528  Glib::Dispatcher& Loader::signal_finishe Line 857  Glib::Dispatcher& Loader::signal_finishe
857      return finished_dispatcher;      return finished_dispatcher;
858  }  }
859    
860  LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)  Glib::Dispatcher& Loader::signal_error()
861    {
862        return error_dispatcher;
863    }
864    
865    void saver_progress_callback(gig::progress_t* progress)
866    {
867        Saver* saver = static_cast<Saver*>(progress->custom);
868        saver->progress_callback(progress->factor);
869    }
870    
871    void Saver::progress_callback(float fraction)
872    {
873        {
874            Glib::Threads::Mutex::Lock lock(progressMutex);
875            progress = fraction;
876        }
877        progress_dispatcher.emit();
878    }
879    
880    void Saver::thread_function()
881    {
882        printf("thread_function self=%p\n",
883               static_cast<void*>(Glib::Threads::Thread::self()));
884        printf("Start %s\n", filename.c_str());
885        try {
886            gig::progress_t progress;
887            progress.callback = saver_progress_callback;
888            progress.custom = this;
889    
890            // if no filename was provided, that means "save", if filename was provided means "save as"
891            if (filename.empty()) {
892                gig->Save(&progress);
893            } else {
894                gig->Save(filename, &progress);
895            }
896    
897            printf("End\n");
898            finished_dispatcher.emit();
899        } catch (RIFF::Exception e) {
900            error_message = e.Message;
901            error_dispatcher.emit();
902        } catch (...) {
903            error_message = _("Unknown exception occurred");
904            error_dispatcher.emit();
905        }
906    }
907    
908    Saver::Saver(gig::File* file, Glib::ustring filename)
909        : gig(file), filename(filename), thread(0), progress(0.f)
910    {
911    }
912    
913    void Saver::launch()
914    {
915    #ifdef OLD_THREADS
916        thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
917    #else
918        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
919    #endif
920        printf("launch thread=%p\n", static_cast<void*>(thread));
921    }
922    
923    float Saver::get_progress()
924    {
925        float res;
926        {
927            Glib::Threads::Mutex::Lock lock(progressMutex);
928            res = progress;
929        }
930        return res;
931    }
932    
933    Glib::Dispatcher& Saver::signal_progress()
934    {
935        return progress_dispatcher;
936    }
937    
938    Glib::Dispatcher& Saver::signal_finished()
939    {
940        return finished_dispatcher;
941    }
942    
943    Glib::Dispatcher& Saver::signal_error()
944    {
945        return error_dispatcher;
946    }
947    
948    ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
949      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
950  {  {
951      get_vbox()->pack_start(progressBar);      get_vbox()->pack_start(progressBar);
952      show_all_children();      show_all_children();
953        resize(600,50);
954  }  }
955    
956  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
957  // 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.
958  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();  
959      // forget all samples that ought to be imported      // forget all samples that ought to be imported
960      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
961      // clear the samples and instruments tree views      // clear the samples and instruments tree views
962      m_refTreeModel->clear();      m_refTreeModel->clear();
963      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
964        m_refScriptsTreeModel->clear();
965        // remove all entries from "Instrument" menu
966        while (!instrument_menu->get_children().empty()) {
967            remove_instrument_from_menu(0);
968        }
969      // free libgig's gig::File instance      // free libgig's gig::File instance
970      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
971      file = NULL;      file = NULL;
972      set_file_is_shared(false);      set_file_is_shared(false);
973  }  }
974    
975    void MainWindow::__refreshEntireGUI() {
976        // clear the samples and instruments tree views
977        m_refTreeModel->clear();
978        m_refSamplesTreeModel->clear();
979        m_refScriptsTreeModel->clear();
980        // remove all entries from "Instrument" menu
981        while (!instrument_menu->get_children().empty()) {
982            remove_instrument_from_menu(0);
983        }
984    
985        if (!this->file) return;
986    
987        load_gig(
988            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
989        );
990    }
991    
992  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
993  {  {
994      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 569  void MainWindow::on_action_file_new() Line 1001  void MainWindow::on_action_file_new()
1001      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
1002      // already add one new instrument by default      // already add one new instrument by default
1003      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
1004      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
1005      // update GUI with that new gig::File      // update GUI with that new gig::File
1006      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
1007  }  }
# Line 580  bool MainWindow::close_confirmation_dial Line 1012  bool MainWindow::close_confirmation_dial
1012                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
1013      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
1014      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
1015      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  
1016      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1017      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1018      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);
1019      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1020      int response = dialog.run();      int response = dialog.run();
1021      dialog.hide();      dialog.hide();
1022      if (response == Gtk::RESPONSE_YES) return file_save();  
1023      return response != Gtk::RESPONSE_CANCEL;      // user decided to exit app without saving
1024        if (response == Gtk::RESPONSE_NO) return true;
1025    
1026        // user cancelled dialog, thus don't close app
1027        if (response == Gtk::RESPONSE_CANCEL) return false;
1028    
1029        // TODO: the following return valid is disabled and hard coded instead for
1030        // now, due to the fact that saving with progress bar is now implemented
1031        // asynchronously, as a result the app does not close automatically anymore
1032        // after saving the file has completed
1033        //
1034        //   if (response == Gtk::RESPONSE_YES) return file_save();
1035        //   return response != Gtk::RESPONSE_CANCEL;
1036        //
1037        if (response == Gtk::RESPONSE_YES) file_save();
1038        return false; // always prevent closing the app for now (see comment above)
1039  }  }
1040    
1041  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
1042      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
1043      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  
1044      dialog.set_secondary_text(      dialog.set_secondary_text(
1045          _("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 "
1046            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1047            "load it.")            "load it."));
    );  
 #endif  
1048      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1049      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1050      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1051      int response = dialog.run();      int response = dialog.run();
1052      dialog.hide();      dialog.hide();
# Line 618  void MainWindow::on_action_file_open() Line 1060  void MainWindow::on_action_file_open()
1060      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1061    
1062      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1063      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1064      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1065      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1066    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1067      Gtk::FileFilter filter;      Gtk::FileFilter filter;
1068      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
1069    #else
1070        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
1071        filter->add_pattern("*.gig");
1072    #endif
1073      dialog.set_filter(filter);      dialog.set_filter(filter);
1074      if (current_dir != "") {      if (current_gig_dir != "") {
1075          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
1076      }      }
1077      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1078          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1079          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1080          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%p\n",
1081                   static_cast<void*>(Glib::Threads::Thread::self()));
1082          load_file(filename.c_str());          load_file(filename.c_str());
1083          current_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1084      }      }
1085  }  }
1086    
1087  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
1088  {  {
1089      __clear();      __clear();
1090      load_dialog = new LoadDialog("Loading...", *this);  
1091      load_dialog->show_all();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1092      loader = new Loader(strdup(name));          _("Loading") +  Glib::ustring(" '") +
1093            Glib::filename_display_basename(name) + "' ...",
1094            *this
1095        );
1096        progress_dialog->show_all();
1097        loader = new Loader(name); //FIXME: memory leak!
1098      loader->signal_progress().connect(      loader->signal_progress().connect(
1099          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
1100      loader->signal_finished().connect(      loader->signal_finished().connect(
1101          sigc::mem_fun(*this, &MainWindow::on_loader_finished));          sigc::mem_fun(*this, &MainWindow::on_loader_finished));
1102        loader->signal_error().connect(
1103            sigc::mem_fun(*this, &MainWindow::on_loader_error));
1104      loader->launch();      loader->launch();
1105  }  }
1106    
# Line 661  void MainWindow::load_instrument(gig::In Line 1116  void MainWindow::load_instrument(gig::In
1116      // load the instrument      // load the instrument
1117      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
1118      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
1119      //TODO: automatically select the given instrument      // automatically select the given instrument
1120        int i = 0;
1121        for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
1122             instrument = pFile->GetNextInstrument(), ++i)
1123        {
1124            if (instrument == instr) {
1125                // select item in "instruments" tree view
1126                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
1127                // make sure the selected item in the "instruments" tree view is
1128                // visible (scroll to it)
1129                m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
1130                // select item in instrument menu
1131                {
1132                    const std::vector<Gtk::Widget*> children =
1133                        instrument_menu->get_children();
1134                    static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
1135                }
1136                // update region chooser and dimension region chooser
1137                m_RegionChooser.set_instrument(instr);
1138                break;
1139            }
1140        }
1141  }  }
1142    
1143  void MainWindow::on_loader_progress()  void MainWindow::on_loader_progress()
1144  {  {
1145      load_dialog->set_fraction(loader->get_progress());      progress_dialog->set_fraction(loader->get_progress());
1146  }  }
1147    
1148  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1149  {  {
1150      printf("Loader finished!\n");      printf("Loader finished!\n");
1151      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%p\n",
1152      load_gig(loader->gig, loader->filename);             static_cast<void*>(Glib::Threads::Thread::self()));
1153      load_dialog->hide();      load_gig(loader->gig, loader->filename.c_str());
1154        progress_dialog->hide();
1155    }
1156    
1157    void MainWindow::on_loader_error()
1158    {
1159        Glib::ustring txt = _("Could not load file: ") + loader->error_message;
1160        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1161        msg.run();
1162        progress_dialog->hide();
1163  }  }
1164    
1165  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
# Line 713  bool MainWindow::file_save() Line 1198  bool MainWindow::file_save()
1198    
1199      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
1200      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
1201      try {  
1202          file->Save();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1203          if (file_is_changed) {          _("Saving") +  Glib::ustring(" '") +
1204              set_title(get_title().substr(1));          Glib::filename_display_basename(this->filename) + "' ...",
1205              file_is_changed = false;          *this
1206          }      );
1207      } catch (RIFF::Exception e) {      progress_dialog->show_all();
1208          file_structure_changed_signal.emit(this->file);      saver = new Saver(this->file); //FIXME: memory leak!
1209          Glib::ustring txt = _("Could not save file: ") + e.Message;      saver->signal_progress().connect(
1210          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1211          msg.run();      saver->signal_finished().connect(
1212          return false;          sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1213      }      saver->signal_error().connect(
1214      std::cout << "Saving file done\n" << std::flush;          sigc::mem_fun(*this, &MainWindow::on_saver_error));
1215        saver->launch();
1216    
1217        return true;
1218    }
1219    
1220    void MainWindow::on_saver_progress()
1221    {
1222        progress_dialog->set_fraction(saver->get_progress());
1223    }
1224    
1225    void MainWindow::on_saver_error()
1226    {
1227        file_structure_changed_signal.emit(this->file);
1228        Glib::ustring txt = _("Could not save file: ") + saver->error_message;
1229        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1230        msg.run();
1231    }
1232    
1233    void MainWindow::on_saver_finished()
1234    {
1235        this->file = saver->gig;
1236        this->filename = saver->filename;
1237        current_gig_dir = Glib::path_get_dirname(filename);
1238        set_title(Glib::filename_display_basename(filename));
1239        file_has_name = true;
1240        file_is_changed = false;
1241        std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
1242      __import_queued_samples();      __import_queued_samples();
1243        std::cout << "Importing queued samples done.\n" << std::flush;
1244    
1245      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1246      return true;  
1247        __refreshEntireGUI();
1248        progress_dialog->hide();
1249  }  }
1250    
1251  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
# Line 740  void MainWindow::on_action_file_save_as( Line 1256  void MainWindow::on_action_file_save_as(
1256    
1257  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1258  {  {
1259      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1260      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1261      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1262      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  
1263      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1264      // TODO: an overwrite dialog for gtkmm < 2.8  
1265  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1266      Gtk::FileFilter filter;      Gtk::FileFilter filter;
1267      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
1268    #else
1269        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
1270        filter->add_pattern("*.gig");
1271    #endif
1272      dialog.set_filter(filter);      dialog.set_filter(filter);
1273    
1274      // set initial dir and filename of the Save As dialog      // set initial dir and filename of the Save As dialog
# Line 758  bool MainWindow::file_save_as() Line 1276  bool MainWindow::file_save_as()
1276      {      {
1277          std::string basename = Glib::path_get_basename(filename);          std::string basename = Glib::path_get_basename(filename);
1278          std::string dir = Glib::path_get_dirname(filename);          std::string dir = Glib::path_get_dirname(filename);
1279          basename = std::string("copy_of_") + basename;          basename = std::string(_("copy_of_")) + basename;
1280          Glib::ustring copyFileName = Glib::build_filename(dir, basename);          Glib::ustring copyFileName = Glib::build_filename(dir, basename);
1281          if (Glib::path_is_absolute(filename)) {          if (Glib::path_is_absolute(filename)) {
1282              dialog.set_filename(copyFileName);              dialog.set_filename(copyFileName);
1283          } else {          } else {
1284              if (current_dir != "") dialog.set_current_folder(current_dir);              if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
1285          }          }
1286          dialog.set_current_name(Glib::filename_display_basename(copyFileName));          dialog.set_current_name(Glib::filename_display_basename(copyFileName));
1287      }      }
# Line 771  bool MainWindow::file_save_as() Line 1289  bool MainWindow::file_save_as()
1289      // show warning in the dialog      // show warning in the dialog
1290      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1291      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1292      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1293        warningIcon.set_from_icon_name("dialog-warning",
1294                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1295      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1296      warningIcon.show();  #if GTKMM_MAJOR_VERSION < 3
1297        view::WrapLabel description;
1298    #else
1299      Gtk::Label description;      Gtk::Label description;
1300        description.set_line_wrap();
1301    #endif
1302      description.set_markup(      description.set_markup(
1303          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
1304            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 783  bool MainWindow::file_save_as() Line 1307  bool MainWindow::file_save_as()
1307            "<span style=\"italic\">\"Save As...\"</span> for writing to the "            "<span style=\"italic\">\"Save As...\"</span> for writing to the "
1308            "same .gig file will end up in corrupted sample wave data!\n")            "same .gig file will end up in corrupted sample wave data!\n")
1309      );      );
1310      description.set_line_wrap(true);      descriptionArea.pack_start(description);
     descriptionArea.pack_start(description, Gtk::PACK_SHRINK);  
     description.show();  
1311      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
1312      descriptionArea.show();      descriptionArea.show_all();
1313    
1314      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1315          file_structure_to_be_changed_signal.emit(this->file);          std::string filename = dialog.get_filename();
1316          try {          if (!Glib::str_has_suffix(filename, ".gig")) {
1317              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;  
1318          }          }
1319          __import_queued_samples();          printf("filename=%s\n", filename.c_str());
1320          file_structure_changed_signal.emit(this->file);  
1321            progress_dialog = new ProgressDialog( //FIXME: memory leak!
1322                _("Saving") +  Glib::ustring(" '") +
1323                Glib::filename_display_basename(filename) + "' ...",
1324                *this
1325            );
1326            progress_dialog->show_all();
1327    
1328            saver = new Saver(file, filename); //FIXME: memory leak!
1329            saver->signal_progress().connect(
1330                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1331            saver->signal_finished().connect(
1332                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1333            saver->signal_error().connect(
1334                sigc::mem_fun(*this, &MainWindow::on_saver_error));
1335            saver->launch();
1336    
1337          return true;          return true;
1338      }      }
1339      return false;      return false;
# Line 821  bool MainWindow::file_save_as() Line 1343  bool MainWindow::file_save_as()
1343  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1344      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1345      Glib::ustring error_files;      Glib::ustring error_files;
1346      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1347      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1348           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1349          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",(*iter).sample_path.c_str());
1350          SF_INFO info;          SF_INFO info;
1351          info.format = 0;          info.format = 0;
1352          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
1353            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1354          try {          try {
1355              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
1356              // determine sample's bit depth              // determine sample's bit depth
1357              int bitdepth;              int bitdepth;
1358              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 846  void MainWindow::__import_queued_samples Line 1369  void MainWindow::__import_queued_samples
1369                      break;                      break;
1370                  default:                  default:
1371                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
1372                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1373              }              }
1374    
1375              const int bufsize = 10000;              const int bufsize = 10000;
# Line 888  void MainWindow::__import_queued_samples Line 1411  void MainWindow::__import_queued_samples
1411              }              }
1412              // cleanup              // cleanup
1413              sf_close(hFile);              sf_close(hFile);
1414                // let the sampler re-cache the sample if needed
1415                sample_changed_signal.emit(iter->gig_sample);
1416              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1417              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1418              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 895  void MainWindow::__import_queued_samples Line 1420  void MainWindow::__import_queued_samples
1420              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1421          } catch (std::string what) {          } catch (std::string what) {
1422              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1423              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1424              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1425              ++iter;              ++iter;
1426          }          }
1427      }      }
1428      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
1429      if (error_files.size()) {      if (!error_files.empty()) {
1430          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;
1431          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1432          msg.run();          msg.run();
# Line 914  void MainWindow::on_action_file_properti Line 1439  void MainWindow::on_action_file_properti
1439      propDialog.deiconify();      propDialog.deiconify();
1440  }  }
1441    
1442    void MainWindow::on_action_warn_user_on_extensions() {
1443        Settings::singleton()->warnUserOnExtensions =
1444            !Settings::singleton()->warnUserOnExtensions;
1445    }
1446    
1447    void MainWindow::on_action_sync_sampler_instrument_selection() {
1448        Settings::singleton()->syncSamplerInstrumentSelection =
1449            !Settings::singleton()->syncSamplerInstrumentSelection;
1450    }
1451    
1452    void MainWindow::on_action_move_root_note_with_region_moved() {
1453        Settings::singleton()->moveRootNoteWithRegionMoved =
1454            !Settings::singleton()->moveRootNoteWithRegionMoved;
1455    }
1456    
1457  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1458  {  {
 #ifdef ABOUT_DIALOG  
1459      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
1460    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
1461        dialog.set_program_name("Gigedit");
1462    #else
1463        dialog.set_name("Gigedit");
1464    #endif
1465      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1466      dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");
1467      dialog.set_comments(      const std::string sComment =
1468          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1469          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1470          "Please notice that this is still a very young instrument editor. "          _(
1471          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1472          "this application.\n"              "\n"
1473          "\n"              "This program is distributed WITHOUT ANY WARRANTY; So better "
1474          "Please report bugs to: http://bugs.linuxsampler.org"              "backup your Gigasampler/GigaStudio files before editing them with "
1475      );              "this application.\n"
1476                "\n"
1477                "Please report bugs to: http://bugs.linuxsampler.org"
1478            );
1479        dialog.set_comments(sComment.c_str());
1480      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1481      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1482      dialog.run();      dialog.run();
 #endif  
1483  }  }
1484    
1485  PropDialog::PropDialog()  PropDialog::PropDialog()
1486      : table(2,1),      : eFileFormat(_("File Format")),
1487        eName("Name"),        eName(_("Name")),
1488        eCreationDate("Creation date"),        eCreationDate(_("Creation date")),
1489        eComments("Comments"),        eComments(_("Comments")),
1490        eProduct("Product"),        eProduct(_("Product")),
1491        eCopyright("Copyright"),        eCopyright(_("Copyright")),
1492        eArtists("Artists"),        eArtists(_("Artists")),
1493        eGenre("Genre"),        eGenre(_("Genre")),
1494        eKeywords("Keywords"),        eKeywords(_("Keywords")),
1495        eEngineer("Engineer"),        eEngineer(_("Engineer")),
1496        eTechnician("Technician"),        eTechnician(_("Technician")),
1497        eSoftware("Software"),        eSoftware(_("Software")),
1498        eMedium("Medium"),        eMedium(_("Medium")),
1499        eSource("Source"),        eSource(_("Source")),
1500        eSourceForm("Source form"),        eSourceForm(_("Source form")),
1501        eCommissioned("Commissioned"),        eCommissioned(_("Commissioned")),
1502        eSubject("Subject"),        eSubject(_("Subject")),
1503        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1504        update_model(0)        table(2, 1),
1505          m_file(NULL)
1506  {  {
1507      set_title("File Properties");      set_title(_("File Properties"));
1508      eName.set_width_chars(50);      eName.set_width_chars(50);
1509    
1510      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
# Line 976  PropDialog::PropDialog() Line 1524  PropDialog::PropDialog()
1524      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1525      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1526    
1527        table.add(eFileFormat);
1528      table.add(eName);      table.add(eName);
1529      table.add(eCreationDate);      table.add(eCreationDate);
1530      table.add(eComments);      table.add(eComments);
# Line 1002  PropDialog::PropDialog() Line 1551  PropDialog::PropDialog()
1551      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1552      buttonBox.show();      buttonBox.show();
1553      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1554      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1555      quitButton.grab_focus();      quitButton.grab_focus();
1556      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1557          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1558        eFileFormat.signal_value_changed().connect(
1559            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1560    
1561      quitButton.show();      quitButton.show();
1562      vbox.show();      vbox.show();
1563      show_all_children();      show_all_children();
1564  }  }
1565    
1566  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_file(gig::File* file)
1567  {  {
1568      this->info = info;      m_file = file;
1569      update_model++;  
1570      eName.set_value(info->Name);      // update file format version combo box
1571      eCreationDate.set_value(info->CreationDate);      const std::string sGiga = "Gigasampler/GigaStudio v";
1572      eComments.set_value(info->Comments);      const int major = file->pVersion->major;
1573      eProduct.set_value(info->Product);      std::vector<std::string> txts;
1574      eCopyright.set_value(info->Copyright);      std::vector<int> values;
1575      eArtists.set_value(info->Artists);      txts.push_back(sGiga + "2"); values.push_back(2);
1576      eGenre.set_value(info->Genre);      txts.push_back(sGiga + "3/v4"); values.push_back(3);
1577      eKeywords.set_value(info->Keywords);      if (major != 2 && major != 3) {
1578      eEngineer.set_value(info->Engineer);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
1579      eTechnician.set_value(info->Technician);      }
1580      eSoftware.set_value(info->Software);      std::vector<const char*> texts;
1581      eMedium.set_value(info->Medium);      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1582      eSource.set_value(info->Source);      texts.push_back(NULL); values.push_back(0);
1583      eSourceForm.set_value(info->SourceForm);      eFileFormat.set_choices(&texts[0], &values[0]);
1584      eCommissioned.set_value(info->Commissioned);      eFileFormat.set_value(major);
1585      eSubject.set_value(info->Subject);  }
1586      update_model--;  
1587    void PropDialog::onFileFormatChanged() {
1588        const int major = eFileFormat.get_value();
1589        if (m_file) m_file->pVersion->major = major;
1590  }  }
1591    
1592  sigc::signal<void>& PropDialog::signal_info_changed()  void PropDialog::set_info(DLS::Info* info)
1593  {  {
1594      return info_changed;      update(info);
1595  }  }
1596    
1597  void InstrumentProps::set_IsDrum(bool value)  
1598    void InstrumentProps::set_Name(const gig::String& name)
1599  {  {
1600      instrument->IsDrum = value;      m->pInfo->Name = name;
1601  }  }
1602    
1603  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1604  {  {
1605      instrument->MIDIBank = value;      update_model++;
1606        eName.set_value(m->pInfo->Name);
1607        update_model--;
1608  }  }
1609    
1610  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1611  {  {
1612      instrument->MIDIProgram = value;      m->IsDrum = value;
1613  }  }
1614    
1615  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1616  {  {
1617      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1618  }  }
1619    
1620  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1621  {  {
1622      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1623  }  }
1624    
1625  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1626      : table(2,1),      quitButton(_("_Close"), true),
1627        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1628        eName("Name"),      eName(_("Name")),
1629        eIsDrum("Is drum"),      eIsDrum(_("Is drum")),
1630        eMIDIBank("MIDI bank", 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1631        eMIDIProgram("MIDI program"),      eMIDIProgram(_("MIDI program")),
1632        eAttenuation("Attenuation", 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1633        eGainPlus6("Gain +6dB", eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1634        eEffectSend("Effect send", 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1635        eFineTune("Fine tune", -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1636        ePitchbendRange("Pitchbend range", 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1637        ePianoReleaseMode("Piano release mode"),      ePianoReleaseMode(_("Piano release mode")),
1638        eDimensionKeyRangeLow("Keyswitching range low"),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1639        eDimensionKeyRangeHigh("Keyswitching range high"),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1640  {  {
1641      set_title("Instrument Properties");      set_title(_("Instrument Properties"));
1642    
1643      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
1644          _("start of the keyboard area which should switch the "          _("start of the keyboard area which should switch the "
# Line 1099  InstrumentProps::InstrumentProps() Line 1649  InstrumentProps::InstrumentProps()
1649            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1650      );      );
1651    
1652        connect(eName, &InstrumentProps::set_Name);
1653      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1654      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1655      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1108  InstrumentProps::InstrumentProps() Line 1659  InstrumentProps::InstrumentProps()
1659      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1660      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1661      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1662      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1663              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1664      connect(eDimensionKeyRangeHigh,  
1665              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1666    
1667      table.set_col_spacings(5);      table.set_col_spacings(5);
1668    
# Line 1137  InstrumentProps::InstrumentProps() Line 1688  InstrumentProps::InstrumentProps()
1688      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1689      buttonBox.show();      buttonBox.show();
1690      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1691      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1692      quitButton.grab_focus();      quitButton.grab_focus();
1693    
1694      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1150  InstrumentProps::InstrumentProps() Line 1701  InstrumentProps::InstrumentProps()
1701    
1702  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1703  {  {
1704      this->instrument = instrument;      update(instrument);
1705    
1706      update_model++;      update_model++;
1707      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1708      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1709      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1710      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);  
1711      update_model--;      update_model--;
1712  }  }
1713    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1714    
1715  void MainWindow::file_changed()  void MainWindow::file_changed()
1716  {  {
# Line 1181  void MainWindow::file_changed() Line 1720  void MainWindow::file_changed()
1720      }      }
1721  }  }
1722    
1723    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1724        sample_ref_count.clear();
1725        
1726        if (!gig) return;
1727    
1728        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1729             instrument = gig->GetNextInstrument())
1730        {
1731            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1732                 rgn = instrument->GetNextRegion())
1733            {
1734                for (int i = 0; i < 256; ++i) {
1735                    if (!rgn->pDimensionRegions[i]) continue;
1736                    if (rgn->pDimensionRegions[i]->pSample) {
1737                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1738                    }
1739                }
1740            }
1741        }
1742    }
1743    
1744  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1745  {  {
1746      file = 0;      file = 0;
1747      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1748    
1749      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1750            (filename && strlen(filename) > 0) ?
1751                filename : (!gig->GetFileName().empty()) ?
1752                    gig->GetFileName() : _("Unsaved Gig File");
1753      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1754      file_has_name = filename;      file_has_name = filename;
1755      file_is_changed = false;      file_is_changed = false;
1756    
1757        propDialog.set_file(gig);
1758      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1759    
1760      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;  
1761      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1762           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1763            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1764    
1765          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1766          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1767          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1768          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1769          // create a menu item for this instrument  
1770          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++;  
1771      }      }
1772      instrument_menu->show();      instrument_name_connection.unblock();
1773      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1774    
1775        updateSampleRefCountMap(gig);
1776    
1777      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1778          if (group->Name != "") {          if (group->Name != "") {
1779              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1780              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1781              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1782              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1783              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1784              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1231  void MainWindow::load_gig(gig::File* gig Line 1786  void MainWindow::load_gig(gig::File* gig
1786                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1787                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1788                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1789                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1790                        gig_to_utf8(sample->pInfo->Name);
1791                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1792                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1793                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1794                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1795                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1796              }              }
1797          }          }
1798      }      }
1799        
1800        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1801            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1802    
1803            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1804            Gtk::TreeModel::Row rowGroup = *iterGroup;
1805            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1806            rowGroup[m_ScriptsModel.m_col_group]  = group;
1807            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1808            for (int s = 0; group->GetScript(s); ++s) {
1809                gig::Script* script = group->GetScript(s);
1810    
1811                Gtk::TreeModel::iterator iterScript =
1812                    m_refScriptsTreeModel->append(rowGroup.children());
1813                Gtk::TreeModel::Row rowScript = *iterScript;
1814                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1815                rowScript[m_ScriptsModel.m_col_script] = script;
1816                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1817            }
1818        }
1819        // unfold all sample groups & script groups by default
1820        m_TreeViewSamples.expand_all();
1821        m_TreeViewScripts.expand_all();
1822    
1823      file = gig;      file = gig;
1824    
1825      // select the first instrument      // select the first instrument
1826      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1827      tree_sel_ref->select(Gtk::TreePath("0"));  
1828        instr_props_set_instrument();
1829        gig::Instrument* instrument = get_instrument();
1830        if (instrument) {
1831            midiRules.set_instrument(instrument);
1832        }
1833  }  }
1834    
1835  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1836  {  {
1837      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1838      if (instrument)  
1839      {      Gtk::TreeModel::const_iterator it =
1840            m_TreeView.get_selection()->get_selected();
1841        if (it) {
1842            Gtk::TreeModel::Row row = *it;
1843            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1844    
1845          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1846    
1847            // make sure instrument tree is updated when user changes the
1848            // instrument name in instrument properties window
1849            instrumentProps.signal_name_changed().connect(
1850                sigc::bind(
1851                    sigc::mem_fun(*this,
1852                                  &MainWindow::instr_name_changed_by_instr_props),
1853                    it));
1854        } else {
1855            instrumentProps.hide();
1856        }
1857        return it;
1858    }
1859    
1860    void MainWindow::show_instr_props()
1861    {
1862        if (instr_props_set_instrument()) {
1863          instrumentProps.show();          instrumentProps.show();
1864          instrumentProps.deiconify();          instrumentProps.deiconify();
1865      }      }
1866  }  }
1867    
1868    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1869    {
1870        Gtk::TreeModel::Row row = *it;
1871        Glib::ustring name = row[m_Columns.m_col_name];
1872    
1873        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1874        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1875        if (gigname != name) {
1876            row[m_Columns.m_col_name] = gigname;
1877        }
1878    }
1879    
1880    void MainWindow::show_midi_rules()
1881    {
1882        if (gig::Instrument* instrument = get_instrument())
1883        {
1884            midiRules.set_instrument(instrument);
1885            midiRules.show();
1886            midiRules.deiconify();
1887        }
1888    }
1889    
1890    void MainWindow::show_script_slots() {
1891        if (!file) return;
1892        // get selected instrument
1893        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1894        Gtk::TreeModel::iterator it = sel->get_selected();
1895        if (!it) return;
1896        Gtk::TreeModel::Row row = *it;
1897        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1898        if (!instrument) return;
1899    
1900        ScriptSlots* window = new ScriptSlots;
1901        window->setInstrument(instrument);
1902        //window->reparent(*this);
1903        window->show();
1904    }
1905    
1906    void MainWindow::on_action_refresh_all() {
1907        __refreshEntireGUI();
1908    }
1909    
1910  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1911      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1912          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1267  void MainWindow::on_action_view_status_b Line 1918  void MainWindow::on_action_view_status_b
1918      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1919  }  }
1920    
1921    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1922        Gtk::CheckMenuItem* item =
1923            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1924        if (!item) {
1925            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1926            return true;
1927        }
1928        return item->get_active();
1929    }
1930    
1931    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1932        Gtk::CheckMenuItem* item =
1933            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1934        if (!item) {
1935            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1936            return true;
1937        }
1938        return item->get_active();
1939    }
1940    
1941    bool MainWindow::is_copy_samples_loop_enabled() const {
1942        Gtk::CheckMenuItem* item =
1943            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1944        if (!item) {
1945            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1946            return true;
1947        }
1948        return item->get_active();
1949    }
1950    
1951  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1952  {  {
1953      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1954          show_instr_props();          show_instr_props();
1955      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1956            // gig v2 files have no midi rules
1957            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1958            static_cast<Gtk::MenuItem*>(
1959                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1960                    bEnabled
1961                );
1962            static_cast<Gtk::MenuItem*>(
1963                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1964                    bEnabled
1965                );
1966          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1967      }      }
1968  }  }
1969    
1970  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1971      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1972            const std::vector<Gtk::Widget*> children =
1973                instrument_menu->get_children();
1974            std::vector<Gtk::Widget*>::const_iterator it =
1975                find(children.begin(), children.end(), item);
1976            if (it != children.end()) {
1977                int index = it - children.begin();
1978                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1979    
1980                m_RegionChooser.set_instrument(file->GetInstrument(index));
1981            }
1982        }
1983    }
1984    
1985    void MainWindow::select_instrument(gig::Instrument* instrument) {
1986        if (!instrument) return;
1987    
1988        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1989        for (int i = 0; i < model->children().size(); ++i) {
1990            Gtk::TreeModel::Row row = model->children()[i];
1991            if (row[m_Columns.m_col_instr] == instrument) {
1992                // select and show the respective instrument in the list view
1993                show_intruments_tab();
1994                m_TreeView.get_selection()->select(model->children()[i]);
1995                Gtk::TreePath path(
1996                    m_TreeView.get_selection()->get_selected()
1997                );
1998                m_TreeView.scroll_to_row(path);
1999                on_sel_change(); // the regular instrument selection change callback
2000            }
2001        }
2002    }
2003    
2004    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
2005    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
2006        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2007        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2008    
2009        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2010        for (int i = 0; i < model->children().size(); ++i) {
2011            Gtk::TreeModel::Row row = model->children()[i];
2012            if (row[m_Columns.m_col_instr] == pInstrument) {
2013                // select and show the respective instrument in the list view
2014                show_intruments_tab();
2015                m_TreeView.get_selection()->select(model->children()[i]);
2016                Gtk::TreePath path(
2017                    m_TreeView.get_selection()->get_selected()
2018                );
2019                m_TreeView.scroll_to_row(path);
2020                on_sel_change(); // the regular instrument selection change callback
2021    
2022                // select respective region in the region selector
2023                m_RegionChooser.set_region(pRegion);
2024    
2025                // select and show the respective dimension region in the editor
2026                //update_dimregs();
2027                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2028                //dimreg_edit.set_dim_region(dimRgn);
2029    
2030                return true;
2031            }
2032        }
2033    
2034        return false;
2035    }
2036    
2037    void MainWindow::select_sample(gig::Sample* sample) {
2038        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2039        for (int g = 0; g < model->children().size(); ++g) {
2040            Gtk::TreeModel::Row rowGroup = model->children()[g];
2041            for (int s = 0; s < rowGroup.children().size(); ++s) {
2042                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2043                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2044                    show_samples_tab();
2045                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2046                    Gtk::TreePath path(
2047                        m_TreeViewSamples.get_selection()->get_selected()
2048                    );
2049                    m_TreeViewSamples.scroll_to_row(path);
2050                    return;
2051                }
2052            }
2053        }
2054  }  }
2055    
2056  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1294  void MainWindow::on_sample_treeview_butt Line 2067  void MainWindow::on_sample_treeview_butt
2067              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
2068              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
2069          }          }
2070            
2071                
2072          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2073              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2074          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2075              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2076          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2077              set_sensitive(file);              set_sensitive(file);
2078            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2079                set_sensitive(sample_selected);
2080          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2081              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2082          // show sample popup          // show sample popup
2083          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2084    
2085            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2086                set_sensitive(group_selected || sample_selected);
2087            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2088                set_sensitive(group_selected || sample_selected);
2089            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2090                set_sensitive(file);
2091            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2092                set_sensitive(sample_selected);
2093            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2094                set_sensitive(group_selected || sample_selected);
2095      }      }
2096  }  }
2097    
2098  void MainWindow::on_action_add_instrument() {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
2099      static int __instrument_indexer = 0;      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2100      if (!file) return;          Gtk::Menu* script_popup =
2101      gig::Instrument* instrument = file->AddInstrument();              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
2102      __instrument_indexer++;          // update enabled/disabled state of sample popup items
2103      instrument->pInfo->Name =          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2104          "Unnamed Instrument " + ToString(__instrument_indexer);          Gtk::TreeModel::iterator it = sel->get_selected();
2105            bool group_selected  = false;
2106            bool script_selected = false;
2107            if (it) {
2108                Gtk::TreeModel::Row row = *it;
2109                group_selected  = row[m_ScriptsModel.m_col_group];
2110                script_selected = row[m_ScriptsModel.m_col_script];
2111            }
2112            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
2113                set_sensitive(group_selected || script_selected);
2114            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
2115                set_sensitive(file);
2116            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
2117                set_sensitive(script_selected);    
2118            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
2119                set_sensitive(group_selected || script_selected);
2120            // show sample popup
2121            script_popup->popup(button->button, button->time);
2122    
2123            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
2124                set_sensitive(group_selected || script_selected);
2125            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
2126                set_sensitive(file);
2127            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
2128                set_sensitive(script_selected);    
2129            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
2130                set_sensitive(group_selected || script_selected);
2131        }
2132    }
2133    
2134    Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
2135        const Glib::ustring& name, int position) {
2136    
2137        Gtk::RadioMenuItem::Group instrument_group;
2138        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2139        if (!children.empty()) {
2140            instrument_group =
2141                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
2142        }
2143        Gtk::RadioMenuItem* item =
2144            new Gtk::RadioMenuItem(instrument_group, name);
2145        if (position < 0) {
2146            instrument_menu->append(*item);
2147        } else {
2148            instrument_menu->insert(*item, position);
2149        }
2150        item->show();
2151        item->signal_activate().connect(
2152            sigc::bind(
2153                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
2154                item));
2155        return item;
2156    }
2157    
2158    void MainWindow::remove_instrument_from_menu(int index) {
2159        const std::vector<Gtk::Widget*> children =
2160            instrument_menu->get_children();
2161        Gtk::Widget* child = children[index];
2162        instrument_menu->remove(*child);
2163        delete child;
2164    }
2165    
2166    void MainWindow::add_instrument(gig::Instrument* instrument) {
2167        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2168    
2169      // update instrument tree view      // update instrument tree view
2170        instrument_name_connection.block();
2171      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2172      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2173      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
2174      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2175        instrument_name_connection.unblock();
2176    
2177        add_instrument_to_menu(name);
2178    
2179        m_TreeView.get_selection()->select(iterInstr);
2180    
2181      file_changed();      file_changed();
2182  }  }
2183    
2184    void MainWindow::on_action_add_instrument() {
2185        static int __instrument_indexer = 0;
2186        if (!file) return;
2187        gig::Instrument* instrument = file->AddInstrument();
2188        __instrument_indexer++;
2189        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
2190                                                ToString(__instrument_indexer));
2191    
2192        add_instrument(instrument);
2193    }
2194    
2195    void MainWindow::on_action_duplicate_instrument() {
2196        if (!file) return;
2197    
2198        // retrieve the currently selected instrument
2199        // (being the original instrument to be duplicated)
2200        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2201        Gtk::TreeModel::iterator itSelection = sel->get_selected();
2202        if (!itSelection) return;
2203        Gtk::TreeModel::Row row = *itSelection;
2204        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2205        if (!instrOrig) return;
2206    
2207        // duplicate the orginal instrument
2208        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2209        instrNew->pInfo->Name =
2210            instrOrig->pInfo->Name +
2211            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2212    
2213        add_instrument(instrNew);
2214    }
2215    
2216  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
2217      if (!file) return;      if (!file) return;
2218      if (file_is_shared) {      if (file_is_shared) {
# Line 1341  void MainWindow::on_action_remove_instru Line 2232  void MainWindow::on_action_remove_instru
2232          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2233          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2234          try {          try {
2235                Gtk::TreePath path(it);
2236                int index = path[0];
2237    
2238              // remove instrument from the gig file              // remove instrument from the gig file
2239              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
2240              file_changed();              file_changed();
2241    
2242                remove_instrument_from_menu(index);
2243    
2244                // remove row from instruments tree view
2245                m_refTreeModel->erase(it);
2246    
2247    #if GTKMM_MAJOR_VERSION < 3
2248                // select another instrument (in gtk3 this is done
2249                // automatically)
2250                if (!m_refTreeModel->children().empty()) {
2251                    if (index == m_refTreeModel->children().size()) {
2252                        index--;
2253                    }
2254                    m_TreeView.get_selection()->select(
2255                        Gtk::TreePath(ToString(index)));
2256                }
2257    #endif
2258                instr_props_set_instrument();
2259                instr = get_instrument();
2260                if (instr) {
2261                    midiRules.set_instrument(instr);
2262                } else {
2263                    midiRules.hide();
2264                }
2265          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
2266              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2267              msg.run();              msg.run();
# Line 1356  void MainWindow::on_action_remove_instru Line 2272  void MainWindow::on_action_remove_instru
2272  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
2273      //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
2274      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
2275          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
2276      );      );
2277      msg.run();      msg.run();
2278  }  }
2279    
2280    void MainWindow::on_action_add_script_group() {
2281        static int __script_indexer = 0;
2282        if (!file) return;
2283        gig::ScriptGroup* group = file->AddScriptGroup();
2284        group->Name = gig_from_utf8(_("Unnamed Group"));
2285        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
2286        __script_indexer++;
2287        // update sample tree view
2288        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
2289        Gtk::TreeModel::Row rowGroup = *iterGroup;
2290        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
2291        rowGroup[m_ScriptsModel.m_col_script] = NULL;
2292        rowGroup[m_ScriptsModel.m_col_group] = group;
2293        file_changed();
2294    }
2295    
2296    void MainWindow::on_action_add_script() {
2297        if (!file) return;
2298        // get selected group
2299        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2300        Gtk::TreeModel::iterator it = sel->get_selected();
2301        if (!it) return;
2302        Gtk::TreeModel::Row row = *it;
2303        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2304        if (!group) { // not a group, but a script is selected (probably)
2305            gig::Script* script = row[m_ScriptsModel.m_col_script];
2306            if (!script) return;
2307            it = row.parent(); // resolve parent (that is the script's group)
2308            if (!it) return;
2309            row = *it;
2310            group = row[m_ScriptsModel.m_col_group];
2311            if (!group) return;
2312        }
2313    
2314        // add a new script to the .gig file
2315        gig::Script* script = group->AddScript();    
2316        Glib::ustring name = _("Unnamed Script");
2317        script->Name = gig_from_utf8(name);
2318    
2319        // add script to the tree view
2320        Gtk::TreeModel::iterator iterScript =
2321            m_refScriptsTreeModel->append(row.children());
2322        Gtk::TreeModel::Row rowScript = *iterScript;
2323        rowScript[m_ScriptsModel.m_col_name] = name;
2324        rowScript[m_ScriptsModel.m_col_script] = script;
2325        rowScript[m_ScriptsModel.m_col_group]  = NULL;
2326    
2327        // unfold group of new script item in treeview
2328        Gtk::TreeModel::Path path(iterScript);
2329        m_TreeViewScripts.expand_to_path(path);
2330    }
2331    
2332    void MainWindow::on_action_edit_script() {
2333        if (!file) return;
2334        // get selected script
2335        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2336        Gtk::TreeModel::iterator it = sel->get_selected();
2337        if (!it) return;
2338        Gtk::TreeModel::Row row = *it;
2339        gig::Script* script = row[m_ScriptsModel.m_col_script];
2340        if (!script) return;
2341    
2342        ScriptEditor* editor = new ScriptEditor;
2343        editor->setScript(script);
2344        //editor->reparent(*this);
2345        editor->show();
2346    }
2347    
2348    void MainWindow::on_action_remove_script() {
2349        if (!file) return;
2350        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2351        Gtk::TreeModel::iterator it = sel->get_selected();
2352        if (it) {
2353            Gtk::TreeModel::Row row = *it;
2354            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2355            gig::Script* script     = row[m_ScriptsModel.m_col_script];
2356            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2357            try {
2358                // remove script group or script from the gig file
2359                if (group) {
2360                    // notify everybody that we're going to remove these samples
2361    //TODO:         scripts_to_be_removed_signal.emit(members);
2362                    // delete the group in the .gig file including the
2363                    // samples that belong to the group
2364                    file->DeleteScriptGroup(group);
2365                    // notify that we're done with removal
2366    //TODO:         scripts_removed_signal.emit();
2367                    file_changed();
2368                } else if (script) {
2369                    // notify everybody that we're going to remove this sample
2370    //TODO:         std::list<gig::Script*> lscripts;
2371    //TODO:         lscripts.push_back(script);
2372    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2373                    // remove sample from the .gig file
2374                    script->GetGroup()->DeleteScript(script);
2375                    // notify that we're done with removal
2376    //TODO:         scripts_removed_signal.emit();
2377                    dimreg_changed();
2378                    file_changed();
2379                }
2380                // remove respective row(s) from samples tree view
2381                m_refScriptsTreeModel->erase(it);
2382            } catch (RIFF::Exception e) {
2383                // pretend we're done with removal (i.e. to avoid dead locks)
2384    //TODO:     scripts_removed_signal.emit();
2385                // show error message
2386                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2387                msg.run();
2388            }
2389        }
2390    }
2391    
2392  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2393      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2394      if (!file) return;      if (!file) return;
2395      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
2396      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
2397      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
2398      __sample_indexer++;      __sample_indexer++;
2399      // update sample tree view      // update sample tree view
2400      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
2401      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
2402      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
2403      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
2404      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
2405      file_changed();      file_changed();
2406  }  }
2407    
2408    void MainWindow::on_action_replace_sample() {
2409        add_or_replace_sample(true);
2410    }
2411    
2412  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2413        add_or_replace_sample(false);
2414    }
2415    
2416    void MainWindow::add_or_replace_sample(bool replace) {
2417      if (!file) return;      if (!file) return;
2418      // get selected group  
2419        // get selected group (and probably selected sample)
2420      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2421      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
2422      if (!it) return;      if (!it) return;
2423      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2424        gig::Sample* sample = NULL;
2425      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2426      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2427          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2428          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2429          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2430          if (!it) return;          if (!it) return;
2431          row = *it;          if (!replace) row = *it;
2432          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2433          if (!group) return;          if (!group) return;
2434      }      }
2435        if (replace && !sample) return;
2436    
2437      // show 'browse for file' dialog      // show 'browse for file' dialog
2438      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2439      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2440      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2441      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2442      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
2443        // matches all file types supported by libsndfile
2444    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2445        Gtk::FileFilter soundfilter;
2446    #else
2447        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
2448    #endif
2449      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
2450          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
2451          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1407  void MainWindow::on_action_add_sample() Line 2453  void MainWindow::on_action_add_sample()
2453          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
2454          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
2455      };      };
2456        const char* soundfiles = _("Sound Files");
2457        const char* allfiles = _("All Files");
2458    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2459      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
2460          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
2461      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
2462      Gtk::FileFilter allpassfilter; // matches every file  
2463        // matches every file
2464        Gtk::FileFilter allpassfilter;
2465      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
2466      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
2467    #else
2468        for (int i = 0; supportedFileTypes[i]; i++)
2469            soundfilter->add_pattern(supportedFileTypes[i]);
2470        soundfilter->set_name(soundfiles);
2471    
2472        // matches every file
2473        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
2474        allpassfilter->add_pattern("*.*");
2475        allpassfilter->set_name(allfiles);
2476    #endif
2477      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
2478      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
2479        if (current_sample_dir != "") {
2480            dialog.set_current_folder(current_sample_dir);
2481        }
2482      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2483            current_sample_dir = dialog.get_current_folder();
2484          Glib::ustring error_files;          Glib::ustring error_files;
2485          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
2486          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
2487               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
2488              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
2489              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1426  void MainWindow::on_action_add_sample() Line 2491  void MainWindow::on_action_add_sample()
2491              info.format = 0;              info.format = 0;
2492              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
2493              try {              try {
2494                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
2495                  int bitdepth;                  int bitdepth;
2496                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2497                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1442  void MainWindow::on_action_add_sample() Line 2507  void MainWindow::on_action_add_sample()
2507                          break;                          break;
2508                      default:                      default:
2509                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2510                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2511                  }                  }
2512                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2513                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2514                  // file name without path                  // file name without path
2515                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2516                  // remove file extension if there is one                  // remove file extension if there is one
# Line 1455  void MainWindow::on_action_add_sample() Line 2520  void MainWindow::on_action_add_sample()
2520                          break;                          break;
2521                      }                      }
2522                  }                  }
2523                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
2524                  sample->Channels = info.channels;                  sample->Channels = info.channels;
2525                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
2526                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1469  void MainWindow::on_action_add_sample() Line 2534  void MainWindow::on_action_add_sample()
2534                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
2535                  {                  {
2536                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
2537                        sample->FineTune      = instrument.detune;
2538    
 #if HAVE_SF_INSTRUMENT_LOOPS  
2539                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
2540                          sample->Loops = 1;                          sample->Loops = 1;
2541    
# Line 1490  void MainWindow::on_action_add_sample() Line 2555  void MainWindow::on_action_add_sample()
2555                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
2556                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
2557                      }                      }
 #endif  
2558                  }                  }
2559    
2560                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
2561                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2562                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2563                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2564                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2565                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2566                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2567                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 1505  void MainWindow::on_action_add_sample() Line 2569  void MainWindow::on_action_add_sample()
2569                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2570                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2571                  // add sample to the tree view                  // add sample to the tree view
2572                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2573                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2574                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2575                  rowSample[m_SamplesModel.m_col_name]   = filename;                      Gtk::TreeModel::iterator iterSample =
2576                  rowSample[m_SamplesModel.m_col_sample] = sample;                          m_refSamplesTreeModel->append(row.children());
2577                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      Gtk::TreeModel::Row rowSample = *iterSample;
2578                        rowSample[m_SamplesModel.m_col_name] =
2579                            gig_to_utf8(sample->pInfo->Name);
2580                        rowSample[m_SamplesModel.m_col_sample] = sample;
2581                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2582                    }
2583                  // close sound file                  // close sound file
2584                  sf_close(hFile);                  sf_close(hFile);
2585                  file_changed();                  file_changed();
2586              } 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)
2587                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2588                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
2589              }              }
2590          }          }
2591          // 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
2592          if (error_files.size()) {          if (!error_files.empty()) {
2593              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2594                    (replace
2595                        ? _("Failed to replace sample with:\n")
2596                        : _("Could not add the following sample(s):\n"))
2597                    + error_files;
2598              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2599              msg.run();              msg.run();
2600          }          }
# Line 1533  void MainWindow::on_action_replace_all_s Line 2606  void MainWindow::on_action_replace_all_s
2606      if (!file) return;      if (!file) return;
2607      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
2608                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
2609      Gtk::Label description(      const char* str =
2610          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
2611            "in the current gig file by samples located in the directory chosen "            "in the current gig file by samples located in the chosen "
2612            "by you above.\n\n"            "directory.\n\n"
2613            "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 "
2614            "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 "
2615            "the sample in the gig file. Optionally you can add a filename "            "the sample in the gig file. Optionally, you can add a filename "
2616            "postfix below, which will be added to the filename expected to be "            "extension below, which will be added to the filename expected to be "
2617            "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 "
2618            "'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 "
2619            "assumes to find a sample file called 'Snare.wav' and will replace "            "expects to find a sample file called 'Snare.wav' and will replace "
2620            "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 "
2621            "postfix, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
2622            "appropriate sample file could be found, will be reported and left "            "appropriate sample file could be found will be reported and left "
2623            "untouched.\n\n")            "untouched.\n");
2624      );  #if GTKMM_MAJOR_VERSION < 3
2625      description.set_line_wrap(true);      view::WrapLabel description(str);
2626    #else
2627        Gtk::Label description(str);
2628        description.set_line_wrap();
2629    #endif
2630      Gtk::HBox entryArea;      Gtk::HBox entryArea;
2631      Gtk::Label entryLabel( _("Add Filename Extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
2632      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
2633      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
2634      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1559  void MainWindow::on_action_replace_all_s Line 2636  void MainWindow::on_action_replace_all_s
2636      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
2637      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2638      description.show();      description.show();
2639      entryLabel.show();      entryArea.show_all();
2640      postfixEntryBox.show();      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
     entryArea.show();  
     dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);  
2641      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2642      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2643      // fix label width (because Gtk by design doesn't      if (current_sample_dir != "") {
2644      // know anything about the parent's size)          dialog.set_current_folder(current_sample_dir);
2645  #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  
2646      if (dialog.run() == Gtk::RESPONSE_OK)      if (dialog.run() == Gtk::RESPONSE_OK)
2647      {      {
2648            current_sample_dir = dialog.get_current_folder();
2649          Glib::ustring error_files;          Glib::ustring error_files;
2650          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
2651          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
2652               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
2653          {          {
2654              std::string filename =              std::string filename =
2655                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
2656                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2657                                             postfixEntryBox.get_text());
2658              SF_INFO info;              SF_INFO info;
2659              info.format = 0;              info.format = 0;
2660              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
2661              try              try
2662              {              {
2663                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2664                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2665                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2666                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2667                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2668                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2669                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2670                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2671                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2672                          break;                          break;
2673                      default:                      default:
2674                          sf_close(hFile);                          sf_close(hFile);
2675                          throw std::string("format not supported");                          throw std::string(_("format not supported"));
2676                  }                  }
2677                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2678                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
# Line 1616  void MainWindow::on_action_replace_all_s Line 2683  void MainWindow::on_action_replace_all_s
2683              }              }
2684              catch (std::string what)              catch (std::string what)
2685              {              {
2686                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2687                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
2688                        " (" + what + ")";
2689              }              }
2690          }          }
2691          // 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
2692          if (error_files.size()) {          if (!error_files.empty()) {
2693              Glib::ustring txt =              Glib::ustring txt =
2694                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
2695              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1642  void MainWindow::on_action_remove_sample Line 2710  void MainWindow::on_action_remove_sample
2710          try {          try {
2711              // remove group or sample from the gig file              // remove group or sample from the gig file
2712              if (group) {              if (group) {
2713                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2714                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2715                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2716                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1706  void MainWindow::on_action_remove_sample Line 2774  void MainWindow::on_action_remove_sample
2774      }      }
2775  }  }
2776    
2777    void MainWindow::on_action_remove_unused_samples() {
2778        if (!file) return;
2779    
2780        // collect all samples that are not referenced by any instrument
2781        std::list<gig::Sample*> lsamples;
2782        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
2783            gig::Sample* sample = file->GetSample(iSample);
2784            bool isUsed = false;
2785            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
2786                                  instrument = file->GetNextInstrument())
2787            {
2788                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2789                                  rgn = instrument->GetNextRegion())
2790                {
2791                    for (int i = 0; i < 256; ++i) {
2792                        if (!rgn->pDimensionRegions[i]) continue;
2793                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
2794                        isUsed = true;
2795                        goto endOfRefSearch;
2796                    }
2797                }
2798            }
2799            endOfRefSearch:
2800            if (!isUsed) lsamples.push_back(sample);
2801        }
2802    
2803        if (lsamples.empty()) return;
2804    
2805        // notify everybody that we're going to remove these samples
2806        samples_to_be_removed_signal.emit(lsamples);
2807    
2808        // remove collected samples
2809        try {
2810            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
2811                 itSample != lsamples.end(); ++itSample)
2812            {
2813                gig::Sample* sample = *itSample;
2814                // remove sample from the .gig file
2815                file->DeleteSample(sample);
2816                // if sample was just previously added, remove it fro the import queue
2817                for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2818                     iter != m_SampleImportQueue.end(); ++iter)
2819                {
2820                    if ((*iter).gig_sample == sample) {
2821                        printf("Removing previously added sample '%s'\n",
2822                               (*iter).sample_path.c_str());
2823                        m_SampleImportQueue.erase(iter);
2824                        break;
2825                    }
2826                }
2827            }
2828        } catch (RIFF::Exception e) {
2829            // show error message
2830            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2831            msg.run();
2832        }
2833    
2834        // notify everybody that we're done with removal
2835        samples_removed_signal.emit();
2836    
2837        dimreg_changed();
2838        file_changed();
2839        __refreshEntireGUI();
2840    }
2841    
2842    // see comment on on_sample_treeview_drag_begin()
2843    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2844    {
2845        first_call_to_drag_data_get = true;
2846    }
2847    
2848    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2849                                                       Gtk::SelectionData& selection_data, guint, guint)
2850    {
2851        if (!first_call_to_drag_data_get) return;
2852        first_call_to_drag_data_get = false;
2853    
2854        // get selected script
2855        gig::Script* script = NULL;
2856        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2857        Gtk::TreeModel::iterator it = sel->get_selected();
2858        if (it) {
2859            Gtk::TreeModel::Row row = *it;
2860            script = row[m_ScriptsModel.m_col_script];
2861        }
2862        // pass the gig::Script as pointer
2863        selection_data.set(selection_data.get_target(), 0/*unused*/,
2864                           (const guchar*)&script,
2865                           sizeof(script)/*length of data in bytes*/);
2866    }
2867    
2868    // see comment on on_sample_treeview_drag_begin()
2869    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2870    {
2871        first_call_to_drag_data_get = true;
2872    }
2873    
2874    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2875                                                           Gtk::SelectionData& selection_data, guint, guint)
2876    {
2877        if (!first_call_to_drag_data_get) return;
2878        first_call_to_drag_data_get = false;
2879    
2880        // get selected source instrument
2881        gig::Instrument* src = NULL;
2882        {
2883            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2884            Gtk::TreeModel::iterator it = sel->get_selected();
2885            if (it) {
2886                Gtk::TreeModel::Row row = *it;
2887                src = row[m_Columns.m_col_instr];
2888            }
2889        }
2890        if (!src) return;
2891    
2892        // pass the source gig::Instrument as pointer
2893        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
2894                           sizeof(src)/*length of data in bytes*/);
2895    }
2896    
2897    void MainWindow::on_instruments_treeview_drop_drag_data_received(
2898        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
2899        const Gtk::SelectionData& selection_data, guint, guint time)
2900    {
2901        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
2902        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
2903            return;
2904    
2905        gig::Instrument* dst = NULL;
2906        {
2907            Gtk::TreeModel::Path path;
2908            const bool found = m_TreeView.get_path_at_pos(x, y, path);
2909            if (!found) return;
2910    
2911            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
2912            if (!iter) return;
2913            Gtk::TreeModel::Row row = *iter;
2914            dst = row[m_Columns.m_col_instr];
2915        }
2916        if (!dst) return;
2917    
2918        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
2919        src->MoveTo(dst);
2920        __refreshEntireGUI();
2921        select_instrument(src);
2922    }
2923    
2924  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2925  // 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
2926  // 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 1764  void MainWindow::on_sample_label_drop_dr Line 2979  void MainWindow::on_sample_label_drop_dr
2979          bool channels_changed = false;          bool channels_changed = false;
2980          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2981              // remove the samplechannel dimension              // remove the samplechannel dimension
2982    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2983              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2984              channels_changed = true;              channels_changed = true;
2985              region_changed();              region_changed();
2986    */
2987          }          }
2988          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2989                sample,
2990                is_copy_samples_unity_note_enabled(),
2991                is_copy_samples_fine_tune_enabled(),
2992                is_copy_samples_loop_enabled()
2993            );
2994    
2995          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2996              // add samplechannel dimension              // add samplechannel dimension
# Line 1811  void MainWindow::sample_name_changed(con Line 3033  void MainWindow::sample_name_changed(con
3033      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
3034      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
3035      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3036        gig::String gigname(gig_from_utf8(name));
3037      if (group) {      if (group) {
3038          if (group->Name != name) {          if (group->Name != gigname) {
3039              group->Name = name;              group->Name = gigname;
3040              printf("group name changed\n");              printf("group name changed\n");
3041              file_changed();              file_changed();
3042          }          }
3043      } else if (sample) {      } else if (sample) {
3044          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
3045              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
3046              printf("sample name changed\n");              printf("sample name changed\n");
3047              file_changed();              file_changed();
3048          }          }
3049      }      }
3050  }  }
3051    
3052    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
3053                                         const Gtk::TreeModel::iterator& iter) {
3054        if (!iter) return;
3055        Gtk::TreeModel::Row row = *iter;
3056        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
3057        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3058        gig::Script* script     = row[m_ScriptsModel.m_col_script];
3059        gig::String gigname(gig_from_utf8(name));
3060        if (group) {
3061            if (group->Name != gigname) {
3062                group->Name = gigname;
3063                printf("script group name changed\n");
3064                file_changed();
3065            }
3066        } else if (script) {
3067            if (script->Name != gigname) {
3068                script->Name = gigname;
3069                printf("script name changed\n");
3070                file_changed();
3071            }
3072        }
3073    }
3074    
3075    void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
3076                                           Gtk::TreeViewColumn* column)
3077    {
3078        Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
3079        if (!iter) return;
3080        Gtk::TreeModel::Row row = *iter;
3081        gig::Script* script = row[m_ScriptsModel.m_col_script];
3082        if (!script) return;
3083    
3084        ScriptEditor* editor = new ScriptEditor;
3085        editor->setScript(script);
3086        //editor->reparent(*this);
3087        editor->show();
3088    }
3089    
3090  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
3091                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
3092      if (!iter) return;      if (!iter) return;
3093      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
3094      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
3095    
3096        // change name in instrument menu
3097        int index = path[0];
3098        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
3099        if (index < children.size()) {
3100    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
3101            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
3102    #else
3103            remove_instrument_from_menu(index);
3104            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
3105            item->set_active();
3106    #endif
3107        }
3108    
3109        // change name in gig
3110      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
3111      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
3112          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
3113            instrument->pInfo->Name = gigname;
3114    
3115            // change name in the instrument properties window
3116            if (instrumentProps.get_instrument() == instrument) {
3117                instrumentProps.update_name();
3118            }
3119    
3120          file_changed();          file_changed();
3121      }      }
3122  }  }
3123    
3124    void MainWindow::on_action_combine_instruments() {
3125        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3126        d->show_all();
3127        d->resize(500, 400);
3128        d->run();
3129        if (d->fileWasChanged()) {
3130            // update GUI with new instrument just created
3131            add_instrument(d->newCombinedInstrument());
3132        }
3133        delete d;
3134    }
3135    
3136    void MainWindow::on_action_view_references() {
3137        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3138        Gtk::TreeModel::iterator it = sel->get_selected();
3139        if (!it) return;
3140        Gtk::TreeModel::Row row = *it;
3141        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3142        if (!sample) return;
3143    
3144        ReferencesView* d = new ReferencesView(*this);
3145        d->setSample(sample);
3146        d->dimension_region_selected.connect(
3147            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3148        );
3149        d->show_all();
3150        d->resize(500, 400);
3151        d->run();
3152        delete d;
3153    }
3154    
3155    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
3156        struct _Source {
3157            std::vector<RIFF::File*> riffs;
3158            std::vector<gig::File*> gigs;
3159            
3160            ~_Source() {
3161                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
3162                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
3163                riffs.clear();
3164                gigs.clear();
3165            }
3166        } sources;
3167    
3168        if (filenames.empty())
3169            throw RIFF::Exception(_("No files selected, so nothing done."));
3170    
3171        // first open all input files (to avoid output file corruption)
3172        int i;
3173        try {
3174            for (i = 0; i < filenames.size(); ++i) {
3175                const std::string& filename = filenames[i];
3176                printf("opening file=%s\n", filename.c_str());
3177    
3178                RIFF::File* riff = new RIFF::File(filename);
3179                sources.riffs.push_back(riff);
3180    
3181                gig::File* gig = new gig::File(riff);
3182                sources.gigs.push_back(gig);
3183            }
3184        } catch (RIFF::Exception e) {
3185            throw RIFF::Exception(
3186                _("Error occurred while opening '") +
3187                filenames[i] +
3188                "': " +
3189                e.Message
3190            );
3191        } catch (...) {
3192            throw RIFF::Exception(
3193                _("Unknown exception occurred while opening '") +
3194                filenames[i] + "'"
3195            );
3196        }
3197    
3198        // now merge the opened .gig files to the main .gig file currently being
3199        // open in gigedit
3200        try {
3201            for (i = 0; i < filenames.size(); ++i) {
3202                const std::string& filename = filenames[i];
3203                printf("merging file=%s\n", filename.c_str());
3204                assert(i < sources.gigs.size());
3205    
3206                this->file->AddContentOf(sources.gigs[i]);
3207            }
3208        } catch (RIFF::Exception e) {
3209            throw RIFF::Exception(
3210                _("Error occurred while merging '") +
3211                filenames[i] +
3212                "': " +
3213                e.Message
3214            );
3215        } catch (...) {
3216            throw RIFF::Exception(
3217                _("Unknown exception occurred while merging '") +
3218                filenames[i] + "'"
3219            );
3220        }
3221    
3222        // Finally save gig file persistently to disk ...
3223        //NOTE: requires that this gig file already has a filename !
3224        {
3225            std::cout << "Saving file\n" << std::flush;
3226            file_structure_to_be_changed_signal.emit(this->file);
3227    
3228            progress_dialog = new ProgressDialog( //FIXME: memory leak!
3229                _("Saving") +  Glib::ustring(" '") +
3230                Glib::filename_display_basename(this->filename) + "' ...",
3231                *this
3232            );
3233            progress_dialog->show_all();
3234            saver = new Saver(this->file); //FIXME: memory leak!
3235            saver->signal_progress().connect(
3236                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
3237            saver->signal_finished().connect(
3238                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
3239            saver->signal_error().connect(
3240                sigc::mem_fun(*this, &MainWindow::on_saver_error));
3241            saver->launch();
3242        }
3243    }
3244    
3245    void MainWindow::on_action_merge_files() {
3246        if (this->file->GetFileName().empty()) {
3247            Glib::ustring txt = _(
3248                "You seem to have a new .gig file open that has not been saved "
3249                "yet. You must save it somewhere before starting to merge it with "
3250                "other .gig files though, because during the merge operation the "
3251                "other files' sample data must be written on file level to the "
3252                "target .gig file."
3253            );
3254            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3255            msg.run();
3256            return;
3257        }
3258    
3259        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3260        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3261        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3262        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3263    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
3264        Gtk::FileFilter filter;
3265        filter.add_pattern("*.gig");
3266    #else
3267        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
3268        filter->add_pattern("*.gig");
3269    #endif
3270        dialog.set_filter(filter);
3271        if (current_gig_dir != "") {
3272            dialog.set_current_folder(current_gig_dir);
3273        }
3274        dialog.set_select_multiple(true);
3275    
3276        // show warning in the file picker dialog
3277        Gtk::HBox descriptionArea;
3278        descriptionArea.set_spacing(15);
3279        Gtk::Image warningIcon;
3280        warningIcon.set_from_icon_name("dialog-warning",
3281                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3282        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3283    #if GTKMM_MAJOR_VERSION < 3
3284        view::WrapLabel description;
3285    #else
3286        Gtk::Label description;
3287        description.set_line_wrap();
3288    #endif
3289        description.set_markup(_(
3290            "\nSelect at least one .gig file that shall be merged to the .gig file "
3291            "currently being open in gigedit.\n\n"
3292            "<b>Please Note:</b> Merging with other files will modify your "
3293            "currently open .gig file on file level! And be aware that the current "
3294            "merge algorithm does not detect duplicate samples yet. So if you are "
3295            "merging files which are using equivalent sample data, those "
3296            "equivalent samples will currently be treated as separate samples and "
3297            "will accordingly be stored separately in the target .gig file!"
3298        ));
3299        descriptionArea.pack_start(description);
3300        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
3301        descriptionArea.show_all();
3302    
3303        if (dialog.run() == Gtk::RESPONSE_OK) {
3304            printf("on_action_merge_files self=%p\n",
3305                   static_cast<void*>(Glib::Threads::Thread::self()));
3306            std::vector<std::string> filenames = dialog.get_filenames();
3307    
3308            // merge the selected files to the currently open .gig file
3309            try {
3310                mergeFiles(filenames);
3311            } catch (RIFF::Exception e) {
3312                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
3313                msg.run();
3314            }
3315    
3316            // update GUI
3317            __refreshEntireGUI();
3318        }
3319    }
3320    
3321  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
3322      this->file_is_shared = b;      this->file_is_shared = b;
3323    
# Line 1852  void MainWindow::set_file_is_shared(bool Line 3332  void MainWindow::set_file_is_shared(bool
3332              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
3333          );          );
3334      }      }
3335    
3336        {
3337            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
3338                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
3339            if (item) item->set_sensitive(b);
3340        }
3341    }
3342    
3343    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
3344        if (!sample) return;
3345        sample_ref_count[sample] += offset;
3346        const int refcount = sample_ref_count[sample];
3347    
3348        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3349        for (int g = 0; g < model->children().size(); ++g) {
3350            Gtk::TreeModel::Row rowGroup = model->children()[g];
3351            for (int s = 0; s < rowGroup.children().size(); ++s) {
3352                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3353                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
3354                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
3355                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
3356            }
3357        }
3358    }
3359    
3360    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
3361        on_sample_ref_count_incremented(oldSample, -1);
3362        on_sample_ref_count_incremented(newSample, +1);
3363    }
3364    
3365    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
3366        // just in case a new sample is added later with exactly the same memory
3367        // address, which would lead to incorrect refcount if not deleted here
3368        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
3369             it != samples.end(); ++it)
3370        {
3371            sample_ref_count.erase(*it);
3372        }
3373    }
3374    
3375    void MainWindow::show_samples_tab() {
3376        m_TreeViewNotebook.set_current_page(0);
3377    }
3378    
3379    void MainWindow::show_intruments_tab() {
3380        m_TreeViewNotebook.set_current_page(1);
3381    }
3382    
3383    void MainWindow::show_scripts_tab() {
3384        m_TreeViewNotebook.set_current_page(2);
3385  }  }
3386    
3387  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 1878  sigc::signal<void, gig::Region*>& MainWi Line 3408  sigc::signal<void, gig::Region*>& MainWi
3408      return region_changed_signal;      return region_changed_signal;
3409  }  }
3410    
3411    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
3412        return sample_changed_signal;
3413    }
3414    
3415  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() {
3416      return sample_ref_changed_signal;      return sample_ref_changed_signal;
3417  }  }
# Line 1905  sigc::signal<void, int/*key*/, int/*velo Line 3439  sigc::signal<void, int/*key*/, int/*velo
3439  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
3440      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
3441  }  }
3442    
3443    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
3444        return switch_sampler_instrument_signal;
3445    }

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

  ViewVC Help
Powered by ViewVC