/[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 1382 by schoenebeck, Thu Oct 4 23:29:22 2007 UTC revision 2624 by schoenebeck, Wed Jun 11 20:26:26 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006, 2007 Andreas Persson   * Copyright (C) 2006-2014 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
 #include <libintl.h>  
20  #include <iostream>  #include <iostream>
21    #include <cstring>
22    
23    #include <glibmm/convert.h>
24    #include <glibmm/dispatcher.h>
25    #include <glibmm/miscutils.h>
26    #include <glibmm/stringutils.h>
27    #include <gtkmm/aboutdialog.h>
28  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
29  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
33    #include <gtkmm/toggleaction.h>
34  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  #if GTKMM_MAJOR_VERSION < 3
35  #define ABOUT_DIALOG  #include "wrapLabel.hh"
 #include <gtkmm/aboutdialog.h>  
36  #endif  #endif
37    
38  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #include "global.h"
39  namespace Glib {  #include "compat.h"
 Glib::ustring filename_display_basename(const std::string& filename)  
 {  
     gchar* gstr = g_path_get_basename(filename.c_str());  
     Glib::ustring str(gstr);  
     g_free(gstr);  
     return Glib::filename_to_utf8(str);  
 }  
 }  
 #endif  
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46    #include "Settings.h"
47    #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49    #include "scriptslots.h"
50    #include "ReferencesView.h"
51    #include "../../gfx/status_attached.xpm"
52    #include "../../gfx/status_detached.xpm"
53    
 #define _(String) gettext(String)  
   
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
54    
55  MainWindow::MainWindow()  MainWindow::MainWindow() :
56        dimreg_label(_("Changes apply to:")),
57        dimreg_all_regions(_("all regions")),
58        dimreg_all_dimregs(_("all dimension splits")),
59        dimreg_stereo(_("both channels"))
60  {  {
61  //    set_border_width(5);  //    set_border_width(5);
62  //    set_default_size(400, 200);  //    set_default_size(400, 200);
# Line 65  MainWindow::MainWindow() Line 65  MainWindow::MainWindow()
65      add(m_VBox);      add(m_VBox);
66    
67      // Handle selection      // Handle selection
68      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
69          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
70    
71      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 82  MainWindow::MainWindow() Line 81  MainWindow::MainWindow()
81      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
82      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
83    
84        m_ScrolledWindowScripts.add(m_TreeViewScripts);
85        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
86    
87    
88      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
89    
90      m_HPaned.add1(m_TreeViewNotebook);      m_HPaned.add1(m_TreeViewNotebook);
91      m_HPaned.add2(dimreg_edit);      dimreg_hbox.add(dimreg_label);
92        dimreg_hbox.add(dimreg_all_regions);
93        dimreg_hbox.add(dimreg_all_dimregs);
94      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");      dimreg_stereo.set_active();
95      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");      dimreg_hbox.add(dimreg_stereo);
96        dimreg_vbox.add(dimreg_edit);
97        dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
98        m_HPaned.add2(dimreg_vbox);
99    
100        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
101        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."));
102        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."));
103        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)."));
104    
105        m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
106        m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
107        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
108    
109      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
110    
# Line 122  MainWindow::MainWindow() Line 135  MainWindow::MainWindow()
135                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
136                       sigc::mem_fun(                       sigc::mem_fun(
137                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
138        actionGroup->add(Gtk::Action::create("MidiRules",
139                                             _("_Midi Rules...")),
140                         sigc::mem_fun(
141                             *this, &MainWindow::show_midi_rules));
142        actionGroup->add(Gtk::Action::create("ScriptSlots",
143                                             _("_Script Slots...")),
144                         sigc::mem_fun(
145                             *this, &MainWindow::show_script_slots));
146      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
147                       sigc::mem_fun(                       sigc::mem_fun(
148                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
149      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
150    
151    
152        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
153    
154        Glib::RefPtr<Gtk::ToggleAction> toggle_action =
155            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
156        toggle_action->set_active(true);
157        actionGroup->add(toggle_action);
158    
159        toggle_action =
160            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
161        toggle_action->set_active(true);
162        actionGroup->add(toggle_action);
163    
164        toggle_action =
165            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
166        toggle_action->set_active(true);
167        actionGroup->add(toggle_action);
168    
169    
170        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
171        toggle_action =
172            Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
173        toggle_action->set_active(true);
174        actionGroup->add(toggle_action,
175                         sigc::mem_fun(
176                             *this, &MainWindow::on_action_view_status_bar));
177    
178      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
179      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
180                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
181      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
182                       sigc::mem_fun(                       sigc::mem_fun(
183                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
184      actionGroup->add(      actionGroup->add(
185          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
186          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
187      );      );
188      actionGroup->add(      actionGroup->add(
189            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
190            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
191        );
192        actionGroup->add(
193          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
194          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
195      );      );
196    
197    
198        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
199        
200        toggle_action =
201            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
202        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
203        actionGroup->add(
204            toggle_action,
205            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
206        );
207    
208    
209        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
210    
211        actionGroup->add(
212            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
213            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
214        );
215    
216        actionGroup->add(
217            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
218            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
219        );
220    
221    
222      // sample right-click popup actions      // sample right-click popup actions
223      actionGroup->add(      actionGroup->add(
224          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 154  MainWindow::MainWindow() Line 229  MainWindow::MainWindow()
229          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
230      );      );
231      actionGroup->add(      actionGroup->add(
232          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
233          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
234      );      );
235      actionGroup->add(      actionGroup->add(
236          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
237          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
238      );      );
239        actionGroup->add(
240            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
241            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
242        );
243        actionGroup->add(
244            Gtk::Action::create("ReplaceAllSamplesInAllGroups",
245                                _("Replace All Samples in All Groups...")),
246            sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
247        );
248        
249        // script right-click popup actions
250        actionGroup->add(
251            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
252            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
253        );
254        actionGroup->add(
255            Gtk::Action::create("AddScript", _("Add _Script")),
256            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
257        );
258        actionGroup->add(
259            Gtk::Action::create("EditScript", _("_Edit Script...")),
260            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
261        );
262        actionGroup->add(
263            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
264            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
265        );
266    
267      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
268      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 180  MainWindow::MainWindow() Line 282  MainWindow::MainWindow()
282          "      <separator/>"          "      <separator/>"
283          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
284          "    </menu>"          "    </menu>"
285            "    <menu action='MenuEdit'>"
286            "      <menuitem action='CopySampleUnity'/>"
287            "      <menuitem action='CopySampleTune'/>"
288            "      <menuitem action='CopySampleLoop'/>"
289            "    </menu>"
290          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
291          "    </menu>"          "    </menu>"
292  #ifdef ABOUT_DIALOG          "    <menu action='MenuView'>"
293            "      <menuitem action='Statusbar'/>"
294            "    </menu>"
295            "    <menu action='MenuTools'>"
296            "      <menuitem action='CombineInstruments'/>"
297            "      <menuitem action='MergeFiles'/>"
298            "    </menu>"
299            "    <menu action='MenuSettings'>"
300            "      <menuitem action='WarnUserOnExtensions'/>"
301            "    </menu>"
302          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
303          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
304          "    </menu>"          "    </menu>"
 #endif  
305          "  </menubar>"          "  </menubar>"
306          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
307          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
308            "    <menuitem action='MidiRules'/>"
309            "    <menuitem action='ScriptSlots'/>"
310          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
311            "    <menuitem action='DupInstrument'/>"
312          "    <separator/>"          "    <separator/>"
313          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
314          "  </popup>"          "  </popup>"
# Line 198  MainWindow::MainWindow() Line 316  MainWindow::MainWindow()
316          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
317          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
318          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
319            "    <menuitem action='ShowSampleRefs'/>"
320            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
321          "    <separator/>"          "    <separator/>"
322          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
323          "  </popup>"          "  </popup>"
324            "  <popup name='ScriptPopupMenu'>"
325            "    <menuitem action='AddScriptGroup'/>"
326            "    <menuitem action='AddScript'/>"
327            "    <menuitem action='EditScript'/>"
328            "    <separator/>"
329            "    <menuitem action='RemoveScript'/>"
330            "  </popup>"
331          "</ui>";          "</ui>";
332      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
333    
334      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
335        
336        // Set tooltips for menu items (for some reason, setting a tooltip on the
337        // respective Gtk::Action objects above will simply be ignored, no matter
338        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
339        // Gtk::Action::create()).
340        {
341            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
342                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
343            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."));
344        }
345        {
346            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
347                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
348            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."));
349        }
350        {
351            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
352                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
353            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."));
354        }
355        {
356            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
357                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
358            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."));
359        }
360        {
361            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
362                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
363            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
364        }
365        {
366            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
367                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
368            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
369        }
370    
371    
372        instrument_menu = static_cast<Gtk::MenuItem*>(
373            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
374    
375      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
376      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
377      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
378      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
379        m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
380      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
381        m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
382    
383        set_file_is_shared(false);
384    
385        // Status Bar:
386        m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
387        m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
388        m_StatusBar.show();
389    
390      m_RegionChooser.signal_region_selected().connect(      m_RegionChooser.signal_region_selected().connect(
391          sigc::mem_fun(*this, &MainWindow::region_changed) );          sigc::mem_fun(*this, &MainWindow::region_changed) );
# Line 221  MainWindow::MainWindow() Line 396  MainWindow::MainWindow()
396      // Create the Tree model:      // Create the Tree model:
397      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
398      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
399      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
400        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
401          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
402      );      );
403    
# Line 232  MainWindow::MainWindow() Line 408  MainWindow::MainWindow()
408      // create samples treeview (including its data model)      // create samples treeview (including its data model)
409      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
410      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
411        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."));
412      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
413      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
414      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
415        {
416            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
417            Gtk::CellRendererText* cellrenderer =
418                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
419            column->add_attribute(
420                cellrenderer->property_foreground(), m_SamplesModel.m_color
421            );
422        }
423        {
424            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
425            Gtk::CellRendererText* cellrenderer =
426                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
427            column->add_attribute(
428                cellrenderer->property_foreground(), m_SamplesModel.m_color
429            );
430        }
431        m_TreeViewSamples.set_headers_visible(true);
432      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
433          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
434      );      );
# Line 242  MainWindow::MainWindow() Line 436  MainWindow::MainWindow()
436          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
437      );      );
438    
439        // create scripts treeview (including its data model)
440        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
441        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
442        m_TreeViewScripts.set_tooltip_text(_(
443            "Note: instrument scripts are a LinuxSampler extension of the gig "
444            "format. This feature will not work with the GigaStudio software!"
445        ));
446        // m_TreeViewScripts.set_reorderable();
447        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
448        m_TreeViewScripts.set_headers_visible(false);
449        m_TreeViewScripts.signal_button_press_event().connect_notify(
450            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
451        );
452        m_refScriptsTreeModel->signal_row_changed().connect(
453            sigc::mem_fun(*this, &MainWindow::script_name_changed)
454        );
455    
456        // establish drag&drop between scripts tree view and ScriptSlots window
457        std::vector<Gtk::TargetEntry> drag_target_gig_script;
458        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
459        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
460        m_TreeViewScripts.signal_drag_begin().connect(
461            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
462        );
463        m_TreeViewScripts.signal_drag_data_get().connect(
464            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
465        );
466    
467      // 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
468      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
469      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
470      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
471      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
472          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 262  MainWindow::MainWindow() Line 484  MainWindow::MainWindow()
484          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
485      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
486          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
487      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
488            sigc::mem_fun(*this, &MainWindow::file_changed));
489        propDialog.signal_changed().connect(
490            sigc::mem_fun(*this, &MainWindow::file_changed));
491        midiRules.signal_changed().connect(
492          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
493    
494      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 271  MainWindow::MainWindow() Line 497  MainWindow::MainWindow()
497          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
498      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
499          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
500        sample_ref_changed_signal.connect(
501            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
502        );
503        samples_to_be_removed_signal.connect(
504            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
505        );
506    
507      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
508          sigc::hide(          sigc::hide(
# Line 293  MainWindow::MainWindow() Line 525  MainWindow::MainWindow()
525      m_RegionChooser.signal_region_changed_signal().connect(      m_RegionChooser.signal_region_changed_signal().connect(
526          region_changed_signal.make_slot());          region_changed_signal.make_slot());
527    
528        note_on_signal.connect(
529            sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
530        note_off_signal.connect(
531            sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
532    
533        dimreg_all_regions.signal_toggled().connect(
534            sigc::mem_fun(*this, &MainWindow::update_dimregs));
535        dimreg_all_dimregs.signal_toggled().connect(
536            sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
537        dimreg_stereo.signal_toggled().connect(
538            sigc::mem_fun(*this, &MainWindow::update_dimregs));
539    
540      file = 0;      file = 0;
541      file_is_changed = false;      file_is_changed = false;
     file_is_shared  = false;  
542    
543      show_all_children();      show_all_children();
544    
545      // start with a new gig file by default      // start with a new gig file by default
546      on_action_file_new();      on_action_file_new();
547    
548        // select 'Instruments' tab by default
549        // (gtk allows this only if the tab childs are visible, thats why it's here)
550        m_TreeViewNotebook.set_current_page(1);
551  }  }
552    
553  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 323  void MainWindow::region_changed() Line 570  void MainWindow::region_changed()
570      m_DimRegionChooser.set_region(m_RegionChooser.get_region());      m_DimRegionChooser.set_region(m_RegionChooser.get_region());
571  }  }
572    
573    gig::Instrument* MainWindow::get_instrument()
574    {
575        gig::Instrument* instrument = 0;
576        Gtk::TreeModel::const_iterator it =
577            m_TreeView.get_selection()->get_selected();
578        if (it) {
579            Gtk::TreeModel::Row row = *it;
580            instrument = row[m_Columns.m_col_instr];
581        }
582        return instrument;
583    }
584    
585    void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
586    {
587        if (all_dimregs) {
588            for (int i = 0 ; i < region->DimensionRegions ; i++) {
589                if (region->pDimensionRegions[i]) {
590                    dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
591                }
592            }
593        } else {
594            m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
595        }
596    }
597    
598    void MainWindow::update_dimregs()
599    {
600        dimreg_edit.dimregs.clear();
601        bool all_regions = dimreg_all_regions.get_active();
602        bool stereo = dimreg_stereo.get_active();
603        bool all_dimregs = dimreg_all_dimregs.get_active();
604    
605        if (all_regions) {
606            gig::Instrument* instrument = get_instrument();
607            if (instrument) {
608                for (gig::Region* region = instrument->GetFirstRegion() ;
609                     region ;
610                     region = instrument->GetNextRegion()) {
611                    add_region_to_dimregs(region, stereo, all_dimregs);
612                }
613            }
614        } else {
615            gig::Region* region = m_RegionChooser.get_region();
616            if (region) {
617                add_region_to_dimregs(region, stereo, all_dimregs);
618            }
619        }
620    }
621    
622    void MainWindow::dimreg_all_dimregs_toggled()
623    {
624        dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
625        update_dimregs();
626    }
627    
628  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
629  {  {
630        update_dimregs();
631      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());
632  }  }
633    
634  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
635  {  {
636      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      // select item in instrument menu
637        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
638      if (it) {      if (it) {
639          Gtk::TreeModel::Row row = *it;          Gtk::TreePath path(it);
640          std::cout << row[m_Columns.m_col_name] << std::endl;          int index = path[0];
641            const std::vector<Gtk::Widget*> children =
642          m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]);              instrument_menu->get_children();
643      } else {          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
         m_RegionChooser.set_instrument(0);  
644      }      }
645    
646        m_RegionChooser.set_instrument(get_instrument());
647  }  }
648    
649  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 352  void loader_progress_callback(gig::progr Line 655  void loader_progress_callback(gig::progr
655  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
656  {  {
657      {      {
658          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
659          progress = fraction;          progress = fraction;
660      }      }
661      progress_dispatcher();      progress_dispatcher();
# Line 360  void Loader::progress_callback(float fra Line 663  void Loader::progress_callback(float fra
663    
664  void Loader::thread_function()  void Loader::thread_function()
665  {  {
666      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
667      printf("Start %s\n", filename);      printf("Start %s\n", filename);
668      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
669      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 374  void Loader::thread_function() Line 677  void Loader::thread_function()
677  }  }
678    
679  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
680      : thread(0), filename(filename)      : filename(filename), thread(0)
681  {  {
682  }  }
683    
684  void Loader::launch()  void Loader::launch()
685  {  {
686    #ifdef OLD_THREADS
687      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
688    #else
689        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
690    #endif
691      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
692  }  }
693    
# Line 388  float Loader::get_progress() Line 695  float Loader::get_progress()
695  {  {
696      float res;      float res;
697      {      {
698          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
699          res = progress;          res = progress;
700      }      }
701      return res;      return res;
# Line 414  LoadDialog::LoadDialog(const Glib::ustri Line 721  LoadDialog::LoadDialog(const Glib::ustri
721  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
722  // 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.
723  void MainWindow::__clear() {  void MainWindow::__clear() {
     // remove all entries from "Instrument" menu  
     Gtk::MenuItem* instrument_menu =  
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
     instrument_menu->hide();  
     for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) {  
         delete &instrument_menu->get_submenu()->items()[i];  
     }  
     instrument_menu->get_submenu()->items().clear();  
724      // forget all samples that ought to be imported      // forget all samples that ought to be imported
725      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
726      // clear the samples and instruments tree views      // clear the samples and instruments tree views
727      m_refTreeModel->clear();      m_refTreeModel->clear();
728      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
729        m_refScriptsTreeModel->clear();
730        // remove all entries from "Instrument" menu
731        while (!instrument_menu->get_children().empty()) {
732            remove_instrument_from_menu(0);
733        }
734      // free libgig's gig::File instance      // free libgig's gig::File instance
735      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
736      file = NULL;      file = NULL;
737      file_is_shared = false;      set_file_is_shared(false);
738    }
739    
740    void MainWindow::__refreshEntireGUI() {
741        // clear the samples and instruments tree views
742        m_refTreeModel->clear();
743        m_refSamplesTreeModel->clear();
744        m_refScriptsTreeModel->clear();
745        // remove all entries from "Instrument" menu
746        while (!instrument_menu->get_children().empty()) {
747            remove_instrument_from_menu(0);
748        }
749    
750        if (!this->file) return;
751    
752        load_gig(
753            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
754        );
755  }  }
756    
757  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
# Line 445  void MainWindow::on_action_file_new() Line 766  void MainWindow::on_action_file_new()
766      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
767      // already add one new instrument by default      // already add one new instrument by default
768      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
769      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
770      // update GUI with that new gig::File      // update GUI with that new gig::File
771      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
772  }  }
# Line 456  bool MainWindow::close_confirmation_dial Line 777  bool MainWindow::close_confirmation_dial
777                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
778      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
779      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
780      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
 #endif  
781      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
782      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
783      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
# Line 472  bool MainWindow::close_confirmation_dial Line 791  bool MainWindow::close_confirmation_dial
791  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
792      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
793      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
794      dialog.set_secondary_text(      dialog.set_secondary_text(
795          _("If you proceed to work on another instrument file, it won't be "          _("If you proceed to work on another instrument file, it won't be "
796            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
797            "load it.")            "load it."));
    );  
 #endif  
798      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
799      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
800      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 497  void MainWindow::on_action_file_open() Line 813  void MainWindow::on_action_file_open()
813      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
814      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
815      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
816    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
817      Gtk::FileFilter filter;      Gtk::FileFilter filter;
818      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
819    #else
820        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
821        filter->add_pattern("*.gig");
822    #endif
823      dialog.set_filter(filter);      dialog.set_filter(filter);
824      if (current_dir != "") {      if (current_gig_dir != "") {
825          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
826      }      }
827      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
828          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
829          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
830          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
831          load_file(filename.c_str());          load_file(filename.c_str());
832          current_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
833      }      }
834  }  }
835    
836  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
837  {  {
838      __clear();      __clear();
839      load_dialog = new LoadDialog("Loading...", *this);      load_dialog = new LoadDialog(_("Loading..."), *this);
840      load_dialog->show_all();      load_dialog->show_all();
841      loader = new Loader(strdup(name));      loader = new Loader(strdup(name));
842      loader->signal_progress().connect(      loader->signal_progress().connect(
# Line 548  void MainWindow::on_loader_progress() Line 869  void MainWindow::on_loader_progress()
869  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
870  {  {
871      printf("Loader finished!\n");      printf("Loader finished!\n");
872      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
873      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
874      load_dialog->hide();      load_dialog->hide();
875  }  }
# Line 620  bool MainWindow::file_save_as() Line 941  bool MainWindow::file_save_as()
941      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
942      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
943      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2  
944      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
945      // TODO: an overwrite dialog for gtkmm < 2.8  
946  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
947      Gtk::FileFilter filter;      Gtk::FileFilter filter;
948      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
949    #else
950        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
951        filter->add_pattern("*.gig");
952    #endif
953      dialog.set_filter(filter);      dialog.set_filter(filter);
954    
955      if (Glib::path_is_absolute(filename)) {      // set initial dir and filename of the Save As dialog
956          dialog.set_filename(filename);      // and prepare that initial filename as a copy of the gig
957      } else if (current_dir != "") {      {
958          dialog.set_current_folder(current_dir);          std::string basename = Glib::path_get_basename(filename);
959            std::string dir = Glib::path_get_dirname(filename);
960            basename = std::string(_("copy_of_")) + basename;
961            Glib::ustring copyFileName = Glib::build_filename(dir, basename);
962            if (Glib::path_is_absolute(filename)) {
963                dialog.set_filename(copyFileName);
964            } else {
965                if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
966            }
967            dialog.set_current_name(Glib::filename_display_basename(copyFileName));
968      }      }
969      dialog.set_current_name(Glib::filename_display_basename(filename));  
970        // show warning in the dialog
971        Gtk::HBox descriptionArea;
972        descriptionArea.set_spacing(15);
973        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
974        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
975    #if GTKMM_MAJOR_VERSION < 3
976        view::WrapLabel description;
977    #else
978        Gtk::Label description;
979        description.set_line_wrap();
980    #endif
981        description.set_markup(
982            _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
983              "<span style=\"italic\">\"Save\"</span> dialog instead of "
984              "<span style=\"italic\">\"Save As...\"</span> if you want to save "
985              "to the same .gig file. Using "
986              "<span style=\"italic\">\"Save As...\"</span> for writing to the "
987              "same .gig file will end up in corrupted sample wave data!\n")
988        );
989        descriptionArea.pack_start(description);
990        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
991        descriptionArea.show_all();
992    
993      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
994          file_structure_to_be_changed_signal.emit(this->file);          file_structure_to_be_changed_signal.emit(this->file);
# Line 646  bool MainWindow::file_save_as() Line 1000  bool MainWindow::file_save_as()
1000              printf("filename=%s\n", filename.c_str());              printf("filename=%s\n", filename.c_str());
1001              file->Save(filename);              file->Save(filename);
1002              this->filename = filename;              this->filename = filename;
1003              current_dir = Glib::path_get_dirname(filename);              current_gig_dir = Glib::path_get_dirname(filename);
1004              set_title(Glib::filename_display_basename(filename));              set_title(Glib::filename_display_basename(filename));
1005              file_has_name = true;              file_has_name = true;
1006              file_is_changed = false;              file_is_changed = false;
# Line 675  void MainWindow::__import_queued_samples Line 1029  void MainWindow::__import_queued_samples
1029          SF_INFO info;          SF_INFO info;
1030          info.format = 0;          info.format = 0;
1031          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
1032            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1033          try {          try {
1034              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
1035              // determine sample's bit depth              // determine sample's bit depth
1036              int bitdepth;              int bitdepth;
1037              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 693  void MainWindow::__import_queued_samples Line 1048  void MainWindow::__import_queued_samples
1048                      break;                      break;
1049                  default:                  default:
1050                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
1051                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1052              }              }
1053    
1054              const int bufsize = 10000;              const int bufsize = 10000;
# Line 735  void MainWindow::__import_queued_samples Line 1090  void MainWindow::__import_queued_samples
1090              }              }
1091              // cleanup              // cleanup
1092              sf_close(hFile);              sf_close(hFile);
1093                // let the sampler re-cache the sample if needed
1094                sample_changed_signal.emit(iter->gig_sample);
1095              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1096              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1097              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 742  void MainWindow::__import_queued_samples Line 1099  void MainWindow::__import_queued_samples
1099              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1100          } catch (std::string what) {          } catch (std::string what) {
1101              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1102              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1103              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1104              ++iter;              ++iter;
1105          }          }
1106      }      }
1107      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
1108      if (error_files.size()) {      if (!error_files.empty()) {
1109          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;
1110          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1111          msg.run();          msg.run();
# Line 761  void MainWindow::on_action_file_properti Line 1118  void MainWindow::on_action_file_properti
1118      propDialog.deiconify();      propDialog.deiconify();
1119  }  }
1120    
1121    void MainWindow::on_action_warn_user_on_extensions() {
1122        Settings::singleton()->warnUserOnExtensions =
1123            !Settings::singleton()->warnUserOnExtensions;
1124    }
1125    
1126  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1127  {  {
 #ifdef ABOUT_DIALOG  
1128      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
1129    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
1130        dialog.set_program_name("Gigedit");
1131    #else
1132        dialog.set_name("Gigedit");
1133    #endif
1134      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1135        dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1136        const std::string sComment =
1137            _("Built " __DATE__ "\nUsing ") +
1138            ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1139            _(
1140                "Gigedit is released under the GNU General Public License.\n"
1141                "\n"
1142                "Please notice that this is still a very young instrument editor. "
1143                "So better backup your Gigasampler files before editing them with "
1144                "this application.\n"
1145                "\n"
1146                "Please report bugs to: http://bugs.linuxsampler.org"
1147            );
1148        dialog.set_comments(sComment.c_str());
1149        dialog.set_website("http://www.linuxsampler.org");
1150        dialog.set_website_label("http://www.linuxsampler.org");
1151      dialog.run();      dialog.run();
 #endif  
1152  }  }
1153    
1154  PropDialog::PropDialog()  PropDialog::PropDialog()
1155      : table(2,1)      : eFileFormat(_("File Format")),
1156          eName(_("Name")),
1157          eCreationDate(_("Creation date")),
1158          eComments(_("Comments")),
1159          eProduct(_("Product")),
1160          eCopyright(_("Copyright")),
1161          eArtists(_("Artists")),
1162          eGenre(_("Genre")),
1163          eKeywords(_("Keywords")),
1164          eEngineer(_("Engineer")),
1165          eTechnician(_("Technician")),
1166          eSoftware(_("Software")),
1167          eMedium(_("Medium")),
1168          eSource(_("Source")),
1169          eSourceForm(_("Source form")),
1170          eCommissioned(_("Commissioned")),
1171          eSubject(_("Subject")),
1172          quitButton(Gtk::Stock::CLOSE),
1173          table(2, 1),
1174          m_file(NULL)
1175  {  {
1176        set_title(_("File Properties"));
1177        eName.set_width_chars(50);
1178    
1179        connect(eName, &DLS::Info::Name);
1180        connect(eCreationDate, &DLS::Info::CreationDate);
1181        connect(eComments, &DLS::Info::Comments);
1182        connect(eProduct, &DLS::Info::Product);
1183        connect(eCopyright, &DLS::Info::Copyright);
1184        connect(eArtists, &DLS::Info::Artists);
1185        connect(eGenre, &DLS::Info::Genre);
1186        connect(eKeywords, &DLS::Info::Keywords);
1187        connect(eEngineer, &DLS::Info::Engineer);
1188        connect(eTechnician, &DLS::Info::Technician);
1189        connect(eSoftware, &DLS::Info::Software);
1190        connect(eMedium, &DLS::Info::Medium);
1191        connect(eSource, &DLS::Info::Source);
1192        connect(eSourceForm, &DLS::Info::SourceForm);
1193        connect(eCommissioned, &DLS::Info::Commissioned);
1194        connect(eSubject, &DLS::Info::Subject);
1195    
1196        table.add(eFileFormat);
1197        table.add(eName);
1198        table.add(eCreationDate);
1199        table.add(eComments);
1200        table.add(eProduct);
1201        table.add(eCopyright);
1202        table.add(eArtists);
1203        table.add(eGenre);
1204        table.add(eKeywords);
1205        table.add(eEngineer);
1206        table.add(eTechnician);
1207        table.add(eSoftware);
1208        table.add(eMedium);
1209        table.add(eSource);
1210        table.add(eSourceForm);
1211        table.add(eCommissioned);
1212        table.add(eSubject);
1213    
1214      table.set_col_spacings(5);      table.set_col_spacings(5);
1215      const char* propLabels[] = {      add(vbox);
1216          "Name:",      table.set_border_width(5);
1217          "CreationDate:",      vbox.add(table);
1218          "Comments:", // TODO: multiline      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
1219          "Product:",      buttonBox.set_layout(Gtk::BUTTONBOX_END);
1220          "Copyright:",      buttonBox.set_border_width(5);
1221          "Artists:",      buttonBox.show();
1222          "Genre:",      buttonBox.pack_start(quitButton);
1223          "Keywords:",      quitButton.set_can_default();
1224          "Engineer:",      quitButton.grab_focus();
1225          "Technician:",      quitButton.signal_clicked().connect(
1226          "Software:", // TODO: readonly          sigc::mem_fun(*this, &PropDialog::hide));
1227          "Medium:",      eFileFormat.signal_value_changed().connect(
1228          "Source:",          sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
         "SourceForm:",  
         "Commissioned:",  
         "Subject:"  
     };  
     for (int i = 0 ; i < sizeof(propLabels) / sizeof(char*) ; i++) {  
         label[i].set_text(propLabels[i]);  
         label[i].set_alignment(Gtk::ALIGN_LEFT);  
         table.attach(label[i], 0, 1, i, i + 1, Gtk::FILL, Gtk::SHRINK);  
         table.attach(entry[i], 1, 2, i, i + 1, Gtk::FILL | Gtk::EXPAND,  
                      Gtk::SHRINK);  
     }  
1229    
1230      add(table);      quitButton.show();
1231      // add_button(Gtk::Stock::CANCEL, 0);      vbox.show();
     // add_button(Gtk::Stock::OK, 1);  
1232      show_all_children();      show_all_children();
1233  }  }
1234    
1235    void PropDialog::set_file(gig::File* file)
1236    {
1237        m_file = file;
1238    
1239        // update file format version combo box
1240        const std::string sGiga = "Gigasampler/GigaStudio v";
1241        const int major = file->pVersion->major;
1242        std::vector<std::string> txts;
1243        std::vector<int> values;
1244        txts.push_back(sGiga + "2"); values.push_back(2);
1245        txts.push_back(sGiga + "3/v4"); values.push_back(3);
1246        if (major != 2 && major != 3) {
1247            txts.push_back(sGiga + ToString(major)); values.push_back(major);
1248        }
1249        std::vector<const char*> texts;
1250        for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1251        texts.push_back(NULL); values.push_back(0);
1252        eFileFormat.set_choices(&texts[0], &values[0]);
1253        eFileFormat.set_value(major);
1254    }
1255    
1256    void PropDialog::onFileFormatChanged() {
1257        const int major = eFileFormat.get_value();
1258        if (m_file) m_file->pVersion->major = major;
1259    }
1260    
1261  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1262  {  {
1263      entry[0].set_text(info->Name);      update(info);
     entry[1].set_text(info->CreationDate);  
     entry[2].set_text(Glib::convert(info->Comments, "UTF-8", "ISO-8859-1"));  
     entry[3].set_text(info->Product);  
     entry[4].set_text(info->Copyright);  
     entry[5].set_text(info->Artists);  
     entry[6].set_text(info->Genre);  
     entry[7].set_text(info->Keywords);  
     entry[8].set_text(info->Engineer);  
     entry[9].set_text(info->Technician);  
     entry[10].set_text(info->Software);  
     entry[11].set_text(info->Medium);  
     entry[12].set_text(info->Source);  
     entry[13].set_text(info->SourceForm);  
     entry[14].set_text(info->Commissioned);  
     entry[15].set_text(info->Subject);  
 }  
   
 void InstrumentProps::add_prop(BoolEntry& boolentry)  
 {  
     table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
                  Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
     boolentry.signal_changed_by_user().connect(instrument_changed.make_slot());  
 }  
   
 void InstrumentProps::add_prop(BoolEntryPlus6& boolentry)  
 {  
     table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
                  Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
     boolentry.signal_changed_by_user().connect(instrument_changed.make_slot());  
 }  
   
 void InstrumentProps::add_prop(LabelWidget& prop)  
 {  
     table.attach(prop.label, 0, 1, rowno, rowno + 1,  
                  Gtk::FILL, Gtk::SHRINK);  
     table.attach(prop.widget, 1, 2, rowno, rowno + 1,  
                  Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);  
     rowno++;  
     prop.signal_changed_by_user().connect(instrument_changed.make_slot());  
1264  }  }
1265    
1266  InstrumentProps::InstrumentProps()  
1267      : table(2,1),  void InstrumentProps::set_Name(const gig::String& name)
       quitButton(Gtk::Stock::CLOSE),  
       eName("Name"),  
       eIsDrum("Is drum"),  
       eMIDIBank("MIDI bank", 0, 16383),  
       eMIDIProgram("MIDI program"),  
       eAttenuation("Attenuation", 0, 96, 0, 1),  
       eGainPlus6("Gain +6dB", eAttenuation, -6),  
       eEffectSend("Effect send", 0, 65535),  
       eFineTune("Fine tune", -8400, 8400),  
       ePitchbendRange("Pitchbend range", 0, 12),  
       ePianoReleaseMode("Piano release mode"),  
       eDimensionKeyRangeLow("Dimension key range low"),  
       eDimensionKeyRangeHigh("Dimension key range high")  
1268  {  {
1269      set_title("Instrument properties");      m->pInfo->Name = name;
1270    }
1271    
1272    void InstrumentProps::update_name()
1273    {
1274        update_model++;
1275        eName.set_value(m->pInfo->Name);
1276        update_model--;
1277    }
1278    
1279    void InstrumentProps::set_IsDrum(bool value)
1280    {
1281        m->IsDrum = value;
1282    }
1283    
1284    void InstrumentProps::set_MIDIBank(uint16_t value)
1285    {
1286        m->MIDIBank = value;
1287    }
1288    
1289    void InstrumentProps::set_MIDIProgram(uint32_t value)
1290    {
1291        m->MIDIProgram = value;
1292    }
1293    
1294    InstrumentProps::InstrumentProps() :
1295        quitButton(Gtk::Stock::CLOSE),
1296        table(2,1),
1297        eName(_("Name")),
1298        eIsDrum(_("Is drum")),
1299        eMIDIBank(_("MIDI bank"), 0, 16383),
1300        eMIDIProgram(_("MIDI program")),
1301        eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1302        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1303        eEffectSend(_("Effect send"), 0, 65535),
1304        eFineTune(_("Fine tune"), -8400, 8400),
1305        ePitchbendRange(_("Pitchbend range"), 0, 12),
1306        ePianoReleaseMode(_("Piano release mode")),
1307        eDimensionKeyRangeLow(_("Keyswitching range low")),
1308        eDimensionKeyRangeHigh(_("Keyswitching range high"))
1309    {
1310        set_title(_("Instrument Properties"));
1311    
1312        eDimensionKeyRangeLow.set_tip(
1313            _("start of the keyboard area which should switch the "
1314              "\"keyswitching\" dimension")
1315        );
1316        eDimensionKeyRangeHigh.set_tip(
1317            _("end of the keyboard area which should switch the "
1318              "\"keyswitching\" dimension")
1319        );
1320    
1321        connect(eName, &InstrumentProps::set_Name);
1322        connect(eIsDrum, &InstrumentProps::set_IsDrum);
1323        connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1324        connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
1325        connect(eAttenuation, &gig::Instrument::Attenuation);
1326        connect(eGainPlus6, &gig::Instrument::Attenuation);
1327        connect(eEffectSend, &gig::Instrument::EffectSend);
1328        connect(eFineTune, &gig::Instrument::FineTune);
1329        connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1330        connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1331        connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1332                &gig::Instrument::DimensionKeyRange);
1333    
1334        eName.signal_value_changed().connect(sig_name_changed.make_slot());
1335    
     rowno = 0;  
1336      table.set_col_spacings(5);      table.set_col_spacings(5);
1337    
1338      add_prop(eName);      table.add(eName);
1339      add_prop(eIsDrum);      table.add(eIsDrum);
1340      add_prop(eMIDIBank);      table.add(eMIDIBank);
1341      add_prop(eMIDIProgram);      table.add(eMIDIProgram);
1342      add_prop(eAttenuation);      table.add(eAttenuation);
1343      add_prop(eGainPlus6);      table.add(eGainPlus6);
1344      add_prop(eEffectSend);      table.add(eEffectSend);
1345      add_prop(eFineTune);      table.add(eFineTune);
1346      add_prop(ePitchbendRange);      table.add(ePitchbendRange);
1347      add_prop(ePianoReleaseMode);      table.add(ePianoReleaseMode);
1348      add_prop(eDimensionKeyRangeLow);      table.add(eDimensionKeyRangeLow);
1349      add_prop(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
   
     eDimensionKeyRangeLow.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed));  
     eDimensionKeyRangeHigh.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed));  
