am I asking you too much?
The library is a wrapper for the JavaxMidi library and reflects the complexity of the midi specification, which can take time to get your head around.
It would be a lot of work to build a project / layout to demonstrate these requirements as you would need to be able to select a track to mute, and select an instrument from a list of some sort and specify where in the track the program change is to occur.
Assuming you have the midi file playing through the sequencer object the process of muting tracks is simple:
- Identify the track you want to mute and get it from the sequence.
- Call Sequencer SetTrackMute(Track,Mute) Where Mute is a boolean value.
Changing the instrument is a little trickier as you would need to make sure that the only program change messages in the track are the ones you want, so it would depend on what is already in the midi file. It is not uncommon for files to change instruments during the sequence, so there are a lot of variables depending on what you want to achieve.
The simplest way would be to loop through all of the events in a track and identify and remove any program change events using Track.Remove(Evt), then insert the one you want at the beginning if you are sure that you don't want it to change half way through.
You can use this sub to check if the MidiEvent is a Program Change:
Private Sub IsProgramChange(evt As MidiEvent) As Boolean
If evt.GetMessage.IsShortMessage Then
If evt.GetMessage.AsShortMessage.GetCommand = MidiStatus.PROGRAM_CHANGE Then Return True
End If
Return False
End Sub
Use MidiMessageBuilder.ProgramChange method to create a new program change message. And:
Dim PCEvt as MidiEvent
PCEvt.Initialize
PCEvt.CreateShort(ProgramChangeMsg, Tick)
To create the event, then add it to the track.
Where Tick is the location in the track so right at the beginning would be 0.
Midi is a complex beast, which is why good midi sequencers cost an arm and a leg when they were first introduced.
The xml file in the Library thread contains the documentation for the library which you can view with one of the document viewers available on the forum. Alternatively you can unzip the b4xlib and look through the code if you prefer that.