Skip to content

Commit

Permalink
[Mod] S3M: Don't clamp out-of-range notes to minimum note.
Browse files Browse the repository at this point in the history
[Imp] Add more tests for S3M / XM out-of-range note saving.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22131 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 9, 2024
1 parent acac87c commit 61efc04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 2 additions & 6 deletions soundlib/Load_s3m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,13 +973,9 @@ bool CSoundFile::SaveS3M(std::ostream &f) const
{
// Note Cut
note = s3mNoteOff;
} else if(note >= NOTE_MIN && note < NOTE_MIN + 12)
} else if(note >= NOTE_MIN + 12 && note <= NOTE_MIN + 107)
{
// Too low
note = 0;
} else if(note >= NOTE_MIN && note <= NOTE_MIN + 107)
{
note -= (12 + NOTE_MIN);
note -= NOTE_MIN + 12;
note = static_cast<uint8>((note % 12) + ((note / 12) << 4));
} else
{
Expand Down
10 changes: 8 additions & 2 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,8 @@ static void TestLoadXMFile(const CSoundFile &sndFile)
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(0, 1)->note, NOTE_MIN + 12);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(1, 1)->note, NOTE_MIN + 12 + 95);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(2, 1)->note, NOTE_KEYOFF);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(31, 0)->IsEmpty(), true);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(30, 0)->IsEmpty(), true); // Test for resaved out-of-range note
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(31, 0)->IsEmpty(), true); // Test for resaved out-of-range note
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(31, 1)->IsEmpty(), false);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(31, 1)->IsPcNote(), false);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetpModCommand(31, 1)->note, NOTE_MIDDLEC + 12);
Expand Down Expand Up @@ -3412,7 +3413,8 @@ static void TestLoadS3MFile(const CSoundFile &sndFile, bool resaved)
VERIFY_EQUAL_NONCONT(sndFile.Patterns[0].GetpModCommand(3, 0)->IsEmpty(), false);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[0].GetpModCommand(3, 0)->note, NOTE_NONE);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[0].GetpModCommand(3, 0)->instr, 99);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[0].GetpModCommand(4, 0)->IsEmpty(), true);
VERIFY_EQUAL_NONCONT(sndFile.Patterns[0].GetpModCommand(4, 0)->IsEmpty(), true); // Test for resaved out-of-range note
VERIFY_EQUAL_NONCONT(sndFile.Patterns[0].GetpModCommand(5, 0)->IsEmpty(), true); // Test for resaved out-of-range note

VERIFY_EQUAL_NONCONT(sndFile.Patterns[1].GetNumRows(), 64);
VERIFY_EQUAL_NONCONT(sndFile.Patterns.IsPatternEmpty(1), false);
Expand Down Expand Up @@ -3714,6 +3716,8 @@ static MPT_NOINLINE void TestLoadSaveFile()
// file still works.
GetSoundFile(sndFileContainer).m_nSamples++;
GetSoundFile(sndFileContainer).Instruments[1]->Keyboard[110] = GetSoundFile(sndFileContainer).GetNumSamples();
GetSoundFile(sndFileContainer).Patterns[1].GetpModCommand(30, 0)->note = NOTE_MIN; // Should not be saved to file
GetSoundFile(sndFileContainer).Patterns[1].GetpModCommand(31, 0)->note = NOTE_MIN + 108; // Ditto

#ifndef MODPLUG_NO_FILESAVE
// Test file saving
Expand Down Expand Up @@ -3774,6 +3778,8 @@ static MPT_NOINLINE void TestLoadSaveFile()
#ifndef MODPLUG_NO_FILESAVE
// Test file saving
sndFile.ChnSettings[1].dwFlags.set(CHN_MUTE);
sndFile.Patterns[0].GetpModCommand(4, 0)->note = NOTE_MIN; // Should not be saved to file
sndFile.Patterns[0].GetpModCommand(5, 0)->note = NOTE_MIN + 108; // Ditto
sndFile.m_dwLastSavedWithVersion = Version::Current();
#if MPT_OS_DJGPP
SaveS3M(sndFileContainer, filenameBase + P_("ss3"));
Expand Down

0 comments on commit 61efc04

Please sign in to comment.