Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions localtypings/pxtmusic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare namespace pxt.assets.music {
}

export interface DrumInstrument {
name?: string;
startFrequency: number;
startVolume: number;
steps: DrumSoundStep[];
Expand Down
2 changes: 2 additions & 0 deletions pxtblocks/fields/fieldEditorRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { FieldSoundEffect } from "./field_sound_effect";
import { FieldAutoComplete } from "./field_autocomplete";
import { FieldColorWheel } from "./field_colorwheel";
import { FieldScopedValueSelector } from "./field_scopedvalueselector";
import { FieldPianoRoll } from "./field_piano_roll";

interface FieldEditorOptions {
field: FieldCustomConstructor;
Expand Down Expand Up @@ -70,6 +71,7 @@ export function initFieldEditors() {
registerFieldEditor('scopedvalueselector', FieldScopedValueSelector);
if (pxt.appTarget.appTheme?.songEditor) {
registerFieldEditor('musiceditor', FieldMusicEditor);
registerFieldEditor('pianoroll', FieldPianoRoll);
}
}

Expand Down
21 changes: 16 additions & 5 deletions pxtblocks/fields/field_asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,18 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte

params.blocksInfo = this.blocksInfo;

let editorKind: string;
let editorKind = this.getEditorKind();

switch (this.asset.type) {
case pxt.AssetType.Tile:
case pxt.AssetType.Image:
editorKind = "image-editor";
params.temporaryAssets = getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Image);
break;
case pxt.AssetType.Animation:
editorKind = "animation-editor";
params.temporaryAssets = getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Image)
.concat(getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Animation));
break;
case pxt.AssetType.Tilemap:
editorKind = "tilemap-editor";
const project = pxt.react.getTilemapProject();
pxt.sprite.addMissingTilemapTilesAndReferences(project, this.asset);

Expand All @@ -121,7 +118,6 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
}
break;
case pxt.AssetType.Song:
editorKind = "music-editor";
params.temporaryAssets = getTemporaryAssets(this.sourceBlock_.workspace, pxt.AssetType.Song);
setMelodyEditorOpen(this.sourceBlock_, true);
break;
Expand All @@ -136,6 +132,21 @@ export abstract class FieldAssetEditor<U extends FieldAssetEditorOptions, V exte
}
}

protected getEditorKind(): string{
switch (this.asset.type) {
case pxt.AssetType.Tile:
case pxt.AssetType.Image:
return "image-editor";
case pxt.AssetType.Animation:
return "animation-editor";
case pxt.AssetType.Tilemap:
return "tilemap-editor";
case pxt.AssetType.Song:
return "music-editor";
}
return undefined;
}

getFieldDescription(): string {
return this.asset?.meta?.displayName || this.getAssetType().toString();
}
Expand Down
7 changes: 7 additions & 0 deletions pxtblocks/fields/field_piano_roll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FieldMusicEditor } from "./field_musiceditor";