1350    
1351      add(vbox);      add(vbox);
1352      table.set_border_width(5);      table.set_border_width(5);
# Line 900  InstrumentProps::InstrumentProps() Line 1357  InstrumentProps::InstrumentProps()
1357      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1358      buttonBox.show();      buttonBox.show();
1359      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1360      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1361      quitButton.grab_focus();      quitButton.grab_focus();
1362    
1363      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 913  InstrumentProps::InstrumentProps() Line 1370  InstrumentProps::InstrumentProps()
1370    
1371  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1372  {  {
1373      eName.set_ptr(&instrument->pInfo->Name);      update(instrument);
     eIsDrum.set_ptr(&instrument->IsDrum);  
     eMIDIBank.set_ptr(&instrument->MIDIBank);  
     eMIDIProgram.set_ptr(&instrument->MIDIProgram);  
     eAttenuation.set_ptr(&instrument->Attenuation);  
     eGainPlus6.set_ptr(&instrument->Attenuation);  
     eEffectSend.set_ptr(&instrument->EffectSend);  
     eFineTune.set_ptr(&instrument->FineTune);  
     ePitchbendRange.set_ptr(&instrument->PitchbendRange);  
     ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode);  
     eDimensionKeyRangeLow.set_ptr(0);  
     eDimensionKeyRangeHigh.set_ptr(0);  
     eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low);  
     eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high);  
 }  
