pxt-common-packages 10.3.18 → 10.3.20

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 (38) hide show
  1. package/built/common-sim.d.ts +18 -0
  2. package/built/common-sim.js +285 -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/sequencer.ts +116 -0
  19. package/libs/mixer/sim/music.ts +102 -0
  20. package/libs/mqtt/built/debug/binary.js +176 -176
  21. package/libs/net/built/debug/binary.js +176 -176
  22. package/libs/net-game/built/debug/binary.js +8625 -8625
  23. package/libs/palette/built/debug/binary.js +7035 -7035
  24. package/libs/pixel/built/debug/binary.js +8 -8
  25. package/libs/power/built/debug/binary.js +8 -8
  26. package/libs/proximity/built/debug/binary.js +8 -8
  27. package/libs/radio/built/debug/binary.js +8 -8
  28. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  29. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  30. package/libs/screen/_locales/screen-jsdoc-strings.json +2 -0
  31. package/libs/screen/built/debug/binary.js +50 -50
  32. package/libs/screen/image.cpp +296 -0
  33. package/libs/screen/image.ts +44 -0
  34. package/libs/screen/sim/image.ts +240 -0
  35. package/libs/servo/built/debug/binary.js +8 -8
  36. package/libs/sprite-scaling/built/debug/binary.js +7035 -7035
  37. package/libs/storyboard/built/debug/binary.js +7035 -7035
  38. package/package.json +2 -2
@@ -947,6 +947,20 @@ declare namespace pxsim.music {
947
947
  function queuePlayInstructions(when: number, b: RefBuffer): void;
948
948
  function stopPlaying(): void;
949
949
  function forceOutput(mode: number): void;
950
+ const SEQUENCER_STOP_MESSAGE = 3243;
951
+ const SEQUENCER_TICK_MESSAGE = 3244;
952
+ const SEQUENCER_STATE_CHANGE_MESSAGE = 3245;
953
+ const SEQUENCER_LOOPED_MESSAGE = 3246;
954
+ function _createSequencer(): Promise<number>;
955
+ function _sequencerState(id: number): string;
956
+ function _sequencerCurrentTick(id: number): number;
957
+ function _sequencerPlaySong(id: number, song: RefBuffer, loop: boolean): void;
958
+ function _sequencerStop(id: number): void;
959
+ function _sequencerSetVolume(id: number, volume: number): void;
960
+ function _sequencerSetVolumeForAll(volume: number): void;
961
+ function _sequencerSetTrackVolume(id: number, trackIndex: number, volume: number): void;
962
+ function _sequencerSetDrumTrackVolume(id: number, trackIndex: number, drumIndex: number, volume: number): void;
963
+ function _sequencerDispose(id: number): void;
950
964
  }
