/[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 2553 by schoenebeck, Wed May 14 19:57:56 2014 UTC revision 2773 by schoenebeck, Fri Jun 12 17:57:52 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2015 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 45  Line 45 
45  #include "mainwindow.h"  #include "mainwindow.h"
46  #include "Settings.h"  #include "Settings.h"
47  #include "CombineInstrumentsDialog.h"  #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49    #include "scriptslots.h"
50    #include "ReferencesView.h"
51  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
52  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
53    
54    
55  MainWindow::MainWindow() :  MainWindow::MainWindow() :
56        m_DimRegionChooser(*this),
57      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
58      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
59      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
# Line 78  MainWindow::MainWindow() : Line 82  MainWindow::MainWindow() :
82      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
83      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
84    
85        m_ScrolledWindowScripts.add(m_TreeViewScripts);
86        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
87    
88    
89      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
90    
# Line 98  MainWindow::MainWindow() : Line 105  MainWindow::MainWindow() :
105    
106      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
107      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
108        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
109    
110      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
111    
# Line 130  MainWindow::MainWindow() : Line 137  MainWindow::MainWindow() :
137                       sigc::mem_fun(                       sigc::mem_fun(
138                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
139      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
140                                           _("_Midi Rules")),                                           _("_Midi Rules...")),
141                       sigc::mem_fun(                       sigc::mem_fun(
142                           *this, &MainWindow::show_midi_rules));                           *this, &MainWindow::show_midi_rules));
143        actionGroup->add(Gtk::Action::create("ScriptSlots",
144                                             _("_Script Slots...")),
145                         sigc::mem_fun(
146                             *this, &MainWindow::show_script_slots));
147      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
148                       sigc::mem_fun(                       sigc::mem_fun(
149                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
150      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
151            Gtk::Action::create("MenuSample", _("_Sample")),
152            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
153        );
154        actionGroup->add(
155            Gtk::Action::create("MenuInstrument", _("_Instrument")),
156            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
157        );
158        actionGroup->add(
159            Gtk::Action::create("MenuScript", _("S_cript")),
160            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
161        );
162        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
163    
164      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
165    
# Line 164  MainWindow::MainWindow() : Line 186  MainWindow::MainWindow() :
186      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
187                       sigc::mem_fun(                       sigc::mem_fun(
188                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
189        actionGroup->add(
190            Gtk::Action::create("RefreshAll", _("_Refresh All")),
191            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
192        );                
193    
194      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
195      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
# Line 195  MainWindow::MainWindow() : Line 221  MainWindow::MainWindow() :
221          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
222      );      );
223    
224        toggle_action =
225            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
226        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
227        actionGroup->add(
228            toggle_action,
229            sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
230        );
231    
232        toggle_action =
233            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
234        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
235        actionGroup->add(
236            toggle_action,
237            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
238        );
239    
240    
241      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
242    
# Line 227  MainWindow::MainWindow() : Line 269  MainWindow::MainWindow() :
269          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
270      );      );
271      actionGroup->add(      actionGroup->add(
272            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
273            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
274        );
275        actionGroup->add(
276            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
277            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
278        );
279        actionGroup->add(
280            Gtk::Action::create("ReplaceSample",
281                                _("Replace Sample...")),
282            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
283        );
284        actionGroup->add(
285          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
286                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
287          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)
288      );      );
289        
290        // script right-click popup actions
291        actionGroup->add(
292            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
293            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
294        );
295        actionGroup->add(
296            Gtk::Action::create("AddScript", _("Add _Script")),
297            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
298        );
299        actionGroup->add(
300            Gtk::Action::create("EditScript", _("_Edit Script...")),
301            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
302        );
303        actionGroup->add(
304            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
305            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
306        );
307    
308      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
309      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 255  MainWindow::MainWindow() : Line 328  MainWindow::MainWindow() :
328          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
329          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
330          "    </menu>"          "    </menu>"
331            "    <menu action='MenuSample'>"
332            "      <menuitem action='SampleProperties'/>"
333            "      <menuitem action='AddGroup'/>"
334            "      <menuitem action='AddSample'/>"
335            "      <menuitem action='ShowSampleRefs'/>"
336            "      <menuitem action='ReplaceSample' />"
337            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
338            "      <separator/>"
339            "      <menuitem action='RemoveSample'/>"
340            "      <menuitem action='RemoveUnusedSamples'/>"
341            "    </menu>"
342          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
343            "      <menu action='AllInstruments'>"
344            "      </menu>"
345            "      <separator/>"
346            "      <menuitem action='InstrProperties'/>"
347            "      <menuitem action='MidiRules'/>"
348            "      <menuitem action='ScriptSlots'/>"
349            "      <menuitem action='AddInstrument'/>"
350            "      <menuitem action='DupInstrument'/>"
351            "      <separator/>"
352            "      <menuitem action='RemoveInstrument'/>"
353            "    </menu>"
354            "    <menu action='MenuScript'>"
355            "      <menuitem action='AddScriptGroup'/>"
356            "      <menuitem action='AddScript'/>"
357            "      <menuitem action='EditScript'/>"
358            "      <separator/>"
359            "      <menuitem action='RemoveScript'/>"
360          "    </menu>"          "    </menu>"
361          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
362          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
363            "      <separator/>"
364            "      <menuitem action='RefreshAll'/>"
365          "    </menu>"          "    </menu>"
366          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
367          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 266  MainWindow::MainWindow() : Line 369  MainWindow::MainWindow() :
369          "    </menu>"          "    </menu>"
370          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
371          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
372            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
373            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
374          "    </menu>"          "    </menu>"
375          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
376          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 274  MainWindow::MainWindow() : Line 379  MainWindow::MainWindow() :
379          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
380          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
381          "    <menuitem action='MidiRules'/>"          "    <menuitem action='MidiRules'/>"
382            "    <menuitem action='ScriptSlots'/>"
383          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
384          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
385          "    <separator/>"          "    <separator/>"
# Line 283  MainWindow::MainWindow() : Line 389  MainWindow::MainWindow() :
389          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
390          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
391          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
392            "    <menuitem action='ShowSampleRefs'/>"
393            "    <menuitem action='ReplaceSample' />"
394          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
395          "    <separator/>"          "    <separator/>"
396          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
397            "    <menuitem action='RemoveUnusedSamples'/>"
398            "  </popup>"
399            "  <popup name='ScriptPopupMenu'>"
400            "    <menuitem action='AddScriptGroup'/>"
401            "    <menuitem action='AddScript'/>"
402            "    <menuitem action='EditScript'/>"
403            "    <separator/>"
404            "    <menuitem action='RemoveScript'/>"
405          "  </popup>"          "  </popup>"
406          "</ui>";          "</ui>";
407      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
# Line 318  MainWindow::MainWindow() : Line 434  MainWindow::MainWindow() :
434      }      }
435      {      {
436          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
437                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
438            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)."));
439        }
440        {
441            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
442                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
443            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."));
444        }
445        {
446            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
447                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
448            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
449            // copy tooltip to popup menu
450            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
451                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
452            item2->set_tooltip_text(item->get_tooltip_text());
453        }
454        {
455            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
456                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
457            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
458        }
459        {
460            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
461              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
462          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
463      }      }
# Line 329  MainWindow::MainWindow() : Line 469  MainWindow::MainWindow() :
469    
470    
471      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
472          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
473    
474      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
475      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 355  MainWindow::MainWindow() : Line 495  MainWindow::MainWindow() :
495      // Create the Tree model:      // Create the Tree model:
496      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
497      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
498      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
499      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
500          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
501      );      );
# Line 363  MainWindow::MainWindow() : Line 503  MainWindow::MainWindow() :
503      // Add the TreeView's view columns:      // Add the TreeView's view columns:
504      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);
505      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
506        
507        // establish drag&drop within the instrument tree view, allowing to reorder
508        // the sequence of instruments within the gig file
509        {
510            std::vector<Gtk::TargetEntry> drag_target_instrument;
511            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
512            m_TreeView.drag_source_set(drag_target_instrument);
513            m_TreeView.drag_dest_set(drag_target_instrument);
514            m_TreeView.signal_drag_begin().connect(
515                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
516            );
517            m_TreeView.signal_drag_data_get().connect(
518                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
519            );
520            m_TreeView.signal_drag_data_received().connect(
521                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
522            );
523        }
524    
525      // create samples treeview (including its data model)      // create samples treeview (including its data model)
526      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
527      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
528      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."));      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."));
529      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
530      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
531      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
532        {
533            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
534            Gtk::CellRendererText* cellrenderer =
535                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
536            column->add_attribute(
537                cellrenderer->property_foreground(), m_SamplesModel.m_color
538            );
539        }
540        {
541            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
542            Gtk::CellRendererText* cellrenderer =
543                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
544            column->add_attribute(
545                cellrenderer->property_foreground(), m_SamplesModel.m_color
546            );
547        }
548        m_TreeViewSamples.set_headers_visible(true);
549      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
550          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
551      );      );
# Line 378  MainWindow::MainWindow() : Line 553  MainWindow::MainWindow() :
553          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
554      );      );
555    
556        // create scripts treeview (including its data model)
557        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
558        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
559        m_TreeViewScripts.set_tooltip_text(_(
560            "Use CTRL + double click for editing a script."
561            "\n\n"
562            "Note: instrument scripts are a LinuxSampler extension of the gig "
563            "format. This feature will not work with the GigaStudio software!"
564        ));
565        // m_TreeViewScripts.set_reorderable();
566        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
567        m_TreeViewScripts.set_headers_visible(false);
568        m_TreeViewScripts.signal_button_press_event().connect_notify(
569            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
570        );
571        //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
572        m_TreeViewScripts.signal_row_activated().connect(
573            sigc::mem_fun(*this, &MainWindow::script_double_clicked)
574        );
575        m_refScriptsTreeModel->signal_row_changed().connect(
576            sigc::mem_fun(*this, &MainWindow::script_name_changed)
577        );
578    
579        // establish drag&drop between scripts tree view and ScriptSlots window
580        std::vector<Gtk::TargetEntry> drag_target_gig_script;
581        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
582        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
583        m_TreeViewScripts.signal_drag_begin().connect(
584            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
585        );
586        m_TreeViewScripts.signal_drag_data_get().connect(
587            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
588        );
589    
590      // 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
591      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
592      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 396  MainWindow::MainWindow() : Line 605  MainWindow::MainWindow() :
605          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
606      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
607          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
608        m_RegionChooser.signal_instrument_changed().connect(
609            sigc::mem_fun(*this, &MainWindow::region_changed));
610      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
611          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
612      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 411  MainWindow::MainWindow() : Line 622  MainWindow::MainWindow() :
622          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
623      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
624          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
625        sample_ref_changed_signal.connect(
626            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
627        );
628        samples_to_be_removed_signal.connect(
629            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
630        );
631    
632        dimreg_edit.signal_select_sample().connect(
633            sigc::mem_fun(*this, &MainWindow::select_sample)
634        );
635    
636      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
637          sigc::hide(          sigc::hide(
# Line 536  void MainWindow::dimreg_all_dimregs_togg Line 757  void MainWindow::dimreg_all_dimregs_togg
757  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
758  {  {
759      update_dimregs();      update_dimregs();
760      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
761  }  }
762    
763  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
# Line 552  void MainWindow::on_sel_change() Line 773  void MainWindow::on_sel_change()
773      }      }
774    
775      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
776    
777        if (Settings::singleton()->syncSamplerInstrumentSelection) {
778            switch_sampler_instrument_signal.emit(get_instrument());
779        }
780  }  }
781    
782  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 572  void Loader::progress_callback(float fra Line 797  void Loader::progress_callback(float fra
797  void Loader::thread_function()  void Loader::thread_function()
798  {  {
799      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
800      printf("Start %s\n", filename);      printf("Start %s\n", filename.c_str());
801      RIFF::File* riff = new RIFF::File(filename);      try {
802      gig = new gig::File(riff);          RIFF::File* riff = new RIFF::File(filename);
803      gig::progress_t progress;          gig = new gig::File(riff);
804      progress.callback = loader_progress_callback;          gig::progress_t progress;
805      progress.custom = this;          progress.callback = loader_progress_callback;
806            progress.custom = this;
807      gig->GetInstrument(0, &progress);  
808      printf("End\n");          gig->GetInstrument(0, &progress);
809      finished_dispatcher();          printf("End\n");
810            finished_dispatcher();
811        } catch (RIFF::Exception e) {
812            error_message = e.Message;
813            error_dispatcher.emit();
814        } catch (...) {
815            error_message = _("Unknown exception occurred");
816            error_dispatcher.emit();
817        }
818  }  }
819    
820  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
821      : filename(filename), thread(0)      : filename(filename), thread(0), progress(0.f)
822  {  {
823  }  }
824    
# Line 619  Glib::Dispatcher& Loader::signal_finishe Line 852  Glib::Dispatcher& Loader::signal_finishe
852      return finished_dispatcher;      return finished_dispatcher;
853  }  }
854    
855  LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)  Glib::Dispatcher& Loader::signal_error()
856    {
857        return error_dispatcher;
858    }
859    
860    void saver_progress_callback(gig::progress_t* progress)
861    {
862        Saver* saver = static_cast<Saver*>(progress->custom);
863        saver->progress_callback(progress->factor);
864    }
865    
866    void Saver::progress_callback(float fraction)
867    {
868        {
869            Glib::Threads::Mutex::Lock lock(progressMutex);
870            progress = fraction;
871        }
872        progress_dispatcher.emit();
873    }
874    
875    void Saver::thread_function()
876    {
877        printf("thread_function self=%x\n", Glib::Threads::Thread::self());
878        printf("Start %s\n", filename.c_str());
879        try {
880            gig::progress_t progress;
881            progress.callback = saver_progress_callback;
882            progress.custom = this;
883    
884            // if no filename was provided, that means "save", if filename was provided means "save as"
885            if (filename.empty()) {
886                gig->Save(&progress);
887            } else {
888                gig->Save(filename, &progress);
889            }
890    
891            printf("End\n");
892            finished_dispatcher.emit();
893        } catch (RIFF::Exception e) {
894            error_message = e.Message;
895            error_dispatcher.emit();
896        } catch (...) {
897            error_message = _("Unknown exception occurred");
898            error_dispatcher.emit();
899        }
900    }
901    
902    Saver::Saver(gig::File* file, Glib::ustring filename)
903        : gig(file), filename(filename), thread(0), progress(0.f)
904    {
905    }
906    
907    void Saver::launch()
908    {
909    #ifdef OLD_THREADS
910        thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
911    #else
912        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
913    #endif
914        printf("launch thread=%x\n", thread);
915    }
916    
917    float Saver::get_progress()
918    {
919        float res;
920        {
921            Glib::Threads::Mutex::Lock lock(progressMutex);
922            res = progress;
923        }
924        return res;
925    }
926    
927    Glib::Dispatcher& Saver::signal_progress()
928    {
929        return progress_dispatcher;
930    }
931    
932    Glib::Dispatcher& Saver::signal_finished()
933    {
934        return finished_dispatcher;
935    }
936    
937    Glib::Dispatcher& Saver::signal_error()
938    {
939        return error_dispatcher;
940    }
941    
942    ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
943      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
944  {  {
945      get_vbox()->pack_start(progressBar);      get_vbox()->pack_start(progressBar);
946      show_all_children();      show_all_children();
947        resize(600,50);
948  }  }
949    
950  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
# Line 634  void MainWindow::__clear() { Line 955  void MainWindow::__clear() {
955      // clear the samples and instruments tree views      // clear the samples and instruments tree views
956      m_refTreeModel->clear();      m_refTreeModel->clear();
957      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
958        m_refScriptsTreeModel->clear();
959      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
960      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
961          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 648  void MainWindow::__refreshEntireGUI() { Line 970  void MainWindow::__refreshEntireGUI() {
970      // clear the samples and instruments tree views      // clear the samples and instruments tree views
971      m_refTreeModel->clear();      m_refTreeModel->clear();
972      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
973        m_refScriptsTreeModel->clear();
974      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
975      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
976          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 690  bool MainWindow::close_confirmation_dial Line 1013  bool MainWindow::close_confirmation_dial
1013      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1014      int response = dialog.run();      int response = dialog.run();
1015      dialog.hide();      dialog.hide();
1016      if (response == Gtk::RESPONSE_YES) return file_save();  
1017      return response != Gtk::RESPONSE_CANCEL;      // user decided to exit app without saving
1018        if (response == Gtk::RESPONSE_NO) return true;
1019    
1020        // user cancelled dialog, thus don't close app
1021        if (response == Gtk::RESPONSE_CANCEL) return false;
1022    
1023        // TODO: the following return valid is disabled and hard coded instead for
1024        // now, due to the fact that saving with progress bar is now implemented
1025        // asynchronously, as a result the app does not close automatically anymore
1026        // after saving the file has completed
1027        //
1028        //   if (response == Gtk::RESPONSE_YES) return file_save();
1029        //   return response != Gtk::RESPONSE_CANCEL;
1030        //
1031        if (response == Gtk::RESPONSE_YES) file_save();
1032        return false; // always prevent closing the app for now (see comment above)
1033  }  }
1034    
1035  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
# Line 742  void MainWindow::on_action_file_open() Line 1080  void MainWindow::on_action_file_open()
1080  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
1081  {  {
1082      __clear();      __clear();
1083      load_dialog = new LoadDialog(_("Loading..."), *this);  
1084      load_dialog->show_all();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1085      loader = new Loader(strdup(name));          _("Loading") +  Glib::ustring(" '") +
1086            Glib::filename_display_basename(name) + "' ...",
1087            *this
1088        );
1089        progress_dialog->show_all();
1090        loader = new Loader(name); //FIXME: memory leak!
1091      loader->signal_progress().connect(      loader->signal_progress().connect(
1092          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
1093      loader->signal_finished().connect(      loader->signal_finished().connect(
1094          sigc::mem_fun(*this, &MainWindow::on_loader_finished));          sigc::mem_fun(*this, &MainWindow::on_loader_finished));
1095        loader->signal_error().connect(
1096            sigc::mem_fun(*this, &MainWindow::on_loader_error));
1097      loader->launch();      loader->launch();
1098  }  }
1099    
# Line 764  void MainWindow::load_instrument(gig::In Line 1109  void MainWindow::load_instrument(gig::In
1109      // load the instrument      // load the instrument
1110      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
1111      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
1112      //TODO: automatically select the given instrument      // automatically select the given instrument
1113        int i = 0;
1114        for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
1115             instrument = pFile->GetNextInstrument(), ++i)
1116        {
1117            if (instrument == instr) {
1118                // select item in "instruments" tree view
1119                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
1120                // make sure the selected item in the "instruments" tree view is
1121                // visible (scroll to it)
1122                m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
1123                // select item in instrument menu
1124                {
1125                    const std::vector<Gtk::Widget*> children =
1126                        instrument_menu->get_children();
1127                    static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
1128                }
1129                // update region chooser and dimension region chooser
1130                m_RegionChooser.set_instrument(instr);
1131                break;
1132            }
1133        }
1134  }  }
1135    
1136  void MainWindow::on_loader_progress()  void MainWindow::on_loader_progress()
1137  {  {
1138      load_dialog->set_fraction(loader->get_progress());      progress_dialog->set_fraction(loader->get_progress());
1139  }  }
1140    
1141  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1142  {  {
1143      printf("Loader finished!\n");      printf("Loader finished!\n");
1144      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
1145      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename.c_str());
1146      load_dialog->hide();      progress_dialog->hide();
1147    }
1148    
1149    void MainWindow::on_loader_error()
1150    {
1151        Glib::ustring txt = _("Could not load file: ") + loader->error_message;
1152        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1153        msg.run();
1154        progress_dialog->hide();
1155  }  }
1156    
1157  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
# Line 816  bool MainWindow::file_save() Line 1190  bool MainWindow::file_save()
1190    
1191      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
1192      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
1193      try {  
1194          file->Save();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1195          if (file_is_changed) {          _("Saving") +  Glib::ustring(" '") +
1196              set_title(get_title().substr(1));          Glib::filename_display_basename(this->filename) + "' ...",
1197              file_is_changed = false;          *this
1198          }      );
1199      } catch (RIFF::Exception e) {      progress_dialog->show_all();
1200          file_structure_changed_signal.emit(this->file);      saver = new Saver(this->file); //FIXME: memory leak!
1201          Glib::ustring txt = _("Could not save file: ") + e.Message;      saver->signal_progress().connect(
1202          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1203          msg.run();      saver->signal_finished().connect(
1204          return false;          sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1205      }      saver->signal_error().connect(
1206      std::cout << "Saving file done\n" << std::flush;          sigc::mem_fun(*this, &MainWindow::on_saver_error));
1207        saver->launch();
1208    
1209        return true;
1210    }
1211    
1212    void MainWindow::on_saver_progress()
1213    {
1214        progress_dialog->set_fraction(saver->get_progress());
1215    }
1216    
1217    void MainWindow::on_saver_error()
1218    {
1219        file_structure_changed_signal.emit(this->file);
1220        Glib::ustring txt = _("Could not save file: ") + saver->error_message;
1221        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1222        msg.run();
1223    }
1224    
1225    void MainWindow::on_saver_finished()
1226    {
1227        this->file = saver->gig;
1228        this->filename = saver->filename;
1229        current_gig_dir = Glib::path_get_dirname(filename);
1230        set_title(Glib::filename_display_basename(filename));
1231        file_has_name = true;
1232        file_is_changed = false;
1233        std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
1234      __import_queued_samples();      __import_queued_samples();
1235        std::cout << "Importing queued samples done.\n" << std::flush;
1236    
1237      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1238      return true;  
1239        __refreshEntireGUI();
1240        progress_dialog->hide();
1241  }  }
1242    
1243  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
# Line 897  bool MainWindow::file_save_as() Line 1302  bool MainWindow::file_save_as()
1302      descriptionArea.show_all();      descriptionArea.show_all();
1303    
1304      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1305          file_structure_to_be_changed_signal.emit(this->file);          std::string filename = dialog.get_filename();
1306          try {          if (!Glib::str_has_suffix(filename, ".gig")) {
1307              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;  
1308          }          }
1309          __import_queued_samples();          printf("filename=%s\n", filename.c_str());
1310          file_structure_changed_signal.emit(this->file);  
1311            progress_dialog = new ProgressDialog( //FIXME: memory leak!
1312                _("Saving") +  Glib::ustring(" '") +
1313                Glib::filename_display_basename(filename) + "' ...",
1314                *this
1315            );
1316            progress_dialog->show_all();
1317    
1318            saver = new Saver(file, filename); //FIXME: memory leak!
1319            saver->signal_progress().connect(
1320                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1321            saver->signal_finished().connect(
1322                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1323            saver->signal_error().connect(
1324                sigc::mem_fun(*this, &MainWindow::on_saver_error));
1325            saver->launch();
1326    
1327          return true;          return true;
1328      }      }
1329      return false;      return false;
# Line 1029  void MainWindow::on_action_warn_user_on_ Line 1434  void MainWindow::on_action_warn_user_on_
1434          !Settings::singleton()->warnUserOnExtensions;          !Settings::singleton()->warnUserOnExtensions;
1435  }  }
1436    
1437    void MainWindow::on_action_sync_sampler_instrument_selection() {
1438        Settings::singleton()->syncSamplerInstrumentSelection =
1439            !Settings::singleton()->syncSamplerInstrumentSelection;
1440    }
1441    
1442    void MainWindow::on_action_move_root_note_with_region_moved() {
1443        Settings::singleton()->moveRootNoteWithRegionMoved =
1444            !Settings::singleton()->moveRootNoteWithRegionMoved;
1445    }
1446    
1447  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1448  {  {
1449      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1038  void MainWindow::on_action_help_about() Line 1453  void MainWindow::on_action_help_about()
1453      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1454  #endif  #endif
1455      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1456      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");
1457      const std::string sComment =      const std::string sComment =
1458          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1459          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1460          _(          _(
1461              "Gigedit is released under the GNU General Public License.\n"              "Gigedit is released under the GNU General Public License.\n"
1462              "\n"              "\n"
1463              "Please notice that this is still a very young instrument editor. "              "This program is distributed WITHOUT ANY WARRANTY; So better "
1464              "So better backup your Gigasampler files before editing them with "              "backup your Gigasampler/GigaStudio files before editing them with "
1465              "this application.\n"              "this application.\n"
1466              "\n"              "\n"
1467              "Please report bugs to: http://bugs.linuxsampler.org"              "Please report bugs to: http://bugs.linuxsampler.org"
# Line 1058  void MainWindow::on_action_help_about() Line 1473  void MainWindow::on_action_help_about()
1473  }  }
1474    
1475  PropDialog::PropDialog()  PropDialog::PropDialog()
1476      : eName(_("Name")),      : eFileFormat(_("File Format")),
1477          eName(_("Name")),
1478        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1479        eComments(_("Comments")),        eComments(_("Comments")),
1480        eProduct(_("Product")),        eProduct(_("Product")),
# Line 1075  PropDialog::PropDialog() Line 1491  PropDialog::PropDialog()
1491        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1492        eSubject(_("Subject")),        eSubject(_("Subject")),
1493        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1494        table(2, 1)        table(2, 1),
1495          m_file(NULL)
1496  {  {
1497      set_title(_("File Properties"));      set_title(_("File Properties"));
1498      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1097  PropDialog::PropDialog() Line 1514  PropDialog::PropDialog()
1514      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1515      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1516    
1517        table.add(eFileFormat);
1518      table.add(eName);      table.add(eName);
1519      table.add(eCreationDate);      table.add(eCreationDate);
1520      table.add(eComments);      table.add(eComments);
# Line 1127  PropDialog::PropDialog() Line 1545  PropDialog::PropDialog()
1545      quitButton.grab_focus();      quitButton.grab_focus();
1546      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1547          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1548        eFileFormat.signal_value_changed().connect(
1549            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1550    
1551      quitButton.show();      quitButton.show();
1552      vbox.show();      vbox.show();
1553      show_all_children();      show_all_children();
1554  }  }
1555    
1556    void PropDialog::set_file(gig::File* file)
1557    {
1558        m_file = file;
1559    
1560        // update file format version combo box
1561        const std::string sGiga = "Gigasampler/GigaStudio v";
1562        const int major = file->pVersion->major;
1563        std::vector<std::string> txts;
1564        std::vector<int> values;
1565        txts.push_back(sGiga + "2"); values.push_back(2);
1566        txts.push_back(sGiga + "3/v4"); values.push_back(3);
1567        if (major != 2 && major != 3) {
1568            txts.push_back(sGiga + ToString(major)); values.push_back(major);
1569        }
1570        std::vector<const char*> texts;
1571        for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1572        texts.push_back(NULL); values.push_back(0);
1573        eFileFormat.set_choices(&texts[0], &values[0]);
1574        eFileFormat.set_value(major);
1575    }
1576    
1577    void PropDialog::onFileFormatChanged() {
1578        const int major = eFileFormat.get_value();
1579        if (m_file) m_file->pVersion->major = major;
1580    }
1581    
1582  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1583  {  {
1584      update(info);      update(info);
# Line 1264  void MainWindow::file_changed() Line 1710  void MainWindow::file_changed()
1710      }      }
1711  }  }
1712    
1713    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1714        sample_ref_count.clear();
1715        
1716        if (!gig) return;
1717    
1718        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1719             instrument = gig->GetNextInstrument())
1720        {
1721            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1722                 rgn = instrument->GetNextRegion())
1723            {
1724                for (int i = 0; i < 256; ++i) {
1725                    if (!rgn->pDimensionRegions[i]) continue;
1726                    if (rgn->pDimensionRegions[i]->pSample) {
1727                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1728                    }
1729                }
1730            }
1731        }
1732    }
1733    
1734  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1735  {  {
1736      file = 0;      file = 0;
1737      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1738    
1739      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1740            (filename && strlen(filename) > 0) ?
1741                filename : (!gig->GetFileName().empty()) ?
1742                    gig->GetFileName() : _("Unsaved Gig File");
1743      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1744      file_has_name = filename;      file_has_name = filename;
1745      file_is_changed = false;      file_is_changed = false;
1746    
1747        propDialog.set_file(gig);
1748      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1749    
1750      instrument_name_connection.block();      instrument_name_connection.block();
# Line 1289  void MainWindow::load_gig(gig::File* gig Line 1760  void MainWindow::load_gig(gig::File* gig
1760          add_instrument_to_menu(name);          add_instrument_to_menu(name);
1761      }      }
1762      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1763      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1764    
1765        updateSampleRefCountMap(gig);
1766    
1767      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1768          if (group->Name != "") {          if (group->Name != "") {
# Line 1307  void MainWindow::load_gig(gig::File* gig Line 1780  void MainWindow::load_gig(gig::File* gig
1780                      gig_to_utf8(sample->pInfo->Name);                      gig_to_utf8(sample->pInfo->Name);
1781                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1782                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1783                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1784                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1785                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1786              }              }
1787          }          }
1788      }      }
1789        
1790        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1791            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1792    
1793            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1794            Gtk::TreeModel::Row rowGroup = *iterGroup;
1795            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1796            rowGroup[m_ScriptsModel.m_col_group]  = group;
1797            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1798            for (int s = 0; group->GetScript(s); ++s) {
1799                gig::Script* script = group->GetScript(s);
1800    
1801                Gtk::TreeModel::iterator iterScript =
1802                    m_refScriptsTreeModel->append(rowGroup.children());
1803                Gtk::TreeModel::Row rowScript = *iterScript;
1804                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1805                rowScript[m_ScriptsModel.m_col_script] = script;
1806                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1807            }
1808        }
1809        // unfold all sample groups & script groups by default
1810        m_TreeViewSamples.expand_all();
1811        m_TreeViewScripts.expand_all();
1812    
1813      file = gig;      file = gig;
1814    
# Line 1378  void MainWindow::show_midi_rules() Line 1877  void MainWindow::show_midi_rules()
1877      }      }
1878  }  }
1879    
1880    void MainWindow::show_script_slots() {
1881        if (!file) return;
1882        // get selected instrument
1883        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1884        Gtk::TreeModel::iterator it = sel->get_selected();
1885        if (!it) return;
1886        Gtk::TreeModel::Row row = *it;
1887        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1888        if (!instrument) return;
1889    
1890        ScriptSlots* window = new ScriptSlots;
1891        window->setInstrument(instrument);
1892        //window->reparent(*this);
1893        window->show();
1894    }
1895    
1896    void MainWindow::on_action_refresh_all() {
1897        __refreshEntireGUI();
1898    }
1899    
1900  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1901      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1902          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1425  void MainWindow::on_button_release(GdkEv Line 1944  void MainWindow::on_button_release(GdkEv
1944          show_instr_props();          show_instr_props();
1945      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1946          // gig v2 files have no midi rules          // gig v2 files have no midi rules
1947            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1948            static_cast<Gtk::MenuItem*>(
1949                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1950                    bEnabled
1951                );
1952          static_cast<Gtk::MenuItem*>(          static_cast<Gtk::MenuItem*>(
1953              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1954                  !(file->pVersion && file->pVersion->major == 2));                  bEnabled
1955                );
1956          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1957      }      }
1958  }  }
# Line 1447  void MainWindow::on_instrument_selection Line 1972  void MainWindow::on_instrument_selection
1972      }      }
1973  }  }
1974    
1975    void MainWindow::select_instrument(gig::Instrument* instrument) {
1976        if (!instrument) return;
1977    
1978        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1979        for (int i = 0; i < model->children().size(); ++i) {
1980            Gtk::TreeModel::Row row = model->children()[i];
1981            if (row[m_Columns.m_col_instr] == instrument) {
1982                // select and show the respective instrument in the list view
1983                show_intruments_tab();
1984                m_TreeView.get_selection()->select(model->children()[i]);
1985                Gtk::TreePath path(
1986                    m_TreeView.get_selection()->get_selected()
1987                );
1988                m_TreeView.scroll_to_row(path);
1989                on_sel_change(); // the regular instrument selection change callback
1990            }
1991        }
1992    }
1993    
1994    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
1995    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
1996        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
1997        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
1998    
1999        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2000        for (int i = 0; i < model->children().size(); ++i) {
2001            Gtk::TreeModel::Row row = model->children()[i];
2002            if (row[m_Columns.m_col_instr] == pInstrument) {
2003                // select and show the respective instrument in the list view
2004                show_intruments_tab();
2005                m_TreeView.get_selection()->select(model->children()[i]);
2006                Gtk::TreePath path(
2007                    m_TreeView.get_selection()->get_selected()
2008                );
2009                m_TreeView.scroll_to_row(path);
2010                on_sel_change(); // the regular instrument selection change callback
2011    
2012                // select respective region in the region selector
2013                m_RegionChooser.set_region(pRegion);
2014    
2015                // select and show the respective dimension region in the editor
2016                //update_dimregs();
2017                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2018                //dimreg_edit.set_dim_region(dimRgn);
2019    
2020                return true;
2021            }
2022        }
2023    
2024        return false;
2025    }
2026    
2027    void MainWindow::select_sample(gig::Sample* sample) {
2028        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2029        for (int g = 0; g < model->children().size(); ++g) {
2030            Gtk::TreeModel::Row rowGroup = model->children()[g];
2031            for (int s = 0; s < rowGroup.children().size(); ++s) {
2032                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2033                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2034                    show_samples_tab();
2035                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2036                    Gtk::TreePath path(
2037                        m_TreeViewSamples.get_selection()->get_selected()
2038                    );
2039                    m_TreeViewSamples.scroll_to_row(path);
2040                    return;
2041                }
2042            }
2043        }
2044    }
2045    
2046  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2047      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2048          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
# Line 1461  void MainWindow::on_sample_treeview_butt Line 2057  void MainWindow::on_sample_treeview_butt
2057              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
2058              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
2059          }          }
2060            
2061                
2062          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2063              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2064          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2065              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2066          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2067              set_sensitive(file);              set_sensitive(file);
2068            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2069                set_sensitive(sample_selected);
2070          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2071              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
2072          // show sample popup          // show sample popup
2073          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2074    
2075            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2076                set_sensitive(group_selected || sample_selected);
2077            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2078                set_sensitive(group_selected || sample_selected);
2079            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2080                set_sensitive(file);
2081            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2082                set_sensitive(sample_selected);
2083            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2084                set_sensitive(group_selected || sample_selected);
2085      }      }
2086  }  }
2087    
2088    void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
2089        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2090            Gtk::Menu* script_popup =
2091                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
2092            // update enabled/disabled state of sample popup items
2093            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2094            Gtk::TreeModel::iterator it = sel->get_selected();
2095            bool group_selected  = false;
2096            bool script_selected = false;
2097            if (it) {
2098                Gtk::TreeModel::Row row = *it;
2099                group_selected  = row[m_ScriptsModel.m_col_group];
2100                script_selected = row[m_ScriptsModel.m_col_script];
2101            }
2102            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
2103                set_sensitive(group_selected || script_selected);
2104            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
2105                set_sensitive(file);
2106            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
2107                set_sensitive(script_selected);    
2108            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
2109                set_sensitive(group_selected || script_selected);
2110            // show sample popup
2111            script_popup->popup(button->button, button->time);
2112    
2113            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
2114                set_sensitive(group_selected || script_selected);
2115            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
2116                set_sensitive(file);
2117            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
2118                set_sensitive(script_selected);    
2119            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
2120                set_sensitive(group_selected || script_selected);
2121        }
2122    }
2123    
2124  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
2125      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
# Line 1621  void MainWindow::on_action_sample_proper Line 2267  void MainWindow::on_action_sample_proper
2267      msg.run();      msg.run();
2268  }  }
2269    
2270    void MainWindow::on_action_add_script_group() {
2271        static int __script_indexer = 0;
2272        if (!file) return;
2273        gig::ScriptGroup* group = file->AddScriptGroup();
2274        group->Name = gig_from_utf8(_("Unnamed Group"));
2275        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
2276        __script_indexer++;
2277        // update sample tree view
2278        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
2279        Gtk::TreeModel::Row rowGroup = *iterGroup;
2280        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
2281        rowGroup[m_ScriptsModel.m_col_script] = NULL;
2282        rowGroup[m_ScriptsModel.m_col_group] = group;
2283        file_changed();
2284    }
2285    
2286    void MainWindow::on_action_add_script() {
2287        if (!file) return;
2288        // get selected group
2289        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2290        Gtk::TreeModel::iterator it = sel->get_selected();
2291        if (!it) return;
2292        Gtk::TreeModel::Row row = *it;
2293        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2294        if (!group) { // not a group, but a script is selected (probably)
2295            gig::Script* script = row[m_ScriptsModel.m_col_script];
2296            if (!script) return;
2297            it = row.parent(); // resolve parent (that is the script's group)
2298            if (!it) return;
2299            row = *it;
2300            group = row[m_ScriptsModel.m_col_group];
2301            if (!group) return;
2302        }
2303    
2304        // add a new script to the .gig file
2305        gig::Script* script = group->AddScript();    
2306        Glib::ustring name = _("Unnamed Script");
2307        script->Name = gig_from_utf8(name);
2308    
2309        // add script to the tree view
2310        Gtk::TreeModel::iterator iterScript =
2311            m_refScriptsTreeModel->append(row.children());
2312        Gtk::TreeModel::Row rowScript = *iterScript;
2313        rowScript[m_ScriptsModel.m_col_name] = name;
2314        rowScript[m_ScriptsModel.m_col_script] = script;
2315        rowScript[m_ScriptsModel.m_col_group]  = NULL;
2316    
2317        // unfold group of new script item in treeview
2318        Gtk::TreeModel::Path path(iterScript);
2319        m_TreeViewScripts.expand_to_path(path);
2320    }
2321    
2322    void MainWindow::on_action_edit_script() {
2323        if (!file) return;
2324        // get selected script
2325        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2326        Gtk::TreeModel::iterator it = sel->get_selected();
2327        if (!it) return;
2328        Gtk::TreeModel::Row row = *it;
2329        gig::Script* script = row[m_ScriptsModel.m_col_script];
2330        if (!script) return;
2331    
2332        ScriptEditor* editor = new ScriptEditor;
2333        editor->setScript(script);
2334        //editor->reparent(*this);
2335        editor->show();
2336    }
2337    
2338    void MainWindow::on_action_remove_script() {
2339        if (!file) return;
2340        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2341        Gtk::TreeModel::iterator it = sel->get_selected();
2342        if (it) {
2343            Gtk::TreeModel::Row row = *it;
2344            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2345            gig::Script* script     = row[m_ScriptsModel.m_col_script];
2346            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2347            try {
2348                // remove script group or script from the gig file
2349                if (group) {
2350                    // notify everybody that we're going to remove these samples
2351    //TODO:         scripts_to_be_removed_signal.emit(members);
2352                    // delete the group in the .gig file including the
2353                    // samples that belong to the group
2354                    file->DeleteScriptGroup(group);
2355                    // notify that we're done with removal
2356    //TODO:         scripts_removed_signal.emit();
2357                    file_changed();
2358                } else if (script) {
2359                    // notify everybody that we're going to remove this sample
2360    //TODO:         std::list<gig::Script*> lscripts;
2361    //TODO:         lscripts.push_back(script);
2362    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2363                    // remove sample from the .gig file
2364                    script->GetGroup()->DeleteScript(script);
2365                    // notify that we're done with removal
2366    //TODO:         scripts_removed_signal.emit();
2367                    dimreg_changed();
2368                    file_changed();
2369                }
2370                // remove respective row(s) from samples tree view
2371                m_refScriptsTreeModel->erase(it);
2372            } catch (RIFF::Exception e) {
2373                // pretend we're done with removal (i.e. to avoid dead locks)
2374    //TODO:     scripts_removed_signal.emit();
2375                // show error message
2376                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2377                msg.run();
2378            }
2379        }
2380    }
2381    
2382  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2383      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2384      if (!file) return;      if (!file) return;
# Line 1637  void MainWindow::on_action_add_group() { Line 2395  void MainWindow::on_action_add_group() {
2395      file_changed();      file_changed();
2396  }  }
2397    
2398    void MainWindow::on_action_replace_sample() {
2399        add_or_replace_sample(true);
2400    }
2401    
2402  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2403        add_or_replace_sample(false);
2404    }
2405    
2406    void MainWindow::add_or_replace_sample(bool replace) {
2407      if (!file) return;      if (!file) return;
2408      // get selected group  
2409        // get selected group (and probably selected sample)
2410      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2411      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
2412      if (!it) return;      if (!it) return;
2413      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2414        gig::Sample* sample = NULL;
2415      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2416      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2417          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2418          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2419          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2420          if (!it) return;          if (!it) return;
2421          row = *it;          if (!replace) row = *it;
2422          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2423          if (!group) return;          if (!group) return;
2424      }      }
2425        if (replace && !sample) return;
2426    
2427      // show 'browse for file' dialog      // show 'browse for file' dialog
2428      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2429      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2430      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2431      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
2432    
2433      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2434  #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 1729  void MainWindow::on_action_add_sample() Line 2499  void MainWindow::on_action_add_sample()
2499                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2500                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2501                  }                  }
2502                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2503                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2504                  // file name without path                  // file name without path
2505                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2506                  // remove file extension if there is one                  // remove file extension if there is one
# Line 1781  void MainWindow::on_action_add_sample() Line 2551  void MainWindow::on_action_add_sample()
2551                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2552                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2553                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2554                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2555                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2556                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2557                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 1789  void MainWindow::on_action_add_sample() Line 2559  void MainWindow::on_action_add_sample()
2559                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2560                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2561                  // add sample to the tree view                  // add sample to the tree view
2562                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2563                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2564                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2565                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2566                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2567                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2568                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2569                            gig_to_utf8(sample->pInfo->Name);
2570                        rowSample[m_SamplesModel.m_col_sample] = sample;
2571                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2572                    }
2573                  // close sound file                  // close sound file
2574                  sf_close(hFile);                  sf_close(hFile);
2575                  file_changed();                  file_changed();
# Line 1806  void MainWindow::on_action_add_sample() Line 2580  void MainWindow::on_action_add_sample()
2580          }          }
2581          // 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
2582          if (!error_files.empty()) {          if (!error_files.empty()) {
2583              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2584                    (replace
2585                        ? _("Failed to replace sample with:\n")
2586                        : _("Could not add the following sample(s):\n"))
2587                    + error_files;
2588              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2589              msg.run();              msg.run();
2590          }          }
# Line 1990  void MainWindow::on_action_remove_sample Line 2768  void MainWindow::on_action_remove_sample
2768      }      }
2769  }  }
2770    
2771    void MainWindow::on_action_remove_unused_samples() {
2772        if (!file) return;
2773    
2774        // collect all samples that are not referenced by any instrument
2775        std::list<gig::Sample*> lsamples;
2776        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
2777            gig::Sample* sample = file->GetSample(iSample);
2778            bool isUsed = false;
2779            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
2780                                  instrument = file->GetNextInstrument())
2781            {
2782                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2783                                  rgn = instrument->GetNextRegion())
2784                {
2785                    for (int i = 0; i < 256; ++i) {
2786                        if (!rgn->pDimensionRegions[i]) continue;
2787                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
2788                        isUsed = true;
2789                        goto endOfRefSearch;
2790                    }
2791                }
2792            }
2793            endOfRefSearch:
2794            if (!isUsed) lsamples.push_back(sample);
2795        }
2796    
2797        if (lsamples.empty()) return;
2798    
2799        // notify everybody that we're going to remove these samples
2800        samples_to_be_removed_signal.emit(lsamples);
2801    
2802        // remove collected samples
2803        try {
2804            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
2805                 itSample != lsamples.end(); ++itSample)
2806            {
2807                gig::Sample* sample = *itSample;
2808                // remove sample from the .gig file
2809                file->DeleteSample(sample);
2810                // if sample was just previously added, remove it fro the import queue
2811                for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2812                     iter != m_SampleImportQueue.end(); ++iter)
2813                {
2814                    if ((*iter).gig_sample == sample) {
2815                        printf("Removing previously added sample '%s'\n",
2816                               (*iter).sample_path.c_str());
2817                        m_SampleImportQueue.erase(iter);
2818                        break;
2819                    }
2820                }
2821            }
2822        } catch (RIFF::Exception e) {
2823            // show error message
2824            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2825            msg.run();
2826        }
2827    
2828        // notify everybody that we're done with removal
2829        samples_removed_signal.emit();
2830    
2831        dimreg_changed();
2832        file_changed();
2833        __refreshEntireGUI();
2834    }
2835    
2836    // see comment on on_sample_treeview_drag_begin()
2837    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2838    {
2839        first_call_to_drag_data_get = true;
2840    }
2841    
2842    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2843                                                       Gtk::SelectionData& selection_data, guint, guint)
2844    {
2845        if (!first_call_to_drag_data_get) return;
2846        first_call_to_drag_data_get = false;
2847    
2848        // get selected script
2849        gig::Script* script = NULL;
2850        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2851        Gtk::TreeModel::iterator it = sel->get_selected();
2852        if (it) {
2853            Gtk::TreeModel::Row row = *it;
2854            script = row[m_ScriptsModel.m_col_script];
2855        }
2856        // pass the gig::Script as pointer
2857        selection_data.set(selection_data.get_target(), 0/*unused*/,
2858                           (const guchar*)&script,
2859                           sizeof(script)/*length of data in bytes*/);
2860    }
2861    
2862    // see comment on on_sample_treeview_drag_begin()
2863    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2864    {
2865        first_call_to_drag_data_get = true;
2866    }
2867    
2868    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2869                                                           Gtk::SelectionData& selection_data, guint, guint)
2870    {
2871        if (!first_call_to_drag_data_get) return;
2872        first_call_to_drag_data_get = false;
2873    
2874        // get selected source instrument
2875        gig::Instrument* src = NULL;
2876        {
2877            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2878            Gtk::TreeModel::iterator it = sel->get_selected();
2879            if (it) {
2880                Gtk::TreeModel::Row row = *it;
2881                src = row[m_Columns.m_col_instr];
2882            }
2883        }
2884        if (!src) return;
2885    
2886        // pass the source gig::Instrument as pointer
2887        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
2888                           sizeof(src)/*length of data in bytes*/);
2889    }
2890    
2891    void MainWindow::on_instruments_treeview_drop_drag_data_received(
2892        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
2893        const Gtk::SelectionData& selection_data, guint, guint time)
2894    {
2895        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
2896        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
2897            return;
2898    
2899        gig::Instrument* dst = NULL;
2900        {
2901            Gtk::TreeModel::Path path;
2902            const bool found = m_TreeView.get_path_at_pos(x, y, path);
2903            if (!found) return;
2904    
2905            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
2906            if (!iter) return;
2907            Gtk::TreeModel::Row row = *iter;
2908            dst = row[m_Columns.m_col_instr];
2909        }
2910        if (!dst) return;
2911    
2912        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
2913        src->MoveTo(dst);
2914        __refreshEntireGUI();
2915        select_instrument(src);
2916    }
2917    
2918  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2919  // 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
2920  // 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 2118  void MainWindow::sample_name_changed(con Line 3043  void MainWindow::sample_name_changed(con
3043      }      }
3044  }  }
3045    
3046    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
3047                                         const Gtk::TreeModel::iterator& iter) {
3048        if (!iter) return;
3049        Gtk::TreeModel::Row row = *iter;
3050        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
3051        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3052        gig::Script* script     = row[m_ScriptsModel.m_col_script];
3053        gig::String gigname(gig_from_utf8(name));
3054        if (group) {
3055            if (group->Name != gigname) {
3056                group->Name = gigname;
3057                printf("script group name changed\n");
3058                file_changed();
3059            }
3060        } else if (script) {
3061            if (script->Name != gigname) {
3062                script->Name = gigname;
3063                printf("script name changed\n");
3064                file_changed();
3065            }
3066        }
3067    }
3068    
3069    void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
3070                                           Gtk::TreeViewColumn* column)
3071    {
3072        Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
3073        if (!iter) return;
3074        Gtk::TreeModel::Row row = *iter;
3075        gig::Script* script = row[m_ScriptsModel.m_col_script];
3076        if (!script) return;
3077    
3078        ScriptEditor* editor = new ScriptEditor;
3079        editor->setScript(script);
3080        //editor->reparent(*this);
3081        editor->show();
3082    }
3083    
3084  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
3085                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
3086      if (!iter) return;      if (!iter) return;
# Line 2164  void MainWindow::on_action_combine_instr Line 3127  void MainWindow::on_action_combine_instr
3127      delete d;      delete d;
3128  }  }
3129    
3130    void MainWindow::on_action_view_references() {
3131        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3132        Gtk::TreeModel::iterator it = sel->get_selected();
3133        if (!it) return;
3134        Gtk::TreeModel::Row row = *it;
3135        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3136        if (!sample) return;
3137    
3138        ReferencesView* d = new ReferencesView(*this);
3139        d->setSample(sample);
3140        d->dimension_region_selected.connect(
3141            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3142        );
3143        d->show_all();
3144        d->resize(500, 400);
3145        d->run();
3146        delete d;
3147    }
3148    
3149  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
3150      struct _Source {      struct _Source {
3151          std::vector<RIFF::File*> riffs;          std::vector<RIFF::File*> riffs;
# Line 2231  void MainWindow::mergeFiles(const std::v Line 3213  void MainWindow::mergeFiles(const std::v
3213          );          );
3214      }      }
3215    
3216      // Note: requires that this file already has a filename !      // Finally save gig file persistently to disk ...
3217      this->file->Save();      //NOTE: requires that this gig file already has a filename !
3218        {
3219            std::cout << "Saving file\n" << std::flush;
3220            file_structure_to_be_changed_signal.emit(this->file);
3221    
3222            progress_dialog = new ProgressDialog( //FIXME: memory leak!
3223                _("Saving") +  Glib::ustring(" '") +
3224                Glib::filename_display_basename(this->filename) + "' ...",
3225                *this
3226            );
3227            progress_dialog->show_all();
3228            saver = new Saver(this->file); //FIXME: memory leak!
3229            saver->signal_progress().connect(
3230                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
3231            saver->signal_finished().connect(
3232                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
3233            saver->signal_error().connect(
3234                sigc::mem_fun(*this, &MainWindow::on_saver_error));
3235            saver->launch();
3236        }
3237  }  }
3238    
3239  void MainWindow::on_action_merge_files() {  void MainWindow::on_action_merge_files() {
# Line 2304  void MainWindow::on_action_merge_files() Line 3305  void MainWindow::on_action_merge_files()
3305          }          }
3306    
3307          // update GUI          // update GUI
3308          __refreshEntireGUI();                  __refreshEntireGUI();
3309      }      }
3310  }  }
3311    
# Line 2322  void MainWindow::set_file_is_shared(bool Line 3323  void MainWindow::set_file_is_shared(bool
3323              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
3324          );          );
3325      }      }
3326    
3327        {
3328            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
3329                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
3330            if (item) item->set_sensitive(b);
3331        }
3332    }
3333    
3334    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
3335        if (!sample) return;
3336        sample_ref_count[sample] += offset;
3337        const int refcount = sample_ref_count[sample];
3338    
3339        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3340        for (int g = 0; g < model->children().size(); ++g) {
3341            Gtk::TreeModel::Row rowGroup = model->children()[g];
3342            for (int s = 0; s < rowGroup.children().size(); ++s) {
3343                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3344                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
3345                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
3346                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
3347            }
3348        }
3349    }
3350    
3351    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
3352        on_sample_ref_count_incremented(oldSample, -1);
3353        on_sample_ref_count_incremented(newSample, +1);
3354    }
3355    
3356    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
3357        // just in case a new sample is added later with exactly the same memory
3358        // address, which would lead to incorrect refcount if not deleted here
3359        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
3360             it != samples.end(); ++it)
3361        {
3362            sample_ref_count.erase(*it);
3363        }
3364    }
3365    
3366    void MainWindow::show_samples_tab() {
3367        m_TreeViewNotebook.set_current_page(0);
3368    }
3369    
3370    void MainWindow::show_intruments_tab() {
3371        m_TreeViewNotebook.set_current_page(1);
3372    }
3373    
3374    void MainWindow::show_scripts_tab() {
3375        m_TreeViewNotebook.set_current_page(2);
3376  }  }
3377    
3378  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 2379  sigc::signal<void, int/*key*/, int/*velo Line 3430  sigc::signal<void, int/*key*/, int/*velo
3430  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
3431      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
3432  }  }
3433    
3434    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
3435        return switch_sampler_instrument_signal;
3436    }

Legend:
Removed from v.2553  
changed lines
  Added in v.2773

  ViewVC Help
Powered by ViewVC