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
z.add(sum)

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

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.add(h)

audio_out = z.AudioOut()
z.add(audio_out)

sum.output.connect(h.input)
h.output.connect(audio_out.input)

z.run()

Privacy

© 2019 Zrna Research