Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new extension MIDI Parser #2035

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

CHCAT1320
Copy link

@CHCAT1320 CHCAT1320 commented Mar 15, 2025

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
Collaborator

The code doesn't even work

@SharkPool-SP
Copy link
Collaborator

The extension doesn't even load

@CHCAT1320
Copy link
Author

The extension doesn't even load

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

@SharkPool-SP
Copy link
Collaborator

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

@CHCAT1320
Copy link
Author

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

Can this code run normally on your side?

@CST1229
Copy link
Collaborator

CST1229 commented Mar 16, 2025

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
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
Copy link
Collaborator

CST1229 commented Mar 16, 2025

But the code for the extension works perfectly on TurboWarp.

i tried it on turbowarp

@CST1229
Copy link
Collaborator

CST1229 commented Mar 16, 2025

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

@CHCAT1320
Copy link
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
Copy link
Collaborator

CST1229 commented Mar 16, 2025

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
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
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
Copy link

lselden commented Mar 17, 2025

@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

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

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

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
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
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

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

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()

Copy link

@lselden lselden left a comment

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
Copy link

lselden commented Mar 18, 2025

@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!

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