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

[MP2K][Bug Report] Tune calculation when saving to MIDI #99

Closed
laqieer opened this issue May 2, 2022 · 4 comments
Closed

[MP2K][Bug Report] Tune calculation when saving to MIDI #99

laqieer opened this issue May 2, 2022 · 4 comments

Comments

@laqieer
Copy link
Contributor

laqieer commented May 2, 2022

5a85cda

@Kermalis
Copy link
Owner

Kermalis commented May 2, 2022

Hi, does this still keep the MIDIs matching? As in, does the midi produce a matching asm output with mid2agb?

The current midi exporter matched all MIDIs for the 5 main series Pokémon games, so as long as this tune modification is an actual fix then it's accepted. I don't remember if they used tune at the moment

Other enhancements to the midi exporter won't be accepted right now since there's no way to toggle the output type (matching or enhanced) with a dialog

@laqieer
Copy link
Contributor Author

laqieer commented May 3, 2022

The expoted midi doesn't match without the bug fix. As in, it produces a mismatching asm output with mid2agb.

Here is an example: FireEmblemUniverse/fireemblem8u@4b87e79

  1. 64 is subtracted for TUNE before:

    AddEvent(new TuneCommand { Tune = (sbyte)(cmd - 0x40) });

    AddEvent(new TuneCommand { Tune = (sbyte)(tuneArg - 0x40) });

  2. But it is not added back later:

    track.Insert(ticks, new ChannelMessage(ChannelCommand.Controller, trackIndex, 24, tune.Tune));

    While it is added back at the same time for PAN and BEND:
    track.Insert(ticks, new ChannelMessage(ChannelCommand.Controller, trackIndex, (int)ControllerType.Pan, pan.Panpot + 0x40));

    track.Insert(ticks, new ChannelMessage(ChannelCommand.PitchWheel, trackIndex, 0, bend.Bend + 0x40));

  3. 64 is subracted from the value for TUNE, PAN and BEND:
    https://github.com/pret/pokeemerald/blob/ef4d99c87e898f34be793fe72bef8f3f3cf2fcb2/tools/mid2agb/agb.cpp#L393
    https://github.com/pret/pokeemerald/blob/ef4d99c87e898f34be793fe72bef8f3f3cf2fcb2/tools/mid2agb/agb.cpp#L360
    https://github.com/pret/pokeemerald/blob/ef4d99c87e898f34be793fe72bef8f3f3cf2fcb2/tools/mid2agb/agb.cpp#L513

  4. as adds it back later:
    https://github.com/pret/pokeemerald/blob/ef4d99c87e898f34be793fe72bef8f3f3cf2fcb2/sound/MPlayDef.s#L132

To conclude:

  • PAN/BEND: ROM value -> -64 by VGMusicStudio -> +64 by VGMusicStudio -> -64 by mid2agb -> +64 by as -> ROM value
  • TUNE: ROM value -> -64 by VGMusicStudio -> +64 by VGMusicStudio -> -64 by mid2agb -> +64 by as -> ROM value - 64

Therefore, both PAN and BEND match, but TUNE doesn't match.

It works for the 5 main series Pokémon games doesn't prove it is correct. It may be unused in this game instead. A similar case:
pret/pokeemerald#1593

Other enhancements to the midi exporter won't be accepted right now since there's no way to toggle the output type (matching or enhanced) with a dialog

They have been removed.

@Kermalis
Copy link
Owner

Kermalis commented May 5, 2022

Hey, I was just making sure it still matches, thanks for the proof. I just didn't remember if the 5 Pokémon games used TUNE or not.

If you make a PR for this commit I'll accept it right away. Your other PR I haven't looked at yet, since I've been so busy irl, but thankfully someone else is helping review it

@Kermalis
Copy link
Owner

Kermalis commented May 6, 2022

Closed in #100

@Kermalis Kermalis closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants