B4J Question JavaxMidi-B4xLib for B4j

Luca1967

Active Member
Hi,

I am trying to use this nice library but I am having problems
1) I can't read the instruments in the tracks
2) I can't mute a channel
3) Are there any explanations or examples online? If so, where can I get them?
Thank you
 

stevel05

Expert
Licensed User
Longtime User
Not with MidiSystemStatic.GetSequence, but download the latest library and you can use either of these.

B4X:
Seq = MidiSystemStatic.GetSequence3(File.GetUri(File.DirAssets,FileName))
Seqr.SetSequence2(Seq)

Or

B4X:
Dim Inp As InputStream = File.OpenInput(File.DirAssets,FileName)
Seq = MidiSystemStatic.GetSequence2(Inp)
Seqr.SetSequence2(Seq)

I have only modified MidiSystemStatic GetSequence2 and GetSequence3 if you still have the library modules in your project you can copy and replace just those subs.
 
Last edited:
Upvote 0

Luca1967

Active Member
Not with MidiSystemStatic.GetSequence, but download the latest library and you can use either of these.

B4X:
Seq = MidiSystemStatic.GetSequence3(File.GetUri(File.DirAssets,FileName))
Seqr.SetSequence2(Seq)

Or

B4X:
Dim Inp As InputStream = File.OpenInput(File.DirAssets,FileName)
Seq = MidiSystemStatic.GetSequence2(Inp)
Seqr.SetSequence2(Seq)

I have only modified MidiSystemStatic GetSequence2 and GetSequence3 if you just want to copy those subs.
Thanks
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
you should also fix the "getformat"
Do you mean MidiSystemStatic.GetMidiFileFormat?

GetMidiFileFormat2 is working, It works from a directory on the disk. but it can't read files from the Assets folder either, it appears it may require write permissions the Assets directory is read only. See the documentation here: https://docs.oracle.com/javase/8/do...m.html#getMidiFileFormat-java.io.InputStream-:

GetMidiFileFormat3 is fixed for the next release and works with the Assets directory, if you want to drop it in the code is here:

B4X:
'Obtains the MIDI file format of the data in the specified URL.
'Pass a FileUri obtained with File.GetUri(Dir, FileName)
Public Sub GetMidiFileFormat3(Url As String) As MidiFileFormat
    Dim MidiSystem1 As JavaObject
    MidiSystem1.InitializeStatic("javax.sound.midi.MidiSystem")
    Dim jURL As JavaObject
    jURL.InitializeNewInstance("java.net.URL",Array(Url))
    Dim Wrapper As MidiFileFormat
    Wrapper.Initialize
    Wrapper.SetObject(MidiSystem1.RunMethod("getMidiFileFormat",Array As Object(jURL)))
    Return Wrapper
End Sub

Pass a FileUri obtained with File.GetUri(Dir, FileName)
 
Last edited:
Upvote 0

drponciano

Member
Licensed User
Longtime User
Do you mean MidiSystemStatic.GetMidiFileFormat?

GetMidiFileFormat2 is working, It works from a directory on the disk. but it can't read files from the Assets folder either, it appears it may require write permissions the Assets directory is read only. See the documentation here: https://docs.oracle.com/javase/8/do...m.html#getMidiFileFormat-java.io.InputStream-:

GetMidiFileFormat3 is fixed for the next release and works with the Assets directory, if you want to drop it in the code is here:

B4X:
'Obtains the MIDI file format of the data in the specified URL.
'Pass a FileUri obtained with File.GetUri(Dir, FileName)
Public Sub GetMidiFileFormat3(Url As String) As MidiFileFormat
    Dim MidiSystem1 As JavaObject
    MidiSystem1.InitializeStatic("javax.sound.midi.MidiSystem")
    Dim jURL As JavaObject
    jURL.InitializeNewInstance("java.net.URL",Array(Url))
    Dim Wrapper As MidiFileFormat
    Wrapper.Initialize
    Wrapper.SetObject(MidiSystem1.RunMethod("getMidiFileFormat",Array As Object(jURL)))
    Return Wrapper
End Sub

Pass a FileUri obtained with File.GetUri(Dir, FileName)
Hello, I just upgraded to B4J 10.0 but my program does not work any more. I get the following error when:

Antes de iniciar Midi
midi_gm._add (java line: 544)
java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextNode(Unknown Source)
at java.util.LinkedHashMap$LinkedKeyIterator.next(Unknown Source)
during
Log("Antes de iniciar Midi")
' Buscamos los dispositivos que están conectados.
MidiSystemStatic.Initialize
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I'm not at my computer until tomorrow but can you post your project or the code that causes this issue? I will have a look at it then.
 
Upvote 0
Top