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

  ViewVC Help
Powered by ViewVC