Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
john-kurkowski committed Dec 13, 2024
1 parent 4466959 commit 7e91d8b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
17 changes: 15 additions & 2 deletions src/music/render/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -191,6 +201,7 @@ async def main(

command = _Command(
parsed_additional_headers,
dry_run,
oauth_token,
upload,
upload_existing,
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
30 changes: 22 additions & 8 deletions src/music/render/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]]:
Expand All @@ -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),
)
)
Expand All @@ -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,
),
Expand All @@ -265,6 +273,7 @@ async def process(
SongVersion.INSTRUMENTAL_DJ,
project,
*vocals,
dry_run=dry_run,
vocal_loudness_worth=vocal_loudness_worth,
verbose=verbose,
),
Expand All @@ -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,
),
Expand All @@ -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),
)
)
Expand Down Expand Up @@ -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]")

Expand Down

0 comments on commit 7e91d8b

Please sign in to comment.