pxt-common-packages 10.3.1 → 10.3.3
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.
- package/built/common-sim.d.ts +2 -2
- package/libs/azureiot/built/debug/binary.js +461 -461
- package/libs/color/built/debug/binary.js +8 -8
- package/libs/color-sensor/built/debug/binary.js +8 -8
- package/libs/controller/built/debug/binary.js +7736 -7608
- package/libs/controller---none/built/debug/binary.js +7715 -7587
- package/libs/datalogger/built/debug/binary.js +63 -63
- package/libs/edge-connector/built/debug/binary.js +9 -9
- package/libs/esp32/built/debug/binary.js +462 -462
- package/libs/game/assetTemplates.ts +10 -0
- package/libs/game/built/debug/binary.js +7628 -7500
- package/libs/game/camera.ts +18 -13
- package/libs/game/physics.ts +2 -1
- package/libs/game/scenes.ts +3 -0
- package/libs/lcd/built/debug/binary.js +8 -8
- package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
- package/libs/lora/built/debug/binary.js +8 -8
- package/libs/matrix-keypad/built/debug/binary.js +8 -8
- package/libs/mixer/instrument.ts +776 -0
- package/libs/mixer/melody.h +1 -1
- package/libs/mixer/melody.ts +29 -1
- package/libs/mixer/pxt.json +2 -0
- package/libs/mixer/sequencer.ts +88 -0
- package/libs/mqtt/built/debug/binary.js +176 -176
- package/libs/net/built/debug/binary.js +176 -176
- package/libs/net-game/built/debug/binary.js +9540 -9412
- package/libs/palette/built/debug/binary.js +7627 -7499
- package/libs/pixel/built/debug/binary.js +8 -8
- package/libs/power/built/debug/binary.js +8 -8
- package/libs/proximity/built/debug/binary.js +8 -8
- package/libs/radio/built/debug/binary.js +8 -8
- package/libs/radio-broadcast/built/debug/binary.js +8 -8
- package/libs/rotary-encoder/built/debug/binary.js +8 -8
- package/libs/screen/built/debug/binary.js +50 -50
- package/libs/servo/built/debug/binary.js +8 -8
- package/libs/sprite-scaling/built/debug/binary.js +7627 -7499
- package/libs/storyboard/built/debug/binary.js +7627 -7499
- package/package.json +1 -1
package/libs/mixer/melody.h
CHANGED
package/libs/mixer/melody.ts
CHANGED
|
@@ -313,7 +313,7 @@ namespace music {
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
-
function addNote(sndInstr: Buffer, sndInstrPtr: number, ms: number, beg: number, end: number, soundWave: number, hz: number, volume: number, endHz: number) {
|
|
316
|
+
export function addNote(sndInstr: Buffer, sndInstrPtr: number, ms: number, beg: number, end: number, soundWave: number, hz: number, volume: number, endHz: number) {
|
|
317
317
|
if (ms > 0) {
|
|
318
318
|
sndInstr.setNumber(NumberFormat.UInt8LE, sndInstrPtr, soundWave)
|
|
319
319
|
sndInstr.setNumber(NumberFormat.UInt8LE, sndInstrPtr + 1, 0)
|
|
@@ -583,6 +583,34 @@ namespace music {
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
|
|
586
|
+
let currentSequencer: sequencer.Sequencer;
|
|
587
|
+
|
|
588
|
+
//% shim=TD_ID
|
|
589
|
+
//% blockId=music_song_field_editor
|
|
590
|
+
//% block="$song"
|
|
591
|
+
//% 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);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function playInstructions(when: number, instructions: Buffer) {
|
|
607
|
+
queuePlayInstructions(when, instructions);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export function lookupFrequency(note: number) {
|
|
611
|
+
return freqs.getNumber(NumberFormat.UInt16LE, note * 2) || 0
|
|
612
|
+
}
|
|
613
|
+
|
|
586
614
|
//% fixedInstance whenUsed block="ba ding"
|
|
587
615
|
export const baDing = new Melody('b5:1 e6:3')
|
|
588
616
|
|
package/libs/mixer/pxt.json
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
namespace music.sequencer {
|
|
2
|
+
export class Sequencer {
|
|
3
|
+
currentTick: number;
|
|
4
|
+
isPlaying: boolean;
|
|
5
|
+
isLooping: boolean;
|
|
6
|
+
isRunning: boolean;
|
|
7
|
+
|
|
8
|
+
constructor(public song: Song) {
|
|
9
|
+
this.currentTick = 0;
|
|
10
|
+
this.isPlaying = false;
|
|
11
|
+
this.isLooping = false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
start(loop: boolean) {
|
|
15
|
+
this.currentTick = 0;
|
|
16
|
+
this.isLooping = loop;
|
|
17
|
+
this.isPlaying = true;
|
|
18
|
+
|
|
19
|
+
if (this.isRunning) return;
|
|
20
|
+
this.isRunning = true;
|
|
21
|
+
|
|
22
|
+
control.runInParallel(() => {
|
|
23
|
+
while (this.isPlaying) {
|
|
24
|
+
this.scheduleCurrentTick();
|
|
25
|
+
|
|
26
|
+
this.currentTick ++;
|
|
27
|
+
|
|
28
|
+
if (this.currentTick >= this.song.beatsPerMeasure * this.song.measures * this.song.ticksPerBeat) {
|
|
29
|
+
if (this.isLooping) this.currentTick = 0;
|
|
30
|
+
else this.isPlaying = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
pause(this.tickToMs(1))
|
|
34
|
+
}
|
|
35
|
+
this.isRunning = false;
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
stop() {
|
|
40
|
+
this.isPlaying = false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
tickToMs(ticks: number) {
|
|
44
|
+
return ((60000 / this.song.beatsPerMinute) / this.song.ticksPerBeat) * ticks;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected scheduleCurrentTick() {
|
|
48
|
+
for (const track of this.song.tracks) {
|
|
49
|
+
if (track.currentNoteEvent.startTick === this.currentTick) {
|
|
50
|
+
if (track.isMelodicTrack) {
|
|
51
|
+
this.scheduleMelodicTrack(track as MelodicTrack);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.scheduleDrumTrack(track as DrumTrack);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
track.advanceNoteEvent();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected scheduleMelodicTrack(track: MelodicTrack) {
|
|
63
|
+
for (let i = 0; i < track.currentNoteEvent.polyphony; i++) {
|
|
64
|
+
playInstructions(
|
|
65
|
+
0,
|
|
66
|
+
renderInstrument(
|
|
67
|
+
track.instrument,
|
|
68
|
+
lookupFrequency(track.currentNoteEvent.getNote(i)),
|
|
69
|
+
this.tickToMs(track.currentNoteEvent.endTick - track.currentNoteEvent.startTick),
|
|
70
|
+
music.volume()
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected scheduleDrumTrack(track: DrumTrack) {
|
|
77
|
+
for (let i = 0; i < track.currentNoteEvent.polyphony; i++) {
|
|
78
|
+
playInstructions(
|
|
79
|
+
0,
|
|
80
|
+
renderDrumInstrument(
|
|
81
|
+
track.drums[track.currentNoteEvent.getNote(i)],
|
|
82
|
+
music.volume()
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|