core

package
v0.50.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package melrose is for programming music melodies in Go

Index

Examples

Constants

View Source
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
)
View Source
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

View Source
const (
	// OnceFromTo "once"
	OnceFromTo = iota
	// OnceFromToFrom "once-two-way"
	OnceFromToFrom
	// RepeatFromTo "repeat"
	RepeatFromTo
	// RepeatFromToFrom "repeat-two-way"
	RepeatFromToFrom
)
View Source
const EditorLineEnd = "editor.line.end"
View Source
const EditorLineStart = "editor.line.start"
View Source
const WorkingDirectory = "shell.pwd"

WorkingDirectory is a key in a context environment.

Variables

View Source
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)
)
View Source
var BuildTag = "dev"
View Source
var EmptySequence = Sequence{}
View Source
var NoLooper = zeroBeat{}

NoLooper is a Beatmaster that does not loop

Functions

func AppendStorexList

func AppendStorexList(b *bytes.Buffer, isFirstParameter bool, list []Sequenceable)

func ContainsInt

func ContainsInt(list []int, value int) bool

func Duration

func Duration(h HasValue) time.Duration

func DurationToFraction

func DurationToFraction(bpm float64, d time.Duration) float32

func Float

func Float(h HasValue) float32

func FractionToDurationParts added in v0.44.0

func FractionToDurationParts(f float64) (fraction float32, dotted bool)

func FractionToString added in v0.47.0

func FractionToString(f float32) string

func IndexOf

func IndexOf(v interface{}) interface{}

IndexOf returns the non HasValue value of v

func InspectValue

func InspectValue(ctx Context, v interface{})

func Int

func Int(h HasValue) int

func IsBlackKey

func IsBlackKey(nr int) bool

func IsDebug

func IsDebug() bool

func IsIdenticalTo

func IsIdenticalTo(left, right Sequenceable) bool

func MIDIToNoteParts added in v0.44.0

func MIDIToNoteParts(nr int) (name string, octave int, accidental int)

func NotesEventsToFile added in v0.44.0

func NotesEventsToFile(events []NoteEvent, name string)

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 ParseVelocity(plusmin string) (velocity int)

func PrintValue

func PrintValue(ctx Context, v interface{})

func QuantizeFraction

func QuantizeFraction(durationFactor float32) (fraction float32, dotted bool, ok bool)

func Storex

func Storex(v interface{}) string

func String

func String(h HasValue) string

func StringFromNoteGroup

func StringFromNoteGroup(notes []Note) string

func ToggleDebug

func ToggleDebug() bool

func ValueOf

func ValueOf(v interface{}) interface{}

ValueOf returns the non HasValue value of v

func VelocityToDynamic added in v0.45.0

func VelocityToDynamic(v int) string

func WholeNoteDuration

func WholeNoteDuration(bpm float64) time.Duration

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 []interface{}) error

	// Play schedules all the notes on the timeline using a BPM (beats-per-minute).
	// Returns the end time of the last played Note.
	Play(condition Condition, seq Sequenceable, bpm float64, beginAt time.Time) (endingAt time.Time)

	HasInputCapability() bool
	Listen(deviceID int, who NoteListener, startOrStop 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)

	// Record(ctx Context) (*Recording, error)
	Reset()
	Close() error
}

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 BeatAction func(when time.Time)

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 MustParseChord(s string) Chord

func ParseChord

func ParseChord(s string) (Chord, error)

C/D7/2 = C dominant 7, 2nd inversion

func (Chord) Inspect

func (c Chord) Inspect(i Inspection)

func (Chord) Notes

func (c Chord) Notes() []Note

Notes returns the Note values for this chord.

func (Chord) Replaced

func (c Chord) Replaced(from, to Sequenceable) Sequenceable

Replaced is part of Replaceable

func (Chord) S

func (c Chord) S() Sequence

S converts a Chord into a Sequence

func (Chord) Storex

