mml

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AST

type AST struct {
	Sequence  []Command
	Positions []Position
}

AST is the root element of the abstract syntax tree generated by the parser. It encapsulates all of the commands that make up a piece of music.

type Command

type Command interface {
	Execute(e Executor) error
}

Command defines the commands that can be executed within a sheet of music. Commands can perform actions on the music state, from emitting a note to setting the tempo and so on.

type Executor

type Executor interface {
	EmitNote(note string, modifier string, length int, dot bool) error
	EmitRest(length int, dot bool) error

	SetTempo(t int) error
	SetDefaultLength(l int, dot bool) error
	SetOctave(o int) error
	CurrentOctave() int
}

Executor is an interface on which state changes can be executed

type LengthCommand

type LengthCommand struct {
	Length int
	Dot    bool
}

LengthCommand sets the default length

func (*LengthCommand) Execute

func (l *LengthCommand) Execute(e Executor) error

Execute sets the default length on the state

type NoOpCommand

type NoOpCommand struct{}

NoOpCommand literally does nothing

func (*NoOpCommand) Execute

func (n *NoOpCommand) Execute(e Executor) error

Execute decrements the octave on the state

type NoteCommand

type NoteCommand struct {
	Note     string
	Modifier string
	Length   int
	Dot      bool
}

NoteCommand emits a note with a certain length

func (*NoteCommand) Execute

func (n *NoteCommand) Execute(e Executor) error

Execute emits a note on the state

type OctaveCommand

type OctaveCommand struct {
	Octave int
}

OctaveCommand sets the octave

func (*OctaveCommand) Execute

func (o *OctaveCommand) Execute(e Executor) error

Execute sets the octave on the state

type OctaveDownCommand

type OctaveDownCommand struct{}

OctaveDownCommand decrements the octave

func (*OctaveDownCommand) Execute

func (o *OctaveDownCommand) Execute(e Executor) error

Execute decrements the octave on the state

type OctaveUpCommand

type OctaveUpCommand struct{}

OctaveUpCommand increments the octave

func (*OctaveUpCommand) Execute

func (o *OctaveUpCommand) Execute(e Executor) error

Execute increments the octave on the state

type Parser

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

Parser represents a parser.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

func (*Parser) Parse

func (p *Parser) Parse() (*AST, error)

Parse returns an abstract syntax tree by parsing the input program with a recursive descent parser (though the language is simple enough that there is not currently any recursion involved).

type Position

type Position struct {
	Line   int
	Column int
}

Position identifies a location of the input string

func (Position) String

func (p Position) String() string

type RestCommand

type RestCommand struct {
	Length int
	Dot    bool
}

RestCommand emits a rest with a certain length

func (*RestCommand) Execute

func (r *RestCommand) Execute(e Executor) error

Execute emits a rest on the state

type Scanner

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

Scanner represents a lexical scanner.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() Token

Scan returns the next token and literal value.

type State

type State struct {
	Sequence encoding.Sequence
	Tempo    int
	Length   int
	Octave   int
	// contains filtered or unexported fields
}

State describes the state machine that consumes state changes and emits either notes or rests

func (*State) CurrentOctave

func (s *State) CurrentOctave() int

CurrentOctave returns the current octave on the state

func (*State) EmitNote

func (s *State) EmitNote(note string, modifier string, length int, dot bool) error

EmitNote emits a music note to the sequence. Modifiers can be one of: `+` or `#` - Makes this note a sharp note `-` - Makes this note a flat note Length is the denominator of 1/x, where the note will be spaced from the next note by 1/x of a beat. If length is -1 (empty length code), the default length will be used. If length is 0 (explicit length code of 0), the length will be set to a very small value (20 milliseconds). If an octave was not specified previously, it will default to octave 3

func (*State) EmitRest

func (s *State) EmitRest(length int, dot bool) error

EmitRest emits a rest note to the sequence. The length is the same as the length defined by EmitNote.

func (*State) SetDefaultLength

func (s *State) SetDefaultLength(l int, dot bool) error

SetDefaultLength sets the default length on the state. If the default length is not set, then it is assumed the length is 1/4th of a beat.

func (*State) SetOctave

func (s *State) SetOctave(o int) error

SetOctave sets the octave on the state

func (*State) SetTempo

func (s *State) SetTempo(t int) error

SetTempo sets the tempo (in BPM) on the state. If the Tempo is not set, it is assumed the tempo is 120 bpm.

type TempoCommand

type TempoCommand struct {
	Tempo int
}

TempoCommand sets the tempo

func (*TempoCommand) Execute

func (t *TempoCommand) Execute(e Executor) error

Execute sets the tempo on the state

type Token

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

Token defines the type for a lexical token

func (Token) Ident

func (t Token) Ident() string

Ident returns the identifier of the token

func (Token) Position

func (t Token) Position() Position

Position returns the position in the input string of the token

func (Token) Type

func (t Token) Type() TokenType

Type returns the type of the token

type TokenType

type TokenType int

TokenType is defined to specifically talk about token types rather than ints

const (
	TNote TokenType = iota
	TRest
	TTempo
	TLength
	TOctave
	TOctaveUp
	TOctaveDown
	TVolume
	TExtend
	TDot
	TModifier
	TNumeric
	TEOF
	TIllegal
)

These constants define the different possible token types

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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