pxt-core 8.5.9 → 8.5.10

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/pxt.js CHANGED
@@ -111692,7 +111692,7 @@ var pxt;
111692
111692
  * notes byte length
111693
111693
  * ...note events
111694
111694
  *
111695
- * instrument(27 bytes)
111695
+ * instrument(28 bytes)
111696
111696
  * 0 waveform
111697
111697
  * 1 amp attack
111698
111698
  * 3 amp decay
@@ -111708,6 +111708,7 @@ var pxt;
111708
111708
  * 22 amp lfo amp
111709
111709
  * 24 pitch lfo freq
111710
111710
  * 25 pitch lfo amp
111711
+ * 27 octave
111711
111712
  *
111712
111713
  * drum(5 + 7 * steps bytes)
111713
111714
  * 0 steps
@@ -111727,6 +111728,12 @@ var pxt;
111727
111728
  * 4 polyphony
111728
111729
  * 5...notes(1 byte each)
111729
111730
  *
111731
+ * note (1 byte)
111732
+ * lower six bits = note - (instrumentOctave - 2) * 12
111733
+ * upper two bits are the enharmonic spelling:
111734
+ * 0 = normal
111735
+ * 1 = flat
111736
+ * 2 = sharp
111730
111737
  */
111731
111738
  function encodeSong(song) {
111732
111739
  const encodedTracks = song.tracks
@@ -111781,6 +111788,7 @@ var pxt;
111781
111788
  set16BitNumber(out, 22, ((_g = instrument.ampLFO) === null || _g === void 0 ? void 0 : _g.amplitude) || 0);
111782
111789
  out[24] = ((_h = instrument.pitchLFO) === null || _h === void 0 ? void 0 : _h.frequency) || 0;
111783
111790
  set16BitNumber(out, 25, ((_j = instrument.pitchLFO) === null || _j === void 0 ? void 0 : _j.amplitude) || 0);
111791
+ out[27] = instrument.octave;
111784
111792
  return out;
111785
111793
  }
111786
111794
  function decodeInstrument(buf, offset) {
@@ -111807,7 +111815,8 @@ var pxt;
111807
111815
  pitchLFO: {
111808
111816
  frequency: buf[offset + 24],
111809
111817
  amplitude: get16BitNumber(buf, 25)
111810
- }
111818
+ },
111819
+ octave: buf[offset + 27]
111811
111820
  };
111812
111821
  }
111813
111822
  function decodeTrack(buf, offset) {
@@ -111847,27 +111856,54 @@ var pxt;
111847
111856
  }
111848
111857
  return res;
111849
111858
  }
