Documentation
¶
Overview ¶
Package melrose is for programming music melodies in Go
Index ¶
- Constants
- Variables
- func AppendStorexList(b *bytes.Buffer, isFirstParameter bool, list []Sequenceable)
- func ContainsInt(list []int, value int) bool
- func Duration(h HasValue) time.Duration
- func DurationToFraction(bpm float64, d time.Duration) (fraction float32, dotted bool)
- func Float(h HasValue) float32
- func FractionToDurationParts(f float64) (fraction float32, dotted bool)
- func FractionToString(f float32) string
- func IndexOf(v any) any
- func InspectValue(ctx Context, v any)
- func Int(h HasValue) int
- func IsBlackKey(nr int) bool
- func IsIdenticalTo(left, right Sequenceable) bool
- func LiteralValue(v any) any
- func MIDIToNoteParts(nr int) (name string, octave int, accidental int)
- func NotesEventsToFile(events []NoteEvent, name string)
- func ParseIntervalStrategy(s string) intervalStrategy
- func ParseVelocity(plusmin string) (velocity int)
- func PlayAt(d interface{ ... }, condition Condition, seq Sequenceable, bpm float64, ...) time.Time
- func PrintValue(ctx Context, v any)
- func QuantizeFraction(durationFactor float32) (fraction float32, dotted bool, ok bool)
- func Storex(v any) string
- func String(h HasValue) string
- func StringFromNoteGroup(notes []Note) string
- func ValueOf(v any) any
- func VelocityToDynamic(v int) string
- func WholeNoteDuration(bpm float64) time.Duration
- type AudioDevice
- type AudioDeviceMock
- func (m *AudioDeviceMock) Close() error
- func (m *AudioDeviceMock) Command(cmd []string) notify.Message
- func (m *AudioDeviceMock) DefaultDeviceIDs() (int, int)
- func (m *AudioDeviceMock) HandleSetting(setting string, value []any) error
- func (m *AudioDeviceMock) HasInputCapability() bool
- func (m *AudioDeviceMock) ListDevices() []DeviceDescriptor
- func (m *AudioDeviceMock) Listen(deviceID int, who NoteListener, isStart bool)
- func (m *AudioDeviceMock) OnKey(ctx Context, deviceID int, channel int, note Note, fun HasValue) error
- func (m *AudioDeviceMock) PlayWithClock(condition Condition, seq Sequenceable, clock *PlaybackClock) time.Time
- func (m *AudioDeviceMock) Report()
- func (m *AudioDeviceMock) Reset()
- func (m *AudioDeviceMock) Schedule(event TimelineEvent, beginAt time.Time)
- type BassTablature
- type BeatAction
- type BeatSchedule
- type Beatmaster
- func (b *Beatmaster) BIAB() int
- func (b *Beatmaster) BPM() float64
- func (b *Beatmaster) BeatsAndBars() (int64, int64)
- func (b *Beatmaster) Plan(bars int64, seq Sequenceable)
- func (b *Beatmaster) Reset()
- func (b *Beatmaster) SetBIAB(biab int)
- func (b *Beatmaster) SetBPM(bpm float64)
- func (b *Beatmaster) SettingNotifier(handler func(LoopController))
- func (b *Beatmaster) Start()
- func (b *Beatmaster) Stop()
- type Capabilities
- type ChannelSelector
- type Chord
- func (c Chord) Inspect(i Inspection)
- func (c Chord) Notes() []Note
- func (c Chord) Replaced(from, to Sequenceable) Sequenceable
- func (c Chord) S() Sequence
- func (c Chord) Storex() string
- func (c Chord) String() string
- func (c Chord) WithFraction(f float32, dotted bool) Chord
- func (c Chord) WithInterval(i int) Chord
- func (c Chord) WithInversion(i int) Chord
- func (c Chord) WithQuality(q int) Chord
- func (c Chord) WithVelocity(v int) Chord
- type ChordProgression
- type ChordSequence
- type Condition
- type Conditional
- type ConditionalPlayContext
- type Context
- type DeviceDescriptor
- type DeviceSelector
- type Euclidean
- type Evaluatable
- type HasIndex
- type HasSequenceables
- type HasValue
- type Indexable
- type Inspectable
- type Inspection
- type Interval
- type Iterator
- type Loop
- func (l *Loop) Evaluate(ctx Context) error
- func (l *Loop) Handle(tim *Timeline, when time.Time)
- func (l *Loop) Inspect(i Inspection)
- func (l *Loop) IsPlaying() bool
- func (l *Loop) IsRunning() bool
- func (l *Loop) NextPlayAt() time.Time
- func (l *Loop) NoteChangesDo(block func(NoteChange))
- func (l *Loop) Play(ctx Context, while Condition, at time.Time) time.Time
- func (l *Loop) S() Sequence
- func (l *Loop) SetLoopCount(n int)
- func (l *Loop) SetTarget(newTarget []Sequenceable)
- func (l *Loop) Stop(ctx Context) error
- func (l *Loop) Storex() string
- func (l *Loop) Target() []Sequenceable
- func (l *Loop) ToSequence(loopcount int) Sequence
- type LoopController
- type MIDINote
- type Map
- type MultiTrack
- type NameAware
- type Nextable
- type Nexter
- type Note
- func MIDItoNote(fraction float32, nr int, vel int) (Note, error)
- func MakeNote(name string, octave int, frac float32, accidental int, dot bool, velocity int) Note
- func MustParseNote(input string) Note
- func NewNote(name string, octave int, frac float32, accidental int, dot bool, velocity int) (Note, error)
- func ParseNote(input string) (Note, error)
- func (n Note) CheckTieableTo(t Note) error
- func (n Note) DurationAt(bpm float64) time.Duration
- func (n Note) DurationFactor() float32
- func (n Note) Equals(o Note) bool
- func (n Note) Fraction() float32
- func (n Note) HasEqualTied(o Note) bool
- func (n Note) Inspect(i Inspection)
- func (n Note) IsHearable() bool
- func (n Note) IsPedal() bool
- func (n Note) IsPedalDown() bool
- func (n Note) IsPedalUp() bool
- func (n Note) IsPedalUpDown() bool
- func (n Note) IsRest() bool
- func (n Note) MIDI() int
- func (n Note) NonFractionBasedDuration() (time.Duration, bool)
- func (n Note) Octaved(howmuch int) Note
- func (n Note) Pitched(howManySemitones int) Note
- func (n Note) Replaced(from, to Sequenceable) Sequenceable
- func (n Note) S() Sequence
- func (n Note) Storex() string
- func (n Note) Stretched(f float32) Note
- func (n Note) String() string
- func (n Note) ToNote() (Note, error)
- func (n Note) ToRest() Note
- func (n Note) WithDynamic(emphasis string) Note
- func (n Note) WithFraction(f float32, dotted bool) Note
- func (n Note) WithTiedNote(t Note) Note
- func (n Note) WithVelocity(v int) Note
- func (n Note) WithoutDynamic() Note
- type NoteChange
- type NoteChangeEvent
- type NoteConvertable
- type NoteEvent
- type NoteEventStatistics
- type NoteListener
- type NotePeriod
- type PlayContext
- type Playable
- type PlaybackClock
- func (c PlaybackClock) After(note Note) PlaybackClock
- func (c PlaybackClock) AfterGroup(notes []Note) PlaybackClock
- func (c PlaybackClock) AfterSequence(sequence Sequence) PlaybackClock
- func (c PlaybackClock) Duration() time.Duration
- func (c *PlaybackClock) SetBPM(bpm float64)
- func (c PlaybackClock) Time() time.Time
- type Print
- type RecordedEvent
- type RecordingAudioDevice
- func (d *RecordingAudioDevice) Close() error
- func (d *RecordingAudioDevice) Command(args []string) notify.Message
- func (d *RecordingAudioDevice) DefaultDeviceIDs() (int, int)
- func (d *RecordingAudioDevice) Drain()
- func (d *RecordingAudioDevice) Events() []RecordedEvent
- func (d *RecordingAudioDevice) HandleSetting(name string, values []any) error
- func (d *RecordingAudioDevice) HasInputCapability() bool
- func (d *RecordingAudioDevice) ListDevices() []DeviceDescriptor
- func (d *RecordingAudioDevice) Listen(deviceID int, who NoteListener, startOrStop bool)
- func (d *RecordingAudioDevice) NoteOns() (list []RecordedEvent)
- func (d *RecordingAudioDevice) OnKey(ctx Context, deviceID int, channel int, note Note, fun HasValue) error
- func (d *RecordingAudioDevice) Pending() int
- func (d *RecordingAudioDevice) PlayWithClock(condition Condition, seq Sequenceable, clock *PlaybackClock) time.Time
- func (d *RecordingAudioDevice) Report()
- func (d *RecordingAudioDevice) Reset()
- func (d *RecordingAudioDevice) RunUntil(offset time.Duration)
- func (d *RecordingAudioDevice) Schedule(event TimelineEvent, beginAt time.Time)
- type Replaceable
- type Scale
- type Sequence
- func (s Sequence) At(i int) []Note
- func (s Sequence) Bars(biab int) float64
- func (s Sequence) DurationAt(bpm float64) time.Duration
- func (s Sequence) DurationFactor() float64
- func (s Sequence) Inspect(i Inspection)
- func (s Sequence) NoDynamics() Sequence
- func (s Sequence) NoFractions() Sequence
- func (s Sequence) NoRests() Sequence
- func (s Sequence) NotesDo(block func(Note))
- func (s Sequence) Octaved(howMuch int) Sequence
- func (s Sequence) Pitched(semitones int) Sequence
- func (s Sequence) PrintString(sharpOrFlatKey int) string
- func (s Sequence) Replaced(from, to Sequenceable) Sequenceable
- func (s Sequence) Reversed() Sequence
- func (s Sequence) RotatedBy(howMany int) Sequence
- func (s Sequence) S() Sequence
- func (s Sequence) SequenceJoin(t Sequence) Sequence
- func (s Sequence) Split() []Sequence
- func (s Sequence) Storex() string
- func (s Sequence) Stretched(f float32) Sequence
- func (s Sequence) String() string
- func (s Sequence) ToRest() Sequence
- func (s Sequence) W() string
- type SequenceBuilder
- type SequenceOnTrack
- type Sequenceable
- type SequenceableList
- type Stoppable
- type Storable
- type TabNote
- type TestLooper
- func (t *TestLooper) BIAB() int
- func (t *TestLooper) BPM() float64
- func (t *TestLooper) BeatsAndBars() (int64, int64)
- func (t *TestLooper) EndLoop(l *Loop)
- func (t *TestLooper) Plan(bars int64, seq Sequenceable)
- func (t *TestLooper) Reset()
- func (t *TestLooper) SetBIAB(biab int)
- func (t *TestLooper) SetBPM(bpm float64)
- func (t *TestLooper) SettingNotifier(handler func(LoopController))
- func (t *TestLooper) Start()
- func (t *TestLooper) StartLoop(l *Loop)
- func (t *TestLooper) Stop()
- func (t *TestLooper) Tick()
- type Timeline
- func (t *Timeline) BuildNotePeriods() []NotePeriod
- func (t *Timeline) EventsDo(block func(event TimelineEvent, when time.Time))
- func (t *Timeline) Len() int64
- func (t *Timeline) NoteEvents() (list []NoteEvent)
- func (t *Timeline) Play()
- func (t *Timeline) Reset()
- func (t *Timeline) Schedule(event TimelineEvent, when time.Time) error
- func (t *Timeline) Stop()
- func (t *Timeline) ZeroStarting() *Timeline
- type TimelineEvent
- type Track
- type ValueFunction
- type ValueHolder
- type VariableStorage
Examples ¶
Constants ¶
const ( Sharp = iota Flat Eight Quarter Half Whole Dot Left Right PrintAsSpecified Major Minor // Natural Septiem Augmented Diminished Suspended2 Suspended4 // https://en.wikipedia.org/wiki/Chord_(music)#Common_types_of_chords Triad Seventh Sixth Ground Inversion1 Inversion2 Inversion3 )
const ( VelocityPPPP = 8 // ----- VelocityPPP = 20 // ---- VelocityPP = 31 // --- VelocityP = 42 // -- VelocityMP = 53 // - Normal = 59 // o VelocityMF = 64 // + VelocityF = 80 // ++ VelocityFF = 96 // +++ VelocityFFF = 112 // ++++ VelocityFFFF = 127 // +++++ )
https://www.cs.cmu.edu/~music/cmsip/readings/MIDI%20tutorial%20for%20programmers.html
const ( // OnceFromTo "once" OnceFromTo = iota // OnceFromToFrom "once-two-way" OnceFromToFrom // RepeatFromTo "repeat" RepeatFromTo // RepeatFromToFrom "repeat-two-way" RepeatFromToFrom )
const EditorLineEnd = "editor.line.end"
const EditorLineStart = "editor.line.start"
const WorkingDirectory = "shell.pwd"
WorkingDirectory is a key in a context environment.
Variables ¶
var ( Rest4 = Note{Name: "=", /* contains filtered or unexported fields */} PedalUpDown = Note{Name: "^", /* contains filtered or unexported fields */} PedalDown = Note{Name: ">", /* contains filtered or unexported fields */} PedalUp = Note{Name: "<", /* contains filtered or unexported fields */} ZeroDuration = time.Duration(0) )
var BuildTag = "dev"
var EmptySequence = Sequence{}
var N = MustParseNote
var NoLooper = zeroBeat{}
NoLooper is a Beatmaster that does not loop
var S = MustParseSequence
Functions ¶
func AppendStorexList ¶
func AppendStorexList(b *bytes.Buffer, isFirstParameter bool, list []Sequenceable)
func ContainsInt ¶
func DurationToFraction ¶
DurationToFraction returns the note length (and whether it is dotted) that is closest to d at the given tempo.
func FractionToDurationParts ¶ added in v0.44.0
func FractionToString ¶ added in v0.47.0
func InspectValue ¶
func IsBlackKey ¶
func IsIdenticalTo ¶
func IsIdenticalTo(left, right Sequenceable) bool
func LiteralValue ¶ added in v1.0.0
LiteralValue returns the literal value of a value, unwrapping any HasValue
func MIDIToNoteParts ¶ added in v0.44.0
func NotesEventsToFile ¶ added in v0.44.0
func ParseIntervalStrategy ¶
func ParseIntervalStrategy(s string) intervalStrategy
ParseIntervalStrategy return the non-exposed strategy based on the name. If unknown then return OnceFromTo ("once").
func ParseVelocity ¶
func PlayAt ¶ added in v1.0.0
func PlayAt(d interface {
PlayWithClock(condition Condition, seq Sequenceable, clock *PlaybackClock) time.Time
}, condition Condition, seq Sequenceable, bpm float64, beginAt time.Time) time.Time
PlayAt plays seq on the device from beginAt using a new clock with the given BPM. Returns the end time of the last played Note.
func PrintValue ¶
func QuantizeFraction ¶
func StringFromNoteGroup ¶
func VelocityToDynamic ¶ added in v0.45.0
func WholeNoteDuration ¶
Types ¶
type AudioDevice ¶
type AudioDevice interface {
DefaultDeviceIDs() (inputDeviceID, outputDeviceID int)
// Per device specific commands
Command(args []string) notify.Message
// Handle generic setting
HandleSetting(name string, values []any) error
// PlayWithClock schedules notes from the supplied clock and advances it to
// the sequence's end, retaining musical ticks across playback calls.
// Returns the end time of the last played Note.
PlayWithClock(condition Condition, seq Sequenceable, clock *PlaybackClock) time.Time
HasInputCapability() bool
Listen(deviceID int, who NoteListener, isStart bool)
// if a key is pressed on a device then play or stop a function
// if fun is nil then uninstall the binding
OnKey(ctx Context, deviceID int, channel int, note Note, fun HasValue) error
// Schedule put an event on the timeline at a begin
Schedule(event TimelineEvent, beginAt time.Time)
ListDevices() []DeviceDescriptor
// Record(ctx Context) (*Recording, error)
Reset()
Close() error
Report()
}
type AudioDeviceMock ¶ added in v0.58.4
type AudioDeviceMock struct {
}
func (*AudioDeviceMock) Close ¶ added in v0.58.4
func (m *AudioDeviceMock) Close() error
Close implements the AudioDevice interface.
func (*AudioDeviceMock) Command ¶ added in v0.58.4
func (m *AudioDeviceMock) Command(cmd []string) notify.Message
Command implements the AudioDevice interface.
func (*AudioDeviceMock) DefaultDeviceIDs ¶ added in v0.58.4
func (m *AudioDeviceMock) DefaultDeviceIDs() (int, int)
DefaultDeviceIDs implements the AudioDevice interface.
func (*AudioDeviceMock) HandleSetting ¶ added in v0.58.4
func (m *AudioDeviceMock) HandleSetting(setting string, value []any) error
HandleSetting implements the AudioDevice interface.
func (*AudioDeviceMock) HasInputCapability ¶ added in v0.58.4
func (m *AudioDeviceMock) HasInputCapability() bool
HasInputCapability implements the AudioDevice interface.
func (*AudioDeviceMock) ListDevices ¶ added in v0.58.4
func (m *AudioDeviceMock) ListDevices() []DeviceDescriptor
ListDevices implements the AudioDevice interface.
func (*AudioDeviceMock) Listen ¶ added in v0.58.4
func (m *AudioDeviceMock) Listen(deviceID int, who NoteListener, isStart bool)
Listen implements the AudioDevice interface.
func (*AudioDeviceMock) OnKey ¶ added in v0.58.4
func (m *AudioDeviceMock) OnKey(ctx Context, deviceID int, channel int, note Note, fun HasValue) error
OnKey implements the AudioDevice interface.
func (*AudioDeviceMock) PlayWithClock ¶ added in v1.0.0
func (m *AudioDeviceMock) PlayWithClock(condition Condition, seq Sequenceable, clock *PlaybackClock) time.Time
PlayWithClock implements the AudioDevice interface.
func (*AudioDeviceMock) Report ¶ added in v0.58.4
func (m *AudioDeviceMock) Report()
Report implements the AudioDevice interface.
func (*AudioDeviceMock) Reset ¶ added in v0.58.4
func (m *AudioDeviceMock) Reset()
Reset implements the AudioDevice interface.
func (*AudioDeviceMock) Schedule ¶ added in v0.58.4
func (m *AudioDeviceMock) Schedule(event TimelineEvent, beginAt time.Time)
Schedule implements the AudioDevice interface.
type BassTablature ¶ added in v0.47.0
type BassTablature struct {
TabNotes []TabNote
}
tabs('e3 a2 a5 d5 a5 a2 e3')
func ParseBassTablature ¶ added in v0.47.0
func ParseBassTablature(s string) (BassTablature, error)
func (BassTablature) S ¶ added in v0.47.0
func (t BassTablature) S() Sequence
func (BassTablature) Storex ¶ added in v0.47.0
func (t BassTablature) Storex() string
type BeatAction ¶
type BeatSchedule ¶
type BeatSchedule struct {
// contains filtered or unexported fields
}
BeatSchedule holds mapping between beat counts and an action (function).
func NewBeatSchedule ¶
func NewBeatSchedule() *BeatSchedule
func (*BeatSchedule) IsEmpty ¶
func (s *BeatSchedule) IsEmpty() bool
func (*BeatSchedule) Reset ¶
func (s *BeatSchedule) Reset()
func (*BeatSchedule) Schedule ¶
func (s *BeatSchedule) Schedule(beat int64, action BeatAction)
func (*BeatSchedule) Unschedule ¶
func (s *BeatSchedule) Unschedule(beat int64) []BeatAction
type Beatmaster ¶
type Beatmaster struct {
// contains filtered or unexported fields
}
Beatmaster is a LoopController
func NewBeatmaster ¶
func NewBeatmaster(ctx Context, bpm float64) *Beatmaster
func (*Beatmaster) BIAB ¶
func (b *Beatmaster) BIAB() int
func (*Beatmaster) BPM ¶
func (b *Beatmaster) BPM() float64
func (*Beatmaster) BeatsAndBars ¶
func (b *Beatmaster) BeatsAndBars() (int64, int64)
func (*Beatmaster) Plan ¶
func (b *Beatmaster) Plan(bars int64, seq Sequenceable)
Plan is part of LoopControl bars is zero-based
func (*Beatmaster) Reset ¶
func (b *Beatmaster) Reset()
func (*Beatmaster) SetBIAB ¶
func (b *Beatmaster) SetBIAB(biab int)
TODO move checks to SetBIAB in control SetBIAB will change the beats per bar, unless the master is not started.
func (*Beatmaster) SetBPM ¶
func (b *Beatmaster) SetBPM(bpm float64)
SetBPM will change the beats per minute at the next bar, unless the master is not started.
func (*Beatmaster) SettingNotifier ¶
func (b *Beatmaster) SettingNotifier(handler func(LoopController))
func (*Beatmaster) Start ¶
func (b *Beatmaster) Start()
func (*Beatmaster) Stop ¶
func (b *Beatmaster) Stop()
Stop will stop the beats. Any Loops will continue to run.
type Capabilities ¶
type Capabilities struct {
AnsiColoring bool
HTTPService bool
ExportMIDI bool
ImportMelrose bool
ReceivingMIDI bool
SendingMIDI bool
}
func NewCapabilities ¶
func NewCapabilities() *Capabilities
type ChannelSelector ¶
type ChannelSelector struct {
Target Sequenceable
Number HasValue
}
func NewChannelSelector ¶
func NewChannelSelector(target Sequenceable, channel HasValue) ChannelSelector
func (ChannelSelector) Channel ¶
func (c ChannelSelector) Channel() int
func (ChannelSelector) S ¶
func (c ChannelSelector) S() Sequence
func (ChannelSelector) Storex ¶
func (c ChannelSelector) Storex() string
func (ChannelSelector) Unwrap ¶
func (c ChannelSelector) Unwrap() Sequenceable
type Chord ¶
type Chord struct {
// contains filtered or unexported fields
}
https://en.wikipedia.org/wiki/Chord_(music)
func MustParseChord ¶
func (Chord) Inspect ¶
func (c Chord) Inspect(i Inspection)
func (Chord) Replaced ¶
func (c Chord) Replaced(from, to Sequenceable) Sequenceable
Replaced is part of Replaceable
func (Chord) WithFraction ¶ added in v0.45.0
func (Chord) WithInterval ¶
func (Chord) WithInversion ¶
func (Chord) WithQuality ¶
func (Chord) WithVelocity ¶ added in v0.45.0
type ChordProgression ¶
type ChordProgression struct {
// contains filtered or unexported fields
}
func NewChordProgression ¶
func NewChordProgression(root, sequence HasValue) ChordProgression
func (ChordProgression) C ¶
func (c ChordProgression) C() []Chord
func (ChordProgression) Replaced ¶
func (c ChordProgression) Replaced(from, to Sequenceable) Sequenceable
Replaced is part of Replaceable
func (ChordProgression) Storex ¶
func (c ChordProgression) Storex() string
Storex is part of Storable
type ChordSequence ¶
type ChordSequence struct {
Chords [][]Chord
}
func MustParseChordSequence ¶
func MustParseChordSequence(s string) ChordSequence
func ParseChordSequence ¶
func ParseChordSequence(input string) (ChordSequence, error)
func (ChordSequence) Inspect ¶
func (p ChordSequence) Inspect(i Inspection)
func (ChordSequence) Replaced ¶
func (p ChordSequence) Replaced(from, to Sequenceable) Sequenceable
Replaced is part of Replaceable
func (ChordSequence) S ¶
func (p ChordSequence) S() Sequence
func (ChordSequence) Storex ¶
func (p ChordSequence) Storex() string
type Conditional ¶
type Conditional interface {
Condition() Condition
}
type ConditionalPlayContext ¶
type ConditionalPlayContext struct {
Context
// contains filtered or unexported fields
}
func (ConditionalPlayContext) Condition ¶
func (c ConditionalPlayContext) Condition() Condition
type Context ¶
type Context interface {
Control() LoopController
Device() AudioDevice
Variables() VariableStorage
Environment() *sync.Map
WithCondition(c Condition) Context
Capabilities() *Capabilities
}
type DeviceDescriptor ¶ added in v0.58.0
type DeviceSelector ¶
type DeviceSelector struct {
Target Sequenceable
ID HasValue
}
func NewDeviceSelector ¶
func NewDeviceSelector(target Sequenceable, deviceID HasValue) DeviceSelector
func (DeviceSelector) DeviceID ¶
func (d DeviceSelector) DeviceID() int
func (DeviceSelector) S ¶
func (d DeviceSelector) S() Sequence
func (DeviceSelector) Storex ¶
func (d DeviceSelector) Storex() string
func (DeviceSelector) Unwrap ¶
func (d DeviceSelector) Unwrap() Sequenceable
type Euclidean ¶ added in v0.54.0
func (*Euclidean) Inspect ¶ added in v0.54.0
func (e *Euclidean) Inspect(i Inspection)
Inspect is part of Inspectable
type Evaluatable ¶
TODO makue users use Play with a Context that can have a Condition
type HasSequenceables ¶ added in v0.54.0
type HasSequenceables interface {
Sequenceables() []Sequenceable
}
type Indexable ¶
type Indexable interface {
At(i int) Sequenceable
}
type Inspectable ¶
type Inspectable interface {
Inspect(i Inspection)
}
type Inspection ¶
type Inspection struct {
Context Context
Type string
Text string
VariableName string
Properties map[string]any
// contains filtered or unexported fields
}
func NewInspect ¶
func NewInspect(ctx Context, varname string, value any) Inspection
func (Inspection) Markdown ¶
func (i Inspection) Markdown() string
Markdown returns a markdown formatted string with inspection details
func (Inspection) String ¶
func (i Inspection) String() string
type Interval ¶
type Interval struct {
// contains filtered or unexported fields
}
Interval is a HasValue that has a Value between [from..to] and increments with [by]. If the end of the interval is reached then the Value is set to [from]. The fields of an Interval are also HasValue.
func NewInterval ¶
NewInterval creates new Interval. The initial Value is set to [from]. Specify the repeat strategy.
type Iterator ¶
type Iterator struct {
Target []any
// contains filtered or unexported fields
}
func (*Iterator) VariableName ¶ added in v0.50.1
VariableName is part of NameAware
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
func NewLoop ¶
func NewLoop(ctx Context, target []Sequenceable) *Loop
func (*Loop) NextPlayAt ¶
func (*Loop) NoteChangesDo ¶
func (l *Loop) NoteChangesDo(block func(NoteChange))
func (*Loop) SetLoopCount ¶ added in v1.0.0
SetLoopCount makes the loop stop by itself after n cycles. Zero means forever.
func (*Loop) SetTarget ¶
func (l *Loop) SetTarget(newTarget []Sequenceable)
func (*Loop) Target ¶
func (l *Loop) Target() []Sequenceable
func (*Loop) ToSequence ¶
type LoopController ¶
type LoopController interface {
Start()
Stop()
Reset()
SetBPM(bpm float64)
BPM() float64
SetBIAB(biab int)
BIAB() int
BeatsAndBars() (int64, int64)
Plan(bars int64, seq Sequenceable)
SettingNotifier(handler func(control LoopController))
}
type MIDINote ¶
type MIDINote struct {
// contains filtered or unexported fields
}
func (MIDINote) Inspect ¶
func (m MIDINote) Inspect(i Inspection)
type Map ¶ added in v0.54.1
type Map struct {
Target HasValue
Replaceable HasValue
Each Sequenceable
}
func (Map) Replaced ¶ added in v0.54.1
func (c Map) Replaced(from, to Sequenceable) Sequenceable
func (Map) Sequenceables ¶ added in v0.54.1
func (c Map) Sequenceables() []Sequenceable
type MultiTrack ¶
type MultiTrack struct {
Tracks []HasValue
}
type Nexter ¶
type Nexter struct {
Target HasValue
}
Nexter is an empty Sequence that has a sideeffect to call Value().Next() on its target when asked for the Sequence.
type Note ¶
type Note struct {
Name string // {C D E F G A B = ^ < >}
Octave int
Accidental int // -1 Flat, +1 Sharp, 0 Normal
Dotted bool // if true then fraction is increased by half
Velocity int // 1..127
// contains filtered or unexported fields
}
Note represents a musical note. Notations:
2.C#3 = half duration, pitch C, sharp, octave 3, velocity default
D = quarter duration, pitch D, octave 4, no accidental
8B_ = eighth duration, pitch B, octave 4, flat
= = quarter rest
-/+ = velocity number
http://en.wikipedia.org/wiki/Musical_Note
func MustParseNote ¶
MustParseNote returns a Note by parsing the input. Panic if it fails.
func ParseNote ¶
ParseNote reads the format <(inverse-)duration?>[CDEFGA=<^>]<accidental?><dot?><octave?>
Example ¶
n1, _ := ParseNote("2C#3")
n2, _ := ParseNote("2.E_2")
n3, _ := ParseNote(".F_2++")
e1, _ := ParseNote("2C#")
e2, _ := ParseNote("8B_")
e3, _ := ParseNote("4.D")
e4, _ := ParseNote("E_")
t1, _ := ParseNote("2c~4c")
fmt.Println(e1)
fmt.Println(e2)
fmt.Println(e3)
fmt.Println(e4)
fmt.Println(n1)
fmt.Println(n2)
fmt.Println(n3)
fmt.Println(t1)
Output: 2C# 8B_ .D E_ 2C#3 2.E_2 .F_2++ 2C~C
func (Note) CheckTieableTo ¶ added in v0.45.0
func (Note) DurationFactor ¶
DurationFactor is the actual duration time factor Only correct if n.duration is 0 and also for each tied note ; use DurationAt otherwise
func (Note) HasEqualTied ¶ added in v0.45.0
func (Note) Inspect ¶
func (n Note) Inspect(i Inspection)
func (Note) IsHearable ¶
func (Note) IsPedalDown ¶
func (Note) IsPedalUpDown ¶
func (Note) NonFractionBasedDuration ¶
func (Note) Pitched ¶
Pitched creates a new Note with a pitch by a (positive or negative) number of semi tones
func (Note) Replaced ¶
func (n Note) Replaced(from, to Sequenceable) Sequenceable
Replaced is part of Replaceable
func (Note) WithDynamic ¶
func (Note) WithTiedNote ¶ added in v0.45.0
func (Note) WithVelocity ¶
func (Note) WithoutDynamic ¶ added in v0.45.0
type NoteChange ¶
type NoteChange struct {
// contains filtered or unexported fields
}
func NewNoteChange ¶
func NewNoteChange(isOn bool, midiNr int64, velocity int64) NoteChange
func (NoteChange) IsOn ¶
func (n NoteChange) IsOn() bool
func (NoteChange) NoteChangesDo ¶
func (n NoteChange) NoteChangesDo(block func(NoteChange))
func (NoteChange) Number ¶
func (n NoteChange) Number() int
func (NoteChange) Velocity ¶
func (n NoteChange) Velocity() int
type NoteChangeEvent ¶ added in v0.44.0
type NoteConvertable ¶
type NoteEvent ¶
type NoteEvent struct {
Start time.Time `json:"start"`
End time.Time `json:"end"`
Number int `json:"number"`
Velocity int `json:"velocity"`
}
func NoteEventsFromFile ¶ added in v0.44.0
type NoteEventStatistics ¶
func NoteStatistics ¶
func NoteStatistics(list []NoteEvent) (stats NoteEventStatistics)
func (NoteEventStatistics) String ¶
func (s NoteEventStatistics) String() string
type NoteListener ¶
type NotePeriod ¶ added in v0.44.0
type NotePeriod struct {
// contains filtered or unexported fields
}
func ConvertToNotePeriods ¶ added in v0.44.0
func ConvertToNotePeriods(changes []NoteChangeEvent) (events []NotePeriod)
TODO move inside sequencebuilder ?
func NoteEventsToPeriods ¶ added in v0.44.0
func NoteEventsToPeriods(events []NoteEvent) (list []NotePeriod)
func (NotePeriod) End ¶ added in v0.44.0
func (p NotePeriod) End() time.Time
func (NotePeriod) Note ¶ added in v0.44.0
func (p NotePeriod) Note(bpm float64) Note
func (NotePeriod) Number ¶ added in v0.44.0
func (p NotePeriod) Number() int
func (NotePeriod) Quantized ¶ added in v0.44.0
func (p NotePeriod) Quantized(bpm float64) NotePeriod
func (NotePeriod) Start ¶ added in v0.44.0
func (p NotePeriod) Start() time.Time
func (NotePeriod) Velocity ¶ added in v0.44.0
func (p NotePeriod) Velocity() int
type PlayContext ¶
type PlayContext struct {
LoopControl LoopController
AudioDevice AudioDevice
VariableStorage VariableStorage
EnvironmentVars *sync.Map
CapabilityFlags *Capabilities
}
func (PlayContext) Capabilities ¶
func (p PlayContext) Capabilities() *Capabilities
func (PlayContext) Control ¶
func (p PlayContext) Control() LoopController
func (PlayContext) Device ¶
func (p PlayContext) Device() AudioDevice
func (PlayContext) Environment ¶
func (p PlayContext) Environment() *sync.Map
func (PlayContext) Variables ¶
func (p PlayContext) Variables() VariableStorage
func (PlayContext) WithCondition ¶
func (p PlayContext) WithCondition(c Condition) Context
type PlaybackClock ¶ added in v1.0.0
type PlaybackClock struct {
// contains filtered or unexported fields
}
PlaybackClock tracks a position in time relative to an origin. Musical positions are accumulated as integer ticks to avoid rounding drift, while notes with an absolute duration are accumulated separately. It is a value type: After* methods return an advanced copy and leave the receiver unchanged.
func NewPlaybackClock ¶ added in v1.0.0
func NewPlaybackClock(begin time.Time, bpm float64) PlaybackClock
NewPlaybackClock returns a clock positioned at begin that runs at the given tempo.
func (PlaybackClock) After ¶ added in v1.0.0
func (c PlaybackClock) After(note Note) PlaybackClock
After returns a copy of the clock advanced by the length of the note, including any tied notes.
func (PlaybackClock) AfterGroup ¶ added in v1.0.0
func (c PlaybackClock) AfterGroup(notes []Note) PlaybackClock
AfterGroup returns a copy of the clock advanced past a group of simultaneous notes. The clock advances by the shortest note in the group, matching MIDI playback where the next group starts when the earliest note ends.
func (PlaybackClock) AfterSequence ¶ added in v1.0.0
func (c PlaybackClock) AfterSequence(sequence Sequence) PlaybackClock
AfterSequence returns a copy of the clock advanced past all note groups of the sequence.
func (PlaybackClock) Duration ¶ added in v1.0.0
func (c PlaybackClock) Duration() time.Duration
Duration returns the time elapsed since the origin.
func (*PlaybackClock) SetBPM ¶ added in v1.0.0
func (c *PlaybackClock) SetBPM(bpm float64)
SetBPM changes the tempo from the current position onwards. Time already elapsed is preserved by moving the origin to the current position.
func (PlaybackClock) Time ¶ added in v1.0.0
func (c PlaybackClock) Time() time.Time
Time returns the absolute wall-clock time of the current position.
type RecordedEvent ¶ added in v1.0.0
type RecordedEvent struct {
At time.Duration // since the origin of the device
Channel int
MIDI int
Velocity int
On bool
}
RecordedEvent is a MIDI note on/off captured by a RecordingAudioDevice.
func (RecordedEvent) String ¶ added in v1.0.0
func (e RecordedEvent) String() string
type RecordingAudioDevice ¶ added in v1.0.0
type RecordingAudioDevice struct {
// contains filtered or unexported fields
}
RecordingAudioDevice is an AudioDevice for tests. It runs on virtual time: scheduled events are only fired by RunUntil or Drain and nothing ever sleeps. Fired note events are recorded with their time relative to the first begin time it received. Pedal changes are not recorded.
func NewRecordingAudioDevice ¶ added in v1.0.0
func NewRecordingAudioDevice() *RecordingAudioDevice
func (*RecordingAudioDevice) Close ¶ added in v1.0.0
func (d *RecordingAudioDevice) Close() error
func (*RecordingAudioDevice) Command ¶ added in v1.0.0
func (d *RecordingAudioDevice) Command(args []string) notify.Message
func (*RecordingAudioDevice) DefaultDeviceIDs ¶ added in v1.0.0
func (d *RecordingAudioDevice) DefaultDeviceIDs() (int, int)
func (*RecordingAudioDevice) Drain ¶ added in v1.0.0
func (d *RecordingAudioDevice) Drain()
Drain fires all scheduled events, including the ones that are scheduled while draining. It panics if there seems no end, e.g. for a Loop without a loop count.
func (*RecordingAudioDevice) Events ¶ added in v1.0.0
func (d *RecordingAudioDevice) Events() []RecordedEvent
Events returns a copy of all fired note on/off events in the order they were fired.
func (*RecordingAudioDevice) HandleSetting ¶ added in v1.0.0
func (d *RecordingAudioDevice) HandleSetting(name string, values []any) error
func (*RecordingAudioDevice) HasInputCapability ¶ added in v1.0.0
func (d *RecordingAudioDevice) HasInputCapability() bool
func (*RecordingAudioDevice) ListDevices ¶ added in v1.0.0
func (d *RecordingAudioDevice) ListDevices() []DeviceDescriptor
func (*RecordingAudioDevice) Listen ¶ added in v1.0.0
func (d *RecordingAudioDevice) Listen(deviceID int, who NoteListener, startOrStop bool)
func (*RecordingAudioDevice) NoteOns ¶ added in v1.0.0
func (d *RecordingAudioDevice) NoteOns() (list []RecordedEvent)
NoteOns returns only the note-on events.
func (*RecordingAudioDevice) Pending ¶ added in v1.0.0
func (d *RecordingAudioDevice) Pending() int
Pending returns the number of scheduled events that have not been fired yet.
func (*RecordingAudioDevice) PlayWithClock ¶ added in v1.0.0
func (d *RecordingAudioDevice) PlayWithClock(condition Condition, seq Sequenceable, clock *PlaybackClock) time.Time
func (*RecordingAudioDevice) Report ¶ added in v1.0.0
func (d *RecordingAudioDevice) Report()
func (*RecordingAudioDevice) Reset ¶ added in v1.0.0
func (d *RecordingAudioDevice) Reset()
Reset forgets all scheduled events, like the MIDI device does. Recorded events are kept.
func (*RecordingAudioDevice) RunUntil ¶ added in v1.0.0
func (d *RecordingAudioDevice) RunUntil(offset time.Duration)
RunUntil fires all scheduled events up to and including the given offset from the origin.
func (*RecordingAudioDevice) Schedule ¶ added in v1.0.0
func (d *RecordingAudioDevice) Schedule(event TimelineEvent, beginAt time.Time)
Schedule is part of AudioDevice.
type Replaceable ¶
type Replaceable interface {
// Returns a new value in which any occurrences of "from" are replaced by "to".
Replaced(from, to Sequenceable) Sequenceable
}
type Scale ¶
type Scale struct {
// contains filtered or unexported fields
}
func ParseScale ¶
func (Scale) Replaced ¶
func (s Scale) Replaced(from, to Sequenceable) Sequenceable
Replaced is part of Replaceable
func (Scale) WithRepeated ¶ added in v0.58.4
type Sequence ¶
type Sequence struct {
Notes [][]Note
}
func BuildSequence ¶
BuildSequence creates a Sequence from a slice of Note
func MustParseSequence ¶
func ParseSequence ¶
ParseSequence creates a Sequence by reading the format "Note* [Note Note*]* Note*"
func RestSequence ¶
RestSequence returns a sequence with rest notes up to <bars> respecting <biab>.
func (Sequence) DurationAt ¶ added in v0.48.0
func (Sequence) DurationFactor ¶
DurationFactor is only valid if none of its notes have a fixed duration.
func (Sequence) Inspect ¶
func (s Sequence) Inspect(i Inspection)
func (Sequence) NoDynamics ¶ added in v0.51.0
func (Sequence) NoFractions ¶ added in v0.51.0
func (Sequence) PrintString ¶
func (Sequence) Replaced ¶
func (s Sequence) Replaced(from, to Sequenceable) Sequenceable
Replaced is part of Replaceable
func (Sequence) SequenceJoin ¶
SequenceJoin returns s + t
type SequenceBuilder ¶ added in v0.44.0
type SequenceBuilder struct {
// contains filtered or unexported fields
}
func NewSequenceBuilder ¶ added in v0.44.0
func NewSequenceBuilder(periods []NotePeriod, bpm float64) *SequenceBuilder
func (*SequenceBuilder) Build ¶ added in v0.44.0
func (s *SequenceBuilder) Build() Sequence
type SequenceOnTrack ¶
type SequenceOnTrack struct {
Bar HasValue
Target Sequenceable
}
func NewSequenceOnTrack ¶
func NewSequenceOnTrack(bar HasValue, seq Sequenceable) SequenceOnTrack
func (SequenceOnTrack) S ¶
func (s SequenceOnTrack) S() Sequence
type Sequenceable ¶
type Sequenceable interface {
S() Sequence
}
func InList ¶
func InList(s Sequenceable) []Sequenceable
func ReplacedAll ¶ added in v0.54.1
func ReplacedAll(target []Sequenceable, from, to Sequenceable) []Sequenceable
func ToSequenceable ¶
func ToSequenceable(v HasValue) Sequenceable
func UnValue ¶
func UnValue(v Sequenceable) Sequenceable
type SequenceableList ¶ added in v0.54.0
type SequenceableList struct {
Target []Sequenceable
}
func (SequenceableList) S ¶ added in v0.54.0
func (l SequenceableList) S() Sequence
type TabNote ¶ added in v0.47.0
type TabNote struct {
Name string // E,A,D,G
Fret int // [0..24]
Dotted bool // if true then fraction is increased by half
Velocity int // 1..127
// contains filtered or unexported fields
}
https://www.studybass.com/lessons/reading-music/how-to-read-bass-tab/
func ParseTabNote ¶ added in v0.47.0
type TestLooper ¶
func (*TestLooper) BIAB ¶
func (t *TestLooper) BIAB() int
func (*TestLooper) BPM ¶
func (t *TestLooper) BPM() float64
func (*TestLooper) BeatsAndBars ¶
func (t *TestLooper) BeatsAndBars() (int64, int64)
func (*TestLooper) EndLoop ¶
func (t *TestLooper) EndLoop(l *Loop)
func (*TestLooper) Plan ¶
func (t *TestLooper) Plan(bars int64, seq Sequenceable)
func (*TestLooper) Reset ¶
func (t *TestLooper) Reset()
func (*TestLooper) SetBIAB ¶
func (t *TestLooper) SetBIAB(biab int)
func (*TestLooper) SetBPM ¶
func (t *TestLooper) SetBPM(bpm float64)
func (*TestLooper) SettingNotifier ¶
func (t *TestLooper) SettingNotifier(handler func(LoopController))
func (*TestLooper) Start ¶
func (t *TestLooper) Start()
func (*TestLooper) StartLoop ¶
func (t *TestLooper) StartLoop(l *Loop)
func (*TestLooper) Stop ¶
func (t *TestLooper) Stop()
func (*TestLooper) Tick ¶
func (t *TestLooper) Tick()
type Timeline ¶
type Timeline struct {
// contains filtered or unexported fields
}
Timeline is a chain of events that are placed in the future (playing).
func (*Timeline) BuildNotePeriods ¶ added in v0.44.0
func (t *Timeline) BuildNotePeriods() []NotePeriod
func (*Timeline) EventsDo ¶
func (t *Timeline) EventsDo(block func(event TimelineEvent, when time.Time))
EventsDo visits all scheduled events and calls the block for each.
func (*Timeline) NoteEvents ¶
func (*Timeline) Play ¶
func (t *Timeline) Play()
Play runs a loop to handle all the events in time. This is blocking.
func (*Timeline) Schedule ¶
func (t *Timeline) Schedule(event TimelineEvent, when time.Time) error
Schedule adds an event for a given time
func (*Timeline) Stop ¶ added in v1.0.0
func (t *Timeline) Stop()
Stop signals the Play loop to exit gracefully. Should be called during shutdown to clean up the timeline goroutine.
func (*Timeline) ZeroStarting ¶
ZeroStarting returns a new one in which all events are shifted back in time starting at time 0.
type TimelineEvent ¶
type TimelineEvent interface {
Handle(tim *Timeline, when time.Time)
NoteChangesDo(block func(NoteChange))
}
TimelineEvent describes an event that can be scheduled on a Timeline.
type Track ¶
type Track struct {
Title string
Channel int
Content map[int]Sequenceable // bar -> musical object
}
func (*Track) Inspect ¶
func (t *Track) Inspect(i Inspection)
type ValueFunction ¶
func (ValueFunction) Storex ¶
func (v ValueFunction) Storex() string
func (ValueFunction) Value ¶
func (v ValueFunction) Value() any
type ValueHolder ¶
type ValueHolder struct {
Any any
}
ValueHolder is decorate any object to become a HasValue.
func (ValueHolder) Storex ¶
func (h ValueHolder) Storex() string
func (ValueHolder) Value ¶
func (h ValueHolder) Value() any
Source Files
¶
- beatmaster.go
- beatschedule.go
- capabilities.go
- chord.go
- chord_sequence.go
- constants.go
- context.go
- doc.go
- euclidean.go
- format_parser.go
- inspect.go
- interfaces.go
- interfaces_mocks.go
- interval.go
- iterator.go
- loop.go
- map.go
- midi_note.go
- nexter.go
- note.go
- note_event.go
- note_midi.go
- note_ops.go
- print.go
- progression.go
- recording_audiodevice.go
- scale.go
- selectors.go
- sequence.go
- sequence_builder.go
- sequence_list.go
- sequence_ops.go
- sequence_transforms.go
- tabs.go
- tabs_parser.go
- test_looper.go
- timeline.go
- times.go
- track.go
- utils.go
- valueholder.go