/[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 1959 by persson, Fri Jul 31 10:15:27 2009 UTC revision 2621 by schoenebeck, Wed Jun 11 16:46:27 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2009 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 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmm/convert.h>
24    #include <glibmm/dispatcher.h>
25    #include <glibmm/miscutils.h>
26    #include <glibmm/stringutils.h>
27    #include <gtkmm/aboutdialog.h>
28  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
29  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34    #if GTKMM_MAJOR_VERSION < 3
35  #include "wrapLabel.hh"  #include "wrapLabel.hh"
   
 #include "global.h"  
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
 #define ABOUT_DIALOG  
 #include <gtkmm/aboutdialog.h>  
36  #endif  #endif
37    
38  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #include "global.h"
39  namespace Glib {  #include "compat.h"
 Glib::ustring filename_display_basename(const std::string& filename)  
 {  
     gchar* gstr = g_path_get_basename(filename.c_str());  
     Glib::ustring str(gstr);  
     g_free(gstr);  
     return Glib::filename_to_utf8(str);  
 }  
 }  
 #endif  
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46    #include "Settings.h"
47    #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49    #include "scriptslots.h"
50  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
51  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
52    
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
   
 Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }  
   
 void Table::add(BoolEntry& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(BoolEntryPlus6& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(LabelWidget& prop)  
 {  
     attach(prop.label, 1, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     attach(prop.widget, 2, 3, rowno, rowno + 1,  
            Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
53    
54  MainWindow::MainWindow() :  MainWindow::MainWindow() :
55      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
# Line 99  MainWindow::MainWindow() : Line 64  MainWindow::MainWindow() :
64      add(m_VBox);      add(m_VBox);
65    
66      // Handle selection      // Handle selection
67      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
68          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
69    
70      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 116  MainWindow::MainWindow() : Line 80  MainWindow::MainWindow() :
80      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
81      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
82    
83        m_ScrolledWindowScripts.add(m_TreeViewScripts);
84        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
85    
86    
87      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
88    
# Line 129  MainWindow::MainWindow() : Line 96  MainWindow::MainWindow() :
96      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
97      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
98    
99        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
100        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."));
101        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."));
102        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)."));
103    
104      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
105      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
106        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
107    
108      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
109    
# Line 163  MainWindow::MainWindow() : Line 134  MainWindow::MainWindow() :
134                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
135                       sigc::mem_fun(                       sigc::mem_fun(
136                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
137        actionGroup->add(Gtk::Action::create("MidiRules",
138                                             _("_Midi Rules...")),
139                         sigc::mem_fun(
140                             *this, &MainWindow::show_midi_rules));
141        actionGroup->add(Gtk::Action::create("ScriptSlots",
142                                             _("_Script Slots...")),
143                         sigc::mem_fun(
144                             *this, &MainWindow::show_script_slots));
145      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
146                       sigc::mem_fun(                       sigc::mem_fun(
147                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
148      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
149    
150      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
151        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
152    
153      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
154            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
155        toggle_action->set_active(true);
156        actionGroup->add(toggle_action);
157    
158        toggle_action =
159            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
160        toggle_action->set_active(true);
161        actionGroup->add(toggle_action);
162    
163        toggle_action =
164            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
165        toggle_action->set_active(true);
166        actionGroup->add(toggle_action);
167    
168    
169        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
170        toggle_action =
171          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
172      toggle_action->set_active(true);      toggle_action->set_active(true);
173      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 179  MainWindow::MainWindow() : Line 177  MainWindow::MainWindow() :
177      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
178      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
179                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
180      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
181                       sigc::mem_fun(                       sigc::mem_fun(
182                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
183      actionGroup->add(      actionGroup->add(
184          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
185          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
186      );      );
187      actionGroup->add(      actionGroup->add(
188            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
189            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
190        );
191        actionGroup->add(
192          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
193          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
194      );      );
195    
196    
197        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
198        
199        toggle_action =
200            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
201        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
202        actionGroup->add(
203            toggle_action,
204            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
205        );
206    
207    
208        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
209    
210        actionGroup->add(
211            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
212            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
213        );
214    
215        actionGroup->add(
216            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
217            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
218        );
219    
220    
221      // sample right-click popup actions      // sample right-click popup actions
222      actionGroup->add(      actionGroup->add(
223          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 215  MainWindow::MainWindow() : Line 240  MainWindow::MainWindow() :
240                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
241          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
242      );      );
243        
244        // script right-click popup actions
245        actionGroup->add(
246            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
247            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
248        );
249        actionGroup->add(
250            Gtk::Action::create("AddScript", _("Add _Script")),
251            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
252        );
253        actionGroup->add(
254            Gtk::Action::create("EditScript", _("_Edit Script...")),
255            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
256        );
257        actionGroup->add(
258            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
259            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
260        );
261    
262      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
263      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 234  MainWindow::MainWindow() : Line 277  MainWindow::MainWindow() :
277          "      <separator/>"          "      <separator/>"
278          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
279          "    </menu>"          "    </menu>"
280            "    <menu action='MenuEdit'>"
281            "      <menuitem action='CopySampleUnity'/>"
282            "      <menuitem action='CopySampleTune'/>"
283            "      <menuitem action='CopySampleLoop'/>"
284            "    </menu>"
285          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
286          "    </menu>"          "    </menu>"
287          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
288          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
289          "    </menu>"          "    </menu>"
290  #ifdef ABOUT_DIALOG          "    <menu action='MenuTools'>"
291            "      <menuitem action='CombineInstruments'/>"
292            "      <menuitem action='MergeFiles'/>"
293            "    </menu>"
294            "    <menu action='MenuSettings'>"
295            "      <menuitem action='WarnUserOnExtensions'/>"
296            "    </menu>"
297          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
298          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
299          "    </menu>"          "    </menu>"
 #endif  
300          "  </menubar>"          "  </menubar>"
301          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
302          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
303            "    <menuitem action='MidiRules'/>"
304            "    <menuitem action='ScriptSlots'/>"
305          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
306            "    <menuitem action='DupInstrument'/>"
307          "    <separator/>"          "    <separator/>"
308          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
309          "  </popup>"          "  </popup>"
# Line 255  MainWindow::MainWindow() : Line 311  MainWindow::MainWindow() :
311          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
312          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
313          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
314          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
315          "    <separator/>"          "    <separator/>"
316          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
317          "  </popup>"          "  </popup>"
318            "  <popup name='ScriptPopupMenu'>"
319            "    <menuitem action='AddScriptGroup'/>"
320            "    <menuitem action='AddScript'/>"
321            "    <menuitem action='EditScript'/>"
322            "    <separator/>"
323            "    <menuitem action='RemoveScript'/>"
324            "  </popup>"
325          "</ui>";          "</ui>";
326      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
327    
328      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
329        
330        // Set tooltips for menu items (for some reason, setting a tooltip on the
331        // respective Gtk::Action objects above will simply be ignored, no matter
332        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
333        // Gtk::Action::create()).
334        {
335            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
336                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
337            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."));
338        }
339        {
340            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
341                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
342            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."));
343        }
344        {
345            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
346                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
347            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."));
348        }
349        {
350            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
351                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
352            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."));
353        }
354        {
355            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
356                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
357            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
358        }
359        {
360            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
361                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
362            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
363        }
364    
365    
366        instrument_menu = static_cast<Gtk::MenuItem*>(
367            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
368    
369      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
370      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 272  MainWindow::MainWindow() : Line 374  MainWindow::MainWindow() :
374      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
375      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
376    
377        set_file_is_shared(false);
378    
379      // Status Bar:      // Status Bar:
380      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
381      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 286  MainWindow::MainWindow() : Line 390  MainWindow::MainWindow() :
390      // Create the Tree model:      // Create the Tree model:
391      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
392      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
393      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
394        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
395          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
396      );      );
397    
# Line 297  MainWindow::MainWindow() : Line 402  MainWindow::MainWindow() :
402      // create samples treeview (including its data model)      // create samples treeview (including its data model)
403      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
404      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
405        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."));
406      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
407      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
408      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
409        {
410            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
411            Gtk::CellRendererText* cellrenderer =
412                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
413            column->add_attribute(
414                cellrenderer->property_foreground(), m_SamplesModel.m_color
415            );
416        }
417        {
418            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
419            Gtk::CellRendererText* cellrenderer =
420                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
421            column->add_attribute(
422                cellrenderer->property_foreground(), m_SamplesModel.m_color
423            );
424        }
425        m_TreeViewSamples.set_headers_visible(true);
426      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
427          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
428      );      );
# Line 307  MainWindow::MainWindow() : Line 430  MainWindow::MainWindow() :
430          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
431      );      );
432    
433        // create scripts treeview (including its data model)
434        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
435        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
436        m_TreeViewScripts.set_tooltip_text(_(
437            "Note: instrument scripts are a LinuxSampler extension of the gig "
438            "format. This feature will not work with the GigaStudio software!"
439        ));
440        // m_TreeViewScripts.set_reorderable();
441        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
442        m_TreeViewScripts.set_headers_visible(false);
443        m_TreeViewScripts.signal_button_press_event().connect_notify(
444            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
445        );
446        m_refScriptsTreeModel->signal_row_changed().connect(
447            sigc::mem_fun(*this, &MainWindow::script_name_changed)
448        );
449    
450        // establish drag&drop between scripts tree view and ScriptSlots window
451        std::vector<Gtk::TargetEntry> drag_target_gig_script;
452        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
453        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
454        m_TreeViewScripts.signal_drag_begin().connect(
455            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
456        );
457        m_TreeViewScripts.signal_drag_data_get().connect(
458            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
459        );
460    
461      // 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
462      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
463      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
464      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
465      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
466          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 327  MainWindow::MainWindow() : Line 478  MainWindow::MainWindow() :
478          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
479      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
480          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
481      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
482            sigc::mem_fun(*this, &MainWindow::file_changed));
483        propDialog.signal_changed().connect(
484          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
485      propDialog.signal_info_changed().connect(      midiRules.signal_changed().connect(
486          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
487    
488      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 338  MainWindow::MainWindow() : Line 491  MainWindow::MainWindow() :
491          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
492      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
493          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
494        sample_ref_changed_signal.connect(
495            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
496        );
497        samples_to_be_removed_signal.connect(
498            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
499        );
500    
501      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
502          sigc::hide(          sigc::hide(
# Line 374  MainWindow::MainWindow() : Line 533  MainWindow::MainWindow() :
533    
534      file = 0;      file = 0;
535      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
536    
537      show_all_children();      show_all_children();
538    
539      // start with a new gig file by default      // start with a new gig file by default
540      on_action_file_new();      on_action_file_new();
541    
542        // select 'Instruments' tab by default
543        // (gtk allows this only if the tab childs are visible, thats why it's here)
544        m_TreeViewNotebook.set_current_page(1);
545  }  }
546    
547  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 405  void MainWindow::region_changed() Line 567  void MainWindow::region_changed()
567  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
568  {  {
569      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
570      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
571            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
572      if (it) {      if (it) {
573          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
574          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 466  void MainWindow::dimreg_changed() Line 627  void MainWindow::dimreg_changed()
627    
628  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
629  {  {
630        // select item in instrument menu
631        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
632        if (it) {
633            Gtk::TreePath path(it);
634            int index = path[0];
635            const std::vector<Gtk::Widget*> children =
636                instrument_menu->get_children();
637            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
638        }
639    
640      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
641  }  }
642    
# Line 478  void loader_progress_callback(gig::progr Line 649  void loader_progress_callback(gig::progr
649  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
650  {  {
651      {      {
652          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
653          progress = fraction;          progress = fraction;
654      }      }
655      progress_dispatcher();      progress_dispatcher();
# Line 486  void Loader::progress_callback(float fra Line 657  void Loader::progress_callback(float fra
657    
658  void Loader::thread_function()  void Loader::thread_function()
659  {  {
660      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
661      printf("Start %s\n", filename);      printf("Start %s\n", filename);
662      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
663      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 500  void Loader::thread_function() Line 671  void Loader::thread_function()
671  }  }
672    
673  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
674      : thread(0), filename(filename)      : filename(filename), thread(0)
675  {  {
676  }  }
677    
678  void Loader::launch()  void Loader::launch()
679  {  {
680    #ifdef OLD_THREADS
681      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
682    #else
683        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
684    #endif
685      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
686  }  }
687    
# Line 514  float Loader::get_progress() Line 689  float Loader::get_progress()
689  {  {
690      float res;      float res;
691      {      {
692          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
693          res = progress;          res = progress;
694      }      }
695      return res;      return res;
# Line 540  LoadDialog::LoadDialog(const Glib::ustri Line 715  LoadDialog::LoadDialog(const Glib::ustri
715  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
716  // 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.
717  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();  
718      // forget all samples that ought to be imported      // forget all samples that ought to be imported
719      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
720      // clear the samples and instruments tree views      // clear the samples and instruments tree views
721      m_refTreeModel->clear();      m_refTreeModel->clear();
722      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
723        m_refScriptsTreeModel->clear();
724        // remove all entries from "Instrument" menu
725        while (!instrument_menu->get_children().empty()) {
726            remove_instrument_from_menu(0);
727        }
728      // free libgig's gig::File instance      // free libgig's gig::File instance
729      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
730      file = NULL;      file = NULL;
731      set_file_is_shared(false);      set_file_is_shared(false);
732  }  }
733    
734    void MainWindow::__refreshEntireGUI() {
735        // clear the samples and instruments tree views
736        m_refTreeModel->clear();
737        m_refSamplesTreeModel->clear();
738        m_refScriptsTreeModel->clear();
739        // remove all entries from "Instrument" menu
740        while (!instrument_menu->get_children().empty()) {
741            remove_instrument_from_menu(0);
742        }
743    
744        if (!this->file) return;
745    
746        load_gig(
747            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
748        );
749    }
750    
751  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
752  {  {
753      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 571  void MainWindow::on_action_file_new() Line 760  void MainWindow::on_action_file_new()
760      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
761      // already add one new instrument by default      // already add one new instrument by default
762      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
763      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
764      // update GUI with that new gig::File      // update GUI with that new gig::File
765      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
766  }  }
# Line 582  bool MainWindow::close_confirmation_dial Line 771  bool MainWindow::close_confirmation_dial
771                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
772      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
773      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
774      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  
775      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
776      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
777      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 598  bool MainWindow::close_confirmation_dial Line 785  bool MainWindow::close_confirmation_dial
785  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
786      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
787      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  
788      dialog.set_secondary_text(      dialog.set_secondary_text(
789          _("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 "
790            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
791            "load it.")            "load it."));
    );  
 #endif  
792      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
793      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
794      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 623  void MainWindow::on_action_file_open() Line 807  void MainWindow::on_action_file_open()
807      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
808      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
809      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
810    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
811      Gtk::FileFilter filter;      Gtk::FileFilter filter;
812      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
813    #else
814        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
815        filter->add_pattern("*.gig");
816    #endif
817      dialog.set_filter(filter);      dialog.set_filter(filter);
818      if (current_gig_dir != "") {      if (current_gig_dir != "") {
819          dialog.set_current_folder(current_gig_dir);          dialog.set_current_folder(current_gig_dir);
# Line 632  void MainWindow::on_action_file_open() Line 821  void MainWindow::on_action_file_open()
821      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
822          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
823          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
824          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
825          load_file(filename.c_str());          load_file(filename.c_str());
826          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
827      }      }
# Line 674  void MainWindow::on_loader_progress() Line 863  void MainWindow::on_loader_progress()
863  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
864  {  {
865      printf("Loader finished!\n");      printf("Loader finished!\n");
866      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
867      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
868      load_dialog->hide();      load_dialog->hide();
869  }  }
# Line 746  bool MainWindow::file_save_as() Line 935  bool MainWindow::file_save_as()
935      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
936      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
937      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  
938      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
939      // TODO: an overwrite dialog for gtkmm < 2.8  
940  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
941      Gtk::FileFilter filter;      Gtk::FileFilter filter;
942      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
943    #else
944        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
945        filter->add_pattern("*.gig");
946    #endif
947      dialog.set_filter(filter);      dialog.set_filter(filter);
948    
949      // set initial dir and filename of the Save As dialog      // set initial dir and filename of the Save As dialog
# Line 775  bool MainWindow::file_save_as() Line 966  bool MainWindow::file_save_as()
966      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
967      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
968      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
969    #if GTKMM_MAJOR_VERSION < 3
970      view::WrapLabel description;      view::WrapLabel description;
971    #else
972        Gtk::Label description;
973        description.set_line_wrap();
974    #endif
975      description.set_markup(      description.set_markup(
976          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
977            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 827  void MainWindow::__import_queued_samples Line 1023  void MainWindow::__import_queued_samples
1023          SF_INFO info;          SF_INFO info;
1024          info.format = 0;          info.format = 0;
1025          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
1026            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1027          try {          try {
1028              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
1029              // determine sample's bit depth              // determine sample's bit depth
# Line 896  void MainWindow::__import_queued_samples Line 1093  void MainWindow::__import_queued_samples
1093              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1094          } catch (std::string what) {          } catch (std::string what) {
1095              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1096              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1097              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1098              ++iter;              ++iter;
1099          }          }
1100      }      }
1101      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
1102      if (error_files.size()) {      if (!error_files.empty()) {
1103          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;
1104          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1105          msg.run();          msg.run();
# Line 915  void MainWindow::on_action_file_properti Line 1112  void MainWindow::on_action_file_properti
1112      propDialog.deiconify();      propDialog.deiconify();
1113  }  }
1114    
1115    void MainWindow::on_action_warn_user_on_extensions() {
1116        Settings::singleton()->warnUserOnExtensions =
1117            !Settings::singleton()->warnUserOnExtensions;
1118    }
1119    
1120  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1121  {  {
 #ifdef ABOUT_DIALOG  
1122      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
1123  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
1124      dialog.set_program_name("Gigedit");      dialog.set_program_name("Gigedit");
# Line 925  void MainWindow::on_action_help_about() Line 1126  void MainWindow::on_action_help_about()
1126      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1127  #endif  #endif
1128      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1129      dialog.set_copyright("Copyright (C) 2006-2009 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1130      dialog.set_comments(_(      const std::string sComment =
1131          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1132          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1133          "Please notice that this is still a very young instrument editor. "          _(
1134          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1135          "this application.\n"              "\n"
1136          "\n"              "Please notice that this is still a very young instrument editor. "
1137          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
1138      );              "this application.\n"
1139                "\n"
1140                "Please report bugs to: http://bugs.linuxsampler.org"
1141            );
1142        dialog.set_comments(sComment.c_str());
1143      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1144      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1145      dialog.run();      dialog.run();
 #endif  
1146  }  }
1147    
1148  PropDialog::PropDialog()  PropDialog::PropDialog()
1149      : table(2,1),      : eFileFormat(_("File Format")),
1150        eName(_("Name")),        eName(_("Name")),
1151        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1152        eComments(_("Comments")),        eComments(_("Comments")),
# Line 960  PropDialog::PropDialog() Line 1164  PropDialog::PropDialog()
1164        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1165        eSubject(_("Subject")),        eSubject(_("Subject")),
1166        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1167        update_model(0)        table(2, 1),
1168          m_file(NULL)
1169  {  {
1170      set_title(_("File Properties"));      set_title(_("File Properties"));
1171      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 982  PropDialog::PropDialog() Line 1187  PropDialog::PropDialog()
1187      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1188      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1189    
1190        table.add(eFileFormat);
1191      table.add(eName);      table.add(eName);
1192      table.add(eCreationDate);      table.add(eCreationDate);
1193      table.add(eComments);      table.add(eComments);
# Line 1008  PropDialog::PropDialog() Line 1214  PropDialog::PropDialog()
1214      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1215      buttonBox.show();      buttonBox.show();
1216      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1217      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1218      quitButton.grab_focus();      quitButton.grab_focus();
1219      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1220          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1221        eFileFormat.signal_value_changed().connect(
1222            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1223    
1224      quitButton.show();      quitButton.show();
1225      vbox.show();      vbox.show();
1226      show_all_children();      show_all_children();
1227  }  }
1228    
1229  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_file(gig::File* file)
1230  {  {
1231      this->info = info;      m_file = file;
1232      update_model++;  
1233      eName.set_value(info->Name);      // update file format version combo box
1234      eCreationDate.set_value(info->CreationDate);      const std::string sGiga = "Gigasampler/GigaStudio v";
1235      eComments.set_value(info->Comments);      const int major = file->pVersion->major;
1236      eProduct.set_value(info->Product);      std::vector<std::string> txts;
1237      eCopyright.set_value(info->Copyright);      std::vector<int> values;
1238      eArtists.set_value(info->Artists);      txts.push_back(sGiga + "2"); values.push_back(2);
1239      eGenre.set_value(info->Genre);      txts.push_back(sGiga + "3/v4"); values.push_back(3);
1240      eKeywords.set_value(info->Keywords);      if (major != 2 && major != 3) {
1241      eEngineer.set_value(info->Engineer);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
1242      eTechnician.set_value(info->Technician);      }
1243      eSoftware.set_value(info->Software);      std::vector<const char*> texts;
1244      eMedium.set_value(info->Medium);      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1245      eSource.set_value(info->Source);      texts.push_back(NULL); values.push_back(0);
1246      eSourceForm.set_value(info->SourceForm);      eFileFormat.set_choices(&texts[0], &values[0]);
1247      eCommissioned.set_value(info->Commissioned);      eFileFormat.set_value(major);
1248      eSubject.set_value(info->Subject);  }
1249      update_model--;  
1250    void PropDialog::onFileFormatChanged() {
1251        const int major = eFileFormat.get_value();
1252        if (m_file) m_file->pVersion->major = major;
1253  }  }
1254    
1255  sigc::signal<void>& PropDialog::signal_info_changed()  void PropDialog::set_info(DLS::Info* info)
1256  {  {
1257      return info_changed;      update(info);
1258  }  }
1259    
1260  void InstrumentProps::set_IsDrum(bool value)  
1261    void InstrumentProps::set_Name(const gig::String& name)
1262  {  {
1263      instrument->IsDrum = value;      m->pInfo->Name = name;
1264  }  }
1265    
1266  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1267  {  {
1268      instrument->MIDIBank = value;      update_model++;
1269        eName.set_value(m->pInfo->Name);
1270        update_model--;
1271  }  }
1272    
1273  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1274  {  {
1275      instrument->MIDIProgram = value;      m->IsDrum = value;
1276  }  }
1277    
1278  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1279  {  {
1280      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1281  }  }
1282    
1283  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1284  {  {
1285      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1286  }  }
1287    
1288  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1289      : table(2,1),      quitButton(Gtk::Stock::CLOSE),
1290        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1291        eName(_("Name")),      eName(_("Name")),
1292        eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
1293        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
1294        eMIDIProgram(_("MIDI program")),      eMIDIProgram(_("MIDI program")),
1295        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1296        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1297        eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
1298        eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
1299        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1300        ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
1301        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1302        eDimensionKeyRangeHigh(_("Keyswitching range high")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       update_model(0)  
1303  {  {
1304      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1305    
# Line 1105  InstrumentProps::InstrumentProps() Line 1312  InstrumentProps::InstrumentProps()
1312            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1313      );      );
1314    
1315        connect(eName, &InstrumentProps::set_Name);
1316      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1317      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1318      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1114  InstrumentProps::InstrumentProps() Line 1322  InstrumentProps::InstrumentProps()
1322      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1323      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1324      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1325      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1326              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1327      connect(eDimensionKeyRangeHigh,  
1328              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1329    
1330      table.set_col_spacings(5);      table.set_col_spacings(5);
1331    
# Line 1143  InstrumentProps::InstrumentProps() Line 1351  InstrumentProps::InstrumentProps()
1351      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1352      buttonBox.show();      buttonBox.show();
1353      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1354      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1355      quitButton.grab_focus();      quitButton.grab_focus();
1356    
1357      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1156  InstrumentProps::InstrumentProps() Line 1364  InstrumentProps::InstrumentProps()
1364    
1365  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1366  {  {
1367      this->instrument = instrument;      update(instrument);
1368    
1369      update_model++;      update_model++;
1370      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1371      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1372      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1373      eMIDIProgram.set_value(instrument->MIDIProgram);      eMIDIProgram.set_value(instrument->MIDIProgram);
     eAttenuation.set_value(instrument->Attenuation);  
     eGainPlus6.set_value(instrument->Attenuation);  
     eEffectSend.set_value(instrument->EffectSend);  
     eFineTune.set_value(instrument->FineTune);  
     ePitchbendRange.set_value(instrument->PitchbendRange);  
     ePianoReleaseMode.set_value(instrument->PianoReleaseMode);  
     eDimensionKeyRangeLow.set_value(instrument->DimensionKeyRange.low);  
     eDimensionKeyRangeHigh.set_value(instrument->DimensionKeyRange.high);  
1374      update_model--;      update_model--;
1375  }  }
1376    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1377    
1378  void MainWindow::file_changed()  void MainWindow::file_changed()
1379  {  {
# Line 1187  void MainWindow::file_changed() Line 1383  void MainWindow::file_changed()
1383      }      }
1384  }  }
1385    
1386    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1387        sample_ref_count.clear();
1388        
1389        if (!gig) return;
1390    
1391        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1392             instrument = gig->GetNextInstrument())
1393        {
1394            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1395                 rgn = instrument->GetNextRegion())
1396            {
1397                for (int i = 0; i < 256; ++i) {
1398                    if (!rgn->pDimensionRegions[i]) continue;
1399                    if (rgn->pDimensionRegions[i]->pSample) {
1400                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1401                    }
1402                }
1403            }
1404        }
1405    }
1406    
1407  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1408  {  {
1409      file = 0;      file = 0;
# Line 1197  void MainWindow::load_gig(gig::File* gig Line 1414  void MainWindow::load_gig(gig::File* gig
1414      file_has_name = filename;      file_has_name = filename;
1415      file_is_changed = false;      file_is_changed = false;
1416    
1417        propDialog.set_file(gig);
1418      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1419    
1420      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;  
1421      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1422           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1423            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1424    
1425          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1426          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1427          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1428          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1429          // create a menu item for this instrument  
1430          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++;  
1431      }      }
1432      instrument_menu->show();      instrument_name_connection.unblock();
1433      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1434    
1435        updateSampleRefCountMap(gig);
1436    
1437      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1438          if (group->Name != "") {          if (group->Name != "") {
1439              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1440              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1441              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1442              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1443              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1444              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1237  void MainWindow::load_gig(gig::File* gig Line 1446  void MainWindow::load_gig(gig::File* gig
1446                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1447                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1448                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1449                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1450                        gig_to_utf8(sample->pInfo->Name);
1451                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1452                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1453                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1454                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1455                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
1456              }              }
1457          }          }
1458      }      }
1459        
1460        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1461            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1462    
1463            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1464            Gtk::TreeModel::Row rowGroup = *iterGroup;
1465            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1466            rowGroup[m_ScriptsModel.m_col_group]  = group;
1467            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1468            for (int s = 0; group->GetScript(s); ++s) {
1469                gig::Script* script = group->GetScript(s);
1470    
1471                Gtk::TreeModel::iterator iterScript =
1472                    m_refScriptsTreeModel->append(rowGroup.children());
1473                Gtk::TreeModel::Row rowScript = *iterScript;
1474                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1475                rowScript[m_ScriptsModel.m_col_script] = script;
1476                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1477            }
1478        }
1479        // unfold all script groups by default
1480        m_TreeViewScripts.expand_all();
1481    
1482      file = gig;      file = gig;
1483    
1484      // select the first instrument      // select the first instrument
1485      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1486      tree_sel_ref->select(Gtk::TreePath("0"));  
1487        instr_props_set_instrument();
1488        gig::Instrument* instrument = get_instrument();
1489        if (instrument) {
1490            midiRules.set_instrument(instrument);
1491        }
1492  }  }
1493    
1494  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1495  {  {
1496      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1497      if (instrument)  
1498      {      Gtk::TreeModel::const_iterator it =
1499            m_TreeView.get_selection()->get_selected();
1500        if (it) {
1501            Gtk::TreeModel::Row row = *it;
1502            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1503    
1504          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1505    
1506            // make sure instrument tree is updated when user changes the
1507            // instrument name in instrument properties window
1508            instrumentProps.signal_name_changed().connect(
1509                sigc::bind(
1510                    sigc::mem_fun(*this,
1511                                  &MainWindow::instr_name_changed_by_instr_props),
1512                    it));
1513        } else {
1514            instrumentProps.hide();
1515        }
1516        return it;
1517    }
1518    
1519    void MainWindow::show_instr_props()
1520    {
1521        if (instr_props_set_instrument()) {
1522          instrumentProps.show();          instrumentProps.show();
1523          instrumentProps.deiconify();          instrumentProps.deiconify();
1524      }      }
1525  }  }
1526    
1527    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1528    {
1529        Gtk::TreeModel::Row row = *it;
1530        Glib::ustring name = row[m_Columns.m_col_name];
1531    
1532        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1533        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1534        if (gigname != name) {
1535            row[m_Columns.m_col_name] = gigname;
1536        }
1537    }
1538    
1539    void MainWindow::show_midi_rules()
1540    {
1541        if (gig::Instrument* instrument = get_instrument())
1542        {
1543            midiRules.set_instrument(instrument);
1544            midiRules.show();
1545            midiRules.deiconify();
1546        }
1547    }
1548    
1549    void MainWindow::show_script_slots() {
1550        if (!file) return;
1551        // get selected instrument
1552        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1553        Gtk::TreeModel::iterator it = sel->get_selected();
1554        if (!it) return;
1555        Gtk::TreeModel::Row row = *it;
1556        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1557        if (!instrument) return;
1558    
1559        ScriptSlots* window = new ScriptSlots;
1560        window->setInstrument(instrument);
1561        //window->reparent(*this);
1562        window->show();
1563    }
1564    
1565  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1566      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1567          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1273  void MainWindow::on_action_view_status_b Line 1573  void MainWindow::on_action_view_status_b
1573      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1574  }  }
1575    
1576    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1577        Gtk::CheckMenuItem* item =
1578            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1579        if (!item) {
1580            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1581            return true;
1582        }
1583        return item->get_active();
1584    }
1585    
1586    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1587        Gtk::CheckMenuItem* item =
1588            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1589        if (!item) {
1590            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1591            return true;
1592        }
1593        return item->get_active();
1594    }
1595    
1596    bool MainWindow::is_copy_samples_loop_enabled() const {
1597        Gtk::CheckMenuItem* item =
1598            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1599        if (!item) {
1600            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1601            return true;
1602        }
1603        return item->get_active();
1604    }
1605    
1606  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1607  {  {
1608      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1609          show_instr_props();          show_instr_props();
1610      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1611            // gig v2 files have no midi rules
1612            static_cast<Gtk::MenuItem*>(
1613                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1614                    !(file->pVersion && file->pVersion->major == 2));
1615          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1616      }      }
1617  }  }
1618    
1619  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1620      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1621            const std::vector<Gtk::Widget*> children =
1622                instrument_menu->get_children();
1623            std::vector<Gtk::Widget*>::const_iterator it =
1624                find(children.begin(), children.end(), item);
1625            if (it != children.end()) {
1626                int index = it - children.begin();
1627                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1628    
1629                m_RegionChooser.set_instrument(file->GetInstrument(index));
1630            }
1631        }
1632  }  }
1633    
1634  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1313  void MainWindow::on_sample_treeview_butt Line 1658  void MainWindow::on_sample_treeview_butt
1658      }      }
1659  }  }
1660    
1661  void MainWindow::on_action_add_instrument() {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1662      static int __instrument_indexer = 0;      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1663      if (!file) return;          Gtk::Menu* script_popup =
1664      gig::Instrument* instrument = file->AddInstrument();              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1665      __instrument_indexer++;          // update enabled/disabled state of sample popup items
1666      instrument->pInfo->Name =          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1667          _("Unnamed Instrument ") + ToString(__instrument_indexer);          Gtk::TreeModel::iterator it = sel->get_selected();
1668            bool group_selected  = false;
1669            bool script_selected = false;
1670            if (it) {
1671                Gtk::TreeModel::Row row = *it;
1672                group_selected  = row[m_ScriptsModel.m_col_group];
1673                script_selected = row[m_ScriptsModel.m_col_script];
1674            }
1675            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1676                set_sensitive(group_selected || script_selected);
1677            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1678                set_sensitive(file);
1679            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1680                set_sensitive(script_selected);    
1681            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1682                set_sensitive(group_selected || script_selected);
1683            // show sample popup
1684            script_popup->popup(button->button, button->time);
1685        }
1686    }
1687    
1688    Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1689        const Glib::ustring& name, int position) {
1690    
1691        Gtk::RadioMenuItem::Group instrument_group;
1692        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1693        if (!children.empty()) {
1694            instrument_group =
1695                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1696        }
1697        Gtk::RadioMenuItem* item =
1698            new Gtk::RadioMenuItem(instrument_group, name);
1699        if (position < 0) {
1700            instrument_menu->append(*item);
1701        } else {
1702            instrument_menu->insert(*item, position);
1703        }
1704        item->show();
1705        item->signal_activate().connect(
1706            sigc::bind(
1707                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1708                item));
1709        return item;
1710    }
1711    
1712    void MainWindow::remove_instrument_from_menu(int index) {
1713        const std::vector<Gtk::Widget*> children =
1714            instrument_menu->get_children();
1715        Gtk::Widget* child = children[index];
1716        instrument_menu->remove(*child);
1717        delete child;
1718    }
1719    
1720    void MainWindow::add_instrument(gig::Instrument* instrument) {
1721        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1722    
1723      // update instrument tree view      // update instrument tree view
1724        instrument_name_connection.block();
1725      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1726      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1727      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1728      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1729        instrument_name_connection.unblock();
1730    
1731        add_instrument_to_menu(name);
1732    
1733        m_TreeView.get_selection()->select(iterInstr);
1734    
1735      file_changed();      file_changed();
1736  }  }
1737    
1738    void MainWindow::on_action_add_instrument() {
1739        static int __instrument_indexer = 0;
1740        if (!file) return;
1741        gig::Instrument* instrument = file->AddInstrument();
1742        __instrument_indexer++;
1743        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1744                                                ToString(__instrument_indexer));
1745    
1746        add_instrument(instrument);
1747    }
1748    
1749    void MainWindow::on_action_duplicate_instrument() {
1750        if (!file) return;
1751    
1752        // retrieve the currently selected instrument
1753        // (being the original instrument to be duplicated)
1754        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1755        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1756        if (!itSelection) return;
1757        Gtk::TreeModel::Row row = *itSelection;
1758        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1759        if (!instrOrig) return;
1760    
1761        // duplicate the orginal instrument
1762        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1763        instrNew->pInfo->Name =
1764            instrOrig->pInfo->Name +
1765            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1766    
1767        add_instrument(instrNew);
1768    }
1769    
1770  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1771      if (!file) return;      if (!file) return;
1772      if (file_is_shared) {      if (file_is_shared) {
# Line 1347  void MainWindow::on_action_remove_instru Line 1786  void MainWindow::on_action_remove_instru
1786          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1787          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1788          try {          try {
1789                Gtk::TreePath path(it);
1790                int index = path[0];
1791    
1792              // remove instrument from the gig file              // remove instrument from the gig file
1793              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1794              file_changed();              file_changed();
1795    
1796                remove_instrument_from_menu(index);
1797    
1798                // remove row from instruments tree view
1799                m_refTreeModel->erase(it);
1800    
1801    #if GTKMM_MAJOR_VERSION < 3
1802                // select another instrument (in gtk3 this is done
1803                // automatically)
1804                if (!m_refTreeModel->children().empty()) {
1805                    if (index == m_refTreeModel->children().size()) {
1806                        index--;
1807                    }
1808                    m_TreeView.get_selection()->select(
1809                        Gtk::TreePath(ToString(index)));
1810                }
1811    #endif
1812                instr_props_set_instrument();
1813                instr = get_instrument();
1814                if (instr) {
1815                    midiRules.set_instrument(instr);
1816                } else {
1817                    midiRules.hide();
1818                }
1819          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1820              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1821              msg.run();              msg.run();
# Line 1367  void MainWindow::on_action_sample_proper Line 1831  void MainWindow::on_action_sample_proper
1831      msg.run();      msg.run();
1832  }  }
1833    
1834    void MainWindow::on_action_add_script_group() {
1835        static int __script_indexer = 0;
1836        if (!file) return;
1837        gig::ScriptGroup* group = file->AddScriptGroup();
1838        group->Name = gig_from_utf8(_("Unnamed Group"));
1839        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1840        __script_indexer++;
1841        // update sample tree view
1842        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1843        Gtk::TreeModel::Row rowGroup = *iterGroup;
1844        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1845        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1846        rowGroup[m_ScriptsModel.m_col_group] = group;
1847        file_changed();
1848    }
1849    
1850    void MainWindow::on_action_add_script() {
1851        if (!file) return;
1852        // get selected group
1853        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1854        Gtk::TreeModel::iterator it = sel->get_selected();
1855        if (!it) return;
1856        Gtk::TreeModel::Row row = *it;
1857        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1858        if (!group) { // not a group, but a script is selected (probably)
1859            gig::Script* script = row[m_ScriptsModel.m_col_script];
1860            if (!script) return;
1861            it = row.parent(); // resolve parent (that is the script's group)
1862            if (!it) return;
1863            row = *it;
1864            group = row[m_ScriptsModel.m_col_group];
1865            if (!group) return;
1866        }
1867    
1868        // add a new script to the .gig file
1869        gig::Script* script = group->AddScript();    
1870        Glib::ustring name = _("Unnamed Script");
1871        script->Name = gig_from_utf8(name);
1872    
1873        // add script to the tree view
1874        Gtk::TreeModel::iterator iterScript =
1875            m_refScriptsTreeModel->append(row.children());
1876        Gtk::TreeModel::Row rowScript = *iterScript;
1877        rowScript[m_ScriptsModel.m_col_name] = name;
1878        rowScript[m_ScriptsModel.m_col_script] = script;
1879        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1880    
1881        // unfold group of new script item in treeview
1882        Gtk::TreeModel::Path path(iterScript);
1883        m_TreeViewScripts.expand_to_path(path);
1884    }
1885    
1886    void MainWindow::on_action_edit_script() {
1887        if (!file) return;
1888        // get selected script
1889        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1890        Gtk::TreeModel::iterator it = sel->get_selected();
1891        if (!it) return;
1892        Gtk::TreeModel::Row row = *it;
1893        gig::Script* script = row[m_ScriptsModel.m_col_script];
1894        if (!script) return;
1895    
1896        ScriptEditor* editor = new ScriptEditor;
1897        editor->setScript(script);
1898        //editor->reparent(*this);
1899        editor->show();
1900    }
1901    
1902    void MainWindow::on_action_remove_script() {
1903        if (!file) return;
1904        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1905        Gtk::TreeModel::iterator it = sel->get_selected();
1906        if (it) {
1907            Gtk::TreeModel::Row row = *it;
1908            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1909            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1910            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1911            try {
1912                // remove script group or script from the gig file
1913                if (group) {
1914                    // notify everybody that we're going to remove these samples
1915    //TODO:         scripts_to_be_removed_signal.emit(members);
1916                    // delete the group in the .gig file including the
1917                    // samples that belong to the group
1918                    file->DeleteScriptGroup(group);
1919                    // notify that we're done with removal
1920    //TODO:         scripts_removed_signal.emit();
1921                    file_changed();
1922                } else if (script) {
1923                    // notify everybody that we're going to remove this sample
1924    //TODO:         std::list<gig::Script*> lscripts;
1925    //TODO:         lscripts.push_back(script);
1926    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
1927                    // remove sample from the .gig file
1928                    script->GetGroup()->DeleteScript(script);
1929                    // notify that we're done with removal
1930    //TODO:         scripts_removed_signal.emit();
1931                    dimreg_changed();
1932                    file_changed();
1933                }
1934                // remove respective row(s) from samples tree view
1935                m_refScriptsTreeModel->erase(it);
1936            } catch (RIFF::Exception e) {
1937                // pretend we're done with removal (i.e. to avoid dead locks)
1938    //TODO:     scripts_removed_signal.emit();
1939                // show error message
1940                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1941                msg.run();
1942            }
1943        }
1944    }
1945    
1946  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
1947      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1948      if (!file) return;      if (!file) return;
1949      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1950      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1951      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1952      __sample_indexer++;      __sample_indexer++;
1953      // update sample tree view      // update sample tree view
1954      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1955      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1956      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1957      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1958      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1959      file_changed();      file_changed();
# Line 1405  void MainWindow::on_action_add_sample() Line 1981  void MainWindow::on_action_add_sample()
1981      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1982      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1983      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1984      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1985        // matches all file types supported by libsndfile
1986    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1987        Gtk::FileFilter soundfilter;
1988    #else
1989        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1990    #endif
1991      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1992          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1993          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1413  void MainWindow::on_action_add_sample() Line 1995  void MainWindow::on_action_add_sample()
1995          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1996          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1997      };      };
1998        const char* soundfiles = _("Sound Files");
1999        const char* allfiles = _("All Files");
2000    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2001      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
2002          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
2003      soundfilter.set_name(_("Sound Files"));      soundfilter.set_name(soundfiles);
2004      Gtk::FileFilter allpassfilter; // matches every file  
2005        // matches every file
2006        Gtk::FileFilter allpassfilter;
2007      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
2008      allpassfilter.set_name(_("All Files"));      allpassfilter.set_name(allfiles);
2009    #else
2010        for (int i = 0; supportedFileTypes[i]; i++)
2011            soundfilter->add_pattern(supportedFileTypes[i]);
2012        soundfilter->set_name(soundfiles);
2013    
2014        // matches every file
2015        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
2016        allpassfilter->add_pattern("*.*");
2017        allpassfilter->set_name(allfiles);
2018    #endif
2019      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
2020      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
2021      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 1427  void MainWindow::on_action_add_sample() Line 2024  void MainWindow::on_action_add_sample()
2024      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2025          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
2026          Glib::ustring error_files;          Glib::ustring error_files;
2027          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
2028          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
2029               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
2030              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
2031              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1465  void MainWindow::on_action_add_sample() Line 2062  void MainWindow::on_action_add_sample()
2062                          break;                          break;
2063                      }                      }
2064                  }                  }
2065                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
2066                  sample->Channels = info.channels;                  sample->Channels = info.channels;
2067                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
2068                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1479  void MainWindow::on_action_add_sample() Line 2076  void MainWindow::on_action_add_sample()
2076                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
2077                  {                  {
2078                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
2079                        sample->FineTune      = instrument.detune;
2080    
 #if HAVE_SF_INSTRUMENT_LOOPS  
2081                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
2082                          sample->Loops = 1;                          sample->Loops = 1;
2083    
# Line 1500  void MainWindow::on_action_add_sample() Line 2097  void MainWindow::on_action_add_sample()
2097                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
2098                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
2099                      }                      }
 #endif  
