event class moved into event.py

logger module used to write interface events to console
This commit is contained in:
onyx-and-iris 2022-09-29 09:44:14 +01:00
parent 81a74d136c
commit eddccb66c5
4 changed files with 61 additions and 47 deletions

View File

@ -1,4 +1,5 @@
import itertools import itertools
import logging
from pathlib import Path from pathlib import Path
try: try:
@ -118,6 +119,8 @@ class Loader(metaclass=SingletonType):
loads data into memory if not found loads data into memory if not found
""" """
logger = logging.getLogger("config.Loader")
def __init__(self, kind): def __init__(self, kind):
self._kind = kind self._kind = kind
self._configs = dict() self._configs = dict()
@ -131,14 +134,16 @@ class Loader(metaclass=SingletonType):
def parse(self, identifier, data): def parse(self, identifier, data):
if identifier in self._configs: if identifier in self._configs:
print(f"config file with name {identifier} already in memory, skipping..") self.logger.info(
f"config file with name {identifier} already in memory, skipping.."
)
return False return False
self.parser = dataextraction_factory(data) self.parser = dataextraction_factory(data)
return True return True
def register(self, identifier, data=None): def register(self, identifier, data=None):
self._configs[identifier] = data if data else self.parser.data self._configs[identifier] = data if data else self.parser.data
print(f"config {self.name}/{identifier} loaded into memory") self.logger.info(f"config {self.name}/{identifier} loaded into memory")
def deregister(self): def deregister(self):
self._configs.clear() self._configs.clear()
@ -161,6 +166,7 @@ def loader(kind):
returns configs loaded into memory returns configs loaded into memory
""" """
logger = logging.getLogger("config.loader")
loader = Loader(kind) loader = Loader(kind)
for path in ( for path in (
@ -169,7 +175,7 @@ def loader(kind):
Path.home() / "Documents/Voicemeeter" / "configs" / kind.name, Path.home() / "Documents/Voicemeeter" / "configs" / kind.name,
): ):
if path.is_dir(): if path.is_dir():
print(f"Checking [{path}] for TOML config files:") logger.info(f"Checking [{path}] for TOML config files:")
for file in path.glob("*.toml"): for file in path.glob("*.toml"):
identifier = file.with_suffix("").stem identifier = file.with_suffix("").stem
if loader.parse(identifier, file): if loader.parse(identifier, file):

48
voicemeeterlib/event.py Normal file
View File

@ -0,0 +1,48 @@
import logging
class Event:
"""Keeps track of event subscriptions"""
logger = logging.getLogger("event.event")
def __init__(self, subs: dict):
self.subs = subs
def info(self, msg=None):
info = (f"{msg} events",) if msg else ()
if self.any():
info += (f"now listening for {', '.join(self.get())} events",)
else:
info += (f"not listening for any events",)
self.logger.info(", ".join(info))
@property
def pdirty(self):
return self.subs["pdirty"]
@property
def mdirty(self):
return self.subs["mdirty"]
@property
def midi(self):
return self.subs["midi"]
@property
def ldirty(self):
return self.subs["ldirty"]
def get(self) -> list:
return [k for k, v in self.subs.items() if v]
def any(self) -> bool:
return any(self.subs.values())
def add(self, event):
self.subs[event] = True
self.info(f"{event} added to")
def remove(self, event):
self.subs[event] = False
self.info(f"{event} removed from")

View File

@ -1,10 +1,10 @@
import logging
from abc import abstractmethod from abc import abstractmethod
from enum import IntEnum from enum import IntEnum
from functools import cached_property from functools import cached_property
from typing import Iterable, NoReturn from typing import Iterable, NoReturn
from . import misc from . import misc
from .base import Remote
from .bus import request_bus_obj as bus from .bus import request_bus_obj as bus
from .command import Command from .command import Command
from .config import request_config as configs from .config import request_config as configs
@ -13,6 +13,7 @@ from .kinds import KindMapClass
from .kinds import request_kind_map as kindmap from .kinds import request_kind_map as kindmap
from .macrobutton import MacroButton from .macrobutton import MacroButton
from .recorder import Recorder from .recorder import Recorder
from .remote import Remote
from .strip import request_strip_obj as strip from .strip import request_strip_obj as strip
from .vban import request_vban_obj as vban from .vban import request_vban_obj as vban
@ -24,6 +25,7 @@ class FactoryBuilder:
Separates construction from representation. Separates construction from representation.
""" """
logger = logging.getLogger("remote.factorybuilder")
BuilderProgress = IntEnum( BuilderProgress = IntEnum(
"BuilderProgress", "BuilderProgress",
"strip bus command macrobutton vban device option recorder patch fx", "strip bus command macrobutton vban device option recorder patch fx",
@ -49,7 +51,7 @@ class FactoryBuilder:
def _pinfo(self, name: str) -> NoReturn: def _pinfo(self, name: str) -> NoReturn:
"""prints progress status for each step""" """prints progress status for each step"""
name = name.split("_")[1] name = name.split("_")[1]
print(self._info[int(getattr(self.BuilderProgress, name))]) self.logger.info(self._info[int(getattr(self.BuilderProgress, name))])
def make_strip(self): def make_strip(self):
self._factory.strip = tuple( self._factory.strip = tuple(

View File

@ -250,45 +250,3 @@ class Midi:
def _set(self, key: int, velocity: int): def _set(self, key: int, velocity: int):
self.cache[key] = velocity self.cache[key] = velocity
class Event:
def __init__(self, subs: dict):
self.subs = subs
def info(self, msg):
info = (
f"{msg} events",
f"Now listening for {', '.join(self.get())} events",
)
print("\n".join(info))
@property
def pdirty(self):
return self.subs["pdirty"]
@property
def mdirty(self):
return self.subs["mdirty"]
@property
def midi(self):
return self.subs["midi"]
@property
def ldirty(self):
return self.subs["ldirty"]
def get(self) -> list:
return [k for k, v in self.subs.items() if v]
def any(self) -> bool:
return any(self.subs.values())
def add(self, event):
self.subs[event] = True
self.info(f"{event} added to")
def remove(self, event):
self.subs[event] = False
self.info(f"{event} removed from")