func (c Chord) Storex() string

Storex implements Storable

func (Chord) String

func (c Chord) String() string

func (Chord) WithFraction added in v0.45.0

func (c Chord) WithFraction(f float32, dotted bool) Chord

func (Chord) WithInterval

func (c Chord) WithInterval(i int) Chord

func (Chord) WithInversion

func (c Chord) WithInversion(i int) Chord

func (Chord) WithQuality

func (c Chord) WithQuality(q int) Chord

func (Chord) WithVelocity added in v0.45.0

func (c Chord) WithVelocity(v int) Chord

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

func (c ChordProgression) S() Sequence

S is part of Sequenceable

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 Condition

type Condition func() bool
var (
	NoCondition   Condition = nil
	TrueCondition Condition = func() bool { return true }
)

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 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 Evaluatable

type Evaluatable interface {
	Evaluate(ctx Context) error
}

TODO makue users use Play with a Context that can have a Condition

type HasIndex

type HasIndex interface {
	Index() HasValue
}

type HasValue

type HasValue interface {
	Value() interface{}
}

func On

func On(v interface{}) HasValue

func ToHasValue

func ToHasValue(v interface{}) HasValue

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]interface{}
}

func NewInspect

func NewInspect(ctx Context, varname string, value interface{}) 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

func NewInterval(from, to, by HasValue, strategy int) *Interval

NewInterval creates new Interval. The initial Value is set to [from]. Specify the repeat strategy.

func (Interval) Inspect

func (i Interval) Inspect(n Inspection)

Inpsect is part of Inspectable

func (*Interval) Next

func (i *Interval) Next() interface{}

Next returns and increases its value with [by].

func (Interval) Storex

func (i Interval) Storex() string

Storex is part of Storable.

func (*Interval) Value

func (i *Interval) Value() interface{}

type Iterator

type Iterator struct {
	Target []interface{}
	// contains filtered or unexported fields
}

func (*Iterator) Index

func (i *Iterator) Index() HasValue

Index returns the current index of the iterator as a HasValue ; 1-based

func (Iterator) Inspect

func (i Iterator) Inspect(in Inspection)

Inspect is part of Inspectable

func (*Iterator) Next

func (i *Iterator) Next() interface{}

Next is part of Nextable

func (*Iterator) S

func (i *Iterator) S() Sequence

S is part of Sequenceable

func (Iterator) Storex

func (i Iterator) Storex() string

Storex is part of Storable

func (*Iterator) Value

func (i *Iterator) Value() interface{}

Value is part of HasValue

func (*Iterator) VariableName added in v0.50.1

func (i *Iterator) VariableName(n string)

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

func (l *Loop) Evaluate(ctx Context) error

func (*Loop) Handle

func (l *Loop) Handle(tim *Timeline, when time.Time)

Handle is part of TimelineEvent

func (*Loop) Inspect

func (l *Loop) Inspect(i Inspection)

Inspect is part of Inspectable

func (*Loop) IsPlaying

func (l *Loop) IsPlaying() bool

IsPlaying is part of Playable

func (*Loop) IsRunning

func (l *Loop) IsRunning() bool

func (*Loop) NextPlayAt

func (l *Loop) NextPlayAt() time.Time

func (*Loop) NoteChangesDo

func (l *Loop) NoteChangesDo(block func(NoteChange))

func (*Loop) Play

func (l *Loop) Play(ctx Context, at time.Time) error

Play is part of Playable

func (*Loop) S

func (l *Loop) S() Sequence

func (*Loop) SetTarget

func (l *Loop) SetTarget(newTarget []Sequenceable)

func (*Loop) Stop

func (l *Loop) Stop(ctx Context) error

Stop is part of Playable

func (*Loop) Storex

func (l *Loop) Storex() string

func (*Loop) Target

func (l *Loop) Target() []Sequenceable

func (*Loop) ToSequence

