1 |
/* |
/* |
2 |
Copyright (c) 2014-2017 Christian Schoenebeck |
Copyright (c) 2014-2020 Christian Schoenebeck |
3 |
|
|
4 |
This file is part of "gigedit" and released under the terms of the |
This file is part of "gigedit" and released under the terms of the |
5 |
GNU General Public License version 2. |
GNU General Public License version 2. |
6 |
*/ |
*/ |
20 |
#include <string.h> |
#include <string.h> |
21 |
|
|
22 |
#include <glibmm/ustring.h> |
#include <glibmm/ustring.h> |
23 |
#include <gtkmm/stock.h> |
#if HAS_GTKMM_STOCK |
24 |
|
# include <gtkmm/stock.h> |
25 |
|
#endif |
26 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
27 |
#include <gtkmm/label.h> |
#include <gtkmm/label.h> |
28 |
#include <gtk/gtkwidget.h> // for gtk_widget_modify_*() |
#include <gtk/gtkwidget.h> // for gtk_widget_modify_*() |
225 |
static Dimensions getDimensionsForRegionGroup(RegionGroup& regionGroup) { |
static Dimensions getDimensionsForRegionGroup(RegionGroup& regionGroup) { |
226 |
std::map<gig::dimension_t, std::set<int> > dimUpperLimits; |
std::map<gig::dimension_t, std::set<int> > dimUpperLimits; |
227 |
|
|
228 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
229 |
|
printf("dimUpperLimits = {\n"); |
230 |
|
#endif |
231 |
// collect all dimension region zones' upper limits |
// collect all dimension region zones' upper limits |
232 |
for (RegionGroup::iterator it = regionGroup.begin(); |
for (RegionGroup::iterator it = regionGroup.begin(); |
233 |
it != regionGroup.end(); ++it) |
it != regionGroup.end(); ++it) |
236 |
int previousBits = 0; |
int previousBits = 0; |
237 |
for (uint d = 0; d < rgn->Dimensions; ++d) { |
for (uint d = 0; d < rgn->Dimensions; ++d) { |
238 |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[d]; |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[d]; |
239 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
240 |
|
printf("\t[rgn=%p,dim=%#x] = {", rgn, def.dimension); |
241 |
|
#endif |
242 |
for (uint z = 0; z < def.zones; ++z) { |
for (uint z = 0; z < def.zones; ++z) { |
243 |
int dr = z << previousBits; |
int dr = z << previousBits; |
244 |
gig::DimensionRegion* dimRgn = rgn->pDimensionRegions[dr]; |
gig::DimensionRegion* dimRgn = rgn->pDimensionRegions[dr]; |
251 |
// velocity splits of all regions is stored here, and when their |
// velocity splits of all regions is stored here, and when their |
252 |
// individual DimensionRegions are finally copied (later), the |
// individual DimensionRegions are finally copied (later), the |
253 |
// individual velocity split size are copied by that. |
// individual velocity split size are copied by that. |
254 |
dimUpperLimits[def.dimension].insert( |
const int upperLimit = |
255 |
(def.dimension == gig::dimension_velocity) ? |
(def.dimension == gig::dimension_velocity) ? |
256 |
z : (def.split_type == gig::split_type_bit) ? |
z : (def.split_type == gig::split_type_bit) ? |
257 |
((z+1) * 128/def.zones - 1) : dimRgn->DimensionUpperLimits[dr] |
((z+1) * 128/def.zones - 1) : dimRgn->DimensionUpperLimits[dr]; |
258 |
); |
#if DEBUG_COMBINE_INSTRUMENTS |
259 |
|
printf(" %d,", upperLimit); |
260 |
|
#endif |
261 |
|
dimUpperLimits[def.dimension].insert(upperLimit); |
262 |
} |
} |
263 |
previousBits += def.bits; |
previousBits += def.bits; |
264 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
265 |
|
printf(" }\n"); |
266 |
|
#endif |
267 |
} |
} |
268 |
} |
} |
269 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
270 |
|
printf("}\n"); |
271 |
|
#endif |
272 |
|
|
273 |
// convert upper limit set to range vector |
// convert upper limit set to range vector |
274 |
Dimensions dims; |
Dimensions dims; |
275 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
276 |
|
printf("dims = {\n"); |
277 |
|
#endif |
278 |
for (std::map<gig::dimension_t, std::set<int> >::const_iterator it = dimUpperLimits.begin(); |
for (std::map<gig::dimension_t, std::set<int> >::const_iterator it = dimUpperLimits.begin(); |
279 |
it != dimUpperLimits.end(); ++it) |
it != dimUpperLimits.end(); ++it) |
280 |
{ |
{ |
281 |
gig::dimension_t type = it->first; |
gig::dimension_t type = it->first; |
282 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
283 |
|
printf("\t[dim=%#x] = {", type); |
284 |
|
#endif |
285 |
int iLow = 0; |
int iLow = 0; |
286 |
for (std::set<int>::const_iterator itNums = it->second.begin(); |
for (std::set<int>::const_iterator itNums = it->second.begin(); |
287 |
itNums != it->second.end(); ++itNums) |
itNums != it->second.end(); ++itNums) |
289 |
const int iUpperLimit = *itNums; |
const int iUpperLimit = *itNums; |
290 |
DLS::range_t range = { uint16_t(iLow), uint16_t(iUpperLimit) }; |
DLS::range_t range = { uint16_t(iLow), uint16_t(iUpperLimit) }; |
291 |
dims[type].push_back(range); |
dims[type].push_back(range); |
292 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
293 |
|
printf(" %d..%d,", iLow, iUpperLimit); |
294 |
|
#endif |
295 |
iLow = iUpperLimit + 1; |
iLow = iUpperLimit + 1; |
296 |
} |
} |
297 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
298 |
|
printf(" }\n"); |
299 |
|
#endif |
300 |
} |
} |
301 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
302 |
|
printf("}\n"); |
303 |
|
#endif |
304 |
|
|
305 |
return dims; |
return dims; |
306 |
} |
} |
814 |
CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig) |
CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig) |
815 |
: ManagedDialog(_("Combine Instruments"), parent, true), |
: ManagedDialog(_("Combine Instruments"), parent, true), |
816 |
m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL), |
m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL), |
817 |
|
#if HAS_GTKMM_STOCK |
818 |
m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK), |
m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK), |
819 |
m_descriptionLabel(), m_tableDimCombo(2, 2), m_comboDimType(), |
#else |
820 |
|
m_cancelButton(_("_Cancel"), true), m_OKButton(_("_OK"), true), |
821 |
|
#endif |
822 |
|
m_descriptionLabel(), |
823 |
|
#if USE_GTKMM_GRID |
824 |
|
m_tableDimCombo(), |
825 |
|
#else |
826 |
|
m_tableDimCombo(2, 2), |
827 |
|
#endif |
828 |
|
m_comboDimType(), |
829 |
m_labelDimType(Glib::ustring(_("Combine by Dimension:")) + " ", Gtk::ALIGN_END) |
m_labelDimType(Glib::ustring(_("Combine by Dimension:")) + " ", Gtk::ALIGN_END) |
830 |
{ |
{ |
831 |
if (!Settings::singleton()->autoRestoreWindowDimension) { |
if (!Settings::singleton()->autoRestoreWindowDimension) { |
836 |
m_scrolledWindow.add(m_treeView); |
m_scrolledWindow.add(m_treeView); |
837 |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
838 |
|
|
839 |
|
#if USE_GTKMM_BOX |
840 |
|
get_content_area()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
841 |
|
get_content_area()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK); |
842 |
|
get_content_area()->pack_start(m_scrolledWindow); |
843 |
|
get_content_area()->pack_start(m_labelOrder, Gtk::PACK_SHRINK); |
844 |
|
get_content_area()->pack_start(m_iconView, Gtk::PACK_SHRINK); |
845 |
|
get_content_area()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
846 |
|
#else |
847 |
get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
848 |
get_vbox()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK); |
849 |
get_vbox()->pack_start(m_scrolledWindow); |
get_vbox()->pack_start(m_scrolledWindow); |
850 |
get_vbox()->pack_start(m_labelOrder, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_labelOrder, Gtk::PACK_SHRINK); |
851 |
get_vbox()->pack_start(m_iconView, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_iconView, Gtk::PACK_SHRINK); |
852 |
get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
853 |
|
#endif |
854 |
|
|
855 |
#if GTKMM_MAJOR_VERSION >= 3 |
#if GTKMM_MAJOR_VERSION >= 3 |
856 |
m_descriptionLabel.set_line_wrap(); |
m_descriptionLabel.set_line_wrap(); |
935 |
// (this also fixes a bug with GTK 2 which often causes visibility issue |
// (this also fixes a bug with GTK 2 which often causes visibility issue |
936 |
// with the text of the selected item) |
// with the text of the selected item) |
937 |
{ |
{ |
938 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
939 |
Gdk::Color white; |
Gdk::Color white; |
940 |
|
#else |
941 |
|
Gdk::RGBA white; |
942 |
|
#endif |
943 |
white.set("#ffffff"); |
white.set("#ffffff"); |
944 |
GtkWidget* widget = (GtkWidget*) m_iconView.gobj(); |
GtkWidget* widget = (GtkWidget*) m_iconView.gobj(); |
945 |
|
#if GTK_MAJOR_VERSION < 3 |
946 |
gtk_widget_modify_base(widget, GTK_STATE_SELECTED, white.gobj()); |
gtk_widget_modify_base(widget, GTK_STATE_SELECTED, white.gobj()); |
947 |
gtk_widget_modify_base(widget, GTK_STATE_ACTIVE, white.gobj()); |
gtk_widget_modify_base(widget, GTK_STATE_ACTIVE, white.gobj()); |
948 |
gtk_widget_modify_bg(widget, GTK_STATE_SELECTED, white.gobj()); |
gtk_widget_modify_bg(widget, GTK_STATE_SELECTED, white.gobj()); |
949 |
gtk_widget_modify_bg(widget, GTK_STATE_ACTIVE, white.gobj()); |
gtk_widget_modify_bg(widget, GTK_STATE_ACTIVE, white.gobj()); |
950 |
|
#endif |
951 |
} |
} |
952 |
|
|
953 |
m_labelOrder.set_text(_("Order of the instruments to be combined:")); |
m_labelOrder.set_text(_("Order of the instruments to be combined:")); |
971 |
} |
} |
972 |
|
|
973 |
m_buttonBox.set_layout(Gtk::BUTTONBOX_END); |
m_buttonBox.set_layout(Gtk::BUTTONBOX_END); |
974 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) |
975 |
|
m_buttonBox.set_margin(5); |
976 |
|
#else |
977 |
m_buttonBox.set_border_width(5); |
m_buttonBox.set_border_width(5); |
978 |
|
#endif |
979 |
m_buttonBox.pack_start(m_cancelButton, Gtk::PACK_SHRINK); |
m_buttonBox.pack_start(m_cancelButton, Gtk::PACK_SHRINK); |
980 |
m_buttonBox.pack_start(m_OKButton, Gtk::PACK_SHRINK); |
m_buttonBox.pack_start(m_OKButton, Gtk::PACK_SHRINK); |
981 |
m_buttonBox.show(); |
m_buttonBox.show(); |
992 |
sigc::mem_fun(*this, &CombineInstrumentsDialog::combineSelectedInstruments) |
sigc::mem_fun(*this, &CombineInstrumentsDialog::combineSelectedInstruments) |
993 |
); |
); |
994 |
|
|
995 |
|
#if HAS_GTKMM_SHOW_ALL_CHILDREN |
996 |
show_all_children(); |
show_all_children(); |
997 |
|
#endif |
998 |
|
|
999 |
|
Settings::singleton()->showTooltips.get_proxy().signal_changed().connect( |
1000 |
|
sigc::mem_fun(*this, &CombineInstrumentsDialog::on_show_tooltips_changed) |
1001 |
|
); |
1002 |
|
on_show_tooltips_changed(); |
1003 |
|
|
1004 |
// show a warning to user if he uses a .gig in v2 format |
// show a warning to user if he uses a .gig in v2 format |
1005 |
if (gig->pVersion->major < 3) { |
if (gig->pVersion->major < 3) { |
1019 |
|
|
1020 |
void CombineInstrumentsDialog::on_order_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
void CombineInstrumentsDialog::on_order_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
1021 |
{ |
{ |
1022 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
1023 |
printf("Drag begin\n"); |
printf("Drag begin\n"); |
1024 |
|
#endif |
1025 |
first_call_to_drag_data_get = true; |
first_call_to_drag_data_get = true; |
1026 |
} |
} |
1027 |
|
|
1028 |
void CombineInstrumentsDialog::on_order_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, |
void CombineInstrumentsDialog::on_order_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, |
1029 |
Gtk::SelectionData& selection_data, guint, guint) |
Gtk::SelectionData& selection_data, guint, guint) |
1030 |
{ |
{ |
1031 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
1032 |
printf("Drag data get\n"); |
printf("Drag data get\n"); |
1033 |
|
#endif |
1034 |
if (!first_call_to_drag_data_get) return; |
if (!first_call_to_drag_data_get) return; |
1035 |
first_call_to_drag_data_get = false; |
first_call_to_drag_data_get = false; |
1036 |
|
|
1050 |
printf("Drag data get: !src\n"); |
printf("Drag data get: !src\n"); |
1051 |
return; |
return; |
1052 |
} |
} |
1053 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
1054 |
printf("src=%ld\n", (size_t)src); |
printf("src=%ld\n", (size_t)src); |
1055 |
|
#endif |
1056 |
|
|
1057 |
// pass the source gig::Instrument as pointer |
// pass the source gig::Instrument as pointer |
1058 |
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
1063 |
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
1064 |
const Gtk::SelectionData& selection_data, guint, guint time) |
const Gtk::SelectionData& selection_data, guint, guint time) |
1065 |
{ |
{ |
1066 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
1067 |
printf("Drag data received\n"); |
printf("Drag data received\n"); |
1068 |
if (&selection_data == NULL) { |
#endif |
|
printf("!selection_data\n"); |
|
|
return; |
|
|
} |
|
1069 |
if (!selection_data.get_data()) { |
if (!selection_data.get_data()) { |
1070 |
printf("selection_data.get_data() == NULL\n"); |
printf("selection_data.get_data() == NULL\n"); |
1071 |
return; |
return; |
1076 |
printf("!src\n"); |
printf("!src\n"); |
1077 |
return; |
return; |
1078 |
} |
} |
1079 |
printf("src=%d\n", src); |
#if DEBUG_COMBINE_INSTRUMENTS |
1080 |
|
printf("src=%ld\n", (size_t)src); |
1081 |
|
#endif |
1082 |
|
|
1083 |
gig::Instrument* dst = NULL; |
gig::Instrument* dst = NULL; |
1084 |
{ |
{ |
1095 |
return; |
return; |
1096 |
} |
} |
1097 |
|
|
1098 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
1099 |
printf("dragdrop received src='%s' dst='%s'\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
printf("dragdrop received src='%s' dst='%s'\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
1100 |
|
#endif |
1101 |
|
|
1102 |
// swap the two items |
// swap the two items |
1103 |
typedef Gtk::TreeModel::Children Children; |
typedef Gtk::TreeModel::Children Children; |
1165 |
Glib::ustring name = row[m_orderColumns.m_col_name]; |
Glib::ustring name = row[m_orderColumns.m_col_name]; |
1166 |
gig::Instrument* instrument = row[m_orderColumns.m_col_instr]; |
gig::Instrument* instrument = row[m_orderColumns.m_col_instr]; |
1167 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
1168 |
printf("Selection %d. '%s' %p\n\n", (i+1), name.c_str(), instrument)); |
printf("Selection %d. '%s' %p\n\n", (i+1), name.c_str(), instrument); |
1169 |
#endif |
#endif |
1170 |
instruments.push_back(instrument); |
instruments.push_back(instrument); |
1171 |
} |
} |
1234 |
{ |
{ |
1235 |
Children allOrdered = m_refOrderModel->children(); |
Children allOrdered = m_refOrderModel->children(); |
1236 |
for (Children::iterator itOrder = allOrdered.begin(); |
for (Children::iterator itOrder = allOrdered.begin(); |
1237 |
itOrder != allOrdered.end(); ++itOrder) |
itOrder != allOrdered.end(); ) |
1238 |
{ |
{ |
1239 |
Gtk::TreeModel::Row rowOrder = *itOrder; |
Gtk::TreeModel::Row rowOrder = *itOrder; |
1240 |
gig::Instrument* instr = rowOrder[m_orderColumns.m_col_instr]; |
gig::Instrument* instr = rowOrder[m_orderColumns.m_col_instr]; |
1246 |
} |
} |
1247 |
goto removeOrderedItem; |
goto removeOrderedItem; |
1248 |
nextOrderedItem: |
nextOrderedItem: |
1249 |
|
++itOrder; |
1250 |
continue; |
continue; |
1251 |
removeOrderedItem: |
removeOrderedItem: |
1252 |
m_refOrderModel->erase(itOrder); |
// postfix increment here to avoid iterator invalidation |
1253 |
|
m_refOrderModel->erase(itOrder++); |
1254 |
} |
} |
1255 |
} |
} |
1256 |
|
|
1294 |
} |
} |
1295 |
} |
} |
1296 |
|
|
1297 |
|
void CombineInstrumentsDialog::on_show_tooltips_changed() { |
1298 |
|
const bool b = Settings::singleton()->showTooltips; |
1299 |
|
|
1300 |
|
m_treeView.set_has_tooltip(b); |
1301 |
|
m_iconView.set_has_tooltip(b); |
1302 |
|
|
1303 |
|
set_has_tooltip(b); |
1304 |
|
} |
1305 |
|
|
1306 |
bool CombineInstrumentsDialog::fileWasChanged() const { |
bool CombineInstrumentsDialog::fileWasChanged() const { |
1307 |
return m_fileWasChanged; |
return m_fileWasChanged; |
1308 |
} |
} |