1 |
/* |
/* |
2 |
* Copyright (C) 2006-2013 Andreas Persson |
* Copyright (C) 2006-2014 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
40 |
|
|
41 |
#include <stdio.h> |
#include <stdio.h> |
42 |
#include <sndfile.h> |
#include <sndfile.h> |
43 |
|
#include <assert.h> |
44 |
|
|
45 |
#include "mainwindow.h" |
#include "mainwindow.h" |
46 |
|
#include "Settings.h" |
47 |
|
#include "CombineInstrumentsDialog.h" |
48 |
|
#include "scripteditor.h" |
49 |
|
#include "scriptslots.h" |
50 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
51 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
52 |
|
|
80 |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
81 |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
82 |
|
|
83 |
|
m_ScrolledWindowScripts.add(m_TreeViewScripts); |
84 |
|
m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
85 |
|
|
86 |
|
|
87 |
m_TreeViewNotebook.set_size_request(300); |
m_TreeViewNotebook.set_size_request(300); |
88 |
|
|
96 |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
97 |
m_HPaned.add2(dimreg_vbox); |
m_HPaned.add2(dimreg_vbox); |
98 |
|
|
99 |
|
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
100 |
|
dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well.")); |
101 |
|
dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below.")); |
102 |
|
dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below).")); |
103 |
|
|
104 |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
105 |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
106 |
|
m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts")); |
107 |
|
|
108 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
109 |
|
|
134 |
Gtk::Stock::PROPERTIES), |
Gtk::Stock::PROPERTIES), |
135 |
sigc::mem_fun( |
sigc::mem_fun( |
136 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
137 |
|
actionGroup->add(Gtk::Action::create("MidiRules", |
138 |
|
_("_Midi Rules...")), |
139 |
|
sigc::mem_fun( |
140 |
|
*this, &MainWindow::show_midi_rules)); |
141 |
|
actionGroup->add(Gtk::Action::create("ScriptSlots", |
142 |
|
_("_Script Slots...")), |
143 |
|
sigc::mem_fun( |
144 |
|
*this, &MainWindow::show_script_slots)); |
145 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
146 |
sigc::mem_fun( |
sigc::mem_fun( |
147 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
151 |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
152 |
|
|
153 |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
154 |
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"), "ffaga"); |
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
155 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
|
//FIXME: doesn't work, why? |
|
|
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
|
156 |
actionGroup->add(toggle_action); |
actionGroup->add(toggle_action); |
157 |
|
|
158 |
toggle_action = |
toggle_action = |
159 |
Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); |
Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); |
160 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
|
//FIXME: doesn't work, why? |
|
|
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
|
161 |
actionGroup->add(toggle_action); |
actionGroup->add(toggle_action); |
162 |
|
|
163 |
toggle_action = |
toggle_action = |
164 |
Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); |
Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); |
165 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
|
//FIXME: doesn't work, why? |
|
|
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
|
166 |
actionGroup->add(toggle_action); |
actionGroup->add(toggle_action); |
167 |
|
|
168 |
|
|
193 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
194 |
); |
); |
195 |
|
|
196 |
|
|
197 |
|
actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings"))); |
198 |
|
|
199 |
|
toggle_action = |
200 |
|
Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions")); |
201 |
|
toggle_action->set_active(Settings::singleton()->warnUserOnExtensions); |
202 |
|
actionGroup->add( |
203 |
|
toggle_action, |
204 |
|
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
205 |
|
); |
206 |
|
|
207 |
|
|
208 |
|
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
209 |
|
|
210 |
|
actionGroup->add( |
211 |
|
Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")), |
212 |
|
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
213 |
|
); |
214 |
|
|
215 |
|
actionGroup->add( |
216 |
|
Gtk::Action::create("MergeFiles", _("_Merge Files...")), |
217 |
|
sigc::mem_fun(*this, &MainWindow::on_action_merge_files) |
218 |
|
); |
219 |
|
|
220 |
|
|
221 |
// sample right-click popup actions |
// sample right-click popup actions |
222 |
actionGroup->add( |
actionGroup->add( |
223 |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
240 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
241 |
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) |
242 |
); |
); |
243 |
|
|
244 |
|
// script right-click popup actions |
245 |
|
actionGroup->add( |
246 |
|
Gtk::Action::create("AddScriptGroup", _("Add _Group")), |
247 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) |
248 |
|
); |
249 |
|
actionGroup->add( |
250 |
|
Gtk::Action::create("AddScript", _("Add _Script")), |
251 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script) |
252 |
|
); |
253 |
|
actionGroup->add( |
254 |
|
Gtk::Action::create("EditScript", _("_Edit Script...")), |
255 |
|
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
256 |
|
); |
257 |
|
actionGroup->add( |
258 |
|
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
259 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
260 |
|
); |
261 |
|
|
262 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
263 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
287 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
288 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
289 |
" </menu>" |
" </menu>" |
290 |
|
" <menu action='MenuTools'>" |
291 |
|
" <menuitem action='CombineInstruments'/>" |
292 |
|
" <menuitem action='MergeFiles'/>" |
293 |
|
" </menu>" |
294 |
|
" <menu action='MenuSettings'>" |
295 |
|
" <menuitem action='WarnUserOnExtensions'/>" |
296 |
|
" </menu>" |
297 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
298 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
299 |
" </menu>" |
" </menu>" |
300 |
" </menubar>" |
" </menubar>" |
301 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
302 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
303 |
|
" <menuitem action='MidiRules'/>" |
304 |
|
" <menuitem action='ScriptSlots'/>" |
305 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
306 |
" <menuitem action='DupInstrument'/>" |
" <menuitem action='DupInstrument'/>" |
307 |
" <separator/>" |
" <separator/>" |
315 |
" <separator/>" |
" <separator/>" |
316 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
317 |
" </popup>" |
" </popup>" |
318 |
|
" <popup name='ScriptPopupMenu'>" |
319 |
|
" <menuitem action='AddScriptGroup'/>" |
320 |
|
" <menuitem action='AddScript'/>" |
321 |
|
" <menuitem action='EditScript'/>" |
322 |
|
" <separator/>" |
323 |
|
" <menuitem action='RemoveScript'/>" |
324 |
|
" </popup>" |
325 |
"</ui>"; |
"</ui>"; |
326 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
327 |
|
|
328 |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
329 |
|
|
330 |
|
// Set tooltips for menu items (for some reason, setting a tooltip on the |
331 |
|
// respective Gtk::Action objects above will simply be ignored, no matter |
332 |
|
// if using Gtk::Action::set_tooltip() or passing the tooltip string on |
333 |
|
// Gtk::Action::create()). |
334 |
|
{ |
335 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
336 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
337 |
|
item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action.")); |
338 |
|
} |
339 |
|
{ |
340 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
341 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
342 |
|
item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action.")); |
343 |
|
} |
344 |
|
{ |
345 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
346 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
347 |
|
item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action.")); |
348 |
|
} |
349 |
|
{ |
350 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
351 |
|
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
352 |
|
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.")); |
353 |
|
} |
354 |
|
{ |
355 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
356 |
|
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
357 |
|
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
358 |
|
} |
359 |
|
{ |
360 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
361 |
|
uiManager->get_widget("/MenuBar/MenuTools/MergeFiles")); |
362 |
|
item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file.")); |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
367 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
390 |
// Create the Tree model: |
// Create the Tree model: |
391 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
392 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
393 |
|
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules.")); |
394 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
395 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
396 |
); |
); |
402 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
403 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
404 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
405 |
|
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.")); |
406 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
407 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
408 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); |
409 |
|
{ |
410 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
411 |
|
Gtk::CellRendererText* cellrenderer = |
412 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
413 |
|
column->add_attribute( |
414 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
415 |
|
); |
416 |
|
} |
417 |
|
{ |
418 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
419 |
|
Gtk::CellRendererText* cellrenderer = |
420 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
421 |
|
column->add_attribute( |
422 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
423 |
|
); |
424 |
|
} |
425 |
|
m_TreeViewSamples.set_headers_visible(true); |
426 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
427 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
428 |
); |
); |
430 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
431 |
); |
); |
432 |
|
|
433 |
|
// create scripts treeview (including its data model) |
434 |
|
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
435 |
|
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
436 |
|
m_TreeViewScripts.set_tooltip_text(_( |
437 |
|
"Note: instrument scripts are a LinuxSampler extension of the gig " |
438 |
|
"format. This feature will not work with the GigaStudio software!" |
439 |
|
)); |
440 |
|
// m_TreeViewScripts.set_reorderable(); |
441 |
|
m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); |
442 |
|
m_TreeViewScripts.set_headers_visible(false); |
443 |
|
m_TreeViewScripts.signal_button_press_event().connect_notify( |
444 |
|
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
445 |
|
); |
446 |
|
m_refScriptsTreeModel->signal_row_changed().connect( |
447 |
|
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
448 |
|
); |
449 |
|
|
450 |
|
// establish drag&drop between scripts tree view and ScriptSlots window |
451 |
|
std::vector<Gtk::TargetEntry> drag_target_gig_script; |
452 |
|
drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); |
453 |
|
m_TreeViewScripts.drag_source_set(drag_target_gig_script); |
454 |
|
m_TreeViewScripts.signal_drag_begin().connect( |
455 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin) |
456 |
|
); |
457 |
|
m_TreeViewScripts.signal_drag_data_get().connect( |
458 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get) |
459 |
|
); |
460 |
|
|
461 |
// 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 |
462 |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
463 |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
482 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
483 |
propDialog.signal_changed().connect( |
propDialog.signal_changed().connect( |
484 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
485 |
|
midiRules.signal_changed().connect( |
486 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
487 |
|
|
488 |
dimreg_edit.signal_dimreg_to_be_changed().connect( |
dimreg_edit.signal_dimreg_to_be_changed().connect( |
489 |
dimreg_to_be_changed_signal.make_slot()); |
dimreg_to_be_changed_signal.make_slot()); |
491 |
dimreg_changed_signal.make_slot()); |
dimreg_changed_signal.make_slot()); |
492 |
dimreg_edit.signal_sample_ref_changed().connect( |
dimreg_edit.signal_sample_ref_changed().connect( |
493 |
sample_ref_changed_signal.make_slot()); |
sample_ref_changed_signal.make_slot()); |
494 |
|
sample_ref_changed_signal.connect( |
495 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) |
496 |
|
); |
497 |
|
samples_to_be_removed_signal.connect( |
498 |
|
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
499 |
|
); |
500 |
|
|
501 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
502 |
sigc::hide( |
sigc::hide( |
538 |
|
|
539 |
// start with a new gig file by default |
// start with a new gig file by default |
540 |
on_action_file_new(); |
on_action_file_new(); |
541 |
|
|
542 |
|
// select 'Instruments' tab by default |
543 |
|
// (gtk allows this only if the tab childs are visible, thats why it's here) |
544 |
|
m_TreeViewNotebook.set_current_page(1); |
545 |
} |
} |
546 |
|
|
547 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
720 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
721 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
722 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
723 |
|
m_refScriptsTreeModel->clear(); |
724 |
// remove all entries from "Instrument" menu |
// remove all entries from "Instrument" menu |
725 |
while (!instrument_menu->get_children().empty()) { |
while (!instrument_menu->get_children().empty()) { |
726 |
remove_instrument_from_menu(0); |
remove_instrument_from_menu(0); |
731 |
set_file_is_shared(false); |
set_file_is_shared(false); |
732 |
} |
} |
733 |
|
|
734 |
|
void MainWindow::__refreshEntireGUI() { |
735 |
|
// clear the samples and instruments tree views |
736 |
|
m_refTreeModel->clear(); |
737 |
|
m_refSamplesTreeModel->clear(); |
738 |
|
m_refScriptsTreeModel->clear(); |
739 |
|
// remove all entries from "Instrument" menu |
740 |
|
while (!instrument_menu->get_children().empty()) { |
741 |
|
remove_instrument_from_menu(0); |
742 |
|
} |
743 |
|
|
744 |
|
if (!this->file) return; |
745 |
|
|
746 |
|
load_gig( |
747 |
|
this->file, this->file->pInfo->Name.c_str(), this->file_is_shared |
748 |
|
); |
749 |
|
} |
750 |
|
|
751 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
752 |
{ |
{ |
753 |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
1112 |
propDialog.deiconify(); |
propDialog.deiconify(); |
1113 |
} |
} |
1114 |
|
|
1115 |
|
void MainWindow::on_action_warn_user_on_extensions() { |
1116 |
|
Settings::singleton()->warnUserOnExtensions = |
1117 |
|
!Settings::singleton()->warnUserOnExtensions; |
1118 |
|
} |
1119 |
|
|
1120 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1121 |
{ |
{ |
1122 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1126 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1127 |
#endif |
#endif |
1128 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1129 |
dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
1130 |
dialog.set_comments(_( |
const std::string sComment = |
1131 |
"Released under the GNU General Public License.\n" |
_("Built " __DATE__ "\nUsing ") + |
1132 |
"\n" |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1133 |
"Please notice that this is still a very young instrument editor. " |
_( |
1134 |
"So better backup your Gigasampler files before editing them with " |
"Gigedit is released under the GNU General Public License.\n" |
1135 |
"this application.\n" |
"\n" |
1136 |
"\n" |
"Please notice that this is still a very young instrument editor. " |
1137 |
"Please report bugs to: http://bugs.linuxsampler.org") |
"So better backup your Gigasampler files before editing them with " |
1138 |
); |
"this application.\n" |
1139 |
|
"\n" |
1140 |
|
"Please report bugs to: http://bugs.linuxsampler.org" |
1141 |
|
); |
1142 |
|
dialog.set_comments(sComment.c_str()); |
1143 |
dialog.set_website("http://www.linuxsampler.org"); |
dialog.set_website("http://www.linuxsampler.org"); |
1144 |
dialog.set_website_label("http://www.linuxsampler.org"); |
dialog.set_website_label("http://www.linuxsampler.org"); |
1145 |
dialog.run(); |
dialog.run(); |
1146 |
} |
} |
1147 |
|
|
1148 |
PropDialog::PropDialog() |
PropDialog::PropDialog() |
1149 |
: eName(_("Name")), |
: eFileFormat(_("File Format")), |
1150 |
|
eName(_("Name")), |
1151 |
eCreationDate(_("Creation date")), |
eCreationDate(_("Creation date")), |
1152 |
eComments(_("Comments")), |
eComments(_("Comments")), |
1153 |
eProduct(_("Product")), |
eProduct(_("Product")), |
1164 |
eCommissioned(_("Commissioned")), |
eCommissioned(_("Commissioned")), |
1165 |
eSubject(_("Subject")), |
eSubject(_("Subject")), |
1166 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(Gtk::Stock::CLOSE), |
1167 |
table(2, 1) |
table(2, 1), |
1168 |
|
m_file(NULL) |
1169 |
{ |
{ |
1170 |
set_title(_("File Properties")); |
set_title(_("File Properties")); |
1171 |
eName.set_width_chars(50); |
eName.set_width_chars(50); |
1187 |
connect(eCommissioned, &DLS::Info::Commissioned); |
connect(eCommissioned, &DLS::Info::Commissioned); |
1188 |
connect(eSubject, &DLS::Info::Subject); |
connect(eSubject, &DLS::Info::Subject); |
1189 |
|
|
1190 |
|
table.add(eFileFormat); |
1191 |
table.add(eName); |
table.add(eName); |
1192 |
table.add(eCreationDate); |
table.add(eCreationDate); |
1193 |
table.add(eComments); |
table.add(eComments); |
1218 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
1219 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
1220 |
sigc::mem_fun(*this, &PropDialog::hide)); |
sigc::mem_fun(*this, &PropDialog::hide)); |
1221 |
|
eFileFormat.signal_value_changed().connect( |
1222 |
|
sigc::mem_fun(*this, &PropDialog::onFileFormatChanged)); |
1223 |
|
|
1224 |
quitButton.show(); |
quitButton.show(); |
1225 |
vbox.show(); |
vbox.show(); |
1226 |
show_all_children(); |
show_all_children(); |
1227 |
} |
} |
1228 |
|
|
1229 |
|
void PropDialog::set_file(gig::File* file) |
1230 |
|
{ |
1231 |
|
m_file = file; |
1232 |
|
|
1233 |
|
// update file format version combo box |
1234 |
|
const std::string sGiga = "Gigasampler/GigaStudio v"; |
1235 |
|
const int major = file->pVersion->major; |
1236 |
|
std::vector<std::string> txts; |
1237 |
|
std::vector<int> values; |
1238 |
|
txts.push_back(sGiga + "2"); values.push_back(2); |
1239 |
|
txts.push_back(sGiga + "3/v4"); values.push_back(3); |
1240 |
|
if (major != 2 && major != 3) { |
1241 |
|
txts.push_back(sGiga + ToString(major)); values.push_back(major); |
1242 |
|
} |
1243 |
|
std::vector<const char*> texts; |
1244 |
|
for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); |
1245 |
|
texts.push_back(NULL); values.push_back(0); |
1246 |
|
eFileFormat.set_choices(&texts[0], &values[0]); |
1247 |
|
eFileFormat.set_value(major); |
1248 |
|
} |
1249 |
|
|
1250 |
|
void PropDialog::onFileFormatChanged() { |
1251 |
|
const int major = eFileFormat.get_value(); |
1252 |
|
if (m_file) m_file->pVersion->major = major; |
1253 |
|
} |
1254 |
|
|
1255 |
void PropDialog::set_info(DLS::Info* info) |
void PropDialog::set_info(DLS::Info* info) |
1256 |
{ |
{ |
1257 |
update(info); |
update(info); |
1383 |
} |
} |
1384 |
} |
} |
1385 |
|
|
1386 |
|
void MainWindow::updateSampleRefCountMap(gig::File* gig) { |
1387 |
|
sample_ref_count.clear(); |
1388 |
|
|
1389 |
|
if (!gig) return; |
1390 |
|
|
1391 |
|
for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; |
1392 |
|
instrument = gig->GetNextInstrument()) |
1393 |
|
{ |
1394 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
1395 |
|
rgn = instrument->GetNextRegion()) |
1396 |
|
{ |
1397 |
|
for (int i = 0; i < 256; ++i) { |
1398 |
|
if (!rgn->pDimensionRegions[i]) continue; |
1399 |
|
if (rgn->pDimensionRegions[i]->pSample) { |
1400 |
|
sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; |
1401 |
|
} |
1402 |
|
} |
1403 |
|
} |
1404 |
|
} |
1405 |
|
} |
1406 |
|
|
1407 |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1408 |
{ |
{ |
1409 |
file = 0; |
file = 0; |
1414 |
file_has_name = filename; |
file_has_name = filename; |
1415 |
file_is_changed = false; |
file_is_changed = false; |
1416 |
|
|
1417 |
|
propDialog.set_file(gig); |
1418 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1419 |
|
|
1420 |
instrument_name_connection.block(); |
instrument_name_connection.block(); |
1432 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1433 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
1434 |
|
|
1435 |
|
updateSampleRefCountMap(gig); |
1436 |
|
|
1437 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1438 |
if (group->Name != "") { |
if (group->Name != "") { |
1439 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1450 |
gig_to_utf8(sample->pInfo->Name); |
gig_to_utf8(sample->pInfo->Name); |
1451 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1452 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1453 |
|
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1454 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1455 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; |
1456 |
} |
} |
1457 |
} |
} |
1458 |
} |
} |
1459 |
|
|
1460 |
|
for (int i = 0; gig->GetScriptGroup(i); ++i) { |
1461 |
|
gig::ScriptGroup* group = gig->GetScriptGroup(i); |
1462 |
|
|
1463 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1464 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1465 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1466 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1467 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1468 |
|
for (int s = 0; group->GetScript(s); ++s) { |
1469 |
|
gig::Script* script = group->GetScript(s); |
1470 |
|
|
1471 |
|
Gtk::TreeModel::iterator iterScript = |
1472 |
|
m_refScriptsTreeModel->append(rowGroup.children()); |
1473 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1474 |
|
rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); |
1475 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1476 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1477 |
|
} |
1478 |
|
} |
1479 |
|
// unfold all script groups by default |
1480 |
|
m_TreeViewScripts.expand_all(); |
1481 |
|
|
1482 |
file = gig; |
file = gig; |
1483 |
|
|
1485 |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
1486 |
|
|
1487 |
instr_props_set_instrument(); |
instr_props_set_instrument(); |
1488 |
|
gig::Instrument* instrument = get_instrument(); |
1489 |
|
if (instrument) { |
1490 |
|
midiRules.set_instrument(instrument); |
1491 |
|
} |
1492 |
} |
} |
1493 |
|
|
1494 |
bool MainWindow::instr_props_set_instrument() |
bool MainWindow::instr_props_set_instrument() |
1536 |
} |
} |
1537 |
} |
} |
1538 |
|
|
1539 |
|
void MainWindow::show_midi_rules() |
1540 |
|
{ |
1541 |
|
if (gig::Instrument* instrument = get_instrument()) |
1542 |
|
{ |
1543 |
|
midiRules.set_instrument(instrument); |
1544 |
|
midiRules.show(); |
1545 |
|
midiRules.deiconify(); |
1546 |
|
} |
1547 |
|
} |
1548 |
|
|
1549 |
|
void MainWindow::show_script_slots() { |
1550 |
|
if (!file) return; |
1551 |
|
// get selected instrument |
1552 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1553 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1554 |
|
if (!it) return; |
1555 |
|
Gtk::TreeModel::Row row = *it; |
1556 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1557 |
|
if (!instrument) return; |
1558 |
|
|
1559 |
|
ScriptSlots* window = new ScriptSlots; |
1560 |
|
window->setInstrument(instrument); |
1561 |
|
//window->reparent(*this); |
1562 |
|
window->show(); |
1563 |
|
} |
1564 |
|
|
1565 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1566 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1567 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1608 |
if (button->type == GDK_2BUTTON_PRESS) { |
if (button->type == GDK_2BUTTON_PRESS) { |
1609 |
show_instr_props(); |
show_instr_props(); |
1610 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1611 |
|
// gig v2 files have no midi rules |
1612 |
|
static_cast<Gtk::MenuItem*>( |
1613 |
|
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1614 |
|
!(file->pVersion && file->pVersion->major == 2)); |
1615 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1616 |
} |
} |
1617 |
} |
} |
1658 |
} |
} |
1659 |
} |
} |
1660 |
|
|
1661 |
|
void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { |
1662 |
|
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1663 |
|
Gtk::Menu* script_popup = |
1664 |
|
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu")); |
1665 |
|
// update enabled/disabled state of sample popup items |
1666 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1667 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1668 |
|
bool group_selected = false; |
1669 |
|
bool script_selected = false; |
1670 |
|
if (it) { |
1671 |
|
Gtk::TreeModel::Row row = *it; |
1672 |
|
group_selected = row[m_ScriptsModel.m_col_group]; |
1673 |
|
script_selected = row[m_ScriptsModel.m_col_script]; |
1674 |
|
} |
1675 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> |
1676 |
|
set_sensitive(group_selected || script_selected); |
1677 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> |
1678 |
|
set_sensitive(file); |
1679 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> |
1680 |
|
set_sensitive(script_selected); |
1681 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> |
1682 |
|
set_sensitive(group_selected || script_selected); |
1683 |
|
// show sample popup |
1684 |
|
script_popup->popup(button->button, button->time); |
1685 |
|
} |
1686 |
|
} |
1687 |
|
|
1688 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1689 |
const Glib::ustring& name, int position) { |
const Glib::ustring& name, int position) { |
1810 |
} |
} |
1811 |
#endif |
#endif |
1812 |
instr_props_set_instrument(); |
instr_props_set_instrument(); |
1813 |
|
instr = get_instrument(); |
1814 |
|
if (instr) { |
1815 |
|
midiRules.set_instrument(instr); |
1816 |
|
} else { |
1817 |
|
midiRules.hide(); |
1818 |
|
} |
1819 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1820 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1821 |
msg.run(); |
msg.run(); |
1831 |
msg.run(); |
msg.run(); |
1832 |
} |
} |
1833 |
|
|
1834 |
|
void MainWindow::on_action_add_script_group() { |
1835 |
|
static int __script_indexer = 0; |
1836 |
|
if (!file) return; |
1837 |
|
gig::ScriptGroup* group = file->AddScriptGroup(); |
1838 |
|
group->Name = gig_from_utf8(_("Unnamed Group")); |
1839 |
|
if (__script_indexer) group->Name += " " + ToString(__script_indexer); |
1840 |
|
__script_indexer++; |
1841 |
|
// update sample tree view |
1842 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1843 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1844 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1845 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1846 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1847 |
|
file_changed(); |
1848 |
|
} |
1849 |
|
|
1850 |
|
void MainWindow::on_action_add_script() { |
1851 |
|
if (!file) return; |
1852 |
|
// get selected group |
1853 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1854 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1855 |
|
if (!it) return; |
1856 |
|
Gtk::TreeModel::Row row = *it; |
1857 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
1858 |
|
if (!group) { // not a group, but a script is selected (probably) |
1859 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1860 |
|
if (!script) return; |
1861 |
|
it = row.parent(); // resolve parent (that is the script's group) |
1862 |
|
if (!it) return; |
1863 |
|
row = *it; |
1864 |
|
group = row[m_ScriptsModel.m_col_group]; |
1865 |
|
if (!group) return; |
1866 |
|
} |
1867 |
|
|
1868 |
|
// add a new script to the .gig file |
1869 |
|
gig::Script* script = group->AddScript(); |
1870 |
|
Glib::ustring name = _("Unnamed Script"); |
1871 |
|
script->Name = gig_from_utf8(name); |
1872 |
|
|
1873 |
|
// add script to the tree view |
1874 |
|
Gtk::TreeModel::iterator iterScript = |
1875 |
|
m_refScriptsTreeModel->append(row.children()); |
1876 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1877 |
|
rowScript[m_ScriptsModel.m_col_name] = name; |
1878 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1879 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1880 |
|
|
1881 |
|
// unfold group of new script item in treeview |
1882 |
|
Gtk::TreeModel::Path path(iterScript); |
1883 |
|
m_TreeViewScripts.expand_to_path(path); |
1884 |
|
} |
1885 |
|
|
1886 |
|
void MainWindow::on_action_edit_script() { |
1887 |
|
if (!file) return; |
1888 |
|
// get selected script |
1889 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1890 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1891 |
|
if (!it) return; |
1892 |
|
Gtk::TreeModel::Row row = *it; |
1893 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1894 |
|
if (!script) return; |
1895 |
|
|
1896 |
|
ScriptEditor* editor = new ScriptEditor; |
1897 |
|
editor->setScript(script); |
1898 |
|
//editor->reparent(*this); |
1899 |
|
editor->show(); |
1900 |
|
} |
1901 |
|
|
1902 |
|
void MainWindow::on_action_remove_script() { |
1903 |
|
if (!file) return; |
1904 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1905 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1906 |
|
if (it) { |
1907 |
|
Gtk::TreeModel::Row row = *it; |
1908 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
1909 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1910 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
1911 |
|
try { |
1912 |
|
// remove script group or script from the gig file |
1913 |
|
if (group) { |
1914 |
|
// notify everybody that we're going to remove these samples |
1915 |
|
//TODO: scripts_to_be_removed_signal.emit(members); |
1916 |
|
// delete the group in the .gig file including the |
1917 |
|
// samples that belong to the group |
1918 |
|
file->DeleteScriptGroup(group); |
1919 |
|
// notify that we're done with removal |
1920 |
|
//TODO: scripts_removed_signal.emit(); |
1921 |
|
file_changed(); |
1922 |
|
} else if (script) { |
1923 |
|
// notify everybody that we're going to remove this sample |
1924 |
|
//TODO: std::list<gig::Script*> lscripts; |
1925 |
|
//TODO: lscripts.push_back(script); |
1926 |
|
//TODO: scripts_to_be_removed_signal.emit(lscripts); |
1927 |
|
// remove sample from the .gig file |
1928 |
|
script->GetGroup()->DeleteScript(script); |
1929 |
|
// notify that we're done with removal |
1930 |
|
//TODO: scripts_removed_signal.emit(); |
1931 |
|
dimreg_changed(); |
1932 |
|
file_changed(); |
1933 |
|
} |
1934 |
|
// remove respective row(s) from samples tree view |
1935 |
|
m_refScriptsTreeModel->erase(it); |
1936 |
|
} catch (RIFF::Exception e) { |
1937 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
1938 |
|
//TODO: scripts_removed_signal.emit(); |
1939 |
|
// show error message |
1940 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1941 |
|
msg.run(); |
1942 |
|
} |
1943 |
|
} |
1944 |
|
} |
1945 |
|
|
1946 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |
1947 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
1948 |
if (!file) return; |
if (!file) return; |
2312 |
} |
} |
2313 |
} |
} |
2314 |
|
|
2315 |
|
// see comment on on_sample_treeview_drag_begin() |
2316 |
|
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2317 |
|
{ |
2318 |
|
first_call_to_drag_data_get = true; |
2319 |
|
} |
2320 |
|
|
2321 |
|
void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2322 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2323 |
|
{ |
2324 |
|
if (!first_call_to_drag_data_get) return; |
2325 |
|
first_call_to_drag_data_get = false; |
2326 |
|
|
2327 |
|
// get selected script |
2328 |
|
gig::Script* script = NULL; |
2329 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2330 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2331 |
|
if (it) { |
2332 |
|
Gtk::TreeModel::Row row = *it; |
2333 |
|
script = row[m_ScriptsModel.m_col_script]; |
2334 |
|
} |
2335 |
|
// pass the gig::Script as pointer |
2336 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, |
2337 |
|
(const guchar*)&script, |
2338 |
|
sizeof(script)/*length of data in bytes*/); |
2339 |
|
} |
2340 |
|
|
2341 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2342 |
// 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 |
2343 |
// 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 |
2396 |
bool channels_changed = false; |
bool channels_changed = false; |
2397 |
if (sample->Channels == 1 && stereo_dimension) { |
if (sample->Channels == 1 && stereo_dimension) { |
2398 |
// remove the samplechannel dimension |
// remove the samplechannel dimension |
2399 |
|
/* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples |
2400 |
region->DeleteDimension(stereo_dimension); |
region->DeleteDimension(stereo_dimension); |
2401 |
channels_changed = true; |
channels_changed = true; |
2402 |
region_changed(); |
region_changed(); |
2403 |
|
*/ |
2404 |
} |
} |
2405 |
dimreg_edit.set_sample( |
dimreg_edit.set_sample( |
2406 |
sample, |
sample, |
2466 |
} |
} |
2467 |
} |
} |
2468 |
|
|
2469 |
|
void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, |
2470 |
|
const Gtk::TreeModel::iterator& iter) { |
2471 |
|
if (!iter) return; |
2472 |
|
Gtk::TreeModel::Row row = *iter; |
2473 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2474 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2475 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2476 |
|
gig::String gigname(gig_from_utf8(name)); |
2477 |
|
if (group) { |
2478 |
|
if (group->Name != gigname) { |
2479 |
|
group->Name = gigname; |
2480 |
|
printf("script group name changed\n"); |
2481 |
|
file_changed(); |
2482 |
|
} |
2483 |
|
} else if (script) { |
2484 |
|
if (script->Name != gigname) { |
2485 |
|
script->Name = gigname; |
2486 |
|
printf("script name changed\n"); |
2487 |
|
file_changed(); |
2488 |
|
} |
2489 |
|
} |
2490 |
|
} |
2491 |
|
|
2492 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
2493 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
2494 |
if (!iter) return; |
if (!iter) return; |
2523 |
} |
} |
2524 |
} |
} |
2525 |
|
|
2526 |
|
void MainWindow::on_action_combine_instruments() { |
2527 |
|
CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file); |
2528 |
|
d->show_all(); |
2529 |
|
d->resize(500, 400); |
2530 |
|
d->run(); |
2531 |
|
if (d->fileWasChanged()) { |
2532 |
|
// update GUI with new instrument just created |
2533 |
|
add_instrument(d->newCombinedInstrument()); |
2534 |
|
} |
2535 |
|
delete d; |
2536 |
|
} |
2537 |
|
|
2538 |
|
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
2539 |
|
struct _Source { |
2540 |
|
std::vector<RIFF::File*> riffs; |
2541 |
|
std::vector<gig::File*> gigs; |
2542 |
|
|
2543 |
|
~_Source() { |
2544 |
|
for (int k = 0; k < gigs.size(); ++k) delete gigs[k]; |
2545 |
|
for (int k = 0; k < riffs.size(); ++k) delete riffs[k]; |
2546 |
|
riffs.clear(); |
2547 |
|
gigs.clear(); |
2548 |
|
} |
2549 |
|
} sources; |
2550 |
|
|
2551 |
|
if (filenames.empty()) |
2552 |
|
throw RIFF::Exception(_("No files selected, so nothing done.")); |
2553 |
|
|
2554 |
|
// first open all input files (to avoid output file corruption) |
2555 |
|
int i; |
2556 |
|
try { |
2557 |
|
for (i = 0; i < filenames.size(); ++i) { |
2558 |
|
const std::string& filename = filenames[i]; |
2559 |
|
printf("opening file=%s\n", filename.c_str()); |
2560 |
|
|
2561 |
|
RIFF::File* riff = new RIFF::File(filename); |
2562 |
|
sources.riffs.push_back(riff); |
2563 |
|
|
2564 |
|
gig::File* gig = new gig::File(riff); |
2565 |
|
sources.gigs.push_back(gig); |
2566 |
|
} |
2567 |
|
} catch (RIFF::Exception e) { |
2568 |
|
throw RIFF::Exception( |
2569 |
|
_("Error occurred while opening '") + |
2570 |
|
filenames[i] + |
2571 |
|
"': " + |
2572 |
|
e.Message |
2573 |
|
); |
2574 |
|
} catch (...) { |
2575 |
|
throw RIFF::Exception( |
2576 |
|
_("Unknown exception occurred while opening '") + |
2577 |
|
filenames[i] + "'" |
2578 |
|
); |
2579 |
|
} |
2580 |
|
|
2581 |
|
// now merge the opened .gig files to the main .gig file currently being |
2582 |
|
// open in gigedit |
2583 |
|
try { |
2584 |
|
for (i = 0; i < filenames.size(); ++i) { |
2585 |
|
const std::string& filename = filenames[i]; |
2586 |
|
printf("merging file=%s\n", filename.c_str()); |
2587 |
|
assert(i < sources.gigs.size()); |
2588 |
|
|
2589 |
|
this->file->AddContentOf(sources.gigs[i]); |
2590 |
|
} |
2591 |
|
} catch (RIFF::Exception e) { |
2592 |
|
throw RIFF::Exception( |
2593 |
|
_("Error occurred while merging '") + |
2594 |
|
filenames[i] + |
2595 |
|
"': " + |
2596 |
|
e.Message |
2597 |
|
); |
2598 |
|
} catch (...) { |
2599 |
|
throw RIFF::Exception( |
2600 |
|
_("Unknown exception occurred while merging '") + |
2601 |
|
filenames[i] + "'" |
2602 |
|
); |
2603 |
|
} |
2604 |
|
|
2605 |
|
// Note: requires that this file already has a filename ! |
2606 |
|
this->file->Save(); |
2607 |
|
} |
2608 |
|
|
2609 |
|
void MainWindow::on_action_merge_files() { |
2610 |
|
if (this->file->GetFileName().empty()) { |
2611 |
|
Glib::ustring txt = _( |
2612 |
|
"You seem to have a new .gig file open that has not been saved " |
2613 |
|
"yet. You must save it somewhere before starting to merge it with " |
2614 |
|
"other .gig files though, because during the merge operation the " |
2615 |
|
"other files' sample data must be written on file level to the " |
2616 |
|
"target .gig file." |
2617 |
|
); |
2618 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2619 |
|
msg.run(); |
2620 |
|
return; |
2621 |
|
} |
2622 |
|
|
2623 |
|
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
2624 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
2625 |
|
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
2626 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
2627 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
2628 |
|
Gtk::FileFilter filter; |
2629 |
|
filter.add_pattern("*.gig"); |
2630 |
|
#else |
2631 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
2632 |
|
filter->add_pattern("*.gig"); |
2633 |
|
#endif |
2634 |
|
dialog.set_filter(filter); |
2635 |
|
if (current_gig_dir != "") { |
2636 |
|
dialog.set_current_folder(current_gig_dir); |
2637 |
|
} |
2638 |
|
dialog.set_select_multiple(true); |
2639 |
|
|
2640 |
|
// show warning in the file picker dialog |
2641 |
|
Gtk::HBox descriptionArea; |
2642 |
|
descriptionArea.set_spacing(15); |
2643 |
|
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
2644 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
2645 |
|
#if GTKMM_MAJOR_VERSION < 3 |
2646 |
|
view::WrapLabel description; |
2647 |
|
#else |
2648 |
|
Gtk::Label description; |
2649 |
|
description.set_line_wrap(); |
2650 |
|
#endif |
2651 |
|
description.set_markup(_( |
2652 |
|
"\nSelect at least one .gig file that shall be merged to the .gig file " |
2653 |
|
"currently being open in gigedit.\n\n" |
2654 |
|
"<b>Please Note:</b> Merging with other files will modify your " |
2655 |
|
"currently open .gig file on file level! And be aware that the current " |
2656 |
|
"merge algorithm does not detect duplicate samples yet. So if you are " |
2657 |
|
"merging files which are using equivalent sample data, those " |
2658 |
|
"equivalent samples will currently be treated as separate samples and " |
2659 |
|
"will accordingly be stored separately in the target .gig file!" |
2660 |
|
)); |
2661 |
|
descriptionArea.pack_start(description); |
2662 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
2663 |
|
descriptionArea.show_all(); |
2664 |
|
|
2665 |
|
if (dialog.run() == Gtk::RESPONSE_OK) { |
2666 |
|
printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); |
2667 |
|
std::vector<std::string> filenames = dialog.get_filenames(); |
2668 |
|
|
2669 |
|
// merge the selected files to the currently open .gig file |
2670 |
|
try { |
2671 |
|
mergeFiles(filenames); |
2672 |
|
} catch (RIFF::Exception e) { |
2673 |
|
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
2674 |
|
msg.run(); |
2675 |
|
} |
2676 |
|
|
2677 |
|
// update GUI |
2678 |
|
__refreshEntireGUI(); |
2679 |
|
} |
2680 |
|
} |
2681 |
|
|
2682 |
void MainWindow::set_file_is_shared(bool b) { |
void MainWindow::set_file_is_shared(bool b) { |
2683 |
this->file_is_shared = b; |
this->file_is_shared = b; |
2684 |
|
|
2695 |
} |
} |
2696 |
} |
} |
2697 |
|
|
2698 |
|
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
2699 |
|
if (!sample) return; |
2700 |
|
sample_ref_count[sample] += offset; |
2701 |
|
const int refcount = sample_ref_count[sample]; |
2702 |
|
|
2703 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2704 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2705 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2706 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2707 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2708 |
|
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
2709 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
2710 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; |
2711 |
|
} |
2712 |
|
} |
2713 |
|
} |
2714 |
|
|
2715 |
|
void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { |
2716 |
|
on_sample_ref_count_incremented(oldSample, -1); |
2717 |
|
on_sample_ref_count_incremented(newSample, +1); |
2718 |
|
} |
2719 |
|
|
2720 |
|
void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) { |
2721 |
|
// just in case a new sample is added later with exactly the same memory |
2722 |
|
// address, which would lead to incorrect refcount if not deleted here |
2723 |
|
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
2724 |
|
it != samples.end(); it != samples.end()) |
2725 |
|
{ |
2726 |
|
sample_ref_count.erase(*it); |
2727 |
|
} |
2728 |
|
} |
2729 |
|
|
2730 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
2731 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
2732 |
} |
} |