From 7e91d8b50cb3b86c39c0dfa324d7f2bd4846e870 Mon Sep 17 00:00:00 2001 From: John Kurkowski Date: Thu, 12 Dec 2024 19:01:00 -0800 Subject: [PATCH] WIP --- src/music/render/command.py | 17 +++++++++++++++-- src/music/render/process.py | 30 ++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/music/render/command.py b/src/music/render/command.py index 5d64984..47dcc4f 100644 --- a/src/music/render/command.py +++ b/src/music/render/command.py @@ -51,6 +51,15 @@ " SOUNDCLOUD_ADDITIONAL_HEADERS." ), ) +@click.option( + "--dry-run", + default=False, + help=( + "Whether to actually write changes to disk or upload, while still" + " performing the render." + ), + is_flag=True, +) @click.option( "--include-main", default=None, @@ -144,6 +153,7 @@ async def main( project_dirs: list[Path], additional_headers: str, + dry_run: bool, include_main: SongVersion | None, include_instrumental: SongVersion | None, include_instrumental_dj: SongVersion | None, @@ -191,6 +201,7 @@ async def main( command = _Command( parsed_additional_headers, + dry_run, oauth_token, upload, upload_existing, @@ -208,6 +219,7 @@ class _Command: """Wrap parsed command line arguments.""" additional_headers: dict[str, str] + dry_run: bool oauth_token: str upload: bool upload_existing: bool @@ -255,7 +267,7 @@ async def _render_project( renders = [] uploads = [] - if self.upload_existing: + if self.upload_existing and not self.dry_run: uploads.append( asyncio.create_task( self.upload_process.process( @@ -270,12 +282,13 @@ async def _render_project( async for _, render in self.render_process.process( project, *self.versions, + dry_run=self.dry_run, verbose=0, vocal_loudness_worth=self.vocal_loudness_worth, ): renders.append(render) - if self.upload and render.fil.is_file(): + if self.upload and render.fil.is_file() and not self.dry_run: uploads.append( asyncio.create_task( self.upload_process.process( diff --git a/src/music/render/process.py b/src/music/render/process.py index 46f2aec..b318b46 100644 --- a/src/music/render/process.py +++ b/src/music/render/process.py @@ -64,7 +64,7 @@ def _cmd_for_stats(fil: Path) -> list[str | Path]: async def render_version( - project: ExtendedProject, version: SongVersion + project: ExtendedProject, version: SongVersion, *, dry_run: bool ) -> RenderResult: """Trigger Reaper to render the current project audio. Returns the output file. @@ -95,10 +95,14 @@ async def render_version( else: tmp_fil = out_fil.with_stem(in_name) - rm_rf(out_fil) - shutil.move(tmp_fil, out_fil) + if dry_run: + final_fil = tmp_fil + else: + final_fil = out_fil + rm_rf(out_fil) + shutil.move(tmp_fil, out_fil) - return RenderResult(out_fil, datetime.timedelta(seconds=time_end - time_start)) + return RenderResult(final_fil, datetime.timedelta(seconds=time_end - time_start)) def trim_silence(fil: Path) -> None: @@ -202,6 +206,7 @@ async def process( self, project: ExtendedProject, *versions: SongVersion, + dry_run: bool, verbose: int, vocal_loudness_worth: float | None, ) -> AsyncIterator[tuple[SongVersion, RenderResult]]: @@ -224,7 +229,9 @@ async def process( results.append( ( SongVersion.MAIN, - lambda: _render_main(project, *vocals, verbose=verbose), + lambda: _render_main( + project, *vocals, dry_run=dry_run, verbose=verbose + ), self._add_task(project, SongVersion.MAIN), ) ) @@ -243,6 +250,7 @@ async def process( for track in [*vocals, *find_vox_tracks_to_mute(project)] if track ], + dry_run=dry_run, vocal_loudness_worth=vocal_loudness_worth, verbose=verbose, ), @@ -265,6 +273,7 @@ async def process( SongVersion.INSTRUMENTAL_DJ, project, *vocals, + dry_run=dry_run, vocal_loudness_worth=vocal_loudness_worth, verbose=verbose, ), @@ -278,6 +287,7 @@ async def process( SongVersion.ACAPPELLA, lambda: _render_a_cappella( project, + dry_run=dry_run, vocal_loudness_worth=vocal_loudness_worth, verbose=verbose, ), @@ -289,7 +299,9 @@ async def process( results.append( ( SongVersion.STEMS, - lambda: _render_stems(project, *vocals, verbose=verbose), + lambda: _render_stems( + project, *vocals, dry_run=dry_run, verbose=verbose + ), self._add_task(project, SongVersion.STEMS), ) ) @@ -349,11 +361,13 @@ async def _print_stats_for_render( before_stats = summary_stats_for_file(out_fil) if out_fil.is_file() else {} out = await render() after_stats = ( - summary_stats_for_file(out_fil, verbose=verbose) - if out_fil.is_file() + summary_stats_for_file(out.fil, verbose=verbose) + if out.fil.is_file() else {} ) + # TODO: cleanup + self.console.print(f"[b default]{name}[/b default]") self.console.print(f"[default dim italic]{out.fil}[/default dim italic]")