1 |
/* |
/* |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2016 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
17 |
* 02110-1301 USA. |
* 02110-1301 USA. |
18 |
*/ |
*/ |
19 |
|
|
|
#include <libintl.h> |
|
20 |
#include <iostream> |
#include <iostream> |
21 |
|
#include <cstring> |
22 |
|
|
23 |
|
#include <glibmmconfig.h> |
24 |
|
// threads.h must be included first to be able to build with |
25 |
|
// G_DISABLE_DEPRECATED |
26 |
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ |
27 |
|
(GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 |
28 |
|
#include <glibmm/threads.h> |
29 |
|
#endif |
30 |
|
|
31 |
|
#include <glibmm/convert.h> |
32 |
|
#include <glibmm/dispatcher.h> |
33 |
|
#include <glibmm/miscutils.h> |
34 |
|
#include <glibmm/stringutils.h> |
35 |
|
#include <gtkmm/aboutdialog.h> |
36 |
#include <gtkmm/filechooserdialog.h> |
#include <gtkmm/filechooserdialog.h> |
37 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
|
#include <gtkmm/stock.h> |
|
38 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
39 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
40 |
|
#include <gtkmm/toggleaction.h> |
41 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
#if GTKMM_MAJOR_VERSION < 3 |
42 |
#define ABOUT_DIALOG |
#include "wrapLabel.hh" |
|
#include <gtkmm/aboutdialog.h> |
|
43 |
#endif |
#endif |
44 |
|
|
45 |
|
#include "global.h" |
46 |
|
#include "compat.h" |
47 |
|
|
48 |
#include <stdio.h> |
#include <stdio.h> |
49 |
#include <sndfile.h> |
#include <sndfile.h> |
50 |
|
#include <assert.h> |
51 |
|
|
52 |
#include "mainwindow.h" |
#include "mainwindow.h" |
53 |
|
#include "Settings.h" |
54 |
|
#include "CombineInstrumentsDialog.h" |
55 |
|
#include "scripteditor.h" |
56 |
|
#include "scriptslots.h" |
57 |
|
#include "ReferencesView.h" |
58 |
|
#include "../../gfx/status_attached.xpm" |
59 |
|
#include "../../gfx/status_detached.xpm" |
60 |
|
|
|
#define _(String) gettext(String) |
|
|
|
|
|
template<class T> inline std::string ToString(T o) { |
|
|
std::stringstream ss; |
|
|
ss << o; |
|
|
return ss.str(); |
|
|
} |
|
61 |
|
|
62 |
MainWindow::MainWindow() |
MainWindow::MainWindow() : |
63 |
|
m_DimRegionChooser(*this), |
64 |
|
dimreg_label(_("Changes apply to:")), |
65 |
|
dimreg_all_regions(_("all regions")), |
66 |
|
dimreg_all_dimregs(_("all dimension splits")), |
67 |
|
dimreg_stereo(_("both channels")) |
68 |
{ |
{ |
69 |
// set_border_width(5); |
// set_border_width(5); |
70 |
// set_default_size(400, 200); |
// set_default_size(400, 200); |
73 |
add(m_VBox); |
add(m_VBox); |
74 |
|
|
75 |
// Handle selection |
// Handle selection |
76 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
m_TreeView.get_selection()->signal_changed().connect( |
|
tree_sel_ref->signal_changed().connect( |
|
77 |
sigc::mem_fun(*this, &MainWindow::on_sel_change)); |
sigc::mem_fun(*this, &MainWindow::on_sel_change)); |
78 |
|
|
79 |
// m_TreeView.set_reorderable(); |
// m_TreeView.set_reorderable(); |
89 |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
90 |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
91 |
|
|
92 |
|
m_ScrolledWindowScripts.add(m_TreeViewScripts); |
93 |
|
m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
94 |
|
|
95 |
|
|
96 |
m_TreeViewNotebook.set_size_request(300); |
m_TreeViewNotebook.set_size_request(300); |
97 |
|
|
98 |
m_HPaned.add1(m_TreeViewNotebook); |
m_HPaned.add1(m_TreeViewNotebook); |
99 |
m_HPaned.add2(dimreg_edit); |
dimreg_hbox.add(dimreg_label); |
100 |
|
dimreg_hbox.add(dimreg_all_regions); |
101 |
|
dimreg_hbox.add(dimreg_all_dimregs); |
102 |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples"); |
dimreg_stereo.set_active(); |
103 |
m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments"); |
dimreg_hbox.add(dimreg_stereo); |
104 |
|
dimreg_vbox.add(dimreg_edit); |
105 |
|
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
106 |
|
m_HPaned.add2(dimreg_vbox); |
107 |
|
|
108 |
|
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
109 |
|
dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well.")); |
110 |
|
dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below.")); |
111 |
|
dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below).")); |
112 |
|
|
113 |
|
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
114 |
|
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
115 |
|
m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts")); |
116 |
|
|
117 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
118 |
|
|
119 |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
120 |
actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW), |
actionGroup->add(Gtk::Action::create("New", _("_New")), |
121 |
|
Gtk::AccelKey("<control>n"), |
122 |
sigc::mem_fun( |
sigc::mem_fun( |
123 |
*this, &MainWindow::on_action_file_new)); |
*this, &MainWindow::on_action_file_new)); |
124 |
Glib::RefPtr<Gtk::Action> action = |
actionGroup->add(Gtk::Action::create("Open", _("_Open...")), |
125 |
Gtk::Action::create("Open", Gtk::Stock::OPEN); |
Gtk::AccelKey("<control>o"), |
|
action->property_label() = action->property_label() + "..."; |
|
|
actionGroup->add(action, |
|
126 |
sigc::mem_fun( |
sigc::mem_fun( |
127 |
*this, &MainWindow::on_action_file_open)); |
*this, &MainWindow::on_action_file_open)); |
128 |
actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE), |
actionGroup->add(Gtk::Action::create("Save", _("_Save")), |
129 |
|
Gtk::AccelKey("<control>s"), |
130 |
sigc::mem_fun( |
sigc::mem_fun( |
131 |
*this, &MainWindow::on_action_file_save)); |
*this, &MainWindow::on_action_file_save)); |
132 |
action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); |
actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")), |
|
action->property_label() = action->property_label() + "..."; |
|
|
actionGroup->add(action, |
|
133 |
Gtk::AccelKey("<shift><control>s"), |
Gtk::AccelKey("<shift><control>s"), |
134 |
sigc::mem_fun( |
sigc::mem_fun( |
135 |
*this, &MainWindow::on_action_file_save_as)); |
*this, &MainWindow::on_action_file_save_as)); |
136 |
actionGroup->add(Gtk::Action::create("Properties", |
actionGroup->add(Gtk::Action::create("Properties", |
137 |
Gtk::Stock::PROPERTIES), |
_("_Properties")), |
138 |
sigc::mem_fun( |
sigc::mem_fun( |
139 |
*this, &MainWindow::on_action_file_properties)); |
*this, &MainWindow::on_action_file_properties)); |
140 |
actionGroup->add(Gtk::Action::create("InstrProperties", |
actionGroup->add(Gtk::Action::create("InstrProperties", |
141 |
Gtk::Stock::PROPERTIES), |
_("_Properties")), |
142 |
sigc::mem_fun( |
sigc::mem_fun( |
143 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
144 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("MidiRules", |
145 |
|
_("_Midi Rules...")), |
146 |
|
sigc::mem_fun( |
147 |
|
*this, &MainWindow::show_midi_rules)); |
148 |
|
actionGroup->add(Gtk::Action::create("ScriptSlots", |
149 |
|
_("_Script Slots...")), |
150 |
|
sigc::mem_fun( |
151 |
|
*this, &MainWindow::show_script_slots)); |
152 |
|
actionGroup->add(Gtk::Action::create("Quit", _("_Quit")), |
153 |
|
Gtk::AccelKey("<control>q"), |
154 |
sigc::mem_fun( |
sigc::mem_fun( |
155 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
156 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add( |
157 |
|
Gtk::Action::create("MenuSample", _("_Sample")), |
158 |
|
sigc::mem_fun(*this, &MainWindow::show_samples_tab) |
159 |
|
); |
160 |
|
actionGroup->add( |
161 |
|
Gtk::Action::create("MenuInstrument", _("_Instrument")), |
162 |
|
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
163 |
|
); |
164 |
|
actionGroup->add( |
165 |
|
Gtk::Action::create("MenuScript", _("S_cript")), |
166 |
|
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
167 |
|
); |
168 |
|
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
169 |
|
|
170 |
|
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
171 |
|
|
172 |
|
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
173 |
|
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
174 |
|
toggle_action->set_active(true); |
175 |
|
actionGroup->add(toggle_action); |
176 |
|
|
177 |
|
toggle_action = |
178 |
|
Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); |
179 |
|
toggle_action->set_active(true); |
180 |
|
actionGroup->add(toggle_action); |
181 |
|
|
182 |
|
toggle_action = |
183 |
|
Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); |
184 |
|
toggle_action->set_active(true); |
185 |
|
actionGroup->add(toggle_action); |
186 |
|
|
187 |
|
|
188 |
|
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
189 |
|
toggle_action = |
190 |
|
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
191 |
|
toggle_action->set_active(true); |
192 |
|
actionGroup->add(toggle_action, |
193 |
|
sigc::mem_fun( |
194 |
|
*this, &MainWindow::on_action_view_status_bar)); |
195 |
|
|
196 |
|
toggle_action = |
197 |
|
Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension")); |
198 |
|
toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension); |
199 |
|
actionGroup->add(toggle_action, |
200 |
|
sigc::mem_fun( |
201 |
|
*this, &MainWindow::on_auto_restore_win_dim)); |
202 |
|
|
203 |
|
toggle_action = |
204 |
|
Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file")); |
205 |
|
toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile); |
206 |
|
actionGroup->add(toggle_action, |
207 |
|
sigc::mem_fun( |
208 |
|
*this, &MainWindow::on_save_with_temporary_file)); |
209 |
|
|
210 |
|
actionGroup->add( |
211 |
|
Gtk::Action::create("RefreshAll", _("_Refresh All")), |
212 |
|
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
213 |
|
); |
214 |
|
|
215 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help"))); |
216 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
actionGroup->add(Gtk::Action::create("About", _("_About")), |
|
action->property_label())); |
|
|
#ifdef ABOUT_DIALOG |
|
|
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
|
217 |
sigc::mem_fun( |
sigc::mem_fun( |
218 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
|
#endif |
|
219 |
actionGroup->add( |
actionGroup->add( |
220 |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
221 |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
222 |
); |
); |
223 |
actionGroup->add( |
actionGroup->add( |
224 |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")), |
225 |
|
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
226 |
|
); |
227 |
|
actionGroup->add( |
228 |
|
Gtk::Action::create("RemoveInstrument", _("_Remove")), |
229 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
230 |
); |
); |
231 |
|
|
232 |
|
|
233 |
|
actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings"))); |
234 |
|
|
235 |
|
toggle_action = |
236 |
|
Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions")); |
237 |
|
toggle_action->set_active(Settings::singleton()->warnUserOnExtensions); |
238 |
|
actionGroup->add( |
239 |
|
toggle_action, |
240 |
|
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
241 |
|
); |
242 |
|
|
243 |
|
toggle_action = |
244 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
245 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
246 |
|
actionGroup->add( |
247 |
|
toggle_action, |
248 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
249 |
|
); |
250 |
|
|
251 |
|
toggle_action = |
252 |
|
Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved")); |
253 |
|
toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved); |
254 |
|
actionGroup->add( |
255 |
|
toggle_action, |
256 |
|
sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved) |
257 |
|
); |
258 |
|
|
259 |
|
|
260 |
|
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
261 |
|
|
262 |
|
actionGroup->add( |
263 |
|
Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")), |
264 |
|
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
265 |
|
); |
266 |
|
|
267 |
|
actionGroup->add( |
268 |
|
Gtk::Action::create("MergeFiles", _("_Merge Files...")), |
269 |
|
sigc::mem_fun(*this, &MainWindow::on_action_merge_files) |
270 |
|
); |
271 |
|
|
272 |
|
|
273 |
// sample right-click popup actions |
// sample right-click popup actions |
274 |
actionGroup->add( |
actionGroup->add( |
275 |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
Gtk::Action::create("SampleProperties", _("_Properties")), |
276 |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
277 |
); |
); |
278 |
actionGroup->add( |
actionGroup->add( |
280 |
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
281 |
); |
); |
282 |
actionGroup->add( |
actionGroup->add( |
283 |
Gtk::Action::create("AddSample", _("Add _Sample(s)")), |
Gtk::Action::create("AddSample", _("Add _Sample(s)...")), |
284 |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
285 |
); |
); |
286 |
actionGroup->add( |
actionGroup->add( |
287 |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveSample", _("_Remove")), |
288 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
289 |
); |
); |
290 |
|
actionGroup->add( |
291 |
|
Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")), |
292 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) |
293 |
|
); |
294 |
|
actionGroup->add( |
295 |
|
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
296 |
|
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
297 |
|
); |
298 |
|
actionGroup->add( |
299 |
|
Gtk::Action::create("ReplaceSample", |
300 |
|
_("Replace Sample...")), |
301 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_sample) |
302 |
|
); |
303 |
|
actionGroup->add( |
304 |
|
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
305 |
|
_("Replace All Samples in All Groups...")), |
306 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
307 |
|
); |
308 |
|
|
309 |
|
// script right-click popup actions |
310 |
|
actionGroup->add( |
311 |
|
Gtk::Action::create("AddScriptGroup", _("Add _Group")), |
312 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) |
313 |
|
); |
314 |
|
actionGroup->add( |
315 |
|
Gtk::Action::create("AddScript", _("Add _Script")), |
316 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script) |
317 |
|
); |
318 |
|
actionGroup->add( |
319 |
|
Gtk::Action::create("EditScript", _("_Edit Script...")), |
320 |
|
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
321 |
|
); |
322 |
|
actionGroup->add( |
323 |
|
Gtk::Action::create("RemoveScript", _("_Remove")), |
324 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
325 |
|
); |
326 |
|
|
327 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
328 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
342 |
" <separator/>" |
" <separator/>" |
343 |
" <menuitem action='Quit'/>" |
" <menuitem action='Quit'/>" |
344 |
" </menu>" |
" </menu>" |
345 |
|
" <menu action='MenuEdit'>" |
346 |
|
" <menuitem action='CopySampleUnity'/>" |
347 |
|
" <menuitem action='CopySampleTune'/>" |
348 |
|
" <menuitem action='CopySampleLoop'/>" |
349 |
|
" </menu>" |
350 |
|
" <menu action='MenuSample'>" |
351 |
|
" <menuitem action='SampleProperties'/>" |
352 |
|
" <menuitem action='AddGroup'/>" |
353 |
|
" <menuitem action='AddSample'/>" |
354 |
|
" <menuitem action='ShowSampleRefs'/>" |
355 |
|
" <menuitem action='ReplaceSample' />" |
356 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
357 |
|
" <separator/>" |
358 |
|
" <menuitem action='RemoveSample'/>" |
359 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
360 |
|
" </menu>" |
361 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
362 |
|
" <menu action='AllInstruments'>" |
363 |
|
" </menu>" |
364 |
|
" <separator/>" |
365 |
|
" <menuitem action='InstrProperties'/>" |
366 |
|
" <menuitem action='MidiRules'/>" |
367 |
|
" <menuitem action='ScriptSlots'/>" |
368 |
|
" <menuitem action='AddInstrument'/>" |
369 |
|
" <menuitem action='DupInstrument'/>" |
370 |
|
" <separator/>" |
371 |
|
" <menuitem action='RemoveInstrument'/>" |
372 |
|
" </menu>" |
373 |
|
" <menu action='MenuScript'>" |
374 |
|
" <menuitem action='AddScriptGroup'/>" |
375 |
|
" <menuitem action='AddScript'/>" |
376 |
|
" <menuitem action='EditScript'/>" |
377 |
|
" <separator/>" |
378 |
|
" <menuitem action='RemoveScript'/>" |
379 |
|
" </menu>" |
380 |
|
" <menu action='MenuView'>" |
381 |
|
" <menuitem action='Statusbar'/>" |
382 |
|
" <menuitem action='AutoRestoreWinDim'/>" |
383 |
|
" <separator/>" |
384 |
|
" <menuitem action='RefreshAll'/>" |
385 |
|
" </menu>" |
386 |
|
" <menu action='MenuTools'>" |
387 |
|
" <menuitem action='CombineInstruments'/>" |
388 |
|
" <menuitem action='MergeFiles'/>" |
389 |
|
" </menu>" |
390 |
|
" <menu action='MenuSettings'>" |
391 |
|
" <menuitem action='WarnUserOnExtensions'/>" |
392 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
393 |
|
" <menuitem action='MoveRootNoteWithRegionMoved'/>" |
394 |
|
" <menuitem action='SaveWithTemporaryFile'/>" |
395 |
" </menu>" |
" </menu>" |
|
#ifdef ABOUT_DIALOG |
|
396 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
397 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
398 |
" </menu>" |
" </menu>" |
|
#endif |
|
399 |
" </menubar>" |
" </menubar>" |
400 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
401 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
402 |
|
" <menuitem action='MidiRules'/>" |
403 |
|
" <menuitem action='ScriptSlots'/>" |
404 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
405 |
|
" <menuitem action='DupInstrument'/>" |
406 |
" <separator/>" |
" <separator/>" |
407 |
" <menuitem action='RemoveInstrument'/>" |
" <menuitem action='RemoveInstrument'/>" |
408 |
" </popup>" |
" </popup>" |
410 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
411 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
412 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
413 |
|
" <menuitem action='ShowSampleRefs'/>" |
414 |
|
" <menuitem action='ReplaceSample' />" |
415 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
416 |
" <separator/>" |
" <separator/>" |
417 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
418 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
419 |
|
" </popup>" |
420 |
|
" <popup name='ScriptPopupMenu'>" |
421 |
|
" <menuitem action='AddScriptGroup'/>" |
422 |
|
" <menuitem action='AddScript'/>" |
423 |
|
" <menuitem action='EditScript'/>" |
424 |
|
" <separator/>" |
425 |
|
" <menuitem action='RemoveScript'/>" |
426 |
" </popup>" |
" </popup>" |
427 |
"</ui>"; |
"</ui>"; |
428 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
429 |
|
|
430 |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
431 |
|
|
432 |
|
// Set tooltips for menu items (for some reason, setting a tooltip on the |
433 |
|
// respective Gtk::Action objects above will simply be ignored, no matter |
434 |
|
// if using Gtk::Action::set_tooltip() or passing the tooltip string on |
435 |
|
// Gtk::Action::create()). |
436 |
|
{ |
437 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
438 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
439 |
|
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.")); |
440 |
|
} |
441 |
|
{ |
442 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
443 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
444 |
|
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.")); |
445 |
|
} |
446 |
|
{ |
447 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
448 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
449 |
|
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.")); |
450 |
|
} |
451 |
|
{ |
452 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
453 |
|
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
454 |
|
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.")); |
455 |
|
} |
456 |
|
{ |
457 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
458 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
459 |
|
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).")); |
460 |
|
} |
461 |
|
{ |
462 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
463 |
|
uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved")); |
464 |
|
item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around.")); |
465 |
|
} |
466 |
|
{ |
467 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
468 |
|
uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples")); |
469 |
|
item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones).")); |
470 |
|
// copy tooltip to popup menu |
471 |
|
Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>( |
472 |
|
uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples")); |
473 |
|
item2->set_tooltip_text(item->get_tooltip_text()); |
474 |
|
} |
475 |
|
{ |
476 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
477 |
|
uiManager->get_widget("/MenuBar/MenuView/RefreshAll")); |
478 |
|
item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface.")); |
479 |
|
} |
480 |
|
{ |
481 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
482 |
|
uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim")); |
483 |
|
item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time.")); |
484 |
|
} |
485 |
|
{ |
486 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
487 |
|
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
488 |
|
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
489 |
|
} |
490 |
|
{ |
491 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
492 |
|
uiManager->get_widget("/MenuBar/MenuTools/MergeFiles")); |
493 |
|
item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file.")); |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
|
instrument_menu = static_cast<Gtk::MenuItem*>( |
498 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
499 |
|
|
500 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
501 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
502 |
m_VBox.pack_start(m_HPaned); |
m_VBox.pack_start(m_HPaned); |
503 |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
504 |
|
m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK); |
505 |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
506 |
|
m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK); |
507 |
|
|
508 |
|
set_file_is_shared(false); |
509 |
|
|
510 |
|
// Status Bar: |
511 |
|
m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); |
512 |
|
m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); |
513 |
|
m_StatusBar.show(); |
514 |
|
|
515 |
m_RegionChooser.signal_region_selected().connect( |
m_RegionChooser.signal_region_selected().connect( |
516 |
sigc::mem_fun(*this, &MainWindow::region_changed) ); |
sigc::mem_fun(*this, &MainWindow::region_changed) ); |
521 |
// Create the Tree model: |
// Create the Tree model: |
522 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
523 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
524 |
m_refTreeModel->signal_row_changed().connect( |
m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
525 |
|
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); |
526 |
|
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
527 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
528 |
); |
); |
529 |
|
|
530 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
531 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr); |
532 |
m_TreeView.set_headers_visible(false); |
m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name); |
533 |
|
m_TreeView.set_headers_visible(true); |
534 |
|
|
535 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
536 |
|
// the sequence of instruments within the gig file |
537 |
|
{ |
538 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
539 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
540 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
541 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
542 |
|
m_TreeView.signal_drag_begin().connect( |
543 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
544 |
|
); |
545 |
|
m_TreeView.signal_drag_data_get().connect( |
546 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
547 |
|
); |
548 |
|
m_TreeView.signal_drag_data_received().connect( |
549 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
550 |
|
); |
551 |
|
} |
552 |
|
|
553 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
554 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
555 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
556 |
|
m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
557 |
|
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.")); |
558 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
559 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
560 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); |
561 |
|
{ |
562 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
563 |
|
Gtk::CellRendererText* cellrenderer = |
564 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
565 |
|
column->add_attribute( |
566 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
567 |
|
); |
568 |
|
} |
569 |
|
{ |
570 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
571 |
|
Gtk::CellRendererText* cellrenderer = |
572 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
573 |
|
column->add_attribute( |
574 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
575 |
|
); |
576 |
|
} |
577 |
|
m_TreeViewSamples.set_headers_visible(true); |
578 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
579 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
580 |
); |
); |
582 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
583 |
); |
); |
584 |
|
|
585 |
|
// create scripts treeview (including its data model) |
586 |
|
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
587 |
|
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
588 |
|
m_TreeViewScripts.set_tooltip_text(_( |
589 |
|
"Use CTRL + double click for editing a script." |
590 |
|
"\n\n" |
591 |
|
"Note: instrument scripts are a LinuxSampler extension of the gig " |
592 |
|
"format. This feature will not work with the GigaStudio software!" |
593 |
|
)); |
594 |
|
// m_TreeViewScripts.set_reorderable(); |
595 |
|
m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); |
596 |
|
m_TreeViewScripts.set_headers_visible(false); |
597 |
|
m_TreeViewScripts.signal_button_press_event().connect_notify( |
598 |
|
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
599 |
|
); |
600 |
|
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
601 |
|
m_TreeViewScripts.signal_row_activated().connect( |
602 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
603 |
|
); |
604 |
|
m_refScriptsTreeModel->signal_row_changed().connect( |
605 |
|
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
606 |
|
); |
607 |
|
|
608 |
|
// establish drag&drop between scripts tree view and ScriptSlots window |
609 |
|
std::vector<Gtk::TargetEntry> drag_target_gig_script; |
610 |
|
drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); |
611 |
|
m_TreeViewScripts.drag_source_set(drag_target_gig_script); |
612 |
|
m_TreeViewScripts.signal_drag_begin().connect( |
613 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin) |
614 |
|
); |
615 |
|
m_TreeViewScripts.signal_drag_data_get().connect( |
616 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get) |
617 |
|
); |
618 |
|
|
619 |
// 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 |
620 |
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
621 |
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
622 |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
623 |
|
m_TreeViewSamples.signal_drag_begin().connect( |
624 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin) |
625 |
|
); |
626 |
m_TreeViewSamples.signal_drag_data_get().connect( |
m_TreeViewSamples.signal_drag_data_get().connect( |
627 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
628 |
); |
); |
631 |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
632 |
); |
); |
633 |
dimreg_edit.signal_dimreg_changed().connect( |
dimreg_edit.signal_dimreg_changed().connect( |
634 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
635 |
m_RegionChooser.signal_instrument_changed().connect( |
m_RegionChooser.signal_instrument_changed().connect( |
636 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
637 |
|
m_RegionChooser.signal_instrument_changed().connect( |
638 |
|
sigc::mem_fun(*this, &MainWindow::region_changed)); |
639 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
640 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
641 |
instrumentProps.signal_instrument_changed().connect( |
instrumentProps.signal_changed().connect( |
642 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
643 |
|
propDialog.signal_changed().connect( |
644 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
645 |
|
midiRules.signal_changed().connect( |
646 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
647 |
|
|
648 |
|
dimreg_edit.signal_dimreg_to_be_changed().connect( |
649 |
|
dimreg_to_be_changed_signal.make_slot()); |
650 |
|
dimreg_edit.signal_dimreg_changed().connect( |
651 |
|
dimreg_changed_signal.make_slot()); |
652 |
|
dimreg_edit.signal_sample_ref_changed().connect( |
653 |
|
sample_ref_changed_signal.make_slot()); |
654 |
|
sample_ref_changed_signal.connect( |
655 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) |
656 |
|
); |
657 |
|
samples_to_be_removed_signal.connect( |
658 |
|
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
659 |
|
); |
660 |
|
|
661 |
|
dimreg_edit.signal_select_sample().connect( |
662 |
|
sigc::mem_fun(*this, &MainWindow::select_sample) |
663 |
|
); |
664 |
|
|
665 |
|
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
666 |
|
sigc::hide( |
667 |
|
sigc::bind( |
668 |
|
file_structure_to_be_changed_signal.make_slot(), |
669 |
|
sigc::ref(this->file) |
670 |
|
) |
671 |
|
) |
672 |
|
); |
673 |
|
m_RegionChooser.signal_instrument_struct_changed().connect( |
674 |
|
sigc::hide( |
675 |
|
sigc::bind( |
676 |
|
file_structure_changed_signal.make_slot(), |
677 |
|
sigc::ref(this->file) |
678 |
|
) |
679 |
|
) |
680 |
|
); |
681 |
|
m_RegionChooser.signal_region_to_be_changed().connect( |
682 |
|
region_to_be_changed_signal.make_slot()); |
683 |
|
m_RegionChooser.signal_region_changed_signal().connect( |
684 |
|
region_changed_signal.make_slot()); |
685 |
|
|
686 |
|
note_on_signal.connect( |
687 |
|
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event)); |
688 |
|
note_off_signal.connect( |
689 |
|
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event)); |
690 |
|
|
691 |
|
dimreg_all_regions.signal_toggled().connect( |
692 |
|
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
693 |
|
dimreg_all_dimregs.signal_toggled().connect( |
694 |
|
sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled)); |
695 |
|
dimreg_stereo.signal_toggled().connect( |
696 |
|
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
697 |
|
|
698 |
file = 0; |
file = 0; |
699 |
file_is_changed = false; |
file_is_changed = false; |
700 |
|
|
701 |
show_all_children(); |
show_all_children(); |
702 |
|
|
703 |
|
// start with a new gig file by default |
704 |
|
on_action_file_new(); |
705 |
|
|
706 |
|
// select 'Instruments' tab by default |
707 |
|
// (gtk allows this only if the tab childs are visible, thats why it's here) |
708 |
|
m_TreeViewNotebook.set_current_page(1); |
709 |
} |
} |
710 |
|
|
711 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
714 |
|
|
715 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
bool MainWindow::on_delete_event(GdkEventAny* event) |
716 |
{ |
{ |
717 |
return file_is_changed && !close_confirmation_dialog(); |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
718 |
} |
} |
719 |
|
|
720 |
void MainWindow::on_action_quit() |
void MainWindow::on_action_quit() |
721 |
{ |
{ |
722 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
723 |
hide(); |
hide(); |
724 |
} |
} |
725 |
|
|
728 |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
729 |
} |
} |
730 |
|
|
731 |
|
gig::Instrument* MainWindow::get_instrument() |
732 |
|
{ |
733 |
|
gig::Instrument* instrument = 0; |
734 |
|
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
735 |
|
if (rows.empty()) return NULL; |
736 |
|
Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); |
737 |
|
if (it) { |
738 |
|
Gtk::TreeModel::Row row = *it; |
739 |
|
instrument = row[m_Columns.m_col_instr]; |
740 |
|
} |
741 |
|
return instrument; |
742 |
|
} |
743 |
|
|
744 |
|
void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs) |
745 |
|
{ |
746 |
|
if (all_dimregs) { |
747 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
748 |
|
if (region->pDimensionRegions[i]) { |
749 |
|
dimreg_edit.dimregs.insert(region->pDimensionRegions[i]); |
750 |
|
} |
751 |
|
} |
752 |
|
} else { |
753 |
|
m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs); |
754 |
|
} |
755 |
|
} |
756 |
|
|
757 |
|
void MainWindow::update_dimregs() |
758 |
|
{ |
759 |
|
dimreg_edit.dimregs.clear(); |
760 |
|
bool all_regions = dimreg_all_regions.get_active(); |
761 |
|
bool stereo = dimreg_stereo.get_active(); |
762 |
|
bool all_dimregs = dimreg_all_dimregs.get_active(); |
763 |
|
|
764 |
|
if (all_regions) { |
765 |
|
gig::Instrument* instrument = get_instrument(); |
766 |
|
if (instrument) { |
767 |
|
for (gig::Region* region = instrument->GetFirstRegion() ; |
768 |
|
region ; |
769 |
|
region = instrument->GetNextRegion()) { |
770 |
|
add_region_to_dimregs(region, stereo, all_dimregs); |
771 |
|
} |
772 |
|
} |
773 |
|
} else { |
774 |
|
gig::Region* region = m_RegionChooser.get_region(); |
775 |
|
if (region) { |
776 |
|
add_region_to_dimregs(region, stereo, all_dimregs); |
777 |
|
} |
778 |
|
} |
779 |
|
} |
780 |
|
|
781 |
|
void MainWindow::dimreg_all_dimregs_toggled() |
782 |
|
{ |
783 |
|
dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active()); |
784 |
|
update_dimregs(); |
785 |
|
} |
786 |
|
|
787 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
788 |
{ |
{ |
789 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
update_dimregs(); |
790 |
|
dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); |
791 |
} |
} |
792 |
|
|
793 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
794 |
{ |
{ |
795 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
// select item in instrument menu |
796 |
|
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
797 |
|
if (!rows.empty()) { |
798 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); |
799 |
|
if (it) { |
800 |
|
Gtk::TreePath path(it); |
801 |
|
int index = path[0]; |
802 |
|
const std::vector<Gtk::Widget*> children = |
803 |
|
instrument_menu->get_children(); |
804 |
|
static_cast<Gtk::RadioMenuItem*>(children[index])->set_active(); |
805 |
|
} |
806 |
|
} |
807 |
|
|
808 |
Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); |
m_RegionChooser.set_instrument(get_instrument()); |
|
if (it) { |
|
|
Gtk::TreeModel::Row row = *it; |
|
|
std::cout << row[m_Columns.m_col_name] << std::endl; |
|
809 |
|
|
810 |
m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]); |
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
811 |
} else { |
switch_sampler_instrument_signal.emit(get_instrument()); |
|
m_RegionChooser.set_instrument(0); |
|
812 |
} |
} |
813 |
} |
} |
814 |
|
|
821 |
void Loader::progress_callback(float fraction) |
void Loader::progress_callback(float fraction) |
822 |
{ |
{ |
823 |
{ |
{ |
824 |
Glib::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
825 |
progress = fraction; |
progress = fraction; |
826 |
} |
} |
827 |
progress_dispatcher(); |
progress_dispatcher(); |
829 |
|
|
830 |
void Loader::thread_function() |
void Loader::thread_function() |
831 |
{ |
{ |
832 |
printf("thread_function self=%x\n", Glib::Thread::self()); |
printf("thread_function self=%p\n", |
833 |
printf("Start %s\n", filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
834 |
RIFF::File* riff = new RIFF::File(filename); |
printf("Start %s\n", filename.c_str()); |
835 |
gig = new gig::File(riff); |
try { |
836 |
gig::progress_t progress; |
RIFF::File* riff = new RIFF::File(filename); |
837 |
progress.callback = loader_progress_callback; |
gig = new gig::File(riff); |
838 |
progress.custom = this; |
gig::progress_t progress; |
839 |
|
progress.callback = loader_progress_callback; |
840 |
gig->GetInstrument(0, &progress); |
progress.custom = this; |
841 |
printf("End\n"); |
|
842 |
finished_dispatcher(); |
gig->GetInstrument(0, &progress); |
843 |
|
printf("End\n"); |
844 |
|
finished_dispatcher(); |
845 |
|
} catch (RIFF::Exception e) { |
846 |
|
error_message = e.Message; |
847 |
|
error_dispatcher.emit(); |
848 |
|
} catch (...) { |
849 |
|
error_message = _("Unknown exception occurred"); |
850 |
|
error_dispatcher.emit(); |
851 |
|
} |
852 |
} |
} |
853 |
|
|
854 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
855 |
: thread(0), filename(filename) |
: filename(filename), gig(0), thread(0), progress(0.f) |
856 |
{ |
{ |
857 |
} |
} |
858 |
|
|
859 |
void Loader::launch() |
void Loader::launch() |
860 |
{ |
{ |
861 |
|
#ifdef OLD_THREADS |
862 |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
863 |
printf("launch thread=%x\n", thread); |
#else |
864 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
865 |
|
#endif |
866 |
|
printf("launch thread=%p\n", static_cast<void*>(thread)); |
867 |
} |
} |
868 |
|
|
869 |
float Loader::get_progress() |
float Loader::get_progress() |
870 |
{ |
{ |
871 |
float res; |
float res; |
872 |
{ |
{ |
873 |
Glib::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
874 |
res = progress; |
res = progress; |
875 |
} |
} |
876 |
return res; |
return res; |
886 |
return finished_dispatcher; |
return finished_dispatcher; |
887 |
} |
} |
888 |
|
|
889 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
890 |
|
{ |
891 |
|
return error_dispatcher; |
892 |
|
} |
893 |
|
|
894 |
|
void saver_progress_callback(gig::progress_t* progress) |
895 |
|
{ |
896 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
897 |
|
saver->progress_callback(progress->factor); |
898 |
|
} |
899 |
|
|
900 |
|
void Saver::progress_callback(float fraction) |
901 |
|
{ |
902 |
|
{ |
903 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
904 |
|
progress = fraction; |
905 |
|
} |
906 |
|
progress_dispatcher.emit(); |
907 |
|
} |
908 |
|
|
909 |
|
void Saver::thread_function() |
910 |
|
{ |
911 |
|
printf("thread_function self=%p\n", |
912 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
913 |
|
printf("Start %s\n", filename.c_str()); |
914 |
|
try { |
915 |
|
gig::progress_t progress; |
916 |
|
progress.callback = saver_progress_callback; |
917 |
|
progress.custom = this; |
918 |
|
|
919 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
920 |
|
if (filename.empty()) { |
921 |
|
if (!Settings::singleton()->saveWithTemporaryFile) { |
922 |
|
// save directly over the existing .gig file |
923 |
|
// (requires less disk space than solution below |
924 |
|
// but may be slower) |
925 |
|
gig->Save(&progress); |
926 |
|
} else { |
927 |
|
// save the file as separate temporary file first, |
928 |
|
// then move the saved file over the old file |
929 |
|
// (may result in performance speedup during save) |
930 |
|
String tmpname = filename + ".TMP"; |
931 |
|
gig->Save(tmpname, &progress); |
932 |
|
#if defined(WIN32) |
933 |
|
if (!DeleteFile(filename.c_str())) { |
934 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file)."); |
935 |
|
} |
936 |
|
#else // POSIX ... |
937 |
|
if (unlink(filename.c_str())) { |
938 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno))); |
939 |
|
} |
940 |
|
#endif |
941 |
|
if (rename(tmpname.c_str(), filename.c_str())) { |
942 |
|
#if defined(WIN32) |
943 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
944 |
|
#else |
945 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno))); |
946 |
|
#endif |
947 |
|
} |
948 |
|
} |
949 |
|
} else { |
950 |
|
gig->Save(filename, &progress); |
951 |
|
} |
952 |
|
|
953 |
|
printf("End\n"); |
954 |
|
finished_dispatcher.emit(); |
955 |
|
} catch (RIFF::Exception e) { |
956 |
|
error_message = e.Message; |
957 |
|
error_dispatcher.emit(); |
958 |
|
} catch (...) { |
959 |
|
error_message = _("Unknown exception occurred"); |
960 |
|
error_dispatcher.emit(); |
961 |
|
} |
962 |
|
} |
963 |
|
|
964 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
965 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
966 |
|
{ |
967 |
|
} |
968 |
|
|
969 |
|
void Saver::launch() |
970 |
|
{ |
971 |
|
#ifdef OLD_THREADS |
972 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
973 |
|
#else |
974 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
975 |
|
#endif |
976 |
|
printf("launch thread=%p\n", static_cast<void*>(thread)); |
977 |
|
} |
978 |
|
|
979 |
|
float Saver::get_progress() |
980 |
|
{ |
981 |
|
float res; |
982 |
|
{ |
983 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
984 |
|
res = progress; |
985 |
|
} |
986 |
|
return res; |
987 |
|
} |
988 |
|
|
989 |
|
Glib::Dispatcher& Saver::signal_progress() |
990 |
|
{ |
991 |
|
return progress_dispatcher; |
992 |
|
} |
993 |
|
|
994 |
|
Glib::Dispatcher& Saver::signal_finished() |
995 |
|
{ |
996 |
|
return finished_dispatcher; |
997 |
|
} |
998 |
|
|
999 |
|
Glib::Dispatcher& Saver::signal_error() |
1000 |
|
{ |
1001 |
|
return error_dispatcher; |
1002 |
|
} |
1003 |
|
|
1004 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
1005 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
1006 |
{ |
{ |
1007 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
1008 |
show_all_children(); |
show_all_children(); |
1009 |
|
resize(600,50); |
1010 |
} |
} |
1011 |
|
|
1012 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
1013 |
// before a new .gig file is to be created or to be loaded. |
// before a new .gig file is to be created or to be loaded. |
1014 |
void MainWindow::__clear() { |
void MainWindow::__clear() { |
|
// remove all entries from "Instrument" menu |
|
|
Gtk::MenuItem* instrument_menu = |
|
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
|
|
instrument_menu->hide(); |
|
|
for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) { |
|
|
delete &instrument_menu->get_submenu()->items()[i]; |
|
|
} |
|
|
instrument_menu->get_submenu()->items().clear(); |
|
1015 |
// forget all samples that ought to be imported |
// forget all samples that ought to be imported |
1016 |
m_SampleImportQueue.clear(); |
m_SampleImportQueue.clear(); |
1017 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
1018 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
1019 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
1020 |
|
m_refScriptsTreeModel->clear(); |
1021 |
|
// remove all entries from "Instrument" menu |
1022 |
|
while (!instrument_menu->get_children().empty()) { |
1023 |
|
remove_instrument_from_menu(0); |
1024 |
|
} |
1025 |
// free libgig's gig::File instance |
// free libgig's gig::File instance |
1026 |
if (file) { |
if (file && !file_is_shared) delete file; |
1027 |
delete file; |
file = NULL; |
1028 |
file = NULL; |
set_file_is_shared(false); |
1029 |
|
} |
1030 |
|
|
1031 |
|
void MainWindow::__refreshEntireGUI() { |
1032 |
|
// clear the samples and instruments tree views |
1033 |
|
m_refTreeModel->clear(); |
1034 |
|
m_refSamplesTreeModel->clear(); |
1035 |
|
m_refScriptsTreeModel->clear(); |
1036 |
|
// remove all entries from "Instrument" menu |
1037 |
|
while (!instrument_menu->get_children().empty()) { |
1038 |
|
remove_instrument_from_menu(0); |
1039 |
} |
} |
1040 |
|
|
1041 |
|
if (!this->file) return; |
1042 |
|
|
1043 |
|
load_gig( |
1044 |
|
this->file, this->file->pInfo->Name.c_str(), this->file_is_shared |
1045 |
|
); |
1046 |
} |
} |
1047 |
|
|
1048 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
1049 |
{ |
{ |
1050 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
1051 |
|
|
1052 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
1053 |
|
|
1054 |
// clear all GUI elements |
// clear all GUI elements |
1055 |
__clear(); |
__clear(); |
1057 |
gig::File* pFile = new gig::File; |
gig::File* pFile = new gig::File; |
1058 |
// already add one new instrument by default |
// already add one new instrument by default |
1059 |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
1060 |
pInstrument->pInfo->Name = "Unnamed Instrument"; |
pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument")); |
1061 |
// update GUI with that new gig::File |
// update GUI with that new gig::File |
1062 |
load_gig(pFile, 0 /*no file name yet*/); |
load_gig(pFile, 0 /*no file name yet*/); |
1063 |
} |
} |
1070 |
g_free(msg); |
g_free(msg); |
1071 |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
1072 |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
1073 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1074 |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES); |
1075 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
1076 |
int response = dialog.run(); |
int response = dialog.run(); |
1077 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
dialog.hide(); |
1078 |
return response != Gtk::RESPONSE_CANCEL; |
|
1079 |
|
// user decided to exit app without saving |
1080 |
|
if (response == Gtk::RESPONSE_NO) return true; |
1081 |
|
|
1082 |
|
// user cancelled dialog, thus don't close app |
1083 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
1084 |
|
|
1085 |
|
// TODO: the following return valid is disabled and hard coded instead for |
1086 |
|
// now, due to the fact that saving with progress bar is now implemented |
1087 |
|
// asynchronously, as a result the app does not close automatically anymore |
1088 |
|
// after saving the file has completed |
1089 |
|
// |
1090 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
1091 |
|
// return response != Gtk::RESPONSE_CANCEL; |
1092 |
|
// |
1093 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
1094 |
|
return false; // always prevent closing the app for now (see comment above) |
1095 |
|
} |
1096 |
|
|
1097 |
|
bool MainWindow::leaving_shared_mode_dialog() { |
1098 |
|
Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); |
1099 |
|
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
1100 |
|
dialog.set_secondary_text( |
1101 |
|
_("If you proceed to work on another instrument file, it won't be " |
1102 |
|
"used by the sampler until you tell the sampler explicitly to " |
1103 |
|
"load it.")); |
1104 |
|
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
1105 |
|
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1106 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
1107 |
|
int response = dialog.run(); |
1108 |
|
dialog.hide(); |
1109 |
|
return response == Gtk::RESPONSE_YES; |
1110 |
} |
} |
1111 |
|
|
1112 |
void MainWindow::on_action_file_open() |
void MainWindow::on_action_file_open() |
1113 |
{ |
{ |
1114 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
1115 |
|
|
1116 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
1117 |
|
|
1118 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
1119 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1120 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
1121 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
1122 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1123 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
1124 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
1125 |
|
#else |
1126 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
1127 |
|
filter->add_pattern("*.gig"); |
1128 |
|
#endif |
1129 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
1130 |
if (current_dir != "") { |
if (current_gig_dir != "") { |
1131 |
dialog.set_current_folder(current_dir); |
dialog.set_current_folder(current_gig_dir); |
1132 |
} |
} |
1133 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1134 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
1135 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
1136 |
__clear(); |
printf("on_action_file_open self=%p\n", |
1137 |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
static_cast<void*>(Glib::Threads::Thread::self())); |
1138 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
1139 |
current_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
1140 |
} |
} |
1141 |
} |
} |
1142 |
|
|
1143 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1144 |
{ |
{ |
1145 |
load_dialog = new LoadDialog("Loading...", *this); |
__clear(); |
1146 |
load_dialog->show_all(); |
|
1147 |
loader = new Loader(strdup(name)); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1148 |
|
_("Loading") + Glib::ustring(" '") + |
1149 |
|
Glib::filename_display_basename(name) + "' ...", |
1150 |
|
*this |
1151 |
|
); |
1152 |
|
progress_dialog->show_all(); |
1153 |
|
loader = new Loader(name); //FIXME: memory leak! |
1154 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1155 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1156 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1157 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1158 |
|
loader->signal_error().connect( |
1159 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1160 |
loader->launch(); |
loader->launch(); |
1161 |
} |
} |
1162 |
|
|
1167 |
msg.run(); |
msg.run(); |
1168 |
Gtk::Main::quit(); |
Gtk::Main::quit(); |
1169 |
} |
} |
1170 |
|
// clear all GUI elements |
1171 |
|
__clear(); |
1172 |
|
// load the instrument |
1173 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1174 |
load_gig(pFile, 0 /*file name*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1175 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1176 |
|
int i = 0; |
1177 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1178 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1179 |
|
{ |
1180 |
|
if (instrument == instr) { |
1181 |
|
// select item in "instruments" tree view |
1182 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1183 |
|
// make sure the selected item in the "instruments" tree view is |
1184 |
|
// visible (scroll to it) |
1185 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1186 |
|
// select item in instrument menu |
1187 |
|
{ |
1188 |
|
const std::vector<Gtk::Widget*> children = |
1189 |
|
instrument_menu->get_children(); |
1190 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1191 |
|
} |
1192 |
|
// update region chooser and dimension region chooser |
1193 |
|
m_RegionChooser.set_instrument(instr); |
1194 |
|
break; |
1195 |
|
} |
1196 |
|
} |
1197 |
} |
} |
1198 |
|
|
1199 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1200 |
{ |
{ |
1201 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1202 |
} |
} |
1203 |
|
|
1204 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1205 |
{ |
{ |
1206 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1207 |
printf("on_loader_finished self=%x\n", Glib::Thread::self()); |
printf("on_loader_finished self=%p\n", |
1208 |
load_gig(loader->gig, loader->filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
1209 |
load_dialog->hide(); |
load_gig(loader->gig, loader->filename.c_str()); |
1210 |
|
progress_dialog->hide(); |
1211 |
|
} |
1212 |
|
|
1213 |
|
void MainWindow::on_loader_error() |
1214 |
|
{ |
1215 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1216 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1217 |
|
msg.run(); |
1218 |
|
progress_dialog->hide(); |
1219 |
} |
} |
1220 |
|
|
1221 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1223 |
file_save(); |
file_save(); |
1224 |
} |
} |
1225 |
|
|
1226 |
bool MainWindow::file_save() |
bool MainWindow::check_if_savable() |
1227 |
{ |
{ |
1228 |
if (!file) return false; |
if (!file) return false; |
|
if (!file_has_name) return file_save_as(); |
|
1229 |
|
|
1230 |
std::cout << "Saving file\n" << std::flush; |
if (!file->GetFirstSample()) { |
1231 |
try { |
Gtk::MessageDialog(*this, _("The file could not be saved " |
1232 |
file->Save(); |
"because it contains no samples"), |
1233 |
if (file_is_changed) { |
false, Gtk::MESSAGE_ERROR).run(); |
|
set_title(get_title().substr(1)); |
|
|
file_is_changed = false; |
|
|
} |
|
|
} catch (RIFF::Exception e) { |
|
|
Glib::ustring txt = "Could not save file: " + e.Message; |
|
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
|
|
msg.run(); |
|
1234 |
return false; |
return false; |
1235 |
} |
} |
1236 |
std::cout << "Saving file done\n" << std::flush; |
|
1237 |
__import_queued_samples(); |
for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ; |
1238 |
|
instrument = file->GetNextInstrument()) { |
1239 |
|
if (!instrument->GetFirstRegion()) { |
1240 |
|
Gtk::MessageDialog(*this, _("The file could not be saved " |
1241 |
|
"because there are instruments " |
1242 |
|
"that have no regions"), |
1243 |
|
false, Gtk::MESSAGE_ERROR).run(); |
1244 |
|
return false; |
1245 |
|
} |
1246 |
|
} |
1247 |
|
return true; |
1248 |
|
} |
1249 |
|
|
1250 |
|
bool MainWindow::file_save() |
1251 |
|
{ |
1252 |
|
if (!check_if_savable()) return false; |
1253 |
|
if (!file_is_shared && !file_has_name) return file_save_as(); |
1254 |
|
|
1255 |
|
std::cout << "Saving file\n" << std::flush; |
1256 |
|
file_structure_to_be_changed_signal.emit(this->file); |
1257 |
|
|
1258 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1259 |
|
_("Saving") + Glib::ustring(" '") + |
1260 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
1261 |
|
*this |
1262 |
|
); |
1263 |
|
progress_dialog->show_all(); |
1264 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
1265 |
|
saver->signal_progress().connect( |
1266 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1267 |
|
saver->signal_finished().connect( |
1268 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1269 |
|
saver->signal_error().connect( |
1270 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1271 |
|
saver->launch(); |
1272 |
|
|
1273 |
return true; |
return true; |
1274 |
} |
} |
1275 |
|
|
1276 |
|
void MainWindow::on_saver_progress() |
1277 |
|
{ |
1278 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1279 |
|
} |
1280 |
|
|
1281 |
|
void MainWindow::on_saver_error() |
1282 |
|
{ |
1283 |
|
file_structure_changed_signal.emit(this->file); |
1284 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1285 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1286 |
|
msg.run(); |
1287 |
|
} |
1288 |
|
|
1289 |
|
void MainWindow::on_saver_finished() |
1290 |
|
{ |
1291 |
|
this->file = saver->gig; |
1292 |
|
this->filename = saver->filename; |
1293 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1294 |
|
set_title(Glib::filename_display_basename(filename)); |
1295 |
|
file_has_name = true; |
1296 |
|
file_is_changed = false; |
1297 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1298 |
|
__import_queued_samples(); |
1299 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1300 |
|
|
1301 |
|
file_structure_changed_signal.emit(this->file); |
1302 |
|
|
1303 |
|
__refreshEntireGUI(); |
1304 |
|
progress_dialog->hide(); |
1305 |
|
} |
1306 |
|
|
1307 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1308 |
{ |
{ |
1309 |
|
if (!check_if_savable()) return; |
1310 |
file_save_as(); |
file_save_as(); |
1311 |
} |
} |
1312 |
|
|
1313 |
bool MainWindow::file_save_as() |
bool MainWindow::file_save_as() |
1314 |
{ |
{ |
1315 |
if (!file) return false; |
Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
1316 |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1317 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Save"), Gtk::RESPONSE_OK); |
|
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
|
1318 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
|
|
|
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2 |
|
1319 |
dialog.set_do_overwrite_confirmation(); |
dialog.set_do_overwrite_confirmation(); |
1320 |
// TODO: an overwrite dialog for gtkmm < 2.8 |
|
1321 |
#endif |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1322 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
1323 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
1324 |
|
#else |
1325 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
1326 |
|
filter->add_pattern("*.gig"); |
1327 |
|
#endif |
1328 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
1329 |
|
|
1330 |
if (Glib::path_is_absolute(filename)) { |
// set initial dir and filename of the Save As dialog |
1331 |
dialog.set_filename(filename); |
// and prepare that initial filename as a copy of the gig |
1332 |
} else if (current_dir != "") { |
{ |
1333 |
dialog.set_current_folder(current_dir); |
std::string basename = Glib::path_get_basename(filename); |
1334 |
|
std::string dir = Glib::path_get_dirname(filename); |
1335 |
|
basename = std::string(_("copy_of_")) + basename; |
1336 |
|
Glib::ustring copyFileName = Glib::build_filename(dir, basename); |
1337 |
|
if (Glib::path_is_absolute(filename)) { |
1338 |
|
dialog.set_filename(copyFileName); |
1339 |
|
} else { |
1340 |
|
if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir); |
1341 |
|
} |
1342 |
|
dialog.set_current_name(Glib::filename_display_basename(copyFileName)); |
1343 |
} |
} |
1344 |
dialog.set_current_name(Glib::filename_display_basename(filename)); |
|
1345 |
|
// show warning in the dialog |
1346 |
|
Gtk::HBox descriptionArea; |
1347 |
|
descriptionArea.set_spacing(15); |
1348 |
|
Gtk::Image warningIcon; |
1349 |
|
warningIcon.set_from_icon_name("dialog-warning", |
1350 |
|
Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
1351 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
1352 |
|
#if GTKMM_MAJOR_VERSION < 3 |
1353 |
|
view::WrapLabel description; |
1354 |
|
#else |
1355 |
|
Gtk::Label description; |
1356 |
|
description.set_line_wrap(); |
1357 |
|
#endif |
1358 |
|
description.set_markup( |
1359 |
|
_("\n<b>CAUTION:</b> You <b>MUST</b> use the " |
1360 |
|
"<span style=\"italic\">\"Save\"</span> dialog instead of " |
1361 |
|
"<span style=\"italic\">\"Save As...\"</span> if you want to save " |
1362 |
|
"to the same .gig file. Using " |
1363 |
|
"<span style=\"italic\">\"Save As...\"</span> for writing to the " |
1364 |
|
"same .gig file will end up in corrupted sample wave data!\n") |
1365 |
|
); |
1366 |
|
descriptionArea.pack_start(description); |
1367 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
1368 |
|
descriptionArea.show_all(); |
1369 |
|
|
1370 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1371 |
try { |
std::string filename = dialog.get_filename(); |
1372 |
std::string filename = dialog.get_filename(); |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1373 |
if (!Glib::str_has_suffix(filename, ".gig")) { |
filename += ".gig"; |
|
filename += ".gig"; |
|
|
} |
|
|
printf("filename=%s\n", filename.c_str()); |
|
|
file->Save(filename); |
|
|
this->filename = filename; |
|
|
current_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) { |
|
|
Glib::ustring txt = "Could not save file: " + e.Message; |
|
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
|
|
msg.run(); |
|
|
return false; |
|
1374 |
} |
} |
1375 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1376 |
|
|
1377 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1378 |
|
_("Saving") + Glib::ustring(" '") + |
1379 |
|
Glib::filename_display_basename(filename) + "' ...", |
1380 |
|
*this |
1381 |
|
); |
1382 |
|
progress_dialog->show_all(); |
1383 |
|
|
1384 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1385 |
|
saver->signal_progress().connect( |
1386 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1387 |
|
saver->signal_finished().connect( |
1388 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1389 |
|
saver->signal_error().connect( |
1390 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1391 |
|
saver->launch(); |
1392 |
|
|
1393 |
return true; |
return true; |
1394 |
} |
} |
1395 |
return false; |
return false; |
1399 |
void MainWindow::__import_queued_samples() { |
void MainWindow::__import_queued_samples() { |
1400 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1401 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1402 |
printf("Samples to import: %d\n", m_SampleImportQueue.size()); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1403 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1404 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1405 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1406 |
SF_INFO info; |
SF_INFO info; |
1407 |
info.format = 0; |
info.format = 0; |
1408 |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
1409 |
|
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
1410 |
try { |
try { |
1411 |
if (!hFile) throw std::string("could not open file"); |
if (!hFile) throw std::string(_("could not open file")); |
1412 |
// determine sample's bit depth |
// determine sample's bit depth |
1413 |
int bitdepth; |
int bitdepth; |
1414 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
1425 |
break; |
break; |
1426 |
default: |
default: |
1427 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
1428 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1429 |
} |
} |
1430 |
|
|
1431 |
const int bufsize = 10000; |
const int bufsize = 10000; |
1467 |
} |
} |
1468 |
// cleanup |
// cleanup |
1469 |
sf_close(hFile); |
sf_close(hFile); |
1470 |
|
// let the sampler re-cache the sample if needed |
1471 |
|
sample_changed_signal.emit(iter->gig_sample); |
1472 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
1473 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
1474 |
std::list<SampleImportItem>::iterator cur = iter; |
std::list<SampleImportItem>::iterator cur = iter; |
1476 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
1477 |
} catch (std::string what) { |
} catch (std::string what) { |
1478 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
1479 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1480 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += (*iter).sample_path += " (" + what + ")"; |
1481 |
++iter; |
++iter; |
1482 |
} |
} |
1483 |
} |
} |
1484 |
// show error message box when some sample(s) could not be imported |
// show error message box when some sample(s) could not be imported |
1485 |
if (error_files.size()) { |
if (!error_files.empty()) { |
1486 |
Glib::ustring txt = "Could not import the following sample(s):\n" + error_files; |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
1487 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1488 |
msg.run(); |
msg.run(); |
1489 |
} |
} |
1495 |
propDialog.deiconify(); |
propDialog.deiconify(); |
1496 |
} |
} |
1497 |
|
|
1498 |
|
void MainWindow::on_action_warn_user_on_extensions() { |
1499 |
|
Settings::singleton()->warnUserOnExtensions = |
1500 |
|
!Settings::singleton()->warnUserOnExtensions; |
1501 |
|
} |
1502 |
|
|
1503 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1504 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1505 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1506 |
|
} |
1507 |
|
|
1508 |
|
void MainWindow::on_action_move_root_note_with_region_moved() { |
1509 |
|
Settings::singleton()->moveRootNoteWithRegionMoved = |
1510 |
|
!Settings::singleton()->moveRootNoteWithRegionMoved; |
1511 |
|
} |
1512 |
|
|
1513 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1514 |
{ |
{ |
|
#ifdef ABOUT_DIALOG |
|
1515 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1516 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2 |
1517 |
|
dialog.set_program_name("Gigedit"); |
1518 |
|
#else |
1519 |
|
dialog.set_name("Gigedit"); |
1520 |
|
#endif |
1521 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1522 |
|
dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson"); |
1523 |
|
const std::string sComment = |
1524 |
|
_("Built " __DATE__ "\nUsing ") + |
1525 |
|
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1526 |
|
_( |
1527 |
|
"Gigedit is released under the GNU General Public License.\n" |
1528 |
|
"\n" |
1529 |
|
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1530 |
|
"backup your Gigasampler/GigaStudio files before editing them with " |
1531 |
|
"this application.\n" |
1532 |
|
"\n" |
1533 |
|
"Please report bugs to: http://bugs.linuxsampler.org" |
1534 |
|
); |
1535 |
|
dialog.set_comments(sComment.c_str()); |
1536 |
|
dialog.set_website("http://www.linuxsampler.org"); |
1537 |
|
dialog.set_website_label("http://www.linuxsampler.org"); |
1538 |
dialog.run(); |
dialog.run(); |
|
#endif |
|
1539 |
} |
} |
1540 |
|
|
1541 |
PropDialog::PropDialog() |
PropDialog::PropDialog() |
1542 |
: table(2,1) |
: eFileFormat(_("File Format")), |
1543 |
{ |
eName(_("Name")), |
1544 |
|
eCreationDate(_("Creation date")), |
1545 |
|
eComments(_("Comments")), |
1546 |
|
eProduct(_("Product")), |
1547 |
|
eCopyright(_("Copyright")), |
1548 |
|
eArtists(_("Artists")), |
1549 |
|
eGenre(_("Genre")), |
1550 |
|
eKeywords(_("Keywords")), |
1551 |
|
eEngineer(_("Engineer")), |
1552 |
|
eTechnician(_("Technician")), |
1553 |
|
eSoftware(_("Software")), |
1554 |
|
eMedium(_("Medium")), |
1555 |
|
eSource(_("Source")), |
1556 |
|
eSourceForm(_("Source form")), |
1557 |
|
eCommissioned(_("Commissioned")), |
1558 |
|
eSubject(_("Subject")), |
1559 |
|
quitButton(_("_Close"), true), |
1560 |
|
table(2, 1), |
1561 |
|
m_file(NULL) |
1562 |
|
{ |
1563 |
|
set_title(_("File Properties")); |
1564 |
|
eName.set_width_chars(50); |
1565 |
|
|
1566 |
|
connect(eName, &DLS::Info::Name); |
1567 |
|
connect(eCreationDate, &DLS::Info::CreationDate); |
1568 |
|
connect(eComments, &DLS::Info::Comments); |
1569 |
|
connect(eProduct, &DLS::Info::Product); |
1570 |
|
connect(eCopyright, &DLS::Info::Copyright); |
1571 |
|
connect(eArtists, &DLS::Info::Artists); |
1572 |
|
connect(eGenre, &DLS::Info::Genre); |
1573 |
|
connect(eKeywords, &DLS::Info::Keywords); |
1574 |
|
connect(eEngineer, &DLS::Info::Engineer); |
1575 |
|
connect(eTechnician, &DLS::Info::Technician); |
1576 |
|
connect(eSoftware, &DLS::Info::Software); |
1577 |
|
connect(eMedium, &DLS::Info::Medium); |
1578 |
|
connect(eSource, &DLS::Info::Source); |
1579 |
|
connect(eSourceForm, &DLS::Info::SourceForm); |
1580 |
|
connect(eCommissioned, &DLS::Info::Commissioned); |
1581 |
|
connect(eSubject, &DLS::Info::Subject); |
1582 |
|
|
1583 |
|
table.add(eFileFormat); |
1584 |
|
table.add(eName); |
1585 |
|
table.add(eCreationDate); |
1586 |
|
table.add(eComments); |
1587 |
|
table.add(eProduct); |
1588 |
|
table.add(eCopyright); |
1589 |
|
table.add(eArtists); |
1590 |
|
table.add(eGenre); |
1591 |
|
table.add(eKeywords); |
1592 |
|
table.add(eEngineer); |
1593 |
|
table.add(eTechnician); |
1594 |
|
table.add(eSoftware); |
1595 |
|
table.add(eMedium); |
1596 |
|
table.add(eSource); |
1597 |
|
table.add(eSourceForm); |
1598 |
|
table.add(eCommissioned); |
1599 |
|
table.add(eSubject); |
1600 |
|
|
1601 |
table.set_col_spacings(5); |
table.set_col_spacings(5); |
1602 |
const char* propLabels[] = { |
add(vbox); |
1603 |
"Name:", |
table.set_border_width(5); |
1604 |
"CreationDate:", |
vbox.add(table); |
1605 |
"Comments:", // TODO: multiline |
vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); |
1606 |
"Product:", |
buttonBox.set_layout(Gtk::BUTTONBOX_END); |
1607 |
"Copyright:", |
buttonBox.set_border_width(5); |
1608 |
"Artists:", |
buttonBox.show(); |
1609 |
"Genre:", |
buttonBox.pack_start(quitButton); |
1610 |
"Keywords:", |
quitButton.set_can_default(); |
1611 |
"Engineer:", |
quitButton.grab_focus(); |
1612 |
"Technician:", |
quitButton.signal_clicked().connect( |
1613 |
"Software:", // TODO: readonly |
sigc::mem_fun(*this, &PropDialog::hide)); |
1614 |
"Medium:", |
eFileFormat.signal_value_changed().connect( |
1615 |
"Source:", |
sigc::mem_fun(*this, &PropDialog::onFileFormatChanged)); |
|
"SourceForm:", |
|
|
"Commissioned:", |
|
|
"Subject:" |
|
|
}; |
|
|
for (int i = 0 ; i < sizeof(propLabels) / sizeof(char*) ; i++) { |
|
|
label[i].set_text(propLabels[i]); |
|
|
label[i].set_alignment(Gtk::ALIGN_LEFT); |
|
|
table.attach(label[i], 0, 1, i, i + 1, Gtk::FILL, Gtk::SHRINK); |
|
|
table.attach(entry[i], 1, 2, i, i + 1, Gtk::FILL | Gtk::EXPAND, |
|
|
Gtk::SHRINK); |
|
|
} |
|
1616 |
|
|
1617 |
add(table); |
quitButton.show(); |
1618 |
// add_button(Gtk::Stock::CANCEL, 0); |
vbox.show(); |
|
// add_button(Gtk::Stock::OK, 1); |
|
1619 |
show_all_children(); |
show_all_children(); |
1620 |
} |
} |
1621 |
|
|
1622 |
|
void PropDialog::set_file(gig::File* file) |
1623 |
|
{ |
1624 |
|
m_file = file; |
1625 |
|
|
1626 |
|
// update file format version combo box |
1627 |
|
const std::string sGiga = "Gigasampler/GigaStudio v"; |
1628 |
|
const int major = file->pVersion->major; |
1629 |
|
std::vector<std::string> txts; |
1630 |
|
std::vector<int> values; |
1631 |
|
txts.push_back(sGiga + "2"); values.push_back(2); |
1632 |
|
txts.push_back(sGiga + "3/v4"); values.push_back(3); |
1633 |
|
if (major != 2 && major != 3) { |
1634 |
|
txts.push_back(sGiga + ToString(major)); values.push_back(major); |
1635 |
|
} |
1636 |
|
std::vector<const char*> texts; |
1637 |
|
for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); |
1638 |
|
texts.push_back(NULL); values.push_back(0); |
1639 |
|
eFileFormat.set_choices(&texts[0], &values[0]); |
1640 |
|
eFileFormat.set_value(major); |
1641 |
|
} |
1642 |
|
|
1643 |
|
void PropDialog::onFileFormatChanged() { |
1644 |
|
const int major = eFileFormat.get_value(); |
1645 |
|
if (m_file) m_file->pVersion->major = major; |
1646 |
|
} |
1647 |
|
|
1648 |
void PropDialog::set_info(DLS::Info* info) |
void PropDialog::set_info(DLS::Info* info) |
1649 |
{ |
{ |
1650 |
entry[0].set_text(info->Name); |
update(info); |
1651 |
entry[1].set_text(info->CreationDate); |
} |
1652 |
entry[2].set_text(Glib::convert(info->Comments, "UTF-8", "ISO-8859-1")); |
|
1653 |
entry[3].set_text(info->Product); |
|
1654 |
entry[4].set_text(info->Copyright); |
void InstrumentProps::set_Name(const gig::String& name) |
1655 |
entry[5].set_text(info->Artists); |
{ |
1656 |
entry[6].set_text(info->Genre); |
m->pInfo->Name = name; |
1657 |
entry[7].set_text(info->Keywords); |
} |
1658 |
entry[8].set_text(info->Engineer); |
|
1659 |
entry[9].set_text(info->Technician); |
void InstrumentProps::update_name() |
|
entry[10].set_text(info->Software); |
|
|
entry[11].set_text(info->Medium); |
|
|
entry[12].set_text(info->Source); |
|
|
entry[13].set_text(info->SourceForm); |
|
|
entry[14].set_text(info->Commissioned); |
|
|
entry[15].set_text(info->Subject); |
|
|
} |
|
|
|
|
|
void InstrumentProps::add_prop(BoolEntry& boolentry) |
|
|
{ |
|
|
table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, |
|
|
Gtk::FILL, Gtk::SHRINK); |
|
|
rowno++; |
|
|
boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); |
|
|
} |
|
|
|
|
|
void InstrumentProps::add_prop(BoolEntryPlus6& boolentry) |
|
|
{ |
|
|
table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, |
|
|
Gtk::FILL, Gtk::SHRINK); |
|
|
rowno++; |
|
|
boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); |
|
|
} |
|
|
|
|
|
void InstrumentProps::add_prop(LabelWidget& prop) |
|
|
{ |
|
|
table.attach(prop.label, 0, 1, rowno, rowno + 1, |
|
|
Gtk::FILL, Gtk::SHRINK); |
|
|
table.attach(prop.widget, 1, 2, rowno, rowno + 1, |
|
|
Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); |
|
|
rowno++; |
|
|
prop.signal_changed_by_user().connect(instrument_changed.make_slot()); |
|
|
} |
|
|
|
|
|
InstrumentProps::InstrumentProps() |
|
|
: table(2,1), |
|
|
quitButton(Gtk::Stock::CLOSE), |
|
|
eName("Name"), |
|
|
eIsDrum("Is drum"), |
|
|
eMIDIBank("MIDI bank", 0, 16383), |
|
|
eMIDIProgram("MIDI program"), |
|
|
eAttenuation("Attenuation", 0, 96, 0, 1), |
|
|
eGainPlus6("Gain +6dB", eAttenuation, -6), |
|
|
eEffectSend("Effect send", 0, 65535), |
|
|
eFineTune("Fine tune", -8400, 8400), |
|
|
ePitchbendRange("Pitchbend range", 0, 12), |
|
|
ePianoReleaseMode("Piano release mode"), |
|
|
eDimensionKeyRangeLow("Dimension key range low"), |
|
|
eDimensionKeyRangeHigh("Dimension key range high") |
|
1660 |
{ |
{ |
1661 |
set_title("Instrument properties"); |
update_model++; |
1662 |
|
eName.set_value(m->pInfo->Name); |
1663 |
|
update_model--; |
1664 |
|
} |
1665 |
|
|
1666 |
|
void InstrumentProps::set_IsDrum(bool value) |
1667 |
|
{ |
1668 |
|
m->IsDrum = value; |
1669 |
|
} |
1670 |
|
|
1671 |
|
void InstrumentProps::set_MIDIBank(uint16_t value) |
1672 |
|
{ |
1673 |
|
m->MIDIBank = value; |
1674 |
|
} |
1675 |
|
|
1676 |
|
void InstrumentProps::set_MIDIProgram(uint32_t value) |
1677 |
|
{ |
1678 |
|
m->MIDIProgram = value; |
1679 |
|
} |
1680 |
|
|
1681 |
|
InstrumentProps::InstrumentProps() : |
1682 |
|
quitButton(_("_Close"), true), |
1683 |
|
table(2,1), |
1684 |
|
eName(_("Name")), |
1685 |
|
eIsDrum(_("Is drum")), |
1686 |
|
eMIDIBank(_("MIDI bank"), 0, 16383), |
1687 |
|
eMIDIProgram(_("MIDI program")), |
1688 |
|
eAttenuation(_("Attenuation"), 0, 96, 0, 1), |
1689 |
|
eGainPlus6(_("Gain +6dB"), eAttenuation, -6), |
1690 |
|
eEffectSend(_("Effect send"), 0, 65535), |
1691 |
|
eFineTune(_("Fine tune"), -8400, 8400), |
1692 |
|
ePitchbendRange(_("Pitchbend range"), 0, 12), |
1693 |
|
ePianoReleaseMode(_("Piano release mode")), |
1694 |
|
eDimensionKeyRangeLow(_("Keyswitching range low")), |
1695 |
|
eDimensionKeyRangeHigh(_("Keyswitching range high")) |
1696 |
|
{ |
1697 |
|
set_title(_("Instrument Properties")); |
1698 |
|
|
1699 |
|
eDimensionKeyRangeLow.set_tip( |
1700 |
|
_("start of the keyboard area which should switch the " |
1701 |
|
"\"keyswitching\" dimension") |
1702 |
|
); |
1703 |
|
eDimensionKeyRangeHigh.set_tip( |
1704 |
|
_("end of the keyboard area which should switch the " |
1705 |
|
"\"keyswitching\" dimension") |
1706 |
|
); |
1707 |
|
|
1708 |
|
connect(eName, &InstrumentProps::set_Name); |
1709 |
|
connect(eIsDrum, &InstrumentProps::set_IsDrum); |
1710 |
|
connect(eMIDIBank, &InstrumentProps::set_MIDIBank); |
1711 |
|
connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); |
1712 |
|
connect(eAttenuation, &gig::Instrument::Attenuation); |
1713 |
|
connect(eGainPlus6, &gig::Instrument::Attenuation); |
1714 |
|
connect(eEffectSend, &gig::Instrument::EffectSend); |
1715 |
|
connect(eFineTune, &gig::Instrument::FineTune); |
1716 |
|
connect(ePitchbendRange, &gig::Instrument::PitchbendRange); |
1717 |
|
connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode); |
1718 |
|
connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, |
1719 |
|
&gig::Instrument::DimensionKeyRange); |
1720 |
|
|
1721 |
|
eName.signal_value_changed().connect(sig_name_changed.make_slot()); |
1722 |
|
|
|
rowno = 0; |
|
1723 |
table.set_col_spacings(5); |
table.set_col_spacings(5); |
1724 |
|
|
1725 |
add_prop(eName); |
table.add(eName); |
1726 |
add_prop(eIsDrum); |
table.add(eIsDrum); |
1727 |
add_prop(eMIDIBank); |
table.add(eMIDIBank); |
1728 |
add_prop(eMIDIProgram); |
table.add(eMIDIProgram); |
1729 |
add_prop(eAttenuation); |
table.add(eAttenuation); |
1730 |
add_prop(eGainPlus6); |
table.add(eGainPlus6); |
1731 |
add_prop(eEffectSend); |
table.add(eEffectSend); |
1732 |
add_prop(eFineTune); |
table.add(eFineTune); |
1733 |
add_prop(ePitchbendRange); |
table.add(ePitchbendRange); |
1734 |
add_prop(ePianoReleaseMode); |
table.add(ePianoReleaseMode); |
1735 |
add_prop(eDimensionKeyRangeLow); |
table.add(eDimensionKeyRangeLow); |
1736 |
add_prop(eDimensionKeyRangeHigh); |
table.add(eDimensionKeyRangeHigh); |
|
|
|
|
eDimensionKeyRangeLow.signal_changed_by_user().connect( |
|
|
sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed)); |
|
|
eDimensionKeyRangeHigh.signal_changed_by_user().connect( |
|
|
sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed)); |
|
1737 |
|
|
1738 |
add(vbox); |
add(vbox); |
1739 |
table.set_border_width(5); |
table.set_border_width(5); |
1744 |
buttonBox.set_border_width(5); |
buttonBox.set_border_width(5); |
1745 |
buttonBox.show(); |
buttonBox.show(); |
1746 |
buttonBox.pack_start(quitButton); |
buttonBox.pack_start(quitButton); |
1747 |
quitButton.set_flags(Gtk::CAN_DEFAULT); |
quitButton.set_can_default(); |
1748 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
1749 |
|
|
1750 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
1757 |
|
|
1758 |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
1759 |
{ |
{ |
1760 |
eName.set_ptr(&instrument->pInfo->Name); |
update(instrument); |
|
eIsDrum.set_ptr(&instrument->IsDrum); |
|
|
eMIDIBank.set_ptr(&instrument->MIDIBank); |
|
|
eMIDIProgram.set_ptr(&instrument->MIDIProgram); |
|
|
eAttenuation.set_ptr(&instrument->Attenuation); |
|
|
eGainPlus6.set_ptr(&instrument->Attenuation); |
|
|
eEffectSend.set_ptr(&instrument->EffectSend); |
|
|
eFineTune.set_ptr(&instrument->FineTune); |
|
|
ePitchbendRange.set_ptr(&instrument->PitchbendRange); |
|
|
ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode); |
|
|
eDimensionKeyRangeLow.set_ptr(0); |
|
|
eDimensionKeyRangeHigh.set_ptr(0); |
|
|
eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low); |
|
|
eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high); |
|
|
} |
|
1761 |
|
|
1762 |
void InstrumentProps::key_range_low_changed() |
update_model++; |
1763 |
{ |
eName.set_value(instrument->pInfo->Name); |
1764 |
double l = eDimensionKeyRangeLow.get_value(); |
eIsDrum.set_value(instrument->IsDrum); |
1765 |
double h = eDimensionKeyRangeHigh.get_value(); |
eMIDIBank.set_value(instrument->MIDIBank); |
1766 |
if (h < l) eDimensionKeyRangeHigh.set_value(l); |
eMIDIProgram.set_value(instrument->MIDIProgram); |
1767 |
|
update_model--; |
1768 |
} |
} |
1769 |
|
|
|
void InstrumentProps::key_range_high_changed() |
|
|
{ |
|
|
double l = eDimensionKeyRangeLow.get_value(); |
|
|
double h = eDimensionKeyRangeHigh.get_value(); |
|
|
if (h < l) eDimensionKeyRangeLow.set_value(h); |
|
|
} |
|
|
|
|
|
sigc::signal<void> InstrumentProps::signal_instrument_changed() |
|
|
{ |
|
|
return instrument_changed; |
|
|
} |
|
1770 |
|
|
1771 |
void MainWindow::file_changed() |
void MainWindow::file_changed() |
1772 |
{ |
{ |
1776 |
} |
} |
1777 |
} |
} |
1778 |
|
|
1779 |
void MainWindow::load_gig(gig::File* gig, const char* filename) |
void MainWindow::updateSampleRefCountMap(gig::File* gig) { |
1780 |
|
sample_ref_count.clear(); |
1781 |
|
|
1782 |
|
if (!gig) return; |
1783 |
|
|
1784 |
|
for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; |
1785 |
|
instrument = gig->GetNextInstrument()) |
1786 |
|
{ |
1787 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
1788 |
|
rgn = instrument->GetNextRegion()) |
1789 |
|
{ |
1790 |
|
for (int i = 0; i < 256; ++i) { |
1791 |
|
if (!rgn->pDimensionRegions[i]) continue; |
1792 |
|
if (rgn->pDimensionRegions[i]->pSample) { |
1793 |
|
sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; |
1794 |
|
} |
1795 |
|
} |
1796 |
|
} |
1797 |
|
} |
1798 |
|
} |
1799 |
|
|
1800 |
|
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1801 |
{ |
{ |
1802 |
file = 0; |
file = 0; |
1803 |
|
set_file_is_shared(isSharedInstrument); |
1804 |
|
|
1805 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = |
1806 |
|
(filename && strlen(filename) > 0) ? |
1807 |
|
filename : (!gig->GetFileName().empty()) ? |
1808 |
|
gig->GetFileName() : _("Unsaved Gig File"); |
1809 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1810 |
file_has_name = filename; |
file_has_name = filename; |
1811 |
file_is_changed = false; |
file_is_changed = false; |
1812 |
|
|
1813 |
|
propDialog.set_file(gig); |
1814 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1815 |
|
|
1816 |
Gtk::MenuItem* instrument_menu = |
instrument_name_connection.block(); |
1817 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
int index = 0; |
|
|
|
|
int instrument_index = 0; |
|
|
Gtk::RadioMenuItem::Group instrument_group; |
|
1818 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
1819 |
instrument = gig->GetNextInstrument()) { |
instrument = gig->GetNextInstrument(), ++index) { |
1820 |
|
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1821 |
|
|
1822 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
1823 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1824 |
row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
row[m_Columns.m_col_nr] = index; |
1825 |
|
row[m_Columns.m_col_name] = name; |
1826 |
row[m_Columns.m_col_instr] = instrument; |
row[m_Columns.m_col_instr] = instrument; |
1827 |
// create a menu item for this instrument |
|
1828 |
Gtk::RadioMenuItem* item = |
add_instrument_to_menu(name); |
|
new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str()); |
|
|
instrument_menu->get_submenu()->append(*item); |
|
|
item->signal_activate().connect( |
|
|
sigc::bind( |
|
|
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
|
|
instrument_index |
|
|
) |
|
|
); |
|
|
instrument_index++; |
|
1829 |
} |
} |
1830 |
instrument_menu->show(); |
instrument_name_connection.unblock(); |
1831 |
instrument_menu->get_submenu()->show_all_children(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); |
1832 |
|
|
1833 |
|
updateSampleRefCountMap(gig); |
1834 |
|
|
1835 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1836 |
if (group->Name != "") { |
if (group->Name != "") { |
1837 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1838 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1839 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
1840 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_group] = group; |
1841 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1842 |
for (gig::Sample* sample = group->GetFirstSample(); |
for (gig::Sample* sample = group->GetFirstSample(); |
1844 |
Gtk::TreeModel::iterator iterSample = |
Gtk::TreeModel::iterator iterSample = |
1845 |
m_refSamplesTreeModel->append(rowGroup.children()); |
m_refSamplesTreeModel->append(rowGroup.children()); |
1846 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
1847 |
rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); |
rowSample[m_SamplesModel.m_col_name] = |
1848 |
|
gig_to_utf8(sample->pInfo->Name); |
1849 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1850 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1851 |
|
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1852 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1853 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
1854 |
} |
} |
1855 |
} |
} |
1856 |
} |
} |
1857 |
|
|
1858 |
|
for (int i = 0; gig->GetScriptGroup(i); ++i) { |
1859 |
|
gig::ScriptGroup* group = gig->GetScriptGroup(i); |
1860 |
|
|
1861 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1862 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1863 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1864 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1865 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1866 |
|
for (int s = 0; group->GetScript(s); ++s) { |
1867 |
|
gig::Script* script = group->GetScript(s); |
1868 |
|
|
1869 |
|
Gtk::TreeModel::iterator iterScript = |
1870 |
|
m_refScriptsTreeModel->append(rowGroup.children()); |
1871 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1872 |
|
rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); |
1873 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1874 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1875 |
|
} |
1876 |
|
} |
1877 |
|
// unfold all sample groups & script groups by default |
1878 |
|
m_TreeViewSamples.expand_all(); |
1879 |
|
m_TreeViewScripts.expand_all(); |
1880 |
|
|
1881 |
file = gig; |
file = gig; |
1882 |
|
|
1883 |
// select the first instrument |
// select the first instrument |
1884 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
1885 |
tree_sel_ref->select(Gtk::TreePath("0")); |
|
1886 |
|
instr_props_set_instrument(); |
1887 |
|
gig::Instrument* instrument = get_instrument(); |
1888 |
|
if (instrument) { |
1889 |
|
midiRules.set_instrument(instrument); |
1890 |
|
} |
1891 |
|
} |
1892 |
|
|
1893 |
|
bool MainWindow::instr_props_set_instrument() |
1894 |
|
{ |
1895 |
|
instrumentProps.signal_name_changed().clear(); |
1896 |
|
|
1897 |
|
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
1898 |
|
if (rows.empty()) { |
1899 |
|
instrumentProps.hide(); |
1900 |
|
return false; |
1901 |
|
} |
1902 |
|
Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); |
1903 |
|
if (it) { |
1904 |
|
Gtk::TreeModel::Row row = *it; |
1905 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1906 |
|
|
1907 |
|
instrumentProps.set_instrument(instrument); |
1908 |
|
|
1909 |
|
// make sure instrument tree is updated when user changes the |
1910 |
|
// instrument name in instrument properties window |
1911 |
|
instrumentProps.signal_name_changed().connect( |
1912 |
|
sigc::bind( |
1913 |
|
sigc::mem_fun(*this, |
1914 |
|
&MainWindow::instr_name_changed_by_instr_props), |
1915 |
|
it)); |
1916 |
|
} else { |
1917 |
|
instrumentProps.hide(); |
1918 |
|
} |
1919 |
|
return it; |
1920 |
} |
} |
1921 |
|
|
1922 |
void MainWindow::show_instr_props() |
void MainWindow::show_instr_props() |
1923 |
{ |
{ |
1924 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
if (instr_props_set_instrument()) { |
1925 |
Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); |
instrumentProps.show(); |
1926 |
if (it) |
instrumentProps.deiconify(); |
1927 |
|
} |
1928 |
|
} |
1929 |
|
|
1930 |
|
void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it) |
1931 |
|
{ |
1932 |
|
Gtk::TreeModel::Row row = *it; |
1933 |
|
Glib::ustring name = row[m_Columns.m_col_name]; |
1934 |
|
|
1935 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1936 |
|
Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name)); |
1937 |
|
if (gigname != name) { |
1938 |
|
row[m_Columns.m_col_name] = gigname; |
1939 |
|
} |
1940 |
|
} |
1941 |
|
|
1942 |
|
void MainWindow::show_midi_rules() |
1943 |
|
{ |
1944 |
|
if (gig::Instrument* instrument = get_instrument()) |
1945 |
{ |
{ |
1946 |
Gtk::TreeModel::Row row = *it; |
midiRules.set_instrument(instrument); |
1947 |
if (row[m_Columns.m_col_instr]) |
midiRules.show(); |
1948 |
{ |
midiRules.deiconify(); |
|
instrumentProps.set_instrument(row[m_Columns.m_col_instr]); |
|
|
instrumentProps.show(); |
|
|
instrumentProps.deiconify(); |
|
|
} |
|
1949 |
} |
} |
1950 |
} |
} |
1951 |
|
|
1952 |
|
void MainWindow::show_script_slots() { |
1953 |
|
if (!file) return; |
1954 |
|
// get selected instrument |
1955 |
|
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
1956 |
|
if (rows.empty()) return; |
1957 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); |
1958 |
|
if (!it) return; |
1959 |
|
Gtk::TreeModel::Row row = *it; |
1960 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1961 |
|
if (!instrument) return; |
1962 |
|
|
1963 |
|
ScriptSlots* window = new ScriptSlots; |
1964 |
|
window->setInstrument(instrument); |
1965 |
|
//window->reparent(*this); |
1966 |
|
window->show(); |
1967 |
|
} |
1968 |
|
|
1969 |
|
void MainWindow::on_action_refresh_all() { |
1970 |
|
__refreshEntireGUI(); |
1971 |
|
} |
1972 |
|
|
1973 |
|
void MainWindow::on_action_view_status_bar() { |
1974 |
|
Gtk::CheckMenuItem* item = |
1975 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1976 |
|
if (!item) { |
1977 |
|
std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n"; |
1978 |
|
return; |
1979 |
|
} |
1980 |
|
if (item->get_active()) m_StatusBar.show(); |
1981 |
|
else m_StatusBar.hide(); |
1982 |
|
} |
1983 |
|
|
1984 |
|
void MainWindow::on_auto_restore_win_dim() { |
1985 |
|
Gtk::CheckMenuItem* item = |
1986 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim")); |
1987 |
|
if (!item) { |
1988 |
|
std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n"; |
1989 |
|
return; |
1990 |
|
} |
1991 |
|
Settings::singleton()->autoRestoreWindowDimension = item->get_active(); |
1992 |
|
} |
1993 |
|
|
1994 |
|
void MainWindow::on_save_with_temporary_file() { |
1995 |
|
Gtk::CheckMenuItem* item = |
1996 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile")); |
1997 |
|
if (!item) { |
1998 |
|
std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n"; |
1999 |
|
return; |
2000 |
|
} |
2001 |
|
Settings::singleton()->saveWithTemporaryFile = item->get_active(); |
2002 |
|
} |
2003 |
|
|
2004 |
|
bool MainWindow::is_copy_samples_unity_note_enabled() const { |
2005 |
|
Gtk::CheckMenuItem* item = |
2006 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
2007 |
|
if (!item) { |
2008 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n"; |
2009 |
|
return true; |
2010 |
|
} |
2011 |
|
return item->get_active(); |
2012 |
|
} |
2013 |
|
|
2014 |
|
bool MainWindow::is_copy_samples_fine_tune_enabled() const { |
2015 |
|
Gtk::CheckMenuItem* item = |
2016 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
2017 |
|
if (!item) { |
2018 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n"; |
2019 |
|
return true; |
2020 |
|
} |
2021 |
|
return item->get_active(); |
2022 |
|
} |
2023 |
|
|
2024 |
|
bool MainWindow::is_copy_samples_loop_enabled() const { |
2025 |
|
Gtk::CheckMenuItem* item = |
2026 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
2027 |
|
if (!item) { |
2028 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n"; |
2029 |
|
return true; |
2030 |
|
} |
2031 |
|
return item->get_active(); |
2032 |
|
} |
2033 |
|
|
2034 |
void MainWindow::on_button_release(GdkEventButton* button) |
void MainWindow::on_button_release(GdkEventButton* button) |
2035 |
{ |
{ |
2036 |
if (button->type == GDK_2BUTTON_PRESS) { |
if (button->type == GDK_2BUTTON_PRESS) { |
2037 |
show_instr_props(); |
show_instr_props(); |
2038 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2039 |
|
// gig v2 files have no midi rules |
2040 |
|
const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); |
2041 |
|
static_cast<Gtk::MenuItem*>( |
2042 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( |
2043 |
|
bEnabled |
2044 |
|
); |
2045 |
|
static_cast<Gtk::MenuItem*>( |
2046 |
|
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
2047 |
|
bEnabled |
2048 |
|
); |
2049 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
2050 |
} |
} |
2051 |
} |
} |
2052 |
|
|
2053 |
void MainWindow::on_instrument_selection_change(int index) { |
void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) { |
2054 |
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
if (item->get_active()) { |
2055 |
|
const std::vector<Gtk::Widget*> children = |
2056 |
|
instrument_menu->get_children(); |
2057 |
|
std::vector<Gtk::Widget*>::const_iterator it = |
2058 |
|
find(children.begin(), children.end(), item); |
2059 |
|
if (it != children.end()) { |
2060 |
|
int index = it - children.begin(); |
2061 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index))); |
2062 |
|
|
2063 |
|
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
2064 |
|
} |
2065 |
|
} |
2066 |
|
} |
2067 |
|
|
2068 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
2069 |
|
if (!instrument) return; |
2070 |
|
|
2071 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
2072 |
|
for (int i = 0; i < model->children().size(); ++i) { |
2073 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
2074 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
2075 |
|
// select and show the respective instrument in the list view |
2076 |
|
show_intruments_tab(); |
2077 |
|
m_TreeView.get_selection()->unselect_all(); |
2078 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
2079 |
|
std::vector<Gtk::TreeModel::Path> rows = |
2080 |
|
m_TreeView.get_selection()->get_selected_rows(); |
2081 |
|
if (!rows.empty()) |
2082 |
|
m_TreeView.scroll_to_row(rows[0]); |
2083 |
|
on_sel_change(); // the regular instrument selection change callback |
2084 |
|
} |
2085 |
|
} |
2086 |
|
} |
2087 |
|
|
2088 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
2089 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
2090 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
2091 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
2092 |
|
|
2093 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
2094 |
|
for (int i = 0; i < model->children().size(); ++i) { |
2095 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
2096 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
2097 |
|
// select and show the respective instrument in the list view |
2098 |
|
show_intruments_tab(); |
2099 |
|
m_TreeView.get_selection()->unselect_all(); |
2100 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
2101 |
|
std::vector<Gtk::TreeModel::Path> rows = |
2102 |
|
m_TreeView.get_selection()->get_selected_rows(); |
2103 |
|
if (!rows.empty()) |
2104 |
|
m_TreeView.scroll_to_row(rows[0]); |
2105 |
|
on_sel_change(); // the regular instrument selection change callback |
2106 |
|
|
2107 |
|
// select respective region in the region selector |
2108 |
|
m_RegionChooser.set_region(pRegion); |
2109 |
|
|
2110 |
|
// select and show the respective dimension region in the editor |
2111 |
|
//update_dimregs(); |
2112 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
2113 |
|
//dimreg_edit.set_dim_region(dimRgn); |
2114 |
|
|
2115 |
|
return true; |
2116 |
|
} |
2117 |
|
} |
2118 |
|
|
2119 |
|
return false; |
2120 |
|
} |
2121 |
|
|
2122 |
|
void MainWindow::select_sample(gig::Sample* sample) { |
2123 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2124 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2125 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2126 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2127 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2128 |
|
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
2129 |
|
show_samples_tab(); |
2130 |
|
m_TreeViewSamples.get_selection()->unselect_all(); |
2131 |
|
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
2132 |
|
std::vector<Gtk::TreeModel::Path> rows = |
2133 |
|
m_TreeViewSamples.get_selection()->get_selected_rows(); |
2134 |
|
if (rows.empty()) return; |
2135 |
|
m_TreeViewSamples.scroll_to_row(rows[0]); |
2136 |
|
return; |
2137 |
|
} |
2138 |
|
} |
2139 |
|
} |
2140 |
} |
} |
2141 |
|
|
2142 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
2143 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2144 |
|
// by default if Ctrl keys is pressed down, then a mouse right-click |
2145 |
|
// does not select the respective row, so we must assure this |
2146 |
|
// programmatically ... |
2147 |
|
/*{ |
2148 |
|
Gtk::TreeModel::Path path; |
2149 |
|
Gtk::TreeViewColumn* pColumn = NULL; |
2150 |
|
int cellX, cellY; |
2151 |
|
bool bSuccess = m_TreeViewSamples.get_path_at_pos( |
2152 |
|
(int)button->x, (int)button->y, |
2153 |
|
path, pColumn, cellX, cellY |
2154 |
|
); |
2155 |
|
if (bSuccess) { |
2156 |
|
if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) { |
2157 |
|
printf("not selected !!!\n"); |
2158 |
|
m_TreeViewSamples.get_selection()->select(path); |
2159 |
|
} |
2160 |
|
} |
2161 |
|
}*/ |
2162 |
|
|
2163 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
2164 |
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu")); |
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu")); |
2165 |
// update enabled/disabled state of sample popup items |
// update enabled/disabled state of sample popup items |
2166 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2167 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2168 |
bool group_selected = false; |
const int n = rows.size(); |
2169 |
bool sample_selected = false; |
int nGroups = 0; |
2170 |
if (it) { |
int nSamples = 0; |
2171 |
|
for (int r = 0; r < n; ++r) { |
2172 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]); |
2173 |
|
if (!it) continue; |
2174 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2175 |
group_selected = row[m_SamplesModel.m_col_group]; |
if (row[m_SamplesModel.m_col_group]) nGroups++; |
2176 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
if (row[m_SamplesModel.m_col_sample]) nSamples++; |
2177 |
} |
} |
2178 |
|
|
2179 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
2180 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n == 1); |
2181 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
2182 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n); |
2183 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
2184 |
set_sensitive(file); |
set_sensitive(file); |
2185 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
2186 |
|
set_sensitive(nSamples == 1); |
2187 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
2188 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n); |
2189 |
// show sample popup |
// show sample popup |
2190 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
2191 |
|
|
2192 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
2193 |
|
set_sensitive(n == 1); |
2194 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
2195 |
|
set_sensitive(n); |
2196 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
2197 |
|
set_sensitive(file); |
2198 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
2199 |
|
set_sensitive(nSamples == 1); |
2200 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
2201 |
|
set_sensitive(n); |
2202 |
} |
} |
2203 |
} |
} |
2204 |
|
|
2205 |
void MainWindow::on_action_add_instrument() { |
void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { |
2206 |
static int __instrument_indexer = 0; |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2207 |
if (!file) return; |
Gtk::Menu* script_popup = |
2208 |
gig::Instrument* instrument = file->AddInstrument(); |
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu")); |
2209 |
__instrument_indexer++; |
// update enabled/disabled state of sample popup items |
2210 |
instrument->pInfo->Name = |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2211 |
"Unnamed Instrument " + ToString(__instrument_indexer); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
2212 |
|
bool group_selected = false; |
2213 |
|
bool script_selected = false; |
2214 |
|
if (it) { |
2215 |
|
Gtk::TreeModel::Row row = *it; |
2216 |
|
group_selected = row[m_ScriptsModel.m_col_group]; |
2217 |
|
script_selected = row[m_ScriptsModel.m_col_script]; |
2218 |
|
} |
2219 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> |
2220 |
|
set_sensitive(group_selected || script_selected); |
2221 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> |
2222 |
|
set_sensitive(file); |
2223 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> |
2224 |
|
set_sensitive(script_selected); |
2225 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> |
2226 |
|
set_sensitive(group_selected || script_selected); |
2227 |
|
// show sample popup |
2228 |
|
script_popup->popup(button->button, button->time); |
2229 |
|
|
2230 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> |
2231 |
|
set_sensitive(group_selected || script_selected); |
2232 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> |
2233 |
|
set_sensitive(file); |
2234 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> |
2235 |
|
set_sensitive(script_selected); |
2236 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> |
2237 |
|
set_sensitive(group_selected || script_selected); |
2238 |
|
} |
2239 |
|
} |
2240 |
|
|
2241 |
|
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
2242 |
|
const Glib::ustring& name, int position) { |
2243 |
|
|
2244 |
|
Gtk::RadioMenuItem::Group instrument_group; |
2245 |
|
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
2246 |
|
if (!children.empty()) { |
2247 |
|
instrument_group = |
2248 |
|
static_cast<Gtk::RadioMenuItem*>(children[0])->get_group(); |
2249 |
|
} |
2250 |
|
Gtk::RadioMenuItem* item = |
2251 |
|
new Gtk::RadioMenuItem(instrument_group, name); |
2252 |
|
if (position < 0) { |
2253 |
|
instrument_menu->append(*item); |
2254 |
|
} else { |
2255 |
|
instrument_menu->insert(*item, position); |
2256 |
|
} |
2257 |
|
item->show(); |
2258 |
|
item->signal_activate().connect( |
2259 |
|
sigc::bind( |
2260 |
|
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
2261 |
|
item)); |
2262 |
|
return item; |
2263 |
|
} |
2264 |
|
|
2265 |
|
void MainWindow::remove_instrument_from_menu(int index) { |
2266 |
|
const std::vector<Gtk::Widget*> children = |
2267 |
|
instrument_menu->get_children(); |
2268 |
|
Gtk::Widget* child = children[index]; |
2269 |
|
instrument_menu->remove(*child); |
2270 |
|
delete child; |
2271 |
|
} |
2272 |
|
|
2273 |
|
void MainWindow::add_instrument(gig::Instrument* instrument) { |
2274 |
|
const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
2275 |
|
|
2276 |
// update instrument tree view |
// update instrument tree view |
2277 |
|
instrument_name_connection.block(); |
2278 |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
2279 |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
2280 |
rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1; |
2281 |
|
rowInstr[m_Columns.m_col_name] = name; |
2282 |
rowInstr[m_Columns.m_col_instr] = instrument; |
rowInstr[m_Columns.m_col_instr] = instrument; |
2283 |
|
instrument_name_connection.unblock(); |
2284 |
|
|
2285 |
|
add_instrument_to_menu(name); |
2286 |
|
|
2287 |
|
m_TreeView.get_selection()->select(iterInstr); |
2288 |
|
|
2289 |
file_changed(); |
file_changed(); |
2290 |
} |
} |
2291 |
|
|
2292 |
|
void MainWindow::on_action_add_instrument() { |
2293 |
|
static int __instrument_indexer = 0; |
2294 |
|
if (!file) return; |
2295 |
|
gig::Instrument* instrument = file->AddInstrument(); |
2296 |
|
__instrument_indexer++; |
2297 |
|
instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") + |
2298 |
|
ToString(__instrument_indexer)); |
2299 |
|
|
2300 |
|
add_instrument(instrument); |
2301 |
|
} |
2302 |
|
|
2303 |
|
void MainWindow::on_action_duplicate_instrument() { |
2304 |
|
if (!file) return; |
2305 |
|
|
2306 |
|
// retrieve the currently selected instrument |
2307 |
|
// (being the original instrument to be duplicated) |
2308 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2309 |
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2310 |
|
for (int r = 0; r < rows.size(); ++r) { |
2311 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]); |
2312 |
|
if (it) { |
2313 |
|
Gtk::TreeModel::Row row = *it; |
2314 |
|
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
2315 |
|
if (instrOrig) { |
2316 |
|
// duplicate the orginal instrument |
2317 |
|
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
2318 |
|
instrNew->pInfo->Name = |
2319 |
|
instrOrig->pInfo->Name + |
2320 |
|
gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); |
2321 |
|
|
2322 |
|
add_instrument(instrNew); |
2323 |
|
} |
2324 |
|
} |
2325 |
|
} |
2326 |
|
} |
2327 |
|
|
2328 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
2329 |
if (!file) return; |
if (!file) return; |
2330 |
|
if (file_is_shared) { |
2331 |
|
Gtk::MessageDialog msg( |
2332 |
|
*this, |
2333 |
|
_("You cannot delete an instrument from this file, since it's " |
2334 |
|
"currently used by the sampler."), |
2335 |
|
false, Gtk::MESSAGE_INFO |
2336 |
|
); |
2337 |
|
msg.run(); |
2338 |
|
return; |
2339 |
|
} |
2340 |
|
|
2341 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2342 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2343 |
if (it) { |
for (int r = rows.size() - 1; r >= 0; --r) { |
2344 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]); |
2345 |
|
if (!it) continue; |
2346 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2347 |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
2348 |
try { |
try { |
2349 |
|
Gtk::TreePath path(it); |
2350 |
|
int index = path[0]; |
2351 |
|
|
2352 |
// remove instrument from the gig file |
// remove instrument from the gig file |
2353 |
if (instr) file->DeleteInstrument(instr); |
if (instr) file->DeleteInstrument(instr); |
|
// remove respective row from instruments tree view |
|
|
m_refTreeModel->erase(it); |
|
2354 |
file_changed(); |
file_changed(); |
2355 |
|
|
2356 |
|
remove_instrument_from_menu(index); |
2357 |
|
|
2358 |
|
// remove row from instruments tree view |
2359 |
|
m_refTreeModel->erase(it); |
2360 |
|
// update "Nr" column of all instrument rows |
2361 |
|
{ |
2362 |
|
int index = 0; |
2363 |
|
for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin(); |
2364 |
|
it != m_refTreeModel->children().end(); ++it, ++index) |
2365 |
|
{ |
2366 |
|
Gtk::TreeModel::Row row = *it; |
2367 |
|
row[m_Columns.m_col_nr] = index; |
2368 |
|
} |
2369 |
|
} |
2370 |
|
|
2371 |
|
#if GTKMM_MAJOR_VERSION < 3 |
2372 |
|
// select another instrument (in gtk3 this is done |
2373 |
|
// automatically) |
2374 |
|
if (!m_refTreeModel->children().empty()) { |
2375 |
|
if (index == m_refTreeModel->children().size()) { |
2376 |
|
index--; |
2377 |
|
} |
2378 |
|
m_TreeView.get_selection()->select( |
2379 |
|
Gtk::TreePath(ToString(index))); |
2380 |
|
} |
2381 |
|
#endif |
2382 |
|
instr_props_set_instrument(); |
2383 |
|
instr = get_instrument(); |
2384 |
|
if (instr) { |
2385 |
|
midiRules.set_instrument(instr); |
2386 |
|
} else { |
2387 |
|
midiRules.hide(); |
2388 |
|
} |
2389 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
2390 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2391 |
msg.run(); |
msg.run(); |
2396 |
void MainWindow::on_action_sample_properties() { |
void MainWindow::on_action_sample_properties() { |
2397 |
//TODO: show a dialog where the selected sample's properties can be edited |
//TODO: show a dialog where the selected sample's properties can be edited |
2398 |
Gtk::MessageDialog msg( |
Gtk::MessageDialog msg( |
2399 |
*this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO |
*this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO |
2400 |
); |
); |
2401 |
msg.run(); |
msg.run(); |
2402 |
} |
} |
2403 |
|
|
2404 |
|
void MainWindow::on_action_add_script_group() { |
2405 |
|
static int __script_indexer = 0; |
2406 |
|
if (!file) return; |
2407 |
|
gig::ScriptGroup* group = file->AddScriptGroup(); |
2408 |
|
group->Name = gig_from_utf8(_("Unnamed Group")); |
2409 |
|
if (__script_indexer) group->Name += " " + ToString(__script_indexer); |
2410 |
|
__script_indexer++; |
2411 |
|
// update sample tree view |
2412 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
2413 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
2414 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
2415 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
2416 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
2417 |
|
file_changed(); |
2418 |
|
} |
2419 |
|
|
2420 |
|
void MainWindow::on_action_add_script() { |
2421 |
|
if (!file) return; |
2422 |
|
// get selected group |
2423 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2424 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2425 |
|
if (!it) return; |
2426 |
|
Gtk::TreeModel::Row row = *it; |
2427 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2428 |
|
if (!group) { // not a group, but a script is selected (probably) |
2429 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2430 |
|
if (!script) return; |
2431 |
|
it = row.parent(); // resolve parent (that is the script's group) |
2432 |
|
if (!it) return; |
2433 |
|
row = *it; |
2434 |
|
group = row[m_ScriptsModel.m_col_group]; |
2435 |
|
if (!group) return; |
2436 |
|
} |
2437 |
|
|
2438 |
|
// add a new script to the .gig file |
2439 |
|
gig::Script* script = group->AddScript(); |
2440 |
|
Glib::ustring name = _("Unnamed Script"); |
2441 |
|
script->Name = gig_from_utf8(name); |
2442 |
|
|
2443 |
|
// add script to the tree view |
2444 |
|
Gtk::TreeModel::iterator iterScript = |
2445 |
|
m_refScriptsTreeModel->append(row.children()); |
2446 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
2447 |
|
rowScript[m_ScriptsModel.m_col_name] = name; |
2448 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
2449 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
2450 |
|
|
2451 |
|
// unfold group of new script item in treeview |
2452 |
|
Gtk::TreeModel::Path path(iterScript); |
2453 |
|
m_TreeViewScripts.expand_to_path(path); |
2454 |
|
} |
2455 |
|
|
2456 |
|
void MainWindow::on_action_edit_script() { |
2457 |
|
if (!file) return; |
2458 |
|
// get selected script |
2459 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2460 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2461 |
|
if (!it) return; |
2462 |
|
Gtk::TreeModel::Row row = *it; |
2463 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2464 |
|
if (!script) return; |
2465 |
|
|
2466 |
|
ScriptEditor* editor = new ScriptEditor; |
2467 |
|
editor->signal_script_to_be_changed.connect( |
2468 |
|
signal_script_to_be_changed.make_slot() |
2469 |
|
); |
2470 |
|
editor->signal_script_changed.connect( |
2471 |
|
signal_script_changed.make_slot() |
2472 |
|
); |
2473 |
|
editor->setScript(script); |
2474 |
|
//editor->reparent(*this); |
2475 |
|
editor->show(); |
2476 |
|
} |
2477 |
|
|
2478 |
|
void MainWindow::on_action_remove_script() { |
2479 |
|
if (!file) return; |
2480 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2481 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2482 |
|
if (it) { |
2483 |
|
Gtk::TreeModel::Row row = *it; |
2484 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2485 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2486 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2487 |
|
try { |
2488 |
|
// remove script group or script from the gig file |
2489 |
|
if (group) { |
2490 |
|
// notify everybody that we're going to remove these samples |
2491 |
|
//TODO: scripts_to_be_removed_signal.emit(members); |
2492 |
|
// delete the group in the .gig file including the |
2493 |
|
// samples that belong to the group |
2494 |
|
file->DeleteScriptGroup(group); |
2495 |
|
// notify that we're done with removal |
2496 |
|
//TODO: scripts_removed_signal.emit(); |
2497 |
|
file_changed(); |
2498 |
|
} else if (script) { |
2499 |
|
// notify everybody that we're going to remove this sample |
2500 |
|
//TODO: std::list<gig::Script*> lscripts; |
2501 |
|
//TODO: lscripts.push_back(script); |
2502 |
|
//TODO: scripts_to_be_removed_signal.emit(lscripts); |
2503 |
|
// remove sample from the .gig file |
2504 |
|
script->GetGroup()->DeleteScript(script); |
2505 |
|
// notify that we're done with removal |
2506 |
|
//TODO: scripts_removed_signal.emit(); |
2507 |
|
dimreg_changed(); |
2508 |
|
file_changed(); |
2509 |
|
} |
2510 |
|
// remove respective row(s) from samples tree view |
2511 |
|
m_refScriptsTreeModel->erase(it); |
2512 |
|
} catch (RIFF::Exception e) { |
2513 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
2514 |
|
//TODO: scripts_removed_signal.emit(); |
2515 |
|
// show error message |
2516 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2517 |
|
msg.run(); |
2518 |
|
} |
2519 |
|
} |
2520 |
|
} |
2521 |
|
|
2522 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |
2523 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
2524 |
if (!file) return; |
if (!file) return; |
2525 |
gig::Group* group = file->AddGroup(); |
gig::Group* group = file->AddGroup(); |
2526 |
group->Name = "Unnamed Group"; |
group->Name = gig_from_utf8(_("Unnamed Group")); |
2527 |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
2528 |
__sample_indexer++; |
__sample_indexer++; |
2529 |
// update sample tree view |
// update sample tree view |
2530 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
2531 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
2532 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
2533 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
2534 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_group] = group; |
2535 |
file_changed(); |
file_changed(); |
2536 |
} |
} |
2537 |
|
|
2538 |
|
void MainWindow::on_action_replace_sample() { |
2539 |
|
add_or_replace_sample(true); |
2540 |
|
} |
2541 |
|
|
2542 |
void MainWindow::on_action_add_sample() { |
void MainWindow::on_action_add_sample() { |
2543 |
|
add_or_replace_sample(false); |
2544 |
|
} |
2545 |
|
|
2546 |
|
void MainWindow::add_or_replace_sample(bool replace) { |
2547 |
if (!file) return; |
if (!file) return; |
2548 |
// get selected group |
|
2549 |
|
// get selected group (and probably selected sample) |
2550 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2551 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2552 |
|
if (rows.empty()) return; |
2553 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); |
2554 |
if (!it) return; |
if (!it) return; |
2555 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2556 |
|
gig::Sample* sample = NULL; |
2557 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2558 |
if (!group) { // not a group, but a sample is selected (probably) |
if (!group) { // not a group, but a sample is selected (probably) |
2559 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
if (replace) sample = row[m_SamplesModel.m_col_sample]; |
2560 |
if (!sample) return; |
if (!row[m_SamplesModel.m_col_sample]) return; |
2561 |
it = row.parent(); // resolve parent (that is the sample's group) |
it = row.parent(); // resolve parent (that is the sample's group) |
2562 |
if (!it) return; |
if (!it) return; |
2563 |
row = *it; |
if (!replace) row = *it; |
2564 |
group = row[m_SamplesModel.m_col_group]; |
group = (*it)[m_SamplesModel.m_col_group]; |
2565 |
if (!group) return; |
if (!group) return; |
2566 |
} |
} |
2567 |
|
if (replace && !sample) return; |
2568 |
|
|
2569 |
// show 'browse for file' dialog |
// show 'browse for file' dialog |
2570 |
Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)")); |
Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); |
2571 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
2572 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
2573 |
dialog.set_select_multiple(true); |
dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample |
2574 |
Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile |
|
2575 |
|
// matches all file types supported by libsndfile |
2576 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
2577 |
|
Gtk::FileFilter soundfilter; |
2578 |
|
#else |
2579 |
|
Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create(); |
2580 |
|
#endif |
2581 |
const char* const supportedFileTypes[] = { |
const char* const supportedFileTypes[] = { |
2582 |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
2583 |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
2585 |
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
2586 |
"*.caf", "*.CAF", NULL |
"*.caf", "*.CAF", NULL |
2587 |
}; |
}; |
2588 |
|
const char* soundfiles = _("Sound Files"); |
2589 |
|
const char* allfiles = _("All Files"); |
2590 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
2591 |
for (int i = 0; supportedFileTypes[i]; i++) |
for (int i = 0; supportedFileTypes[i]; i++) |
2592 |
soundfilter.add_pattern(supportedFileTypes[i]); |
soundfilter.add_pattern(supportedFileTypes[i]); |
2593 |
soundfilter.set_name("Sound Files"); |
soundfilter.set_name(soundfiles); |
2594 |
Gtk::FileFilter allpassfilter; // matches every file |
|
2595 |
|
// matches every file |
2596 |
|
Gtk::FileFilter allpassfilter; |
2597 |
allpassfilter.add_pattern("*.*"); |
allpassfilter.add_pattern("*.*"); |
2598 |
allpassfilter.set_name("All Files"); |
allpassfilter.set_name(allfiles); |
2599 |
|
#else |
2600 |
|
for (int i = 0; supportedFileTypes[i]; i++) |
2601 |
|
soundfilter->add_pattern(supportedFileTypes[i]); |
2602 |
|
soundfilter->set_name(soundfiles); |
2603 |
|
|
2604 |
|
// matches every file |
2605 |
|
Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create(); |
2606 |
|
allpassfilter->add_pattern("*.*"); |
2607 |
|
allpassfilter->set_name(allfiles); |
2608 |
|
#endif |
2609 |
dialog.add_filter(soundfilter); |
dialog.add_filter(soundfilter); |
2610 |
dialog.add_filter(allpassfilter); |
dialog.add_filter(allpassfilter); |
2611 |
|
if (current_sample_dir != "") { |
2612 |
|
dialog.set_current_folder(current_sample_dir); |
2613 |
|
} |
2614 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
2615 |
|
current_sample_dir = dialog.get_current_folder(); |
2616 |
Glib::ustring error_files; |
Glib::ustring error_files; |
2617 |
Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
2618 |
for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin(); |
for (std::vector<std::string>::iterator iter = filenames.begin(); |
2619 |
iter != filenames.end(); ++iter) { |
iter != filenames.end(); ++iter) { |
2620 |
printf("Adding sample %s\n",(*iter).c_str()); |
printf("Adding sample %s\n",(*iter).c_str()); |
2621 |
// use libsndfile to retrieve file informations |
// use libsndfile to retrieve file informations |
2623 |
info.format = 0; |
info.format = 0; |
2624 |
SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); |
2625 |
try { |
try { |
2626 |
if (!hFile) throw std::string("could not open file"); |
if (!hFile) throw std::string(_("could not open file")); |
2627 |
int bitdepth; |
int bitdepth; |
2628 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
2629 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
2639 |
break; |
break; |
2640 |
default: |
default: |
2641 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
2642 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
2643 |
} |
} |
2644 |
// add a new sample to the .gig file |
// add a new sample to the .gig file (if adding is requested actually) |
2645 |
gig::Sample* sample = file->AddSample(); |
if (!replace) sample = file->AddSample(); |
2646 |
// file name without path |
// file name without path |
2647 |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
2648 |
// remove file extension if there is one |
// remove file extension if there is one |
2652 |
break; |
break; |
2653 |
} |
} |
2654 |
} |
} |
2655 |
sample->pInfo->Name = filename; |
sample->pInfo->Name = gig_from_utf8(filename); |
2656 |
sample->Channels = info.channels; |
sample->Channels = info.channels; |
2657 |
sample->BitDepth = bitdepth; |
sample->BitDepth = bitdepth; |
2658 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
2666 |
&instrument, sizeof(instrument)) != SF_FALSE) |
&instrument, sizeof(instrument)) != SF_FALSE) |
2667 |
{ |
{ |
2668 |
sample->MIDIUnityNote = instrument.basenote; |
sample->MIDIUnityNote = instrument.basenote; |
2669 |
|
sample->FineTune = instrument.detune; |
2670 |
|
|
2671 |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
2672 |
sample->Loops = 1; |
sample->Loops = 1; |
2693 |
// physically when File::Save() is called) |
// physically when File::Save() is called) |
2694 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
2695 |
// make sure sample is part of the selected group |
// make sure sample is part of the selected group |
2696 |
group->AddSample(sample); |
if (!replace) group->AddSample(sample); |
2697 |
// schedule that physical resize and sample import |
// schedule that physical resize and sample import |
2698 |
// (data copying), performed when "Save" is requested |
// (data copying), performed when "Save" is requested |
2699 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2701 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2702 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue.push_back(sched_item); |
2703 |
// add sample to the tree view |
// add sample to the tree view |
2704 |
Gtk::TreeModel::iterator iterSample = |
if (replace) { |
2705 |
m_refSamplesTreeModel->append(row.children()); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
2706 |
Gtk::TreeModel::Row rowSample = *iterSample; |
} else { |
2707 |
rowSample[m_SamplesModel.m_col_name] = filename; |
Gtk::TreeModel::iterator iterSample = |
2708 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
m_refSamplesTreeModel->append(row.children()); |
2709 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
Gtk::TreeModel::Row rowSample = *iterSample; |
2710 |
|
rowSample[m_SamplesModel.m_col_name] = |
2711 |
|
gig_to_utf8(sample->pInfo->Name); |
2712 |
|
rowSample[m_SamplesModel.m_col_sample] = sample; |
2713 |
|
rowSample[m_SamplesModel.m_col_group] = NULL; |
2714 |
|
} |
2715 |
// close sound file |
// close sound file |
2716 |
sf_close(hFile); |
sf_close(hFile); |
2717 |
file_changed(); |
file_changed(); |
2718 |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
2719 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
2720 |
error_files += *iter += " (" + what + ")"; |
error_files += *iter += " (" + what + ")"; |
2721 |
} |
} |
2722 |
} |
} |
2723 |
// show error message box when some file(s) could not be opened / added |
// show error message box when some file(s) could not be opened / added |
2724 |
if (error_files.size()) { |
if (!error_files.empty()) { |
2725 |
Glib::ustring txt = "Could not add the following sample(s):\n" + error_files; |
Glib::ustring txt = |
2726 |
|
(replace |
2727 |
|
? _("Failed to replace sample with:\n") |
2728 |
|
: _("Could not add the following sample(s):\n")) |
2729 |
|
+ error_files; |
2730 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2731 |
|
msg.run(); |
2732 |
|
} |
2733 |
|
} |
2734 |
|
} |
2735 |
|
|
2736 |
|
void MainWindow::on_action_replace_all_samples_in_all_groups() |
2737 |
|
{ |
2738 |
|
if (!file) return; |
2739 |
|
Gtk::FileChooserDialog dialog(*this, _("Select Folder"), |
2740 |
|
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
2741 |
|
const char* str = |
2742 |
|
_("This is a very specific function. It tries to replace all samples " |
2743 |
|
"in the current gig file by samples located in the chosen " |
2744 |
|
"directory.\n\n" |
2745 |
|
"It works like this: For each sample in the gig file, it tries to " |
2746 |
|
"find a sample file in the selected directory with the same name as " |
2747 |
|
"the sample in the gig file. Optionally, you can add a filename " |
2748 |
|
"extension below, which will be added to the filename expected to be " |
2749 |
|
"found. That is, assume you have a gig file with a sample called " |
2750 |
|
"'Snare', if you enter '.wav' below (like it's done by default), it " |
2751 |
|
"expects to find a sample file called 'Snare.wav' and will replace " |
2752 |
|
"the sample in the gig file accordingly. If you don't need an " |
2753 |
|
"extension, blank the field below. Any gig sample where no " |
2754 |
|
"appropriate sample file could be found will be reported and left " |
2755 |
|
"untouched.\n"); |
2756 |
|
#if GTKMM_MAJOR_VERSION < 3 |
2757 |
|
view::WrapLabel description(str); |
2758 |
|
#else |
2759 |
|
Gtk::Label description(str); |
2760 |
|
description.set_line_wrap(); |
2761 |
|
#endif |
2762 |
|
Gtk::HBox entryArea; |
2763 |
|
Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START); |
2764 |
|
Gtk::Entry postfixEntryBox; |
2765 |
|
postfixEntryBox.set_text(".wav"); |
2766 |
|
entryArea.pack_start(entryLabel); |
2767 |
|
entryArea.pack_start(postfixEntryBox); |
2768 |
|
dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK); |
2769 |
|
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
2770 |
|
description.show(); |
2771 |
|
entryArea.show_all(); |
2772 |
|
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
2773 |
|
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
2774 |
|
dialog.set_select_multiple(false); |
2775 |
|
if (current_sample_dir != "") { |
2776 |
|
dialog.set_current_folder(current_sample_dir); |
2777 |
|
} |
2778 |
|
if (dialog.run() == Gtk::RESPONSE_OK) |
2779 |
|
{ |
2780 |
|
current_sample_dir = dialog.get_current_folder(); |
2781 |
|
Glib::ustring error_files; |
2782 |
|
std::string folder = dialog.get_filename(); |
2783 |
|
for (gig::Sample* sample = file->GetFirstSample(); |
2784 |
|
sample; sample = file->GetNextSample()) |
2785 |
|
{ |
2786 |
|
std::string filename = |
2787 |
|
folder + G_DIR_SEPARATOR_S + |
2788 |
|
Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) + |
2789 |
|
postfixEntryBox.get_text()); |
2790 |
|
SF_INFO info; |
2791 |
|
info.format = 0; |
2792 |
|
SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); |
2793 |
|
try |
2794 |
|
{ |
2795 |
|
if (!hFile) throw std::string(_("could not open file")); |
2796 |
|
switch (info.format & 0xff) { |
2797 |
|
case SF_FORMAT_PCM_S8: |
2798 |
|
case SF_FORMAT_PCM_16: |
2799 |
|
case SF_FORMAT_PCM_U8: |
2800 |
|
case SF_FORMAT_PCM_24: |
2801 |
|
case SF_FORMAT_PCM_32: |
2802 |
|
case SF_FORMAT_FLOAT: |
2803 |
|
case SF_FORMAT_DOUBLE: |
2804 |
|
break; |
2805 |
|
default: |
2806 |
|
sf_close(hFile); |
2807 |
|
throw std::string(_("format not supported")); |
2808 |
|
} |
2809 |
|
SampleImportItem sched_item; |
2810 |
|
sched_item.gig_sample = sample; |
2811 |
|
sched_item.sample_path = filename; |
2812 |
|
m_SampleImportQueue.push_back(sched_item); |
2813 |
|
sf_close(hFile); |
2814 |
|
file_changed(); |
2815 |
|
} |
2816 |
|
catch (std::string what) |
2817 |
|
{ |
2818 |
|
if (!error_files.empty()) error_files += "\n"; |
2819 |
|
error_files += Glib::filename_to_utf8(filename) + |
2820 |
|
" (" + what + ")"; |
2821 |
|
} |
2822 |
|
} |
2823 |
|
// show error message box when some file(s) could not be opened / added |
2824 |
|
if (!error_files.empty()) { |
2825 |
|
Glib::ustring txt = |
2826 |
|
_("Could not replace the following sample(s):\n") + error_files; |
2827 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2828 |
msg.run(); |
msg.run(); |
2829 |
} |
} |
2833 |
void MainWindow::on_action_remove_sample() { |
void MainWindow::on_action_remove_sample() { |
2834 |
if (!file) return; |
if (!file) return; |
2835 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2836 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2837 |
if (it) { |
for (int r = rows.size() - 1; r >= 0; --r) { |
2838 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]); |
2839 |
|
if (!it) continue; |
2840 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2841 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2842 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2844 |
try { |
try { |
2845 |
// remove group or sample from the gig file |
// remove group or sample from the gig file |
2846 |
if (group) { |
if (group) { |
2847 |
// temporarily remember the samples that bolong to |
// temporarily remember the samples that belong to |
2848 |
// that group (we need that to clean the queue) |
// that group (we need that to clean the queue) |
2849 |
std::list<gig::Sample*> members; |
std::list<gig::Sample*> members; |
2850 |
for (gig::Sample* pSample = group->GetFirstSample(); |
for (gig::Sample* pSample = group->GetFirstSample(); |
2851 |
pSample; pSample = group->GetNextSample()) { |
pSample; pSample = group->GetNextSample()) { |
2852 |
members.push_back(pSample); |
members.push_back(pSample); |
2853 |
} |
} |
2854 |
|
// notify everybody that we're going to remove these samples |
2855 |
|
samples_to_be_removed_signal.emit(members); |
2856 |
// delete the group in the .gig file including the |
// delete the group in the .gig file including the |
2857 |
// samples that belong to the group |
// samples that belong to the group |
2858 |
file->DeleteGroup(group); |
file->DeleteGroup(group); |
2859 |
|
// notify that we're done with removal |
2860 |
|
samples_removed_signal.emit(); |
2861 |
// if sample(s) were just previously added, remove |
// if sample(s) were just previously added, remove |
2862 |
// them from the import queue |
// them from the import queue |
2863 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
2874 |
} |
} |
2875 |
file_changed(); |
file_changed(); |
2876 |
} else if (sample) { |
} else if (sample) { |
2877 |
|
// notify everybody that we're going to remove this sample |
2878 |
|
std::list<gig::Sample*> lsamples; |
2879 |
|
lsamples.push_back(sample); |
2880 |
|
samples_to_be_removed_signal.emit(lsamples); |
2881 |
// remove sample from the .gig file |
// remove sample from the .gig file |
2882 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
2883 |
|
// notify that we're done with removal |
2884 |
|
samples_removed_signal.emit(); |
2885 |
// if sample was just previously added, remove it from |
// if sample was just previously added, remove it from |
2886 |
// the import queue |
// the import queue |
2887 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
2893 |
break; |
break; |
2894 |
} |
} |
2895 |
} |
} |
2896 |
|
dimreg_changed(); |
2897 |
file_changed(); |
file_changed(); |
2898 |
} |
} |
2899 |
// remove respective row(s) from samples tree view |
// remove respective row(s) from samples tree view |
2900 |
m_refSamplesTreeModel->erase(it); |
m_refSamplesTreeModel->erase(it); |
2901 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
2902 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
2903 |
|
samples_removed_signal.emit(); |
2904 |
|
// show error message |
2905 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2906 |
msg.run(); |
msg.run(); |
2907 |
} |
} |
2908 |
} |
} |
2909 |
} |
} |
2910 |
|
|
2911 |
|
void MainWindow::on_action_remove_unused_samples() { |
2912 |
|
if (!file) return; |
2913 |
|
|
2914 |
|
// collect all samples that are not referenced by any instrument |
2915 |
|
std::list<gig::Sample*> lsamples; |
2916 |
|
for (int iSample = 0; file->GetSample(iSample); ++iSample) { |
2917 |
|
gig::Sample* sample = file->GetSample(iSample); |
2918 |
|
bool isUsed = false; |
2919 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; |
2920 |
|
instrument = file->GetNextInstrument()) |
2921 |
|
{ |
2922 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
2923 |
|
rgn = instrument->GetNextRegion()) |
2924 |
|
{ |
2925 |
|
for (int i = 0; i < 256; ++i) { |
2926 |
|
if (!rgn->pDimensionRegions[i]) continue; |
2927 |
|
if (rgn->pDimensionRegions[i]->pSample != sample) continue; |
2928 |
|
isUsed = true; |
2929 |
|
goto endOfRefSearch; |
2930 |
|
} |
2931 |
|
} |
2932 |
|
} |
2933 |
|
endOfRefSearch: |
2934 |
|
if (!isUsed) lsamples.push_back(sample); |
2935 |
|
} |
2936 |
|
|
2937 |
|
if (lsamples.empty()) return; |
2938 |
|
|
2939 |
|
// notify everybody that we're going to remove these samples |
2940 |
|
samples_to_be_removed_signal.emit(lsamples); |
2941 |
|
|
2942 |
|
// remove collected samples |
2943 |
|
try { |
2944 |
|
for (std::list<gig::Sample*>::iterator itSample = lsamples.begin(); |
2945 |
|
itSample != lsamples.end(); ++itSample) |
2946 |
|
{ |
2947 |
|
gig::Sample* sample = *itSample; |
2948 |
|
// remove sample from the .gig file |
2949 |
|
file->DeleteSample(sample); |
2950 |
|
// if sample was just previously added, remove it fro the import queue |
2951 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
2952 |
|
iter != m_SampleImportQueue.end(); ++iter) |
2953 |
|
{ |
2954 |
|
if ((*iter).gig_sample == sample) { |
2955 |
|
printf("Removing previously added sample '%s'\n", |
2956 |
|
(*iter).sample_path.c_str()); |
2957 |
|
m_SampleImportQueue.erase(iter); |
2958 |
|
break; |
2959 |
|
} |
2960 |
|
} |
2961 |
|
} |
2962 |
|
} catch (RIFF::Exception e) { |
2963 |
|
// show error message |
2964 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2965 |
|
msg.run(); |
2966 |
|
} |
2967 |
|
|
2968 |
|
// notify everybody that we're done with removal |
2969 |
|
samples_removed_signal.emit(); |
2970 |
|
|
2971 |
|
dimreg_changed(); |
2972 |
|
file_changed(); |
2973 |
|
__refreshEntireGUI(); |
2974 |
|
} |
2975 |
|
|
2976 |
|
// see comment on on_sample_treeview_drag_begin() |
2977 |
|
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2978 |
|
{ |
2979 |
|
first_call_to_drag_data_get = true; |
2980 |
|
} |
2981 |
|
|
2982 |
|
void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2983 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2984 |
|
{ |
2985 |
|
if (!first_call_to_drag_data_get) return; |
2986 |
|
first_call_to_drag_data_get = false; |
2987 |
|
|
2988 |
|
// get selected script |
2989 |
|
gig::Script* script = NULL; |
2990 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2991 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2992 |
|
if (it) { |
2993 |
|
Gtk::TreeModel::Row row = *it; |
2994 |
|
script = row[m_ScriptsModel.m_col_script]; |
2995 |
|
} |
2996 |
|
// pass the gig::Script as pointer |
2997 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, |
2998 |
|
(const guchar*)&script, |
2999 |
|
sizeof(script)/*length of data in bytes*/); |
3000 |
|
} |
3001 |
|
|
3002 |
|
// see comment on on_sample_treeview_drag_begin() |
3003 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
3004 |
|
{ |
3005 |
|
first_call_to_drag_data_get = true; |
3006 |
|
} |
3007 |
|
|
3008 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
3009 |
|
Gtk::SelectionData& selection_data, guint, guint) |
3010 |
|
{ |
3011 |
|
if (!first_call_to_drag_data_get) return; |
3012 |
|
first_call_to_drag_data_get = false; |
3013 |
|
|
3014 |
|
// get selected source instrument |
3015 |
|
gig::Instrument* src = NULL; |
3016 |
|
{ |
3017 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
3018 |
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
3019 |
|
if (!rows.empty()) { |
3020 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); |
3021 |
|
if (it) { |
3022 |
|
Gtk::TreeModel::Row row = *it; |
3023 |
|
src = row[m_Columns.m_col_instr]; |
3024 |
|
} |
3025 |
|
} |
3026 |
|
} |
3027 |
|
if (!src) return; |
3028 |
|
|
3029 |
|
// pass the source gig::Instrument as pointer |
3030 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
3031 |
|
sizeof(src)/*length of data in bytes*/); |
3032 |
|
} |
3033 |
|
|
3034 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
3035 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
3036 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
3037 |
|
{ |
3038 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
3039 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
3040 |
|
return; |
3041 |
|
|
3042 |
|
gig::Instrument* dst = NULL; |
3043 |
|
{ |
3044 |
|
Gtk::TreeModel::Path path; |
3045 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
3046 |
|
if (!found) return; |
3047 |
|
|
3048 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
3049 |
|
if (!iter) return; |
3050 |
|
Gtk::TreeModel::Row row = *iter; |
3051 |
|
dst = row[m_Columns.m_col_instr]; |
3052 |
|
} |
3053 |
|
if (!dst) return; |
3054 |
|
|
3055 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
3056 |
|
src->MoveTo(dst); |
3057 |
|
__refreshEntireGUI(); |
3058 |
|
select_instrument(src); |
3059 |
|
} |
3060 |
|
|
3061 |
|
// For some reason drag_data_get gets called two times for each |
3062 |
|
// drag'n'drop (at least when target is an Entry). This work-around |
3063 |
|
// makes sure the code in drag_data_get and drop_drag_data_received is |
3064 |
|
// only executed once, as drag_begin only gets called once. |
3065 |
|
void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
3066 |
|
{ |
3067 |
|
first_call_to_drag_data_get = true; |
3068 |
|
} |
3069 |
|
|
3070 |
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
3071 |
Gtk::SelectionData& selection_data, guint, guint) |
Gtk::SelectionData& selection_data, guint, guint) |
3072 |
{ |
{ |
3073 |
|
if (!first_call_to_drag_data_get) return; |
3074 |
|
first_call_to_drag_data_get = false; |
3075 |
|
|
3076 |
// get selected sample |
// get selected sample |
3077 |
gig::Sample* sample = NULL; |
gig::Sample* sample = NULL; |
3078 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
3079 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
3080 |
if (it) { |
if (!rows.empty()) { |
3081 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); |
3082 |
sample = row[m_SamplesModel.m_col_sample]; |
if (it) { |
3083 |
|
Gtk::TreeModel::Row row = *it; |
3084 |
|
sample = row[m_SamplesModel.m_col_sample]; |
3085 |
|
} |
3086 |
} |
} |
3087 |
// pass the gig::Sample as pointer |
// pass the gig::Sample as pointer |
3088 |
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, |
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, |
3096 |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
3097 |
|
|
3098 |
if (sample && selection_data.get_length() == sizeof(gig::Sample*)) { |
if (sample && selection_data.get_length() == sizeof(gig::Sample*)) { |
3099 |
if (dimreg_edit.set_sample(sample)) { |
std::cout << "Drop received sample \"" << |
3100 |
std::cout << "Drop received sample \"" << |
sample->pInfo->Name << "\"" << std::endl; |
3101 |
sample->pInfo->Name << "\"" << std::endl; |
// drop success |
3102 |
// drop success |
context->drop_reply(true, time); |
3103 |
context->drop_reply(true, time); |
|
3104 |
return; |
//TODO: we should better move most of the following code to DimRegionEdit::set_sample() |
3105 |
|
|
3106 |
|
// notify everybody that we're going to alter the region |
3107 |
|
gig::Region* region = m_RegionChooser.get_region(); |
3108 |
|
region_to_be_changed_signal.emit(region); |
3109 |
|
|
3110 |
|
// find the samplechannel dimension |
3111 |
|
gig::dimension_def_t* stereo_dimension = 0; |
3112 |
|
for (int i = 0 ; i < region->Dimensions ; i++) { |
3113 |
|
if (region->pDimensionDefinitions[i].dimension == |
3114 |
|
gig::dimension_samplechannel) { |
3115 |
|
stereo_dimension = ®ion->pDimensionDefinitions[i]; |
3116 |
|
break; |
3117 |
|
} |
3118 |
} |
} |
3119 |
|
bool channels_changed = false; |
3120 |
|
if (sample->Channels == 1 && stereo_dimension) { |
3121 |
|
// remove the samplechannel dimension |
3122 |
|
/* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples |
3123 |
|
region->DeleteDimension(stereo_dimension); |
3124 |
|
channels_changed = true; |
3125 |
|
region_changed(); |
3126 |
|
*/ |
3127 |
|
} |
3128 |
|
dimreg_edit.set_sample( |
3129 |
|
sample, |
3130 |
|
is_copy_samples_unity_note_enabled(), |
3131 |
|
is_copy_samples_fine_tune_enabled(), |
3132 |
|
is_copy_samples_loop_enabled() |
3133 |
|
); |
3134 |
|
|
3135 |
|
if (sample->Channels == 2 && !stereo_dimension) { |
3136 |
|
// add samplechannel dimension |
3137 |
|
gig::dimension_def_t dim; |
3138 |
|
dim.dimension = gig::dimension_samplechannel; |
3139 |
|
dim.bits = 1; |
3140 |
|
dim.zones = 2; |
3141 |
|
region->AddDimension(&dim); |
3142 |
|
channels_changed = true; |
3143 |
|
region_changed(); |
3144 |
|
} |
3145 |
|
if (channels_changed) { |
3146 |
|
// unmap all samples with wrong number of channels |
3147 |
|
// TODO: maybe there should be a warning dialog for this |
3148 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
3149 |
|
gig::DimensionRegion* d = region->pDimensionRegions[i]; |
3150 |
|
if (d->pSample && d->pSample->Channels != sample->Channels) { |
3151 |
|
gig::Sample* oldref = d->pSample; |
3152 |
|
d->pSample = NULL; |
3153 |
|
sample_ref_changed_signal.emit(oldref, NULL); |
3154 |
|
} |
3155 |
|
} |
3156 |
|
} |
3157 |
|
|
3158 |
|
// notify we're done with altering |
3159 |
|
region_changed_signal.emit(region); |
3160 |
|
|
3161 |
|
file_changed(); |
3162 |
|
|
3163 |
|
return; |
3164 |
} |
} |
3165 |
// drop failed |
// drop failed |
3166 |
context->drop_reply(false, time); |
context->drop_reply(false, time); |
3173 |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
3174 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
3175 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
3176 |
|
gig::String gigname(gig_from_utf8(name)); |
3177 |
if (group) { |
if (group) { |
3178 |
if (group->Name != name) { |
if (group->Name != gigname) { |
3179 |
group->Name = name; |
group->Name = gigname; |
3180 |
printf("group name changed\n"); |
printf("group name changed\n"); |
3181 |
file_changed(); |
file_changed(); |
3182 |
} |
} |
3183 |
} else if (sample) { |
} else if (sample) { |
3184 |
if (sample->pInfo->Name != name.raw()) { |
if (sample->pInfo->Name != gigname) { |
3185 |
sample->pInfo->Name = name.raw(); |
sample->pInfo->Name = gigname; |
3186 |
printf("sample name changed\n"); |
printf("sample name changed\n"); |
3187 |
file_changed(); |
file_changed(); |
3188 |
} |
} |
3189 |
} |
} |
3190 |
} |
} |
3191 |
|
|
3192 |
|
void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, |
3193 |
|
const Gtk::TreeModel::iterator& iter) { |
3194 |
|
if (!iter) return; |
3195 |
|
Gtk::TreeModel::Row row = *iter; |
3196 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
3197 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
3198 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
3199 |
|
gig::String gigname(gig_from_utf8(name)); |
3200 |
|
if (group) { |
3201 |
|
if (group->Name != gigname) { |
3202 |
|
group->Name = gigname; |
3203 |
|
printf("script group name changed\n"); |
3204 |
|
file_changed(); |
3205 |
|
} |
3206 |
|
} else if (script) { |
3207 |
|
if (script->Name != gigname) { |
3208 |
|
script->Name = gigname; |
3209 |
|
printf("script name changed\n"); |
3210 |
|
file_changed(); |
3211 |
|
} |
3212 |
|
} |
3213 |
|
} |
3214 |
|
|
3215 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
3216 |
|
Gtk::TreeViewColumn* column) |
3217 |
|
{ |
3218 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
3219 |
|
if (!iter) return; |
3220 |
|
Gtk::TreeModel::Row row = *iter; |
3221 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
3222 |
|
if (!script) return; |
3223 |
|
|
3224 |
|
ScriptEditor* editor = new ScriptEditor; |
3225 |
|
editor->signal_script_to_be_changed.connect( |
3226 |
|
signal_script_to_be_changed.make_slot() |
3227 |
|
); |
3228 |
|
editor->signal_script_changed.connect( |
3229 |
|
signal_script_changed.make_slot() |
3230 |
|
); |
3231 |
|
editor->setScript(script); |
3232 |
|
//editor->reparent(*this); |
3233 |
|
editor->show(); |
3234 |
|
} |
3235 |
|
|
3236 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
3237 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
3238 |
if (!iter) return; |
if (!iter) return; |
3239 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
3240 |
Glib::ustring name = row[m_Columns.m_col_name]; |
Glib::ustring name = row[m_Columns.m_col_name]; |
3241 |
|
|
3242 |
|
// change name in instrument menu |
3243 |
|
int index = path[0]; |
3244 |
|
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
3245 |
|
if (index < children.size()) { |
3246 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2 |
3247 |
|
static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name); |
3248 |
|
#else |
3249 |
|
remove_instrument_from_menu(index); |
3250 |
|
Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index); |
3251 |
|
item->set_active(); |
3252 |
|
#endif |
3253 |
|
} |
3254 |
|
|
3255 |
|
// change name in gig |
3256 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
3257 |
if (instrument && instrument->pInfo->Name != name.raw()) { |
gig::String gigname(gig_from_utf8(name)); |
3258 |
instrument->pInfo->Name = name.raw(); |
if (instrument && instrument->pInfo->Name != gigname) { |
3259 |
|
instrument->pInfo->Name = gigname; |
3260 |
|
|
3261 |
|
// change name in the instrument properties window |
3262 |
|
if (instrumentProps.get_instrument() == instrument) { |
3263 |
|
instrumentProps.update_name(); |
3264 |
|
} |
3265 |
|
|
3266 |
file_changed(); |
file_changed(); |
3267 |
} |
} |
3268 |
} |
} |
3269 |
|
|
3270 |
|
void MainWindow::on_action_combine_instruments() { |
3271 |
|
CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file); |
3272 |
|
d->show_all(); |
3273 |
|
d->resize(500, 400); |
3274 |
|
d->run(); |
3275 |
|
if (d->fileWasChanged()) { |
3276 |
|
// update GUI with new instrument just created |
3277 |
|
add_instrument(d->newCombinedInstrument()); |
3278 |
|
} |
3279 |
|
delete d; |
3280 |
|
} |
3281 |
|
|
3282 |
|
void MainWindow::on_action_view_references() { |
3283 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
3284 |
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
3285 |
|
if (rows.empty()) return; |
3286 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); |
3287 |
|
if (!it) return; |
3288 |
|
Gtk::TreeModel::Row row = *it; |
3289 |
|
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
3290 |
|
if (!sample) return; |
3291 |
|
|
3292 |
|
ReferencesView* d = new ReferencesView(*this); |
3293 |
|
d->setSample(sample); |
3294 |
|
d->dimension_region_selected.connect( |
3295 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
3296 |
|
); |
3297 |
|
d->show_all(); |
3298 |
|
d->resize(500, 400); |
3299 |
|
d->run(); |
3300 |
|
delete d; |
3301 |
|
} |
3302 |
|
|
3303 |
|
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
3304 |
|
struct _Source { |
3305 |
|
std::vector<RIFF::File*> riffs; |
3306 |
|
std::vector<gig::File*> gigs; |
3307 |
|
|
3308 |
|
~_Source() { |
3309 |
|
for (int k = 0; k < gigs.size(); ++k) delete gigs[k]; |
3310 |
|
for (int k = 0; k < riffs.size(); ++k) delete riffs[k]; |
3311 |
|
riffs.clear(); |
3312 |
|
gigs.clear(); |
3313 |
|
} |
3314 |
|
} sources; |
3315 |
|
|
3316 |
|
if (filenames.empty()) |
3317 |
|
throw RIFF::Exception(_("No files selected, so nothing done.")); |
3318 |
|
|
3319 |
|
// first open all input files (to avoid output file corruption) |
3320 |
|
int i; |
3321 |
|
try { |
3322 |
|
for (i = 0; i < filenames.size(); ++i) { |
3323 |
|
const std::string& filename = filenames[i]; |
3324 |
|
printf("opening file=%s\n", filename.c_str()); |
3325 |
|
|
3326 |
|
RIFF::File* riff = new RIFF::File(filename); |
3327 |
|
sources.riffs.push_back(riff); |
3328 |
|
|
3329 |
|
gig::File* gig = new gig::File(riff); |
3330 |
|
sources.gigs.push_back(gig); |
3331 |
|
} |
3332 |
|
} catch (RIFF::Exception e) { |
3333 |
|
throw RIFF::Exception( |
3334 |
|
_("Error occurred while opening '") + |
3335 |
|
filenames[i] + |
3336 |
|
"': " + |
3337 |
|
e.Message |
3338 |
|
); |
3339 |
|
} catch (...) { |
3340 |
|
throw RIFF::Exception( |
3341 |
|
_("Unknown exception occurred while opening '") + |
3342 |
|
filenames[i] + "'" |
3343 |
|
); |
3344 |
|
} |
3345 |
|
|
3346 |
|
// now merge the opened .gig files to the main .gig file currently being |
3347 |
|
// open in gigedit |
3348 |
|
try { |
3349 |
|
for (i = 0; i < filenames.size(); ++i) { |
3350 |
|
const std::string& filename = filenames[i]; |
3351 |
|
printf("merging file=%s\n", filename.c_str()); |
3352 |
|
assert(i < sources.gigs.size()); |
3353 |
|
|
3354 |
|
this->file->AddContentOf(sources.gigs[i]); |
3355 |
|
} |
3356 |
|
} catch (RIFF::Exception e) { |
3357 |
|
throw RIFF::Exception( |
3358 |
|
_("Error occurred while merging '") + |
3359 |
|
filenames[i] + |
3360 |
|
"': " + |
3361 |
|
e.Message |
3362 |
|
); |
3363 |
|
} catch (...) { |
3364 |
|
throw RIFF::Exception( |
3365 |
|
_("Unknown exception occurred while merging '") + |
3366 |
|
filenames[i] + "'" |
3367 |
|
); |
3368 |
|
} |
3369 |
|
|
3370 |
|
// Finally save gig file persistently to disk ... |
3371 |
|
//NOTE: requires that this gig file already has a filename ! |
3372 |
|
{ |
3373 |
|
std::cout << "Saving file\n" << std::flush; |
3374 |
|
file_structure_to_be_changed_signal.emit(this->file); |
3375 |
|
|
3376 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
3377 |
|
_("Saving") + Glib::ustring(" '") + |
3378 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
3379 |
|
*this |
3380 |
|
); |
3381 |
|
progress_dialog->show_all(); |
3382 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
3383 |
|
saver->signal_progress().connect( |
3384 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
3385 |
|
saver->signal_finished().connect( |
3386 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
3387 |
|
saver->signal_error().connect( |
3388 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
3389 |
|
saver->launch(); |
3390 |
|
} |
3391 |
|
} |
3392 |
|
|
3393 |
|
void MainWindow::on_action_merge_files() { |
3394 |
|
if (this->file->GetFileName().empty()) { |
3395 |
|
Glib::ustring txt = _( |
3396 |
|
"You seem to have a new .gig file open that has not been saved " |
3397 |
|
"yet. You must save it somewhere before starting to merge it with " |
3398 |
|
"other .gig files though, because during the merge operation the " |
3399 |
|
"other files' sample data must be written on file level to the " |
3400 |
|
"target .gig file." |
3401 |
|
); |
3402 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
3403 |
|
msg.run(); |
3404 |
|
return; |
3405 |
|
} |
3406 |
|
|
3407 |
|
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
3408 |
|
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
3409 |
|
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
3410 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
3411 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
3412 |
|
Gtk::FileFilter filter; |
3413 |
|
filter.add_pattern("*.gig"); |
3414 |
|
#else |
3415 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
3416 |
|
filter->add_pattern("*.gig"); |
3417 |
|
#endif |
3418 |
|
dialog.set_filter(filter); |
3419 |
|
if (current_gig_dir != "") { |
3420 |
|
dialog.set_current_folder(current_gig_dir); |
3421 |
|
} |
3422 |
|
dialog.set_select_multiple(true); |
3423 |
|
|
3424 |
|
// show warning in the file picker dialog |
3425 |
|
Gtk::HBox descriptionArea; |
3426 |
|
descriptionArea.set_spacing(15); |
3427 |
|
Gtk::Image warningIcon; |
3428 |
|
warningIcon.set_from_icon_name("dialog-warning", |
3429 |
|
Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
3430 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
3431 |
|
#if GTKMM_MAJOR_VERSION < 3 |
3432 |
|
view::WrapLabel description; |
3433 |
|
#else |
3434 |
|
Gtk::Label description; |
3435 |
|
description.set_line_wrap(); |
3436 |
|
#endif |
3437 |
|
description.set_markup(_( |
3438 |
|
"\nSelect at least one .gig file that shall be merged to the .gig file " |
3439 |
|
"currently being open in gigedit.\n\n" |
3440 |
|
"<b>Please Note:</b> Merging with other files will modify your " |
3441 |
|
"currently open .gig file on file level! And be aware that the current " |
3442 |
|
"merge algorithm does not detect duplicate samples yet. So if you are " |
3443 |
|
"merging files which are using equivalent sample data, those " |
3444 |
|
"equivalent samples will currently be treated as separate samples and " |
3445 |
|
"will accordingly be stored separately in the target .gig file!" |
3446 |
|
)); |
3447 |
|
descriptionArea.pack_start(description); |
3448 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
3449 |
|
descriptionArea.show_all(); |
3450 |
|
|
3451 |
|
if (dialog.run() == Gtk::RESPONSE_OK) { |
3452 |
|
printf("on_action_merge_files self=%p\n", |
3453 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
3454 |
|
std::vector<std::string> filenames = dialog.get_filenames(); |
3455 |
|
|
3456 |
|
// merge the selected files to the currently open .gig file |
3457 |
|
try { |
3458 |
|
mergeFiles(filenames); |
3459 |
|
} catch (RIFF::Exception e) { |
3460 |
|
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
3461 |
|
msg.run(); |
3462 |
|
} |
3463 |
|
|
3464 |
|
// update GUI |
3465 |
|
__refreshEntireGUI(); |
3466 |
|
} |
3467 |
|
} |
3468 |
|
|
3469 |
|
void MainWindow::set_file_is_shared(bool b) { |
3470 |
|
this->file_is_shared = b; |
3471 |
|
|
3472 |
|
if (file_is_shared) { |
3473 |
|
m_AttachedStateLabel.set_label(_("live-mode")); |
3474 |
|
m_AttachedStateImage.set( |
3475 |
|
Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm) |
3476 |
|
); |
3477 |
|
} else { |
3478 |
|
m_AttachedStateLabel.set_label(_("stand-alone")); |
3479 |
|
m_AttachedStateImage.set( |
3480 |
|
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
3481 |
|
); |
3482 |
|
} |
3483 |
|
|
3484 |
|
{ |
3485 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
3486 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
3487 |
|
if (item) item->set_sensitive(b); |
3488 |
|
} |
3489 |
|
} |
3490 |
|
|
3491 |
|
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3492 |
|
if (!sample) return; |
3493 |
|
sample_ref_count[sample] += offset; |
3494 |
|
const int refcount = sample_ref_count[sample]; |
3495 |
|
|
3496 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
3497 |
|
for (int g = 0; g < model->children().size(); ++g) { |
3498 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
3499 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
3500 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
3501 |
|
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
3502 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
3503 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
3504 |
|
} |
3505 |
|
} |
3506 |
|
} |
3507 |
|
|
3508 |
|
void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { |
3509 |
|
on_sample_ref_count_incremented(oldSample, -1); |
3510 |
|
on_sample_ref_count_incremented(newSample, +1); |
3511 |
|
} |
3512 |
|
|
3513 |
|
void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) { |
3514 |
|
// just in case a new sample is added later with exactly the same memory |
3515 |
|
// address, which would lead to incorrect refcount if not deleted here |
3516 |
|
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3517 |
|
it != samples.end(); ++it) |
3518 |
|
{ |
3519 |
|
sample_ref_count.erase(*it); |
3520 |
|
} |
3521 |
|
} |
3522 |
|
|
3523 |
|
void MainWindow::show_samples_tab() { |
3524 |
|
m_TreeViewNotebook.set_current_page(0); |
3525 |
|
} |
3526 |
|
|
3527 |
|
void MainWindow::show_intruments_tab() { |
3528 |
|
m_TreeViewNotebook.set_current_page(1); |
3529 |
|
} |
3530 |
|
|
3531 |
|
void MainWindow::show_scripts_tab() { |
3532 |
|
m_TreeViewNotebook.set_current_page(2); |
3533 |
|
} |
3534 |
|
|
3535 |
|
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
3536 |
|
return file_structure_to_be_changed_signal; |
3537 |
|
} |
3538 |
|
|
3539 |
|
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() { |
3540 |
|
return file_structure_changed_signal; |
3541 |
|
} |
3542 |
|
|
3543 |
|
sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() { |
3544 |
|
return samples_to_be_removed_signal; |
3545 |
|
} |
3546 |
|
|
3547 |
|
sigc::signal<void>& MainWindow::signal_samples_removed() { |
3548 |
|
return samples_removed_signal; |
3549 |
|
} |
3550 |
|
|
3551 |
|
sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() { |
3552 |
|
return region_to_be_changed_signal; |
3553 |
|
} |
3554 |
|
|
3555 |
|
sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() { |
3556 |
|
return region_changed_signal; |
3557 |
|
} |
3558 |
|
|
3559 |
|
sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() { |
3560 |
|
return sample_changed_signal; |
3561 |
|
} |
3562 |
|
|
3563 |
|
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() { |
3564 |
|
return sample_ref_changed_signal; |
3565 |
|
} |
3566 |
|
|
3567 |
|
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() { |
3568 |
|
return dimreg_to_be_changed_signal; |
3569 |
|
} |
3570 |
|
|
3571 |
|
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() { |
3572 |
|
return dimreg_changed_signal; |
3573 |
|
} |
3574 |
|
|
3575 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() { |
3576 |
|
return note_on_signal; |
3577 |
|
} |
3578 |
|
|
3579 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() { |
3580 |
|
return note_off_signal; |
3581 |
|
} |
3582 |
|
|
3583 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() { |
3584 |
|
return m_RegionChooser.signal_keyboard_key_hit(); |
3585 |
|
} |
3586 |
|
|
3587 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
3588 |
|
return m_RegionChooser.signal_keyboard_key_released(); |
3589 |
|
} |
3590 |
|
|
3591 |
|
sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() { |
3592 |
|
return switch_sampler_instrument_signal; |
3593 |
|
} |