951
965
  declare namespace pxsim.mouse {
952
966
  function setButton(button: number, down: boolean): void;
@@ -1117,6 +1131,10 @@ declare namespace pxsim.ImageMethods {
1117
1131
  function _drawIcon(img: RefImage, icon: RefBuffer, xy: number, color: number): void;
1118
1132
  function fillCircle(img: RefImage, cx: number, cy: number, r: number, c: number): void;
1119
1133
  function _fillCircle(img: RefImage, cxy: number, r: number, c: number): void;
1134
+ function fillTriangle(img: RefImage, x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, c: number): void;
1135
+ function _fillTriangle(img: RefImage, args: RefCollection): void;
1136
+ function fillPolygon4(img: RefImage, x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, c: number): void;
1137
+ function _fillPolygon4(img: RefImage, args: RefCollection): void;
1120
1138
  function _blitRow(img: RefImage, xy: number, from: RefImage, xh: number): void;
1121
1139
  function blitRow(img: RefImage, x: number, y: number, from: RefImage, fromX: number, fromH: number): void;
1122
1140
  function _blit(img: RefImage, src: RefImage, args: RefCollection): boolean;
@@ -3200,10 +3200,108 @@ var pxsim;
3200
3200
  music.queuePlayInstructions = queuePlayInstructions;
3201
3201
  function stopPlaying() {
3202
3202
  pxsim.AudioContextManager.muteAllChannels();
3203
+ if (sequencers) {
3204
+ for (const seq of sequencers) {
3205
+ seq.sequencer.stop();
3206
+ seq.sequencer.dispose();
3207
+ }
3208
+ }
3203
3209
  }
3204
3210
  music.stopPlaying = stopPlaying;
3205
3211
  function forceOutput(mode) { }
3206
3212
  music.forceOutput = forceOutput;
3213
+ music.SEQUENCER_STOP_MESSAGE = 3243;
3214
+ music.SEQUENCER_TICK_MESSAGE = 3244;
3215
+ music.SEQUENCER_STATE_CHANGE_MESSAGE = 3245;
3216
+ music.SEQUENCER_LOOPED_MESSAGE = 3246;
3217
+ let sequencers;
3218
+ let nextSequencerId = 0;
3219
+ async function _createSequencer() {
3220
+ if (!sequencers) {
3221
+ pxsim.AudioContextManager.onStopAll(() => {
3222
+ for (const seq of sequencers) {
3223
+ seq.sequencer.stop();
3224
+ seq.sequencer.dispose();
3225
+ }
3226
+ sequencers = [];
3227
+ });
3228
+ sequencers = [];
3229
+ }
3230
+ const res = {
3231
+ id: nextSequencerId++,
3232
+ sequencer: new music.Sequencer()
3233
+ };
3234
+ sequencers.push(res);
3235
+ await res.sequencer.initAsync();
3236
+ res.sequencer.addEventListener("stop", () => {
3237
+ pxsim.board().bus.queue(music.SEQUENCER_STOP_MESSAGE, this.id);
3238
+ });
3239
+ res.sequencer.addEventListener("state-change", () => {
3240
+ pxsim.board().bus.queue(music.SEQUENCER_STATE_CHANGE_MESSAGE, this.id);
3241
+ });
3242
+ res.sequencer.addEventListener("looped", () => {
3243
+ pxsim.board().bus.queue(music.SEQUENCER_LOOPED_MESSAGE, this.id);
3244
+ });
3245
+ res.sequencer.addEventListener("tick", () => {
3246
+ pxsim.board().bus.queue(music.SEQUENCER_TICK_MESSAGE, this.id);
3247
+ });
3248
+ return res.id;
3249
+ }
3250
+ music._createSequencer = _createSequencer;
3251
+ function _sequencerState(id) {
3252
+ var _a;
3253
+ return (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.state();
3254
+ }
3255
+ music._sequencerState = _sequencerState;
3256
+ function _sequencerCurrentTick(id) {
3257
+ var _a;
3258
+ return (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.currentTick();
3259
+ }
3260
+ music._sequencerCurrentTick = _sequencerCurrentTick;
3261
+ function _sequencerPlaySong(id, song, loop) {
3262
+ var _a;
3263
+ const decoded = music.decodeSong(song.data);
3264
+ (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.start(decoded, loop);
3265
+ }
3266
+ music._sequencerPlaySong = _sequencerPlaySong;
3267
+ function _sequencerStop(id) {
3268
+ var _a;
3269
+ (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.stop();
3270
+ }
3271
+ music._sequencerStop = _sequencerStop;
3272
+ function _sequencerSetVolume(id, volume) {
3273
+ var _a;
3274
+ (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.setVolume(volume);
3275
+ }
3276
+ music._sequencerSetVolume = _sequencerSetVolume;
3277
+ function _sequencerSetVolumeForAll(volume) {
3278
+ for (const seq of sequencers) {
3279
+ seq.sequencer.setVolume(volume);
3280
+ }
3281
+ }
3282
+ music._sequencerSetVolumeForAll = _sequencerSetVolumeForAll;
3283
+ function _sequencerSetTrackVolume(id, trackIndex, volume) {
3284
+ var _a;
3285
+ (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.setTrackVolume(trackIndex, volume);
3286
+ }
3287
+ music._sequencerSetTrackVolume = _sequencerSetTrackVolume;
3288
+ function _sequencerSetDrumTrackVolume(id, trackIndex, drumIndex, volume) {
3289
+ var _a;
3290
+ (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.setDrumTrackVolume(trackIndex, drumIndex, volume);
3291
+ }
3292
+ music._sequencerSetDrumTrackVolume = _sequencerSetDrumTrackVolume;
3293
+ function _sequencerDispose(id) {
3294
+ var _a;
3295
+ (_a = lookupSequencer(id)) === null || _a === void 0 ? void 0 : _a.dispose();
3296
+ sequencers = sequencers.filter(s => s.id !== id);
3297
+ }
3298
+ music._sequencerDispose = _sequencerDispose;
3299
+ function lookupSequencer(id) {
3300
+ for (const seq of sequencers)
3301
+ if (seq.id === id)
3302
+ return seq.sequencer;
3303
+ return undefined;
3304
+ }
3207
3305
  })(music = pxsim.music || (pxsim.music = {}));
3208
3306
  })(pxsim || (pxsim = {}));
3209
3307
  var pxsim;
@@ -4203,6 +4301,193 @@ var pxsim;
4203
4301
  fillCircle(img, XX(cxy), YY(cxy), r, c);
4204
4302
  }
4205
4303
  ImageMethods._fillCircle = _fillCircle;
4304
+ function nextYRange_Low(x, line, yRange) {
4305
+ while (line.x === x && line.x <= line.x1 && line.x < line.W) {
4306
+ if (0 <= line.x) {
4307
+ if (line.y < yRange.min)
4308
+ yRange.min = line.y;
4309
+ if (line.y > yRange.max)
4310
+ yRange.max = line.y;
4311
+ }
4312
+ if (line.D > 0) {
4313
+ line.y += line.yi;
4314
+ line.D -= line.dx;
4315
+ }
4316
+ line.D += line.dy;
4317
+ ++line.x;
4318
+ }
4319
+ }
4320
+ function nextYRange_HighUp(x, line, yRange) {
4321
+ while (line.x == x && line.y >= line.y1 && line.x < line.W) {
4322
+ if (0 <= line.x) {
4323
+ if (line.y < yRange.min)
4324
+ yRange.min = line.y;
4325
+ if (line.y > yRange.max)
4326
+ yRange.max = line.y;
4327
+ }
4328
+ if (line.D > 0) {
4329
+ line.x += line.xi;
4330
+ line.D += line.dy;
4331
+ }
4332
+ line.D += line.dx;
4333
+ --line.y;
4334
+ }
4335
+ }
4336
+ function nextYRange_HighDown(x, line, yRange) {
4337
+ while (line.x == x && line.y <= line.y1 && line.x < line.W) {
4338
+ if (0 <= line.x) {
4339
+ if (line.y < yRange.min)
4340
+ yRange.min = line.y;
4341
+ if (line.y > yRange.max)
4342
+ yRange.max = line.y;
4343
+ }
4344
+ if (line.D > 0) {
4345
+ line.x += line.xi;
4346
+ line.D -= line.dy;
4347
+ }
4348
+ line.D += line.dx;
4349
+ ++line.y;
4350
+ }
4351
+ }
4352
+ function initYRangeGenerator(X0, Y0, X1, Y1) {
4353
+ const line = {
4354
+ x: X0,
4355
+ y: Y0,
4356
+ x0: X0,
4357
+ y0: Y0,
4358
+ x1: X1,
4359
+ y1: Y1,
4360
+ W: 0,
4361
+ H: 0,
4362
+ dx: X1 - X0,
4363
+ dy: Y1 - Y0,
4364
+ yi: 0,
4365
+ xi: 0,
4366
+ D: 0,
4367
+ nextFuncIndex: 0,
4368
+ };
4369
+ if ((line.dy < 0 ? -line.dy : line.dy) < line.dx) {
4370
+ line.yi = 1;
4371
+ if (line.dy < 0) {
4372
+ line.yi = -1;
4373
+ line.dy = -line.dy;
4374
+ }
4375
+ line.D = 2 * line.dy - line.dx;
4376
+ line.dx = line.dx << 1;
4377
+ line.dy = line.dy << 1;
4378
+ line.nextFuncIndex = 0;
4379
+ return line;
4380
+ }
4381
+ else {
4382
+ line.xi = 1;
4383
+ if (line.dy < 0) {
4384
+ line.D = 2 * line.dx + line.dy;
4385
+ line.dx = line.dx << 1;
4386
+ line.dy = line.dy << 1;
4387
+ line.nextFuncIndex = 1;
4388
+ return line;
4389
+ }
4390
+ else {
4391
+ line.D = 2 * line.dx - line.dy;
4392
+ line.dx = line.dx << 1;
4393
+ line.dy = line.dy << 1;
4394
+ line.nextFuncIndex = 2;
4395
+ return line;
4396
+ }
4397
+ }
4398
+ }
4399
+ function fillTriangle(img, x0, y0, x1, y1, x2, y2, c) {
4400
+ if (x1 < x0) {
4401
+ [x1, x0] = [x0, x1];
4402
+ [y1, y0] = [y0, y1];
4403
+ }
4404
+ if (x2 < x1) {
4405
+ [x2, x1] = [x1, x2];
4406
+ [y2, y1] = [y1, y2];
4407
+ }
4408
+ if (x1 < x0) {
4409
+ [x1, x0] = [x0, x1];
4410
+ [y1, y0] = [y0, y1];
4411
+ }
4412
+ const lines = [
4413
+ initYRangeGenerator(x0, y0, x2, y2),
4414
+ initYRangeGenerator(x0, y0, x1, y1),
4415
+ initYRangeGenerator(x1, y1, x2, y2)
4416
+ ];
4417
+ lines[0].W = lines[1].W = lines[2].W = width(img);
4418
+ lines[0].H = lines[1].H = lines[2].H = height(img);
4419
+ const nextFuncList = [
4420
+ nextYRange_Low,
4421
+ nextYRange_HighUp,
4422
+ nextYRange_HighDown
4423
+ ];
4424
+ const fpNext0 = nextFuncList[lines[0].nextFuncIndex];
4425
+ const fpNext1 = nextFuncList[lines[1].nextFuncIndex];
4426
+ const fpNext2 = nextFuncList[lines[2].nextFuncIndex];
4427
+ const yRange = {
4428
+ min: lines[0].H,
4429
+ max: -1
4430
+ };
4431
+ for (let x = lines[1].x0; x <= lines[1].x1; x++) {
4432
+ yRange.min = lines[0].H;
4433
+ yRange.max = -1;
4434
+ fpNext0(x, lines[0], yRange);
4435
+ fpNext1(x, lines[1], yRange);
4436
+ fillRect(img, x, yRange.min, 1, yRange.max - yRange.min + 1, c);
4437
+ }
4438
+ fpNext2(lines[2].x0, lines[2], yRange);
4439
+ for (let x = lines[2].x0 + 1; x <= lines[2].x1; x++) {
4440
+ yRange.min = lines[0].H;
4441
+ yRange.max = -1;
4442
+ fpNext0(x, lines[0], yRange);
4443
+ fpNext2(x, lines[2], yRange);
4444
+ fillRect(img, x, yRange.min, 1, yRange.max - yRange.min + 1, c);
4445
+ }
4446
+ }
4447
+ ImageMethods.fillTriangle = fillTriangle;
4448
+ function _fillTriangle(img, args) {
4449
+ fillTriangle(img, args.getAt(0) | 0, args.getAt(1) | 0, args.getAt(2) | 0, args.getAt(3) | 0, args.getAt(4) | 0, args.getAt(5) | 0, args.getAt(6) | 0);
4450
+ }
4451
+ ImageMethods._fillTriangle = _fillTriangle;
4452
+ function fillPolygon4(img, x0, y0, x1, y1, x2, y2, x3, y3, c) {
4453
+ const lines = [
4454
+ (x0 < x1) ? initYRangeGenerator(x0, y0, x1, y1) : initYRangeGenerator(x1, y1, x0, y0),
4455
+ (x1 < x2) ? initYRangeGenerator(x1, y1, x2, y2) : initYRangeGenerator(x2, y2, x1, y1),
4456
+ (x2 < x3) ? initYRangeGenerator(x2, y2, x3, y3) : initYRangeGenerator(x3, y3, x2, y2),
4457
+ (x0 < x3) ? initYRangeGenerator(x0, y0, x3, y3) : initYRangeGenerator(x3, y3, x0, y0)
4458
+ ];
4459
+ lines[0].W = lines[1].W = lines[2].W = lines[3].W = width(img);
4460
+ lines[0].H = lines[1].H = lines[2].H = lines[3].H = height(img);
4461
+ let minX = Math.min(Math.min(x0, x1), Math.min(x2, x3));
4462
+ let maxX = Math.min(Math.max(Math.max(x0, x1), Math.max(x2, x3)), lines[0].W - 1);
4463
+ const nextFuncList = [
4464
+ nextYRange_Low,
4465
+ nextYRange_HighUp,
4466
+ nextYRange_HighDown
4467
+ ];
4468
+ const fpNext0 = nextFuncList[lines[0].nextFuncIndex];
4469
+ const fpNext1 = nextFuncList[lines[1].nextFuncIndex];
4470
+ const fpNext2 = nextFuncList[lines[2].nextFuncIndex];
4471
+ const fpNext3 = nextFuncList[lines[3].nextFuncIndex];
4472
+ const yRange = {
4473
+ min: lines[0].H,
4474
+ max: -1
4475
+ };
4476
+ for (let x = minX; x <= maxX; x++) {
4477
+ yRange.min = lines[0].H;
4478
+ yRange.max = -1;
4479
+ fpNext0(x, lines[0], yRange);
4480
+ fpNext1(x, lines[1], yRange);
4481
+ fpNext2(x, lines[2], yRange);
4482
+ fpNext3(x, lines[3], yRange);
4483
+ fillRect(img, x, yRange.min, 1, yRange.max - yRange.min + 1, c);
4484
+ }
4485
+ }
4486
+ ImageMethods.fillPolygon4 = fillPolygon4;
4487
+ function _fillPolygon4(img, args) {
4488
+ fillPolygon4(img, args.getAt(0) | 0, args.getAt(1) | 0, args.getAt(2) | 0, args.getAt(3) | 0, args.getAt(4) | 0, args.getAt(5) | 0, args.getAt(6) | 0, args.getAt(7) | 0, args.getAt(8) | 0);
4489
+ }
4490
+ ImageMethods._fillPolygon4 = _fillPolygon4;
4206
4491
  function _blitRow(img, xy, from, xh) {
4207
4492
  blitRow(img, XX(xy), YY(xy), from, XX(xh), YY(xh));
4208
4493
  }