pxt-common-packages 10.3.17 → 10.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/built/common-sim.d.ts +14 -0
  2. package/built/common-sim.js +98 -0
  3. package/libs/azureiot/built/debug/binary.js +461 -461
  4. package/libs/color/built/debug/binary.js +8 -8
  5. package/libs/color-sensor/built/debug/binary.js +8 -8
  6. package/libs/controller/built/debug/binary.js +7117 -7117
  7. package/libs/controller---none/built/debug/binary.js +7097 -7097
  8. package/libs/datalogger/built/debug/binary.js +63 -63
  9. package/libs/edge-connector/built/debug/binary.js +8 -8
  10. package/libs/esp32/built/debug/binary.js +462 -462
  11. package/libs/game/built/debug/binary.js +7036 -7036
  12. package/libs/lcd/built/debug/binary.js +8 -8
  13. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  14. package/libs/lora/built/debug/binary.js +8 -8
  15. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  16. package/libs/mixer/instrument.ts +28 -9
  17. package/libs/mixer/melody.cpp +43 -0
  18. package/libs/mixer/melody.ts +4 -0
  19. package/libs/mixer/sequencer.ts +116 -0
  20. package/libs/mixer/sim/music.ts +102 -0
  21. package/libs/mqtt/built/debug/binary.js +176 -176
  22. package/libs/net/built/debug/binary.js +176 -176
  23. package/libs/net-game/built/debug/binary.js +8625 -8625
  24. package/libs/palette/built/debug/binary.js +7035 -7035
  25. package/libs/pixel/built/debug/binary.js +8 -8
  26. package/libs/power/built/debug/binary.js +8 -8
  27. package/libs/proximity/built/debug/binary.js +8 -8
  28. package/libs/radio/built/debug/binary.js +8 -8
  29. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  30. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  31. package/libs/screen/built/debug/binary.js +50 -50
  32. package/libs/servo/built/debug/binary.js +8 -8
  33. package/libs/sprite-scaling/built/debug/binary.js +7035 -7035
  34. package/libs/storyboard/built/debug/binary.js +7035 -7035
  35. package/package.json +2 -2
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P48826(s) {
59
+ function _main___P48860(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___49069 = (undefined);
70
- globals._pollEventQueue___49082 = (undefined);
69
+ globals._intervals___49103 = (undefined);
70
+ globals._pollEventQueue___49116 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P48826.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P48826.continuations = [ ]
75
+ _main___P48860.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P48860.continuations = [ ]
77
77
 
78
- function _main___P48826_mk(s) {
78
+ function _main___P48860_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P48826, depth: s.depth + 1,
81
+ parent: s, fn: _main___P48860, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P48826_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P48826
91
+ return _main___P48860
92
92
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P98810(s) {
59
+ function _main___P98912(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___99053 = (undefined);
70
- globals._pollEventQueue___99066 = (undefined);
69
+ globals._intervals___99155 = (undefined);
70
+ globals._pollEventQueue___99168 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P98810.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P98810.continuations = [ ]
75
+ _main___P98912.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P98912.continuations = [ ]
77
77
 
78
- function _main___P98810_mk(s) {
78
+ function _main___P98912_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P98810, depth: s.depth + 1,
81
+ parent: s, fn: _main___P98912, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P98810_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P98810
91
+ return _main___P98912
92
92
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P60128(s) {
59
+ function _main___P60162(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___60371 = (undefined);
70
- globals._pollEventQueue___60384 = (undefined);
69
+ globals._intervals___60405 = (undefined);
70
+ globals._pollEventQueue___60418 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P60128.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P60128.continuations = [ ]
75
+ _main___P60162.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P60162.continuations = [ ]
77
77
 
78
- function _main___P60128_mk(s) {
78
+ function _main___P60162_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P60128, depth: s.depth + 1,
81
+ parent: s, fn: _main___P60162, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P60128_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P60128
91
+ return _main___P60162
92
92
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P192302(s) {
59
+ function _main___P192540(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___192545 = (undefined);
70
- globals._pollEventQueue___192558 = (undefined);
69
+ globals._intervals___192783 = (undefined);
70
+ globals._pollEventQueue___192796 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P192302.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P192302.continuations = [ ]
75
+ _main___P192540.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P192540.continuations = [ ]
77
77
 
78
- function _main___P192302_mk(s) {
78
+ function _main___P192540_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P192302, depth: s.depth + 1,
81
+ parent: s, fn: _main___P192540, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P192302_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P192302
91
+ return _main___P192540
92
92
  })
@@ -133,18 +133,36 @@ namespace music.sequencer {
133
133
  }
134
134
 
135
135
  play(playbackMode: PlaybackMode) {
136
- if (currentSequencer) currentSequencer.stop();
137
- currentSequencer = new sequencer.Sequencer(this);
136
+ if (control.deviceDalVersion() === "sim") {
137
+ const seq = new _SimulatorSequencer();
138
138
 
139
- if (playbackMode === PlaybackMode.UntilDone) {
140
- currentSequencer.start(false);
141
- pause(this.measures * this.beatsPerMeasure * this.beatsPerMinute * 60 * 1000)
142
- }
143
- else if (playbackMode === PlaybackMode.InBackground) {
144
- currentSequencer.start(false);
139
+ if (playbackMode === PlaybackMode.UntilDone) {
140
+ seq.play(this.buf, false);
141
+
142
+ pauseUntil(() => seq.state() === "stop");
143
+ }
144
+ else if (playbackMode === PlaybackMode.InBackground) {
145
+ seq.play(this.buf, false);
146
+ }
147
+ else {
148
+ seq.play(this.buf, true);
149
+ }
145
150
  }
146
151
  else {
147
- currentSequencer.start(true);
152
+ if (currentSequencer) currentSequencer.stop();
153
+ currentSequencer = new sequencer.Sequencer(this);
154
+
155
+ if (playbackMode === PlaybackMode.UntilDone) {
156
+ let seq = currentSequencer;
157
+ currentSequencer.start(false);
158
+ pauseUntil(() => !seq.isRunning);
159
+ }
160
+ else if (playbackMode === PlaybackMode.InBackground) {
161
+ currentSequencer.start(false);
162
+ }
163
+ else {
164
+ currentSequencer.start(true);
165
+ }
148
166
  }
149
167
  }
150
168
  }
@@ -817,5 +835,6 @@ namespace music.sequencer {
817
835
  currentSequencer.stop();
818
836
  currentSequencer = undefined;
819
837
  }
838
+ _stopAllSimSequencers();
820
839
  }
821
840
  }
@@ -426,6 +426,49 @@ WSynthesizer::WSynthesizer() : upstream(NULL), out(*this) {
426
426
  PXT_REGISTER_RESET(stopPlaying);
427
427
  }
428
428
 
429
+ //% promise
430
+ int _createSequencer() {
431
+ return 0;
432
+ }
433
+
434
+ //%
435
+ String _sequencerState(int id) {
436
+ return NULL;
437
+ }
438
+
439
+ //%
440
+ int _sequencerCurrentTick(int id) {
441
+ return 0;
442
+ }
443
+
444
+ //%
445
+ void _sequencerPlaySong(int id, Buffer buf, bool loop) {
446
+ }
447
+
448
+ //%
449
+ void _sequencerStop(int id) {
450
+ }
451
+
452
+ //%
453
+ void _sequencerSetVolume(int id, int volume) {
454
+ }
455
+
456
+ //%
457
+ void _sequencerSetVolumeForAll(int volume) {
458
+ }
459
+
460
+ //%
461
+ void _sequencerSetTrackVolume(int id, int trackIndex, int volume) {
462
+ }
463
+
464
+ //%
465
+ void _sequencerSetDrumTrackVolume(int id, int trackIndex, int drumIndex, int volume) {
466
+ }
467
+
468
+ //%
469
+ void _sequencerDispose(int id) {
470
+ }
471
+
429
472
  } // namespace music
430
473
 
431
474
  namespace pxt {
@@ -594,6 +594,10 @@ namespace music {
594
594
  //% blockId=music_song_field_editor
595
595
  //% block="song $song"
596
596
  //% song.fieldEditor=musiceditor
597
+ //% song.fieldOptions.decompileLiterals=true
598
+ //% song.fieldOptions.taggedTemplate="hex"
599
+ //% song.fieldOptions.decompileIndirectFixedInstances="true"
600
+ //% song.fieldOptions.decompileArgumentAsString="true"
597
601
  //% toolboxParent=music_playable_play
598
602
  //% toolboxParentArgument=toPlay
599
603
  //% group="Songs"
@@ -1,4 +1,9 @@
1
1
  namespace music.sequencer {
2
+ const SEQUENCER_STOP_MESSAGE = 3243;
3
+ const SEQUENCER_TICK_MESSAGE = 3244;
4
+ const SEQUENCER_STATE_CHANGE_MESSAGE = 3245;
5
+ const SEQUENCER_LOOPED_MESSAGE = 3246;
6
+
2
7
  export class Sequencer {
3
8
  currentTick: number;
4
9
  isPlaying: boolean;
@@ -85,4 +90,115 @@ namespace music.sequencer {
85
90
  }
86
91
  }
87
92
  }
93
+
94
+ let activeSimSequencers: _SimulatorSequencer[];
95
+ export function _stopAllSimSequencers() {
96
+ if (activeSimSequencers) {
97
+ for (const seq of activeSimSequencers) {
98
+ seq.stop();
99
+ seq.dispose();
100
+ }
101
+ activeSimSequencers = [];
102
+ }
103
+ }
104
+
105
+ // Simulator only! Does nothing on hardware
106
+ export class _SimulatorSequencer {
107
+ protected id: number;
108
+
109
+ constructor() {
110
+ if (!activeSimSequencers) activeSimSequencers = [];
111
+ activeSimSequencers.push(this);
112
+ this.id = _createSequencer();
113
+ this.setVolume(music.volume());
114
+ }
115
+
116
+ play(song: Buffer, loop: boolean) {
117
+ this.setVolume(music.volume());
118
+ _sequencerPlaySong(this.id, song, loop)
119
+ }
120
+
121
+ stop() {
122
+ _sequencerStop(this.id);
123
+ }
124
+
125
+ setVolume(volume: number) {
126
+ _sequencerSetVolume(this.id, volume);
127
+ }
128
+
129
+ setTrackVolume(trackIndex: number, volume: number) {
130
+ _sequencerSetTrackVolume(this.id, trackIndex, volume)
131
+ }
132
+
133
+ setDrumTrackVolume(trackIndex: number, drumIndex: number, volume: number) {
134
+ _sequencerSetDrumTrackVolume(this.id, drumIndex, trackIndex, volume)
135
+ }
136
+
137
+ state() {
138
+ return _sequencerState(this.id) || "stop";
139
+ }
140
+
141
+ currentTick() {
142
+ return _sequencerCurrentTick(this.id);
143
+ }
144
+
145
+ dispose() {
146
+ _sequencerDispose(this.id);
147
+ }
148
+
149
+ onTick(handler: (tick: number) => void) {
150
+ control.onEvent(SEQUENCER_TICK_MESSAGE, this.id, () => {
151
+ handler(this.currentTick());
152
+ });
153
+ }
154
+
155
+ onStateChange(handler: (state: string) => void) {
156
+ control.onEvent(SEQUENCER_STATE_CHANGE_MESSAGE, this.id, () => {
157
+ handler(this.state());
158
+ });
159
+ }
160
+
161
+ onStop(handler: () => void) {
162
+ control.onEvent(SEQUENCER_STOP_MESSAGE, this.id, () => {
163
+ handler();
164
+ });
165
+ }
166
+
167
+ onLooped(handler: () => void) {
168
+ control.onEvent(SEQUENCER_LOOPED_MESSAGE, this.id, () => {
169
+ handler();
170
+ });
171
+ }
172
+ }
173
+
174
+ //% promise
175
+ //% shim=music::_createSequencer
176
+ declare function _createSequencer(): number
177
+
178
+ //% shim=music::_sequencerState
179
+ declare function _sequencerState(id: number): string;
180
+
181
+ //% shim=music::_sequencerCurrentTick
182
+ declare function _sequencerCurrentTick(id: number): number;
183
+
184
+ //% shim=music::_sequencerPlaySong
185
+ declare function _sequencerPlaySong(id: number, song: Buffer, loop: boolean): void;
186
+
187
+ //% shim=music::_sequencerStop
188
+ declare function _sequencerStop(id: number): void;
189
+
190
+ //% shim=music::_sequencerSetVolume
191
+ declare function _sequencerSetVolume(id: number, volume: number): void;
192
+
193
+ //% shim=music::_sequencerSetVolumeForAll
194
+ declare function _sequencerSetVolumeForAll(volume: number): void;
195
+
196
+ //% shim=music::_sequencerSetTrackVolume
197
+ declare function _sequencerSetTrackVolume(id: number, trackIndex: number, volume: number): void;
198
+
199
+ //% shim=music::_sequencerSetDrumTrackVolume
200
+ declare function _sequencerSetDrumTrackVolume(id: number, trackIndex: number, drumIndex: number, volume: number): void;
201
+
202
+ //% shim=music::_sequencerDispose
203
+ declare function _sequencerDispose(id: number): void;
88
204
  }
@@ -9,7 +9,109 @@ namespace pxsim.music {
9
9
 
10
10
  export function stopPlaying() {
11
11
  AudioContextManager.muteAllChannels()
12
+
13
+ if (sequencers) {
14
+ for (const seq of sequencers) {
15
+ seq.sequencer.stop();
16
+ seq.sequencer.dispose();
17
+ }
18
+ }
12
19
  }
13
20
 
14
21
  export function forceOutput(mode: number) { }
22
+
23
+ export const SEQUENCER_STOP_MESSAGE = 3243;
24
+ export const SEQUENCER_TICK_MESSAGE = 3244;
25
+ export const SEQUENCER_STATE_CHANGE_MESSAGE = 3245;
26
+ export const SEQUENCER_LOOPED_MESSAGE = 3246;
27
+
28
+ interface SequencerWithId {
29
+ id: number;
30
+ sequencer: Sequencer;
31
+ }
32
+
33
+ let sequencers: SequencerWithId[];
34
+ let nextSequencerId = 0;
35
+
36
+ export async function _createSequencer(): Promise<number> {
37
+ if (!sequencers) {
38
+ pxsim.AudioContextManager.onStopAll(() => {
39
+ for (const seq of sequencers) {
40
+ seq.sequencer.stop();
41
+ seq.sequencer.dispose();
42
+ }
43
+ sequencers = [];
44
+ })
45
+
46
+ sequencers = [];
47
+ }
48
+ const res = {
49
+ id: nextSequencerId++,
50
+ sequencer: new Sequencer()
51
+ };
52
+
53
+ sequencers.push(res)
54
+
55
+ await res.sequencer.initAsync();
56
+ res.sequencer.addEventListener("stop", () => {
57
+ board().bus.queue(SEQUENCER_STOP_MESSAGE, this.id);
58
+ });
59
+ res.sequencer.addEventListener("state-change", () => {
60
+ board().bus.queue(SEQUENCER_STATE_CHANGE_MESSAGE, this.id);
61
+ });
62
+ res.sequencer.addEventListener("looped", () => {
63
+ board().bus.queue(SEQUENCER_LOOPED_MESSAGE, this.id);
64
+ });
65
+ res.sequencer.addEventListener("tick", () => {
66
+ board().bus.queue(SEQUENCER_TICK_MESSAGE, this.id);
67
+ });
68
+
69
+
70
+ return res.id;
71
+ }
72
+
73
+ export function _sequencerState(id: number): string {
74
+ return lookupSequencer(id)?.state();
75
+ }
76
+
77
+ export function _sequencerCurrentTick(id: number): number {
78
+ return lookupSequencer(id)?.currentTick();
79
+ }
80
+
81
+ export function _sequencerPlaySong(id: number, song: RefBuffer, loop: boolean): void {
82
+ const decoded = decodeSong(song.data);
83
+ lookupSequencer(id)?.start(decoded, loop);
84
+ }
85
+
86
+ export function _sequencerStop(id: number): void {
87
+ lookupSequencer(id)?.stop();
88
+ }
89
+
90
+ export function _sequencerSetVolume(id: number, volume: number): void {
91
+ lookupSequencer(id)?.setVolume(volume);
92
+ }
93
+
94
+ export function _sequencerSetVolumeForAll(volume: number): void {
95
+ for (const seq of sequencers) {
96
+ seq.sequencer.setVolume(volume);
97
+ }
98
+ }
99
+
100
+ export function _sequencerSetTrackVolume(id: number, trackIndex: number, volume: number): void {
101
+ lookupSequencer(id)?.setTrackVolume(trackIndex, volume);
102
+ }
103
+
104
+ export function _sequencerSetDrumTrackVolume(id: number, trackIndex: number, drumIndex: number, volume: number): void {
105
+ lookupSequencer(id)?.setDrumTrackVolume(trackIndex, drumIndex, volume);
106
+ }
107
+
108
+ export function _sequencerDispose(id: number) {
109
+ lookupSequencer(id)?.dispose();
110
+ sequencers = sequencers.filter(s => s.id !== id);
111
+ }
112
+
113
+ function lookupSequencer(id: number) {
114
+ for (const seq of sequencers) if (seq.id === id) return seq.sequencer;
115
+ return undefined;
116
+ }
15
117
  }