Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting ModuleParameterRanges is really hard! #445

Open
turian opened this issue Dec 22, 2023 · 0 comments
Open

Setting ModuleParameterRanges is really hard! #445

turian opened this issue Dec 22, 2023 · 0 comments

Comments

@turian
Copy link
Collaborator

turian commented Dec 22, 2023

So, let's say I want to make an LFO into a MultiVCO (see #442).

I want a higher frequency range:

new_freq_range = ModuleParameterRange(
            50.0,
            2006.0,
            curve=0.25,
            name="frequency",
            description="Frequency in Hz of oscillation",
        )

So how do I change the ModuleParameterRange for the LFO frequency?

class MultiVCOSynth(AbstractSynth):

def __init__(self, synthconfig: Optional[SynthConfig] = None):
    # Call the constructor in the parent AbstractSynth class
    super().__init__(synthconfig=synthconfig)
    
    # Add all the modules that we'll use for this synth
    self.add_synth_modules(
        [
            ("lfo", LFO),
        ]
    )
    
    # Do something here
    
def output(self) -> torch.Tensor:
    return self.lfo()

Okay, I see that each module has `parameter_ranges` so let me replace the one I want:
    for i, parameter_range in enumerate(self.lfo.parameter_ranges):
        if parameter_range.name == "frequency":
            self.lfo.parameter_ranges[i] = new_freq_range

Does not work, fails silently.

Oh, the module constructor has a dict, I should set that too:
    self.lfo._parameter_ranges_dict["frequency"] = new_freq_range

Does not work, fails silently.

Okay wait, the module_parameter range is put in the constructor of individual parameters. (This is annoying because then module.parameter_ranges and module._parameter_range_dict should be `__` private to discourage the sort of monkeying I just did.)

    self.lfo.get_parameter("frequency") = new_freq_range

Can't assign to a function call. Damn.

Okay, there are torchparameters:

    self.lfo.torchparameters["frequency"].range = new_freq_range

Does not work, fails silently.

At this point I give up because there are too many moving parts, and do the ugly thing I know will work:

At the TOP of my code I do this

from torchsynth.module import LFO

new_freq_range = ModuleParameterRange(
50.0,
2006.0,
curve=0.25,
name="frequency",
description="Frequency in Hz of oscillation",
)

for i, parameter_range in enumerate(LFO.default_ranges):
if parameter_range.name == "frequency":
LFO.default_ranges[i] = new_freq_range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant