Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from ledfx.effects.audio import AudioReactiveEffect, MIN_MIDI, MAX_MIDI
from ledfx.effects.gradient import GradientEffect
from ledfx.effects import mix_colors
from ledfx.color import COLORS
import voluptuous as vol
import numpy as np
import aubio
class PitchSpectrumAudioEffect(AudioReactiveEffect, GradientEffect):
NAME = "PitchSpectrum"
CONFIG_SCHEMA = vol.Schema({
vol.Optional('blur', description='Amount to blur the effect', default = 1.0): vol.Coerce(float),
vol.Optional('mirror', description='Mirror the effect', default = True): bool,
vol.Optional('fade_rate', description='Rate at which notes fade', default = 0.15): vol.All(vol.Coerce(float), vol.Range(min=0.0, max=1.0)),
vol.Optional('responsiveness', description='Responsiveness of the note changes', default = 0.15): vol.All(vol.Coerce(float), vol.Range(min=0.0, max=1.0)),
})
def config_updated(self, config):
win_s = 1024
hop_s = 48000 // 60
tolerance = 0.8
# TODO: Move into the base audio effect class
from ledfx.effects.audio import AudioReactiveEffect
from ledfx.effects.gradient import GradientEffect
import voluptuous as vol
import numpy as np
class WavelengthAudioEffect(AudioReactiveEffect, GradientEffect):
NAME = "Wavelength"
# There is no additional configuration here, but override the blur
# default to be 3.0 so blurring is enabled.
CONFIG_SCHEMA = vol.Schema({
vol.Optional('blur', description='Amount to blur the effect', default = 3.0): vol.Coerce(float)
})
def config_updated(self, config):
# Create the filters used for the effect
self._r_filter = self.create_filter(
alpha_decay = 0.2,
alpha_rise = 0.99)
from ledfx.effects.audio import AudioReactiveEffect, FREQUENCY_RANGES
from ledfx.effects.gradient import GradientEffect
import voluptuous as vol
import numpy as np
class BeatAudioEffect(AudioReactiveEffect, GradientEffect):
NAME = "Beat"
CONFIG_SCHEMA = vol.Schema({
vol.Optional('frequency_range', description='Frequency range for the beat detection', default = 'bass'): vol.In(list(FREQUENCY_RANGES.keys())),
})
def config_updated(self, config):
self._frequency_range = np.linspace(
FREQUENCY_RANGES[self.config['frequency_range']].min,
FREQUENCY_RANGES[self.config['frequency_range']].max,
20)
def audio_data_updated(self, data):
# Grab the filtered and interpolated melbank data
magnitude = np.max(data.sample_melbank(list(self._frequency_range)))
def config_updated(self, config):
"""Invalidate the gradient"""
self._gradient_curve = None
def apply_gradient(self, y):
self._validate_gradient()
# Apply and roll the gradient if necessary
output = (self._gradient_curve[:][::1]*y).T
self._roll_gradient()
return output
class TemporalGradientEffect(TemporalEffect, GradientEffect):
"""
A simple effect that just applies a gradient to the channel. This
is essentually just the temporal exposure of gradients.
"""
NAME = "Gradient"
def effect_loop(self):
# TODO: Could add some cool effects like twinkle or sin modulation
# of the gradient.
self.pixels = self.apply_gradient(1)