Skip to main content

Tag: MIDI apps

A humanoid robot sits in front of blue curtains, playing a blue electric guitar. The robot appears focused, with its hands positioned on the strings and frets of the guitar.

Turning MIDI Melodies Into Full Songs with Meta’s MusicGen

The popularity of generative AI software has reached an all time high this year, with music lagging behind other mediums like image and text. Nevertheless, two applications dropped in May and June 2023 that marked a major improvement in the technology. It probably comes as no surprise that the companies behind these apps are Google and Facebook-Meta.

One of Google’s research teams published a paper in early January 2023, describing a generative AI music app called MusicLM. The paper detailed a product that could turn text prompts into songs. But perhaps more impressively, it could also take in a melody and incorporate that tune into its final output. Some demos in the paper featured humming and whistling, combined with written descriptions of attributes like genre and instrument, to output a song with that tune, in that style.

When Google launched their MusicLM beta app in May 2023, it included the text prompt feature but lacked the option to upload a melodic condition. This was a bit disappointing to those of us who had been eagerly awaiting the experience of turning our musical ideas into the genre of our choice.

Fortunately, just one month later, Meta has released their own music generator called MusicGen. As if responding to Google and one-upping them, Meta included the melodic audio input feature that Google omitted from their beta app.

In this article I’ll share a quick overview of how MIDI generation fits into the picture, along with tips about how to get started with your own experiments. 

Current limitations in AI MIDI generation

To date, even the most high profile AI MIDI melody generators have been underwhelming. OpenAI decommissioned their MIDI generation app MuseNet in December 2022, right after the launch of ChatGPT. Google offers a DAW plugin suite called Magenta Studio that includes MIDI generation, but it simply doesn’t deliver the quality that any of us would have hoped for.

Experimentally minded folks might have some fun using ChatGPT music prompts to generate MIDI melodies. WavTool is a browser app that supports the ability to do this within a DAW, but it takes a great deal of trial and error to create a good melody. In many cases, you could have composed something yourself in a shorter period of time. This comes down to the fact that large language models are not trained on music composition, despite having a solid grasp of music theory concepts.

AudioCipher’s text-to-MIDI generation VST is another option you may have already explored. It lets you control key signature, chord extensions, and rhythm automation. However, the plugin does not use artificial intelligence. Users encode words and phrases into the MIDI tracks as a source of creative inspiration. The algorithm draws from a classical tradition practiced by both spies and composers, called musical cryptography.

Suffice to say, each of these options has pushed the game forward, but none of them have perfected the MIDI song generation experience. Instead of waiting around for AI MIDI generators to get better, I propose using Meta’s MusicGen application in combination with an audio-to-midi converter. We’ll get into that next. 

Turning your MIDI melodies into full songs

To get started, create a MIDI melody in your DAW and export it as an audio file. It’s best to use a sine wave or a clean instrument without any effects. Once the audio file is ready, upload it to MusicGen and include a text prompt that describes the type of music you want to generate.

I’ve created a video demo (shown above) with AudioCipher’s text-to-MIDI melody generator and MusicGen. We created a short MIDI track, exported it as a wav file and then fed it into the Melody Condition container in Hugging Face. From there, we were able to use text prompts to turn the same tune into 15 different genres of music. 

To learn more, see this article on how to use MusicGen for music production, including suggestions on the best prompts to use with the app. I’ve also included an important tip for managing your Hugging Face account settings, to avoid accidentally racking up a large bill! 

Convert MusicGen audio back into MIDI

Now that you’ve seen how MusicGen works and may have even created an audio file of your own, the last step is to pass that file back through a polyphonic audio-to-midi converter like Samplab 2, Basic Pitch, or Melodyne.

A word of advice; MusicGen produces a lot of noise, so if you have noise reduction software, I recommend using that before passing it through a MIDI converter. Noise tends to be misinterpreted as tonal content, so cleaning it up will save you time later.

Here are the three best audio-to-midi converters that I’ve found:

Samplab 2 is my favorite option for audio-to-midi because it detects and separates instrument layers before transposing each one into MIDI. MusicGen tends to add drum layers to tracks even when you ask it not to. Samplab will separate those drums out, so you can isolate tonal instruments like piano, guitar and bass. The app is available as a DAW plugin and standalone app, with drag-to-midi capabilities.

Basic Pitch is a free alternative to Samplab that was built by Spotify and runs in your browser. It mashes everything together in a single piano roll, so I would only recommend using it for single-instrument audio files. If the track is too complex, Basic Pitch will omit a large part of the music, while simultaneously adding excessive rhythmic articulations due to noise and effect layers.

