Synth Unit

Support the following products:

SynthUnit

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from unit import SynthUnit
 9import time
10
11
12synth_0 = None
13
14
15def setup():
16    global synth_0
17
18    M5.begin()
19    Widgets.fillScreen(0x222222)
20
21    synth_0 = SynthUnit(1, port=(1, 2))
22    synth_0.set_channel_volume(0, 64)
23    synth_0.set_instrument(0, 0, 112)
24
25
26def loop():
27    global synth_0
28    M5.update()
29    synth_0.set_note_on(0, 0, 61)
30    synth_0.set_note_on(0, 36, 127)
31    time.sleep_ms(300)
32    synth_0.set_note_on(0, 48, 124)
33    synth_0.set_note_on(0, 60, 124)
34
35
36if __name__ == "__main__":
37    try:
38        setup()
39        while True:
40            loop()
41    except (Exception, KeyboardInterrupt) as e:
42        try:
43            from utility import print_error_msg
44
45            print_error_msg(e)
46        except ImportError:
47            print("please update to latest firmware")

UIFLOW2 Example:

example.png

synth_cores3_example.m5f2

class SynthUnit

Constructors

class SynthUnit(id, port)
Initializes the MIDI unit with a specified UART ID and port pins.

The UART interface is used to transmit MIDI messages.

Parameters:
  • id (Literal[0,1,2]) – UART device ID.

  • port (List[int]|Tuple[int,int]) – UART TX and RX pins.

UIFLOW2:

init.png

Methods

SynthUnit.set_note_on(channel, pitch, velocity)

Sends a MIDI Note On message to the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • pitch – Note pitch (0-127).

  • velocity – Note velocity (0-127).

UIFLOW2:

set_note_on2.png

set_note_on.png

SynthUnit.set_note_off(channel, pitch)

Sends a MIDI Note Off message to the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • pitch – Note pitch (0-127).

UIFLOW2:

set_note_off.png

SynthUnit.set_instrument(bank, channel, value)

Changes the program (instrument) on the specified channel.

Parameters:
  • bank – Bank selector (MSB) for the program change.

  • channel – MIDI channel (0-15).

  • value – Program number (0-127).

UIFLOW2:

set_instrument.png

SynthUnit.set_drums_instrument(drum_pitch, velocity)

Sets a drum instrument and plays a note on MIDI channel 10.

Parameters:
  • drum_pitch – Drum pitch number.

  • velocity – Note velocity (0-127).

UIFLOW2:

set_drums_instrument.png

SynthUnit.set_pitch_bend(channel, value)

Sends a MIDI Pitch Bend message to the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • value – Pitch bend value (0-16383).

UIFLOW2:

set_pitch_bend.png

SynthUnit.set_pitch_bend_range(channel, value)

Sets the pitch bend range on the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • value – Pitch bend range in semitones.

UIFLOW2:

set_pitch_bend_range.png

SynthUnit.midi_reset()

Sends a MIDI System Exclusive Reset command.

UIFLOW2:

midi_reset.png

SynthUnit.set_channel_volume(channel, level)

Sets the channel volume for the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • level – Volume level (0-100).

UIFLOW2:

set_channel_volume.png

SynthUnit.set_all_notes_off(channel)

Sends a MIDI Control Change message to turn off all notes on the specified channel.

Parameters:

channel – MIDI channel (0-15).

UIFLOW2:

set_all_notes_off.png

SynthUnit.set_master_volume(level)

Sets the master volume using a standard System Exclusive message.

Parameters:

level – Volume level (0-100).

UIFLOW2:

set_master_volume.png

SynthUnit.set_reverb(channel, program, level, delayfeedback)

Configures reverb effect on the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • program – Reverb program number (0-7).

  • level – Reverb level (0-127).

  • delayfeedback – Delay feedback amount (0-127).

UIFLOW2:

set_reverb.png

SynthUnit.set_chorus(channel, program, level, feedback, chorusdelay)

Configures chorus effect on the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • program – Chorus program number (0-7).

  • level – Chorus level (0-127).

  • feedback – Chorus feedback amount (0-127).

  • chorusdelay – Chorus delay amount (0-127).

