45 |
#include "mainwindow.h" |
#include "mainwindow.h" |
46 |
#include "Settings.h" |
#include "Settings.h" |
47 |
#include "CombineInstrumentsDialog.h" |
#include "CombineInstrumentsDialog.h" |
48 |
|
#include "scripteditor.h" |
49 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
50 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
51 |
|
|
79 |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
80 |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
81 |
|
|
82 |
|
m_ScrolledWindowScripts.add(m_TreeViewScripts); |
83 |
|
m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
84 |
|
|
85 |
|
|
86 |
m_TreeViewNotebook.set_size_request(300); |
m_TreeViewNotebook.set_size_request(300); |
87 |
|
|
102 |
|
|
103 |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
104 |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
105 |
|
m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts")); |
106 |
|
|
107 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
108 |
|
|
235 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
236 |
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
237 |
); |
); |
238 |
|
|
239 |
|
// script right-click popup actions |
240 |
|
actionGroup->add( |
241 |
|
Gtk::Action::create("AddScriptGroup", _("Add _Group")), |
242 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) |
243 |
|
); |
244 |
|
actionGroup->add( |
245 |
|
Gtk::Action::create("AddScript", _("Add _Script")), |
246 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script) |
247 |
|
); |
248 |
|
actionGroup->add( |
249 |
|
Gtk::Action::create("EditScript", _("_Edit Script...")), |
250 |
|
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
251 |
|
); |
252 |
|
actionGroup->add( |
253 |
|
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
254 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
255 |
|
); |
256 |
|
|
257 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
258 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
309 |
" <separator/>" |
" <separator/>" |
310 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
311 |
" </popup>" |
" </popup>" |
312 |
|
" <popup name='ScriptPopupMenu'>" |
313 |
|
" <menuitem action='AddScriptGroup'/>" |
314 |
|
" <menuitem action='AddScript'/>" |
315 |
|
" <menuitem action='EditScript'/>" |
316 |
|
" <separator/>" |
317 |
|
" <menuitem action='RemoveScript'/>" |
318 |
|
" </popup>" |
319 |
"</ui>"; |
"</ui>"; |
320 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
321 |
|
|
407 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
408 |
); |
); |
409 |
|
|
410 |
|
// create scripts treeview (including its data model) |
411 |
|
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
412 |
|
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
413 |
|
m_TreeViewScripts.set_tooltip_text(_( |
414 |
|
"Note: instrument scripts are a LinuxSampler extension of the gig " |
415 |
|
"format. This feature will not work with the GigaStudio software!" |
416 |
|
)); |
417 |
|
// m_TreeViewScripts.set_reorderable(); |
418 |
|
m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); |
419 |
|
m_TreeViewScripts.set_headers_visible(false); |
420 |
|
m_TreeViewScripts.signal_button_press_event().connect_notify( |
421 |
|
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
422 |
|
); |
423 |
|
m_refScriptsTreeModel->signal_row_changed().connect( |
424 |
|
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
425 |
|
); |
426 |
|
|
427 |
// 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 |
428 |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
429 |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
1388 |
} |
} |
1389 |
} |
} |
1390 |
} |
} |
1391 |
|
|
1392 |
|
for (int i = 0; gig->GetScriptGroup(i); ++i) { |
1393 |
|
gig::ScriptGroup* group = gig->GetScriptGroup(i); |
1394 |
|
|
1395 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1396 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1397 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1398 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1399 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1400 |
|
for (int s = 0; group->GetScript(s); ++s) { |
1401 |
|
gig::Script* script = group->GetScript(s); |
1402 |
|
|
1403 |
|
Gtk::TreeModel::iterator iterScript = |
1404 |
|
m_refScriptsTreeModel->append(rowGroup.children()); |
1405 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1406 |
|
rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); |
1407 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1408 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1409 |
|
} |
1410 |
|
} |
1411 |
|
// unfold all script groups by default |
1412 |
|
m_TreeViewScripts.expand_all(); |
1413 |
|
|
1414 |
file = gig; |
file = gig; |
1415 |
|
|
1574 |
} |
} |
1575 |
} |
} |
1576 |
|
|
1577 |
|
void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { |
1578 |
|
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1579 |
|
Gtk::Menu* script_popup = |
1580 |
|
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu")); |
1581 |
|
// update enabled/disabled state of sample popup items |
1582 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1583 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1584 |
|
bool group_selected = false; |
1585 |
|
bool script_selected = false; |
1586 |
|
if (it) { |
1587 |
|
Gtk::TreeModel::Row row = *it; |
1588 |
|
group_selected = row[m_ScriptsModel.m_col_group]; |
1589 |
|
script_selected = row[m_ScriptsModel.m_col_script]; |
1590 |
|
} |
1591 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> |
1592 |
|
set_sensitive(group_selected || script_selected); |
1593 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> |
1594 |
|
set_sensitive(file); |
1595 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> |
1596 |
|
set_sensitive(script_selected); |
1597 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> |
1598 |
|
set_sensitive(group_selected || script_selected); |
1599 |
|
// show sample popup |
1600 |
|
script_popup->popup(button->button, button->time); |
1601 |
|
} |
1602 |
|
} |
1603 |
|
|
1604 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1605 |
const Glib::ustring& name, int position) { |
const Glib::ustring& name, int position) { |
1747 |
msg.run(); |
msg.run(); |
1748 |
} |
} |
1749 |
|
|
1750 |
|
void MainWindow::on_action_add_script_group() { |
1751 |
|
static int __script_indexer = 0; |
1752 |
|
if (!file) return; |
1753 |
|
gig::ScriptGroup* group = file->AddScriptGroup(); |
1754 |
|
group->Name = gig_from_utf8(_("Unnamed Group")); |
1755 |
|
if (__script_indexer) group->Name += " " + ToString(__script_indexer); |
1756 |
|
__script_indexer++; |
1757 |
|
// update sample tree view |
1758 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1759 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1760 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1761 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1762 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1763 |
|
file_changed(); |
1764 |
|
} |
1765 |
|
|
1766 |
|
void MainWindow::on_action_add_script() { |
1767 |
|
if (!file) return; |
1768 |
|
// get selected group |
1769 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1770 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1771 |
|
if (!it) return; |
1772 |
|
Gtk::TreeModel::Row row = *it; |
1773 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
1774 |
|
if (!group) { // not a group, but a script is selected (probably) |
1775 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1776 |
|
if (!script) return; |
1777 |
|
it = row.parent(); // resolve parent (that is the script's group) |
1778 |
|
if (!it) return; |
1779 |
|
row = *it; |
1780 |
|
group = row[m_ScriptsModel.m_col_group]; |
1781 |
|
if (!group) return; |
1782 |
|
} |
1783 |
|
|
1784 |
|
// add a new script to the .gig file |
1785 |
|
gig::Script* script = group->AddScript(); |
1786 |
|
Glib::ustring name = _("Unnamed Script"); |
1787 |
|
script->Name = gig_from_utf8(name); |
1788 |
|
|
1789 |
|
// add script to the tree view |
1790 |
|
Gtk::TreeModel::iterator iterScript = |
1791 |
|
m_refScriptsTreeModel->append(row.children()); |
1792 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1793 |
|
rowScript[m_ScriptsModel.m_col_name] = name; |
1794 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1795 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1796 |
|
|
1797 |
|
// unfold group of new script item in treeview |
1798 |
|
Gtk::TreeModel::Path path(iterScript); |
1799 |
|
m_TreeViewScripts.expand_to_path(path); |
1800 |
|
} |
1801 |
|
|
1802 |
|
void MainWindow::on_action_edit_script() { |
1803 |
|
if (!file) return; |
1804 |
|
// get selected script |
1805 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1806 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1807 |
|
if (!it) return; |
1808 |
|
Gtk::TreeModel::Row row = *it; |
1809 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1810 |
|
if (!script) return; |
1811 |
|
|
1812 |
|
ScriptEditor* editor = new ScriptEditor; |
1813 |
|
editor->setScript(script); |
1814 |
|
//editor->reparent(*this); |
1815 |
|
editor->show(); |
1816 |
|
} |
1817 |
|
|
1818 |
|
void MainWindow::on_action_remove_script() { |
1819 |
|
if (!file) return; |
1820 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1821 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1822 |
|
if (it) { |
1823 |
|
Gtk::TreeModel::Row row = *it; |
1824 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
1825 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
1826 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
1827 |
|
try { |
1828 |
|
// remove script group or script from the gig file |
1829 |
|
if (group) { |
1830 |
|
// notify everybody that we're going to remove these samples |
1831 |
|
//TODO: scripts_to_be_removed_signal.emit(members); |
1832 |
|
// delete the group in the .gig file including the |
1833 |
|
// samples that belong to the group |
1834 |
|
file->DeleteScriptGroup(group); |
1835 |
|
// notify that we're done with removal |
1836 |
|
//TODO: scripts_removed_signal.emit(); |
1837 |
|
file_changed(); |
1838 |
|
} else if (script) { |
1839 |
|
// notify everybody that we're going to remove this sample |
1840 |
|
//TODO: std::list<gig::Script*> lscripts; |
1841 |
|
//TODO: lscripts.push_back(script); |
1842 |
|
//TODO: scripts_to_be_removed_signal.emit(lscripts); |
1843 |
|
// remove sample from the .gig file |
1844 |
|
script->GetGroup()->DeleteScript(script); |
1845 |
|
// notify that we're done with removal |
1846 |
|
//TODO: scripts_removed_signal.emit(); |
1847 |
|
dimreg_changed(); |
1848 |
|
file_changed(); |
1849 |
|
} |
1850 |
|
// remove respective row(s) from samples tree view |
1851 |
|
m_refScriptsTreeModel->erase(it); |
1852 |
|
} catch (RIFF::Exception e) { |
1853 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
1854 |
|
//TODO: scripts_removed_signal.emit(); |
1855 |
|
// show error message |
1856 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1857 |
|
msg.run(); |
1858 |
|
} |
1859 |
|
} |
1860 |
|
} |
1861 |
|
|
1862 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |
1863 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
1864 |
if (!file) return; |
if (!file) return; |
2354 |
file_changed(); |
file_changed(); |
2355 |
} |
} |
2356 |
} |
} |
2357 |
|
} |
2358 |
|
|
2359 |
|
void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, |
2360 |
|
const Gtk::TreeModel::iterator& iter) { |
2361 |
|
if (!iter) return; |
2362 |
|
Gtk::TreeModel::Row row = *iter; |
2363 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2364 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2365 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2366 |
|
gig::String gigname(gig_from_utf8(name)); |
2367 |
|
if (group) { |
2368 |
|
if (group->Name != gigname) { |
2369 |
|
group->Name = gigname; |
2370 |
|
printf("script group name changed\n"); |
2371 |
|
file_changed(); |
2372 |
|
} |
2373 |
|
} else if (script) { |
2374 |
|
if (script->Name != gigname) { |
2375 |
|
script->Name = gigname; |
2376 |
|
printf("script name changed\n"); |
2377 |
|
file_changed(); |
2378 |
|
} |
2379 |
|
} |
2380 |
} |
} |
2381 |
|
|
2382 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |