1 |
/* |
/* |
2 |
Copyright (c) 2014 Christian Schoenebeck |
Copyright (c) 2014-2019 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 |
*/ |
*/ |
7 |
|
|
8 |
|
#include "global.h" |
9 |
#include "CombineInstrumentsDialog.h" |
#include "CombineInstrumentsDialog.h" |
10 |
|
|
11 |
// enable this for debug messages being printed while combining the instruments |
// enable this for debug messages being printed while combining the instruments |
12 |
#define DEBUG_COMBINE_INSTRUMENTS 0 |
#define DEBUG_COMBINE_INSTRUMENTS 0 |
13 |
|
|
14 |
#include "global.h" |
#include "compat.h" |
15 |
|
|
16 |
#include <set> |
#include <set> |
17 |
#include <iostream> |
#include <iostream> |
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> |
28 |
|
#include <gtk/gtkwidget.h> // for gtk_widget_modify_*() |
29 |
|
|
30 |
Glib::ustring gig_to_utf8(const gig::String& gig_string); |
Glib::ustring dimTypeAsString(gig::dimension_t d); |
31 |
|
|
32 |
|
typedef std::vector< std::pair<gig::Instrument*, gig::Region*> > OrderedRegionGroup; |
33 |
typedef std::map<gig::Instrument*, gig::Region*> RegionGroup; |
typedef std::map<gig::Instrument*, gig::Region*> RegionGroup; |
34 |
typedef std::map<DLS::range_t,RegionGroup> RegionGroups; |
typedef std::map<DLS::range_t,RegionGroup> RegionGroups; |
35 |
|
|
36 |
typedef std::vector<DLS::range_t> DimensionZones; |
typedef std::vector<DLS::range_t> DimensionZones; |
37 |
typedef std::map<gig::dimension_t,DimensionZones> Dimensions; |
typedef std::map<gig::dimension_t,DimensionZones> Dimensions; |
38 |
|
|
|
typedef std::map<gig::dimension_t,int> DimensionCase; |
|
|
|
|
39 |
typedef std::map<gig::dimension_t, int> DimensionRegionUpperLimits; |
typedef std::map<gig::dimension_t, int> DimensionRegionUpperLimits; |
40 |
|
|
41 |
typedef std::set<Glib::ustring> Warnings; |
typedef std::set<Glib::ustring> Warnings; |
97 |
* found with a range member point >= iStart |
* found with a range member point >= iStart |
98 |
*/ |
*/ |
99 |
static int findLowestRegionPoint(std::vector<gig::Instrument*>& instruments, int iStart) { |
static int findLowestRegionPoint(std::vector<gig::Instrument*>& instruments, int iStart) { |
100 |
DLS::range_t searchRange = { iStart, 127 }; |
DLS::range_t searchRange = { uint16_t(iStart), 127 }; |
101 |
int result = -1; |
int result = -1; |
102 |
for (uint i = 0; i < instruments.size(); ++i) { |
for (uint i = 0; i < instruments.size(); ++i) { |
103 |
gig::Instrument* instr = instruments[i]; |
gig::Instrument* instr = instruments[i]; |
119 |
* with a range end >= iStart |
* with a range end >= iStart |
120 |
*/ |
*/ |
121 |
static int findFirstRegionEnd(std::vector<gig::Instrument*>& instruments, int iStart) { |
static int findFirstRegionEnd(std::vector<gig::Instrument*>& instruments, int iStart) { |
122 |
DLS::range_t searchRange = { iStart, 127 }; |
DLS::range_t searchRange = { uint16_t(iStart), 127 }; |
123 |
int result = -1; |
int result = -1; |
124 |
for (uint i = 0; i < instruments.size(); ++i) { |
for (uint i = 0; i < instruments.size(); ++i) { |
125 |
gig::Instrument* instr = instruments[i]; |
gig::Instrument* instr = instruments[i]; |
172 |
/** @brief Identify required regions. |
/** @brief Identify required regions. |
173 |
* |
* |
174 |
* Takes a list of @a instruments as argument (which are planned to be combined |
* Takes a list of @a instruments as argument (which are planned to be combined |
175 |
* as layers in one single new instrument) and fulfills the following tasks: |
* as separate dimension zones of a certain dimension into one single new |
176 |
|
* instrument) and fulfills the following tasks: |
177 |
* |
* |
178 |
* - 1. Identification of total amount of regions required to create a new |
* - 1. Identification of total amount of regions required to create a new |
179 |
* instrument to become a layered version of the given instruments. |
* instrument to become a combined version of the given instruments. |
180 |
* - 2. Precise key range of each of those identified required regions to be |
* - 2. Precise key range of each of those identified required regions to be |
181 |
* created in that new instrument. |
* created in that new instrument. |
182 |
* - 3. Grouping the original source regions of the given original instruments |
* - 3. Grouping the original source regions of the given original instruments |
195 |
iStart = findLowestRegionPoint(instruments, iStart); |
iStart = findLowestRegionPoint(instruments, iStart); |
196 |
if (iStart < 0) break; |
if (iStart < 0) break; |
197 |
const int iEnd = findFirstRegionEnd(instruments, iStart); |
const int iEnd = findFirstRegionEnd(instruments, iStart); |
198 |
DLS::range_t range = { iStart, iEnd }; |
DLS::range_t range = { uint16_t(iStart), uint16_t(iEnd) }; |
199 |
intersections.push_back(range); |
intersections.push_back(range); |
200 |
iStart = iEnd + 1; |
iStart = iEnd + 1; |
201 |
} |
} |
266 |
itNums != it->second.end(); ++itNums) |
itNums != it->second.end(); ++itNums) |
267 |
{ |
{ |
268 |
const int iUpperLimit = *itNums; |
const int iUpperLimit = *itNums; |
269 |
DLS::range_t range = { iLow, iUpperLimit }; |
DLS::range_t range = { uint16_t(iLow), uint16_t(iUpperLimit) }; |
270 |
dims[type].push_back(range); |
dims[type].push_back(range); |
271 |
iLow = iUpperLimit + 1; |
iLow = iUpperLimit + 1; |
272 |
} |
} |
275 |
return dims; |
return dims; |
276 |
} |
} |
277 |
|
|
|
inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) { |
|
|
for (uint i = 0; i < rgn->Dimensions; ++i) |
|
|
if (rgn->pDimensionDefinitions[i].dimension == type) |
|
|
return i; |
|
|
return -1; |
|
|
} |
|
|
|
|
278 |
static void fillDimValues(uint* values/*[8]*/, DimensionCase dimCase, gig::Region* rgn, bool bShouldHaveAllDimensionsPassed) { |
static void fillDimValues(uint* values/*[8]*/, DimensionCase dimCase, gig::Region* rgn, bool bShouldHaveAllDimensionsPassed) { |
279 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
280 |
printf("dimvalues = { "); |
printf("dimvalues = { "); |
291 |
#endif |
#endif |
292 |
} |
} |
293 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
294 |
printf("\n"); |
printf("}\n"); |
295 |
#endif |
#endif |
296 |
} |
} |
297 |
|
|
316 |
} |
} |
317 |
} |
} |
318 |
|
|
|
/** |
|
|
* Returns the sum of all bits of all dimensions defined before the given |
|
|
* dimensions (@a type). This allows to access cases of that particular |
|
|
* dimension directly. |
|
|
* |
|
|
* @param type - dimension that shall be used |
|
|
* @param rgn - parent region of that dimension |
|
|
*/ |
|
|
inline int baseBits(gig::dimension_t type, gig::Region* rgn) { |
|
|
int previousBits = 0; |
|
|
for (uint i = 0; i < rgn->Dimensions; ++i) { |
|
|
if (rgn->pDimensionDefinitions[i].dimension == type) break; |
|
|
previousBits += rgn->pDimensionDefinitions[i].bits; |
|
|
} |
|
|
return previousBits; |
|
|
} |
|
|
|
|
319 |
inline int dimensionRegionIndex(gig::DimensionRegion* dimRgn) { |
inline int dimensionRegionIndex(gig::DimensionRegion* dimRgn) { |
320 |
gig::Region* rgn = dimRgn->GetParent(); |
gig::Region* rgn = dimRgn->GetParent(); |
321 |
int sz = sizeof(rgn->pDimensionRegions) / sizeof(gig::DimensionRegion*); |
int sz = sizeof(rgn->pDimensionRegions) / sizeof(gig::DimensionRegion*); |
348 |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[iDimension]; |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[iDimension]; |
349 |
int iDimRgn = dimensionRegionIndex(dimRgn); |
int iDimRgn = dimensionRegionIndex(dimRgn); |
350 |
int iBaseBits = baseBits(type, rgn); |
int iBaseBits = baseBits(type, rgn); |
351 |
|
assert(iBaseBits >= 0); |
352 |
int mask = ~(((1 << def.bits) - 1) << iBaseBits); |
int mask = ~(((1 << def.bits) - 1) << iBaseBits); |
353 |
|
|
354 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
360 |
gig::DimensionRegion* dimRgn2 = |
gig::DimensionRegion* dimRgn2 = |
361 |
rgn->pDimensionRegions[ (iDimRgn & mask) | ( z << iBaseBits) ]; |
rgn->pDimensionRegions[ (iDimRgn & mask) | ( z << iBaseBits) ]; |
362 |
int iHigh = dimRgn2->DimensionUpperLimits[iDimension]; |
int iHigh = dimRgn2->DimensionUpperLimits[iDimension]; |
363 |
DLS::range_t range = { iLow, iHigh}; |
DLS::range_t range = { uint16_t(iLow), uint16_t(iHigh) }; |
364 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
365 |
printf("%d..%d, ", iLow, iHigh); |
printf("%d..%d, ", iLow, iHigh); |
366 |
fflush(stdout); |
fflush(stdout); |
382 |
}; |
}; |
383 |
typedef std::vector<CopyAssignSchedEntry> CopyAssignSchedule; |
typedef std::vector<CopyAssignSchedEntry> CopyAssignSchedule; |
384 |
|
|
385 |
/** @brief Copy all DimensionRegions from source Region to target Region. |
/** @brief Schedule copying DimensionRegions from source Region to target Region. |
386 |
|
* |
387 |
|
* Schedules copying the entire articulation informations (including sample |
388 |
|
* reference) from all individual DimensionRegions of source Region @a inRgn to |
389 |
|
* target Region @a outRgn. It is expected that the required dimensions (thus |
390 |
|
* the required dimension regions) were already created before calling this |
391 |
|
* function. |
392 |
* |
* |
393 |
* Copies the entire articulation informations (including sample reference of |
* To be precise, it does the task above only for the dimension zones defined by |
394 |
* course) from all individual DimensionRegions of source Region @a inRgn to |
* the three arguments @a mainDim, @a iSrcMainBit, @a iDstMainBit, which reflect |
395 |
* target Region @a outRgn. There are no dimension regions created during this |
* a selection which dimension zones shall be copied. All other dimension zones |
396 |
* task. It is expected that the required dimensions (thus the required |
* will not be scheduled to be copied by a single call of this function. So this |
397 |
* dimension regions) were already created before calling this function. |
* function needs to be called several time in case all dimension regions shall |
398 |
* |
* be copied of the entire region (@a inRgn, @a outRgn). |
|
* To be precise, it does the task above only for the layer selected by |
|
|
* @a iSrcLayer and @a iDstLayer. All dimensions regions of other layers that |
|
|
* may exist, will not be copied by one single call of this function. So if |
|
|
* there is a layer dimension, this function needs to be called several times. |
|
399 |
* |
* |
400 |
* @param outRgn - where the dimension regions shall be copied to |
* @param outRgn - where the dimension regions shall be copied to |
401 |
* @param inRgn - all dimension regions that shall be copied from |
* @param inRgn - all dimension regions that shall be copied from |
402 |
* @param dims - precise dimension definitions of target region |
* @param dims - precise dimension definitions of target region |
403 |
* @param iDstLayer - layer index of destination region where the dimension |
* @param mainDim - this dimension type, in combination with @a iSrcMainBit and |
404 |
* regions shall be copied to |
* @a iDstMainBit defines a selection which dimension region |
405 |
* @param iSrcLayer - layer index of the source region where the dimension |
* zones shall be copied by this call of this function |
406 |
* regions shall be copied from |
* @param iDstMainBit - destination bit of @a mainDim |
407 |
|
* @param iSrcMainBit - source bit of @a mainDim |
408 |
|
* @param schedule - list of all DimensionRegion copy operations which is filled |
409 |
|
* during the nested loops / recursions of this function call |
410 |
* @param dimCase - just for internal purpose (function recursion), don't pass |
* @param dimCase - just for internal purpose (function recursion), don't pass |
411 |
* anything here, this function will call itself recursively |
* anything here, this function will call itself recursively |
412 |
* will fill this container with concrete dimension values for |
* will fill this container with concrete dimension values for |
413 |
* selecting the precise dimension regions during its task |
* selecting the precise dimension regions during its task |
|
* @param schedule - just for internal purpose (function recursion), don't pass |
|
|
anything here: list of all DimensionRegion copy operations |
|
|
* which is filled during the nested loops / recursions of |
|
|
* this function call, they will be peformed after all |
|
|
* function recursions have been completed |
|
414 |
*/ |
*/ |
415 |
static void copyDimensionRegions(gig::Region* outRgn, gig::Region* inRgn, Dimensions dims, int iDstLayer, int iSrcLayer, DimensionCase dimCase = DimensionCase(), CopyAssignSchedule* schedule = NULL) { |
static void scheduleCopyDimensionRegions(gig::Region* outRgn, gig::Region* inRgn, |
416 |
const bool isHighestLevelOfRecursion = !schedule; |
Dimensions dims, gig::dimension_t mainDim, |
417 |
|
int iDstMainBit, int iSrcMainBit, |
418 |
if (isHighestLevelOfRecursion) |
CopyAssignSchedule* schedule, |
419 |
schedule = new CopyAssignSchedule; |
DimensionCase dimCase = DimensionCase()) |
420 |
|
{ |
421 |
if (dims.empty()) { // reached deepest level of function recursion ... |
if (dims.empty()) { // reached deepest level of function recursion ... |
422 |
CopyAssignSchedEntry e; |
CopyAssignSchedEntry e; |
423 |
|
|
426 |
uint dstDimValues[8] = {}; |
uint dstDimValues[8] = {}; |
427 |
DimensionCase srcDimCase = dimCase; |
DimensionCase srcDimCase = dimCase; |
428 |
DimensionCase dstDimCase = dimCase; |
DimensionCase dstDimCase = dimCase; |
429 |
srcDimCase[gig::dimension_layer] = iSrcLayer; |
srcDimCase[mainDim] = iSrcMainBit; |
430 |
dstDimCase[gig::dimension_layer] = iDstLayer; |
dstDimCase[mainDim] = iDstMainBit; |
431 |
|
|
432 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
433 |
printf("-------------------------------\n"); |
printf("-------------------------------\n"); |
434 |
|
printf("iDstMainBit=%d iSrcMainBit=%d\n", iDstMainBit, iSrcMainBit); |
435 |
#endif |
#endif |
436 |
|
|
437 |
// first select source & target dimension region with an arbitrary |
// first select source & target dimension region with an arbitrary |
446 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
447 |
printf("dst "); fflush(stdout); |
printf("dst "); fflush(stdout); |
448 |
#endif |
#endif |
449 |
fillDimValues(dstDimValues, dstDimCase, outRgn, true); |
fillDimValues(dstDimValues, dstDimCase, outRgn, false); |
450 |
gig::DimensionRegion* srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues); |
gig::DimensionRegion* srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues); |
451 |
gig::DimensionRegion* dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
gig::DimensionRegion* dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
452 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
453 |
printf("iDstLayer=%d iSrcLayer=%d\n", iDstLayer, iSrcLayer); |
printf("iDstMainBit=%d iSrcMainBit=%d\n", iDstMainBit, iSrcMainBit); |
454 |
printf("srcDimRgn=%lx dstDimRgn=%lx\n", (uint64_t)srcDimRgn, (uint64_t)dstDimRgn); |
printf("srcDimRgn=%lx dstDimRgn=%lx\n", (uint64_t)srcDimRgn, (uint64_t)dstDimRgn); |
455 |
printf("srcSample='%s' dstSample='%s'\n", |
printf("srcSample='%s' dstSample='%s'\n", |
456 |
(!srcDimRgn->pSample ? "NULL" : srcDimRgn->pSample->pInfo->Name.c_str()), |
(!srcDimRgn->pSample ? "NULL" : srcDimRgn->pSample->pInfo->Name.c_str()), |
469 |
// re-select target dimension region (with correct velocity zone) |
// re-select target dimension region (with correct velocity zone) |
470 |
DimensionZones dstZones = preciseDimensionZonesFor(gig::dimension_velocity, dstDimRgn); |
DimensionZones dstZones = preciseDimensionZonesFor(gig::dimension_velocity, dstDimRgn); |
471 |
assert(dstZones.size() > 1); |
assert(dstZones.size() > 1); |
472 |
int iZoneIndex = dstDimCase[gig::dimension_velocity]; |
const int iDstZoneIndex = |
473 |
e.velocityZone = iZoneIndex; |
(mainDim == gig::dimension_velocity) |
474 |
|
? iDstMainBit : dstDimCase[gig::dimension_velocity]; // (mainDim == gig::dimension_velocity) exception case probably unnecessary here |
475 |
|
e.velocityZone = iDstZoneIndex; |
476 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
477 |
printf("dst velocity zone: %d/%d\n", iZoneIndex, (int)dstZones.size()); |
printf("dst velocity zone: %d/%d\n", iDstZoneIndex, (int)dstZones.size()); |
478 |
#endif |
#endif |
479 |
assert(uint(iZoneIndex) < dstZones.size()); |
assert(uint(iDstZoneIndex) < dstZones.size()); |
480 |
dstDimCase[gig::dimension_velocity] = dstZones[iZoneIndex].low; // arbitrary value between low and high |
dstDimCase[gig::dimension_velocity] = dstZones[iDstZoneIndex].low; // arbitrary value between low and high |
481 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
482 |
printf("dst velocity value = %d\n", dstDimCase[gig::dimension_velocity]); |
printf("dst velocity value = %d\n", dstDimCase[gig::dimension_velocity]); |
483 |
printf("dst refilled "); fflush(stdout); |
printf("dst refilled "); fflush(stdout); |
484 |
#endif |
#endif |
485 |
fillDimValues(dstDimValues, dstDimCase, outRgn, true); |
fillDimValues(dstDimValues, dstDimCase, outRgn, false); |
486 |
dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
487 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
488 |
printf("reselected dstDimRgn=%lx\n", (uint64_t)dstDimRgn); |
printf("reselected dstDimRgn=%lx\n", (uint64_t)dstDimRgn); |
489 |
printf("dstSample='%s'\n", |
printf("dstSample='%s'%s\n", |
490 |
(!dstDimRgn->pSample ? "NULL" : dstDimRgn->pSample->pInfo->Name.c_str()) |
(!dstDimRgn->pSample ? "NULL" : dstDimRgn->pSample->pInfo->Name.c_str()), |
491 |
|
(dstDimRgn->pSample ? " <--- ERROR ERROR ERROR !!!!!!!!! " : "") |
492 |
); |
); |
493 |
#endif |
#endif |
494 |
|
|
501 |
if (srcZones.size() <= 1) { |
if (srcZones.size() <= 1) { |
502 |
addWarning("Input region has a velocity dimension with only ONE zone!"); |
addWarning("Input region has a velocity dimension with only ONE zone!"); |
503 |
} |
} |
504 |
if (uint(iZoneIndex) >= srcZones.size()) |
int iSrcZoneIndex = |
505 |
iZoneIndex = srcZones.size() - 1; |
(mainDim == gig::dimension_velocity) |
506 |
srcDimCase[gig::dimension_velocity] = srcZones[iZoneIndex].low; // same zone as used above for target dimension region (no matter what the precise zone ranges are) |
? iSrcMainBit : iDstZoneIndex; |
507 |
|
if (uint(iSrcZoneIndex) >= srcZones.size()) |
508 |
|
iSrcZoneIndex = srcZones.size() - 1; |
509 |
|
srcDimCase[gig::dimension_velocity] = srcZones[iSrcZoneIndex].low; // same zone as used above for target dimension region (no matter what the precise zone ranges are) |
510 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
511 |
printf("src refilled "); fflush(stdout); |
printf("src refilled "); fflush(stdout); |
512 |
#endif |
#endif |
521 |
} |
} |
522 |
} |
} |
523 |
|
|
524 |
// Schedule copy opertion of source -> target DimensionRegion for the |
// Schedule copy operation of source -> target DimensionRegion for the |
525 |
// time after all nested loops have been traversed. We have to postpone |
// time after all nested loops have been traversed. We have to postpone |
526 |
// the actual copy operations this way, because otherwise it would |
// the actual copy operations this way, because otherwise it would |
527 |
// overwrite informations inside the destination DimensionRegion object |
// overwrite informations inside the destination DimensionRegion object |
552 |
dimCase[type] = (def->split_type == gig::split_type_bit) ? iZone : zoneRange.low; |
dimCase[type] = (def->split_type == gig::split_type_bit) ? iZone : zoneRange.low; |
553 |
|
|
554 |
// recurse until 'dims' is exhausted (and dimCase filled up with concrete value) |
// recurse until 'dims' is exhausted (and dimCase filled up with concrete value) |
555 |
copyDimensionRegions(outRgn, inRgn, dims, iDstLayer, iSrcLayer, dimCase, schedule); |
scheduleCopyDimensionRegions(outRgn, inRgn, dims, mainDim, iDstMainBit, iSrcMainBit, schedule, dimCase); |
556 |
} |
} |
557 |
|
} |
558 |
|
|
559 |
// if current function call is the (very first) entry point ... |
static OrderedRegionGroup sortRegionGroup(const RegionGroup& group, const std::vector<gig::Instrument*>& instruments) { |
560 |
if (isHighestLevelOfRecursion) { |
OrderedRegionGroup result; |
561 |
// ... then perform all scheduled DimensionRegion copy operations |
for (std::vector<gig::Instrument*>::const_iterator it = instruments.begin(); |
562 |
for (uint i = 0; i < schedule->size(); ++i) { |
it != instruments.end(); ++it) |
563 |
CopyAssignSchedEntry& e = (*schedule)[i]; |
{ |
564 |
|
RegionGroup::const_iterator itRgn = group.find(*it); |
565 |
// backup the target DimensionRegion's current dimension zones upper |
if (itRgn == group.end()) continue; |
566 |
// limits (because the target DimensionRegion's upper limits are |
result.push_back( |
567 |
// already defined correctly since calling AddDimension(), and the |
std::pair<gig::Instrument*, gig::Region*>( |
568 |
// CopyAssign() call next, will overwrite those upper limits |
itRgn->first, itRgn->second |
569 |
// unfortunately |
) |
570 |
DimensionRegionUpperLimits dstUpperLimits = getDimensionRegionUpperLimits(e.dst); |
); |
|
DimensionRegionUpperLimits srcUpperLimits = getDimensionRegionUpperLimits(e.src); |
|
|
|
|
|
// now actually copy over the current DimensionRegion |
|
|
const gig::Region* const origRgn = e.dst->GetParent(); // just for sanity check below |
|
|
e.dst->CopyAssign(e.src); |
|
|
assert(origRgn == e.dst->GetParent()); // if gigedit is crashing here, then you must update libgig (to at least SVN r2547, v3.3.0.svn10) |
|
|
|
|
|
// restore all original dimension zone upper limits except of the |
|
|
// velocity dimension, because the velocity dimension zone sizes are |
|
|
// allowed to differ for individual DimensionRegions in gig v3 |
|
|
// format |
|
|
if (srcUpperLimits.count(gig::dimension_velocity)) { |
|
|
if (!dstUpperLimits.count(gig::dimension_velocity)) { |
|
|
addWarning("Source instrument seems to have a velocity dimension whereas new target instrument doesn't!"); |
|
|
} else { |
|
|
dstUpperLimits[gig::dimension_velocity] = |
|
|
(e.velocityZone >= e.totalSrcVelocityZones) |
|
|
? 127 : srcUpperLimits[gig::dimension_velocity]; |
|
|
} |
|
|
} |
|
|
restoreDimensionRegionUpperLimits(e.dst, dstUpperLimits); |
|
|
} |
|
|
delete schedule; |
|
571 |
} |
} |
572 |
|
return result; |
573 |
} |
} |
574 |
|
|
575 |
/** @brief Combine given list of instruments to one instrument. |
/** @brief Combine given list of instruments to one instrument. |
576 |
* |
* |
577 |
* Takes a list of @a instruments as argument and combines them to one single |
* Takes a list of @a instruments as argument and combines them to one single |
578 |
* new @a output instrument. For this task, it will create a 'layer' dimension |
* new @a output instrument. For this task, it will create a dimension of type |
579 |
* in the new instrument and copies the source instruments to those layers. |
* given by @a mainDimension in the new instrument and copies the source |
580 |
|
* instruments to those dimension zones. |
581 |
* |
* |
582 |
* @param instruments - (input) list of instruments that shall be combined, |
* @param instruments - (input) list of instruments that shall be combined, |
583 |
* they will only be read, so they will be left untouched |
* they will only be read, so they will be left untouched |
585 |
* be created |
* be created |
586 |
* @param output - (output) on success this pointer will be set to the new |
* @param output - (output) on success this pointer will be set to the new |
587 |
* instrument being created |
* instrument being created |
588 |
|
* @param mainDimension - the dimension that shall be used to combine the |
589 |
|
* instruments |
590 |
* @throw RIFF::Exception on any kinds of errors |
* @throw RIFF::Exception on any kinds of errors |
591 |
*/ |
*/ |
592 |
static void combineInstruments(std::vector<gig::Instrument*>& instruments, gig::File* gig, gig::Instrument*& output) { |
static void combineInstruments(std::vector<gig::Instrument*>& instruments, gig::File* gig, gig::Instrument*& output, gig::dimension_t mainDimension) { |
593 |
output = NULL; |
output = NULL; |
594 |
|
|
595 |
// divide the individual regions to (probably even smaller) groups of |
// divide the individual regions to (probably even smaller) groups of |
626 |
printf("---> Start target region %d..%d\n", itGroup->first.low, itGroup->first.high); |
printf("---> Start target region %d..%d\n", itGroup->first.low, itGroup->first.high); |
627 |
#endif |
#endif |
628 |
|
|
629 |
// detect the total amount of layers required to build up this combi |
// detect the total amount of zones required for the given main |
630 |
// for current key range |
// dimension to build up this combi for current key range |
631 |
int iTotalLayers = 0; |
int iTotalZones = 0; |
632 |
for (RegionGroup::iterator itRgn = itGroup->second.begin(); |
for (RegionGroup::iterator itRgn = itGroup->second.begin(); |
633 |
itRgn != itGroup->second.end(); ++itRgn) |
itRgn != itGroup->second.end(); ++itRgn) |
634 |
{ |
{ |
635 |
gig::Region* inRgn = itRgn->second; |
gig::Region* inRgn = itRgn->second; |
636 |
iTotalLayers += inRgn->Layers; |
gig::dimension_def_t* def = inRgn->GetDimensionDefinition(mainDimension); |
637 |
|
iTotalZones += (def) ? def->zones : 1; |
638 |
} |
} |
639 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
640 |
printf("Required total layers: %d\n", iTotalLayers); |
printf("Required total zones: %d, vertical regions: %d\n", iTotalZones, itGroup->second.size()); |
641 |
#endif |
#endif |
642 |
|
|
643 |
// create all required dimensions for this output region |
// create all required dimensions for this output region |
644 |
// (except the layer dimension, which we create as next step) |
// (except the main dimension used for separating the individual |
645 |
|
// instruments, we create that particular dimension as next step) |
646 |
Dimensions dims = getDimensionsForRegionGroup(itGroup->second); |
Dimensions dims = getDimensionsForRegionGroup(itGroup->second); |
647 |
|
// the given main dimension which is used to combine the instruments is |
648 |
|
// created separately after the next code block, and the main dimension |
649 |
|
// should not be part of dims here, because it also used for iterating |
650 |
|
// all dimensions zones, which would lead to this dimensions being |
651 |
|
// iterated twice |
652 |
|
dims.erase(mainDimension); |
653 |
{ |
{ |
654 |
std::vector<gig::dimension_t> skipTheseDimensions; // used to prevent a misbehavior (i.e. crash) of the combine algorithm in case one of the source instruments has a dimension with only one zone, which is not standard conform |
std::vector<gig::dimension_t> skipTheseDimensions; // used to prevent a misbehavior (i.e. crash) of the combine algorithm in case one of the source instruments has a dimension with only one zone, which is not standard conform |
655 |
|
|
656 |
for (Dimensions::iterator itDim = dims.begin(); |
for (Dimensions::iterator itDim = dims.begin(); |
657 |
itDim != dims.end(); ++itDim) |
itDim != dims.end(); ++itDim) |
658 |
{ |
{ |
|
// layer dimension is created separately in the next code block |
|
|
// (outside of this loop) |
|
|
if (itDim->first == gig::dimension_layer) continue; |
|
|
|
|
659 |
gig::dimension_def_t def; |
gig::dimension_def_t def; |
660 |
def.dimension = itDim->first; // dimension type |
def.dimension = itDim->first; // dimension type |
661 |
def.zones = itDim->second.size(); |
def.zones = itDim->second.size(); |
686 |
dims.erase(skipTheseDimensions[i]); |
dims.erase(skipTheseDimensions[i]); |
687 |
} |
} |
688 |
|
|
689 |
// create the layer dimension (if necessary for current key range) |
// create the main dimension (if necessary for current key range) |
690 |
if (iTotalLayers > 1) { |
if (iTotalZones > 1) { |
691 |
gig::dimension_def_t def; |
gig::dimension_def_t def; |
692 |
def.dimension = gig::dimension_layer; // dimension type |
def.dimension = mainDimension; // dimension type |
693 |
def.zones = iTotalLayers; |
def.zones = iTotalZones; |
694 |
def.bits = zoneCountToBits(def.zones); |
def.bits = zoneCountToBits(def.zones); |
695 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
696 |
std::cout << "Adding new (layer) dimension type=" << std::hex << (int)def.dimension << std::dec << ", zones=" << (int)def.zones << ", bits=" << (int)def.bits << " ... " << std::flush; |
std::cout << "Adding new main combi dimension type=" << std::hex << (int)def.dimension << std::dec << ", zones=" << (int)def.zones << ", bits=" << (int)def.bits << " ... " << std::flush; |
697 |
#endif |
#endif |
698 |
outRgn->AddDimension(&def); |
outRgn->AddDimension(&def); |
699 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
700 |
std::cout << "OK" << std::endl << std::flush; |
std::cout << "OK" << std::endl << std::flush; |
701 |
#endif |
#endif |
702 |
|
} else { |
703 |
|
dims.erase(mainDimension); |
704 |
} |
} |
705 |
|
|
706 |
// now copy the source dimension regions to the target dimension regions |
// for the next task we need to have the current RegionGroup to be |
707 |
int iDstLayer = 0; |
// sorted by instrument in the same sequence as the 'instruments' vector |
708 |
for (RegionGroup::iterator itRgn = itGroup->second.begin(); |
// argument passed to this function (because the std::map behind the |
709 |
itRgn != itGroup->second.end(); ++itRgn) // iterate over 'vertical' / source regions ... |
// 'RegionGroup' type sorts by memory address instead, and that would |
710 |
|
// sometimes lead to the source instruments' region to be sorted into |
711 |
|
// the wrong target layer) |
712 |
|
OrderedRegionGroup currentGroup = sortRegionGroup(itGroup->second, instruments); |
713 |
|
|
714 |
|
// schedule copying the source dimension regions to the target dimension |
715 |
|
// regions |
716 |
|
CopyAssignSchedule schedule; |
717 |
|
int iDstMainBit = 0; |
718 |
|
for (OrderedRegionGroup::iterator itRgn = currentGroup.begin(); |
719 |
|
itRgn != currentGroup.end(); ++itRgn) // iterate over 'vertical' / source regions ... |
720 |
{ |
{ |
721 |
gig::Region* inRgn = itRgn->second; |
gig::Region* inRgn = itRgn->second; |
722 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
723 |
printf("[source region of '%s']\n", inRgn->GetParent()->pInfo->Name.c_str()); |
printf("[source region of '%s']\n", inRgn->GetParent()->pInfo->Name.c_str()); |
724 |
#endif |
#endif |
725 |
for (uint iSrcLayer = 0; iSrcLayer < inRgn->Layers; ++iSrcLayer, ++iDstLayer) { |
|
726 |
copyDimensionRegions(outRgn, inRgn, dims, iDstLayer, iSrcLayer); |
// determine how many main dimension zones this input region requires |
727 |
|
gig::dimension_def_t* def = inRgn->GetDimensionDefinition(mainDimension); |
728 |
|
const int inRgnMainZones = (def) ? def->zones : 1; |
729 |
|
|
730 |
|
for (uint iSrcMainBit = 0; iSrcMainBit < inRgnMainZones; ++iSrcMainBit, ++iDstMainBit) { |
731 |
|
scheduleCopyDimensionRegions( |
732 |
|
outRgn, inRgn, dims, mainDimension, |
733 |
|
iDstMainBit, iSrcMainBit, &schedule |
734 |
|
); |
735 |
} |
} |
736 |
} |
} |
737 |
|
|
738 |
|
// finally copy the scheduled source -> target dimension regions |
739 |
|
for (uint i = 0; i < schedule.size(); ++i) { |
740 |
|
CopyAssignSchedEntry& e = schedule[i]; |
741 |
|
|
742 |
|
// backup the target DimensionRegion's current dimension zones upper |
743 |
|
// limits (because the target DimensionRegion's upper limits are |
744 |
|
// already defined correctly since calling AddDimension(), and the |
745 |
|
// CopyAssign() call next, will overwrite those upper limits |
746 |
|
// unfortunately |
747 |
|
DimensionRegionUpperLimits dstUpperLimits = getDimensionRegionUpperLimits(e.dst); |
748 |
|
DimensionRegionUpperLimits srcUpperLimits = getDimensionRegionUpperLimits(e.src); |
749 |
|
|
750 |
|
// now actually copy over the current DimensionRegion |
751 |
|
const gig::Region* const origRgn = e.dst->GetParent(); // just for sanity check below |
752 |
|
e.dst->CopyAssign(e.src); |
753 |
|
assert(origRgn == e.dst->GetParent()); // if gigedit is crashing here, then you must update libgig (to at least SVN r2547, v3.3.0.svn10) |
754 |
|
|
755 |
|
// restore all original dimension zone upper limits except of the |
756 |
|
// velocity dimension, because the velocity dimension zone sizes are |
757 |
|
// allowed to differ for individual DimensionRegions in gig v3 |
758 |
|
// format |
759 |
|
// |
760 |
|
// if the main dinension is the 'velocity' dimension, then skip |
761 |
|
// restoring the source's original velocity zone limits, because |
762 |
|
// dealing with merging that is not implemented yet |
763 |
|
// TODO: merge custom velocity splits if main dimension is the velocity dimension (for now equal sized velocity zones are used if mainDim is 'velocity') |
764 |
|
if (srcUpperLimits.count(gig::dimension_velocity) && mainDimension != gig::dimension_velocity) { |
765 |
|
if (!dstUpperLimits.count(gig::dimension_velocity)) { |
766 |
|
addWarning("Source instrument seems to have a velocity dimension whereas new target instrument doesn't!"); |
767 |
|
} else { |
768 |
|
dstUpperLimits[gig::dimension_velocity] = |
769 |
|
(e.velocityZone >= e.totalSrcVelocityZones) |
770 |
|
? 127 : srcUpperLimits[gig::dimension_velocity]; |
771 |
|
} |
772 |
|
} |
773 |
|
restoreDimensionRegionUpperLimits(e.dst, dstUpperLimits); |
774 |
|
} |
775 |
} |
} |
776 |
|
|
777 |
// success |
// success |
782 |
// class 'CombineInstrumentsDialog' |
// class 'CombineInstrumentsDialog' |
783 |
|
|
784 |
CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig) |
CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig) |
785 |
: Gtk::Dialog(_("Combine Instruments"), parent, true), |
: ManagedDialog(_("Combine Instruments"), parent, true), |
786 |
m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL), |
m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL), |
787 |
|
#if HAS_GTKMM_STOCK |
788 |
m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK), |
m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK), |
789 |
m_descriptionLabel() |
#else |
790 |
|
m_cancelButton(_("_Cancel"), true), m_OKButton(_("_OK"), true), |
791 |
|
#endif |
792 |
|
m_descriptionLabel(), |
793 |
|
#if USE_GTKMM_GRID |
794 |
|
m_tableDimCombo(), |
795 |
|
#else |
796 |
|
m_tableDimCombo(2, 2), |
797 |
|
#endif |
798 |
|
m_comboDimType(), |
799 |
|
m_labelDimType(Glib::ustring(_("Combine by Dimension:")) + " ", Gtk::ALIGN_END) |
800 |
{ |
{ |
801 |
|
if (!Settings::singleton()->autoRestoreWindowDimension) { |
802 |
|
set_default_size(500, 600); |
803 |
|
set_position(Gtk::WIN_POS_MOUSE); |
804 |
|
} |
805 |
|
|
806 |
|
m_scrolledWindow.add(m_treeView); |
807 |
|
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
808 |
|
|
809 |
|
#if USE_GTKMM_BOX |
810 |
|
get_content_area()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
811 |
|
get_content_area()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK); |
812 |
|
get_content_area()->pack_start(m_scrolledWindow); |
813 |
|
get_content_area()->pack_start(m_labelOrder, Gtk::PACK_SHRINK); |
814 |
|
get_content_area()->pack_start(m_iconView, Gtk::PACK_SHRINK); |
815 |
|
get_content_area()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
816 |
|
#else |
817 |
get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
818 |
get_vbox()->pack_start(m_treeView); |
get_vbox()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK); |
819 |
|
get_vbox()->pack_start(m_scrolledWindow); |
820 |
|
get_vbox()->pack_start(m_labelOrder, Gtk::PACK_SHRINK); |
821 |
|
get_vbox()->pack_start(m_iconView, Gtk::PACK_SHRINK); |
822 |
get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
823 |
|
#endif |
824 |
|
|
825 |
#if GTKMM_MAJOR_VERSION >= 3 |
#if GTKMM_MAJOR_VERSION >= 3 |
826 |
description.set_line_wrap(); |
m_descriptionLabel.set_line_wrap(); |
827 |
#endif |
#endif |
828 |
m_descriptionLabel.set_text(_( |
m_descriptionLabel.set_text(_( |
829 |
"Select at least two instruments below that shall be combined " |
"Select at least two instruments below that shall be combined (as " |
830 |
"as layers (using a \"Layer\" dimension) to a new instrument. The " |
"separate dimension zones of the selected dimension type) as a new " |
831 |
"original instruments remain untouched.") |
"instrument. The original instruments remain untouched.\n\n" |
832 |
); |
"You may use this tool for example to combine solo instruments into " |
833 |
|
"a combi sound arrangement by selecting the 'layer' dimension, or you " |
834 |
|
"might combine similar sounding solo sounds into separate velocity " |
835 |
|
"split layers by using the 'velocity' dimension, and so on." |
836 |
|
)); |
837 |
|
|
838 |
|
// add dimension type combo box |
839 |
|
{ |
840 |
|
int iLayerDimIndex = -1; |
841 |
|
Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(m_comboDimsModel); |
842 |
|
for (int i = 0x01, iRow = 0; i < 0xff; i++) { |
843 |
|
Glib::ustring sType = |
844 |
|
dimTypeAsString(static_cast<gig::dimension_t>(i)); |
845 |
|
if (sType.find("Unknown") != 0) { |
846 |
|
Gtk::TreeModel::Row row = *(refComboModel->append()); |
847 |
|
row[m_comboDimsModel.m_type_id] = i; |
848 |
|
row[m_comboDimsModel.m_type_name] = sType; |
849 |
|
if (i == gig::dimension_layer) iLayerDimIndex = iRow; |
850 |
|
iRow++; |
851 |
|
} |
852 |
|
} |
853 |
|
m_comboDimType.set_model(refComboModel); |
854 |
|
m_comboDimType.pack_start(m_comboDimsModel.m_type_id); |
855 |
|
m_comboDimType.pack_start(m_comboDimsModel.m_type_name); |
856 |
|
m_tableDimCombo.attach(m_labelDimType, 0, 1, 0, 1); |
857 |
|
m_tableDimCombo.attach(m_comboDimType, 1, 2, 0, 1); |
858 |
|
m_comboDimType.set_active(iLayerDimIndex); // preselect "layer" dimension |
859 |
|
} |
860 |
|
|
861 |
m_refTreeModel = Gtk::ListStore::create(m_columns); |
m_refTreeModel = Gtk::ListStore::create(m_columns); |
862 |
m_treeView.set_model(m_refTreeModel); |
m_treeView.set_model(m_refTreeModel); |
864 |
"Use SHIFT + left click or CTRL + left click to select the instruments " |
"Use SHIFT + left click or CTRL + left click to select the instruments " |
865 |
"you want to combine." |
"you want to combine." |
866 |
)); |
)); |
867 |
m_treeView.append_column("Instrument", m_columns.m_col_name); |
m_treeView.append_column(_("Nr"), m_columns.m_col_index); |
868 |
m_treeView.set_headers_visible(false); |
m_treeView.append_column(_("Instrument"), m_columns.m_col_name); |
869 |
|
m_treeView.set_headers_visible(true); |
870 |
m_treeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
m_treeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
871 |
m_treeView.get_selection()->signal_changed().connect( |
m_treeView.get_selection()->signal_changed().connect( |
872 |
sigc::mem_fun(*this, &CombineInstrumentsDialog::onSelectionChanged) |
sigc::mem_fun(*this, &CombineInstrumentsDialog::onSelectionChanged) |
891 |
Glib::ustring name(gig_to_utf8(instr->pInfo->Name)); |
Glib::ustring name(gig_to_utf8(instr->pInfo->Name)); |
892 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
893 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
894 |
|
row[m_columns.m_col_index] = i; |
895 |
row[m_columns.m_col_name] = name; |
row[m_columns.m_col_name] = name; |
896 |
row[m_columns.m_col_instr] = instr; |
row[m_columns.m_col_instr] = instr; |
897 |
} |
} |
898 |
|
|
899 |
|
m_refOrderModel = Gtk::ListStore::create(m_orderColumns); |
900 |
|
m_iconView.set_model(m_refOrderModel); |
901 |
|
m_iconView.set_tooltip_text(_("Use drag & drop to change the order.")); |
902 |
|
m_iconView.set_markup_column(1); |
903 |
|
m_iconView.set_selection_mode(Gtk::SELECTION_SINGLE); |
904 |
|
// force background to retain white also on selections |
905 |
|
// (this also fixes a bug with GTK 2 which often causes visibility issue |
906 |
|
// with the text of the selected item) |
907 |
|
{ |
908 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
909 |
|
Gdk::Color white; |
910 |
|
#else |
911 |
|
Gdk::RGBA white; |
912 |
|
#endif |
913 |
|
white.set("#ffffff"); |
914 |
|
GtkWidget* widget = (GtkWidget*) m_iconView.gobj(); |
915 |
|
#if GTK_MAJOR_VERSION < 3 |
916 |
|
gtk_widget_modify_base(widget, GTK_STATE_SELECTED, white.gobj()); |
917 |
|
gtk_widget_modify_base(widget, GTK_STATE_ACTIVE, white.gobj()); |
918 |
|
gtk_widget_modify_bg(widget, GTK_STATE_SELECTED, white.gobj()); |
919 |
|
gtk_widget_modify_bg(widget, GTK_STATE_ACTIVE, white.gobj()); |
920 |
|
#endif |
921 |
|
} |
922 |
|
|
923 |
|
m_labelOrder.set_text(_("Order of the instruments to be combined:")); |
924 |
|
|
925 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
926 |
|
// the sequence of instruments within the gig file |
927 |
|
{ |
928 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
929 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
930 |
|
m_iconView.drag_source_set(drag_target_instrument); |
931 |
|
m_iconView.drag_dest_set(drag_target_instrument); |
932 |
|
m_iconView.signal_drag_begin().connect( |
933 |
|
sigc::mem_fun(*this, &CombineInstrumentsDialog::on_order_drag_begin) |
934 |
|
); |
935 |
|
m_iconView.signal_drag_data_get().connect( |
936 |
|
sigc::mem_fun(*this, &CombineInstrumentsDialog::on_order_drag_data_get) |
937 |
|
); |
938 |
|
m_iconView.signal_drag_data_received().connect( |
939 |
|
sigc::mem_fun(*this, &CombineInstrumentsDialog::on_order_drop_drag_data_received) |
940 |
|
); |
941 |
|
} |
942 |
|
|
943 |
m_buttonBox.set_layout(Gtk::BUTTONBOX_END); |
m_buttonBox.set_layout(Gtk::BUTTONBOX_END); |
944 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) |
945 |
|
m_buttonBox.set_margin(5); |
946 |
|
#else |
947 |
m_buttonBox.set_border_width(5); |
m_buttonBox.set_border_width(5); |
948 |
|
#endif |
949 |
m_buttonBox.pack_start(m_cancelButton, Gtk::PACK_SHRINK); |
m_buttonBox.pack_start(m_cancelButton, Gtk::PACK_SHRINK); |
950 |
m_buttonBox.pack_start(m_OKButton, Gtk::PACK_SHRINK); |
m_buttonBox.pack_start(m_OKButton, Gtk::PACK_SHRINK); |
951 |
m_buttonBox.show(); |
m_buttonBox.show(); |
962 |
sigc::mem_fun(*this, &CombineInstrumentsDialog::combineSelectedInstruments) |
sigc::mem_fun(*this, &CombineInstrumentsDialog::combineSelectedInstruments) |
963 |
); |
); |
964 |
|
|
965 |
|
#if HAS_GTKMM_SHOW_ALL_CHILDREN |
966 |
show_all_children(); |
show_all_children(); |
967 |
|
#endif |
968 |
|
|
969 |
|
Settings::singleton()->showTooltips.get_proxy().signal_changed().connect( |
970 |
|
sigc::mem_fun(*this, &CombineInstrumentsDialog::on_show_tooltips_changed) |
971 |
|
); |
972 |
|
on_show_tooltips_changed(); |
973 |
|
|
974 |
// 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 |
975 |
if (gig->pVersion->major < 3) { |
if (gig->pVersion->major < 3) { |
982 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_WARNING); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_WARNING); |
983 |
msg.run(); |
msg.run(); |
984 |
} |
} |
985 |
|
|
986 |
|
// OK button should have focus by default for quick combining with Return key |
987 |
|
m_OKButton.grab_focus(); |
988 |
|
} |
989 |
|
|
990 |
|
void CombineInstrumentsDialog::on_order_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
991 |
|
{ |
992 |
|
printf("Drag begin\n"); |
993 |
|
first_call_to_drag_data_get = true; |
994 |
|
} |
995 |
|
|
996 |
|
void CombineInstrumentsDialog::on_order_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, |
997 |
|
Gtk::SelectionData& selection_data, guint, guint) |
998 |
|
{ |
999 |
|
printf("Drag data get\n"); |
1000 |
|
if (!first_call_to_drag_data_get) return; |
1001 |
|
first_call_to_drag_data_get = false; |
1002 |
|
|
1003 |
|
// get selected source instrument |
1004 |
|
gig::Instrument* src = NULL; |
1005 |
|
{ |
1006 |
|
std::vector<Gtk::TreeModel::Path> rows = m_iconView.get_selected_items(); |
1007 |
|
if (!rows.empty()) { |
1008 |
|
Gtk::TreeModel::iterator it = m_refOrderModel->get_iter(rows[0]); |
1009 |
|
if (it) { |
1010 |
|
Gtk::TreeModel::Row row = *it; |
1011 |
|
src = row[m_orderColumns.m_col_instr]; |
1012 |
|
} |
1013 |
|
} |
1014 |
|
} |
1015 |
|
if (!src) { |
1016 |
|
printf("Drag data get: !src\n"); |
1017 |
|
return; |
1018 |
|
} |
1019 |
|
printf("src=%ld\n", (size_t)src); |
1020 |
|
|
1021 |
|
// pass the source gig::Instrument as pointer |
1022 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
1023 |
|
sizeof(src)/*length of data in bytes*/); |
1024 |
|
} |
1025 |
|
|
1026 |
|
void CombineInstrumentsDialog::on_order_drop_drag_data_received( |
1027 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
1028 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
1029 |
|
{ |
1030 |
|
printf("Drag data received\n"); |
1031 |
|
if (!selection_data.get_data()) { |
1032 |
|
printf("selection_data.get_data() == NULL\n"); |
1033 |
|
return; |
1034 |
|
} |
1035 |
|
|
1036 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
1037 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) { |
1038 |
|
printf("!src\n"); |
1039 |
|
return; |
1040 |
|
} |
1041 |
|
printf("src=%ld\n", (size_t)src); |
1042 |
|
|
1043 |
|
gig::Instrument* dst = NULL; |
1044 |
|
{ |
1045 |
|
Gtk::TreeModel::Path path = m_iconView.get_path_at_pos(x, y); |
1046 |
|
if (!path) return; |
1047 |
|
|
1048 |
|
Gtk::TreeModel::iterator iter = m_refOrderModel->get_iter(path); |
1049 |
|
if (!iter) return; |
1050 |
|
Gtk::TreeModel::Row row = *iter; |
1051 |
|
dst = row[m_orderColumns.m_col_instr]; |
1052 |
|
} |
1053 |
|
if (!dst) { |
1054 |
|
printf("!dst\n"); |
1055 |
|
return; |
1056 |
|
} |
1057 |
|
|
1058 |
|
printf("dragdrop received src='%s' dst='%s'\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
1059 |
|
|
1060 |
|
// swap the two items |
1061 |
|
typedef Gtk::TreeModel::Children Children; |
1062 |
|
Children children = m_refOrderModel->children(); |
1063 |
|
Children::iterator itSrc, itDst; |
1064 |
|
int i = 0, iSrc = -1, iDst = -1; |
1065 |
|
for (Children::iterator iter = children.begin(); |
1066 |
|
iter != children.end(); ++iter, ++i) |
1067 |
|
{ |
1068 |
|
Gtk::TreeModel::Row row = *iter; |
1069 |
|
if (row[m_orderColumns.m_col_instr] == src) { |
1070 |
|
itSrc = iter; |
1071 |
|
iSrc = i; |
1072 |
|
} else if (row[m_orderColumns.m_col_instr] == dst) { |
1073 |
|
itDst = iter; |
1074 |
|
iDst = i; |
1075 |
|
} |
1076 |
|
} |
1077 |
|
if (itSrc && itDst) { |
1078 |
|
// swap elements |
1079 |
|
m_refOrderModel->iter_swap(itSrc, itDst); |
1080 |
|
// update markup |
1081 |
|
Gtk::TreeModel::Row rowSrc = *itSrc; |
1082 |
|
Gtk::TreeModel::Row rowDst = *itDst; |
1083 |
|
{ |
1084 |
|
Glib::ustring name = rowSrc[m_orderColumns.m_col_name]; |
1085 |
|
Glib::ustring markup = |
1086 |
|
"<span foreground='black' background='white'>" + ToString(iDst+1) + ".</span>\n<span foreground='green' background='white'>" + name + "</span>"; |
1087 |
|
rowSrc[m_orderColumns.m_col_markup] = markup; |
1088 |
|
} |
1089 |
|
{ |
1090 |
|
Glib::ustring name = rowDst[m_orderColumns.m_col_name]; |
1091 |
|
Glib::ustring markup = |
1092 |
|
"<span foreground='black' background='white'>" + ToString(iSrc+1) + ".</span>\n<span foreground='green' background='white'>" + name + "</span>"; |
1093 |
|
rowDst[m_orderColumns.m_col_markup] = markup; |
1094 |
|
} |
1095 |
|
} |
1096 |
|
} |
1097 |
|
|
1098 |
|
void CombineInstrumentsDialog::setSelectedInstruments(const std::set<int>& instrumentIndeces) { |
1099 |
|
typedef Gtk::TreeModel::Children Children; |
1100 |
|
Children children = m_refTreeModel->children(); |
1101 |
|
for (Children::iterator iter = children.begin(); |
1102 |
|
iter != children.end(); ++iter) |
1103 |
|
{ |
1104 |
|
Gtk::TreeModel::Row row = *iter; |
1105 |
|
int index = row[m_columns.m_col_index]; |
1106 |
|
if (instrumentIndeces.count(index)) |
1107 |
|
m_treeView.get_selection()->select(iter); |
1108 |
|
} |
1109 |
|
// hack: OK button lost focus after doing the above, it should have focus by default for quick combining with Return key |
1110 |
|
m_OKButton.grab_focus(); |
1111 |
} |
} |
1112 |
|
|
1113 |
void CombineInstrumentsDialog::combineSelectedInstruments() { |
void CombineInstrumentsDialog::combineSelectedInstruments() { |
1114 |
std::vector<gig::Instrument*> instruments; |
std::vector<gig::Instrument*> instruments; |
1115 |
std::vector<Gtk::TreeModel::Path> v = m_treeView.get_selection()->get_selected_rows(); |
{ |
1116 |
for (uint i = 0; i < v.size(); ++i) { |
typedef Gtk::TreeModel::Children Children; |
1117 |
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(v[i]); |
int i = 0; |
1118 |
Gtk::TreeModel::Row row = *it; |
Children selection = m_refOrderModel->children(); |
1119 |
Glib::ustring name = row[m_columns.m_col_name]; |
for (Children::iterator it = selection.begin(); |
1120 |
gig::Instrument* instrument = row[m_columns.m_col_instr]; |
it != selection.end(); ++it, ++i) |
1121 |
#if DEBUG_COMBINE_INSTRUMENTS |
{ |
1122 |
printf("Selection '%s' 0x%lx\n\n", name.c_str(), int64_t((void*)instrument)); |
Gtk::TreeModel::Row row = *it; |
1123 |
#endif |
Glib::ustring name = row[m_orderColumns.m_col_name]; |
1124 |
instruments.push_back(instrument); |
gig::Instrument* instrument = row[m_orderColumns.m_col_instr]; |
1125 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
1126 |
|
printf("Selection %d. '%s' %p\n\n", (i+1), name.c_str(), instrument)); |
1127 |
|
#endif |
1128 |
|
instruments.push_back(instrument); |
1129 |
|
} |
1130 |
} |
} |
1131 |
|
|
1132 |
g_warnings.clear(); |
g_warnings.clear(); |
1133 |
|
|
1134 |
try { |
try { |
1135 |
combineInstruments(instruments, m_gig, m_newCombinedInstrument); |
// which main dimension was selected in the combo box? |
1136 |
|
gig::dimension_t mainDimension; |
1137 |
|
{ |
1138 |
|
Gtk::TreeModel::iterator iterType = m_comboDimType.get_active(); |
1139 |
|
if (!iterType) throw gig::Exception("No dimension selected"); |
1140 |
|
Gtk::TreeModel::Row rowType = *iterType; |
1141 |
|
if (!rowType) throw gig::Exception("Something is wrong regarding dimension selection"); |
1142 |
|
int iTypeID = rowType[m_comboDimsModel.m_type_id]; |
1143 |
|
mainDimension = static_cast<gig::dimension_t>(iTypeID); |
1144 |
|
} |
1145 |
|
|
1146 |
|
// now start the actual combination task ... |
1147 |
|
combineInstruments(instruments, m_gig, m_newCombinedInstrument, mainDimension); |
1148 |
} catch (RIFF::Exception e) {; |
} catch (RIFF::Exception e) {; |
1149 |
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
1150 |
msg.run(); |
msg.run(); |
1183 |
void CombineInstrumentsDialog::onSelectionChanged() { |
void CombineInstrumentsDialog::onSelectionChanged() { |
1184 |
std::vector<Gtk::TreeModel::Path> v = m_treeView.get_selection()->get_selected_rows(); |
std::vector<Gtk::TreeModel::Path> v = m_treeView.get_selection()->get_selected_rows(); |
1185 |
m_OKButton.set_sensitive(v.size() >= 2); |
m_OKButton.set_sensitive(v.size() >= 2); |
1186 |
|
|
1187 |
|
typedef Gtk::TreeModel::Children Children; |
1188 |
|
|
1189 |
|
// update horizontal selection list (icon view) ... |
1190 |
|
|
1191 |
|
// remove items which are not part of the new selection anymore |
1192 |
|
{ |
1193 |
|
Children allOrdered = m_refOrderModel->children(); |
1194 |
|
for (Children::iterator itOrder = allOrdered.begin(); |
1195 |
|
itOrder != allOrdered.end(); ++itOrder) |
1196 |
|
{ |
1197 |
|
Gtk::TreeModel::Row rowOrder = *itOrder; |
1198 |
|
gig::Instrument* instr = rowOrder[m_orderColumns.m_col_instr]; |
1199 |
|
for (uint i = 0; i < v.size(); ++i) { |
1200 |
|
Gtk::TreeModel::iterator itSel = m_refTreeModel->get_iter(v[i]); |
1201 |
|
Gtk::TreeModel::Row rowSel = *itSel; |
1202 |
|
if (rowSel[m_columns.m_col_instr] == instr) |
1203 |
|
goto nextOrderedItem; |
1204 |
|
} |
1205 |
|
goto removeOrderedItem; |
1206 |
|
nextOrderedItem: |
1207 |
|
continue; |
1208 |
|
removeOrderedItem: |
1209 |
|
m_refOrderModel->erase(itOrder); |
1210 |
|
} |
1211 |
|
} |
1212 |
|
|
1213 |
|
// add items newly added to the selection |
1214 |
|
for (uint i = 0; i < v.size(); ++i) { |
1215 |
|
Gtk::TreeModel::iterator itSel = m_refTreeModel->get_iter(v[i]); |
1216 |
|
Gtk::TreeModel::Row rowSel = *itSel; |
1217 |
|
gig::Instrument* instr = rowSel[m_columns.m_col_instr]; |
1218 |
|
Children allOrdered = m_refOrderModel->children(); |
1219 |
|
for (Children::iterator itOrder = allOrdered.begin(); |
1220 |
|
itOrder != allOrdered.end(); ++itOrder) |
1221 |
|
{ |
1222 |
|
Gtk::TreeModel::Row rowOrder = *itOrder; |
1223 |
|
if (rowOrder[m_orderColumns.m_col_instr] == instr) |
1224 |
|
goto nextSelectionItem; |
1225 |
|
} |
1226 |
|
goto addNewSelectionItem; |
1227 |
|
nextSelectionItem: |
1228 |
|
continue; |
1229 |
|
addNewSelectionItem: |
1230 |
|
Glib::ustring name = gig_to_utf8(instr->pInfo->Name); |
1231 |
|
Gtk::TreeModel::iterator iterOrder = m_refOrderModel->append(); |
1232 |
|
Gtk::TreeModel::Row rowOrder = *iterOrder; |
1233 |
|
rowOrder[m_orderColumns.m_col_name] = name; |
1234 |
|
rowOrder[m_orderColumns.m_col_instr] = instr; |
1235 |
|
} |
1236 |
|
|
1237 |
|
// update markup |
1238 |
|
{ |
1239 |
|
int i = 0; |
1240 |
|
Children allOrdered = m_refOrderModel->children(); |
1241 |
|
for (Children::iterator itOrder = allOrdered.begin(); |
1242 |
|
itOrder != allOrdered.end(); ++itOrder, ++i) |
1243 |
|
{ |
1244 |
|
Gtk::TreeModel::Row rowOrder = *itOrder; |
1245 |
|
Glib::ustring name = rowOrder[m_orderColumns.m_col_name]; |
1246 |
|
Glib::ustring markup = |
1247 |
|
"<span foreground='black' background='white'>" + ToString(i+1) + ".</span>\n<span foreground='green' background='white'>" + name + "</span>"; |
1248 |
|
rowOrder[m_orderColumns.m_col_markup] = markup; |
1249 |
|
} |
1250 |
|
} |
1251 |
|
} |
1252 |
|
|
1253 |
|
void CombineInstrumentsDialog::on_show_tooltips_changed() { |
1254 |
|
const bool b = Settings::singleton()->showTooltips; |
1255 |
|
|
1256 |
|
m_treeView.set_has_tooltip(b); |
1257 |
|
m_iconView.set_has_tooltip(b); |
1258 |
|
|
1259 |
|
set_has_tooltip(b); |
1260 |
} |
} |
1261 |
|
|
1262 |
bool CombineInstrumentsDialog::fileWasChanged() const { |
bool CombineInstrumentsDialog::fileWasChanged() const { |