XM (standing for eXtended Module) is a popular module music file format, that was introduced in 1994 in FastTracker2 by Triton demo group. Akin to MOD files, it bundles both digital samples (instruments) and instructions on which note to play at what time (patterns), which provides good audio quality with relatively small file size. Audio is reproducible without relying on the sound of particular hardware samplers or synths.
This page hosts a formal specification of Extended Module using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.
All parsing code for C++11/STL generated by Kaitai Struct depends on the C++/STL runtime library. You have to install it before you can parse data.
For C++, the easiest way is to clone the runtime library sources and build them along with your project.
Using Kaitai Struct in C++/STL usually consists of 3 steps.
std::istream
). One can open local file for that, or use existing std::string
or char*
buffer.
#include <fstream>
std::ifstream is("path/to/local/file.xm", std::ifstream::binary);
#include <sstream>
std::istringstream is(str);
#include <sstream>
const char buf[] = { ... };
std::string str(buf, sizeof buf);
std::istringstream is(str);
#include "kaitai/kaitaistream.h"
kaitai::kstream ks(&is);
fasttracker_xm_module_t data(&ks);
After that, one can get various attributes from the structure by invoking getter methods like:
data.preheader() // => get preheader
#pragma once
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "kaitai/kaitaistruct.h"
#include <stdint.h>
#include <memory>
#include <vector>
#if KAITAI_STRUCT_VERSION < 9000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required"
#endif
/**
* XM (standing for eXtended Module) is a popular module music file
* format, that was introduced in 1994 in FastTracker2 by Triton demo
* group. Akin to MOD files, it bundles both digital samples
* (instruments) and instructions on which note to play at what time
* (patterns), which provides good audio quality with relatively small
* file size. Audio is reproducible without relying on the sound of
* particular hardware samplers or synths.
* \sa http://sid.ethz.ch/debian/milkytracker/milkytracker-0.90.85%2Bdfsg/resources/reference/xm-form.txt
* ftp://ftp.modland.com/pub/documents/format_documentation/FastTracker%202%20v2.04%20(.xm).html
* Source
*/
class fasttracker_xm_module_t : public kaitai::kstruct {
public:
class preheader_t;
class pattern_t;
class flags_t;
class header_t;
class instrument_t;
fasttracker_xm_module_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~fasttracker_xm_module_t();
class preheader_t : public kaitai::kstruct {
public:
class version_t;
preheader_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~preheader_t();
class version_t : public kaitai::kstruct {
public:
version_t(kaitai::kstream* p__io, fasttracker_xm_module_t::preheader_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~version_t();
private:
bool f_value;
int32_t m_value;
public:
int32_t value();
private:
uint8_t m_minor;
uint8_t m_major;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::preheader_t* m__parent;
public:
/**
* currently 0x04
*/
uint8_t minor() const { return m_minor; }
/**
* currently 0x01
*/
uint8_t major() const { return m_major; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::preheader_t* _parent() const { return m__parent; }
};
private:
std::string m_signature0;
std::string m_module_name;
std::string m_signature1;
std::string m_tracker_name;
std::unique_ptr<version_t> m_version_number;
uint32_t m_header_size;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t* m__parent;
public:
std::string signature0() const { return m_signature0; }
/**
* Module name, padded with zeroes
*/
std::string module_name() const { return m_module_name; }
std::string signature1() const { return m_signature1; }
/**
* Tracker name
*/
std::string tracker_name() const { return m_tracker_name; }
/**
* Format versions below [0x01, 0x04] have a LOT of differences. Check this field!
*/
version_t* version_number() const { return m_version_number.get(); }
/**
* Header size << Calculated FROM THIS OFFSET, not from the beginning of the file! >>
*/
uint32_t header_size() const { return m_header_size; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t* _parent() const { return m__parent; }
};
class pattern_t : public kaitai::kstruct {
public:
class header_t;
pattern_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~pattern_t();
class header_t : public kaitai::kstruct {
public:
class header_main_t;
header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::pattern_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~header_t();
class header_main_t : public kaitai::kstruct {
public:
header_main_t(kaitai::kstream* p__io, fasttracker_xm_module_t::pattern_t::header_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~header_main_t();
private:
bool f_num_rows;
int32_t m_num_rows;
public:
int32_t num_rows();
private:
uint8_t m_packing_type;
uint16_t m_num_rows_raw;
uint16_t m_len_packed_pattern;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::pattern_t::header_t* m__parent;
public:
/**
* Packing type (always 0)
*/
uint8_t packing_type() const { return m_packing_type; }
/**
* Number of rows in pattern (1..256)
*/
uint16_t num_rows_raw() const { return m_num_rows_raw; }
/**
* Packed pattern data size
*/
uint16_t len_packed_pattern() const { return m_len_packed_pattern; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::pattern_t::header_t* _parent() const { return m__parent; }
};
private:
uint32_t m_header_length;
std::unique_ptr<header_main_t> m_main;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::pattern_t* m__parent;
std::string m__raw_main;
std::unique_ptr<kaitai::kstream> m__io__raw_main;
public:
/**
* Pattern header length
*/
uint32_t header_length() const { return m_header_length; }
header_main_t* main() const { return m_main.get(); }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::pattern_t* _parent() const { return m__parent; }
std::string _raw_main() const { return m__raw_main; }
kaitai::kstream* _io__raw_main() const { return m__io__raw_main.get(); }
};
private:
std::unique_ptr<header_t> m_header;
std::string m_packed_data;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t* m__parent;
public:
header_t* header() const { return m_header.get(); }
std::string packed_data() const { return m_packed_data; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t* _parent() const { return m__parent; }
};
class flags_t : public kaitai::kstruct {
public:
flags_t(kaitai::kstream* p__io, fasttracker_xm_module_t::header_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~flags_t();
private:
uint64_t m_reserved;
bool m_freq_table_type;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::header_t* m__parent;
public:
uint64_t reserved() const { return m_reserved; }
/**
* 0 = Amiga frequency table (see below); 1 = Linear frequency table
*/
bool freq_table_type() const { return m_freq_table_type; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::header_t* _parent() const { return m__parent; }
};
class header_t : public kaitai::kstruct {
public:
header_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~header_t();
private:
uint16_t m_song_length;
uint16_t m_restart_position;
uint16_t m_num_channels;
uint16_t m_num_patterns;
uint16_t m_num_instruments;
std::unique_ptr<flags_t> m_flags;
uint16_t m_default_tempo;
uint16_t m_default_bpm;
std::unique_ptr<std::vector<uint8_t>> m_pattern_order_table;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t* m__parent;
public:
/**
* Song length (in pattern order table)
*/
uint16_t song_length() const { return m_song_length; }
uint16_t restart_position() const { return m_restart_position; }
/**
* (2,4,6,8,10,...,32)
*/
uint16_t num_channels() const { return m_num_channels; }
/**
* (max 256)
*/
uint16_t num_patterns() const { return m_num_patterns; }
/**
* (max 128)
*/
uint16_t num_instruments() const { return m_num_instruments; }
flags_t* flags() const { return m_flags.get(); }
uint16_t default_tempo() const { return m_default_tempo; }
uint16_t default_bpm() const { return m_default_bpm; }
/**
* max 256
*/
std::vector<uint8_t>* pattern_order_table() const { return m_pattern_order_table.get(); }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t* _parent() const { return m__parent; }
};
/**
* XM's notion of "instrument" typically constitutes of a
* instrument metadata and one or several samples. Metadata
* includes:
*
* * instrument's name
* * instruction of which sample to use for which note
* * volume and panning envelopes and looping instructions
* * vibrato settings
*/
class instrument_t : public kaitai::kstruct {
public:
class header_t;
class extra_header_t;
class samples_data_t;
class sample_header_t;
instrument_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~instrument_t();
class header_t : public kaitai::kstruct {
public:
header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~header_t();
private:
std::string m_name;
uint8_t m_type;
uint16_t m_num_samples;
std::unique_ptr<extra_header_t> m_extra_header;
bool n_extra_header;
public:
bool _is_null_extra_header() { extra_header(); return n_extra_header; };
private:
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::instrument_t* m__parent;
public:
std::string name() const { return m_name; }
/**
* Usually zero, but this seems pretty random, don't assume it's zero
*/
uint8_t type() const { return m_type; }
uint16_t num_samples() const { return m_num_samples; }
extra_header_t* extra_header() const { return m_extra_header.get(); }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::instrument_t* _parent() const { return m__parent; }
};
class extra_header_t : public kaitai::kstruct {
public:
class envelope_point_t;
enum type_t {
TYPE_TRUE = 0,
TYPE_SUSTAIN = 1,
TYPE_LOOP = 2
};
extra_header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t::header_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~extra_header_t();
/**
* Envelope frame-counters work in range 0..FFFFh (0..65535 dec).
* BUT! FT2 only itself supports only range 0..FFh (0..255 dec).
* Some other trackers (like SoundTracker for Unix), however, can use the full range 0..FFFF, so it should be supported.
* !!TIP: This is also a good way to detect if the module has been made with FT2 or not. (In case the tracker name is brain- deadly left unchanged!)
* Of course it does not help if all instruments have the values inside FT2 supported range.
* The value-field of the envelope point is ranged between 00..3Fh (0..64 dec).
*/
class envelope_point_t : public kaitai::kstruct {
public:
envelope_point_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t::extra_header_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~envelope_point_t();
private:
uint16_t m_x;
uint16_t m_y;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::instrument_t::extra_header_t* m__parent;
public:
/**
* Frame number of the point
*/
uint16_t x() const { return m_x; }
/**
* Value of the point
*/
uint16_t y() const { return m_y; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::instrument_t::extra_header_t* _parent() const { return m__parent; }
};
private:
uint32_t m_len_sample_header;
std::unique_ptr<std::vector<uint8_t>> m_idx_sample_per_note;
std::unique_ptr<std::vector<std::unique_ptr<envelope_point_t>>> m_volume_points;
std::unique_ptr<std::vector<std::unique_ptr<envelope_point_t>>> m_panning_points;
uint8_t m_num_volume_points;
uint8_t m_num_panning_points;
uint8_t m_volume_sustain_point;
uint8_t m_volume_loop_start_point;
uint8_t m_volume_loop_end_point;
uint8_t m_panning_sustain_point;
uint8_t m_panning_loop_start_point;
uint8_t m_panning_loop_end_point;
type_t m_volume_type;
type_t m_panning_type;
uint8_t m_vibrato_type;
uint8_t m_vibrato_sweep;
uint8_t m_vibrato_depth;
uint8_t m_vibrato_rate;
uint16_t m_volume_fadeout;
uint16_t m_reserved;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::instrument_t::header_t* m__parent;
public:
uint32_t len_sample_header() const { return m_len_sample_header; }
/**
* Index of sample that should be used for any particular
* note. In the simplest case, where it's only one sample
* is available, it's an array of full of zeroes.
*/
std::vector<uint8_t>* idx_sample_per_note() const { return m_idx_sample_per_note.get(); }
/**
* Points for volume envelope. Only `num_volume_points` will be actually used.
*/
std::vector<std::unique_ptr<envelope_point_t>>* volume_points() const { return m_volume_points.get(); }
/**
* Points for panning envelope. Only `num_panning_points` will be actually used.
*/
std::vector<std::unique_ptr<envelope_point_t>>* panning_points() const { return m_panning_points.get(); }
uint8_t num_volume_points() const { return m_num_volume_points; }
uint8_t num_panning_points() const { return m_num_panning_points; }
uint8_t volume_sustain_point() const { return m_volume_sustain_point; }
uint8_t volume_loop_start_point() const { return m_volume_loop_start_point; }
uint8_t volume_loop_end_point() const { return m_volume_loop_end_point; }
uint8_t panning_sustain_point() const { return m_panning_sustain_point; }
uint8_t panning_loop_start_point() const { return m_panning_loop_start_point; }
uint8_t panning_loop_end_point() const { return m_panning_loop_end_point; }
type_t volume_type() const { return m_volume_type; }
type_t panning_type() const { return m_panning_type; }
uint8_t vibrato_type() const { return m_vibrato_type; }
uint8_t vibrato_sweep() const { return m_vibrato_sweep; }
uint8_t vibrato_depth() const { return m_vibrato_depth; }
uint8_t vibrato_rate() const { return m_vibrato_rate; }
uint16_t volume_fadeout() const { return m_volume_fadeout; }
uint16_t reserved() const { return m_reserved; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::instrument_t::header_t* _parent() const { return m__parent; }
};
/**
* The saved data uses simple delta-encoding to achieve better compression ratios (when compressed with pkzip, etc.)
* Pseudocode for converting the delta-coded data to normal data,
* old = 0;
* for i in range(data_len):
* new = sample[i] + old;
* sample[i] = new;
* old = new;
*/
class samples_data_t : public kaitai::kstruct {
public:
samples_data_t(sample_header_t* p_header, kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~samples_data_t();
private:
std::string m_data;
sample_header_t* m_header;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::instrument_t* m__parent;
public:
std::string data() const { return m_data; }
sample_header_t* header() const { return m_header; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::instrument_t* _parent() const { return m__parent; }
};
class sample_header_t : public kaitai::kstruct {
public:
class loop_type_t;
sample_header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~sample_header_t();
class loop_type_t : public kaitai::kstruct {
public:
enum loop_type_t {
LOOP_TYPE_NONE = 0,
LOOP_TYPE_FORWARD = 1,
LOOP_TYPE_PING_PONG = 2
};
loop_type_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t::sample_header_t* p__parent = nullptr, fasttracker_xm_module_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~loop_type_t();
private:
uint64_t m_reserved0;
bool m_is_sample_data_16_bit;
uint64_t m_reserved1;
loop_type_t m_loop_type;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::instrument_t::sample_header_t* m__parent;
public:
uint64_t reserved0() const { return m_reserved0; }
bool is_sample_data_16_bit() const { return m_is_sample_data_16_bit; }
uint64_t reserved1() const { return m_reserved1; }
loop_type_t loop_type() const { return m_loop_type; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::instrument_t::sample_header_t* _parent() const { return m__parent; }
};
private:
uint32_t m_sample_length;
uint32_t m_sample_loop_start;
uint32_t m_sample_loop_length;
uint8_t m_volume;
int8_t m_fine_tune;
std::unique_ptr<loop_type_t> m_type;
uint8_t m_panning;
int8_t m_relative_note_number;
uint8_t m_reserved;
std::string m_name;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t::instrument_t* m__parent;
public:
uint32_t sample_length() const { return m_sample_length; }
uint32_t sample_loop_start() const { return m_sample_loop_start; }
uint32_t sample_loop_length() const { return m_sample_loop_length; }
uint8_t volume() const { return m_volume; }
/**
* -16..+15
*/
int8_t fine_tune() const { return m_fine_tune; }
loop_type_t* type() const { return m_type.get(); }
/**
* (0-255)
*/
uint8_t panning() const { return m_panning; }
int8_t relative_note_number() const { return m_relative_note_number; }
uint8_t reserved() const { return m_reserved; }
std::string name() const { return m_name; }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t::instrument_t* _parent() const { return m__parent; }
};
private:
uint32_t m_header_size;
std::unique_ptr<header_t> m_header;
std::unique_ptr<std::vector<std::unique_ptr<sample_header_t>>> m_samples_headers;
std::unique_ptr<std::vector<std::unique_ptr<samples_data_t>>> m_samples;
fasttracker_xm_module_t* m__root;
fasttracker_xm_module_t* m__parent;
std::string m__raw_header;
std::unique_ptr<kaitai::kstream> m__io__raw_header;
public:
/**
* Instrument size << header that is >>
* << "Instrument Size" field tends to be more than the actual size of the structure documented here (it includes also the extended instrument sample header above). So remember to check it and skip the additional bytes before the first sample header >>
*/
uint32_t header_size() const { return m_header_size; }
header_t* header() const { return m_header.get(); }
std::vector<std::unique_ptr<sample_header_t>>* samples_headers() const { return m_samples_headers.get(); }
std::vector<std::unique_ptr<samples_data_t>>* samples() const { return m_samples.get(); }
fasttracker_xm_module_t* _root() const { return m__root; }
fasttracker_xm_module_t* _parent() const { return m__parent; }
std::string _raw_header() const { return m__raw_header; }
kaitai::kstream* _io__raw_header() const { return m__io__raw_header.get(); }
};
private:
std::unique_ptr<preheader_t> m_preheader;
std::unique_ptr<header_t> m_header;
std::unique_ptr<std::vector<std::unique_ptr<pattern_t>>> m_patterns;
std::unique_ptr<std::vector<std::unique_ptr<instrument_t>>> m_instruments;
fasttracker_xm_module_t* m__root;
kaitai::kstruct* m__parent;
std::string m__raw_header;
std::unique_ptr<kaitai::kstream> m__io__raw_header;
public:
preheader_t* preheader() const { return m_preheader.get(); }
header_t* header() const { return m_header.get(); }
std::vector<std::unique_ptr<pattern_t>>* patterns() const { return m_patterns.get(); }
std::vector<std::unique_ptr<instrument_t>>* instruments() const { return m_instruments.get(); }
fasttracker_xm_module_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
std::string _raw_header() const { return m__raw_header; }
kaitai::kstream* _io__raw_header() const { return m__io__raw_header.get(); }
};
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "fasttracker_xm_module.h"
#include "kaitai/exceptions.h"
fasttracker_xm_module_t::fasttracker_xm_module_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_preheader = nullptr;
m_header = nullptr;
m__io__raw_header = nullptr;
m_patterns = nullptr;
m_instruments = nullptr;
_read();
}
void fasttracker_xm_module_t::_read() {
m_preheader = std::unique_ptr<preheader_t>(new preheader_t(m__io, this, m__root));
m__raw_header = m__io->read_bytes((preheader()->header_size() - 4));
m__io__raw_header = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_header));
m_header = std::unique_ptr<header_t>(new header_t(m__io__raw_header.get(), this, m__root));
m_patterns = std::unique_ptr<std::vector<std::unique_ptr<pattern_t>>>(new std::vector<std::unique_ptr<pattern_t>>());
const int l_patterns = header()->num_patterns();
for (int i = 0; i < l_patterns; i++) {
m_patterns->push_back(std::move(std::unique_ptr<pattern_t>(new pattern_t(m__io, this, m__root))));
}
m_instruments = std::unique_ptr<std::vector<std::unique_ptr<instrument_t>>>(new std::vector<std::unique_ptr<instrument_t>>());
const int l_instruments = header()->num_instruments();
for (int i = 0; i < l_instruments; i++) {
m_instruments->push_back(std::move(std::unique_ptr<instrument_t>(new instrument_t(m__io, this, m__root))));
}
}
fasttracker_xm_module_t::~fasttracker_xm_module_t() {
_clean_up();
}
void fasttracker_xm_module_t::_clean_up() {
}
fasttracker_xm_module_t::preheader_t::preheader_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_version_number = nullptr;
_read();
}
void fasttracker_xm_module_t::preheader_t::_read() {
m_signature0 = m__io->read_bytes(17);
if (!(signature0() == std::string("\x45\x78\x74\x65\x6E\x64\x65\x64\x20\x4D\x6F\x64\x75\x6C\x65\x3A\x20", 17))) {
throw kaitai::validation_not_equal_error<std::string>(std::string("\x45\x78\x74\x65\x6E\x64\x65\x64\x20\x4D\x6F\x64\x75\x6C\x65\x3A\x20", 17), signature0(), _io(), std::string("/types/preheader/seq/0"));
}
m_module_name = kaitai::kstream::bytes_to_str(kaitai::kstream::bytes_terminate(m__io->read_bytes(20), 0, false), std::string("utf-8"));
m_signature1 = m__io->read_bytes(1);
if (!(signature1() == std::string("\x1A", 1))) {
throw kaitai::validation_not_equal_error<std::string>(std::string("\x1A", 1), signature1(), _io(), std::string("/types/preheader/seq/2"));
}
m_tracker_name = kaitai::kstream::bytes_to_str(kaitai::kstream::bytes_terminate(m__io->read_bytes(20), 0, false), std::string("utf-8"));
m_version_number = std::unique_ptr<version_t>(new version_t(m__io, this, m__root));
m_header_size = m__io->read_u4le();
}
fasttracker_xm_module_t::preheader_t::~preheader_t() {
_clean_up();
}
void fasttracker_xm_module_t::preheader_t::_clean_up() {
}
fasttracker_xm_module_t::preheader_t::version_t::version_t(kaitai::kstream* p__io, fasttracker_xm_module_t::preheader_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
f_value = false;
_read();
}
void fasttracker_xm_module_t::preheader_t::version_t::_read() {
m_minor = m__io->read_u1();
m_major = m__io->read_u1();
}
fasttracker_xm_module_t::preheader_t::version_t::~version_t() {
_clean_up();
}
void fasttracker_xm_module_t::preheader_t::version_t::_clean_up() {
}
int32_t fasttracker_xm_module_t::preheader_t::version_t::value() {
if (f_value)
return m_value;
m_value = ((major() << 8) | minor());
f_value = true;
return m_value;
}
fasttracker_xm_module_t::pattern_t::pattern_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_header = nullptr;
_read();
}
void fasttracker_xm_module_t::pattern_t::_read() {
m_header = std::unique_ptr<header_t>(new header_t(m__io, this, m__root));
m_packed_data = m__io->read_bytes(header()->main()->len_packed_pattern());
}
fasttracker_xm_module_t::pattern_t::~pattern_t() {
_clean_up();
}
void fasttracker_xm_module_t::pattern_t::_clean_up() {
}
fasttracker_xm_module_t::pattern_t::header_t::header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::pattern_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_main = nullptr;
m__io__raw_main = nullptr;
_read();
}
void fasttracker_xm_module_t::pattern_t::header_t::_read() {
m_header_length = m__io->read_u4le();
m__raw_main = m__io->read_bytes((header_length() - 4));
m__io__raw_main = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_main));
m_main = std::unique_ptr<header_main_t>(new header_main_t(m__io__raw_main.get(), this, m__root));
}
fasttracker_xm_module_t::pattern_t::header_t::~header_t() {
_clean_up();
}
void fasttracker_xm_module_t::pattern_t::header_t::_clean_up() {
}
fasttracker_xm_module_t::pattern_t::header_t::header_main_t::header_main_t(kaitai::kstream* p__io, fasttracker_xm_module_t::pattern_t::header_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
f_num_rows = false;
_read();
}
void fasttracker_xm_module_t::pattern_t::header_t::header_main_t::_read() {
m_packing_type = m__io->read_u1();
switch (_root()->preheader()->version_number()->value()) {
case 258: {
m_num_rows_raw = m__io->read_u1();
break;
}
default: {
m_num_rows_raw = m__io->read_u2le();
break;
}
}
m_len_packed_pattern = m__io->read_u2le();
}
fasttracker_xm_module_t::pattern_t::header_t::header_main_t::~header_main_t() {
_clean_up();
}
void fasttracker_xm_module_t::pattern_t::header_t::header_main_t::_clean_up() {
}
int32_t fasttracker_xm_module_t::pattern_t::header_t::header_main_t::num_rows() {
if (f_num_rows)
return m_num_rows;
m_num_rows = (num_rows_raw() + ((_root()->preheader()->version_number()->value() == 258) ? (1) : (0)));
f_num_rows = true;
return m_num_rows;
}
fasttracker_xm_module_t::flags_t::flags_t(kaitai::kstream* p__io, fasttracker_xm_module_t::header_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
_read();
}
void fasttracker_xm_module_t::flags_t::_read() {
m_reserved = m__io->read_bits_int_be(15);
m_freq_table_type = m__io->read_bits_int_be(1);
}
fasttracker_xm_module_t::flags_t::~flags_t() {
_clean_up();
}
void fasttracker_xm_module_t::flags_t::_clean_up() {
}
fasttracker_xm_module_t::header_t::header_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_flags = nullptr;
m_pattern_order_table = nullptr;
_read();
}
void fasttracker_xm_module_t::header_t::_read() {
m_song_length = m__io->read_u2le();
m_restart_position = m__io->read_u2le();
m_num_channels = m__io->read_u2le();
m_num_patterns = m__io->read_u2le();
m_num_instruments = m__io->read_u2le();
m_flags = std::unique_ptr<flags_t>(new flags_t(m__io, this, m__root));
m_default_tempo = m__io->read_u2le();
m_default_bpm = m__io->read_u2le();
m_pattern_order_table = std::unique_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>());
const int l_pattern_order_table = 256;
for (int i = 0; i < l_pattern_order_table; i++) {
m_pattern_order_table->push_back(std::move(m__io->read_u1()));
}
}
fasttracker_xm_module_t::header_t::~header_t() {
_clean_up();
}
void fasttracker_xm_module_t::header_t::_clean_up() {
}
fasttracker_xm_module_t::instrument_t::instrument_t(kaitai::kstream* p__io, fasttracker_xm_module_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_header = nullptr;
m__io__raw_header = nullptr;
m_samples_headers = nullptr;
m_samples = nullptr;
_read();
}
void fasttracker_xm_module_t::instrument_t::_read() {
m_header_size = m__io->read_u4le();
m__raw_header = m__io->read_bytes((header_size() - 4));
m__io__raw_header = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_header));
m_header = std::unique_ptr<header_t>(new header_t(m__io__raw_header.get(), this, m__root));
m_samples_headers = std::unique_ptr<std::vector<std::unique_ptr<sample_header_t>>>(new std::vector<std::unique_ptr<sample_header_t>>());
const int l_samples_headers = header()->num_samples();
for (int i = 0; i < l_samples_headers; i++) {
m_samples_headers->push_back(std::move(std::unique_ptr<sample_header_t>(new sample_header_t(m__io, this, m__root))));
}
m_samples = std::unique_ptr<std::vector<std::unique_ptr<samples_data_t>>>(new std::vector<std::unique_ptr<samples_data_t>>());
const int l_samples = header()->num_samples();
for (int i = 0; i < l_samples; i++) {
m_samples->push_back(std::move(std::unique_ptr<samples_data_t>(new samples_data_t(samples_headers()->at(i), m__io, this, m__root))));
}
}
fasttracker_xm_module_t::instrument_t::~instrument_t() {
_clean_up();
}
void fasttracker_xm_module_t::instrument_t::_clean_up() {
}
fasttracker_xm_module_t::instrument_t::header_t::header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_extra_header = nullptr;
_read();
}
void fasttracker_xm_module_t::instrument_t::header_t::_read() {
m_name = kaitai::kstream::bytes_to_str(kaitai::kstream::bytes_terminate(m__io->read_bytes(22), 0, false), std::string("utf-8"));
m_type = m__io->read_u1();
m_num_samples = m__io->read_u2le();
n_extra_header = true;
if (num_samples() > 0) {
n_extra_header = false;
m_extra_header = std::unique_ptr<extra_header_t>(new extra_header_t(m__io, this, m__root));
}
}
fasttracker_xm_module_t::instrument_t::header_t::~header_t() {
_clean_up();
}
void fasttracker_xm_module_t::instrument_t::header_t::_clean_up() {
if (!n_extra_header) {
}
}
fasttracker_xm_module_t::instrument_t::extra_header_t::extra_header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t::header_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_idx_sample_per_note = nullptr;
m_volume_points = nullptr;
m_panning_points = nullptr;
_read();
}
void fasttracker_xm_module_t::instrument_t::extra_header_t::_read() {
m_len_sample_header = m__io->read_u4le();
m_idx_sample_per_note = std::unique_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>());
const int l_idx_sample_per_note = 96;
for (int i = 0; i < l_idx_sample_per_note; i++) {
m_idx_sample_per_note->push_back(std::move(m__io->read_u1()));
}
m_volume_points = std::unique_ptr<std::vector<std::unique_ptr<envelope_point_t>>>(new std::vector<std::unique_ptr<envelope_point_t>>());
const int l_volume_points = 12;
for (int i = 0; i < l_volume_points; i++) {
m_volume_points->push_back(std::move(std::unique_ptr<envelope_point_t>(new envelope_point_t(m__io, this, m__root))));
}
m_panning_points = std::unique_ptr<std::vector<std::unique_ptr<envelope_point_t>>>(new std::vector<std::unique_ptr<envelope_point_t>>());
const int l_panning_points = 12;
for (int i = 0; i < l_panning_points; i++) {
m_panning_points->push_back(std::move(std::unique_ptr<envelope_point_t>(new envelope_point_t(m__io, this, m__root))));
}
m_num_volume_points = m__io->read_u1();
m_num_panning_points = m__io->read_u1();
m_volume_sustain_point = m__io->read_u1();
m_volume_loop_start_point = m__io->read_u1();
m_volume_loop_end_point = m__io->read_u1();
m_panning_sustain_point = m__io->read_u1();
m_panning_loop_start_point = m__io->read_u1();
m_panning_loop_end_point = m__io->read_u1();
m_volume_type = static_cast<fasttracker_xm_module_t::instrument_t::extra_header_t::type_t>(m__io->read_u1());
m_panning_type = static_cast<fasttracker_xm_module_t::instrument_t::extra_header_t::type_t>(m__io->read_u1());
m_vibrato_type = m__io->read_u1();
m_vibrato_sweep = m__io->read_u1();
m_vibrato_depth = m__io->read_u1();
m_vibrato_rate = m__io->read_u1();
m_volume_fadeout = m__io->read_u2le();
m_reserved = m__io->read_u2le();
}
fasttracker_xm_module_t::instrument_t::extra_header_t::~extra_header_t() {
_clean_up();
}
void fasttracker_xm_module_t::instrument_t::extra_header_t::_clean_up() {
}
fasttracker_xm_module_t::instrument_t::extra_header_t::envelope_point_t::envelope_point_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t::extra_header_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
_read();
}
void fasttracker_xm_module_t::instrument_t::extra_header_t::envelope_point_t::_read() {
m_x = m__io->read_u2le();
m_y = m__io->read_u2le();
}
fasttracker_xm_module_t::instrument_t::extra_header_t::envelope_point_t::~envelope_point_t() {
_clean_up();
}
void fasttracker_xm_module_t::instrument_t::extra_header_t::envelope_point_t::_clean_up() {
}
fasttracker_xm_module_t::instrument_t::samples_data_t::samples_data_t(sample_header_t* p_header, kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_header = p_header;
_read();
}
void fasttracker_xm_module_t::instrument_t::samples_data_t::_read() {
m_data = m__io->read_bytes((header()->sample_length() * ((header()->type()->is_sample_data_16_bit()) ? (2) : (1))));
}
fasttracker_xm_module_t::instrument_t::samples_data_t::~samples_data_t() {
_clean_up();
}
void fasttracker_xm_module_t::instrument_t::samples_data_t::_clean_up() {
}
fasttracker_xm_module_t::instrument_t::sample_header_t::sample_header_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_type = nullptr;
_read();
}
void fasttracker_xm_module_t::instrument_t::sample_header_t::_read() {
m_sample_length = m__io->read_u4le();
m_sample_loop_start = m__io->read_u4le();
m_sample_loop_length = m__io->read_u4le();
m_volume = m__io->read_u1();
m_fine_tune = m__io->read_s1();
m_type = std::unique_ptr<loop_type_t>(new loop_type_t(m__io, this, m__root));
m_panning = m__io->read_u1();
m_relative_note_number = m__io->read_s1();
m_reserved = m__io->read_u1();
m_name = kaitai::kstream::bytes_to_str(kaitai::kstream::bytes_terminate(m__io->read_bytes(22), 0, false), std::string("utf-8"));
}
fasttracker_xm_module_t::instrument_t::sample_header_t::~sample_header_t() {
_clean_up();
}
void fasttracker_xm_module_t::instrument_t::sample_header_t::_clean_up() {
}
fasttracker_xm_module_t::instrument_t::sample_header_t::loop_type_t::loop_type_t(kaitai::kstream* p__io, fasttracker_xm_module_t::instrument_t::sample_header_t* p__parent, fasttracker_xm_module_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
_read();
}
void fasttracker_xm_module_t::instrument_t::sample_header_t::loop_type_t::_read() {
m_reserved0 = m__io->read_bits_int_be(3);
m_is_sample_data_16_bit = m__io->read_bits_int_be(1);
m_reserved1 = m__io->read_bits_int_be(2);
m_loop_type = static_cast<fasttracker_xm_module_t::instrument_t::sample_header_t::loop_type_t::loop_type_t>(m__io->read_bits_int_be(2));
}
fasttracker_xm_module_t::instrument_t::sample_header_t::loop_type_t::~loop_type_t() {
_clean_up();
}
void fasttracker_xm_module_t::instrument_t::sample_header_t::loop_type_t::_clean_up() {
}