export class FieldPianoRoll extends FieldMusicEditor {
protected override getEditorKind() {
return "piano-roll-editor";
}
}
58 changes: 32 additions & 26 deletions pxtlib/music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ namespace pxt.assets.music {

song.tracks = base.tracks.map((track, index) => {
const existing = song.tracks.find(t => t.id === index);
if (existing) track.notes = existing.notes;
if (existing) {
track.notes = existing.notes;
if (track.instrument) {
track.instrument.octave = existing.instrument?.octave || track.instrument.octave;
}
}
return track;
})
}
Expand Down Expand Up @@ -709,7 +714,7 @@ namespace pxt.assets.music {
},
drums: [
{
/* neutral kick */
name: lf("neutral kick"),
startFrequency: 100,
startVolume: 1024,
steps: [
Expand All @@ -728,7 +733,7 @@ namespace pxt.assets.music {
]
},
{
/* punchy kick */
name: lf("punchy kick"),
startFrequency: 200,
startVolume: 1024,
steps: [{
Expand All @@ -740,7 +745,7 @@ namespace pxt.assets.music {
},

{
/* booming kick */
name: lf("booming kick"),
startFrequency: 100,
startVolume: 1024,
steps: [{
Expand All @@ -753,7 +758,7 @@ namespace pxt.assets.music {


{
/* snare 1 */
name: lf("snare 1"),
startFrequency: 175,
startVolume: 1024,
steps: [
Expand Down Expand Up @@ -785,7 +790,7 @@ namespace pxt.assets.music {
},

{
/* snare 2 */
name: lf("snare 2"),
startFrequency: 220,
startVolume: 1024,
steps: [
Expand Down Expand Up @@ -818,7 +823,7 @@ namespace pxt.assets.music {


{
/* hat 1 */
name: lf("hat 1"),
startFrequency: 400,
startVolume: 500,
steps: [
Expand All @@ -838,7 +843,7 @@ namespace pxt.assets.music {
},

{
/* hat 2 */
name: lf("hat 2"),
startFrequency: 400,
startVolume: 0,
steps: [
Expand All @@ -865,7 +870,7 @@ namespace pxt.assets.music {


{
/* hat 3 */
name: lf("hat 3"),
startFrequency: 400,
startVolume: 0,
steps: [
Expand Down Expand Up @@ -897,7 +902,7 @@ namespace pxt.assets.music {
},

{
/* hat 4 */
name: lf("hat 4"),
startFrequency: 400,
startVolume: 0,
steps: [
Expand Down Expand Up @@ -929,7 +934,7 @@ namespace pxt.assets.music {
},

{
/* double hat */
name: lf("double hat"),
startFrequency: 3500,
startVolume: 1024,
steps: [
Expand Down Expand Up @@ -967,7 +972,7 @@ namespace pxt.assets.music {
},

{
/* metallic */
name: lf("metallic"),
startFrequency: 2000,
startVolume: 1024,
steps: [
Expand All @@ -987,7 +992,7 @@ namespace pxt.assets.music {
},

{
/* low tom */
name: lf("low tom"),
startFrequency: 200,
startVolume: 200,
steps: [
Expand All @@ -1013,7 +1018,7 @@ namespace pxt.assets.music {
},

{
/* mid tom */
name: lf("mid tom"),
startFrequency: 300,
startVolume: 200,
steps: [
Expand All @@ -1039,7 +1044,7 @@ namespace pxt.assets.music {
},

{
/* hi tom */
name: lf("hi tom"),
startFrequency: 500,
startVolume: 200,
steps: [
Expand All @@ -1064,7 +1069,7 @@ namespace pxt.assets.music {
]
},
{
/* lo tom 2 */
name: lf("lo tom 2"),
startFrequency: 200,
startVolume: 1024,
steps: [
Expand All @@ -1077,7 +1082,7 @@ namespace pxt.assets.music {
]
},
{
/* mid tom 2 */
name: lf("mid tom 2"),
startFrequency: 300,
startVolume: 1024,
steps: [
Expand All @@ -1092,7 +1097,7 @@ namespace pxt.assets.music {


{
/* hi tom 2 */
name: lf("hi tom 2"),
startFrequency: 400,
startVolume: 1024,
steps: [
Expand All @@ -1107,7 +1112,7 @@ namespace pxt.assets.music {


{
/* thump 1 */
name: lf("thump 1"),
startFrequency: 200,
startVolume: 1024,
steps: [
Expand All @@ -1127,7 +1132,7 @@ namespace pxt.assets.music {
},

{
/* thump 2 */
name: lf("thump 2"),
startFrequency: 450,
startVolume: 1024,
steps: [
Expand All @@ -1147,7 +1152,7 @@ namespace pxt.assets.music {
},

{
/* cymbal */
name: lf("cymbal"),
startFrequency: 2500,
startVolume: 1024,
steps: [
Expand All @@ -1167,7 +1172,7 @@ namespace pxt.assets.music {
},

{
/* crash 1 */
name: lf("crash 1"),
startFrequency: 3000,
startVolume: 1024,
steps: [
Expand All @@ -1187,7 +1192,7 @@ namespace pxt.assets.music {
},

{
/* crash 2 */
name: lf("crash 2"),
startFrequency: 800,
startVolume: 0,
steps: [
Expand All @@ -1207,7 +1212,7 @@ namespace pxt.assets.music {
},

{
/* crash 3 */
name: lf("crash 3"),
startFrequency: 400,
startVolume: 0,
steps: [
Expand All @@ -1227,7 +1232,7 @@ namespace pxt.assets.music {
},

{
/* buzzer */
name: lf("buzzer"),
startFrequency: 2000,
startVolume: 1024,
steps: [
Expand All @@ -1244,7 +1249,8 @@ namespace pxt.assets.music {
waveform: 16
}
]
},]
},
]
}
]
}
Expand Down
Loading
Loading