1 |
/* |
/* |
2 |
Copyright (c) 2014 Christian Schoenebeck |
Copyright (c) 2014-2017 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> |
18 |
#include <assert.h> |
#include <assert.h> |
19 |
|
#include <stdarg.h> |
20 |
|
#include <string.h> |
21 |
|
|
22 |
#include <glibmm/ustring.h> |
#include <glibmm/ustring.h> |
23 |
#include <gtkmm/stock.h> |
#include <gtkmm/stock.h> |
24 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
25 |
|
#include <gtkmm/label.h> |
26 |
|
|
27 |
Glib::ustring gig_to_utf8(const gig::String& gig_string); |
Glib::ustring dimTypeAsString(gig::dimension_t d); |
28 |
|
|
29 |
|
typedef std::vector< std::pair<gig::Instrument*, gig::Region*> > OrderedRegionGroup; |
30 |
typedef std::map<gig::Instrument*, gig::Region*> RegionGroup; |
typedef std::map<gig::Instrument*, gig::Region*> RegionGroup; |
31 |
typedef std::map<DLS::range_t,RegionGroup> RegionGroups; |
typedef std::map<DLS::range_t,RegionGroup> RegionGroups; |
32 |
|
|
33 |
typedef std::vector<DLS::range_t> DimensionZones; |
typedef std::vector<DLS::range_t> DimensionZones; |
34 |
typedef std::map<gig::dimension_t,DimensionZones> Dimensions; |
typedef std::map<gig::dimension_t,DimensionZones> Dimensions; |
35 |
|
|
|
typedef std::map<gig::dimension_t,int> DimensionCase; |
|
|
|
|
36 |
typedef std::map<gig::dimension_t, int> DimensionRegionUpperLimits; |
typedef std::map<gig::dimension_t, int> DimensionRegionUpperLimits; |
37 |
|
|
38 |
|
typedef std::set<Glib::ustring> Warnings; |
39 |
|
|
40 |
|
/////////////////////////////////////////////////////////////////////////// |
41 |
|
// private static data |
42 |
|
|
43 |
|
static Warnings g_warnings; |
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
46 |
// private functions |
// private functions |
47 |
|
|
57 |
#endif |
#endif |
58 |
|
|
59 |
/** |
/** |
60 |
|
* Store a warning message that shall be stored and displayed to the user as a |
61 |
|
* list of warnings after the overall operation has finished. Duplicate warning |
62 |
|
* messages are automatically eliminated. |
63 |
|
*/ |
64 |
|
inline void addWarning(const char* fmt, ...) { |
65 |
|
va_list arg; |
66 |
|
va_start(arg, fmt); |
67 |
|
const int SZ = 255 + strlen(fmt); |
68 |
|
char* buf = new char[SZ]; |
69 |
|
vsnprintf(buf, SZ, fmt, arg); |
70 |
|
Glib::ustring s = buf; |
71 |
|
delete [] buf; |
72 |
|
va_end(arg); |
73 |
|
std::cerr << _("WARNING:") << " " << s << std::endl << std::flush; |
74 |
|
g_warnings.insert(s); |
75 |
|
} |
76 |
|
|
77 |
|
/** |
78 |
* If the two ranges overlap, then this function returns the smallest point |
* If the two ranges overlap, then this function returns the smallest point |
79 |
* within that overlapping zone. If the two ranges do not overlap, then this |
* within that overlapping zone. If the two ranges do not overlap, then this |
80 |
* function will return -1 instead. |
* function will return -1 instead. |
94 |
* found with a range member point >= iStart |
* found with a range member point >= iStart |
95 |
*/ |
*/ |
96 |
static int findLowestRegionPoint(std::vector<gig::Instrument*>& instruments, int iStart) { |
static int findLowestRegionPoint(std::vector<gig::Instrument*>& instruments, int iStart) { |
97 |
DLS::range_t searchRange = { iStart, 127 }; |
DLS::range_t searchRange = { uint16_t(iStart), 127 }; |
98 |
int result = -1; |
int result = -1; |
99 |
for (uint i = 0; i < instruments.size(); ++i) { |
for (uint i = 0; i < instruments.size(); ++i) { |
100 |
gig::Instrument* instr = instruments[i]; |
gig::Instrument* instr = instruments[i]; |
116 |
* with a range end >= iStart |
* with a range end >= iStart |
117 |
*/ |
*/ |
118 |
static int findFirstRegionEnd(std::vector<gig::Instrument*>& instruments, int iStart) { |
static int findFirstRegionEnd(std::vector<gig::Instrument*>& instruments, int iStart) { |
119 |
DLS::range_t searchRange = { iStart, 127 }; |
DLS::range_t searchRange = { uint16_t(iStart), 127 }; |
120 |
int result = -1; |
int result = -1; |
121 |
for (uint i = 0; i < instruments.size(); ++i) { |
for (uint i = 0; i < instruments.size(); ++i) { |
122 |
gig::Instrument* instr = instruments[i]; |
gig::Instrument* instr = instruments[i]; |
159 |
std::vector<gig::Region*> v = getAllRegionsWhichOverlapRange(instr, range); |
std::vector<gig::Region*> v = getAllRegionsWhichOverlapRange(instr, range); |
160 |
if (v.empty()) continue; |
if (v.empty()) continue; |
161 |
if (v.size() > 1) { |
if (v.size() > 1) { |
162 |
std::cerr << "WARNING: More than one region found!" << std::endl; |
addWarning("More than one region found!"); |
163 |
} |
} |
164 |
group[instr] = v[0]; |
group[instr] = v[0]; |
165 |
} |
} |
169 |
/** @brief Identify required regions. |
/** @brief Identify required regions. |
170 |
* |
* |
171 |
* 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 |
172 |
* as layers in one single new instrument) and fulfills the following tasks: |
* as separate dimension zones of a certain dimension into one single new |
173 |
|
* instrument) and fulfills the following tasks: |
174 |
* |
* |
175 |
* - 1. Identification of total amount of regions required to create a new |
* - 1. Identification of total amount of regions required to create a new |
176 |
* instrument to become a layered version of the given instruments. |
* instrument to become a combined version of the given instruments. |
177 |
* - 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 |
178 |
* created in that new instrument. |
* created in that new instrument. |
179 |
* - 3. Grouping the original source regions of the given original instruments |
* - 3. Grouping the original source regions of the given original instruments |
192 |
iStart = findLowestRegionPoint(instruments, iStart); |
iStart = findLowestRegionPoint(instruments, iStart); |
193 |
if (iStart < 0) break; |
if (iStart < 0) break; |
194 |
const int iEnd = findFirstRegionEnd(instruments, iStart); |
const int iEnd = findFirstRegionEnd(instruments, iStart); |
195 |
DLS::range_t range = { iStart, iEnd }; |
DLS::range_t range = { uint16_t(iStart), uint16_t(iEnd) }; |
196 |
intersections.push_back(range); |
intersections.push_back(range); |
197 |
iStart = iEnd + 1; |
iStart = iEnd + 1; |
198 |
} |
} |
204 |
if (!group.empty()) |
if (!group.empty()) |
205 |
groups[range] = group; |
groups[range] = group; |
206 |
else |
else |
207 |
std::cerr << "WARNING: empty region group!" << std::endl; |
addWarning("Empty region group!"); |
208 |
} |
} |
209 |
|
|
210 |
return groups; |
return groups; |
263 |
itNums != it->second.end(); ++itNums) |
itNums != it->second.end(); ++itNums) |
264 |
{ |
{ |
265 |
const int iUpperLimit = *itNums; |
const int iUpperLimit = *itNums; |
266 |
DLS::range_t range = { iLow, iUpperLimit }; |
DLS::range_t range = { uint16_t(iLow), uint16_t(iUpperLimit) }; |
267 |
dims[type].push_back(range); |
dims[type].push_back(range); |
268 |
iLow = iUpperLimit + 1; |
iLow = iUpperLimit + 1; |
269 |
} |
} |
272 |
return dims; |
return dims; |
273 |
} |
} |
274 |
|
|
|
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; |
|
|
} |
|
|
|
|
275 |
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) { |
276 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
277 |
|
printf("dimvalues = { "); |
278 |
|
fflush(stdout); |
279 |
|
#endif |
280 |
for (DimensionCase::iterator it = dimCase.begin(); it != dimCase.end(); ++it) { |
for (DimensionCase::iterator it = dimCase.begin(); it != dimCase.end(); ++it) { |
281 |
gig::dimension_t type = it->first; |
gig::dimension_t type = it->first; |
282 |
int iDimIndex = getDimensionIndex(type, rgn); |
int iDimIndex = getDimensionIndex(type, rgn); |
283 |
if (bShouldHaveAllDimensionsPassed) assert(iDimIndex >= 0); |
if (bShouldHaveAllDimensionsPassed) assert(iDimIndex >= 0); |
284 |
else if (iDimIndex < 0) continue; |
else if (iDimIndex < 0) continue; |
285 |
values[iDimIndex] = it->second; |
values[iDimIndex] = it->second; |
286 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
287 |
|
printf("%x=%d, ", type, it->second); |
288 |
|
#endif |
289 |
} |
} |
290 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
291 |
|
printf("}\n"); |
292 |
|
#endif |
293 |
} |
} |
294 |
|
|
295 |
static DimensionRegionUpperLimits getDimensionRegionUpperLimits(gig::DimensionRegion* dimRgn) { |
static DimensionRegionUpperLimits getDimensionRegionUpperLimits(gig::DimensionRegion* dimRgn) { |
296 |
DimensionRegionUpperLimits limits; |
DimensionRegionUpperLimits limits; |
297 |
gig::Region* rgn = dimRgn->GetParent(); |
gig::Region* rgn = dimRgn->GetParent(); |
298 |
for (int d = 0; d < rgn->Dimensions; ++d) { |
for (uint d = 0; d < rgn->Dimensions; ++d) { |
299 |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[d]; |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[d]; |
300 |
limits[def.dimension] = dimRgn->DimensionUpperLimits[d]; |
limits[def.dimension] = dimRgn->DimensionUpperLimits[d]; |
301 |
} |
} |
313 |
} |
} |
314 |
} |
} |
315 |
|
|
|
/** |
|
|
* 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 (int i = 0; i < rgn->Dimensions; ++i) { |
|
|
if (rgn->pDimensionDefinitions[i].dimension == type) break; |
|
|
previousBits += rgn->pDimensionDefinitions[i].bits; |
|
|
} |
|
|
return previousBits; |
|
|
} |
|
|
|
|
316 |
inline int dimensionRegionIndex(gig::DimensionRegion* dimRgn) { |
inline int dimensionRegionIndex(gig::DimensionRegion* dimRgn) { |
317 |
gig::Region* rgn = dimRgn->GetParent(); |
gig::Region* rgn = dimRgn->GetParent(); |
318 |
int sz = sizeof(rgn->pDimensionRegions) / sizeof(gig::DimensionRegion*); |
int sz = sizeof(rgn->pDimensionRegions) / sizeof(gig::DimensionRegion*); |
345 |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[iDimension]; |
const gig::dimension_def_t& def = rgn->pDimensionDefinitions[iDimension]; |
346 |
int iDimRgn = dimensionRegionIndex(dimRgn); |
int iDimRgn = dimensionRegionIndex(dimRgn); |
347 |
int iBaseBits = baseBits(type, rgn); |
int iBaseBits = baseBits(type, rgn); |
348 |
|
assert(iBaseBits >= 0); |
349 |
int mask = ~(((1 << def.bits) - 1) << iBaseBits); |
int mask = ~(((1 << def.bits) - 1) << iBaseBits); |
350 |
|
|
351 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
352 |
|
printf("velo zones { "); |
353 |
|
fflush(stdout); |
354 |
|
#endif |
355 |
int iLow = 0; |
int iLow = 0; |
356 |
for (int z = 0; z < def.zones; ++z) { |
for (int z = 0; z < def.zones; ++z) { |
357 |
gig::DimensionRegion* dimRgn2 = |
gig::DimensionRegion* dimRgn2 = |
358 |
rgn->pDimensionRegions[ (iDimRgn & mask) | ( z << iBaseBits) ]; |
rgn->pDimensionRegions[ (iDimRgn & mask) | ( z << iBaseBits) ]; |
359 |
int iHigh = dimRgn2->DimensionUpperLimits[iDimension]; |
int iHigh = dimRgn2->DimensionUpperLimits[iDimension]; |
360 |
DLS::range_t range = { iLow, iHigh}; |
DLS::range_t range = { uint16_t(iLow), uint16_t(iHigh) }; |
361 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
362 |
|
printf("%d..%d, ", iLow, iHigh); |
363 |
|
fflush(stdout); |
364 |
|
#endif |
365 |
zones.push_back(range); |
zones.push_back(range); |
366 |
iLow = iHigh + 1; |
iLow = iHigh + 1; |
367 |
} |
} |
368 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
369 |
|
printf("}\n"); |
370 |
|
#endif |
371 |
return zones; |
return zones; |
372 |
} |
} |
373 |
|
|
374 |
/** @brief Copy all DimensionRegions from source Region to target Region. |
struct CopyAssignSchedEntry { |
375 |
* |
gig::DimensionRegion* src; |
376 |
* Copies the entire articulation informations (including sample reference of |
gig::DimensionRegion* dst; |
377 |
* course) from all individual DimensionRegions of source Region @a inRgn to |
int velocityZone; |
378 |
* target Region @a outRgn. There are no dimension regions created during this |
int totalSrcVelocityZones; |
379 |
* task. It is expected that the required dimensions (thus the required |
}; |
380 |
* dimension regions) were already created before calling this function. |
typedef std::vector<CopyAssignSchedEntry> CopyAssignSchedule; |
381 |
* |
|
382 |
* To be precise, it does the task above only for the layer selected by |
/** @brief Schedule copying DimensionRegions from source Region to target Region. |
383 |
* @a iSrcLayer and @a iDstLayer. All dimensions regions of other layers that |
* |
384 |
* may exist, will not be copied by one single call of this function. So if |
* Schedules copying the entire articulation informations (including sample |
385 |
* there is a layer dimension, this function needs to be called several times. |
* reference) from all individual DimensionRegions of source Region @a inRgn to |
386 |
|
* target Region @a outRgn. It is expected that the required dimensions (thus |
387 |
|
* the required dimension regions) were already created before calling this |
388 |
|
* function. |
389 |
|
* |
390 |
|
* To be precise, it does the task above only for the dimension zones defined by |
391 |
|
* the three arguments @a mainDim, @a iSrcMainBit, @a iDstMainBit, which reflect |
392 |
|
* a selection which dimension zones shall be copied. All other dimension zones |
393 |
|
* will not be scheduled to be copied by a single call of this function. So this |
394 |
|
* function needs to be called several time in case all dimension regions shall |
395 |
|
* be copied of the entire region (@a inRgn, @a outRgn). |
396 |
* |
* |
397 |
* @param outRgn - where the dimension regions shall be copied to |
* @param outRgn - where the dimension regions shall be copied to |
398 |
* @param inRgn - all dimension regions that shall be copied from |
* @param inRgn - all dimension regions that shall be copied from |
399 |
* @param dims - dimension definitions of target region |
* @param dims - precise dimension definitions of target region |
400 |
* @param iDstLayer - layer number of destination region where the dimension |
* @param mainDim - this dimension type, in combination with @a iSrcMainBit and |
401 |
* regions shall be copied to |
* @a iDstMainBit defines a selection which dimension region |
402 |
* @param iSrcLayer - layer number of the source region where the dimension |
* zones shall be copied by this call of this function |
403 |
* regions shall be copied from |
* @param iDstMainBit - destination bit of @a mainDim |
404 |
|
* @param iSrcMainBit - source bit of @a mainDim |
405 |
|
* @param schedule - list of all DimensionRegion copy operations which is filled |
406 |
|
* during the nested loops / recursions of this function call |
407 |
* @param dimCase - just for internal purpose (function recursion), don't pass |
* @param dimCase - just for internal purpose (function recursion), don't pass |
408 |
* anything here, this function will call itself recursively |
* anything here, this function will call itself recursively |
409 |
* will fill this container with concrete dimension values for |
* will fill this container with concrete dimension values for |
410 |
* selecting the precise dimension regions during its task |
* selecting the precise dimension regions during its task |
411 |
*/ |
*/ |
412 |
static void copyDimensionRegions(gig::Region* outRgn, gig::Region* inRgn, Dimensions dims, int iDstLayer, int iSrcLayer, DimensionCase dimCase = DimensionCase()) { |
static void scheduleCopyDimensionRegions(gig::Region* outRgn, gig::Region* inRgn, |
413 |
if (dims.empty()) { |
Dimensions dims, gig::dimension_t mainDim, |
414 |
|
int iDstMainBit, int iSrcMainBit, |
415 |
|
CopyAssignSchedule* schedule, |
416 |
|
DimensionCase dimCase = DimensionCase()) |
417 |
|
{ |
418 |
|
if (dims.empty()) { // reached deepest level of function recursion ... |
419 |
|
CopyAssignSchedEntry e; |
420 |
|
|
421 |
// resolve the respective source & destination DimensionRegion ... |
// resolve the respective source & destination DimensionRegion ... |
422 |
uint srcDimValues[8] = {}; |
uint srcDimValues[8] = {}; |
423 |
uint dstDimValues[8] = {}; |
uint dstDimValues[8] = {}; |
424 |
DimensionCase srcDimCase = dimCase; |
DimensionCase srcDimCase = dimCase; |
425 |
DimensionCase dstDimCase = dimCase; |
DimensionCase dstDimCase = dimCase; |
426 |
srcDimCase[gig::dimension_layer] = iSrcLayer; |
srcDimCase[mainDim] = iSrcMainBit; |
427 |
dstDimCase[gig::dimension_layer] = iDstLayer; |
dstDimCase[mainDim] = iDstMainBit; |
428 |
|
|
429 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
430 |
|
printf("-------------------------------\n"); |
431 |
|
printf("iDstMainBit=%d iSrcMainBit=%d\n", iDstMainBit, iSrcMainBit); |
432 |
|
#endif |
433 |
|
|
434 |
// first select source & target dimension region with an arbitrary |
// first select source & target dimension region with an arbitrary |
435 |
// velocity split zone, to get access to the precise individual velocity |
// velocity split zone, to get access to the precise individual velocity |
436 |
// split zone sizes (if there is actually a velocity dimension at all, |
// split zone sizes (if there is actually a velocity dimension at all, |
437 |
// otherwise we already select the desired source & target dimension |
// otherwise we already select the desired source & target dimension |
438 |
// region here) |
// region here) |
439 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
440 |
|
printf("src "); fflush(stdout); |
441 |
|
#endif |
442 |
fillDimValues(srcDimValues, srcDimCase, inRgn, false); |
fillDimValues(srcDimValues, srcDimCase, inRgn, false); |
443 |
fillDimValues(dstDimValues, dstDimCase, outRgn, true); |
#if DEBUG_COMBINE_INSTRUMENTS |
444 |
|
printf("dst "); fflush(stdout); |
445 |
|
#endif |
446 |
|
fillDimValues(dstDimValues, dstDimCase, outRgn, false); |
447 |
gig::DimensionRegion* srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues); |
gig::DimensionRegion* srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues); |
448 |
gig::DimensionRegion* dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
gig::DimensionRegion* dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
449 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
450 |
|
printf("iDstMainBit=%d iSrcMainBit=%d\n", iDstMainBit, iSrcMainBit); |
451 |
|
printf("srcDimRgn=%lx dstDimRgn=%lx\n", (uint64_t)srcDimRgn, (uint64_t)dstDimRgn); |
452 |
|
printf("srcSample='%s' dstSample='%s'\n", |
453 |
|
(!srcDimRgn->pSample ? "NULL" : srcDimRgn->pSample->pInfo->Name.c_str()), |
454 |
|
(!dstDimRgn->pSample ? "NULL" : dstDimRgn->pSample->pInfo->Name.c_str()) |
455 |
|
); |
456 |
|
#endif |
457 |
|
|
458 |
|
assert(srcDimRgn->GetParent() == inRgn); |
459 |
|
assert(dstDimRgn->GetParent() == outRgn); |
460 |
|
|
461 |
// now that we have access to the precise velocity split zone upper |
// now that we have access to the precise velocity split zone upper |
462 |
// limits, we can select the actual source & destination dimension |
// limits, we can select the actual source & destination dimension |
463 |
// regions we need to copy (assuming that source or target region has |
// regions we need to copy (assuming that source or target region has |
464 |
// a velocity dimension) |
// a velocity dimension) |
465 |
if (outRgn->GetDimensionDefinition(gig::dimension_velocity)) { |
if (outRgn->GetDimensionDefinition(gig::dimension_velocity)) { |
466 |
// re-select target dimension region |
// re-select target dimension region (with correct velocity zone) |
467 |
DimensionZones zones = preciseDimensionZonesFor(gig::dimension_velocity, dstDimRgn); |
DimensionZones dstZones = preciseDimensionZonesFor(gig::dimension_velocity, dstDimRgn); |
468 |
assert(zones.size() > 1); |
assert(dstZones.size() > 1); |
469 |
const int iZoneIndex = dstDimCase[gig::dimension_velocity]; |
const int iDstZoneIndex = |
470 |
assert(iZoneIndex <= zones.size()); |
(mainDim == gig::dimension_velocity) |
471 |
dstDimCase[gig::dimension_velocity] = zones[iZoneIndex].low; // arbitrary value between low and high |
? iDstMainBit : dstDimCase[gig::dimension_velocity]; // (mainDim == gig::dimension_velocity) exception case probably unnecessary here |
472 |
fillDimValues(dstDimValues, dstDimCase, outRgn, true); |
e.velocityZone = iDstZoneIndex; |
473 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
474 |
|
printf("dst velocity zone: %d/%d\n", iDstZoneIndex, (int)dstZones.size()); |
475 |
|
#endif |
476 |
|
assert(uint(iDstZoneIndex) < dstZones.size()); |
477 |
|
dstDimCase[gig::dimension_velocity] = dstZones[iDstZoneIndex].low; // arbitrary value between low and high |
478 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
479 |
|
printf("dst velocity value = %d\n", dstDimCase[gig::dimension_velocity]); |
480 |
|
printf("dst refilled "); fflush(stdout); |
481 |
|
#endif |
482 |
|
fillDimValues(dstDimValues, dstDimCase, outRgn, false); |
483 |
dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues); |
484 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
485 |
|
printf("reselected dstDimRgn=%lx\n", (uint64_t)dstDimRgn); |
486 |
|
printf("dstSample='%s'%s\n", |
487 |
|
(!dstDimRgn->pSample ? "NULL" : dstDimRgn->pSample->pInfo->Name.c_str()), |
488 |
|
(dstDimRgn->pSample ? " <--- ERROR ERROR ERROR !!!!!!!!! " : "") |
489 |
|
); |
490 |
|
#endif |
491 |
|
|
492 |
// re-select source dimension region |
// re-select source dimension region with correct velocity zone |
493 |
// (if it has a velocity dimension) |
// (if it has a velocity dimension that is) |
494 |
if (inRgn->GetDimensionDefinition(gig::dimension_velocity)) { |
if (inRgn->GetDimensionDefinition(gig::dimension_velocity)) { |
495 |
srcDimCase[gig::dimension_velocity] = zones[iZoneIndex].low; // same value as used above for target dimension region |
DimensionZones srcZones = preciseDimensionZonesFor(gig::dimension_velocity, srcDimRgn); |
496 |
|
e.totalSrcVelocityZones = srcZones.size(); |
497 |
|
assert(srcZones.size() > 0); |
498 |
|
if (srcZones.size() <= 1) { |
499 |
|
addWarning("Input region has a velocity dimension with only ONE zone!"); |
500 |
|
} |
501 |
|
int iSrcZoneIndex = |
502 |
|
(mainDim == gig::dimension_velocity) |
503 |
|
? iSrcMainBit : iDstZoneIndex; |
504 |
|
if (uint(iSrcZoneIndex) >= srcZones.size()) |
505 |
|
iSrcZoneIndex = srcZones.size() - 1; |
506 |
|
srcDimCase[gig::dimension_velocity] = srcZones[iSrcZoneIndex].low; // same zone as used above for target dimension region (no matter what the precise zone ranges are) |
507 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
508 |
|
printf("src refilled "); fflush(stdout); |
509 |
|
#endif |
510 |
fillDimValues(srcDimValues, srcDimCase, inRgn, false); |
fillDimValues(srcDimValues, srcDimCase, inRgn, false); |
511 |
srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues); |
srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues); |
512 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
513 |
|
printf("reselected srcDimRgn=%lx\n", (uint64_t)srcDimRgn); |
514 |
|
printf("srcSample='%s'\n", |
515 |
|
(!srcDimRgn->pSample ? "NULL" : srcDimRgn->pSample->pInfo->Name.c_str()) |
516 |
|
); |
517 |
|
#endif |
518 |
} |
} |
519 |
} |
} |
520 |
|
|
521 |
// backup the target DimensionRegion's current dimension zones upper |
// Schedule copy operation of source -> target DimensionRegion for the |
522 |
// limits (because the target DimensionRegion's upper limits are already |
// time after all nested loops have been traversed. We have to postpone |
523 |
// defined correctly since calling AddDimension(), and the CopyAssign() |
// the actual copy operations this way, because otherwise it would |
524 |
// call next, will overwrite those upper limits unfortunately |
// overwrite informations inside the destination DimensionRegion object |
525 |
DimensionRegionUpperLimits dstUpperLimits = getDimensionRegionUpperLimits(dstDimRgn); |
// that we need to read in the code block above. |
526 |
DimensionRegionUpperLimits srcUpperLimits = getDimensionRegionUpperLimits(srcDimRgn); |
e.src = srcDimRgn; |
527 |
|
e.dst = dstDimRgn; |
528 |
// copy over the selected DimensionRegion |
schedule->push_back(e); |
529 |
const gig::Region* const origRgn = dstDimRgn->GetParent(); // just for sanity check below |
|
530 |
dstDimRgn->CopyAssign(srcDimRgn); |
return; // returning from deepest level of function recursion |
531 |
assert(origRgn == dstDimRgn->GetParent()); |
} |
532 |
|
|
533 |
// restore all original dimension zone upper limits except of the |
// Copying n dimensions requires n nested loops. That's why this function |
534 |
// velocity dimension, because the velocity dimension zone sizes are |
// is calling itself recursively to provide the required amount of nested |
535 |
// allowed to differ for individual DimensionRegions in gig v3 format |
// loops. With each call it pops from argument 'dims' and pushes to |
536 |
if (srcUpperLimits.count(gig::dimension_velocity)) { |
// argument 'dimCase'. |
|
assert(dstUpperLimits.count(gig::dimension_velocity)); |
|
|
dstUpperLimits[gig::dimension_velocity] = srcUpperLimits[gig::dimension_velocity]; |
|
|
} |
|
|
restoreDimensionRegionUpperLimits(dstDimRgn, dstUpperLimits); |
|
|
|
|
|
return; // end of recursion |
|
|
} |
|
537 |
|
|
538 |
Dimensions::iterator itDimension = dims.begin(); |
Dimensions::iterator itDimension = dims.begin(); |
|
|
|
539 |
gig::dimension_t type = itDimension->first; |
gig::dimension_t type = itDimension->first; |
540 |
DimensionZones zones = itDimension->second; |
DimensionZones zones = itDimension->second; |
|
|
|
541 |
dims.erase(itDimension); |
dims.erase(itDimension); |
542 |
|
|
543 |
int iZone = 0; |
int iZone = 0; |
547 |
DLS::range_t zoneRange = *itZone; |
DLS::range_t zoneRange = *itZone; |
548 |
gig::dimension_def_t* def = outRgn->GetDimensionDefinition(type); |
gig::dimension_def_t* def = outRgn->GetDimensionDefinition(type); |
549 |
dimCase[type] = (def->split_type == gig::split_type_bit) ? iZone : zoneRange.low; |
dimCase[type] = (def->split_type == gig::split_type_bit) ? iZone : zoneRange.low; |
550 |
|
|
551 |
// recurse until 'dims' is exhausted (and dimCase filled up with concrete value) |
// recurse until 'dims' is exhausted (and dimCase filled up with concrete value) |
552 |
copyDimensionRegions(outRgn, inRgn, dims, iDstLayer, iSrcLayer, dimCase); |
scheduleCopyDimensionRegions(outRgn, inRgn, dims, mainDim, iDstMainBit, iSrcMainBit, schedule, dimCase); |
553 |
} |
} |
554 |
} |
} |
555 |
|
|
556 |
|
static OrderedRegionGroup sortRegionGroup(const RegionGroup& group, const std::vector<gig::Instrument*>& instruments) { |
557 |
|
OrderedRegionGroup result; |
558 |
|
for (std::vector<gig::Instrument*>::const_iterator it = instruments.begin(); |
559 |
|
it != instruments.end(); ++it) |
560 |
|
{ |
561 |
|
RegionGroup::const_iterator itRgn = group.find(*it); |
562 |
|
if (itRgn == group.end()) continue; |
563 |
|
result.push_back( |
564 |
|
std::pair<gig::Instrument*, gig::Region*>( |
565 |
|
itRgn->first, itRgn->second |
566 |
|
) |
567 |
|
); |
568 |
|
} |
569 |
|
return result; |
570 |
|
} |
571 |
|
|
572 |
/** @brief Combine given list of instruments to one instrument. |
/** @brief Combine given list of instruments to one instrument. |
573 |
* |
* |
574 |
* 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 |
575 |
* 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 |
576 |
* in the new instrument and copies the source instruments to those layers. |
* given by @a mainDimension in the new instrument and copies the source |
577 |
|
* instruments to those dimension zones. |
578 |
* |
* |
579 |
* @param instruments - (input) list of instruments that shall be combined, |
* @param instruments - (input) list of instruments that shall be combined, |
580 |
* they will only be read, so they will be left untouched |
* they will only be read, so they will be left untouched |
582 |
* be created |
* be created |
583 |
* @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 |
584 |
* instrument being created |
* instrument being created |
585 |
|
* @param mainDimension - the dimension that shall be used to combine the |
586 |
|
* instruments |
587 |
* @throw RIFF::Exception on any kinds of errors |
* @throw RIFF::Exception on any kinds of errors |
588 |
*/ |
*/ |
589 |
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) { |
590 |
output = NULL; |
output = NULL; |
591 |
|
|
592 |
// divide the individual regions to (probably even smaller) groups of |
// divide the individual regions to (probably even smaller) groups of |
604 |
|
|
605 |
// create a new output instrument |
// create a new output instrument |
606 |
gig::Instrument* outInstr = gig->AddInstrument(); |
gig::Instrument* outInstr = gig->AddInstrument(); |
607 |
outInstr->pInfo->Name = "NEW COMBINATION"; |
outInstr->pInfo->Name = _("NEW COMBINATION"); |
608 |
|
|
609 |
// Distinguishing in the following code block between 'horizontal' and |
// Distinguishing in the following code block between 'horizontal' and |
610 |
// 'vertical' regions. The 'horizontal' ones are meant to be the key ranges |
// 'vertical' regions. The 'horizontal' ones are meant to be the key ranges |
619 |
{ |
{ |
620 |
gig::Region* outRgn = outInstr->AddRegion(); |
gig::Region* outRgn = outInstr->AddRegion(); |
621 |
outRgn->SetKeyRange(itGroup->first.low, itGroup->first.high); |
outRgn->SetKeyRange(itGroup->first.low, itGroup->first.high); |
622 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
623 |
|
printf("---> Start target region %d..%d\n", itGroup->first.low, itGroup->first.high); |
624 |
|
#endif |
625 |
|
|
626 |
// detect the total amount of layers required to build up this combi |
// detect the total amount of zones required for the given main |
627 |
// for current key range |
// dimension to build up this combi for current key range |
628 |
int iTotalLayers = 0; |
int iTotalZones = 0; |
629 |
for (RegionGroup::iterator itRgn = itGroup->second.begin(); |
for (RegionGroup::iterator itRgn = itGroup->second.begin(); |
630 |
itRgn != itGroup->second.end(); ++itRgn) |
itRgn != itGroup->second.end(); ++itRgn) |
631 |
{ |
{ |
632 |
gig::Region* inRgn = itRgn->second; |
gig::Region* inRgn = itRgn->second; |
633 |
iTotalLayers += inRgn->Layers; |
gig::dimension_def_t* def = inRgn->GetDimensionDefinition(mainDimension); |
634 |
|
iTotalZones += (def) ? def->zones : 1; |
635 |
} |
} |
636 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
637 |
|
printf("Required total zones: %d, vertical regions: %d\n", iTotalZones, itGroup->second.size()); |
638 |
|
#endif |
639 |
|
|
640 |
// create all required dimensions for this output region |
// create all required dimensions for this output region |
641 |
// (except the layer dimension, which we create as next step) |
// (except the main dimension used for separating the individual |
642 |
|
// instruments, we create that particular dimension as next step) |
643 |
Dimensions dims = getDimensionsForRegionGroup(itGroup->second); |
Dimensions dims = getDimensionsForRegionGroup(itGroup->second); |
644 |
for (Dimensions::iterator itDim = dims.begin(); |
// the given main dimension which is used to combine the instruments is |
645 |
itDim != dims.end(); ++itDim) |
// created separately after the next code block, and the main dimension |
646 |
|
// should not be part of dims here, because it also used for iterating |
647 |
|
// all dimensions zones, which would lead to this dimensions being |
648 |
|
// iterated twice |
649 |
|
dims.erase(mainDimension); |
650 |
{ |
{ |
651 |
if (itDim->first == gig::dimension_layer) continue; |
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 |
652 |
|
|
653 |
gig::dimension_def_t def; |
for (Dimensions::iterator itDim = dims.begin(); |
654 |
def.dimension = itDim->first; // dimension type |
itDim != dims.end(); ++itDim) |
655 |
def.zones = itDim->second.size(); |
{ |
656 |
def.bits = zoneCountToBits(def.zones); |
gig::dimension_def_t def; |
657 |
#if DEBUG_COMBINE_INSTRUMENTS |
def.dimension = itDim->first; // dimension type |
658 |
std::cout << "Adding new regular dimension type=" << std::hex << (int)def.dimension << std::dec << ", zones=" << (int)def.zones << ", bits=" << (int)def.bits << " ... " << std::flush; |
def.zones = itDim->second.size(); |
659 |
#endif |
def.bits = zoneCountToBits(def.zones); |
660 |
outRgn->AddDimension(&def); |
if (def.zones < 2) { |
661 |
#if DEBUG_COMBINE_INSTRUMENTS |
addWarning( |
662 |
std::cout << "OK" << std::endl << std::flush; |
"Attempt to create dimension with type=0x%x with only " |
663 |
#endif |
"ONE zone (because at least one of the source " |
664 |
|
"instruments seems to have such a velocity dimension " |
665 |
|
"with only ONE zone, which is odd)! Skipping this " |
666 |
|
"dimension for now.", |
667 |
|
(int)itDim->first |
668 |
|
); |
669 |
|
skipTheseDimensions.push_back(itDim->first); |
670 |
|
continue; |
671 |
|
} |
672 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
673 |
|
std::cout << "Adding new regular dimension type=" << std::hex << (int)def.dimension << std::dec << ", zones=" << (int)def.zones << ", bits=" << (int)def.bits << " ... " << std::flush; |
674 |
|
#endif |
675 |
|
outRgn->AddDimension(&def); |
676 |
|
#if DEBUG_COMBINE_INSTRUMENTS |
677 |
|
std::cout << "OK" << std::endl << std::flush; |
678 |
|
#endif |
679 |
|
} |
680 |
|
// prevent the following dimensions to be processed further below |
681 |
|
// (since the respective dimension was not created above) |
682 |
|
for (int i = 0; i < skipTheseDimensions.size(); ++i) |
683 |
|
dims.erase(skipTheseDimensions[i]); |
684 |
} |
} |
685 |
|
|
686 |
// create the layer dimension (if necessary for current key range) |
// create the main dimension (if necessary for current key range) |
687 |
if (iTotalLayers > 1) { |
if (iTotalZones > 1) { |
688 |
gig::dimension_def_t def; |
gig::dimension_def_t def; |
689 |
def.dimension = gig::dimension_layer; // dimension type |
def.dimension = mainDimension; // dimension type |
690 |
def.zones = iTotalLayers; |
def.zones = iTotalZones; |
691 |
def.bits = zoneCountToBits(def.zones); |
def.bits = zoneCountToBits(def.zones); |
692 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
693 |
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; |
694 |
#endif |
#endif |
695 |
outRgn->AddDimension(&def); |
outRgn->AddDimension(&def); |
696 |
#if DEBUG_COMBINE_INSTRUMENTS |
#if DEBUG_COMBINE_INSTRUMENTS |
697 |
std::cout << "OK" << std::endl << std::flush; |
std::cout << "OK" << std::endl << std::flush; |
698 |
#endif |
#endif |
699 |
|
} else { |
700 |
|
dims.erase(mainDimension); |
701 |
} |
} |
702 |
|
|
703 |
// now copy the source dimension regions to the target dimension regions |
// for the next task we need to have the current RegionGroup to be |
704 |
int iDstLayer = 0; |
// sorted by instrument in the same sequence as the 'instruments' vector |
705 |
for (RegionGroup::iterator itRgn = itGroup->second.begin(); |
// argument passed to this function (because the std::map behind the |
706 |
itRgn != itGroup->second.end(); ++itRgn) // iterate over 'vertical' / source regions ... |
// 'RegionGroup' type sorts by memory address instead, and that would |
707 |
|
// sometimes lead to the source instruments' region to be sorted into |
708 |
|
// the wrong target layer) |
709 |
|
OrderedRegionGroup currentGroup = sortRegionGroup(itGroup->second, instruments); |
710 |
|
|
711 |
|
// schedule copying the source dimension regions to the target dimension |
712 |
|
// regions |
713 |
|
CopyAssignSchedule schedule; |
714 |
|
int iDstMainBit = 0; |
715 |
|
for (OrderedRegionGroup::iterator itRgn = currentGroup.begin(); |
716 |
|
itRgn != currentGroup.end(); ++itRgn) // iterate over 'vertical' / source regions ... |
717 |
{ |
{ |
718 |
gig::Region* inRgn = itRgn->second; |
gig::Region* inRgn = itRgn->second; |
719 |
for (uint iSrcLayer = 0; iSrcLayer < inRgn->Layers; ++iSrcLayer, ++iDstLayer) { |
#if DEBUG_COMBINE_INSTRUMENTS |
720 |
copyDimensionRegions(outRgn, inRgn, dims, iDstLayer, iSrcLayer); |
printf("[source region of '%s']\n", inRgn->GetParent()->pInfo->Name.c_str()); |
721 |
|
#endif |
722 |
|
|
723 |
|
// determine how many main dimension zones this input region requires |
724 |
|
gig::dimension_def_t* def = inRgn->GetDimensionDefinition(mainDimension); |
725 |
|
const int inRgnMainZones = (def) ? def->zones : 1; |
726 |
|
|
727 |
|
for (uint iSrcMainBit = 0; iSrcMainBit < inRgnMainZones; ++iSrcMainBit, ++iDstMainBit) { |
728 |
|
scheduleCopyDimensionRegions( |
729 |
|
outRgn, inRgn, dims, mainDimension, |
730 |
|
iDstMainBit, iSrcMainBit, &schedule |
731 |
|
); |
732 |
} |
} |
733 |
} |
} |
734 |
|
|
735 |
|
// finally copy the scheduled source -> target dimension regions |
736 |
|
for (uint i = 0; i < schedule.size(); ++i) { |
737 |
|
CopyAssignSchedEntry& e = schedule[i]; |
738 |
|
|
739 |
|
// backup the target DimensionRegion's current dimension zones upper |
740 |
|
// limits (because the target DimensionRegion's upper limits are |
741 |
|
// already defined correctly since calling AddDimension(), and the |
742 |
|
// CopyAssign() call next, will overwrite those upper limits |
743 |
|
// unfortunately |
744 |
|
DimensionRegionUpperLimits dstUpperLimits = getDimensionRegionUpperLimits(e.dst); |
745 |
|
DimensionRegionUpperLimits srcUpperLimits = getDimensionRegionUpperLimits(e.src); |
746 |
|
|
747 |
|
// now actually copy over the current DimensionRegion |
748 |
|
const gig::Region* const origRgn = e.dst->GetParent(); // just for sanity check below |
749 |
|
e.dst->CopyAssign(e.src); |
750 |
|
assert(origRgn == e.dst->GetParent()); // if gigedit is crashing here, then you must update libgig (to at least SVN r2547, v3.3.0.svn10) |
751 |
|
|
752 |
|
// restore all original dimension zone upper limits except of the |
753 |
|
// velocity dimension, because the velocity dimension zone sizes are |
754 |
|
// allowed to differ for individual DimensionRegions in gig v3 |
755 |
|
// format |
756 |
|
// |
757 |
|
// if the main dinension is the 'velocity' dimension, then skip |
758 |
|
// restoring the source's original velocity zone limits, because |
759 |
|
// dealing with merging that is not implemented yet |
760 |
|
// TODO: merge custom velocity splits if main dimension is the velocity dimension (for now equal sized velocity zones are used if mainDim is 'velocity') |
761 |
|
if (srcUpperLimits.count(gig::dimension_velocity) && mainDimension != gig::dimension_velocity) { |
762 |
|
if (!dstUpperLimits.count(gig::dimension_velocity)) { |
763 |
|
addWarning("Source instrument seems to have a velocity dimension whereas new target instrument doesn't!"); |
764 |
|
} else { |
765 |
|
dstUpperLimits[gig::dimension_velocity] = |
766 |
|
(e.velocityZone >= e.totalSrcVelocityZones) |
767 |
|
? 127 : srcUpperLimits[gig::dimension_velocity]; |
768 |
|
} |
769 |
|
} |
770 |
|
restoreDimensionRegionUpperLimits(e.dst, dstUpperLimits); |
771 |
|
} |
772 |
} |
} |
773 |
|
|
774 |
// success |
// success |
779 |
// class 'CombineInstrumentsDialog' |
// class 'CombineInstrumentsDialog' |
780 |
|
|
781 |
CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig) |
CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig) |
782 |
: Gtk::Dialog(_("Combine Instruments"), parent, true), |
: ManagedDialog(_("Combine Instruments"), parent, true), |
783 |
m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL), |
m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL), |
784 |
m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK), |
m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK), |
785 |
m_descriptionLabel() |
m_descriptionLabel(), m_tableDimCombo(2, 2), m_comboDimType(), |
786 |
|
m_labelDimType(Glib::ustring(_("Combine by Dimension:")) + " ", Gtk::ALIGN_END) |
787 |
{ |
{ |
788 |
|
if (!Settings::singleton()->autoRestoreWindowDimension) { |
789 |
|
set_default_size(500, 600); |
790 |
|
set_position(Gtk::WIN_POS_MOUSE); |
791 |
|
} |
792 |
|
|
793 |
|
m_scrolledWindow.add(m_treeView); |
794 |
|
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
795 |
|
|
796 |
get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK); |
797 |
get_vbox()->pack_start(m_treeView); |
get_vbox()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK); |
798 |
|
get_vbox()->pack_start(m_scrolledWindow); |
799 |
get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK); |
800 |
|
|
801 |
#if GTKMM_MAJOR_VERSION >= 3 |
#if GTKMM_MAJOR_VERSION >= 3 |
802 |
description.set_line_wrap(); |
m_descriptionLabel.set_line_wrap(); |
803 |
#endif |
#endif |
804 |
m_descriptionLabel.set_text(_( |
m_descriptionLabel.set_text(_( |
805 |
"Select at least two instruments below that shall be combined " |
"Select at least two instruments below that shall be combined (as " |
806 |
"as layers (using a \"Layer\" dimension) to a new instrument. The " |
"separate dimension zones of the selected dimension type) as a new " |
807 |
"original instruments remain untouched.") |
"instrument. The original instruments remain untouched.\n\n" |
808 |
); |
"You may use this tool for example to combine solo instruments into " |
809 |
|
"a combi sound arrangement by selecting the 'layer' dimension, or you " |
810 |
|
"might combine similar sounding solo sounds into separate velocity " |
811 |
|
"split layers by using the 'velocity' dimension, and so on." |
812 |
|
)); |
813 |
|
|
814 |
|
// add dimension type combo box |
815 |
|
{ |
816 |
|
int iLayerDimIndex = -1; |
817 |
|
Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(m_comboDimsModel); |
818 |
|
for (int i = 0x01, iRow = 0; i < 0xff; i++) { |
819 |
|
Glib::ustring sType = |
820 |
|
dimTypeAsString(static_cast<gig::dimension_t>(i)); |
821 |
|
if (sType.find("Unknown") != 0) { |
822 |
|
Gtk::TreeModel::Row row = *(refComboModel->append()); |
823 |
|
row[m_comboDimsModel.m_type_id] = i; |
824 |
|
row[m_comboDimsModel.m_type_name] = sType; |
825 |
|
if (i == gig::dimension_layer) iLayerDimIndex = iRow; |
826 |
|
iRow++; |
827 |
|
} |
828 |
|
} |
829 |
|
m_comboDimType.set_model(refComboModel); |
830 |
|
m_comboDimType.pack_start(m_comboDimsModel.m_type_id); |
831 |
|
m_comboDimType.pack_start(m_comboDimsModel.m_type_name); |
832 |
|
m_tableDimCombo.attach(m_labelDimType, 0, 1, 0, 1); |
833 |
|
m_tableDimCombo.attach(m_comboDimType, 1, 2, 0, 1); |
834 |
|
m_comboDimType.set_active(iLayerDimIndex); // preselect "layer" dimension |
835 |
|
} |
836 |
|
|
837 |
m_refTreeModel = Gtk::ListStore::create(m_columns); |
m_refTreeModel = Gtk::ListStore::create(m_columns); |
838 |
m_treeView.set_model(m_refTreeModel); |
m_treeView.set_model(m_refTreeModel); |
839 |
//m_treeView.set_tooltip_text(_("asdf")); |
m_treeView.set_tooltip_text(_( |
840 |
m_treeView.append_column("Instrument", m_columns.m_col_name); |
"Use SHIFT + left click or CTRL + left click to select the instruments " |
841 |
m_treeView.set_headers_visible(false); |
"you want to combine." |
842 |
|
)); |
843 |
|
m_treeView.append_column(_("Nr"), m_columns.m_col_index); |
844 |
|
m_treeView.append_column(_("Instrument"), m_columns.m_col_name); |
845 |
|
m_treeView.set_headers_visible(true); |
846 |
m_treeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
m_treeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
847 |
m_treeView.get_selection()->signal_changed().connect( |
m_treeView.get_selection()->signal_changed().connect( |
848 |
sigc::mem_fun(*this, &CombineInstrumentsDialog::onSelectionChanged) |
sigc::mem_fun(*this, &CombineInstrumentsDialog::onSelectionChanged) |
867 |
Glib::ustring name(gig_to_utf8(instr->pInfo->Name)); |
Glib::ustring name(gig_to_utf8(instr->pInfo->Name)); |
868 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
869 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
870 |
|
row[m_columns.m_col_index] = i; |
871 |
row[m_columns.m_col_name] = name; |
row[m_columns.m_col_name] = name; |
872 |
row[m_columns.m_col_instr] = instr; |
row[m_columns.m_col_instr] = instr; |
873 |
} |
} |
891 |
); |
); |
892 |
|
|
893 |
show_all_children(); |
show_all_children(); |
894 |
|
|
895 |
|
// show a warning to user if he uses a .gig in v2 format |
896 |
|
if (gig->pVersion->major < 3) { |
897 |
|
Glib::ustring txt = _( |
898 |
|
"You are currently using a .gig file in old v2 format. The current " |
899 |
|
"combine algorithm will most probably fail trying to combine " |
900 |
|
"instruments in this old format. So better save the file in new v3 " |
901 |
|
"format before trying to combine your instruments." |
902 |
|
); |
903 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_WARNING); |
904 |
|
msg.run(); |
905 |
|
} |
906 |
|
} |
907 |
|
|
908 |
|
void CombineInstrumentsDialog::setSelectedInstruments(const std::set<int>& instrumentIndeces) { |
909 |
|
typedef Gtk::TreeModel::Children Children; |
910 |
|
Children children = m_refTreeModel->children(); |
911 |
|
for (Children::iterator iter = children.begin(); |
912 |
|
iter != children.end(); ++iter) |
913 |
|
{ |
914 |
|
Gtk::TreeModel::Row row = *iter; |
915 |
|
int index = row[m_columns.m_col_index]; |
916 |
|
if (instrumentIndeces.count(index)) |
917 |
|
m_treeView.get_selection()->select(iter); |
918 |
|
} |
919 |
} |
} |
920 |
|
|
921 |
void CombineInstrumentsDialog::combineSelectedInstruments() { |
void CombineInstrumentsDialog::combineSelectedInstruments() { |
932 |
instruments.push_back(instrument); |
instruments.push_back(instrument); |
933 |
} |
} |
934 |
|
|
935 |
|
g_warnings.clear(); |
936 |
|
|
937 |
try { |
try { |
938 |
combineInstruments(instruments, m_gig, m_newCombinedInstrument); |
// which main dimension was selected in the combo box? |
939 |
|
gig::dimension_t mainDimension; |
940 |
|
{ |
941 |
|
Gtk::TreeModel::iterator iterType = m_comboDimType.get_active(); |
942 |
|
if (!iterType) throw gig::Exception("No dimension selected"); |
943 |
|
Gtk::TreeModel::Row rowType = *iterType; |
944 |
|
if (!rowType) throw gig::Exception("Something is wrong regarding dimension selection"); |
945 |
|
int iTypeID = rowType[m_comboDimsModel.m_type_id]; |
946 |
|
mainDimension = static_cast<gig::dimension_t>(iTypeID); |
947 |
|
} |
948 |
|
|
949 |
|
// now start the actual cobination task ... |
950 |
|
combineInstruments(instruments, m_gig, m_newCombinedInstrument, mainDimension); |
951 |
} catch (RIFF::Exception e) {; |
} catch (RIFF::Exception e) {; |
952 |
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
953 |
msg.run(); |
msg.run(); |
954 |
return; |
return; |
955 |
|
} catch (...) { |
956 |
|
Glib::ustring txt = _("An unknown exception occurred!"); |
957 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
958 |
|
msg.run(); |
959 |
|
return; |
960 |
|
} |
961 |
|
|
962 |
|
if (!g_warnings.empty()) { |
963 |
|
Glib::ustring txt = _( |
964 |
|
"Combined instrument was created successfully, but there were warnings:" |
965 |
|
); |
966 |
|
txt += "\n\n"; |
967 |
|
for (Warnings::const_iterator itWarn = g_warnings.begin(); |
968 |
|
itWarn != g_warnings.end(); ++itWarn) |
969 |
|
{ |
970 |
|
txt += "-> " + *itWarn + "\n"; |
971 |
|
} |
972 |
|
txt += "\n"; |
973 |
|
txt += _( |
974 |
|
"You might also want to check the console for further warnings and " |
975 |
|
"error messages." |
976 |
|
); |
977 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_WARNING); |
978 |
|
msg.run(); |
979 |
} |
} |
980 |
|
|
981 |
// no error occurred |
// no error occurred |