Skip to content

Commit

Permalink
Require kwargs for anonymous numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
john-kurkowski committed Dec 12, 2024
1 parent 83c42ba commit 66a1b9d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
53 changes: 29 additions & 24 deletions src/music/render/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from .tracks import find_acappella_tracks_to_mute, find_stems, find_vox_tracks_to_mute


def summary_stats_for_file(fil: Path, verbose: int = 0) -> dict[str, float | str]:
def summary_stats_for_file(fil: Path, *, verbose: int = 0) -> dict[str, float | str]:
"""Print statistics for the given audio file, like LUFS-I and LRA."""
cmd = _cmd_for_stats(fil)
proc = subprocess.run(cmd, check=True, stderr=subprocess.PIPE, text=True)
Expand Down Expand Up @@ -135,18 +135,18 @@ def trim_silence(fil: Path) -> None:


async def _render_main(
project: ExtendedProject, vocals: reapy.core.Track | None, verbose: int
project: ExtendedProject, *vocals: reapy.core.Track, verbose: int
) -> RenderResult:
if vocals:
vocals.unsolo()
vocals.unmute()
for vocal in vocals:
vocal.unsolo()
vocal.unmute()
return await render_version(project, SongVersion.MAIN)


async def _render_version_with_muted_tracks(
version: Literal[SongVersion.INSTRUMENTAL, SongVersion.INSTRUMENTAL_DJ],
project: ExtendedProject,
tracks_to_mute: list[reapy.core.Track],
*tracks_to_mute: reapy.core.Track,
vocal_loudness_worth: float,
verbose: int,
) -> RenderResult:
Expand All @@ -159,6 +159,7 @@ async def _render_version_with_muted_tracks(

async def _render_a_cappella(
project: ExtendedProject,
*,
vocal_loudness_worth: float,
verbose: int,
) -> RenderResult:
Expand All @@ -176,12 +177,12 @@ async def _render_a_cappella(

async def _render_stems(
project: ExtendedProject,
vocals: reapy.core.Track | None,
*vocals: reapy.core.Track,
verbose: int,
) -> RenderResult:
if vocals:
vocals.unsolo()
vocals.unmute()
for vocal in vocals:
vocal.unsolo()
vocal.unmute()
for track in project.tracks:
track.unselect()
for track in find_stems(project):
Expand Down Expand Up @@ -210,9 +211,7 @@ async def process(
no output. For example, if a project does not have vocals, rendering an a
capella or instrumental version are skipped.
"""
vocals = next(
(track for track in project.tracks if track.name == "Vocals"), None
)
vocals = [track for track in project.tracks if track.name == "Vocals"]

if vocal_loudness_worth is None:
vocal_loudness_worth = float(
Expand All @@ -225,7 +224,7 @@ async def process(
results.append(
(
SongVersion.MAIN,
lambda: _render_main(project, vocals, verbose),
lambda: _render_main(project, *vocals, verbose=verbose),
self._add_task(project, SongVersion.MAIN),
)
)
Expand All @@ -239,13 +238,13 @@ async def process(
lambda: _render_version_with_muted_tracks(
SongVersion.INSTRUMENTAL,
project,
[
*[
track
for track in [vocals, *find_vox_tracks_to_mute(project)]
for track in [*vocals, *find_vox_tracks_to_mute(project)]
if track
],
vocal_loudness_worth,
verbose,
vocal_loudness_worth=vocal_loudness_worth,
verbose=verbose,
),
self._add_task(project, SongVersion.INSTRUMENTAL),
)
Expand All @@ -265,9 +264,9 @@ async def process(
lambda: _render_version_with_muted_tracks(
SongVersion.INSTRUMENTAL_DJ,
project,
[vocals],
vocal_loudness_worth,
verbose,
*vocals,
vocal_loudness_worth=vocal_loudness_worth,
verbose=verbose,
),
self._add_task(project, SongVersion.INSTRUMENTAL_DJ),
)
Expand All @@ -277,7 +276,11 @@ async def process(
results.append(
(
SongVersion.ACAPPELLA,
lambda: _render_a_cappella(project, vocal_loudness_worth, verbose),
lambda: _render_a_cappella(
project,
vocal_loudness_worth=vocal_loudness_worth,
verbose=verbose,
),
self._add_task(project, SongVersion.ACAPPELLA),
)
)
Expand All @@ -286,7 +289,7 @@ async def process(
results.append(
(
SongVersion.STEMS,
lambda: _render_stems(project, vocals, verbose),
lambda: _render_stems(project, *vocals, verbose=verbose),
self._add_task(project, SongVersion.STEMS),
)
)
Expand Down Expand Up @@ -343,7 +346,9 @@ 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) if out_fil.is_file() else {}
summary_stats_for_file(out_fil, verbose=verbose)
if out_fil.is_file()
else {}
)

self.console.print(f"[b default]{name}[/b default]")
Expand Down
4 changes: 3 additions & 1 deletion src/music/stat/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def main(files_or_project_dirs: list[Path], verbose: int) -> None:
print()
if len(files) > 1:
print(fil)
for k, v in music.render.process.summary_stats_for_file(fil, verbose).items():
for k, v in music.render.process.summary_stats_for_file(
fil, verbose=verbose
).items():
print(f"{k:<16}: {v:<32}")


Expand Down

0 comments on commit 66a1b9d

Please sign in to comment.