Skip to content

Commit

Permalink
Added new /parameter for wave_amplitude (only for StaticWave yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtimes-code committed Dec 31, 2023
1 parent 989c1ad commit 0e650b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion osc-receiver/config_laser1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ points_per_frame = no
osc_server_received_message = no
osc_server_add_or_remove_laser_object = no
osc_server_effect_handling = no
osc_server_parameter_handling = no

[laser_output]
# Pixel dimensions
Expand All @@ -31,7 +32,7 @@ scan_rate = 30000
# min: 0.01
# max: 1.0 (=100% intensity)
#intensity_factor = 0.7
intensity_factor = 0.5
intensity_factor = 0.4

# How often blank points (at the beginning of each new laser object) shall be repeated
# min: 1
Expand Down
3 changes: 2 additions & 1 deletion osc-receiver/global_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
running = True
visible_laser_objects = [] # visible laser objects to draw on preview screen / output to laser
NOTE_LASEROBJECT_MAPPING = None
config = None
config = None
parameters = {} # parameters (like 'wave_amplitude') received via OSC
12 changes: 11 additions & 1 deletion osc-receiver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,25 @@ def __init__(self, group = 0):

# Set up wave properties
self.wave_length = int(global_data.config['laser_output']['width'])
self.amplitude = 500
self.amplitude = 500
self.frequency = 3
self.vertical_shift = int(global_data.config['laser_output']['height']) / 2

self.draw_wave()

def draw_wave(self):
self.point_list = []
for x in range(0, int(global_data.config['laser_output']['width']), 50):
y = math.sin((2 * math.pi * self.frequency * x) / self.wave_length) * self.amplitude + self.vertical_shift
laser_point = LaserPoint(int(x), int(y))
laser_point.set_color(0, 0, 255)
self.point_list.append(laser_point)

def update(self):
super().update()
if 'wave_amplitude' in global_data.parameters and self.amplitude != global_data.parameters['wave_amplitude']:
self.amplitude = global_data.parameters['wave_amplitude']
self.draw_wave()


class AnimatedWave(StaticWave):
Expand Down
9 changes: 8 additions & 1 deletion osc-receiver/osc_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def handle_osc_message(address, *args):
logging.info(f'[OSC] Added new laser object: {laser_object}')
except Exception as e:
logging.error(f'[OSC] Error while adding new laser object: {e}')
# /effect is related to LaserObject
# /effect is related to any LaserObject
elif address.startswith("/effect/"):
if address == "/effect/xy_pos":
# Handle the combined XY position message
Expand All @@ -55,6 +55,12 @@ def handle_osc_message(address, *args):
}
effect_name = effect_names.get(address, "UNKNOWN_EFFECT")
handle_effect(effect_name, pos)
elif address.startswith("/parameters/"):
parameter_name = address.split('/')[2]
parameter_value = int(args[0])
if global_data.config['logging']['osc_server_parameter_handling'] == 'yes':
logging.info(f"[OSC] Handling parameter {parameter_name}: {parameter_value}")
global_data.parameters[parameter_name] = parameter_value

def handle_effect(effect_name, pos):
if global_data.config['logging']['osc_server_effect_handling'] == 'yes':
Expand Down Expand Up @@ -86,6 +92,7 @@ def process_osc_input():
disp.map("/effect/color_change/r", handle_osc_message)
disp.map("/effect/color_change/g", handle_osc_message)
disp.map("/effect/color_change/b", handle_osc_message)
disp.map("/parameters/*", handle_osc_message)

server = osc_server.ThreadingOSCUDPServer(
(global_data.config['osc_server']['ip'], int(global_data.config['osc_server']['port'])), disp)
Expand Down

0 comments on commit 0e650b9

Please sign in to comment.