kopia lustrzana https://github.com/corrscope/corrscope
wip multithreading
rodzic
728e775ca0
commit
eb612a54fe
|
@ -6,6 +6,7 @@ from typing import Optional, List, Tuple, Union, cast, TypeVar
|
|||
import click
|
||||
|
||||
import corrscope
|
||||
import corrscope.settings.global_prefs as gp
|
||||
from corrscope.channel import ChannelConfig
|
||||
from corrscope.config import yaml
|
||||
from corrscope.corrscope import template_config, CorrScope, Config, Arguments
|
||||
|
@ -79,6 +80,7 @@ def get_file_stem(cfg_path: Optional[Path], cfg: Config, default: T) -> Union[st
|
|||
|
||||
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
||||
|
||||
|
||||
# fmt: off
|
||||
@click.command(context_settings=CONTEXT_SETTINGS)
|
||||
# Inputs
|
||||
|
@ -232,7 +234,13 @@ def main(
|
|||
outputs.append(cfg.get_ffmpeg_cfg(video_path))
|
||||
|
||||
if outputs:
|
||||
arg = Arguments(cfg_dir=cfg_dir, outputs=outputs)
|
||||
try:
|
||||
pref = gp.load_prefs()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pref = gp.GlobalPrefs()
|
||||
|
||||
arg = Arguments(cfg_dir=cfg_dir, outputs=outputs, parallel=pref.parallel)
|
||||
command = lambda: CorrScope(cfg, arg).play()
|
||||
if profile:
|
||||
first_song_name = Path(files[0]).name
|
||||
|
|
|
@ -6,6 +6,7 @@ from enum import unique
|
|||
from fractions import Fraction
|
||||
from pathlib import Path
|
||||
from typing import Iterator, Optional, List, Callable
|
||||
from multiprocessing.pool import Pool
|
||||
|
||||
import attr
|
||||
|
||||
|
@ -148,6 +149,7 @@ IsAborted = Callable[[], bool]
|
|||
class Arguments:
|
||||
cfg_dir: str
|
||||
outputs: List[outputs_.IOutputConfig]
|
||||
parallel: bool = False
|
||||
|
||||
on_begin: BeginFunc = lambda begin_time, end_time: None
|
||||
progress: ProgressFunc = lambda p: print(p, flush=True)
|
||||
|
@ -268,7 +270,8 @@ class CorrScope:
|
|||
benchmark_mode = self.cfg.benchmark_mode
|
||||
not_benchmarking = not benchmark_mode
|
||||
|
||||
with self._load_outputs():
|
||||
def play_impl():
|
||||
nonlocal end_frame
|
||||
prev = -1
|
||||
|
||||
# When subsampling FPS, render frames from the future to alleviate lag.
|
||||
|
@ -339,6 +342,12 @@ class CorrScope:
|
|||
end_frame = frame + 1
|
||||
break
|
||||
|
||||
with self._load_outputs():
|
||||
if self.arg.parallel:
|
||||
pass
|
||||
else:
|
||||
play_impl()
|
||||
|
||||
if PRINT_TIMESTAMP:
|
||||
# noinspection PyUnboundLocalVariable
|
||||
dtime_sec = time.perf_counter() - begin
|
||||
|
|
|
@ -185,8 +185,6 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
|
|||
prefs_error = None
|
||||
try:
|
||||
self.pref = gp.load_prefs()
|
||||
if not isinstance(self.pref, gp.GlobalPrefs):
|
||||
raise TypeError(f"prefs.yaml contains wrong type {type(self.pref)}")
|
||||
except Exception as e:
|
||||
prefs_error = e
|
||||
self.pref = gp.GlobalPrefs()
|
||||
|
@ -608,7 +606,10 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
|
|||
)
|
||||
|
||||
arg = Arguments(
|
||||
cfg_dir=self.cfg_dir, outputs=outputs, is_aborted=raise_exception
|
||||
cfg_dir=self.cfg_dir,
|
||||
outputs=outputs,
|
||||
parallel=self.pref.parallel,
|
||||
is_aborted=raise_exception,
|
||||
)
|
||||
return arg
|
||||
|
||||
|
|
|
@ -40,13 +40,19 @@ class GlobalPrefs(DumpableAttrs, always_dump="*"):
|
|||
else:
|
||||
return self.file_dir_ref
|
||||
|
||||
parallel: bool = True
|
||||
|
||||
|
||||
_PREF_PATH = paths.appdata_dir / "prefs.yaml"
|
||||
|
||||
|
||||
def load_prefs() -> GlobalPrefs:
|
||||
try:
|
||||
return yaml.load(_PREF_PATH)
|
||||
pref = yaml.load(_PREF_PATH)
|
||||
if not isinstance(pref, GlobalPrefs):
|
||||
raise TypeError(f"prefs.yaml contains wrong type {type(pref)}")
|
||||
return pref
|
||||
|
||||
except FileNotFoundError:
|
||||
return GlobalPrefs()
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue