1 |
/* |
2 |
* Copyright (C) 2006-2014 Andreas Persson |
3 |
* |
4 |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
6 |
* published by the Free Software Foundation; either version 2, or (at |
7 |
* your option) any later version. |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, but |
10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
* General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with program; see the file COPYING. If not, write to the Free |
16 |
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
17 |
* 02110-1301 USA. |
18 |
*/ |
19 |
|
20 |
#include <iostream> |
21 |
#include <cstring> |
22 |
|
23 |
#include <glibmm/convert.h> |
24 |
#include <glibmm/dispatcher.h> |
25 |
#include <glibmm/miscutils.h> |
26 |
#include <glibmm/stringutils.h> |
27 |
#include <gtkmm/aboutdialog.h> |
28 |
#include <gtkmm/filechooserdialog.h> |
29 |
#include <gtkmm/messagedialog.h> |
30 |
#include <gtkmm/stock.h> |
31 |
#include <gtkmm/targetentry.h> |
32 |
#include <gtkmm/main.h> |
33 |
#include <gtkmm/toggleaction.h> |
34 |
#if GTKMM_MAJOR_VERSION < 3 |
35 |
#include "wrapLabel.hh" |
36 |
#endif |
37 |
|
38 |
#include "global.h" |
39 |
#include "compat.h" |
40 |
|
41 |
#include <stdio.h> |
42 |
#include <sndfile.h> |
43 |
|
44 |
#include "mainwindow.h" |
45 |
|
46 |
#include "../../gfx/status_attached.xpm" |
47 |
#include "../../gfx/status_detached.xpm" |
48 |
|
49 |
|
50 |
MainWindow::MainWindow() : |
51 |
dimreg_label(_("Changes apply to:")), |
52 |
dimreg_all_regions(_("all regions")), |
53 |
dimreg_all_dimregs(_("all dimension splits")), |
54 |
dimreg_stereo(_("both channels")) |
55 |
{ |
56 |
// set_border_width(5); |
57 |
// set_default_size(400, 200); |
58 |
|
59 |
|
60 |
add(m_VBox); |
61 |
|
62 |
// Handle selection |
63 |
m_TreeView.get_selection()->signal_changed().connect( |
64 |
sigc::mem_fun(*this, &MainWindow::on_sel_change)); |
65 |
|
66 |
// m_TreeView.set_reorderable(); |
67 |
|
68 |
m_TreeView.signal_button_press_event().connect_notify( |
69 |
sigc::mem_fun(*this, &MainWindow::on_button_release)); |
70 |
|
71 |
// Add the TreeView tab, inside a ScrolledWindow, with the button underneath: |
72 |
m_ScrolledWindow.add(m_TreeView); |
73 |
// m_ScrolledWindow.set_size_request(200, 600); |
74 |
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
75 |
|
76 |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
77 |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
78 |
|
79 |
|
80 |
m_TreeViewNotebook.set_size_request(300); |
81 |
|
82 |
m_HPaned.add1(m_TreeViewNotebook); |
83 |
dimreg_hbox.add(dimreg_label); |
84 |
dimreg_hbox.add(dimreg_all_regions); |
85 |
dimreg_hbox.add(dimreg_all_dimregs); |
86 |
dimreg_stereo.set_active(); |
87 |
dimreg_hbox.add(dimreg_stereo); |
88 |
dimreg_vbox.add(dimreg_edit); |
89 |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
90 |
m_HPaned.add2(dimreg_vbox); |
91 |
|
92 |
|
93 |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
94 |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
95 |
|
96 |
|
97 |
actionGroup = Gtk::ActionGroup::create(); |
98 |
|
99 |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
100 |
actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW), |
101 |
sigc::mem_fun( |
102 |
*this, &MainWindow::on_action_file_new)); |
103 |
Glib::RefPtr<Gtk::Action> action = |
104 |
Gtk::Action::create("Open", Gtk::Stock::OPEN); |
105 |
action->property_label() = action->property_label() + "..."; |
106 |
actionGroup->add(action, |
107 |
sigc::mem_fun( |
108 |
*this, &MainWindow::on_action_file_open)); |
109 |
actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE), |
110 |
sigc::mem_fun( |
111 |
*this, &MainWindow::on_action_file_save)); |
112 |
action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); |
113 |
action->property_label() = action->property_label() + "..."; |
114 |
actionGroup->add(action, |
115 |
Gtk::AccelKey("<shift><control>s"), |
116 |
sigc::mem_fun( |
117 |
*this, &MainWindow::on_action_file_save_as)); |
118 |
actionGroup->add(Gtk::Action::create("Properties", |
119 |
Gtk::Stock::PROPERTIES), |
120 |
sigc::mem_fun( |
121 |
*this, &MainWindow::on_action_file_properties)); |
122 |
actionGroup->add(Gtk::Action::create("InstrProperties", |
123 |
Gtk::Stock::PROPERTIES), |
124 |
sigc::mem_fun( |
125 |
*this, &MainWindow::show_instr_props)); |
126 |
actionGroup->add(Gtk::Action::create("MidiRules", |
127 |
_("_Midi Rules")), |
128 |
sigc::mem_fun( |
129 |
*this, &MainWindow::show_midi_rules)); |
130 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
131 |
sigc::mem_fun( |
132 |
*this, &MainWindow::on_action_quit)); |
133 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
134 |
|
135 |
|
136 |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
137 |
|
138 |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
139 |
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"), "ffaga"); |
140 |
toggle_action->set_active(true); |
141 |
//FIXME: doesn't work, why? |
142 |
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
143 |
actionGroup->add(toggle_action); |
144 |
|
145 |
toggle_action = |
146 |
Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); |
147 |
toggle_action->set_active(true); |
148 |
//FIXME: doesn't work, why? |
149 |
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
150 |
actionGroup->add(toggle_action); |
151 |
|
152 |
toggle_action = |
153 |
Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); |
154 |
toggle_action->set_active(true); |
155 |
//FIXME: doesn't work, why? |
156 |
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
157 |
actionGroup->add(toggle_action); |
158 |
|
159 |
|
160 |
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
161 |
toggle_action = |
162 |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
163 |
toggle_action->set_active(true); |
164 |
actionGroup->add(toggle_action, |
165 |
sigc::mem_fun( |
166 |
*this, &MainWindow::on_action_view_status_bar)); |
167 |
|
168 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
169 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
170 |
action->property_label())); |
171 |
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
172 |
sigc::mem_fun( |
173 |
*this, &MainWindow::on_action_help_about)); |
174 |
actionGroup->add( |
175 |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
176 |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
177 |
); |
178 |
actionGroup->add( |
179 |
Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")), |
180 |
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
181 |
); |
182 |
actionGroup->add( |
183 |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
184 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
185 |
); |
186 |
|
187 |
// sample right-click popup actions |
188 |
actionGroup->add( |
189 |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
190 |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
191 |
); |
192 |
actionGroup->add( |
193 |
Gtk::Action::create("AddGroup", _("Add _Group")), |
194 |
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
195 |
); |
196 |
actionGroup->add( |
197 |
Gtk::Action::create("AddSample", _("Add _Sample(s)...")), |
198 |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
199 |
); |
200 |
actionGroup->add( |
201 |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
202 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
203 |
); |
204 |
actionGroup->add( |
205 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
206 |
_("Replace All Samples in All Groups...")), |
207 |
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
208 |
); |
209 |
|
210 |
uiManager = Gtk::UIManager::create(); |
211 |
uiManager->insert_action_group(actionGroup); |
212 |
add_accel_group(uiManager->get_accel_group()); |
213 |
|
214 |
Glib::ustring ui_info = |
215 |
"<ui>" |
216 |
" <menubar name='MenuBar'>" |
217 |
" <menu action='MenuFile'>" |
218 |
" <menuitem action='New'/>" |
219 |
" <menuitem action='Open'/>" |
220 |
" <separator/>" |
221 |
" <menuitem action='Save'/>" |
222 |
" <menuitem action='SaveAs'/>" |
223 |
" <separator/>" |
224 |
" <menuitem action='Properties'/>" |
225 |
" <separator/>" |
226 |
" <menuitem action='Quit'/>" |
227 |
" </menu>" |
228 |
" <menu action='MenuEdit'>" |
229 |
" <menuitem action='CopySampleUnity'/>" |
230 |
" <menuitem action='CopySampleTune'/>" |
231 |
" <menuitem action='CopySampleLoop'/>" |
232 |
" </menu>" |
233 |
" <menu action='MenuInstrument'>" |
234 |
" </menu>" |
235 |
" <menu action='MenuView'>" |
236 |
" <menuitem action='Statusbar'/>" |
237 |
" </menu>" |
238 |
" <menu action='MenuHelp'>" |
239 |
" <menuitem action='About'/>" |
240 |
" </menu>" |
241 |
" </menubar>" |
242 |
" <popup name='PopupMenu'>" |
243 |
" <menuitem action='InstrProperties'/>" |
244 |
" <menuitem action='MidiRules'/>" |
245 |
" <menuitem action='AddInstrument'/>" |
246 |
" <menuitem action='DupInstrument'/>" |
247 |
" <separator/>" |
248 |
" <menuitem action='RemoveInstrument'/>" |
249 |
" </popup>" |
250 |
" <popup name='SamplePopupMenu'>" |
251 |
" <menuitem action='SampleProperties'/>" |
252 |
" <menuitem action='AddGroup'/>" |
253 |
" <menuitem action='AddSample'/>" |
254 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
255 |
" <separator/>" |
256 |
" <menuitem action='RemoveSample'/>" |
257 |
" </popup>" |
258 |
"</ui>"; |
259 |
uiManager->add_ui_from_string(ui_info); |
260 |
|
261 |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
262 |
|
263 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
264 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
265 |
|
266 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
267 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
268 |
m_VBox.pack_start(m_HPaned); |
269 |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
270 |
m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK); |
271 |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
272 |
m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK); |
273 |
|
274 |
set_file_is_shared(false); |
275 |
|
276 |
// Status Bar: |
277 |
m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); |
278 |
m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); |
279 |
m_StatusBar.show(); |
280 |
|
281 |
m_RegionChooser.signal_region_selected().connect( |
282 |
sigc::mem_fun(*this, &MainWindow::region_changed) ); |
283 |
m_DimRegionChooser.signal_dimregion_selected().connect( |
284 |
sigc::mem_fun(*this, &MainWindow::dimreg_changed) ); |
285 |
|
286 |
|
287 |
// Create the Tree model: |
288 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
289 |
m_TreeView.set_model(m_refTreeModel); |
290 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
291 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
292 |
); |
293 |
|
294 |
// Add the TreeView's view columns: |
295 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
296 |
m_TreeView.set_headers_visible(false); |
297 |
|
298 |
// create samples treeview (including its data model) |
299 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
300 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
301 |
// m_TreeViewSamples.set_reorderable(); |
302 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
303 |
m_TreeViewSamples.set_headers_visible(false); |
304 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
305 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
306 |
); |
307 |
m_refSamplesTreeModel->signal_row_changed().connect( |
308 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
309 |
); |
310 |
|
311 |
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
312 |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
313 |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
314 |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
315 |
m_TreeViewSamples.signal_drag_begin().connect( |
316 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin) |
317 |
); |
318 |
m_TreeViewSamples.signal_drag_data_get().connect( |
319 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
320 |
); |
321 |
dimreg_edit.wSample->drag_dest_set(drag_target_gig_sample); |
322 |
dimreg_edit.wSample->signal_drag_data_received().connect( |
323 |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
324 |
); |
325 |
dimreg_edit.signal_dimreg_changed().connect( |
326 |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
327 |
m_RegionChooser.signal_instrument_changed().connect( |
328 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
329 |
m_DimRegionChooser.signal_region_changed().connect( |
330 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
331 |
instrumentProps.signal_changed().connect( |
332 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
333 |
propDialog.signal_changed().connect( |
334 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
335 |
midiRules.signal_changed().connect( |
336 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
337 |
|
338 |
dimreg_edit.signal_dimreg_to_be_changed().connect( |
339 |
dimreg_to_be_changed_signal.make_slot()); |
340 |
dimreg_edit.signal_dimreg_changed().connect( |
341 |
dimreg_changed_signal.make_slot()); |
342 |
dimreg_edit.signal_sample_ref_changed().connect( |
343 |
sample_ref_changed_signal.make_slot()); |
344 |
|
345 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
346 |
sigc::hide( |
347 |
sigc::bind( |
348 |
file_structure_to_be_changed_signal.make_slot(), |
349 |
sigc::ref(this->file) |
350 |
) |
351 |
) |
352 |
); |
353 |
m_RegionChooser.signal_instrument_struct_changed().connect( |
354 |
sigc::hide( |
355 |
sigc::bind( |
356 |
file_structure_changed_signal.make_slot(), |
357 |
sigc::ref(this->file) |
358 |
) |
359 |
) |
360 |
); |
361 |
m_RegionChooser.signal_region_to_be_changed().connect( |
362 |
region_to_be_changed_signal.make_slot()); |
363 |
m_RegionChooser.signal_region_changed_signal().connect( |
364 |
region_changed_signal.make_slot()); |
365 |
|
366 |
note_on_signal.connect( |
367 |
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event)); |
368 |
note_off_signal.connect( |
369 |
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event)); |
370 |
|
371 |
dimreg_all_regions.signal_toggled().connect( |
372 |
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
373 |
dimreg_all_dimregs.signal_toggled().connect( |
374 |
sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled)); |
375 |
dimreg_stereo.signal_toggled().connect( |
376 |
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
377 |
|
378 |
file = 0; |
379 |
file_is_changed = false; |
380 |
|
381 |
show_all_children(); |
382 |
|
383 |
// start with a new gig file by default |
384 |
on_action_file_new(); |
385 |
} |
386 |
|
387 |
MainWindow::~MainWindow() |
388 |
{ |
389 |
} |
390 |
|
391 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
392 |
{ |
393 |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
394 |
} |
395 |
|
396 |
void MainWindow::on_action_quit() |
397 |
{ |
398 |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
399 |
hide(); |
400 |
} |
401 |
|
402 |
void MainWindow::region_changed() |
403 |
{ |
404 |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
405 |
} |
406 |
|
407 |
gig::Instrument* MainWindow::get_instrument() |
408 |
{ |
409 |
gig::Instrument* instrument = 0; |
410 |
Gtk::TreeModel::const_iterator it = |
411 |
m_TreeView.get_selection()->get_selected(); |
412 |
if (it) { |
413 |
Gtk::TreeModel::Row row = *it; |
414 |
instrument = row[m_Columns.m_col_instr]; |
415 |
} |
416 |
return instrument; |
417 |
} |
418 |
|
419 |
void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs) |
420 |
{ |
421 |
if (all_dimregs) { |
422 |
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
423 |
if (region->pDimensionRegions[i]) { |
424 |
dimreg_edit.dimregs.insert(region->pDimensionRegions[i]); |
425 |
} |
426 |
} |
427 |
} else { |
428 |
m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs); |
429 |
} |
430 |
} |
431 |
|
432 |
void MainWindow::update_dimregs() |
433 |
{ |
434 |
dimreg_edit.dimregs.clear(); |
435 |
bool all_regions = dimreg_all_regions.get_active(); |
436 |
bool stereo = dimreg_stereo.get_active(); |
437 |
bool all_dimregs = dimreg_all_dimregs.get_active(); |
438 |
|
439 |
if (all_regions) { |
440 |
gig::Instrument* instrument = get_instrument(); |
441 |
if (instrument) { |
442 |
for (gig::Region* region = instrument->GetFirstRegion() ; |
443 |
region ; |
444 |
region = instrument->GetNextRegion()) { |
445 |
add_region_to_dimregs(region, stereo, all_dimregs); |
446 |
} |
447 |
} |
448 |
} else { |
449 |
gig::Region* region = m_RegionChooser.get_region(); |
450 |
if (region) { |
451 |
add_region_to_dimregs(region, stereo, all_dimregs); |
452 |
} |
453 |
} |
454 |
} |
455 |
|
456 |
void MainWindow::dimreg_all_dimregs_toggled() |
457 |
{ |
458 |
dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active()); |
459 |
update_dimregs(); |
460 |
} |
461 |
|
462 |
void MainWindow::dimreg_changed() |
463 |
{ |
464 |
update_dimregs(); |
465 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
466 |
} |
467 |
|
468 |
void MainWindow::on_sel_change() |
469 |
{ |
470 |
// select item in instrument menu |
471 |
Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected(); |
472 |
if (it) { |
473 |
Gtk::TreePath path(it); |
474 |
int index = path[0]; |
475 |
const std::vector<Gtk::Widget*> children = |
476 |
instrument_menu->get_children(); |
477 |
static_cast<Gtk::RadioMenuItem*>(children[index])->set_active(); |
478 |
} |
479 |
|
480 |
m_RegionChooser.set_instrument(get_instrument()); |
481 |
} |
482 |
|
483 |
void loader_progress_callback(gig::progress_t* progress) |
484 |
{ |
485 |
Loader* loader = static_cast<Loader*>(progress->custom); |
486 |
loader->progress_callback(progress->factor); |
487 |
} |
488 |
|
489 |
void Loader::progress_callback(float fraction) |
490 |
{ |
491 |
{ |
492 |
Glib::Threads::Mutex::Lock lock(progressMutex); |
493 |
progress = fraction; |
494 |
} |
495 |
progress_dispatcher(); |
496 |
} |
497 |
|
498 |
void Loader::thread_function() |
499 |
{ |
500 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
501 |
printf("Start %s\n", filename); |
502 |
RIFF::File* riff = new RIFF::File(filename); |
503 |
gig = new gig::File(riff); |
504 |
gig::progress_t progress; |
505 |
progress.callback = loader_progress_callback; |
506 |
progress.custom = this; |
507 |
|
508 |
gig->GetInstrument(0, &progress); |
509 |
printf("End\n"); |
510 |
finished_dispatcher(); |
511 |
} |
512 |
|
513 |
Loader::Loader(const char* filename) |
514 |
: filename(filename), thread(0) |
515 |
{ |
516 |
} |
517 |
|
518 |
void Loader::launch() |
519 |
{ |
520 |
#ifdef OLD_THREADS |
521 |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
522 |
#else |
523 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
524 |
#endif |
525 |
printf("launch thread=%x\n", thread); |
526 |
} |
527 |
|
528 |
float Loader::get_progress() |
529 |
{ |
530 |
float res; |
531 |
{ |
532 |
Glib::Threads::Mutex::Lock lock(progressMutex); |
533 |
res = progress; |
534 |
} |
535 |
return res; |
536 |
} |
537 |
|
538 |
Glib::Dispatcher& Loader::signal_progress() |
539 |
{ |
540 |
return progress_dispatcher; |
541 |
} |
542 |
|
543 |
Glib::Dispatcher& Loader::signal_finished() |
544 |
{ |
545 |
return finished_dispatcher; |
546 |
} |
547 |
|
548 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
549 |
: Gtk::Dialog(title, parent, true) |
550 |
{ |
551 |
get_vbox()->pack_start(progressBar); |
552 |
show_all_children(); |
553 |
} |
554 |
|
555 |
// Clear all GUI elements / controls. This method is typically called |
556 |
// before a new .gig file is to be created or to be loaded. |
557 |
void MainWindow::__clear() { |
558 |
// forget all samples that ought to be imported |
559 |
m_SampleImportQueue.clear(); |
560 |
// clear the samples and instruments tree views |
561 |
m_refTreeModel->clear(); |
562 |
m_refSamplesTreeModel->clear(); |
563 |
// remove all entries from "Instrument" menu |
564 |
while (!instrument_menu->get_children().empty()) { |
565 |
remove_instrument_from_menu(0); |
566 |
} |
567 |
// free libgig's gig::File instance |
568 |
if (file && !file_is_shared) delete file; |
569 |
file = NULL; |
570 |
set_file_is_shared(false); |
571 |
} |
572 |
|
573 |
void MainWindow::on_action_file_new() |
574 |
{ |
575 |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
576 |
|
577 |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
578 |
|
579 |
// clear all GUI elements |
580 |
__clear(); |
581 |
// create a new .gig file (virtually yet) |
582 |
gig::File* pFile = new gig::File; |
583 |
// already add one new instrument by default |
584 |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
585 |
pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument")); |
586 |
// update GUI with that new gig::File |
587 |
load_gig(pFile, 0 /*no file name yet*/); |
588 |
} |
589 |
|
590 |
bool MainWindow::close_confirmation_dialog() |
591 |
{ |
592 |
gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"), |
593 |
Glib::filename_display_basename(filename).c_str()); |
594 |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
595 |
g_free(msg); |
596 |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
597 |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
598 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
599 |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
600 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
601 |
int response = dialog.run(); |
602 |
dialog.hide(); |
603 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
604 |
return response != Gtk::RESPONSE_CANCEL; |
605 |
} |
606 |
|
607 |
bool MainWindow::leaving_shared_mode_dialog() { |
608 |
Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); |
609 |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
610 |
dialog.set_secondary_text( |
611 |
_("If you proceed to work on another instrument file, it won't be " |
612 |
"used by the sampler until you tell the sampler explicitly to " |
613 |
"load it.")); |
614 |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
615 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
616 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
617 |
int response = dialog.run(); |
618 |
dialog.hide(); |
619 |
return response == Gtk::RESPONSE_YES; |
620 |
} |
621 |
|
622 |
void MainWindow::on_action_file_open() |
623 |
{ |
624 |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
625 |
|
626 |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
627 |
|
628 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
629 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
630 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
631 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
632 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
633 |
Gtk::FileFilter filter; |
634 |
filter.add_pattern("*.gig"); |
635 |
#else |
636 |
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
637 |
filter->add_pattern("*.gig"); |
638 |
#endif |
639 |
dialog.set_filter(filter); |
640 |
if (current_gig_dir != "") { |
641 |
dialog.set_current_folder(current_gig_dir); |
642 |
} |
643 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
644 |
std::string filename = dialog.get_filename(); |
645 |
printf("filename=%s\n", filename.c_str()); |
646 |
printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); |
647 |
load_file(filename.c_str()); |
648 |
current_gig_dir = Glib::path_get_dirname(filename); |
649 |
} |
650 |
} |
651 |
|
652 |
void MainWindow::load_file(const char* name) |
653 |
{ |
654 |
__clear(); |
655 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
656 |
load_dialog->show_all(); |
657 |
loader = new Loader(strdup(name)); |
658 |
loader->signal_progress().connect( |
659 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
660 |
loader->signal_finished().connect( |
661 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
662 |
loader->launch(); |
663 |
} |
664 |
|
665 |
void MainWindow::load_instrument(gig::Instrument* instr) { |
666 |
if (!instr) { |
667 |
Glib::ustring txt = "Provided instrument is NULL!\n"; |
668 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
669 |
msg.run(); |
670 |
Gtk::Main::quit(); |
671 |
} |
672 |
// clear all GUI elements |
673 |
__clear(); |
674 |
// load the instrument |
675 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
676 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
677 |
//TODO: automatically select the given instrument |
678 |
} |
679 |
|
680 |
void MainWindow::on_loader_progress() |
681 |
{ |
682 |
load_dialog->set_fraction(loader->get_progress()); |
683 |
} |
684 |
|
685 |
void MainWindow::on_loader_finished() |
686 |
{ |
687 |
printf("Loader finished!\n"); |
688 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
689 |
load_gig(loader->gig, loader->filename); |
690 |
load_dialog->hide(); |
691 |
} |
692 |
|
693 |
void MainWindow::on_action_file_save() |
694 |
{ |
695 |
file_save(); |
696 |
} |
697 |
|
698 |
bool MainWindow::check_if_savable() |
699 |
{ |
700 |
if (!file) return false; |
701 |
|
702 |
if (!file->GetFirstSample()) { |
703 |
Gtk::MessageDialog(*this, _("The file could not be saved " |
704 |
"because it contains no samples"), |
705 |
false, Gtk::MESSAGE_ERROR).run(); |
706 |
return false; |
707 |
} |
708 |
|
709 |
for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ; |
710 |
instrument = file->GetNextInstrument()) { |
711 |
if (!instrument->GetFirstRegion()) { |
712 |
Gtk::MessageDialog(*this, _("The file could not be saved " |
713 |
"because there are instruments " |
714 |
"that have no regions"), |
715 |
false, Gtk::MESSAGE_ERROR).run(); |
716 |
return false; |
717 |
} |
718 |
} |
719 |
return true; |
720 |
} |
721 |
|
722 |
bool MainWindow::file_save() |
723 |
{ |
724 |
if (!check_if_savable()) return false; |
725 |
if (!file_is_shared && !file_has_name) return file_save_as(); |
726 |
|
727 |
std::cout << "Saving file\n" << std::flush; |
728 |
file_structure_to_be_changed_signal.emit(this->file); |
729 |
try { |
730 |
file->Save(); |
731 |
if (file_is_changed) { |
732 |
set_title(get_title().substr(1)); |
733 |
file_is_changed = false; |
734 |
} |
735 |
} catch (RIFF::Exception e) { |
736 |
file_structure_changed_signal.emit(this->file); |
737 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
738 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
739 |
msg.run(); |
740 |
return false; |
741 |
} |
742 |
std::cout << "Saving file done\n" << std::flush; |
743 |
__import_queued_samples(); |
744 |
file_structure_changed_signal.emit(this->file); |
745 |
return true; |
746 |
} |
747 |
|
748 |
void MainWindow::on_action_file_save_as() |
749 |
{ |
750 |
if (!check_if_savable()) return; |
751 |
file_save_as(); |
752 |
} |
753 |
|
754 |
bool MainWindow::file_save_as() |
755 |
{ |
756 |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
757 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
758 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
759 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
760 |
dialog.set_do_overwrite_confirmation(); |
761 |
|
762 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
763 |
Gtk::FileFilter filter; |
764 |
filter.add_pattern("*.gig"); |
765 |
#else |
766 |
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
767 |
filter->add_pattern("*.gig"); |
768 |
#endif |
769 |
dialog.set_filter(filter); |
770 |
|
771 |
// set initial dir and filename of the Save As dialog |
772 |
// and prepare that initial filename as a copy of the gig |
773 |
{ |
774 |
std::string basename = Glib::path_get_basename(filename); |
775 |
std::string dir = Glib::path_get_dirname(filename); |
776 |
basename = std::string(_("copy_of_")) + basename; |
777 |
Glib::ustring copyFileName = Glib::build_filename(dir, basename); |
778 |
if (Glib::path_is_absolute(filename)) { |
779 |
dialog.set_filename(copyFileName); |
780 |
} else { |
781 |
if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir); |
782 |
} |
783 |
dialog.set_current_name(Glib::filename_display_basename(copyFileName)); |
784 |
} |
785 |
|
786 |
// show warning in the dialog |
787 |
Gtk::HBox descriptionArea; |
788 |
descriptionArea.set_spacing(15); |
789 |
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
790 |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
791 |
#if GTKMM_MAJOR_VERSION < 3 |
792 |
view::WrapLabel description; |
793 |
#else |
794 |
Gtk::Label description; |
795 |
description.set_line_wrap(); |
796 |
#endif |
797 |
description.set_markup( |
798 |
_("\n<b>CAUTION:</b> You <b>MUST</b> use the " |
799 |
"<span style=\"italic\">\"Save\"</span> dialog instead of " |
800 |
"<span style=\"italic\">\"Save As...\"</span> if you want to save " |
801 |
"to the same .gig file. Using " |
802 |
"<span style=\"italic\">\"Save As...\"</span> for writing to the " |
803 |
"same .gig file will end up in corrupted sample wave data!\n") |
804 |
); |
805 |
descriptionArea.pack_start(description); |
806 |
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
807 |
descriptionArea.show_all(); |
808 |
|
809 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
810 |
file_structure_to_be_changed_signal.emit(this->file); |
811 |
try { |
812 |
std::string filename = dialog.get_filename(); |
813 |
if (!Glib::str_has_suffix(filename, ".gig")) { |
814 |
filename += ".gig"; |
815 |
} |
816 |
printf("filename=%s\n", filename.c_str()); |
817 |
file->Save(filename); |
818 |
this->filename = filename; |
819 |
current_gig_dir = Glib::path_get_dirname(filename); |
820 |
set_title(Glib::filename_display_basename(filename)); |
821 |
file_has_name = true; |
822 |
file_is_changed = false; |
823 |
} catch (RIFF::Exception e) { |
824 |
file_structure_changed_signal.emit(this->file); |
825 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
826 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
827 |
msg.run(); |
828 |
return false; |
829 |
} |
830 |
__import_queued_samples(); |
831 |
file_structure_changed_signal.emit(this->file); |
832 |
return true; |
833 |
} |
834 |
return false; |
835 |
} |
836 |
|
837 |
// actually write the sample(s)' data to the gig file |
838 |
void MainWindow::__import_queued_samples() { |
839 |
std::cout << "Starting sample import\n" << std::flush; |
840 |
Glib::ustring error_files; |
841 |
printf("Samples to import: %d\n", m_SampleImportQueue.size()); |
842 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
843 |
iter != m_SampleImportQueue.end(); ) { |
844 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
845 |
SF_INFO info; |
846 |
info.format = 0; |
847 |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
848 |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
849 |
try { |
850 |
if (!hFile) throw std::string(_("could not open file")); |
851 |
// determine sample's bit depth |
852 |
int bitdepth; |
853 |
switch (info.format & 0xff) { |
854 |
case SF_FORMAT_PCM_S8: |
855 |
case SF_FORMAT_PCM_16: |
856 |
case SF_FORMAT_PCM_U8: |
857 |
bitdepth = 16; |
858 |
break; |
859 |
case SF_FORMAT_PCM_24: |
860 |
case SF_FORMAT_PCM_32: |
861 |
case SF_FORMAT_FLOAT: |
862 |
case SF_FORMAT_DOUBLE: |
863 |
bitdepth = 24; |
864 |
break; |
865 |
default: |
866 |
sf_close(hFile); // close sound file |
867 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
868 |
} |
869 |
|
870 |
const int bufsize = 10000; |
871 |
switch (bitdepth) { |
872 |
case 16: { |
873 |
short* buffer = new short[bufsize * info.channels]; |
874 |
sf_count_t cnt = info.frames; |
875 |
while (cnt) { |
876 |
// libsndfile does the conversion for us (if needed) |
877 |
int n = sf_readf_short(hFile, buffer, bufsize); |
878 |
// write from buffer directly (physically) into .gig file |
879 |
iter->gig_sample->Write(buffer, n); |
880 |
cnt -= n; |
881 |
} |
882 |
delete[] buffer; |
883 |
break; |
884 |
} |
885 |
case 24: { |
886 |
int* srcbuf = new int[bufsize * info.channels]; |
887 |
uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels]; |
888 |
sf_count_t cnt = info.frames; |
889 |
while (cnt) { |
890 |
// libsndfile returns 32 bits, convert to 24 |
891 |
int n = sf_readf_int(hFile, srcbuf, bufsize); |
892 |
int j = 0; |
893 |
for (int i = 0 ; i < n * info.channels ; i++) { |
894 |
dstbuf[j++] = srcbuf[i] >> 8; |
895 |
dstbuf[j++] = srcbuf[i] >> 16; |
896 |
dstbuf[j++] = srcbuf[i] >> 24; |
897 |
} |
898 |
// write from buffer directly (physically) into .gig file |
899 |
iter->gig_sample->Write(dstbuf, n); |
900 |
cnt -= n; |
901 |
} |
902 |
delete[] srcbuf; |
903 |
delete[] dstbuf; |
904 |
break; |
905 |
} |
906 |
} |
907 |
// cleanup |
908 |
sf_close(hFile); |
909 |
// let the sampler re-cache the sample if needed |
910 |
sample_changed_signal.emit(iter->gig_sample); |
911 |
// on success we remove the sample from the import queue, |
912 |
// otherwise keep it, maybe it works the next time ? |
913 |
std::list<SampleImportItem>::iterator cur = iter; |
914 |
++iter; |
915 |
m_SampleImportQueue.erase(cur); |
916 |
} catch (std::string what) { |
917 |
// remember the files that made trouble (and their cause) |
918 |
if (!error_files.empty()) error_files += "\n"; |
919 |
error_files += (*iter).sample_path += " (" + what + ")"; |
920 |
++iter; |
921 |
} |
922 |
} |
923 |
// show error message box when some sample(s) could not be imported |
924 |
if (!error_files.empty()) { |
925 |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
926 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
927 |
msg.run(); |
928 |
} |
929 |
} |
930 |
|
931 |
void MainWindow::on_action_file_properties() |
932 |
{ |
933 |
propDialog.show(); |
934 |
propDialog.deiconify(); |
935 |
} |
936 |
|
937 |
void MainWindow::on_action_help_about() |
938 |
{ |
939 |
Gtk::AboutDialog dialog; |
940 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2 |
941 |
dialog.set_program_name("Gigedit"); |
942 |
#else |
943 |
dialog.set_name("Gigedit"); |
944 |
#endif |
945 |
dialog.set_version(VERSION); |
946 |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
947 |
const std::string sComment = |
948 |
_("Built " __DATE__ "\nUsing ") + |
949 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
950 |
_( |
951 |
"Gigedit is released under the GNU General Public License.\n" |
952 |
"\n" |
953 |
"Please notice that this is still a very young instrument editor. " |
954 |
"So better backup your Gigasampler files before editing them with " |
955 |
"this application.\n" |
956 |
"\n" |
957 |
"Please report bugs to: http://bugs.linuxsampler.org" |
958 |
); |
959 |
dialog.set_comments(sComment.c_str()); |
960 |
dialog.set_website("http://www.linuxsampler.org"); |
961 |
dialog.set_website_label("http://www.linuxsampler.org"); |
962 |
dialog.run(); |
963 |
} |
964 |
|
965 |
PropDialog::PropDialog() |
966 |
: eName(_("Name")), |
967 |
eCreationDate(_("Creation date")), |
968 |
eComments(_("Comments")), |
969 |
eProduct(_("Product")), |
970 |
eCopyright(_("Copyright")), |
971 |
eArtists(_("Artists")), |
972 |
eGenre(_("Genre")), |
973 |
eKeywords(_("Keywords")), |
974 |
eEngineer(_("Engineer")), |
975 |
eTechnician(_("Technician")), |
976 |
eSoftware(_("Software")), |
977 |
eMedium(_("Medium")), |
978 |
eSource(_("Source")), |
979 |
eSourceForm(_("Source form")), |
980 |
eCommissioned(_("Commissioned")), |
981 |
eSubject(_("Subject")), |
982 |
quitButton(Gtk::Stock::CLOSE), |
983 |
table(2, 1) |
984 |
{ |
985 |
set_title(_("File Properties")); |
986 |
eName.set_width_chars(50); |
987 |
|
988 |
connect(eName, &DLS::Info::Name); |
989 |
connect(eCreationDate, &DLS::Info::CreationDate); |
990 |
connect(eComments, &DLS::Info::Comments); |
991 |
connect(eProduct, &DLS::Info::Product); |
992 |
connect(eCopyright, &DLS::Info::Copyright); |
993 |
connect(eArtists, &DLS::Info::Artists); |
994 |
connect(eGenre, &DLS::Info::Genre); |
995 |
connect(eKeywords, &DLS::Info::Keywords); |
996 |
connect(eEngineer, &DLS::Info::Engineer); |
997 |
connect(eTechnician, &DLS::Info::Technician); |
998 |
connect(eSoftware, &DLS::Info::Software); |
999 |
connect(eMedium, &DLS::Info::Medium); |
1000 |
connect(eSource, &DLS::Info::Source); |
1001 |
connect(eSourceForm, &DLS::Info::SourceForm); |
1002 |
connect(eCommissioned, &DLS::Info::Commissioned); |
1003 |
connect(eSubject, &DLS::Info::Subject); |
1004 |
|
1005 |
table.add(eName); |
1006 |
table.add(eCreationDate); |
1007 |
table.add(eComments); |
1008 |
table.add(eProduct); |
1009 |
table.add(eCopyright); |
1010 |
table.add(eArtists); |
1011 |
table.add(eGenre); |
1012 |
table.add(eKeywords); |
1013 |
table.add(eEngineer); |
1014 |
table.add(eTechnician); |
1015 |
table.add(eSoftware); |
1016 |
table.add(eMedium); |
1017 |
table.add(eSource); |
1018 |
table.add(eSourceForm); |
1019 |
table.add(eCommissioned); |
1020 |
table.add(eSubject); |
1021 |
|
1022 |
table.set_col_spacings(5); |
1023 |
add(vbox); |
1024 |
table.set_border_width(5); |
1025 |
vbox.add(table); |
1026 |
vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); |
1027 |
buttonBox.set_layout(Gtk::BUTTONBOX_END); |
1028 |
buttonBox.set_border_width(5); |
1029 |
buttonBox.show(); |
1030 |
buttonBox.pack_start(quitButton); |
1031 |
quitButton.set_can_default(); |
1032 |
quitButton.grab_focus(); |
1033 |
quitButton.signal_clicked().connect( |
1034 |
sigc::mem_fun(*this, &PropDialog::hide)); |
1035 |
|
1036 |
quitButton.show(); |
1037 |
vbox.show(); |
1038 |
show_all_children(); |
1039 |
} |
1040 |
|
1041 |
void PropDialog::set_info(DLS::Info* info) |
1042 |
{ |
1043 |
update(info); |
1044 |
} |
1045 |
|
1046 |
|
1047 |
void InstrumentProps::set_Name(const gig::String& name) |
1048 |
{ |
1049 |
m->pInfo->Name = name; |
1050 |
} |
1051 |
|
1052 |
void InstrumentProps::update_name() |
1053 |
{ |
1054 |
update_model++; |
1055 |
eName.set_value(m->pInfo->Name); |
1056 |
update_model--; |
1057 |
} |
1058 |
|
1059 |
void InstrumentProps::set_IsDrum(bool value) |
1060 |
{ |
1061 |
m->IsDrum = value; |
1062 |
} |
1063 |
|
1064 |
void InstrumentProps::set_MIDIBank(uint16_t value) |
1065 |
{ |
1066 |
m->MIDIBank = value; |
1067 |
} |
1068 |
|
1069 |
void InstrumentProps::set_MIDIProgram(uint32_t value) |
1070 |
{ |
1071 |
m->MIDIProgram = value; |
1072 |
} |
1073 |
|
1074 |
InstrumentProps::InstrumentProps() : |
1075 |
quitButton(Gtk::Stock::CLOSE), |
1076 |
table(2,1), |
1077 |
eName(_("Name")), |
1078 |
eIsDrum(_("Is drum")), |
1079 |
eMIDIBank(_("MIDI bank"), 0, 16383), |
1080 |
eMIDIProgram(_("MIDI program")), |
1081 |
eAttenuation(_("Attenuation"), 0, 96, 0, 1), |
1082 |
eGainPlus6(_("Gain +6dB"), eAttenuation, -6), |
1083 |
eEffectSend(_("Effect send"), 0, 65535), |
1084 |
eFineTune(_("Fine tune"), -8400, 8400), |
1085 |
ePitchbendRange(_("Pitchbend range"), 0, 12), |
1086 |
ePianoReleaseMode(_("Piano release mode")), |
1087 |
eDimensionKeyRangeLow(_("Keyswitching range low")), |
1088 |
eDimensionKeyRangeHigh(_("Keyswitching range high")) |
1089 |
{ |
1090 |
set_title(_("Instrument Properties")); |
1091 |
|
1092 |
eDimensionKeyRangeLow.set_tip( |
1093 |
_("start of the keyboard area which should switch the " |
1094 |
"\"keyswitching\" dimension") |
1095 |
); |
1096 |
eDimensionKeyRangeHigh.set_tip( |
1097 |
_("end of the keyboard area which should switch the " |
1098 |
"\"keyswitching\" dimension") |
1099 |
); |
1100 |
|
1101 |
connect(eName, &InstrumentProps::set_Name); |
1102 |
connect(eIsDrum, &InstrumentProps::set_IsDrum); |
1103 |
connect(eMIDIBank, &InstrumentProps::set_MIDIBank); |
1104 |
connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); |
1105 |
connect(eAttenuation, &gig::Instrument::Attenuation); |
1106 |
connect(eGainPlus6, &gig::Instrument::Attenuation); |
1107 |
connect(eEffectSend, &gig::Instrument::EffectSend); |
1108 |
connect(eFineTune, &gig::Instrument::FineTune); |
1109 |
connect(ePitchbendRange, &gig::Instrument::PitchbendRange); |
1110 |
connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode); |
1111 |
connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, |
1112 |
&gig::Instrument::DimensionKeyRange); |
1113 |
|
1114 |
eName.signal_value_changed().connect(sig_name_changed.make_slot()); |
1115 |
|
1116 |
table.set_col_spacings(5); |
1117 |
|
1118 |
table.add(eName); |
1119 |
table.add(eIsDrum); |
1120 |
table.add(eMIDIBank); |
1121 |
table.add(eMIDIProgram); |
1122 |
table.add(eAttenuation); |
1123 |
table.add(eGainPlus6); |
1124 |
table.add(eEffectSend); |
1125 |
table.add(eFineTune); |
1126 |
table.add(ePitchbendRange); |
1127 |
table.add(ePianoReleaseMode); |
1128 |
table.add(eDimensionKeyRangeLow); |
1129 |
table.add(eDimensionKeyRangeHigh); |
1130 |
|
1131 |
add(vbox); |
1132 |
table.set_border_width(5); |
1133 |
vbox.pack_start(table); |
1134 |
table.show(); |
1135 |
vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); |
1136 |
buttonBox.set_layout(Gtk::BUTTONBOX_END); |
1137 |
buttonBox.set_border_width(5); |
1138 |
buttonBox.show(); |
1139 |
buttonBox.pack_start(quitButton); |
1140 |
quitButton.set_can_default(); |
1141 |
quitButton.grab_focus(); |
1142 |
|
1143 |
quitButton.signal_clicked().connect( |
1144 |
sigc::mem_fun(*this, &InstrumentProps::hide)); |
1145 |
|
1146 |
quitButton.show(); |
1147 |
vbox.show(); |
1148 |
show_all_children(); |
1149 |
} |
1150 |
|
1151 |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
1152 |
{ |
1153 |
update(instrument); |
1154 |
|
1155 |
update_model++; |
1156 |
eName.set_value(instrument->pInfo->Name); |
1157 |
eIsDrum.set_value(instrument->IsDrum); |
1158 |
eMIDIBank.set_value(instrument->MIDIBank); |
1159 |
eMIDIProgram.set_value(instrument->MIDIProgram); |
1160 |
update_model--; |
1161 |
} |
1162 |
|
1163 |
|
1164 |
void MainWindow::file_changed() |
1165 |
{ |
1166 |
if (file && !file_is_changed) { |
1167 |
set_title("*" + get_title()); |
1168 |
file_is_changed = true; |
1169 |
} |
1170 |
} |
1171 |
|
1172 |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1173 |
{ |
1174 |
file = 0; |
1175 |
set_file_is_shared(isSharedInstrument); |
1176 |
|
1177 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
1178 |
set_title(Glib::filename_display_basename(this->filename)); |
1179 |
file_has_name = filename; |
1180 |
file_is_changed = false; |
1181 |
|
1182 |
propDialog.set_info(gig->pInfo); |
1183 |
|
1184 |
instrument_name_connection.block(); |
1185 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
1186 |
instrument = gig->GetNextInstrument()) { |
1187 |
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1188 |
|
1189 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
1190 |
Gtk::TreeModel::Row row = *iter; |
1191 |
row[m_Columns.m_col_name] = name; |
1192 |
row[m_Columns.m_col_instr] = instrument; |
1193 |
|
1194 |
add_instrument_to_menu(name); |
1195 |
} |
1196 |
instrument_name_connection.unblock(); |
1197 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
1198 |
|
1199 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1200 |
if (group->Name != "") { |
1201 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1202 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1203 |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
1204 |
rowGroup[m_SamplesModel.m_col_group] = group; |
1205 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1206 |
for (gig::Sample* sample = group->GetFirstSample(); |
1207 |
sample; sample = group->GetNextSample()) { |
1208 |
Gtk::TreeModel::iterator iterSample = |
1209 |
m_refSamplesTreeModel->append(rowGroup.children()); |
1210 |
Gtk::TreeModel::Row rowSample = *iterSample; |
1211 |
rowSample[m_SamplesModel.m_col_name] = |
1212 |
gig_to_utf8(sample->pInfo->Name); |
1213 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1214 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1215 |
} |
1216 |
} |
1217 |
} |
1218 |
|
1219 |
file = gig; |
1220 |
|
1221 |
// select the first instrument |
1222 |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
1223 |
|
1224 |
instr_props_set_instrument(); |
1225 |
gig::Instrument* instrument = get_instrument(); |
1226 |
if (instrument) { |
1227 |
midiRules.set_instrument(instrument); |
1228 |
} |
1229 |
} |
1230 |
|
1231 |
bool MainWindow::instr_props_set_instrument() |
1232 |
{ |
1233 |
instrumentProps.signal_name_changed().clear(); |
1234 |
|
1235 |
Gtk::TreeModel::const_iterator it = |
1236 |
m_TreeView.get_selection()->get_selected(); |
1237 |
if (it) { |
1238 |
Gtk::TreeModel::Row row = *it; |
1239 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1240 |
|
1241 |
instrumentProps.set_instrument(instrument); |
1242 |
|
1243 |
// make sure instrument tree is updated when user changes the |
1244 |
// instrument name in instrument properties window |
1245 |
instrumentProps.signal_name_changed().connect( |
1246 |
sigc::bind( |
1247 |
sigc::mem_fun(*this, |
1248 |
&MainWindow::instr_name_changed_by_instr_props), |
1249 |
it)); |
1250 |
} else { |
1251 |
instrumentProps.hide(); |
1252 |
} |
1253 |
return it; |
1254 |
} |
1255 |
|
1256 |
void MainWindow::show_instr_props() |
1257 |
{ |
1258 |
if (instr_props_set_instrument()) { |
1259 |
instrumentProps.show(); |
1260 |
instrumentProps.deiconify(); |
1261 |
} |
1262 |
} |
1263 |
|
1264 |
void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it) |
1265 |
{ |
1266 |
Gtk::TreeModel::Row row = *it; |
1267 |
Glib::ustring name = row[m_Columns.m_col_name]; |
1268 |
|
1269 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1270 |
Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name)); |
1271 |
if (gigname != name) { |
1272 |
row[m_Columns.m_col_name] = gigname; |
1273 |
} |
1274 |
} |
1275 |
|
1276 |
void MainWindow::show_midi_rules() |
1277 |
{ |
1278 |
if (gig::Instrument* instrument = get_instrument()) |
1279 |
{ |
1280 |
midiRules.set_instrument(instrument); |
1281 |
midiRules.show(); |
1282 |
midiRules.deiconify(); |
1283 |
} |
1284 |
} |
1285 |
|
1286 |
void MainWindow::on_action_view_status_bar() { |
1287 |
Gtk::CheckMenuItem* item = |
1288 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1289 |
if (!item) { |
1290 |
std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n"; |
1291 |
return; |
1292 |
} |
1293 |
if (item->get_active()) m_StatusBar.show(); |
1294 |
else m_StatusBar.hide(); |
1295 |
} |
1296 |
|
1297 |
bool MainWindow::is_copy_samples_unity_note_enabled() const { |
1298 |
Gtk::CheckMenuItem* item = |
1299 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
1300 |
if (!item) { |
1301 |
std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n"; |
1302 |
return true; |
1303 |
} |
1304 |
return item->get_active(); |
1305 |
} |
1306 |
|
1307 |
bool MainWindow::is_copy_samples_fine_tune_enabled() const { |
1308 |
Gtk::CheckMenuItem* item = |
1309 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
1310 |
if (!item) { |
1311 |
std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n"; |
1312 |
return true; |
1313 |
} |
1314 |
return item->get_active(); |
1315 |
} |
1316 |
|
1317 |
bool MainWindow::is_copy_samples_loop_enabled() const { |
1318 |
Gtk::CheckMenuItem* item = |
1319 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
1320 |
if (!item) { |
1321 |
std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n"; |
1322 |
return true; |
1323 |
} |
1324 |
return item->get_active(); |
1325 |
} |
1326 |
|
1327 |
void MainWindow::on_button_release(GdkEventButton* button) |
1328 |
{ |
1329 |
if (button->type == GDK_2BUTTON_PRESS) { |
1330 |
show_instr_props(); |
1331 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1332 |
// gig v2 files have no midi rules |
1333 |
static_cast<Gtk::MenuItem*>( |
1334 |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1335 |
!(file->pVersion && file->pVersion->major == 2)); |
1336 |
popup_menu->popup(button->button, button->time); |
1337 |
} |
1338 |
} |
1339 |
|
1340 |
void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) { |
1341 |
if (item->get_active()) { |
1342 |
const std::vector<Gtk::Widget*> children = |
1343 |
instrument_menu->get_children(); |
1344 |
std::vector<Gtk::Widget*>::const_iterator it = |
1345 |
find(children.begin(), children.end(), item); |
1346 |
if (it != children.end()) { |
1347 |
int index = it - children.begin(); |
1348 |
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index))); |
1349 |
|
1350 |
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
1351 |
} |
1352 |
} |
1353 |
} |
1354 |
|
1355 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
1356 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1357 |
Gtk::Menu* sample_popup = |
1358 |
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu")); |
1359 |
// update enabled/disabled state of sample popup items |
1360 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1361 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1362 |
bool group_selected = false; |
1363 |
bool sample_selected = false; |
1364 |
if (it) { |
1365 |
Gtk::TreeModel::Row row = *it; |
1366 |
group_selected = row[m_SamplesModel.m_col_group]; |
1367 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
1368 |
} |
1369 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
1370 |
set_sensitive(group_selected || sample_selected); |
1371 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
1372 |
set_sensitive(group_selected || sample_selected); |
1373 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
1374 |
set_sensitive(file); |
1375 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
1376 |
set_sensitive(group_selected || sample_selected); |
1377 |
// show sample popup |
1378 |
sample_popup->popup(button->button, button->time); |
1379 |
} |
1380 |
} |
1381 |
|
1382 |
|
1383 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1384 |
const Glib::ustring& name, int position) { |
1385 |
|
1386 |
Gtk::RadioMenuItem::Group instrument_group; |
1387 |
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
1388 |
if (!children.empty()) { |
1389 |
instrument_group = |
1390 |
static_cast<Gtk::RadioMenuItem*>(children[0])->get_group(); |
1391 |
} |
1392 |
Gtk::RadioMenuItem* item = |
1393 |
new Gtk::RadioMenuItem(instrument_group, name); |
1394 |
if (position < 0) { |
1395 |
instrument_menu->append(*item); |
1396 |
} else { |
1397 |
instrument_menu->insert(*item, position); |
1398 |
} |
1399 |
item->show(); |
1400 |
item->signal_activate().connect( |
1401 |
sigc::bind( |
1402 |
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
1403 |
item)); |
1404 |
return item; |
1405 |
} |
1406 |
|
1407 |
void MainWindow::remove_instrument_from_menu(int index) { |
1408 |
const std::vector<Gtk::Widget*> children = |
1409 |
instrument_menu->get_children(); |
1410 |
Gtk::Widget* child = children[index]; |
1411 |
instrument_menu->remove(*child); |
1412 |
delete child; |
1413 |
} |
1414 |
|
1415 |
void MainWindow::add_instrument(gig::Instrument* instrument) { |
1416 |
const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1417 |
|
1418 |
// update instrument tree view |
1419 |
instrument_name_connection.block(); |
1420 |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
1421 |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
1422 |
rowInstr[m_Columns.m_col_name] = name; |
1423 |
rowInstr[m_Columns.m_col_instr] = instrument; |
1424 |
instrument_name_connection.unblock(); |
1425 |
|
1426 |
add_instrument_to_menu(name); |
1427 |
|
1428 |
m_TreeView.get_selection()->select(iterInstr); |
1429 |
|
1430 |
file_changed(); |
1431 |
} |
1432 |
|
1433 |
void MainWindow::on_action_add_instrument() { |
1434 |
static int __instrument_indexer = 0; |
1435 |
if (!file) return; |
1436 |
gig::Instrument* instrument = file->AddInstrument(); |
1437 |
__instrument_indexer++; |
1438 |
instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") + |
1439 |
ToString(__instrument_indexer)); |
1440 |
|
1441 |
add_instrument(instrument); |
1442 |
} |
1443 |
|
1444 |
void MainWindow::on_action_duplicate_instrument() { |
1445 |
if (!file) return; |
1446 |
|
1447 |
// retrieve the currently selected instrument |
1448 |
// (being the original instrument to be duplicated) |
1449 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1450 |
Gtk::TreeModel::iterator itSelection = sel->get_selected(); |
1451 |
if (!itSelection) return; |
1452 |
Gtk::TreeModel::Row row = *itSelection; |
1453 |
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
1454 |
if (!instrOrig) return; |
1455 |
|
1456 |
// duplicate the orginal instrument |
1457 |
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
1458 |
instrNew->pInfo->Name = |
1459 |
instrOrig->pInfo->Name + |
1460 |
gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); |
1461 |
|
1462 |
add_instrument(instrNew); |
1463 |
} |
1464 |
|
1465 |
void MainWindow::on_action_remove_instrument() { |
1466 |
if (!file) return; |
1467 |
if (file_is_shared) { |
1468 |
Gtk::MessageDialog msg( |
1469 |
*this, |
1470 |
_("You cannot delete an instrument from this file, since it's " |
1471 |
"currently used by the sampler."), |
1472 |
false, Gtk::MESSAGE_INFO |
1473 |
); |
1474 |
msg.run(); |
1475 |
return; |
1476 |
} |
1477 |
|
1478 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1479 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1480 |
if (it) { |
1481 |
Gtk::TreeModel::Row row = *it; |
1482 |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
1483 |
try { |
1484 |
Gtk::TreePath path(it); |
1485 |
int index = path[0]; |
1486 |
|
1487 |
// remove instrument from the gig file |
1488 |
if (instr) file->DeleteInstrument(instr); |
1489 |
file_changed(); |
1490 |
|
1491 |
remove_instrument_from_menu(index); |
1492 |
|
1493 |
// remove row from instruments tree view |
1494 |
m_refTreeModel->erase(it); |
1495 |
|
1496 |
#if GTKMM_MAJOR_VERSION < 3 |
1497 |
// select another instrument (in gtk3 this is done |
1498 |
// automatically) |
1499 |
if (!m_refTreeModel->children().empty()) { |
1500 |
if (index == m_refTreeModel->children().size()) { |
1501 |
index--; |
1502 |
} |
1503 |
m_TreeView.get_selection()->select( |
1504 |
Gtk::TreePath(ToString(index))); |
1505 |
} |
1506 |
#endif |
1507 |
instr_props_set_instrument(); |
1508 |
instr = get_instrument(); |
1509 |
if (instr) { |
1510 |
midiRules.set_instrument(instr); |
1511 |
} else { |
1512 |
midiRules.hide(); |
1513 |
} |
1514 |
} catch (RIFF::Exception e) { |
1515 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1516 |
msg.run(); |
1517 |
} |
1518 |
} |
1519 |
} |
1520 |
|
1521 |
void MainWindow::on_action_sample_properties() { |
1522 |
//TODO: show a dialog where the selected sample's properties can be edited |
1523 |
Gtk::MessageDialog msg( |
1524 |
*this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO |
1525 |
); |
1526 |
msg.run(); |
1527 |
} |
1528 |
|
1529 |
void MainWindow::on_action_add_group() { |
1530 |
static int __sample_indexer = 0; |
1531 |
if (!file) return; |
1532 |
gig::Group* group = file->AddGroup(); |
1533 |
group->Name = gig_from_utf8(_("Unnamed Group")); |
1534 |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
1535 |
__sample_indexer++; |
1536 |
// update sample tree view |
1537 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1538 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1539 |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
1540 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1541 |
rowGroup[m_SamplesModel.m_col_group] = group; |
1542 |
file_changed(); |
1543 |
} |
1544 |
|
1545 |
void MainWindow::on_action_add_sample() { |
1546 |
if (!file) return; |
1547 |
// get selected group |
1548 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1549 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1550 |
if (!it) return; |
1551 |
Gtk::TreeModel::Row row = *it; |
1552 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
1553 |
if (!group) { // not a group, but a sample is selected (probably) |
1554 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
1555 |
if (!sample) return; |
1556 |
it = row.parent(); // resolve parent (that is the sample's group) |
1557 |
if (!it) return; |
1558 |
row = *it; |
1559 |
group = row[m_SamplesModel.m_col_group]; |
1560 |
if (!group) return; |
1561 |
} |
1562 |
// show 'browse for file' dialog |
1563 |
Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)")); |
1564 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1565 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
1566 |
dialog.set_select_multiple(true); |
1567 |
|
1568 |
// matches all file types supported by libsndfile |
1569 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1570 |
Gtk::FileFilter soundfilter; |
1571 |
#else |
1572 |
Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create(); |
1573 |
#endif |
1574 |
const char* const supportedFileTypes[] = { |
1575 |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
1576 |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
1577 |
"*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64", |
1578 |
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
1579 |
"*.caf", "*.CAF", NULL |
1580 |
}; |
1581 |
const char* soundfiles = _("Sound Files"); |
1582 |
const char* allfiles = _("All Files"); |
1583 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1584 |
for (int i = 0; supportedFileTypes[i]; i++) |
1585 |
soundfilter.add_pattern(supportedFileTypes[i]); |
1586 |
soundfilter.set_name(soundfiles); |
1587 |
|
1588 |
// matches every file |
1589 |
Gtk::FileFilter allpassfilter; |
1590 |
allpassfilter.add_pattern("*.*"); |
1591 |
allpassfilter.set_name(allfiles); |
1592 |
#else |
1593 |
for (int i = 0; supportedFileTypes[i]; i++) |
1594 |
soundfilter->add_pattern(supportedFileTypes[i]); |
1595 |
soundfilter->set_name(soundfiles); |
1596 |
|
1597 |
// matches every file |
1598 |
Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create(); |
1599 |
allpassfilter->add_pattern("*.*"); |
1600 |
allpassfilter->set_name(allfiles); |
1601 |
#endif |
1602 |
dialog.add_filter(soundfilter); |
1603 |
dialog.add_filter(allpassfilter); |
1604 |
if (current_sample_dir != "") { |
1605 |
dialog.set_current_folder(current_sample_dir); |
1606 |
} |
1607 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1608 |
current_sample_dir = dialog.get_current_folder(); |
1609 |
Glib::ustring error_files; |
1610 |
std::vector<std::string> filenames = dialog.get_filenames(); |
1611 |
for (std::vector<std::string>::iterator iter = filenames.begin(); |
1612 |
iter != filenames.end(); ++iter) { |
1613 |
printf("Adding sample %s\n",(*iter).c_str()); |
1614 |
// use libsndfile to retrieve file informations |
1615 |
SF_INFO info; |
1616 |
info.format = 0; |
1617 |
SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); |
1618 |
try { |
1619 |
if (!hFile) throw std::string(_("could not open file")); |
1620 |
int bitdepth; |
1621 |
switch (info.format & 0xff) { |
1622 |
case SF_FORMAT_PCM_S8: |
1623 |
case SF_FORMAT_PCM_16: |
1624 |
case SF_FORMAT_PCM_U8: |
1625 |
bitdepth = 16; |
1626 |
break; |
1627 |
case SF_FORMAT_PCM_24: |
1628 |
case SF_FORMAT_PCM_32: |
1629 |
case SF_FORMAT_FLOAT: |
1630 |
case SF_FORMAT_DOUBLE: |
1631 |
bitdepth = 24; |
1632 |
break; |
1633 |
default: |
1634 |
sf_close(hFile); // close sound file |
1635 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1636 |
} |
1637 |
// add a new sample to the .gig file |
1638 |
gig::Sample* sample = file->AddSample(); |
1639 |
// file name without path |
1640 |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
1641 |
// remove file extension if there is one |
1642 |
for (int i = 0; supportedFileTypes[i]; i++) { |
1643 |
if (Glib::str_has_suffix(filename, supportedFileTypes[i] + 1)) { |
1644 |
filename.erase(filename.length() - strlen(supportedFileTypes[i] + 1)); |
1645 |
break; |
1646 |
} |
1647 |
} |
1648 |
sample->pInfo->Name = gig_from_utf8(filename); |
1649 |
sample->Channels = info.channels; |
1650 |
sample->BitDepth = bitdepth; |
1651 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
1652 |
sample->SamplesPerSecond = info.samplerate; |
1653 |
sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond; |
1654 |
sample->BlockAlign = sample->FrameSize; |
1655 |
sample->SamplesTotal = info.frames; |
1656 |
|
1657 |
SF_INSTRUMENT instrument; |
1658 |
if (sf_command(hFile, SFC_GET_INSTRUMENT, |
1659 |
&instrument, sizeof(instrument)) != SF_FALSE) |
1660 |
{ |
1661 |
sample->MIDIUnityNote = instrument.basenote; |
1662 |
sample->FineTune = instrument.detune; |
1663 |
|
1664 |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
1665 |
sample->Loops = 1; |
1666 |
|
1667 |
switch (instrument.loops[0].mode) { |
1668 |
case SF_LOOP_FORWARD: |
1669 |
sample->LoopType = gig::loop_type_normal; |
1670 |
break; |
1671 |
case SF_LOOP_BACKWARD: |
1672 |
sample->LoopType = gig::loop_type_backward; |
1673 |
break; |
1674 |
case SF_LOOP_ALTERNATING: |
1675 |
sample->LoopType = gig::loop_type_bidirectional; |
1676 |
break; |
1677 |
} |
1678 |
sample->LoopStart = instrument.loops[0].start; |
1679 |
sample->LoopEnd = instrument.loops[0].end; |
1680 |
sample->LoopPlayCount = instrument.loops[0].count; |
1681 |
sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; |
1682 |
} |
1683 |
} |
1684 |
|
1685 |
// schedule resizing the sample (which will be done |
1686 |
// physically when File::Save() is called) |
1687 |
sample->Resize(info.frames); |
1688 |
// make sure sample is part of the selected group |
1689 |
group->AddSample(sample); |
1690 |
// schedule that physical resize and sample import |
1691 |
// (data copying), performed when "Save" is requested |
1692 |
SampleImportItem sched_item; |
1693 |
sched_item.gig_sample = sample; |
1694 |
sched_item.sample_path = *iter; |
1695 |
m_SampleImportQueue.push_back(sched_item); |
1696 |
// add sample to the tree view |
1697 |
Gtk::TreeModel::iterator iterSample = |
1698 |
m_refSamplesTreeModel->append(row.children()); |
1699 |
Gtk::TreeModel::Row rowSample = *iterSample; |
1700 |
rowSample[m_SamplesModel.m_col_name] = |
1701 |
gig_to_utf8(sample->pInfo->Name); |
1702 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1703 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1704 |
// close sound file |
1705 |
sf_close(hFile); |
1706 |
file_changed(); |
1707 |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
1708 |
if (!error_files.empty()) error_files += "\n"; |
1709 |
error_files += *iter += " (" + what + ")"; |
1710 |
} |
1711 |
} |
1712 |
// show error message box when some file(s) could not be opened / added |
1713 |
if (!error_files.empty()) { |
1714 |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
1715 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1716 |
msg.run(); |
1717 |
} |
1718 |
} |
1719 |
} |
1720 |
|
1721 |
void MainWindow::on_action_replace_all_samples_in_all_groups() |
1722 |
{ |
1723 |
if (!file) return; |
1724 |
Gtk::FileChooserDialog dialog(*this, _("Select Folder"), |
1725 |
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
1726 |
const char* str = |
1727 |
_("This is a very specific function. It tries to replace all samples " |
1728 |
"in the current gig file by samples located in the chosen " |
1729 |
"directory.\n\n" |
1730 |
"It works like this: For each sample in the gig file, it tries to " |
1731 |
"find a sample file in the selected directory with the same name as " |
1732 |
"the sample in the gig file. Optionally, you can add a filename " |
1733 |
"extension below, which will be added to the filename expected to be " |
1734 |
"found. That is, assume you have a gig file with a sample called " |
1735 |
"'Snare', if you enter '.wav' below (like it's done by default), it " |
1736 |
"expects to find a sample file called 'Snare.wav' and will replace " |
1737 |
"the sample in the gig file accordingly. If you don't need an " |
1738 |
"extension, blank the field below. Any gig sample where no " |
1739 |
"appropriate sample file could be found will be reported and left " |
1740 |
"untouched.\n"); |
1741 |
#if GTKMM_MAJOR_VERSION < 3 |
1742 |
view::WrapLabel description(str); |
1743 |
#else |
1744 |
Gtk::Label description(str); |
1745 |
description.set_line_wrap(); |
1746 |
#endif |
1747 |
Gtk::HBox entryArea; |
1748 |
Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START); |
1749 |
Gtk::Entry postfixEntryBox; |
1750 |
postfixEntryBox.set_text(".wav"); |
1751 |
entryArea.pack_start(entryLabel); |
1752 |
entryArea.pack_start(postfixEntryBox); |
1753 |
dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK); |
1754 |
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
1755 |
description.show(); |
1756 |
entryArea.show_all(); |
1757 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1758 |
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
1759 |
dialog.set_select_multiple(false); |
1760 |
if (current_sample_dir != "") { |
1761 |
dialog.set_current_folder(current_sample_dir); |
1762 |
} |
1763 |
if (dialog.run() == Gtk::RESPONSE_OK) |
1764 |
{ |
1765 |
current_sample_dir = dialog.get_current_folder(); |
1766 |
Glib::ustring error_files; |
1767 |
std::string folder = dialog.get_filename(); |
1768 |
for (gig::Sample* sample = file->GetFirstSample(); |
1769 |
sample; sample = file->GetNextSample()) |
1770 |
{ |
1771 |
std::string filename = |
1772 |
folder + G_DIR_SEPARATOR_S + |
1773 |
Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) + |
1774 |
postfixEntryBox.get_text()); |
1775 |
SF_INFO info; |
1776 |
info.format = 0; |
1777 |
SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); |
1778 |
try |
1779 |
{ |
1780 |
if (!hFile) throw std::string(_("could not open file")); |
1781 |
int bitdepth; |
1782 |
switch (info.format & 0xff) { |
1783 |
case SF_FORMAT_PCM_S8: |
1784 |
case SF_FORMAT_PCM_16: |
1785 |
case SF_FORMAT_PCM_U8: |
1786 |
bitdepth = 16; |
1787 |
break; |
1788 |
case SF_FORMAT_PCM_24: |
1789 |
case SF_FORMAT_PCM_32: |
1790 |
case SF_FORMAT_FLOAT: |
1791 |
case SF_FORMAT_DOUBLE: |
1792 |
bitdepth = 24; |
1793 |
break; |
1794 |
default: |
1795 |
sf_close(hFile); |
1796 |
throw std::string(_("format not supported")); |
1797 |
} |
1798 |
SampleImportItem sched_item; |
1799 |
sched_item.gig_sample = sample; |
1800 |
sched_item.sample_path = filename; |
1801 |
m_SampleImportQueue.push_back(sched_item); |
1802 |
sf_close(hFile); |
1803 |
file_changed(); |
1804 |
} |
1805 |
catch (std::string what) |
1806 |
{ |
1807 |
if (!error_files.empty()) error_files += "\n"; |
1808 |
error_files += Glib::filename_to_utf8(filename) + |
1809 |
" (" + what + ")"; |
1810 |
} |
1811 |
} |
1812 |
// show error message box when some file(s) could not be opened / added |
1813 |
if (!error_files.empty()) { |
1814 |
Glib::ustring txt = |
1815 |
_("Could not replace the following sample(s):\n") + error_files; |
1816 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1817 |
msg.run(); |
1818 |
} |
1819 |
} |
1820 |
} |
1821 |
|
1822 |
void MainWindow::on_action_remove_sample() { |
1823 |
if (!file) return; |
1824 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1825 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1826 |
if (it) { |
1827 |
Gtk::TreeModel::Row row = *it; |
1828 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
1829 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
1830 |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
1831 |
try { |
1832 |
// remove group or sample from the gig file |
1833 |
if (group) { |
1834 |
// temporarily remember the samples that belong to |
1835 |
// that group (we need that to clean the queue) |
1836 |
std::list<gig::Sample*> members; |
1837 |
for (gig::Sample* pSample = group->GetFirstSample(); |
1838 |
pSample; pSample = group->GetNextSample()) { |
1839 |
members.push_back(pSample); |
1840 |
} |
1841 |
// notify everybody that we're going to remove these samples |
1842 |
samples_to_be_removed_signal.emit(members); |
1843 |
// delete the group in the .gig file including the |
1844 |
// samples that belong to the group |
1845 |
file->DeleteGroup(group); |
1846 |
// notify that we're done with removal |
1847 |
samples_removed_signal.emit(); |
1848 |
// if sample(s) were just previously added, remove |
1849 |
// them from the import queue |
1850 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
1851 |
member != members.end(); ++member) { |
1852 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1853 |
iter != m_SampleImportQueue.end(); ++iter) { |
1854 |
if ((*iter).gig_sample == *member) { |
1855 |
printf("Removing previously added sample '%s' from group '%s'\n", |
1856 |
(*iter).sample_path.c_str(), name.c_str()); |
1857 |
m_SampleImportQueue.erase(iter); |
1858 |
break; |
1859 |
} |
1860 |
} |
1861 |
} |
1862 |
file_changed(); |
1863 |
} else if (sample) { |
1864 |
// notify everybody that we're going to remove this sample |
1865 |
std::list<gig::Sample*> lsamples; |
1866 |
lsamples.push_back(sample); |
1867 |
samples_to_be_removed_signal.emit(lsamples); |
1868 |
// remove sample from the .gig file |
1869 |
file->DeleteSample(sample); |
1870 |
// notify that we're done with removal |
1871 |
samples_removed_signal.emit(); |
1872 |
// if sample was just previously added, remove it from |
1873 |
// the import queue |
1874 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1875 |
iter != m_SampleImportQueue.end(); ++iter) { |
1876 |
if ((*iter).gig_sample == sample) { |
1877 |
printf("Removing previously added sample '%s'\n", |
1878 |
(*iter).sample_path.c_str()); |
1879 |
m_SampleImportQueue.erase(iter); |
1880 |
break; |
1881 |
} |
1882 |
} |
1883 |
dimreg_changed(); |
1884 |
file_changed(); |
1885 |
} |
1886 |
// remove respective row(s) from samples tree view |
1887 |
m_refSamplesTreeModel->erase(it); |
1888 |
} catch (RIFF::Exception e) { |
1889 |
// pretend we're done with removal (i.e. to avoid dead locks) |
1890 |
samples_removed_signal.emit(); |
1891 |
// show error message |
1892 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1893 |
msg.run(); |
1894 |
} |
1895 |
} |
1896 |
} |
1897 |
|
1898 |
// For some reason drag_data_get gets called two times for each |
1899 |
// drag'n'drop (at least when target is an Entry). This work-around |
1900 |
// makes sure the code in drag_data_get and drop_drag_data_received is |
1901 |
// only executed once, as drag_begin only gets called once. |
1902 |
void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
1903 |
{ |
1904 |
first_call_to_drag_data_get = true; |
1905 |
} |
1906 |
|
1907 |
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
1908 |
Gtk::SelectionData& selection_data, guint, guint) |
1909 |
{ |
1910 |
if (!first_call_to_drag_data_get) return; |
1911 |
first_call_to_drag_data_get = false; |
1912 |
|
1913 |
// get selected sample |
1914 |
gig::Sample* sample = NULL; |
1915 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1916 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1917 |
if (it) { |
1918 |
Gtk::TreeModel::Row row = *it; |
1919 |
sample = row[m_SamplesModel.m_col_sample]; |
1920 |
} |
1921 |
// pass the gig::Sample as pointer |
1922 |
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, |
1923 |
sizeof(sample)/*length of data in bytes*/); |
1924 |
} |
1925 |
|
1926 |
void MainWindow::on_sample_label_drop_drag_data_received( |
1927 |
const Glib::RefPtr<Gdk::DragContext>& context, int, int, |
1928 |
const Gtk::SelectionData& selection_data, guint, guint time) |
1929 |
{ |
1930 |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
1931 |
|
1932 |
if (sample && selection_data.get_length() == sizeof(gig::Sample*)) { |
1933 |
std::cout << "Drop received sample \"" << |
1934 |
sample->pInfo->Name << "\"" << std::endl; |
1935 |
// drop success |
1936 |
context->drop_reply(true, time); |
1937 |
|
1938 |
//TODO: we should better move most of the following code to DimRegionEdit::set_sample() |
1939 |
|
1940 |
// notify everybody that we're going to alter the region |
1941 |
gig::Region* region = m_RegionChooser.get_region(); |
1942 |
region_to_be_changed_signal.emit(region); |
1943 |
|
1944 |
// find the samplechannel dimension |
1945 |
gig::dimension_def_t* stereo_dimension = 0; |
1946 |
for (int i = 0 ; i < region->Dimensions ; i++) { |
1947 |
if (region->pDimensionDefinitions[i].dimension == |
1948 |
gig::dimension_samplechannel) { |
1949 |
stereo_dimension = ®ion->pDimensionDefinitions[i]; |
1950 |
break; |
1951 |
} |
1952 |
} |
1953 |
bool channels_changed = false; |
1954 |
if (sample->Channels == 1 && stereo_dimension) { |
1955 |
// remove the samplechannel dimension |
1956 |
region->DeleteDimension(stereo_dimension); |
1957 |
channels_changed = true; |
1958 |
region_changed(); |
1959 |
} |
1960 |
dimreg_edit.set_sample( |
1961 |
sample, |
1962 |
is_copy_samples_unity_note_enabled(), |
1963 |
is_copy_samples_fine_tune_enabled(), |
1964 |
is_copy_samples_loop_enabled() |
1965 |
); |
1966 |
|
1967 |
if (sample->Channels == 2 && !stereo_dimension) { |
1968 |
// add samplechannel dimension |
1969 |
gig::dimension_def_t dim; |
1970 |
dim.dimension = gig::dimension_samplechannel; |
1971 |
dim.bits = 1; |
1972 |
dim.zones = 2; |
1973 |
region->AddDimension(&dim); |
1974 |
channels_changed = true; |
1975 |
region_changed(); |
1976 |
} |
1977 |
if (channels_changed) { |
1978 |
// unmap all samples with wrong number of channels |
1979 |
// TODO: maybe there should be a warning dialog for this |
1980 |
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
1981 |
gig::DimensionRegion* d = region->pDimensionRegions[i]; |
1982 |
if (d->pSample && d->pSample->Channels != sample->Channels) { |
1983 |
gig::Sample* oldref = d->pSample; |
1984 |
d->pSample = NULL; |
1985 |
sample_ref_changed_signal.emit(oldref, NULL); |
1986 |
} |
1987 |
} |
1988 |
} |
1989 |
|
1990 |
// notify we're done with altering |
1991 |
region_changed_signal.emit(region); |
1992 |
|
1993 |
file_changed(); |
1994 |
|
1995 |
return; |
1996 |
} |
1997 |
// drop failed |
1998 |
context->drop_reply(false, time); |
1999 |
} |
2000 |
|
2001 |
void MainWindow::sample_name_changed(const Gtk::TreeModel::Path& path, |
2002 |
const Gtk::TreeModel::iterator& iter) { |
2003 |
if (!iter) return; |
2004 |
Gtk::TreeModel::Row row = *iter; |
2005 |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
2006 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2007 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2008 |
gig::String gigname(gig_from_utf8(name)); |
2009 |
if (group) { |
2010 |
if (group->Name != gigname) { |
2011 |
group->Name = gigname; |
2012 |
printf("group name changed\n"); |
2013 |
file_changed(); |
2014 |
} |
2015 |
} else if (sample) { |
2016 |
if (sample->pInfo->Name != gigname) { |
2017 |
sample->pInfo->Name = gigname; |
2018 |
printf("sample name changed\n"); |
2019 |
file_changed(); |
2020 |
} |
2021 |
} |
2022 |
} |
2023 |
|
2024 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
2025 |
const Gtk::TreeModel::iterator& iter) { |
2026 |
if (!iter) return; |
2027 |
Gtk::TreeModel::Row row = *iter; |
2028 |
Glib::ustring name = row[m_Columns.m_col_name]; |
2029 |
|
2030 |
// change name in instrument menu |
2031 |
int index = path[0]; |
2032 |
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
2033 |
if (index < children.size()) { |
2034 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2 |
2035 |
static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name); |
2036 |
#else |
2037 |
remove_instrument_from_menu(index); |
2038 |
Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index); |
2039 |
item->set_active(); |
2040 |
#endif |
2041 |
} |
2042 |
|
2043 |
// change name in gig |
2044 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
2045 |
gig::String gigname(gig_from_utf8(name)); |
2046 |
if (instrument && instrument->pInfo->Name != gigname) { |
2047 |
instrument->pInfo->Name = gigname; |
2048 |
|
2049 |
// change name in the instrument properties window |
2050 |
if (instrumentProps.get_instrument() == instrument) { |
2051 |
instrumentProps.update_name(); |
2052 |
} |
2053 |
|
2054 |
file_changed(); |
2055 |
} |
2056 |
} |
2057 |
|
2058 |
void MainWindow::set_file_is_shared(bool b) { |
2059 |
this->file_is_shared = b; |
2060 |
|
2061 |
if (file_is_shared) { |
2062 |
m_AttachedStateLabel.set_label(_("live-mode")); |
2063 |
m_AttachedStateImage.set( |
2064 |
Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm) |
2065 |
); |
2066 |
} else { |
2067 |
m_AttachedStateLabel.set_label(_("stand-alone")); |
2068 |
m_AttachedStateImage.set( |
2069 |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
2070 |
); |
2071 |
} |
2072 |
} |
2073 |
|
2074 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
2075 |
return file_structure_to_be_changed_signal; |
2076 |
} |
2077 |
|
2078 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() { |
2079 |
return file_structure_changed_signal; |
2080 |
} |
2081 |
|
2082 |
sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() { |
2083 |
return samples_to_be_removed_signal; |
2084 |
} |
2085 |
|
2086 |
sigc::signal<void>& MainWindow::signal_samples_removed() { |
2087 |
return samples_removed_signal; |
2088 |
} |
2089 |
|
2090 |
sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() { |
2091 |
return region_to_be_changed_signal; |
2092 |
} |
2093 |
|
2094 |
sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() { |
2095 |
return region_changed_signal; |
2096 |
} |
2097 |
|
2098 |
sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() { |
2099 |
return sample_changed_signal; |
2100 |
} |
2101 |
|
2102 |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() { |
2103 |
return sample_ref_changed_signal; |
2104 |
} |
2105 |
|
2106 |
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() { |
2107 |
return dimreg_to_be_changed_signal; |
2108 |
} |
2109 |
|
2110 |
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() { |
2111 |
return dimreg_changed_signal; |
2112 |
} |
2113 |
|
2114 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() { |
2115 |
return note_on_signal; |
2116 |
} |
2117 |
|
2118 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() { |
2119 |
return note_off_signal; |
2120 |
} |
2121 |
|
2122 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() { |
2123 |
return m_RegionChooser.signal_keyboard_key_hit(); |
2124 |
} |
2125 |
|
2126 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
2127 |
return m_RegionChooser.signal_keyboard_key_released(); |
2128 |
} |