-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern.ts
More file actions
56 lines (45 loc) · 1.32 KB
/
pattern.ts
File metadata and controls
56 lines (45 loc) · 1.32 KB
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
namespace micromusic {
export type Note = [string, number]
export const NUM_CHANNELS = 4
export class Pattern {
private _channels: Channel[]
private _id: number
constructor(id: number) {
this._channels = [
new Channel(),
new Channel(),
new Channel(),
new Channel(),
]
this._id = id
}
public get id() {
return this._id
}
public setChannel(channel: Channel, index: number) {
this._channels[index] = channel
}
public get channels() {
return this._channels
}
public getChannel(index: number) {
return this._channels[index]
}
public playAsync() {
// starts playing on all channels, each one has their own control.inbackground?
}
toJSON() {
return {
id: this._id,
channels: this._channels.map(c => c.toJSON()),
}
}
static fromJSON(data: any): Pattern {
const pattern = new Pattern(data.id)
pattern._channels = (<Array<Channel>>data.channels).map((c: any) =>
Channel.fromJSON(c),
)
return pattern
}
}
}