123 |
sigc::mem_fun( |
sigc::mem_fun( |
124 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
125 |
#endif |
#endif |
126 |
action = Gtk::Action::create("Remove", Gtk::Stock::REMOVE); |
actionGroup->add( |
127 |
actionGroup->add(action, |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
128 |
sigc::mem_fun( |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
129 |
*this, &MainWindow::hide)); |
); |
130 |
|
actionGroup->add( |
131 |
|
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
132 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
133 |
|
); |
134 |
|
|
135 |
// sample right-click popup actions |
// sample right-click popup actions |
136 |
actionGroup->add( |
actionGroup->add( |
178 |
" </menubar>" |
" </menubar>" |
179 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
180 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
181 |
" <menuitem action='Remove'/>" |
" <menuitem action='AddInstrument'/>" |
182 |
|
" <separator/>" |
183 |
|
" <menuitem action='RemoveInstrument'/>" |
184 |
" </popup>" |
" </popup>" |
185 |
" <popup name='SamplePopupMenu'>" |
" <popup name='SamplePopupMenu'>" |
186 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
233 |
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
234 |
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
235 |
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
|
//drag_target_gig_sample.push_back( Gtk::TargetEntry("STRING") ); |
|
|
//drag_target_gig_sample.push_back( Gtk::TargetEntry("text/plain") ); |
|
236 |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
237 |
m_TreeViewSamples.signal_drag_data_get().connect( |
m_TreeViewSamples.signal_drag_data_get().connect( |
238 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
344 |
show_all_children(); |
show_all_children(); |
345 |
} |
} |
346 |
|
|
347 |
|
// Clear all GUI elements / controls. This method is typically called |
348 |
|
// before a new .gig file is to be created or to be loaded. |
349 |
|
void MainWindow::__clear() { |
350 |
|
// remove all entries from "Instrument" menu |
351 |
|
Gtk::MenuItem* instrument_menu = |
352 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
353 |
|
instrument_menu->hide(); |
354 |
|
for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) { |
355 |
|
delete &instrument_menu->get_submenu()->items()[i]; |
356 |
|
} |
357 |
|
instrument_menu->get_submenu()->items().clear(); |
358 |
|
// forget all samples that ought to be imported |
359 |
|
m_SampleImportQueue.clear(); |
360 |
|
// clear the samples and instruments tree views |
361 |
|
m_refTreeModel->clear(); |
362 |
|
m_refSamplesTreeModel->clear(); |
363 |
|
// free libgig's gig::File instance |
364 |
|
if (file) { |
365 |
|
delete file; |
366 |
|
file = NULL; |
367 |
|
} |
368 |
|
} |
369 |
|
|
370 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
371 |
{ |
{ |
372 |
m_SampleImportQueue.clear(); |
// clear all GUI elements |
373 |
|
__clear(); |
374 |
|
// create a new .gig file (virtually yet) |
375 |
|
gig::File* pFile = new gig::File; |
376 |
|
// already add one new instrument by default |
377 |
|
gig::Instrument* pInstrument = pFile->AddInstrument(); |
378 |
|
pInstrument->pInfo->Name = "Unnamed Instrument"; |
379 |
|
// update GUI with that new gig::File |
380 |
|
load_gig(pFile, NULL /*no file name yet*/); |
381 |
} |
} |
382 |
|
|
383 |
void MainWindow::on_action_file_open() |
void MainWindow::on_action_file_open() |
390 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
391 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
392 |
printf("filename=%s\n", dialog.get_filename().c_str()); |
printf("filename=%s\n", dialog.get_filename().c_str()); |
393 |
|
__clear(); |
|
// remove all entries from "Instrument" menu |
|
|
Gtk::MenuItem* instrument_menu = |
|
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
|
|
instrument_menu->hide(); |
|
|
for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) { |
|
|
delete &instrument_menu->get_submenu()->items()[i]; |
|
|
} |
|
|
instrument_menu->get_submenu()->items().clear(); |
|
|
|
|
|
m_SampleImportQueue.clear(); |
|
|
m_refTreeModel->clear(); |
|
|
m_refSamplesTreeModel->clear(); |
|
|
if (file) delete file; |
|
|
|
|
394 |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
395 |
load_file(dialog.get_filename().c_str()); |
load_file(dialog.get_filename().c_str()); |
396 |
} |
} |
419 |
printf("on_loader_finished self=%x\n", Glib::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Thread::self()); |
420 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename); |
421 |
|
|
|
|
|
422 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
423 |
tree_sel_ref->select(Gtk::TreePath("0")); |
tree_sel_ref->select(Gtk::TreePath("0")); |
424 |
|
|
525 |
(*iter).gig_sample->Write(buffer, info.frames); |
(*iter).gig_sample->Write(buffer, info.frames); |
526 |
// cleanup |
// cleanup |
527 |
sf_close(hFile); |
sf_close(hFile); |
528 |
delete buffer; |
delete[] buffer; |
529 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
530 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
531 |
std::list<SampleImportItem>::iterator cur = iter; |
std::list<SampleImportItem>::iterator cur = iter; |
710 |
{ |
{ |
711 |
file = gig; |
file = gig; |
712 |
|
|
713 |
const char *basename = strrchr(filename, '/'); |
if (filename) { |
714 |
basename = basename ? basename + 1 : filename; |
const char *basename = strrchr(filename, '/'); |
715 |
|
basename = basename ? basename + 1 : filename; |
716 |
set_title(basename); |
set_title(basename); |
717 |
|
} else { |
718 |
|
set_title("unnamed"); |
719 |
|
} |
720 |
|
|
721 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
722 |
|
|
822 |
} |
} |
823 |
} |
} |
824 |
|
|
825 |
|
void MainWindow::on_action_add_instrument() { |
826 |
|
static int __instrument_indexer = 0; |
827 |
|
if (!file) return; |
828 |
|
gig::Instrument* instrument = file->AddInstrument(); |
829 |
|
__instrument_indexer++; |
830 |
|
instrument->pInfo->Name = |
831 |
|
"Unnamed Instrument " + ToString(__instrument_indexer); |
832 |
|
// update instrument tree view |
833 |
|
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
834 |
|
Gtk::TreeModel::Row rowInstr = *iterInstr; |
835 |
|
rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
836 |
|
rowInstr[m_Columns.m_col_instr] = instrument; |
837 |
|
} |
838 |
|
|
839 |
|
void MainWindow::on_action_remove_instrument() { |
840 |
|
if (!file) return; |
841 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
842 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
843 |
|
if (it) { |
844 |
|
Gtk::TreeModel::Row row = *it; |
845 |
|
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
846 |
|
try { |
847 |
|
// remove instrument from the gig file |
848 |
|
if (instr) file->DeleteInstrument(instr); |
849 |
|
// remove respective row from instruments tree view |
850 |
|
m_refTreeModel->erase(it); |
851 |
|
} catch (RIFF::Exception e) { |
852 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
853 |
|
msg.run(); |
854 |
|
} |
855 |
|
} |
856 |
|
} |
857 |
|
|
858 |
void MainWindow::on_action_sample_properties() { |
void MainWindow::on_action_sample_properties() { |
859 |
//TODO: show a dialog where the selected sample's properties can be edited |
//TODO: show a dialog where the selected sample's properties can be edited |
860 |
|
Gtk::MessageDialog msg( |
861 |
|
*this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO |
862 |
|
); |
863 |
|
msg.run(); |
864 |
} |
} |
865 |
|
|
866 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |