/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2398 by persson, Sun Jan 13 09:14:29 2013 UTC revision 2604 by schoenebeck, Sat Jun 7 22:34:31 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2013 Andreas Persson   * Copyright (C) 2006-2014 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 30  Line 30 
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
 #include <gtkmm/radiomenuitem.h>  
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
35  #include "wrapLabel.hh"  #include "wrapLabel.hh"
# Line 41  Line 40 
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46    #include "Settings.h"
47    #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
50  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
51    
 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++;  
 }  
52    
53  MainWindow::MainWindow() :  MainWindow::MainWindow() :
54      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
# Line 91  MainWindow::MainWindow() : Line 63  MainWindow::MainWindow() :
63      add(m_VBox);      add(m_VBox);
64    
65      // Handle selection      // Handle selection
66      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
67          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
68    
69      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 108  MainWindow::MainWindow() : Line 79  MainWindow::MainWindow() :
79      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
80      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
81    
82        m_ScrolledWindowScripts.add(m_TreeViewScripts);
83        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
84    
85    
86      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
87    
# Line 121  MainWindow::MainWindow() : Line 95  MainWindow::MainWindow() :
95      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
96      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
97    
98        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
99        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."));
100        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."));
101        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)."));
102    
103      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
104      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
105        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
106    
107      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
108    
# Line 155  MainWindow::MainWindow() : Line 133  MainWindow::MainWindow() :
133                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
134                       sigc::mem_fun(                       sigc::mem_fun(
135                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
136        actionGroup->add(Gtk::Action::create("MidiRules",
137                                             _("_Midi Rules")),
138                         sigc::mem_fun(
139                             *this, &MainWindow::show_midi_rules));
140      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
141                       sigc::mem_fun(                       sigc::mem_fun(
142                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
143      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
144    
145      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
146        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
147    
148      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
149            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
150        toggle_action->set_active(true);
151        actionGroup->add(toggle_action);
152    
153        toggle_action =
154            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
155        toggle_action->set_active(true);
156        actionGroup->add(toggle_action);
157    
158        toggle_action =
159            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
160        toggle_action->set_active(true);
161        actionGroup->add(toggle_action);
162    
163    
164        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
165        toggle_action =
166          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
167      toggle_action->set_active(true);      toggle_action->set_active(true);
168      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 187  MainWindow::MainWindow() : Line 188  MainWindow::MainWindow() :
188          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
189      );      );
190    
191    
192        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
193        
194        toggle_action =
195            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
196        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
197        actionGroup->add(
198            toggle_action,
199            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
200        );
201    
202    
203        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
204    
205        actionGroup->add(
206            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
207            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
208        );
209    
210        actionGroup->add(
211            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
212            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
213        );
214    
215    
216      // sample right-click popup actions      // sample right-click popup actions
217      actionGroup->add(      actionGroup->add(
218          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 209  MainWindow::MainWindow() : Line 235  MainWindow::MainWindow() :
235                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
236          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)
237      );      );
238        
239        // script right-click popup actions
240        actionGroup->add(
241            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
242            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
243        );
244        actionGroup->add(
245            Gtk::Action::create("AddScript", _("Add _Script")),
246            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
247        );
248        actionGroup->add(
249            Gtk::Action::create("EditScript", _("_Edit Script...")),
250            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
251        );
252        actionGroup->add(
253            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
254            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
255        );
256    
257      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
258      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 228  MainWindow::MainWindow() : Line 272  MainWindow::MainWindow() :
272          "      <separator/>"          "      <separator/>"
273          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
274          "    </menu>"          "    </menu>"
275            "    <menu action='MenuEdit'>"
276            "      <menuitem action='CopySampleUnity'/>"
277            "      <menuitem action='CopySampleTune'/>"
278            "      <menuitem action='CopySampleLoop'/>"
279            "    </menu>"
280          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
281          "    </menu>"          "    </menu>"
282          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
283          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
284          "    </menu>"          "    </menu>"
285            "    <menu action='MenuTools'>"
286            "      <menuitem action='CombineInstruments'/>"
287            "      <menuitem action='MergeFiles'/>"
288            "    </menu>"
289            "    <menu action='MenuSettings'>"
290            "      <menuitem action='WarnUserOnExtensions'/>"
291            "    </menu>"
292          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
293          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
294          "    </menu>"          "    </menu>"
295          "  </menubar>"          "  </menubar>"
296          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
297          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
298            "    <menuitem action='MidiRules'/>"
299          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
300          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
301          "    <separator/>"          "    <separator/>"
# Line 248  MainWindow::MainWindow() : Line 305  MainWindow::MainWindow() :
305          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
306          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
307          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
308          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
309          "    <separator/>"          "    <separator/>"
310          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
311          "  </popup>"          "  </popup>"
312            "  <popup name='ScriptPopupMenu'>"
313            "    <menuitem action='AddScriptGroup'/>"
314            "    <menuitem action='AddScript'/>"
315            "    <menuitem action='EditScript'/>"
316            "    <separator/>"
317            "    <menuitem action='RemoveScript'/>"
318            "  </popup>"
319          "</ui>";          "</ui>";
320      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
321    
322      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
323        
324        // Set tooltips for menu items (for some reason, setting a tooltip on the
325        // respective Gtk::Action objects above will simply be ignored, no matter
326        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
327        // Gtk::Action::create()).
328        {
329            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
330                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
331            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."));
332        }
333        {
334            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
335                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
336            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."));
337        }
338        {
339            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
340                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
341            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."));
342        }
343        {
344            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
345                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
346            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."));
347        }
348        {
349            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
350                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
351            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
352        }
353        {
354            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
355                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
356            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
357        }
358    
359    
360        instrument_menu = static_cast<Gtk::MenuItem*>(
361            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
362    
363      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
364      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 281  MainWindow::MainWindow() : Line 384  MainWindow::MainWindow() :
384      // Create the Tree model:      // Create the Tree model:
385      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
386      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
387      m_refTreeModel->signal_row_changed().connect(      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
388        instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
389          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
390      );      );
391    
# Line 292  MainWindow::MainWindow() : Line 396  MainWindow::MainWindow() :
396      // create samples treeview (including its data model)      // create samples treeview (including its data model)
397      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
398      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
399        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."));
400      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
401      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
402      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 302  MainWindow::MainWindow() : Line 407  MainWindow::MainWindow() :
407          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
408      );      );
409    
410        // create scripts treeview (including its data model)
411        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
412        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
413        m_TreeViewScripts.set_tooltip_text(_(
414            "Note: instrument scripts are a LinuxSampler extension of the gig "
415            "format. This feature will not work with the GigaStudio software!"
416        ));
417        // m_TreeViewScripts.set_reorderable();
418        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
419        m_TreeViewScripts.set_headers_visible(false);
420        m_TreeViewScripts.signal_button_press_event().connect_notify(
421            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
422        );
423        m_refScriptsTreeModel->signal_row_changed().connect(
424            sigc::mem_fun(*this, &MainWindow::script_name_changed)
425        );
426    
427      // 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
428      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
429      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 322  MainWindow::MainWindow() : Line 444  MainWindow::MainWindow() :
444          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
445      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
446          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
447      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
448          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
449      propDialog.signal_info_changed().connect(      propDialog.signal_changed().connect(
450            sigc::mem_fun(*this, &MainWindow::file_changed));
451        midiRules.signal_changed().connect(
452          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
453    
454      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 374  MainWindow::MainWindow() : Line 498  MainWindow::MainWindow() :
498    
499      // start with a new gig file by default      // start with a new gig file by default
500      on_action_file_new();      on_action_file_new();
501    
502        // select 'Instruments' tab by default
503        // (gtk allows this only if the tab childs are visible, thats why it's here)
504        m_TreeViewNotebook.set_current_page(1);
505  }  }
506    
507  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 399  void MainWindow::region_changed() Line 527  void MainWindow::region_changed()
527  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
528  {  {
529      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
530      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
531            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
532      if (it) {      if (it) {
533          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
534          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 460  void MainWindow::dimreg_changed() Line 587  void MainWindow::dimreg_changed()
587    
588  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
589  {  {
590        // select item in instrument menu
591        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
592        if (it) {
593            Gtk::TreePath path(it);
594            int index = path[0];
595            const std::vector<Gtk::Widget*> children =
596                instrument_menu->get_children();
597            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
598        }
599    
600      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
601  }  }
602    
# Line 538  LoadDialog::LoadDialog(const Glib::ustri Line 675  LoadDialog::LoadDialog(const Glib::ustri
675  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
676  // 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.
677  void MainWindow::__clear() {  void MainWindow::__clear() {
     // remove all entries from "Instrument" menu  
     Gtk::MenuItem* instrument_menu =  
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
     instrument_menu->hide();  
     Gtk::Menu* menu = instrument_menu->get_submenu();  
     while (menu->get_children().size()) {  
         Gtk::Widget* child = *menu->get_children().begin();  
         menu->remove(*child);  
         delete child;  
     }  
678      // forget all samples that ought to be imported      // forget all samples that ought to be imported
679      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
680      // clear the samples and instruments tree views      // clear the samples and instruments tree views
681      m_refTreeModel->clear();      m_refTreeModel->clear();
682      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
683        // remove all entries from "Instrument" menu
684        while (!instrument_menu->get_children().empty()) {
685            remove_instrument_from_menu(0);
686        }
687      // free libgig's gig::File instance      // free libgig's gig::File instance
688      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
689      file = NULL;      file = NULL;
690      set_file_is_shared(false);      set_file_is_shared(false);
691  }  }
692    
693    void MainWindow::__refreshEntireGUI() {
694        // clear the samples and instruments tree views
695        m_refTreeModel->clear();
696        m_refSamplesTreeModel->clear();
697        // remove all entries from "Instrument" menu
698        while (!instrument_menu->get_children().empty()) {
699            remove_instrument_from_menu(0);
700        }
701    
702        if (!this->file) return;
703    
704        load_gig(
705            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
706        );
707    }
708    
709  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
710  {  {
711      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 718  void MainWindow::on_action_file_new()
718      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
719      // already add one new instrument by default      // already add one new instrument by default
720      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
721      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
722      // update GUI with that new gig::File      // update GUI with that new gig::File
723      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
724  }  }
# Line 904  void MainWindow::__import_queued_samples Line 1051  void MainWindow::__import_queued_samples
1051              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1052          } catch (std::string what) {          } catch (std::string what) {
1053              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1054              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1055              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
1056              ++iter;              ++iter;
1057          }          }
1058      }      }
1059      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
1060      if (error_files.size()) {      if (!error_files.empty()) {
1061          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;
1062          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1063          msg.run();          msg.run();
# Line 923  void MainWindow::on_action_file_properti Line 1070  void MainWindow::on_action_file_properti
1070      propDialog.deiconify();      propDialog.deiconify();
1071  }  }
1072    
1073    void MainWindow::on_action_warn_user_on_extensions() {
1074        Settings::singleton()->warnUserOnExtensions =
1075            !Settings::singleton()->warnUserOnExtensions;
1076    }
1077    
1078  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1079  {  {
1080      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 932  void MainWindow::on_action_help_about() Line 1084  void MainWindow::on_action_help_about()
1084      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1085  #endif  #endif
1086      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1087      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1088      dialog.set_comments(_(      const std::string sComment =
1089          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1090          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1091          "Please notice that this is still a very young instrument editor. "          _(
1092          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1093          "this application.\n"              "\n"
1094          "\n"              "Please notice that this is still a very young instrument editor. "
1095          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
1096      );              "this application.\n"
1097                "\n"
1098                "Please report bugs to: http://bugs.linuxsampler.org"
1099            );
1100        dialog.set_comments(sComment.c_str());
1101      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1102      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1103      dialog.run();      dialog.run();
1104  }  }
1105    
1106  PropDialog::PropDialog()  PropDialog::PropDialog()
1107      : eName(_("Name")),      : eFileFormat(_("File Format")),
1108          eName(_("Name")),
1109        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1110        eComments(_("Comments")),        eComments(_("Comments")),
1111        eProduct(_("Product")),        eProduct(_("Product")),
# Line 966  PropDialog::PropDialog() Line 1123  PropDialog::PropDialog()
1123        eSubject(_("Subject")),        eSubject(_("Subject")),
1124        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1125        table(2, 1),        table(2, 1),
1126        update_model(0)        m_file(NULL)
1127  {  {
1128      set_title(_("File Properties"));      set_title(_("File Properties"));
1129      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 988  PropDialog::PropDialog() Line 1145  PropDialog::PropDialog()
1145      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1146      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1147    
1148        table.add(eFileFormat);
1149      table.add(eName);      table.add(eName);
1150      table.add(eCreationDate);      table.add(eCreationDate);
1151      table.add(eComments);      table.add(eComments);
# Line 1018  PropDialog::PropDialog() Line 1176  PropDialog::PropDialog()
1176      quitButton.grab_focus();      quitButton.grab_focus();
1177      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1178          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1179        eFileFormat.signal_value_changed().connect(
1180            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1181    
1182      quitButton.show();      quitButton.show();
1183      vbox.show();      vbox.show();
1184      show_all_children();      show_all_children();
1185  }  }
1186    
1187  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_file(gig::File* file)
1188  {  {
1189      this->info = info;      m_file = file;
1190      update_model++;  
1191      eName.set_value(info->Name);      // update file format version combo box
1192      eCreationDate.set_value(info->CreationDate);      const std::string sGiga = "Gigasampler/GigaStudio v";
1193      eComments.set_value(info->Comments);      const int major = file->pVersion->major;
1194      eProduct.set_value(info->Product);      std::vector<std::string> txts;
1195      eCopyright.set_value(info->Copyright);      std::vector<int> values;
1196      eArtists.set_value(info->Artists);      txts.push_back(sGiga + "2"); values.push_back(2);
1197      eGenre.set_value(info->Genre);      txts.push_back(sGiga + "3/v4"); values.push_back(3);
1198      eKeywords.set_value(info->Keywords);      if (major != 2 && major != 3) {
1199      eEngineer.set_value(info->Engineer);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
1200      eTechnician.set_value(info->Technician);      }
1201      eSoftware.set_value(info->Software);      std::vector<const char*> texts;
1202      eMedium.set_value(info->Medium);      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1203      eSource.set_value(info->Source);      texts.push_back(NULL); values.push_back(0);
1204      eSourceForm.set_value(info->SourceForm);      eFileFormat.set_choices(&texts[0], &values[0]);
1205      eCommissioned.set_value(info->Commissioned);      eFileFormat.set_value(major);
1206      eSubject.set_value(info->Subject);  }
1207      update_model--;  
1208    void PropDialog::onFileFormatChanged() {
1209        const int major = eFileFormat.get_value();
1210        if (m_file) m_file->pVersion->major = major;
1211  }  }
1212    
1213  sigc::signal<void>& PropDialog::signal_info_changed()  void PropDialog::set_info(DLS::Info* info)
1214  {  {
1215      return info_changed;      update(info);
1216  }  }
1217    
1218  void InstrumentProps::set_IsDrum(bool value)  
1219    void InstrumentProps::set_Name(const gig::String& name)
1220  {  {
1221      instrument->IsDrum = value;      m->pInfo->Name = name;
1222  }  }
1223    
1224  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1225  {  {
1226      instrument->MIDIBank = value;      update_model++;
1227        eName.set_value(m->pInfo->Name);
1228        update_model--;
1229  }  }
1230    
1231  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1232  {  {
1233      instrument->MIDIProgram = value;      m->IsDrum = value;
1234  }  }
1235    
1236  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1237  {  {
1238      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1239  }  }
1240    
1241  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1242  {  {
1243      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1244  }  }
1245    
1246  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1247      : update_model(0),      quitButton(Gtk::Stock::CLOSE),
1248        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1249        table(2,1),      eName(_("Name")),
1250        eName(_("Name")),      eIsDrum(_("Is drum")),
1251        eIsDrum(_("Is drum")),      eMIDIBank(_("MIDI bank"), 0, 16383),
1252        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIProgram(_("MIDI program")),
1253        eMIDIProgram(_("MIDI program")),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1254        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1255        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eEffectSend(_("Effect send"), 0, 65535),
1256        eEffectSend(_("Effect send"), 0, 65535),      eFineTune(_("Fine tune"), -8400, 8400),
1257        eFineTune(_("Fine tune"), -8400, 8400),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1258        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePianoReleaseMode(_("Piano release mode")),
1259        ePianoReleaseMode(_("Piano release mode")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1260        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       eDimensionKeyRangeHigh(_("Keyswitching range high"))  
1261  {  {
1262      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1263    
# Line 1111  InstrumentProps::InstrumentProps() Line 1270  InstrumentProps::InstrumentProps()
1270            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1271      );      );
1272    
1273        connect(eName, &InstrumentProps::set_Name);
1274      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1275      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1276      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1120  InstrumentProps::InstrumentProps() Line 1280  InstrumentProps::InstrumentProps()
1280      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1281      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1282      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1283      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1284              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1285      connect(eDimensionKeyRangeHigh,  
1286              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1287    
1288      table.set_col_spacings(5);      table.set_col_spacings(5);
1289    
# Line 1162  InstrumentProps::InstrumentProps() Line 1322  InstrumentProps::InstrumentProps()
1322    
1323  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1324  {  {
1325      this->instrument = instrument;      update(instrument);
1326    
1327      update_model++;      update_model++;
1328      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1329      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1330      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1331      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);  
1332      update_model--;      update_model--;
1333  }  }
1334    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1335    
1336  void MainWindow::file_changed()  void MainWindow::file_changed()
1337  {  {
# Line 1203  void MainWindow::load_gig(gig::File* gig Line 1351  void MainWindow::load_gig(gig::File* gig
1351      file_has_name = filename;      file_has_name = filename;
1352      file_is_changed = false;      file_is_changed = false;
1353    
1354        propDialog.set_file(gig);
1355      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1356    
1357      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;  
1358      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1359           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1360            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1361    
1362          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1363          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1364          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1365          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1366          // create a menu item for this instrument  
1367          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++;  
1368      }      }
1369      instrument_menu->show();      instrument_name_connection.unblock();
1370      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1371    
1372      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1373          if (group->Name != "") {          if (group->Name != "") {
1374              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1375              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1376              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1377              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1378              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1379              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1243  void MainWindow::load_gig(gig::File* gig Line 1381  void MainWindow::load_gig(gig::File* gig
1381                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1382                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1383                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1384                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1385                        gig_to_utf8(sample->pInfo->Name);
1386                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1387                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1388              }              }
1389          }          }
1390      }      }
1391        
1392        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1393            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1394    
1395            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1396            Gtk::TreeModel::Row rowGroup = *iterGroup;
1397            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1398            rowGroup[m_ScriptsModel.m_col_group]  = group;
1399            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1400            for (int s = 0; group->GetScript(s); ++s) {
1401                gig::Script* script = group->GetScript(s);
1402    
1403                Gtk::TreeModel::iterator iterScript =
1404                    m_refScriptsTreeModel->append(rowGroup.children());
1405                Gtk::TreeModel::Row rowScript = *iterScript;
1406                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1407                rowScript[m_ScriptsModel.m_col_script] = script;
1408                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1409            }
1410        }
1411        // unfold all script groups by default
1412        m_TreeViewScripts.expand_all();
1413    
1414      file = gig;      file = gig;
1415    
1416      // select the first instrument      // select the first instrument
1417      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1418      tree_sel_ref->select(Gtk::TreePath("0"));  
1419        instr_props_set_instrument();
1420        gig::Instrument* instrument = get_instrument();
1421        if (instrument) {
1422            midiRules.set_instrument(instrument);
1423        }
1424  }  }
1425    
1426  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1427  {  {
1428      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1429      if (instrument)  
1430      {      Gtk::TreeModel::const_iterator it =
1431            m_TreeView.get_selection()->get_selected();
1432        if (it) {
1433            Gtk::TreeModel::Row row = *it;
1434            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1435    
1436          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1437    
1438            // make sure instrument tree is updated when user changes the
1439            // instrument name in instrument properties window
1440            instrumentProps.signal_name_changed().connect(
1441                sigc::bind(
1442                    sigc::mem_fun(*this,
1443                                  &MainWindow::instr_name_changed_by_instr_props),
1444                    it));
1445        } else {
1446            instrumentProps.hide();
1447        }
1448        return it;
1449    }
1450    
1451    void MainWindow::show_instr_props()
1452    {
1453        if (instr_props_set_instrument()) {
1454          instrumentProps.show();          instrumentProps.show();
1455          instrumentProps.deiconify();          instrumentProps.deiconify();
1456      }      }
1457  }  }
1458    
1459    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1460    {
1461        Gtk::TreeModel::Row row = *it;
1462        Glib::ustring name = row[m_Columns.m_col_name];
1463    
1464        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1465        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1466        if (gigname != name) {
1467            row[m_Columns.m_col_name] = gigname;
1468        }
1469    }
1470    
1471    void MainWindow::show_midi_rules()
1472    {
1473        if (gig::Instrument* instrument = get_instrument())
1474        {
1475            midiRules.set_instrument(instrument);
1476            midiRules.show();
1477            midiRules.deiconify();
1478        }
1479    }
1480    
1481  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1482      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1483          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1279  void MainWindow::on_action_view_status_b Line 1489  void MainWindow::on_action_view_status_b
1489      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1490  }  }
1491    
1492    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1493        Gtk::CheckMenuItem* item =
1494            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1495        if (!item) {
1496            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1497            return true;
1498        }
1499        return item->get_active();
1500    }
1501    
1502    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1503        Gtk::CheckMenuItem* item =
1504            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1505        if (!item) {
1506            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1507            return true;
1508        }
1509        return item->get_active();
1510    }
1511    
1512    bool MainWindow::is_copy_samples_loop_enabled() const {
1513        Gtk::CheckMenuItem* item =
1514            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1515        if (!item) {
1516            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1517            return true;
1518        }
1519        return item->get_active();
1520    }
1521    
1522  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1523  {  {
1524      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1525          show_instr_props();          show_instr_props();
1526      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1527            // gig v2 files have no midi rules
1528            static_cast<Gtk::MenuItem*>(
1529                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1530                    !(file->pVersion && file->pVersion->major == 2));
1531          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1532      }      }
1533  }  }
1534    
1535  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1536      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1537            const std::vector<Gtk::Widget*> children =
1538                instrument_menu->get_children();
1539            std::vector<Gtk::Widget*>::const_iterator it =
1540                find(children.begin(), children.end(), item);
1541            if (it != children.end()) {
1542                int index = it - children.begin();
1543                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1544    
1545                m_RegionChooser.set_instrument(file->GetInstrument(index));
1546            }
1547        }
1548  }  }
1549    
1550  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1319  void MainWindow::on_sample_treeview_butt Line 1574  void MainWindow::on_sample_treeview_butt
1574      }      }
1575  }  }
1576    
1577  void MainWindow::on_action_add_instrument() {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1578      static int __instrument_indexer = 0;      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1579      if (!file) return;          Gtk::Menu* script_popup =
1580      gig::Instrument* instrument = file->AddInstrument();              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1581      __instrument_indexer++;          // update enabled/disabled state of sample popup items
1582      instrument->pInfo->Name =          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1583          _("Unnamed Instrument ") + ToString(__instrument_indexer);          Gtk::TreeModel::iterator it = sel->get_selected();
1584            bool group_selected  = false;
1585            bool script_selected = false;
1586            if (it) {
1587                Gtk::TreeModel::Row row = *it;
1588                group_selected  = row[m_ScriptsModel.m_col_group];
1589                script_selected = row[m_ScriptsModel.m_col_script];
1590            }
1591            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1592                set_sensitive(group_selected || script_selected);
1593            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1594                set_sensitive(file);
1595            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1596                set_sensitive(script_selected);    
1597            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1598                set_sensitive(group_selected || script_selected);
1599            // show sample popup
1600            script_popup->popup(button->button, button->time);
1601        }
1602    }
1603    
1604    Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1605        const Glib::ustring& name, int position) {
1606    
1607        Gtk::RadioMenuItem::Group instrument_group;
1608        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1609        if (!children.empty()) {
1610            instrument_group =
1611                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1612        }
1613        Gtk::RadioMenuItem* item =
1614            new Gtk::RadioMenuItem(instrument_group, name);
1615        if (position < 0) {
1616            instrument_menu->append(*item);
1617        } else {
1618            instrument_menu->insert(*item, position);
1619        }
1620        item->show();
1621        item->signal_activate().connect(
1622            sigc::bind(
1623                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1624                item));
1625        return item;
1626    }
1627    
1628    void MainWindow::remove_instrument_from_menu(int index) {
1629        const std::vector<Gtk::Widget*> children =
1630            instrument_menu->get_children();
1631        Gtk::Widget* child = children[index];
1632        instrument_menu->remove(*child);
1633        delete child;
1634    }
1635    
1636    void MainWindow::add_instrument(gig::Instrument* instrument) {
1637        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1638    
1639      // update instrument tree view      // update instrument tree view
1640        instrument_name_connection.block();
1641      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1642      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1643      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1644      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1645        instrument_name_connection.unblock();
1646    
1647        add_instrument_to_menu(name);
1648    
1649        m_TreeView.get_selection()->select(iterInstr);
1650    
1651      file_changed();      file_changed();
1652  }  }
1653    
1654    void MainWindow::on_action_add_instrument() {
1655        static int __instrument_indexer = 0;
1656        if (!file) return;
1657        gig::Instrument* instrument = file->AddInstrument();
1658        __instrument_indexer++;
1659        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1660                                                ToString(__instrument_indexer));
1661    
1662        add_instrument(instrument);
1663    }
1664    
1665  void MainWindow::on_action_duplicate_instrument() {  void MainWindow::on_action_duplicate_instrument() {
1666      if (!file) return;      if (!file) return;
1667        
1668      // retrieve the currently selected instrument      // retrieve the currently selected instrument
1669      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
1670      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
# Line 1345  void MainWindow::on_action_duplicate_ins Line 1673  void MainWindow::on_action_duplicate_ins
1673      Gtk::TreeModel::Row row = *itSelection;      Gtk::TreeModel::Row row = *itSelection;
1674      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1675      if (!instrOrig) return;      if (!instrOrig) return;
1676        
1677      // duplicate the orginal instrument      // duplicate the orginal instrument
1678      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1679      instrNew->pInfo->Name =      instrNew->pInfo->Name =
1680          instrOrig->pInfo->Name + " (" + _("Copy") + ")";          instrOrig->pInfo->Name +
1681                    gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1682      // update instrument tree view  
1683      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      add_instrument(instrNew);
     Gtk::TreeModel::Row rowInstr = *iterInstr;  
     rowInstr[m_Columns.m_col_name] = instrNew->pInfo->Name.c_str();  
     rowInstr[m_Columns.m_col_instr] = instrNew;  
     file_changed();  
1684  }  }
1685    
1686  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 1378  void MainWindow::on_action_remove_instru Line 1702  void MainWindow::on_action_remove_instru
1702          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1703          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1704          try {          try {
1705                Gtk::TreePath path(it);
1706                int index = path[0];
1707    
1708              // remove instrument from the gig file              // remove instrument from the gig file
1709              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1710              file_changed();              file_changed();
1711    
1712                remove_instrument_from_menu(index);
1713    
1714                // remove row from instruments tree view
1715                m_refTreeModel->erase(it);
1716    
1717    #if GTKMM_MAJOR_VERSION < 3
1718                // select another instrument (in gtk3 this is done
1719                // automatically)
1720                if (!m_refTreeModel->children().empty()) {
1721                    if (index == m_refTreeModel->children().size()) {
1722                        index--;
1723                    }
1724                    m_TreeView.get_selection()->select(
1725                        Gtk::TreePath(ToString(index)));
1726                }
1727    #endif
1728                instr_props_set_instrument();
1729                instr = get_instrument();
1730                if (instr) {
1731                    midiRules.set_instrument(instr);
1732                } else {
1733                    midiRules.hide();
1734                }
1735          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1736              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1737              msg.run();              msg.run();
# Line 1398  void MainWindow::on_action_sample_proper Line 1747  void MainWindow::on_action_sample_proper
1747      msg.run();      msg.run();
1748  }  }
1749    
1750    void MainWindow::on_action_add_script_group() {
1751        static int __script_indexer = 0;
1752        if (!file) return;
1753        gig::ScriptGroup* group = file->AddScriptGroup();
1754        group->Name = gig_from_utf8(_("Unnamed Group"));
1755        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1756        __script_indexer++;
1757        // update sample tree view
1758        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1759        Gtk::TreeModel::Row rowGroup = *iterGroup;
1760        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1761        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1762        rowGroup[m_ScriptsModel.m_col_group] = group;
1763        file_changed();
1764    }
1765    
1766    void MainWindow::on_action_add_script() {
1767        if (!file) return;
1768        // get selected group
1769        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1770        Gtk::TreeModel::iterator it = sel->get_selected();
1771        if (!it) return;
1772        Gtk::TreeModel::Row row = *it;
1773        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1774        if (!group) { // not a group, but a script is selected (probably)
1775            gig::Script* script = row[m_ScriptsModel.m_col_script];
1776            if (!script) return;
1777            it = row.parent(); // resolve parent (that is the script's group)
1778            if (!it) return;
1779            row = *it;
1780            group = row[m_ScriptsModel.m_col_group];
1781            if (!group) return;
1782        }
1783    
1784        // add a new script to the .gig file
1785        gig::Script* script = group->AddScript();    
1786        Glib::ustring name = _("Unnamed Script");
1787        script->Name = gig_from_utf8(name);
1788    
1789        // add script to the tree view
1790        Gtk::TreeModel::iterator iterScript =
1791            m_refScriptsTreeModel->append(row.children());
1792        Gtk::TreeModel::Row rowScript = *iterScript;
1793        rowScript[m_ScriptsModel.m_col_name] = name;
1794        rowScript[m_ScriptsModel.m_col_script] = script;
1795        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1796    
1797        // unfold group of new script item in treeview
1798        Gtk::TreeModel::Path path(iterScript);
1799        m_TreeViewScripts.expand_to_path(path);
1800    }
1801    
1802    void MainWindow::on_action_edit_script() {
1803        if (!file) return;
1804        // get selected script
1805        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1806        Gtk::TreeModel::iterator it = sel->get_selected();
1807        if (!it) return;
1808        Gtk::TreeModel::Row row = *it;
1809        gig::Script* script = row[m_ScriptsModel.m_col_script];
1810        if (!script) return;
1811    
1812        ScriptEditor* editor = new ScriptEditor;
1813        editor->setScript(script);
1814        //editor->reparent(*this);
1815        editor->show();
1816    }
1817    
1818    void MainWindow::on_action_remove_script() {
1819        if (!file) return;
1820        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1821        Gtk::TreeModel::iterator it = sel->get_selected();
1822        if (it) {
1823            Gtk::TreeModel::Row row = *it;
1824            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1825            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1826            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1827            try {
1828                // remove script group or script from the gig file
1829                if (group) {
1830                    // notify everybody that we're going to remove these samples
1831    //TODO:         scripts_to_be_removed_signal.emit(members);
1832                    // delete the group in the .gig file including the
1833                    // samples that belong to the group
1834                    file->DeleteScriptGroup(group);
1835                    // notify that we're done with removal
1836    //TODO:         scripts_removed_signal.emit();
1837                    file_changed();
1838                } else if (script) {
1839                    // notify everybody that we're going to remove this sample
1840    //TODO:         std::list<gig::Script*> lscripts;
1841    //TODO:         lscripts.push_back(script);
1842    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
1843                    // remove sample from the .gig file
1844                    script->GetGroup()->DeleteScript(script);
1845                    // notify that we're done with removal
1846    //TODO:         scripts_removed_signal.emit();
1847                    dimreg_changed();
1848                    file_changed();
1849                }
1850                // remove respective row(s) from samples tree view
1851                m_refScriptsTreeModel->erase(it);
1852            } catch (RIFF::Exception e) {
1853                // pretend we're done with removal (i.e. to avoid dead locks)
1854    //TODO:     scripts_removed_signal.emit();
1855                // show error message
1856                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1857                msg.run();
1858            }
1859        }
1860    }
1861    
1862  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
1863      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1864      if (!file) return;      if (!file) return;
1865      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1866      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1867      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1868      __sample_indexer++;      __sample_indexer++;
1869      // update sample tree view      // update sample tree view
1870      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1871      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1872      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1873      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1874      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1875      file_changed();      file_changed();
# Line 1517  void MainWindow::on_action_add_sample() Line 1978  void MainWindow::on_action_add_sample()
1978                          break;                          break;
1979                      }                      }
1980                  }                  }
1981                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1982                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1983                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1984                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1531  void MainWindow::on_action_add_sample() Line 1992  void MainWindow::on_action_add_sample()
1992                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1993                  {                  {
1994                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1995                        sample->FineTune      = instrument.detune;
1996    
1997                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1998                          sample->Loops = 1;                          sample->Loops = 1;
# Line 1568  void MainWindow::on_action_add_sample() Line 2030  void MainWindow::on_action_add_sample()
2030                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
2031                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
2032                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
2033                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
2034                        gig_to_utf8(sample->pInfo->Name);
2035                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
2036                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
2037                  // close sound file                  // close sound file
2038                  sf_close(hFile);                  sf_close(hFile);
2039                  file_changed();                  file_changed();
2040              } 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)
2041                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2042                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
2043              }              }
2044          }          }
2045          // 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
2046          if (error_files.size()) {          if (!error_files.empty()) {
2047              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;
2048              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2049              msg.run();              msg.run();
# Line 1593  void MainWindow::on_action_replace_all_s Line 2056  void MainWindow::on_action_replace_all_s
2056      if (!file) return;      if (!file) return;
2057      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
2058                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
2059      const char* str =      const char* str =
2060          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
2061            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
2062            "directory.\n\n"            "directory.\n\n"
# Line 1639  void MainWindow::on_action_replace_all_s Line 2102  void MainWindow::on_action_replace_all_s
2102               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
2103          {          {
2104              std::string filename =              std::string filename =
2105                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
2106                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2107                                             postfixEntryBox.get_text());
2108              SF_INFO info;              SF_INFO info;
2109              info.format = 0;              info.format = 0;
2110              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1673  void MainWindow::on_action_replace_all_s Line 2137  void MainWindow::on_action_replace_all_s
2137              }              }
2138              catch (std::string what)              catch (std::string what)
2139              {              {
2140                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2141                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
2142                        " (" + what + ")";
2143              }              }
2144          }          }
2145          // 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
2146          if (error_files.size()) {          if (!error_files.empty()) {
2147              Glib::ustring txt =              Glib::ustring txt =
2148                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
2149              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1699  void MainWindow::on_action_remove_sample Line 2164  void MainWindow::on_action_remove_sample
2164          try {          try {
2165              // remove group or sample from the gig file              // remove group or sample from the gig file
2166              if (group) {              if (group) {
2167                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2168                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2169                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2170                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1821  void MainWindow::on_sample_label_drop_dr Line 2286  void MainWindow::on_sample_label_drop_dr
2286          bool channels_changed = false;          bool channels_changed = false;
2287          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2288              // remove the samplechannel dimension              // remove the samplechannel dimension
2289    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2290              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2291              channels_changed = true;              channels_changed = true;
2292              region_changed();              region_changed();
2293    */
2294          }          }
2295          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2296                sample,
2297                is_copy_samples_unity_note_enabled(),
2298                is_copy_samples_fine_tune_enabled(),
2299                is_copy_samples_loop_enabled()
2300            );
2301    
2302          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2303              // add samplechannel dimension              // add samplechannel dimension
# Line 1868  void MainWindow::sample_name_changed(con Line 2340  void MainWindow::sample_name_changed(con
2340      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2341      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2342      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2343        gig::String gigname(gig_from_utf8(name));
2344      if (group) {      if (group) {
2345          if (group->Name != name) {          if (group->Name != gigname) {
2346              group->Name = name;              group->Name = gigname;
2347              printf("group name changed\n");              printf("group name changed\n");
2348              file_changed();              file_changed();
2349          }          }
2350      } else if (sample) {      } else if (sample) {
2351          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2352              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2353              printf("sample name changed\n");              printf("sample name changed\n");
2354              file_changed();              file_changed();
2355          }          }
2356      }      }
2357  }  }
2358    
2359    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2360                                         const Gtk::TreeModel::iterator& iter) {
2361        if (!iter) return;
2362        Gtk::TreeModel::Row row = *iter;
2363        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2364        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2365        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2366        gig::String gigname(gig_from_utf8(name));
2367        if (group) {
2368            if (group->Name != gigname) {
2369                group->Name = gigname;
2370                printf("script group name changed\n");
2371                file_changed();
2372            }
2373        } else if (script) {
2374            if (script->Name != gigname) {
2375                script->Name = gigname;
2376                printf("script name changed\n");
2377                file_changed();
2378            }
2379        }
2380    }
2381    
2382  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2383                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2384      if (!iter) return;      if (!iter) return;
2385      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2386      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2387    
2388        // change name in instrument menu
2389        int index = path[0];
2390        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2391        if (index < children.size()) {
2392    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2393            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2394    #else
2395            remove_instrument_from_menu(index);
2396            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2397            item->set_active();
2398    #endif
2399        }
2400    
2401        // change name in gig
2402      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2403      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2404          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2405            instrument->pInfo->Name = gigname;
2406    
2407            // change name in the instrument properties window
2408            if (instrumentProps.get_instrument() == instrument) {
2409                instrumentProps.update_name();
2410            }
2411    
2412          file_changed();          file_changed();
2413      }      }
2414  }  }
2415    
2416    void MainWindow::on_action_combine_instruments() {
2417        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2418        d->show_all();
2419        d->resize(500, 400);
2420        d->run();
2421        if (d->fileWasChanged()) {
2422            // update GUI with new instrument just created
2423            add_instrument(d->newCombinedInstrument());
2424        }
2425        delete d;
2426    }
2427    
2428    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2429        struct _Source {
2430            std::vector<RIFF::File*> riffs;
2431            std::vector<gig::File*> gigs;
2432            
2433            ~_Source() {
2434                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2435                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2436                riffs.clear();
2437                gigs.clear();
2438            }
2439        } sources;
2440    
2441        if (filenames.empty())
2442            throw RIFF::Exception(_("No files selected, so nothing done."));
2443    
2444        // first open all input files (to avoid output file corruption)
2445        int i;
2446        try {
2447            for (i = 0; i < filenames.size(); ++i) {
2448                const std::string& filename = filenames[i];
2449                printf("opening file=%s\n", filename.c_str());
2450    
2451                RIFF::File* riff = new RIFF::File(filename);
2452                sources.riffs.push_back(riff);
2453    
2454                gig::File* gig = new gig::File(riff);
2455                sources.gigs.push_back(gig);
2456            }
2457        } catch (RIFF::Exception e) {
2458            throw RIFF::Exception(
2459                _("Error occurred while opening '") +
2460                filenames[i] +
2461                "': " +
2462                e.Message
2463            );
2464        } catch (...) {
2465            throw RIFF::Exception(
2466                _("Unknown exception occurred while opening '") +
2467                filenames[i] + "'"
2468            );
2469        }
2470    
2471        // now merge the opened .gig files to the main .gig file currently being
2472        // open in gigedit
2473        try {
2474            for (i = 0; i < filenames.size(); ++i) {
2475                const std::string& filename = filenames[i];
2476                printf("merging file=%s\n", filename.c_str());
2477                assert(i < sources.gigs.size());
2478    
2479                this->file->AddContentOf(sources.gigs[i]);
2480            }
2481        } catch (RIFF::Exception e) {
2482            throw RIFF::Exception(
2483                _("Error occurred while merging '") +
2484                filenames[i] +
2485                "': " +
2486                e.Message
2487            );
2488        } catch (...) {
2489            throw RIFF::Exception(
2490                _("Unknown exception occurred while merging '") +
2491                filenames[i] + "'"
2492            );
2493        }
2494    
2495        // Note: requires that this file already has a filename !
2496        this->file->Save();
2497    }
2498    
2499    void MainWindow::on_action_merge_files() {
2500        if (this->file->GetFileName().empty()) {
2501            Glib::ustring txt = _(
2502                "You seem to have a new .gig file open that has not been saved "
2503                "yet. You must save it somewhere before starting to merge it with "
2504                "other .gig files though, because during the merge operation the "
2505                "other files' sample data must be written on file level to the "
2506                "target .gig file."
2507            );
2508            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2509            msg.run();
2510            return;
2511        }
2512    
2513        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2514        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2515        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2516        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2517    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2518        Gtk::FileFilter filter;
2519        filter.add_pattern("*.gig");
2520    #else
2521        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2522        filter->add_pattern("*.gig");
2523    #endif
2524        dialog.set_filter(filter);
2525        if (current_gig_dir != "") {
2526            dialog.set_current_folder(current_gig_dir);
2527        }
2528        dialog.set_select_multiple(true);
2529    
2530        // show warning in the file picker dialog
2531        Gtk::HBox descriptionArea;
2532        descriptionArea.set_spacing(15);
2533        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2534        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2535    #if GTKMM_MAJOR_VERSION < 3
2536        view::WrapLabel description;
2537    #else
2538        Gtk::Label description;
2539        description.set_line_wrap();
2540    #endif
2541        description.set_markup(_(
2542            "\nSelect at least one .gig file that shall be merged to the .gig file "
2543            "currently being open in gigedit.\n\n"
2544            "<b>Please Note:</b> Merging with other files will modify your "
2545            "currently open .gig file on file level! And be aware that the current "
2546            "merge algorithm does not detect duplicate samples yet. So if you are "
2547            "merging files which are using equivalent sample data, those "
2548            "equivalent samples will currently be treated as separate samples and "
2549            "will accordingly be stored separately in the target .gig file!"
2550        ));
2551        descriptionArea.pack_start(description);
2552        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2553        descriptionArea.show_all();
2554    
2555        if (dialog.run() == Gtk::RESPONSE_OK) {
2556            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2557            std::vector<std::string> filenames = dialog.get_filenames();
2558    
2559            // merge the selected files to the currently open .gig file
2560            try {
2561                mergeFiles(filenames);
2562            } catch (RIFF::Exception e) {
2563                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2564                msg.run();
2565            }
2566    
2567            // update GUI
2568            __refreshEntireGUI();        
2569        }
2570    }
2571    
2572  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2573      this->file_is_shared = b;      this->file_is_shared = b;
2574    

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

  ViewVC Help
Powered by ViewVC