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

.midi Export #4319

Merged
merged 20 commits into from
Feb 16, 2025
Merged

.midi Export #4319

merged 20 commits into from
Feb 16, 2025

Conversation

Commanderk3
Copy link
Contributor

@Commanderk3 Commanderk3 commented Jan 28, 2025

To export .midi this PR uses the library tones/midi.

@Commanderk3
Copy link
Contributor Author

I am close to completing this feature 👍

@Commanderk3
Copy link
Contributor Author

Commanderk3 commented Feb 1, 2025

fixes:#4311

@pikurasa I think the PR is ready for review. Please check it. Next, I have to work on adding instruments to the MIDI file. After exporting, you can play the MIDI file in media players like Windows Media Player. Right now, it will only play on the piano.
Just like Lilypond the notes have to be in a Start block. Each Start blocks are considered as "tracks" in midi. If you import it in a DAW you can edit it as well.

@Commanderk3 Commanderk3 mentioned this pull request Feb 1, 2025
4 tasks
@Commanderk3 Commanderk3 marked this pull request as ready for review February 8, 2025 08:17
@Commanderk3
Copy link
Contributor Author

Commanderk3 commented Feb 8, 2025

@pikurasa The midi export is finally done. Please review this PR.
@walterbender I made a tune and exported it to FL studio. It is working well. Although my windows player does not seem to understand the instrument. But it works fine with others.

final.mp4

For testing we can use : https://pianotify.com/import-midi-file

@pikurasa
Copy link
Collaborator

I tested https://github.com/sugarlabs/musicblocks/blob/master/examples/Holly-Jolly-Christmas.html, and the output seems to get off track after the third note.

This is the MIDI file generated while on your branch, HEAD is now at d343fd1f4 bug fix:
Christmas.zip

@Commanderk3
Copy link
Contributor Author

@pikurasa, I have fixed the issue. I thought _midiData was filled instantly, but that is not the case. It takes some time to retrieve all the data. Like Lilypond and others, I have created an after-save function to generate a MIDI file when midi data is filled.

Here is the result :->

midi2.mp4

@pikurasa
Copy link
Collaborator

Yes, it seems to work well.

I think it's ready for a code review.

js/logo.js Outdated
@@ -1690,7 +1703,11 @@ class Logo {
// console.log("saving mxml output");
logo.activity.save.afterSaveMxml();
logo.runningMxml = false;
} else if (tur.singer.suppressOutput) {
} else if (logo.runningMIDI) {
logo.activity.save.afterSaveMIDI(); //save midi
Copy link
Member

Choose a reason for hiding this comment

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

no need for this comment

generateMidi(data);
activity.logo._midiData = {};
document.body.style.cursor = "default";
},500);
Copy link
Member

Choose a reason for hiding this comment

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

please add a space after the comma

@walterbender
Copy link
Member

One other small change: please update the Save help string in turtledefs to include MIDI.

@Commanderk3
Copy link
Contributor Author

@walterbender Sir I have updated turtledefs.js and other changes you mentioned.

@@ -566,6 +566,8 @@ const createHelpContent = (activity) => {
_("Save project"),
_("Save project as HTML") +
"<br/>" +
_("Save project as MIDI") +
"<br/>" +
Copy link
Member

Choose a reason for hiding this comment

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

Should this be Save music as MIDI ???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought about that. You can edit MIDI files, so I thought "project" would be appropriate.

@walterbender
Copy link
Member

Also, since when you import MIDI, you get a MB project, I guess "project" does make sense.

@walterbender walterbender merged commit 7b17e9b into sugarlabs:master Feb 16, 2025
4 checks passed
@Commanderk3
Copy link
Contributor Author

I can add test cases for MIDI now in SaveInterface

@Ubayed-Bin-Sufian
Copy link
Contributor

@Commanderk3 Please add documentation for .MIDI export in Guide/README.md at section 5.2.

@Commanderk3
Copy link
Contributor Author

@Commanderk3 Please add documentation for .MIDI export in Guide/README.md at section 5.2.

Sure

@pikurasa
Copy link
Collaborator

FWIW, I tested our "Romanian Folk Dance" example (in the examples folder), and I'm very impressed with how it was able to handle the complex rhythms in that project.

@Commanderk3
Copy link
Contributor Author

Happy to see it working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants