Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add start offset multiplier #680

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion hi_core/hi_sampler/sampler/ModulatorSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ void ModulatorSampler::preStartVoice(int voiceIndex, const HiseEvent& e)
else
{
// hack: the sample start value is normalized so we need to just flip the sign in order to tell startVoice to use a direct sample value
sampleStartModValue = -1.0f * static_cast<ModulatorSynthVoice*>(getVoice(voiceIndex))->getCurrentHiseEvent().getStartOffset();
sampleStartModValue = -1.0f * static_cast<ModulatorSynthVoice*>(getVoice(voiceIndex))->getCurrentHiseEvent().getStartOffset() * startOffsetMultiplier;
samplerDisplayValues.currentSampleStartPos = 0.0f;
}

Expand Down Expand Up @@ -1778,6 +1778,11 @@ bool ModulatorSampler::setCurrentGroupIndex(int currentIndex, int eventId)
}
}

void ModulatorSampler::setStartOffsetMultiplier(int multiplier)
{
startOffsetMultiplier = multiplier;
}

void ModulatorSampler::setRRGroupVolume(int groupIndex, float gainValue)
{
if (groupIndex == -1)
Expand Down
3 changes: 2 additions & 1 deletion hi_core/hi_sampler/sampler/ModulatorSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class ModulatorSampler: public ModulatorSynth,
/** Sets the current index to the group. */
bool setCurrentGroupIndex(int currentIndex, int eventId=-1);


void setStartOffsetMultiplier(int multiplier);

void setRRGroupVolume(int groupIndex, float gainValue);

Expand Down Expand Up @@ -758,6 +758,7 @@ class ModulatorSampler: public ModulatorSynth,
TimestretchOptions currentTimestretchOptions;

double ratioToUse = 1.0;
int startOffsetMultiplier = 1;

TimestretchOptions timestretchOptions;

Expand Down
14 changes: 13 additions & 1 deletion hi_scripting/scripting/api/ScriptingApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ void ScriptingApi::Message::setStartOffset(int newStartOffset)
}

if (newStartOffset > UINT16_MAX)
reportScriptError("Max start offset is 65536 (2^16)");
reportScriptError("Max start offset is 65535 (2^16-1)");

#endif

Expand Down Expand Up @@ -3764,6 +3764,7 @@ struct ScriptingApi::Sampler::Wrapper
API_METHOD_WRAPPER_2(Sampler, setAllowReleaseStart);
API_VOID_METHOD_WRAPPER_2(Sampler, setGUISelection);
API_VOID_METHOD_WRAPPER_1(Sampler, setSortByRRGroup);
API_VOID_METHOD_WRAPPER_1(Sampler, setOffsetMultiplier);
};


Expand Down Expand Up @@ -3826,6 +3827,7 @@ sampler(sampler_)
ADD_API_METHOD_0(getTimestretchOptions);
ADD_API_METHOD_0(getReleaseStartOptions);
ADD_API_METHOD_1(setReleaseStartOptions);
ADD_API_METHOD_1(setOffsetMultiplier);

sampleIds = SampleIds::Helpers::getAllIds();

Expand Down Expand Up @@ -4751,6 +4753,16 @@ void ScriptingApi::Sampler::setReleaseStartOptions(var data)
#endif
}

void ScriptingApi::Sampler::setOffsetMultiplier(int multiplier)
{
ModulatorSampler* s = dynamic_cast<ModulatorSampler*>(sampler.get());

if (s == nullptr)
reportScriptError("Invalid sampler call");

s->setStartOffsetMultiplier(multiplier);
}

String ScriptingApi::Sampler::getAudioWaveformContentAsBase64(var presetObj)
{
auto fileName = presetObj.getProperty("data", "").toString();
Expand Down
3 changes: 3 additions & 0 deletions hi_scripting/scripting/api/ScriptingApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,9 @@ class ScriptingApi

/** Sets the options for the release start behaviour. */
void setReleaseStartOptions(var newOptions);

/** Internally multiply sample start offsets by set amount */
void setOffsetMultiplier(int multiplier);

/** Converts the user preset data of a audio waveform to a base 64 samplemap. */
String getAudioWaveformContentAsBase64(var presetObj);
Expand Down