MIDI Operations
The command to set-up MIDI ports is simply [midi].
Use it without parameters to see what MIDI devices are available.
Once you can see them, you can select the ones you want with [midi *in *out] command.
For example, [midi 0 0] will select the first input device and the first output device.
On Apple OS X you don't actually have to do anything.
The application creates virtual MIDI ports and uses them by default. They can be used by all your other software.
You can also use [midi *in *out] to select additional ports for extra transmission.
On Windows you must select devices, otherwise no MIDI will be transmitted and/or received.
On Linux the [midi] command will show you 10 input and output devices, regardles of whether they are connected or not.
You must look into your /dev directory and check if the devices are actually present. Then you can select the appropriated device.
If they are then you can select them.
On every platform you can access in-built help on MIDI commands. First, load the help module, i.e.: [load "help.prc"].
Once it is loaded you can access help by typing [help midi] or simply [help] for general help.
You can get help on each separate command using [help midiCommand], for example, [help keyoff] will tell you more about keyoff command.
TRANSMITTING MIDI
- [keyon *channel *key *velocity]
Transmits keyon message.
- [keyoff *channel *key] or [keyoff *channel *key *velocity]
Transmits keyoff message. The velocity parameter is optional and can be used by instruments, which can receive keyoff velocity.
- [keyoff *channel]
Transmits all-keys-off message.
- [programchange *channel *program]
Transmits program change message.
- [pitch *channel *value] or [pitch *channel *lsb *msb]
Transmits pitch-bend message.
In most cases you will use the version with just one parameter. However, for better precision you may want to use the second version.
- [control *channel *controller *value]
Transmits control-change message.
There are several predefined controllers.
For example, instead of writing [control 0 7 100] for changing the volume, you can use the shortcut [volume 0 100].
The following controllers are predefined: attack, release, holdon, holdoff, cutoff, resonance, mono, poly,
bank, banklsb, portaon, portaoff, portatime, volume, reverb, chorus, foot, pan, breath and modulation.
- [aftertouch *channel *value]
Transmits after-touch message.
- [polyaftertouch *channel *key *value]
Transmits polyphonic after-touch for key specified.
- [timingclock]
Transmits clock tick message.
- [activesensing]
Transmits active-sensing message.
- [SYSEX .... ]
Transmit system exclusive message. You can put whatever values you wish.
- [SYSEXCH .... ]
Transmit system exclusive message and inserts checksum byte at the end.
- [sysex .... ]
Transmit system exclusive message with manufacturer's id. The default value is 7D.
You can change it using [midi_manufacturers_id *id] or [midi_manufacturers_id *id1 *id2].
The first version assumes manufacturer's id is only one byte.
The second version uses 0 and 2 bytes of extended value.
- [sysexch .... ]
Works same as above but also insert checksum byte at the end.
- 14-bit controllers
These predefined controlchange messages allow for sending control values in the range from 0 to 16383.
They are composed as macrodefinitions sending in fact two different controlchange messages.
For more information consult in-built help.
The predefined 14-bit controllers are: CONTROL, ATTACK, RELEASE, CUTOFF, PORTATIME, VOLUME, REVERB, CHORUS, FOOT, PAN, BREATH and MODULATION.
- [hit *channel *velocity *key1 *key2 .... ]
This one is good for playing chords.
- nrpn, rpn, NRPN, RPN
These commands are usefull for sending nrpn and rpn messages.
Upper-case versions are 14-bit versions, i.e. you can specify values in the range from 0 to 16383.
For details consult in-built help.
RECEIVING MIDI
For receiving MIDI messages HERCs Prolog uses callback mechanism.
There is a dedicated symbol for this purpose: income_midi.
Whenever a new MIDI message arrives, a call to [income_midi ..... ] is executed.
It is your responsibility to provide the definition of income_midi.
You can find an example below.
MIDI MONITOR
This is probably the simplest program, which you can write for HERCs Prolog.
It shows incoming MIDI transmission. Just a single line of code.
You can download the sample code midi_monitor.prc or midi_monitor.prb.
The first one is in a form of a module, another is just a batch script.
- Check if the income_midi callback is defined. The list instruction will tell you. Write [list income_midi].
If it shows nothing, then it is not defined.
In most cases it won't be defined (default situation).
- If income_midi is defined then you should un-define it. Write [delallcl income_midi].
It will delete all the clauses attached to income_midi. Delallcl stands for: DELete-ALL-CLauses.
- Whenever Prolog detects incoming MIDI message, it will call the income_midi callback.
For example, if you play middle C (number 60) in MIDI channel 0 with velocity 100, then Prolog will call [income_midi keyon 0 60 100].
The exact number of parameters depends on the MIDI message. It may vary substantially for system exclusive, i.e. [income_midi sysex 1 2 3 4 5]
-
To make a midi monitor we just need to display whatever midi message comes.
We don't know what the message is and what is the exact number of parameters.
Therefore, we will use colon (:) to indicate that we want everything grouped together into a list.
This list will be displayed on the screen using the show command.
-
Now we can define our own version of income_midi callback.
It is a full clause with header and just one instruction in the body.
Type: [[income_midi : *command] [show *command]].
- You may wish to make sure that the income_midi callback is correctly installed.
Type [list income_midi] to see it.