1374    
1375  void InstrumentProps::key_range_low_changed()      update_model++;
1376  {      eName.set_value(instrument->pInfo->Name);
1377      double l = eDimensionKeyRangeLow.get_value();      eIsDrum.set_value(instrument->IsDrum);
1378      double h = eDimensionKeyRangeHigh.get_value();      eMIDIBank.set_value(instrument->MIDIBank);
1379      if (h < l) eDimensionKeyRangeHigh.set_value(l);      eMIDIProgram.set_value(instrument->MIDIProgram);
1380        update_model--;
1381  }  }
1382    
 void InstrumentProps::key_range_high_changed()  
 {  
     double l = eDimensionKeyRangeLow.get_value();  
     double h = eDimensionKeyRangeHigh.get_value();  
     if (h < l) eDimensionKeyRangeLow.set_value(h);  
 }  
   
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1383    
1384  void MainWindow::file_changed()  void MainWindow::file_changed()
1385  {  {
# Line 956  void MainWindow::file_changed() Line 1389  void MainWindow::file_changed()
1389      }      }
1390  }  }
1391    
1392    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1393        sample_ref_count.clear();
1394        
1395        if (!gig) return;
1396    
1397        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1398             instrument = gig->GetNextInstrument())
1399        {
1400            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1401                 rgn = instrument->GetNextRegion())
1402            {
1403                for (int i = 0; i < 256; ++i) {
1404                    if (!rgn->pDimensionRegions[i]) continue;
1405                    if (rgn->pDimensionRegions[i]->pSample) {
1406                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1407                    }
1408                }
1409            }
1410        }
1411    }
1412    
1413  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1414  {  {
1415      file = 0;      file = 0;
1416      file_is_shared = isSharedInstrument;      set_file_is_shared(isSharedInstrument);
1417    
1418      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename = filename ? filename : _("Unsaved Gig File");
1419      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1420      file_has_name = filename;      file_has_name = filename;
1421      file_is_changed = false;      file_is_changed = false;
1422    
1423        propDialog.set_file(gig);
1424      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1425    
1426      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;  
1427      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1428           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1429            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1430    
1431          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1432          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1433          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1434          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1435          // create a menu item for this instrument  
1436          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++;  
1437      }      }
1438      instrument_menu->show();      instrument_name_connection.unblock();
1439      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1440    
1441        updateSampleRefCountMap(gig);
1442    
1443      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1444          if (group->Name != "") {          if (group->Name != "") {
1445              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1446              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1447              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1448              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1449              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1450              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1006  void MainWindow::load_gig(gig::File* gig Line 1452  void MainWindow::load_gig(gig::File* gig
1452                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1453                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1454                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1455                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1456                        gig_to_utf8(sample->pInfo->Name);
1457                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1458                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1459                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1460                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1461                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
1462              }              }
1463          }          }
1464      }      }
1465        
1466        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1467            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1468    
1469            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1470            Gtk::TreeModel::Row rowGroup = *iterGroup;
1471            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1472            rowGroup[m_ScriptsModel.m_col_group]  = group;
1473            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1474            for (int s = 0; group->GetScript(s); ++s) {
1475                gig::Script* script = group->GetScript(s);
1476    
1477                Gtk::TreeModel::iterator iterScript =
1478                    m_refScriptsTreeModel->append(rowGroup.children());
1479                Gtk::TreeModel::Row rowScript = *iterScript;
1480                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1481                rowScript[m_ScriptsModel.m_col_script] = script;
1482                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1483            }
1484        }
1485        // unfold all sample groups & script groups by default
1486        m_TreeViewSamples.expand_all();
1487        m_TreeViewScripts.expand_all();
1488    
1489      file = gig;      file = gig;
1490    
1491      // select the first instrument      // select the first instrument
1492      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1493      tree_sel_ref->select(Gtk::TreePath("0"));  
1494        instr_props_set_instrument();
1495        gig::Instrument* instrument = get_instrument();
1496        if (instrument) {
1497            midiRules.set_instrument(instrument);
1498        }
1499    }
1500    
1501    bool MainWindow::instr_props_set_instrument()
1502    {
1503        instrumentProps.signal_name_changed().clear();
1504    
1505        Gtk::TreeModel::const_iterator it =
1506            m_TreeView.get_selection()->get_selected();
1507        if (it) {
1508            Gtk::TreeModel::Row row = *it;
1509            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1510    
1511            instrumentProps.set_instrument(instrument);
1512    
1513            // make sure instrument tree is updated when user changes the
1514            // instrument name in instrument properties window
1515            instrumentProps.signal_name_changed().connect(
1516                sigc::bind(
1517                    sigc::mem_fun(*this,
1518                                  &MainWindow::instr_name_changed_by_instr_props),
1519                    it));
1520        } else {
1521            instrumentProps.hide();
1522        }
1523        return it;
1524  }  }
1525    
1526  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
1527  {  {
1528      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      if (instr_props_set_instrument()) {
1529      Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();          instrumentProps.show();
1530      if (it)          instrumentProps.deiconify();
1531        }
1532    }
1533    
1534    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1535    {
1536        Gtk::TreeModel::Row row = *it;
1537        Glib::ustring name = row[m_Columns.m_col_name];
1538    
1539        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1540        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1541        if (gigname != name) {
1542            row[m_Columns.m_col_name] = gigname;
1543        }
1544    }
1545    
1546    void MainWindow::show_midi_rules()
1547    {
1548        if (gig::Instrument* instrument = get_instrument())
1549      {      {
1550          Gtk::TreeModel::Row row = *it;          midiRules.set_instrument(instrument);
1551          if (row[m_Columns.m_col_instr])          midiRules.show();
1552          {          midiRules.deiconify();
1553              instrumentProps.set_instrument(row[m_Columns.m_col_instr]);      }
1554              instrumentProps.show();  }
1555              instrumentProps.deiconify();  
1556          }  void MainWindow::show_script_slots() {
1557        if (!file) return;
1558        // get selected instrument
1559        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1560        Gtk::TreeModel::iterator it = sel->get_selected();
1561        if (!it) return;
1562        Gtk::TreeModel::Row row = *it;
1563        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1564        if (!instrument) return;
1565    
1566        ScriptSlots* window = new ScriptSlots;
1567        window->setInstrument(instrument);
1568        //window->reparent(*this);
1569        window->show();
1570    }
1571    
1572    void MainWindow::on_action_view_status_bar() {
1573        Gtk::CheckMenuItem* item =
1574            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
1575        if (!item) {
1576            std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n";
1577            return;
1578      }      }
1579        if (item->get_active()) m_StatusBar.show();
1580        else                    m_StatusBar.hide();
1581    }
1582    
1583    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1584        Gtk::CheckMenuItem* item =
1585            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1586        if (!item) {
1587            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1588            return true;
1589        }
1590        return item->get_active();
1591    }
1592    
1593    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1594        Gtk::CheckMenuItem* item =
1595            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1596        if (!item) {
1597            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1598            return true;
1599        }
1600        return item->get_active();
1601    }
1602    
1603    bool MainWindow::is_copy_samples_loop_enabled() const {
1604        Gtk::CheckMenuItem* item =
1605            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1606        if (!item) {
1607            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1608            return true;
1609        }
1610        return item->get_active();
1611  }  }
1612    
1613  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
# Line 1041  void MainWindow::on_button_release(GdkEv Line 1615  void MainWindow::on_button_release(GdkEv
1615      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1616          show_instr_props();          show_instr_props();
1617      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1618            // gig v2 files have no midi rules
1619            static_cast<Gtk::MenuItem*>(
1620                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1621                    !(file->pVersion && file->pVersion->major == 2));
1622          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1623      }      }
1624  }  }
1625    
1626  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1627      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1628            const std::vector<Gtk::Widget*> children =
1629                instrument_menu->get_children();
1630            std::vector<Gtk::Widget*>::const_iterator it =
1631                find(children.begin(), children.end(), item);
1632            if (it != children.end()) {
1633                int index = it - children.begin();
1634                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1635    
1636                m_RegionChooser.set_instrument(file->GetInstrument(index));
1637            }
1638        }
1639  }  }
1640    
1641  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1069  void MainWindow::on_sample_treeview_butt Line 1658  void MainWindow::on_sample_treeview_butt
1658              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1659          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1660              set_sensitive(file);              set_sensitive(file);
1661            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
1662                set_sensitive(sample_selected);
1663          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1664              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1665          // show sample popup          // show sample popup
# Line 1076  void MainWindow::on_sample_treeview_butt Line 1667  void MainWindow::on_sample_treeview_butt
1667      }      }
1668  }  }
1669    
1670  void MainWindow::on_action_add_instrument() {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1671      static int __instrument_indexer = 0;      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1672      if (!file) return;          Gtk::Menu* script_popup =
1673      gig::Instrument* instrument = file->AddInstrument();              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1674      __instrument_indexer++;          // update enabled/disabled state of sample popup items
1675      instrument->pInfo->Name =          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1676          "Unnamed Instrument " + ToString(__instrument_indexer);          Gtk::TreeModel::iterator it = sel->get_selected();
1677            bool group_selected  = false;
1678            bool script_selected = false;
1679            if (it) {
1680                Gtk::TreeModel::Row row = *it;
1681                group_selected  = row[m_ScriptsModel.m_col_group];
1682                script_selected = row[m_ScriptsModel.m_col_script];
1683            }
1684            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1685                set_sensitive(group_selected || script_selected);
1686            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1687                set_sensitive(file);
1688            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1689                set_sensitive(script_selected);    
1690            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1691                set_sensitive(group_selected || script_selected);
1692            // show sample popup
1693            script_popup->popup(button->button, button->time);
1694        }
1695    }
1696    
1697    Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1698        const Glib::ustring& name, int position) {
1699    
1700        Gtk::RadioMenuItem::Group instrument_group;
1701        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1702        if (!children.empty()) {
1703            instrument_group =
1704                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1705        }
1706        Gtk::RadioMenuItem* item =
1707            new Gtk::RadioMenuItem(instrument_group, name);
1708        if (position < 0) {
1709            instrument_menu->append(*item);
1710        } else {
1711            instrument_menu->insert(*item, position);
1712        }
1713        item->show();
1714        item->signal_activate().connect(
1715            sigc::bind(
1716                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1717                item));
1718        return item;
1719    }
1720    
1721    void MainWindow::remove_instrument_from_menu(int index) {
1722        const std::vector<Gtk::Widget*> children =
1723            instrument_menu->get_children();
1724        Gtk::Widget* child = children[index];
1725        instrument_menu->remove(*child);
1726        delete child;
1727    }
1728    
1729    void MainWindow::add_instrument(gig::Instrument* instrument) {
1730        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1731    
1732      // update instrument tree view      // update instrument tree view
1733        instrument_name_connection.block();
1734      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1735      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1736      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1737      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1738        instrument_name_connection.unblock();
1739    
1740        add_instrument_to_menu(name);
1741    
1742        m_TreeView.get_selection()->select(iterInstr);
1743    
1744      file_changed();      file_changed();
1745  }  }
1746    
1747    void MainWindow::on_action_add_instrument() {
1748        static int __instrument_indexer = 0;
1749        if (!file) return;
1750        gig::Instrument* instrument = file->AddInstrument();
1751        __instrument_indexer++;
1752        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1753                                                ToString(__instrument_indexer));
1754    
1755        add_instrument(instrument);
1756    }
1757    
1758    void MainWindow::on_action_duplicate_instrument() {
1759        if (!file) return;
1760    
1761        // retrieve the currently selected instrument
1762        // (being the original instrument to be duplicated)
1763        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1764        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1765        if (!itSelection) return;
1766        Gtk::TreeModel::Row row = *itSelection;
1767        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1768        if (!instrOrig) return;
1769    
1770        // duplicate the orginal instrument
1771        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1772        instrNew->pInfo->Name =
1773            instrOrig->pInfo->Name +
1774            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1775    
1776        add_instrument(instrNew);
1777    }
1778    
1779  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1780      if (!file) return;      if (!file) return;
1781      if (file_is_shared) {      if (file_is_shared) {
# Line 1110  void MainWindow::on_action_remove_instru Line 1795  void MainWindow::on_action_remove_instru
1795          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1796          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1797          try {          try {
1798                Gtk::TreePath path(it);
1799                int index = path[0];
1800    
1801              // remove instrument from the gig file              // remove instrument from the gig file
1802              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1803              file_changed();              file_changed();
1804    
1805                remove_instrument_from_menu(index);
1806    
1807                // remove row from instruments tree view
1808                m_refTreeModel->erase(it);
1809    
1810    #if GTKMM_MAJOR_VERSION < 3
1811                // select another instrument (in gtk3 this is done
1812                // automatically)
1813                if (!m_refTreeModel->children().empty()) {
1814                    if (index == m_refTreeModel->children().size()) {
1815                        index--;
1816                    }
1817                    m_TreeView.get_selection()->select(
1818                        Gtk::TreePath(ToString(index)));
1819                }
1820    #endif
1821                instr_props_set_instrument();
1822                instr = get_instrument();
1823                if (instr) {
1824                    midiRules.set_instrument(instr);
1825                } else {
1826                    midiRules.hide();
1827                }
1828          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1829              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1830              msg.run();              msg.run();
# Line 1125  void MainWindow::on_action_remove_instru Line 1835  void MainWindow::on_action_remove_instru
1835  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
1836      //TODO: show a dialog where the selected sample's properties can be edited      //TODO: show a dialog where the selected sample's properties can be edited
1837      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
1838          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
1839      );      );
1840      msg.run();      msg.run();
1841  }  }
1842    
1843    void MainWindow::on_action_add_script_group() {
1844        static int __script_indexer = 0;
1845        if (!file) return;
1846        gig::ScriptGroup* group = file->AddScriptGroup();
1847        group->Name = gig_from_utf8(_("Unnamed Group"));
1848        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1849        __script_indexer++;
1850        // update sample tree view
1851        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1852        Gtk::TreeModel::Row rowGroup = *iterGroup;
1853        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1854        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1855        rowGroup[m_ScriptsModel.m_col_group] = group;
1856        file_changed();
1857    }
1858    
1859    void MainWindow::on_action_add_script() {
1860        if (!file) return;
1861        // get selected group
1862        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1863        Gtk::TreeModel::iterator it = sel->get_selected();
1864        if (!it) return;
1865        Gtk::TreeModel::Row row = *it;
1866        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1867        if (!group) { // not a group, but a script is selected (probably)
1868            gig::Script* script = row[m_ScriptsModel.m_col_script];
1869            if (!script) return;
1870            it = row.parent(); // resolve parent (that is the script's group)
1871            if (!it) return;
1872            row = *it;
1873            group = row[m_ScriptsModel.m_col_group];
1874            if (!group) return;
1875        }
1876    
1877        // add a new script to the .gig file
1878        gig::Script* script = group->AddScript();    
1879        Glib::ustring name = _("Unnamed Script");
1880        script->Name = gig_from_utf8(name);
1881    
1882        // add script to the tree view
1883        Gtk::TreeModel::iterator iterScript =
1884            m_refScriptsTreeModel->append(row.children());
1885        Gtk::TreeModel::Row rowScript = *iterScript;
1886        rowScript[m_ScriptsModel.m_col_name] = name;
1887        rowScript[m_ScriptsModel.m_col_script] = script;
1888        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1889    
1890        // unfold group of new script item in treeview
1891        Gtk::TreeModel::Path path(iterScript);
1892        m_TreeViewScripts.expand_to_path(path);
1893    }
1894    
1895    void MainWindow::on_action_edit_script() {
1896        if (!file) return;
1897        // get selected script
1898        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1899        Gtk::TreeModel::iterator it = sel->get_selected();
1900        if (!it) return;
1901        Gtk::TreeModel::Row row = *it;
1902        gig::Script* script = row[m_ScriptsModel.m_col_script];
1903        if (!script) return;
1904    
1905        ScriptEditor* editor = new ScriptEditor;
1906        editor->setScript(script);
1907        //editor->reparent(*this);
1908        editor->show();
1909    }
1910    
1911    void MainWindow::on_action_remove_script() {
1912        if (!file) return;
1913        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1914        Gtk::TreeModel::iterator it = sel->get_selected();
1915        if (it) {
1916            Gtk::TreeModel::Row row = *it;
1917            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1918            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1919            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1920            try {
1921                // remove script group or script from the gig file
1922                if (group) {
1923                    // notify everybody that we're going to remove these samples
1924    //TODO:         scripts_to_be_removed_signal.emit(members);
1925                    // delete the group in the .gig file including the
1926                    // samples that belong to the group
1927                    file->DeleteScriptGroup(group);
1928                    // notify that we're done with removal
1929    //TODO:         scripts_removed_signal.emit();
1930                    file_changed();
1931                } else if (script) {
1932                    // notify everybody that we're going to remove this sample
1933    //TODO:         std::list<gig::Script*> lscripts;
1934    //TODO:         lscripts.push_back(script);
1935    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
1936                    // remove sample from the .gig file
1937                    script->GetGroup()->DeleteScript(script);
1938                    // notify that we're done with removal
1939    //TODO:         scripts_removed_signal.emit();
1940                    dimreg_changed();
1941                    file_changed();
1942                }
1943                // remove respective row(s) from samples tree view
1944                m_refScriptsTreeModel->erase(it);
1945            } catch (RIFF::Exception e) {
1946                // pretend we're done with removal (i.e. to avoid dead locks)
1947    //TODO:     scripts_removed_signal.emit();
1948                // show error message
1949                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1950                msg.run();
1951            }
1952        }
1953    }
1954    
1955  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
1956      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1957      if (!file) return;      if (!file) return;
1958      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1959      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
1960      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1961      __sample_indexer++;      __sample_indexer++;
1962      // update sample tree view      // update sample tree view
1963      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1964      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1965      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1966      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1967      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1968      file_changed();      file_changed();
# Line 1168  void MainWindow::on_action_add_sample() Line 1990  void MainWindow::on_action_add_sample()
1990      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1991      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1992      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1993      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1994        // matches all file types supported by libsndfile
1995    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1996        Gtk::FileFilter soundfilter;
1997    #else
1998        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1999    #endif
2000      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
2001          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
2002          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1176  void MainWindow::on_action_add_sample() Line 2004  void MainWindow::on_action_add_sample()
2004          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
2005          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
2006      };      };
2007        const char* soundfiles = _("Sound Files");
2008        const char* allfiles = _("All Files");
2009    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2010      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
2011          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
2012      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
2013      Gtk::FileFilter allpassfilter; // matches every file  
2014        // matches every file
2015        Gtk::FileFilter allpassfilter;
2016      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
2017      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
2018    #else
2019        for (int i = 0; supportedFileTypes[i]; i++)
2020            soundfilter->add_pattern(supportedFileTypes[i]);
2021        soundfilter->set_name(soundfiles);
2022    
2023        // matches every file
2024        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
2025        allpassfilter->add_pattern("*.*");
2026        allpassfilter->set_name(allfiles);
2027    #endif
2028      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
2029      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
2030        if (current_sample_dir != "") {
2031            dialog.set_current_folder(current_sample_dir);
2032        }
2033      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2034            current_sample_dir = dialog.get_current_folder();
2035          Glib::ustring error_files;          Glib::ustring error_files;
2036          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
2037          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
2038               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
2039              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
2040              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1195  void MainWindow::on_action_add_sample() Line 2042  void MainWindow::on_action_add_sample()
2042              info.format = 0;              info.format = 0;
2043              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
2044              try {              try {
2045                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
2046                  int bitdepth;                  int bitdepth;
2047                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2048                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1211  void MainWindow::on_action_add_sample() Line 2058  void MainWindow::on_action_add_sample()
2058                          break;                          break;
2059                      default:                      default:
2060                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2061                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2062                  }                  }
2063                  // add a new sample to the .gig file                  // add a new sample to the .gig file
2064                  gig::Sample* sample = file->AddSample();                  gig::Sample* sample = file->AddSample();
# Line 1224  void MainWindow::on_action_add_sample() Line 2071  void MainWindow::on_action_add_sample()
2071                          break;                          break;
2072                      }                      }
2073                  }                  }
2074                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
2075                  sample->Channels = info.channels;                  sample->Channels = info.channels;
2076                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
2077                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1238  void MainWindow::on_action_add_sample() Line 2085  void MainWindow::on_action_add_sample()
2085                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
2086                  {                  {
2087                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
2088                        sample->FineTune      = instrument.detune;
2089    
 #if HAVE_SF_INSTRUMENT_LOOPS  
2090                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
2091                          sample->Loops = 1;                          sample->Loops = 1;
2092    
# Line 1259  void MainWindow::on_action_add_sample() Line 2106  void MainWindow::on_action_add_sample()
2106                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
2107                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
2108                      }                      }
 #endif  
