@@ -136,13 +136,8 @@ it was always ignored, because sample indices may change when loading external i
136136
137137#ifndef MODPLUG_NO_FILESAVE
138138
139- namespace
140- {
141- const ModInstrument DEFAULT_INSTRUMENT;
142- }
143-
144139template <auto Member>
145- constexpr bool IsPropertyNonDefault (const ModInstrument &ins) { return DEFAULT_INSTRUMENT .*Member != ins.*Member; }
140+ constexpr bool IsPropertyNonDefault (const ModInstrument &ins) { return ModInstrument{} .*Member != ins.*Member; }
146141
147142template <auto Member>
148143constexpr uint16 PropertySize () noexcept { return sizeof (ModInstrument{}.*Member); }
@@ -179,27 +174,33 @@ struct PropertyWriterEnum : PropertyWriterBase<Member, PropertyNeededFunc, Prope
179174
180175struct PropertyWriterReleaseNode
181176{
182- bool IsPropertyNeeded (const ModInstrument &ins) const noexcept { return DEFAULT_INSTRUMENT .GetEnvelope (type).nReleaseNode != ins.GetEnvelope (type).nReleaseNode ; }
177+ bool IsPropertyNeeded (const ModInstrument &ins) const noexcept { return ModInstrument{} .GetEnvelope (type).nReleaseNode != ins.GetEnvelope (type).nReleaseNode ; }
183178 static constexpr uint16 Size () noexcept { return sizeof (InstrumentEnvelope{}.nReleaseNode ); }
184179 void Write (std::ostream &file, const ModInstrument &ins) const { mpt::IO::WriteIntLE (file, ins.GetEnvelope (type).nReleaseNode ); }
185180 const EnvelopeType type;
186181};
187182
188183struct PropertyWriterEnvelopeBase
189184{
190- static constexpr bool IsPropertyNeeded (const ModInstrument &) noexcept { return true ; }
185+ PropertyWriterEnvelopeBase (uint32 nodes, EnvelopeType type) : nodes{nodes}, type{type} {};
186+ static constexpr bool IsPropertyNeeded (const ModInstrument&) noexcept
187+ {
188+ return true ;
189+ }
191190 const uint32 nodes;
192191 const EnvelopeType type;
193192};
194193
195194struct PropertyWriterEnvelopeSize : PropertyWriterEnvelopeBase
196195{
196+ using PropertyWriterEnvelopeBase::PropertyWriterEnvelopeBase;
197197 static constexpr uint16 Size () noexcept { return sizeof (uint32le); }
198198 void Write (std::ostream &file, const ModInstrument &ins) const { mpt::IO::WriteIntLE<uint32>(file, ins.GetEnvelope (type).size ()); }
199199};
200200
201201struct PropertyWriterEnvelopeTicks : PropertyWriterEnvelopeBase
202202{
203+ using PropertyWriterEnvelopeBase::PropertyWriterEnvelopeBase;
203204 uint16 Size () const noexcept { return static_cast <uint16>(sizeof (uint16le) * nodes); }
204205 void Write (std::ostream &file, const ModInstrument &ins) const
205206 {
@@ -220,6 +221,7 @@ struct PropertyWriterEnvelopeTicks : PropertyWriterEnvelopeBase
220221
221222struct PropertyWriterEnvelopeValues : PropertyWriterEnvelopeBase
222223{
224+ using PropertyWriterEnvelopeBase::PropertyWriterEnvelopeBase;
223225 uint16 Size () const noexcept { return static_cast <uint16>(sizeof (uint8) * nodes); }
224226 void Write (std::ostream &file, const ModInstrument &ins) const
225227 {
@@ -240,7 +242,7 @@ struct PropertyWriterEnvelopeValues : PropertyWriterEnvelopeBase
240242
241243struct PropertyWriterPitchTempoLock
242244{
243- static constexpr bool IsPropertyNeeded (const ModInstrument &ins) noexcept { return DEFAULT_INSTRUMENT .pitchToTempoLock != ins.pitchToTempoLock ; }
245+ static constexpr bool IsPropertyNeeded (const ModInstrument &ins) noexcept { return ModInstrument{} .pitchToTempoLock != ins.pitchToTempoLock ; }
244246 static constexpr uint16 Size () noexcept { return sizeof (uint16le); }
245247 PropertyWriterPitchTempoLock (bool intPart) : m_intPart{intPart} {}
246248 void Write (std::ostream &file, const ModInstrument &ins)
@@ -267,9 +269,10 @@ static void WriteProperty(std::ostream &f, uint32 code, mpt::span<const ModInstr
267269 return ;
268270 mpt::IO::WriteIntLE<uint32>(f, code);
269271 mpt::IO::WriteIntLE<uint16>(f, property.Size ());
272+ ModInstrument defaultInstr{};
270273 for (const ModInstrument *ins : instruments)
271274 {
272- property.Write (f, ins ? *ins : DEFAULT_INSTRUMENT );
275+ property.Write (f, ins ? *ins : defaultInstr );
273276 }
274277}
275278
0 commit comments