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

WIP: Event system #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

WIP: Event system #8

wants to merge 9 commits into from

Conversation

nwoeanhinnogaehr
Copy link
Owner

@nwoeanhinnogaehr nwoeanhinnogaehr commented Jan 23, 2021

I'm replacing the process function / hop based architecture with a new system that uses events. Events can be scheduled to occur at any time, can be repeated, and can be cancelled.

The following prints "Hello, world!" in 5 seconds time:

Def<> my_event;
my_event.run_fn([](){
    cout << "Hello, world!" << endl;
}).in(5_sec);

A familiar windowed time reversal effect can be written like so:

Def<int> reverser; // define an event type called reverser which takes an int parameter

reverser.cancel() // cancel any existing events in case of live editing
        .snd_fn([&](int k){ // define sound callback function
    reverser.in(k/2, k); // Schedule this event to repeat after k/2 samples.
    WaveBuf buf = get_input_back(0, k); // Read the previous k samples of input
    reverse(buf[0], buf[0]+buf.size*buf.num_channels); // Reverse it
    window_hann(buf);
    return buf;
}).in(0_sec, 256); // schedule the effect to start in 0 seconds from now, with parameter 256

All existing hacks can be easily converted to this new API, but it is significantly more flexible. For example there can be many different events generating audio in parallel, and there can be one-off events that transition to the next part of the song.

This still needs a lot more work, testing and refinement. WIP

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

1 participant