gibber-cc / gibberish

Fast, JavaScript DSP library that creates JIT optimized audio callbacks using code generation techniques
387 stars 35 forks source link

Generating sequences on the fly #32

Closed jreus closed 4 years ago

jreus commented 4 years ago

Hi Charlie, thank you for this wonderful work! I wasn't sure where the best place to contact you was..

I'm currently using gibberish in a new project where I need to do real-time pattern generation (kind of like a virtual environment with generative melodies that change depending on position and behavior). Is there an ideal way of doing this using gibberish? It seems like the sequencer objects are really focused on having a fixed, pre-determined sequence. And I can't seem to wrap my head around how the scheduler works...

charlieroberts commented 4 years ago

Hi Jonathan,

Best place for discussion is probably over in the toplap chat: https://chat.toplap.org/channel/gibber

But good question... this is a bit more difficult now that there's a separate audio thread. Basically you have to replace the entire values array of the sequencer; replacing an individual array member won't trigger the necessary inter-thread communication. So, for example:

syn = Synth()
seq = Sequencer.make( [220,440], [22050], syn, 'note' ).start()
// some time later
seq.values = [ 110,330,550,770 ]

You can do the same thing for seq.timings as well.

The scheduler is also trickier to deal with because it's running in the audio thread, but the basic idea is that when you add event to the schedule you're giving it a function to call in the future. If you can give me an idea of what you're trying to do I can try and give some hints...

jreus commented 4 years ago

thanks @charlieroberts ! I'm trying to make an interactive web-gl environment, kind of like a musical game... and I'd like to make user interactions schedule musical events on the fly (locked to a beat/tempo - but not looped indefinitely) ... maybe there's just a way of creating one-shot or x-loop sequences that I'm missing... anyway, I'm moving this over to toplap.

charlieroberts commented 4 years ago

For reference, conversation continues here: https://chat.toplap.org/channel/gibber?msg=4Weq2xd6eBMi8YtyP

Also, I added one-shot sequences (and a few other options for controlling playback) in 294a537202a411c72644aa3895af40093c96b34b