Melodyne 5 is a high quality application that supports single-instrument polyphonic MIDI conversion only. It won’t separate instruments into their own tracks, but it handles solo piano and guitar very well. You get what you pay for and to be blunt, Melodyne is expensive. So if you already have Melodyne, go ahead and try it out with this workflow. Otherwise Samplab is probably your best bet.

There you have it. Once you’ve converted the MusicGen audio file into MIDI, you can pull it down to your DAW and clean things up further in the piano roll. You’ll have an expanded arrangement based on the initial MIDI idea. But now you can add your own virtual instruments and sound design to tighten up the quality.

This might seem like a lot of information, but the whole process takes about 2 minutes, from creating an audio file in MusicGen to passing it through an audio-to-MIDI converter. You may need to spend more time fine tuning your text prompt to get the sound that you’re after. MIDI clean up in the DAW will also require a little work. But hey, it is what it is. 

I hope this primer has given you some food for thought and an entry point to deepening your AI music discovery process. These workflows might become obsolete in the coming year as the technology continues to improve. For now, this is one of the best methods I’ve found for developing a MIDI melody and turning it into a full song with artificial intelligence. Visit our site to find this complete guide to AI music apps in 2023.

A green Android robot mascot DJing with two turntables and a mixer, holding headphones to its head and standing behind DJ equipment with green vinyl records.

Developing MIDI applications on Android

About Android MIDI

In 2015 Android introduced MIDI support. Android has billions of users which means there’s a whole lot of people with MIDI compatible devices in their pocket!

In this article I’ll explore the most popular types of MIDI applications on Android and how to choose the right MIDI API when developing your own app.

Common types of MIDI app

 The two most popular types of MIDI app are:

1) Apps controlled by MIDI. These are apps which primarily receive MIDI data, such as synthesizers, drum machines and DJing apps.

2) MIDI controller apps. These apps are used to control other apps, external hardware or external software (such as a desktop audio workstation).

Apps controlled by MIDI

These apps receive MIDI data from hardware connected over Bluetooth or USB, or from a virtual MIDI service running on the phone itself.

The virtual analog synthesizer app, DRC can be played using an external MIDI keyboard  

 MIDI controller apps

These types of apps are designed to control other apps by sending MIDI to them. Examples include:

  • Using the phone’s touch screen as an X-Y pad which sends MIDI Control Change messages
  • Using the phone’s accelerometer to send MIDI pitch bend information
  • Step sequencing and piano roll apps

Super MIDI Box is a MIDI drum machine and step sequencer 

These types of apps are especially useful on Android because of how easy it is to use Android as a USB-MIDI device.

Android as a USB-MIDI device

A little-known feature of Android is that when connected to a USB host (like a computer) it can become a class compliant USB-MIDI device. This is done in the USB settings.  

Once the USB mode is changed to MIDI, it will appear on the host as a MIDI device with one input channel and one output channel. A MIDI controller app can then be used to control software, such as a Digital Audio Workstation (DAW), on the host.

Inside the app the MIDI device will show up as “Android USB Peripheral” with a single input port and a single output port.

DRC app connected to the Android USB Peripheral MIDI device

Android’s MIDI APIs 

 In order to develop a MIDI application on Android you’ll need to use one or both of the available MIDI APIs. Here’s a summary of the available APIs and their features:

JVM Midi

 In Android Marshmallow (API 23) the JVM Midi API was released. It can be accessed using Kotlin or the Java Programming Language. It enables you to enumerate, connect and communicate with MIDI devices over USB, Bluetooth LE and other apps advertising as virtual MIDI services.

Pros

  • Available on over 60% of all Android devices (correct as of July 10th 2019)

Cons

  • Sending MIDI messages to C/C++ code requires use of JNI which can introduce complexity due to multi-threading
  • MIDI data only available through callback mechanism

You must use this API for enumerating and connecting to MIDI devices, however, for reading and writing you can choose between this API and the Native Midi API described below.

Native Midi

In Android Q the Native MIDI API was released. It’s specifically designed for communicating with MIDI devices inside an audio callback which makes it easy to control audio rendering objects, for example a software synthesizer.

This API only handles sending and receiving MIDI data, not MIDI device enumeration or connection. That still needs to be done using the JVM API.

Pros

  • Easy to integrate with existing C and C++ code
  • Best possible latency
  • MIDI data can be received and sent inside an audio callback without blocking

Cons

  • Still need to enumerate and connect to MIDI devices in Kotlin or the Java Programming Language using the JVM MIDI API
  • Only available on Android Q and above 

Getting Started 

You can start developing a MIDI app using Android Studio. You’ll want to check out the following resources:

You should also take a look at the existing MIDI apps on the Google Play Store.

If you are using audio in your app you might want to check out the Oboe library for developing high performance audio apps.

If you have questions about developing MIDI apps on Android feel free to ask them on the android-midi group. Good luck and have fun!