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