# Trigger and release an external synth via MIDI

``

    midi  note (number)

Sends a MIDI note on event to all connected MIDI devices and all channels and then after sustain beats sends a MIDI note off event. Ensures MIDI trigger is synchronised with standard calls to play and sample. Co-operates completely with Sonic Pi’s timing system including `time_warp`.

If `note` is specified as `:off` then all notes will be turned off (same as `midi_all_notes_off`).

Introduced in v3.0

## Options

sustain: | Duration of note event in beats
vel: | Velocity of note as a MIDI number
on: | If specified and false/nil/0 will stop the midi on/off messages from being sent out. (Ensures all opts are evaluated in this call to `midi` regardless of value).

## Examples

# Example 1
``
    midi :e1, sustain: 0.3, vel_f: 0.5, channel: 3
| ``
    # Play E, octave 1 for 0.3 beats at half velocity on channel 3 on all connected MIDI ports.
# Example 2
``
    midi :off, channel: 3
| ``
    #=> Turn off all notes on channel 3 on all connected MIDI ports
# Example 3
``
    midi :e1, channel: 3, port: "foo"
| ``
    #=> Play note :E1 for 1 beats on channel 3 on MIDI port named "foo" only
# Example 4
``
    live_loop :arp do
      midi (octs :e1, 3).tick, sustain: 0.1
      sleep 0.125
    end
| ``
    # repeatedly play a ring of octaves