From: <sv...@op...> - 2024-04-13 22:14:58
|
Author: sagamusix Date: Sun Apr 14 00:14:50 2024 New Revision: 20584 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20584 Log: [Fix] Avoid using non-standard anonymous structs. This approach also removes the padding bytes in the Event structure. [Fix] Fix compilation on DJGPP. Modified: trunk/OpenMPT/soundlib/InstrumentSynth.cpp trunk/OpenMPT/soundlib/InstrumentSynth.h trunk/OpenMPT/soundlib/Load_med.cpp Modified: trunk/OpenMPT/soundlib/InstrumentSynth.cpp ============================================================================== --- trunk/OpenMPT/soundlib/InstrumentSynth.cpp Sat Apr 13 23:48:02 2024 (r20583) +++ trunk/OpenMPT/soundlib/InstrumentSynth.cpp Sun Apr 14 00:14:50 2024 (r20584) @@ -242,8 +242,8 @@ // MED stuff if(m_medArpOffset < events.size()) { - m_linearPitchFactor = 16 * events[m_medArpOffset + m_medArpPos].bytes[0]; - m_medArpPos = (m_medArpPos + 1) % events[m_medArpOffset].bytes[1]; + m_linearPitchFactor = 16 * events[m_medArpOffset + m_medArpPos].u8; + m_medArpPos = (m_medArpPos + 1) % static_cast<uint8>(events[m_medArpOffset].u16); } if(m_medVibratoDepth) { @@ -296,7 +296,7 @@ } if(m_volumeAdd != int16_min) { - chn.nRealVolume = std::clamp(chn.nRealVolume + m_volumeAdd, 0, 16384); + chn.nRealVolume = std::clamp(chn.nRealVolume + m_volumeAdd, int32(0), int32(16384)); } if(m_panning != 2048) { @@ -384,10 +384,10 @@ m_gtkTremorEnabled = event.u8 != 0; return false; case Event::Type::GTK_SetTremorTime: - if(event.bytes[0]) - m_gtkTremorOnTime = event.bytes[0]; - if(event.bytes[1]) - m_gtkTremorOffTime = event.bytes[1]; + if(event.Byte0()) + m_gtkTremorOnTime = event.Byte0(); + if(event.Byte1()) + m_gtkTremorOffTime = event.Byte1(); m_gtkTremorPos = 0; return false; case Event::Type::GTK_EnableTremolo: @@ -407,27 +407,27 @@ m_gtkVibratoSpeed = 8; return false; case Event::Type::GTK_SetVibratoParams: - if(event.bytes[0]) - m_gtkVibratoWidth = event.bytes[0]; - if(event.bytes[1]) - m_gtkVibratoSpeed = event.bytes[1]; + if(event.Byte0()) + m_gtkVibratoWidth = event.Byte0(); + if(event.Byte1()) + m_gtkVibratoSpeed = event.Byte1(); return false; case Event::Type::Puma_SetWaveform: - m_pumaWaveform = m_pumaStartWaveform = event.bytes[0] + 1; - if(event.bytes[0] < 10) + m_pumaWaveform = m_pumaStartWaveform = event.Byte0() + 1; + if(event.Byte0() < 10) { m_pumaWaveformStep = 0; } else { - m_pumaWaveformStep = event.bytes[1]; - m_pumaEndWaveform = event.bytes[2] + m_pumaStartWaveform; + m_pumaWaveformStep = event.Byte1(); + m_pumaEndWaveform = event.Byte2() + m_pumaStartWaveform; } ChannelSetSample(chn, sndFile, m_pumaWaveform); return false; case Event::Type::Puma_VolumeRamp: - m_ticksRemain = event.bytes[2]; - m_volumeAdd = event.bytes[0] * 256 - 16384; + m_ticksRemain = event.Byte2(); + m_volumeAdd = event.Byte0() * 256 - 16384; return true; case Event::Type::Puma_StopVoice: chn.nRealVolume = 0; @@ -435,25 +435,25 @@ m_nextRow = STOP_ROW; return true; case Event::Type::Puma_SetPitch: - m_linearPitchFactor = static_cast<int8>(event.bytes[0]) * 8; + m_linearPitchFactor = static_cast<int8>(event.Byte0()) * 8; m_periodAdd = 0; - m_ticksRemain = event.bytes[2]; + m_ticksRemain = event.Byte2(); return true; case Event::Type::Puma_PitchRamp: m_linearPitchFactor = 0; - m_periodAdd = static_cast<int8>(event.bytes[0]) * 4; - m_ticksRemain = event.bytes[2]; + m_periodAdd = static_cast<int8>(event.Byte0()) * 4; + m_ticksRemain = event.Byte2(); return true; case Event::Type::Mupp_SetWaveform: - ChannelSetSample(chn, sndFile, 32 + event.bytes[0] * 28 + event.bytes[1]); - m_volumeFactor = static_cast<uint16>(std::min(event.bytes[2] & 0x7F, 64) * 256u); + ChannelSetSample(chn, sndFile, 32 + event.Byte0() * 28 + event.Byte1()); + m_volumeFactor = static_cast<uint16>(std::min(event.Byte2() & 0x7F, 64) * 256u); return true; case Event::Type::MED_DefineArpeggio: - if(!event.bytes[1]) + if(!event.Byte1()) return false; - m_nextRow = m_currentRow + event.bytes[1]; + m_nextRow = m_currentRow + event.u16; m_medArpOffset = m_currentRow; m_medArpPos = 0; return true; @@ -465,10 +465,10 @@ } return false; case Event::Type::MED_SetEnvelope: - if(event.bytes[2]) - m_medVolumeEnv = (event.bytes[0] & 0x3F) | (event.bytes[1] ? 0x80 : 0x00); + if(event.Byte2()) + m_medVolumeEnv = (event.Byte0() & 0x3F) | (event.Byte1() ? 0x80 : 0x00); else - m_medVibratoEnvelope = event.bytes[0]; + m_medVibratoEnvelope = event.Byte0(); m_medVolumeEnvPos = 0; return false; case Event::Type::MED_SetVolume: @@ -505,12 +505,12 @@ switch(event.type) { case Event::Type::Puma_VolumeRamp: - if(event.bytes[2] > 0) - m_volumeAdd = static_cast<int16>((event.bytes[1] + Util::muldivr(event.bytes[0] - event.bytes[1], m_ticksRemain, event.bytes[2])) * 256 - 16384); + if(event.Byte2() > 0) + m_volumeAdd = static_cast<int16>((event.Byte1() + Util::muldivr(event.Byte0() - event.Byte1(), m_ticksRemain, event.Byte2())) * 256 - 16384); break; case Event::Type::Puma_PitchRamp: - if(event.bytes[2] > 0) - m_periodAdd = static_cast<int16>((static_cast<int8>(event.bytes[1]) + Util::muldivr(static_cast<int8>(event.bytes[0]) - static_cast<int8>(event.bytes[1]), m_ticksRemain, event.bytes[2])) * 4); + if(event.Byte2() > 0) + m_periodAdd = static_cast<int16>((static_cast<int8>(event.Byte1()) + Util::muldivr(static_cast<int8>(event.Byte0()) - static_cast<int8>(event.Byte1()), m_ticksRemain, event.Byte2())) * 4); break; default: break; Modified: trunk/OpenMPT/soundlib/InstrumentSynth.h ============================================================================== --- trunk/OpenMPT/soundlib/InstrumentSynth.h Sat Apr 13 23:48:02 2024 (r20583) +++ trunk/OpenMPT/soundlib/InstrumentSynth.h Sun Apr 14 00:14:50 2024 (r20584) @@ -55,7 +55,7 @@ Mupp_SetWaveform, // Parameter: Source instrument (uint8), waveform (uint8), volume (uint8) - MED_DefineArpeggio, // Parameter: Arpeggio note (uint8), arp length or 0 if it's not the first note (uint8) + MED_DefineArpeggio, // Parameter: Arpeggio note (uint8), arp length or 0 if it's not the first note (uint16) MED_JumpScript, // Parameter: Script index (uint8), jump target (uint16) MED_SetEnvelope, // Parameter: Envelope index (uint8), loop on/off (uint8), is volume envelope (uint8) MED_SetVolume, // Parameter: Volume (uint8) @@ -70,17 +70,14 @@ Type type = Type::StopScript; union { - std::array<uint8, 3> bytes = {{}}; - struct - { - uint16 u16; - uint8 u8; - }; - struct - { - int16 i16; - int8 i8; - }; + uint8 u8 = 0; + int8 i8; + }; + union + { + uint16 u16 = 0; + int16 i16; + std::array<uint8, 2> bytes; }; static constexpr Event StopScript() noexcept { return Event{Type::StopScript}; } @@ -113,7 +110,7 @@ static constexpr Event Mupp_SetWaveform(uint8 instr, uint8 waveform, uint8 volume) noexcept { return Event{Type::Mupp_SetWaveform, instr, waveform, volume}; } - static constexpr Event MED_DefineArpeggio(uint8 note, uint8 noteCount) noexcept { return Event{Type::MED_DefineArpeggio, note, noteCount, uint8(0)}; } + static constexpr Event MED_DefineArpeggio(uint8 note, uint16 noteCount) noexcept { return Event{Type::MED_DefineArpeggio, noteCount, note}; } static constexpr Event MED_JumpScript(uint8 scriptIndex, uint16 target) noexcept { return Event{Type::MED_JumpScript, target, scriptIndex}; } static constexpr Event MED_SetEnvelope(uint8 envelope, bool loop, bool volumeEnv) noexcept { return Event{Type::MED_SetEnvelope, envelope, uint8(loop ? 1 : 0), uint8(volumeEnv ? 1 : 0)}; } static constexpr Event MED_SetVolume(uint8 volume) noexcept { return Event{Type::MED_SetVolume, volume}; } @@ -146,13 +143,17 @@ u16 = uint16_max; } + constexpr uint8 Byte0() const noexcept { return u8; } + constexpr uint8 Byte1() const noexcept { return bytes[0]; } + constexpr uint8 Byte2() const noexcept { return bytes[1]; } + protected: - constexpr Event(Type type, uint8 b1, uint8 b2, uint8 b3) noexcept : type{type}, bytes{b1, b2, b3} {} + constexpr Event(Type type, uint8 b1, uint8 b2, uint8 b3) noexcept : type{type}, u8{b1}, bytes{b2, b3} {} constexpr Event(Type type, uint16 u16, uint8 u8 = 0) noexcept : type{type}, u16{u16}, u8{u8} {} constexpr Event(Type type, int16 i16) noexcept : type{type}, i16{i16} {} constexpr Event(Type type, uint8 u8) noexcept : type{type}, u8{u8} {} constexpr Event(Type type, int8 i8) noexcept : type{type}, i8{i8} {} - explicit constexpr Event(Type type) noexcept : type{type}, bytes{{}} {} + explicit constexpr Event(Type type) noexcept : type{type}, u8{}, u16{} {} }; using Events = std::vector<Event>; Modified: trunk/OpenMPT/soundlib/Load_med.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Load_med.cpp Sat Apr 13 23:48:02 2024 (r20583) +++ trunk/OpenMPT/soundlib/Load_med.cpp Sun Apr 14 00:14:50 2024 (r20584) @@ -665,7 +665,7 @@ arpSize++; } if(arpSize) - events[firstEvent].bytes[1] = arpSize; + events[firstEvent].u16 = arpSize; } break; case 0xFA: // JWV / JWS - Jump waveform / volume sequence |