func (l *Loop) ToSequence(loopcount int) Sequence

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 NewMIDI

func NewMIDI(duration HasValue, number HasValue, velocity HasValue) MIDINote

func (MIDINote) Inspect

func (m MIDINote) Inspect(i Inspection)

func (MIDINote) S

func (m MIDINote) S() Sequence

func (MIDINote) Storex

func (m MIDINote) Storex() string

func (MIDINote) ToNote

func (m MIDINote) ToNote() (Note, error)

ToNote() is part of NoteConvertable

type MultiTrack

type MultiTrack struct {
	Tracks []HasValue
}

func (MultiTrack) Play

func (m MultiTrack) Play(ctx Context, at time.Time) error

Play is part of Playable

func (MultiTrack) Storex

func (m MultiTrack) Storex() string

Storex implements Storable

type NameAware

type NameAware interface {
	VariableName(yours string)
}

type Nextable

type Nextable interface {
	Next() interface{}
}

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.

func (Nexter) S

func (n Nexter) S() Sequence

S is part of Sequenceable

func (Nexter) Storex

func (n Nexter) Storex() string

Storex is part of Storable

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 MIDItoNote

func MIDItoNote(fraction float32, nr int, vel int) (Note, error)

func MakeNote

func MakeNote(name string, octave int, frac float32, accidental int, dot bool, velocity int) Note

func MustParseNote

func MustParseNote(input string) Note

MustParseNote returns a Note by parsing the input. Panic if it fails.

func NewNote

func NewNote(name string, octave int, frac float32, accidental int, dot bool, velocity int) (Note, error)

func ParseNote

func ParseNote(input string) (Note, error)

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 (n Note) CheckTieableTo(t Note) error

func (Note) DurationAt added in v0.48.0

func (n Note) DurationAt(bpm float64) time.Duration

func (Note) DurationFactor

func (n Note) DurationFactor() float32

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) Equals added in v0.45.0

func (n Note) Equals(o Note) bool

func (Note) Fraction added in v0.45.0

func (n Note) Fraction() float32

func (Note) HasEqualTied added in v0.45.0

func (n Note) HasEqualTied(o Note) bool

func (Note) Inspect

func (n Note) Inspect(i Inspection)

func (Note) IsHearable

func (n Note) IsHearable() bool

func (Note) IsPedal added in v0.44.0

func (n Note) IsPedal() bool

func (Note) IsPedalDown

func (n Note) IsPedalDown() bool

func (Note) IsPedalUp

func (n Note) IsPedalUp() bool

func (Note) IsPedalUpDown

func (n Note) IsPedalUpDown() bool

func (Note) IsRest

func (n Note) IsRest() bool

func (Note) MIDI

func (n Note) MIDI() int

func (Note) NonFractionBasedDuration

func (n Note) NonFractionBasedDuration() (time.Duration, bool)

func (Note) Octaved

func (n Note) Octaved(howmuch int) Note

func (Note) Pitched

func (n Note) Pitched(howManySemitones int) Note

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

func (n Note) S() Sequence

func (Note) Storex

func (n Note) Storex() string

func (Note) Stretched

func (n Note) Stretched(f float32) Note

func (Note) String

func (n Note) String() string

func (Note) ToNote

func (n Note) ToNote() (Note, error)

ToNote() is part of NoteConvertable

func (Note) ToRest

func (n Note) ToRest() Note

func (Note) WithDynamic

func (n Note) WithDynamic(emphasis string) Note

func (Note) WithFraction

func (n Note) WithFraction(f float32, dotted bool) Note

func (Note) WithTiedNote added in v0.45.0

func (n Note) WithTiedNote(t Note) Note

func (Note) WithVelocity

func (n Note) WithVelocity(v int) Note

func (Note) WithoutDynamic added in v0.45.0

func (n Note) WithoutDynamic() Note

type NoteChange

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

func NewNoteChange

func NewNoteChange(isOn bool, midiNr int64, velocity int64) NoteChange

