Skip to content

Commit d9a2fd4

Browse files
committed
one shot fade ms
2 parents 4d1108e + 0aa81c9 commit d9a2fd4

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎Source/Node/Connection/NodeConnectionManager.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ NodeConnection* NodeConnectionManager::addItemFromData(var data, bool addToUndo)
106106
Array<NodeConnection*> NodeConnectionManager::addItemsFromData(var data, bool addToUndo)
107107
{
108108
Array<NodeConnection*> itemsToAdd;
109-
109+
110110
for (int i = 0; i < data.size(); i++)
111111
{
112112
NodeConnection::ConnectionType t = (NodeConnection::ConnectionType)(int)data[i].getProperty("connectionType", NodeConnection::AUDIO);

‎Source/Node/nodes/sampler/SamplerNode.cpp‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ SamplerNode::SamplerNode(var params) :
3737
hitMode = playCC.addEnumParameter("Hit Mode", "How playing a sample is handled.\nPiano is normal playing, releasing a key stops the sample.\nHit is starting the sample but releasing doesn't affect (only works in One Shot play mode) Full will not take in account playing again the note if the sample is still playing. Reset will allow to replay from start.\nToggle is alternating key presses to start/stop instead of using key release");
3838
hitMode->addOption("Piano", PIANO)->addOption("Hit (Full Sample)", HIT_FULL)->addOption("Hit (Reset)", HIT_RESET)->addOption("Toggle", TOGGLE);
3939

40+
oneShotFadeTimeMS = playCC.addIntParameter("One Shot Fade MS", "Fade applied to the end of a hit/one shot sample (ms)", 10, 0, 1000);
41+
4042
autoKeyLiveMode = playCC.addBoolParameter("Auto Key", "If checked, hitting an unrecorded note will play it repitched from the closest found", false);
4143
autoKeyFadeTimeMS = playCC.addIntParameter("Auto Key Fade", "Fade for anticlick when repitching auto keys, in milliseconds", 50);
4244
autoKeyMode = playCC.addEnumParameter("Auto Key Algorithm", "Algorithm used to pitch-shift when computing auto keys.\nResample: clean, no wobble, slight formant shift.\nRubberBand: phase vocoder, preserves formants, may wobble on tonal sounds.");
@@ -49,7 +51,7 @@ SamplerNode::SamplerNode(var params) :
4951
rbPitchMode->addOption("High Quality", RB_PITCH_HQ)->addOption("High Consistency", RB_PITCH_CONSISTENT);
5052

5153
rbTransients = playCC.addEnumParameter("RB Transients", "Transient handling");
52-
rbTransients->addOption("Crisp", RB_TRANS_CRISP)->addOption("Mixed", RB_TRANS_MIXED)->addOption("Smooth", RB_TRANS_SMOOTH);
54+
rbTransients->addOption("Crisp", RB_TRANS_CRISP)->addOption("Mixed", RB_TRANS_SMOOTH)->addOption("Smooth", RB_TRANS_SMOOTH);
5355

5456
rbWindowSize = playCC.addEnumParameter("RB Window", "FFT Window Size");
5557
rbWindowSize->addOption("Standard", RB_WIN_STANDARD)->addOption("Short", RB_WIN_SHORT)->addOption("Long", RB_WIN_LONG);
@@ -936,12 +938,23 @@ void SamplerNode::processBlockInternal(AudioBuffer<float>& buffer, MidiBuffer& m
936938
if (pm == HIT_ONESHOT || s->isProxyNote())
937939
{
938940
if (firstPart > 0)
939-
tmpNoteBuffer.copyFrom(j, 0, *targetBuffer, j, targetReadSample, firstPart);
940-
941-
if (secondPart > 0 && firstPart > 0)
942941
{
943-
const int fadeLen = jmin(64, firstPart);
944-
tmpNoteBuffer.applyGainRamp(j, firstPart - fadeLen, fadeLen, 1.0f, 0.0f);
942+
tmpNoteBuffer.copyFrom(j, 0, *targetBuffer, j, targetReadSample, firstPart);
943+
944+
int fadeSamples = (int)(AudioManager::getInstance()->currentSampleRate * oneShotFadeTimeMS->intValue() / 1000.0f);
945+
if (fadeSamples > 0)
946+
{
947+
int fadeStartSample = jmax(0, targetBuffer->getNumSamples() - fadeSamples);
948+
float startGain = targetReadSample < fadeStartSample ? 1.0f : jmax(0.0f, 1.0f - (targetReadSample - fadeStartSample) / (float)fadeSamples);
949+
float endGain = (targetReadSample + firstPart) < fadeStartSample ? 1.0f : jmax(0.0f, 1.0f - (targetReadSample + firstPart - fadeStartSample) / (float)fadeSamples);
950+
951+
tmpNoteBuffer.applyGainRamp(j, 0, firstPart, startGain, endGain);
952+
}
953+
else if (secondPart > 0)
954+
{
955+
const int fadeLen = jmin(64, firstPart);
956+
tmpNoteBuffer.applyGainRamp(j, firstPart - fadeLen, fadeLen, 1.0f, 0.0f);
957+
}
945958
}
946959
}
947960
else

‎Source/Node/nodes/sampler/SamplerNode.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SamplerNode :
3333
BoolParameter* monitor;
3434
EnumParameter* playMode;
3535
EnumParameter* hitMode;
36+
IntParameter* oneShotFadeTimeMS;
3637
BoolParameter* autoKeyLiveMode;
3738
IntParameter* autoKeyFadeTimeMS;
3839
EnumParameter* autoKeyMode;

0 commit comments

Comments
 (0)