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
Which java version are you using?
 
Upvote 0

Luca1967

Active Member
Which java version are you using?
if I compile with java8 everything is fine.
But now I have another problem.
If I compile the program in Jar I get the error you see.
I had to use ISO-8859-16 to show the words with the accent, otherwise utf-8 puts me a wrong character.
If I launch the program from inside B4J it works, but when I compile and launch the Jar it crashes and the error is what you see.
How can I do?
 

Attachments

  • Cattura.JPG
    Cattura.JPG
    130 KB · Views: 170
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you changed the code in Midievent.ToString?

Although it is asking for a characterset, it is not using it. There is a bug. If you change the references of UTF-8 to ChrSet does it help?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The JDK for Java 9+ does not include the JRE, you need to create a package to run the application.

Capture the Next MetaMessage event, is possible?
No, you will need to create a list or map of the events from the track if you want to do this and manage it yourself.
 
Upvote 0

Luca1967

Active Member
Have you changed the code in Midievent.ToString?

Although it is asking for a characterset, it is not using it. There is a bug. If you change the references of UTF-8 to ChrSet does it help?
Yes.
Data(6) = eMsg.AsMidiMetaMessage.GetMetaText("ISO-8859-16")

If I use UTF-8 it doesn't show me accented characters.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I had to use ISO-8859-16 to show the words with the accent, otherwise utf-8 puts me a wrong character.
Now I have fixed the bug, the app crashes within the IDE, it appears that ISO-8859-16 is not supported by java. Try a different encoding.

I will release the fixed library shortly. You will need to copy the following classes to your project if you are not using the library:

MidiTrack
MidiEventBuilder
MidiEventStatic
MidiEvent
MidiMessageBuilder
MidiMetaMessage

And add the ChrSet to the calls to the relevant methods, this will be obvious in the log.
 
Upvote 0

Luca1967

Active Member
Now I have fixed the bug, the app crashes within the IDE, it appears that ISO-8859-16 is not supported by java. Try a different encoding.

I will release the fixed library shortly. You will need to copy the following classes to your project if you are not using the library:

MidiTrack
MidiEventBuilder
MidiEventStatic
MidiEvent
MidiMessageBuilder
MidiMetaMessage

And add the ChrSet to the calls to the relevant methods, this will be obvious in the log.

You write : "And add the ChrSet to the calls to the relevant methods, this will be obvious in the log."

how can I do . I have never used the chrset.
Thank you
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
No, you will need to create a list or map of the events from the track if you want to do this and manage it yourself.

Make a thread based timer to manage ticks in milliseconds to dispatch events to midi receiver?

steve, I am trying to make a midi sequencer (just use Windows internal midi to playback) and I found the simple chord example you shared doesn't compile. I tried clone receiver code in that example and it also doesn't work. Now I am using sequencer but during playing any parameter changes in real-time like bpm or event I will have to stop the sequencer, regenerate the midi sequence and play again. Any advice? Thanks.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You said you tried ISO-8859-16, This was generally ignored because of the bug. The fix is to allow the character set to be specified when a text event is required to be read. Unfortunately it appears that ISO-8859-16 is not supported by the java encoding methods.

The encoding used in the midifile should be specified at the beginning of the Lyric track, you'll have to read the midi spec to find the specifics.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
steve, I am trying to make a midi sequencer (just use Windows internal midi to playback) and I found the simple chord example you shared doesn't compile. I tried clone receiver code in that example and it also doesn't work. Now I am using sequencer but during playing any parameter changes in real-time like bpm or event I will have to stop the sequencer, regenerate the midi sequence and play again. Any advice? Thanks.
Can you start a new thread for this issue so that this one doesn't become a spaghetti thread. It's easier to follow issues in their own thread. I will look at the old simple chord app, thanks for reporting that.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
ISO-8859-16
A bit more investigation and apparently ISO-8859-16 is supported in java 10+, I tried compiling with java 11 and it doesn't crash. I can't tell if it's working correctly as I don't have a midi file encoded using it. You will then need to create a package to run it stand alone.
 
Upvote 0

Luca1967

Active Member
Hi Stevel,
I have finished the first release of the karaoke software made with your library and your precious help and advice.
I would love to hear from you, although I know there are many things still to be done.
The program is bigger than 1 MB and it doesn't let me post it (JAR).
I would have liked to have your opinion.
If I can get it to you somehow just tell me.
Thank you.
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Hi Luca, could you send me the jar by email kimstudio@163.com if convenient as I can't access googledrive or dropbox. I am interested in midi and would like to try your work, thanks.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It's looking good, although it doesn't load all of my midi files. I have very few with lyrics so cant test much of that.
 
Upvote 0

Luca1967

Active Member
It's looking good, although it doesn't load all of my midi files. I have very few with lyrics so cant test much of that.
Thank you, it's nice to hear from you.
I tried with several midi files (0 and 1) Kar and Mid, and I fixed some problems (not all files are done correctly).
There are still some problems to solve, and I'll solve them in time, maybe I'll bother you again, if it doesn't bother you.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Replace the MidiData_Event sub in the MidiTransmitter Class with:

B4X:
Private Sub MidiData_Event (MethodName As String, Args() As Object)
    Dim Msg As MidiMessage
    Msg.Initialize
    Msg.SetObject(Args(0))
    For Each LT As MidiListenerClass In ListenerMap.Keys
        CallSub3(LT.Callback,LT.EventName & "_Received",Msg,Args(1))
    Next
End Sub

Create a listener on the Sequencer Transmitter after the sequencer is opened:

B4X:
Seqr.GetTransmitter.AddListener(Me,"Trans")

Add this sub in the module that the listener is created in:

B4X:
Private Sub Trans_Received(Msg As MidiMessage, TimeStamp As Long)
    If Msg.IsShortMessage Then
        Dim SM As MidiShortMessage = Msg.AsShortMessage
        If SM.GetCommand = MidiStatus.NOTE_ON Or SM.GetCommand = MidiStatus.NOTE_OFF Then
            Log(SM.GetCommand & " : " & SM.GetChannel & " : " & SM.GetData1 & " : " & SM.GetData2)
        End If
    End If
End Sub

I have updated the library.
 
Last edited:
Upvote 0
Top