40 |
|
|
41 |
#include <stdio.h> |
#include <stdio.h> |
42 |
#include <sndfile.h> |
#include <sndfile.h> |
43 |
|
#include <assert.h> |
44 |
|
|
45 |
#include "mainwindow.h" |
#include "mainwindow.h" |
46 |
#include "Settings.h" |
#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")), |
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 |
|
|
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 |
|
|
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 |
|
|
225 |
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
226 |
); |
); |
227 |
|
|
228 |
|
actionGroup->add( |
229 |
|
Gtk::Action::create("MergeFiles", _("_Merge Files...")), |
230 |
|
sigc::mem_fun(*this, &MainWindow::on_action_merge_files) |
231 |
|
); |
232 |
|
|
233 |
|
|
234 |
// sample right-click popup actions |
// sample right-click popup actions |
235 |
actionGroup->add( |
actionGroup->add( |
249 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
250 |
); |
); |
251 |
actionGroup->add( |
actionGroup->add( |
252 |
|
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
253 |
|
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
254 |
|
); |
255 |
|
actionGroup->add( |
256 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
257 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
258 |
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) |
259 |
); |
); |
260 |
|
|
261 |
|
// script right-click popup actions |
262 |
|
actionGroup->add( |
263 |
|
Gtk::Action::create("AddScriptGroup", _("Add _Group")), |
264 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) |
265 |
|
); |
266 |
|
actionGroup->add( |
267 |
|
Gtk::Action::create("AddScript", _("Add _Script")), |
268 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script) |
269 |
|
); |
270 |
|
actionGroup->add( |
271 |
|
Gtk::Action::create("EditScript", _("_Edit Script...")), |
272 |
|
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
273 |
|
); |
274 |
|
actionGroup->add( |
275 |
|
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
276 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
277 |
|
); |
278 |
|
|
279 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
280 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
299 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
300 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
301 |
" </menu>" |
" </menu>" |
302 |
|
" <menu action='MenuSample'>" |
303 |
|
" <menuitem action='SampleProperties'/>" |
304 |
|
" <menuitem action='AddGroup'/>" |
305 |
|
" <menuitem action='AddSample'/>" |
306 |
|
" <menuitem action='ShowSampleRefs'/>" |
307 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
308 |
|
" <separator/>" |
309 |
|
" <menuitem action='RemoveSample'/>" |
310 |
|
" </menu>" |
311 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
312 |
|
" <menu action='AllInstruments'>" |
313 |
|
" </menu>" |
314 |
|
" <separator/>" |
315 |
|
" <menuitem action='InstrProperties'/>" |
316 |
|
" <menuitem action='MidiRules'/>" |
317 |
|
" <menuitem action='ScriptSlots'/>" |
318 |
|
" <menuitem action='AddInstrument'/>" |
319 |
|
" <menuitem action='DupInstrument'/>" |
320 |
|
" <separator/>" |
321 |
|
" <menuitem action='RemoveInstrument'/>" |
322 |
|
" </menu>" |
323 |
|
" <menu action='MenuScript'>" |
324 |
|
" <menuitem action='AddScriptGroup'/>" |
325 |
|
" <menuitem action='AddScript'/>" |
326 |
|
" <menuitem action='EditScript'/>" |
327 |
|
" <separator/>" |
328 |
|
" <menuitem action='RemoveScript'/>" |
329 |
" </menu>" |
" </menu>" |
330 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
331 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
332 |
" </menu>" |
" </menu>" |
333 |
" <menu action='MenuTools'>" |
" <menu action='MenuTools'>" |
334 |
" <menuitem action='CombineInstruments'/>" |
" <menuitem action='CombineInstruments'/>" |
335 |
|
" <menuitem action='MergeFiles'/>" |
336 |
" </menu>" |
" </menu>" |
337 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
338 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
344 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
345 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
346 |
" <menuitem action='MidiRules'/>" |
" <menuitem action='MidiRules'/>" |
347 |
|
" <menuitem action='ScriptSlots'/>" |
348 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
349 |
" <menuitem action='DupInstrument'/>" |
" <menuitem action='DupInstrument'/>" |
350 |
" <separator/>" |
" <separator/>" |
354 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
355 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
356 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
357 |
|
" <menuitem action='ShowSampleRefs'/>" |
358 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
359 |
" <separator/>" |
" <separator/>" |
360 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
361 |
" </popup>" |
" </popup>" |
362 |
|
" <popup name='ScriptPopupMenu'>" |
363 |
|
" <menuitem action='AddScriptGroup'/>" |
364 |
|
" <menuitem action='AddScript'/>" |
365 |
|
" <menuitem action='EditScript'/>" |
366 |
|
" <separator/>" |
367 |
|
" <menuitem action='RemoveScript'/>" |
368 |
|
" </popup>" |
369 |
"</ui>"; |
"</ui>"; |
370 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
371 |
|
|
395 |
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
396 |
item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application.")); |
item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application.")); |
397 |
} |
} |
398 |
|
{ |
399 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
400 |
|
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
401 |
|
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
402 |
|
} |
403 |
|
{ |
404 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
405 |
|
uiManager->get_widget("/MenuBar/MenuTools/MergeFiles")); |
406 |
|
item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file.")); |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
411 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
412 |
|
|
413 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
414 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
448 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
449 |
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.")); |
450 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
451 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
452 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); |
453 |
|
{ |
454 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
455 |
|
Gtk::CellRendererText* cellrenderer = |
456 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
457 |
|
column->add_attribute( |
458 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
459 |
|
); |
460 |
|
} |
461 |
|
{ |
462 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
463 |
|
Gtk::CellRendererText* cellrenderer = |
464 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
465 |
|
column->add_attribute( |
466 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
467 |
|
); |
468 |
|
} |
469 |
|
m_TreeViewSamples.set_headers_visible(true); |
470 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
471 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
472 |
); |
); |
474 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
475 |
); |
); |
476 |
|
|
477 |
|
// create scripts treeview (including its data model) |
478 |
|
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
479 |
|
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
480 |
|
m_TreeViewScripts.set_tooltip_text(_( |
481 |
|
"Use CTRL + double click for editing a script." |
482 |
|
"\n\n" |
483 |
|
"Note: instrument scripts are a LinuxSampler extension of the gig " |
484 |
|
"format. This feature will not work with the GigaStudio software!" |
485 |
|
)); |
486 |
|
// m_TreeViewScripts.set_reorderable(); |
487 |
|
m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); |
488 |
|
m_TreeViewScripts.set_headers_visible(false); |
489 |
|
m_TreeViewScripts.signal_button_press_event().connect_notify( |
490 |
|
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
491 |
|
); |
492 |
|
//FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ? |
493 |
|
m_TreeViewScripts.signal_row_activated().connect( |
494 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
495 |
|
); |
496 |
|
m_refScriptsTreeModel->signal_row_changed().connect( |
497 |
|
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
498 |
|
); |
499 |
|
|
500 |
|
// establish drag&drop between scripts tree view and ScriptSlots window |
501 |
|
std::vector<Gtk::TargetEntry> drag_target_gig_script; |
502 |
|
drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); |
503 |
|
m_TreeViewScripts.drag_source_set(drag_target_gig_script); |
504 |
|
m_TreeViewScripts.signal_drag_begin().connect( |
505 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin) |
506 |
|
); |
507 |
|
m_TreeViewScripts.signal_drag_data_get().connect( |
508 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get) |
509 |
|
); |
510 |
|
|
511 |
// 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 |
512 |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
513 |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
541 |
dimreg_changed_signal.make_slot()); |
dimreg_changed_signal.make_slot()); |
542 |
dimreg_edit.signal_sample_ref_changed().connect( |
dimreg_edit.signal_sample_ref_changed().connect( |
543 |
sample_ref_changed_signal.make_slot()); |
sample_ref_changed_signal.make_slot()); |
544 |
|
sample_ref_changed_signal.connect( |
545 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) |
546 |
|
); |
547 |
|
samples_to_be_removed_signal.connect( |
548 |
|
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
549 |
|
); |
550 |
|
|
551 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
552 |
sigc::hide( |
sigc::hide( |
588 |
|
|
589 |
// start with a new gig file by default |
// start with a new gig file by default |
590 |
on_action_file_new(); |
on_action_file_new(); |
591 |
|
|
592 |
|
// select 'Instruments' tab by default |
593 |
|
// (gtk allows this only if the tab childs are visible, thats why it's here) |
594 |
|
m_TreeViewNotebook.set_current_page(1); |
595 |
} |
} |
596 |
|
|
597 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
672 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
673 |
{ |
{ |
674 |
update_dimregs(); |
update_dimregs(); |
675 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); |
676 |
} |
} |
677 |
|
|
678 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
770 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
771 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
772 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
773 |
|
m_refScriptsTreeModel->clear(); |
774 |
// remove all entries from "Instrument" menu |
// remove all entries from "Instrument" menu |
775 |
while (!instrument_menu->get_children().empty()) { |
while (!instrument_menu->get_children().empty()) { |
776 |
remove_instrument_from_menu(0); |
remove_instrument_from_menu(0); |
781 |
set_file_is_shared(false); |
set_file_is_shared(false); |
782 |
} |
} |
783 |
|
|
784 |
|
void MainWindow::__refreshEntireGUI() { |
785 |
|
// clear the samples and instruments tree views |
786 |
|
m_refTreeModel->clear(); |
787 |
|
m_refSamplesTreeModel->clear(); |
788 |
|
m_refScriptsTreeModel->clear(); |
789 |
|
// remove all entries from "Instrument" menu |
790 |
|
while (!instrument_menu->get_children().empty()) { |
791 |
|
remove_instrument_from_menu(0); |
792 |
|
} |
793 |
|
|
794 |
|
if (!this->file) return; |
795 |
|
|
796 |
|
load_gig( |
797 |
|
this->file, this->file->pInfo->Name.c_str(), this->file_is_shared |
798 |
|
); |
799 |
|
} |
800 |
|
|
801 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
802 |
{ |
{ |
803 |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
902 |
// load the instrument |
// load the instrument |
903 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
904 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
905 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
906 |
|
int i = 0; |
907 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
908 |
|
instrument = pFile->GetNextInstrument(), ++i) |
909 |
|
{ |
910 |
|
if (instrument == instr) { |
911 |
|
// select item in "instruments" tree view |
912 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
913 |
|
// make sure the selected item in the "instruments" tree view is |
914 |
|
// visible (scroll to it) |
915 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
916 |
|
// select item in instrument menu |
917 |
|
{ |
918 |
|
const std::vector<Gtk::Widget*> children = |
919 |
|
instrument_menu->get_children(); |
920 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
921 |
|
} |
922 |
|
// update region chooser and dimension region chooser |
923 |
|
m_RegionChooser.set_instrument(instr); |
924 |
|
break; |
925 |
|
} |
926 |
|
} |
927 |
} |
} |
928 |
|
|
929 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1204 |
_( |
_( |
1205 |
"Gigedit is released under the GNU General Public License.\n" |
"Gigedit is released under the GNU General Public License.\n" |
1206 |
"\n" |
"\n" |
1207 |
"Please notice that this is still a very young instrument editor. " |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1208 |
"So better backup your Gigasampler files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
1209 |
"this application.\n" |
"this application.\n" |
1210 |
"\n" |
"\n" |
1211 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: http://bugs.linuxsampler.org" |
1217 |
} |
} |
1218 |
|
|
1219 |
PropDialog::PropDialog() |
PropDialog::PropDialog() |
1220 |
: eName(_("Name")), |
: eFileFormat(_("File Format")), |
1221 |
|
eName(_("Name")), |
1222 |
eCreationDate(_("Creation date")), |
eCreationDate(_("Creation date")), |
1223 |
eComments(_("Comments")), |
eComments(_("Comments")), |
1224 |
eProduct(_("Product")), |
eProduct(_("Product")), |
1235 |
eCommissioned(_("Commissioned")), |
eCommissioned(_("Commissioned")), |
1236 |
eSubject(_("Subject")), |
eSubject(_("Subject")), |
1237 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(Gtk::Stock::CLOSE), |
1238 |
table(2, 1) |
table(2, 1), |
1239 |
|
m_file(NULL) |
1240 |
{ |
{ |
1241 |
set_title(_("File Properties")); |
set_title(_("File Properties")); |
1242 |
eName.set_width_chars(50); |
eName.set_width_chars(50); |
1258 |
connect(eCommissioned, &DLS::Info::Commissioned); |
connect(eCommissioned, &DLS::Info::Commissioned); |
1259 |
connect(eSubject, &DLS::Info::Subject); |
connect(eSubject, &DLS::Info::Subject); |
1260 |
|
|
1261 |
|
table.add(eFileFormat); |
1262 |
table.add(eName); |
table.add(eName); |
1263 |
table.add(eCreationDate); |
table.add(eCreationDate); |
1264 |
table.add(eComments); |
table.add(eComments); |
1289 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
1290 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
1291 |
sigc::mem_fun(*this, &PropDialog::hide)); |
sigc::mem_fun(*this, &PropDialog::hide)); |
1292 |
|
eFileFormat.signal_value_changed().connect( |
1293 |
|
sigc::mem_fun(*this, &PropDialog::onFileFormatChanged)); |
1294 |
|
|
1295 |
quitButton.show(); |
quitButton.show(); |
1296 |
vbox.show(); |
vbox.show(); |
1297 |
show_all_children(); |
show_all_children(); |
1298 |
} |
} |
1299 |
|
|
1300 |
|
void PropDialog::set_file(gig::File* file) |
1301 |
|
{ |
1302 |
|
m_file = file; |
1303 |
|
|
1304 |
|
// update file format version combo box |
1305 |
|
const std::string sGiga = "Gigasampler/GigaStudio v"; |
1306 |
|
const int major = file->pVersion->major; |
1307 |
|
std::vector<std::string> txts; |
1308 |
|
std::vector<int> values; |
1309 |
|
txts.push_back(sGiga + "2"); values.push_back(2); |
1310 |
|
txts.push_back(sGiga + "3/v4"); values.push_back(3); |
1311 |
|
if (major != 2 && major != 3) { |
1312 |
|
txts.push_back(sGiga + ToString(major)); values.push_back(major); |
1313 |
|
} |
1314 |
|
std::vector<const char*> texts; |
1315 |
|
for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); |
1316 |
|
texts.push_back(NULL); values.push_back(0); |
1317 |
|
eFileFormat.set_choices(&texts[0], &values[0]); |
1318 |
|
eFileFormat.set_value(major); |
1319 |
|
} |
1320 |
|
|
1321 |
|
void PropDialog::onFileFormatChanged() { |
1322 |
|
const int major = eFileFormat.get_value(); |
1323 |
|
if (m_file) m_file->pVersion->major = major; |
1324 |
|
} |
1325 |
|
|
1326 |
void PropDialog::set_info(DLS::Info* info) |
void PropDialog::set_info(DLS::Info* info) |
1327 |
{ |
{ |
1328 |
update(info); |
update(info); |
1454 |
} |
} |
1455 |
} |
} |
1456 |
|
|
1457 |
|
void MainWindow::updateSampleRefCountMap(gig::File* gig) { |
1458 |
|
sample_ref_count.clear(); |
1459 |
|
|
1460 |
|
if (!gig) return; |
1461 |
|
|
1462 |
|
for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; |
1463 |
|
instrument = gig->GetNextInstrument()) |
1464 |
|
{ |
1465 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
1466 |
|
rgn = instrument->GetNextRegion()) |
1467 |
|
{ |
1468 |
|
for (int i = 0; i < 256; ++i) { |
1469 |
|
if (!rgn->pDimensionRegions[i]) continue; |
1470 |
|
if (rgn->pDimensionRegions[i]->pSample) { |
1471 |
|
sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; |
1472 |
|
} |
1473 |
|
} |
1474 |
|
} |
1475 |
|
} |
1476 |
|
} |
1477 |
|
|
1478 |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1479 |
{ |
{ |
1480 |
file = 0; |
file = 0; |
1485 |
file_has_name = filename; |
file_has_name = filename; |
1486 |
file_is_changed = false; |
file_is_changed = false; |
1487 |
|
|
1488 |
|
propDialog.set_file(gig); |
1489 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1490 |
|
|
1491 |
instrument_name_connection.block(); |
instrument_name_connection.block(); |
1501 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
1502 |
} |
} |
1503 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1504 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); |
1505 |
|
|
1506 |
|
updateSampleRefCountMap(gig); |
1507 |
|
|
1508 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1509 |
if (group->Name != "") { |
if (group->Name != "") { |
1521 |
gig_to_utf8(sample->pInfo->Name); |
gig_to_utf8(sample->pInfo->Name); |
1522 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1523 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1524 |
|
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1525 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1526 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
1527 |
} |
} |
1528 |
} |
} |
1529 |
} |
} |
1530 |
|
|
1531 |
|
for (int i = 0; gig->GetScriptGroup(i); ++i) { |
1532 |
|
gig::ScriptGroup* group = gig->GetScriptGroup(i); |
1533 |
|
|
1534 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1535 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1536 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1537 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1538 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1539 |
|
for (int s = 0; group->GetScript(s); ++s) { |
1540 |
|
gig::Script* script = group->GetScript(s); |
1541 |
|
|
1542 |
|
Gtk::TreeModel::iterator iterScript = |
1543 |
|
m_refScriptsTreeModel->append(rowGroup.children()); |
1544 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1545 |
|
rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); |
1546 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1547 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1548 |
|
} |
1549 |
|
} |
1550 |
|
// unfold all sample groups & script groups by default |
1551 |
|
m_TreeViewSamples.expand_all(); |
1552 |
|
m_TreeViewScripts.expand_all(); |
1553 |
|
|
1554 |
file = gig; |
file = gig; |
1555 |
|
|
1618 |
} |
} |
1619 |
} |
} |
1620 |
|
|
1621 |
|
void MainWindow::show_script_slots() { |
1622 |
|
if (!file) return; |
1623 |
|
// get selected instrument |
1624 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1625 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1626 |
|
if (!it) return; |
1627 |
|
Gtk::TreeModel::Row row = *it; |
1628 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1629 |
|
if (!instrument) return; |
1630 |
|
|
1631 |
|
ScriptSlots* window = new ScriptSlots; |
1632 |
|
window->setInstrument(instrument); |
1633 |
|
//window->reparent(*this); |
1634 |
|
window->show(); |
1635 |
|
} |
1636 |
|
|
1637 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1638 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1639 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1681 |
show_instr_props(); |
show_instr_props(); |
1682 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1683 |
// gig v2 files have no midi rules |
// gig v2 files have no midi rules |
1684 |
|
const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); |
1685 |
|
static_cast<Gtk::MenuItem*>( |
1686 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( |
1687 |
|
bEnabled |
1688 |
|
); |
1689 |
static_cast<Gtk::MenuItem*>( |
static_cast<Gtk::MenuItem*>( |
1690 |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1691 |
!(file->pVersion && file->pVersion->major == 2)); |
bEnabled |
1692 |
|
); |
1693 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1694 |
} |
} |
1695 |
} |
} |
1723 |
group_selected = row[m_SamplesModel.m_col_group]; |
group_selected = row[m_SamplesModel.m_col_group]; |
1724 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
sample_selected = row[m_SamplesModel.m_col_sample]; |
1725 |
} |
} |
1726 |
|
|
1727 |
|
|
1728 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
1729 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1730 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
1731 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1732 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
1733 |
set_sensitive(file); |
set_sensitive(file); |
1734 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
1735 |
|
set_sensitive(sample_selected); |
1736 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
1737 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1738 |
// show sample popup |
// show sample popup |
1739 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
1740 |
|
|
1741 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
1742 |
|
set_sensitive(group_selected || sample_selected); |
1743 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
1744 |
|
set_sensitive(group_selected || sample_selected); |
1745 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
1746 |
|
set_sensitive(file); |
1747 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
1748 |
|
set_sensitive(sample_selected); |
1749 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
1750 |
|
set_sensitive(group_selected || sample_selected); |
1751 |
} |
} |
1752 |
} |
} |
1753 |
|
|
1754 |
|
void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { |
1755 |
|
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1756 |
|
Gtk::Menu* script_popup = |
1757 |
|
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu")); |
1758 |
|
// update enabled/disabled state of sample popup items |
1759 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1760 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1761 |
|
bool group_selected = false; |
1762 |
|
bool script_selected = false; |
1763 |
|
if (it) { |
1764 |
|
Gtk::TreeModel::Row row = *it; |
1765 |
|
group_selected = row[m_ScriptsModel.m_col_group]; |
1766 |
|
script_selected = row[m_ScriptsModel.m_col_script]; |
1767 |
|
} |
1768 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> |
1769 |
|
set_sensitive(group_selected || script_selected); |
1770 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> |
1771 |
|
set_sensitive(file); |
1772 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> |
1773 |
|
set_sensitive(script_selected); |
1774 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> |
1775 |
|
set_sensitive(group_selected || script_selected); |
1776 |
|
// show sample popup |
1777 |
|
script_popup->popup(button->button, button->time); |
1778 |
|
|
1779 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> |
1780 |
|
set_sensitive(group_selected || script_selected); |
1781 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> |
1782 |
|
set_sensitive(file); |
1783 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> |
1784 |
|
set_sensitive(script_selected); |
1785 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> |
1786 |
|
set_sensitive(group_selected || script_selected); |
1787 |
|
} |
1788 |
|
} |
1789 |
|
|
1790 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1791 |
const Glib::ustring& name, int position) { |
const Glib::ustring& name, int position) { |
1933 |
msg.run(); |
msg.run(); |
1934 |
} |
} |
1935 |
|
|
1936 |
|
void MainWindow::on_action_add_script_group() { |
1937 |
|
static int __script_indexer = 0; |
1938 |
|
if (!file) return; |
1939 |
|
gig::ScriptGroup* group = file->AddScriptGroup(); |
1940 |
|
group->Name = gig_from_utf8(_("Unnamed Group")); |
1941 |
|
if (__script_indexer) group->Name += " " + ToString(__script_indexer); |
1942 |
|
__script_indexer++; |
1943 |
|
// update sample tree view |
1944 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1945 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1946 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1947 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1948 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1949 |
|
file_changed(); |
1950 |
|
} |
1951 |
|
|
1952 |
|
void MainWindow::on_action_add_script() { |
1953 |
|
if (!file) return; |
1954 |
|
// get selected group |
1955 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1956 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1957 |
|
if (!it) return; |
1958 |
|
Gtk::TreeModel::Row row = *it; |
1959 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
1960 |
|
if (!group) { // not a group, but a script is selected (probably) |
1961 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1962 |
|
if (!script) return; |
1963 |
|
it = row.parent(); // resolve parent (that is the script's group) |
1964 |
|
if (!it) return; |
1965 |
|
row = *it; |
1966 |
|
group = row[m_ScriptsModel.m_col_group]; |
1967 |
|
if (!group) return; |
1968 |
|
} |
1969 |
|
|
1970 |
|
// add a new script to the .gig file |
1971 |
|
gig::Script* script = group->AddScript(); |
1972 |
|
Glib::ustring name = _("Unnamed Script"); |
1973 |
|
script->Name = gig_from_utf8(name); |
1974 |
|
|
1975 |
|
// add script to the tree view |
1976 |
|
Gtk::TreeModel::iterator iterScript = |
1977 |
|
m_refScriptsTreeModel->append(row.children()); |
1978 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1979 |
|
rowScript[m_ScriptsModel.m_col_name] = name; |
1980 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1981 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1982 |
|
|
1983 |
|
// unfold group of new script item in treeview |
1984 |
|
Gtk::TreeModel::Path path(iterScript); |
1985 |
|
m_TreeViewScripts.expand_to_path(path); |
1986 |
|
} |
1987 |
|
|
1988 |
|
void MainWindow::on_action_edit_script() { |
1989 |
|
if (!file) return; |
1990 |
|
// get selected script |
1991 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1992 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1993 |
|
if (!it) return; |
1994 |
|
Gtk::TreeModel::Row row = *it; |
1995 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1996 |
|
if (!script) return; |
1997 |
|
|
1998 |
|
ScriptEditor* editor = new ScriptEditor; |
1999 |
|
editor->setScript(script); |
2000 |
|
//editor->reparent(*this); |
2001 |
|
editor->show(); |
2002 |
|
} |
2003 |
|
|
2004 |
|
void MainWindow::on_action_remove_script() { |
2005 |
|
if (!file) return; |
2006 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2007 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2008 |
|
if (it) { |
2009 |
|
Gtk::TreeModel::Row row = *it; |
2010 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2011 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2012 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2013 |
|
try { |
2014 |
|
// remove script group or script from the gig file |
2015 |
|
if (group) { |
2016 |
|
// notify everybody that we're going to remove these samples |
2017 |
|
//TODO: scripts_to_be_removed_signal.emit(members); |
2018 |
|
// delete the group in the .gig file including the |
2019 |
|
// samples that belong to the group |
2020 |
|
file->DeleteScriptGroup(group); |
2021 |
|
// notify that we're done with removal |
2022 |
|
//TODO: scripts_removed_signal.emit(); |
2023 |
|
file_changed(); |
2024 |
|
} else if (script) { |
2025 |
|
// notify everybody that we're going to remove this sample |
2026 |
|
//TODO: std::list<gig::Script*> lscripts; |
2027 |
|
//TODO: lscripts.push_back(script); |
2028 |
|
//TODO: scripts_to_be_removed_signal.emit(lscripts); |
2029 |
|
// remove sample from the .gig file |
2030 |
|
script->GetGroup()->DeleteScript(script); |
2031 |
|
// notify that we're done with removal |
2032 |
|
//TODO: scripts_removed_signal.emit(); |
2033 |
|
dimreg_changed(); |
2034 |
|
file_changed(); |
2035 |
|
} |
2036 |
|
// remove respective row(s) from samples tree view |
2037 |
|
m_refScriptsTreeModel->erase(it); |
2038 |
|
} catch (RIFF::Exception e) { |
2039 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
2040 |
|
//TODO: scripts_removed_signal.emit(); |
2041 |
|
// show error message |
2042 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2043 |
|
msg.run(); |
2044 |
|
} |
2045 |
|
} |
2046 |
|
} |
2047 |
|
|
2048 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |
2049 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
2050 |
if (!file) return; |
if (!file) return; |
2414 |
} |
} |
2415 |
} |
} |
2416 |
|
|
2417 |
|
// see comment on on_sample_treeview_drag_begin() |
2418 |
|
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2419 |
|
{ |
2420 |
|
first_call_to_drag_data_get = true; |
2421 |
|
} |
2422 |
|
|
2423 |
|
void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2424 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2425 |
|
{ |
2426 |
|
if (!first_call_to_drag_data_get) return; |
2427 |
|
first_call_to_drag_data_get = false; |
2428 |
|
|
2429 |
|
// get selected script |
2430 |
|
gig::Script* script = NULL; |
2431 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2432 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2433 |
|
if (it) { |
2434 |
|
Gtk::TreeModel::Row row = *it; |
2435 |
|
script = row[m_ScriptsModel.m_col_script]; |
2436 |
|
} |
2437 |
|
// pass the gig::Script as pointer |
2438 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, |
2439 |
|
(const guchar*)&script, |
2440 |
|
sizeof(script)/*length of data in bytes*/); |
2441 |
|
} |
2442 |
|
|
2443 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2444 |
// 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 |
2445 |
// 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 |
2498 |
bool channels_changed = false; |
bool channels_changed = false; |
2499 |
if (sample->Channels == 1 && stereo_dimension) { |
if (sample->Channels == 1 && stereo_dimension) { |
2500 |
// remove the samplechannel dimension |
// remove the samplechannel dimension |
2501 |
|
/* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples |
2502 |
region->DeleteDimension(stereo_dimension); |
region->DeleteDimension(stereo_dimension); |
2503 |
channels_changed = true; |
channels_changed = true; |
2504 |
region_changed(); |
region_changed(); |
2505 |
|
*/ |
2506 |
} |
} |
2507 |
dimreg_edit.set_sample( |
dimreg_edit.set_sample( |
2508 |
sample, |
sample, |
2568 |
} |
} |
2569 |
} |
} |
2570 |
|
|
2571 |
|
void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, |
2572 |
|
const Gtk::TreeModel::iterator& iter) { |
2573 |
|
if (!iter) return; |
2574 |
|
Gtk::TreeModel::Row row = *iter; |
2575 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2576 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2577 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2578 |
|
gig::String gigname(gig_from_utf8(name)); |
2579 |
|
if (group) { |
2580 |
|
if (group->Name != gigname) { |
2581 |
|
group->Name = gigname; |
2582 |
|
printf("script group name changed\n"); |
2583 |
|
file_changed(); |
2584 |
|
} |
2585 |
|
} else if (script) { |
2586 |
|
if (script->Name != gigname) { |
2587 |
|
script->Name = gigname; |
2588 |
|
printf("script name changed\n"); |
2589 |
|
file_changed(); |
2590 |
|
} |
2591 |
|
} |
2592 |
|
} |
2593 |
|
|
2594 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
2595 |
|
Gtk::TreeViewColumn* column) |
2596 |
|
{ |
2597 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
2598 |
|
if (!iter) return; |
2599 |
|
Gtk::TreeModel::Row row = *iter; |
2600 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2601 |
|
if (!script) return; |
2602 |
|
|
2603 |
|
ScriptEditor* editor = new ScriptEditor; |
2604 |
|
editor->setScript(script); |
2605 |
|
//editor->reparent(*this); |
2606 |
|
editor->show(); |
2607 |
|
} |
2608 |
|
|
2609 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
2610 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
2611 |
if (!iter) return; |
if (!iter) return; |
2652 |
delete d; |
delete d; |
2653 |
} |
} |
2654 |
|
|
2655 |
|
void MainWindow::on_action_view_references() { |
2656 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2657 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2658 |
|
if (!it) return; |
2659 |
|
Gtk::TreeModel::Row row = *it; |
2660 |
|
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2661 |
|
if (!sample) return; |
2662 |
|
|
2663 |
|
ReferencesView* d = new ReferencesView(*this); |
2664 |
|
d->setSample(sample); |
2665 |
|
d->show_all(); |
2666 |
|
d->resize(500, 400); |
2667 |
|
d->run(); |
2668 |
|
delete d; |
2669 |
|
} |
2670 |
|
|
2671 |
|
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
2672 |
|
struct _Source { |
2673 |
|
std::vector<RIFF::File*> riffs; |
2674 |
|
std::vector<gig::File*> gigs; |
2675 |
|
|
2676 |
|
~_Source() { |
2677 |
|
for (int k = 0; k < gigs.size(); ++k) delete gigs[k]; |
2678 |
|
for (int k = 0; k < riffs.size(); ++k) delete riffs[k]; |
2679 |
|
riffs.clear(); |
2680 |
|
gigs.clear(); |
2681 |
|
} |
2682 |
|
} sources; |
2683 |
|
|
2684 |
|
if (filenames.empty()) |
2685 |
|
throw RIFF::Exception(_("No files selected, so nothing done.")); |
2686 |
|
|
2687 |
|
// first open all input files (to avoid output file corruption) |
2688 |
|
int i; |
2689 |
|
try { |
2690 |
|
for (i = 0; i < filenames.size(); ++i) { |
2691 |
|
const std::string& filename = filenames[i]; |
2692 |
|
printf("opening file=%s\n", filename.c_str()); |
2693 |
|
|
2694 |
|
RIFF::File* riff = new RIFF::File(filename); |
2695 |
|
sources.riffs.push_back(riff); |
2696 |
|
|
2697 |
|
gig::File* gig = new gig::File(riff); |
2698 |
|
sources.gigs.push_back(gig); |
2699 |
|
} |
2700 |
|
} catch (RIFF::Exception e) { |
2701 |
|
throw RIFF::Exception( |
2702 |
|
_("Error occurred while opening '") + |
2703 |
|
filenames[i] + |
2704 |
|
"': " + |
2705 |
|
e.Message |
2706 |
|
); |
2707 |
|
} catch (...) { |
2708 |
|
throw RIFF::Exception( |
2709 |
|
_("Unknown exception occurred while opening '") + |
2710 |
|
filenames[i] + "'" |
2711 |
|
); |
2712 |
|
} |
2713 |
|
|
2714 |
|
// now merge the opened .gig files to the main .gig file currently being |
2715 |
|
// open in gigedit |
2716 |
|
try { |
2717 |
|
for (i = 0; i < filenames.size(); ++i) { |
2718 |
|
const std::string& filename = filenames[i]; |
2719 |
|
printf("merging file=%s\n", filename.c_str()); |
2720 |
|
assert(i < sources.gigs.size()); |
2721 |
|
|
2722 |
|
this->file->AddContentOf(sources.gigs[i]); |
2723 |
|
} |
2724 |
|
} catch (RIFF::Exception e) { |
2725 |
|
throw RIFF::Exception( |
2726 |
|
_("Error occurred while merging '") + |
2727 |
|
filenames[i] + |
2728 |
|
"': " + |
2729 |
|
e.Message |
2730 |
|
); |
2731 |
|
} catch (...) { |
2732 |
|
throw RIFF::Exception( |
2733 |
|
_("Unknown exception occurred while merging '") + |
2734 |
|
filenames[i] + "'" |
2735 |
|
); |
2736 |
|
} |
2737 |
|
|
2738 |
|
// Note: requires that this file already has a filename ! |
2739 |
|
this->file->Save(); |
2740 |
|
} |
2741 |
|
|
2742 |
|
void MainWindow::on_action_merge_files() { |
2743 |
|
if (this->file->GetFileName().empty()) { |
2744 |
|
Glib::ustring txt = _( |
2745 |
|
"You seem to have a new .gig file open that has not been saved " |
2746 |
|
"yet. You must save it somewhere before starting to merge it with " |
2747 |
|
"other .gig files though, because during the merge operation the " |
2748 |
|
"other files' sample data must be written on file level to the " |
2749 |
|
"target .gig file." |
2750 |
|
); |
2751 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2752 |
|
msg.run(); |
2753 |
|
return; |
2754 |
|
} |
2755 |
|
|
2756 |
|
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
2757 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
2758 |
|
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
2759 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
2760 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
2761 |
|
Gtk::FileFilter filter; |
2762 |
|
filter.add_pattern("*.gig"); |
2763 |
|
#else |
2764 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
2765 |
|
filter->add_pattern("*.gig"); |
2766 |
|
#endif |
2767 |
|
dialog.set_filter(filter); |
2768 |
|
if (current_gig_dir != "") { |
2769 |
|
dialog.set_current_folder(current_gig_dir); |
2770 |
|
} |
2771 |
|
dialog.set_select_multiple(true); |
2772 |
|
|
2773 |
|
// show warning in the file picker dialog |
2774 |
|
Gtk::HBox descriptionArea; |
2775 |
|
descriptionArea.set_spacing(15); |
2776 |
|
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
2777 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
2778 |
|
#if GTKMM_MAJOR_VERSION < 3 |
2779 |
|
view::WrapLabel description; |
2780 |
|
#else |
2781 |
|
Gtk::Label description; |
2782 |
|
description.set_line_wrap(); |
2783 |
|
#endif |
2784 |
|
description.set_markup(_( |
2785 |
|
"\nSelect at least one .gig file that shall be merged to the .gig file " |
2786 |
|
"currently being open in gigedit.\n\n" |
2787 |
|
"<b>Please Note:</b> Merging with other files will modify your " |
2788 |
|
"currently open .gig file on file level! And be aware that the current " |
2789 |
|
"merge algorithm does not detect duplicate samples yet. So if you are " |
2790 |
|
"merging files which are using equivalent sample data, those " |
2791 |
|
"equivalent samples will currently be treated as separate samples and " |
2792 |
|
"will accordingly be stored separately in the target .gig file!" |
2793 |
|
)); |
2794 |
|
descriptionArea.pack_start(description); |
2795 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
2796 |
|
descriptionArea.show_all(); |
2797 |
|
|
2798 |
|
if (dialog.run() == Gtk::RESPONSE_OK) { |
2799 |
|
printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); |
2800 |
|
std::vector<std::string> filenames = dialog.get_filenames(); |
2801 |
|
|
2802 |
|
// merge the selected files to the currently open .gig file |
2803 |
|
try { |
2804 |
|
mergeFiles(filenames); |
2805 |
|
} catch (RIFF::Exception e) { |
2806 |
|
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
2807 |
|
msg.run(); |
2808 |
|
} |
2809 |
|
|
2810 |
|
// update GUI |
2811 |
|
__refreshEntireGUI(); |
2812 |
|
} |
2813 |
|
} |
2814 |
|
|
2815 |
void MainWindow::set_file_is_shared(bool b) { |
void MainWindow::set_file_is_shared(bool b) { |
2816 |
this->file_is_shared = b; |
this->file_is_shared = b; |
2817 |
|
|
2828 |
} |
} |
2829 |
} |
} |
2830 |
|
|
2831 |
|
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
2832 |
|
if (!sample) return; |
2833 |
|
sample_ref_count[sample] += offset; |
2834 |
|
const int refcount = sample_ref_count[sample]; |
2835 |
|
|
2836 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2837 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2838 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2839 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2840 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2841 |
|
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
2842 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
2843 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
2844 |
|
} |
2845 |
|
} |
2846 |
|
} |
2847 |
|
|
2848 |
|
void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { |
2849 |
|
on_sample_ref_count_incremented(oldSample, -1); |
2850 |
|
on_sample_ref_count_incremented(newSample, +1); |
2851 |
|
} |
2852 |
|
|
2853 |
|
void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) { |
2854 |
|
// just in case a new sample is added later with exactly the same memory |
2855 |
|
// address, which would lead to incorrect refcount if not deleted here |
2856 |
|
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
2857 |
|
it != samples.end(); ++it) |
2858 |
|
{ |
2859 |
|
sample_ref_count.erase(*it); |
2860 |
|
} |
2861 |
|
} |
2862 |
|
|
2863 |
|
void MainWindow::show_samples_tab() { |
2864 |
|
m_TreeViewNotebook.set_current_page(0); |
2865 |
|
} |
2866 |
|
|
2867 |
|
void MainWindow::show_intruments_tab() { |
2868 |
|
m_TreeViewNotebook.set_current_page(1); |
2869 |
|
} |
2870 |
|
|
2871 |
|
void MainWindow::show_scripts_tab() { |
2872 |
|
m_TreeViewNotebook.set_current_page(2); |
2873 |
|
} |
2874 |
|
|
2875 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
2876 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
2877 |
} |
} |