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 |
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 |
|
|
217 |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
218 |
); |
); |
219 |
|
|
220 |
|
toggle_action = |
221 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
222 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
223 |
|
actionGroup->add( |
224 |
|
toggle_action, |
225 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
226 |
|
); |
227 |
|
|
228 |
|
|
229 |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
230 |
|
|
233 |
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
234 |
); |
); |
235 |
|
|
236 |
|
actionGroup->add( |
237 |
|
Gtk::Action::create("MergeFiles", _("_Merge Files...")), |
238 |
|
sigc::mem_fun(*this, &MainWindow::on_action_merge_files) |
239 |
|
); |
240 |
|
|
241 |
|
|
242 |
// sample right-click popup actions |
// sample right-click popup actions |
243 |
actionGroup->add( |
actionGroup->add( |
257 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
258 |
); |
); |
259 |
actionGroup->add( |
actionGroup->add( |
260 |
|
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
261 |
|
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
262 |
|
); |
263 |
|
actionGroup->add( |
264 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
265 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
266 |
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) |
267 |
); |
); |
268 |
|
|
269 |
|
// script right-click popup actions |
270 |
|
actionGroup->add( |
271 |
|
Gtk::Action::create("AddScriptGroup", _("Add _Group")), |
272 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) |
273 |
|
); |
274 |
|
actionGroup->add( |
275 |
|
Gtk::Action::create("AddScript", _("Add _Script")), |
276 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script) |
277 |
|
); |
278 |
|
actionGroup->add( |
279 |
|
Gtk::Action::create("EditScript", _("_Edit Script...")), |
280 |
|
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
281 |
|
); |
282 |
|
actionGroup->add( |
283 |
|
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
284 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
285 |
|
); |
286 |
|
|
287 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
288 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
307 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
308 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
309 |
" </menu>" |
" </menu>" |
310 |
|
" <menu action='MenuSample'>" |
311 |
|
" <menuitem action='SampleProperties'/>" |
312 |
|
" <menuitem action='AddGroup'/>" |
313 |
|
" <menuitem action='AddSample'/>" |
314 |
|
" <menuitem action='ShowSampleRefs'/>" |
315 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
316 |
|
" <separator/>" |
317 |
|
" <menuitem action='RemoveSample'/>" |
318 |
|
" </menu>" |
319 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
320 |
|
" <menu action='AllInstruments'>" |
321 |
|
" </menu>" |
322 |
|
" <separator/>" |
323 |
|
" <menuitem action='InstrProperties'/>" |
324 |
|
" <menuitem action='MidiRules'/>" |
325 |
|
" <menuitem action='ScriptSlots'/>" |
326 |
|
" <menuitem action='AddInstrument'/>" |
327 |
|
" <menuitem action='DupInstrument'/>" |
328 |
|
" <separator/>" |
329 |
|
" <menuitem action='RemoveInstrument'/>" |
330 |
|
" </menu>" |
331 |
|
" <menu action='MenuScript'>" |
332 |
|
" <menuitem action='AddScriptGroup'/>" |
333 |
|
" <menuitem action='AddScript'/>" |
334 |
|
" <menuitem action='EditScript'/>" |
335 |
|
" <separator/>" |
336 |
|
" <menuitem action='RemoveScript'/>" |
337 |
" </menu>" |
" </menu>" |
338 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
339 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
340 |
" </menu>" |
" </menu>" |
341 |
" <menu action='MenuTools'>" |
" <menu action='MenuTools'>" |
342 |
" <menuitem action='CombineInstruments'/>" |
" <menuitem action='CombineInstruments'/>" |
343 |
|
" <menuitem action='MergeFiles'/>" |
344 |
" </menu>" |
" </menu>" |
345 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
346 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
347 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
348 |
" </menu>" |
" </menu>" |
349 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
350 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
353 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
354 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
355 |
" <menuitem action='MidiRules'/>" |
" <menuitem action='MidiRules'/>" |
356 |
|
" <menuitem action='ScriptSlots'/>" |
357 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
358 |
" <menuitem action='DupInstrument'/>" |
" <menuitem action='DupInstrument'/>" |
359 |
" <separator/>" |
" <separator/>" |
363 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
364 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
365 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
366 |
|
" <menuitem action='ShowSampleRefs'/>" |
367 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
368 |
" <separator/>" |
" <separator/>" |
369 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
370 |
" </popup>" |
" </popup>" |
371 |
|
" <popup name='ScriptPopupMenu'>" |
372 |
|
" <menuitem action='AddScriptGroup'/>" |
373 |
|
" <menuitem action='AddScript'/>" |
374 |
|
" <menuitem action='EditScript'/>" |
375 |
|
" <separator/>" |
376 |
|
" <menuitem action='RemoveScript'/>" |
377 |
|
" </popup>" |
378 |
"</ui>"; |
"</ui>"; |
379 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
380 |
|
|
404 |
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
405 |
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.")); |
406 |
} |
} |
407 |
|
{ |
408 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
409 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
410 |
|
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).")); |
411 |
|
} |
412 |
|
{ |
413 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
414 |
|
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
415 |
|
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
416 |
|
} |
417 |
|
{ |
418 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
419 |
|
uiManager->get_widget("/MenuBar/MenuTools/MergeFiles")); |
420 |
|
item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file.")); |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
425 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
426 |
|
|
427 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
428 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
462 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
463 |
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.")); |
464 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
465 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
466 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); |
467 |
|
{ |
468 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
469 |
|
Gtk::CellRendererText* cellrenderer = |
470 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
471 |
|
column->add_attribute( |
472 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
473 |
|
); |
474 |
|
} |
475 |
|
{ |
476 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
477 |
|
Gtk::CellRendererText* cellrenderer = |
478 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
479 |
|
column->add_attribute( |
480 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
481 |
|
); |
482 |
|
} |
483 |
|
m_TreeViewSamples.set_headers_visible(true); |
484 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
485 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
486 |
); |
); |
488 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
489 |
); |
); |
490 |
|
|
491 |
|
// create scripts treeview (including its data model) |
492 |
|
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
493 |
|
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
494 |
|
m_TreeViewScripts.set_tooltip_text(_( |
495 |
|
"Use CTRL + double click for editing a script." |
496 |
|
"\n\n" |
497 |
|
"Note: instrument scripts are a LinuxSampler extension of the gig " |
498 |
|
"format. This feature will not work with the GigaStudio software!" |
499 |
|
)); |
500 |
|
// m_TreeViewScripts.set_reorderable(); |
501 |
|
m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); |
502 |
|
m_TreeViewScripts.set_headers_visible(false); |
503 |
|
m_TreeViewScripts.signal_button_press_event().connect_notify( |
504 |
|
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
505 |
|
); |
506 |
|
//FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ? |
507 |
|
m_TreeViewScripts.signal_row_activated().connect( |
508 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
509 |
|
); |
510 |
|
m_refScriptsTreeModel->signal_row_changed().connect( |
511 |
|
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
512 |
|
); |
513 |
|
|
514 |
|
// establish drag&drop between scripts tree view and ScriptSlots window |
515 |
|
std::vector<Gtk::TargetEntry> drag_target_gig_script; |
516 |
|
drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); |
517 |
|
m_TreeViewScripts.drag_source_set(drag_target_gig_script); |
518 |
|
m_TreeViewScripts.signal_drag_begin().connect( |
519 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin) |
520 |
|
); |
521 |
|
m_TreeViewScripts.signal_drag_data_get().connect( |
522 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get) |
523 |
|
); |
524 |
|
|
525 |
// 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 |
526 |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
527 |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
555 |
dimreg_changed_signal.make_slot()); |
dimreg_changed_signal.make_slot()); |
556 |
dimreg_edit.signal_sample_ref_changed().connect( |
dimreg_edit.signal_sample_ref_changed().connect( |
557 |
sample_ref_changed_signal.make_slot()); |
sample_ref_changed_signal.make_slot()); |
558 |
|
sample_ref_changed_signal.connect( |
559 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) |
560 |
|
); |
561 |
|
samples_to_be_removed_signal.connect( |
562 |
|
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
563 |
|
); |
564 |
|
|
565 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
566 |
sigc::hide( |
sigc::hide( |
602 |
|
|
603 |
// start with a new gig file by default |
// start with a new gig file by default |
604 |
on_action_file_new(); |
on_action_file_new(); |
605 |
|
|
606 |
|
// select 'Instruments' tab by default |
607 |
|
// (gtk allows this only if the tab childs are visible, thats why it's here) |
608 |
|
m_TreeViewNotebook.set_current_page(1); |
609 |
} |
} |
610 |
|
|
611 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
686 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
687 |
{ |
{ |
688 |
update_dimregs(); |
update_dimregs(); |
689 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); |
690 |
} |
} |
691 |
|
|
692 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
702 |
} |
} |
703 |
|
|
704 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
705 |
|
|
706 |
|
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
707 |
|
switch_sampler_instrument_signal.emit(get_instrument()); |
708 |
|
} |
709 |
} |
} |
710 |
|
|
711 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
726 |
void Loader::thread_function() |
void Loader::thread_function() |
727 |
{ |
{ |
728 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
729 |
printf("Start %s\n", filename); |
printf("Start %s\n", filename.c_str()); |
730 |
RIFF::File* riff = new RIFF::File(filename); |
try { |
731 |
gig = new gig::File(riff); |
RIFF::File* riff = new RIFF::File(filename); |
732 |
gig::progress_t progress; |
gig = new gig::File(riff); |
733 |
progress.callback = loader_progress_callback; |
gig::progress_t progress; |
734 |
progress.custom = this; |
progress.callback = loader_progress_callback; |
735 |
|
progress.custom = this; |
736 |
gig->GetInstrument(0, &progress); |
|
737 |
printf("End\n"); |
gig->GetInstrument(0, &progress); |
738 |
finished_dispatcher(); |
printf("End\n"); |
739 |
|
finished_dispatcher(); |
740 |
|
} catch (RIFF::Exception e) { |
741 |
|
error_message = e.Message; |
742 |
|
error_dispatcher.emit(); |
743 |
|
} catch (...) { |
744 |
|
error_message = _("Unknown exception occurred"); |
745 |
|
error_dispatcher.emit(); |
746 |
|
} |
747 |
} |
} |
748 |
|
|
749 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
750 |
: filename(filename), thread(0) |
: filename(filename), thread(0), progress(0.f) |
751 |
{ |
{ |
752 |
} |
} |
753 |
|
|
781 |
return finished_dispatcher; |
return finished_dispatcher; |
782 |
} |
} |
783 |
|
|
784 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
785 |
|
{ |
786 |
|
return error_dispatcher; |
787 |
|
} |
788 |
|
|
789 |
|
void saver_progress_callback(gig::progress_t* progress) |
790 |
|
{ |
791 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
792 |
|
saver->progress_callback(progress->factor); |
793 |
|
} |
794 |
|
|
795 |
|
void Saver::progress_callback(float fraction) |
796 |
|
{ |
797 |
|
{ |
798 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
799 |
|
progress = fraction; |
800 |
|
} |
801 |
|
progress_dispatcher.emit(); |
802 |
|
} |
803 |
|
|
804 |
|
void Saver::thread_function() |
805 |
|
{ |
806 |
|
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
807 |
|
printf("Start %s\n", filename.c_str()); |
808 |
|
try { |
809 |
|
gig::progress_t progress; |
810 |
|
progress.callback = saver_progress_callback; |
811 |
|
progress.custom = this; |
812 |
|
|
813 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
814 |
|
if (filename.empty()) { |
815 |
|
gig->Save(&progress); |
816 |
|
} else { |
817 |
|
gig->Save(filename, &progress); |
818 |
|
} |
819 |
|
|
820 |
|
printf("End\n"); |
821 |
|
finished_dispatcher.emit(); |
822 |
|
} catch (RIFF::Exception e) { |
823 |
|
error_message = e.Message; |
824 |
|
error_dispatcher.emit(); |
825 |
|
} catch (...) { |
826 |
|
error_message = _("Unknown exception occurred"); |
827 |
|
error_dispatcher.emit(); |
828 |
|
} |
829 |
|
} |
830 |
|
|
831 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
832 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
833 |
|
{ |
834 |
|
} |
835 |
|
|
836 |
|
void Saver::launch() |
837 |
|
{ |
838 |
|
#ifdef OLD_THREADS |
839 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
840 |
|
#else |
841 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
842 |
|
#endif |
843 |
|
printf("launch thread=%x\n", thread); |
844 |
|
} |
845 |
|
|
846 |
|
float Saver::get_progress() |
847 |
|
{ |
848 |
|
float res; |
849 |
|
{ |
850 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
851 |
|
res = progress; |
852 |
|
} |
853 |
|
return res; |
854 |
|
} |
855 |
|
|
856 |
|
Glib::Dispatcher& Saver::signal_progress() |
857 |
|
{ |
858 |
|
return progress_dispatcher; |
859 |
|
} |
860 |
|
|
861 |
|
Glib::Dispatcher& Saver::signal_finished() |
862 |
|
{ |
863 |
|
return finished_dispatcher; |
864 |
|
} |
865 |
|
|
866 |
|
Glib::Dispatcher& Saver::signal_error() |
867 |
|
{ |
868 |
|
return error_dispatcher; |
869 |
|
} |
870 |
|
|
871 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
872 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
873 |
{ |
{ |
874 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
875 |
show_all_children(); |
show_all_children(); |
876 |
|
resize(600,50); |
877 |
} |
} |
878 |
|
|
879 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
884 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
885 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
886 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
887 |
|
m_refScriptsTreeModel->clear(); |
888 |
// remove all entries from "Instrument" menu |
// remove all entries from "Instrument" menu |
889 |
while (!instrument_menu->get_children().empty()) { |
while (!instrument_menu->get_children().empty()) { |
890 |
remove_instrument_from_menu(0); |
remove_instrument_from_menu(0); |
895 |
set_file_is_shared(false); |
set_file_is_shared(false); |
896 |
} |
} |
897 |
|
|
898 |
|
void MainWindow::__refreshEntireGUI() { |
899 |
|
// clear the samples and instruments tree views |
900 |
|
m_refTreeModel->clear(); |
901 |
|
m_refSamplesTreeModel->clear(); |
902 |
|
m_refScriptsTreeModel->clear(); |
903 |
|
// remove all entries from "Instrument" menu |
904 |
|
while (!instrument_menu->get_children().empty()) { |
905 |
|
remove_instrument_from_menu(0); |
906 |
|
} |
907 |
|
|
908 |
|
if (!this->file) return; |
909 |
|
|
910 |
|
load_gig( |
911 |
|
this->file, this->file->pInfo->Name.c_str(), this->file_is_shared |
912 |
|
); |
913 |
|
} |
914 |
|
|
915 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
916 |
{ |
{ |
917 |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
942 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
943 |
int response = dialog.run(); |
int response = dialog.run(); |
944 |
dialog.hide(); |
dialog.hide(); |
945 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
946 |
return response != Gtk::RESPONSE_CANCEL; |
// TODO: the following return valid is disabled and hard coded instead for |
947 |
|
// now, due to the fact that saving with progress bar is now implemented |
948 |
|
// asynchronously, as a result the app does not close automatically anymore |
949 |
|
// after saving the file has completed |
950 |
|
// |
951 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
952 |
|
// return response != Gtk::RESPONSE_CANCEL; |
953 |
|
// |
954 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
955 |
|
return false; // always prevent closing the app for now (see comment above) |
956 |
} |
} |
957 |
|
|
958 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
1003 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1004 |
{ |
{ |
1005 |
__clear(); |
__clear(); |
1006 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
1007 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1008 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
1009 |
|
Glib::filename_display_basename(name) + "' ...", |
1010 |
|
*this |
1011 |
|
); |
1012 |
|
progress_dialog->show_all(); |
1013 |
|
loader = new Loader(name); //FIXME: memory leak! |
1014 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1015 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1016 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1017 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1018 |
|
loader->signal_error().connect( |
1019 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1020 |
loader->launch(); |
loader->launch(); |
1021 |
} |
} |
1022 |
|
|
1032 |
// load the instrument |
// load the instrument |
1033 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1034 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1035 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1036 |
|
int i = 0; |
1037 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1038 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1039 |
|
{ |
1040 |
|
if (instrument == instr) { |
1041 |
|
// select item in "instruments" tree view |
1042 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1043 |
|
// make sure the selected item in the "instruments" tree view is |
1044 |
|
// visible (scroll to it) |
1045 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1046 |
|
// select item in instrument menu |
1047 |
|
{ |
1048 |
|
const std::vector<Gtk::Widget*> children = |
1049 |
|
instrument_menu->get_children(); |
1050 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1051 |
|
} |
1052 |
|
// update region chooser and dimension region chooser |
1053 |
|
m_RegionChooser.set_instrument(instr); |
1054 |
|
break; |
1055 |
|
} |
1056 |
|
} |
1057 |
} |
} |
1058 |
|
|
1059 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1060 |
{ |
{ |
1061 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1062 |
} |
} |
1063 |
|
|
1064 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1065 |
{ |
{ |
1066 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1067 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
1068 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename.c_str()); |
1069 |
load_dialog->hide(); |
progress_dialog->hide(); |
1070 |
|
} |
1071 |
|
|
1072 |
|
void MainWindow::on_loader_error() |
1073 |
|
{ |
1074 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1075 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1076 |
|
msg.run(); |
1077 |
|
progress_dialog->hide(); |
1078 |
} |
} |
1079 |
|
|
1080 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1113 |
|
|
1114 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1115 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1116 |
try { |
|
1117 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1118 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1119 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1120 |
file_is_changed = false; |
*this |
1121 |
} |
); |
1122 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1123 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1124 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1125 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1126 |
msg.run(); |
saver->signal_finished().connect( |
1127 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1128 |
} |
saver->signal_error().connect( |
1129 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1130 |
|
saver->launch(); |
1131 |
|
|
1132 |
|
return true; |
1133 |
|
} |
1134 |
|
|
1135 |
|
void MainWindow::on_saver_progress() |
1136 |
|
{ |
1137 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1138 |
|
} |
1139 |
|
|
1140 |
|
void MainWindow::on_saver_error() |
1141 |
|
{ |
1142 |
|
file_structure_changed_signal.emit(this->file); |
1143 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1144 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1145 |
|
msg.run(); |
1146 |
|
} |
1147 |
|
|
1148 |
|
void MainWindow::on_saver_finished() |
1149 |
|
{ |
1150 |
|
this->file = saver->gig; |
1151 |
|
this->filename = saver->filename; |
1152 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1153 |
|
set_title(Glib::filename_display_basename(filename)); |
1154 |
|
file_has_name = true; |
1155 |
|
file_is_changed = false; |
1156 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1157 |
__import_queued_samples(); |
__import_queued_samples(); |
1158 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1159 |
|
|
1160 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1161 |
return true; |
|
1162 |
|
load_gig(this->file, this->filename.c_str()); |
1163 |
|
progress_dialog->hide(); |
1164 |
} |
} |
1165 |
|
|
1166 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1225 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1226 |
|
|
1227 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1228 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1229 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1230 |
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; |
|
1231 |
} |
} |
1232 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1233 |
file_structure_changed_signal.emit(this->file); |
|
1234 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1235 |
|
_("Saving") + Glib::ustring(" '") + |
1236 |
|
Glib::filename_display_basename(filename) + "' ...", |
1237 |
|
*this |
1238 |
|
); |
1239 |
|
progress_dialog->show_all(); |
1240 |
|
|
1241 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1242 |
|
saver->signal_progress().connect( |
1243 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1244 |
|
saver->signal_finished().connect( |
1245 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1246 |
|
saver->signal_error().connect( |
1247 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1248 |
|
saver->launch(); |
1249 |
|
|
1250 |
return true; |
return true; |
1251 |
} |
} |
1252 |
return false; |
return false; |
1357 |
!Settings::singleton()->warnUserOnExtensions; |
!Settings::singleton()->warnUserOnExtensions; |
1358 |
} |
} |
1359 |
|
|
1360 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1361 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1362 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1363 |
|
} |
1364 |
|
|
1365 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1366 |
{ |
{ |
1367 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1371 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1372 |
#endif |
#endif |
1373 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1374 |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson"); |
1375 |
const std::string sComment = |
const std::string sComment = |
1376 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1377 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1378 |
_( |
_( |
1379 |
"Gigedit is released under the GNU General Public License.\n" |
"Gigedit is released under the GNU General Public License.\n" |
1380 |
"\n" |
"\n" |
1381 |
"Please notice that this is still a very young instrument editor. " |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1382 |
"So better backup your Gigasampler files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
1383 |
"this application.\n" |
"this application.\n" |
1384 |
"\n" |
"\n" |
1385 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: http://bugs.linuxsampler.org" |
1391 |
} |
} |
1392 |
|
|
1393 |
PropDialog::PropDialog() |
PropDialog::PropDialog() |
1394 |
: eName(_("Name")), |
: eFileFormat(_("File Format")), |
1395 |
|
eName(_("Name")), |
1396 |
eCreationDate(_("Creation date")), |
eCreationDate(_("Creation date")), |
1397 |
eComments(_("Comments")), |
eComments(_("Comments")), |
1398 |
eProduct(_("Product")), |
eProduct(_("Product")), |
1409 |
eCommissioned(_("Commissioned")), |
eCommissioned(_("Commissioned")), |
1410 |
eSubject(_("Subject")), |
eSubject(_("Subject")), |
1411 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(Gtk::Stock::CLOSE), |
1412 |
table(2, 1) |
table(2, 1), |
1413 |
|
m_file(NULL) |
1414 |
{ |
{ |
1415 |
set_title(_("File Properties")); |
set_title(_("File Properties")); |
1416 |
eName.set_width_chars(50); |
eName.set_width_chars(50); |
1432 |
connect(eCommissioned, &DLS::Info::Commissioned); |
connect(eCommissioned, &DLS::Info::Commissioned); |
1433 |
connect(eSubject, &DLS::Info::Subject); |
connect(eSubject, &DLS::Info::Subject); |
1434 |
|
|
1435 |
|
table.add(eFileFormat); |
1436 |
table.add(eName); |
table.add(eName); |
1437 |
table.add(eCreationDate); |
table.add(eCreationDate); |
1438 |
table.add(eComments); |
table.add(eComments); |
1463 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
1464 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
1465 |
sigc::mem_fun(*this, &PropDialog::hide)); |
sigc::mem_fun(*this, &PropDialog::hide)); |
1466 |
|
eFileFormat.signal_value_changed().connect( |
1467 |
|
sigc::mem_fun(*this, &PropDialog::onFileFormatChanged)); |
1468 |
|
|
1469 |
quitButton.show(); |
quitButton.show(); |
1470 |
vbox.show(); |
vbox.show(); |
1471 |
show_all_children(); |
show_all_children(); |
1472 |
} |
} |
1473 |
|
|
1474 |
|
void PropDialog::set_file(gig::File* file) |
1475 |
|
{ |
1476 |
|
m_file = file; |
1477 |
|
|
1478 |
|
// update file format version combo box |
1479 |
|
const std::string sGiga = "Gigasampler/GigaStudio v"; |
1480 |
|
const int major = file->pVersion->major; |
1481 |
|
std::vector<std::string> txts; |
1482 |
|
std::vector<int> values; |
1483 |
|
txts.push_back(sGiga + "2"); values.push_back(2); |
1484 |
|
txts.push_back(sGiga + "3/v4"); values.push_back(3); |
1485 |
|
if (major != 2 && major != 3) { |
1486 |
|
txts.push_back(sGiga + ToString(major)); values.push_back(major); |
1487 |
|
} |
1488 |
|
std::vector<const char*> texts; |
1489 |
|
for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); |
1490 |
|
texts.push_back(NULL); values.push_back(0); |
1491 |
|
eFileFormat.set_choices(&texts[0], &values[0]); |
1492 |
|
eFileFormat.set_value(major); |
1493 |
|
} |
1494 |
|
|
1495 |
|
void PropDialog::onFileFormatChanged() { |
1496 |
|
const int major = eFileFormat.get_value(); |
1497 |
|
if (m_file) m_file->pVersion->major = major; |
1498 |
|
} |
1499 |
|
|
1500 |
void PropDialog::set_info(DLS::Info* info) |
void PropDialog::set_info(DLS::Info* info) |
1501 |
{ |
{ |
1502 |
update(info); |
update(info); |
1628 |
} |
} |
1629 |
} |
} |
1630 |
|
|
1631 |
|
void MainWindow::updateSampleRefCountMap(gig::File* gig) { |
1632 |
|
sample_ref_count.clear(); |
1633 |
|
|
1634 |
|
if (!gig) return; |
1635 |
|
|
1636 |
|
for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; |
1637 |
|
instrument = gig->GetNextInstrument()) |
1638 |
|
{ |
1639 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
1640 |
|
rgn = instrument->GetNextRegion()) |
1641 |
|
{ |
1642 |
|
for (int i = 0; i < 256; ++i) { |
1643 |
|
if (!rgn->pDimensionRegions[i]) continue; |
1644 |
|
if (rgn->pDimensionRegions[i]->pSample) { |
1645 |
|
sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; |
1646 |
|
} |
1647 |
|
} |
1648 |
|
} |
1649 |
|
} |
1650 |
|
} |
1651 |
|
|
1652 |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1653 |
{ |
{ |
1654 |
file = 0; |
file = 0; |
1659 |
file_has_name = filename; |
file_has_name = filename; |
1660 |
file_is_changed = false; |
file_is_changed = false; |
1661 |
|
|
1662 |
|
propDialog.set_file(gig); |
1663 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1664 |
|
|
1665 |
instrument_name_connection.block(); |
instrument_name_connection.block(); |
1675 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
1676 |
} |
} |
1677 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1678 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); |
1679 |
|
|
1680 |
|
updateSampleRefCountMap(gig); |
1681 |
|
|
1682 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1683 |
if (group->Name != "") { |
if (group->Name != "") { |
1695 |
gig_to_utf8(sample->pInfo->Name); |
gig_to_utf8(sample->pInfo->Name); |
1696 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1697 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1698 |
|
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1699 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1700 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
1701 |
} |
} |
1702 |
} |
} |
1703 |
} |
} |
1704 |
|
|
1705 |
|
for (int i = 0; gig->GetScriptGroup(i); ++i) { |
1706 |
|
gig::ScriptGroup* group = gig->GetScriptGroup(i); |
1707 |
|
|
1708 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1709 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1710 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1711 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1712 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1713 |
|
for (int s = 0; group->GetScript(s); ++s) { |
1714 |
|
gig::Script* script = group->GetScript(s); |
1715 |
|
|
1716 |
|
Gtk::TreeModel::iterator iterScript = |
1717 |
|
m_refScriptsTreeModel->append(rowGroup.children()); |
1718 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1719 |
|
rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); |
1720 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1721 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1722 |
|
} |
1723 |
|
} |
1724 |
|
// unfold all sample groups & script groups by default |
1725 |
|
m_TreeViewSamples.expand_all(); |
1726 |
|
m_TreeViewScripts.expand_all(); |
1727 |
|
|
1728 |
file = gig; |
file = gig; |
1729 |
|
|
1792 |
} |
} |
1793 |
} |
} |
1794 |
|
|
1795 |
|
void MainWindow::show_script_slots() { |
1796 |
|
if (!file) return; |
1797 |
|
// get selected instrument |
1798 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1799 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1800 |
|
if (!it) return; |
1801 |
|
Gtk::TreeModel::Row row = *it; |
1802 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1803 |
|
if (!instrument) return; |
1804 |
|
|
1805 |
|
ScriptSlots* window = new ScriptSlots; |
1806 |
|
window->setInstrument(instrument); |
1807 |
|
//window->reparent(*this); |
1808 |
|
window->show(); |
1809 |
|
} |
1810 |
|
|
1811 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1812 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1813 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1855 |
show_instr_props(); |
show_instr_props(); |
1856 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1857 |
// gig v2 files have no midi rules |
// gig v2 files have no midi rules |
1858 |
|
const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); |
1859 |
|
static_cast<Gtk::MenuItem*>( |
1860 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( |
1861 |
|
bEnabled |
1862 |
|
); |
1863 |
static_cast<Gtk::MenuItem*>( |
static_cast<Gtk::MenuItem*>( |
1864 |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1865 |
!(file->pVersion && file->pVersion->major == 2)); |
bEnabled |
1866 |
|
); |
1867 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1868 |
} |
} |
1869 |
} |
} |
1897 |
group_selected = row[m_SamplesModel.m_col_group]; |
group_selected = row[m_SamplesModel.m_col_group]; |
1898 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
sample_selected = row[m_SamplesModel.m_col_sample]; |
1899 |
} |
} |
1900 |
|
|
1901 |
|
|
1902 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
1903 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1904 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
1905 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1906 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
1907 |
set_sensitive(file); |
set_sensitive(file); |
1908 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
1909 |
|
set_sensitive(sample_selected); |
1910 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
1911 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1912 |
// show sample popup |
// show sample popup |
1913 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
1914 |
|
|
1915 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
1916 |
|
set_sensitive(group_selected || sample_selected); |
1917 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
1918 |
|
set_sensitive(group_selected || sample_selected); |
1919 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
1920 |
|
set_sensitive(file); |
1921 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
1922 |
|
set_sensitive(sample_selected); |
1923 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
1924 |
|
set_sensitive(group_selected || sample_selected); |
1925 |
} |
} |
1926 |
} |
} |
1927 |
|
|
1928 |
|
void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { |
1929 |
|
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1930 |
|
Gtk::Menu* script_popup = |
1931 |
|
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu")); |
1932 |
|
// update enabled/disabled state of sample popup items |
1933 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1934 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1935 |
|
bool group_selected = false; |
1936 |
|
bool script_selected = false; |
1937 |
|
if (it) { |
1938 |
|
Gtk::TreeModel::Row row = *it; |
1939 |
|
group_selected = row[m_ScriptsModel.m_col_group]; |
1940 |
|
script_selected = row[m_ScriptsModel.m_col_script]; |
1941 |
|
} |
1942 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> |
1943 |
|
set_sensitive(group_selected || script_selected); |
1944 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> |
1945 |
|
set_sensitive(file); |
1946 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> |
1947 |
|
set_sensitive(script_selected); |
1948 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> |
1949 |
|
set_sensitive(group_selected || script_selected); |
1950 |
|
// show sample popup |
1951 |
|
script_popup->popup(button->button, button->time); |
1952 |
|
|
1953 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> |
1954 |
|
set_sensitive(group_selected || script_selected); |
1955 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> |
1956 |
|
set_sensitive(file); |
1957 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> |
1958 |
|
set_sensitive(script_selected); |
1959 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> |
1960 |
|
set_sensitive(group_selected || script_selected); |
1961 |
|
} |
1962 |
|
} |
1963 |
|
|
1964 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1965 |
const Glib::ustring& name, int position) { |
const Glib::ustring& name, int position) { |
2107 |
msg.run(); |
msg.run(); |
2108 |
} |
} |
2109 |
|
|
2110 |
|
void MainWindow::on_action_add_script_group() { |
2111 |
|
static int __script_indexer = 0; |
2112 |
|
if (!file) return; |
2113 |
|
gig::ScriptGroup* group = file->AddScriptGroup(); |
2114 |
|
group->Name = gig_from_utf8(_("Unnamed Group")); |
2115 |
|
if (__script_indexer) group->Name += " " + ToString(__script_indexer); |
2116 |
|
__script_indexer++; |
2117 |
|
// update sample tree view |
2118 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
2119 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
2120 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
2121 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
2122 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
2123 |
|
file_changed(); |
2124 |
|
} |
2125 |
|
|
2126 |
|
void MainWindow::on_action_add_script() { |
2127 |
|
if (!file) return; |
2128 |
|
// get selected group |
2129 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2130 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2131 |
|
if (!it) return; |
2132 |
|
Gtk::TreeModel::Row row = *it; |
2133 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2134 |
|
if (!group) { // not a group, but a script is selected (probably) |
2135 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2136 |
|
if (!script) return; |
2137 |
|
it = row.parent(); // resolve parent (that is the script's group) |
2138 |
|
if (!it) return; |
2139 |
|
row = *it; |
2140 |
|
group = row[m_ScriptsModel.m_col_group]; |
2141 |
|
if (!group) return; |
2142 |
|
} |
2143 |
|
|
2144 |
|
// add a new script to the .gig file |
2145 |
|
gig::Script* script = group->AddScript(); |
2146 |
|
Glib::ustring name = _("Unnamed Script"); |
2147 |
|
script->Name = gig_from_utf8(name); |
2148 |
|
|
2149 |
|
// add script to the tree view |
2150 |
|
Gtk::TreeModel::iterator iterScript = |
2151 |
|
m_refScriptsTreeModel->append(row.children()); |
2152 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
2153 |
|
rowScript[m_ScriptsModel.m_col_name] = name; |
2154 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
2155 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
2156 |
|
|
2157 |
|
// unfold group of new script item in treeview |
2158 |
|
Gtk::TreeModel::Path path(iterScript); |
2159 |
|
m_TreeViewScripts.expand_to_path(path); |
2160 |
|
} |
2161 |
|
|
2162 |
|
void MainWindow::on_action_edit_script() { |
2163 |
|
if (!file) return; |
2164 |
|
// get selected script |
2165 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2166 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2167 |
|
if (!it) return; |
2168 |
|
Gtk::TreeModel::Row row = *it; |
2169 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2170 |
|
if (!script) return; |
2171 |
|
|
2172 |
|
ScriptEditor* editor = new ScriptEditor; |
2173 |
|
editor->setScript(script); |
2174 |
|
//editor->reparent(*this); |
2175 |
|
editor->show(); |
2176 |
|
} |
2177 |
|
|
2178 |
|
void MainWindow::on_action_remove_script() { |
2179 |
|
if (!file) return; |
2180 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2181 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2182 |
|
if (it) { |
2183 |
|
Gtk::TreeModel::Row row = *it; |
2184 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2185 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2186 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2187 |
|
try { |
2188 |
|
// remove script group or script from the gig file |
2189 |
|
if (group) { |
2190 |
|
// notify everybody that we're going to remove these samples |
2191 |
|
//TODO: scripts_to_be_removed_signal.emit(members); |
2192 |
|
// delete the group in the .gig file including the |
2193 |
|
// samples that belong to the group |
2194 |
|
file->DeleteScriptGroup(group); |
2195 |
|
// notify that we're done with removal |
2196 |
|
//TODO: scripts_removed_signal.emit(); |
2197 |
|
file_changed(); |
2198 |
|
} else if (script) { |
2199 |
|
// notify everybody that we're going to remove this sample |
2200 |
|
//TODO: std::list<gig::Script*> lscripts; |
2201 |
|
//TODO: lscripts.push_back(script); |
2202 |
|
//TODO: scripts_to_be_removed_signal.emit(lscripts); |
2203 |
|
// remove sample from the .gig file |
2204 |
|
script->GetGroup()->DeleteScript(script); |
2205 |
|
// notify that we're done with removal |
2206 |
|
//TODO: scripts_removed_signal.emit(); |
2207 |
|
dimreg_changed(); |
2208 |
|
file_changed(); |
2209 |
|
} |
2210 |
|
// remove respective row(s) from samples tree view |
2211 |
|
m_refScriptsTreeModel->erase(it); |
2212 |
|
} catch (RIFF::Exception e) { |
2213 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
2214 |
|
//TODO: scripts_removed_signal.emit(); |
2215 |
|
// show error message |
2216 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2217 |
|
msg.run(); |
2218 |
|
} |
2219 |
|
} |
2220 |
|
} |
2221 |
|
|
2222 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |
2223 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
2224 |
if (!file) return; |
if (!file) return; |
2588 |
} |
} |
2589 |
} |
} |
2590 |
|
|
2591 |
|
// see comment on on_sample_treeview_drag_begin() |
2592 |
|
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2593 |
|
{ |
2594 |
|
first_call_to_drag_data_get = true; |
2595 |
|
} |
2596 |
|
|
2597 |
|
void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2598 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2599 |
|
{ |
2600 |
|
if (!first_call_to_drag_data_get) return; |
2601 |
|
first_call_to_drag_data_get = false; |
2602 |
|
|
2603 |
|
// get selected script |
2604 |
|
gig::Script* script = NULL; |
2605 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2606 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2607 |
|
if (it) { |
2608 |
|
Gtk::TreeModel::Row row = *it; |
2609 |
|
script = row[m_ScriptsModel.m_col_script]; |
2610 |
|
} |
2611 |
|
// pass the gig::Script as pointer |
2612 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, |
2613 |
|
(const guchar*)&script, |
2614 |
|
sizeof(script)/*length of data in bytes*/); |
2615 |
|
} |
2616 |
|
|
2617 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2618 |
// 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 |
2619 |
// 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 |
2672 |
bool channels_changed = false; |
bool channels_changed = false; |
2673 |
if (sample->Channels == 1 && stereo_dimension) { |
if (sample->Channels == 1 && stereo_dimension) { |
2674 |
// remove the samplechannel dimension |
// remove the samplechannel dimension |
2675 |
|
/* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples |
2676 |
region->DeleteDimension(stereo_dimension); |
region->DeleteDimension(stereo_dimension); |
2677 |
channels_changed = true; |
channels_changed = true; |
2678 |
region_changed(); |
region_changed(); |
2679 |
|
*/ |
2680 |
} |
} |
2681 |
dimreg_edit.set_sample( |
dimreg_edit.set_sample( |
2682 |
sample, |
sample, |
2742 |
} |
} |
2743 |
} |
} |
2744 |
|
|
2745 |
|
void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, |
2746 |
|
const Gtk::TreeModel::iterator& iter) { |
2747 |
|
if (!iter) return; |
2748 |
|
Gtk::TreeModel::Row row = *iter; |
2749 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2750 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2751 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2752 |
|
gig::String gigname(gig_from_utf8(name)); |
2753 |
|
if (group) { |
2754 |
|
if (group->Name != gigname) { |
2755 |
|
group->Name = gigname; |
2756 |
|
printf("script group name changed\n"); |
2757 |
|
file_changed(); |
2758 |
|
} |
2759 |
|
} else if (script) { |
2760 |
|
if (script->Name != gigname) { |
2761 |
|
script->Name = gigname; |
2762 |
|
printf("script name changed\n"); |
2763 |
|
file_changed(); |
2764 |
|
} |
2765 |
|
} |
2766 |
|
} |
2767 |
|
|
2768 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
2769 |
|
Gtk::TreeViewColumn* column) |
2770 |
|
{ |
2771 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
2772 |
|
if (!iter) return; |
2773 |
|
Gtk::TreeModel::Row row = *iter; |
2774 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2775 |
|
if (!script) return; |
2776 |
|
|
2777 |
|
ScriptEditor* editor = new ScriptEditor; |
2778 |
|
editor->setScript(script); |
2779 |
|
//editor->reparent(*this); |
2780 |
|
editor->show(); |
2781 |
|
} |
2782 |
|
|
2783 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
2784 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
2785 |
if (!iter) return; |
if (!iter) return; |
2826 |
delete d; |
delete d; |
2827 |
} |
} |
2828 |
|
|
2829 |
|
void MainWindow::on_action_view_references() { |
2830 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2831 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2832 |
|
if (!it) return; |
2833 |
|
Gtk::TreeModel::Row row = *it; |
2834 |
|
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2835 |
|
if (!sample) return; |
2836 |
|
|
2837 |
|
ReferencesView* d = new ReferencesView(*this); |
2838 |
|
d->setSample(sample); |
2839 |
|
d->show_all(); |
2840 |
|
d->resize(500, 400); |
2841 |
|
d->run(); |
2842 |
|
delete d; |
2843 |
|
} |
2844 |
|
|
2845 |
|
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
2846 |
|
struct _Source { |
2847 |
|
std::vector<RIFF::File*> riffs; |
2848 |
|
std::vector<gig::File*> gigs; |
2849 |
|
|
2850 |
|
~_Source() { |
2851 |
|
for (int k = 0; k < gigs.size(); ++k) delete gigs[k]; |
2852 |
|
for (int k = 0; k < riffs.size(); ++k) delete riffs[k]; |
2853 |
|
riffs.clear(); |
2854 |
|
gigs.clear(); |
2855 |
|
} |
2856 |
|
} sources; |
2857 |
|
|
2858 |
|
if (filenames.empty()) |
2859 |
|
throw RIFF::Exception(_("No files selected, so nothing done.")); |
2860 |
|
|
2861 |
|
// first open all input files (to avoid output file corruption) |
2862 |
|
int i; |
2863 |
|
try { |
2864 |
|
for (i = 0; i < filenames.size(); ++i) { |
2865 |
|
const std::string& filename = filenames[i]; |
2866 |
|
printf("opening file=%s\n", filename.c_str()); |
2867 |
|
|
2868 |
|
RIFF::File* riff = new RIFF::File(filename); |
2869 |
|
sources.riffs.push_back(riff); |
2870 |
|
|
2871 |
|
gig::File* gig = new gig::File(riff); |
2872 |
|
sources.gigs.push_back(gig); |
2873 |
|
} |
2874 |
|
} catch (RIFF::Exception e) { |
2875 |
|
throw RIFF::Exception( |
2876 |
|
_("Error occurred while opening '") + |
2877 |
|
filenames[i] + |
2878 |
|
"': " + |
2879 |
|
e.Message |
2880 |
|
); |
2881 |
|
} catch (...) { |
2882 |
|
throw RIFF::Exception( |
2883 |
|
_("Unknown exception occurred while opening '") + |
2884 |
|
filenames[i] + "'" |
2885 |
|
); |
2886 |
|
} |
2887 |
|
|
2888 |
|
// now merge the opened .gig files to the main .gig file currently being |
2889 |
|
// open in gigedit |
2890 |
|
try { |
2891 |
|
for (i = 0; i < filenames.size(); ++i) { |
2892 |
|
const std::string& filename = filenames[i]; |
2893 |
|
printf("merging file=%s\n", filename.c_str()); |
2894 |
|
assert(i < sources.gigs.size()); |
2895 |
|
|
2896 |
|
this->file->AddContentOf(sources.gigs[i]); |
2897 |
|
} |
2898 |
|
} catch (RIFF::Exception e) { |
2899 |
|
throw RIFF::Exception( |
2900 |
|
_("Error occurred while merging '") + |
2901 |
|
filenames[i] + |
2902 |
|
"': " + |
2903 |
|
e.Message |
2904 |
|
); |
2905 |
|
} catch (...) { |
2906 |
|
throw RIFF::Exception( |
2907 |
|
_("Unknown exception occurred while merging '") + |
2908 |
|
filenames[i] + "'" |
2909 |
|
); |
2910 |
|
} |
2911 |
|
|
2912 |
|
// Finally save gig file persistently to disk ... |
2913 |
|
//NOTE: requires that this gig file already has a filename ! |
2914 |
|
{ |
2915 |
|
std::cout << "Saving file\n" << std::flush; |
2916 |
|
file_structure_to_be_changed_signal.emit(this->file); |
2917 |
|
|
2918 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
2919 |
|
_("Saving") + Glib::ustring(" '") + |
2920 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
2921 |
|
*this |
2922 |
|
); |
2923 |
|
progress_dialog->show_all(); |
2924 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
2925 |
|
saver->signal_progress().connect( |
2926 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
2927 |
|
saver->signal_finished().connect( |
2928 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
2929 |
|
saver->signal_error().connect( |
2930 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
2931 |
|
saver->launch(); |
2932 |
|
} |
2933 |
|
} |
2934 |
|
|
2935 |
|
void MainWindow::on_action_merge_files() { |
2936 |
|
if (this->file->GetFileName().empty()) { |
2937 |
|
Glib::ustring txt = _( |
2938 |
|
"You seem to have a new .gig file open that has not been saved " |
2939 |
|
"yet. You must save it somewhere before starting to merge it with " |
2940 |
|
"other .gig files though, because during the merge operation the " |
2941 |
|
"other files' sample data must be written on file level to the " |
2942 |
|
"target .gig file." |
2943 |
|
); |
2944 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2945 |
|
msg.run(); |
2946 |
|
return; |
2947 |
|
} |
2948 |
|
|
2949 |
|
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
2950 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
2951 |
|
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
2952 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
2953 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
2954 |
|
Gtk::FileFilter filter; |
2955 |
|
filter.add_pattern("*.gig"); |
2956 |
|
#else |
2957 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
2958 |
|
filter->add_pattern("*.gig"); |
2959 |
|
#endif |
2960 |
|
dialog.set_filter(filter); |
2961 |
|
if (current_gig_dir != "") { |
2962 |
|
dialog.set_current_folder(current_gig_dir); |
2963 |
|
} |
2964 |
|
dialog.set_select_multiple(true); |
2965 |
|
|
2966 |
|
// show warning in the file picker dialog |
2967 |
|
Gtk::HBox descriptionArea; |
2968 |
|
descriptionArea.set_spacing(15); |
2969 |
|
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
2970 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
2971 |
|
#if GTKMM_MAJOR_VERSION < 3 |
2972 |
|
view::WrapLabel description; |
2973 |
|
#else |
2974 |
|
Gtk::Label description; |
2975 |
|
description.set_line_wrap(); |
2976 |
|
#endif |
2977 |
|
description.set_markup(_( |
2978 |
|
"\nSelect at least one .gig file that shall be merged to the .gig file " |
2979 |
|
"currently being open in gigedit.\n\n" |
2980 |
|
"<b>Please Note:</b> Merging with other files will modify your " |
2981 |
|
"currently open .gig file on file level! And be aware that the current " |
2982 |
|
"merge algorithm does not detect duplicate samples yet. So if you are " |
2983 |
|
"merging files which are using equivalent sample data, those " |
2984 |
|
"equivalent samples will currently be treated as separate samples and " |
2985 |
|
"will accordingly be stored separately in the target .gig file!" |
2986 |
|
)); |
2987 |
|
descriptionArea.pack_start(description); |
2988 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
2989 |
|
descriptionArea.show_all(); |
2990 |
|
|
2991 |
|
if (dialog.run() == Gtk::RESPONSE_OK) { |
2992 |
|
printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); |
2993 |
|
std::vector<std::string> filenames = dialog.get_filenames(); |
2994 |
|
|
2995 |
|
// merge the selected files to the currently open .gig file |
2996 |
|
try { |
2997 |
|
mergeFiles(filenames); |
2998 |
|
} catch (RIFF::Exception e) { |
2999 |
|
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
3000 |
|
msg.run(); |
3001 |
|
} |
3002 |
|
|
3003 |
|
// update GUI |
3004 |
|
__refreshEntireGUI(); |
3005 |
|
} |
3006 |
|
} |
3007 |
|
|
3008 |
void MainWindow::set_file_is_shared(bool b) { |
void MainWindow::set_file_is_shared(bool b) { |
3009 |
this->file_is_shared = b; |
this->file_is_shared = b; |
3010 |
|
|
3019 |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
3020 |
); |
); |
3021 |
} |
} |
3022 |
|
|
3023 |
|
{ |
3024 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
3025 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
3026 |
|
if (item) item->set_sensitive(b); |
3027 |
|
} |
3028 |
|
} |
3029 |
|
|
3030 |
|
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3031 |
|
if (!sample) return; |
3032 |
|
sample_ref_count[sample] += offset; |
3033 |
|
const int refcount = sample_ref_count[sample]; |
3034 |
|
|
3035 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
3036 |
|
for (int g = 0; g < model->children().size(); ++g) { |
3037 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
3038 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
3039 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
3040 |
|
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
3041 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
3042 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
3043 |
|
} |
3044 |
|
} |
3045 |
|
} |
3046 |
|
|
3047 |
|
void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { |
3048 |
|
on_sample_ref_count_incremented(oldSample, -1); |
3049 |
|
on_sample_ref_count_incremented(newSample, +1); |
3050 |
|
} |
3051 |
|
|
3052 |
|
void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) { |
3053 |
|
// just in case a new sample is added later with exactly the same memory |
3054 |
|
// address, which would lead to incorrect refcount if not deleted here |
3055 |
|
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3056 |
|
it != samples.end(); ++it) |
3057 |
|
{ |
3058 |
|
sample_ref_count.erase(*it); |
3059 |
|
} |
3060 |
|
} |
3061 |
|
|
3062 |
|
void MainWindow::show_samples_tab() { |
3063 |
|
m_TreeViewNotebook.set_current_page(0); |
3064 |
|
} |
3065 |
|
|
3066 |
|
void MainWindow::show_intruments_tab() { |
3067 |
|
m_TreeViewNotebook.set_current_page(1); |
3068 |
|
} |
3069 |
|
|
3070 |
|
void MainWindow::show_scripts_tab() { |
3071 |
|
m_TreeViewNotebook.set_current_page(2); |
3072 |
} |
} |
3073 |
|
|
3074 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
3126 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
3127 |
return m_RegionChooser.signal_keyboard_key_released(); |
return m_RegionChooser.signal_keyboard_key_released(); |
3128 |
} |
} |
3129 |
|
|
3130 |
|
sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() { |
3131 |
|
return switch_sampler_instrument_signal; |
3132 |
|
} |