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: 5 Imported by: 0

README

Go Challenge 1

For more information about the challenge see http://golang-challenge.com/go-challenge1/.

Test

$ go test -v
=== RUN TestDecodeFile
--- PASS: TestDecodeFile (0.00 seconds)
=== RUN TestEncodeFile
--- PASS: TestEncodeFile (0.00 seconds)
PASS
ok  	github.com/gedex/drum0.007s

Benchmark

$ go test -bench=. -benchmem
PASS
BenchmarkDecodePattern1  500000      7383 ns/op    1460 B/op      38 allocs/op
BenchmarkDecodePattern2  500000      6490 ns/op    1016 B/op      27 allocs/op
BenchmarkDecodePattern3  500000      7397 ns/op    1447 B/op      37 allocs/op
BenchmarkDecodePattern4  500000      6914 ns/op    1057 B/op      29 allocs/op
BenchmarkDecodePattern5  500000      5137 ns/op     636 B/op      18 allocs/op
BenchmarkEncodePattern1  200000     14514 ns/op    3526 B/op      82 allocs/op
BenchmarkEncodePattern2  200000     10929 ns/op    2676 B/op      60 allocs/op
BenchmarkEncodePattern3  200000     14421 ns/op    3512 B/op      82 allocs/op
BenchmarkEncodePattern4  200000     10734 ns/op    2690 B/op      61 allocs/op
BenchmarkEncodePattern5  500000      6767 ns/op    1487 B/op      37 allocs/op
ok  	github.com/gedex/drum070.653s

Documentation

Overview

Package drum is supposed to implement 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(filename string, pattern *Pattern) error

EncodeFile writes the binary encoding of pattern to a file named filename.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reads and decodes drum machine object fron an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

func (d *Decoder) Decode() (*Pattern, error)

Decode reads the binary-encoded value from its input d.r and return the parsed Pattern.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder writes binary-encoded Pattern to output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(pattern *Pattern) error

Encode writes the binary encoding of pattern to the stream.

type Pattern

type Pattern struct {

	// Pattern version information. Padding bytes are removed during UnmarshalBinary.
	Version string

	// Pattern tempo.
	Tempo float32

	// Pattern tracks.
	Tracks []*Track
	// contains filtered or unexported fields
}

Pattern is the high level representation of the drum pattern.

func DecodeFile

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

DecodeFile decodes the drum machine 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.

func (*Pattern) CalcSize

func (p *Pattern) CalcSize() uint8

CalcSize calculates number of bytes will be used by Pattern.

func (*Pattern) MarshalBinary

func (p *Pattern) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler.

func (*Pattern) String

func (p *Pattern) String() string

String representation of a pattern p.

func (*Pattern) TracksString

func (p *Pattern) TracksString() string

TracksString repesents string of Pattern.Tracks.

func (*Pattern) UnmarshalBinary

func (p *Pattern) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Steps

type Steps [16]byte

Steps represents 16 steps in a pattern. A byte 0x01 means a sound being triggered, while 0x00 means no sound being played for that step. In string, 0x00 is represented with '-' and 0x01 is represented with 'x'.

func (Steps) String

func (s Steps) String() string

String representation of steps.

type Track

type Track struct {
	ID    uint32
	Name  string
	Steps Steps
}

Track represents a single track in a pattern.

func (*Track) MarshalBinary

func (t *Track) MarshalBinary() (data []byte, err error)

MarshalBinary implements the binary.BinaryMarshaler.

func (*Track) String

func (t *Track) String() string

String representation of a track in a pattern.

func (*Track) UnmarshalBinary

func (t *Track) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

Jump to

Keyboard shortcuts

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