Skip to content

Commit

Permalink
Add license header to all files, clean up and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
vanous committed Jun 23, 2024
1 parent ea2df8b commit 5de03a7
Show file tree
Hide file tree
Showing 52 changed files with 1,566 additions and 973 deletions.
18 changes: 17 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Copyright Hugo Aboud, Kaspars Jaudzems, Mark Steward, vanous
#
# This file is part of BlenderDMX.
#
# BlenderDMX is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# BlenderDMX is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.

bl_info = {
"name": "DMX",
"description": "DMX visualization and programming, with GDTF/MVR and Network support",
Expand All @@ -18,7 +35,6 @@
from .data import DMX_Data
from .artnet import DMX_ArtNet
from .acn import DMX_sACN
from .logging import DMX_Log

from .panels import profiles as Profiles

Expand Down
19 changes: 18 additions & 1 deletion acn.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
# Copyright Mark Steward, vanous
#
# This file is part of BlenderDMX.
#
# BlenderDMX is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# BlenderDMX is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.


import bpy
from .sacn import sACNreceiver
from .data import DMX_Data
from .logging import DMX_Log
import os


class DMX_sACN:
Expand Down
39 changes: 28 additions & 11 deletions artnet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Copyright Hugo Aboud, Kaspars Jaudzems, vanous
#
# This file is part of BlenderDMX.
#
# BlenderDMX is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# BlenderDMX is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.


import bpy

from socket import socket, AF_INET, SOCK_DGRAM, SHUT_RDWR, SOL_SOCKET, SO_BROADCAST, SO_REUSEADDR
Expand Down Expand Up @@ -65,7 +83,7 @@ def __init__(self, ip_addr, *args, **kwargs):
self._dmx.artnet_status = "socket_error"
raise ValueError("Socket opening error")

#self._socket.settimeout(30)
# self._socket.settimeout(30)
self._stopped = False

def stop(self):
Expand All @@ -77,7 +95,6 @@ def stop(self):
raise ValueError("Socket closing error")
self._stopped = True


def run(self):
while not self._stopped:
data = b""
Expand Down Expand Up @@ -139,14 +156,14 @@ def build_ArtPollReply(self):
else:
ip = "0.0.0.0"
ip = [int(i) for i in ip.split(".")]
content += [struct.pack('B', i) for i in ip]
content += [struct.pack("B", i) for i in ip]
# Port
content.append(struct.pack("<H", 0x1936))
# Firmware Version
content.append(struct.pack("!H", 1))
# Net and subnet of this node
content.append(struct.pack('B', ip[1]))
content.append(struct.pack('B', ip[0]))
content.append(struct.pack("B", ip[1]))
content.append(struct.pack("B", ip[0]))

# BlenderDMX OEM registered code, do not reuse if copying this code.
# Programmers: do not copy for other Art-Net implementations,
Expand All @@ -158,16 +175,16 @@ def build_ArtPollReply(self):
# Status1
content.append(struct.pack("H", 0))
# Manufacture ESTA Code
content.append(struct.pack("<H", 32767)) # ESTA RDM test code since we did not apply
content.append(struct.pack("<H", 32767)) # ESTA RDM test code since we did not apply
# Short Name
content.append(struct.pack("18s", b"BlenderDMX"))
content.append(struct.pack("64s", b"BlenderDMX GDTF & MVR plugin for Blender"))
description=b"#0001 [0000] BlenderDMX. All your GDTFs are belong to us."
description = b"#0001 [0000] BlenderDMX. All your GDTFs are belong to us."
content.append(struct.pack("64s", description))
#ports
content.append(struct.pack(">H", 8)) #0000
content.append(struct.pack(">L", 0)) #0000
content.append(struct.pack("46s", b"")) #0000
# ports
content.append(struct.pack(">H", 8)) # 0000
content.append(struct.pack(">L", 0)) # 0000
content.append(struct.pack("46s", b"")) # 0000

# stitch together
return b"".join(content)
Expand Down
24 changes: 23 additions & 1 deletion blender_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Copyright vanous
#
# This file is part of BlenderDMX.
#
# BlenderDMX is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# BlenderDMX is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.


import threading
import requests
import shutil
Expand Down Expand Up @@ -127,18 +145,22 @@ def reload_addon():
return SimpleNamespace(ok=False, error=str(e))
return SimpleNamespace(ok=True, error="")


def get_extension_manifest():
import toml

folder_path = os.path.dirname(os.path.realpath(__file__))
toml_path = os.path.join(folder_path, "blender_manifest.toml")
data=toml.load(toml_path)
data = toml.load(toml_path)
return data


def get_application_version():
if bpy.app.version >= (4, 2):
data = get_extension_manifest()
version = data["version"]
return tuple(version.split("."))
else:
from . import bl_info as application_info

return application_info["version"]
87 changes: 50 additions & 37 deletions data.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# Copyright Hugo Aboud, Kaspars Jaudzems, Mark Steward, vanous
#
# BlendexDMX > Data
# Allocates memory for DMX universes, which can be set from the Programmer
# Future:
# - Set from artnet
# -
# This file is part of BlenderDMX.
#
# http://www.github.com/open-stage/BlenderDMX
# BlenderDMX is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# BlenderDMX is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.


import bpy
import time

from .logging import DMX_Log
from bpy.types import (PropertyGroup)
from bpy.props import (IntProperty)
from bpy.types import PropertyGroup
from bpy.props import IntProperty


def update_callback(self, context):
# https://blender.stackexchange.com/questions/238441/force-redraw-add-on-custom-propery-in-n-panel-from-a-separate-thread
Expand All @@ -22,28 +30,27 @@ def update_callback(self, context):
# causes the UI to be refreshed periodically even when not in focus
return None


class DMX_Value(PropertyGroup):
channel: IntProperty(
name = "DMX Value",
update=update_callback,
default = 0)
channel: IntProperty(name="DMX Value", update=update_callback, default=0)

class DMX_Data():

class DMX_Data:
_universes = []
_virtuals = {} # Virtual channels. These are per fixture and have an attribute and a value
_dmx = None # Cache access to the context.scene
_live_view_data = [0]*512
_virtuals = {} # Virtual channels. These are per fixture and have an attribute and a value
_dmx = None # Cache access to the context.scene
_live_view_data = [0] * 512

@staticmethod
def prepare_empty_buffer():
# Prepare structure in the dmx_values collection, this is then used for the LiveDMX table
if DMX_Data._dmx is not None:
dmx = DMX_Data._dmx
dmx.dmx_values.clear()
buffer = [0]*512
buffer = [0] * 512
for i in buffer:
dmx.dmx_values.add()
dmx.dmx_values[-1].channel=i
dmx.dmx_values[-1].channel = i

@staticmethod
def setup(universes):
Expand All @@ -54,13 +61,13 @@ def setup(universes):
DMX_Data.prepare_empty_buffer()
old_n = len(DMX_Data._universes)
# shrinking (less universes then before)
if (universes < old_n):
if universes < old_n:
DMX_Log.log.info(f"DMX Universes Deallocated: {universes}, to {old_n}")
DMX_Data._universes = DMX_Data._universes[:universes]
# growing (more universes then before)
else:
for u in range(old_n,universes):
DMX_Data._universes.append(bytearray([0]*512))
for u in range(old_n, universes):
DMX_Data._universes.append(bytearray([0] * 512))
DMX_Log.log.debug(f"DMX Universe Allocated: {u}")

@staticmethod
Expand All @@ -70,32 +77,39 @@ def get_value(universe, *channels):
sum = 0
for idx, channel in enumerate(reversed(channels)):
val = DMX_Data.get(universe, channel, 1)[0]
sum |= val<<(idx<<3)
sum |= val << (idx << 3)
return sum

@staticmethod
def get(universe, addr, n):
if (universe >= len(DMX_Data._universes)): return bytearray([0]*n)
if (addr + n > 512): return bytearray([0]*n)
return DMX_Data._universes[universe][addr-1:addr+n-1]
if universe >= len(DMX_Data._universes):
return bytearray([0] * n)
if addr + n > 512:
return bytearray([0] * n)
return DMX_Data._universes[universe][addr - 1 : addr + n - 1]

@staticmethod
def set(universe, addr, val):
DMX_Log.log.debug((universe, addr, val))
if (universe >= len(DMX_Data._universes)): return
if (not bpy.context.scene.dmx.universes[universe]): return
if (bpy.context.scene.dmx.universes[universe].input != 'BLENDERDMX'): return
if val > 255: return
if universe >= len(DMX_Data._universes):
return
if not bpy.context.scene.dmx.universes[universe]:
return
if bpy.context.scene.dmx.universes[universe].input != "BLENDERDMX":
return
if val > 255:
return
# This happened when importing one MVR file
if addr > 511:
return

if DMX_Data._dmx is not None:
dmx = bpy.context.scene.dmx
dmx = bpy.context.scene.dmx # hmm, here we use non cached dmx, probably this was safer...
if dmx.get_selected_live_dmx_universe().input == "BLENDERDMX":
dmx = bpy.context.scene.dmx
dmx.dmx_values[addr-1].channel=val
DMX_Data._universes[universe][addr-1] = val
dmx.dmx_values[addr - 1].channel = val

DMX_Data._universes[universe][addr - 1] = val

# LiveDMX view
if DMX_Data._dmx is not None:
Expand All @@ -113,7 +127,7 @@ def set_virtual(fixture, attribute, value):
if value > 255:
return
if fixture not in DMX_Data._virtuals:
DMX_Data._virtuals[fixture]={}
DMX_Data._virtuals[fixture] = {}
DMX_Data._virtuals[fixture][attribute] = value

@staticmethod
Expand All @@ -126,18 +140,17 @@ def get_virtual(fixture):
@staticmethod
def set_universe(universe, data, source):
DMX_Log.log.debug((universe, data))
if (universe >= len(DMX_Data._universes)):
if universe >= len(DMX_Data._universes):
return

dmx_changed = DMX_Data._universes[universe] != data
if dmx_changed:
DMX_Data._universes[universe] = data


if DMX_Data._dmx is not None:
dmx = bpy.context.scene.dmx
selected_live_dmx_universe = dmx.get_selected_live_dmx_universe()
if selected_live_dmx_universe is None: # this should not happen
if selected_live_dmx_universe is None: # this should not happen
raise ValueError("Missing selected universe, as if DMX base class is empty...")
if selected_live_dmx_universe.input == source and selected_live_dmx_universe.id == universe:
if dmx_changed:
Expand Down
23 changes: 21 additions & 2 deletions dmx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Copyright Hugo Aboud, vanous
#
# This file is part of BlenderDMX.
#
# BlenderDMX is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# BlenderDMX is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.


import sys
import bpy
import os
Expand All @@ -12,6 +30,7 @@
from .pymvr import GeneralSceneDescription
from .mvr import extract_mvr_textures, process_mvr_child_list

from . import param as param
from . import fixture as fixture
from . import tracker as tracker
from .universe import DMX_Universe
Expand Down Expand Up @@ -71,8 +90,8 @@ class DMX(PropertyGroup):
# Base classes to be registered
# These should be registered before the DMX class, so it can register properly

classes_base = (fixture.DMX_Param,
fixture.DMX_Model_Param,
classes_base = (param.DMX_Param,
param.DMX_Model_Param,
fixture.DMX_Fixture_Object,
fixture.DMX_Fixture_Image,
fixture.DMX_Emitter_Material,
Expand Down
Loading

0 comments on commit 5de03a7

Please sign in to comment.