Android MIDI sequencer with Processing interface


#1

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

Thanks!


#2

@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


#3

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


#4

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


#5

@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!

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");
  }
}

#6

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


#7

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


#8

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


#9

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.

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);
}
}


#10

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


#11

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.


#12

@sensn

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


#15

@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
https://play.google.com/store/apps/details?id=com.mobileer.midikeyboard
https://play.google.com/store/apps/details?id=com.mobileer.example.midiscope

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


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() {
}

#16

Ok… :smiley: 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


#17

Nice. @chanof if you read through 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.


#18

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:

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


#19

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.


#20

@chanof @sensn

I’m working on it …!


#21

@chanof @sensn

ok …
at the top of your sketch add


import android.os.Handler ;
import android.os.Looper ;

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


     //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

#22

Great!

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