Skip to content

Commit

Permalink
add new modulation types for FMX and Analog Generator osc2
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewryanscott committed Nov 25, 2024
1 parent 97875e0 commit c3783ea
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 342 deletions.
4 changes: 4 additions & 0 deletions specs/fileformat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,8 @@ module_types:
"max": 4
"bitwise_and": 5
"bitwise_xor": 6
"min_abs": 7
"max_abs": 8
controllers:
- volume: { min: 0, max: 256, default: 80 }
- waveform: { enum: Waveform, default: "triangle" }
Expand Down Expand Up @@ -1474,6 +1476,8 @@ module_types:
"bitwise_and": 7
"bitwise_xor": 8
"phase_plus": 9
"min_abs": 10
"max_abs": 11
Op1OutputMode:
"none": 0
"to_output": 1
Expand Down
2 changes: 2 additions & 0 deletions src/python/rv/modules/base/analoggenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Osc2Mode(IntEnum):
max = 4
bitwise_and = 5
bitwise_xor = 6
min_abs = 7
max_abs = 8

volume = Controller((0, 256), 80)
waveform = Controller(Waveform, Waveform.triangle)
Expand Down
2 changes: 2 additions & 0 deletions src/python/rv/modules/base/fmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class ModulationType(IntEnum):
bitwise_and = 7
bitwise_xor = 8
phase_plus = 9
min_abs = 10
max_abs = 11

class Op1OutputMode(IntEnum):
none = 0
Expand Down
2 changes: 2 additions & 0 deletions src/ts/modtypes/analogGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export namespace AnalogGenerator {
Max = 4,
BitwiseAnd = 5,
BitwiseXor = 6,
MinAbs = 7,
MaxAbs = 8,
}
export enum CtlNum {
Volume = 1,
Expand Down
2 changes: 2 additions & 0 deletions src/ts/modtypes/analogGeneratorEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ export enum Osc2Mode {
Max = 4,
BitwiseAnd = 5,
BitwiseXor = 6,
MinAbs = 7,
MaxAbs = 8,
}
2 changes: 2 additions & 0 deletions src/ts/modtypes/fmx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export namespace Fmx {
BitwiseAnd = 7,
BitwiseXor = 8,
PhasePlus = 9,
MinAbs = 10,
MaxAbs = 11,
}
export enum Op1OutputMode {
// noinspection JSUnusedGlobalSymbols
Expand Down
2 changes: 2 additions & 0 deletions src/ts/modtypes/fmxEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export enum ModulationType {
BitwiseAnd = 7,
BitwiseXor = 8,
PhasePlus = 9,
MinAbs = 10,
MaxAbs = 11,
}
export enum Op1OutputMode {
// noinspection JSUnusedGlobalSymbols
Expand Down
Binary file modified tests/files/analog-generator.sunsynth
Binary file not shown.
Binary file modified tests/files/fmx.sunsynth
Binary file not shown.
27 changes: 20 additions & 7 deletions tests/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ def test_files_path() -> Path:
@pytest.fixture
def read_write_read_synth(test_files_path):
def _read_write_read_synth(name: str) -> Synth:
synth = read_sunvox_file(test_files_path / f"{name}.sunsynth")
synth = read_sunvox_file(path := test_files_path / f"{name}.sunsynth")
f = BytesIO()
synth.write_to(f)
f.seek(0)
synth = read_sunvox_file(f)
synth.module.path = path # for inspecting original file as needed
return synth

return _read_write_read_synth
Expand Down Expand Up @@ -55,19 +56,31 @@ def _read_write_read_project(name: str, verbose=False) -> Project:

@pytest.fixture
def dump_on_failure():
"""Context manager useful for debugging test failures for module tests."""
"""
Context manager to print a hex dump of the module on failure.
Include the fixture and then use it like this:
with dump_on_failure(mod): # or mod.path to dump the original file
assert mod.custom_waveform.values == EXPECTED_CUSTOM_WAVEFORM
"""

@contextmanager
def _dump_on_failure(module: m.Module):
def _dump_on_failure(module: m.Module | Path):
try:
yield
except Exception:
from rv.lib.iff import dump_file

f = BytesIO()
synth = Synth(module)
synth.write_to(f)
f.seek(0)
if isinstance(module, m.Module):
f = BytesIO()
synth = Synth(module)
synth.write_to(f)
f.seek(0)
elif isinstance(module, Path):
f = module.open("rb")
else:
raise TypeError(f"Don't know how to dump {type(module)}")
dump_file(f)
raise

Expand Down
2 changes: 1 addition & 1 deletion tests/python/readwrite/synth/test_analog_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_analog_generator(read_write_read_synth):
assert mod.mode == mod.Mode.lq
assert mod.noise == 9
assert mod.osc2_volume == 20640
assert mod.osc2_mode == mod.Osc2Mode.mul
assert mod.osc2_mode == mod.Osc2Mode.max_abs
assert mod.osc2_phase == 0

assert mod.volume_envelope_scaling_per_key
Expand Down
Loading

0 comments on commit c3783ea

Please sign in to comment.