1
0

XMTools.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * XMTools.h
  3. * ---------
  4. * Purpose: Definition of XM file structures and helper functions
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. OPENMPT_NAMESPACE_BEGIN
  12. // XM File Header
  13. struct XMFileHeader
  14. {
  15. enum XMHeaderFlags
  16. {
  17. linearSlides = 0x01,
  18. extendedFilterRange = 0x1000,
  19. };
  20. char signature[17]; // "Extended Module: "
  21. char songName[20]; // Song Name, not null-terminated (any nulls are treated as spaces)
  22. uint8le eof; // DOS EOF Character (0x1A)
  23. char trackerName[20]; // Software that was used to create the XM file
  24. uint16le version; // File version (1.02 - 1.04 are supported)
  25. uint32le size; // Header Size
  26. uint16le orders; // Number of Orders
  27. uint16le restartPos; // Restart Position
  28. uint16le channels; // Number of Channels
  29. uint16le patterns; // Number of Patterns
  30. uint16le instruments; // Number of Unstruments
  31. uint16le flags; // Song Flags
  32. uint16le speed; // Default Speed
  33. uint16le tempo; // Default Tempo
  34. };
  35. MPT_BINARY_STRUCT(XMFileHeader, 80)
  36. // XM Instrument Data
  37. struct XMInstrument
  38. {
  39. // Envelope Flags
  40. enum XMEnvelopeFlags
  41. {
  42. envEnabled = 0x01,
  43. envSustain = 0x02,
  44. envLoop = 0x04,
  45. };
  46. uint8le sampleMap[96]; // Note -> Sample assignment
  47. uint16le volEnv[24]; // Volume envelope nodes / values (0...64)
  48. uint16le panEnv[24]; // Panning envelope nodes / values (0...63)
  49. uint8le volPoints; // Volume envelope length
  50. uint8le panPoints; // Panning envelope length
  51. uint8le volSustain; // Volume envelope sustain point
  52. uint8le volLoopStart; // Volume envelope loop start point
  53. uint8le volLoopEnd; // Volume envelope loop end point
  54. uint8le panSustain; // Panning envelope sustain point
  55. uint8le panLoopStart; // Panning envelope loop start point
  56. uint8le panLoopEnd; // Panning envelope loop end point
  57. uint8le volFlags; // Volume envelope flags
  58. uint8le panFlags; // Panning envelope flags
  59. uint8le vibType; // Sample Auto-Vibrato Type
  60. uint8le vibSweep; // Sample Auto-Vibrato Sweep
  61. uint8le vibDepth; // Sample Auto-Vibrato Depth
  62. uint8le vibRate; // Sample Auto-Vibrato Rate
  63. uint16le volFade; // Volume Fade-Out
  64. uint8le midiEnabled; // MIDI Out Enabled (0 / 1)
  65. uint8le midiChannel; // MIDI Channel (0...15)
  66. uint16le midiProgram; // MIDI Program (0...127)
  67. uint16le pitchWheelRange; // MIDI Pitch Wheel Range (0...36 halftones)
  68. uint8le muteComputer; // Mute instrument if MIDI is enabled (0 / 1)
  69. uint8le reserved[15]; // Reserved
  70. enum EnvType
  71. {
  72. EnvTypeVol,
  73. EnvTypePan,
  74. };
  75. // Convert OpenMPT's internal envelope representation to XM envelope data.
  76. void ConvertEnvelopeToXM(const InstrumentEnvelope &mptEnv, uint8le &numPoints, uint8le &flags, uint8le &sustain, uint8le &loopStart, uint8le &loopEnd, EnvType env);
  77. // Convert XM envelope data to an OpenMPT's internal envelope representation.
  78. void ConvertEnvelopeToMPT(InstrumentEnvelope &mptEnv, uint8 numPoints, uint8 flags, uint8 sustain, uint8 loopStart, uint8 loopEnd, EnvType env) const;
  79. // Convert OpenMPT's internal sample representation to an XMInstrument.
  80. uint16 ConvertToXM(const ModInstrument &mptIns, bool compatibilityExport);
  81. // Convert an XMInstrument to OpenMPT's internal instrument representation.
  82. void ConvertToMPT(ModInstrument &mptIns) const;
  83. // Apply auto-vibrato settings from sample to file.
  84. void ApplyAutoVibratoToXM(const ModSample &mptSmp, MODTYPE fromType);
  85. // Apply auto-vibrato settings from file to a sample.
  86. void ApplyAutoVibratoToMPT(ModSample &mptSmp) const;
  87. // Get a list of samples that should be written to the file.
  88. std::vector<SAMPLEINDEX> GetSampleList(const ModInstrument &mptIns, bool compatibilityExport) const;
  89. };
  90. MPT_BINARY_STRUCT(XMInstrument, 230)
  91. // XM Instrument Header
  92. struct XMInstrumentHeader
  93. {
  94. uint32le size; // Size of XMInstrumentHeader + XMInstrument
  95. char name[22]; // Instrument Name, not null-terminated (any nulls are treated as spaces)
  96. uint8le type; // Instrument Type (Apparently FT2 writes some crap here, but it's the same crap for all instruments of the same module!)
  97. uint16le numSamples; // Number of Samples associated with instrument
  98. uint32le sampleHeaderSize; // Size of XMSample
  99. XMInstrument instrument;
  100. // Write stuff to the header that's always necessary (also for empty instruments)
  101. void Finalise();
  102. // Convert OpenMPT's internal sample representation to an XMInstrument.
  103. void ConvertToXM(const ModInstrument &mptIns, bool compatibilityExport);
  104. // Convert an XMInstrument to OpenMPT's internal instrument representation.
  105. void ConvertToMPT(ModInstrument &mptIns) const;
  106. };
  107. MPT_BINARY_STRUCT(XMInstrumentHeader, 263)
  108. // XI Instrument Header
  109. struct XIInstrumentHeader
  110. {
  111. enum
  112. {
  113. fileVersion = 0x102,
  114. };
  115. char signature[21]; // "Extended Instrument: "
  116. char name[22]; // Instrument Name, not null-terminated (any nulls are treated as spaces)
  117. uint8le eof; // DOS EOF Character (0x1A)
  118. char trackerName[20]; // Software that was used to create the XI file
  119. uint16le version; // File Version (1.02)
  120. XMInstrument instrument;
  121. uint16le numSamples; // Number of embedded sample headers + samples
  122. // Convert OpenMPT's internal sample representation to an XIInstrumentHeader.
  123. void ConvertToXM(const ModInstrument &mptIns, bool compatibilityExport);
  124. // Convert an XIInstrumentHeader to OpenMPT's internal instrument representation.
  125. void ConvertToMPT(ModInstrument &mptIns) const;
  126. };
  127. MPT_BINARY_STRUCT(XIInstrumentHeader, 298)
  128. // XM Sample Header
  129. struct XMSample
  130. {
  131. enum XMSampleFlags
  132. {
  133. sampleLoop = 0x01,
  134. sampleBidiLoop = 0x02,
  135. sample16Bit = 0x10,
  136. sampleStereo = 0x20,
  137. sampleADPCM = 0xAD, // MODPlugin :(
  138. };
  139. uint32le length; // Sample Length (in bytes)
  140. uint32le loopStart; // Loop Start (in bytes)
  141. uint32le loopLength; // Loop Length (in bytes)
  142. uint8le vol; // Default Volume
  143. int8le finetune; // Sample Finetune
  144. uint8le flags; // Sample Flags
  145. uint8le pan; // Sample Panning
  146. int8le relnote; // Sample Transpose
  147. uint8le reserved; // Reserved (abused for ModPlug's ADPCM compression)
  148. char name[22]; // Sample Name, not null-terminated (any nulls are treated as spaces)
  149. // Convert OpenMPT's internal sample representation to an XMSample.
  150. void ConvertToXM(const ModSample &mptSmp, MODTYPE fromType, bool compatibilityExport);
  151. // Convert an XMSample to OpenMPT's internal sample representation.
  152. void ConvertToMPT(ModSample &mptSmp) const;
  153. // Retrieve the internal sample format flags for this instrument.
  154. SampleIO GetSampleFormat() const;
  155. };
  156. MPT_BINARY_STRUCT(XMSample, 40)
  157. OPENMPT_NAMESPACE_END