31 |
|
|
32 |
#define _(String) gettext(String) |
#define _(String) gettext(String) |
33 |
|
|
34 |
|
template<class T> inline std::string ToString(T o) { |
35 |
|
std::stringstream ss; |
36 |
|
ss << o; |
37 |
|
return ss.str(); |
38 |
|
} |
39 |
|
|
40 |
bool update_gui; |
bool update_gui; |
41 |
|
|
42 |
uint8_t& access_UnityNote(gig::DimensionRegion* dimreg) |
uint8_t& access_UnityNote(gig::DimensionRegion* dimreg) |
529 |
m_TreeView.signal_button_press_event().connect_notify( |
m_TreeView.signal_button_press_event().connect_notify( |
530 |
sigc::mem_fun(*this, &MainWindow::on_button_release)); |
sigc::mem_fun(*this, &MainWindow::on_button_release)); |
531 |
|
|
532 |
// Add the TreeView, inside a ScrolledWindow, with the button underneath: |
// Add the TreeView tab, inside a ScrolledWindow, with the button underneath: |
533 |
m_ScrolledWindow.add(m_TreeView); |
m_ScrolledWindow.add(m_TreeViewNotebook); |
534 |
m_ScrolledWindow.set_size_request(400, 600); |
m_ScrolledWindow.set_size_request(400, 600); |
535 |
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
536 |
|
|
789 |
m_HPaned.add2(m_Notebook); |
m_HPaned.add2(m_Notebook); |
790 |
|
|
791 |
|
|
792 |
|
m_TreeViewNotebook.append_page(m_TreeViewSamples, "Samples"); |
793 |
|
m_TreeViewNotebook.append_page(m_TreeView, "Instruments"); |
794 |
|
|
795 |
|
|
796 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
797 |
|
|
798 |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
836 |
sigc::mem_fun( |
sigc::mem_fun( |
837 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
838 |
#endif |
#endif |
839 |
action = Gtk::Action::create("Remove", "Ta bort"); |
action = Gtk::Action::create("Remove", Gtk::Stock::REMOVE); |
840 |
actionGroup->add(action, |
actionGroup->add(action, |
841 |
sigc::mem_fun( |
sigc::mem_fun( |
842 |
*this, &MainWindow::hide)); |
*this, &MainWindow::hide)); |
843 |
|
|
844 |
|
// sample right-click popup actions |
845 |
|
actionGroup->add( |
846 |
|
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
847 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
848 |
|
); |
849 |
|
actionGroup->add( |
850 |
|
Gtk::Action::create("AddGroup", _("Add _Group")), |
851 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
852 |
|
); |
853 |
|
actionGroup->add( |
854 |
|
Gtk::Action::create("AddSample", _("Add _Sample")), |
855 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
856 |
|
); |
857 |
|
actionGroup->add( |
858 |
|
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
859 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
860 |
|
); |
861 |
|
|
862 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
863 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
864 |
// add_accel_group(uiManager->get_accel_group()); |
// add_accel_group(uiManager->get_accel_group()); |
889 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
890 |
" <menuitem action='Remove'/>" |
" <menuitem action='Remove'/>" |
891 |
" </popup>" |
" </popup>" |
892 |
|
" <popup name='SamplePopupMenu'>" |
893 |
|
" <menuitem action='SampleProperties'/>" |
894 |
|
" <menuitem action='AddGroup'/>" |
895 |
|
" <menuitem action='AddSample'/>" |
896 |
|
" <separator/>" |
897 |
|
" <menuitem action='RemoveSample'/>" |
898 |
|
" </popup>" |
899 |
"</ui>"; |
"</ui>"; |
900 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
901 |
|
|
921 |
m_TreeView.append_column("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column("Instrument", m_Columns.m_col_name); |
922 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
923 |
|
|
924 |
|
// create samples treeview (including its data model) |
925 |
|
m_refSamplesTreeModel = Gtk::TreeStore::create(m_SamplesModel); |
926 |
|
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
927 |
|
m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name); |
928 |
|
m_TreeViewSamples.set_headers_visible(false); |
929 |
|
m_TreeViewSamples.signal_button_press_event().connect_notify( |
930 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
931 |
|
); |
932 |
|
|
933 |
file = 0; |
file = 0; |
934 |
|
|
935 |
show_all_children(); |
show_all_children(); |
1299 |
instrument_menu->get_submenu()->items().clear(); |
instrument_menu->get_submenu()->items().clear(); |
1300 |
|
|
1301 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
1302 |
|
m_refSamplesTreeModel->clear(); |
1303 |
if (file) delete file; |
if (file) delete file; |
1304 |
|
|
1305 |
// getInfo(dialog.get_filename().c_str(), *this); |
// getInfo(dialog.get_filename().c_str(), *this); |
1535 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
1536 |
|
|
1537 |
int instrument_index = 0; |
int instrument_index = 0; |
1538 |
|
Gtk::RadioMenuItem::Group instrument_group; |
1539 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
1540 |
instrument = gig->GetNextInstrument()) { |
instrument = gig->GetNextInstrument()) { |
1541 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
1543 |
row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
1544 |
row[m_Columns.m_col_instr] = instrument; |
row[m_Columns.m_col_instr] = instrument; |
1545 |
// create a menu item for this instrument |
// create a menu item for this instrument |
1546 |
Gtk::MenuItem* item= new Gtk::MenuItem(instrument->pInfo->Name.c_str()); |
Gtk::RadioMenuItem* item= new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str()); |
1547 |
instrument_menu->get_submenu()->append(*item); |
instrument_menu->get_submenu()->append(*item); |
1548 |
item->signal_activate().connect( |
item->signal_activate().connect( |
1549 |
sigc::bind( |
sigc::bind( |
1555 |
} |
} |
1556 |
instrument_menu->show(); |
instrument_menu->show(); |
1557 |
instrument_menu->get_submenu()->show_all_children(); |
instrument_menu->get_submenu()->show_all_children(); |
1558 |
|
|
1559 |
|
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1560 |
|
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1561 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1562 |
|
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
1563 |
|
rowGroup[m_SamplesModel.m_col_group] = group; |
1564 |
|
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1565 |
|
for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) { |
1566 |
|
Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children()); |
1567 |
|
Gtk::TreeModel::Row rowSample = *iterSample; |
1568 |
|
rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); |
1569 |
|
rowSample[m_SamplesModel.m_col_sample] = sample; |
1570 |
|
rowSample[m_SamplesModel.m_col_group] = NULL; |
1571 |
|
} |
1572 |
|
} |
1573 |
} |
} |
1574 |
|
|
1575 |
void MainWindow::on_button_release(GdkEventButton* button) |
void MainWindow::on_button_release(GdkEventButton* button) |
1595 |
void MainWindow::on_instrument_selection_change(int index) { |
void MainWindow::on_instrument_selection_change(int index) { |
1596 |
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
1597 |
} |
} |
1598 |
|
|
1599 |
|
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
1600 |
|
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1601 |
|
Gtk::Menu* sample_popup = |
1602 |
|
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu")); |
1603 |
|
// update enabled/disabled state of sample popup items |
1604 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1605 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1606 |
|
bool group_selected = false; |
1607 |
|
bool sample_selected = false; |
1608 |
|
if (it) { |
1609 |
|
Gtk::TreeModel::Row row = *it; |
1610 |
|
group_selected = row[m_SamplesModel.m_col_group]; |
1611 |
|
sample_selected = row[m_SamplesModel.m_col_sample]; |
1612 |
|
} |
1613 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->set_sensitive(group_selected || sample_selected); |
1614 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->set_sensitive(group_selected || sample_selected); |
1615 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->set_sensitive(file); |
1616 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->set_sensitive(group_selected || sample_selected); |
1617 |
|
// show sample popup |
1618 |
|
sample_popup->popup(button->button, button->time); |
1619 |
|
} |
1620 |
|
} |
1621 |
|
|
1622 |
|
void MainWindow::on_action_sample_properties() { |
1623 |
|
//TODO: show a dialog where the selected sample's properties can be edited |
1624 |
|
} |
1625 |
|
|
1626 |
|
void MainWindow::on_action_add_group() { |
1627 |
|
static int __sample_indexer = 0; |
1628 |
|
if (!file) return; |
1629 |
|
gig::Group* group = file->AddGroup(); |
1630 |
|
group->Name = "Unnamed Group"; |
1631 |
|
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
1632 |
|
__sample_indexer++; |
1633 |
|
// update sample tree view |
1634 |
|
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1635 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1636 |
|
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
1637 |
|
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1638 |
|
rowGroup[m_SamplesModel.m_col_group] = group; |
1639 |
|
} |
1640 |
|
|
1641 |
|
void MainWindow::on_action_add_sample() { |
1642 |
|
//TODO: open browse for file dialog for adding new samples |
1643 |
|
} |
1644 |
|
|
1645 |
|
void MainWindow::on_action_remove_sample() { |
1646 |
|
//TODO: remove the selected group or sample |
1647 |
|
} |