59 |
cout << endl; |
cout << endl; |
60 |
cout << " --force-replace Replace all old mono references by the new stereo ones." << endl; |
cout << " --force-replace Replace all old mono references by the new stereo ones." << endl; |
61 |
cout << endl; |
cout << endl; |
62 |
|
cout << " --incompatible Also match sample pairs that seem to be incompatible." << endl; |
63 |
|
cout << endl; |
64 |
cout << " --keep Keep orphaned mono samples after conversion." << endl; |
cout << " --keep Keep orphaned mono samples after conversion." << endl; |
65 |
cout << endl; |
cout << endl; |
66 |
cout << " -r Recurse through subdirectories." << endl; |
cout << " -r Recurse through subdirectories." << endl; |
176 |
return s; |
return s; |
177 |
} |
} |
178 |
|
|
179 |
|
#define OPTIONAL_SKIP_CHECK() \ |
180 |
|
if (skipIncompatible) { \ |
181 |
|
cerr << " Skipping!\n"; \ |
182 |
|
continue; /* skip to convert this sample pair */ \ |
183 |
|
} else { \ |
184 |
|
cerr << " Merging anyway (upon request)!\n"; \ |
185 |
|
} |
186 |
|
|
187 |
/** |
/** |
188 |
* Converts .gig file given by @a path towards using true stereo interleaved |
* Converts .gig file given by @a path towards using true stereo interleaved |
189 |
* samples. |
* samples. |
198 |
* mono, not stereo. By enabling this argument all those |
* mono, not stereo. By enabling this argument all those |
199 |
* old references will be replaced by the new stereo |
* old references will be replaced by the new stereo |
200 |
* sample reference instead as well. |
* sample reference instead as well. |
201 |
|
* @param matchIncompatible - if set to true, only mono sample pairs will be |
202 |
|
* qualified to be merged to true stereo samples if |
203 |
|
* their main sample characteristics match, if set |
204 |
|
* to true this sanity check will be skipped |
205 |
* @param verbosity - verbosity level, defines whether and how much additional |
* @param verbosity - verbosity level, defines whether and how much additional |
206 |
* informations to be printed to the console while doing the |
* informations to be printed to the console while doing the |
207 |
* conversion (0 .. 2) |
* conversion (0 .. 2) |
208 |
*/ |
*/ |
209 |
static bool convertFileToStereo(const string path, bool keep, bool forceReplace, int verbose) { |
static bool convertFileToStereo(const string path, bool keep, bool forceReplace, bool skipIncompatible, int verbose) { |
210 |
try { |
try { |
211 |
// open .gig file |
// open .gig file |
212 |
RIFF::File riff(path); |
RIFF::File riff(path); |
230 |
if (!rgn->pDimensionRegions[dr]->pSample) continue; // no sample assigned, ignore |
if (!rgn->pDimensionRegions[dr]->pSample) continue; // no sample assigned, ignore |
231 |
if (rgn->pDimensionRegions[dr]->pSample->Channels != 1) continue; // seems already to be a true stereo sample, ignore |
if (rgn->pDimensionRegions[dr]->pSample->Channels != 1) continue; // seems already to be a true stereo sample, ignore |
232 |
|
|
233 |
const int channel = (dr & ~(1 << bits)) ? 1 : 0; |
const int channel = (dr & (1 << bits)) ? 1 : 0; |
234 |
if (channel == 1) continue; // ignore right audio channel dimension region here |
if (channel == 1) continue; // ignore right audio channel dimension region here |
235 |
|
|
236 |
// so current dimension region is for left channel, so now get its matching right channel dimension region ... |
// so current dimension region is for left channel, so now get its matching right channel dimension region ... |
296 |
// bunch of sanity checks which ensure that both mono samples are |
// bunch of sanity checks which ensure that both mono samples are |
297 |
// using the same base parameter characteristics |
// using the same base parameter characteristics |
298 |
if (pSampleL->SamplesPerSecond != pSampleR->SamplesPerSecond) { |
if (pSampleL->SamplesPerSecond != pSampleR->SamplesPerSecond) { |
299 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different sample rate!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different sample rate! Skipping!\n"; |
300 |
continue; // skip to convert this sample pair |
continue; |
301 |
} |
} |
302 |
if (pSampleL->FrameSize != pSampleR->FrameSize) { |
if (pSampleL->FrameSize != pSampleR->FrameSize) { |
303 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different frame size!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different frame size! Skipping!\n"; |
304 |
continue; // skip to convert this sample pair |
continue; |
305 |
} |
} |
306 |
if (pSampleL->MIDIUnityNote != pSampleR->MIDIUnityNote) { |
if (pSampleL->MIDIUnityNote != pSampleR->MIDIUnityNote) { |
307 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different unity notes!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different unity notes!"; |
308 |
continue; // skip to convert this sample pair |
OPTIONAL_SKIP_CHECK(); |
309 |
} |
} |
310 |
if (pSampleL->FineTune != pSampleR->FineTune) { |
if (pSampleL->FineTune != pSampleR->FineTune) { |
311 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different fine tune!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different fine tune!"; |
312 |
continue; // skip to convert this sample pair |
OPTIONAL_SKIP_CHECK(); |
313 |
} |
} |
314 |
if (pSampleL->Loops != pSampleR->Loops) { |
if (pSampleL->Loops != pSampleR->Loops) { |
315 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop amount!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop amount! Skipping!\n"; |
316 |
continue; // skip to convert this sample pair |
continue; // skip to convert this sample pair |
317 |
} |
} |
318 |
if (pSampleL->Loops == 1 && pSampleR->Loops == 1) { |
if (pSampleL->Loops == 1 && pSampleR->Loops == 1) { |
319 |
if (pSampleL->LoopType != pSampleR->LoopType) { |
if (pSampleL->LoopType != pSampleR->LoopType) { |
320 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop type!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop type!"; |
321 |
continue; // skip to convert this sample pair |
OPTIONAL_SKIP_CHECK(); |
322 |
} |
} |
323 |
if (pSampleL->LoopStart != pSampleR->LoopStart) { |
if (pSampleL->LoopStart != pSampleR->LoopStart) { |
324 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop start!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop start! Skipping!\n"; |
325 |
continue; // skip to convert this sample pair |
continue; // skip to convert this sample pair |
326 |
} |
} |
327 |
if (pSampleL->LoopEnd != pSampleR->LoopEnd) { |
if (pSampleL->LoopEnd != pSampleR->LoopEnd) { |
328 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop end!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop end! Skipping!\n"; |
329 |
continue; // skip to convert this sample pair |
continue; // skip to convert this sample pair |
330 |
} |
} |
331 |
if (pSampleL->LoopSize != pSampleR->LoopSize) { |
if (pSampleL->LoopSize != pSampleR->LoopSize) { |
332 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop size!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop size! Skipping!\n"; |
333 |
continue; // skip to convert this sample pair |
continue; // skip to convert this sample pair |
334 |
} |
} |
335 |
if (pSampleL->LoopPlayCount != pSampleR->LoopPlayCount) { |
if (pSampleL->LoopPlayCount != pSampleR->LoopPlayCount) { |
336 |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop play count!\n"; |
cerr << "WARNING: Sample pair ['" << pSampleL->pInfo->Name << "', '" << pSampleR->pInfo->Name << "'] with different loop play count!"; |
337 |
continue; // skip to convert this sample pair |
OPTIONAL_SKIP_CHECK(); |
338 |
} |
} |
339 |
} |
} |
340 |
|
|
578 |
bool bOptionRecurse = false; |
bool bOptionRecurse = false; |
579 |
bool bOptionKeep = false; |
bool bOptionKeep = false; |
580 |
bool bOptionForceReplace = false; |
bool bOptionForceReplace = false; |
581 |
|
bool bOptionMatchIncompatible = false; |
582 |
int iVerbose = 0; |
int iVerbose = 0; |
583 |
|
|
584 |
// validate & parse arguments provided to this program |
// validate & parse arguments provided to this program |
606 |
} else if (opt == "--force-replace") { |
} else if (opt == "--force-replace") { |
607 |
nOptions++; |
nOptions++; |
608 |
bOptionForceReplace = true; |
bOptionForceReplace = true; |
609 |
|
} else if (opt == "--incompatible") { |
610 |
|
nOptions++; |
611 |
|
bOptionMatchIncompatible = true; |
612 |
} else if (opt == "--verbose") { |
} else if (opt == "--verbose") { |
613 |
nOptions++; |
nOptions++; |
614 |
iVerbose = 1; |
iVerbose = 1; |
657 |
for (set<string>::const_iterator it = g_files.begin(); it != g_files.end(); ++it, ++i) { |
for (set<string>::const_iterator it = g_files.begin(); it != g_files.end(); ++it, ++i) { |
658 |
cout << "Converting file " << (i+1) << "/" << int(g_files.size()) << ": " << *it << " ... " << flush; |
cout << "Converting file " << (i+1) << "/" << int(g_files.size()) << ": " << *it << " ... " << flush; |
659 |
if (iVerbose) cout << endl; |
if (iVerbose) cout << endl; |
660 |
bool bSuccess = convertFileToStereo(*it, bOptionKeep, bOptionForceReplace, iVerbose); |
bool bSuccess = convertFileToStereo( |
661 |
|
*it, bOptionKeep, bOptionForceReplace, !bOptionMatchIncompatible, |
662 |
|
iVerbose |
663 |
|
); |
664 |
if (!bSuccess) return EXIT_FAILURE; |
if (!bSuccess) return EXIT_FAILURE; |
665 |
cout << "OK" << endl; |
cout << "OK" << endl; |
666 |
} |
} |