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

README

Drum

My solution to Go Challenge 1. And my first project in Go, very fun!

Functionality

  • Read SPLICE drum pattern files (decoder.go).
  • Save SPLICE drum patterns to file (encoder.go).
  • Play SPLICE drum patterns (player.go).
  • Edit SPLICE drum patterns (editor/).
    • Open files.
    • Save files.
    • Edit steps.
    • Change tempo.
    • Add shuffle.

Drum launcher

The project also includes a simple «launcher» (create with make), called drumcli:

# print a textual representation of a SPLICE pattern
drumcli print fixtures/pattern_1.splice

# play a SPLICE file
drumcli print fixtures/pattern_1.splice

# open the editor
drumcli edit fixtures/pattern_1.splice

Requirements

  • The Player uses SDL2 to play WAV files.
  • The Editor uses Termbox.

Notes

The Player expects to find WAV files in the relative directory sounds/ (so must be run from the root of the package).

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

View Source
const (
	DrumVersion string = "0.616-alpha"
)
View Source
const (
	SoundPath string = "sounds/"
)

Variables

This section is empty.

Functions

func EncodePattern

func EncodePattern(p *Pattern, path string) error

EncodePattern encodes the pattern to binary format and saves it to a file. Pretty much the opposite of `DecodeFile`.

Types

type Pattern

type Pattern struct {
	Version string
	Tempo   float32
	Tracks  []*Track
}

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 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) ClearSteps

func (p *Pattern) ClearSteps()

Turn off all the steps of the Pattern (but keeps everything else intact).

func (*Pattern) String

func (p *Pattern) String() string

Get a textual representation of the Pattern.

type Player

type Player struct {
	Sounds  []*mix.Chunk
	Shuffle float64
	// contains filtered or unexported fields
}

A Player plays back a Pattern using the provided WAV files and SDL2.

func PlayerNew

func PlayerNew(p *Pattern) (*Player, error)

func (*Player) AddCallback

func (pl *Player) AddCallback(f func(s int))

Add a callback function to be called on each step.

func (*Player) Free

func (pl *Player) Free()

Frees all the chunks (loaded WAVs) and closes the SDL-mixer.

func (*Player) Play

func (pl *Player) Play()

Starts playing the pattern (if not already playing).

func (*Player) Stop

func (pl *Player) Stop()

Stops playing.

func (*Player) TogglePlay

func (pl *Player) TogglePlay()

Starts playing if not playing, and stops playing if playing.

type Track

type Track struct {
	Id    int32
	Name  string
	Steps []bool
}

A Track is a high level representation of a Pattern's tracks. Simplified, a track is an instrument, and rules for on which «steps» the instrument should make a sound. A step is a 16th of a bar (and thus a 4th of a beat).

func (*Track) String

func (t *Track) String() string

Get a textual representation of a Track.

Directories

Path Synopsis
A quick (and dirty!) editor for SPLICE drum patterns.
A quick (and dirty!) editor for SPLICE drum patterns.

Jump to

Keyboard shortcuts

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