30 |
#include <gtkmm/stock.h> |
#include <gtkmm/stock.h> |
31 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
32 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
|
#include <gtkmm/radiomenuitem.h> |
|
33 |
#include <gtkmm/toggleaction.h> |
#include <gtkmm/toggleaction.h> |
34 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
35 |
#include "wrapLabel.hh" |
#include "wrapLabel.hh" |
46 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
47 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
48 |
|
|
|
template<class T> inline std::string ToString(T o) { |
|
|
std::stringstream ss; |
|
|
ss << o; |
|
|
return ss.str(); |
|
|
} |
|
|
|
|
49 |
|
|
50 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
51 |
dimreg_label(_("Changes apply to:")), |
dimreg_label(_("Changes apply to:")), |
60 |
add(m_VBox); |
add(m_VBox); |
61 |
|
|
62 |
// Handle selection |
// Handle selection |
63 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
m_TreeView.get_selection()->signal_changed().connect( |
|
tree_sel_ref->signal_changed().connect( |
|
64 |
sigc::mem_fun(*this, &MainWindow::on_sel_change)); |
sigc::mem_fun(*this, &MainWindow::on_sel_change)); |
65 |
|
|
66 |
// m_TreeView.set_reorderable(); |
// m_TreeView.set_reorderable(); |
128 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
129 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
130 |
|
|
131 |
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
|
132 |
|
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
133 |
|
|
134 |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
135 |
|
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"), "ffaga"); |
136 |
|
toggle_action->set_active(true); |
137 |
|
//FIXME: doesn't work, why? |
138 |
|
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
139 |
|
actionGroup->add(toggle_action); |
140 |
|
|
141 |
|
toggle_action = |
142 |
|
Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); |
143 |
|
toggle_action->set_active(true); |
144 |
|
//FIXME: doesn't work, why? |
145 |
|
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
146 |
|
actionGroup->add(toggle_action); |
147 |
|
|
148 |
|
toggle_action = |
149 |
|
Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); |
150 |
|
toggle_action->set_active(true); |
151 |
|
//FIXME: doesn't work, why? |
152 |
|
toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); |
153 |
|
actionGroup->add(toggle_action); |
154 |
|
|
155 |
|
|
156 |
|
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
157 |
|
toggle_action = |
158 |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
159 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
160 |
actionGroup->add(toggle_action, |
actionGroup->add(toggle_action, |
221 |
" <separator/>" |
" <separator/>" |
222 |
" <menuitem action='Quit'/>" |
" <menuitem action='Quit'/>" |
223 |
" </menu>" |
" </menu>" |
224 |
|
" <menu action='MenuEdit'>" |
225 |
|
" <menuitem action='CopySampleUnity'/>" |
226 |
|
" <menuitem action='CopySampleTune'/>" |
227 |
|
" <menuitem action='CopySampleLoop'/>" |
228 |
|
" </menu>" |
229 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
230 |
" </menu>" |
" </menu>" |
231 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
246 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
247 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
248 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
249 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
250 |
" <separator/>" |
" <separator/>" |
251 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
252 |
" </popup>" |
" </popup>" |
255 |
|
|
256 |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
257 |
|
|
258 |
|
instrument_menu = static_cast<Gtk::MenuItem*>( |
259 |
|
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
260 |
|
|
261 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
262 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
263 |
m_VBox.pack_start(m_HPaned); |
m_VBox.pack_start(m_HPaned); |
282 |
// Create the Tree model: |
// Create the Tree model: |
283 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
284 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
285 |
m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
286 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
287 |
); |
); |
288 |
|
|
400 |
gig::Instrument* MainWindow::get_instrument() |
gig::Instrument* MainWindow::get_instrument() |
401 |
{ |
{ |
402 |
gig::Instrument* instrument = 0; |
gig::Instrument* instrument = 0; |
403 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
Gtk::TreeModel::const_iterator it = |
404 |
|
m_TreeView.get_selection()->get_selected(); |
|
Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); |
|
405 |
if (it) { |
if (it) { |
406 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
407 |
instrument = row[m_Columns.m_col_instr]; |
instrument = row[m_Columns.m_col_instr]; |
460 |
|
|
461 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
462 |
{ |
{ |
463 |
|
// select item in instrument menu |
464 |
|
Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected(); |
465 |
|
if (it) { |
466 |
|
Gtk::TreePath path(it); |
467 |
|
int index = path[0]; |
468 |
|
const std::vector<Gtk::Widget*> children = |
469 |
|
instrument_menu->get_children(); |
470 |
|
static_cast<Gtk::RadioMenuItem*>(children[index])->set_active(); |
471 |
|
} |
472 |
|
|
473 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
474 |
} |
} |
475 |
|
|
548 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
549 |
// before a new .gig file is to be created or to be loaded. |
// before a new .gig file is to be created or to be loaded. |
550 |
void MainWindow::__clear() { |
void MainWindow::__clear() { |
|
// remove all entries from "Instrument" menu |
|
|
Gtk::MenuItem* instrument_menu = |
|
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
|
|
instrument_menu->hide(); |
|
|
Gtk::Menu* menu = instrument_menu->get_submenu(); |
|
|
while (menu->get_children().size()) { |
|
|
Gtk::Widget* child = *menu->get_children().begin(); |
|
|
menu->remove(*child); |
|
|
delete child; |
|
|
} |
|
551 |
// forget all samples that ought to be imported |
// forget all samples that ought to be imported |
552 |
m_SampleImportQueue.clear(); |
m_SampleImportQueue.clear(); |
553 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
554 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
555 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
556 |
|
// remove all entries from "Instrument" menu |
557 |
|
while (!instrument_menu->get_children().empty()) { |
558 |
|
remove_instrument_from_menu(0); |
559 |
|
} |
560 |
// free libgig's gig::File instance |
// free libgig's gig::File instance |
561 |
if (file && !file_is_shared) delete file; |
if (file && !file_is_shared) delete file; |
562 |
file = NULL; |
file = NULL; |
575 |
gig::File* pFile = new gig::File; |
gig::File* pFile = new gig::File; |
576 |
// already add one new instrument by default |
// already add one new instrument by default |
577 |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
578 |
pInstrument->pInfo->Name = _("Unnamed Instrument"); |
pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument")); |
579 |
// update GUI with that new gig::File |
// update GUI with that new gig::File |
580 |
load_gig(pFile, 0 /*no file name yet*/); |
load_gig(pFile, 0 /*no file name yet*/); |
581 |
} |
} |
908 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
909 |
} catch (std::string what) { |
} catch (std::string what) { |
910 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
911 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
912 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += (*iter).sample_path += " (" + what + ")"; |
913 |
++iter; |
++iter; |
914 |
} |
} |
915 |
} |
} |
916 |
// show error message box when some sample(s) could not be imported |
// show error message box when some sample(s) could not be imported |
917 |
if (error_files.size()) { |
if (!error_files.empty()) { |
918 |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
919 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
920 |
msg.run(); |
msg.run(); |
1033 |
} |
} |
1034 |
|
|
1035 |
|
|
1036 |
|
void InstrumentProps::set_Name(const gig::String& name) |
1037 |
|
{ |
1038 |
|
m->pInfo->Name = name; |
1039 |
|
} |
1040 |
|
|
1041 |
|
void InstrumentProps::update_name() |
1042 |
|
{ |
1043 |
|
update_model++; |
1044 |
|
eName.set_value(m->pInfo->Name); |
1045 |
|
update_model--; |
1046 |
|
} |
1047 |
|
|
1048 |
void InstrumentProps::set_IsDrum(bool value) |
void InstrumentProps::set_IsDrum(bool value) |
1049 |
{ |
{ |
1050 |
m->IsDrum = value; |
m->IsDrum = value; |
1087 |
"\"keyswitching\" dimension") |
"\"keyswitching\" dimension") |
1088 |
); |
); |
1089 |
|
|
1090 |
|
connect(eName, &InstrumentProps::set_Name); |
1091 |
connect(eIsDrum, &InstrumentProps::set_IsDrum); |
connect(eIsDrum, &InstrumentProps::set_IsDrum); |
1092 |
connect(eMIDIBank, &InstrumentProps::set_MIDIBank); |
connect(eMIDIBank, &InstrumentProps::set_MIDIBank); |
1093 |
connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); |
connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); |
1100 |
connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, |
connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, |
1101 |
&gig::Instrument::DimensionKeyRange); |
&gig::Instrument::DimensionKeyRange); |
1102 |
|
|
1103 |
|
eName.signal_value_changed().connect(sig_name_changed.make_slot()); |
1104 |
|
|
1105 |
table.set_col_spacings(5); |
table.set_col_spacings(5); |
1106 |
|
|
1107 |
table.add(eName); |
table.add(eName); |
1142 |
update(instrument); |
update(instrument); |
1143 |
|
|
1144 |
update_model++; |
update_model++; |
1145 |
|
eName.set_value(instrument->pInfo->Name); |
1146 |
eIsDrum.set_value(instrument->IsDrum); |
eIsDrum.set_value(instrument->IsDrum); |
1147 |
eMIDIBank.set_value(instrument->MIDIBank); |
eMIDIBank.set_value(instrument->MIDIBank); |
1148 |
eMIDIProgram.set_value(instrument->MIDIProgram); |
eMIDIProgram.set_value(instrument->MIDIProgram); |
1170 |
|
|
1171 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1172 |
|
|
1173 |
Gtk::MenuItem* instrument_menu = |
instrument_name_connection.block(); |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
|
|
|
|
|
int instrument_index = 0; |
|
|
Gtk::RadioMenuItem::Group instrument_group; |
|
1174 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
1175 |
instrument = gig->GetNextInstrument()) { |
instrument = gig->GetNextInstrument()) { |
1176 |
|
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1177 |
|
|
1178 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
1179 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1180 |
row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
row[m_Columns.m_col_name] = name; |
1181 |
row[m_Columns.m_col_instr] = instrument; |
row[m_Columns.m_col_instr] = instrument; |
1182 |
// create a menu item for this instrument |
|
1183 |
Gtk::RadioMenuItem* item = |
add_instrument_to_menu(name); |
|
new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str()); |
|
|
instrument_menu->get_submenu()->append(*item); |
|
|
item->signal_activate().connect( |
|
|
sigc::bind( |
|
|
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
|
|
instrument_index |
|
|
) |
|
|
); |
|
|
instrument_index++; |
|
1184 |
} |
} |
1185 |
instrument_menu->show(); |
instrument_name_connection.unblock(); |
1186 |
instrument_menu->get_submenu()->show_all_children(); |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
1187 |
|
|
1188 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1189 |
if (group->Name != "") { |
if (group->Name != "") { |
1190 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1191 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1192 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
1193 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_group] = group; |
1194 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1195 |
for (gig::Sample* sample = group->GetFirstSample(); |
for (gig::Sample* sample = group->GetFirstSample(); |
1197 |
Gtk::TreeModel::iterator iterSample = |
Gtk::TreeModel::iterator iterSample = |
1198 |
m_refSamplesTreeModel->append(rowGroup.children()); |
m_refSamplesTreeModel->append(rowGroup.children()); |
1199 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
1200 |
rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); |
rowSample[m_SamplesModel.m_col_name] = |
1201 |
|
gig_to_utf8(sample->pInfo->Name); |
1202 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1203 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1204 |
} |
} |
1208 |
file = gig; |
file = gig; |
1209 |
|
|
1210 |
// select the first instrument |
// select the first instrument |
1211 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
1212 |
tree_sel_ref->select(Gtk::TreePath("0")); |
|
1213 |
|
instr_props_set_instrument(); |
1214 |
|
} |
1215 |
|
|
1216 |
|
bool MainWindow::instr_props_set_instrument() |
1217 |
|
{ |
1218 |
|
instrumentProps.signal_name_changed().clear(); |
1219 |
|
|
1220 |
|
Gtk::TreeModel::const_iterator it = |
1221 |
|
m_TreeView.get_selection()->get_selected(); |
1222 |
|
if (it) { |
1223 |
|
Gtk::TreeModel::Row row = *it; |
1224 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1225 |
|
|
|
gig::Instrument* instrument = get_instrument(); |
|
|
if (instrument) { |
|
1226 |
instrumentProps.set_instrument(instrument); |
instrumentProps.set_instrument(instrument); |
1227 |
|
|
1228 |
|
// make sure instrument tree is updated when user changes the |
1229 |
|
// instrument name in instrument properties window |
1230 |
|
instrumentProps.signal_name_changed().connect( |
1231 |
|
sigc::bind( |
1232 |
|
sigc::mem_fun(*this, |
1233 |
|
&MainWindow::instr_name_changed_by_instr_props), |
1234 |
|
it)); |
1235 |
|
} else { |
1236 |
|
instrumentProps.hide(); |
1237 |
} |
} |
1238 |
|
return it; |
1239 |
} |
} |
1240 |
|
|
1241 |
void MainWindow::show_instr_props() |
void MainWindow::show_instr_props() |
1242 |
{ |
{ |
1243 |
gig::Instrument* instrument = get_instrument(); |
if (instr_props_set_instrument()) { |
|
if (instrument) |
|
|
{ |
|
|
instrumentProps.set_instrument(instrument); |
|
1244 |
instrumentProps.show(); |
instrumentProps.show(); |
1245 |
instrumentProps.deiconify(); |
instrumentProps.deiconify(); |
1246 |
} |
} |
1247 |
} |
} |
1248 |
|
|
1249 |
|
void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it) |
1250 |
|
{ |
1251 |
|
Gtk::TreeModel::Row row = *it; |
1252 |
|
Glib::ustring name = row[m_Columns.m_col_name]; |
1253 |
|
|
1254 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1255 |
|
Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name)); |
1256 |
|
if (gigname != name) { |
1257 |
|
row[m_Columns.m_col_name] = gigname; |
1258 |
|
} |
1259 |
|
} |
1260 |
|
|
1261 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1262 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1263 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1269 |
else m_StatusBar.hide(); |
else m_StatusBar.hide(); |
1270 |
} |
} |
1271 |
|
|
1272 |
|
bool MainWindow::is_copy_samples_unity_note_enabled() const { |
1273 |
|
Gtk::CheckMenuItem* item = |
1274 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
1275 |
|
if (!item) { |
1276 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n"; |
1277 |
|
return true; |
1278 |
|
} |
1279 |
|
return item->get_active(); |
1280 |
|
} |
1281 |
|
|
1282 |
|
bool MainWindow::is_copy_samples_fine_tune_enabled() const { |
1283 |
|
Gtk::CheckMenuItem* item = |
1284 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
1285 |
|
if (!item) { |
1286 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n"; |
1287 |
|
return true; |
1288 |
|
} |
1289 |
|
return item->get_active(); |
1290 |
|
} |
1291 |
|
|
1292 |
|
bool MainWindow::is_copy_samples_loop_enabled() const { |
1293 |
|
Gtk::CheckMenuItem* item = |
1294 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
1295 |
|
if (!item) { |
1296 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n"; |
1297 |
|
return true; |
1298 |
|
} |
1299 |
|
return item->get_active(); |
1300 |
|
} |
1301 |
|
|
1302 |
void MainWindow::on_button_release(GdkEventButton* button) |
void MainWindow::on_button_release(GdkEventButton* button) |
1303 |
{ |
{ |
1304 |
if (button->type == GDK_2BUTTON_PRESS) { |
if (button->type == GDK_2BUTTON_PRESS) { |
1308 |
} |
} |
1309 |
} |
} |
1310 |
|
|
1311 |
void MainWindow::on_instrument_selection_change(int index) { |
void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) { |
1312 |
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
if (item->get_active()) { |
1313 |
|
const std::vector<Gtk::Widget*> children = |
1314 |
|
instrument_menu->get_children(); |
1315 |
|
std::vector<Gtk::Widget*>::const_iterator it = |
1316 |
|
find(children.begin(), children.end(), item); |
1317 |
|
if (it != children.end()) { |
1318 |
|
int index = it - children.begin(); |
1319 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index))); |
1320 |
|
|
1321 |
|
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
1322 |
|
} |
1323 |
|
} |
1324 |
} |
} |
1325 |
|
|
1326 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
1350 |
} |
} |
1351 |
} |
} |
1352 |
|
|
1353 |
void MainWindow::on_action_add_instrument() { |
|
1354 |
static int __instrument_indexer = 0; |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1355 |
if (!file) return; |
const Glib::ustring& name, int position) { |
1356 |
gig::Instrument* instrument = file->AddInstrument(); |
|
1357 |
__instrument_indexer++; |
Gtk::RadioMenuItem::Group instrument_group; |
1358 |
instrument->pInfo->Name = |
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
1359 |
_("Unnamed Instrument ") + ToString(__instrument_indexer); |
if (!children.empty()) { |
1360 |
|
instrument_group = |
1361 |
|
static_cast<Gtk::RadioMenuItem*>(children[0])->get_group(); |
1362 |
|
} |
1363 |
|
Gtk::RadioMenuItem* item = |
1364 |
|
new Gtk::RadioMenuItem(instrument_group, name); |
1365 |
|
if (position < 0) { |
1366 |
|
instrument_menu->append(*item); |
1367 |
|
} else { |
1368 |
|
instrument_menu->insert(*item, position); |
1369 |
|
} |
1370 |
|
item->show(); |
1371 |
|
item->signal_activate().connect( |
1372 |
|
sigc::bind( |
1373 |
|
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
1374 |
|
item)); |
1375 |
|
return item; |
1376 |
|
} |
1377 |
|
|
1378 |
|
void MainWindow::remove_instrument_from_menu(int index) { |
1379 |
|
const std::vector<Gtk::Widget*> children = |
1380 |
|
instrument_menu->get_children(); |
1381 |
|
Gtk::Widget* child = children[index]; |
1382 |
|
instrument_menu->remove(*child); |
1383 |
|
delete child; |
1384 |
|
} |
1385 |
|
|
1386 |
|
void MainWindow::add_instrument(gig::Instrument* instrument) { |
1387 |
|
const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1388 |
|
|
1389 |
// update instrument tree view |
// update instrument tree view |
1390 |
|
instrument_name_connection.block(); |
1391 |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
1392 |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
1393 |
rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
rowInstr[m_Columns.m_col_name] = name; |
1394 |
rowInstr[m_Columns.m_col_instr] = instrument; |
rowInstr[m_Columns.m_col_instr] = instrument; |
1395 |
|
instrument_name_connection.unblock(); |
1396 |
|
|
1397 |
|
add_instrument_to_menu(name); |
1398 |
|
|
1399 |
|
m_TreeView.get_selection()->select(iterInstr); |
1400 |
|
|
1401 |
file_changed(); |
file_changed(); |
1402 |
} |
} |
1403 |
|
|
1404 |
|
void MainWindow::on_action_add_instrument() { |
1405 |
|
static int __instrument_indexer = 0; |
1406 |
|
if (!file) return; |
1407 |
|
gig::Instrument* instrument = file->AddInstrument(); |
1408 |
|
__instrument_indexer++; |
1409 |
|
instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") + |
1410 |
|
ToString(__instrument_indexer)); |
1411 |
|
|
1412 |
|
add_instrument(instrument); |
1413 |
|
} |
1414 |
|
|
1415 |
void MainWindow::on_action_duplicate_instrument() { |
void MainWindow::on_action_duplicate_instrument() { |
1416 |
if (!file) return; |
if (!file) return; |
1417 |
|
|
1418 |
// retrieve the currently selected instrument |
// retrieve the currently selected instrument |
1419 |
// (being the original instrument to be duplicated) |
// (being the original instrument to be duplicated) |
1420 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1423 |
Gtk::TreeModel::Row row = *itSelection; |
Gtk::TreeModel::Row row = *itSelection; |
1424 |
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
1425 |
if (!instrOrig) return; |
if (!instrOrig) return; |
1426 |
|
|
1427 |
// duplicate the orginal instrument |
// duplicate the orginal instrument |
1428 |
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
1429 |
instrNew->pInfo->Name = |
instrNew->pInfo->Name = |
1430 |
instrOrig->pInfo->Name + " (" + _("Copy") + ")"; |
instrOrig->pInfo->Name + |
1431 |
|
gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); |
1432 |
// update instrument tree view |
|
1433 |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
add_instrument(instrNew); |
|
Gtk::TreeModel::Row rowInstr = *iterInstr; |
|
|
rowInstr[m_Columns.m_col_name] = instrNew->pInfo->Name.c_str(); |
|
|
rowInstr[m_Columns.m_col_instr] = instrNew; |
|
|
file_changed(); |
|
1434 |
} |
} |
1435 |
|
|
1436 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
1452 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
1453 |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
1454 |
try { |
try { |
1455 |
|
Gtk::TreePath path(it); |
1456 |
|
int index = path[0]; |
1457 |
|
|
1458 |
// remove instrument from the gig file |
// remove instrument from the gig file |
1459 |
if (instr) file->DeleteInstrument(instr); |
if (instr) file->DeleteInstrument(instr); |
|
// remove respective row from instruments tree view |
|
|
m_refTreeModel->erase(it); |
|
1460 |
file_changed(); |
file_changed(); |
1461 |
|
|
1462 |
instr = get_instrument(); |
remove_instrument_from_menu(index); |
1463 |
if (instr) { |
|
1464 |
instrumentProps.set_instrument(instr); |
// remove row from instruments tree view |
1465 |
} else { |
m_refTreeModel->erase(it); |
1466 |
instrumentProps.hide(); |
|
1467 |
|
#if GTKMM_MAJOR_VERSION < 3 |
1468 |
|
// select another instrument (in gtk3 this is done |
1469 |
|
// automatically) |
1470 |
|
if (!m_refTreeModel->children().empty()) { |
1471 |
|
if (index == m_refTreeModel->children().size()) { |
1472 |
|
index--; |
1473 |
|
} |
1474 |
|
m_TreeView.get_selection()->select( |
1475 |
|
Gtk::TreePath(ToString(index))); |
1476 |
} |
} |
1477 |
|
#endif |
1478 |
|
instr_props_set_instrument(); |
1479 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1480 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1481 |
msg.run(); |
msg.run(); |
1495 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
1496 |
if (!file) return; |
if (!file) return; |
1497 |
gig::Group* group = file->AddGroup(); |
gig::Group* group = file->AddGroup(); |
1498 |
group->Name = _("Unnamed Group"); |
group->Name = gig_from_utf8(_("Unnamed Group")); |
1499 |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
1500 |
__sample_indexer++; |
__sample_indexer++; |
1501 |
// update sample tree view |
// update sample tree view |
1502 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1503 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1504 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
1505 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1506 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_group] = group; |
1507 |
file_changed(); |
file_changed(); |
1610 |
break; |
break; |
1611 |
} |
} |
1612 |
} |
} |
1613 |
sample->pInfo->Name = filename; |
sample->pInfo->Name = gig_from_utf8(filename); |
1614 |
sample->Channels = info.channels; |
sample->Channels = info.channels; |
1615 |
sample->BitDepth = bitdepth; |
sample->BitDepth = bitdepth; |
1616 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
1661 |
Gtk::TreeModel::iterator iterSample = |
Gtk::TreeModel::iterator iterSample = |
1662 |
m_refSamplesTreeModel->append(row.children()); |
m_refSamplesTreeModel->append(row.children()); |
1663 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
1664 |
rowSample[m_SamplesModel.m_col_name] = filename; |
rowSample[m_SamplesModel.m_col_name] = |
1665 |
|
gig_to_utf8(sample->pInfo->Name); |
1666 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1667 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1668 |
// close sound file |
// close sound file |
1669 |
sf_close(hFile); |
sf_close(hFile); |
1670 |
file_changed(); |
file_changed(); |
1671 |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
1672 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1673 |
error_files += *iter += " (" + what + ")"; |
error_files += *iter += " (" + what + ")"; |
1674 |
} |
} |
1675 |
} |
} |
1676 |
// show error message box when some file(s) could not be opened / added |
// show error message box when some file(s) could not be opened / added |
1677 |
if (error_files.size()) { |
if (!error_files.empty()) { |
1678 |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
1679 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1680 |
msg.run(); |
msg.run(); |
1687 |
if (!file) return; |
if (!file) return; |
1688 |
Gtk::FileChooserDialog dialog(*this, _("Select Folder"), |
Gtk::FileChooserDialog dialog(*this, _("Select Folder"), |
1689 |
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
1690 |
const char* str = |
const char* str = |
1691 |
_("This is a very specific function. It tries to replace all samples " |
_("This is a very specific function. It tries to replace all samples " |
1692 |
"in the current gig file by samples located in the chosen " |
"in the current gig file by samples located in the chosen " |
1693 |
"directory.\n\n" |
"directory.\n\n" |
1733 |
sample; sample = file->GetNextSample()) |
sample; sample = file->GetNextSample()) |
1734 |
{ |
{ |
1735 |
std::string filename = |
std::string filename = |
1736 |
folder + G_DIR_SEPARATOR_S + sample->pInfo->Name + |
folder + G_DIR_SEPARATOR_S + |
1737 |
postfixEntryBox.get_text().raw(); |
Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) + |
1738 |
|
postfixEntryBox.get_text()); |
1739 |
SF_INFO info; |
SF_INFO info; |
1740 |
info.format = 0; |
info.format = 0; |
1741 |
SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); |
1768 |
} |
} |
1769 |
catch (std::string what) |
catch (std::string what) |
1770 |
{ |
{ |
1771 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1772 |
error_files += filename += " (" + what + ")"; |
error_files += Glib::filename_to_utf8(filename) + |
1773 |
|
" (" + what + ")"; |
1774 |
} |
} |
1775 |
} |
} |
1776 |
// show error message box when some file(s) could not be opened / added |
// show error message box when some file(s) could not be opened / added |
1777 |
if (error_files.size()) { |
if (!error_files.empty()) { |
1778 |
Glib::ustring txt = |
Glib::ustring txt = |
1779 |
_("Could not replace the following sample(s):\n") + error_files; |
_("Could not replace the following sample(s):\n") + error_files; |
1780 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1795 |
try { |
try { |
1796 |
// remove group or sample from the gig file |
// remove group or sample from the gig file |
1797 |
if (group) { |
if (group) { |
1798 |
// temporarily remember the samples that bolong to |
// temporarily remember the samples that belong to |
1799 |
// that group (we need that to clean the queue) |
// that group (we need that to clean the queue) |
1800 |
std::list<gig::Sample*> members; |
std::list<gig::Sample*> members; |
1801 |
for (gig::Sample* pSample = group->GetFirstSample(); |
for (gig::Sample* pSample = group->GetFirstSample(); |
1921 |
channels_changed = true; |
channels_changed = true; |
1922 |
region_changed(); |
region_changed(); |
1923 |
} |
} |
1924 |
dimreg_edit.set_sample(sample); |
dimreg_edit.set_sample( |
1925 |
|
sample, |
1926 |
|
is_copy_samples_unity_note_enabled(), |
1927 |
|
is_copy_samples_fine_tune_enabled(), |
1928 |
|
is_copy_samples_loop_enabled() |
1929 |
|
); |
1930 |
|
|
1931 |
if (sample->Channels == 2 && !stereo_dimension) { |
if (sample->Channels == 2 && !stereo_dimension) { |
1932 |
// add samplechannel dimension |
// add samplechannel dimension |
1969 |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
1970 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
1971 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
1972 |
|
gig::String gigname(gig_from_utf8(name)); |
1973 |
if (group) { |
if (group) { |
1974 |
if (group->Name != name) { |
if (group->Name != gigname) { |
1975 |
group->Name = name; |
group->Name = gigname; |
1976 |
printf("group name changed\n"); |
printf("group name changed\n"); |
1977 |
file_changed(); |
file_changed(); |
1978 |
} |
} |
1979 |
} else if (sample) { |
} else if (sample) { |
1980 |
if (sample->pInfo->Name != name.raw()) { |
if (sample->pInfo->Name != gigname) { |
1981 |
sample->pInfo->Name = name.raw(); |
sample->pInfo->Name = gigname; |
1982 |
printf("sample name changed\n"); |
printf("sample name changed\n"); |
1983 |
file_changed(); |
file_changed(); |
1984 |
} |
} |
1990 |
if (!iter) return; |
if (!iter) return; |
1991 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1992 |
Glib::ustring name = row[m_Columns.m_col_name]; |
Glib::ustring name = row[m_Columns.m_col_name]; |
1993 |
|
|
1994 |
|
// change name in instrument menu |
1995 |
|
int index = path[0]; |
1996 |
|
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
1997 |
|
if (index < children.size()) { |
1998 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2 |
1999 |
|
static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name); |
2000 |
|
#else |
2001 |
|
remove_instrument_from_menu(index); |
2002 |
|
Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index); |
2003 |
|
item->set_active(); |
2004 |
|
#endif |
2005 |
|
} |
2006 |
|
|
2007 |
|
// change name in gig |
2008 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
2009 |
if (instrument && instrument->pInfo->Name != name.raw()) { |
gig::String gigname(gig_from_utf8(name)); |
2010 |
instrument->pInfo->Name = name.raw(); |
if (instrument && instrument->pInfo->Name != gigname) { |
2011 |
|
instrument->pInfo->Name = gigname; |
2012 |
|
|
2013 |
|
// change name in the instrument properties window |
2014 |
|
if (instrumentProps.get_instrument() == instrument) { |
2015 |
|
instrumentProps.update_name(); |
2016 |
|
} |
2017 |
|
|
2018 |
file_changed(); |
file_changed(); |
2019 |
} |
} |
2020 |
} |
} |