0.40.0 (75): Sampler One-shot (Android and iOS)
- Sampler parameter oneShot (Off/On): note-offs don't release its pads; they play their whole slice. Transport stop/pause still releases (SampleVoice:: release), panic kills - Engine in core/ and the Kotlin reference both implement it; the golden Sampler "high" scenario covers it; oneshot_test checks MIDI, song, stop, panic - ONE-SHOT toggle in both apps' Sampler editors; specs and layouts regenerated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5240019b47
commit
7041f762e5
@@ -855,6 +855,7 @@ void Engine::Impl::playNote(Project &proj, int bus, int note, int velocity, int
|
||||
v.ownerTrack = ownerTrack;
|
||||
v.noteOn(*vs.sample, note, velocity, vs.root, vs.sliceStart, vs.sliceEnd, vs.volume,
|
||||
vs.attack, vs.decay, vs.sustain, vs.release, vs.loop, vs.crossfadeMs);
|
||||
v.oneShot = vs.oneShot;
|
||||
} else if (!hasType(slot) || is(slot, "SAMPLER")) {
|
||||
// Empty bus or a Sampler with an empty pad: silent.
|
||||
} else if (is(slot, "GRAIN_CLOUD")) {
|
||||
@@ -926,6 +927,7 @@ void Engine::Impl::auditionSlotOn(int slotIndex, int midi) {
|
||||
if (!v) { v = auditionSampleVoices[0].get(); v->kill(); }
|
||||
v->noteOn(*vs.sample, midi, 110, vs.root, vs.sliceStart, vs.sliceEnd, vs.volume,
|
||||
vs.attack, vs.decay, vs.sustain, vs.release, vs.loop, vs.crossfadeMs);
|
||||
v->oneShot = vs.oneShot;
|
||||
return;
|
||||
}
|
||||
if (is(slot, "SAMPLER")) return;
|
||||
@@ -972,6 +974,7 @@ void Engine::Impl::busNoteOn(int midiChannel, int midi, int velocity) {
|
||||
if (!v) { v = busSampleVoices[base].get(); v->kill(); }
|
||||
v->noteOn(*vs.sample, midi, velocity, vs.root, vs.sliceStart, vs.sliceEnd, vs.volume,
|
||||
vs.attack, vs.decay, vs.sustain, vs.release, vs.loop, vs.crossfadeMs);
|
||||
v->oneShot = vs.oneShot;
|
||||
} else if (is(slot, "SAMPLER")) {
|
||||
} else if (is(slot, "GRAIN_CLOUD")) {
|
||||
clouds[ch]->noteOn(midi, velocity, GrainCloud::OWNER_LIVE);
|
||||
@@ -1146,7 +1149,7 @@ void Engine::Impl::refreshSynthPatches(Project &proj) {
|
||||
void Engine::Impl::allSeqVoicesOff() {
|
||||
for (auto &c : clouds) c->releaseSequenced();
|
||||
for (auto &v : seqVoices) v->noteOff();
|
||||
for (auto &v : sampleVoices) v->noteOff();
|
||||
for (auto &v : sampleVoices) v->release(); // a stopped song stops One-shot pads too
|
||||
for (auto &a : arps) a.stop();
|
||||
allMidiNotesOff();
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ bool voiceSample(const char *type, const Params &slot, const SampleStore &store,
|
||||
out.sliceStart = slot.f(SamplerPads::sliceStartKey(pad).s, 0.f);
|
||||
out.sliceEnd = slot.f(SamplerPads::sliceEndKey(pad).s, 1.f);
|
||||
out.volume = slot.f(SamplerPads::volumeKey(pad).s, SamplerPads::DEFAULT_VOLUME);
|
||||
out.oneShot = std::strcmp(slot.s("oneShot", "Off"), "On") == 0;
|
||||
return true;
|
||||
}
|
||||
if (std::strcmp(type, "SOUNDFONT") == 0) {
|
||||
@@ -93,6 +94,7 @@ void SampleVoice::noteOn(const Sample &s, int midi, int velocity, int root,
|
||||
const int len = (int)s.data.size();
|
||||
// An empty sample would make Kotlin's coerceIn(startIndex + 1, 0) throw; play nothing.
|
||||
if (len <= 0) return;
|
||||
oneShot = false; // the caller sets it again for a One-shot Sampler
|
||||
// Carry the level we're interrupting so the new note starts continuously.
|
||||
declick += lastY;
|
||||
setSample(&s);
|
||||
@@ -142,7 +144,7 @@ void SampleVoice::noteOn(const Sample &s, int midi, int velocity, int root,
|
||||
endGain = 1.f;
|
||||
}
|
||||
|
||||
void SampleVoice::noteOff() {
|
||||
void SampleVoice::release() {
|
||||
const float sr = (float)engineSampleRate;
|
||||
releaseInc = releaseSeconds <= 0.f ? 1.f : env / (releaseSeconds * sr);
|
||||
if (releaseInc <= 0.f) releaseInc = 1.f;
|
||||
|
||||
@@ -54,6 +54,8 @@ struct VoiceSample {
|
||||
float sustain = 1.f, release = 0.02f;
|
||||
bool loop = false;
|
||||
float crossfadeMs = 0.f;
|
||||
/** A Sampler with One-shot on: note-offs don't release the voice. */
|
||||
bool oneShot = false;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -83,6 +85,9 @@ public:
|
||||
int pitch = -1;
|
||||
/** Which tracker (lane,track) started this voice, or -1 if unowned. */
|
||||
int ownerTrack = -1;
|
||||
/** Playing a One-shot Sampler pad: noteOff() leaves it be, it plays to its slice
|
||||
* end; release() (transport stop / pause) still fades it. Reset by noteOn. */
|
||||
bool oneShot = false;
|
||||
|
||||
bool isActive() const { return sample != nullptr; }
|
||||
/** Note is still held (not in its release stage). */
|
||||
@@ -98,11 +103,16 @@ public:
|
||||
float attack = 0.002f, float decay = 0.f, float sustain = 1.f, float release = 0.02f,
|
||||
bool loop = false, float crossfadeMs = 0.f);
|
||||
void noteOn(const VoiceSample &v, int midi, int velocity) {
|
||||
if (v.sample) noteOn(*v.sample, midi, velocity, v.root, v.sliceStart, v.sliceEnd, v.volume,
|
||||
v.attack, v.decay, v.sustain, v.release, v.loop, v.crossfadeMs);
|
||||
if (!v.sample) return;
|
||||
noteOn(*v.sample, midi, velocity, v.root, v.sliceStart, v.sliceEnd, v.volume,
|
||||
v.attack, v.decay, v.sustain, v.release, v.loop, v.crossfadeMs);
|
||||
oneShot = v.oneShot;
|
||||
}
|
||||
/** Enter the release stage: fade from the current level to 0 over the release time. */
|
||||
void noteOff();
|
||||
/** A note-off: enter the release stage (fade from the current level to 0 over
|
||||
* the release time), unless the voice is one-shot. */
|
||||
void noteOff() { if (!oneShot) release(); }
|
||||
/** Enter the release stage whatever the note (transport stop / pause). */
|
||||
void release();
|
||||
void kill();
|
||||
float render();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user