-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ts
225 lines (197 loc) · 5.68 KB
/
api.ts
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
* VVN TODO
*/
//% color="#b3687d" weight=100 icon="\uf1ec" block="Soundtrack"
namespace soundtrack {
export enum TrackRole {
//% block="Bass"
Bass,
//% block="Rhythm"
Rhythm,
//% block="Melody"
Melody,
//% block="Flavor"
Flavor
}
export enum PlaySpeed {
//% block="Very Slowly"
VerySlowly,
//% block="Slowly"
Slowly,
//% block="Normal"
Normal,
//% block="Quickly"
Quickly,
//% block="Very Quickly"
VeryQuickly
}
export enum MusicMood {
//% block="Adventure"
Adventure,
//% block="Chill"
Chill,
//% block="Magical"
Magical,
//% block="Free",
Free,
//% block="Bluesy"
Bluesy
}
export enum TrackPlayType {
//% block="Loop"
Loop,
//% block="One Shot"
OneShot
}
export enum InstrumentType {
//% block="Piano"
Piano,
//% block="Brass"
Brass,
//% block="String"
String,
//% block="Bells"
Bell,
//% block="Drums"
Percussion,
//% block="Chip"
Chip
}
/***********************************
* PLAY
***********************************/
//% block="play soundtrack $name"
//% group="Play"
export function playSoundtrack(name: string): void {
playSoundtrackSecret(name);
}
//% block="stop soundtrack"
//% group="Play"
export function stopSountrack() {
stopSoundtrackSecret();
}
//% block="change key by $interval"
//% group="Play"
export function changeKeyBy(interval: number) {
changeKeyBySecret(interval);
}
/***********************************
* MOTIF
***********************************/
/**
* Create a new motif from image
*/
//% blockId="motifCreate" block="motif $img"
//% img.shadow="screen_image_picker"
//% block
//% group="Compose"
export function motif( img: Image): Motif {
return soundtrack.createMotif(img);
}
//% block="play $motif on $track $speed"
//% motif.shadow="motifCreate"
//% speed.shadow="soundtrack_speed_picker"
//% group="Compose"
export function playMotif(track: string, motif: Motif, speed: PlaySpeed) {
registerMotif(track, motif, speed);
}
/***********************************
* SOUNDTRACK
***********************************/
/**
* Define a soundtrack with a name. Doesn't play it
*/
//% block="soundtrack $name"
//% group="Song"
export function setSoundtrack(name: string, handler: () => void) {
registerSoundtrack(name, handler)
}
//% blockId=soundtrack_set_key
//% block="set key $key"
//% key.fieldEditor="note"
//% group="Song"
export function setSountrackKey(key: number) {
setSoundtrackKeySecret(key)
}
//% blockId=soundtrack_set_mood
//% block="set mood to $mood"
//% mood.shadow="soundtrack_mood_picker"
//% group="Song"
export function setSoundtrackMood(mood: number) {
setSoundtrackMoodSecret(mood)
}
//% blockId=soundtrack_set_chords
//% block="set chords $chords in key $key"
//% key.fieldEditor="note"
//% group="Song"
export function setChords(chords: string, key: Note) {
setChordsSecret(chords, key);
}
/***********************************
* TRACK
***********************************/
//% block="set track $name $instrument as $role $t"
//% handlerStatement
//% instrument.shadow=soundtrack_instrument_picker
//% role.shadow=soundtrack_track_role_picker
//% t.shadow=soundtrack_track_play_type
//% expandableArgumentMode="toggle"
//% group="Track"
export function setTrack(name: string, instrument: number, role: number, t: number, handler: ()=>void) {
registerTrack(name, instrument, role, t, handler);
}
//% blockId=soundtrack_set_volume
//% block="set track $track volume $vol"
//% group="Track"
export function setTrackVolume(track: string, vol: number) {
setTrackVolumeSecret(track, vol);
}
/***********************************
* shhhh
***********************************/
//% blockId=soundtrack_track_role_picker
//% shim=TD_ID
//% block="$role"
//% blockHidden=true
//% role.defl="soundtrack.TrackRole.Melody"
//% duplicateShadowOnDrag
export function _trackRole(role: TrackRole): number {
return role;
}
//% blockId=soundtrack_speed_picker
//% shim=TD_ID
//% block="$speed"
//% blockHidden=true
//% speed.defl="soundtrack.PlaySpeed.Normal"
//% duplicateShadowOnDrag
export function _playSpeed(speed: PlaySpeed): number {
return speed;
}
//% blockId=soundtrack_track_play_type
//% shim=TD_ID
//% block="$theType"
//% blockHidden=true
//% theType.defl="soundtrack.TrackPlayType.Loop"
//% duplicateShadowOnDrag
export function _trackPlayType(theType: TrackPlayType): number {
return theType;
}
//% blockId=soundtrack_mood_picker
//% shim=TD_ID
//% block="$mood"
//% blockHidden=true
//% type.defl="soundtrack.MusicMood.Adventure"
//% duplicateShadowOnDrag
export function _setSoundtrackMood(mood: MusicMood): number {
return mood
}
//% blockId=soundtrack_instrument_picker
//% shim=TD_ID
//% block="$instrument"
//% blockHidden=true
//% instrument.defl="Piano"
//% duplicateShadowOnDrag
export function _instrument(instrument: InstrumentType): number {
return instrument
}
}