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