func (NoteChange) Handle

func (n NoteChange) Handle(tim *Timeline, when time.Time)

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 NoteChangeEvent struct {
	When     int64 `json:"when"`
	IsOn     bool  `json:"ison"`
	Note     int64 `json:"note"`
	Velocity int64 `json:"velocity"`
}

type NoteConvertable

type NoteConvertable interface {
	ToNote() (Note, error)
}

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

func NoteEventsFromFile(name string) (list []NoteEvent)

func (NoteEvent) WithEnd

func (e NoteEvent) WithEnd(end time.Time) NoteEvent

type NoteEventStatistics

type NoteEventStatistics struct {
	Start, End      time.Time
	Lowest, Highest int
}

func NoteStatistics

func NoteStatistics(list []NoteEvent) (stats NoteEventStatistics)

func (NoteEventStatistics) String

func (s NoteEventStatistics) String() string

type NoteListener

type NoteListener interface {
	NoteOn(channel int, note Note)
	NoteOff(channel int, note Note)
	ControlChange(channel, number, value int)
}

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 Playable

type Playable interface {
	Play(ctx Context, at time.Time) error
}

type Print

type Print struct {
	Context Context
	Target  interface{}
}

func (Print) Evaluate

func (w Print) Evaluate(ctx Context) error

func (Print) Play

func (w Print) Play(ctx Context, at time.Time) error

func (Print) S

func (w Print) S() Sequence

S is part of Sequenceable

func (Print) Storex added in v0.45.0

func (w Print) Storex() string

Storex is part of Storable

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 NewScale

func NewScale(octaves int, input string) (Scale, error)

func ParseScale

func ParseScale(s string) (Scale, error)

func (Scale) ChordAt

func (s Scale) ChordAt(index int) Chord

ChordAt uses one-based index

func (Scale) Replaced

func (s Scale) Replaced(from, to Sequenceable) Sequenceable

Replaced is part of Replaceable

func (Scale) S

func (s Scale) S() Sequence

func (Scale) Storex

func (s Scale) Storex() string

type Sequence

type Sequence struct {
	Notes [][]Note
}

func BuildSequence

func BuildSequence(notes []Note) Sequence

BuildSequence creates a Sequence from a slice of Note

func MustParseSequence

func MustParseSequence(input string) Sequence

func ParseSequence

func ParseSequence(input string) (Sequence, error)

ParseSequence creates a Sequence by reading the format "Note* [Note Note*]* Note*"

func RestSequence

func RestSequence(bars, biab int) Sequence

RestSequence returns a sequence with rest notes up to <bars> respecting <biab>.

func (Sequence) At

func (s Sequence) At(i int) []Note

At uses zero-based indexing into the Notes

func (Sequence) Bars

func (s Sequence) Bars(biab int) float64

func (Sequence) DurationAt added in v0.48.0

func (s Sequence) DurationAt(bpm float64) time.Duration

func (Sequence) DurationFactor

func (s Sequence) DurationFactor() float64

DurationFactor is only valid if none of its notes have a fixed duration.

func (Sequence) Inspect

func (s Sequence) Inspect(i Inspection)

func (Sequence) NotesDo

func (s Sequence) NotesDo(block func(Note))

func (Sequence) Octaved

func (s Sequence) Octaved(howMuch int) Sequence

func (Sequence) Pitched

func (s Sequence) Pitched(semitones int) Sequence

func (Sequence) PrintString

func (s Sequence) PrintString(sharpOrFlatKey int) string

func (Sequence) Replaced

func (s Sequence) Replaced(from, to Sequenceable) Sequenceable

Replaced is part of Replaceable

func (Sequence) Reversed

func (s Sequence) Reversed() Sequence

func (Sequence) RotatedBy

func (s Sequence) RotatedBy(howMany int) Sequence

TODO create op for this

func (Sequence) S

func (s Sequence) S() Sequence

