/[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 2398 by persson, Sun Jan 13 09:14:29 2013 UTC revision 2658 by persson, Tue Jun 24 02:50:05 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2013 Andreas Persson   * Copyright (C) 2006-2014 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 30  Line 30 
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
 #include <gtkmm/radiomenuitem.h>  
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
35  #include "wrapLabel.hh"  #include "wrapLabel.hh"
# Line 41  Line 40 
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46    #include "Settings.h"
47    #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49    #include "scriptslots.h"
50    #include "ReferencesView.h"
51  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
52  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
53    
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
   
 Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }  
   
 void Table::add(BoolEntry& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(BoolEntryPlus6& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(LabelWidget& prop)  
 {  
     attach(prop.label, 1, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     attach(prop.widget, 2, 3, rowno, rowno + 1,  
            Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
54    
55  MainWindow::MainWindow() :  MainWindow::MainWindow() :
56        m_DimRegionChooser(*this),
57      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
58      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
59      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
# Line 91  MainWindow::MainWindow() : Line 66  MainWindow::MainWindow() :
66      add(m_VBox);      add(m_VBox);
67    
68      // Handle selection      // Handle selection
69      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
70          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
71    
72      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 108  MainWindow::MainWindow() : Line 82  MainWindow::MainWindow() :
82      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
83      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
84    
85        m_ScrolledWindowScripts.add(m_TreeViewScripts);
86        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
87    
88    
89      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
90    
# Line 121  MainWindow::MainWindow() : Line 98  MainWindow::MainWindow() :
98      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
99      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
100    
101        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
102        dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
103        dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
104        dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
105    
106      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
107      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
108        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
109    
110      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
111    
# Line 155  MainWindow::MainWindow() : Line 136  MainWindow::MainWindow() :
136                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
137                       sigc::mem_fun(                       sigc::mem_fun(
138                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
139        actionGroup->add(Gtk::Action::create("MidiRules",
140                                             _("_Midi Rules...")),
141                         sigc::mem_fun(
142                             *this, &MainWindow::show_midi_rules));
143        actionGroup->add(Gtk::Action::create("ScriptSlots",
144                                             _("_Script Slots...")),
145                         sigc::mem_fun(
146                             *this, &MainWindow::show_script_slots));
147      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
148                       sigc::mem_fun(                       sigc::mem_fun(
149                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
150      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
151            Gtk::Action::create("MenuSample", _("_Sample")),
152            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
153        );
154        actionGroup->add(
155            Gtk::Action::create("MenuInstrument", _("_Instrument")),
156            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
157        );
158        actionGroup->add(
159            Gtk::Action::create("MenuScript", _("S_cript")),
160            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
161        );
162        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
163    
164        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
165    
     actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
166      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
167            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
168        toggle_action->set_active(true);
169        actionGroup->add(toggle_action);
170    
171        toggle_action =
172            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
173        toggle_action->set_active(true);
174        actionGroup->add(toggle_action);
175    
176        toggle_action =
177            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
178        toggle_action->set_active(true);
179        actionGroup->add(toggle_action);
180    
181    
182        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
183        toggle_action =
184          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
185      toggle_action->set_active(true);      toggle_action->set_active(true);
186      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 187  MainWindow::MainWindow() : Line 206  MainWindow::MainWindow() :
206          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
207      );      );
208    
209    
210        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
211        
212        toggle_action =
213            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
214        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
215        actionGroup->add(
216            toggle_action,
217            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
218        );
219    
220    
221        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
222    
223        actionGroup->add(
224            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
225            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
226        );
227    
228        actionGroup->add(
229            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
230            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
231        );
232    
233    
234      // sample right-click popup actions      // sample right-click popup actions
235      actionGroup->add(      actionGroup->add(
236          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 205  MainWindow::MainWindow() : Line 249  MainWindow::MainWindow() :
249          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
250      );      );
251      actionGroup->add(      actionGroup->add(
252            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
253            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
254        );
255        actionGroup->add(
256          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
257                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
258          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)
259      );      );
260        
261        // script right-click popup actions
262        actionGroup->add(
263            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
264            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
265        );
266        actionGroup->add(
267            Gtk::Action::create("AddScript", _("Add _Script")),
268            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
269        );
270        actionGroup->add(
271            Gtk::Action::create("EditScript", _("_Edit Script...")),
272            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
273        );
274        actionGroup->add(
275            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
276            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
277        );
278    
279      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
280      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 228  MainWindow::MainWindow() : Line 294  MainWindow::MainWindow() :
294          "      <separator/>"          "      <separator/>"
295          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
296          "    </menu>"          "    </menu>"
297            "    <menu action='MenuEdit'>"
298            "      <menuitem action='CopySampleUnity'/>"
299            "      <menuitem action='CopySampleTune'/>"
300            "      <menuitem action='CopySampleLoop'/>"
301            "    </menu>"
302            "    <menu action='MenuSample'>"
303            "      <menuitem action='SampleProperties'/>"
304            "      <menuitem action='AddGroup'/>"
305            "      <menuitem action='AddSample'/>"
306            "      <menuitem action='ShowSampleRefs'/>"
307            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
308            "      <separator/>"
309            "      <menuitem action='RemoveSample'/>"
310            "    </menu>"
311          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
312            "      <menu action='AllInstruments'>"
313            "      </menu>"
314            "      <separator/>"
315            "      <menuitem action='InstrProperties'/>"
316            "      <menuitem action='MidiRules'/>"
317            "      <menuitem action='ScriptSlots'/>"
318            "      <menuitem action='AddInstrument'/>"
319            "      <menuitem action='DupInstrument'/>"
320            "      <separator/>"
321            "      <menuitem action='RemoveInstrument'/>"
322            "    </menu>"
323            "    <menu action='MenuScript'>"
324            "      <menuitem action='AddScriptGroup'/>"
325            "      <menuitem action='AddScript'/>"
326            "      <menuitem action='EditScript'/>"
327            "      <separator/>"
328            "      <menuitem action='RemoveScript'/>"
329          "    </menu>"          "    </menu>"
330          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
331          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
332          "    </menu>"          "    </menu>"
333            "    <menu action='MenuTools'>"
334            "      <menuitem action='CombineInstruments'/>"
335            "      <menuitem action='MergeFiles'/>"
336            "    </menu>"
337            "    <menu action='MenuSettings'>"
338            "      <menuitem action='WarnUserOnExtensions'/>"
339            "    </menu>"
340          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
341          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
342          "    </menu>"          "    </menu>"
343          "  </menubar>"          "  </menubar>"
344          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
345          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
346            "    <menuitem action='MidiRules'/>"
347            "    <menuitem action='ScriptSlots'/>"
348          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
349          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
350          "    <separator/>"          "    <separator/>"
# Line 248  MainWindow::MainWindow() : Line 354  MainWindow::MainWindow() :
354          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
355          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
356          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
357          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ShowSampleRefs'/>"
358            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
359          "    <separator/>"          "    <separator/>"
360          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
361          "  </popup>"          "  </popup>"
362            "  <popup name='ScriptPopupMenu'>"
363            "    <menuitem action='AddScriptGroup'/>"
364            "    <menuitem action='AddScript'/>"
365            "    <menuitem action='EditScript'/>"
366            "    <separator/>"
367            "    <menuitem action='RemoveScript'/>"
368            "  </popup>"
369          "</ui>";          "</ui>";
370      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
371    
372      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
373        
374        // Set tooltips for menu items (for some reason, setting a tooltip on the
375        // respective Gtk::Action objects above will simply be ignored, no matter
376        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
377        // Gtk::Action::create()).
378        {
379            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
380                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
381            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."));
382        }
383        {
384            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
385                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
386            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."));
387        }
388        {
389            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
390                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
391            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."));
392        }
393        {
394            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
395                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
396            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."));
397        }
398        {
399            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
400                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
401            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
402        }
403        {
404            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
405                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
406            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
407        }
408    
409    
410        instrument_menu = static_cast<Gtk::MenuItem*>(
411            uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
412    
413      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
414      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 281  MainWindow::MainWindow() : Line 434  MainWindow::MainWindow() :
434      // Create the Tree model:      // Create the Tree model:
435      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
436      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
437      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
438        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
439          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
440      );      );
441    
# Line 292  MainWindow::MainWindow() : Line 446  MainWindow::MainWindow() :
446      // create samples treeview (including its data model)      // create samples treeview (including its data model)
447      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
448      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
449        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."));
450      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
451      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
452      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
453        {
454            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
455            Gtk::CellRendererText* cellrenderer =
456                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
457            column->add_attribute(
458                cellrenderer->property_foreground(), m_SamplesModel.m_color
459            );
460        }
461        {
462            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
463            Gtk::CellRendererText* cellrenderer =
464                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
465            column->add_attribute(
466                cellrenderer->property_foreground(), m_SamplesModel.m_color
467            );
468        }
469        m_TreeViewSamples.set_headers_visible(true);
470      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
471          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
472      );      );
# Line 302  MainWindow::MainWindow() : Line 474  MainWindow::MainWindow() :
474          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
475      );      );
476    
477        // create scripts treeview (including its data model)
478        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
479        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
480        m_TreeViewScripts.set_tooltip_text(_(
481            "Use CTRL + double click for editing a script."
482            "\n\n"
483            "Note: instrument scripts are a LinuxSampler extension of the gig "
484            "format. This feature will not work with the GigaStudio software!"
485        ));
486        // m_TreeViewScripts.set_reorderable();
487        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
488        m_TreeViewScripts.set_headers_visible(false);
489        m_TreeViewScripts.signal_button_press_event().connect_notify(
490            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
491        );
492        //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?
493        m_TreeViewScripts.signal_row_activated().connect(
494            sigc::mem_fun(*this, &MainWindow::script_double_clicked)
495        );
496        m_refScriptsTreeModel->signal_row_changed().connect(
497            sigc::mem_fun(*this, &MainWindow::script_name_changed)
498        );
499    
500        // establish drag&drop between scripts tree view and ScriptSlots window
501        std::vector<Gtk::TargetEntry> drag_target_gig_script;
502        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
503        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
504        m_TreeViewScripts.signal_drag_begin().connect(
505            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
506        );
507        m_TreeViewScripts.signal_drag_data_get().connect(
508            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
509        );
510    
511      // 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
512      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
513      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 322  MainWindow::MainWindow() : Line 528  MainWindow::MainWindow() :
528          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
529      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
530          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
531      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
532          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
533      propDialog.signal_info_changed().connect(      propDialog.signal_changed().connect(
534            sigc::mem_fun(*this, &MainWindow::file_changed));
535        midiRules.signal_changed().connect(
536          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
537    
538      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 333  MainWindow::MainWindow() : Line 541  MainWindow::MainWindow() :
541          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
542      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
543          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
544        sample_ref_changed_signal.connect(
545            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
546        );
547        samples_to_be_removed_signal.connect(
548            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
549        );
550    
551      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
552          sigc::hide(          sigc::hide(
# Line 374  MainWindow::MainWindow() : Line 588  MainWindow::MainWindow() :
588    
589      // start with a new gig file by default      // start with a new gig file by default
590      on_action_file_new();      on_action_file_new();
591    
592        // select 'Instruments' tab by default
593        // (gtk allows this only if the tab childs are visible, thats why it's here)
594        m_TreeViewNotebook.set_current_page(1);
595  }  }
596    
597  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 399  void MainWindow::region_changed() Line 617  void MainWindow::region_changed()
617  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
618  {  {
619      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
620      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
621            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
622      if (it) {      if (it) {
623          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
624          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 455  void MainWindow::dimreg_all_dimregs_togg Line 672  void MainWindow::dimreg_all_dimregs_togg
672  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
673  {  {
674      update_dimregs();      update_dimregs();
675      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
676  }  }
677    
678  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
679  {  {
680        // select item in instrument menu
681        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
682        if (it) {
683            Gtk::TreePath path(it);
684            int index = path[0];
685            const std::vector<Gtk::Widget*> children =
686                instrument_menu->get_children();
687            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
688        }
689    
690      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
691  }  }
692    
# Line 538  LoadDialog::LoadDialog(const Glib::ustri Line 765  LoadDialog::LoadDialog(const Glib::ustri
765  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
766  // 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.
767  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();  
     Gtk::Menu* menu = instrument_menu->get_submenu();  
     while (menu->get_children().size()) {  
         Gtk::Widget* child = *menu->get_children().begin();  
         menu->remove(*child);  
         delete child;  
     }  
768      // forget all samples that ought to be imported      // forget all samples that ought to be imported
769      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
770      // clear the samples and instruments tree views      // clear the samples and instruments tree views
771      m_refTreeModel->clear();      m_refTreeModel->clear();
772      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
773        m_refScriptsTreeModel->clear();
774        // remove all entries from "Instrument" menu
775        while (!instrument_menu->get_children().empty()) {
776            remove_instrument_from_menu(0);
777        }
778      // free libgig's gig::File instance      // free libgig's gig::File instance
779      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
780      file = NULL;      file = NULL;
781      set_file_is_shared(false);      set_file_is_shared(false);
782  }  }
783    
784    void MainWindow::__refreshEntireGUI() {
785        // clear the samples and instruments tree views
786        m_refTreeModel->clear();
787        m_refSamplesTreeModel->clear();
788        m_refScriptsTreeModel->clear();
789        // remove all entries from "Instrument" menu
790        while (!instrument_menu->get_children().empty()) {
791            remove_instrument_from_menu(0);
792        }
793    
794        if (!this->file) return;
795    
796        load_gig(
797            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
798        );
799    }
800    
801  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
802  {  {
803      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 571  void MainWindow::on_action_file_new() Line 810  void MainWindow::on_action_file_new()
810      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
811      // already add one new instrument by default      // already add one new instrument by default
812      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
813      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
814      // update GUI with that new gig::File      // update GUI with that new gig::File
815      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
816  }  }
# Line 904  void MainWindow::__import_queued_samples Line 1143  void MainWindow::__import_queued_samples
1143              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1144          } catch (std::string what) {          } catch (std::string what) {
1145              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1146              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1147              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1148              ++iter;              ++iter;
1149          }          }
1150      }      }
1151      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
1152      if (error_files.size()) {      if (!error_files.empty()) {
1153          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;
1154          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1155          msg.run();          msg.run();
# Line 923  void MainWindow::on_action_file_properti Line 1162  void MainWindow::on_action_file_properti
1162      propDialog.deiconify();      propDialog.deiconify();
1163  }  }
1164    
1165    void MainWindow::on_action_warn_user_on_extensions() {
1166        Settings::singleton()->warnUserOnExtensions =
1167            !Settings::singleton()->warnUserOnExtensions;
1168    }
1169    
1170  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1171  {  {
1172      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 932  void MainWindow::on_action_help_about() Line 1176  void MainWindow::on_action_help_about()
1176      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1177  #endif  #endif
1178      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1179      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1180      dialog.set_comments(_(      const std::string sComment =
1181          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1182          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1183          "Please notice that this is still a very young instrument editor. "          _(
1184          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1185          "this application.\n"              "\n"
1186          "\n"              "This program is distributed WITHOUT ANY WARRANTY; So better "
1187          "Please report bugs to: http://bugs.linuxsampler.org")              "backup your Gigasampler/GigaStudio files before editing them with "
1188      );              "this application.\n"
1189                "\n"
1190                "Please report bugs to: http://bugs.linuxsampler.org"
1191            );
1192        dialog.set_comments(sComment.c_str());
1193      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1194      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1195      dialog.run();      dialog.run();
1196  }  }
1197    
1198  PropDialog::PropDialog()  PropDialog::PropDialog()
1199      : eName(_("Name")),      : eFileFormat(_("File Format")),
1200          eName(_("Name")),
1201        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1202        eComments(_("Comments")),        eComments(_("Comments")),
1203        eProduct(_("Product")),        eProduct(_("Product")),
# Line 966  PropDialog::PropDialog() Line 1215  PropDialog::PropDialog()
1215        eSubject(_("Subject")),        eSubject(_("Subject")),
1216        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1217        table(2, 1),        table(2, 1),
1218        update_model(0)        m_file(NULL)
1219  {  {
1220      set_title(_("File Properties"));      set_title(_("File Properties"));
1221      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 988  PropDialog::PropDialog() Line 1237  PropDialog::PropDialog()
1237      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1238      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1239    
1240        table.add(eFileFormat);
1241      table.add(eName);      table.add(eName);
1242      table.add(eCreationDate);      table.add(eCreationDate);
1243      table.add(eComments);      table.add(eComments);
# Line 1018  PropDialog::PropDialog() Line 1268  PropDialog::PropDialog()
1268      quitButton.grab_focus();      quitButton.grab_focus();
1269      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1270          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1271        eFileFormat.signal_value_changed().connect(
1272            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1273    
1274      quitButton.show();      quitButton.show();
1275      vbox.show();      vbox.show();
1276      show_all_children();      show_all_children();
1277  }  }
1278    
1279  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_file(gig::File* file)
1280  {  {
1281      this->info = info;      m_file = file;
1282      update_model++;  
1283      eName.set_value(info->Name);      // update file format version combo box
1284      eCreationDate.set_value(info->CreationDate);      const std::string sGiga = "Gigasampler/GigaStudio v";
1285      eComments.set_value(info->Comments);      const int major = file->pVersion->major;
1286      eProduct.set_value(info->Product);      std::vector<std::string> txts;
1287      eCopyright.set_value(info->Copyright);      std::vector<int> values;
1288      eArtists.set_value(info->Artists);      txts.push_back(sGiga + "2"); values.push_back(2);
1289      eGenre.set_value(info->Genre);      txts.push_back(sGiga + "3/v4"); values.push_back(3);
1290      eKeywords.set_value(info->Keywords);      if (major != 2 && major != 3) {
1291      eEngineer.set_value(info->Engineer);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
1292      eTechnician.set_value(info->Technician);      }
1293      eSoftware.set_value(info->Software);      std::vector<const char*> texts;
1294      eMedium.set_value(info->Medium);      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1295      eSource.set_value(info->Source);      texts.push_back(NULL); values.push_back(0);
1296      eSourceForm.set_value(info->SourceForm);      eFileFormat.set_choices(&texts[0], &values[0]);
1297      eCommissioned.set_value(info->Commissioned);      eFileFormat.set_value(major);
1298      eSubject.set_value(info->Subject);  }
1299      update_model--;  
1300    void PropDialog::onFileFormatChanged() {
1301        const int major = eFileFormat.get_value();
1302        if (m_file) m_file->pVersion->major = major;
1303  }  }
1304    
1305  sigc::signal<void>& PropDialog::signal_info_changed()  void PropDialog::set_info(DLS::Info* info)
1306  {  {
1307      return info_changed;      update(info);
1308  }  }
1309    
1310  void InstrumentProps::set_IsDrum(bool value)  
1311    void InstrumentProps::set_Name(const gig::String& name)
1312  {  {
1313      instrument->IsDrum = value;      m->pInfo->Name = name;
1314  }  }
1315    
1316  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1317  {  {
1318      instrument->MIDIBank = value;      update_model++;
1319        eName.set_value(m->pInfo->Name);
1320        update_model--;
1321  }  }
1322    
1323  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1324  {  {
1325      instrument->MIDIProgram = value;      m->IsDrum = value;
1326  }  }
1327    
1328  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1329  {  {
1330      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1331  }  }
1332    
1333  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1334  {  {
1335      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1336  }  }
1337    
1338  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1339      : update_model(0),      quitButton(Gtk::Stock::CLOSE),
1340        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1341        table(2,1),      eName(_("Name")),
1342        eName(_("Name")),      eIsDrum(_("Is drum")),
1343        eIsDrum(_("Is drum")),      eMIDIBank(_("MIDI bank"), 0, 16383),
1344        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIProgram(_("MIDI program")),
1345        eMIDIProgram(_("MIDI program")),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1346        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1347        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eEffectSend(_("Effect send"), 0, 65535),
1348        eEffectSend(_("Effect send"), 0, 65535),      eFineTune(_("Fine tune"), -8400, 8400),
1349        eFineTune(_("Fine tune"), -8400, 8400),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1350        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePianoReleaseMode(_("Piano release mode")),
1351        ePianoReleaseMode(_("Piano release mode")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1352        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       eDimensionKeyRangeHigh(_("Keyswitching range high"))  
1353  {  {
1354      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1355    
# Line 1111  InstrumentProps::InstrumentProps() Line 1362  InstrumentProps::InstrumentProps()
1362            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1363      );      );
1364    
1365        connect(eName, &InstrumentProps::set_Name);
1366      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1367      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1368      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1120  InstrumentProps::InstrumentProps() Line 1372  InstrumentProps::InstrumentProps()
1372      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1373      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1374      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1375      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1376              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1377      connect(eDimensionKeyRangeHigh,  
1378              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1379    
1380      table.set_col_spacings(5);      table.set_col_spacings(5);
1381    
# Line 1162  InstrumentProps::InstrumentProps() Line 1414  InstrumentProps::InstrumentProps()
1414    
1415  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1416  {  {
1417      this->instrument = instrument;      update(instrument);
1418    
1419      update_model++;      update_model++;
1420      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1421      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1422      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1423      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);  
1424      update_model--;      update_model--;
1425  }  }
1426    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1427    
1428  void MainWindow::file_changed()  void MainWindow::file_changed()
1429  {  {
# Line 1193  void MainWindow::file_changed() Line 1433  void MainWindow::file_changed()
1433      }      }
1434  }  }
1435    
1436    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1437        sample_ref_count.clear();
1438        
1439        if (!gig) return;
1440    
1441        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1442             instrument = gig->GetNextInstrument())
1443        {
1444            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1445                 rgn = instrument->GetNextRegion())
1446            {
1447                for (int i = 0; i < 256; ++i) {
1448                    if (!rgn->pDimensionRegions[i]) continue;
1449                    if (rgn->pDimensionRegions[i]->pSample) {
1450                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1451                    }
1452                }
1453            }
1454        }
1455    }
1456    
1457  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1458  {  {
1459      file = 0;      file = 0;
# Line 1203  void MainWindow::load_gig(gig::File* gig Line 1464  void MainWindow::load_gig(gig::File* gig
1464      file_has_name = filename;      file_has_name = filename;
1465      file_is_changed = false;      file_is_changed = false;
1466    
1467        propDialog.set_file(gig);
1468      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1469    
1470      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;  
1471      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1472           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1473            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1474    
1475          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1476          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1477          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1478          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1479          // create a menu item for this instrument  
1480          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++;  
1481      }      }
1482      instrument_menu->show();      instrument_name_connection.unblock();
1483      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1484    
1485        updateSampleRefCountMap(gig);
1486    
1487      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1488          if (group->Name != "") {          if (group->Name != "") {
1489              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1490              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1491              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1492              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1493              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1494              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1243  void MainWindow::load_gig(gig::File* gig Line 1496  void MainWindow::load_gig(gig::File* gig
1496                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1497                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1498                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1499                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1500                        gig_to_utf8(sample->pInfo->Name);
1501                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1502                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1503                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1504                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1505                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1506              }              }
1507          }          }
1508      }      }
1509        
1510        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1511            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1512    
1513            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1514            Gtk::TreeModel::Row rowGroup = *iterGroup;
1515            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1516            rowGroup[m_ScriptsModel.m_col_group]  = group;
1517            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1518            for (int s = 0; group->GetScript(s); ++s) {
1519                gig::Script* script = group->GetScript(s);
1520    
1521                Gtk::TreeModel::iterator iterScript =
1522                    m_refScriptsTreeModel->append(rowGroup.children());
1523                Gtk::TreeModel::Row rowScript = *iterScript;
1524                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1525                rowScript[m_ScriptsModel.m_col_script] = script;
1526                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1527            }
1528        }
1529        // unfold all sample groups & script groups by default
1530        m_TreeViewSamples.expand_all();
1531        m_TreeViewScripts.expand_all();
1532    
1533      file = gig;      file = gig;
1534    
1535      // select the first instrument      // select the first instrument
1536      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1537      tree_sel_ref->select(Gtk::TreePath("0"));  
1538        instr_props_set_instrument();
1539        gig::Instrument* instrument = get_instrument();
1540        if (instrument) {
1541            midiRules.set_instrument(instrument);
1542        }
1543  }  }
1544    
1545  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1546  {  {
1547      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1548      if (instrument)  
1549      {      Gtk::TreeModel::const_iterator it =
1550            m_TreeView.get_selection()->get_selected();
1551        if (it) {
1552            Gtk::TreeModel::Row row = *it;
1553            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1554    
1555          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1556    
1557            // make sure instrument tree is updated when user changes the
1558            // instrument name in instrument properties window
1559            instrumentProps.signal_name_changed().connect(
1560                sigc::bind(
1561                    sigc::mem_fun(*this,
1562                                  &MainWindow::instr_name_changed_by_instr_props),
1563                    it));
1564        } else {
1565            instrumentProps.hide();
1566        }
1567        return it;
1568    }
1569    
1570    void MainWindow::show_instr_props()
1571    {
1572        if (instr_props_set_instrument()) {
1573          instrumentProps.show();          instrumentProps.show();
1574          instrumentProps.deiconify();          instrumentProps.deiconify();
1575      }      }
1576  }  }
1577    
1578    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1579    {
1580        Gtk::TreeModel::Row row = *it;
1581        Glib::ustring name = row[m_Columns.m_col_name];
1582    
1583        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1584        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1585        if (gigname != name) {
1586            row[m_Columns.m_col_name] = gigname;
1587        }
1588    }
1589    
1590    void MainWindow::show_midi_rules()
1591    {
1592        if (gig::Instrument* instrument = get_instrument())
1593        {
1594            midiRules.set_instrument(instrument);
1595            midiRules.show();
1596            midiRules.deiconify();
1597        }
1598    }
1599    
1600    void MainWindow::show_script_slots() {
1601        if (!file) return;
1602        // get selected instrument
1603        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1604        Gtk::TreeModel::iterator it = sel->get_selected();
1605        if (!it) return;
1606        Gtk::TreeModel::Row row = *it;
1607        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1608        if (!instrument) return;
1609    
1610        ScriptSlots* window = new ScriptSlots;
1611        window->setInstrument(instrument);
1612        //window->reparent(*this);
1613        window->show();
1614    }
1615    
1616  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1617      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1618          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1279  void MainWindow::on_action_view_status_b Line 1624  void MainWindow::on_action_view_status_b
1624      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1625  }  }
1626    
1627    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1628        Gtk::CheckMenuItem* item =
1629            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1630        if (!item) {
1631            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1632            return true;
1633        }
1634        return item->get_active();
1635    }
1636    
1637    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1638        Gtk::CheckMenuItem* item =
1639            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1640        if (!item) {
1641            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1642            return true;
1643        }
1644        return item->get_active();
1645    }
1646    
1647    bool MainWindow::is_copy_samples_loop_enabled() const {
1648        Gtk::CheckMenuItem* item =
1649            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1650        if (!item) {
1651            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1652            return true;
1653        }
1654        return item->get_active();
1655    }
1656    
1657  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1658  {  {
1659      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1660          show_instr_props();          show_instr_props();
1661      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1662            // gig v2 files have no midi rules
1663            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1664            static_cast<Gtk::MenuItem*>(
1665                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1666                    bEnabled
1667                );
1668            static_cast<Gtk::MenuItem*>(
1669                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1670                    bEnabled
1671                );
1672          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1673      }      }
1674  }  }
1675    
1676  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1677      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1678            const std::vector<Gtk::Widget*> children =
1679                instrument_menu->get_children();
1680            std::vector<Gtk::Widget*>::const_iterator it =
1681                find(children.begin(), children.end(), item);
1682            if (it != children.end()) {
1683                int index = it - children.begin();
1684                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1685    
1686                m_RegionChooser.set_instrument(file->GetInstrument(index));
1687            }
1688        }
1689  }  }
1690    
1691  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1306  void MainWindow::on_sample_treeview_butt Line 1702  void MainWindow::on_sample_treeview_butt
1702              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
1703              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
1704          }          }
1705            
1706                
1707          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
1708              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1709          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
1710              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1711          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1712              set_sensitive(file);              set_sensitive(file);
1713            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
1714                set_sensitive(sample_selected);
1715          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1716              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1717          // show sample popup          // show sample popup
1718          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
1719    
1720            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
1721                set_sensitive(group_selected || sample_selected);
1722            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
1723                set_sensitive(group_selected || sample_selected);
1724            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
1725                set_sensitive(file);
1726            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
1727                set_sensitive(sample_selected);
1728            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
1729                set_sensitive(group_selected || sample_selected);
1730      }      }
1731  }  }
1732    
1733  void MainWindow::on_action_add_instrument() {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1734      static int __instrument_indexer = 0;      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1735      if (!file) return;          Gtk::Menu* script_popup =
1736      gig::Instrument* instrument = file->AddInstrument();              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1737      __instrument_indexer++;          // update enabled/disabled state of sample popup items
1738      instrument->pInfo->Name =          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1739          _("Unnamed Instrument ") + ToString(__instrument_indexer);          Gtk::TreeModel::iterator it = sel->get_selected();
1740            bool group_selected  = false;
1741            bool script_selected = false;
1742            if (it) {
1743                Gtk::TreeModel::Row row = *it;
1744                group_selected  = row[m_ScriptsModel.m_col_group];
1745                script_selected = row[m_ScriptsModel.m_col_script];
1746            }
1747            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1748                set_sensitive(group_selected || script_selected);
1749            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1750                set_sensitive(file);
1751            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1752                set_sensitive(script_selected);    
1753            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1754                set_sensitive(group_selected || script_selected);
1755            // show sample popup
1756            script_popup->popup(button->button, button->time);
1757    
1758            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
1759                set_sensitive(group_selected || script_selected);
1760            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
1761                set_sensitive(file);
1762            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
1763                set_sensitive(script_selected);    
1764            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
1765                set_sensitive(group_selected || script_selected);
1766        }
1767    }
1768    
1769    Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1770        const Glib::ustring& name, int position) {
1771    
1772        Gtk::RadioMenuItem::Group instrument_group;
1773        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1774        if (!children.empty()) {
1775            instrument_group =
1776                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1777        }
1778        Gtk::RadioMenuItem* item =
1779            new Gtk::RadioMenuItem(instrument_group, name);
1780        if (position < 0) {
1781            instrument_menu->append(*item);
1782        } else {
1783            instrument_menu->insert(*item, position);
1784        }
1785        item->show();
1786        item->signal_activate().connect(
1787            sigc::bind(
1788                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1789                item));
1790        return item;
1791    }
1792    
1793    void MainWindow::remove_instrument_from_menu(int index) {
1794        const std::vector<Gtk::Widget*> children =
1795            instrument_menu->get_children();
1796        Gtk::Widget* child = children[index];
1797        instrument_menu->remove(*child);
1798        delete child;
1799    }
1800    
1801    void MainWindow::add_instrument(gig::Instrument* instrument) {
1802        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1803    
1804      // update instrument tree view      // update instrument tree view
1805        instrument_name_connection.block();
1806      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1807      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1808      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1809      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1810        instrument_name_connection.unblock();
1811    
1812        add_instrument_to_menu(name);
1813    
1814        m_TreeView.get_selection()->select(iterInstr);
1815    
1816      file_changed();      file_changed();
1817  }  }
1818    
1819    void MainWindow::on_action_add_instrument() {
1820        static int __instrument_indexer = 0;
1821        if (!file) return;
1822        gig::Instrument* instrument = file->AddInstrument();
1823        __instrument_indexer++;
1824        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1825                                                ToString(__instrument_indexer));
1826    
1827        add_instrument(instrument);
1828    }
1829    
1830  void MainWindow::on_action_duplicate_instrument() {  void MainWindow::on_action_duplicate_instrument() {
1831      if (!file) return;      if (!file) return;
1832        
1833      // retrieve the currently selected instrument      // retrieve the currently selected instrument
1834      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
1835      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
# Line 1345  void MainWindow::on_action_duplicate_ins Line 1838  void MainWindow::on_action_duplicate_ins
1838      Gtk::TreeModel::Row row = *itSelection;      Gtk::TreeModel::Row row = *itSelection;
1839      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1840      if (!instrOrig) return;      if (!instrOrig) return;
1841        
1842      // duplicate the orginal instrument      // duplicate the orginal instrument
1843      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1844      instrNew->pInfo->Name =      instrNew->pInfo->Name =
1845          instrOrig->pInfo->Name + " (" + _("Copy") + ")";          instrOrig->pInfo->Name +
1846                    gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1847      // update instrument tree view  
1848      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      add_instrument(instrNew);
     Gtk::TreeModel::Row rowInstr = *iterInstr;  
     rowInstr[m_Columns.m_col_name] = instrNew->pInfo->Name.c_str();  
     rowInstr[m_Columns.m_col_instr] = instrNew;  
     file_changed();  
1849  }  }
1850    
1851  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 1378  void MainWindow::on_action_remove_instru Line 1867  void MainWindow::on_action_remove_instru
1867          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1868          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1869          try {          try {
1870                Gtk::TreePath path(it);
1871                int index = path[0];
1872    
1873              // remove instrument from the gig file              // remove instrument from the gig file
1874              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1875              file_changed();              file_changed();
1876    
1877                remove_instrument_from_menu(index);
1878    
1879                // remove row from instruments tree view
1880                m_refTreeModel->erase(it);
1881    
1882    #if GTKMM_MAJOR_VERSION < 3
1883                // select another instrument (in gtk3 this is done
1884                // automatically)
1885                if (!m_refTreeModel->children().empty()) {
1886                    if (index == m_refTreeModel->children().size()) {
1887                        index--;
1888                    }
1889                    m_TreeView.get_selection()->select(
1890                        Gtk::TreePath(ToString(index)));
1891                }
1892    #endif
1893                instr_props_set_instrument();
1894                instr = get_instrument();
1895                if (instr) {
1896                    midiRules.set_instrument(instr);
1897                } else {
1898                    midiRules.hide();
1899                }
1900          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1901              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1902              msg.run();              msg.run();
# Line 1398  void MainWindow::on_action_sample_proper Line 1912  void MainWindow::on_action_sample_proper
1912      msg.run();      msg.run();
1913  }  }
1914    
1915    void MainWindow::on_action_add_script_group() {
1916        static int __script_indexer = 0;
1917        if (!file) return;
1918        gig::ScriptGroup* group = file->AddScriptGroup();
1919        group->Name = gig_from_utf8(_("Unnamed Group"));
1920        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1921        __script_indexer++;
1922        // update sample tree view
1923        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1924        Gtk::TreeModel::Row rowGroup = *iterGroup;
1925        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1926        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1927        rowGroup[m_ScriptsModel.m_col_group] = group;
1928        file_changed();
1929    }
1930    
1931    void MainWindow::on_action_add_script() {
1932        if (!file) return;
1933        // get selected group
1934        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1935        Gtk::TreeModel::iterator it = sel->get_selected();
1936        if (!it) return;
1937        Gtk::TreeModel::Row row = *it;
1938        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1939        if (!group) { // not a group, but a script is selected (probably)
1940            gig::Script* script = row[m_ScriptsModel.m_col_script];
1941            if (!script) return;
1942            it = row.parent(); // resolve parent (that is the script's group)
1943            if (!it) return;
1944            row = *it;
1945            group = row[m_ScriptsModel.m_col_group];
1946            if (!group) return;
1947        }
1948    
1949        // add a new script to the .gig file
1950        gig::Script* script = group->AddScript();    
1951        Glib::ustring name = _("Unnamed Script");
1952        script->Name = gig_from_utf8(name);
1953    
1954        // add script to the tree view
1955        Gtk::TreeModel::iterator iterScript =
1956            m_refScriptsTreeModel->append(row.children());
1957        Gtk::TreeModel::Row rowScript = *iterScript;
1958        rowScript[m_ScriptsModel.m_col_name] = name;
1959        rowScript[m_ScriptsModel.m_col_script] = script;
1960        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1961    
1962        // unfold group of new script item in treeview
1963        Gtk::TreeModel::Path path(iterScript);
1964        m_TreeViewScripts.expand_to_path(path);
1965    }
1966    
1967    void MainWindow::on_action_edit_script() {
1968        if (!file) return;
1969        // get selected script
1970        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1971        Gtk::TreeModel::iterator it = sel->get_selected();
1972        if (!it) return;
1973        Gtk::TreeModel::Row row = *it;
1974        gig::Script* script = row[m_ScriptsModel.m_col_script];
1975        if (!script) return;
1976    
1977        ScriptEditor* editor = new ScriptEditor;
1978        editor->setScript(script);
1979        //editor->reparent(*this);
1980        editor->show();
1981    }
1982    
1983    void MainWindow::on_action_remove_script() {
1984        if (!file) return;
1985        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1986        Gtk::TreeModel::iterator it = sel->get_selected();
1987        if (it) {
1988            Gtk::TreeModel::Row row = *it;
1989            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1990            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1991            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1992            try {
1993                // remove script group or script from the gig file
1994                if (group) {
1995                    // notify everybody that we're going to remove these samples
1996    //TODO:         scripts_to_be_removed_signal.emit(members);
1997                    // delete the group in the .gig file including the
1998                    // samples that belong to the group
1999                    file->DeleteScriptGroup(group);
2000                    // notify that we're done with removal
2001    //TODO:         scripts_removed_signal.emit();
2002                    file_changed();
2003                } else if (script) {
2004                    // notify everybody that we're going to remove this sample
2005    //TODO:         std::list<gig::Script*> lscripts;
2006    //TODO:         lscripts.push_back(script);
2007    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2008                    // remove sample from the .gig file
2009                    script->GetGroup()->DeleteScript(script);
2010                    // notify that we're done with removal
2011    //TODO:         scripts_removed_signal.emit();
2012                    dimreg_changed();
2013                    file_changed();
2014                }
2015                // remove respective row(s) from samples tree view
2016                m_refScriptsTreeModel->erase(it);
2017            } catch (RIFF::Exception e) {
2018                // pretend we're done with removal (i.e. to avoid dead locks)
2019    //TODO:     scripts_removed_signal.emit();
2020                // show error message
2021                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2022                msg.run();
2023            }
2024        }
2025    }
2026    
2027  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2028      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2029      if (!file) return;      if (!file) return;
2030      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
2031      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
2032      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
2033      __sample_indexer++;      __sample_indexer++;
2034      // update sample tree view      // update sample tree view
2035      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
2036      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
2037      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
2038      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
2039      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
2040      file_changed();      file_changed();
# Line 1517  void MainWindow::on_action_add_sample() Line 2143  void MainWindow::on_action_add_sample()
2143                          break;                          break;
2144                      }                      }
2145                  }                  }
2146                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
2147                  sample->Channels = info.channels;                  sample->Channels = info.channels;
2148                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
2149                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1531  void MainWindow::on_action_add_sample() Line 2157  void MainWindow::on_action_add_sample()
2157                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
2158                  {                  {
2159                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
2160                        sample->FineTune      = instrument.detune;
2161    
2162                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
2163                          sample->Loops = 1;                          sample->Loops = 1;
# Line 1568  void MainWindow::on_action_add_sample() Line 2195  void MainWindow::on_action_add_sample()
2195                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
2196                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
2197                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
2198                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
2199                        gig_to_utf8(sample->pInfo->Name);
2200                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
2201                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
2202                  // close sound file                  // close sound file
2203                  sf_close(hFile);                  sf_close(hFile);
2204                  file_changed();                  file_changed();
2205              } 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)
2206                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2207                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
2208              }              }
2209          }          }
2210          // 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
2211          if (error_files.size()) {          if (!error_files.empty()) {
2212              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;
2213              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2214              msg.run();              msg.run();
# Line 1593  void MainWindow::on_action_replace_all_s Line 2221  void MainWindow::on_action_replace_all_s
2221      if (!file) return;      if (!file) return;
2222      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
2223                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
2224      const char* str =      const char* str =
2225          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
2226            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
2227            "directory.\n\n"            "directory.\n\n"
# Line 1639  void MainWindow::on_action_replace_all_s Line 2267  void MainWindow::on_action_replace_all_s
2267               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
2268          {          {
2269              std::string filename =              std::string filename =
2270                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
2271                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2272                                             postfixEntryBox.get_text());
2273              SF_INFO info;              SF_INFO info;
2274              info.format = 0;              info.format = 0;
2275              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1673  void MainWindow::on_action_replace_all_s Line 2302  void MainWindow::on_action_replace_all_s
2302              }              }
2303              catch (std::string what)              catch (std::string what)
2304              {              {
2305                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2306                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
2307                        " (" + what + ")";
2308              }              }
2309          }          }
2310          // 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
2311          if (error_files.size()) {          if (!error_files.empty()) {
2312              Glib::ustring txt =              Glib::ustring txt =
2313                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
2314              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1699  void MainWindow::on_action_remove_sample Line 2329  void MainWindow::on_action_remove_sample
2329          try {          try {
2330              // remove group or sample from the gig file              // remove group or sample from the gig file
2331              if (group) {              if (group) {
2332                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2333                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2334                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2335                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1763  void MainWindow::on_action_remove_sample Line 2393  void MainWindow::on_action_remove_sample
2393      }      }
2394  }  }
2395    
2396    // see comment on on_sample_treeview_drag_begin()
2397    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2398    {
2399        first_call_to_drag_data_get = true;
2400    }
2401    
2402    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2403                                                       Gtk::SelectionData& selection_data, guint, guint)
2404    {
2405        if (!first_call_to_drag_data_get) return;
2406        first_call_to_drag_data_get = false;
2407    
2408        // get selected script
2409        gig::Script* script = NULL;
2410        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2411        Gtk::TreeModel::iterator it = sel->get_selected();
2412        if (it) {
2413            Gtk::TreeModel::Row row = *it;
2414            script = row[m_ScriptsModel.m_col_script];
2415        }
2416        // pass the gig::Script as pointer
2417        selection_data.set(selection_data.get_target(), 0/*unused*/,
2418                           (const guchar*)&script,
2419                           sizeof(script)/*length of data in bytes*/);
2420    }
2421    
2422  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2423  // 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
2424  // 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 1821  void MainWindow::on_sample_label_drop_dr Line 2477  void MainWindow::on_sample_label_drop_dr
2477          bool channels_changed = false;          bool channels_changed = false;
2478          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2479              // remove the samplechannel dimension              // remove the samplechannel dimension
2480    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2481              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2482              channels_changed = true;              channels_changed = true;
2483              region_changed();              region_changed();
2484    */
2485          }          }
2486          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2487                sample,
2488                is_copy_samples_unity_note_enabled(),
2489                is_copy_samples_fine_tune_enabled(),
2490                is_copy_samples_loop_enabled()
2491            );
2492    
2493          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2494              // add samplechannel dimension              // add samplechannel dimension
# Line 1868  void MainWindow::sample_name_changed(con Line 2531  void MainWindow::sample_name_changed(con
2531      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2532      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2533      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2534        gig::String gigname(gig_from_utf8(name));
2535      if (group) {      if (group) {
2536          if (group->Name != name) {          if (group->Name != gigname) {
2537              group->Name = name;              group->Name = gigname;
2538              printf("group name changed\n");              printf("group name changed\n");
2539              file_changed();              file_changed();
2540          }          }
2541      } else if (sample) {      } else if (sample) {
2542          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2543              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2544              printf("sample name changed\n");              printf("sample name changed\n");
2545              file_changed();              file_changed();
2546          }          }
2547      }      }
2548  }  }
2549    
2550    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2551                                         const Gtk::TreeModel::iterator& iter) {
2552        if (!iter) return;
2553        Gtk::TreeModel::Row row = *iter;
2554        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2555        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2556        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2557        gig::String gigname(gig_from_utf8(name));
2558        if (group) {
2559            if (group->Name != gigname) {
2560                group->Name = gigname;
2561                printf("script group name changed\n");
2562                file_changed();
2563            }
2564        } else if (script) {
2565            if (script->Name != gigname) {
2566                script->Name = gigname;
2567                printf("script name changed\n");
2568                file_changed();
2569            }
2570        }
2571    }
2572    
2573    void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
2574                                           Gtk::TreeViewColumn* column)
2575    {
2576        Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
2577        if (!iter) return;
2578        Gtk::TreeModel::Row row = *iter;
2579        gig::Script* script = row[m_ScriptsModel.m_col_script];
2580        if (!script) return;
2581    
2582        ScriptEditor* editor = new ScriptEditor;
2583        editor->setScript(script);
2584        //editor->reparent(*this);
2585        editor->show();
2586    }
2587    
2588  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2589                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2590      if (!iter) return;      if (!iter) return;
2591      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2592      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2593    
2594        // change name in instrument menu
2595        int index = path[0];
2596        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2597        if (index < children.size()) {
2598    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2599            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2600    #else
2601            remove_instrument_from_menu(index);
2602            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2603            item->set_active();
2604    #endif
2605        }
2606    
2607        // change name in gig
2608      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2609      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2610          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2611            instrument->pInfo->Name = gigname;
2612    
2613            // change name in the instrument properties window
2614            if (instrumentProps.get_instrument() == instrument) {
2615                instrumentProps.update_name();
2616            }
2617    
2618          file_changed();          file_changed();
2619      }      }
2620  }  }
2621    
2622    void MainWindow::on_action_combine_instruments() {
2623        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2624        d->show_all();
2625        d->resize(500, 400);
2626        d->run();
2627        if (d->fileWasChanged()) {
2628            // update GUI with new instrument just created
2629            add_instrument(d->newCombinedInstrument());
2630        }
2631        delete d;
2632    }
2633    
2634    void MainWindow::on_action_view_references() {
2635        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2636        Gtk::TreeModel::iterator it = sel->get_selected();
2637        if (!it) return;
2638        Gtk::TreeModel::Row row = *it;
2639        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2640        if (!sample) return;
2641    
2642        ReferencesView* d = new ReferencesView(*this);
2643        d->setSample(sample);
2644        d->show_all();
2645        d->resize(500, 400);
2646        d->run();
2647        delete d;
2648    }
2649    
2650    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2651        struct _Source {
2652            std::vector<RIFF::File*> riffs;
2653            std::vector<gig::File*> gigs;
2654            
2655            ~_Source() {
2656                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2657                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2658                riffs.clear();
2659                gigs.clear();
2660            }
2661        } sources;
2662    
2663        if (filenames.empty())
2664            throw RIFF::Exception(_("No files selected, so nothing done."));
2665    
2666        // first open all input files (to avoid output file corruption)
2667        int i;
2668        try {
2669            for (i = 0; i < filenames.size(); ++i) {
2670                const std::string& filename = filenames[i];
2671                printf("opening file=%s\n", filename.c_str());
2672    
2673                RIFF::File* riff = new RIFF::File(filename);
2674                sources.riffs.push_back(riff);
2675    
2676                gig::File* gig = new gig::File(riff);
2677                sources.gigs.push_back(gig);
2678            }
2679        } catch (RIFF::Exception e) {
2680            throw RIFF::Exception(
2681                _("Error occurred while opening '") +
2682                filenames[i] +
2683                "': " +
2684                e.Message
2685            );
2686        } catch (...) {
2687            throw RIFF::Exception(
2688                _("Unknown exception occurred while opening '") +
2689                filenames[i] + "'"
2690            );
2691        }
2692    
2693        // now merge the opened .gig files to the main .gig file currently being
2694        // open in gigedit
2695        try {
2696            for (i = 0; i < filenames.size(); ++i) {
2697                const std::string& filename = filenames[i];
2698                printf("merging file=%s\n", filename.c_str());
2699                assert(i < sources.gigs.size());
2700    
2701                this->file->AddContentOf(sources.gigs[i]);
2702            }
2703        } catch (RIFF::Exception e) {
2704            throw RIFF::Exception(
2705                _("Error occurred while merging '") +
2706                filenames[i] +
2707                "': " +
2708                e.Message
2709            );
2710        } catch (...) {
2711            throw RIFF::Exception(
2712                _("Unknown exception occurred while merging '") +
2713                filenames[i] + "'"
2714            );
2715        }
2716    
2717        // Note: requires that this file already has a filename !
2718        this->file->Save();
2719    }
2720    
2721    void MainWindow::on_action_merge_files() {
2722        if (this->file->GetFileName().empty()) {
2723            Glib::ustring txt = _(
2724                "You seem to have a new .gig file open that has not been saved "
2725                "yet. You must save it somewhere before starting to merge it with "
2726                "other .gig files though, because during the merge operation the "
2727                "other files' sample data must be written on file level to the "
2728                "target .gig file."
2729            );
2730            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2731            msg.run();
2732            return;
2733        }
2734    
2735        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2736        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2737        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2738        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2739    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2740        Gtk::FileFilter filter;
2741        filter.add_pattern("*.gig");
2742    #else
2743        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2744        filter->add_pattern("*.gig");
2745    #endif
2746        dialog.set_filter(filter);
2747        if (current_gig_dir != "") {
2748            dialog.set_current_folder(current_gig_dir);
2749        }
2750        dialog.set_select_multiple(true);
2751    
2752        // show warning in the file picker dialog
2753        Gtk::HBox descriptionArea;
2754        descriptionArea.set_spacing(15);
2755        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2756        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2757    #if GTKMM_MAJOR_VERSION < 3
2758        view::WrapLabel description;
2759    #else
2760        Gtk::Label description;
2761        description.set_line_wrap();
2762    #endif
2763        description.set_markup(_(
2764            "\nSelect at least one .gig file that shall be merged to the .gig file "
2765            "currently being open in gigedit.\n\n"
2766            "<b>Please Note:</b> Merging with other files will modify your "
2767            "currently open .gig file on file level! And be aware that the current "
2768            "merge algorithm does not detect duplicate samples yet. So if you are "
2769            "merging files which are using equivalent sample data, those "
2770            "equivalent samples will currently be treated as separate samples and "
2771            "will accordingly be stored separately in the target .gig file!"
2772        ));
2773        descriptionArea.pack_start(description);
2774        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2775        descriptionArea.show_all();
2776    
2777        if (dialog.run() == Gtk::RESPONSE_OK) {
2778            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2779            std::vector<std::string> filenames = dialog.get_filenames();
2780    
2781            // merge the selected files to the currently open .gig file
2782            try {
2783                mergeFiles(filenames);
2784            } catch (RIFF::Exception e) {
2785                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2786                msg.run();
2787            }
2788    
2789            // update GUI
2790            __refreshEntireGUI();        
2791        }
2792    }
2793    
2794  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2795      this->file_is_shared = b;      this->file_is_shared = b;
2796    
# Line 1911  void MainWindow::set_file_is_shared(bool Line 2807  void MainWindow::set_file_is_shared(bool
2807      }      }
2808  }  }
2809    
2810    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2811        if (!sample) return;
2812        sample_ref_count[sample] += offset;
2813        const int refcount = sample_ref_count[sample];
2814    
2815        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2816        for (int g = 0; g < model->children().size(); ++g) {
2817            Gtk::TreeModel::Row rowGroup = model->children()[g];
2818            for (int s = 0; s < rowGroup.children().size(); ++s) {
2819                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2820                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2821                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2822                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
2823            }
2824        }
2825    }
2826    
2827    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2828        on_sample_ref_count_incremented(oldSample, -1);
2829        on_sample_ref_count_incremented(newSample, +1);
2830    }
2831    
2832    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2833        // just in case a new sample is added later with exactly the same memory
2834        // address, which would lead to incorrect refcount if not deleted here
2835        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2836             it != samples.end(); it != samples.end())
2837        {
2838            sample_ref_count.erase(*it);
2839        }
2840    }
2841    
2842    void MainWindow::show_samples_tab() {
2843        m_TreeViewNotebook.set_current_page(0);
2844    }
2845    
2846    void MainWindow::show_intruments_tab() {
2847        m_TreeViewNotebook.set_current_page(1);
2848    }
2849    
2850    void MainWindow::show_scripts_tab() {
2851        m_TreeViewNotebook.set_current_page(2);
2852    }
2853    
2854  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2855      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2856  }  }

Legend:
Removed from v.2398  
changed lines
  Added in v.2658

  ViewVC Help
Powered by ViewVC