Hi Steve, sorry for delay on reply but I had not time to work with the project.
Today I've tried it and this worked, the java code is as last post, on B4J I Initialize this way:
Midi.Initialize2(MainForm.RootPane, "Midi", -1, -1, "myMidiBus") ' Initialize one midi bus whithout open input and open devices. Assign an event callback and a bus name just for reference.
By commenting the Midi.Close on MainForm_CloseRequest and MainForm_Closed
Sub MainForm_Closed
Log(">>>>>> MainForm_Closed")
Log("BYE")
End Sub
Sub MainForm_CloseRequest (EventData As Event)
' Midi.Close
Log(">>>>>> MainForm_CloseRequest")
End Sub
.... when I close the B4J app with X on top-right of form the java function is correctly called and automatically closes all opened midi in and out port if any, this is the log I receive:
Form focus: true
--- Close All Devices ---
MidiBus: Closing All Midi Devices
MidiBus: Done
Form focus: false
>>>>>> MainForm_Closed
BYE
..... but as you said it completely do not call MainForm_CloseRequest, this is a problem because if here there are other code to close other stuffs this is not called at all.
Now I will try it, maybe when MainForm_Close fires I can put a call inside it to call MainForm_CloseRequest to just execute the code on the end. I'm not sure if it works.... I will try it now... but is not too good way to work with....
Another issue is that I placed on the form an EXIT button, when pressed it just call ExitApplication, when this is called the application exit without call a java function, so midi ports are not closed.
Here need to know what really B4X do, seem the ports already closed when the class instance dead, personally I never had problems to open midi ports not well closed, I had this type of problems with sockets but not midi, probably it already automatically closes all ports.