Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bank parameter does not work for exporting music #2190

Closed
borbware opened this issue May 10, 2023 · 9 comments · Fixed by #2202
Closed

Bank parameter does not work for exporting music #2190

borbware opened this issue May 10, 2023 · 9 comments · Fixed by #2202
Assignees

Comments

@borbware
Copy link
Contributor

The bank parameter doesn't work for exporting music tracks. Regardless of its value, the music track with the id corresponding to the id parameter from the currently active bank is exported

Thus, it's not possible to export music from other banks when using TIC-80 from the command line.

@joshgoebel
Copy link
Collaborator

How are you defining currently active?

@borbware
Copy link
Contributor Author

image
the one shown on red in the music editor.

@bztsrc
Copy link
Contributor

bztsrc commented May 12, 2023

The bank parameter doesn't work for exporting music tracks. Regardless of its value, the music track with the id corresponding to the id parameter from the currently active bank is exported

According to the code, the function tic_cart_save does not have any reference to the "currently active bank" at all. It saves music patterns and tracks like this:

        buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->banks[i].music.patterns,  i);
        buffer = SAVE_CHUNK(CHUNK_MUSIC,    cart->banks[i].music.tracks,    i);

Where i is a loop variable and given a value here:

    for(s32 i = 0; i < TIC_BANKS; i++)

I can't see how this code could only save the current bank, except SAVE_CHUNK checks and skips fully empty (filled with just zeros) banks.

Are you absolutely sure you have valid music data in the other banks too, not just in one?

Hope this helps,
bzt

@borbware
Copy link
Contributor Author

borbware commented May 12, 2023

Here's an example cartridge so you can try it for yourself if I'm missing something here.
exportbankbug.zip

Consider these commands:

  1. export music megalo.wav id=0 bank=0
  2. export music fanfare.wav id=0 bank=1

If you run both the commands, they will export the same song, the one on bank 0 (because it's active by default).

If you go to music editor, disable bank sync (the red ankh symbol), and change the active bank to 1, the song on bank 1 is exported instead.

You can also choose to not disable bank sync: you will still get the song on bank 1 with both the commands, but it will be composed of noise, because the instrument on bank 1 is not defined.

@borbware
Copy link
Contributor Author

borbware commented May 12, 2023

If it helps any: my investigations led me to the function studioExportMusic: it doesn't take the bank in as an argument, only the track.

@bztsrc
Copy link
Contributor

bztsrc commented May 12, 2023

Ah I see, it's not when saving a cartridge, but when exporting a wav. That's a different code path.

my investigations led me to the function studioExportMusic: it doesn't take the bank in as an argument, only the track.

Indeed. I can confirm that wav export uses the bank selector of the studio and not the cli argument (line 344).

        const Music* editor = studio->banks.music[studio->bank.index.music];

Cheers,
bzt

@borbware
Copy link
Contributor Author

Hmm, this looks simple enough that I could try my hand at fixing this myself. Let's see!

@borbware
Copy link
Contributor Author

...not as simple as i thought.

I tried passing params.bank to the studioExportMusic function, but using

const Music* editor = studio->banks.music[bank];

instead of

const Music* editor = studio->banks.music[studio->bank.index.music];

makes no difference :(

(I checked, the bank param does have the correct value of 0 or 1 inside the function.)

@borbware
Copy link
Contributor Author

okay i found a solution. i'll create a pull request when i have time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants