ultraabox / ultrabox_typescript

ultrabox source code
MIT License
26 stars 17 forks source link

Tempo modulation is imported incorrectly #52

Open leovoel opened 11 months ago

leovoel commented 11 months ago

Related to the tempo range being increased.

leovoel commented 11 months ago

I believe I've figured out how to remap this for song URLs. The first step is to identify the channel, instrument, and pitch of the note to change the pins of. There's some code to do this for song reverb:

https://github.com/ultraabox/ultrabox_typescript/blob/d4bc09df02201449e75c9101da9d2537051f90d0/synth/synth.ts#L5185-L5190

Later, after the note data is parsed from the URL, the corrections are applied:

https://github.com/ultraabox/ultrabox_typescript/blob/d4bc09df02201449e75c9101da9d2537051f90d0/synth/synth.ts#L5440-L5448

Below that, this could be added:

if ((fromJummBox || fromGoldBox) && songTempoIndex >= 0) {
    for (let channelIndex: number = 0; channelIndex < this.channels.length; channelIndex++) {
        for (let instrumentIndex: number = 0; instrumentIndex < this.channels[channelIndex].instruments.length; instrumentIndex++) {
            if (songTempoChannel == channelIndex && songTempoInstrument == instrumentIndex) {
                for (const pattern of this.channels[channelIndex].patterns) {
                    for (const note of pattern.notes) {
                        if (note.pitches[0] !== Config.modCount - 1 - songTempoIndex) continue;
                        for (const pin of note.pins) {
                            const oldMin: number = 30;
                            const newMin: number = 1;
                            const old: number = pin.size + oldMin;
                            pin.size = old - newMin; // convertRealFactor will add back newMin as necessary
                        }
                    }
                }
            }
        }
    }
}

I don't think the version/variant check is quite correct though. It should capture JummBox and GoldBox songs only, but old UltraBox songs share the same format as GoldBox, so if the tempo range was increased while those were still the same, those old songs can't be identified unambiguously.

Similar code should be added for json imports. I think that's even more ambiguous when it comes to figuring out whether something is a JummBox song, or a GoldBox song, or an UltraBox song, which is unfortunate.