111850
- function encodeNoteEvent(event) {
111859
+ function encodeNoteEvent(event, instrumentOctave, isDrumTrack) {
111851
111860
  const out = new Uint8Array(5 + event.notes.length);
111852
111861
  set16BitNumber(out, 0, event.startTick);
111853
111862
  set16BitNumber(out, 2, event.endTick);
111854
111863
  out[4] = event.notes.length;
111855
111864
  for (let i = 0; i < event.notes.length; i++) {
111856
- out[5 + i] = event.notes[i];
111865
+ out[5 + i] = encodeNote(event.notes[i], instrumentOctave, isDrumTrack);
111857
111866
  }
111858
111867
  return out;
111859
111868
  }
111860
- function decodeNoteEvent(buf, offset) {
111869
+ function decodeNoteEvent(buf, offset, instrumentOctave, isDrumTrack) {
111861
111870
  const res = {
111862
111871
  startTick: get16BitNumber(buf, offset),
111863
111872
  endTick: get16BitNumber(buf, offset + 2),
111864
111873
  notes: []
111865
111874
  };
111866
111875
  for (let i = 0; i < buf[offset + 4]; i++) {
111867
- res.notes.push(buf[offset + 5 + i]);
111876
+ res.notes.push(decodeNote(buf[offset + 5 + i], instrumentOctave, isDrumTrack));
111868
111877
  }
111869
111878
  return res;
111870
111879
  }
111880
+ function encodeNote(note, instrumentOctave, isDrumTrack) {
111881
+ if (isDrumTrack) {
111882
+ return note.note;
111883
+ }
111884
+ let flags = 0;
111885
+ if (note.enharmonicSpelling === "flat") {
111886
+ flags = 1;
111887
+ }
111888
+ else if (note.enharmonicSpelling === "sharp") {
111889
+ flags = 2;
111890
+ }
111891
+ return (note.note - (instrumentOctave - 2) * 12) | (flags << 6);
111892
+ }
111893
+ function decodeNote(note, instrumentOctave, isDrumTrack) {
111894
+ const flags = note >> 6;
111895
+ const result = {
111896
+ note: isDrumTrack ? note : ((note & 0x3f) + (instrumentOctave - 2) * 12),
111897
+ enharmonicSpelling: "normal"
111898
+ };
111899
+ if (flags === 1) {
111900
+ result.enharmonicSpelling = "flat";
111901
+ }
111902
+ else if (flags === 2) {
111903
+ result.enharmonicSpelling = "sharp";
111904
+ }
111905
+ return result;
111906
+ }
111871
111907
  function encodeTrack(track) {
111872
111908
  if (track.drums)
111873
111909
  return encodeDrumTrack(track);
@@ -111875,7 +111911,7 @@ var pxt;
111875
111911
  }
111876
111912
  function encodeMelodicTrack(track) {
111877
111913
  const encodedInstrument = encodeInstrument(track.instrument);
111878
- const encodedNotes = track.notes.map(encodeNoteEvent);
111914
+ const encodedNotes = track.notes.map(note => encodeNoteEvent(note, track.instrument.octave, false));
111879
111915
  const noteLength = encodedNotes.reduce((d, c) => c.length + d, 0);
111880
111916
  const out = new Uint8Array(6 + encodedInstrument.length + noteLength);
111881
111917
  out[0] = track.id;
@@ -111902,7 +111938,7 @@ var pxt;
111902
111938
  const noteLength = get16BitNumber(buf, noteStart);
111903
111939
  let currentOffset = noteStart + 2;
111904
111940
  while (currentOffset < noteStart + 2 + noteLength) {
111905
- res.notes.push(decodeNoteEvent(buf, currentOffset));
111941
+ res.notes.push(decodeNoteEvent(buf, currentOffset, res.instrument.octave, false));
111906
111942
  currentOffset += 5 + res.notes[res.notes.length - 1].notes.length;
111907
111943
  }
111908
111944
  return [res, currentOffset];
@@ -111910,7 +111946,7 @@ var pxt;
111910
111946
  function encodeDrumTrack(track) {
111911
111947
  const encodedDrums = track.drums.map(encodeDrumInstrument);
111912
111948
  const drumLength = encodedDrums.reduce((d, c) => c.length + d, 0);
111913
- const encodedNotes = track.notes.map(encodeNoteEvent);
111949
+ const encodedNotes = track.notes.map(note => encodeNoteEvent(note, 0, true));
111914
111950
  const noteLength = encodedNotes.reduce((d, c) => c.length + d, 0);
111915
111951
  const out = new Uint8Array(6 + drumLength + noteLength);
111916
111952
  out[0] = track.id;
@@ -111945,7 +111981,7 @@ var pxt;
111945
111981
  const noteLength = get16BitNumber(buf, currentOffset);
111946
111982
  currentOffset += 2;
111947
111983
  while (currentOffset < offset + 4 + drumByteLength + noteLength) {
111948
- res.notes.push(decodeNoteEvent(buf, currentOffset));
111984
+ res.notes.push(decodeNoteEvent(buf, currentOffset, 0, true));
111949
111985
  currentOffset += 5 + res.notes[res.notes.length - 1].notes.length;
111950
111986
  }
111951
111987
  return [res, currentOffset];
@@ -112012,6 +112048,27 @@ var pxt;
112012
112048
  tracks: [
112013
112049
  {
112014
112050
  id: 0,
112051
+ name: lf("Dog"),
112052
+ notes: [],
112053
+ iconURI: "/static/music-editor/dog.png",
112054
+ instrument: {
112055
+ waveform: 1,
112056
+ octave: 4,
112057
+ ampEnvelope: {
112058
+ attack: 10,
112059
+ decay: 100,
112060
+ sustain: 500,
112061
+ release: 100,
112062
+ amplitude: 1024
112063
+ },
112064
+ pitchLFO: {
112065
+ frequency: 5,
112066
+ amplitude: 0
112067
+ }
112068
+ }
112069
+ },
112070
+ {
112071
+ id: 1,
112015
112072
  name: lf("Duck"),
112016
112073
  notes: [],
112017
112074
  iconURI: "/static/music-editor/duck.png",
@@ -112043,7 +112100,7 @@ var pxt;
112043
112100
  }
112044
112101
  },
112045
112102
  {
112046
- id: 1,
112103
+ id: 2,
112047
112104
  name: lf("Cat"),
112048
112105
  notes: [],
112049
112106
  iconURI: "/static/music-editor/cat.png",
@@ -112070,27 +112127,6 @@ var pxt;
112070
112127
  }
112071
112128
  }
112072
112129
  },
112073
- {
112074
- id: 2,
112075
- name: lf("Dog"),
112076
- notes: [],
112077
- iconURI: "/static/music-editor/dog.png",
112078
- instrument: {
112079
- waveform: 1,
112080
- octave: 4,
112081
- ampEnvelope: {
112082
- attack: 10,
112083
- decay: 100,
112084
- sustain: 500,
112085
- release: 100,
112086
- amplitude: 1024
112087
- },
112088
- pitchLFO: {
112089
- frequency: 5,
112090
- amplitude: 0
112091
- }
112092
- }
112093
- },
112094
112130
  {
112095
112131
  id: 3,
112096
112132
  name: lf("Fish"),
@@ -17365,7 +17365,7 @@ var pxtblockly;
17365
17365
  if (col > cellsShown)
17366
17366
  break;
17367
17367
  for (const note of noteEvent.notes) {
17368
- const row = 12 - (note % 12);
17368
+ const row = 12 - (note.note % 12);
17369
17369
  if (row > notesShown)
17370
17370
  continue;
17371
17371
  context.fillStyle = colors[trackColors[track.id || song.tracks.indexOf(track)]];
@@ -13803,7 +13803,7 @@ var pxtblockly;
13803
13803
  if (col > cellsShown)
13804
13804
  break;
13805
13805
  for (const note of noteEvent.notes) {
13806
- const row = 12 - (note % 12);
13806
+ const row = 12 - (note.note % 12);
13807
13807
  if (row > notesShown)
13808
13808
  continue;
13809
13809
  context.fillStyle = colors[trackColors[track.id || song.tracks.indexOf(track)]];
package/built/pxtlib.d.ts CHANGED
@@ -1829,10 +1829,14 @@ declare namespace pxt.assets.music {
1829
1829
  notes: NoteEvent[];
1830
1830
  }
1831
1831
  interface NoteEvent {
1832
- notes: number[];
1832
+ notes: Note[];
1833
1833
  startTick: number;
1834
1834
  endTick: number;
1835
1835
  }
1836
+ interface Note {
1837
+ note: number;
1838
+ enharmonicSpelling: "normal" | "flat" | "sharp";
1839
+ }
1836
1840
  interface DrumSoundStep {
1837
1841
  waveform: number;
1838
1842
  frequency: number;
package/built/pxtlib.js CHANGED
@@ -14006,7 +14006,7 @@ var pxt;
14006
14006
  * notes byte length
14007
14007
  * ...note events
14008
14008
  *
14009
- * instrument(27 bytes)
14009
+ * instrument(28 bytes)
14010
14010
  * 0 waveform
14011
14011
  * 1 amp attack
14012
14012
  * 3 amp decay
@@ -14022,6 +14022,7 @@ var pxt;
14022
14022
  * 22 amp lfo amp
14023
14023
  * 24 pitch lfo freq
14024
14024
  * 25 pitch lfo amp
14025
+ * 27 octave
14025
14026
  *
14026
14027
  * drum(5 + 7 * steps bytes)
14027
14028
  * 0 steps
@@ -14041,6 +14042,12 @@ var pxt;
14041
14042
  * 4 polyphony
14042
14043
  * 5...notes(1 byte each)
14043
14044
  *
14045
+ * note (1 byte)
14046
+ * lower six bits = note - (instrumentOctave - 2) * 12
14047
+ * upper two bits are the enharmonic spelling:
14048
+ * 0 = normal
14049
+ * 1 = flat
14050
+ * 2 = sharp
14044
14051
  */
14045
14052
  function encodeSong(song) {
14046
14053
  const encodedTracks = song.tracks
@@ -14095,6 +14102,7 @@ var pxt;
14095
14102
  set16BitNumber(out, 22, ((_g = instrument.ampLFO) === null || _g === void 0 ? void 0 : _g.amplitude) || 0);
14096
14103
  out[24] = ((_h = instrument.pitchLFO) === null || _h === void 0 ? void 0 : _h.frequency) || 0;
14097
14104
  set16BitNumber(out, 25, ((_j = instrument.pitchLFO) === null || _j === void 0 ? void 0 : _j.amplitude) || 0);
14105
+ out[27] = instrument.octave;
14098
14106
  return out;
14099
14107
  }
14100
14108
  function decodeInstrument(buf, offset) {
@@ -14121,7 +14129,8 @@ var pxt;
14121
14129
  pitchLFO: {
14122
14130
  frequency: buf[offset + 24],
14123
14131
  amplitude: get16BitNumber(buf, 25)
14124
- }
14132
+ },
14133
+ octave: buf[offset + 27]
14125
14134
  };
14126
14135
  }
14127
14136
  function decodeTrack(buf, offset) {
@@ -14161,27 +14170,54 @@ var pxt;
14161
14170
  }
14162
14171
  return res;
14163
14172
  }
14164
- function encodeNoteEvent(event) {
14173
+ function encodeNoteEvent(event, instrumentOctave, isDrumTrack) {
14165
14174
  const out = new Uint8Array(5 + event.notes.length);
14166
14175
  set16BitNumber(out, 0, event.startTick);
14167
14176
  set16BitNumber(out, 2, event.endTick);
14168
14177
  out[4] = event.notes.length;
14169
14178
  for (let i = 0; i < event.notes.length; i++) {
14170
- out[5 + i] = event.notes[i];
14179
+ out[5 + i] = encodeNote(event.notes[i], instrumentOctave, isDrumTrack);
14171
14180
  }
14172
14181
  return out;
14173
14182
  }
14174
- function decodeNoteEvent(buf, offset) {
14183
+ function decodeNoteEvent(buf, offset, instrumentOctave, isDrumTrack) {
14175
14184
  const res = {
14176
14185
  startTick: get16BitNumber(buf, offset),
14177
14186
  endTick: get16BitNumber(buf, offset + 2),
14178
14187
  notes: []
14179
14188
  };
14180
14189
  for (let i = 0; i < buf[offset + 4]; i++) {
14181
- res.notes.push(buf[offset + 5 + i]);
14190
+ res.notes.push(decodeNote(buf[offset + 5 + i], instrumentOctave, isDrumTrack));
14182
14191
  }
14183
14192
  return res;
14184
14193
  }
14194
+ function encodeNote(note, instrumentOctave, isDrumTrack) {
14195
+ if (isDrumTrack) {
14196
+ return note.note;
14197
+ }
14198
+ let flags = 0;
14199
+ if (note.enharmonicSpelling === "flat") {
14200
+ flags = 1;
14201
+ }
14202
+ else if (note.enharmonicSpelling === "sharp") {
14203
+ flags = 2;
14204
+ }
14205
+ return (note.note - (instrumentOctave - 2) * 12) | (flags << 6);
14206
+ }
14207
+ function decodeNote(note, instrumentOctave, isDrumTrack) {
14208
+ const flags = note >> 6;
14209
+ const result = {
14210
+ note: isDrumTrack ? note : ((note & 0x3f) + (instrumentOctave - 2) * 12),
14211
+ enharmonicSpelling: "normal"
14212
+ };
14213
+ if (flags === 1) {
14214
+ result.enharmonicSpelling = "flat";
14215
+ }
14216
+ else if (flags === 2) {
14217
+ result.enharmonicSpelling = "sharp";
14218
+ }
14219
+ return result;
14220
+ }
14185
14221
  function encodeTrack(track) {
14186
14222
  if (track.drums)
14187
14223
  return encodeDrumTrack(track);
@@ -14189,7 +14225,7 @@ var pxt;
14189
14225
  }
14190
14226
  function encodeMelodicTrack(track) {
14191
14227
  const encodedInstrument = encodeInstrument(track.instrument);
14192
- const encodedNotes = track.notes.map(encodeNoteEvent);
14228
+ const encodedNotes = track.notes.map(note => encodeNoteEvent(note, track.instrument.octave, false));
14193
14229
  const noteLength = encodedNotes.reduce((d, c) => c.length + d, 0);
14194
14230
  const out = new Uint8Array(6 + encodedInstrument.length + noteLength);
14195
14231
  out[0] = track.id;
@@ -14216,7 +14252,7 @@ var pxt;
14216
14252
  const noteLength = get16BitNumber(buf, noteStart);
14217
14253
  let currentOffset = noteStart + 2;
14218
14254
  while (currentOffset < noteStart + 2 + noteLength) {
14219
- res.notes.push(decodeNoteEvent(buf, currentOffset));
14255
+ res.notes.push(decodeNoteEvent(buf, currentOffset, res.instrument.octave, false));
14220
14256
  currentOffset += 5 + res.notes[res.notes.length - 1].notes.length;
14221
14257
  }
14222
14258
  return [res, currentOffset];
@@ -14224,7 +14260,7 @@ var pxt;
14224
14260
  function encodeDrumTrack(track) {
14225
14261
  const encodedDrums = track.drums.map(encodeDrumInstrument);
14226
14262
  const drumLength = encodedDrums.reduce((d, c) => c.length + d, 0);
14227
- const encodedNotes = track.notes.map(encodeNoteEvent);
14263
+ const encodedNotes = track.notes.map(note => encodeNoteEvent(note, 0, true));
14228
14264
  const noteLength = encodedNotes.reduce((d, c) => c.length + d, 0);
14229
14265
  const out = new Uint8Array(6 + drumLength + noteLength);
14230
14266
  out[0] = track.id;
@@ -14259,7 +14295,7 @@ var pxt;
14259
14295
  const noteLength = get16BitNumber(buf, currentOffset);
14260
14296
  currentOffset += 2;
14261
14297
  while (currentOffset < offset + 4 + drumByteLength + noteLength) {
14262
- res.notes.push(decodeNoteEvent(buf, currentOffset));
14298
+ res.notes.push(decodeNoteEvent(buf, currentOffset, 0, true));
14263
14299
  currentOffset += 5 + res.notes[res.notes.length - 1].notes.length;
14264
14300
  }
14265
14301
  return [res, currentOffset];
@@ -14326,6 +14362,27 @@ var pxt;
14326
14362
  tracks: [
14327
14363
  {
14328
14364
  id: 0,
14365
+ name: lf("Dog"),
14366
+ notes: [],
14367
+ iconURI: "/static/music-editor/dog.png",
14368
+ instrument: {
14369
+ waveform: 1,
14370
+ octave: 4,
14371
+ ampEnvelope: {
14372
+ attack: 10,
14373
+ decay: 100,
14374
+ sustain: 500,
14375
+ release: 100,
14376
+ amplitude: 1024
14377
+ },
14378
+ pitchLFO: {
14379
+ frequency: 5,
14380
+ amplitude: 0
14381
+ }
14382
+ }
14383
+ },
14384
+ {
14385
+ id: 1,
14329
14386
  name: lf("Duck"),
14330
14387
  notes: [],
14331
14388
  iconURI: "/static/music-editor/duck.png",
@@ -14357,7 +14414,7 @@ var pxt;
14357
14414
  }
14358
14415
  },
14359
14416
  {
14360
- id: 1,
14417
+ id: 2,
14361
14418
  name: lf("Cat"),
14362
14419
  notes: [],
14363
14420
  iconURI: "/static/music-editor/cat.png",
@@ -14384,27 +14441,6 @@ var pxt;
14384
14441
  }
14385
14442
  }
14386
14443
  },
14387
- {
14388
- id: 2,
14389
- name: lf("Dog"),
14390
- notes: [],
14391
- iconURI: "/static/music-editor/dog.png",
14392
- instrument: {
14393
- waveform: 1,
14394
- octave: 4,
14395
- ampEnvelope: {
14396
- attack: 10,
14397
- decay: 100,
14398
- sustain: 500,
14399
- release: 100,
14400
- amplitude: 1024
14401
- },
14402
- pitchLFO: {
14403
- frequency: 5,
14404
- amplitude: 0
14405
- }
14406
- }
14407
- },
14408
14444
  {
14409
14445
  id: 3,
14410
14446
  name: lf("Fish"),