# Android MIDI sequencer with Processing interface

**URL:** <https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500>\
**Category:** Processing for Android\
**Created:** [July 4, 2018, 4:34pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500 "2018-07-04T16:34:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![chanof](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chanof](https://discourse.processing.org/u/chanof)\
**Post date:** [July 4, 2018, 4:34pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/1 "2018-07-04T16:34:54Z")

</div>

I’m developing a MIDI sequencer for Android devices, to create the graphic interface I obtained excellent results using the Processing framework inside Android Studio.

Currently the sequencer is set up to control 16 steps for 16 channels and is designed to generate polyrhythm by reducing the number of steps for each channel.

In the future I want to implement it with different generative algorithms to generate variations of the patterns.

There are 8 patterns that can be interchanged every 4 beats. At the beginning I was trying to complete the project exclusively with Processing, but the lack of a compatible MIDI library (midibus) inside of Processing forced me to rewrite the project within Android Studio.

Unfortunately, my skills do not allow me to implement the MIDI output port in Android Studio as described by Android.media.midi. I also hear about a c ++ framework: superpowered that would probably make the application even more professional with less latency.

If there is the possibility of continuing the project on processing please say me.

I am looking for a partner who is interested in the project and who can enter the project to help me complete it and from which I can learn what it takes to interface with a MIDI device via android.

I can propose and expect code highly commented to arrive at the result, probably the best place for this project is github but it is not essential, I can share my entire work of which I show this screen shot of the current responsive interface.

is anyone interested?

![36660502_10205150949690664_4201923344997548032_n](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/759690a5bfa74d28aa3938e6a42f533f5a574501.jpg)

Thanks!

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 4, 2018, 5:23pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/2 "2018-07-04T17:23:33Z")

</div>

@chanof  
I have also written a sequencer using Processing but as yet don’t have midi … I hope to do it soon so I could be interested in collaborating …

I am thinking though of writing my own code to make use of the Android sdk … no libraries as they seem to get out of date too quickly when Processing gets updated

---

<div class="post-metadata">

**Author:** ![chanof](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chanof](https://discourse.processing.org/u/chanof)\
**Post date:** [July 4, 2018, 5:46pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/3 "2018-07-04T17:46:25Z")

</div>

Hi shedMusic! do you mean midi processing library? I never found anyone who is compatible inside android, by moving to android studio i think android.media.midi is the right way, i hope that is possible to crate a condition like if the button is on and is blinking (the play point is on it) send a midi noteOn, however I’m unable to cross from native processing code to this API.  
my e-mail is [chanof@hotmail.com](mailto:chanof@hotmail.com)

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 4, 2018, 6:05pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/4 "2018-07-04T18:05:31Z")

</div>

Hi @chanof

no libraries…

I intend to see about using android.media.midi from within Processing. I’m also looking at maybe trying to do a video wrapper too.

Might take me a while but I’ll post here with some thoughts in the next couple of days

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 4, 2018, 8:24pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/5 "2018-07-04T20:24:36Z")

</div>

@chanof

Just a very brief start to show you how I’m getting started … just a quick test to see how to go about importing android.media.midi, and a simple test that the phone/tablet supports MIDI.

More tomorrow … need to get an OTG cable to plug something in!

```auto
import android.app.Activity;
import android.content.Context;
import android.media.midi.* ;
import android.content.pm.PackageManager ;

Activity act;
Context context;
MidiManager m ;

void setup() {
  act = this.getActivity();
  context = act.getApplicationContext();
  m = (MidiManager)context.getSystemService(Context.MIDI_SERVICE);
  //check device supports MIDI
  if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
    // Phone.tablet supports MIDI
    println("great .... can do midi things");
  } else {
    println("boo .... no midi possible");
  }
}

```

---

<div class="post-metadata">

