--- gigedit/trunk/src/gigedit/mainwindow.cpp 2017/05/08 21:31:45 3160
+++ gigedit/trunk/src/gigedit/mainwindow.cpp 2017/07/30 18:57:35 3339
@@ -62,6 +62,16 @@
#include "gfx/builtinpix.h"
#include "MacroEditor.h"
#include "MacrosSetup.h"
+#if defined(__APPLE__)
+# include "MacHelper.h"
+#endif
+
+static const Gdk::ModifierType primaryModifierKey =
+ #if defined(__APPLE__)
+ Gdk::META_MASK; // Cmd key on Mac
+ #else
+ Gdk::CONTROL_MASK; // Ctrl key on all other OSs
+ #endif
MainWindow::MainWindow() :
m_DimRegionChooser(*this),
@@ -77,8 +87,14 @@
{
loadBuiltInPix();
+ this->file = NULL;
+
// set_border_width(5);
-// set_default_size(400, 200);
+
+ if (!Settings::singleton()->autoRestoreWindowDimension) {
+ set_default_size(800, 600);
+ set_position(Gtk::WIN_POS_CENTER);
+ }
add(m_VBox);
@@ -207,6 +223,7 @@
sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
);
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
+ actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
@@ -232,6 +249,16 @@
Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
+ actionGroup->add(Gtk::Action::create("SelectPrevInstr",
+ _("Select Previous Instrument")),
+ Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
+ sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
+
+ actionGroup->add(Gtk::Action::create("SelectNextInstr",
+ _("Select Next Instrument")),
+ Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
+ sigc::mem_fun(*this, &MainWindow::select_next_instrument));
+
actionGroup->add(Gtk::Action::create("SelectPrevRegion",
_("Select Previous Region")),
Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
@@ -333,6 +360,11 @@
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
);
actionGroup->add(
+ Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
+ Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
+ sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
+ );
+ actionGroup->add(
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
);
@@ -455,6 +487,9 @@
" "
" "
" "
+ " "
+ " "
+ " "
" "
" "
" "
@@ -489,8 +524,10 @@
" "
" "
" "
+ "
"
" "
" "
+ " "
" "
" "
" "
@@ -527,6 +564,7 @@
" "
" "
" "
+ " "
" "
" "
" "
@@ -621,6 +659,9 @@
instrument_menu = static_cast(
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
+ assign_scripts_menu = static_cast(
+ uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
+
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
m_VBox.pack_start(m_HPaned);
@@ -654,6 +695,7 @@
// 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);
// establish drag&drop within the instrument tree view, allowing to reorder
@@ -843,13 +885,6 @@
uiManager->get_widget("/MenuBar/MenuMacro")
)->get_submenu();
- const Gdk::ModifierType primaryModifierKey =
-#if defined(__APPLE__)
- Gdk::META_MASK; // Cmd key on Mac
-#else
- Gdk::CONTROL_MASK; // Ctrl key on all other OSs
-#endif
-
const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
Gtk::AccelMap::add_entry("/macro_0", GDK_KEY_F1, noModifier);
Gtk::AccelMap::add_entry("/macro_1", GDK_KEY_F2, noModifier);
@@ -870,12 +905,44 @@
updateMacroMenu();
}
+
+ // setup "Assign Scripts" keyboard accelerators
+ {
+ Gtk::AccelMap::add_entry("/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
+ Gtk::AccelMap::add_entry("/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
+
+ Glib::RefPtr accelGroup = this->get_accel_group();
+ assign_scripts_menu->set_accel_group(accelGroup);
+ }
+
+ Glib::signal_idle().connect_once(
+ sigc::mem_fun(*this, &MainWindow::bringToFront),
+ 200
+ );
}
MainWindow::~MainWindow()
{
}
+void MainWindow::bringToFront() {
+ #if defined(__APPLE__)
+ macRaiseAppWindow();
+ #endif
+ raise();
+ present();
+}
+
void MainWindow::updateMacroMenu() {
Gtk::Menu* menuMacro = dynamic_cast(
uiManager->get_widget("/MenuBar/MenuMacro")
@@ -914,6 +981,9 @@
);
menuMacro->append(*item);
item->set_accel_path("/macro_" + ToString(iMacro));
+ Glib::ustring comment = macro.comment();
+ if (!comment.empty())
+ item->set_tooltip_text(comment);
}
// if there are no macros configured at all, then show a dummy entry instead
if (m_macros.empty()) {
@@ -1071,6 +1141,8 @@
}
}
+ updateScriptListOfMenu();
+
m_RegionChooser.set_instrument(get_instrument());
if (Settings::singleton()->syncSamplerInstrumentSelection) {
@@ -1201,7 +1273,7 @@
// save the file as separate temporary file first,
// then move the saved file over the old file
// (may result in performance speedup during save)
- String tmpname = filename + ".TMP";
+ gig::String tmpname = filename + ".TMP";
gig->Save(tmpname, &progress);
#if defined(WIN32)
if (!DeleteFile(filename.c_str())) {
@@ -1209,14 +1281,14 @@
}
#else // POSIX ...
if (unlink(filename.c_str())) {
- throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
+ throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
}
#endif
if (rename(tmpname.c_str(), filename.c_str())) {
#if defined(WIN32)
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
#else
- throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
+ throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
#endif
}
}
@@ -1812,6 +1884,7 @@
dialog.set_comments(sComment.c_str());
dialog.set_website("http://www.linuxsampler.org");
dialog.set_website_label("http://www.linuxsampler.org");
+ dialog.set_position(Gtk::WIN_POS_CENTER);
dialog.run();
}
@@ -1837,6 +1910,11 @@
table(2, 1),
m_file(NULL)
{
+ if (!Settings::singleton()->autoRestoreWindowDimension) {
+ set_default_size(470, 390);
+ set_position(Gtk::WIN_POS_MOUSE);
+ }
+
set_title(_("File Properties"));
eName.set_width_chars(50);
@@ -1971,6 +2049,11 @@
eDimensionKeyRangeLow(_("Keyswitching range low")),
eDimensionKeyRangeHigh(_("Keyswitching range high"))
{
+ if (!Settings::singleton()->autoRestoreWindowDimension) {
+ //set_default_size(470, 390);
+ set_position(Gtk::WIN_POS_MOUSE);
+ }
+
set_title(_("Instrument Properties"));
eDimensionKeyRangeLow.set_tip(
@@ -2095,12 +2178,14 @@
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
instrument = gig->GetNextInstrument(), ++index) {
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
+ const int iScriptSlots = instrument->ScriptSlotCount();
Gtk::TreeModel::iterator iter = m_refTreeModel->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) : "";
add_instrument_to_menu(name);
}
@@ -2239,10 +2324,47 @@
ScriptSlots* window = new ScriptSlots;
window->setInstrument(instrument);
+ window->signal_script_slots_changed().connect(
+ sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
+ );
//window->reparent(*this);
window->show();
}
+void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
+ if (!pInstrument) return;
+ const int iScriptSlots = pInstrument->ScriptSlotCount();
+
+ Glib::RefPtr model = m_TreeView.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) : "";
+ break;
+ }
+
+ // causes the sampler to reload the instrument with the new script
+ on_sel_change();
+}
+
+void MainWindow::assignScript(gig::Script* pScript) {
+ if (!pScript) {
+ printf("assignScript() : !script\n");
+ return;
+ }
+ printf("assignScript('%s')\n", pScript->Name.c_str());
+
+ gig::Instrument* pInstrument = get_instrument();
+ if (!pInstrument) {
+ printf("!instrument\n");
+ return;
+ }
+
+ pInstrument->AddScriptSlot(pScript);
+
+ onScriptSlotsModified(pInstrument);
+}
+
void MainWindow::on_action_refresh_all() {
__refreshEntireGUI();
}
@@ -2515,6 +2637,52 @@
}
}
+void MainWindow::updateScriptListOfMenu() {
+ // remove all entries from "Assign Script" menu
+ {
+ const std::vector children = assign_scripts_menu->get_children();
+ for (int i = 0; i < children.size(); ++i) {
+ Gtk::Widget* child = children[i];
+ assign_scripts_menu->remove(*child);
+ delete child;
+ }
+ }
+
+ int iTotalScripts = 0;
+
+ if (!file) goto noScripts;
+
+ // add all configured macros as menu items to the "Macro" menu
+ for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
+ gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
+ for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
+ gig::Script* pScript = pGroup->GetScript(iScript);
+ std::string name = pScript->Name;
+
+ Gtk::MenuItem* item = new Gtk::MenuItem(name);
+ item->signal_activate().connect(
+ sigc::bind(
+ sigc::mem_fun(*this, &MainWindow::assignScript), pScript
+ )
+ );
+ assign_scripts_menu->append(*item);
+ item->set_accel_path("/script_" + ToString(iTotalScripts));
+ //item->set_tooltip_text(comment);
+ }
+ }
+
+ noScripts:
+
+ // if there are no macros configured at all, then show a dummy entry instead
+ if (!iTotalScripts) {
+ Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
+ item->set_sensitive(false);
+ assign_scripts_menu->append(*item);
+ }
+
+ assign_scripts_menu->show_all_children();
+}
+
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
const Glib::ustring& name, int position) {
@@ -2557,12 +2725,11 @@
rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
rowInstr[m_Columns.m_col_name] = name;
rowInstr[m_Columns.m_col_instr] = instrument;
+ rowInstr[m_Columns.m_col_scripts] = "";
instrument_name_connection.unblock();
add_instrument_to_menu(name);
-
- m_TreeView.get_selection()->select(iterInstr);
-
+ select_instrument(instrument);
file_changed();
}
@@ -3534,8 +3701,25 @@
void MainWindow::on_action_combine_instruments() {
CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
+
+ // take over selection from instruments list view for the combine dialog's
+ // list view as pre-selection
+ std::set indeces;
+ {
+ Glib::RefPtr sel = m_TreeView.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]);
+ if (it) {
+ Gtk::TreeModel::Row row = *it;
+ int index = row[m_Columns.m_col_nr];
+ indeces.insert(index);
+ }
+ }
+ }
+ d->setSelectedInstruments(indeces);
+
d->show_all();
- d->resize(500, 400);
d->run();
if (d->fileWasChanged()) {
// update GUI with new instrument just created
@@ -3797,6 +3981,29 @@
m_TreeViewNotebook.set_current_page(2);
}
+void MainWindow::select_instrument_by_dir(int dir) {
+ if (!file) return;
+ gig::Instrument* pInstrument = get_instrument();
+ if (!pInstrument) {
+ select_instrument( file->GetInstrument(0) );
+ return;
+ }
+ for (int i = 0; file->GetInstrument(i); ++i) {
+ if (file->GetInstrument(i) == pInstrument) {
+ select_instrument( file->GetInstrument(i + dir) );
+ return;
+ }
+ }
+}
+
+void MainWindow::select_prev_instrument() {
+ select_instrument_by_dir(-1);
+}
+
+void MainWindow::select_next_instrument() {
+ select_instrument_by_dir(1);
+}
+
void MainWindow::select_prev_region() {
m_RegionChooser.select_prev_region();
}
@@ -3870,7 +4077,7 @@
void MainWindow::adjust_clipboard_content() {
MacroEditor* editor = new MacroEditor();
- editor->setMacro(&m_serializationArchive);
+ editor->setMacro(&m_serializationArchive, true);
editor->show();
}
@@ -3920,9 +4127,8 @@
itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
{
gig::DimensionRegion* pDimRgn = *itDimReg;
- dimreg_to_be_changed_signal.emit(pDimRgn);
+ DimRegionChangeGuard(this, pDimRgn);
macro.deserialize(pDimRgn);
- dimreg_changed_signal.emit(pDimRgn);
}
//region_changed()
file_changed();