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

Modulators don't reconnect to samplers on resetNode() #57

Open
jamesstaub opened this issue Jan 8, 2024 · 2 comments
Open

Modulators don't reconnect to samplers on resetNode() #57

jamesstaub opened this issue Jan 8, 2024 · 2 comments

Comments

@jamesstaub
Copy link

I'm playing around with LFOs on __().sampler nodes within a __.loop. Since buffer nodes are recreated on each play modulators get disconnected after the first play, so you need something like this for it to work:

__().sampler({path:"/Sounds/various/gun-cock.wav",speed:1,start:0}).dac();
__().lfo({type:"sine",modulates:"speed",frequency:4, gain:.5})

__.loop(600,function(){
    __("sampler").stop()
    __('lfo').connect("sampler")
    __('lfo').start()
    __("sampler").start();
});

__.loop("start");

I'm wondering what it would take to get a script to work such that the LFO continues to modulate the sampler speed on each loop. eg.

__().sampler({path:"/Sounds/various/gun-cock.wav",speed:1,start:0}).dac();
__().lfo({type:"sine",modulates: "speed", frequency:40, gain:1}).connect('sampler').start()

__.loop(600,function(){
    __("sampler").stop().start()
});

__.loop("start");

In /src/create.js I see the this.resetNode method is designed to reconnect the sampler after each play. I'm wondering if it's possible to reconnect modulators here as well.

I don't know of a way to query the audio context for modulator connections on the node being reset, so perhaps it would require adding a reference to the modulator node's uuid on the sampler node when __().lfo({}).connect('sampler') is called.

maybe something like this could be added to resetNode method:

  for (var i = 0; i < this.connectedModulators.length; i++) {
      this.connect(connectedModulators[i]);
  }

I'm happy to try it out and make a PR, but I thought I'd run it by you to see if you have recommend other approaches or considerations.

@billorcutt
Copy link
Owner

billorcutt commented Jan 9, 2024

This is great, thanks! Your two line workaround would probably be fine for me, but if you'd like take this on, please do. We definitely reconnect modulators with other kinds of nodes so maybe have a look there for precedents. For example

__().lfo().sine().dac(.15);
__("sine,lfo").start();

__.loop(600,function(){
    __("sine").stop().start();
});

__.loop("start");

Something is reconnecting the modulator here. I'm a little rusty on the source so you'll have to find it, but would love to see your PR if you decide to tackle it.

@jamesstaub
Copy link
Author

jamesstaub commented Jan 9, 2024

Ah ok so it actually works fine when everything is connected in the same chain like your example. That's probably a fine work around for my use case but I'll still take a look and see if I can come up with something to support reconnecting modulators that are not instantiated as direct sibling nodes

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

2 participants