From: <sv...@op...> - 2024-12-17 22:13:10
|
Author: sagamusix Date: Tue Dec 17 23:12:57 2024 New Revision: 22565 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22565 Log: [Ref] Combine instrument extension reading for ITI/XI and IT/XM/MO3 into the same parsing logic. Modified: trunk/OpenMPT/soundlib/InstrumentExtensions.cpp trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/soundlib/InstrumentExtensions.cpp ============================================================================== --- trunk/OpenMPT/soundlib/InstrumentExtensions.cpp Tue Dec 17 16:43:09 2024 (r22564) +++ trunk/OpenMPT/soundlib/InstrumentExtensions.cpp Tue Dec 17 23:12:57 2024 (r22565) @@ -51,11 +51,11 @@ - have a look below in current tag dictionnary - take the initial ones of the field name -- 4 caracters code (not more, not less) -- must be filled with '.' caracters if code has less than 4 caracters -- for arrays, must include a '[' caracter following significant caracters ('.' not significant!!!) -- use only caracters used in full member name, ordered as they appear in it -- match caracter attribute (small,capital) +- 4 characters code (not more, not less) +- must be filled with '.' characters if code has less than 4 characters +- for arrays, must include a '[' character following significant characters ('.' not significant!!!) +- use only characters used in full member name, ordered as they appear in it +- match character attribute (small, capital) Example with "PanEnv.nLoopEnd" , "PitchEnv.nLoopEnd" & "VolEnv.Values[MAX_ENVPOINTS]" members : - use 'PLE.' for PanEnv.nLoopEnd @@ -66,6 +66,8 @@ * In use CODE tag dictionary (alphabetical order): -------------------------------------------------- +AERN PanEnv.nReleaseNode +AFLG PanEnv.dwFlags CS.. nCutSwing DCT. nDCT dF.. dwFlags @@ -82,12 +84,15 @@ MDK. nMidiDrumKey MiP. nMixPlug MP.. nMidiProgram +MPWD MIDI Pitch Wheel Depth n[.. name[32] -NNA. nNNA NM[. NoteMap[128] +NNA. nNNA P... nPan PE.. PanEnv.nNodes PE[. PanEnv.Values[MAX_ENVPOINTS] +PERN PitchEnv.nReleaseNode +PFLG PitchEnv.dwFlag PiE. PitchEnv.nNodes PiE[ PitchEnv.Values[MAX_ENVPOINTS] PiLE PitchEnv.nLoopEnd @@ -103,14 +108,16 @@ PS.. nPanSwing PSB. PanEnv.nSustainStart PSE. PanEnv.nSustainEnd -PTTL pitchToTempoLock PTTF pitchToTempoLock (fractional part) +PTTL pitchToTempoLock PVEH pluginVelocityHandling PVOH pluginVolumeHandling R... Resampling RS.. nResSwing VE.. VolEnv.nNodes VE[. VolEnv.Values[MAX_ENVPOINTS] +VERN VolEnv.nReleaseNode +VFLG VolEnv.dwFlags VLE. VolEnv.nLoopEnd VLS. VolEnv.nLoopStart VP[. VolEnv.Ticks[MAX_ENVPOINTS] @@ -118,13 +125,6 @@ VS.. nVolSwing VSB. VolEnv.nSustainStart VSE. VolEnv.nSustainEnd -PERN PitchEnv.nReleaseNode -AERN PanEnv.nReleaseNode -VERN VolEnv.nReleaseNode -PFLG PitchEnv.dwFlag -AFLG PanEnv.dwFlags -VFLG VolEnv.dwFlags -MPWD MIDI Pitch Wheel Depth Note that many of these extensions were only relevant for ITP files, and thus there is no code for writing them, only reading. Some of them used to be written but were never read ("K[.." sample map - it was only relevant for ITP files, but even there @@ -605,30 +605,20 @@ // For ITP and internal usage -void ReadExtendedInstrumentProperty(ModInstrument *ins, const uint32 code, FileReader &file) +void ReadExtendedInstrumentProperty(mpt::span<ModInstrument *> instruments, const uint32 code, FileReader &file) { uint16 size = file.ReadUint16LE(); - FileReader chunk = file.ReadChunk(size); - if(ins && chunk.GetLength() == size) - ReadInstrumentHeaderField(*ins, code, chunk); -} - - -// For ITI / XI -void ReadExtendedInstrumentProperties(ModInstrument &ins, FileReader &file) -{ - if(!file.ReadMagic("XTPM")) // 'MPTX' - return; - - while(file.CanRead(7)) + for(ModInstrument *ins : instruments) { - ReadExtendedInstrumentProperty(&ins, file.ReadUint32LE(), file); + FileReader chunk = file.ReadChunk(size); + if(ins && chunk.GetLength() == size) + ReadInstrumentHeaderField(*ins, code, chunk); } } -// For IT / XM / MO3 -bool CSoundFile::LoadExtendedInstrumentProperties(FileReader &file) +// For IT / XM / MO3 / ITI / XI +bool CSoundFile::LoadExtendedInstrumentProperties(mpt::span<ModInstrument *> instruments, FileReader &file) { if(!file.ReadMagic("XTPM")) // 'MPTX' return false; @@ -645,15 +635,7 @@ break; } - // Read size of this property for *one* instrument - const uint16 size = file.ReadUint16LE(); - - for(INSTRUMENTINDEX i = 1; i <= GetNumInstruments(); i++) - { - FileReader chunk = file.ReadChunk(size); - if(Instruments[i] && chunk.GetLength() == size) - ReadInstrumentHeaderField(*Instruments[i], code, chunk); - } + ReadExtendedInstrumentProperty(instruments, code, file); } return true; } Modified: trunk/OpenMPT/soundlib/Load_itp.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp Tue Dec 17 16:43:09 2024 (r22564) +++ trunk/OpenMPT/soundlib/Load_itp.cpp Tue Dec 17 23:12:57 2024 (r22565) @@ -387,7 +387,7 @@ ins++; } else { - ReadExtendedInstrumentProperty(Instruments[ins], code, file); + ReadExtendedInstrumentProperty(mpt::as_span(&Instruments[ins], 1), code, file); } code = file.ReadUint32LE(); Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp ============================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp Tue Dec 17 16:43:09 2024 (r22564) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp Tue Dec 17 23:12:57 2024 (r22565) @@ -1341,7 +1341,7 @@ } // Read MPT crap - ReadExtendedInstrumentProperties(*pIns, file); + LoadExtendedInstrumentProperties(mpt::as_span(&Instruments[nInstr], 1), file); pIns->Convert(MOD_TYPE_XM, GetType()); pIns->Sanitize(GetType()); return true; @@ -2405,7 +2405,7 @@ if(file.Seek(extraOffset)) { // Read MPT crap - ReadExtendedInstrumentProperties(*pIns, file); + LoadExtendedInstrumentProperties(mpt::as_span(&Instruments[nInstr], 1), file); } pIns->Convert(MOD_TYPE_IT, GetType()); Modified: trunk/OpenMPT/soundlib/Sndfile.h ============================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h Tue Dec 17 16:43:09 2024 (r22564) +++ trunk/OpenMPT/soundlib/Sndfile.h Tue Dec 17 23:12:57 2024 (r22565) @@ -75,9 +75,7 @@ void WriteInstrumentHeaderStructOrField(ModInstrument * input, std::ostream &file, uint32 only_this_code = -1 /* -1 for all */, uint16 fixedsize = 0); #endif // !MODPLUG_NO_FILESAVE // ITP: Read instrument property with 'code' from 'file' to instrument 'ins'. -void ReadExtendedInstrumentProperty(ModInstrument *ins, const uint32 code, FileReader &file); -// ITI / XI: Read extended instrument properties from 'file' to instrument 'ins'. -void ReadExtendedInstrumentProperties(ModInstrument &ins, FileReader &file); +void ReadExtendedInstrumentProperty(mpt::span<ModInstrument *> instruments, const uint32 code, FileReader &file); // Sample decompression routines in format-specific source files @@ -945,9 +943,10 @@ static mpt::ustring GetImpulseTrackerVersion(uint16 cwtv, uint16 cmwt); static mpt::ustring GetSchismTrackerVersion(uint16 cwtv, uint32 reserved); - // Reads extended instrument properties(XM/IT/MPTM). + // Reads extended instrument properties(XM/IT/MPTM/ITI/XI). // Returns true if extended instrument properties were found. - bool LoadExtendedInstrumentProperties(FileReader &file); + bool LoadExtendedInstrumentProperties(FileReader &file) { return LoadExtendedInstrumentProperties(mpt::as_span(Instruments).subspan(1, GetNumInstruments()), file); } + static bool LoadExtendedInstrumentProperties(mpt::span<ModInstrument *> instruments, FileReader &file); void SetDefaultPlaybackBehaviour(MODTYPE type); static PlayBehaviourSet GetSupportedPlaybackBehaviour(MODTYPE type); |