-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
interfaces.go
147 lines (112 loc) · 2.97 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package core
import (
"sync"
"time"
"github.com/emicklei/melrose/notify"
)
type Sequenceable interface {
S() Sequence
}
type NoteConvertable interface {
ToNote() (Note, error)
}
type Storable interface {
Storex() string
}
type Indexable interface {
At(i int) Sequenceable
}
type Nextable interface {
Next() interface{}
}
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 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 Replaceable interface {
// Returns a new value in which any occurrences of "from" are replaced by "to".
Replaced(from, to Sequenceable) Sequenceable
}
type HasValue interface {
Value() interface{}
}
type Inspectable interface {
Inspect(i Inspection)
}
type Playable interface {
Play(ctx Context, at time.Time) error
}
type Stoppable interface {
Stop(ctx Context) error
IsPlaying() bool
}
type VariableStorage interface {
NameFor(value interface{}) string
Get(key string) (interface{}, bool)
Put(key string, value interface{})
Delete(key string)
Variables() map[string]interface{}
}
type Context interface {
Control() LoopController
Device() AudioDevice
Variables() VariableStorage
Environment() *sync.Map
WithCondition(c Condition) Context
Capabilities() *Capabilities
}
// WorkingDirectory is a key in a context environment.
const WorkingDirectory = "shell.pwd"
const EditorLineStart = "editor.line.start"
const EditorLineEnd = "editor.line.end"
// TODO makue users use Play with a Context that can have a Condition
type Evaluatable interface {
Evaluate(ctx Context) error
}
type NoteListener interface {
NoteOn(channel int, note Note)
NoteOff(channel int, note Note)
ControlChange(channel, number, value int)
}
type Conditional interface {
Condition() Condition
}
type Condition func() bool
var (
NoCondition Condition = nil
TrueCondition Condition = func() bool { return true }
)
type NameAware interface {
VariableName(yours string)
}
type HasIndex interface {
Index() HasValue
}