/[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 2903 by schoenebeck, Tue May 3 14:08:34 2016 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2013 Andreas Persson   * Copyright (C) 2006-2016 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmmconfig.h>
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31  #include <glibmm/convert.h>  #include <glibmm/convert.h>
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
# Line 27  Line 35 
35  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
36  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
 #include <gtkmm/stock.h>  
38  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
39  #include <gtkmm/main.h>  #include <gtkmm/main.h>
40  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
# Line 40  Line 47 
47    
48  #include <stdio.h>  #include <stdio.h>
49  #include <sndfile.h>  #include <sndfile.h>
50    #include <assert.h>
51    
52  #include "mainwindow.h"  #include "mainwindow.h"
53    #include "Settings.h"
54    #include "CombineInstrumentsDialog.h"
55    #include "scripteditor.h"
56    #include "scriptslots.h"
57    #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    
61    
62  MainWindow::MainWindow() :  MainWindow::MainWindow() :
63        m_DimRegionChooser(*this),
64      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
65      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
66      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
# Line 76  MainWindow::MainWindow() : Line 89  MainWindow::MainWindow() :
89      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
90      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
91    
92        m_ScrolledWindowScripts.add(m_TreeViewScripts);
93        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
94    
95    
96      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
97    
# Line 89  MainWindow::MainWindow() : Line 105  MainWindow::MainWindow() :
105      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
106      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
107    
108        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
109        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."));
110        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."));
111        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)."));
112    
113      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
114      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
115        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
116    
117      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
118    
119      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
120      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),      actionGroup->add(Gtk::Action::create("New", _("_New")),
121                         Gtk::AccelKey("<control>n"),
122                       sigc::mem_fun(                       sigc::mem_fun(
123                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
124      Glib::RefPtr<Gtk::Action> action =      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),
125          Gtk::Action::create("Open", Gtk::Stock::OPEN);                       Gtk::AccelKey("<control>o"),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
126                       sigc::mem_fun(                       sigc::mem_fun(
127                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
128      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),      actionGroup->add(Gtk::Action::create("Save", _("_Save")),
129                         Gtk::AccelKey("<control>s"),
130                       sigc::mem_fun(                       sigc::mem_fun(
131                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
132      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
133                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
134                       sigc::mem_fun(                       sigc::mem_fun(
135                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
136      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
137                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
138                       sigc::mem_fun(                       sigc::mem_fun(
139                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
140      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
141                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
142                       sigc::mem_fun(                       sigc::mem_fun(
143                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
144      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("MidiRules",
145                                             _("_Midi Rules...")),
146                         sigc::mem_fun(
147                             *this, &MainWindow::show_midi_rules));
148        actionGroup->add(Gtk::Action::create("ScriptSlots",
149                                             _("_Script Slots...")),
150                         sigc::mem_fun(
151                             *this, &MainWindow::show_script_slots));
152        actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),
153                         Gtk::AccelKey("<control>q"),
154                       sigc::mem_fun(                       sigc::mem_fun(
155                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
156      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
157            Gtk::Action::create("MenuSample", _("_Sample")),
158            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
159        );
160        actionGroup->add(
161            Gtk::Action::create("MenuInstrument", _("_Instrument")),
162            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
163        );
164        actionGroup->add(
165            Gtk::Action::create("MenuScript", _("S_cript")),
166            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
167        );
168        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
169    
170        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
171    
     actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
172      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
173            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
174        toggle_action->set_active(true);
175        actionGroup->add(toggle_action);
176    
177        toggle_action =
178            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
179        toggle_action->set_active(true);
180        actionGroup->add(toggle_action);
181    
182        toggle_action =
183            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
184        toggle_action->set_active(true);
185        actionGroup->add(toggle_action);
186    
187    
188        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
189        toggle_action =
190          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
191      toggle_action->set_active(true);      toggle_action->set_active(true);
192      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
193                       sigc::mem_fun(                       sigc::mem_fun(
194                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
195        actionGroup->add(
196            Gtk::Action::create("RefreshAll", _("_Refresh All")),
197            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
198        );                
199    
200      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
201      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("About", _("_About")),
                                          action->property_label()));  
     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),  
202                       sigc::mem_fun(                       sigc::mem_fun(
203                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
204      actionGroup->add(      actionGroup->add(
# Line 151  MainWindow::MainWindow() : Line 210  MainWindow::MainWindow() :
210          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
211      );      );
212      actionGroup->add(      actionGroup->add(
213          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", _("_Remove")),
214          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
215      );      );
216    
217    
218        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
219        
220        toggle_action =
221            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
222        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
223        actionGroup->add(
224            toggle_action,
225            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
226        );
227    
228        toggle_action =
229            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
230        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
231        actionGroup->add(
232            toggle_action,
233            sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
234        );
235    
236        toggle_action =
237            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
238        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
239        actionGroup->add(
240            toggle_action,
241            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
242        );
243    
244    
245        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
246    
247        actionGroup->add(
248            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
249            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
250        );
251    
252        actionGroup->add(
253            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
254            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
255        );
256    
257    
258      // sample right-click popup actions      // sample right-click popup actions
259      actionGroup->add(      actionGroup->add(
260          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
261          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
262      );      );
263      actionGroup->add(      actionGroup->add(
# Line 169  MainWindow::MainWindow() : Line 269  MainWindow::MainWindow() :
269          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
270      );      );
271      actionGroup->add(      actionGroup->add(
272          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
273          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
274      );      );
275      actionGroup->add(      actionGroup->add(
276            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
277            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
278        );
279        actionGroup->add(
280            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
281            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
282        );
283        actionGroup->add(
284            Gtk::Action::create("ReplaceSample",
285                                _("Replace Sample...")),
286            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
287        );
288        actionGroup->add(
289          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
290                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
291          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)
292      );      );
293        
294        // script right-click popup actions
295        actionGroup->add(
296            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
297            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
298        );
299        actionGroup->add(
300            Gtk::Action::create("AddScript", _("Add _Script")),
301            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
302        );
303        actionGroup->add(
304            Gtk::Action::create("EditScript", _("_Edit Script...")),
305            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
306        );
307        actionGroup->add(
308            Gtk::Action::create("RemoveScript", _("_Remove")),
309            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
310        );
311    
312      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
313      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 196  MainWindow::MainWindow() : Line 327  MainWindow::MainWindow() :
327          "      <separator/>"          "      <separator/>"
328          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
329          "    </menu>"          "    </menu>"
330            "    <menu action='MenuEdit'>"
331            "      <menuitem action='CopySampleUnity'/>"
332            "      <menuitem action='CopySampleTune'/>"
333            "      <menuitem action='CopySampleLoop'/>"
334            "    </menu>"
335            "    <menu action='MenuSample'>"
336            "      <menuitem action='SampleProperties'/>"
337            "      <menuitem action='AddGroup'/>"
338            "      <menuitem action='AddSample'/>"
339            "      <menuitem action='ShowSampleRefs'/>"
340            "      <menuitem action='ReplaceSample' />"
341            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
342            "      <separator/>"
343            "      <menuitem action='RemoveSample'/>"
344            "      <menuitem action='RemoveUnusedSamples'/>"
345            "    </menu>"
346          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
347            "      <menu action='AllInstruments'>"
348            "      </menu>"
349            "      <separator/>"
350            "      <menuitem action='InstrProperties'/>"
351            "      <menuitem action='MidiRules'/>"
352            "      <menuitem action='ScriptSlots'/>"
353            "      <menuitem action='AddInstrument'/>"
354            "      <menuitem action='DupInstrument'/>"
355            "      <separator/>"
356            "      <menuitem action='RemoveInstrument'/>"
357            "    </menu>"
358            "    <menu action='MenuScript'>"
359            "      <menuitem action='AddScriptGroup'/>"
360            "      <menuitem action='AddScript'/>"
361            "      <menuitem action='EditScript'/>"
362            "      <separator/>"
363            "      <menuitem action='RemoveScript'/>"
364          "    </menu>"          "    </menu>"
365          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
366          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
367            "      <separator/>"
368            "      <menuitem action='RefreshAll'/>"
369            "    </menu>"
370            "    <menu action='MenuTools'>"
371            "      <menuitem action='CombineInstruments'/>"
372            "      <menuitem action='MergeFiles'/>"
373            "    </menu>"
374            "    <menu action='MenuSettings'>"
375            "      <menuitem action='WarnUserOnExtensions'/>"
376            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
377            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
378          "    </menu>"          "    </menu>"
379          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
380          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 207  MainWindow::MainWindow() : Line 382  MainWindow::MainWindow() :
382          "  </menubar>"          "  </menubar>"
383          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
384          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
385            "    <menuitem action='MidiRules'/>"
386            "    <menuitem action='ScriptSlots'/>"
387          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
388          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
389          "    <separator/>"          "    <separator/>"
# Line 216  MainWindow::MainWindow() : Line 393  MainWindow::MainWindow() :
393          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
394          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
395          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
396            "    <menuitem action='ShowSampleRefs'/>"
397            "    <menuitem action='ReplaceSample' />"
398          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
399          "    <separator/>"          "    <separator/>"
400          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
401            "    <menuitem action='RemoveUnusedSamples'/>"
402            "  </popup>"
403            "  <popup name='ScriptPopupMenu'>"
404            "    <menuitem action='AddScriptGroup'/>"
405            "    <menuitem action='AddScript'/>"
406            "    <menuitem action='EditScript'/>"
407            "    <separator/>"
408            "    <menuitem action='RemoveScript'/>"
409          "  </popup>"          "  </popup>"
410          "</ui>";          "</ui>";
411      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
412    
413      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
414        
415        // Set tooltips for menu items (for some reason, setting a tooltip on the
416        // respective Gtk::Action objects above will simply be ignored, no matter
417        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
418        // Gtk::Action::create()).
419        {
420            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
421                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
422            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."));
423        }
424        {
425            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
426                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
427            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."));
428        }
429        {
430            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
431                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
432            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."));
433        }
434        {
435            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
436                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
437            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."));
438        }
439        {
440            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
441                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
442            item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
443        }
444        {
445            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
446                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
447            item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
448        }
449        {
450            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
451                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
452            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
453            // copy tooltip to popup menu
454            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
455                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
456            item2->set_tooltip_text(item->get_tooltip_text());
457        }
458        {
459            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
460                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
461            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
462        }
463        {
464            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
465                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
466            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
467        }
468        {
469            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
470                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
471            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
472        }
473    
474    
475      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
476          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
477    
478      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
479      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 252  MainWindow::MainWindow() : Line 499  MainWindow::MainWindow() :
499      // Create the Tree model:      // Create the Tree model:
500      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
501      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
502        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
503      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
504          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
505      );      );
# Line 259  MainWindow::MainWindow() : Line 507  MainWindow::MainWindow() :
507      // Add the TreeView's view columns:      // Add the TreeView's view columns:
508      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);
509      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
510        
511        // establish drag&drop within the instrument tree view, allowing to reorder
512        // the sequence of instruments within the gig file
513        {
514            std::vector<Gtk::TargetEntry> drag_target_instrument;
515            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
516            m_TreeView.drag_source_set(drag_target_instrument);
517            m_TreeView.drag_dest_set(drag_target_instrument);
518            m_TreeView.signal_drag_begin().connect(
519                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
520            );
521            m_TreeView.signal_drag_data_get().connect(
522                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
523            );
524            m_TreeView.signal_drag_data_received().connect(
525                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
526            );
527        }
528    
529      // create samples treeview (including its data model)      // create samples treeview (including its data model)
530      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
531      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
532        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."));
533      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
534      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
535      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
536        {
537            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
538            Gtk::CellRendererText* cellrenderer =
539                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
540            column->add_attribute(
541                cellrenderer->property_foreground(), m_SamplesModel.m_color
542            );
543        }
544        {
545            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
546            Gtk::CellRendererText* cellrenderer =
547                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
548            column->add_attribute(
549                cellrenderer->property_foreground(), m_SamplesModel.m_color
550            );
551        }
552        m_TreeViewSamples.set_headers_visible(true);
553      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
554          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
555      );      );
# Line 273  MainWindow::MainWindow() : Line 557  MainWindow::MainWindow() :
557          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
558      );      );
559    
560        // create scripts treeview (including its data model)
561        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
562        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
563        m_TreeViewScripts.set_tooltip_text(_(
564            "Use CTRL + double click for editing a script."
565            "\n\n"
566            "Note: instrument scripts are a LinuxSampler extension of the gig "
567            "format. This feature will not work with the GigaStudio software!"
568        ));
569        // m_TreeViewScripts.set_reorderable();
570        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
571        m_TreeViewScripts.set_headers_visible(false);
572        m_TreeViewScripts.signal_button_press_event().connect_notify(
573            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
574        );
575        //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
576        m_TreeViewScripts.signal_row_activated().connect(
577            sigc::mem_fun(*this, &MainWindow::script_double_clicked)
578        );
579        m_refScriptsTreeModel->signal_row_changed().connect(
580            sigc::mem_fun(*this, &MainWindow::script_name_changed)
581        );
582    
583        // establish drag&drop between scripts tree view and ScriptSlots window
584        std::vector<Gtk::TargetEntry> drag_target_gig_script;
585        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
586        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
587        m_TreeViewScripts.signal_drag_begin().connect(
588            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
589        );
590        m_TreeViewScripts.signal_drag_data_get().connect(
591            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
592        );
593    
594      // 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
595      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
596      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 291  MainWindow::MainWindow() : Line 609  MainWindow::MainWindow() :
609          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
610      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
611          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
612        m_RegionChooser.signal_instrument_changed().connect(
613            sigc::mem_fun(*this, &MainWindow::region_changed));
614      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
615          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
616      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
617          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
618      propDialog.signal_changed().connect(      propDialog.signal_changed().connect(
619          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
620        midiRules.signal_changed().connect(
621            sigc::mem_fun(*this, &MainWindow::file_changed));
622    
623      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
624          dimreg_to_be_changed_signal.make_slot());          dimreg_to_be_changed_signal.make_slot());
# Line 304  MainWindow::MainWindow() : Line 626  MainWindow::MainWindow() :
626          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
627      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
628          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
629        sample_ref_changed_signal.connect(
630            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
631        );
632        samples_to_be_removed_signal.connect(
633            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
634        );
635    
636        dimreg_edit.signal_select_sample().connect(
637            sigc::mem_fun(*this, &MainWindow::select_sample)
638        );
639    
640      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
641          sigc::hide(          sigc::hide(
# Line 345  MainWindow::MainWindow() : Line 677  MainWindow::MainWindow() :
677    
678      // start with a new gig file by default      // start with a new gig file by default
679      on_action_file_new();      on_action_file_new();
680    
681        // select 'Instruments' tab by default
682        // (gtk allows this only if the tab childs are visible, thats why it's here)
683        m_TreeViewNotebook.set_current_page(1);
684  }  }
685    
686  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 425  void MainWindow::dimreg_all_dimregs_togg Line 761  void MainWindow::dimreg_all_dimregs_togg
761  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
762  {  {
763      update_dimregs();      update_dimregs();
764      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
765  }  }
766    
767  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
# Line 441  void MainWindow::on_sel_change() Line 777  void MainWindow::on_sel_change()
777      }      }
778    
779      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
780    
781        if (Settings::singleton()->syncSamplerInstrumentSelection) {
782            switch_sampler_instrument_signal.emit(get_instrument());
783        }
784  }  }
785    
786  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 460  void Loader::progress_callback(float fra Line 800  void Loader::progress_callback(float fra
800    
801  void Loader::thread_function()  void Loader::thread_function()
802  {  {
803      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
804      printf("Start %s\n", filename);             static_cast<void*>(Glib::Threads::Thread::self()));
805      RIFF::File* riff = new RIFF::File(filename);      printf("Start %s\n", filename.c_str());
806      gig = new gig::File(riff);      try {
807      gig::progress_t progress;          RIFF::File* riff = new RIFF::File(filename);
808      progress.callback = loader_progress_callback;          gig = new gig::File(riff);
809      progress.custom = this;          gig::progress_t progress;
810            progress.callback = loader_progress_callback;
811      gig->GetInstrument(0, &progress);          progress.custom = this;
812      printf("End\n");  
813      finished_dispatcher();          gig->GetInstrument(0, &progress);
814            printf("End\n");
815            finished_dispatcher();
816        } catch (RIFF::Exception e) {
817            error_message = e.Message;
818            error_dispatcher.emit();
819        } catch (...) {
820            error_message = _("Unknown exception occurred");
821            error_dispatcher.emit();
822        }
823  }  }
824    
825  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
826      : filename(filename), thread(0)      : filename(filename), gig(0), thread(0), progress(0.f)
827  {  {
828  }  }
829    
# Line 485  void Loader::launch() Line 834  void Loader::launch()
834  #else  #else
835      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
836  #endif  #endif
837      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
838  }  }
839    
840  float Loader::get_progress()  float Loader::get_progress()
# Line 508  Glib::Dispatcher& Loader::signal_finishe Line 857  Glib::Dispatcher& Loader::signal_finishe
857      return finished_dispatcher;      return finished_dispatcher;
858  }  }
859    
860  LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)  Glib::Dispatcher& Loader::signal_error()
861    {
862        return error_dispatcher;
863    }
864    
865    void saver_progress_callback(gig::progress_t* progress)
866    {
867        Saver* saver = static_cast<Saver*>(progress->custom);
868        saver->progress_callback(progress->factor);
869    }
870    
871    void Saver::progress_callback(float fraction)
872    {
873        {
874            Glib::Threads::Mutex::Lock lock(progressMutex);
875            progress = fraction;
876        }
877        progress_dispatcher.emit();
878    }
879    
880    void Saver::thread_function()
881    {
882        printf("thread_function self=%p\n",
883               static_cast<void*>(Glib::Threads::Thread::self()));
884        printf("Start %s\n", filename.c_str());
885        try {
886            gig::progress_t progress;
887            progress.callback = saver_progress_callback;
888            progress.custom = this;
889    
890            // if no filename was provided, that means "save", if filename was provided means "save as"
891            if (filename.empty()) {
892                gig->Save(&progress);
893            } else {
894                gig->Save(filename, &progress);
895            }
896    
897            printf("End\n");
898            finished_dispatcher.emit();
899        } catch (RIFF::Exception e) {
900            error_message = e.Message;
901            error_dispatcher.emit();
902        } catch (...) {
903            error_message = _("Unknown exception occurred");
904            error_dispatcher.emit();
905        }
906    }
907    
908    Saver::Saver(gig::File* file, Glib::ustring filename)
909        : gig(file), filename(filename), thread(0), progress(0.f)
910    {
911    }
912    
913    void Saver::launch()
914    {
915    #ifdef OLD_THREADS
916        thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
917    #else
918        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
919    #endif
920        printf("launch thread=%p\n", static_cast<void*>(thread));
921    }
922    
923    float Saver::get_progress()
924    {
925        float res;
926        {
927            Glib::Threads::Mutex::Lock lock(progressMutex);
928            res = progress;
929        }
930        return res;
931    }
932    
933    Glib::Dispatcher& Saver::signal_progress()
934    {
935        return progress_dispatcher;
936    }
937    
938    Glib::Dispatcher& Saver::signal_finished()
939    {
940        return finished_dispatcher;
941    }
942    
943    Glib::Dispatcher& Saver::signal_error()
944    {
945        return error_dispatcher;
946    }
947    
948    ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
949      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
950  {  {
951      get_vbox()->pack_start(progressBar);      get_vbox()->pack_start(progressBar);
952      show_all_children();      show_all_children();
953        resize(600,50);
954  }  }
955    
956  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
# Line 523  void MainWindow::__clear() { Line 961  void MainWindow::__clear() {
961      // clear the samples and instruments tree views      // clear the samples and instruments tree views
962      m_refTreeModel->clear();      m_refTreeModel->clear();
963      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
964        m_refScriptsTreeModel->clear();
965      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
966      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
967          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 533  void MainWindow::__clear() { Line 972  void MainWindow::__clear() {
972      set_file_is_shared(false);      set_file_is_shared(false);
973  }  }
974    
975    void MainWindow::__refreshEntireGUI() {
976        // clear the samples and instruments tree views
977        m_refTreeModel->clear();
978        m_refSamplesTreeModel->clear();
979        m_refScriptsTreeModel->clear();
980        // remove all entries from "Instrument" menu
981        while (!instrument_menu->get_children().empty()) {
982            remove_instrument_from_menu(0);
983        }
984    
985        if (!this->file) return;
986    
987        load_gig(
988            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
989        );
990    }
991    
992  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
993  {  {
994      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 1001  void MainWindow::on_action_file_new()
1001      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
1002      // already add one new instrument by default      // already add one new instrument by default
1003      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
1004      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
1005      // update GUI with that new gig::File      // update GUI with that new gig::File
1006      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
1007  }  }
# Line 558  bool MainWindow::close_confirmation_dial Line 1014  bool MainWindow::close_confirmation_dial
1014      g_free(msg);      g_free(msg);
1015      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
1016      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1017      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1018      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);
1019      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1020      int response = dialog.run();      int response = dialog.run();
1021      dialog.hide();      dialog.hide();
1022      if (response == Gtk::RESPONSE_YES) return file_save();  
1023      return response != Gtk::RESPONSE_CANCEL;      // user decided to exit app without saving
1024        if (response == Gtk::RESPONSE_NO) return true;
1025    
1026        // user cancelled dialog, thus don't close app
1027        if (response == Gtk::RESPONSE_CANCEL) return false;
1028    
1029        // TODO: the following return valid is disabled and hard coded instead for
1030        // now, due to the fact that saving with progress bar is now implemented
1031        // asynchronously, as a result the app does not close automatically anymore
1032        // after saving the file has completed
1033        //
1034        //   if (response == Gtk::RESPONSE_YES) return file_save();
1035        //   return response != Gtk::RESPONSE_CANCEL;
1036        //
1037        if (response == Gtk::RESPONSE_YES) file_save();
1038        return false; // always prevent closing the app for now (see comment above)
1039  }  }
1040    
1041  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
# Line 575  bool MainWindow::leaving_shared_mode_dia Line 1046  bool MainWindow::leaving_shared_mode_dia
1046            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1047            "load it."));            "load it."));
1048      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1049      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1050      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1051      int response = dialog.run();      int response = dialog.run();
1052      dialog.hide();      dialog.hide();
# Line 589  void MainWindow::on_action_file_open() Line 1060  void MainWindow::on_action_file_open()
1060      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1061    
1062      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1063      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1064      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1065      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1066  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1067      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 606  void MainWindow::on_action_file_open() Line 1077  void MainWindow::on_action_file_open()
1077      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1078          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1079          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1080          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1081                   static_cast<void*>(Glib::Threads::Thread::self()));
1082          load_file(filename.c_str());          load_file(filename.c_str());
1083          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1084      }      }
# Line 615  void MainWindow::on_action_file_open() Line 1087  void MainWindow::on_action_file_open()
1087  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
1088  {  {
1089      __clear();      __clear();
1090      load_dialog = new LoadDialog(_("Loading..."), *this);  
1091      load_dialog->show_all();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1092      loader = new Loader(strdup(name));          _("Loading") +  Glib::ustring(" '") +
1093            Glib::filename_display_basename(name) + "' ...",
1094            *this
1095        );
1096        progress_dialog->show_all();
1097        loader = new Loader(name); //FIXME: memory leak!
1098      loader->signal_progress().connect(      loader->signal_progress().connect(
1099          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
1100      loader->signal_finished().connect(      loader->signal_finished().connect(
1101          sigc::mem_fun(*this, &MainWindow::on_loader_finished));          sigc::mem_fun(*this, &MainWindow::on_loader_finished));
1102        loader->signal_error().connect(
1103            sigc::mem_fun(*this, &MainWindow::on_loader_error));
1104      loader->launch();      loader->launch();
1105  }  }
1106    
# Line 637  void MainWindow::load_instrument(gig::In Line 1116  void MainWindow::load_instrument(gig::In
1116      // load the instrument      // load the instrument
1117      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
1118      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
1119      //TODO: automatically select the given instrument      // automatically select the given instrument
1120        int i = 0;
1121        for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
1122             instrument = pFile->GetNextInstrument(), ++i)
1123        {
1124            if (instrument == instr) {
1125                // select item in "instruments" tree view
1126                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
1127                // make sure the selected item in the "instruments" tree view is
1128                // visible (scroll to it)
1129                m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
1130                // select item in instrument menu
1131                {
1132                    const std::vector<Gtk::Widget*> children =
1133                        instrument_menu->get_children();
1134                    static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
1135                }
1136                // update region chooser and dimension region chooser
1137                m_RegionChooser.set_instrument(instr);
1138                break;
1139            }
1140        }
1141  }  }
1142    
1143  void MainWindow::on_loader_progress()  void MainWindow::on_loader_progress()
1144  {  {
1145      load_dialog->set_fraction(loader->get_progress());      progress_dialog->set_fraction(loader->get_progress());
1146  }  }
1147    
1148  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1149  {  {
1150      printf("Loader finished!\n");      printf("Loader finished!\n");
1151      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1152      load_gig(loader->gig, loader->filename);             static_cast<void*>(Glib::Threads::Thread::self()));
1153      load_dialog->hide();      load_gig(loader->gig, loader->filename.c_str());
1154        progress_dialog->hide();
1155    }
1156    
1157    void MainWindow::on_loader_error()
1158    {
1159        Glib::ustring txt = _("Could not load file: ") + loader->error_message;
1160        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1161        msg.run();
1162        progress_dialog->hide();
1163  }  }
1164    
1165  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
# Line 689  bool MainWindow::file_save() Line 1198  bool MainWindow::file_save()
1198    
1199      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
1200      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
1201      try {  
1202          file->Save();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1203          if (file_is_changed) {          _("Saving") +  Glib::ustring(" '") +
1204              set_title(get_title().substr(1));          Glib::filename_display_basename(this->filename) + "' ...",
1205              file_is_changed = false;          *this
1206          }      );
1207      } catch (RIFF::Exception e) {      progress_dialog->show_all();
1208          file_structure_changed_signal.emit(this->file);      saver = new Saver(this->file); //FIXME: memory leak!
1209          Glib::ustring txt = _("Could not save file: ") + e.Message;      saver->signal_progress().connect(
1210          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1211          msg.run();      saver->signal_finished().connect(
1212          return false;          sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1213      }      saver->signal_error().connect(
1214      std::cout << "Saving file done\n" << std::flush;          sigc::mem_fun(*this, &MainWindow::on_saver_error));
1215        saver->launch();
1216    
1217        return true;
1218    }
1219    
1220    void MainWindow::on_saver_progress()
1221    {
1222        progress_dialog->set_fraction(saver->get_progress());
1223    }
1224    
1225    void MainWindow::on_saver_error()
1226    {
1227        file_structure_changed_signal.emit(this->file);
1228        Glib::ustring txt = _("Could not save file: ") + saver->error_message;
1229        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1230        msg.run();
1231    }
1232    
1233    void MainWindow::on_saver_finished()
1234    {
1235        this->file = saver->gig;
1236        this->filename = saver->filename;
1237        current_gig_dir = Glib::path_get_dirname(filename);
1238        set_title(Glib::filename_display_basename(filename));
1239        file_has_name = true;
1240        file_is_changed = false;
1241        std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
1242      __import_queued_samples();      __import_queued_samples();
1243        std::cout << "Importing queued samples done.\n" << std::flush;
1244    
1245      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1246      return true;  
1247        __refreshEntireGUI();
1248        progress_dialog->hide();
1249  }  }
1250    
1251  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
# Line 716  void MainWindow::on_action_file_save_as( Line 1256  void MainWindow::on_action_file_save_as(
1256    
1257  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1258  {  {
1259      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1260      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1261      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1262      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1263      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1264    
# Line 749  bool MainWindow::file_save_as() Line 1289  bool MainWindow::file_save_as()
1289      // show warning in the dialog      // show warning in the dialog
1290      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1291      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1292      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1293        warningIcon.set_from_icon_name("dialog-warning",
1294                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1295      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1296  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1297      view::WrapLabel description;      view::WrapLabel description;
# Line 770  bool MainWindow::file_save_as() Line 1312  bool MainWindow::file_save_as()
1312      descriptionArea.show_all();      descriptionArea.show_all();
1313    
1314      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1315          file_structure_to_be_changed_signal.emit(this->file);          std::string filename = dialog.get_filename();
1316          try {          if (!Glib::str_has_suffix(filename, ".gig")) {
1317              std::string filename = dialog.get_filename();              filename += ".gig";
             if (!Glib::str_has_suffix(filename, ".gig")) {  
                 filename += ".gig";  
             }  
             printf("filename=%s\n", filename.c_str());  
             file->Save(filename);  
             this->filename = filename;  
             current_gig_dir = Glib::path_get_dirname(filename);  
             set_title(Glib::filename_display_basename(filename));  
             file_has_name = true;  
             file_is_changed = false;  
         } catch (RIFF::Exception e) {  
             file_structure_changed_signal.emit(this->file);  
             Glib::ustring txt = _("Could not save file: ") + e.Message;  
             Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);  
             msg.run();  
             return false;  
1318          }          }
1319          __import_queued_samples();          printf("filename=%s\n", filename.c_str());
1320          file_structure_changed_signal.emit(this->file);  
1321            progress_dialog = new ProgressDialog( //FIXME: memory leak!
1322                _("Saving") +  Glib::ustring(" '") +
1323                Glib::filename_display_basename(filename) + "' ...",
1324                *this
1325            );
1326            progress_dialog->show_all();
1327    
1328            saver = new Saver(file, filename); //FIXME: memory leak!
1329            saver->signal_progress().connect(
1330                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1331            saver->signal_finished().connect(
1332                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1333            saver->signal_error().connect(
1334                sigc::mem_fun(*this, &MainWindow::on_saver_error));
1335            saver->launch();
1336    
1337          return true;          return true;
1338      }      }
1339      return false;      return false;
# Line 801  bool MainWindow::file_save_as() Line 1343  bool MainWindow::file_save_as()
1343  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1344      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1345      Glib::ustring error_files;      Glib::ustring error_files;
1346      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1347      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1348           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1349          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",(*iter).sample_path.c_str());
# Line 897  void MainWindow::on_action_file_properti Line 1439  void MainWindow::on_action_file_properti
1439      propDialog.deiconify();      propDialog.deiconify();
1440  }  }
1441    
1442    void MainWindow::on_action_warn_user_on_extensions() {
1443        Settings::singleton()->warnUserOnExtensions =
1444            !Settings::singleton()->warnUserOnExtensions;
1445    }
1446    
1447    void MainWindow::on_action_sync_sampler_instrument_selection() {
1448        Settings::singleton()->syncSamplerInstrumentSelection =
1449            !Settings::singleton()->syncSamplerInstrumentSelection;
1450    }
1451    
1452    void MainWindow::on_action_move_root_note_with_region_moved() {
1453        Settings::singleton()->moveRootNoteWithRegionMoved =
1454            !Settings::singleton()->moveRootNoteWithRegionMoved;
1455    }
1456    
1457  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1458  {  {
1459      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 906  void MainWindow::on_action_help_about() Line 1463  void MainWindow::on_action_help_about()
1463      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1464  #endif  #endif
1465      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1466      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");
1467      dialog.set_comments(_(      const std::string sComment =
1468          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1469          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1470          "Please notice that this is still a very young instrument editor. "          _(
1471          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1472          "this application.\n"              "\n"
1473          "\n"              "This program is distributed WITHOUT ANY WARRANTY; So better "
1474          "Please report bugs to: http://bugs.linuxsampler.org")              "backup your Gigasampler/GigaStudio files before editing them with "
1475      );              "this application.\n"
1476                "\n"
1477                "Please report bugs to: http://bugs.linuxsampler.org"
1478            );
1479        dialog.set_comments(sComment.c_str());
1480      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1481      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1482      dialog.run();      dialog.run();
1483  }  }
1484    
1485  PropDialog::PropDialog()  PropDialog::PropDialog()
1486      : eName(_("Name")),      : eFileFormat(_("File Format")),
1487          eName(_("Name")),
1488        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1489        eComments(_("Comments")),        eComments(_("Comments")),
1490        eProduct(_("Product")),        eProduct(_("Product")),
# Line 938  PropDialog::PropDialog() Line 1500  PropDialog::PropDialog()
1500        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1501        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1502        eSubject(_("Subject")),        eSubject(_("Subject")),
1503        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1504        table(2, 1)        table(2, 1),
1505          m_file(NULL)
1506  {  {
1507      set_title(_("File Properties"));      set_title(_("File Properties"));
1508      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 961  PropDialog::PropDialog() Line 1524  PropDialog::PropDialog()
1524      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1525      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1526    
1527        table.add(eFileFormat);
1528      table.add(eName);      table.add(eName);
1529      table.add(eCreationDate);      table.add(eCreationDate);
1530      table.add(eComments);      table.add(eComments);
# Line 991  PropDialog::PropDialog() Line 1555  PropDialog::PropDialog()
1555      quitButton.grab_focus();      quitButton.grab_focus();
1556      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1557          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1558        eFileFormat.signal_value_changed().connect(
1559            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1560    
1561      quitButton.show();      quitButton.show();
1562      vbox.show();      vbox.show();
1563      show_all_children();      show_all_children();
1564  }  }
1565    
1566    void PropDialog::set_file(gig::File* file)
1567    {
1568        m_file = file;
1569    
1570        // update file format version combo box
1571        const std::string sGiga = "Gigasampler/GigaStudio v";
1572        const int major = file->pVersion->major;
1573        std::vector<std::string> txts;
1574        std::vector<int> values;
1575        txts.push_back(sGiga + "2"); values.push_back(2);
1576        txts.push_back(sGiga + "3/v4"); values.push_back(3);
1577        if (major != 2 && major != 3) {
1578            txts.push_back(sGiga + ToString(major)); values.push_back(major);
1579        }
1580        std::vector<const char*> texts;
1581        for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1582        texts.push_back(NULL); values.push_back(0);
1583        eFileFormat.set_choices(&texts[0], &values[0]);
1584        eFileFormat.set_value(major);
1585    }
1586    
1587    void PropDialog::onFileFormatChanged() {
1588        const int major = eFileFormat.get_value();
1589        if (m_file) m_file->pVersion->major = major;
1590    }
1591    
1592  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1593  {  {
1594      update(info);      update(info);
# Line 1031  void InstrumentProps::set_MIDIProgram(ui Line 1623  void InstrumentProps::set_MIDIProgram(ui
1623  }  }
1624    
1625  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1626      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1627      table(2,1),      table(2,1),
1628      eName(_("Name")),      eName(_("Name")),
1629      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1128  void MainWindow::file_changed() Line 1720  void MainWindow::file_changed()
1720      }      }
1721  }  }
1722    
1723    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1724        sample_ref_count.clear();
1725        
1726        if (!gig) return;
1727    
1728        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1729             instrument = gig->GetNextInstrument())
1730        {
1731            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1732                 rgn = instrument->GetNextRegion())
1733            {
1734                for (int i = 0; i < 256; ++i) {
1735                    if (!rgn->pDimensionRegions[i]) continue;
1736                    if (rgn->pDimensionRegions[i]->pSample) {
1737                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1738                    }
1739                }
1740            }
1741        }
1742    }
1743    
1744  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1745  {  {
1746      file = 0;      file = 0;
1747      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1748    
1749      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1750            (filename && strlen(filename) > 0) ?
1751                filename : (!gig->GetFileName().empty()) ?
1752                    gig->GetFileName() : _("Unsaved Gig File");
1753      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1754      file_has_name = filename;      file_has_name = filename;
1755      file_is_changed = false;      file_is_changed = false;
1756    
1757        propDialog.set_file(gig);
1758      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1759    
1760      instrument_name_connection.block();      instrument_name_connection.block();
1761      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1762           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1763          Glib::ustring name(instrument->pInfo->Name);          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1764    
1765          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1766          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
# Line 1153  void MainWindow::load_gig(gig::File* gig Line 1770  void MainWindow::load_gig(gig::File* gig
1770          add_instrument_to_menu(name);          add_instrument_to_menu(name);
1771      }      }
1772      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1773      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1774    
1775        updateSampleRefCountMap(gig);
1776    
1777      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1778          if (group->Name != "") {          if (group->Name != "") {
1779              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1780              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1781              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1782              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1783              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1784              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1167  void MainWindow::load_gig(gig::File* gig Line 1786  void MainWindow::load_gig(gig::File* gig
1786                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1787                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1788                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1789                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1790                        gig_to_utf8(sample->pInfo->Name);
1791                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1792                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1793                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1794                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1795                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1796              }              }
1797          }          }
1798      }      }
1799        
1800        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1801            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1802    
1803            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1804            Gtk::TreeModel::Row rowGroup = *iterGroup;
1805            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1806            rowGroup[m_ScriptsModel.m_col_group]  = group;
1807            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1808            for (int s = 0; group->GetScript(s); ++s) {
1809                gig::Script* script = group->GetScript(s);
1810    
1811                Gtk::TreeModel::iterator iterScript =
1812                    m_refScriptsTreeModel->append(rowGroup.children());
1813                Gtk::TreeModel::Row rowScript = *iterScript;
1814                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1815                rowScript[m_ScriptsModel.m_col_script] = script;
1816                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1817            }
1818        }
1819        // unfold all sample groups & script groups by default
1820        m_TreeViewSamples.expand_all();
1821        m_TreeViewScripts.expand_all();
1822    
1823      file = gig;      file = gig;
1824    
# Line 1180  void MainWindow::load_gig(gig::File* gig Line 1826  void MainWindow::load_gig(gig::File* gig
1826      m_TreeView.get_selection()->select(Gtk::TreePath("0"));      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1827    
1828      instr_props_set_instrument();      instr_props_set_instrument();
1829        gig::Instrument* instrument = get_instrument();
1830        if (instrument) {
1831            midiRules.set_instrument(instrument);
1832        }
1833  }  }
1834    
1835  bool MainWindow::instr_props_set_instrument()  bool MainWindow::instr_props_set_instrument()
# Line 1221  void MainWindow::instr_name_changed_by_i Line 1871  void MainWindow::instr_name_changed_by_i
1871      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
1872    
1873      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
1874      if (instrument->pInfo->Name != name) {      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1875          row[m_Columns.m_col_name] = instrument->pInfo->Name;      if (gigname != name) {
1876            row[m_Columns.m_col_name] = gigname;
1877      }      }
1878  }  }
1879    
1880    void MainWindow::show_midi_rules()
1881    {
1882        if (gig::Instrument* instrument = get_instrument())
1883        {
1884            midiRules.set_instrument(instrument);
1885            midiRules.show();
1886            midiRules.deiconify();
1887        }
1888    }
1889    
1890    void MainWindow::show_script_slots() {
1891        if (!file) return;
1892        // get selected instrument
1893        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1894        Gtk::TreeModel::iterator it = sel->get_selected();
1895        if (!it) return;
1896        Gtk::TreeModel::Row row = *it;
1897        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1898        if (!instrument) return;
1899    
1900        ScriptSlots* window = new ScriptSlots;
1901        window->setInstrument(instrument);
1902        //window->reparent(*this);
1903        window->show();
1904    }
1905    
1906    void MainWindow::on_action_refresh_all() {
1907        __refreshEntireGUI();
1908    }
1909    
1910  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1911      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1912          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 1918  void MainWindow::on_action_view_status_b
1918      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1919  }  }
1920    
1921    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1922        Gtk::CheckMenuItem* item =
1923            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1924        if (!item) {
1925            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1926            return true;
1927        }
1928        return item->get_active();
1929    }
1930    
1931    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1932        Gtk::CheckMenuItem* item =
1933            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1934        if (!item) {
1935            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1936            return true;
1937        }
1938        return item->get_active();
1939    }
1940    
1941    bool MainWindow::is_copy_samples_loop_enabled() const {
1942        Gtk::CheckMenuItem* item =
1943            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1944        if (!item) {
1945            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1946            return true;
1947        }
1948        return item->get_active();
1949    }
1950    
1951  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1952  {  {
1953      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1954          show_instr_props();          show_instr_props();
1955      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1956            // gig v2 files have no midi rules
1957            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1958            static_cast<Gtk::MenuItem*>(
1959                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1960                    bEnabled
1961                );
1962            static_cast<Gtk::MenuItem*>(
1963                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1964                    bEnabled
1965                );
1966          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1967      }      }
1968  }  }
# Line 1261  void MainWindow::on_instrument_selection Line 1982  void MainWindow::on_instrument_selection
1982      }      }
1983  }  }
1984    
1985    void MainWindow::select_instrument(gig::Instrument* instrument) {
1986        if (!instrument) return;
1987    
1988        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1989        for (int i = 0; i < model->children().size(); ++i) {
1990            Gtk::TreeModel::Row row = model->children()[i];
1991            if (row[m_Columns.m_col_instr] == instrument) {
1992                // select and show the respective instrument in the list view
1993                show_intruments_tab();
1994                m_TreeView.get_selection()->select(model->children()[i]);
1995                Gtk::TreePath path(
1996                    m_TreeView.get_selection()->get_selected()
1997                );
1998                m_TreeView.scroll_to_row(path);
1999                on_sel_change(); // the regular instrument selection change callback
2000            }
2001        }
2002    }
2003    
2004    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
2005    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
2006        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2007        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2008    
2009        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2010        for (int i = 0; i < model->children().size(); ++i) {
2011            Gtk::TreeModel::Row row = model->children()[i];
2012            if (row[m_Columns.m_col_instr] == pInstrument) {
2013                // select and show the respective instrument in the list view
2014                show_intruments_tab();
2015                m_TreeView.get_selection()->select(model->children()[i]);
2016                Gtk::TreePath path(
2017                    m_TreeView.get_selection()->get_selected()
2018                );
2019                m_TreeView.scroll_to_row(path);
2020                on_sel_change(); // the regular instrument selection change callback
2021    
2022                // select respective region in the region selector
2023                m_RegionChooser.set_region(pRegion);
2024    
2025                // select and show the respective dimension region in the editor
2026                //update_dimregs();
2027                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2028                //dimreg_edit.set_dim_region(dimRgn);
2029    
2030                return true;
2031            }
2032        }
2033    
2034        return false;
2035    }
2036    
2037    void MainWindow::select_sample(gig::Sample* sample) {
2038        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2039        for (int g = 0; g < model->children().size(); ++g) {
2040            Gtk::TreeModel::Row rowGroup = model->children()[g];
2041            for (int s = 0; s < rowGroup.children().size(); ++s) {
2042                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2043                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2044                    show_samples_tab();
2045                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2046                    Gtk::TreePath path(
2047                        m_TreeViewSamples.get_selection()->get_selected()
2048                    );
2049                    m_TreeViewSamples.scroll_to_row(path);
2050                    return;
2051                }
2052            }
2053        }
2054    }
2055    
2056  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2057      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2058          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
# Line 1275  void MainWindow::on_sample_treeview_butt Line 2067  void MainWindow::on_sample_treeview_butt
2067              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
2068              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
2069          }          }
2070            
2071                
2072          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2073              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2074          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2075              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2076          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2077              set_sensitive(file);              set_sensitive(file);
2078            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2079                set_sensitive(sample_selected);
2080          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2081              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2082          // show sample popup          // show sample popup
2083          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2084    
2085            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2086                set_sensitive(group_selected || sample_selected);
2087            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2088                set_sensitive(group_selected || sample_selected);
2089            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2090                set_sensitive(file);
2091            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2092                set_sensitive(sample_selected);
2093            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2094                set_sensitive(group_selected || sample_selected);
2095      }      }
2096  }  }
2097    
2098    void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
2099        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2100            Gtk::Menu* script_popup =
2101                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
2102            // update enabled/disabled state of sample popup items
2103            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2104            Gtk::TreeModel::iterator it = sel->get_selected();
2105            bool group_selected  = false;
2106            bool script_selected = false;
2107            if (it) {
2108                Gtk::TreeModel::Row row = *it;
2109                group_selected  = row[m_ScriptsModel.m_col_group];
2110                script_selected = row[m_ScriptsModel.m_col_script];
2111            }
2112            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
2113                set_sensitive(group_selected || script_selected);
2114            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
2115                set_sensitive(file);
2116            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
2117                set_sensitive(script_selected);    
2118            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
2119                set_sensitive(group_selected || script_selected);
2120            // show sample popup
2121            script_popup->popup(button->button, button->time);
2122    
2123            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
2124                set_sensitive(group_selected || script_selected);
2125            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
2126                set_sensitive(file);
2127            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
2128                set_sensitive(script_selected);    
2129            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
2130                set_sensitive(group_selected || script_selected);
2131        }
2132    }
2133    
2134  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
2135      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
# Line 1322  void MainWindow::remove_instrument_from_ Line 2164  void MainWindow::remove_instrument_from_
2164  }  }
2165    
2166  void MainWindow::add_instrument(gig::Instrument* instrument) {  void MainWindow::add_instrument(gig::Instrument* instrument) {
2167      const char* name = instrument->pInfo->Name.c_str();      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2168    
2169      // update instrument tree view      // update instrument tree view
2170      instrument_name_connection.block();      instrument_name_connection.block();
# Line 1344  void MainWindow::on_action_add_instrumen Line 2186  void MainWindow::on_action_add_instrumen
2186      if (!file) return;      if (!file) return;
2187      gig::Instrument* instrument = file->AddInstrument();      gig::Instrument* instrument = file->AddInstrument();
2188      __instrument_indexer++;      __instrument_indexer++;
2189      instrument->pInfo->Name =      instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
2190          _("Unnamed Instrument ") + ToString(__instrument_indexer);                                              ToString(__instrument_indexer));
2191    
2192      add_instrument(instrument);      add_instrument(instrument);
2193  }  }
# Line 1365  void MainWindow::on_action_duplicate_ins Line 2207  void MainWindow::on_action_duplicate_ins
2207      // duplicate the orginal instrument      // duplicate the orginal instrument
2208      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2209      instrNew->pInfo->Name =      instrNew->pInfo->Name =
2210          instrOrig->pInfo->Name + " (" + _("Copy") + ")";          instrOrig->pInfo->Name +
2211            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2212    
2213      add_instrument(instrNew);      add_instrument(instrNew);
2214  }  }
# Line 1413  void MainWindow::on_action_remove_instru Line 2256  void MainWindow::on_action_remove_instru
2256              }              }
2257  #endif  #endif
2258              instr_props_set_instrument();              instr_props_set_instrument();
2259                instr = get_instrument();
2260                if (instr) {
2261                    midiRules.set_instrument(instr);
2262                } else {
2263                    midiRules.hide();
2264                }
2265          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
2266              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2267              msg.run();              msg.run();
# Line 1428  void MainWindow::on_action_sample_proper Line 2277  void MainWindow::on_action_sample_proper
2277      msg.run();      msg.run();
2278  }  }
2279    
2280    void MainWindow::on_action_add_script_group() {
2281        static int __script_indexer = 0;
2282        if (!file) return;
2283        gig::ScriptGroup* group = file->AddScriptGroup();
2284        group->Name = gig_from_utf8(_("Unnamed Group"));
2285        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
2286        __script_indexer++;
2287        // update sample tree view
2288        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
2289        Gtk::TreeModel::Row rowGroup = *iterGroup;
2290        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
2291        rowGroup[m_ScriptsModel.m_col_script] = NULL;
2292        rowGroup[m_ScriptsModel.m_col_group] = group;
2293        file_changed();
2294    }
2295    
2296    void MainWindow::on_action_add_script() {
2297        if (!file) return;
2298        // get selected group
2299        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2300        Gtk::TreeModel::iterator it = sel->get_selected();
2301        if (!it) return;
2302        Gtk::TreeModel::Row row = *it;
2303        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2304        if (!group) { // not a group, but a script is selected (probably)
2305            gig::Script* script = row[m_ScriptsModel.m_col_script];
2306            if (!script) return;
2307            it = row.parent(); // resolve parent (that is the script's group)
2308            if (!it) return;
2309            row = *it;
2310            group = row[m_ScriptsModel.m_col_group];
2311            if (!group) return;
2312        }
2313    
2314        // add a new script to the .gig file
2315        gig::Script* script = group->AddScript();    
2316        Glib::ustring name = _("Unnamed Script");
2317        script->Name = gig_from_utf8(name);
2318    
2319        // add script to the tree view
2320        Gtk::TreeModel::iterator iterScript =
2321            m_refScriptsTreeModel->append(row.children());
2322        Gtk::TreeModel::Row rowScript = *iterScript;
2323        rowScript[m_ScriptsModel.m_col_name] = name;
2324        rowScript[m_ScriptsModel.m_col_script] = script;
2325        rowScript[m_ScriptsModel.m_col_group]  = NULL;
2326    
2327        // unfold group of new script item in treeview
2328        Gtk::TreeModel::Path path(iterScript);
2329        m_TreeViewScripts.expand_to_path(path);
2330    }
2331    
2332    void MainWindow::on_action_edit_script() {
2333        if (!file) return;
2334        // get selected script
2335        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2336        Gtk::TreeModel::iterator it = sel->get_selected();
2337        if (!it) return;
2338        Gtk::TreeModel::Row row = *it;
2339        gig::Script* script = row[m_ScriptsModel.m_col_script];
2340        if (!script) return;
2341    
2342        ScriptEditor* editor = new ScriptEditor;
2343        editor->signal_script_to_be_changed.connect(
2344            signal_script_to_be_changed.make_slot()
2345        );
2346        editor->signal_script_changed.connect(
2347            signal_script_changed.make_slot()
2348        );
2349        editor->setScript(script);
2350        //editor->reparent(*this);
2351        editor->show();
2352    }
2353    
2354    void MainWindow::on_action_remove_script() {
2355        if (!file) return;
2356        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2357        Gtk::TreeModel::iterator it = sel->get_selected();
2358        if (it) {
2359            Gtk::TreeModel::Row row = *it;
2360            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2361            gig::Script* script     = row[m_ScriptsModel.m_col_script];
2362            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2363            try {
2364                // remove script group or script from the gig file
2365                if (group) {
2366                    // notify everybody that we're going to remove these samples
2367    //TODO:         scripts_to_be_removed_signal.emit(members);
2368                    // delete the group in the .gig file including the
2369                    // samples that belong to the group
2370                    file->DeleteScriptGroup(group);
2371                    // notify that we're done with removal
2372    //TODO:         scripts_removed_signal.emit();
2373                    file_changed();
2374                } else if (script) {
2375                    // notify everybody that we're going to remove this sample
2376    //TODO:         std::list<gig::Script*> lscripts;
2377    //TODO:         lscripts.push_back(script);
2378    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2379                    // remove sample from the .gig file
2380                    script->GetGroup()->DeleteScript(script);
2381                    // notify that we're done with removal
2382    //TODO:         scripts_removed_signal.emit();
2383                    dimreg_changed();
2384                    file_changed();
2385                }
2386                // remove respective row(s) from samples tree view
2387                m_refScriptsTreeModel->erase(it);
2388            } catch (RIFF::Exception e) {
2389                // pretend we're done with removal (i.e. to avoid dead locks)
2390    //TODO:     scripts_removed_signal.emit();
2391                // show error message
2392                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2393                msg.run();
2394            }
2395        }
2396    }
2397    
2398  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2399      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2400      if (!file) return;      if (!file) return;
2401      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
2402      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
2403      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
2404      __sample_indexer++;      __sample_indexer++;
2405      // update sample tree view      // update sample tree view
2406      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
2407      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
2408      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
2409      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
2410      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
2411      file_changed();      file_changed();
2412  }  }
2413    
2414    void MainWindow::on_action_replace_sample() {
2415        add_or_replace_sample(true);
2416    }
2417    
2418  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2419        add_or_replace_sample(false);
2420    }
2421    
2422    void MainWindow::add_or_replace_sample(bool replace) {
2423      if (!file) return;      if (!file) return;
2424      // get selected group  
2425        // get selected group (and probably selected sample)
2426      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2427      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
2428      if (!it) return;      if (!it) return;
2429      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2430        gig::Sample* sample = NULL;
2431      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2432      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2433          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2434          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2435          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2436          if (!it) return;          if (!it) return;
2437          row = *it;          if (!replace) row = *it;
2438          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2439          if (!group) return;          if (!group) return;
2440      }      }
2441        if (replace && !sample) return;
2442    
2443      // show 'browse for file' dialog      // show 'browse for file' dialog
2444      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2445      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2446      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2447      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2448    
2449      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2450  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 1536  void MainWindow::on_action_add_sample() Line 2515  void MainWindow::on_action_add_sample()
2515                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2516                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2517                  }                  }
2518                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2519                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2520                  // file name without path                  // file name without path
2521                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2522                  // remove file extension if there is one                  // remove file extension if there is one
# Line 1547  void MainWindow::on_action_add_sample() Line 2526  void MainWindow::on_action_add_sample()
2526                          break;                          break;
2527                      }                      }
2528                  }                  }
2529                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
2530                  sample->Channels = info.channels;                  sample->Channels = info.channels;
2531                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
2532                  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 2540  void MainWindow::on_action_add_sample()
2540                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
2541                  {                  {
2542                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
2543                        sample->FineTune      = instrument.detune;
2544    
2545                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
2546                          sample->Loops = 1;                          sample->Loops = 1;
# Line 1587  void MainWindow::on_action_add_sample() Line 2567  void MainWindow::on_action_add_sample()
2567                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2568                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2569                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2570                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2571                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2572                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2573                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 1595  void MainWindow::on_action_add_sample() Line 2575  void MainWindow::on_action_add_sample()
2575                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2576                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2577                  // add sample to the tree view                  // add sample to the tree view
2578                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2579                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2580                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2581                  rowSample[m_SamplesModel.m_col_name]   = filename;                      Gtk::TreeModel::iterator iterSample =
2582                  rowSample[m_SamplesModel.m_col_sample] = sample;                          m_refSamplesTreeModel->append(row.children());
2583                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      Gtk::TreeModel::Row rowSample = *iterSample;
2584                        rowSample[m_SamplesModel.m_col_name] =
2585                            gig_to_utf8(sample->pInfo->Name);
2586                        rowSample[m_SamplesModel.m_col_sample] = sample;
2587                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2588                    }
2589                  // close sound file                  // close sound file
2590                  sf_close(hFile);                  sf_close(hFile);
2591                  file_changed();                  file_changed();
# Line 1611  void MainWindow::on_action_add_sample() Line 2596  void MainWindow::on_action_add_sample()
2596          }          }
2597          // 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
2598          if (!error_files.empty()) {          if (!error_files.empty()) {
2599              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2600                    (replace
2601                        ? _("Failed to replace sample with:\n")
2602                        : _("Could not add the following sample(s):\n"))
2603                    + error_files;
2604              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2605              msg.run();              msg.run();
2606          }          }
# Line 1654  void MainWindow::on_action_replace_all_s Line 2643  void MainWindow::on_action_replace_all_s
2643      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2644      description.show();      description.show();
2645      entryArea.show_all();      entryArea.show_all();
2646      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2647      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2648      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2649      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 1669  void MainWindow::on_action_replace_all_s Line 2658  void MainWindow::on_action_replace_all_s
2658               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
2659          {          {
2660              std::string filename =              std::string filename =
2661                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
2662                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2663                                             postfixEntryBox.get_text());
2664              SF_INFO info;              SF_INFO info;
2665              info.format = 0;              info.format = 0;
2666              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
2667              try              try
2668              {              {
2669                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2670                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2671                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2672                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2673                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2674                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2675                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2676                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2677                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2678                          break;                          break;
2679                      default:                      default:
2680                          sf_close(hFile);                          sf_close(hFile);
# Line 1704  void MainWindow::on_action_replace_all_s Line 2690  void MainWindow::on_action_replace_all_s
2690              catch (std::string what)              catch (std::string what)
2691              {              {
2692                  if (!error_files.empty()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
2693                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
2694                        " (" + what + ")";
2695              }              }
2696          }          }
2697          // 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 2716  void MainWindow::on_action_remove_sample
2716          try {          try {
2717              // remove group or sample from the gig file              // remove group or sample from the gig file
2718              if (group) {              if (group) {
2719                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
2720                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
2721                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
2722                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1793  void MainWindow::on_action_remove_sample Line 2780  void MainWindow::on_action_remove_sample
2780      }      }
2781  }  }
2782    
2783    void MainWindow::on_action_remove_unused_samples() {
2784        if (!file) return;
2785    
2786        // collect all samples that are not referenced by any instrument
2787        std::list<gig::Sample*> lsamples;
2788        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
2789            gig::Sample* sample = file->GetSample(iSample);
2790            bool isUsed = false;
2791            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
2792                                  instrument = file->GetNextInstrument())
2793            {
2794                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2795                                  rgn = instrument->GetNextRegion())
2796                {
2797                    for (int i = 0; i < 256; ++i) {
2798                        if (!rgn->pDimensionRegions[i]) continue;
2799                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
2800                        isUsed = true;
2801                        goto endOfRefSearch;
2802                    }
2803                }
2804            }
2805            endOfRefSearch:
2806            if (!isUsed) lsamples.push_back(sample);
2807        }
2808    
2809        if (lsamples.empty()) return;
2810    
2811        // notify everybody that we're going to remove these samples
2812        samples_to_be_removed_signal.emit(lsamples);
2813    
2814        // remove collected samples
2815        try {
2816            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
2817                 itSample != lsamples.end(); ++itSample)
2818            {
2819                gig::Sample* sample = *itSample;
2820                // remove sample from the .gig file
2821                file->DeleteSample(sample);
2822                // if sample was just previously added, remove it fro the import queue
2823                for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2824                     iter != m_SampleImportQueue.end(); ++iter)
2825                {
2826                    if ((*iter).gig_sample == sample) {
2827                        printf("Removing previously added sample '%s'\n",
2828                               (*iter).sample_path.c_str());
2829                        m_SampleImportQueue.erase(iter);
2830                        break;
2831                    }
2832                }
2833            }
2834        } catch (RIFF::Exception e) {
2835            // show error message
2836            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2837            msg.run();
2838        }
2839    
2840        // notify everybody that we're done with removal
2841        samples_removed_signal.emit();
2842    
2843        dimreg_changed();
2844        file_changed();
2845        __refreshEntireGUI();
2846    }
2847    
2848    // see comment on on_sample_treeview_drag_begin()
2849    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2850    {
2851        first_call_to_drag_data_get = true;
2852    }
2853    
2854    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2855                                                       Gtk::SelectionData& selection_data, guint, guint)
2856    {
2857        if (!first_call_to_drag_data_get) return;
2858        first_call_to_drag_data_get = false;
2859    
2860        // get selected script
2861        gig::Script* script = NULL;
2862        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2863        Gtk::TreeModel::iterator it = sel->get_selected();
2864        if (it) {
2865            Gtk::TreeModel::Row row = *it;
2866            script = row[m_ScriptsModel.m_col_script];
2867        }
2868        // pass the gig::Script as pointer
2869        selection_data.set(selection_data.get_target(), 0/*unused*/,
2870                           (const guchar*)&script,
2871                           sizeof(script)/*length of data in bytes*/);
2872    }
2873    
2874    // see comment on on_sample_treeview_drag_begin()
2875    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2876    {
2877        first_call_to_drag_data_get = true;
2878    }
2879    
2880    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2881                                                           Gtk::SelectionData& selection_data, guint, guint)
2882    {
2883        if (!first_call_to_drag_data_get) return;
2884        first_call_to_drag_data_get = false;
2885    
2886        // get selected source instrument
2887        gig::Instrument* src = NULL;
2888        {
2889            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2890            Gtk::TreeModel::iterator it = sel->get_selected();
2891            if (it) {
2892                Gtk::TreeModel::Row row = *it;
2893                src = row[m_Columns.m_col_instr];
2894            }
2895        }
2896        if (!src) return;
2897    
2898        // pass the source gig::Instrument as pointer
2899        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
2900                           sizeof(src)/*length of data in bytes*/);
2901    }
2902    
2903    void MainWindow::on_instruments_treeview_drop_drag_data_received(
2904        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
2905        const Gtk::SelectionData& selection_data, guint, guint time)
2906    {
2907        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
2908        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
2909            return;
2910    
2911        gig::Instrument* dst = NULL;
2912        {
2913            Gtk::TreeModel::Path path;
2914            const bool found = m_TreeView.get_path_at_pos(x, y, path);
2915            if (!found) return;
2916    
2917            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
2918            if (!iter) return;
2919            Gtk::TreeModel::Row row = *iter;
2920            dst = row[m_Columns.m_col_instr];
2921        }
2922        if (!dst) return;
2923    
2924        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
2925        src->MoveTo(dst);
2926        __refreshEntireGUI();
2927        select_instrument(src);
2928    }
2929    
2930  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2931  // 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
2932  // 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 2985  void MainWindow::on_sample_label_drop_dr
2985          bool channels_changed = false;          bool channels_changed = false;
2986          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2987              // remove the samplechannel dimension              // remove the samplechannel dimension
2988    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2989              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2990              channels_changed = true;              channels_changed = true;
2991              region_changed();              region_changed();
2992    */
2993          }          }
2994          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2995                sample,
2996                is_copy_samples_unity_note_enabled(),
2997                is_copy_samples_fine_tune_enabled(),
2998                is_copy_samples_loop_enabled()
2999            );
3000    
3001          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
3002              // add samplechannel dimension              // add samplechannel dimension
# Line 1898  void MainWindow::sample_name_changed(con Line 3039  void MainWindow::sample_name_changed(con
3039      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
3040      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
3041      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3042        gig::String gigname(gig_from_utf8(name));
3043      if (group) {      if (group) {
3044          if (group->Name != name) {          if (group->Name != gigname) {
3045              group->Name = name;              group->Name = gigname;
3046              printf("group name changed\n");              printf("group name changed\n");
3047              file_changed();              file_changed();
3048          }          }
3049      } else if (sample) {      } else if (sample) {
3050          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
3051              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
3052              printf("sample name changed\n");              printf("sample name changed\n");
3053              file_changed();              file_changed();
3054          }          }
3055      }      }
3056  }  }
3057    
3058    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
3059                                         const Gtk::TreeModel::iterator& iter) {
3060        if (!iter) return;
3061        Gtk::TreeModel::Row row = *iter;
3062        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
3063        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3064        gig::Script* script     = row[m_ScriptsModel.m_col_script];
3065        gig::String gigname(gig_from_utf8(name));
3066        if (group) {
3067            if (group->Name != gigname) {
3068                group->Name = gigname;
3069                printf("script group name changed\n");
3070                file_changed();
3071            }
3072        } else if (script) {
3073            if (script->Name != gigname) {
3074                script->Name = gigname;
3075                printf("script name changed\n");
3076                file_changed();
3077            }
3078        }
3079    }
3080    
3081    void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
3082                                           Gtk::TreeViewColumn* column)
3083    {
3084        Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
3085        if (!iter) return;
3086        Gtk::TreeModel::Row row = *iter;
3087        gig::Script* script = row[m_ScriptsModel.m_col_script];
3088        if (!script) return;
3089    
3090        ScriptEditor* editor = new ScriptEditor;
3091        editor->signal_script_to_be_changed.connect(
3092            signal_script_to_be_changed.make_slot()
3093        );
3094        editor->signal_script_changed.connect(
3095            signal_script_changed.make_slot()
3096        );
3097        editor->setScript(script);
3098        //editor->reparent(*this);
3099        editor->show();
3100    }
3101    
3102  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
3103                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
3104      if (!iter) return;      if (!iter) return;
# Line 1934  void MainWindow::instrument_name_changed Line 3120  void MainWindow::instrument_name_changed
3120    
3121      // change name in gig      // change name in gig
3122      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
3123      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
3124          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
3125            instrument->pInfo->Name = gigname;
3126    
3127          // change name in the instrument properties window          // change name in the instrument properties window
3128          if (instrumentProps.get_instrument() == instrument) {          if (instrumentProps.get_instrument() == instrument) {
# Line 1946  void MainWindow::instrument_name_changed Line 3133  void MainWindow::instrument_name_changed
3133      }      }
3134  }  }
3135    
3136    void MainWindow::on_action_combine_instruments() {
3137        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3138        d->show_all();
3139        d->resize(500, 400);
3140        d->run();
3141        if (d->fileWasChanged()) {
3142            // update GUI with new instrument just created
3143            add_instrument(d->newCombinedInstrument());
3144        }
3145        delete d;
3146    }
3147    
3148    void MainWindow::on_action_view_references() {
3149        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3150        Gtk::TreeModel::iterator it = sel->get_selected();
3151        if (!it) return;
3152        Gtk::TreeModel::Row row = *it;
3153        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3154        if (!sample) return;
3155    
3156        ReferencesView* d = new ReferencesView(*this);
3157        d->setSample(sample);
3158        d->dimension_region_selected.connect(
3159            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3160        );
3161        d->show_all();
3162        d->resize(500, 400);
3163        d->run();
3164        delete d;
3165    }
3166    
3167    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
3168        struct _Source {
3169            std::vector<RIFF::File*> riffs;
3170            std::vector<gig::File*> gigs;
3171            
3172            ~_Source() {
3173                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
3174                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
3175                riffs.clear();
3176                gigs.clear();
3177            }
3178        } sources;
3179    
3180        if (filenames.empty())
3181            throw RIFF::Exception(_("No files selected, so nothing done."));
3182    
3183        // first open all input files (to avoid output file corruption)
3184        int i;
3185        try {
3186            for (i = 0; i < filenames.size(); ++i) {
3187                const std::string& filename = filenames[i];
3188                printf("opening file=%s\n", filename.c_str());
3189    
3190                RIFF::File* riff = new RIFF::File(filename);
3191                sources.riffs.push_back(riff);
3192    
3193                gig::File* gig = new gig::File(riff);
3194                sources.gigs.push_back(gig);
3195            }
3196        } catch (RIFF::Exception e) {
3197            throw RIFF::Exception(
3198                _("Error occurred while opening '") +
3199                filenames[i] +
3200                "': " +
3201                e.Message
3202            );
3203        } catch (...) {
3204            throw RIFF::Exception(
3205                _("Unknown exception occurred while opening '") +
3206                filenames[i] + "'"
3207            );
3208        }
3209    
3210        // now merge the opened .gig files to the main .gig file currently being
3211        // open in gigedit
3212        try {
3213            for (i = 0; i < filenames.size(); ++i) {
3214                const std::string& filename = filenames[i];
3215                printf("merging file=%s\n", filename.c_str());
3216                assert(i < sources.gigs.size());
3217    
3218                this->file->AddContentOf(sources.gigs[i]);
3219            }
3220        } catch (RIFF::Exception e) {
3221            throw RIFF::Exception(
3222                _("Error occurred while merging '") +
3223                filenames[i] +
3224                "': " +
3225                e.Message
3226            );
3227        } catch (...) {
3228            throw RIFF::Exception(
3229                _("Unknown exception occurred while merging '") +
3230                filenames[i] + "'"
3231            );
3232        }
3233    
3234        // Finally save gig file persistently to disk ...
3235        //NOTE: requires that this gig file already has a filename !
3236        {
3237            std::cout << "Saving file\n" << std::flush;
3238            file_structure_to_be_changed_signal.emit(this->file);
3239    
3240            progress_dialog = new ProgressDialog( //FIXME: memory leak!
3241                _("Saving") +  Glib::ustring(" '") +
3242                Glib::filename_display_basename(this->filename) + "' ...",
3243                *this
3244            );
3245            progress_dialog->show_all();
3246            saver = new Saver(this->file); //FIXME: memory leak!
3247            saver->signal_progress().connect(
3248                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
3249            saver->signal_finished().connect(
3250                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
3251            saver->signal_error().connect(
3252                sigc::mem_fun(*this, &MainWindow::on_saver_error));
3253            saver->launch();
3254        }
3255    }
3256    
3257    void MainWindow::on_action_merge_files() {
3258        if (this->file->GetFileName().empty()) {
3259            Glib::ustring txt = _(
3260                "You seem to have a new .gig file open that has not been saved "
3261                "yet. You must save it somewhere before starting to merge it with "
3262                "other .gig files though, because during the merge operation the "
3263                "other files' sample data must be written on file level to the "
3264                "target .gig file."
3265            );
3266            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3267            msg.run();
3268            return;
3269        }
3270    
3271        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3272        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3273        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3274        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3275    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
3276        Gtk::FileFilter filter;
3277        filter.add_pattern("*.gig");
3278    #else
3279        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
3280        filter->add_pattern("*.gig");
3281    #endif
3282        dialog.set_filter(filter);
3283        if (current_gig_dir != "") {
3284            dialog.set_current_folder(current_gig_dir);
3285        }
3286        dialog.set_select_multiple(true);
3287    
3288        // show warning in the file picker dialog
3289        Gtk::HBox descriptionArea;
3290        descriptionArea.set_spacing(15);
3291        Gtk::Image warningIcon;
3292        warningIcon.set_from_icon_name("dialog-warning",
3293                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3294        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3295    #if GTKMM_MAJOR_VERSION < 3
3296        view::WrapLabel description;
3297    #else
3298        Gtk::Label description;
3299        description.set_line_wrap();
3300    #endif
3301        description.set_markup(_(
3302            "\nSelect at least one .gig file that shall be merged to the .gig file "
3303            "currently being open in gigedit.\n\n"
3304            "<b>Please Note:</b> Merging with other files will modify your "
3305            "currently open .gig file on file level! And be aware that the current "
3306            "merge algorithm does not detect duplicate samples yet. So if you are "
3307            "merging files which are using equivalent sample data, those "
3308            "equivalent samples will currently be treated as separate samples and "
3309            "will accordingly be stored separately in the target .gig file!"
3310        ));
3311        descriptionArea.pack_start(description);
3312        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
3313        descriptionArea.show_all();
3314    
3315        if (dialog.run() == Gtk::RESPONSE_OK) {
3316            printf("on_action_merge_files self=%p\n",
3317                   static_cast<void*>(Glib::Threads::Thread::self()));
3318            std::vector<std::string> filenames = dialog.get_filenames();
3319    
3320            // merge the selected files to the currently open .gig file
3321            try {
3322                mergeFiles(filenames);
3323            } catch (RIFF::Exception e) {
3324                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
3325                msg.run();
3326            }
3327    
3328            // update GUI
3329            __refreshEntireGUI();
3330        }
3331    }
3332    
3333  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
3334      this->file_is_shared = b;      this->file_is_shared = b;
3335    
# Line 1960  void MainWindow::set_file_is_shared(bool Line 3344  void MainWindow::set_file_is_shared(bool
3344              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
3345          );          );
3346      }      }
3347    
3348        {
3349            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
3350                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
3351            if (item) item->set_sensitive(b);
3352        }
3353    }
3354    
3355    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
3356        if (!sample) return;
3357        sample_ref_count[sample] += offset;
3358        const int refcount = sample_ref_count[sample];
3359    
3360        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3361        for (int g = 0; g < model->children().size(); ++g) {
3362            Gtk::TreeModel::Row rowGroup = model->children()[g];
3363            for (int s = 0; s < rowGroup.children().size(); ++s) {
3364                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3365                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
3366                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
3367                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
3368            }
3369        }
3370    }
3371    
3372    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
3373        on_sample_ref_count_incremented(oldSample, -1);
3374        on_sample_ref_count_incremented(newSample, +1);
3375    }
3376    
3377    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
3378        // just in case a new sample is added later with exactly the same memory
3379        // address, which would lead to incorrect refcount if not deleted here
3380        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
3381             it != samples.end(); ++it)
3382        {
3383            sample_ref_count.erase(*it);
3384        }
3385    }
3386    
3387    void MainWindow::show_samples_tab() {
3388        m_TreeViewNotebook.set_current_page(0);
3389    }
3390    
3391    void MainWindow::show_intruments_tab() {
3392        m_TreeViewNotebook.set_current_page(1);
3393    }
3394    
3395    void MainWindow::show_scripts_tab() {
3396        m_TreeViewNotebook.set_current_page(2);
3397  }  }
3398    
3399  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
# Line 2017  sigc::signal<void, int/*key*/, int/*velo Line 3451  sigc::signal<void, int/*key*/, int/*velo
3451  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
3452      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
3453  }  }
3454    
3455    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
3456        return switch_sampler_instrument_signal;
3457    }

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

  ViewVC Help
Powered by ViewVC