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

Added ability to mute a synth/sound after it was triggered #975

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

klibardi
Copy link

@klibardi klibardi commented Mar 4, 2024

I would like to introduce an ability to control synth or sample after it was triggered. For now I just need the ability to mute, but I am open to implementing control over other aspects of sound too.

Here is an example of what I'm using this for:

await WebMidi.enable()
const myInput = WebMidi.inputs[0];
const noteControls = Array.from(Array(128)).map(x => null)
myInput.removeListener('noteon');
myInput.removeListener('noteoff');
myInput.addListener('noteon', e => {
  const [n, vel] = e.dataBytes;
  superdough({ note: n, s: 'piano', postgain: vel / 127 }, 0.05, 10).then(function (x) {
    noteControls[n] = x;
  });
});
myInput.addListener('noteoff', e => {
  const [note] = e.dataBytes;
  const { mute } = noteControls[note]
  mute(0.1);
  noteControls[note] = null
})

sound("metal casio casio casio")

@klibardi
Copy link
Author

klibardi commented Mar 4, 2024

Just a link for reference of what I'd like to accomplish in the long run:
https://club.tidalcycles.org/t/baked-in-support-for-midi-in-audio-in-and-audio-devices-channels/5098

@felixroos
Copy link
Collaborator

thanks! this looks useful, tho it might be limiting in the context of note in, because superdough currently does not support triggering the attack / decay phase without knowing the total duration, so as you did, you need to set duration to a high number, meaning you could theoretically run out of time.. This used to work before this PR, where the envelope was returning a stop function, which turned out to impractical due to browser differences as outlined here.

The idea we had to fix this was to write a custom envelope with an audio worklet that supports the desired behavior.
It might still make sense to merge this, as it provides pragmatic workaround to the problem. @Jader what do you think?

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

Successfully merging this pull request may close these issues.

None yet

3 participants