Rename MainTriggerConfig.post to post_trigger (#223)

pull/357/head
nyanpasu64 2019-03-08 21:03:32 -08:00
rodzic 97cac7706d
commit adaa629828
3 zmienionych plików z 19 dodań i 22 usunięć

Wyświetl plik

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
from contextlib import ExitStack, contextmanager from contextlib import ExitStack, contextmanager
from enum import unique, Enum from enum import unique
from fractions import Fraction from fractions import Fraction
from pathlib import Path from pathlib import Path
from types import SimpleNamespace from types import SimpleNamespace
from typing import Iterator from typing import Iterator
from typing import Optional, List, Union, Callable, cast from typing import Optional, List, Callable, cast
import attr import attr
@ -16,7 +16,6 @@ from corrscope.config import KeywordAttrs, DumpEnumAsStr, CorrError, with_units
from corrscope.layout import LayoutConfig from corrscope.layout import LayoutConfig
from corrscope.renderer import MatplotlibRenderer, RendererConfig, Renderer from corrscope.renderer import MatplotlibRenderer, RendererConfig, Renderer
from corrscope.triggers import ( from corrscope.triggers import (
MainTriggerConfig,
CorrelationTriggerConfig, CorrelationTriggerConfig,
PerFrameCache, PerFrameCache,
CorrelationTrigger, CorrelationTrigger,
@ -118,9 +117,8 @@ def default_config(**kwargs) -> Config:
edge_strength=2, edge_strength=2,
responsiveness=0.5, responsiveness=0.5,
buffer_falloff=0.5, buffer_falloff=0.5,
pitch_tracking=SpectrumConfig() pitch_tracking=SpectrumConfig(),
# Removed due to speed hit. # post_trigger=ZeroCrossingTriggerConfig(),
# post=LocalPostTriggerConfig(strength=0.1),
), ),
channels=[], channels=[],
layout=LayoutConfig(orientation="v", ncols=1), layout=LayoutConfig(orientation="v", ncols=1),

Wyświetl plik

@ -44,8 +44,7 @@ class MainTriggerConfig(_TriggerConfig, KeywordAttrs, always_dump="edge_directio
edge_direction: int = 1 edge_direction: int = 1
# Optional trigger for postprocessing # Optional trigger for postprocessing
# TODO rename to post_trigger post_trigger: Optional["PostTriggerConfig"] = None
post: Optional["PostTriggerConfig"] = None
post_radius: Optional[int] = 3 post_radius: Optional[int] = 3
@property @property
@ -59,17 +58,17 @@ class MainTriggerConfig(_TriggerConfig, KeywordAttrs, always_dump="edge_directio
if self.edge_direction not in [-1, 1]: if self.edge_direction not in [-1, 1]:
raise CorrError(f"{obj_name(self)}.edge_direction must be {{-1, 1}}") raise CorrError(f"{obj_name(self)}.edge_direction must be {{-1, 1}}")
if self.post: if self.post_trigger:
self.post.parent = self self.post_trigger.parent = self
if self.post_radius is None: if self.post_radius is None:
name = obj_name(self) name = obj_name(self)
raise CorrError( raise CorrError(
f"Cannot supply {name}.post without supplying {name}.post_radius" f"Cannot supply {name}.post_trigger without supplying {name}.post_radius"
) )
class PostTriggerConfig(_TriggerConfig, KeywordAttrs): class PostTriggerConfig(_TriggerConfig, KeywordAttrs):
parent: MainTriggerConfig = attr.ib(init=False) parent: MainTriggerConfig = attr.ib(init=False) # TODO Unused
pass pass
@ -132,10 +131,10 @@ class MainTrigger(_Trigger, ABC):
self._wave.amplification *= self.cfg.edge_direction self._wave.amplification *= self.cfg.edge_direction
cfg = self.cfg cfg = self.cfg
if cfg.post: if cfg.post_trigger:
# Create a post-processing trigger, with narrow nsamp and stride=1. # Create a post-processing trigger, with narrow nsamp and stride=1.
# This improves speed and precision. # This improves speed and precision.
self.post = cfg.post(self._wave, cfg.post_nsamp, 1, self._fps) self.post = cfg.post_trigger(self._wave, cfg.post_nsamp, 1, self._fps)
else: else:
self.post = None self.post = None

Wyświetl plik

@ -76,9 +76,9 @@ def test_trigger(cfg: CorrelationTriggerConfig):
plt.show() plt.show()
@parametrize("post", [None, ZeroCrossingTriggerConfig()]) @parametrize("post_trigger", [None, ZeroCrossingTriggerConfig()])
def test_post_stride(post): def test_post_stride(post_trigger):
cfg = cfg_template(post=post) cfg = cfg_template(post_trigger=post_trigger)
wave = Wave("tests/sine440.wav") wave = Wave("tests/sine440.wav")
iters = 5 iters = 5
@ -90,7 +90,7 @@ def test_post_stride(post):
for i in range(1, iters): for i in range(1, iters):
offset = trigger.get_trigger(x0, cache) offset = trigger.get_trigger(x0, cache)
if not cfg.post: if not cfg.post_trigger:
assert (offset - x0) % stride == 0, f"iteration {i}" assert (offset - x0) % stride == 0, f"iteration {i}"
assert abs(offset - x0) < 10, f"iteration {i}" assert abs(offset - x0) < 10, f"iteration {i}"
@ -100,9 +100,9 @@ def test_post_stride(post):
assert abs(offset - x0) <= 2, f"iteration {i}" assert abs(offset - x0) <= 2, f"iteration {i}"
@parametrize("post", [None, ZeroCrossingTriggerConfig()]) @parametrize("post_trigger", [None, ZeroCrossingTriggerConfig()])
@parametrize("double_negate", [False, True]) @parametrize("double_negate", [False, True])
def test_trigger_direction(post, double_negate): def test_trigger_direction(post_trigger, double_negate):
""" """
Right now, MainTrigger is responsible for negating wave.amplification Right now, MainTrigger is responsible for negating wave.amplification
if edge_direction == -1. if edge_direction == -1.
@ -114,9 +114,9 @@ def test_trigger_direction(post, double_negate):
if double_negate: if double_negate:
wave.amplification = -1 wave.amplification = -1
cfg = cfg_template(post=post, edge_direction=-1) cfg = cfg_template(post_trigger=post_trigger, edge_direction=-1)
else: else:
cfg = cfg_template(post=post) cfg = cfg_template(post_trigger=post_trigger)
trigger = cfg(wave, 100, 1, FPS) trigger = cfg(wave, 100, 1, FPS)
cfg.edge_direction = None cfg.edge_direction = None