**Author:** ![chanof](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chanof](https://discourse.processing.org/u/chanof)\
**Post date:** [July 4, 2018, 8:55pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/6 "2018-07-04T20:55:11Z")

</div>

Wow! seems you are importing android.media.midi lib inside Processing IDE. Great start mate!

---

<div class="post-metadata">

**Author:** ![chanof](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chanof](https://discourse.processing.org/u/chanof)\
**Post date:** [July 4, 2018, 9:18pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/7 "2018-07-04T21:18:09Z")

</div>

I commenting my code to post it as soon as possible!

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 5, 2018, 6:39am UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/8 "2018-07-05T06:39:51Z")

</div>

Yes it’s in Processing IDE … it’s a matter of reading the android sdk docs and trying things out a bit at a time. I’m expecting this to take a while yet! Might be a bit soon to start looking at your code, but still post it if you want to

---

<div class="post-metadata">

**Author:** ![sensn](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@sensn](https://discourse.processing.org/u/sensn)\
**Post date:** [July 5, 2018, 10:35am UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/9 "2018-07-05T10:35:38Z")

</div>

Great.

I added ‘m.getDevices()’ to shedMusics code. Now it prints available Midi devices.  
That was easy. But I can’t figure out how to open a device. Hopefully shedMusic can do it.

```auto
import android.app.Activity;
import android.content.Context;
import android.media.midi.* ;
import android.content.pm.PackageManager ;

Activity act;
Context context;
MidiManager m ;
MidiDeviceInfo[] infos;
  

String s = "MIDI supported";
String z = "MIDI not supported ";
void setup() {
act = this.getActivity();
context = act.getApplicationContext();
m = (MidiManager)context.getSystemService(Context.MIDI_SERVICE);
//check device supports MIDI
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
// Phone.tablet supports MIDI
println (s);
infos = m.getDevices();
println (infos); // list of all the available MIDI devices
  } else {
print (z);
}
}

```

---

<div class="post-metadata">

**Author:** ![chanof](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chanof](https://discourse.processing.org/u/chanof)\
**Post date:** [July 5, 2018, 1:46pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/10 "2018-07-05T13:46:42Z")

</div>

Thanks @sensn seems to be hope! This feature could allow hundreds of professional musical applications developed directly in processing. Thanks for yours works!

---

<div class="post-metadata">

**Author:** ![sensn](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@sensn](https://discourse.processing.org/u/sensn)\
**Post date:** [July 5, 2018, 2:13pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/11 "2018-07-05T14:13:39Z")

</div>

Hi,  
I just kept on trying to open a device, but we really have to hope for @shedMusic to share his work on this. My knowledge is way to little to do it. So please Mr. shedMusic if you make your work available this would be really great for artists with little coding know-how.

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 5, 2018, 2:26pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/12 "2018-07-05T14:26:38Z")

</div>

@sensn

The plan is to make it work! I will post again as soon as I have made even just a little more progress 😀

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 5, 2018, 8:43pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/15 "2018-07-05T20:43:37Z")

</div>

@chanof @sensn

No external hardware yet , but this works if you have a virtual midi device installed such as

> <https://play.google.com/store/apps/details?id=net.volcanomobile.fluidsynthmidi>
>
> Turn your device into a FluidSynth synthesizer...

> <https://play.google.com/store/apps/details?id=com.mobileer.midikeyboard>
>
> On-screen keyboard that sends MIDI messages to other devices or apps...

> <https://play.google.com/store/apps/details?id=com.mobileer.example.midiscope>
>
> Display MIDI messages on screen. Uses new Android MIDI API...

I am going to play with these before trying any external keyboards etc, but the learning will be the same … 🙂

> ```java
> 
> import android.app.Activity;
> import android.content.Context;
> import android.os.Bundle ;
> import android.media.midi.* ;
> import android.content.pm.PackageManager ;
> 
> Activity act;
> Context context;
> MidiManager m ;
> 
> void setup() {
> act = this.getActivity();
> context = act.getApplicationContext();
> m = (MidiManager)context.getSystemService(Context.MIDI_SERVICE);
> //check device supports MIDI
> if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
> // Phone.tablet supports MIDI
> println("great .... can do midi things");
> //search for attached devices
> MidiDeviceInfo[] deviceInfo = m.getDevices();
> if (deviceInfo.length == 0) {
> println("No MIDI devices found .. " + deviceInfo.length);
> } else {
> println("Num MIDI Devices found = " + deviceInfo.length);
> Bundle properties ;
> for (int i=0; i<deviceInfo.length; i++) {
> println("Device " + i);
> println(" Num MIDI inputs = " + deviceInfo[i].getInputPortCount());
> println(" Num MIDI outputs = " + deviceInfo[i].getOutputPortCount());
> properties = deviceInfo[i].getProperties();
> println(" Manufacturer = " + properties.getString(MidiDeviceInfo.PROPERTY_MANUFACTURER)); 
> println(" Product =" + properties.getString(MidiDeviceInfo.PROPERTY_PRODUCT));
> println(" Name = " + properties.getString(MidiDeviceInfo.PROPERTY_NAME));
> println(" Serial Number = " + properties.getString(MidiDeviceInfo.PROPERTY_SERIAL_NUMBER));
> //Port Information
> MidiDeviceInfo.PortInfo[] portInfo = deviceInfo[i].getPorts();
> println(" Num ports found = " + portInfo.length);
> for (int j=0; j<portInfo.length; j++) {
> println(" port " + j + " Name = " + portInfo[j].getName() + "Type = " + portInfo[j].getType());
> }// end j loop
> println(""); // to give a blank space in the console
> }//end i loop
> }
> } else {
> println("boo .... no midi possible");
> }
> }
> 
> void draw() {
> }
> 
> ```

`
`

``

---

<div class="post-metadata">

**Author:** ![chanof](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chanof](https://discourse.processing.org/u/chanof)\
**Post date:** [July 5, 2018, 9:26pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/16 "2018-07-05T21:26:10Z")

</div>

Ok… 😃 i think i need too to order a usb to midi cable!  
Great work Mark @shedMusic !  
Are you going to add the parameters input, like noteOn noteOff (or note length), note, velocity, channel and CC ? Please!  
Thanks

---

<div class="post-metadata">

**Author:** ![sensn](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@sensn](https://discourse.processing.org/u/sensn)\
**Post date:** [July 6, 2018, 5:39am UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/17 "2018-07-06T05:39:56Z")

</div>

Nice. @chanof if you read through [https://developer.android.com/reference/android/media/midi/package-summary](https://developer.android.com/reference/android/media/midi/package-summary)  
you can see that the next step will be to open a device, which might be a bit tricky. Then we need to open a input port. Once @shedMusic gets this ready, I think it will be possible for us to get the note-on thing done from what is written in the docs.  
I do have an OTG-cable and a USB-MIDI interface that works, so i can help testing, once we are there.

---

<div class="post-metadata">

**Author:** ![chanof](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@chanof](https://discourse.processing.org/u/chanof)\
**Post date:** [July 6, 2018, 8:14am UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/18 "2018-07-06T08:14:37Z")

</div>

Thanks guys, I’m even happier if I can learn instead of copying. You need some patience with me :).  
For example:  
I think the next step after the posted code is to open the MIDI devices to which I want to send notes:

```auto
m.openDevice(info, new MidiManager.OnDeviceOpenedListener() {
    @Override
    public void onDeviceOpened(MidiDevice device) {
        if (device == null) {
            Log.e(TAG, "could not open device " + info);
        } else {
            ...
        }
    }, new Handler(Looper.getMainLooper())
    );

```

By copying this method i got an error: unexpected token

What i need to insert instead dots (…)?

Thanks

---

<div class="post-metadata">

**Author:** ![sensn](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@sensn](https://discourse.processing.org/u/sensn)\
**Post date:** [July 6, 2018, 9:37am UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/19 "2018-07-06T09:37:01Z")

</div>

Yeah, that’s what I tried yesterday. It’s not that easy. That code has to be rewritten to work inside the processing IDE. I guess shedMusic is working on it. So we’ll have to wait and see.

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 6, 2018, 11:25am UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/20 "2018-07-06T11:25:41Z")

</div>

@chanof @sensn

I’m working on it …!

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [July 6, 2018, 11:57am UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/21 "2018-07-06T11:57:29Z")

</div>

@chanof @sensn

ok …  
at the top of your sketch add

> ```java
> 
> import android.os.Handler ;
> import android.os.Looper ;
> 
> ```

after the line **}//end i loop** insert this code:

> ```java
> 
> //Try to open a device!
> //To get this bit to work, make sure you have imported android.os.Handler and android.os.Looper at the top of your sketch;
> //Still experimental at this stage but is working
> //I have used deviceInfo[0] here which for me (at least for now) is FluidSynth
> m.openDevice(deviceInfo[0], new MidiManager.OnDeviceOpenedListener() {
> @Override
> public void onDeviceOpened(MidiDevice device) {
> if (device == null) {
> println("could not open device");
> } else {
> println("device opened and ready for use");
> }
> }
> }
> , new Handler(Looper.getMainLooper())
> );
> //and that ends opening a device ... phew...!
> //next ... playing some notes ... I hope
> 
> ```

---

<div class="post-metadata">

**Author:** ![sensn](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@sensn](https://discourse.processing.org/u/sensn)\
**Post date:** [July 6, 2018, 12:20pm UTC](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500/22 "2018-07-06T12:20:29Z")

</div>

Great!

device opened and ready for use!  
If you can send some notes you should get the MIDI-Award of the year!😃

[Next page](https://discourse.processing.org/t/android-midi-sequencer-with-processing-interface/1500.md?page=2)
