Set the pitch key center from sample
This commit is contained in:
parent
dc7b42fc43
commit
3b3f6d2731
5 changed files with 18 additions and 4 deletions
|
|
@ -216,14 +216,15 @@ absl::optional<sfz::FileInformation> sfz::FilePool::getFileInformation(const Fil
|
||||||
returnedValue.numChannels = reader->channels();
|
returnedValue.numChannels = reader->channels();
|
||||||
|
|
||||||
SF_INSTRUMENT instrumentInfo {};
|
SF_INSTRUMENT instrumentInfo {};
|
||||||
|
bool haveInstrumentInfo = reader->getInstrument(&instrumentInfo);
|
||||||
|
|
||||||
FileMetadataReader mdReader;
|
FileMetadataReader mdReader;
|
||||||
bool mdReaderOpened = mdReader.open(file);
|
bool mdReaderOpened = mdReader.open(file);
|
||||||
|
|
||||||
if (!reader->getInstrument(&instrumentInfo)) {
|
if (!haveInstrumentInfo) {
|
||||||
// if no instrument, then try extracting from embedded RIFF chunks (flac)
|
// if no instrument, then try extracting from embedded RIFF chunks (flac)
|
||||||
if (mdReaderOpened)
|
if (mdReaderOpened)
|
||||||
mdReader.extractRiffInstrument(instrumentInfo);
|
haveInstrumentInfo = mdReader.extractRiffInstrument(instrumentInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mdReaderOpened) {
|
if (mdReaderOpened) {
|
||||||
|
|
@ -233,7 +234,7 @@ absl::optional<sfz::FileInformation> sfz::FilePool::getFileInformation(const Fil
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileId.isReverse()) {
|
if (!fileId.isReverse()) {
|
||||||
if (instrumentInfo.loop_count > 0) {
|
if (haveInstrumentInfo && instrumentInfo.loop_count > 0) {
|
||||||
returnedValue.hasLoop = true;
|
returnedValue.hasLoop = true;
|
||||||
returnedValue.loopBegin = instrumentInfo.loops[0].start;
|
returnedValue.loopBegin = instrumentInfo.loops[0].start;
|
||||||
returnedValue.loopEnd = min(returnedValue.end, instrumentInfo.loops[0].end - 1);
|
returnedValue.loopEnd = min(returnedValue.end, instrumentInfo.loops[0].end - 1);
|
||||||
|
|
@ -243,6 +244,9 @@ absl::optional<sfz::FileInformation> sfz::FilePool::getFileInformation(const Fil
|
||||||
// prehaps it can make use of SF_LOOP_BACKWARD?
|
// prehaps it can make use of SF_LOOP_BACKWARD?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (haveInstrumentInfo)
|
||||||
|
returnedValue.rootKey = clamp<int8_t>(instrumentInfo.basenote, 0, 127);
|
||||||
|
|
||||||
return returnedValue;
|
return returnedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ struct FileInformation {
|
||||||
bool hasLoop { false };
|
bool hasLoop { false };
|
||||||
double sampleRate { config::defaultSampleRate };
|
double sampleRate { config::defaultSampleRate };
|
||||||
int numChannels { 0 };
|
int numChannels { 0 };
|
||||||
|
int rootKey { 0 };
|
||||||
absl::optional<WavetableInfo> wavetable;
|
absl::optional<WavetableInfo> wavetable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -779,7 +779,12 @@ bool sfz::Region::parseOpcode(const Opcode& rawOpcode)
|
||||||
|
|
||||||
// Performance parameters: pitch
|
// Performance parameters: pitch
|
||||||
case hash("pitch_keycenter"):
|
case hash("pitch_keycenter"):
|
||||||
setValueFromOpcode(opcode, pitchKeycenter, Default::keyRange);
|
if (opcode.value == "sample")
|
||||||
|
pitchKeycenterFromSample = true;
|
||||||
|
else {
|
||||||
|
pitchKeycenterFromSample = false;
|
||||||
|
setValueFromOpcode(opcode, pitchKeycenter, Default::keyRange);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case hash("pitch_keytrack"):
|
case hash("pitch_keytrack"):
|
||||||
setValueFromOpcode(opcode, pitchKeytrack, Default::pitchKeytrackRange);
|
setValueFromOpcode(opcode, pitchKeytrack, Default::pitchKeytrackRange);
|
||||||
|
|
|
||||||
|
|
@ -382,6 +382,7 @@ struct Region {
|
||||||
|
|
||||||
// Performance parameters: pitch
|
// Performance parameters: pitch
|
||||||
uint8_t pitchKeycenter { Default::pitchKeycenter }; // pitch_keycenter
|
uint8_t pitchKeycenter { Default::pitchKeycenter }; // pitch_keycenter
|
||||||
|
bool pitchKeycenterFromSample { false };
|
||||||
int pitchKeytrack { Default::pitchKeytrack }; // pitch_keytrack
|
int pitchKeytrack { Default::pitchKeytrack }; // pitch_keytrack
|
||||||
int pitchRandom { Default::pitchRandom }; // pitch_random
|
int pitchRandom { Default::pitchRandom }; // pitch_random
|
||||||
int pitchVeltrack { Default::pitchVeltrack }; // pitch_veltrack
|
int pitchVeltrack { Default::pitchVeltrack }; // pitch_veltrack
|
||||||
|
|
|
||||||
|
|
@ -536,6 +536,9 @@ void sfz::Synth::finalizeSfzLoad()
|
||||||
if (fileInformation->numChannels == 2)
|
if (fileInformation->numChannels == 2)
|
||||||
region->hasStereoSample = true;
|
region->hasStereoSample = true;
|
||||||
|
|
||||||
|
if (region->pitchKeycenterFromSample)
|
||||||
|
region->pitchKeycenter = fileInformation->rootKey;
|
||||||
|
|
||||||
// TODO: adjust with LFO targets
|
// TODO: adjust with LFO targets
|
||||||
const auto maxOffset = [region]() {
|
const auto maxOffset = [region]() {
|
||||||
uint64_t sumOffsetCC = region->offset + region->offsetRandom;
|
uint64_t sumOffsetCC = region->offset + region->offsetRandom;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue