Skip to content

Commit 317592c

Browse files
authored
Merge branch 'master' into generics-page-fix
2 parents 5c0564f + bf996de commit 317592c

27 files changed

Lines changed: 1982 additions & 132 deletions

localtypings/pxtmusic.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ declare namespace pxt.assets.music {
6060
}
6161

6262
export interface DrumInstrument {
63+
name?: string;
6364
startFrequency: number;
6465
startVolume: number;
6566
steps: DrumSoundStep[];

pxtblocks/fields/fieldEditorRegistry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { FieldSoundEffect } from "./field_sound_effect";
3131
import { FieldAutoComplete } from "./field_autocomplete";
3232
import { FieldColorWheel } from "./field_colorwheel";
3333
import { FieldScopedValueSelector } from "./field_scopedvalueselector";
34+
import { FieldPianoRoll } from "./field_piano_roll";
3435

3536
interface FieldEditorOptions {
3637
field: FieldCustomConstructor;
@@ -70,6 +71,7 @@ export function initFieldEditors() {
7071
registerFieldEditor('scopedvalueselector', FieldScopedValueSelector);
7172
if (pxt.appTarget.appTheme?.songEditor) {
7273
registerFieldEditor('musiceditor', FieldMusicEditor);
74+
registerFieldEditor('pianoroll', FieldPianoRoll);
7375
}
7476
}
7577

pxtblocks/fields/field_asset.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,18 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
9696

9797
params.blocksInfo = this.blocksInfo;
9898

99-
let editorKind: string;
99+
let editorKind = this.getEditorKind();
100100

101101
switch (this.asset.type) {
102102
case pxt.AssetType.Tile:
103103
case pxt.AssetType.Image:
104-
editorKind = "image-editor";
105104
params.temporaryAssets = getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Image);
106105
break;
107106
case pxt.AssetType.Animation:
108-
editorKind = "animation-editor";
109107
params.temporaryAssets = getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Image)
110108
.concat(getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Animation));
111109
break;
112110
case pxt.AssetType.Tilemap:
113-
editorKind = "tilemap-editor";
114111
const project = pxt.react.getTilemapProject();
115112
pxt.sprite.addMissingTilemapTilesAndReferences(project, this.asset);
116113

@@ -121,7 +118,6 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
121118
}
122119
break;
123120
case pxt.AssetType.Song:
124-
editorKind = "music-editor";
125121
params.temporaryAssets = getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Song);
126122
setMelodyEditorOpen(this.sourceBlock_, true);
127123
break;
@@ -136,6 +132,21 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
136132
}
137133
}
138134

135+
protected getEditorKind(): string{
136+
switch (this.asset.type) {
137+
case pxt.AssetType.Tile:
138+
case pxt.AssetType.Image:
139+
return "image-editor";
140+
case pxt.AssetType.Animation:
141+
return "animation-editor";
142+
case pxt.AssetType.Tilemap:
143+
return "tilemap-editor";
144+
case pxt.AssetType.Song:
145+
return "music-editor";
146+
}
147+
return undefined;
148+
}
149+
139150
getFieldDescription(): string {
140151
return this.asset?.meta?.displayName || this.getAssetType().toString();
141152
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { FieldMusicEditor } from "./field_musiceditor";
2+
3+
export class FieldPianoRoll extends FieldMusicEditor {
4+
protected override getEditorKind() {
5+
return "piano-roll-editor";
6+
}
7+
}

pxtblocks/importer.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -202,60 +202,6 @@ export function loadWorkspaceXml(xml: string, skipReport = false, opts?: DomToWo
202202
}
203203
}
204204

