Skip to content

MIDI Extension #1725

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

Closed
wants to merge 24 commits into from
Closed

MIDI Extension #1725

wants to merge 24 commits into from

Conversation

Brackets-Coder
Copy link
Contributor

@Brackets-Coder Brackets-Coder commented Oct 15, 2024

This extension manages MIDI input. While support for MIDI output is possible in the future, I'm not planning on it at the moment. Currently, only MIDI note input is supported. Other MIDI input events return a console log. This means things like pitch bend, damper pedals, etc. will not work. These may also be supported in the future, but not as of now.

Note that MIDI compatibility varies depending on which browser you're using. If the browser doesn't have MIDI API support, it will return an error, show an alert, and the extension won't load. The main cause of this is Safari and significantly outdated versions of browsers.

I've made a sample project, but I won't add it until this gets merged because it uses localhost instead of extensions.turbowarp.org.

Sorry the code is bad I wrote it in like four hours

353662493-3f9327ac-dd48-4dad-8b59-e35de05e76e6

@GarboMuffin GarboMuffin added the pr: new extension Pull requests that add a new extension label Oct 15, 2024
@CubesterYT CubesterYT self-assigned this Oct 15, 2024
@CubesterYT
Copy link
Member

I'll need to remember to handle this PR

Brackets-Coder and others added 3 commits October 16, 2024 15:27
I've ran prettier like a few dozen times with the same version and settings as the repo. If this fails I have no idea why
@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Oct 17, 2024

Something to note: I haven't tested the latest commit, but it basically just condenses some blocks into single blocks with inputs, and it passed all checks, so I'm assuming it works. Code looks perfect, but I can't test it right now.

@Brackets-Coder
Copy link
Contributor Author

@CubesterYT One thing to note: If you're going to test this extension's functionality while you're reviewing it, you need a MIDI compatible digital keyboard and a MIDI API compatible browser (basically everything but Safari works). However, you probably don't need to do this as I've tested it and it works consistently.

Take your time. I'll wait and be patient.

@CubesterYT
Copy link
Member

I'm just going to look through the code and make any fixes

@Brackets-Coder
Copy link
Contributor Author

I'm just going to look through the code and make any fixes

No problem. Take your time

@lselden
Copy link

lselden commented Oct 31, 2024

Hi @Brackets-Coder - nice work so far, and I'm excited someone else wants to get midi into Turbowarp! I've forked your pull request and gotten started in making some changes. In particular I'm looking to add in support for all midi events (CCs, pitchbend, etc.), and possibly MIDI Out as well.

Before I make a open a pull request to your fork (a pull request of a pull request 😁 ) I just wanted to make sure: are you open to collaborating and accepting changes? I'm a professional developer, but new to Scratch and how people use it/expect blocks to look and work, so please push back on any of my changes/suggestions, or let me know if you have questions.

Let me know if you're down. You can review my progress so far here: https://github.com/lselden/extensions/blob/midi/extensions/MasterMath/midi.js , or review the full changelog:

@lselden
Copy link

lselden commented Oct 31, 2024

@CubesterYT or other testers/reviewers: If on windows you can use the free LoopMIDI and virtualKeys tools to test even if you don't have a hardware MIDI device. I don't have a mac handy but I believe you can use the built-in MIDI Studio feature

@Brackets-Coder
Copy link
Contributor Author

https://github.com/lselden/extensions/blob/midi/extensions/MasterMath/midi.js

Thanks for asking. I appreciate your excitement and willingness. The code looks great, professional, well-formatted, etc. but I was kind of not expecting such a request. My initial intent for this extension was to be a small and minimalistic MIDI input handling interface, with the possibility of me adding more MIDI events and MIDI output support in a later update. As of right now, I've marked this PR as "finished" and am waiting on it to be merged before I worry about further updates. So we'll see. Not right now though, thanks anyway. I hope you understand.

@Brackets-Coder
Copy link
Contributor Author

