View Source X32Remote.Types.Channel (x32_remote v0.1.0)

Guards and functions specifically for channel names, in type/## format.

valid-channels

Valid channels

The following names are considered valid:

  • ch/01 through ch/32
  • auxin/01 through auxin/08
  • fxrtn/01 through fxrtn/08
  • bus/01 through bus/16
  • mtx/01 through mtx/06
  • main/st and main/m

All single-digit numbers must be zero-padded. E.g. ch/05 is a valid channel, ch/5 is not.

Link to this section Summary

Types

An X32 mixer channel, in type/## format

A one- or two-digit integer, as a two-character zero-padded string.

A one- or two-digit integer.

Functions

Checks if a string refers to a valid channel name.

Runtime assertion to ensure that a channel name is valid.

Converts a two-character string into a one- or two-digit integer.

Converts a one- or two-digit integer into a two-character zero-padded string.

Link to this section Types

@type channel() :: binary()

An X32 mixer channel, in type/## format

@type twodigit_binary() :: <<_::16>>

A one- or two-digit integer, as a two-character zero-padded string.

@type twodigit_integer() :: 0..99

A one- or two-digit integer.

Link to this section Functions

@spec channel?(binary()) :: boolean()

Checks if a string refers to a valid channel name.

Returns true if valid, false otherwise.

@spec ensure_channel(binary()) :: binary()

Runtime assertion to ensure that a channel name is valid.

Returns ch if channel?/1 returns true. Raises ArgumentError otherwise.

This could technically be a guard, but the guard version was extremely verbose on error, and about 2.8x slower besides.

@spec from_twodigit(twodigit_binary()) :: twodigit_integer()

Converts a two-character string into a one- or two-digit integer.

Faster than String.to_integer/1 for this specific case.

@spec to_twodigit(twodigit_integer()) :: twodigit_binary()

Converts a one- or two-digit integer into a two-character zero-padded string.

Faster than Integer.to_string/1 + String.pad_leading/3.