drum

package
v0.0.0-...-e04bdec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2015 License: BSD-3-Clause Imports: 11 Imported by: 0

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

func EncodeFile(pattern *Pattern, path string) error

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.

func Play

func Play(pt *Pattern, n int) error

Play attempts to play the specified pattern for 'n' seconds on the default audio output device on the current system. An error is returned if the audio could not be played correctly.

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

func DecodeFile(path string) (*Pattern, error)

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

func NewPattern(input io.Reader, length uint64) (*Pattern, error)

NewPattern decodes 'length' bytes of data from 'input' and constructs a Pattern with appropriate values.

func (*Pattern) String

func (pt *Pattern) String() string

Returns a human readable version of the Pattern, including tracks. For example:

Saved with HW Version: 0.808-alpha
Tempo: 98.4
(0) kick    |x---|----|x---|----|
(1) snare   |----|x---|----|x---|
(3) hh-open |--x-|--x-|x-x-|--x-|
(5) cowbell |----|----|x---|----|

func (*Pattern) Write

func (pt *Pattern) Write(output io.Writer) error

Writes the version string, tempo and all tracks in the pattern into the provided 'output'.

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

func NewTrack(input io.Reader) (*Track, int, error)

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.

func (*Track) String

func (tr *Track) String() string

Returns a human readable version of the Track. For example:

(5) cowbell	|----|----|x---|----|

func (*Track) Write

func (tr *Track) Write(output io.Writer) error

Writes the track ID, name and steps to the provided 'output'.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL