mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-13 11:50:12 +01:00
SoundReactPlugin preserves settings between sessions, removed peakfreq functionality that didnt work well yet
This commit is contained in:
@@ -26,32 +26,47 @@ class SoundReactPlugin(ActionsPlugin,SequencePlugin,DisplayPlugin):
|
|||||||
|
|
||||||
frequency = 10 # how often messages are sampled+calculated+sent, not anything to do with audio frequency
|
frequency = 10 # how often messages are sampled+calculated+sent, not anything to do with audio frequency
|
||||||
|
|
||||||
|
values = {}
|
||||||
|
levels = {
|
||||||
|
"energy": [ 0.0, 0.0, 1.0, 0.0 ],
|
||||||
|
"peakfreq": [ 0.0, 0.0, 0.0, 0.0 ]
|
||||||
|
}
|
||||||
|
last_values = {}
|
||||||
|
display_values = {}
|
||||||
|
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
# TODO: save + reload current config
|
# TODO: UI to select other sources than 'energy'
|
||||||
|
# TODO: fix/restore peakfreq source
|
||||||
|
# TODO: make triggery work better
|
||||||
|
# TODO: slope/curves so eg set threshold when signal received above threshold set energy level, decay energy level over time
|
||||||
|
|
||||||
def __init__(self, plugin_collection):
|
def __init__(self, plugin_collection):
|
||||||
super().__init__(plugin_collection)
|
super().__init__(plugin_collection)
|
||||||
|
|
||||||
"""#self.PRESET_FILE_NAME = "ShaderLoopRecordPlugin/frames.json"
|
self.PRESET_FILE_NAME = "SoundReactPlugin/config.json"
|
||||||
if self.active and not self.disabled:
|
presets = self.load_presets()
|
||||||
try:
|
self.config = presets.get('config',self.config)
|
||||||
p=pyaudio.PyAudio()
|
self.levels = presets.get('levels',self.levels)
|
||||||
self.stream=p.open(format=pyaudio.paInt16,channels=1,rate=self.RATE,input=True,
|
self.active = presets.get('active',self.active)
|
||||||
frames_per_buffer=self.CHUNK)
|
|
||||||
except:
|
|
||||||
print("Failed to open sound device - disabling SoundReactPlugin!")
|
|
||||||
self.disabled = True
|
|
||||||
return
|
|
||||||
|
|
||||||
print ("now setting to run automation..")
|
|
||||||
|
|
||||||
self.pc.shaders.root.after(500, self.run_automation)"""
|
|
||||||
if not self.disabled:
|
if not self.disabled:
|
||||||
self.start_plugin()
|
self.start_plugin()
|
||||||
|
|
||||||
|
def load_presets(self):
|
||||||
|
print("trying load presets? %s " % self.PRESET_FILE_NAME)
|
||||||
|
return self.pc.read_json(self.PRESET_FILE_NAME) or {}
|
||||||
|
|
||||||
|
def save_presets(self):
|
||||||
|
self.pc.update_json(self.PRESET_FILE_NAME, { 'config': self.config, 'levels': self.levels, 'active': self.active } )
|
||||||
|
|
||||||
|
def stop_plugin(self):
|
||||||
|
super().stop_plugin()
|
||||||
|
self.save_presets()
|
||||||
|
|
||||||
def stop_plugin(self):
|
def stop_plugin(self):
|
||||||
self.close_sound_device()
|
self.close_sound_device()
|
||||||
|
self.save_presets()
|
||||||
super().stop_plugin()
|
super().stop_plugin()
|
||||||
|
|
||||||
def start_plugin(self):
|
def start_plugin(self):
|
||||||
@@ -86,16 +101,9 @@ class SoundReactPlugin(ActionsPlugin,SequencePlugin,DisplayPlugin):
|
|||||||
#"low": self.low,
|
#"low": self.low,
|
||||||
#"mid": self.mid,
|
#"mid": self.mid,
|
||||||
#"high": self.high,
|
#"high": self.high,
|
||||||
"peakfreq": self.peakfreq
|
#"peakfreq": self.peakfreq
|
||||||
}
|
}
|
||||||
|
|
||||||
values = {}
|
|
||||||
levels = {
|
|
||||||
"energy": [ 0.0, 0.0, 1.0, 0.0 ],
|
|
||||||
"peakfreq": [ 0.0, 0.0, 0.0, 1.0 ]
|
|
||||||
}
|
|
||||||
last_values = {}
|
|
||||||
display_values = {}
|
|
||||||
# triggers?
|
# triggers?
|
||||||
# sudden drop - sudden leap?
|
# sudden drop - sudden leap?
|
||||||
|
|
||||||
@@ -226,3 +234,4 @@ class SoundReactPlugin(ActionsPlugin,SequencePlugin,DisplayPlugin):
|
|||||||
|
|
||||||
def toggle_active(self):
|
def toggle_active(self):
|
||||||
self.active = not self.active
|
self.active = not self.active
|
||||||
|
self.save_presets()
|
||||||
|
|||||||
Reference in New Issue
Block a user