B4A Library MidiSystem

OK, here is the culmination of many months of work, it is a port of a large part of the javax MidiSystem, written entirely in Basic4Android.

This Library gives access to a Midi file at the event/message level, you can create, load, play and save midi files and much more. It incorporates a USB manager module so you can attach external midi devices via USB and receive and send midi messages to the attached hardware. You can also create your own transmitter module and send midi data to the Sequencer as if it were a hardware device.

I have simplified some of the workings as Android devices do not provide as many in/out configurations as working on a PC.

The biggest problem remains audio latency especially when playing from a User module to the internal Midi module, using USB hardware provides better performance.

I will post some complete examples so you can see how the System works in the Example forum as there are a few of them. Most of the documentation for the Javax Midi System is relevant.

The library depends on these libraries which should be in your additional libs folder:

threading, javaobject, slbytearraybuffer, mididriver, usb, slstreams, nanotime, android-support-v4

if you don't already have it, android-support-v4 has to be downloaded using the Android SDK Manager. Add the extras/Android Support package, then copy the jar file from <SDK root folder>\extras\android\support\v4 to your addl libs folder.

This is a large library, although I have tested it as thoroughly as possible, I am sure there will be some bugs in there somewhere, please treat it as Beta software and test any app using it thoroughly yourself prior to release.

I have a reasonably fast (2013 Asus Nexus 7) which handles the workload very well, I can't guarantee that all devices will do the same. Please have a target in mind and test developed software on that. I would be surprised if anything over 3 years old would give acceptable performance. There could be as many a 5 threads (including the Gui thread) running at once if you are recording, so it could be a drain on resources for older / slower devices.

Updated to v1.01 as post#2
Update to V2 to allow newer android versions to access the midi driver. (You also need the mididriver2 Lib)
Update to V2.1 Added getShortMessageData3 To MidiMessage

MidiLibNew contains the B4a source code for the library.

Enjoy
 

Attachments

  • MidiLibNew.zip
    60.7 KB · Views: 231
  • MidiSystem2.zip
    125.6 KB · Views: 244
Last edited:

Michael Wenning

Member
Licensed User
Longtime User
Thank's Steve!

I have found a solution:

Class InstrumentList
Private mPno As Piano

Sub SendeProgramChange
Dim ProgrammChange As MidiEvent
Dim MMsg1 As MidiMessage

MMsg1.Initialize

' change to 5 ==> Electric Piano 2
MMsg1.setShortMessageWithStatus1(0xC0 , 0x05)

ProgrammChange.Initialize(MMsg1,0)
mPno.send(ProgrammChange)

End sub

class Piano:

Public Sub Send(MEvt As MidiEvent)
For Each MDi As MidiDeviceInfo In mMDI.Transmitter.Receivers
MDi.Receiver.Send(MEvt.Message.Message)
Next
If mSeqr.IsRecording Then MidiSequencerReceiver_Static.Send(MEvt.Message,-1)
End Sub

Best regards from Germany
Michael
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Updated in what way?
 

stevel05

Expert
Licensed User
Longtime User
I will put it on my list and take a look.
 

stevel05

Expert
Licensed User
Longtime User
Updated source code to latest version and added getShortMessageData3 To MidiMessage
 

stevel05

Expert
Licensed User
Longtime User
could you please let me know where I can finde the current version or "updated source code"?
Both are in the first post of this thread.
 

holgr

New Member
Hi Steve,

thank you very much! As a B4A newby, I wasn't Sure where to get the newest Version.

Cheers,
Holger
 

stari

Active Member
Licensed User
Longtime User
OK, here is the culmination of many months of work, it is a port of a large part of the javax MidiSystem, written entirely in Basic4Android.

This Library gives access to a Midi file at the event/message level, you can create, load, play and save midi files and much more. It incorporates a USB manager module so you can attach external midi devices via USB and receive and send midi messages to the attached hardware. You can also create your own transmitter module and send midi data to the Sequencer as if it were a hardware device.

I have simplified some of the workings as Android devices do not provide as many in/out configurations as working on a PC.

The biggest problem remains audio latency especially when playing from a User module to the internal Midi module, using USB hardware provides better performance.

I will post some complete examples so you can see how the System works in the Example forum as there are a few of them. Most of the documentation for the Javax Midi System is relevant.

The library depends on these libraries which should be in your additional libs folder:

threading, javaobject, slbytearraybuffer, mididriver, usb, slstreams, nanotime, android-support-v4

if you don't already have it, android-support-v4 has to be downloaded using the Android SDK Manager. Add the extras/Android Support package, then copy the jar file from <SDK root folder>\extras\android\support\v4 to your addl libs folder.

This is a large library, although I have tested it as thoroughly as possible, I am sure there will be some bugs in there somewhere, please treat it as Beta software and test any app using it thoroughly yourself prior to release.

I have a reasonably fast (2013 Asus Nexus 7) which handles the workload very well, I can't guarantee that all devices will do the same. Please have a target in mind and test developed software on that. I would be surprised if anything over 3 years old would give acceptable performance. There could be as many a 5 threads (including the Gui thread) running at once if you are recording, so it could be a drain on resources for older / slower devices.

Updated to v1.01 as post#2
Update to V2 to allow newer android versions to access the midi driver. (You also need the mididriver2 Lib)
Update to V2.1 Added getShortMessageData3 To MidiMessage

MidiLibNew contains the B4a source code for the library.

Enjoy
Hello stevel05.
I wish to try your Midi system, but i get error by compiling:
Linking resources Error
AndroidManifest.xml:33: error: resource xml/device_filter (aka com.stevel05.midilib:xml/device_filter) not found.
error: failed processing manifest.

I didn't change anything, but now I don't know what to do?

Greetings from Celje
 

stevel05

Expert
Licensed User
Longtime User
Have you downloaded the MidiDriver2 library linked in the first post?
 

GMan

Well-Known Member
Licensed User
Longtime User
And i got these errors in the IDE

[IDE message - 4:25:21]
Die folgenden Bibliotheken fehlen: (the following libs are missing)
nanotime
slbytearraybuffer
slstreams
threading
mididriver2
 

stevel05

Expert
Licensed User
Longtime User
And i got these errors in the IDE
These are libraries you would need to download to compile the source code to a library. Which you can if you want to. The source code was posted much later that the library for those interested, rather than to compile.

Download the library (midisystem2,zip) and the MidiDriver2 library linked in the first post. There are demos of it's use in other threads in the forum.
 

stari

Active Member
Licensed User
Longtime User
Have you downloaded the MidiDriver2 library linked in the first post?
Yes, i have downloaded all necessary libs. And i still get:
Linking resources Error
AndroidManifest.xml:33: error: resource xml/device_filter (aka com.stevel05.midilib:xml/device_filter) not found.
error: failed processing manifest.

Hm,......I can't solve it !!
 

stevel05

Expert
Licensed User
Longtime User
Have you downloaded the library or the project?
 

stevel05

Expert
Licensed User
Longtime User
But are you trying the library? See post#33
 

kimstudio

Active Member
Licensed User
Longtime User
Hi steve, I'd like to consult you on the update of Android midi system, does Android support play midi directly like Windows without using another midi to wav to play now? It seems it is a midi event dispatching system and to play the note we need another soundfont or synth module to play?
 

stevel05

Expert
Licensed User
Longtime User
Hi, yes it should play using the mididriver2 Lib unless something has changed in Android recently to stop it.
 
Top