News for hackers. Stuff that matters.
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Thursday September 06, 2018 @07:51PM (#17930684)
Hey HN, site author here! I was asked to repost this by the HN mods (read about the second-chance queue: https://news.ycombinator.com/item?id=11662380).

---

So, the context for this site is that I was reminiscing about the days of Geocities and Angelfire, when the web was quirky and fun. In those days, sites often used the <bgsound> HTML tag to include an auto-playing song in the background of a page. Usually the song was in the MIDI file format.

It’s hard to describe MIDI files if you’ve never heard them before. The MIDI aesthetic is synth-laced, nostalgia-inducing, old-school, and endearing. It’s mixed up with the first DOS video games I ever played and the first websites that I visited as a small child in ‘95 and '96. A textual description can’t adequetly capture the feeling of listening to a MIDI.

I was surprised and sad to learn that all major web browsers have removed MIDI file support. Perhaps this happened at the same time that the <bgsound> HTML tag was removed? This explains why I haven’t heard a MIDI in many years!

So, I really wanted to play a MIDI file. When I searching the web for a MIDI websites, I discovered that existing websites were quite disappointing. It was difficult to find a site with a decent user experience. Almost all the top sites were unmaintained or broken in various ways. Most sites could not play back the files directly in the site, requiring them to be downloaded and played in an external program instead.

Quicktime also dropped support for MIDI when Quicktime X was released in 2009 which inconvenienced many musicians and probably stopped many users from playing back (or discovering!) this wonderful file format. Technically, Apple still offers Quicktime 7 for download, which can play MIDI. But it’s a 32-bit app so it will likely stop working once the macOS version after 10.14 Mojave is released. Also, embarrassingly, the Quicktime 7 download link uses insecure HTTP!

Even the venerable VLC failed to play back the MIDI files I threw at it. (I later learned that VLC can actually play MIDIs and I just got unlucky with the few I tried, hah!)

There were some websites that could convert MIDI to low-quality MP3, and some sites offered inline MIDI playback using Adobe Flash, but they were flaky and impossible to get working in Chrome. Other websites implemented MIDI players in JavaScript, but they were usually missing instruments or extremely ineffecient multi-megabyte cross-compiled Emscripten libraries.

I eventually found a .ZIP archive with around 100,000 MIDI files. I wanted a way to search through them and share the best ones with friends. So I decided to build a site to address the shortcomings of existing MIDI sites.

And that’s BitMidi. A free way to browse and play MIDI files!

Feedback welcome!

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Thursday September 06, 2018 @07:57PM (#17930728)
A bit more info about how BitMidi is built...

First step, I needed to build a MIDI player in JavaScript. At first, I was determinted to write one from scratch in JavaScript and use the Web Audio API to synthesize all the instruments in code. I thought this would yield the the smallest possible JavaScript file size.

However, I didn’t really have the audio engineering skills to pull this off. So ended up settling for an approach that uses SoundFonts, which are basically instrument voices or files that contain all the possible notes an instrument can play.

BitMidi uses the instrument voices from the General MIDI sound set released by FreePats.

Then I compiled the best MIDI player written in C (libtimidity) to WebAssembly using Emscripten. I put in lots of effort to optimize the built size and include the minimal amount of code. The result of my efforts are available in the npm package timidity (https://github.com/feross/timidity). It’s quite lightweight – just 34 KB of JavaScript and 23 KB of lazy-loaded WebAssembly, smaller than anything I’ve seen on any other site.

Then I put a frontend on it, so it’s easy to browse all the files. BitMidi uses all the best techniques that I know about to make it super fast and snappy. The site gets perfect 100s on all categories on Chrome’s Lighthouse Performance benchmark, which is extremely non-trivial in my experience.

I plan to ingest a lot more MIDI files in the future, from sources like the Geocities MIDI archive on the Internet Archive and elsewhere.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by jimbo1qaz on Friday September 07, 2018 @01:05AM (#17932007)
>the best MIDI player written in C (libtimidity)

Ouch. Has timidity fixed the issue where playing 2 of the same note in sequence cuts off the release tail of the first note when the second starts? Fluidsynth is written in C and doesn't have that issue and sounds better (I assume this behavior matches good MIDI hardware, but not sure about the crappy Windows GS Wavetable Synth). fluidsynth-lite is a Fluidsynth fork with dependencies removed.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Friday September 07, 2018 @01:21AM (#17932055)
Okay, I stand corrected. I did a bunch of research, but I clearly missed some superior MIDI players. I'll take a look at FluidSynth-lite and see if there's some way to use it.

One issue I can already see is they use a SoundFont file (.sf2) instead of instrument patch files, which means the whole 100MB+ file probably needs to be loaded before playback. My current approach uses GUS patch files which have one file per instrument, so I can load just what's needed for a particular song and start playing much sooner.

Edit: It looks the GeneralUser SoundFont is only 31MB and it sounds almost as good as the 100MB+ one. So, while this will still be slower than my current approach of loading just the needed instruments, perhaps if I start loading it in the background with ServiceWorker and cache it forever, this could work. Thoughts welcome.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by SmellyGeekBoy on Friday September 07, 2018 @04:23AM (#17932690)
Perhaps give users the choice of which MIDI playback "engine" to use? It seems a shame to throw away all of your hard work (on the player) so far.
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by j0wy on Thursday September 06, 2018 @09:29PM (#17931224)
Awesome job - I’m about to cry from the memories this brings back. I really appreciate the effort put into porting a proper MIDI player to the browser while keeping page optimization in mind.

Dragging and dropping to play a midi is a great touch!

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Thursday September 06, 2018 @10:02PM (#17931364)
It's heartwarming to get feedback like this. Thank you for this.
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by jek0 on Friday September 07, 2018 @12:47AM (#17931941)
Great job putting all this together! Brings back memories.

Out of curiosity I downloaded a .mid file to compare it with my local timidity install. The quality of the later is way better (I installed it from brew)... It sounds like it either use a better SoundFont or midi effects (like reverb) are not working properly on the site?

Is it just me? Not complaining, just mentioning it.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Friday September 07, 2018 @01:05AM (#17932004)
You're right. Reverb sounds way better with the version of timidity available on Homebrew. I noticed that brew is installing TiMidity++ (http://timidity.sourceforge.net/) instead of libTiMidity (http://libtimidity.sourceforge.net/) which is what I ported to WebAssembly. I'll look into the differences between the two, but if anyone knows more please share.
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by coding123 on Thursday September 06, 2018 @09:33PM (#17931244)
That's a pretty amazing technical feat!
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by culot on Friday September 07, 2018 @11:04AM (#17934782)
I have an archive of about 3600 MIDI files I collected from 1997-2004. I don't know if it's of any use, but here we go:

https://drive.google.com/file/d/1mqI7d6kd3zOIZ2VjbKaeu3f6u3a...

Most of the file names are wonky, but I think the artist and title information should be inside many of the files.

There should be some files in there that are long gone from the web, some I know are from amateur or unknown musicians. But as I said, the filenames are a mess, so yeah.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by pbhjpbhj on Friday September 07, 2018 @09:39AM (#17934103)
In part the midi thing on GeoCities was stimulated by the lack of any semblance of copyright controls. You saw a graphic, sound, etc., You stuck it on your own page.

Then framing grew big (putting other people's content inside your frames) and content ownership broke in to the web.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by grawprog on Thursday September 06, 2018 @11:08PM (#17931584)
That's really cool. I struggled to get a good midi engine working on linux and even what I have still messes around sometimes. Plus the instruments, while similar, aren't quite the same as those old school midi tunes from back in the day.

I thought maybe my struggle was unique to Linux. Setting up sound drivers for recording, was fairly complicated even without adding midi into it. Though after the initial setup linux's audio production tools are fairly awesome. I never realized midi support had declined so much all over. It's nice to see projects that keep old technology alive, sometimes older, more simple things really do have appeal and it's always sad when things kind of vanish unnoticed.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Thursday September 06, 2018 @11:42PM (#17931715)
> I never realized midi support had declined so much all over

I actually have no idea why MIDI support was removed from browsers. I understand that <bgsound> was a bad idea – autoplaying audio and all – but why did MIDI file support have to go too? I was under the impression that web browsers took backwards compatibility pretty seriously and deleting a supported audio format and breaking most of the sound on the early web seems like something that wouldn't fly today.

Does anyone know the story here?

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by SmellyGeekBoy on Friday September 07, 2018 @04:25AM (#17932699)
Perhaps autoplaying audio wasn't obnoxious enough, so autoplaying video became top priority? /s
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by rewgs on Friday September 07, 2018 @04:27PM (#17937383)
Just to be really, really clear so that those unfamiliar with MIDI don't get confused or given incorrect information while reading this...

MIDI does not sound like anything. It's instructions, a protocol, nothing more. The music will only sound nostalgic if the MIDI is triggering instruments that sound nostalgic.

There's also no such thing as an "old-school" MIDI file. The MIDI standard hasn't changed since its release in the 80s, and is just as if not more important today than it was back then.

Anyways, this is super cool and great job building it!

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by blobert on Friday September 07, 2018 @09:17AM (#17933968)
Just a heads up in Chromium version 68.0.3440.106 (Official Build) (64-bit) the midi's seem to be playing back at 10x or faster. In Firefox 61.0.1 (64-bit) at 2x or so. I'm on Ubuntu 18.04.1 LTS. Other generic web midi players play at the correct speed in either browser. Not sure if timidity has some timing issues that might be caused by the combo of OS and browser. Other than that, wonderful job and great idea!
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by ravenstine on Friday September 07, 2018 @10:16AM (#17934370)
I'm so glad this exists! The feature of playing a MIDI file in a webpage was one of the things that inspired me to learn web development when I was 10 years old.

I'm especially impressed at the number of Rammstein MIDIs your site has! Das ist gut! :D

May I ask how I can contribute MIDI files? I may have some decent ones buried deep in my backup drive.

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by arayh on Friday September 07, 2018 @10:04AM (#17934282)
Thank you, this is awesome! I used to collect my favourite MIDI tunes around the web (and I still have them on my HD). I always thought how amazing it was to have so much music yet take up so little space on my drive. This really brings back memories of the music that automatically played on the background of personal websites.
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by wickedOne on Thursday September 06, 2018 @09:37PM (#17931262)
love these memories :-)

a category / theme browsing method would be added value i think

Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Thursday September 06, 2018 @09:41PM (#17931280)
Yep, I plan to add a way to suggest tags for each MIDI. And then list the top 20 tags on the homepage for easy browsing. Does this seem like it would work for you?
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by Bluecobra on Thursday September 06, 2018 @09:53PM (#17931332)
I would suggest using an UMRN (Unique Midi Routing Number) to help sort all those MIDI files.
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by feross on Thursday September 06, 2018 @09:59PM (#17931355)
Will consider it! Here's the reference, for those who don't get it: https://twitter.com/BitMidi/status/1027693160531668992
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by wickedOne on Friday September 07, 2018 @06:49AM (#17933274)
sounds good to me!
Re:Show HN: BitMidi – Wayback machine for old-school MIDI files by gregjw on Friday September 07, 2018 @07:12AM (#17933368)
What an amazing idea.

Thanks for putting the effort in, you've given me a lot of nostalgia feels.