Skip to content

add new extension MIDI Parser#2035

Closed
CHCAT1320 wants to merge 9 commits into
TurboWarp:masterfrom
CHCAT1320:master
Closed

add new extension MIDI Parser#2035
CHCAT1320 wants to merge 9 commits into
TurboWarp:masterfrom
CHCAT1320:master

Conversation

@CHCAT1320

@CHCAT1320 CHCAT1320 commented Mar 15, 2025

Copy link
Copy Markdown

Parse MIDI files into JSON.

@github-actions github-actions Bot added the pr: new extension Pull requests that add a new extension label Mar 15, 2025
@SharkPool-SP

Copy link
Copy Markdown
Collaborator

The code doesn't even work

@SharkPool-SP

Copy link
Copy Markdown
Collaborator

The extension doesn't even load

@CHCAT1320

Copy link
Copy Markdown
Author

The extension doesn't even load

But the code works fine on my end.How are you using it?

@SharkPool-SP

Copy link
Copy Markdown
Collaborator

oh wait nevermind, github mobile is just really messing up the display

@CHCAT1320

Copy link
Copy Markdown
Author

oh wait nevermind, github mobile is just really messing up the display

Can this code run normally on your side?

@CST1229

CST1229 commented Mar 16, 2025

Copy link
Copy Markdown
Collaborator

it really does, in fact, not work (at least when pasting the source code). you are defining MidiLibrary twice, for some reason
image
image

also ideally you should define that string inside the main function to not pollute global scope

@CHCAT1320

Copy link
Copy Markdown
Author

it really does, in fact, not work (at least when pasting the source code). you are defining MidiLibrary twice, for some reason
image
image

also ideally you should define that string inside the main function to not pollute global scope

But the code for the extension works perfectly on TurboWarp.

@CST1229

CST1229 commented Mar 16, 2025

Copy link
Copy Markdown
Collaborator

But the code for the extension works perfectly on TurboWarp.

i tried it on turbowarp

@CST1229

CST1229 commented Mar 16, 2025

Copy link
Copy Markdown
Collaborator

i also tried cloning your repository and running it locally. still errors
image

@CHCAT1320

Copy link
Copy Markdown
Author

i also tried cloning your repository and running it locally. still errors
image

But this issue doesn't cause much trouble.The extension can output JSON properly.

@CST1229

CST1229 commented Mar 16, 2025

Copy link
Copy Markdown
Collaborator

But this issue doesn't cause much trouble.The extension can output JSON properly.

the issue quite literally PREVENTS THE EXTENSION FROM LOADING

@CHCAT1320

Copy link
Copy Markdown
Author

But this issue doesn't cause much trouble.The extension can output JSON properly.

the issue quite literally PREVENTS THE EXTENSION FROM LOADING

Oh, sorry, it was my mistake. I duplicated "const MidiLibrary". It was my carelessness. I'll fix it right away.

@CHCAT1320

Copy link
Copy Markdown
Author

But this issue doesn't cause much trouble.The extension can output JSON properly.

the issue quite literally PREVENTS THE EXTENSION FROM LOADING

I have fixed the issue of duplicate declaration of "const MidiLibrary".

@lselden

lselden commented Mar 17, 2025

Copy link
Copy Markdown

@CHCAT1320 I added a pull request to your repo with a suggested change on how you import the tonejs/midi code.

Do you think it'd make sense to merge this PR and my WebMidi one into the same extension?

return 'MIDI library failed to load';
}

const dataUrl = args.DATA_URL.trim();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use cast: Scratch.Cast.toString(args.DATA_URL).trim()

midi.tracks.forEach((track, trackIndex) => {
track.notes.forEach(note => {
this.notesData.push({
track: trackIndex,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: consider outputting this as trackIndex + 1 since scratch indexes start at 1 instead of 0

noteName: note.name,
startTime: note.time,
duration: note.duration,
velocity: note.velocity

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: @tonejs/midi outputs a normalized value of 0-1. Consider scaling this to 0-100, since that seems to be standard scaling for scratch. (I have no preference personally)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I finished writing,I found there were no blocks for controlling note velocity,and the volume-control blocks were global.I intended to delete the velocity key.

@CHCAT1320

Copy link
Copy Markdown
Author

@CHCAT1320 I added a pull request to your repo with a suggested change on how you import the tonejs/midi code.

Do you think it'd make sense to merge this PR and my WebMidi one into the same extension?

Sure, it's my first time writing an extension, so there are many shortcomings. Thanks for your suggestions. Feel free to modify or reference it.

// License: MIT


// tonejs/midi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a full comment block including link to the original code and maybe license text as well - check other extensions for examples


const dataUrl = args.DATA_URL.trim();
if (!dataUrl) {
return 'MIDI Data URL is empty';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error messages should probably be wrapped in Scratch.translate()

@lselden lselden left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some suggestions / tips. See also the PR I passed in as well, which has fixes for some of the linting errors you're getting

@lselden

lselden commented Mar 18, 2025

Copy link
Copy Markdown

@CHCAT1320 I added a pull request to your repo with a suggested change on how you import the tonejs/midi code.
Do you think it'd make sense to merge this PR and my WebMidi one into the same extension?

Sure, it's my first time writing an extension, so there are many shortcomings. Thanks for your suggestions. Feel free to modify or reference it.

Glad you're open to it. I can manage merging the changes together. Please don't hesitate to contribute to it!

@CHCAT1320 CHCAT1320 closed this May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new extension Pull requests that add a new extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants