Documentation
¶
Index ¶
- type AST
- type Command
- type Executor
- type LengthCommand
- type NoOpCommand
- type NoteCommand
- type OctaveCommand
- type OctaveDownCommand
- type OctaveUpCommand
- type Parser
- type Position
- type RestCommand
- type Scanner
- type State
- func (s *State) CurrentOctave() int
- func (s *State) EmitNote(note string, modifier string, length int, dot bool) error
- func (s *State) EmitRest(length int, dot bool) error
- func (s *State) SetDefaultLength(l int, dot bool) error
- func (s *State) SetOctave(o int) error
- func (s *State) SetTempo(t int) error
- type TempoCommand
- type Token
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AST ¶
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 ¶
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 ¶
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 ¶
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.
type RestCommand ¶
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 ¶
NewScanner returns a new instance of Scanner.
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 ¶
CurrentOctave returns the current octave on the state
func (*State) EmitNote ¶
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 ¶
EmitRest emits a rest note to the sequence. The length is the same as the length defined by EmitNote.
func (*State) SetDefaultLength ¶
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.
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