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
 

Luca1967

Active Member
Hi Stevel.

The software starts running.
But I have some questions left for you.
1) I tried with your Sub in Midiutils to do the transpose, but it gives an error.
I then used the synth with the SetPitchBend, but it doesn't work great. Do you know which values are passed for the various semitones?
2) In the Meta Meta_Event how can I retrieve the ticks? I need them for the correct synchronization of the text.If I try to do this by retrieving them from the sequencer, the whole base is slowed down.
Thanks
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
What error do you get using the transpose function?

For pitchbend values see the midi spec Or : https://sites.uci.edu/camp2014/2014/04/30/managing-midi-pitchbend-messages/#:~:text=The MIDI protocol specifies that,16,383 means maximum upward bend. The relationship between the pitchbend value and the number of semitone or cents is I believe dependent on the synthesizers implementation.

2) In the Meta Meta_Event how can I retrieve the ticks?
Good question, the meta message doesn't contain a reference to the tick of it's related event or the event itself. I would suggest that you try building a list of all metaevents in the target track and increment a pointer with each metamessage received to the appropriate item in the list. You could create a custom type to hold additional information such as the tick value or if the message is actually a text or lyric message or both if necessary as you need it

the whole base is slowed down

Were you running in Debug mode?
 
Last edited:
Upvote 0

Luca1967

Active Member
What error do you get using the transpose function?

For pitchbend values see the midi spec Or : https://sites.uci.edu/camp2014/2014/04/30/managing-midi-pitchbend-messages/#:~:text=The MIDI protocol specifies that,16,383 means maximum upward bend. The relationship between the pitchbend value and the number of semitone or cents is I believe dependent on the synthesizers implementation.


Good question, the meta message doesn't contain a reference to the tick of it's related event or the event itself. I would suggest that you try building a list of all metaevents in the target track and increment a pointer with each metamessage received to the appropriate item in the list. You could create a custom type to hold additional information such as the tick value or if the message is actually a text or lyric message or both if necessary as you need it



Were you running in Debug mode?
 
Upvote 0

Luca1967

Active Member
1) If I transpose all tracks (except 10) the sounds overlap and there is only noise.

Dim Var As Int
Var = Tonalita.Formatter.Format(Tonalita.SelectedValue)
Dim Track As MidiTrack
Dim i As Int
Dim v1 As Int
Dim Chnls() As MidiChannel = Synth.GetChannels

If Var >0 Then v1= 1
If Var <0 Then v1 =-1

For i = 0 To 8
Chnls(i).ResetAllControllers
Track = Seq.GetTracks(i)
MidiUtils.TransposeTrack(Track,v1)
Next
For i = 10 To 15
Chnls(i).ResetAllControllers
Track = Seq.GetTracks(i)
MidiUtils.TransposeTrack(Track,v1)
Next
End Sub

2) In vanbasco the transpose ranges from -12 to +12.
If I consider 8192 (midi specifications) the 0 (zero) 8192 the -12 and 16383 the +12 it means that I have to increase or decrease by 682 every semitone.

3) Yes. Debug Mode.
4) If I put in the METAEVENT I connect the slider I put on the screen with Seqr.GetTickPosition the whole base feels bad. Slows.
If I use a timer, it's even worse.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try running you test in release mode.
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
2) In vanbasco the transpose ranges from -12 to +12.
If I consider 8192 (midi specifications) the 0 (zero) 8192 the -12 and 16383 the +12 it means that I have to increase or decrease by 682 every semitone.

Where is this 8192 coming from? If I understand correctly 1 means a semitone in midi note, so from key C to D just add 2 to each note, +12 one octave higher. Correct me if I am wrong.
 
Upvote 0

Luca1967

Active Member
Da dove viene questo 8192? Se ho capito bene 1 significa un semitono in nota midi, quindi dalla chiave C a D basta aggiungere 2 a ciascuna nota, +12 un'ottava più alta. Correggimi se sbaglio.

Where is this 8192 coming from? If I understand correctly 1 means a semitone in midi note, so from key C to D just add 2 to each note, +12 one octave higher. Correct me if I am wrong.

Even in the standard midi specification it is explained in this way.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
2) In vanbasco the transpose ranges from -12 to +12.
If I consider 8192 (midi specifications) the 0 (zero) 8192 the -12 and 16383 the +12 it means that I have to increase or decrease by 682 every semitone.
You shouldn't use pitchbend to transpose a track, the result will be dependant on how the synthesizer handles the pitch bend and is likely to be different on different synths.

It is not possible to know the channel until you are reading the messages on each track (unless you have already captured it by parsing the file), the attached project has an amended TransposeTrack2 method (in main) that allows channels to be excluded (primarily for drum tracks). To work correctly and not leave hanging notes, the Synth object has to be available, so if you use the internal synth it will need to be initialized as in post #34. The AllnotesOff message is sent to all channels.

I've added a transpose B4xCombobox to the layout next to the Solo4 button.
 

Attachments

  • stevel-2.zip
    56.3 KB · Views: 148
