/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2169 - (show annotations) (download)
Sun Mar 6 07:51:04 2011 UTC (13 years ago) by persson
File size: 71621 byte(s)
* ported to gtkmm 3, keeping compatibility with gtkmm 2

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

  ViewVC Help
Powered by ViewVC