/[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 2445 by persson, Sun Apr 28 06:07:22 2013 UTC revision 2625 by schoenebeck, Wed Jun 11 21:22:24 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2013 Andreas Persson   * Copyright (C) 2006-2014 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 40  Line 40 
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46    #include "Settings.h"
47    #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49    #include "scriptslots.h"
50    #include "ReferencesView.h"
51  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
52  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
53    
# Line 76  MainWindow::MainWindow() : Line 81  MainWindow::MainWindow() :
81      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
82      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
83    
84        m_ScrolledWindowScripts.add(m_TreeViewScripts);
85        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
86    
87    
88      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
89    
# Line 89  MainWindow::MainWindow() : Line 97  MainWindow::MainWindow() :
97      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
98      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
99    
100        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
101        dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
102        dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
103        dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
104    
105      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
106      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
107        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
108    
109      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
110    
# Line 123  MainWindow::MainWindow() : Line 135  MainWindow::MainWindow() :
135                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
136                       sigc::mem_fun(                       sigc::mem_fun(
137                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
138        actionGroup->add(Gtk::Action::create("MidiRules",
139                                             _("_Midi Rules...")),
140                         sigc::mem_fun(
141                             *this, &MainWindow::show_midi_rules));
142        actionGroup->add(Gtk::Action::create("ScriptSlots",
143                                             _("_Script Slots...")),
144                         sigc::mem_fun(
145                             *this, &MainWindow::show_script_slots));
146      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
147                       sigc::mem_fun(                       sigc::mem_fun(
148                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
149      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
150            Gtk::Action::create("MenuSample", _("_Sample")),
151            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
152        );
153        actionGroup->add(
154            Gtk::Action::create("MenuInstrument", _("_Instrument")),
155            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
156        );
157        actionGroup->add(
158            Gtk::Action::create("MenuScript", _("S_cript")),
159            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
160        );
161        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
162    
163        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
164    
     actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
165      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
166            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
167        toggle_action->set_active(true);
168        actionGroup->add(toggle_action);
169    
170        toggle_action =
171            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
172        toggle_action->set_active(true);
173        actionGroup->add(toggle_action);
174    
175        toggle_action =
176            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
177        toggle_action->set_active(true);
178        actionGroup->add(toggle_action);
179    
180    
181        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
182        toggle_action =
183          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
184      toggle_action->set_active(true);      toggle_action->set_active(true);
185      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 155  MainWindow::MainWindow() : Line 205  MainWindow::MainWindow() :
205          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
206      );      );
207    
208    
209        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
210        
211        toggle_action =
212            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
213        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
214        actionGroup->add(
215            toggle_action,
216            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
217        );
218    
219    
220        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
221    
222        actionGroup->add(
223            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
224            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
225        );
226    
227        actionGroup->add(
228            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
229            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
230        );
231    
232    
233      // sample right-click popup actions      // sample right-click popup actions
234      actionGroup->add(      actionGroup->add(
235          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 173  MainWindow::MainWindow() : Line 248  MainWindow::MainWindow() :
248          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
249      );      );
250      actionGroup->add(      actionGroup->add(
251            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
252            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
253        );
254        actionGroup->add(
255          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
256                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
257          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)
258      );      );
259        
260        // script right-click popup actions
261        actionGroup->add(
262            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
263            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
264        );
265        actionGroup->add(
266            Gtk::Action::create("AddScript", _("Add _Script")),
267            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
268        );
269        actionGroup->add(
270            Gtk::Action::create("EditScript", _("_Edit Script...")),
271            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
272        );
273        actionGroup->add(
274            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
275            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
276        );
277    
278      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
279      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 196  MainWindow::MainWindow() : Line 293  MainWindow::MainWindow() :
293          "      <separator/>"          "      <separator/>"
294          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
295          "    </menu>"          "    </menu>"
296            "    <menu action='MenuEdit'>"
297            "      <menuitem action='CopySampleUnity'/>"
298            "      <menuitem action='CopySampleTune'/>"
299            "      <menuitem action='CopySampleLoop'/>"
300            "    </menu>"
301            "    <menu action='MenuSample'>"
302            "      <menuitem action='SampleProperties'/>"
303            "      <menuitem action='AddGroup'/>"
304            "      <menuitem action='AddSample'/>"
305            "      <menuitem action='ShowSampleRefs'/>"
306            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
307            "      <separator/>"
308            "      <menuitem action='RemoveSample'/>"
309            "    </menu>"
310          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
311            "      <menu action='AllInstruments'>"
312            "      </menu>"
313            "      <separator/>"
314            "      <menuitem action='InstrProperties'/>"
315            "      <menuitem action='MidiRules'/>"
316            "      <menuitem action='ScriptSlots'/>"
317            "      <menuitem action='AddInstrument'/>"
318            "      <menuitem action='DupInstrument'/>"
319            "      <separator/>"
320            "      <menuitem action='RemoveInstrument'/>"
321            "    </menu>"
322            "    <menu action='MenuScript'>"
323            "      <menuitem action='AddScriptGroup'/>"
324            "      <menuitem action='AddScript'/>"
325            "      <menuitem action='EditScript'/>"
326            "      <separator/>"
327            "      <menuitem action='RemoveScript'/>"
328          "    </menu>"          "    </menu>"
329          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
330          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
331          "    </menu>"          "    </menu>"
332            "    <menu action='MenuTools'>"
333            "      <menuitem action='CombineInstruments'/>"
334            "      <menuitem action='MergeFiles'/>"
335            "    </menu>"
336            "    <menu action='MenuSettings'>"
337            "      <menuitem action='WarnUserOnExtensions'/>"
338            "    </menu>"
339          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
340          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
341          "    </menu>"          "    </menu>"
342          "  </menubar>"          "  </menubar>"
343          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
344          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
345            "    <menuitem action='MidiRules'/>"
346            "    <menuitem action='ScriptSlots'/>"
347          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
348          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
349          "    <separator/>"          "    <separator/>"
# Line 216  MainWindow::MainWindow() : Line 353  MainWindow::MainWindow() :
353          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
354          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
355          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
356            "    <menuitem action='ShowSampleRefs'/>"
357          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
358          "    <separator/>"          "    <separator/>"
359          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
360          "  </popup>"          "  </popup>"
361            "  <popup name='ScriptPopupMenu'>"
362            "    <menuitem action='AddScriptGroup'/>"
363            "    <menuitem action='AddScript'/>"
364            "    <menuitem action='EditScript'/>"
365            "    <separator/>"
366            "    <menuitem action='RemoveScript'/>"
367            "  </popup>"
368          "</ui>";          "</ui>";
369      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
370    
371      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
372        
373        // Set tooltips for menu items (for some reason, setting a tooltip on the
374        // respective Gtk::Action objects above will simply be ignored, no matter
375        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
376        // Gtk::Action::create()).
377        {
378            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
379                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
380            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."));
381        }
382        {
383            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
384                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
385            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."));
386        }
387        {
388            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
389                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
390            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."));
391        }
392        {
393            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
394                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
395            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."));
396        }
397        {
398            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
399                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
400            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
401        }
402        {
403            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
404                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
405            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
406        }
407    
408    
409      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
410          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
411    
412      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
413      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 252  MainWindow::MainWindow() : Line 433  MainWindow::MainWindow() :
433      // Create the Tree model:      // Create the Tree model:
434      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
435      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
436        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
437      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
438          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
439      );      );
# Line 263  MainWindow::MainWindow() : Line 445  MainWindow::MainWindow() :
445      // create samples treeview (including its data model)      // create samples treeview (including its data model)
446      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
447      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
448        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."));
449      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
450      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
451      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
452        {
453            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
454            Gtk::CellRendererText* cellrenderer =
455                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
456            column->add_attribute(
457                cellrenderer->property_foreground(), m_SamplesModel.m_color
458            );
459        }
460        {
461            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
462            Gtk::CellRendererText* cellrenderer =
463                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
464            column->add_attribute(
465                cellrenderer->property_foreground(), m_SamplesModel.m_color
466            );
467        }
468        m_TreeViewSamples.set_headers_visible(true);
469      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
470          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
471      );      );
# Line 273  MainWindow::MainWindow() : Line 473  MainWindow::MainWindow() :
473          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
474      );      );
475    
476        // create scripts treeview (including its data model)
477        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
478        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
479        m_TreeViewScripts.set_tooltip_text(_(
480            "Note: instrument scripts are a LinuxSampler extension of the gig "
481            "format. This feature will not work with the GigaStudio software!"
482        ));
483        // m_TreeViewScripts.set_reorderable();
484        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
485        m_TreeViewScripts.set_headers_visible(false);
486        m_TreeViewScripts.signal_button_press_event().connect_notify(
487            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
488        );
489        m_refScriptsTreeModel->signal_row_changed().connect(
490            sigc::mem_fun(*this, &MainWindow::script_name_changed)
491        );
492    
493        // establish drag&drop between scripts tree view and ScriptSlots window
494        std::vector<Gtk::TargetEntry> drag_target_gig_script;
495        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
496        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
497        m_TreeViewScripts.signal_drag_begin().connect(
498            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
499        );
500        m_TreeViewScripts.signal_drag_data_get().connect(
501            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
502        );
503    
504      // 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
505      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
506      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 297  MainWindow::MainWindow() : Line 525  MainWindow::MainWindow() :
525          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
526      propDialog.signal_changed().connect(      propDialog.signal_changed().connect(
527          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
528        midiRules.signal_changed().connect(
529            sigc::mem_fun(*this, &MainWindow::file_changed));
530    
531      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
532          dimreg_to_be_changed_signal.make_slot());          dimreg_to_be_changed_signal.make_slot());
# Line 304  MainWindow::MainWindow() : Line 534  MainWindow::MainWindow() :
534          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
535      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
536          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
537        sample_ref_changed_signal.connect(
538            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
539        );
540        samples_to_be_removed_signal.connect(
541            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
542        );
543    
544      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
545          sigc::hide(          sigc::hide(
# Line 345  MainWindow::MainWindow() : Line 581  MainWindow::MainWindow() :
581    
582      // start with a new gig file by default      // start with a new gig file by default
583      on_action_file_new();      on_action_file_new();
584    
585        // select 'Instruments' tab by default
586        // (gtk allows this only if the tab childs are visible, thats why it's here)
587        m_TreeViewNotebook.set_current_page(1);
588  }  }
589    
590  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 523  void MainWindow::__clear() { Line 763  void MainWindow::__clear() {
763      // clear the samples and instruments tree views      // clear the samples and instruments tree views
764      m_refTreeModel->clear();      m_refTreeModel->clear();
765      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
766        m_refScriptsTreeModel->clear();
767      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
768      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
769          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 533  void MainWindow::__clear() { Line 774  void MainWindow::__clear() {
774      set_file_is_shared(false);      set_file_is_shared(false);
775  }  }
776    
777    void MainWindow::__refreshEntireGUI() {
778        // clear the samples and instruments tree views
779        m_refTreeModel->clear();
780        m_refSamplesTreeModel->clear();
781        m_refScriptsTreeModel->clear();
782        // remove all entries from "Instrument" menu
783        while (!instrument_menu->get_children().empty()) {
784            remove_instrument_from_menu(0);
785        }
786    
787        if (!this->file) return;
788    
789        load_gig(
790            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
791        );
792    }
793    
794  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
795  {  {
796      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 545  void MainWindow::on_action_file_new() Line 803  void MainWindow::on_action_file_new()
803      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
804      // already add one new instrument by default      // already add one new instrument by default
805      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
806      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
807      // update GUI with that new gig::File      // update GUI with that new gig::File
808      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
809  }  }
# Line 897  void MainWindow::on_action_file_properti Line 1155  void MainWindow::on_action_file_properti
1155      propDialog.deiconify();      propDialog.deiconify();
1156  }  }
1157    
1158    void MainWindow::on_action_warn_user_on_extensions() {
1159        Settings::singleton()->warnUserOnExtensions =
1160            !Settings::singleton()->warnUserOnExtensions;
1161    }
1162    
1163  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1164  {  {
1165      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 906  void MainWindow::on_action_help_about() Line 1169  void MainWindow::on_action_help_about()
1169      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1170  #endif  #endif
1171      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1172      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1173      dialog.set_comments(_(      const std::string sComment =
1174          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1175          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1176          "Please notice that this is still a very young instrument editor. "          _(
1177          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1178          "this application.\n"              "\n"
1179          "\n"              "Please notice that this is still a very young instrument editor. "
1180          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
1181      );              "this application.\n"
1182                "\n"
1183                "Please report bugs to: http://bugs.linuxsampler.org"
1184            );
1185        dialog.set_comments(sComment.c_str());
1186      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1187      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1188      dialog.run();      dialog.run();
1189  }  }
1190    
1191  PropDialog::PropDialog()  PropDialog::PropDialog()
1192      : eName(_("Name")),      : eFileFormat(_("File Format")),
1193          eName(_("Name")),
1194        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1195        eComments(_("Comments")),        eComments(_("Comments")),
1196        eProduct(_("Product")),        eProduct(_("Product")),
# Line 939  PropDialog::PropDialog() Line 1207  PropDialog::PropDialog()
1207        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1208        eSubject(_("Subject")),        eSubject(_("Subject")),
1209        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1210        table(2, 1)        table(2, 1),
1211          m_file(NULL)
1212  {  {
1213      set_title(_("File Properties"));      set_title(_("File Properties"));
1214      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 961  PropDialog::PropDialog() Line 1230  PropDialog::PropDialog()
1230      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1231      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1232    
1233        table.add(eFileFormat);
1234      table.add(eName);      table.add(eName);
1235      table.add(eCreationDate);      table.add(eCreationDate);
1236      table.add(eComments);      table.add(eComments);
# Line 991  PropDialog::PropDialog() Line 1261  PropDialog::PropDialog()
1261      quitButton.grab_focus();      quitButton.grab_focus();
1262      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1263          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1264        eFileFormat.signal_value_changed().connect(
1265            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1266    
1267      quitButton.show();      quitButton.show();
1268      vbox.show();      vbox.show();
1269      show_all_children();      show_all_children();
1270  }  }
1271    
1272    void PropDialog::set_file(gig::File* file)
1273    {
1274        m_file = file;
1275    
1276        // update file format version combo box
1277        const std::string sGiga = "Gigasampler/GigaStudio v";
1278        const int major = file->pVersion->major;
1279        std::vector<std::string> txts;
1280        std::vector<int> values;
1281        txts.push_back(sGiga + "2"); values.push_back(2);
1282        txts.push_back(sGiga + "3/v4"); values.push_back(3);
1283        if (major != 2 && major != 3) {
1284            txts.push_back(sGiga + ToString(major)); values.push_back(major);
1285        }
1286        std::vector<const char*> texts;
1287        for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1288        texts.push_back(NULL); values.push_back(0);
1289        eFileFormat.set_choices(&texts[0], &values[0]);
1290        eFileFormat.set_value(major);
1291    }
1292    
1293    void PropDialog::onFileFormatChanged() {
1294        const int major = eFileFormat.get_value();
1295        if (m_file) m_file->pVersion->major = major;
1296    }
1297    
1298  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1299  {  {
1300      update(info);      update(info);
# Line 1128  void MainWindow::file_changed() Line 1426  void MainWindow::file_changed()
1426      }      }
1427  }  }
1428    
1429    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1430        sample_ref_count.clear();
1431        
1432        if (!gig) return;
1433    
1434        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1435             instrument = gig->GetNextInstrument())
1436        {
1437            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1438                 rgn = instrument->GetNextRegion())
1439            {
1440                for (int i = 0; i < 256; ++i) {
1441                    if (!rgn->pDimensionRegions[i]) continue;
1442                    if (rgn->pDimensionRegions[i]->pSample) {
1443                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1444                    }
1445                }
1446            }
1447        }
1448    }
1449    
1450  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1451  {  {
1452      file = 0;      file = 0;
# Line 1138  void MainWindow::load_gig(gig::File* gig Line 1457  void MainWindow::load_gig(gig::File* gig
1457      file_has_name = filename;      file_has_name = filename;
1458      file_is_changed = false;      file_is_changed = false;
1459    
1460        propDialog.set_file(gig);
1461      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1462    
1463      instrument_name_connection.block();      instrument_name_connection.block();
1464      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1465           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1466          Glib::ustring name(instrument->pInfo->Name);          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1467    
1468          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1469          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
# Line 1153  void MainWindow::load_gig(gig::File* gig Line 1473  void MainWindow::load_gig(gig::File* gig
1473          add_instrument_to_menu(name);          add_instrument_to_menu(name);
1474      }      }
1475      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1476      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1477    
1478        updateSampleRefCountMap(gig);
1479    
1480      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1481          if (group->Name != "") {          if (group->Name != "") {
1482              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1483              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1484              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1485              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1486              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1487              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1167  void MainWindow::load_gig(gig::File* gig Line 1489  void MainWindow::load_gig(gig::File* gig
1489                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1490                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1491                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1492                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1493                        gig_to_utf8(sample->pInfo->Name);
1494                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1495                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1496                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1497                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1498                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1499              }              }
1500          }          }
1501      }      }
1502        
1503        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1504            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1505    
1506            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1507            Gtk::TreeModel::Row rowGroup = *iterGroup;
1508            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1509            rowGroup[m_ScriptsModel.m_col_group]  = group;
1510            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1511            for (int s = 0; group->GetScript(s); ++s) {
1512                gig::Script* script = group->GetScript(s);
1513    
1514                Gtk::TreeModel::iterator iterScript =
1515                    m_refScriptsTreeModel->append(rowGroup.children());
1516                Gtk::TreeModel::Row rowScript = *iterScript;
1517                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1518                rowScript[m_ScriptsModel.m_col_script] = script;
1519                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1520            }
1521        }
1522        // unfold all sample groups & script groups by default
1523        m_TreeViewSamples.expand_all();
1524        m_TreeViewScripts.expand_all();
1525    
1526      file = gig;      file = gig;
1527    
# Line 1180  void MainWindow::load_gig(gig::File* gig Line 1529  void MainWindow::load_gig(gig::File* gig
1529      m_TreeView.get_selection()->select(Gtk::TreePath("0"));      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1530    
1531      instr_props_set_instrument();      instr_props_set_instrument();
1532        gig::Instrument* instrument = get_instrument();
1533        if (instrument) {
1534            midiRules.set_instrument(instrument);
1535        }
1536  }  }
1537    
1538  bool MainWindow::instr_props_set_instrument()  bool MainWindow::instr_props_set_instrument()
# Line 1221  void MainWindow::instr_name_changed_by_i Line 1574  void MainWindow::instr_name_changed_by_i
1574      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
1575    
1576      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
1577      if (instrument->pInfo->Name != name) {      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1578          row[m_Columns.m_col_name] = instrument->pInfo->Name;      if (gigname != name) {
1579            row[m_Columns.m_col_name] = gigname;
1580      }      }
1581  }  }
1582    
1583    void MainWindow::show_midi_rules()
1584    {
1585        if (gig::Instrument* instrument = get_instrument())
1586        {
1587            midiRules.set_instrument(instrument);
1588            midiRules.show();
1589            midiRules.deiconify();
1590        }
1591    }
1592    
1593    void MainWindow::show_script_slots() {
1594        if (!file) return;
1595        // get selected instrument
1596        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1597        Gtk::TreeModel::iterator it = sel->get_selected();
1598        if (!it) return;
1599        Gtk::TreeModel::Row row = *it;
1600        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1601        if (!instrument) return;
1602    
1603        ScriptSlots* window = new ScriptSlots;
1604        window->setInstrument(instrument);
1605        //window->reparent(*this);
1606        window->show();
1607    }
1608    
1609  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1610      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1611          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1237  void MainWindow::on_action_view_status_b Line 1617  void MainWindow::on_action_view_status_b
1617      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1618  }  }
1619    
1620    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1621        Gtk::CheckMenuItem* item =
1622            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1623        if (!item) {
1624            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1625            return true;
1626        }
1627        return item->get_active();
1628    }
1629    
1630    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1631        Gtk::CheckMenuItem* item =
1632            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1633        if (!item) {
1634            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1635            return true;
1636        }
1637        return item->get_active();
1638    }
1639    
1640    bool MainWindow::is_copy_samples_loop_enabled() const {
1641        Gtk::CheckMenuItem* item =
1642            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1643        if (!item) {
1644            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1645            return true;
1646        }
1647        return item->get_active();
1648    }
1649    
1650  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1651  {  {
1652      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1653          show_instr_props();          show_instr_props();
1654      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1655            // gig v2 files have no midi rules
1656            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1657            static_cast<Gtk::MenuItem*>(
1658                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1659                    bEnabled
1660                );
1661            static_cast<Gtk::MenuItem*>(
1662                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1663                    bEnabled
1664                );
1665          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1666      }      }
1667  }  }
# Line 1275  void MainWindow::on_sample_treeview_butt Line 1695  void MainWindow::on_sample_treeview_butt
1695              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
1696              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
1697          }          }
1698            
1699                
1700          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
1701              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1702          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
1703              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1704          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1705              set_sensitive(file);              set_sensitive(file);
1706            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
1707                set_sensitive(sample_selected);
1708          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1709              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1710          // show sample popup          // show sample popup
1711          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
1712    
1713            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
1714                set_sensitive(group_selected || sample_selected);
1715            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
1716                set_sensitive(group_selected || sample_selected);
1717            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
1718                set_sensitive(file);
1719            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
1720                set_sensitive(sample_selected);
1721            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
1722                set_sensitive(group_selected || sample_selected);
1723      }      }
1724  }  }
1725    
1726    void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1727        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1728            Gtk::Menu* script_popup =
1729                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1730            // update enabled/disabled state of sample popup items
1731            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1732            Gtk::TreeModel::iterator it = sel->get_selected();
1733            bool group_selected  = false;
1734            bool script_selected = false;
1735            if (it) {
1736                Gtk::TreeModel::Row row = *it;
1737                group_selected  = row[m_ScriptsModel.m_col_group];
1738                script_selected = row[m_ScriptsModel.m_col_script];
1739            }
1740            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1741                set_sensitive(group_selected || script_selected);
1742            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1743                set_sensitive(file);
1744            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1745                set_sensitive(script_selected);    
1746            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1747                set_sensitive(group_selected || script_selected);
1748            // show sample popup
1749            script_popup->popup(button->button, button->time);
1750    
1751            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
1752                set_sensitive(group_selected || script_selected);
1753            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
1754                set_sensitive(file);
1755            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
1756                set_sensitive(script_selected);    
1757            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
1758                set_sensitive(group_selected || script_selected);
1759        }
1760    }
1761    
1762  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1763      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
# Line 1322  void MainWindow::remove_instrument_from_ Line 1792  void MainWindow::remove_instrument_from_
1792  }  }
1793    
1794  void MainWindow::add_instrument(gig::Instrument* instrument) {  void MainWindow::add_instrument(gig::Instrument* instrument) {
1795      const char* name = instrument->pInfo->Name.c_str();      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1796    
1797      // update instrument tree view      // update instrument tree view
1798      instrument_name_connection.block();      instrument_name_connection.block();
# Line 1344  void MainWindow::on_action_add_instrumen Line 1814  void MainWindow::on_action_add_instrumen
1814      if (!file) return;      if (!file) return;
1815      gig::Instrument* instrument = file->AddInstrument();      gig::Instrument* instrument = file->AddInstrument();
1816      __instrument_indexer++;      __instrument_indexer++;
1817      instrument->pInfo->Name =      instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1818          _("Unnamed Instrument ") + ToString(__instrument_indexer);                                              ToString(__instrument_indexer));
1819    
1820      add_instrument(instrument);      add_instrument(instrument);
1821  }  }
# Line 1365  void MainWindow::on_action_duplicate_ins Line 1835  void MainWindow::on_action_duplicate_ins
1835      // duplicate the orginal instrument      // duplicate the orginal instrument
1836      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1837      instrNew->pInfo->Name =      instrNew->pInfo->Name =
1838          instrOrig->pInfo->Name + " (" + _("Copy") + ")";          instrOrig->pInfo->Name +
1839            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1840    
1841      add_instrument(instrNew);      add_instrument(instrNew);
1842  }  }
# Line 1413  void MainWindow::on_action_remove_instru Line 1884  void MainWindow::on_action_remove_instru
1884              }              }
1885  #endif  #endif
1886              instr_props_set_instrument();              instr_props_set_instrument();
1887                instr = get_instrument();
1888                if (instr) {
1889                    midiRules.set_instrument(instr);
1890                } else {
1891                    midiRules.hide();
1892                }
1893          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1894              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1895              msg.run();              msg.run();
# Line 1428  void MainWindow::on_action_sample_proper Line 1905  void MainWindow::on_action_sample_proper
1905      msg.run();      msg.run();
1906  }  }
1907    
1908    void MainWindow::on_action_add_script_group() {
1909        static int __script_indexer = 0;
1910        if (!file) return;
1911        gig::ScriptGroup* group = file->AddScriptGroup();
1912        group->Name = gig_from_utf8(_("Unnamed Group"));
1913        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1914        __script_indexer++;
1915        // update sample tree view
1916        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1917        Gtk::TreeModel::Row rowGroup = *iterGroup;
1918        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1919        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1920        rowGroup[m_ScriptsModel.m_col_group] = group;
1921        file_changed();
1922    }
1923    
1924    void MainWindow::on_action_add_script() {
1925        if (!file) return;
1926        // get selected group
1927        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1928        Gtk::TreeModel::iterator it = sel->get_selected();
1929        if (!it) return;
1930        Gtk::TreeModel::Row row = *it;
1931        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1932        if (!group) { // not a group, but a script is selected (probably)
1933            gig::Script* script = row[m_ScriptsModel.m_col_script];
1934            if (!script) return;
1935            it = row.parent(); // resolve parent (that is the script's group)
1936            if (!it) return;
1937            row = *it;
1938            group = row[m_ScriptsModel.m_col_group];
1939            if (!group) return;
1940        }
1941    
1942        // add a new script to the .gig file
1943        gig::Script* script = group->AddScript();    
1944        Glib::ustring name = _("Unnamed Script");
1945        script->Name = gig_from_utf8(name);
1946    
1947        // add script to the tree view
1948        Gtk::TreeModel::iterator iterScript =
1949            m_refScriptsTreeModel->append(row.children());
1950        Gtk::TreeModel::Row rowScript = *iterScript;
1951        rowScript[m_ScriptsModel.m_col_name] = name;
1952        rowScript[m_ScriptsModel.m_col_script] = script;
1953        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1954    
1955        // unfold group of new script item in treeview
1956        Gtk::TreeModel::Path path(iterScript);
1957        m_TreeViewScripts.expand_to_path(path);
1958    }
1959    
1960    void MainWindow::on_action_edit_script() {
1961        if (!file) return;
1962        // get selected script
1963        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1964        Gtk::TreeModel::iterator it = sel->get_selected();
1965        if (!it) return;
1966        Gtk::TreeModel::Row row = *it;
1967        gig::Script* script = row[m_ScriptsModel.m_col_script];
1968        if (!script) return;
1969    
1970        ScriptEditor* editor = new ScriptEditor;
1971        editor->setScript(script);
1972        //editor->reparent(*this);
1973        editor->show();
1974    }
1975    
1976    void MainWindow::on_action_remove_script() {
1977        if (!file) return;
1978        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1979        Gtk::TreeModel::iterator it = sel->get_selected();
1980        if (it) {
1981            Gtk::TreeModel::Row row = *it;
1982            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1983            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1984            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1985            try {
1986                // remove script group or script from the gig file
1987                if (group) {
1988                    // notify everybody that we're going to remove these samples
1989    //TODO:         scripts_to_be_removed_signal.emit(members);
1990                    // delete the group in the .gig file including the
1991                    // samples that belong to the group
1992                    file->DeleteScriptGroup(group);
1993                    // notify that we're done with removal
1994    //TODO:         scripts_removed_signal.emit();
1995                    file_changed();
1996                } else if (script) {
1997                    // notify everybody that we're going to remove this sample
1998    //TODO:         std::list<gig::Script*> lscripts;
1999    //TODO:         lscripts.push_back(script);
2000    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2001                    // remove sample from the .gig file
2002                    script->GetGroup()->DeleteScript(script);
2003                    // notify that we're done with removal
2004    //TODO:         scripts_removed_signal.emit();
2005                    dimreg_changed();
2006                    file_changed();
2007                }
2008                // remove respective row(s) from samples tree view
2009                m_refScriptsTreeModel->erase(it);
2010            } catch (RIFF::Exception e) {
2011                // pretend we're done with removal (i.e. to avoid dead locks)
2012    //TODO:     scripts_removed_signal.emit();
2013                // show error message
2014                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2015                msg.run();
2016            }
2017        }
2018    }
2019    
2020  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2021      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2022      if (!file) return;      if (!file) return;
2023      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
2024      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
2025      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
2026      __sample_indexer++;      __sample_indexer++;
2027      // update sample tree view      // update sample tree view
2028      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
2029      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
2030      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
2031      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
2032      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
2033      file_changed();      file_changed();
# Line 1547  void MainWindow::on_action_add_sample() Line 2136  void MainWindow::on_action_add_sample()
2136                          break;                          break;
2137                      }                      }
2138                  }                  }
2139                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
2140                  sample->Channels = info.channels;                  sample->Channels = info.channels;
2141                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
2142                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1561  void MainWindow::on_action_add_sample() Line 2150  void MainWindow::on_action_add_sample()
2150                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
2151                  {                  {
2152                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
2153                        sample->FineTune      = instrument.detune;
2154    
2155                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
2156                          sample->Loops = 1;                          sample->Loops = 1;
# Line 1598  void MainWindow::on_action_add_sample() Line 2188  void MainWindow::on_action_add_sample()
2188                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
2189                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
2190                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
2191                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
2192                        gig_to_utf8(sample->pInfo->Name);
2193                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
2194                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
2195                  // close sound file                  // close sound file
# Line 1669  void MainWindow::on_action_replace_all_s Line 2260  void MainWindow::on_action_replace_all_s
2260               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
2261          {          {
2262              std::string filename =              std::string filename =
2263                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
2264                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2265                                             postfixEntryBox.get_text());
2266              SF_INFO info;              SF_INFO info;
2267              info.format = 0;              info.format = 0;
2268              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1704  void MainWindow::on_action_replace_all_s Line 2296  void MainWindow::on_action_replace_all_s
2296              catch (std::string what)              catch (std::string what)
2297              {              {
2298                  if (!error_files.empty()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2299                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
2300                        " (" + what + ")";
2301              }              }
2302          }          }
2303          // 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
# Line 1729  void MainWindow::on_action_remove_sample Line 2322  void MainWindow::on_action_remove_sample
2322          try {          try {
2323              // remove group or sample from the gig file              // remove group or sample from the gig file
2324              if (group) {              if (group) {
2325                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2326                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2327                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2328                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1793  void MainWindow::on_action_remove_sample Line 2386  void MainWindow::on_action_remove_sample
2386      }      }
2387  }  }
2388    
2389    // see comment on on_sample_treeview_drag_begin()
2390    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2391    {
2392        first_call_to_drag_data_get = true;
2393    }
2394    
2395    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2396                                                       Gtk::SelectionData& selection_data, guint, guint)
2397    {
2398        if (!first_call_to_drag_data_get) return;
2399        first_call_to_drag_data_get = false;
2400    
2401        // get selected script
2402        gig::Script* script = NULL;
2403        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2404        Gtk::TreeModel::iterator it = sel->get_selected();
2405        if (it) {
2406            Gtk::TreeModel::Row row = *it;
2407            script = row[m_ScriptsModel.m_col_script];
2408        }
2409        // pass the gig::Script as pointer
2410        selection_data.set(selection_data.get_target(), 0/*unused*/,
2411                           (const guchar*)&script,
2412                           sizeof(script)/*length of data in bytes*/);
2413    }
2414    
2415  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2416  // 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
2417  // 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 1851  void MainWindow::on_sample_label_drop_dr Line 2470  void MainWindow::on_sample_label_drop_dr
2470          bool channels_changed = false;          bool channels_changed = false;
2471          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2472              // remove the samplechannel dimension              // remove the samplechannel dimension
2473    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2474              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2475              channels_changed = true;              channels_changed = true;
2476              region_changed();              region_changed();
2477    */
2478          }          }
2479          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2480                sample,
2481                is_copy_samples_unity_note_enabled(),
2482                is_copy_samples_fine_tune_enabled(),
2483                is_copy_samples_loop_enabled()
2484            );
2485    
2486          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2487              // add samplechannel dimension              // add samplechannel dimension
# Line 1898  void MainWindow::sample_name_changed(con Line 2524  void MainWindow::sample_name_changed(con
2524      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2525      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2526      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2527        gig::String gigname(gig_from_utf8(name));
2528      if (group) {      if (group) {
2529          if (group->Name != name) {          if (group->Name != gigname) {
2530              group->Name = name;              group->Name = gigname;
2531              printf("group name changed\n");              printf("group name changed\n");
2532              file_changed();              file_changed();
2533          }          }
2534      } else if (sample) {      } else if (sample) {
2535          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2536              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2537              printf("sample name changed\n");              printf("sample name changed\n");
2538              file_changed();              file_changed();
2539          }          }
2540      }      }
2541  }  }
2542    
2543    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2544                                         const Gtk::TreeModel::iterator& iter) {
2545        if (!iter) return;
2546        Gtk::TreeModel::Row row = *iter;
2547        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2548        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2549        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2550        gig::String gigname(gig_from_utf8(name));
2551        if (group) {
2552            if (group->Name != gigname) {
2553                group->Name = gigname;
2554                printf("script group name changed\n");
2555                file_changed();
2556            }
2557        } else if (script) {
2558            if (script->Name != gigname) {
2559                script->Name = gigname;
2560                printf("script name changed\n");
2561                file_changed();
2562            }
2563        }
2564    }
2565    
2566  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2567                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2568      if (!iter) return;      if (!iter) return;
# Line 1934  void MainWindow::instrument_name_changed Line 2584  void MainWindow::instrument_name_changed
2584    
2585      // change name in gig      // change name in gig
2586      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2587      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2588          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2589            instrument->pInfo->Name = gigname;
2590    
2591          // change name in the instrument properties window          // change name in the instrument properties window
2592          if (instrumentProps.get_instrument() == instrument) {          if (instrumentProps.get_instrument() == instrument) {
# Line 1946  void MainWindow::instrument_name_changed Line 2597  void MainWindow::instrument_name_changed
2597      }      }
2598  }  }
2599    
2600    void MainWindow::on_action_combine_instruments() {
2601        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2602        d->show_all();
2603        d->resize(500, 400);
2604        d->run();
2605        if (d->fileWasChanged()) {
2606            // update GUI with new instrument just created
2607            add_instrument(d->newCombinedInstrument());
2608        }
2609        delete d;
2610    }
2611    
2612    void MainWindow::on_action_view_references() {
2613        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2614        Gtk::TreeModel::iterator it = sel->get_selected();
2615        if (!it) return;
2616        Gtk::TreeModel::Row row = *it;
2617        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2618        if (!sample) return;
2619    
2620        ReferencesView* d = new ReferencesView(*this);
2621        d->setSample(sample);
2622        d->show_all();
2623        d->resize(500, 400);
2624        d->run();
2625        delete d;
2626    }
2627    
2628    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2629        struct _Source {
2630            std::vector<RIFF::File*> riffs;
2631            std::vector<gig::File*> gigs;
2632            
2633            ~_Source() {
2634                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2635                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2636                riffs.clear();
2637                gigs.clear();
2638            }
2639        } sources;
2640    
2641        if (filenames.empty())
2642            throw RIFF::Exception(_("No files selected, so nothing done."));
2643    
2644        // first open all input files (to avoid output file corruption)
2645        int i;
2646        try {
2647            for (i = 0; i < filenames.size(); ++i) {
2648                const std::string& filename = filenames[i];
2649                printf("opening file=%s\n", filename.c_str());
2650    
2651                RIFF::File* riff = new RIFF::File(filename);
2652                sources.riffs.push_back(riff);
2653    
2654                gig::File* gig = new gig::File(riff);
2655                sources.gigs.push_back(gig);
2656            }
2657        } catch (RIFF::Exception e) {
2658            throw RIFF::Exception(
2659                _("Error occurred while opening '") +
2660                filenames[i] +
2661                "': " +
2662                e.Message
2663            );
2664        } catch (...) {
2665            throw RIFF::Exception(
2666                _("Unknown exception occurred while opening '") +
2667                filenames[i] + "'"
2668            );
2669        }
2670    
2671        // now merge the opened .gig files to the main .gig file currently being
2672        // open in gigedit
2673        try {
2674            for (i = 0; i < filenames.size(); ++i) {
2675                const std::string& filename = filenames[i];
2676                printf("merging file=%s\n", filename.c_str());
2677                assert(i < sources.gigs.size());
2678    
2679                this->file->AddContentOf(sources.gigs[i]);
2680            }
2681        } catch (RIFF::Exception e) {
2682            throw RIFF::Exception(
2683                _("Error occurred while merging '") +
2684                filenames[i] +
2685                "': " +
2686                e.Message
2687            );
2688        } catch (...) {
2689            throw RIFF::Exception(
2690                _("Unknown exception occurred while merging '") +
2691                filenames[i] + "'"
2692            );
2693        }
2694    
2695        // Note: requires that this file already has a filename !
2696        this->file->Save();
2697    }
2698    
2699    void MainWindow::on_action_merge_files() {
2700        if (this->file->GetFileName().empty()) {
2701            Glib::ustring txt = _(
2702                "You seem to have a new .gig file open that has not been saved "
2703                "yet. You must save it somewhere before starting to merge it with "
2704                "other .gig files though, because during the merge operation the "
2705                "other files' sample data must be written on file level to the "
2706                "target .gig file."
2707            );
2708            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2709            msg.run();
2710            return;
2711        }
2712    
2713        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2714        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2715        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2716        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2717    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2718        Gtk::FileFilter filter;
2719        filter.add_pattern("*.gig");
2720    #else
2721        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2722        filter->add_pattern("*.gig");
2723    #endif
2724        dialog.set_filter(filter);
2725        if (current_gig_dir != "") {
2726            dialog.set_current_folder(current_gig_dir);
2727        }
2728        dialog.set_select_multiple(true);
2729    
2730        // show warning in the file picker dialog
2731        Gtk::HBox descriptionArea;
2732        descriptionArea.set_spacing(15);
2733        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2734        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2735    #if GTKMM_MAJOR_VERSION < 3
2736        view::WrapLabel description;
2737    #else
2738        Gtk::Label description;
2739        description.set_line_wrap();
2740    #endif
2741        description.set_markup(_(
2742            "\nSelect at least one .gig file that shall be merged to the .gig file "
2743            "currently being open in gigedit.\n\n"
2744            "<b>Please Note:</b> Merging with other files will modify your "
2745            "currently open .gig file on file level! And be aware that the current "
2746            "merge algorithm does not detect duplicate samples yet. So if you are "
2747            "merging files which are using equivalent sample data, those "
2748            "equivalent samples will currently be treated as separate samples and "
2749            "will accordingly be stored separately in the target .gig file!"
2750        ));
2751        descriptionArea.pack_start(description);
2752        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2753        descriptionArea.show_all();
2754    
2755        if (dialog.run() == Gtk::RESPONSE_OK) {
2756            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2757            std::vector<std::string> filenames = dialog.get_filenames();
2758    
2759            // merge the selected files to the currently open .gig file
2760            try {
2761                mergeFiles(filenames);
2762            } catch (RIFF::Exception e) {
2763                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2764                msg.run();
2765            }
2766    
2767            // update GUI
2768            __refreshEntireGUI();        
2769        }
2770    }
2771    
2772  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2773      this->file_is_shared = b;      this->file_is_shared = b;
2774    
# Line 1962  void MainWindow::set_file_is_shared(bool Line 2785  void MainWindow::set_file_is_shared(bool
2785      }      }
2786  }  }
2787    
2788    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2789        if (!sample) return;
2790        sample_ref_count[sample] += offset;
2791        const int refcount = sample_ref_count[sample];
2792    
2793        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2794        for (int g = 0; g < model->children().size(); ++g) {
2795            Gtk::TreeModel::Row rowGroup = model->children()[g];
2796            for (int s = 0; s < rowGroup.children().size(); ++s) {
2797                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2798                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2799                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2800                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
2801            }
2802        }
2803    }
2804    
2805    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2806        on_sample_ref_count_incremented(oldSample, -1);
2807        on_sample_ref_count_incremented(newSample, +1);
2808    }
2809    
2810    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2811        // just in case a new sample is added later with exactly the same memory
2812        // address, which would lead to incorrect refcount if not deleted here
2813        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2814             it != samples.end(); it != samples.end())
2815        {
2816            sample_ref_count.erase(*it);
2817        }
2818    }
2819    
2820    void MainWindow::show_samples_tab() {
2821        m_TreeViewNotebook.set_current_page(0);
2822    }
2823    
2824    void MainWindow::show_intruments_tab() {
2825        m_TreeViewNotebook.set_current_page(1);
2826    }
2827    
2828    void MainWindow::show_scripts_tab() {
2829        m_TreeViewNotebook.set_current_page(2);
2830    }
2831    
2832  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2833      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2834  }  }

Legend:
Removed from v.2445  
changed lines
  Added in v.2625

  ViewVC Help
Powered by ViewVC