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: 7 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

View Source
var ErrNotSplice = errors.New("decode: not a SPLICE file")

ErrNotSplice indicates that a decoded file is not in a valid SPLICE format.

Functions

This section is empty.

Types

type Pattern

type Pattern struct {
	Version []byte  // The hardware version.
	Tempo   float64 // The drum kit tempo as BPM.
	Tracks  []Track // The tracks that make up the pattern.
}

Pattern represents the drum pattern contained in a .splice file.

func Decode

func Decode(r io.Reader) (*Pattern, error)

Decode reads a Splice drum machine file from r. It returns a pointer to a drum kit pattern as a Pattern and an error, if any.

func DecodeFile

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

DecodeFile decodes the Splice drum machine file found at the provided path. It returns a pointer to a drum kit pattern as a Pattern and an error, if any.

func (Pattern) String

func (p Pattern) String() string

String returns a representation of the Pattern in the following form:

Saved with HW Version: {Version}
Tempo: {Tempo}
({ID}) {Name}\t|{QuarterNote}|{QuarterNote}|{QuarterNote}|{QuarterNote}|
({ID}) {Name}\t|{QuarterNote}|{QuarterNote}|{QuarterNote}|{QuarterNote}|
...

type QuarterNote

type QuarterNote [4]byte

QuarterNote represents 4 sixteenth notes as a byte with a value of 1 or 0

func (QuarterNote) String

func (n QuarterNote) String() string

String returns a representation of the QuarterNote as it should appear in a drum kit measure. The sixteenth note steps are marked with 'x'. Empty steps are marked with '-'.

type Track

type Track struct {
	ID      uint32
	Name    []byte         // Instrument name
	Measure [4]QuarterNote // 4 quarter notes, 16 sixteenth notes
}

Track represents a drum kit track with an ID, instrument name, and a measure of 4 quarter notes.

func ReadTrack

func ReadTrack(r io.Reader) (*Track, error)

ReadTrack reads 4 bytes as a little endian uint32 to retrieve a track ID, reads a byte for a string length, reads that length to retrieve the track's instrument name, then reads 16 bytes as the tracks measure. It returns the resulting reads as a drum kit Track and an error, if any.

func (Track) String

func (t Track) String() string

String returns a representation of the Track as in the following form:

({ID}) {Name}\t|{QuarterNote}|{QuarterNote}|{QuarterNote}|{QuarterNote}|

The sixteenth note steps of each QuarterNote are marked with 'x'. Empty steps are marked with '-'.

Jump to

Keyboard shortcuts

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