# main

uuid: 3998028c913180d8145d156b050a20f57bcf2cdd
text: ffmpeg -i input.opus -b:a 192k output.mp3
mimetypes:
text/plain,text/plain;charset=utf-8,text/html,text/_moz_htmlcontext,text/_moz_htmlinfo,text/x-moz-url-priv


uuid: cfecdb24cc7569899dfaf42fcb344bdec7792be0
mimetypes:
text/plain,text/plain;charset=utf-8,text/html,text/_moz_htmlcontext,text/_moz_htmlinfo,text/x-moz-url-priv

text:
Sehnsucht.

Es schienen so golden die Sterne,
Am Fenster ich einsam stand
Und hörte aus weiter Ferne
Ein Posthorn im stillen Land.
Das Herz mir im Leibe entbrennte,
Da hab‘ ich mir heimlich gedacht:
Ach wer da mitreisen könnte
In der prächtigen Sommernacht!

Zwei junge Gesellen gingen
Vorüber am Bergeshang,
Ich hörte im Wandern sie singen
Die stille Gegend entlang:
Von schwindelnden Felsenschlüften,
Wo die Wälder rauschen so sacht,
Von Quellen, die von den Klüften
Sich stürzen in die Waldesnacht.

Sie sangen von Marmorbildern,
Von Gärten, die über’m Gestein
In dämmernden Lauben verwildern,
Palästen im Mondenschein,
Wo die Mädchen am Fenster lauschen,
Wann der Lauten Klang erwacht,
Und die Brunnen verschlafen rauschen
In der prächtigen Sommernacht.


uuid: cef0fc910ccaff912f9b7bbe189f42312fb4ca2e
mimetypes: text/plain,text/plain;charset=utf-8,text/html
text:
class HwConfig:
    def __init__(self, lights = 300, pin_id = 13, active = 0, version = 1, preset = {0: []}):
        """
        blocks: list[Block]
        """
        self.lights = lights or 300
        self.pin_id = pin_id or 13
        self.active = active or 0
        self.version = version or 1
        self.preset = preset or {0: []}
    
    @staticmethod
    def from_file(file):
        content = ""
        with open(file, "r") as f:
            content = f.read()
        return HwConfig.from_json(json.loads(content))
    
    @staticmethod
    def from_json(data):
            fm_presets = {}
            for id, preset in data.get("preset", {}).items():
                fm_blocks = []
                for block in preset.get("blocks", []):
                    fm_blocks.append(Block.from_json(block))
                fm_presets[id] = fm_blocks

            return HwConfig(data.get("lights"), data.get("pin_id"), data.get("active"), data.get("version"), fm_presets)

class Led:
    def __init__(self, color = "ffffff", bright = 1, id = 0, relative_pos=(0,0)):
        # relative_v_pos: (0,0) is bottom left of block
        self.color = hex_to_rgb(color) or "ffffff"
        self.bright = bright or 1
        self.number = id
        self.relative = relative_pos or (0,0)

    @staticmethod
    def from_json(data):
        return Led(data.get("color"), data.get("bright"), data.get("id"), data.get("relative_pos"))
    
class Block:
    def __init__(self, members = [], mode = "static", position = (0,0)):
        """
        members: dict[Led]
        """
        self.members = members
        self.possition = position
        self.mode = mode

    @staticmethod
    def from_json(data):
        fmt_members = []
        for member in data.get("members", []):
            fmt_members.append(Led.from_json(member))
        return Block(fmt_members, data.get("mode"), data.get("position"))
        

class Backlight:
    def __init__(self, lights = 300, pin = machine.Pin.board.GP13):
        self.strip = neopixel.NeoPixel(pin, lights, bpp=3)

    def _apply_for_pin(self, id, color, bright):
        self.strip[id] = (int(color[0]*bright), int(color[1]*bright), int(color[2]*bright))
        self.strip.write()

    def apply_preset(self, blocks: list[Block]):
        """
        blocks: list[Block]
        """
        for block in blocks:
            if block.mode == "pass":
                pass
            else:
               for member in block.members:
                    self._apply_for_pin(member.number, member.color, member.bright)