205-
function patchFloatingBlocks(dom: Element, info: pxtc.BlocksInfo) {
206-
const onstarts = getBlocksWithType(dom, ts.pxtc.ON_START_TYPE);
207-
let onstart = onstarts.length ? onstarts[0] : undefined;
208-
if (onstart) { // nothing to do
209-
onstart.removeAttribute("deletable");
210-
return;
211-
}
212-
213-
let newnodes: Element[] = [];
214-
215-
const blocks: pxt.Map<pxtc.SymbolInfo> = info.blocksById;
216-
217-
// walk top level blocks
218-
let node = dom.firstElementChild;
219-
let insertNode: Element = undefined;
220-
while (node) {
221-
const nextNode = node.nextElementSibling;
222-
// does this block is disable or have s nested statement block?
223-
const nodeType = node.getAttribute("type");
224-
if (!node.getAttribute("disabled") && !node.getElementsByTagName("statement").length
225-
&& (buildinBlockStatements[nodeType] ||
226-
(blocks[nodeType] && blocks[nodeType].retType == "void" && !hasArrowFunction(blocks[nodeType])))
227-
) {
228-
// old block, needs to be wrapped in onstart
229-
if (!insertNode) {
230-
insertNode = dom.ownerDocument.createElement("statement");
231-
insertNode.setAttribute("name", "HANDLER");
232-
if (!onstart) {
233-
onstart = dom.ownerDocument.createElement("block");
234-
onstart.setAttribute("type", ts.pxtc.ON_START_TYPE);
235-
newnodes.push(onstart);
236-
}
237-
onstart.appendChild(insertNode);
238-
insertNode.appendChild(node);
239-
240-
node.removeAttribute("x");
241-
node.removeAttribute("y");
242-
insertNode = node;
243-
} else {
244-
// event, add nested statement
245-
const next = dom.ownerDocument.createElement("next");
246-
next.appendChild(node);
247-
insertNode.appendChild(next);
248-
node.removeAttribute("x");
249-
node.removeAttribute("y");
250-
insertNode = node;
251-
}
252-
}
253-
node = nextNode;
254-
}
255-
256-
newnodes.forEach(n => dom.appendChild(n));
257-
}
258-
259205
/**
260206
* Patch to transform old function blocks to new ones, and rename child nodes
261207
*/
@@ -347,9 +293,6 @@ export function importXml(pkgTargetVersion: string, xml: string, info: pxtc.Bloc
347293
for (let i = 0; i < blocks.length; ++i)
348294
patchBlock(info, enums, blocks[i]);
349295

350-
// patch floating blocks
351-
patchFloatingBlocks(doc.documentElement, info);
352-
353296
// patch function blocks
354297
patchFunctionBlocks(doc.documentElement, info)
355298

pxtlib/music.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,12 @@ namespace pxt.assets.music {
460460

461461
song.tracks = base.tracks.map((track, index) => {
462462
const existing = song.tracks.find(t => t.id === index);
463-
if (existing) track.notes = existing.notes;
463+
if (existing) {
464+
track.notes = existing.notes;
465+
if (track.instrument) {
466+
track.instrument.octave = existing.instrument?.octave || track.instrument.octave;
467+
}
468+
}
464469
return track;
465470
})
466471
}
@@ -709,7 +714,7 @@ namespace pxt.assets.music {
709714
},
710715
drums: [
711716
{
712-
/* neutral kick */
717+
name: lf("neutral kick"),
713718
startFrequency: 100,
714719
startVolume: 1024,
715720
steps: [
@@ -728,7 +733,7 @@ namespace pxt.assets.music {
728733
]
729734
},
730735
{
731-
/* punchy kick */
736+
name: lf("punchy kick"),
732737
startFrequency: 200,
733738
startVolume: 1024,
734739
steps: [{
@@ -740,7 +745,7 @@ namespace pxt.assets.music {
740745
},
741746

742747
{
743-
/* booming kick */
748+
name: lf("booming kick"),
744749
startFrequency: 100,
745750
startVolume: 1024,
746751
steps: [{
@@ -753,7 +758,7 @@ namespace pxt.assets.music {
753758

754759

755760
{
756-
/* snare 1 */
761+
name: lf("snare 1"),
757762
startFrequency: 175,
758763
startVolume: 1024,
759764
steps: [
@@ -785,7 +790,7 @@ namespace pxt.assets.music {
785790
},
786791

787792
{
788-
/* snare 2 */
793+
name: lf("snare 2"),
789794
startFrequency: 220,
790795
startVolume: 1024,
791796
steps: [
@@ -818,7 +823,7 @@ namespace pxt.assets.music {
818823

819824

820825
{
821-
/* hat 1 */
826+
name: lf("hat 1"),
822827
startFrequency: 400,
823828
startVolume: 500,
824829
steps: [
@@ -838,7 +843,7 @@ namespace pxt.assets.music {
838843
},
839844

840845
{
841-
/* hat 2 */
846+
name: lf("hat 2"),
842847
startFrequency: 400,
843848
startVolume: 0,
844849
steps: [
@@ -865,7 +870,7 @@ namespace pxt.assets.music {
865870

866871

867872
{
868-
/* hat 3 */
873+
name: lf("hat 3"),
869874
startFrequency: 400,
870875
startVolume: 0,
871876
steps: [
@@ -897,7 +902,7 @@ namespace pxt.assets.music {
897902
},
898903

899904
{
900-
/* hat 4 */
905+
name: lf("hat 4"),
901906
startFrequency: 400,
902907
startVolume: 0,
903908
steps: [
@@ -929,7 +934,7 @@ namespace pxt.assets.music {
929934
},
930935

931936
{
932-
/* double hat */
937+
name: lf("double hat"),
933938
startFrequency: 3500,
934939
startVolume: 1024,
935940
steps: [
@@ -967,7 +972,7 @@ namespace pxt.assets.music {
967972
},
968973

969974
{
970-
/* metallic */
975+
name: lf("metallic"),
971976
startFrequency: 2000,
972977
startVolume: 1024,
973978
steps: [
@@ -987,7 +992,7 @@ namespace pxt.assets.music {
987992
},
988993

989994
{
990-
/* low tom */
995+
name: lf("low tom"),
991996
startFrequency: 200,
992997
startVolume: 200,
993998
steps: [
@@ -1013,7 +1018,7 @@ namespace pxt.assets.music {
10131018
},
10141019

10151020
{
1016-
/* mid tom */
1021+
name: lf("mid tom"),
10171022
startFrequency: 300,
10181023
startVolume: 200,
10191024
steps: [
@@ -1039,7 +1044,7 @@ namespace pxt.assets.music {
10391044
},
10401045

10411046
{
1042-
/* hi tom */
1047+
name: lf("hi tom"),
10431048
startFrequency: 500,
10441049
startVolume: 200,
10451050
steps: [
@@ -1064,7 +1069,7 @@ namespace pxt.assets.music {
10641069
]
10651070
},
10661071
{
1067-
/* lo tom 2 */
1072+
name: lf("lo tom 2"),
10681073
startFrequency: 200,
10691074
startVolume: 1024,
10701075
steps: [
@@ -1077,7 +1082,7 @@ namespace pxt.assets.music {
10771082
]
10781083
},
10791084
{
1080-
/* mid tom 2 */
1085+
name: lf("mid tom 2"),
10811086
startFrequency: 300,
10821087
startVolume: 1024,
10831088
steps: [
@@ -1092,7 +1097,7 @@ namespace pxt.assets.music {
10921097

10931098

10941099
{
1095-
/* hi tom 2 */
1100+
name: lf("hi tom 2"),
10961101
startFrequency: 400,
10971102
startVolume: 1024,
10981103
steps: [
@@ -1107,7 +1112,7 @@ namespace pxt.assets.music {
11071112

11081113

11091114
{
1110-
/* thump 1 */
1115+
name: lf("thump 1"),
11111116
startFrequency: 200,
11121117
startVolume: 1024,
11131118
steps: [
@@ -1127,7 +1132,7 @@ namespace pxt.assets.music {
11271132
},
11281133

11291134
{
1130-
/* thump 2 */
1135+
name: lf("thump 2"),
11311136
startFrequency: 450,
11321137
startVolume: 1024,
11331138
steps: [
@@ -1147,7 +1152,7 @@ namespace pxt.assets.music {
11471152
},
11481153

11491154
{
1150-
/* cymbal */
1155+
name: lf("cymbal"),
11511156
startFrequency: 2500,
11521157
startVolume: 1024,
11531158
steps: [
@@ -1167,7 +1172,7 @@ namespace pxt.assets.music {
11671172
},
11681173

11691174
{
1170-
/* crash 1 */
1175+
name: lf("crash 1"),
11711176
startFrequency: 3000,
11721177
startVolume: 1024,
11731178
steps: [
@@ -1187,7 +1192,7 @@ namespace pxt.assets.music {
11871192
},
11881193

11891194
{
1190-
/* crash 2 */
1195+
name: lf("crash 2"),
11911196
startFrequency: 800,
11921197
startVolume: 0,
11931198
steps: [
@@ -1207,7 +1212,7 @@ namespace pxt.assets.music {
12071212
},
12081213

12091214
{
1210-
/* crash 3 */
1215+
name: lf("crash 3"),
12111216
startFrequency: 400,
12121217
startVolume: 0,
12131218
steps: [
@@ -1227,7 +1232,7 @@ namespace pxt.assets.music {
12271232
},
12281233

12291234
{
1230-
/* buzzer */
1235+
name: lf("buzzer"),
12311236
startFrequency: 2000,
12321237
startVolume: 1024,
12331238
steps: [
@@ -1244,7 +1249,8 @@ namespace pxt.assets.music {
12441249
waveform: 16
12451250
}
12461251
]
1247-
},]
1252+
},
1253+
]
12481254
}
12491255
]
12501256
}

0 commit comments

Comments
 (0)