Last edited:
Upvote 0

Luca1967

Active Member
Thanks.
if i connect midi out the sound is wrong...double sound, and the solo and mute not function.

this is my routine for connect midi out

It's correct?
Thanks

Dim Md() As MidiDeviceInfo= MidiSystemStatic.GetMidiDeviceInfo
Dim MidiDev As MidiDevice
MidiDev = MidiSystemStatic.GetMidiDevice(Md(ChoiceDevice.SelectedIndex))
MidiDev.Open
Dim midioutrec As MidiReceiver = MidiDev.GetReceiver
Dim Seqr As MidiSequencer = MidiSystemStatic.GetSequencer

Seqr.GetTransmitter.SetReceiver(midioutrec)
Seqr.Open
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Difficult to tell what is going on without seeing the whole code, it sounds like you may have two devices attached. Can you post the current project?
 
Upvote 0

Luca1967

Active Member
Another questions.

If I try to compile the program this error appears.
Do you have any idea why?
 

Attachments

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

stevel05

Expert
Licensed User
Longtime User
OK, the first thing is to understand the javaxmidi library a little better.

The synth as returned by MidiSystemStatic.GetSynthesizer is the default synthesizer for the system and can be controlled using the Synth object and is provided as a quick way to access the internal sound generator and/or for loading soundfonts.

If you are using midi devices, it is simpler to manage the mute and solo at a track level as opposed to channel level, I have modified the attached project to do that and it still works with the soundfonts.

You were getting 2 devices as your code in SelezionaMidiOut used MidiSystemStatic.GetSequencer as opposed to MidiSystemStatic.GetSequencer2(False) which attached the default synthesizer as well as the selected midi out device. I also added code to that method to disable any existing transmitters and receivers before assigning a new device.

SelezionaMidiOut is called by If ChoiceDevice.Items.Size > 0 Then ChoiceDevice.SelectedIndex = 0 at line 764 which is why the device is selected as opposed to the internal synth when the app starts.

I have also amended Variatono method to send AllnotesOff to the MidiDevice or the synth as required so that the transpose still works as expected.
 

Attachments

  • SLTest2.zip
    57.3 KB · Views: 129
Upvote 0

Luca1967

Active Member
OK, la prima cosa è capire un po' meglio la libreria javaxmidi.

Il sintetizzatore restituito da MidiSystemStatic.GetSynthesizer è il sintetizzatore predefinito per il sistema e può essere controllato utilizzando l'oggetto Synth e viene fornito come un modo rapido per accedere al generatore di suoni interno e/o per caricare i soundfont.

Se stai usando dispositivi midi, è più semplice gestire il mute e l'assolo a livello di traccia anziché a livello di canale, ho modificato il progetto allegato per farlo e funziona ancora con i soundfont.

Stavi ricevendo 2 dispositivi poiché il tuo codice in SelezionaMidiOut utilizzava MidiSystemStatic.GetSequencer invece di MidiSystemStatic.GetSequencer2(False) che collegava il sintetizzatore predefinito e il dispositivo midi out selezionato. Ho anche aggiunto il codice a quel metodo per disabilitare tutti i trasmettitori e ricevitori esistenti prima di assegnare un nuovo dispositivo.

SelezionaMidiOut viene chiamato da If ChoiceDevice.Items.Size > 0 Then ChoiceDevice.SelectedIndex = 0 alla riga 764 motivo per cui il dispositivo viene selezionato al posto del synth interno all'avvio dell'app.

Ho anche modificato il metodo Variatono per inviare AllnotesOff al MidiDevice o al sintetizzatore come richiesto in modo che la trasposizione funzioni ancora come previsto.
tAHNK
 
Upvote 0

Luca1967

Active Member
If you use the sequencer for mute and solo, instead of sinth, the transmission of the META_EVENT is blocked.
For this I used the midichannel.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
But i now select a change strument, the software goes into error.
Which is why I explained the change to the Variotono method, you need to do something similar for the program change if the synth object is not initialized.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
META_EVENT is blocked
When the instrument is changed a new sequencer object is obtained, you need to add the listener again:

B4X:
private Sub SelezionaMidiOut ' Per cambiare il midi out
   
    If Seqr.IsInitialized Then Seqr.Stop
   
    ResetDevices
   
    Dim Md() As MidiDeviceInfo= MidiSystemStatic.GetMidiDeviceInfo
   
    MidiDev = MidiSystemStatic.GetMidiDevice(Md(ChoiceDevice.SelectedIndex))
    MidiDev.Open
    Dim midioutrec As MidiReceiver = MidiDev.GetReceiver
    Dim Seqr As MidiSequencer = MidiSystemStatic.GetSequencer2(False)
   
    Seqr.GetTransmitter.SetReceiver(midioutrec)
    Seqr.Open
   
    Seqr.AddMetaEventListener(Me,"Meta")   'Add the meta listener to the new sequencer instance.

    If Seq.IsInitialized Then Seqr.SetSequence2(Seq)
   

End Sub
 
Upvote 0
Top