pxt-common-packages 10.3.7 → 10.3.9

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 (51) hide show
  1. package/libs/azureiot/built/debug/binary.js +461 -461
  2. package/libs/color/built/debug/binary.js +8 -8
  3. package/libs/color-sensor/built/debug/binary.js +8 -8
  4. package/libs/controller/built/debug/binary.js +15483 -15338
  5. package/libs/controller---none/built/debug/binary.js +15467 -15322
  6. package/libs/datalogger/built/debug/binary.js +63 -63
  7. package/libs/edge-connector/built/debug/binary.js +8 -8
  8. package/libs/esp32/built/debug/binary.js +462 -462
  9. package/libs/game/_locales/game-jsdoc-strings.json +8 -3
  10. package/libs/game/_locales/game-strings.json +11 -0
  11. package/libs/game/ask.ts +0 -1
  12. package/libs/game/built/debug/binary.js +16092 -15947
  13. package/libs/game/controller.ts +0 -6
  14. package/libs/game/game.ts +194 -45
  15. package/libs/game/gameutil.ts +0 -2
  16. package/libs/game/info.ts +98 -45
  17. package/libs/game/multiplayer.ts +9 -8
  18. package/libs/game/ns.ts +5 -0
  19. package/libs/game/numberprompt.ts +0 -1
  20. package/libs/game/particleeffects.ts +30 -0
  21. package/libs/game/prompt.ts +0 -1
  22. package/libs/game/pxt.json +1 -0
  23. package/libs/game/textDialogs.ts +275 -40
  24. package/libs/lcd/built/debug/binary.js +8 -8
  25. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  26. package/libs/lora/built/debug/binary.js +8 -8
  27. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  28. package/libs/mixer/instrument.ts +20 -1
  29. package/libs/mixer/melody.ts +13 -15
  30. package/libs/mixer/playable.ts +181 -0
  31. package/libs/mixer/pxt.json +1 -0
  32. package/libs/mixer/soundEffect.ts +19 -2
  33. package/libs/mqtt/built/debug/binary.js +176 -176
  34. package/libs/multiplayer/ns.ts +6 -0
  35. package/libs/multiplayer/player.ts +24 -6
  36. package/libs/multiplayer/pxt.json +1 -0
  37. package/libs/music/ns.ts +1 -1
  38. package/libs/net/built/debug/binary.js +176 -176
  39. package/libs/net-game/built/debug/binary.js +20403 -20258
  40. package/libs/palette/built/debug/binary.js +16083 -15938
  41. package/libs/pixel/built/debug/binary.js +8 -8
  42. package/libs/power/built/debug/binary.js +8 -8
  43. package/libs/proximity/built/debug/binary.js +8 -8
  44. package/libs/radio/built/debug/binary.js +8 -8
  45. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  46. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  47. package/libs/screen/built/debug/binary.js +50 -50
  48. package/libs/servo/built/debug/binary.js +8 -8
  49. package/libs/sprite-scaling/built/debug/binary.js +16091 -15946
  50. package/libs/storyboard/built/debug/binary.js +16091 -15946
  51. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
