You load an existing MIDI file into RAM, or create an empty MIDI file in RAM, by calling MIDIOpenFile() once.
If creating an empty MIDI file, then that means that you're creating a MIDI file in RAM without any events or tracks yet in it. You will subsequently add tracks/events with MIDISetEvent().
After successfully loading/creating a file in RAM, you may call numerous other functions to enumerate the MIDI events in the file, add/modify/delete events in tracks, add/delete tracks, and perform other operations.
When I say "enumerate", I mean "stepping through" the events in the file one at a time. You do not have simultaneous access to all events in the file. Instead, you have access to only 1 event at any given time, and must call MIDIGetEvent() each time that you need to access a different event. RxMIDI sort of manages the entire MIDI file in RAM on your behalf. Your script merely accesses the events one at a time to edit or perform some operation for each one, and gives RxMIDI overall instructions on what to do with the MIDI file. In this way, RxMIDI can perform reasonably decent MIDI recording/playback latency, and more efficiently manage large amounts of data, even with an interpreted language like REXX.
Typically after loading an existing MIDI file, you'll next make a call to MIDITrack() to set the search track(s). The search tracks can be set to one or more specific tracks (or even all tracks). These determine in which tracks MIDIGetEvent() searches for the next event that matches some criteria that you specify, or which tracks it ignores.
Then you'll make numerous calls to MIDIGetEvent() to "step through" the events that interest you in the search track(s). MIDIGetEvent() searches, in (only) those search track(s), for the next event that matches your search criteria. You can search for an event by MIDI channel, and/or type of event. When MIDIGetEvent() finds an event that matches your search criteria, it is marked as the currently selected event, and the track in which it is found is marked as the currently selected track. MIDIGetEvent() also sets several variables in your REXX script with the values of the currently selected event. For example, the REXX variable named MIDIEvent.!Type tells you what type of event the currently selected event is. This will be a number, for example 144 if the currently selected event is a MIDI Note On event. MIDIGetEvent() also typically sets other variables. For example, MIDIEvent.!Channel will be set to the MIDI channel number that the currently selected event is upon. This will be a number from 1 to 16 for one of the 16 MIDI channels. Some events do not have a channel. For example, if the currently selected event's MIDIEvent.!Type is 81 (ie, a Tempo event), then MIDIEvent.!Channel will be set to an empty string to indicate that the currently selected event is not the kind of event that has a channel. (ie, It's not a "Voice category" MIDI message). Other variables may also be set, for example, with a MIDI Note On, MIDIEvent.!Data1 will be set to the note number, and MIDIEvent.!Data2 will be set to the velocity.
The very first time that you call MIDIGetEvent() (after calling MIDITrack()) it will start searching from the beginning of the search track(s). Each subsequent time that you call MIDIGetEvent(), it will start searching from after the currently selected event. Remember that in a MIDI file, events are ordered according to the time that they occur, so events that playback first will ultimately be searched first.
You can use MIDISetEvent() to change the currently selected event's values, or delete the currently selected event. Or you can insert a new event in the currently selected track. Typically, you'll set some of those above REXX variables to desired values, and then call MIDISetEvent(). You can also use MIDISetEvent() to add an event to a track that previously had no events, thus starting a new track.
After you're done operating upon the MIDI file in RAM, if you have made any changes to it which you'd like to save, then you'll call MIDISaveFile() to save that MIDI file to disk. You can then subsequently load/create another file (RxMIDI works upon only one MIDI file in RAM at a time), or continue modifying the same MIDI file.
Note: To avoid any conflicts with the names of REXX variables that MIDI Rexx sets in your script, you should avoid naming any of your own variables starting with an exclamation point, nor use the variable names of MidiErr or MidiHeading.
Note: RxMIDI is limited to loading/creating MIDI files with 32 or less tracks.