Skip to content

Commit

Permalink
Generate multiple versions, rather than synchronously gathering them …
Browse files Browse the repository at this point in the history
…into a dict

Prepares for async render and upload.
  • Loading branch information
john-kurkowski committed Oct 28, 2023
1 parent 3e969df commit bdc3f32
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# music

Miscellaneous tasks for publishing my music.
Tasks for publishing my music.

The code is idiosyncratic with my music project conventions and therefore
applicable mainly to me. However, the code may be a useful example for using
Expand Down
15 changes: 9 additions & 6 deletions src/music/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,21 @@ def render(
if version
} or set(SongVersion)

renders = [
music.render.main(project, versions, vocal_loudness_worth, verbose=0)
for project in projects
]
renders = []

if not any(renders):
for project in projects:
for _, render in music.render.main(
project, versions, vocal_loudness_worth, verbose=0
):
renders.append(render)

if not renders:
raise click.UsageError("nothing to render")

if upload:
music.upload.main(
oauth_token,
[version.fil for render in renders for version in render.values()],
[render.fil for render in renders],
)


Expand Down
60 changes: 35 additions & 25 deletions src/music/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,52 +349,62 @@ def main(
versions: Collection[SongVersion],
vocal_loudness_worth: float,
verbose: int,
) -> dict[SongVersion, RenderResult]:
) -> Iterator[tuple[SongVersion, RenderResult]]:
"""Render the given versions of the given Reaper project.
Returns True if anything was rendered, False otherwise. For example, if a
project does not have vocals, rendering an a capella or instrumental
version are skipped.
Returns render results if anything was rendered. Skips versions that have
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)
did_something = False

rv: dict[SongVersion, RenderResult] = {}
vocals = next((track for track in project.tracks if track.name == "Vocals"), None)

if SongVersion.MAIN in versions:
rv[SongVersion.MAIN] = _print_stats_for_render(
project,
did_something = True
yield (
SongVersion.MAIN,
verbose,
lambda: _render_main(project, vocals, verbose),
_print_stats_for_render(
project,
SongVersion.MAIN,
verbose,
lambda: _render_main(project, vocals, verbose),
),
)

if SongVersion.INSTRUMENTAL in versions and vocals:
if rv:
if did_something:
print()
rv[SongVersion.INSTRUMENTAL] = _print_stats_for_render(
project,
did_something = True
yield (
SongVersion.INSTRUMENTAL,
verbose,
lambda: _render_instrumental(
_print_stats_for_render(
project,
cast(reapy.Track, vocals),
vocal_loudness_worth,
SongVersion.INSTRUMENTAL,
verbose,
lambda: _render_instrumental(
project,
cast(reapy.Track, vocals),
vocal_loudness_worth,
verbose,
),
),
)

if SongVersion.ACAPPELLA in versions and vocals:
if rv:
if did_something:
print()
rv[SongVersion.ACAPPELLA] = _print_stats_for_render(
project,
did_something = True
yield (
SongVersion.ACAPPELLA,
verbose,
lambda: _render_a_cappella(project, vocal_loudness_worth, verbose),
_print_stats_for_render(
project,
SongVersion.ACAPPELLA,
verbose,
lambda: _render_a_cappella(project, vocal_loudness_worth, verbose),
),
)

if rv:
if did_something:
# Render causes a project to have unsaved changes, no matter what. Save the user a step.
project.save()

return rv

0 comments on commit bdc3f32

Please sign in to comment.