more tracker stuff

This commit is contained in:
minjaesong
2026-04-23 12:43:56 +09:00
parent 3a91edb379
commit e58eb2c12b
3 changed files with 149 additions and 8 deletions

View File

@@ -89,6 +89,27 @@ class AudioJSR223Delegate(private val vm: VM) {
}
fun getCuePosition(playhead: Int) = getPlayhead(playhead)?.position
fun getTrackerRow(playhead: Int) = getPlayhead(playhead)?.trackerState?.rowIndex ?: 0
fun setVoiceMute(playhead: Int, voice: Int, muted: Boolean) {
getPlayhead(playhead)?.trackerState?.voices?.getOrNull(voice.coerceIn(0, 19))?.muted = muted
}
fun getVoiceMute(playhead: Int, voice: Int): Boolean =
getPlayhead(playhead)?.trackerState?.voices?.getOrNull(voice.coerceIn(0, 19))?.muted ?: false
/** Set the starting row for the next play call, resetting per-row timing and silencing active voices. */
fun setTrackerRow(playhead: Int, row: Int) {
getPlayhead(playhead)?.trackerState?.let { ts ->
ts.rowIndex = row.coerceIn(0, 63)
ts.tickInRow = 0
ts.samplesIntoTick = 0.0
ts.firstRow = true
ts.pendingOrderJump = -1
ts.pendingRowJump = -1
ts.voices.forEach { it.active = false }
}
}
/** Upload 64 bytes defining instrument `slot` (0-255). */
fun uploadInstrument(slot: Int, bytes: IntArray) {
getFirstSnd()?.instruments?.get(slot and 0xFF)?.let { inst ->

View File

@@ -1708,7 +1708,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
var mixR = 0.0
val gvol = playhead.globalVolume / 255.0
for (voice in ts.voices) {
if (!voice.active) continue
if (!voice.active || voice.muted) continue
val s = fetchTrackerSample(voice, instruments[voice.instrumentId])
val vol = voice.envVolume * voice.rowVolume / 63.0 * gvol * playhead.masterVolume / 255.0
mixL += s * vol * (63 - voice.rowPan) / 63.0
@@ -1857,6 +1857,7 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
class Voice {
var active = false
var muted = false
var instrumentId = 0
var samplePos = 0.0
var playbackRate = 1.0