1
  namespace music.sequencer {
2
2
  const BUFFER_SIZE = 12;
3
3
 
4
+ let currentSequencer: sequencer.Sequencer;
5
+
4
6
  /**
5
7
  * Byte encoding format for songs
6
8
  * FIXME: should this all be word aligned?
@@ -66,10 +68,11 @@ namespace music.sequencer {
66
68
  * 2 = sharp
67
69
  */
68
70
 
69
- export class Song {
71
+ export class Song extends Playable {
70
72
  tracks: Track[];
71
73
 
72
74
  constructor(public buf: Buffer) {
75
+ super();
73
76
  this.tracks = [];
74
77
 
75
78
  let currentOffset = 7;
@@ -128,6 +131,22 @@ namespace music.sequencer {
128
131
  get numberOfTracks(): number {
129
132
  return this.buf[6];
130
133
  }
134
+
135
+ play(playbackMode: PlaybackMode) {
136
+ if (currentSequencer) currentSequencer.stop();
137
+ currentSequencer = new sequencer.Sequencer(this);
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);
145
+ }
146
+ else {
147
+ currentSequencer.start(true);
148
+ }
149
+ }
131
150
  }
132
151
 
133
152
  export class Envelope {
@@ -81,6 +81,7 @@ namespace music {
81
81
  //% blockNamespace=music
82
82
  //% weight=76 blockGap=8
83
83
  //% group="Tone"
84
+ //% deprecated=1
84
85
  export function playTone(frequency: number, ms: number): void {
85
86
  if (ms == 0)
86
87
  ms = 86400000 // 1 day
@@ -123,6 +124,7 @@ namespace music {
123
124
  //% melody.shadow="melody_editor"
124
125
  //% tempo.min=40 tempo.max=500
125
126
  //% tempo.defl=120
127
+ //% deprecated=1
126
128
  export function playMelody(melody: string, tempo: number) {
127
129
  let notes: string[] = melody.split(" ").filter(n => !!n);
128
130
  let formattedMelody = "";
@@ -181,6 +183,7 @@ namespace music {
181
183
  export function stopAllSounds() {
182
184
  Melody.stopAll();
183
185
  stopPlaying();
186
+ _stopPlayables();
184
187
  }
185
188
 
186
189
  //% fixedInstances
@@ -213,6 +216,7 @@ namespace music {
213
216
  //% parts="headphone"
214
217
  //% weight=92 blockGap=8
215
218
  //% group="Sounds"
219
+ //% deprecated=1
216
220
  stop() {
217
221
  if (this._player) {
218
222
  this._player.stop()
@@ -270,6 +274,7 @@ namespace music {
270
274
  //% parts="headphone"
271
275
  //% weight=93 blockGap=8
272
276
  //% group="Sounds"
277
+ //% deprecated=1
273
278
  loop(volume = 255) {
274
279
  this.playCore(volume, true)
275
280
  }
@@ -283,6 +288,7 @@ namespace music {
283
288
  //% parts="headphone"
284
289
  //% weight=95 blockGap=8
285
290
  //% group="Sounds"
291
+ //% deprecated=1
286
292
  play(volume = 255) {
287
293
  this.playCore(volume, false)
288
294
  }
@@ -297,6 +303,7 @@ namespace music {
297
303
  //% parts="headphone"
298
304
  //% weight=94 blockGap=8
299
305
  //% group="Sounds"
306
+ //% deprecated=1
300
307
  playUntilDone(volume = 255) {
301
308
  this.stop()
302
309
  const p = this._player = new MelodyPlayer(this)
@@ -583,24 +590,15 @@ namespace music {
583
590
  }
584
591
  }
585
592
 
586
- let currentSequencer: sequencer.Sequencer;
587
-
588
593
  //% shim=TD_ID
589
594
  //% blockId=music_song_field_editor
590
- //% block="$song"
595
+ //% block="song $song"
591
596
  //% song.fieldEditor=musiceditor
592
- export function _songFieldEditor(song: Buffer) {
593
- return song;
594
- }
595
-
596
- //% blockId=music_start_song
597
- //% block="start song $song looping $loop"
598
- //% song.shadow=music_song_field_editor
599
- export function startSong(song: Buffer, loop: boolean) {
600
- if (currentSequencer) currentSequencer.stop();
601
-
602
- currentSequencer = new sequencer.Sequencer(new sequencer.Song(song));
603
- currentSequencer.start(loop);
597
+ //% toolboxParent=music_playable_play
598
+ //% toolboxParentArgument=toPlay
599
+ //% group="Songs"
600
+ export function createSong(song: Buffer): Playable {
601
+ return new sequencer.Song(song);
604
602
  }
605
603
 
606
604
  export function playInstructions(when: number, instructions: Buffer) {
@@ -0,0 +1,181 @@
1
+ namespace music {
2
+ export enum PlaybackMode {
3
+ //% block="until done"
4
+ UntilDone,
5
+ //% block="in background"
6
+ InBackground,
7
+ //% block="looping in background"
8
+ LoopingInBackground
9
+ }
10
+
11
+ let stateStack: PlayableState[];
12
+
13
+ class PlayableState {
14
+ looping: Playable[];
15
+ constructor() {
16
+ this.looping = [];
17
+ }
18
+
19
+ stopLooping() {
20
+ for (const p of this.looping) {
21
+ p.stopped = true;
22
+ }
23
+ this.looping = [];
24
+ }
25
+ }
26
+
27
+ function state() {
28
+ _init();
29
+ return stateStack[stateStack.length - 1];
30
+ }
31
+
32
+ function _init() {
33
+ if (stateStack) return;
34
+ stateStack = [new PlayableState()];
35
+
36
+ game.addScenePushHandler(() => {
37
+ stateStack.push(new PlayableState());
38
+ });
39
+
40
+ game.addScenePopHandler(() => {
41
+ stateStack.pop();
42
+ if (stateStack.length === 0) stateStack.push(new PlayableState());
43
+ });
44
+ }
45
+
46
+ export class Playable {
47
+ stopped: boolean;
48
+ constructor() {
49
+
50
+ }
51
+
52
+ play(playbackMode: PlaybackMode) {
53
+ // subclass
54
+ }
55
+
56
+ loop() {
57
+ state().looping.push(this);
58
+ this.stopped = false;
59
+
60
+ control.runInParallel(() => {
61
+ while (!this.stopped) {
62
+ this.play(PlaybackMode.UntilDone);
63
+ }
64
+ });
65
+ }
66
+ }
67
+
68
+ export class MelodyPlayable extends Playable {
69
+ constructor(public melody: Melody) {
70
+ super();
71
+ }
72
+
73
+ play(playbackMode: PlaybackMode) {
74
+ if (playbackMode === PlaybackMode.InBackground) {
75
+ this.melody.play(music.volume());
76
+ }
77
+ else if (playbackMode === PlaybackMode.UntilDone) {
78
+ this.melody.playUntilDone(music.volume());
79
+ }
80
+ else {
81
+ this.melody.loop(music.volume());
82
+ }
83
+ }
84
+ }
85
+
86
+ export class TonePlayable extends Playable {
87
+ constructor(public pitch: number, public duration: number) {
88
+ super();
89
+ }
90
+
91
+ play(playbackMode: PlaybackMode) {
92
+ if (playbackMode === PlaybackMode.InBackground) {
93
+ control.runInParallel(() => music.playTone(this.pitch, this.duration));
94
+ }
95
+ else if (playbackMode === PlaybackMode.UntilDone) {
96
+ music.playTone(this.pitch, this.duration);
97
+ if (this.duration > 2000) {
98
+ pause(this.duration);
99
+ }
100
+ }
101
+ else {
102
+ this.loop();
103
+ }
104
+ }
105
+ }
106
+
107
+ //% blockId="music_playable_play"
108
+ //% block="play $toPlay $playbackMode"
109
+ //% toPlay.shadow=music_melody_playable
110
+ //% group="Sounds"
111
+ export function play(toPlay: Playable, playbackMode: PlaybackMode) {
112
+ toPlay.play(playbackMode);
113
+ }
114
+
115
+ //% blockId="music_melody_playable"
116
+ //% block="sound $melody"
117
+ //% toolboxParent=music_playable_play
118
+ //% toolboxParentArgument=toPlay
119
+ //% group="Sounds"
120
+ //% duplicateShadowOnDrag
121
+ //% blockHidden
122
+ export function melodyPlayable(melody: Melody): Playable {
123
+ return new MelodyPlayable(melody);
124
+ }
125
+
126
+
127
+ //% blockId="music_string_playable"
128
+ //% block="melody $melody at tempo $tempo|(bpm)"
129
+ //% toolboxParent=music_playable_play
130
+ //% toolboxParentArgument=toPlay
131
+ //% weight=85 blockGap=8
132
+ //% help=music/melody-editor
133
+ //% group="Songs"
134
+ //% duplicateShadowOnDrag
135
+ //% melody.shadow=melody_editor
136
+ //% tempo.min=40 tempo.max=500
137
+ //% tempo.defl=120
138
+ export function stringPlayable(melody: string, tempo: number): Playable {
139
+ let notes: string[] = melody.split(" ").filter(n => !!n);
140
+ let formattedMelody = "";
141
+ let newOctave = false;
142
+
143
+ // build melody string, replace '-' with 'R' and add tempo
144
+ // creates format like "C5-174 B4 A G F E D C "
145
+ for (let i = 0; i < notes.length; i++) {
146
+ if (notes[i] === "-") {
147
+ notes[i] = "R";
148
+ } else if (notes[i] === "C5") {
149
+ newOctave = true;
150
+ } else if (newOctave) { // change the octave if necesary
151
+ notes[i] += "4";
152
+ newOctave = false;
153
+ }
154
+ // add tempo after first note
155
+ if (i == 0) {
156
+ formattedMelody += notes[i] + "-" + tempo + " ";
157
+ } else {
158
+ formattedMelody += notes[i] + " ";
159
+ }
160
+ }
161
+
162
+ return new MelodyPlayable(new Melody(formattedMelody));
163
+ }
164
+
165
+ //% blockId="music_tone_playable"
166
+ //% block="tone $note for $duration"
167
+ //% toolboxParent=music_playable_play
168
+ //% toolboxParentArgument=toPlay
169
+ //% group="Tone"
170
+ //% duplicateShadowOnDrag
171
+ //% note.shadow=device_note
172
+ //% duration.shadow=device_beat
173
+ //% parts="headphone"
174
+ export function tonePlayable(note: number, duration: number): Playable {
175
+ return new TonePlayable(note, duration);
176
+ }
177
+
178
+ export function _stopPlayables() {
179
+ state().stopLooping();
180
+ }
181
+ }
@@ -16,6 +16,7 @@
16
16
  "soundEffect.ts",
17
17
  "instrument.ts",
18
18
  "sequencer.ts",
19
+ "playable.ts",
19
20
  "pxtparts.json",
20
21
  "headphone.svg"
21
22
  ],
@@ -39,7 +39,7 @@ enum SoundExpressionPlayMode {
39
39
  }
40
40
 
41
41
  namespace music {
42
- export class SoundEffect {
42
+ export class SoundEffect extends Playable {
43
43
  waveShape: WaveShape;
44
44
  startFrequency: number;
45
45
  endFrequency: number;
@@ -50,6 +50,7 @@ namespace music {
50
50
  interpolation: InterpolationCurve;
51
51
 
52
52
  constructor() {
53
+ super();
53
54
  this.waveShape = WaveShape.Sine;
54
55
  this.startFrequency = 5000;
55
56
  this.endFrequency = 1;
@@ -77,6 +78,20 @@ namespace music {
77
78
  volume
78
79
  );
79
80
  }
81
+
82
+ play(playbackMode: PlaybackMode) {
83
+ const toPlay = this.toBuffer(music.volume());
84
+ if (playbackMode === PlaybackMode.InBackground) {
85
+ queuePlayInstructions(0, toPlay);
86
+ }
87
+ else if (playbackMode === PlaybackMode.UntilDone) {
88
+ queuePlayInstructions(0, toPlay);
89
+ pause(this.duration)
90
+ }
91
+ else {
92
+ this.loop();
93
+ }
94
+ }
80
95
  }
81
96
 
82
97
 
@@ -87,11 +102,11 @@ namespace music {
87
102
  */
88
103
  //% blockId=soundExpression_playSoundEffect
89
104
  //% block="play sound $sound $mode"
90
- //% sound.shadow=soundExpression_createSoundEffect
91
105
  //% weight=30
92
106
  //% help=music/play-sound-effect
93
107
  //% blockGap=8
94
108
  //% group="Sounds"
109
+ //% deprecated=1
95
110
  export function playSoundEffect(sound: SoundEffect, mode: SoundExpressionPlayMode) {
96
111
  const toPlay = sound.toBuffer(music.volume());
97
112
 
@@ -139,6 +154,8 @@ namespace music {
139
154
  //% inlineInputMode="variable"
140
155
  //% inlineInputModeLimit=3
141
156
  //% expandableArgumentBreaks="3,5"
157
+ //% toolboxParent=music_playable_play
158
+ //% toolboxParentArgument=toPlay
142
159
  //% weight=20
143
160
  //% group="Sounds"
144
161
  export function createSoundEffect(waveShape: WaveShape, startFrequency: number, endFrequency: number, startVolume: number, endVolume: number, duration: number, effect: SoundExpressionEffect, interpolation: InterpolationCurve): SoundEffect {