func (Sequence) SequenceJoin

func (s Sequence) SequenceJoin(t Sequence) Sequence

SequenceJoin returns s + t

func (Sequence) Split

func (s Sequence) Split() []Sequence

Split return sequences with one-note groups. Merge would produce s again.

func (Sequence) Storex

func (s Sequence) Storex() string

Storex returns the command line expression that creates the receiver

func (Sequence) Stretched

func (s Sequence) Stretched(f float32) Sequence

func (Sequence) String

func (s Sequence) String() string

func (Sequence) ToRest

func (s Sequence) ToRest() Sequence

func (Sequence) W

func (s Sequence) W() string

W returns the mapping of each note to a delta of semitones compared to middle C4. Can be used for the pitch lane of the Korg Wavestate

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

func (SequenceOnTrack) Storex

func (s SequenceOnTrack) Storex() string

Storex implements Storable

type Sequenceable

type Sequenceable interface {
	S() Sequence
}

func InList

func InList(s Sequenceable) []Sequenceable

func ToSequenceable

func ToSequenceable(v HasValue) Sequenceable

func UnValue

func UnValue(v Sequenceable) Sequenceable

type Stoppable

type Stoppable interface {
	Stop(ctx Context) error
	IsPlaying() bool
}

type Storable

type Storable interface {
	Storex() string
}

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

func ParseTabNote(input string) (TabNote, error)

func (TabNote) IsRest added in v0.47.0

func (t TabNote) IsRest() bool

func (TabNote) String added in v0.47.0

func (t TabNote) String() string

func (TabNote) ToNote added in v0.47.0

func (t TabNote) ToNote() Note

func (TabNote) WriteWith added in v0.47.0

func (t TabNote) WriteWith(b *strings.Builder)

type TestLooper

type TestLooper struct {
	Beats int64
	Bars  int64
	Biab  int64
}

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 NewTimeline

func NewTimeline() *Timeline

NewTimeline creates a new Timeline.

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

func (t *Timeline) Len() int64

Len returns the current number of scheduled events.

func (*Timeline) NoteEvents

func (t *Timeline) NoteEvents() (list []NoteEvent)

func (*Timeline) Play

func (t *Timeline) Play()

Play runs a loop to handle all the events in time. This is blocking.

func (*Timeline) Reset

func (t *Timeline) Reset()

Reset forgets about all scheduled calls.

func (*Timeline) Schedule

func (t *Timeline) Schedule(event TimelineEvent, when time.Time) error

Schedule adds an event for a given time

func (*Timeline) ZeroStarting

func (t *Timeline) ZeroStarting() *Timeline

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 NewTrack

func NewTrack(title string, channel int) *Track

func (*Track) Add

func (t *Track) Add(seq SequenceOnTrack)

Add adds a SequenceOnTrack

func (*Track) Inspect

func (t *Track) Inspect(i Inspection)

func (*Track) Play

func (t *Track) Play(ctx Context, now time.Time) error

func (*Track) Storex

func (t *Track) Storex() string

Storex implements Storable

type ValueFunction

type ValueFunction struct {
	StoreString string
	Function    func() interface{}
}

func (ValueFunction) Storex

func (v ValueFunction) Storex() string

func (ValueFunction) Value

func (v ValueFunction) Value() interface{}

type ValueHolder

type ValueHolder struct {
	Any interface{}
}

ValueHolder is decorate any object to become a HasValue.

func (ValueHolder) Storex

func (h ValueHolder) Storex() string

func (ValueHolder) String

func (h ValueHolder) String() string

TODO used?

func (ValueHolder) Value

func (h ValueHolder) Value() interface{}

type VariableStorage

type VariableStorage interface {
	NameFor(value interface{}) string
	Get(key string) (interface{}, bool)
	Put(key string, value interface{})
	Delete(key string)
	Variables() map[string]interface{}
}

Jump to

Keyboard shortcuts

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