Source code for jdxi_editor.midi.data.digital.oscillator

"""Digital Oscillator"""

from enum import Enum, IntEnum

from jdxi_editor.midi.wave.form import (
    OSC_WAVE_NOISE,
    OSC_WAVE_PCM,
    OSC_WAVE_SAW,
    OSC_WAVE_SINE,
    OSC_WAVE_SQUARE,
    OSC_WAVE_SUPER_SAW,
    OSC_WAVE_TRIANGLE,
    Waveform,
)


[docs] class DigitalOscPcmWaveGain(IntEnum): """Wave gain values in dB"""
[docs] DB_MINUS_6 = 0 # -6 dB
[docs] DB_0 = 1 # 0 dB
[docs] DB_PLUS_6 = 2 # +6 dB
[docs] DB_PLUS_12 = 3 # +12 dB
[docs] class DigitalOscWave(IntEnum): """Oscillator waveform types"""
[docs] SAW = 0
[docs] SQUARE = 1
[docs] PW_SQUARE = 2 # Pulse Width Square
[docs] TRIANGLE = 3
[docs] SINE = 4
[docs] NOISE = 5
[docs] SUPER_SAW = 6
[docs] PCM = 7
@property
[docs] def display_name(self) -> str: """Get display name for the waveform""" return { self.SAW: "SAW", self.SQUARE: "SQR", self.PW_SQUARE: "PWM", self.TRIANGLE: "TRI", self.SINE: "SINE", self.NOISE: "NOISE", self.SUPER_SAW: "S-SAW", self.PCM: "PCM", }[self]
@property
[docs] def description(self) -> str: """Get full description of the waveform""" return { self.SAW: "Sawtooth", self.SQUARE: "Square", self.PW_SQUARE: "Pulse Width Square", self.TRIANGLE: "Triangle", self.SINE: "Sine", self.NOISE: "Noise", self.SUPER_SAW: "Super Saw", self.PCM: "PCM Wave", }[self]
[docs] class DigitalWaveform(Enum): """Waveform types available on the JD-Xi"""
[docs] SAW = 0x00 # Sawtooth wave
[docs] SQUARE = 0x01 # Square wave
[docs] PW_SQUARE = 0x02 # Pulse width square wave
[docs] TRIANGLE = 0x03 # Triangle wave
[docs] SINE = 0x04 # Sine wave
[docs] NOISE = 0x05 # Noise
[docs] SUPER_SAW = 0x06 # Super saw
[docs] PCM = 0x07 # PCM waveform
@property
[docs] def display_name(self) -> str: """Get display name for waveform""" names = { DigitalWaveform.SAW: "SAW", DigitalWaveform.SQUARE: "SQR", DigitalWaveform.PW_SQUARE: "PW.SQR", DigitalWaveform.TRIANGLE: "TRI", DigitalWaveform.SINE: "SIN", DigitalWaveform.NOISE: "NOISE", DigitalWaveform.SUPER_SAW: "S.SAW", DigitalWaveform.PCM: "PCM", } return names[self]
@property
[docs] def midi_value(self) -> int: """Get MIDI value for waveform""" values = { Waveform.SAW: OSC_WAVE_SAW, Waveform.SQUARE: OSC_WAVE_SQUARE, Waveform.TRIANGLE: OSC_WAVE_TRIANGLE, Waveform.SINE: OSC_WAVE_SINE, Waveform.NOISE: OSC_WAVE_NOISE, Waveform.SUPER_SAW: OSC_WAVE_SUPER_SAW, Waveform.PCM: OSC_WAVE_PCM, } return values[self]
@classmethod
[docs] def from_midi_value(cls, value: int) -> Waveform: """Create Waveform from MIDI value""" for waveform in cls: if waveform.midi_value == value: return waveform raise ValueError(f"Invalid waveform value: {value}")