JuliaMusic / MIDI.jl

A Julia library for handling MIDI files
https://juliamusic.github.io/JuliaMusic_documentation.jl/latest/
MIT License
67 stars 22 forks source link

Compressing or reducing the size of MIDI file #127

Closed ashwani-rathee closed 3 years ago

ashwani-rathee commented 3 years ago

Hey@Datseris, I am working on a hackathon project that kind of revolves around around the idea that : Can music be encoded on QR code?? Yes,it can be This is the first 30 seconds of "Edvard Grieg - Peer Gynt - Suite No. 1, Op. 46 - I. Morning Mood" Data in midi file:https://pastebin.com/cJ00j61P Good you tube one : https://www.youtube.com/watch?v=kzTQ9fjforY I am working on classical pieces(should I??since they are pretty intensive and heavy) Why would I like to make music on qr code??

How I doing it right now??

Can you guide me on this regarding midi files,their compression(I am able to get around 40 sec worth of data in the bar code but I think a lot more can be done),their encoding and decoding to get the data back?For now I want to make the qr codes myself and allow publish them on my website or in nearby place inside room,from which I can create some classical music.

The Classical Music files are pretty big,so I don't mind the idea of making multiple files for a same code (since they can be used as an indicator if the people is really interested in listening to to the music or it is just background noise for them) It is a hackathon project for nwhacks2021,jan9-jan10

Datseris commented 3 years ago

Hi there,

MIDI files have a very specific format, which in itself is already as optimized as it can get, due to the usage of variable length integers. You cannot compress the RAW MIDI data further, at least not to the best of my knowledge.

If you were using some music that can be repeated, e.g. rock, then it would be easy to compress further, but it would not be a true compression. You would write e.g. only one verse and one chorus into the MIDI file. Then, using some auxilary data that MIDI allows for, you could write instructions of the form "VERSE = 0-16, CHORUS = 17-32", which would denote the bars the verse and chorus occupy, as well as another instruction like "REPEAT VERSE CHORUS x3" to repeat them three times. But that's not compression, this is just smart reading...

I scanned your QR and got a text that included both raw midi data, as well as some copyrights and disclaimers at the end. Wouldn't these copyrights make the MIDI file unreadable, since they are commands that do not abide the MIDI encoding? How do you intend to actually read this QR code to play music? That is not yet clear to me.


(putting this under invalid, as it is not related with the Julia package MIDI.jl in any way)

ashwani-rathee commented 3 years ago

What I intend on doing is making the qr data for 50 greatest pieces of classical music (Pretty sure I won't be able to make all of them in the time available)and just make android qr reader/also make a website with data and then implement a midi file player in android+website and kind of a make query system on website. That should be good enough as proof of concept.

If the person using the qr code is interested in listening to full version,I could create a simple small qr code leading to the website near the preview qrcode(30 second is pretty small).

And yeah,I am aware of the issue due to the copyrighted disclaimers.I am searching multiple version of same piece and then find the best one and then make it as clean as possible.Good thing that you were able to see QR code and the midi data,serves as proof of concept almost.Just need to make the midi player I think.Also need to fix some encoding issue arising when reading the file.Maybe zbarimg never used .mid before,so it's making several assumptions on its own.Almost half of the file in the example is copyright disclaimers,well need to find/write for a cleaner one.

Datseris commented 3 years ago

You still haven't answered the most fundamental question: how do you go from scanning a QR code on your phone, to listening sound?

ashwani-rathee commented 3 years ago

I saw several midi packages in java,I am thinking that would work. I am yet to start the developement part in android,so I might be missing something. Also I saw a different problem as most qr code reader in android output text and not the binary data which is stored in the file(image)... I saw several midi players in google playstore: like https://play.google.com/store/apps/details?id=net.volcanomobile.midiplayer&hl=en_IN&gl=US This answer kind of answers of a big chunk of the problem I believe: https://stackoverflow.com/questions/36193250/android-6-0-marshmallow-how-to-play-midi-notes javax.sound.midi pakage should be helpful with that,it has javax.sound.midi.MidiSystem;javax.sound.midi.Sequencer I am hoping to being able to run sequencer there and run the file. For desktop,it's much more simple and direct: https://examples.javacodegeeks.com/desktop-java/sound/play-midi-audio/

ashwani-rathee commented 3 years ago

Successfully figured out the encoding and decoding of the raw binary data of midi files and final.mid worked just the way it should have on computer. I am having some issue with decoding with as the decoder tries to interpret the binary data in UTF-8 and not in ECI mode on phone.

Datseris commented 3 years ago

Great sounds cool! I'm closing this now since it has no relation to MIDI.jl, which this GitHub repository contains. If you want to chat more feel free to join the Julia Slack, specifically the channel #music-dev.