Documentation ¶
Overview ¶
Package drum implements the decoding of .splice drum machine files. See golang-challenge.com/go-challenge1/ for more information
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeFile ¶
EncodeFile encodes a given pattern to a drum machine file at the provided path. If a file already exists at the path, it will be overwritten.
See decoder.go for information on the layout of the file.
Types ¶
type Pattern ¶
type Pattern struct { Version string // The version that generated the pattern. Tempo float32 // The tempo that the pattern must be played at. Tracks []*Track // A list of tracks contained by this pattern. }
Pattern is the high level representation of the drum pattern contained in a .splice file.
func DecodeFile ¶
DecodeFile decodes the .splice file found at the provided path and returns a pointer to a parsed pattern which is the entry point to the rest of the data.
A drum file is binary and has the following format:
6 bytes : The word "SPLICE" in ASCII. 8 bytes : A big endian integer describing the length (in bytes) of the remaining data. 32 bytes : A NULL-terminated version string. 4 bytes : A little endian single-precision floating point describing the tempo.
All following bytes consist of a series of tracks. A track is laid out as:
1 byte : The ID of the track. n bytes : A length prefixed string that is the name of the track. The length is prefixed as a 4 byte big endian integer. 16 bytes : Each of the 16 steps for this track, 1 byte each.
func NewPattern ¶
NewPattern decodes 'length' bytes of data from 'input' and constructs a Pattern with appropriate values.
type Track ¶
type Track struct { ID byte // The track ID. Name string // The track name. Steps []byte // A 16-byte array indicating steps at which this track is played. }
Track is the high level representation of an indivual track in a drum pattern.
func NewTrack ¶
NewTrack extracts a single track from the provided 'input'. Returns a pointer to a Track struct with the appropriate values, the number of bytes consumed and an error if applicable. See DecodeFile() in decoder.go for an overview of the track layout in a splice file.