MIDI to CV Converter

This example shows one approach for generating CV from MIDI note messages. We drive both inputs of a two input sum stage with a constant 2V. One input is inverted, so initially the output is zero. MIDI messages are bound to the sum stage input gains such that note 0 produces near -5V and note 128 produces an output near 5V. The AudioOut module provides an implicit gain of 2. The flexibility we have in mapping note numbers to gain values allows output accuracy and range to be tuned as needed.

import zrna
import numpy as np

z = zrna.api.Client()
z.connect()
z.clear()

sum = z.SumTwo()
sum.gain_input1 = 1.0
sum.gain_input2 = 1.0
sum.input1_polarity = z.NONINVERTING
sum.input2_polarity = z.INVERTING

dc_two_volts = z.VoltageConstant(
polarity=z.POSITIVE)

dc_two_volts.output.connect(sum.input1)
dc_two_volts.output.connect(sum.input2)

sum.gain_input1.listen(
midi=z.Note,
value_for_note=np.linspace(0, 1.25, 128)
)
sum.gain_input2.listen(
midi=z.Note,
value_for_note=np.linspace(1.25, 0, 128)
)

h = z.Hold()
z.run()