chrismaltby / gb-studio

A quick and easy to use drag and drop retro game creator for your favourite handheld video game system
https://www.gbstudio.dev
MIT License
8.55k stars 470 forks source link

Play Music event using hUGETracker do not take loop param into account #1015

Open ReyAnthony opened 2 years ago

ReyAnthony commented 2 years ago

Describe the bug When using the play music event with loop == false and using HUGE_TRACKER the music is still lopping

To Reproduce Steps to reproduce the behavior: Simply add a play music event without a loop using HUGE.

Expected behavior loop being false in the event means it should not loop

Screenshots Not applicable

Platform (please complete the following information): tested @ rev 7d5932d on Windows 10

Additional context I believe the problem is simply that the behavior is not implemented for HUGE :

void music_play(const TRACK_T *track, UBYTE bank, UBYTE loop) NONBANKED {
    if (track == NULL) {
        music_stop();
    } else if (track != current_track || bank != current_track_bank) {
        channel_mask = MASK_ALL_CHANNELS;
#ifdef GBT_PLAYER
        UBYTE _save = _current_bank;
        current_track_bank = bank;
        CRITICAL {
            gbt_play(track, bank, 7);
            gbt_loop(loop);
            SWITCH_ROM(_save);
            music_mute(channel_mask);
        }
#endif
#ifdef HUGE_TRACKER
        loop;
        UBYTE _save = _current_bank;
        current_track_bank = bank;
        CRITICAL {
            music_stop();
            SWITCH_ROM(current_track_bank);
            hUGE_init(track);
            SWITCH_ROM(_save);
            huge_initialized = TRUE;
            music_mute(channel_mask);
            music_stopped = FALSE;        
        }
#endif
        current_track = track;
    } else {
#ifdef SAME_TUNE_RESTARTS
        // restart current song from beginning
        music_stop();
        music_play(index, loop);
#endif
    }
}

The loop param is not used, and afaik music_update is not using it anyway. My 2 cents is that we should stop the HugeDriver when end of the music is reached. (mist likely in music_update)

I'll try looking for a fix, but I am not well versed in asm šŸ˜„

ReyAnthony commented 2 years ago

As expected I'm not well versed enough in asm to fix this šŸ˜

I tried getting the value from current_order in HugeDriver.asm As far as I could understand from the driver code, this variable is used to store the "current seek" in the song (see hugeHelper.ts for the code generating the song data that will loaded) and could thoerically be used to know if the song has looped

aka : If this value is 0 again and you don't allow looping, then stop the music.

Maybe I am going too far and the solution is easier tho, don't know šŸ˜„

darkhog commented 2 years ago

It can be bypassed by adding an empty pattern at the end of the uge file and clever usage of the Bxx effect. But you would need a copy of the track without that addition if you want it to loop some time and not the other.

untoxa commented 2 years ago

insert music event effect into the last row of your song, it will call a script, where you decide whether to loop, chain into the other song or simply stop.