--- gigedit/trunk/src/gigedit/mainwindow.cpp 2020/01/10 14:22:25 3711
+++ gigedit/trunk/src/gigedit/mainwindow.cpp 2020/08/14 12:29:01 3814
@@ -96,9 +96,9 @@
if (!Settings::singleton()->autoRestoreWindowDimension) {
#if GTKMM_MAJOR_VERSION >= 3
- set_default_size(960, 600);
+ set_default_size(1010, -1);
#else
- set_default_size(865, 600);
+ set_default_size(915, -1);
#endif
set_position(Gtk::WIN_POS_CENTER);
}
@@ -106,21 +106,21 @@
add(m_VBox);
// Handle selection
- m_TreeView.get_selection()->signal_changed().connect(
+ m_TreeViewInstruments.get_selection()->signal_changed().connect(
sigc::mem_fun(*this, &MainWindow::on_sel_change));
- // m_TreeView.set_reorderable();
+ // m_TreeViewInstruments.set_reorderable();
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
- m_TreeView.signal_button_press_event().connect(
+ m_TreeViewInstruments.signal_button_press_event().connect(
sigc::mem_fun(*this, &MainWindow::on_button_release));
#else
- m_TreeView.signal_button_press_event().connect_notify(
+ m_TreeViewInstruments.signal_button_press_event().connect_notify(
sigc::mem_fun(*this, &MainWindow::on_button_release));
#endif
// Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
- m_ScrolledWindow.add(m_TreeView);
+ m_ScrolledWindow.add(m_TreeViewInstruments);
// m_ScrolledWindow.set_size_request(200, 600);
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
@@ -522,6 +522,9 @@
"DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
);
m_actionGroup->add_action(
+ "MoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_move_instr)
+ );
+ m_actionGroup->add_action(
"CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
);
m_actionGroup->add_action(
@@ -543,6 +546,11 @@
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
);
actionGroup->add(
+ Gtk::Action::create("MoveInstrument", _("Move _Instrument To ...")),
+ Gtk::AccelKey(GDK_KEY_i, primaryModifierKey),
+ sigc::mem_fun(*this, &MainWindow::on_action_move_instr)
+ );
+ actionGroup->add(
Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
@@ -898,6 +906,10 @@
" Duplicate Instrument"
" AppMenu.DupInstrument"
" "
+ " - "
+ " Move Instrument To ..."
+ " AppMenu.MoveInstrument"
+ "
"
" - "
" Combine Instrument"
" AppMenu.CombInstruments"
@@ -1027,6 +1039,10 @@
" Duplicate Instrument"
" AppMenu.DupInstrument"
"
"
+ " - "
+ " Move Instrument To ..."
+ " AppMenu.MoveInstrument"
+ "
"
" - "
" Combine Instruments"
" AppMenu.CombInstruments"
@@ -1165,6 +1181,7 @@
" "
" "
" "
+ " "
" "
" "
" "
@@ -1204,6 +1221,7 @@
" "
" "
" "
+ " "
" "
" "
" "
@@ -1365,42 +1383,42 @@
// Create the Tree model:
- m_refTreeModel = Gtk::ListStore::create(m_Columns);
- m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
- m_refTreeModelFilter->set_visible_func(
+ m_refInstrumentsTreeModel = Gtk::ListStore::create(m_InstrumentsModel);
+ m_refInstrumentsModelFilter = Gtk::TreeModelFilter::create(m_refInstrumentsTreeModel);
+ m_refInstrumentsModelFilter->set_visible_func(
sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
);
- m_TreeView.set_model(m_refTreeModelFilter);
+ m_TreeViewInstruments.set_model(m_refInstrumentsModelFilter);
- m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
- m_TreeView.set_has_tooltip(true);
- m_TreeView.signal_query_tooltip().connect(
+ m_TreeViewInstruments.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
+ m_TreeViewInstruments.set_has_tooltip(true);
+ m_TreeViewInstruments.signal_query_tooltip().connect(
sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)
);
- instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
+ instrument_name_connection = m_refInstrumentsTreeModel->signal_row_changed().connect(
sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
);
// Add the TreeView's view columns:
- m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
- m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
- m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
- m_TreeView.set_headers_visible(true);
+ m_TreeViewInstruments.append_column(_("Nr"), m_InstrumentsModel.m_col_nr);
+ m_TreeViewInstruments.append_column_editable(_("Instrument"), m_InstrumentsModel.m_col_name);
+ m_TreeViewInstruments.append_column(_("Scripts"), m_InstrumentsModel.m_col_scripts);
+ m_TreeViewInstruments.set_headers_visible(true);
// establish drag&drop within the instrument tree view, allowing to reorder
// the sequence of instruments within the gig file
{
std::vector drag_target_instrument;
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
- m_TreeView.drag_source_set(drag_target_instrument);
- m_TreeView.drag_dest_set(drag_target_instrument);
- m_TreeView.signal_drag_begin().connect(
+ m_TreeViewInstruments.drag_source_set(drag_target_instrument);
+ m_TreeViewInstruments.drag_dest_set(drag_target_instrument);
+ m_TreeViewInstruments.signal_drag_begin().connect(
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
);
- m_TreeView.signal_drag_data_get().connect(
+ m_TreeViewInstruments.signal_drag_data_get().connect(
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
);
- m_TreeView.signal_drag_data_received().connect(
+ m_TreeViewInstruments.signal_drag_data_received().connect(
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
);
}
@@ -1531,6 +1549,35 @@
sigc::mem_fun(*this, &MainWindow::select_sample)
);
+ dimreg_edit.editScriptSlotsButton.signal_clicked().connect(
+ sigc::mem_fun(*this, &MainWindow::show_script_slots)
+ );
+ // simply sending the same signal (pair) to the sampler on 'patch' variable
+ // changes as the already existing signal (pair) when the user edits the
+ // script's source code, because the sampler would reload the source code
+ // and the 'patch' variables from the instrument on this signal anyway
+ dimreg_edit.scriptVars.signal_vars_to_be_changed.connect(
+ [this](gig::Instrument* instr) {
+ for (int i = 0; i < instr->ScriptSlotCount(); ++i) {
+ gig::Script* script = instr->GetScriptOfSlot(i);
+ signal_script_to_be_changed.emit(script);
+ }
+ }
+ );
+ dimreg_edit.scriptVars.signal_vars_changed.connect(
+ [this](gig::Instrument* instr) {
+ for (int i = 0; i < instr->ScriptSlotCount(); ++i) {
+ gig::Script* script = instr->GetScriptOfSlot(i);
+ signal_script_changed.emit(script);
+ }
+ }
+ );
+ dimreg_edit.scriptVars.signal_edit_script.connect(
+ [this](gig::Script* script) {
+ editScript(script);
+ }
+ );
+
m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
sigc::hide(
sigc::bind(
@@ -1573,7 +1620,7 @@
sigc::mem_fun(*this, &MainWindow::update_dimregs));
m_searchText.signal_changed().connect(
- sigc::mem_fun(*m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
+ sigc::mem_fun(*m_refInstrumentsModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
);
file = 0;
@@ -1817,14 +1864,21 @@
gig::Instrument* MainWindow::get_instrument()
{
- gig::Instrument* instrument = 0;
- std::vector rows = m_TreeView.get_selection()->get_selected_rows();
+ gig::Instrument* instrument = NULL;
+
+ // get indeces of visual selection
+ std::vector rows = m_TreeViewInstruments.get_selection()->get_selected_rows();
if (rows.empty()) return NULL;
+
+ // convert index of visual selection (i.e. if filtered) to index of model
+ Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
+ if (!path) return NULL;
+
//NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
+ Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
if (it) {
Gtk::TreeModel::Row row = *it;
- instrument = row[m_Columns.m_col_instr];
+ instrument = row[m_InstrumentsModel.m_col_instr];
}
return instrument;
}
@@ -1889,9 +1943,11 @@
{
#if !USE_GTKMM_BUILDER
// select item in instrument menu
- std::vector rows = m_TreeView.get_selection()->get_selected_rows();
+ std::vector rows = m_TreeViewInstruments.get_selection()->get_selected_rows();
if (!rows.empty()) {
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
+ // convert index of visual selection (i.e. if filtered) to index of model
+ Gtk::TreeModel::Path row = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
+ Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(row);
if (it) {
Gtk::TreePath path(it);
int index = path[0];
@@ -1904,7 +1960,10 @@
updateScriptListOfMenu();
- m_RegionChooser.set_instrument(get_instrument());
+ gig::Instrument* instr = get_instrument();
+
+ m_RegionChooser.set_instrument(instr);
+ dimreg_edit.scriptVars.setInstrument(instr, true/*force update*/);
if (Settings::singleton()->syncSamplerInstrumentSelection) {
switch_sampler_instrument_signal.emit(get_instrument());
@@ -2096,7 +2155,7 @@
// forget all samples that ought to be imported
m_SampleImportQueue.clear();
// clear the samples and instruments tree views
- m_refTreeModel->clear();
+ m_refInstrumentsTreeModel->clear();
m_refSamplesTreeModel->clear();
m_refScriptsTreeModel->clear();
#if !USE_GTKMM_BUILDER
@@ -2113,7 +2172,7 @@
void MainWindow::__refreshEntireGUI() {
// clear the samples and instruments tree views
- m_refTreeModel->clear();
+ m_refInstrumentsTreeModel->clear();
m_refSamplesTreeModel->clear();
m_refScriptsTreeModel->clear();
#if !USE_GTKMM_BUILDER
@@ -2286,10 +2345,10 @@
{
if (instrument == instr) {
// select item in "instruments" tree view
- m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
+ m_TreeViewInstruments.get_selection()->select(Gtk::TreePath(ToString(i)));
// make sure the selected item in the "instruments" tree view is
// visible (scroll to it)
- m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
+ m_TreeViewInstruments.scroll_to_row(Gtk::TreePath(ToString(i)));
#if !USE_GTKMM_BUILDER
// select item in instrument menu
{
@@ -2653,7 +2712,7 @@
dimreg_stereo.set_has_tooltip(b);
// Not doing this here, we let onQueryTreeViewTooltip() handle this per cell
- //m_TreeView.set_has_tooltip(b);
+ //m_TreeViewInstruments.set_has_tooltip(b);
m_TreeViewSamples.set_has_tooltip(b);
m_TreeViewScripts.set_has_tooltip(b);
@@ -3405,7 +3464,7 @@
bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr& tooltip) {
Gtk::TreeModel::iterator iter;
- if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
+ if (!m_TreeViewInstruments.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
return false;
}
Gtk::TreeModel::Path path(iter);
@@ -3415,13 +3474,13 @@
{
Gtk::TreeModel::Path path; // unused
int cellX, cellY; // unused
- m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
+ m_TreeViewInstruments.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
}
- Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);
+ Gtk::TreeViewColumn* scriptsColumn = m_TreeViewInstruments.get_column(2);
if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
// show the script(s) assigned to the hovered instrument as tooltip
- tooltip->set_markup( row[m_Columns.m_col_tooltip] );
- m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
+ tooltip->set_markup( row[m_InstrumentsModel.m_col_tooltip] );
+ m_TreeViewInstruments.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
} else {
// if beginners' tooltips is disabled then don't show the following one
if (!Settings::singleton()->showTooltips)
@@ -3431,7 +3490,7 @@
"Right click here for actions on instruments & MIDI Rules. "
"Drag & drop to change the order of instruments."
));
- m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
+ m_TreeViewInstruments.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
}
return true;
}
@@ -3474,13 +3533,13 @@
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
const int iScriptSlots = instrument->ScriptSlotCount();
- Gtk::TreeModel::iterator iter = m_refTreeModel->append();
+ Gtk::TreeModel::iterator iter = m_refInstrumentsTreeModel->append();
Gtk::TreeModel::Row row = *iter;
- row[m_Columns.m_col_nr] = index;
- row[m_Columns.m_col_name] = name;
- row[m_Columns.m_col_instr] = instrument;
- row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
- row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
+ row[m_InstrumentsModel.m_col_nr] = index;
+ row[m_InstrumentsModel.m_col_name] = name;
+ row[m_InstrumentsModel.m_col_instr] = instrument;
+ row[m_InstrumentsModel.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
+ row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
#if !USE_GTKMM_BUILDER
add_instrument_to_menu(name);
@@ -3542,7 +3601,7 @@
file = gig;
// select the first instrument
- m_TreeView.get_selection()->select(Gtk::TreePath("0"));
+ m_TreeViewInstruments.get_selection()->select(Gtk::TreePath("0"));
instr_props_set_instrument();
gig::Instrument* instrument = get_instrument();
@@ -3555,16 +3614,21 @@
{
instrumentProps.signal_name_changed().clear();
- std::vector rows = m_TreeView.get_selection()->get_selected_rows();
+ // get visual selection
+ std::vector rows = m_TreeViewInstruments.get_selection()->get_selected_rows();
if (rows.empty()) {
instrumentProps.hide();
return false;
}
+
+ // convert index of visual selection (i.e. if filtered) to index of model
+ Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
+
//NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
+ Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
if (it) {
Gtk::TreeModel::Row row = *it;
- gig::Instrument* instrument = row[m_Columns.m_col_instr];
+ gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
instrumentProps.set_instrument(instrument);
@@ -3593,15 +3657,15 @@
void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
{
Gtk::TreeModel::Row row = *it;
- Glib::ustring name = row[m_Columns.m_col_name];
+ Glib::ustring name = row[m_InstrumentsModel.m_col_name];
- gig::Instrument* instrument = row[m_Columns.m_col_instr];
+ gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
if (gigname != name) {
Gtk::TreeModel::Path path(*it);
const int index = path[0];
- row[m_Columns.m_col_name] = gigname;
- row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
+ row[m_InstrumentsModel.m_col_name] = gigname;
+ row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
}
}
@@ -3671,13 +3735,9 @@
void MainWindow::show_script_slots() {
if (!file) return;
+
// get selected instrument
- std::vector rows = m_TreeView.get_selection()->get_selected_rows();
- if (rows.empty()) return;
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
- if (!it) return;
- Gtk::TreeModel::Row row = *it;
- gig::Instrument* instrument = row[m_Columns.m_col_instr];
+ gig::Instrument* instrument = get_instrument();
if (!instrument) return;
ScriptSlots* window = new ScriptSlots;
@@ -3693,20 +3753,23 @@
if (!pInstrument) return;
const int iScriptSlots = pInstrument->ScriptSlotCount();
- //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!
- //Glib::RefPtr model = m_TreeView.get_model();
- Glib::RefPtr model = m_refTreeModelFilter->get_model();
+ //NOTE: This is a big mess! Sometimes GTK requires m_TreeViewInstruments.get_model(), here we need m_refInstrumentsModelFilter->get_model(), otherwise accessing children below causes an error!
+ //Glib::RefPtr model = m_TreeViewInstruments.get_model();
+ Glib::RefPtr model = m_refInstrumentsModelFilter->get_model();
for (int i = 0; i < model->children().size(); ++i) {
Gtk::TreeModel::Row row = model->children()[i];
- if (row[m_Columns.m_col_instr] != pInstrument) continue;
- row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
- row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
+ if (row[m_InstrumentsModel.m_col_instr] != pInstrument) continue;
+ row[m_InstrumentsModel.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
+ row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
break;
}
// causes the sampler to reload the instrument with the new script
on_sel_change();
+
+ // force script 'patch' variables editor ("Script" tab) to be refreshed
+ dimreg_edit.scriptVars.setInstrument(pInstrument, true/*force update*/);
}
void MainWindow::assignScript(gig::Script* pScript) {
@@ -3913,7 +3976,7 @@
find(children.begin(), children.end(), item);
if (it != children.end()) {
int index = it - children.begin();
- m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
+ m_TreeViewInstruments.get_selection()->select(Gtk::TreePath(ToString(index)));
m_RegionChooser.set_instrument(file->GetInstrument(index));
}
@@ -3921,30 +3984,90 @@
}
#endif
+void MainWindow::on_action_move_instr() {
+ gig::Instrument* instr = get_instrument();
+ if (!instr) return;
+
+ int currentIndex = getIndexOf(instr);
+
+ Gtk::Dialog dialog(_("Move Instrument"), true /*modal*/);
+#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
+ Gtk::Adjustment adjustment(
+ currentIndex,
+ 0 /*min*/, file->CountInstruments() - 1 /*max*/
+ );
+ Gtk::SpinButton spinBox(adjustment);
+#else
+ Gtk::SpinButton spinBox(
+ Gtk::Adjustment::create(
+ currentIndex,
+ 0 /*min*/, file->CountInstruments() - 1 /*max*/
+ )
+ );
+#endif
+#if USE_GTKMM_BOX
+ dialog.get_content_area()->pack_start(spinBox);
+#else
+ dialog.get_vbox()->pack_start(spinBox);
+#endif
+#if HAS_GTKMM_STOCK
+ Gtk::Button* okButton = dialog.add_button(Gtk::Stock::OK, 0);
+ dialog.add_button(Gtk::Stock::CANCEL, 1);
+#else
+ Gtk::Button* okButton = dialog.add_button(_("_OK"), 0);
+ dialog.add_button(_("_Cancel"), 1);
+#endif
+ okButton->set_sensitive(false);
+ // show the dialog at a reasonable screen position
+ dialog.set_position(Gtk::WIN_POS_MOUSE);
+ // only enable the 'OK' button if entered new index is not instrument's
+ // current index already
+ spinBox.signal_value_changed().connect([&]{
+ okButton->set_sensitive( spinBox.get_value_as_int() != currentIndex );
+ });
+ // usability acceleration: if user hits enter key on the text entry field
+ // then auto trigger the 'OK' button
+ spinBox.signal_activate().connect([&]{
+ if (okButton->get_sensitive())
+ okButton->clicked();
+ });
+#if HAS_GTKMM_SHOW_ALL_CHILDREN
+ dialog.show_all_children();
+#endif
+ if (!dialog.run()) { // 'OK' selected ...
+ int newIndex = spinBox.get_value_as_int();
+ printf("MOVE TO %d\n", newIndex);
+ gig::Instrument* dst = file->GetInstrument(newIndex);
+ instr->MoveTo(dst);
+ __refreshEntireGUI();
+ select_instrument(instr);
+ }
+}
+
void MainWindow::select_instrument(gig::Instrument* instrument) {
if (!instrument) return;
- //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
- Glib::RefPtr model = m_TreeView.get_model();
- //Glib::RefPtr model = m_refTreeModelFilter->get_model();
+ //NOTE: This is a big mess! Sometimes GTK requires m_refInstrumentsModelFilter->get_model(), here we need m_TreeViewInstruments.get_model(), otherwise treeview selection below causes an error!
+ Glib::RefPtr model = m_TreeViewInstruments.get_model();
+ //Glib::RefPtr model = m_refInstrumentsModelFilter->get_model();
for (int i = 0; i < model->children().size(); ++i) {
Gtk::TreeModel::Row row = model->children()[i];
- if (row[m_Columns.m_col_instr] == instrument) {
+ if (row[m_InstrumentsModel.m_col_instr] == instrument) {
// select and show the respective instrument in the list view
show_intruments_tab();
- m_TreeView.get_selection()->unselect_all();
+ m_TreeViewInstruments.get_selection()->unselect_all();
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
auto iterSel = model->children()[i].get_iter();
- m_TreeView.get_selection()->select(iterSel);
+ m_TreeViewInstruments.get_selection()->select(iterSel);
#else
- m_TreeView.get_selection()->select(model->children()[i]);
+ m_TreeViewInstruments.get_selection()->select(model->children()[i]);
#endif
std::vector rows =
- m_TreeView.get_selection()->get_selected_rows();
+ m_TreeViewInstruments.get_selection()->get_selected_rows();
if (!rows.empty())
- m_TreeView.scroll_to_row(rows[0]);
+ m_TreeViewInstruments.scroll_to_row(rows[0]);
on_sel_change(); // the regular instrument selection change callback
}
}
@@ -3955,26 +4078,26 @@
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
- //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
- Glib::RefPtr model = m_TreeView.get_model();
- //Glib::RefPtr model = m_refTreeModelFilter->get_model();
+ //NOTE: This is a big mess! Sometimes GTK requires m_refInstrumentsModelFilter->get_model(), here we need m_TreeViewInstruments.get_model(), otherwise treeview selection below causes an error!
+ Glib::RefPtr model = m_TreeViewInstruments.get_model();
+ //Glib::RefPtr model = m_refInstrumentsModelFilter->get_model();
for (int i = 0; i < model->children().size(); ++i) {
Gtk::TreeModel::Row row = model->children()[i];
- if (row[m_Columns.m_col_instr] == pInstrument) {
+ if (row[m_InstrumentsModel.m_col_instr] == pInstrument) {
// select and show the respective instrument in the list view
show_intruments_tab();
- m_TreeView.get_selection()->unselect_all();
+ m_TreeViewInstruments.get_selection()->unselect_all();
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
auto iterSel = model->children()[i].get_iter();
- m_TreeView.get_selection()->select(iterSel);
+ m_TreeViewInstruments.get_selection()->select(iterSel);
#else
- m_TreeView.get_selection()->select(model->children()[i]);
+ m_TreeViewInstruments.get_selection()->select(model->children()[i]);
#endif
std::vector rows =
- m_TreeView.get_selection()->get_selected_rows();
+ m_TreeViewInstruments.get_selection()->get_selected_rows();
if (!rows.empty())
- m_TreeView.scroll_to_row(rows[0]);
+ m_TreeViewInstruments.scroll_to_row(rows[0]);
on_sel_change(); // the regular instrument selection change callback
// select respective region in the region selector
@@ -4259,14 +4382,15 @@
// update instrument tree view
instrument_name_connection.block();
- Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
+ Gtk::TreeModel::iterator iterInstr = m_refInstrumentsTreeModel->append();
Gtk::TreeModel::Row rowInstr = *iterInstr;
- const int index = m_refTreeModel->children().size() - 1;
- rowInstr[m_Columns.m_col_nr] = index;
- rowInstr[m_Columns.m_col_name] = name;
- rowInstr[m_Columns.m_col_instr] = instrument;
- rowInstr[m_Columns.m_col_scripts] = "";
- rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
+ const int index = m_refInstrumentsTreeModel->children().size() - 1;
+ const int iScriptSlots = instrument->ScriptSlotCount();
+ rowInstr[m_InstrumentsModel.m_col_nr] = index;
+ rowInstr[m_InstrumentsModel.m_col_name] = name;
+ rowInstr[m_InstrumentsModel.m_col_instr] = instrument;
+ rowInstr[m_InstrumentsModel.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
+ rowInstr[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
instrument_name_connection.unblock();
#if !USE_GTKMM_BUILDER
@@ -4292,13 +4416,15 @@
// retrieve the currently selected instrument
// (being the original instrument to be duplicated)
- Glib::RefPtr sel = m_TreeView.get_selection();
+ Glib::RefPtr sel = m_TreeViewInstruments.get_selection();
std::vector rows = sel->get_selected_rows();
for (int r = 0; r < rows.size(); ++r) {
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
+ // convert index of visual selection (i.e. if filtered) to index of model
+ Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[r]);
+ Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
if (it) {
Gtk::TreeModel::Row row = *it;
- gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
+ gig::Instrument* instrOrig = row[m_InstrumentsModel.m_col_instr];
if (instrOrig) {
// duplicate the orginal instrument
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
@@ -4325,13 +4451,22 @@
return;
}
- Glib::RefPtr sel = m_TreeView.get_selection();
- std::vector rows = sel->get_selected_rows();
+ Glib::RefPtr sel = m_TreeViewInstruments.get_selection();
+ std::vector rowsVisual = sel->get_selected_rows();
+
+ // convert indeces of visual selection (i.e. if filtered) to indeces of model
+ std::vector rows;
+ for (int rv = 0; rv < rowsVisual.size(); ++rv) {
+ Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rowsVisual[rv]);
+ if (path)
+ rows.push_back(path);
+ }
+
for (int r = rows.size() - 1; r >= 0; --r) {
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
+ Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[r]);
if (!it) continue;
Gtk::TreeModel::Row row = *it;
- gig::Instrument* instr = row[m_Columns.m_col_instr];
+ gig::Instrument* instr = row[m_InstrumentsModel.m_col_instr];
try {
Gtk::TreePath path(it);
int index = path[0];
@@ -4345,28 +4480,28 @@
#endif
// remove row from instruments tree view
- m_refTreeModel->erase(it);
+ m_refInstrumentsTreeModel->erase(it);
// update "Nr" column of all instrument rows
{
int index = 0;
- for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
- it != m_refTreeModel->children().end(); ++it, ++index)
+ for (Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->children().begin();
+ it != m_refInstrumentsTreeModel->children().end(); ++it, ++index)
{
Gtk::TreeModel::Row row = *it;
- gig::Instrument* instrument = row[m_Columns.m_col_instr];
- row[m_Columns.m_col_nr] = index;
- row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
+ gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
+ row[m_InstrumentsModel.m_col_nr] = index;
+ row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
}
}
#if GTKMM_MAJOR_VERSION < 3
// select another instrument (in gtk3 this is done
// automatically)
- if (!m_refTreeModel->children().empty()) {
- if (index == m_refTreeModel->children().size()) {
+ if (!m_refInstrumentsTreeModel->children().empty()) {
+ if (index == m_refInstrumentsTreeModel->children().size()) {
index--;
}
- m_TreeView.get_selection()->select(
+ m_TreeViewInstruments.get_selection()->select(
Gtk::TreePath(ToString(index)));
}
#endif
@@ -4448,15 +4583,22 @@
if (!it) return;
Gtk::TreeModel::Row row = *it;
gig::Script* script = row[m_ScriptsModel.m_col_script];
- if (!script) return;
+ editScript(script);
+}
+void MainWindow::editScript(gig::Script* script) {
+ if (!script) return;
ScriptEditor* editor = new ScriptEditor;
editor->signal_script_to_be_changed.connect(
signal_script_to_be_changed.make_slot()
);
- editor->signal_script_changed.connect(
- signal_script_changed.make_slot()
- );
+ editor->signal_script_changed.connect([this](gig::Script* script) {
+ // signal to sampler (which will reload the script due to this)
+ signal_script_changed.emit(script);
+ // force script 'patch' variables editor ("Script" tab) to be refreshed
+ gig::Instrument* instr = get_instrument();
+ dimreg_edit.scriptVars.setInstrument(instr, true/*force update*/);
+ });
editor->setScript(script);
//editor->reparent(*this);
editor->show();
@@ -5011,13 +5153,15 @@
// get selected source instrument
gig::Instrument* src = NULL;
{
- Glib::RefPtr sel = m_TreeView.get_selection();
+ Glib::RefPtr sel = m_TreeViewInstruments.get_selection();
std::vector rows = sel->get_selected_rows();
if (!rows.empty()) {
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
+ // convert index of visual selection (i.e. if filtered) to index of model
+ Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
+ Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
if (it) {
Gtk::TreeModel::Row row = *it;
- src = row[m_Columns.m_col_instr];
+ src = row[m_InstrumentsModel.m_col_instr];
}
}
}
@@ -5039,13 +5183,17 @@
gig::Instrument* dst = NULL;
{
Gtk::TreeModel::Path path;
- const bool found = m_TreeView.get_path_at_pos(x, y, path);
+ const bool found = m_TreeViewInstruments.get_path_at_pos(x, y, path);
if (!found) return;
- Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
+ // convert index of visual selection (i.e. if filtered) to index of model
+ path = m_refInstrumentsModelFilter->convert_path_to_child_path(path);
+ if (!path) return;
+
+ Gtk::TreeModel::iterator iter = m_refInstrumentsTreeModel->get_iter(path);
if (!iter) return;
Gtk::TreeModel::Row row = *iter;
- dst = row[m_Columns.m_col_instr];
+ dst = row[m_InstrumentsModel.m_col_instr];
}
if (!dst) return;
@@ -5220,25 +5368,14 @@
if (!iter) return;
Gtk::TreeModel::Row row = *iter;
gig::Script* script = row[m_ScriptsModel.m_col_script];
- if (!script) return;
-
- ScriptEditor* editor = new ScriptEditor;
- editor->signal_script_to_be_changed.connect(
- signal_script_to_be_changed.make_slot()
- );
- editor->signal_script_changed.connect(
- signal_script_changed.make_slot()
- );
- editor->setScript(script);
- //editor->reparent(*this);
- editor->show();
+ editScript(script);
}
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
const Gtk::TreeModel::iterator& iter) {
if (!iter) return;
Gtk::TreeModel::Row row = *iter;
- Glib::ustring name = row[m_Columns.m_col_name];
+ Glib::ustring name = row[m_InstrumentsModel.m_col_name];
#if !USE_GTKMM_BUILDER
// change name in instrument menu
@@ -5256,7 +5393,7 @@
#endif
// change name in gig
- gig::Instrument* instrument = row[m_Columns.m_col_instr];
+ gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
gig::String gigname(gig_from_utf8(name));
if (instrument && instrument->pInfo->Name != gigname) {
instrument->pInfo->Name = gigname;
@@ -5284,7 +5421,7 @@
#else
Gtk::TreeModel::Row row = *iter;
#endif
- Glib::ustring name = row[m_Columns.m_col_name];
+ Glib::ustring name = row[m_InstrumentsModel.m_col_name];
name = name.lowercase();
std::vector tokens = Glib::Regex::split_simple(" ", pattern);
@@ -5302,13 +5439,15 @@
// list view as pre-selection
std::set indeces;
{
- Glib::RefPtr sel = m_TreeView.get_selection();
+ Glib::RefPtr sel = m_TreeViewInstruments.get_selection();
std::vector rows = sel->get_selected_rows();
for (int r = 0; r < rows.size(); ++r) {
- Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
+ // convert index of visual selection (i.e. if filtered) to index of model
+ Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[r]);
+ Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
if (it) {
Gtk::TreeModel::Row row = *it;
- int index = row[m_Columns.m_col_nr];
+ int index = row[m_InstrumentsModel.m_col_nr];
indeces.insert(index);
}
}