Information about the "MIDIplayer" Max patch
by Ere Lievonen 2017

This "MIDIplayer" Max patch can play back MIDI files, starting them at specified registration events. It works only in conjunction with "Ere's Fokker organ console". 

Max patches are in fact plain text files, so even if saving is disabled on your copy of Max, you can make certain simple edits to the patch by using a regular text editor. However, never edit the original patch file, but always make a renamed copy of it which you can then edit. Use the text editor's search function to find the object you need to edit (for example, search for "zl slice"), then edit its "text" value. Be careful not to change anything else, and make sure that your text editor does not perform any automatic substitutions (such as smart quotes), otherwise the patch may not work. After editing and saving, you need to reopen the patch in Max.

MIDI files for playback must be single track MIDI files (Type 0). This MIDIplayer does not support multi-track (Type 1) MIDI files.

A single instance of this patch can handle a maximum of five MIDI files. Put the names of your MIDI files inside the "seq" objects. If a name contains spaces, it must be enclosed in quotes. If using a text editor, note that the code for a quote character inside an already quoted text field is \" (backslash + quote). 

If you have more than five MIDI files to play back, simply create and use multiple copies of the MIDIplayer patch, each one of course renamed differently.

As it stands, the MIDIplayer is inactive by default, and activates itself only when a specified registration list is loaded, and deactivates automatically when any other registration list is loaded. In the "zl compare" object, replace the words "Registration list name" with the actual name of your registration list to make this work. (Don't use quotes for the name in this box.) You can have the MIDIplayer patch load automatically when the registration list is loaded if you include the "loadMaxpat" initial command in your registration list. For example:
loadMaxpat, MIDIplayer.maxpat;

If you want the patch to react to any registration list whose name begins with certain words, replace "99" in the "zl slice" object with the number of significant words. The name given inside the "zl compare" object immediately below it must not contain more words than this number. ("Words" are defined here as character strings separated by spaces.)

If you prefer that the patch is always active regardless of what registration list is loaded, change the object "switch 2 2" to "switch 2 1". You can also manually activate and deactivate the patch by clicking on the on/off toggle.

By way of an example, the patch starts playing MIDI file 1 at registration # 10, MIDI file 2 at registration # 20, etc. You can change the registration event numbers for the five MIDI files by changing the numbers inside the "select 10 20 30 40 50" object. Be sure to always include five items, otherwise the patch may not work correctly. If you don't need all five of them, you can change the ones you don't need to something that isn't a registration event number (for example x, or -1), to disable their playback.

You can also manually start playback of the MIDI files by clicking on the buttons "1" to "5" onscreen.

Pressing Esc key will stop MIDI playback. If you'd prefer to use some other key to stop playback: Press the desired key and observe the number that appears in the "key code" box. In the "select 27" object, replace "27" with the key code of the desired key. For example, another good key to use might be the Space bar (key code 32); this would then simultaneously execute the All Notes Off command in Ere's Fokker organ console.

If you need a delay before the start of MIDI playback, change the value "0" (in milliseconds) in the relevant "delay 0" object. For example, if a registration change needs to happen exactly at the start of the MIDI file, change this to "delay 157".

The notes from the played MIDI files are sent internally to "Ere's Fokker organ console". There are several options of where the note messages can be sent to; this is determined by the two "send" objects at the bottom of the patch. In the example patch, these are "send Ext31t_noteon" and "send Ext31t_noteoff", which will send the notes through the virtual couplers, as if they were input from external MIDI source. This means that you can use virtual couplers (specifically, those belonging to External MIDI input) to affect the registration of the played MIDI files. (The mode switch for input from external MIDI source on the Setup window has no influence on this; it could even be in the "off" position.) If you change the two send objects to "send 31t_noteon" and "send 31t_noteoff", the MIDI notes will be sent through the virtual couplers as if they were input from the Fokker organ keyboard, and the relevant virtual couplers will have effect on the playback. If you want to bypass virtual couplers and output the MIDI notes directly to the Fokker organ, change the send objects to "send noteon" and "send noteoff".
