Skip to content

Commit

Permalink
Add support for CTC
Browse files Browse the repository at this point in the history
  • Loading branch information
vanous committed Sep 5, 2024
1 parent e23fa78 commit fb689b4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 11 deletions.
26 changes: 26 additions & 0 deletions dmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,18 @@ def onProgrammerZoom(self, context):
})
self.render()

def onProgrammerColorTemperature(self, context):
for fixture in self.fixtures:
if fixture.collection is None:
continue
if fixture.is_selected():
fixture.setDMX({
'CTO':int(self.programmer_color_temperature),
'CTC':int(self.programmer_color_temperature),
'CTB':int(self.programmer_color_temperature)
})
self.render()

def onProgrammerColorWheel(self, context):
for fixture in self.fixtures:
if fixture.collection is None:
Expand Down Expand Up @@ -1405,6 +1417,13 @@ def onProgrammerShutter(self, context):
default = 0,
update = onProgrammerColorWheel)

programmer_color_temperature: IntProperty(
name = "Programmer Color Temperature",
min = 0,
max = 255,
default = 0,
update = onProgrammerColorTemperature)

programmer_gobo: IntProperty(
name = "Programmer Gobo",
min = 0,
Expand Down Expand Up @@ -1439,6 +1458,7 @@ def syncProgrammer(self):
self.programmer_zoom = 25
self.programmer_shutter = 0
self.programmer_color_wheel = 0
self.programmer_color_temperature = 0
self.programmer_gobo = 0
self.programmer_gobo_index = 63
return
Expand All @@ -1457,6 +1477,12 @@ def syncProgrammer(self):
self.programmer_color_wheel = int(data['Color2'])
if ('ColorMacro1' in data):
self.programmer_color_wheel = int(data['ColorMacro1'])
if ('CTC' in data):
self.programmer_color_temperature = int(data['CTC'])
if ('CTO' in data):
self.programmer_color_temperature = int(data['CTO'])
if ('CTB' in data):
self.programmer_color_temperature = int(data['CTB'])
if ('Gobo1' in data):
self.programmer_gobo = int(data['Gobo1'])
if ('Gobo2' in data):
Expand Down
49 changes: 38 additions & 11 deletions fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from .gdtf import DMX_GDTF
from .data import DMX_Data
from .util import cmy_to_rgb, add_rgb, colors_to_rgb, rgb2xyY
from .util import cmy_to_rgb, add_rgb, colors_to_rgb, rgb2xyY, kelvin_table
from .osc_utils import DMX_OSC_Handlers
from bpy.props import (IntProperty,
BoolProperty,
Expand Down Expand Up @@ -598,6 +598,7 @@ def render(self, skip_cache = False, current_frame = None):
cmy = [None,None,None]
zoom = None
color1 = None
ctc = None
rgb_mixing_geometries={}
xyz_moving_geometries={}
xyz_rotating_geometries={}
Expand Down Expand Up @@ -712,6 +713,9 @@ def render(self, skip_cache = False, current_frame = None):
elif (channels[c] == 'Zoom'): zoom = data[c]
elif (channels[c] == 'Color1'): color1 = data[c]
elif (channels[c] == 'Color2'): color1 = data[c]
elif (channels[c] == 'CTC'): ctc = data[c]
elif (channels[c] == 'CTO'): ctc = data[c]
elif (channels[c] == 'CTB'): ctc = data[c]
elif (channels[c] == 'ColorMacro1'): color1 = data[c]
elif (channels[c] == 'Gobo1'): gobo1[0] = data[c]
elif (channels[c] == 'Gobo1Pos' or channels[c] == 'Gobo1PosRotate'): gobo1[1] = data[c]
Expand All @@ -736,17 +740,21 @@ def render(self, skip_cache = False, current_frame = None):
colorwheel_color = None
if (color1 is not None):
colorwheel_color = self.get_colorwheel_color(color1)
color_temperature = None
if (ctc is not None):
color_temperature = self.get_color_temperature(ctc)

for geometry, colors in rgb_mixing_geometries.items():
if len(rgb_mixing_geometries)==1:
geometry = None
self.updateRGB(colors, geometry, colorwheel_color, current_frame)
self.updateRGB(colors, geometry, colorwheel_color, color_temperature, current_frame)

if not len(rgb_mixing_geometries):# handle units without mixing
if not all([c == 255 for c in self.gel_color_rgb]) or colorwheel_color is not None: #gel color is set and has priority or there is a color wheel
self.updateRGB([255] * 12, None, colorwheel_color, current_frame)
if not all([c == 255 for c in self.gel_color_rgb]) or colorwheel_color is not None or color_temperature is not None: #gel color is set and has priority or there is a color wheel or color_temperature
self.updateRGB([255] * 12, None, colorwheel_color, color_temperature, current_frame)

if (cmy[0] is not None and cmy[1] is not None and cmy[2] is not None):
self.updateCMY(cmy, colorwheel_color, current_frame)
self.updateCMY(cmy, colorwheel_color, color_temperature, current_frame)


if "Target" in self.objects:
Expand Down Expand Up @@ -859,9 +867,9 @@ def updateShutterDimmer(self, shutter, dimmer, geometry, bits, current_frame):
if geometry is not None:
if f"{geometry}" in emitter_material.name:
DMX_Log.log.info("matched emitter")
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 10*(dimmer/(255.0 * bits))
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 1*(dimmer/(255.0 * bits))
else:
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 10*(dimmer/(255.0 * bits))
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 1*(dimmer/(255.0 * bits))
if current_frame and self.dmx_cache_dirty:
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].keyframe_insert(data_path='default_value', frame=current_frame)

Expand Down Expand Up @@ -935,7 +943,7 @@ def runStrobe(self):

# Here we can reuse data we got from the light object...
for emitter_material in self.emitter_materials:
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 10*(dimmer_value/(255.0 * dimmer_bits))
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 1*(dimmer_value/(255.0 * dimmer_bits))

if exit_timer:
DMX_Log.log.info("Killing shutter timer")
Expand All @@ -947,14 +955,16 @@ def runStrobe(self):
return None # kills the timer
return 1.0/24.0

def updateRGB(self, colors, geometry, colorwheel_color, current_frame):
def updateRGB(self, colors, geometry, colorwheel_color, color_temperature, current_frame):
if geometry is not None:
geometry = geometry.replace(" ", "_")
DMX_Log.log.info(("color change for geometry", geometry))
colors = [c if c is not None else 0 for c in colors] # replace None with 0, can happen if someone maps colors across geometries...
rgb = colors_to_rgb(colors)
if colorwheel_color is not None:
rgb = add_rgb(rgb, colorwheel_color[:3])
if color_temperature is not None:
rgb = add_rgb(rgb, color_temperature[:3])
rgb = add_rgb(self.gel_color_rgb, rgb)
rgb = [c/255.0 for c in rgb]

Expand Down Expand Up @@ -988,13 +998,20 @@ def updateRGB(self, colors, geometry, colorwheel_color, current_frame):
return rgb


def updateCMY(self, cmy, colorwheel_color, current_frame):
def updateCMY(self, cmy, colorwheel_color, color_temperature, current_frame):
rgb=[0,0,0]
rgb=cmy_to_rgb(cmy)

if all([c == 255 for c in rgb]) and (colorwheel_color is not None or color_temperature is not None):
rgb=[0,0,0] # without this, default white would always be overwriting ctc

if colorwheel_color is not None:
rgb = add_rgb(rgb, colorwheel_color[:3])
if color_temperature is not None:
rgb = add_rgb(rgb, color_temperature[:3])
if not all([c == 255 for c in self.gel_color_rgb]):
rgb = add_rgb(self.gel_color_rgb, rgb)

rgb = add_rgb(self.gel_color_rgb, rgb)
rgb = [c/255.0 for c in rgb]

for emitter_material in self.emitter_materials:
Expand Down Expand Up @@ -1057,6 +1074,16 @@ def get_colorwheel_color(self, color1):
if len(colors) > index:
return colors[index]

def get_color_temperature(self, ctc):
if ctc == 0:
return
if 1 <= ctc <= 255:
ctc = 1000 + (ctc - 1) * (12000 - 1000) / (255 - 1)
ctc -= ctc % -100 # round to full 100s
return kelvin_table[ctc]
else:
return

def updateGobo(self, gobo1, current_frame):
if "gobos" not in self.images:
self.hide_gobo(current_frame=current_frame)
Expand Down
4 changes: 4 additions & 0 deletions panels/programmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def execute(self, context):
scene.dmx.programmer_tilt = 0.0
scene.dmx.programmer_zoom = 25
scene.dmx.programmer_color_wheel = 0
scene.dmx.programmer_color_temperature = 0
scene.dmx.programmer_gobo = 0
scene.dmx.programmer_gobo_index = 63
scene.dmx.programmer_shutter = 0
Expand Down Expand Up @@ -520,6 +521,8 @@ def draw(self, context):
box.prop(scene.dmx, "programmer_zoom", text=_("Zoom"), translate=False, slider = True)
if selected_fixtures[0].has_attributes(["Color1", "Color2", "ColorMacro1"]):
box.prop(scene.dmx, "programmer_color_wheel", text=_("Color Wheel"), translate=False)
if selected_fixtures[0].has_attributes(["CTO", "CTC", "CTB"]):
box.prop(scene.dmx, "programmer_color_temperature", text=_("Color Temperature"), translate=False)
if selected_fixtures[0].has_attributes(["Gobo"]):
box.prop(scene.dmx, "programmer_gobo", text=_("Gobo"), translate=False)
box.prop(scene.dmx, "programmer_gobo_index", text=_("Gobo Rotation"), translate=False)
Expand Down Expand Up @@ -551,6 +554,7 @@ def draw(self, context):

box.prop(scene.dmx, "programmer_zoom", text=_("Zoom"), translate=False, slider = True)
box.prop(scene.dmx, "programmer_color_wheel", text=_("Color Wheel"), translate=False)
box.prop(scene.dmx, "programmer_color_temperature", text=_("Color Temperature"), translate=False)
box.prop(scene.dmx, "programmer_gobo", text=_("Gobo"), translate=False)
box.prop(scene.dmx, "programmer_gobo_index", text=_("Gobo Rotation"), translate=False)
box.prop(scene.dmx, "programmer_shutter", text=_("Strobe"), translate=False)
Expand Down
4 changes: 4 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,7 @@ def create_unique_fixture_name(name):
name = f"{name}-{rand}"
else:
return name


# https://andi-siess.de/rgb-to-color-temperature/
kelvin_table = { 1000: (255, 56, 0), 1100: (255, 71, 0), 1200: (255, 83, 0), 1300: (255, 93, 0), 1400: (255, 101, 0), 1500: (255, 109, 0), 1600: (255, 115, 0), 1700: (255, 121, 0), 1800: (255, 126, 0), 1900: (255, 131, 0), 2000: (255, 138, 18), 2100: (255, 142, 33), 2200: (255, 147, 44), 2300: (255, 152, 54), 2400: (255, 157, 63), 2500: (255, 161, 72), 2600: (255, 165, 79), 2700: (255, 169, 87), 2800: (255, 173, 94), 2900: (255, 177, 101), 3000: (255, 180, 107), 3100: (255, 184, 114), 3200: (255, 187, 120), 3300: (255, 190, 126), 3400: (255, 193, 132), 3500: (255, 196, 137), 3600: (255, 199, 143), 3700: (255, 201, 148), 3800: (255, 204, 153), 3900: (255, 206, 159), 4000: (255, 209, 163), 4100: (255, 211, 168), 4200: (255, 213, 173), 4300: (255, 215, 177), 4400: (255, 217, 182), 4500: (255, 219, 186), 4600: (255, 221, 190), 4700: (255, 223, 194), 4800: (255, 225, 198), 4900: (255, 227, 202), 5000: (255, 228, 206), 5100: (255, 230, 210), 5200: (255, 232, 213), 5300: (255, 233, 217), 5400: (255, 235, 220), 5500: (255, 236, 224), 5600: (255, 238, 227), 5700: (255, 239, 230), 5800: (255, 240, 233), 5900: (255, 242, 236), 6000: (255, 243, 239), 6100: (255, 244, 242), 6200: (255, 245, 245), 6300: (255, 246, 247), 6400: (255, 248, 251), 6500: (255, 249, 253), 6600: (254, 249, 255), 6700: (252, 247, 255), 6800: (249, 246, 255), 6900: (247, 245, 255), 7000: (245, 243, 255), 7100: (243, 242, 255), 7200: (240, 241, 255), 7300: (239, 240, 255), 7400: (237, 239, 255), 7500: (235, 238, 255), 7600: (233, 237, 255), 7700: (231, 236, 255), 7800: (230, 235, 255), 7900: (228, 234, 255), 8000: (227, 233, 255), 8100: (225, 232, 255), 8200: (224, 231, 255), 8300: (222, 230, 255), 8400: (221, 230, 255), 8500: (220, 229, 255), 8600: (218, 229, 255), 8700: (217, 227, 255), 8800: (216, 227, 255), 8900: (215, 226, 255), 9000: (214, 225, 255), 9100: (212, 225, 255), 9200: (211, 224, 255), 9300: (210, 223, 255), 9400: (209, 223, 255), 9500: (208, 222, 255), 9600: (207, 221, 255), 9700: (207, 221, 255), 9800: (206, 220, 255), 9900: (205, 220, 255), 10000: (207, 218, 255), 10100: (207, 218, 255), 10200: (206, 217, 255), 10300: (205, 217, 255), 10400: (204, 216, 255), 10500: (204, 216, 255), 10600: (203, 215, 255), 10700: (202, 215, 255), 10800: (202, 214, 255), 10900: (201, 214, 255), 11000: (200, 213, 255), 11100: (200, 213, 255), 11200: (199, 212, 255), 11300: (198, 212, 255), 11400: (198, 212, 255), 11500: (197, 211, 255), 11600: (197, 211, 255), 11700: (197, 210, 255), 11800: (196, 210, 255), 11900: (195, 210, 255), 12000: (195, 209, 255), }

0 comments on commit fb689b4

Please sign in to comment.