@CubesterYT or other testers/reviewers: If on windows you can use the free LoopMIDI and virtualKeys tools to test even if you don't have a hardware MIDI device. I don't have a mac handy but I believe you can use the built-in MIDI Studio feature

Yes. I'm not opposed to this, but for the most part I've been using some physical MIDI input devices I have for testing as they're what are meant to be used by the extension and I'm not quite sure how it will handle software interference with the API, but any testing is better than nothing.

@CubesterYT
Copy link
Member

I'll look into it

@Brackets-Coder
Copy link
Contributor Author

@CubesterYT or other testers/reviewers: If on windows you can use the free LoopMIDI and virtualKeys tools to test even if you don't have a hardware MIDI device. I don't have a mac handy but I believe you can use the built-in MIDI Studio feature

Speaking of Macs - A quick note about that. The Safari desktop browser is the only major browser that doesn't support the Web MIDI API. What's with that? The only reason I need the compatibility detection code is because of Safari and really outdated browsers

@lselden
Copy link

lselden commented Oct 31, 2024

@CubesterYT or other testers/reviewers: If on windows you can use the free LoopMIDI and virtualKeys tools to test even if you don't have a hardware MIDI device. I don't have a mac handy but I believe you can use the built-in MIDI Studio feature

Speaking of Macs - A quick note about that. The Safari desktop browser is the only major browser that doesn't support the Web MIDI API. What's with that? The only reason I need the compatibility detection code is because of Safari and really outdated browsers

Because of security concerns - SYSEX could (in theory) be used maliciously, and for fingerprinting. This PR doesn't attempt to use sysex (you have to pass { sysex: true } when requesting midi access), so it shouldn't trigger any restrictions in other browsers (Firefox, I believe?) that doesn't like sysex.

@lselden
Copy link

lselden commented Oct 31, 2024

https://github.com/lselden/extensions/blob/midi/extensions/MasterMath/midi.js

Thanks for asking. I appreciate your excitement and willingness. The code looks great, professional, well-formatted, etc. but I was kind of not expecting such a request. My initial intent for this extension was to be a small and minimalistic MIDI input handling interface, with the possibility of me adding more MIDI events and MIDI output support in a later update. As of right now, I've marked this PR as "finished" and am waiting on it to be merged before I worry about further updates. So we'll see. Not right now though, thanks anyway. I hope you understand.

Totally understand! No complaints here.

@Brackets-Coder
Copy link
Contributor Author

Right now there's a block that returns all active notes.
Should I add some more reporters that help with managing these, such as getting a specific index of that array, or re-sorting the array by pitch or most recent / least recent?

@Thebloxers998
Copy link

What's MIDI?

@Brackets-Coder
Copy link
Contributor Author

What's MIDI?

MIDI stands for Musical Input Digital Interface. It allows electric instruments (in this case a digital piano keyboard) to communicate with computers and other devices.

This extension allows you to use note input from a MIDI device to control your projects. For example, pressing a note on a piano keyboard could play the corresponding note with the music extension, or be used for music visualization.

@Brackets-Coder
Copy link
Contributor Author

@CubesterYT I have granted your wishes. Is it better now?

@CubesterYT
Copy link
Member

I'll look it over again

@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Jan 29, 2025

If any of the moderators with write access happens to have access to a MIDI keyboard for testing it'd be great if we could get them over here but no rush at all. This is too much of a tiny extension to worry about

@Brackets-Coder
Copy link
Contributor Author

@SharkPool-SP maybe? idk

@SharkPool-SP
Copy link
Collaborator

Nope. I don't have one

@Brackets-Coder
Copy link
Contributor Author

Nope. I don't have one

That's what I would've guessed

@Brackets-Coder
Copy link
Contributor Author

This extension does not require a full 88 key digital piano keyboard, really any MIDI compatible keyboard (even the small octave size ones or the older synthesizers) should work

@Brackets-Coder
Copy link
Contributor Author

Can any moderator test / review this? A MIDI keyboard would be great but emulation software may also work

@samuellouf
Copy link
Contributor

Not a moderator, but I'm willing to test it!

