You can get the track name directly from the track Class. you could get the instrument name from the Program change events contained in the track if the instrument is a General Midi instrument, alternatively instrument names may or may not be stored in the meta data of the track as a MidiMetaMessage. There is a GetInstrumentName method in the Track class to help with that.
You can mute a track using the MidiSequencer SetTrackMute method.
The only example I have written is provided in the library post, which demonstrates loading, playing and getting the track name, selecting a track from the list of tracks and looping all of the events in a track.
The B4j library is a wrapper for the javax midi library, so you should be able to convert any java examples you may find on the internet without too much effort.
Dim Soundfont As MidiSoundbank = MidiSystemStatic.GetSoundbank("Path-to-soundfont-file","soundfontfile.sf2")
Dim Synth As MidiSynthesizer = MidiSystemStatic.GetSynthesizer
Synth.Open
Synth.LoadAllInstruments(Soundfont)
Seqr = MidiSystemStatic.GetSequencer2(False) 'Do not connect to default device.
Seqr.Open
Seqr.GetTransmitter.SetReceiver(Synth.GetReceiver)
Seqr.AddMetaEventListener(Me,"Meta")
Private Sub Meta_MetaEvent(Msg As MidiMetaMessage)
' Do what you need with the messages when they arrive.
Log(Msg.ToString)
End Sub
Thanks. It's Ok.Add this line after the sequencer is opened. (assuming your sequencer object is called Seqr)
B4X:Seqr.AddMetaEventListener(Me,"Meta")
Then add a sub to handle the messages with a name prefix matching the Eventname passed above, in this case "Meta":
B4X:Private Sub Meta_MetaEvent(Msg As MidiMetaMessage) ' Do what you need with the messages when they arrive. Log(Msg.ToString) End Sub
No timer required.
This is the expected behaviour, it is much better to work with type 1 midi files where each track is separate. While it is possible for any track to contain lyrics, it is better for the lyrics to be on a separate track for this reason.I have a midi file with only one track but which contains all the information.
SetTrackMute and SetTrackSolo
You write : "You could pre-process the file and separate the tracks as required on load."
GrazieEcco un esempio di conversione di una traccia midi dal tipo 0 (1 traccia) al tipo 1 tracce multiple.Non c'è alcuna convalida che si tratti effettivamente di un Midi File di tipo 0. Questo può essere fatto usando il metodo MidiSystemStatic.GetFileFormat.GetType_.Aggiunto al progetto zip
Sarà necessario modificare le posizioni di input e output del file nel modulo principale.
Thanks. You're great.Here is an example of converting a midi track from type 0 (1 track) to type 1 multiple tracks.There is no validation that it is actually a type 0 Midi File. That can be done using MidiSystemStatic.GetFileFormat.GetType_ method.Added to project zip
You will need to change the file Input and output locations in the Main Module.