From 4b394ab4654036cc81c0a5a49f258c6a363b9f37 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Tue, 22 Jan 2019 22:12:35 -0800 Subject: [PATCH] Add stereo options to GUI --- corrscope/gui/__init__.py | 28 ++++++++++++++++++++++++---- corrscope/gui/data_bind.py | 16 +++++++++++----- corrscope/gui/mainwindow.ui | 29 +++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/corrscope/gui/__init__.py b/corrscope/gui/__init__.py index f09fb36..d7047d5 100644 --- a/corrscope/gui/__init__.py +++ b/corrscope/gui/__init__.py @@ -1,10 +1,9 @@ import functools -import os import sys import traceback from pathlib import Path from types import MethodType -from typing import Type, Optional, List, Any, Tuple, Callable, Union +from typing import Type, Optional, List, Any, Tuple, Callable, Union, Dict import PyQt5.QtCore as qc import PyQt5.QtWidgets as qw @@ -26,6 +25,7 @@ from corrscope.gui.data_bind import ( behead, rgetattr, rsetattr, + Symbol, ) from corrscope.gui.history_file_dlg import ( get_open_file_name, @@ -37,6 +37,7 @@ from corrscope.outputs import IOutputConfig, FFplayOutputConfig, FFmpegOutputCon from corrscope.settings import paths from corrscope.triggers import CorrelationTriggerConfig, ITriggerConfig from corrscope.util import obj_name +from corrscope.wave import Flatten FILTER_WAV_FILES = ["WAV files (*.wav)"] @@ -627,13 +628,32 @@ def path_fix_property(path: str) -> property: return property(getter, setter) +flatten_modes = { + Flatten.SumAvg: "Average: (L+R)/2", + Flatten.DiffAvg: "DiffAvg: (L-R)/2", + Flatten.Sum: "Sum: (L+R)", + Flatten.Diff: "Difference: (L-R)", + Flatten.Stereo: "Stereo (broken)", +} +assert set(flatten_modes.keys()) == set(Flatten.modes) + +flatten_symbols = list(flatten_modes.keys()) +flatten_text = list(flatten_modes.values()) + + class ConfigModel(PresentationModel): cfg: Config - combo_symbols = {} - combo_text = {} + combo_symbols: Dict[str, List[Symbol]] = {} + combo_text: Dict[str, List[str]] = {} master_audio = path_fix_property("master_audio") + # Stereo flattening + for path in ["trigger_stereo", "render_stereo"]: + combo_symbols[path] = flatten_symbols + combo_text[path] = flatten_text + del path + render__bg_color = color2hex_property("render__bg_color") render__init_line_color = color2hex_property("render__init_line_color") render__grid_color = color2hex_maybe_property("render__grid_color") diff --git a/corrscope/gui/data_bind.py b/corrscope/gui/data_bind.py index e1d96c1..89e43be 100644 --- a/corrscope/gui/data_bind.py +++ b/corrscope/gui/data_bind.py @@ -1,6 +1,6 @@ import functools import operator -from typing import Optional, List, Callable, Dict, Any, ClassVar, TYPE_CHECKING +from typing import Optional, List, Callable, Dict, Any, ClassVar, TYPE_CHECKING, Union from PyQt5 import QtWidgets as qw, QtCore as qc from PyQt5.QtCore import pyqtSlot @@ -13,6 +13,9 @@ from corrscope.util import obj_name, perr if TYPE_CHECKING: from corrscope.gui import MainWindow + from enum import Enum + + assert Enum __all__ = ["PresentationModel", "map_gui", "behead", "rgetattr", "rsetattr"] @@ -20,6 +23,9 @@ __all__ = ["PresentationModel", "map_gui", "behead", "rgetattr", "rsetattr"] WidgetUpdater = Callable[[], None] +Symbol = Union[str, "Enum"] + + class PresentationModel(qc.QObject): """ Key-value MVP presentation-model. @@ -30,7 +36,7 @@ class PresentationModel(qc.QObject): # These fields are specific to each subclass, and assigned there. # Although less explicit, these can be assigned using __init_subclass__. - combo_symbols: Dict[str, List[str]] + combo_symbols: Dict[str, List[Symbol]] combo_text: Dict[str, List[str]] edited = qc.pyqtSignal() @@ -202,8 +208,8 @@ class BoundDoubleSpinBox(qw.QDoubleSpinBox, BoundWidget): class BoundComboBox(qw.QComboBox, BoundWidget): - combo_symbols: List[str] - symbol2idx: Dict[str, int] + combo_symbols: List[Symbol] + symbol2idx: Dict[Symbol, int] # noinspection PyAttributeOutsideInit def bind_widget(self, model: PresentationModel, path: str) -> None: @@ -222,7 +228,7 @@ class BoundComboBox(qw.QComboBox, BoundWidget): BoundWidget.bind_widget(self, model, path) # combobox.index = pmodel.attr - def set_gui(self, symbol: str): + def set_gui(self, symbol: Symbol): combo_index = self.symbol2idx[symbol] self.setCurrentIndex(combo_index) diff --git a/corrscope/gui/mainwindow.ui b/corrscope/gui/mainwindow.ui index b27e4f5..04d49f5 100644 --- a/corrscope/gui/mainwindow.ui +++ b/corrscope/gui/mainwindow.ui @@ -245,6 +245,35 @@ + + + + Stereo Downmixing + + + + + + Trigger Stereo + + + + + + + + + + Render Stereo + + + + + + + + +