Skip to content

Commit

Permalink
Merge pull request #59 from HEnquist/import_fix
Browse files Browse the repository at this point in the history
Import fix
  • Loading branch information
HEnquist authored Mar 9, 2024
2 parents 8ec286a + 34e0c20 commit 43b305c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
27 changes: 21 additions & 6 deletions backend/legacy_config_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ def _modify_devices(config):
Update the options in the devices section
"""
# New logic for setting sample format
dev = config["devices"]["capture"]
_modify_coreaudio_device(dev)
dev = config["devices"]["playback"]
_modify_coreaudio_device(dev)
if "devices" in config:
if "capture" in config["devices"]:
dev = config["devices"]["capture"]
_modify_coreaudio_device(dev)
if "playback" in config["devices"]:
dev = config["devices"]["playback"]
_modify_coreaudio_device(dev)

# Resampler
_modify_resampler(config)
# Resampler
_modify_resampler(config)


def _modify_coreaudio_device(dev):
Expand Down Expand Up @@ -114,11 +117,23 @@ def _modify_dither(config):
params["parameters"]["type"] = "Highpass"


def _fix_rew_pipeline(config):
if "pipeline" in config:
pipeline = config["pipeline"]
if isinstance(pipeline, dict) and "names" in pipeline and "type" in pipeline:
# This config was exported from REW.
# Convert `pipeline` to a list of steps instead of a single step,
# and add the missing `channel` attribute.
if "channel" not in pipeline:
pipeline["channel"] = 0
config["pipeline"] = [pipeline]

def migrate_legacy_config(config):
"""
Modifies an older config file to the latest format.
The modifications are done in-place.
"""
_fix_rew_pipeline(config)
_remove_volume_filters(config)
_modify_loundness_filters(config)
_modify_dither(config)
Expand Down
2 changes: 1 addition & 1 deletion backend/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = (2, 1, 0)
VERSION = (2, 1, 1)
14 changes: 14 additions & 0 deletions tests/test_legacy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,17 @@ def test_schema_validation(basic_config):
validator.validate_config(basic_config)
errors = validator.get_errors()
assert len(errors) == 0

def test_filters_only(basic_config):
# make a config containing only filters,
# to check that partial configs can be translated
filters_only = {"filters": basic_config["filters"]}
migrate_legacy_config(filters_only)
assert len(filters_only["filters"]) == 3

def test_rew_export(basic_config):
# REW exports a single pipeline step rather than a list.
# Check that this is handled ok.
basic_config["pipeline"] = basic_config["pipeline"][0]
migrate_legacy_config(basic_config)
assert len(basic_config["pipeline"]) == 1

0 comments on commit 43b305c

Please sign in to comment.