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
@@ -86,6 +86,7 @@ class SampleVoice(private val engineSampleRate: Int) {
|
||||
attack: Float = 0.002f, decay: Float = 0f, sustain: Float = 1f, release: Float = 0.02f,
|
||||
loop: Boolean = false, crossfadeMs: Float = 0f,
|
||||
) {
|
||||
oneShot = false // the caller sets it again for a One-shot Sampler
|
||||
// Carry the level we're interrupting so the new note starts continuously
|
||||
// (the new note fades in from ~0; without this the sum would jump from the
|
||||
// old voice's level straight to ~0 → a click when stealing a loud voice).
|
||||
@@ -139,8 +140,15 @@ class SampleVoice(private val engineSampleRate: Int) {
|
||||
endGain = 1f
|
||||
}
|
||||
|
||||
/** Playing a One-shot Sampler pad: [noteOff] leaves it be (it plays to its slice
|
||||
* end); [release] still fades it. Reset by [noteOn]. */
|
||||
var oneShot = false
|
||||
|
||||
/** A note-off: the release stage, unless the voice is one-shot. */
|
||||
fun noteOff() { if (!oneShot) release() }
|
||||
|
||||
/** Enter the release stage: fade from the current level to 0 over the release time. */
|
||||
fun noteOff() {
|
||||
fun release() {
|
||||
val sr = engineSampleRate.toFloat()
|
||||
releaseInc = if (releaseSeconds <= 0f) 1f else env / (releaseSeconds * sr)
|
||||
if (releaseInc <= 0f) releaseInc = 1f
|
||||
|
||||
@@ -94,6 +94,10 @@ enum class ToolboxType(
|
||||
ToolboxKind.INSTRUMENT, "Sampler",
|
||||
listOf(
|
||||
ParamSpec("volume", "Volume", 0.8f, 0f, 1f),
|
||||
// On: note-offs (MIDI, the tracker's ===, a new note on the track) are
|
||||
// ignored and every pad plays its whole slice. Stop / pause / panic still
|
||||
// silence it. Played by the C++ engine (core/), not the Kotlin reference.
|
||||
ParamSpec("oneShot", "One-shot", choices = listOf("Off", "On")),
|
||||
// A 16-pad bank: each pad maps to a consecutive note from C2 (see
|
||||
// [SamplerPads]) and stores its own sample id + slice as string params
|
||||
// ("pad0", "pad0S", "pad0E", …). Edited by ui/toolbox/SamplerEditor.
|
||||
|
||||
@@ -102,6 +102,24 @@ fun SamplerEditor(vm: AppViewModel, slot: ToolboxSlot, pad: Int, onSelectPad: (I
|
||||
}
|
||||
|
||||
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
// ----- One-shot (the whole Sampler): note-offs don't cut the pads -----
|
||||
val oneShot = slot.string("oneShot", "Off") == "On"
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
RetroButton("ONE-SHOT", active = oneShot) {
|
||||
slot.set("oneShot", if (oneShot) "Off" else "On")
|
||||
vm.bumpForToolbar()
|
||||
}
|
||||
Text(
|
||||
if (oneShot) "Pads play their whole slice; note-offs are ignored."
|
||||
else "Pads stop on note-off (key release, ===).",
|
||||
color = c.textDim, fontFamily = FontFamily.Monospace, fontSize = 11.sp,
|
||||
)
|
||||
}
|
||||
|
||||
// ----- Selected pad + source buttons (act on the selected pad) -----
|
||||
Text(
|
||||
"Pad ${pad + 1} · ${Pitch.name(SamplerPads.noteFor(pad))}",
|
||||
|
||||
@@ -166,6 +166,7 @@ class IosGoldenInstruments {
|
||||
val s = SampleStore.get(slot.string(SamplerPads.key(pad))) ?: return
|
||||
v.noteOn(s, note, velocity, note, slot.float(SamplerPads.sliceStartKey(pad), 0f),
|
||||
slot.float(SamplerPads.sliceEndKey(pad), 1f), slot.float(SamplerPads.volumeKey(pad), SamplerPads.DEFAULT_VOLUME))
|
||||
v.oneShot = slot.string("oneShot", "Off") == "On"
|
||||
} else {
|
||||
val s = SampleStore.get(slot.string("sfSample")) ?: return
|
||||
v.noteOn(s, note, velocity, slot.float("sfRoot", 60f).toInt(), 0f, 1f, slot.float("volume", 0.8f),
|
||||
|
||||
@@ -1056,9 +1056,11 @@ class ReferenceEngine(
|
||||
val vs = voiceSample(slot, note)
|
||||
when {
|
||||
vs != null ->
|
||||
allocSampleVoice(bus).also { it.ownerTrack = ownerTrack }.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)
|
||||
allocSampleVoice(bus).also { it.ownerTrack = ownerTrack }.apply {
|
||||
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)
|
||||
oneShot = vs.oneShot
|
||||
}
|
||||
// Empty bus (no instrument — e.g. the default channel 0) or a Sampler
|
||||
// with an empty pad → silent, matching the live audition path.
|
||||
slot?.type == null || slot.type == ToolboxType.SAMPLER -> {}
|
||||
@@ -1079,6 +1081,7 @@ class ReferenceEngine(
|
||||
val attack: Float = 0.002f, val decay: Float = 0f,
|
||||
val sustain: Float = 1f, val release: Float = 0.02f,
|
||||
val loop: Boolean = false, val crossfadeMs: Float = 0f,
|
||||
val oneShot: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -1101,6 +1104,7 @@ class ReferenceEngine(
|
||||
slot.float(SamplerPads.sliceStartKey(pad), 0f),
|
||||
slot.float(SamplerPads.sliceEndKey(pad), 1f),
|
||||
slot.float(SamplerPads.volumeKey(pad), SamplerPads.DEFAULT_VOLUME),
|
||||
oneShot = slot.string("oneShot", "Off") == "On",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1282,6 +1286,7 @@ class ReferenceEngine(
|
||||
val v = auditionSampleVoices.firstOrNull { !it.isActive } ?: auditionSampleVoices[0].also { it.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
|
||||
}
|
||||
// A Sampler with an empty pad stays silent (audition is a one-shot with no
|
||||
@@ -1337,6 +1342,7 @@ class ReferenceEngine(
|
||||
val v = freeBusVoice(busSampleVoices, base)
|
||||
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
|
||||
}
|
||||
// Sampler with an empty pad → silent (no synth fallback).
|
||||
type == ToolboxType.SAMPLER -> {}
|
||||
@@ -1559,7 +1565,7 @@ class ReferenceEngine(
|
||||
private fun allSeqVoicesOff() {
|
||||
clouds.forEach { it.releaseSequenced() }
|
||||
seqVoices.forEach { it.noteOff() }
|
||||
sampleVoices.forEach { it.noteOff() }
|
||||
sampleVoices.forEach { it.release() } // a stopped song stops One-shot pads too
|
||||
arps.forEach { it.stop() }
|
||||
allMidiNotesOff() // release any notes we sent to external gear
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user