2100                  }                  }
2101    
2102                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1518  void MainWindow::on_action_add_sample() Line 2114  void MainWindow::on_action_add_sample()
2114                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
2115                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
2116                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
2117                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
2118                        gig_to_utf8(sample->pInfo->Name);
2119                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
2120                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
2121                  // close sound file                  // close sound file
2122                  sf_close(hFile);                  sf_close(hFile);
2123                  file_changed();                  file_changed();
2124              } 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)
2125                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2126                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
2127              }              }
2128          }          }
2129          // 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
2130          if (error_files.size()) {          if (!error_files.empty()) {
2131              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;
2132              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2133              msg.run();              msg.run();
# Line 1543  void MainWindow::on_action_replace_all_s Line 2140  void MainWindow::on_action_replace_all_s
2140      if (!file) return;      if (!file) return;
2141      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
2142                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
2143      view::WrapLabel description(      const char* str =
2144          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
2145            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
2146            "directory.\n\n"            "directory.\n\n"
# Line 1557  void MainWindow::on_action_replace_all_s Line 2154  void MainWindow::on_action_replace_all_s
2154            "the sample in the gig file accordingly. If you don't need an "            "the sample in the gig file accordingly. If you don't need an "
2155            "extension, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
2156            "appropriate sample file could be found will be reported and left "            "appropriate sample file could be found will be reported and left "
2157            "untouched.\n")            "untouched.\n");
2158      );  #if GTKMM_MAJOR_VERSION < 3
2159        view::WrapLabel description(str);
2160    #else
2161        Gtk::Label description(str);
2162        description.set_line_wrap();
2163    #endif
2164      Gtk::HBox entryArea;      Gtk::HBox entryArea;
2165      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
2166      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
2167      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
2168      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
# Line 1579  void MainWindow::on_action_replace_all_s Line 2181  void MainWindow::on_action_replace_all_s
2181      {      {
2182          current_sample_dir = dialog.get_current_folder();          current_sample_dir = dialog.get_current_folder();
2183          Glib::ustring error_files;          Glib::ustring error_files;
2184          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
2185          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
2186               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
2187          {          {
2188              std::string filename =              std::string filename =
2189                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
2190                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2191                                             postfixEntryBox.get_text());
2192              SF_INFO info;              SF_INFO info;
2193              info.format = 0;              info.format = 0;
2194              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1618  void MainWindow::on_action_replace_all_s Line 2221  void MainWindow::on_action_replace_all_s
2221              }              }
2222              catch (std::string what)              catch (std::string what)
2223              {              {
2224                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2225                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
2226                        " (" + what + ")";
2227              }              }
2228          }          }
2229          // 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
2230          if (error_files.size()) {          if (!error_files.empty()) {
2231              Glib::ustring txt =              Glib::ustring txt =
2232                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
2233              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1644  void MainWindow::on_action_remove_sample Line 2248  void MainWindow::on_action_remove_sample
2248          try {          try {
2249              // remove group or sample from the gig file              // remove group or sample from the gig file
2250              if (group) {              if (group) {
2251                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2252                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2253                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2254                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1708  void MainWindow::on_action_remove_sample Line 2312  void MainWindow::on_action_remove_sample
2312      }      }
2313  }  }
2314    
2315    // see comment on on_sample_treeview_drag_begin()
2316    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2317    {
2318        first_call_to_drag_data_get = true;
2319    }
2320    
2321    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2322                                                       Gtk::SelectionData& selection_data, guint, guint)
2323    {
2324        if (!first_call_to_drag_data_get) return;
2325        first_call_to_drag_data_get = false;
2326    
2327        // get selected script
2328        gig::Script* script = NULL;
2329        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2330        Gtk::TreeModel::iterator it = sel->get_selected();
2331        if (it) {
2332            Gtk::TreeModel::Row row = *it;
2333            script = row[m_ScriptsModel.m_col_script];
2334        }
2335        // pass the gig::Script as pointer
2336        selection_data.set(selection_data.get_target(), 0/*unused*/,
2337                           (const guchar*)&script,
2338                           sizeof(script)/*length of data in bytes*/);
2339    }
2340    
2341  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2342  // 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
2343  // 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 1766  void MainWindow::on_sample_label_drop_dr Line 2396  void MainWindow::on_sample_label_drop_dr
2396          bool channels_changed = false;          bool channels_changed = false;
2397          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2398              // remove the samplechannel dimension              // remove the samplechannel dimension
2399    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2400              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2401              channels_changed = true;              channels_changed = true;
2402              region_changed();              region_changed();
2403    */
2404          }          }
2405          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2406                sample,
2407                is_copy_samples_unity_note_enabled(),
2408                is_copy_samples_fine_tune_enabled(),
2409                is_copy_samples_loop_enabled()
2410            );
2411    
2412          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2413              // add samplechannel dimension              // add samplechannel dimension
# Line 1813  void MainWindow::sample_name_changed(con Line 2450  void MainWindow::sample_name_changed(con
2450      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2451      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2452      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2453        gig::String gigname(gig_from_utf8(name));
2454      if (group) {      if (group) {
2455          if (group->Name != name) {          if (group->Name != gigname) {
2456              group->Name = name;              group->Name = gigname;
2457              printf("group name changed\n");              printf("group name changed\n");
2458              file_changed();              file_changed();
2459          }          }
2460      } else if (sample) {      } else if (sample) {
2461          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2462              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2463              printf("sample name changed\n");              printf("sample name changed\n");
2464              file_changed();              file_changed();
2465          }          }
2466      }      }
2467  }  }
2468    
2469    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2470                                         const Gtk::TreeModel::iterator& iter) {
2471        if (!iter) return;
2472        Gtk::TreeModel::Row row = *iter;
2473        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2474        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2475        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2476        gig::String gigname(gig_from_utf8(name));
2477        if (group) {
2478            if (group->Name != gigname) {
2479                group->Name = gigname;
2480                printf("script group name changed\n");
2481                file_changed();
2482            }
2483        } else if (script) {
2484            if (script->Name != gigname) {
2485                script->Name = gigname;
2486                printf("script name changed\n");
2487                file_changed();
2488            }
2489        }
2490    }
2491    
2492  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2493                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2494      if (!iter) return;      if (!iter) return;
2495      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2496      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2497    
2498        // change name in instrument menu
2499        int index = path[0];
2500        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2501        if (index < children.size()) {
2502    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2503            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2504    #else
2505            remove_instrument_from_menu(index);
2506            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2507            item->set_active();
2508    #endif
2509        }
2510    
2511        // change name in gig
2512      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2513      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2514          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2515            instrument->pInfo->Name = gigname;
2516    
2517            // change name in the instrument properties window
2518            if (instrumentProps.get_instrument() == instrument) {
2519                instrumentProps.update_name();
2520            }
2521    
2522          file_changed();          file_changed();
2523      }      }
2524  }  }
2525    
2526    void MainWindow::on_action_combine_instruments() {
2527        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2528        d->show_all();
2529        d->resize(500, 400);
2530        d->run();
2531        if (d->fileWasChanged()) {
2532            // update GUI with new instrument just created
2533            add_instrument(d->newCombinedInstrument());
2534        }
2535        delete d;
2536    }
2537    
2538    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2539        struct _Source {
2540            std::vector<RIFF::File*> riffs;
2541            std::vector<gig::File*> gigs;
2542            
2543            ~_Source() {
2544                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2545                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2546                riffs.clear();
2547                gigs.clear();
2548            }
2549        } sources;
2550    
2551        if (filenames.empty())
2552            throw RIFF::Exception(_("No files selected, so nothing done."));
2553    
2554        // first open all input files (to avoid output file corruption)
2555        int i;
2556        try {
2557            for (i = 0; i < filenames.size(); ++i) {
2558                const std::string& filename = filenames[i];
2559                printf("opening file=%s\n", filename.c_str());
2560    
2561                RIFF::File* riff = new RIFF::File(filename);
2562                sources.riffs.push_back(riff);
2563    
2564                gig::File* gig = new gig::File(riff);
2565                sources.gigs.push_back(gig);
2566            }
2567        } catch (RIFF::Exception e) {
2568            throw RIFF::Exception(
2569                _("Error occurred while opening '") +
2570                filenames[i] +
2571                "': " +
2572                e.Message
2573            );
2574        } catch (...) {
2575            throw RIFF::Exception(
2576                _("Unknown exception occurred while opening '") +
2577                filenames[i] + "'"
2578            );
2579        }
2580    
2581        // now merge the opened .gig files to the main .gig file currently being
2582        // open in gigedit
2583        try {
2584            for (i = 0; i < filenames.size(); ++i) {
2585                const std::string& filename = filenames[i];
2586                printf("merging file=%s\n", filename.c_str());
2587                assert(i < sources.gigs.size());
2588    
2589                this->file->AddContentOf(sources.gigs[i]);
2590            }
2591        } catch (RIFF::Exception e) {
2592            throw RIFF::Exception(
2593                _("Error occurred while merging '") +
2594                filenames[i] +
2595                "': " +
2596                e.Message
2597            );
2598        } catch (...) {
2599            throw RIFF::Exception(
2600                _("Unknown exception occurred while merging '") +
2601                filenames[i] + "'"
2602            );
2603        }
2604    
2605        // Note: requires that this file already has a filename !
2606        this->file->Save();
2607    }
2608    
2609    void MainWindow::on_action_merge_files() {
2610        if (this->file->GetFileName().empty()) {
2611            Glib::ustring txt = _(
2612                "You seem to have a new .gig file open that has not been saved "
2613                "yet. You must save it somewhere before starting to merge it with "
2614                "other .gig files though, because during the merge operation the "
2615                "other files' sample data must be written on file level to the "
2616                "target .gig file."
2617            );
2618            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2619            msg.run();
2620            return;
2621        }
2622    
2623        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2624        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2625        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2626        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2627    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2628        Gtk::FileFilter filter;
2629        filter.add_pattern("*.gig");
2630    #else
2631        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2632        filter->add_pattern("*.gig");
2633    #endif
2634        dialog.set_filter(filter);
2635        if (current_gig_dir != "") {
2636            dialog.set_current_folder(current_gig_dir);
2637        }
2638        dialog.set_select_multiple(true);
2639    
2640        // show warning in the file picker dialog
2641        Gtk::HBox descriptionArea;
2642        descriptionArea.set_spacing(15);
2643        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2644        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2645    #if GTKMM_MAJOR_VERSION < 3
2646        view::WrapLabel description;
2647    #else
2648        Gtk::Label description;
2649        description.set_line_wrap();
2650    #endif
2651        description.set_markup(_(
2652            "\nSelect at least one .gig file that shall be merged to the .gig file "
2653            "currently being open in gigedit.\n\n"
2654            "<b>Please Note:</b> Merging with other files will modify your "
2655            "currently open .gig file on file level! And be aware that the current "
2656            "merge algorithm does not detect duplicate samples yet. So if you are "
2657            "merging files which are using equivalent sample data, those "
2658            "equivalent samples will currently be treated as separate samples and "
2659            "will accordingly be stored separately in the target .gig file!"
2660        ));
2661        descriptionArea.pack_start(description);
2662        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2663        descriptionArea.show_all();
2664    
2665        if (dialog.run() == Gtk::RESPONSE_OK) {
2666            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2667            std::vector<std::string> filenames = dialog.get_filenames();
2668    
2669            // merge the selected files to the currently open .gig file
2670            try {
2671                mergeFiles(filenames);
2672            } catch (RIFF::Exception e) {
2673                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2674                msg.run();
2675            }
2676    
2677            // update GUI
2678            __refreshEntireGUI();        
2679        }
2680    }
2681    
2682  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2683      this->file_is_shared = b;      this->file_is_shared = b;
2684    
# Line 1856  void MainWindow::set_file_is_shared(bool Line 2695  void MainWindow::set_file_is_shared(bool
2695      }      }
2696  }  }
2697    
2698    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2699        if (!sample) return;
2700        sample_ref_count[sample] += offset;
2701        const int refcount = sample_ref_count[sample];
2702    
2703        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2704        for (int g = 0; g < model->children().size(); ++g) {
2705            Gtk::TreeModel::Row rowGroup = model->children()[g];
2706            for (int s = 0; s < rowGroup.children().size(); ++s) {
2707                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2708                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2709                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2710                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
2711            }
2712        }
2713    }
2714    
2715    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2716        on_sample_ref_count_incremented(oldSample, -1);
2717        on_sample_ref_count_incremented(newSample, +1);
2718    }
2719    
2720    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2721        // just in case a new sample is added later with exactly the same memory
2722        // address, which would lead to incorrect refcount if not deleted here
2723        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2724             it != samples.end(); it != samples.end())
2725        {
2726            sample_ref_count.erase(*it);
2727        }
2728    }
2729    
2730  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2731      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2732  }  }

Legend:
Removed from v.1959  
changed lines
  Added in v.2621

  ViewVC Help
Powered by ViewVC