@samuellouf
Copy link
Contributor

samuellouf commented Feb 20, 2025

It works awersomely here, however, I have a few suggestions to make.

@Brackets-Coder
Copy link
Contributor Author

It works awersomely here, however, I have a few suggestions to make.

That was fast! I wouldn't mind a few suggestions, but it's probably not going to get many updates before it's merged

@samuellouf
Copy link
Contributor

samuellouf commented Feb 20, 2025

I think it would be better if :

  • the extension was able to detect when an input or output is (dis)connected and return the name,id... of the said input/output
  • the "when any note is pressed" / "when any note is released" / "when note [NOTE] is pressed" / "when note [NOTE] is released" blocks had another option which would be pressed/released
  • the "when any note is pressed" / "when any note is released" block was able to give you the number of the key that was pressed/released

I can fork the extension and code it for you. Since I was already working on a MIDI extension I already have most of the code ready, I would just need to adapt it a little. I would have it ready between today and Monday.

@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Feb 20, 2025

I think it would be better if :

  • the extension was able to detect when an input or output is (dis)connected and return the name,id... of the said input/output
  • the "when any note is pressed" / "when any note is released" / "when note [NOTE] is pressed" / "when note [NOTE] is released" blocks had another option which would be pressed/released
  • the "when any note is pressed" / "when any note is released" block was able to give you the number of the key that was pressed/released

I can fork the extension and code it for you. Since I was already working on a MIDI extension I already have most of the code ready, I would just need to adapt it a little. I would have it ready between today and Monday.

That'd be great. Like the first comment says, I wrote this in four hours very hastily so it's not at all a masterpiece and doesn't have as many features as I'd like.

I think I'm just going to hold off on this PR for now though, you and @lselden can make changes if you'd like. I'm too busy with #1732 and #1936

@samuellouf
Copy link
Contributor

Hello!
Could you please maybe allow me to add edits to your repository?
I'm trying to fork it but it seems like I can't because I already forked TurboWarp/extensions.

@Brackets-Coder
Copy link
Contributor Author

Hello! Could you please maybe allow me to add edits to your repository? I'm trying to fork it but it seems like I can't because I already forked TurboWarp/extensions.

I'm afraid I can't help you. "Allow edits by maintainers" is already enabled. try submitting a PR to https://github.com/Brackets-Coder/extensions?

@samuellouf
Copy link
Contributor

Okay

@samuellouf
Copy link
Contributor

Could you Sync the fork before I fork it?

@samuellouf
Copy link
Contributor

A lil suggestion for the banner :
I really like the piano, but I think it would look nice if you made your background with Haikey, like "layered waved" or "stacked steps".

@Brackets-Coder
Copy link
Contributor Author

Could you Sync the fork before I fork it?

Sorry, I was away from the computer for a bit. I'll do that now.

A lil suggestion for the banner :
I really like the piano, but I think it would look nice if you made your background with Haikey, like "layered waved" or "stacked steps".

  1. Not much of an artist
  2. The banner wasn't my main focus
  3. I'm not really working on this PR anymore...?

@lselden
Copy link

lselden commented Mar 10, 2025

@Brackets-Coder since it seems you aren't working on this PR anymore I went ahead and opened up a separate PR, which includes MIDI output not just input. I'm sure your testing/feedback would be helpful.

@samuellouf if you're interested in trying it out here's the PR I submitted

@Brackets-Coder
Copy link
Contributor Author

@Brackets-Coder since it seems you aren't working on this PR anymore I went ahead and opened up a separate PR, which includes MIDI output not just input. I'm sure your testing/feedback would be helpful.

@samuellouf if you're interested in trying it out here's the PR I submitted

Thanks so much.

Closing in favor of your better PR, I wrote this too hastily to be of any quality

@samuellouf
Copy link
Contributor

@samuellouf if you're interested in trying it out here's the PR I submitted

Thanks!

@Brackets-Coder Brackets-Coder deleted the midi branch March 19, 2025 17:39
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.

7 participants