2109                  }                  }
2110    
2111                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1277  void MainWindow::on_action_add_sample() Line 2123  void MainWindow::on_action_add_sample()
2123                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
2124                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
2125                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
2126                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
2127                        gig_to_utf8(sample->pInfo->Name);
2128                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
2129                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
2130                  // close sound file                  // close sound file
2131                  sf_close(hFile);                  sf_close(hFile);
2132                  file_changed();                  file_changed();
2133              } 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)
2134                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2135                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
2136              }              }
2137          }          }
2138          // 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
2139          if (error_files.size()) {          if (!error_files.empty()) {
2140              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;
2141              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2142              msg.run();              msg.run();
# Line 1297  void MainWindow::on_action_add_sample() Line 2144  void MainWindow::on_action_add_sample()
2144      }      }
2145  }  }
2146    
2147    void MainWindow::on_action_replace_all_samples_in_all_groups()
2148    {
2149        if (!file) return;
2150        Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
2151                                      Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
2152        const char* str =
2153            _("This is a very specific function. It tries to replace all samples "
2154              "in the current gig file by samples located in the chosen "
2155              "directory.\n\n"
2156              "It works like this: For each sample in the gig file, it tries to "
2157              "find a sample file in the selected directory with the same name as "
2158              "the sample in the gig file. Optionally, you can add a filename "
2159              "extension below, which will be added to the filename expected to be "
2160              "found. That is, assume you have a gig file with a sample called "
2161              "'Snare', if you enter '.wav' below (like it's done by default), it "
2162              "expects to find a sample file called 'Snare.wav' and will replace "
2163              "the sample in the gig file accordingly. If you don't need an "
2164              "extension, blank the field below. Any gig sample where no "
2165              "appropriate sample file could be found will be reported and left "
2166              "untouched.\n");
2167    #if GTKMM_MAJOR_VERSION < 3
2168        view::WrapLabel description(str);
2169    #else
2170        Gtk::Label description(str);
2171        description.set_line_wrap();
2172    #endif
2173        Gtk::HBox entryArea;
2174        Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
2175        Gtk::Entry postfixEntryBox;
2176        postfixEntryBox.set_text(".wav");
2177        entryArea.pack_start(entryLabel);
2178        entryArea.pack_start(postfixEntryBox);
2179        dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
2180        dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2181        description.show();
2182        entryArea.show_all();
2183        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2184        dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2185        dialog.set_select_multiple(false);
2186        if (current_sample_dir != "") {
2187            dialog.set_current_folder(current_sample_dir);
2188        }
2189        if (dialog.run() == Gtk::RESPONSE_OK)
2190        {
2191            current_sample_dir = dialog.get_current_folder();
2192            Glib::ustring error_files;
2193            std::string folder = dialog.get_filename();
2194            for (gig::Sample* sample = file->GetFirstSample();
2195                 sample; sample = file->GetNextSample())
2196            {
2197                std::string filename =
2198                    folder + G_DIR_SEPARATOR_S +
2199                    Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2200                                             postfixEntryBox.get_text());
2201                SF_INFO info;
2202                info.format = 0;
2203                SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
2204                try
2205                {
2206                    if (!hFile) throw std::string(_("could not open file"));
2207                    int bitdepth;
2208                    switch (info.format & 0xff) {
2209                        case SF_FORMAT_PCM_S8:
2210                        case SF_FORMAT_PCM_16:
2211                        case SF_FORMAT_PCM_U8:
2212                            bitdepth = 16;
2213                            break;
2214                        case SF_FORMAT_PCM_24:
2215                        case SF_FORMAT_PCM_32:
2216                        case SF_FORMAT_FLOAT:
2217                        case SF_FORMAT_DOUBLE:
2218                            bitdepth = 24;
2219                            break;
2220                        default:
2221                            sf_close(hFile);
2222                            throw std::string(_("format not supported"));
2223                    }
2224                    SampleImportItem sched_item;
2225                    sched_item.gig_sample  = sample;
2226                    sched_item.sample_path = filename;
2227                    m_SampleImportQueue.push_back(sched_item);
2228                    sf_close(hFile);
2229                    file_changed();
2230                }
2231                catch (std::string what)
2232                {
2233                    if (!error_files.empty()) error_files += "\n";
2234                    error_files += Glib::filename_to_utf8(filename) +
2235                        " (" + what + ")";
2236                }
2237            }
2238            // show error message box when some file(s) could not be opened / added
2239            if (!error_files.empty()) {
2240                Glib::ustring txt =
2241                    _("Could not replace the following sample(s):\n") + error_files;
2242                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2243                msg.run();
2244            }
2245        }
2246    }
2247    
2248  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2249      if (!file) return;      if (!file) return;
2250      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
# Line 1309  void MainWindow::on_action_remove_sample Line 2257  void MainWindow::on_action_remove_sample
2257          try {          try {
2258              // remove group or sample from the gig file              // remove group or sample from the gig file
2259              if (group) {              if (group) {
2260                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2261                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2262                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2263                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1373  void MainWindow::on_action_remove_sample Line 2321  void MainWindow::on_action_remove_sample
2321      }      }
2322  }  }
2323    
2324    // see comment on on_sample_treeview_drag_begin()
2325    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2326    {
2327        first_call_to_drag_data_get = true;
2328    }
2329    
2330    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2331                                                       Gtk::SelectionData& selection_data, guint, guint)
2332    {
2333        if (!first_call_to_drag_data_get) return;
2334        first_call_to_drag_data_get = false;
2335    
2336        // get selected script
2337        gig::Script* script = NULL;
2338        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2339        Gtk::TreeModel::iterator it = sel->get_selected();
2340        if (it) {
2341            Gtk::TreeModel::Row row = *it;
2342            script = row[m_ScriptsModel.m_col_script];
2343        }
2344        // pass the gig::Script as pointer
2345        selection_data.set(selection_data.get_target(), 0/*unused*/,
2346                           (const guchar*)&script,
2347                           sizeof(script)/*length of data in bytes*/);
2348    }
2349    
2350  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2351  // 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
2352  // 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 1431  void MainWindow::on_sample_label_drop_dr Line 2405  void MainWindow::on_sample_label_drop_dr
2405          bool channels_changed = false;          bool channels_changed = false;
2406          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2407              // remove the samplechannel dimension              // remove the samplechannel dimension
2408    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2409              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2410              channels_changed = true;              channels_changed = true;
2411              region_changed();              region_changed();
2412    */
2413          }          }
2414          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2415                sample,
2416                is_copy_samples_unity_note_enabled(),
2417                is_copy_samples_fine_tune_enabled(),
2418                is_copy_samples_loop_enabled()
2419            );
2420    
2421          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2422              // add samplechannel dimension              // add samplechannel dimension
# Line 1463  void MainWindow::on_sample_label_drop_dr Line 2444  void MainWindow::on_sample_label_drop_dr
2444          // notify we're done with altering          // notify we're done with altering
2445          region_changed_signal.emit(region);          region_changed_signal.emit(region);
2446    
2447            file_changed();
2448    
2449          return;          return;
2450      }      }
2451      // drop failed      // drop failed
# Line 1476  void MainWindow::sample_name_changed(con Line 2459  void MainWindow::sample_name_changed(con
2459      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2460      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2461      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2462        gig::String gigname(gig_from_utf8(name));
2463      if (group) {      if (group) {
2464          if (group->Name != name) {          if (group->Name != gigname) {
2465              group->Name = name;              group->Name = gigname;
2466              printf("group name changed\n");              printf("group name changed\n");
2467              file_changed();              file_changed();
2468          }          }
2469      } else if (sample) {      } else if (sample) {
2470          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2471              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2472              printf("sample name changed\n");              printf("sample name changed\n");
2473              file_changed();              file_changed();
2474          }          }
2475      }      }
2476  }  }
2477    
2478    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2479                                         const Gtk::TreeModel::iterator& iter) {
2480        if (!iter) return;
2481        Gtk::TreeModel::Row row = *iter;
2482        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2483        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2484        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2485        gig::String gigname(gig_from_utf8(name));
2486        if (group) {
2487            if (group->Name != gigname) {
2488                group->Name = gigname;
2489                printf("script group name changed\n");
2490                file_changed();
2491            }
2492        } else if (script) {
2493            if (script->Name != gigname) {
2494                script->Name = gigname;
2495                printf("script name changed\n");
2496                file_changed();
2497            }
2498        }
2499    }
2500    
2501  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2502                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2503      if (!iter) return;      if (!iter) return;
2504      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2505      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2506    
2507        // change name in instrument menu
2508        int index = path[0];
2509        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2510        if (index < children.size()) {
2511    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2512            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2513    #else
2514            remove_instrument_from_menu(index);
2515            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2516            item->set_active();
2517    #endif
2518        }
2519    
2520        // change name in gig
2521      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2522      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2523          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2524            instrument->pInfo->Name = gigname;
2525    
2526            // change name in the instrument properties window
2527            if (instrumentProps.get_instrument() == instrument) {
2528                instrumentProps.update_name();
2529            }
2530    
2531          file_changed();          file_changed();
2532      }      }
2533  }  }
2534    
2535    void MainWindow::on_action_combine_instruments() {
2536        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2537        d->show_all();
2538        d->resize(500, 400);
2539        d->run();
2540        if (d->fileWasChanged()) {
2541            // update GUI with new instrument just created
2542            add_instrument(d->newCombinedInstrument());
2543        }
2544        delete d;
2545    }
2546    
2547    void MainWindow::on_action_view_references() {
2548        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2549        Gtk::TreeModel::iterator it = sel->get_selected();
2550        if (!it) return;
2551        Gtk::TreeModel::Row row = *it;
2552        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2553        if (!sample) return;
2554    
2555        ReferencesView* d = new ReferencesView(*this);
2556        d->setSample(sample);
2557        d->show_all();
2558        d->resize(500, 400);
2559        d->run();
2560        delete d;
2561    }
2562    
2563    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2564        struct _Source {
2565            std::vector<RIFF::File*> riffs;
2566            std::vector<gig::File*> gigs;
2567            
2568            ~_Source() {
2569                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2570                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2571                riffs.clear();
2572                gigs.clear();
2573            }
2574        } sources;
2575    
2576        if (filenames.empty())
2577            throw RIFF::Exception(_("No files selected, so nothing done."));
2578    
2579        // first open all input files (to avoid output file corruption)
2580        int i;
2581        try {
2582            for (i = 0; i < filenames.size(); ++i) {
2583                const std::string& filename = filenames[i];
2584                printf("opening file=%s\n", filename.c_str());
2585    
2586                RIFF::File* riff = new RIFF::File(filename);
2587                sources.riffs.push_back(riff);
2588    
2589                gig::File* gig = new gig::File(riff);
2590                sources.gigs.push_back(gig);
2591            }
2592        } catch (RIFF::Exception e) {
2593            throw RIFF::Exception(
2594                _("Error occurred while opening '") +
2595                filenames[i] +
2596                "': " +
2597                e.Message
2598            );
2599        } catch (...) {
2600            throw RIFF::Exception(
2601                _("Unknown exception occurred while opening '") +
2602                filenames[i] + "'"
2603            );
2604        }
2605    
2606        // now merge the opened .gig files to the main .gig file currently being
2607        // open in gigedit
2608        try {
2609            for (i = 0; i < filenames.size(); ++i) {
2610                const std::string& filename = filenames[i];
2611                printf("merging file=%s\n", filename.c_str());
2612                assert(i < sources.gigs.size());
2613    
2614                this->file->AddContentOf(sources.gigs[i]);
2615            }
2616        } catch (RIFF::Exception e) {
2617            throw RIFF::Exception(
2618                _("Error occurred while merging '") +
2619                filenames[i] +
2620                "': " +
2621                e.Message
2622            );
2623        } catch (...) {
2624            throw RIFF::Exception(
2625                _("Unknown exception occurred while merging '") +
2626                filenames[i] + "'"
2627            );
2628        }
2629    
2630        // Note: requires that this file already has a filename !
2631        this->file->Save();
2632    }
2633    
2634    void MainWindow::on_action_merge_files() {
2635        if (this->file->GetFileName().empty()) {
2636            Glib::ustring txt = _(
2637                "You seem to have a new .gig file open that has not been saved "
2638                "yet. You must save it somewhere before starting to merge it with "
2639                "other .gig files though, because during the merge operation the "
2640                "other files' sample data must be written on file level to the "
2641                "target .gig file."
2642            );
2643            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2644            msg.run();
2645            return;
2646        }
2647    
2648        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2649        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2650        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2651        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2652    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2653        Gtk::FileFilter filter;
2654        filter.add_pattern("*.gig");
2655    #else
2656        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2657        filter->add_pattern("*.gig");
2658    #endif
2659        dialog.set_filter(filter);
2660        if (current_gig_dir != "") {
2661            dialog.set_current_folder(current_gig_dir);
2662        }
2663        dialog.set_select_multiple(true);
2664    
2665        // show warning in the file picker dialog
2666        Gtk::HBox descriptionArea;
2667        descriptionArea.set_spacing(15);
2668        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2669        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2670    #if GTKMM_MAJOR_VERSION < 3
2671        view::WrapLabel description;
2672    #else
2673        Gtk::Label description;
2674        description.set_line_wrap();
2675    #endif
2676        description.set_markup(_(
2677            "\nSelect at least one .gig file that shall be merged to the .gig file "
2678            "currently being open in gigedit.\n\n"
2679            "<b>Please Note:</b> Merging with other files will modify your "
2680            "currently open .gig file on file level! And be aware that the current "
2681            "merge algorithm does not detect duplicate samples yet. So if you are "
2682            "merging files which are using equivalent sample data, those "
2683            "equivalent samples will currently be treated as separate samples and "
2684            "will accordingly be stored separately in the target .gig file!"
2685        ));
2686        descriptionArea.pack_start(description);
2687        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2688        descriptionArea.show_all();
2689    
2690        if (dialog.run() == Gtk::RESPONSE_OK) {
2691            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2692            std::vector<std::string> filenames = dialog.get_filenames();
2693    
2694            // merge the selected files to the currently open .gig file
2695            try {
2696                mergeFiles(filenames);
2697            } catch (RIFF::Exception e) {
2698                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2699                msg.run();
2700            }
2701    
2702            // update GUI
2703            __refreshEntireGUI();        
2704        }
2705    }
2706    
2707    void MainWindow::set_file_is_shared(bool b) {
2708        this->file_is_shared = b;
2709    
2710        if (file_is_shared) {
2711            m_AttachedStateLabel.set_label(_("live-mode"));
2712            m_AttachedStateImage.set(
2713                Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
2714            );
2715        } else {
2716            m_AttachedStateLabel.set_label(_("stand-alone"));
2717            m_AttachedStateImage.set(
2718                Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
2719            );
2720        }
2721    }
2722    
2723    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2724        if (!sample) return;
2725        sample_ref_count[sample] += offset;
2726        const int refcount = sample_ref_count[sample];
2727    
2728        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2729        for (int g = 0; g < model->children().size(); ++g) {
2730            Gtk::TreeModel::Row rowGroup = model->children()[g];
2731            for (int s = 0; s < rowGroup.children().size(); ++s) {
2732                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2733                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2734                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2735                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
2736            }
2737        }
2738    }
2739    
2740    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2741        on_sample_ref_count_incremented(oldSample, -1);
2742        on_sample_ref_count_incremented(newSample, +1);
2743    }
2744    
2745    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2746        // just in case a new sample is added later with exactly the same memory
2747        // address, which would lead to incorrect refcount if not deleted here
2748        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2749             it != samples.end(); it != samples.end())
2750        {
2751            sample_ref_count.erase(*it);
2752        }
2753    }
2754    
2755  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2756      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2757  }  }
# Line 1527  sigc::signal<void, gig::Region*>& MainWi Line 2776  sigc::signal<void, gig::Region*>& MainWi
2776      return region_changed_signal;      return region_changed_signal;
2777  }  }
2778    
2779    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2780        return sample_changed_signal;
2781    }
2782    
2783  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
2784      return sample_ref_changed_signal;      return sample_ref_changed_signal;
2785  }  }
# Line 1538  sigc::signal<void, gig::DimensionRegion* Line 2791  sigc::signal<void, gig::DimensionRegion*
2791  sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {  sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
2792      return dimreg_changed_signal;      return dimreg_changed_signal;
2793  }  }
2794    
2795    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() {
2796        return note_on_signal;
2797    }
2798    
2799    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() {
2800        return note_off_signal;
2801    }
2802    
2803    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() {
2804        return m_RegionChooser.signal_keyboard_key_hit();
2805    }
2806    
2807    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
2808        return m_RegionChooser.signal_keyboard_key_released();
2809    }

Legend:
Removed from v.1382  
changed lines
  Added in v.2624

  ViewVC Help
Powered by ViewVC