alda icon indicating copy to clipboard operation
alda copied to clipboard

Import MIDI files

Open daveyarwood opened this issue 7 years ago • 9 comments

Moved from https://github.com/alda-lang/alda/issues/85.

Quoth @crisptrutski:

We need some help from the machines in the effect to build the Library of Aldaxandria

Shout-out to @alandipert for also having the same intriguing idea. 💡

It would be cool to be able to read a MIDI file and spit an Alda score to STDOUT. You could then redirect that to a file...

$ alda import -f carry_on_my_wayward_son.mid > carry_on_my_wayward_son.alda

...or even pipe it back to alda to play it, effectively making alda a sort of command-line MIDI player!

$ alda import -f gangnam_style.mid | alda play

daveyarwood avatar Nov 24 '16 00:11 daveyarwood

It took me a while to figure out which Alda subproject repo this issue should belong to.

What I'm describing could be implemented as a standalone CLI tool, kept in its own repo and installed separately to Alda.

But it would be great if we included such a thing as a built-in alda command. So that made me think this should be filed under alda-client-java.

...Then I thought about implementing it in Java and puked in my mouth a little bit. If it were up to me, I'd do it in Clojure.

So I finally landed on alda-core being the right place to add this feature. We could make it a part of the Alda "standard library," and implement the alda import command as just another request to the server to do something, get the response, and print it to STDOUT. (This is akin to the alda parse task.)

daveyarwood avatar Nov 24 '16 00:11 daveyarwood

I'd like to take a crack at this. No guarantees (it's a clojure learning project for me, and MIDI parsing seems a bit hairy, even using the java libraries), but I'll give it a go. 😺

gdpelican avatar Jan 01 '17 14:01 gdpelican

Great, thanks! Let me know if you have any questions along the way.

On Jan 1, 2017 9:18 AM, "James Kiesel" [email protected] wrote:

I'd like to take a crack at this. No guarantees (it's a clojure learning project for me, and MIDI parsing seems a bit hairy, even using the java libraries), but I'll give it a go. 😺

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/alda-lang/alda-core/issues/25#issuecomment-269904644, or mute the thread https://github.com/notifications/unsubscribe-auth/AEroF4dwv15-dUhw69gc2R3vQFrP61OXks5rN7W8gaJpZM4K7Ld8 .

daveyarwood avatar Jan 01 '17 14:01 daveyarwood

So, It is still not a exact way to import the midi file?😅

Dongsh avatar May 07 '17 03:05 Dongsh

I found this issue by accident after googling for "MIDI-decompiler". I don't know much about ALDA but I'm working on a MIDI-decompiler for another project: truj/midica Since yesterday I have a first working prototype and tested with some random files. For most of them it works pretty well, for some I still need to optimize a lot.

I guess the base problems in both languages (ALDA and MidicaPL) are the same. So maybe you can re-use a part of the strategies that I'm using. Or even parts of my code, if you prefer to do it in Java.

In Midica the decompilation is mainly distributed over the following classes:

  1. MidiParser reads the sequence from the MIDI file.
  2. SequenceCreator creates a different instance of the sequence. This instance is actually used by the Midica Player and the decompiler. It contains mostly the same events than the original sequence. But this instance guarantees that each channel corresponds to one single track.
  3. SequenceAnalyzer reads and stores a lot of information from the sequence, not only for the decompiler but also for other purposes.
  4. MidicaPLExporter is the heart of the decompiler. It reads the data structures produced by the SequenceAnalyzer and translates them to MidicaPL source code.
  5. Slice is just a helper class that helps splitting the sequence into slices that can be processed after each other.

My decompiler works only for MIDI files with division type PPQ (pulse per quarter note). This makes it easier to guess the note length of a Note-ON/Note-OFF combination from the MIDI file. Fortunately this works for most files available on the internet as most of them use PPQ.

I hope this can help you for building a decompiler for ALDA as well. If you have questions, let me know.

truj avatar Dec 02 '19 22:12 truj

@truj Midica looks awesome! It's very much in the same spirit as Alda, but with its own flavor and a different niche. It makes me happy that there are other people out there doing similar things.

Your MIDI decompiler will be super helpful as a reference. Thanks for sharing!

daveyarwood avatar Dec 03 '19 02:12 daveyarwood

Meanwhile I tried out ALDA and had a bit of time to learn more about it. So I decided to support it as a decompilation format from Midica. Maybe I'll have some ALDA related questions later. Is it OK to post them here? Or maybe better there, than I don't need to misuse this issue any more.

truj avatar Mar 03 '20 19:03 truj

Interesting! I'd be happy to help, feel free to ping me with any questions in https://github.com/truj/midica/issues/53.

daveyarwood avatar Mar 03 '20 19:03 daveyarwood

@gdpelican started implementing MIDI import for Alda v1 (in Clojure) here: https://github.com/alda-lang/alda-core/pull/30

At this point, Alda v2 (Go / Kotlin) is almost ready for release, so we'll have to close the aforementioned PR, but it's still valuable to use as reference when we implement this feature (in Go) for Alda v2.

daveyarwood avatar Jan 01 '21 20:01 daveyarwood