UIFLOW2:

set_chorus.png

SynthUnit.set_pan(channel, value)

Sets the pan position for the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • value – Pan position (0-127).

UIFLOW2:

set_pan.png

SynthUnit.set_equalizer(channel, lowband, medlowband, medhighband, highband, lowfreq, medlowfreq, medhighfreq, highfreq)

Sets the equalizer levels and frequencies for the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • lowband – Low band level (-12dB to +12dB).

  • medlowband – Mid-low band level (-12dB to +12dB).

  • medhighband – Mid-high band level (-12dB to +12dB).

  • highband – High band level (-12dB to +12dB).

  • lowfreq – Low band frequency (Hz).

  • medlowfreq – Mid-low band frequency (Hz).

  • medhighfreq – Mid-high band frequency (Hz).

  • highfreq – High band frequency (Hz).

UIFLOW2:

set_equalizer.png

SynthUnit.set_tuning(channel, fine, coarse)

Sets the tuning for the specified channel.

Parameters:
  • channel – MIDI channel (0-15).

  • fine – Fine tuning value (cents).

  • coarse – Coarse tuning value (semitones).

UIFLOW2:

set_tuning.png

SynthUnit.set_vibrate(channel, rate, depth, delay)

Sets the vibrato effect parameters on the specified channel.

Parameters:
  • channel – The MIDI channel to apply the vibrato effect to (0-15).

  • rate – The vibrato rate (0-127).

  • depth – The vibrato depth (0-127).

  • delay – The vibrato delay (0-127).

UIFLOW2:

set_vibrate.png

SynthUnit.set_tvf(channel, cutoff, resonance)

Sets the parameters for a TVF (Tone-Voltage Filter) on the specified channel.

Parameters:
  • channel – The MIDI channel to apply the filter to (0-15).

  • cutoff – The filter cutoff frequency (0-127).

  • resonance – The filter resonance (0-127).

UIFLOW2:

set_tvf.png

SynthUnit.set_envelope(channel, attack, decay, release)

Sets the ADSR (Attack, Decay, Sustain, Release) envelope parameters on the specified channel.

Parameters:
  • channel – The MIDI channel to apply the envelope to (0-15).

  • attack – The attack time (0-127).

  • decay – The decay time (0-127).

  • release – The release time (0-127).

UIFLOW2:

set_envelope.png

SynthUnit.set_scale_tuning(channel, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)

Sets scale tuning for the specified channel.

Parameters:
  • channel – The MIDI channel to apply the scale tuning to (0-15).

  • v1~v12 – Tuning values for each note in the scale (0-127).

UIFLOW2:

set_scale_tuning.png

SynthUnit.set_mod_wheel(channel, pitch, tvtcutoff, amplitude, rate, pitchdepth, tvfdepth, tvadepth)

Sets modulation wheel parameters that affect various effects on the specified channel.

Parameters:
  • channel – The MIDI channel to apply the modulation to (0-15).

  • pitch – Pitch modulation depth.

  • tvtcutoff – Cutoff frequency modulation depth.

  • amplitude – Amplitude modulation depth.

  • rate – Modulation rate.

  • pitchdepth – Depth of pitch modulation.

  • tvfdepth – Depth of TVF modulation.

  • tvadepth – Depth of TVA (Tone-Voltage Amplifier) modulation.

UIFLOW2:

set_mod_wheel.png

SynthUnit.set_all_drums()

Sends a System Exclusive message to set all drums on channel 10 to default values.

UIFLOW2:

set_all_drums.png

SynthUnit.cmd_write(cmd)

Writes a MIDI command to the UART interface.

Parameters:

cmd – List of MIDI command bytes.

SynthUnit.map(x, in_min, in_max, out_min, out_max)

Maps a value from one range to another.

Parameters:
  • x – Value to map.

  • in_min – Minimum value of the input range.

  • in_max – Maximum value of the input range.

  • out_min – Minimum value of the output range.

  • out_max – Maximum value of the output range.