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

Evaluate MIDI Track overlapping envelope issue, add a "re-trigger" toggle #1820

Open
ghost opened this issue Dec 27, 2021 · 5 comments
Open
Labels
good first contribution New developers can implement this task. to-do Accepted proposal that needs to be implemented.

Comments

@ghost
Copy link

ghost commented Dec 27, 2021

Just as an example, If you have a midi file in 4/4 with 4 consecutive C4 quarter notes and a non-zero attack, the value of the note resets to 0 before again rising in accordance with the interpolation of the attack. This is probably a good behavior to keep. However, if you map this value to a blender midi keyboard for example, the key jumps impossibly fast down before rising again. This behavior can be seen in many different ways when envelopes are overlapping.

In Ableton (as an example im familiar with) there is a parameter to toggle for things like this labelled as a "re-trigger". So if you have an LFO, and you don't retrigger, the lfo is global for all notes, if you do retrigger, the lfo restarts at t=0 for each new note. Maybe a "re-trigger" toggle can be added to this to determine if the interpolation happens with respect to the previous frames note or not? If re-trigger is 'on', that would correspond to the current "Evaluate MIDI Track" envelope behavior.

How does this sound?

@OmarEmaraDev
Copy link
Collaborator

I actually did wounder how this case of overlapping notes should be handled, I think adding an advanced option to choose the target behavior is reasonable and can be implemented.

@OmarEmaraDev OmarEmaraDev added good first contribution New developers can implement this task. to-do Accepted proposal that needs to be implemented. labels Dec 28, 2021
@ghost
Copy link
Author

ghost commented Dec 30, 2021

Great!

I might be able to work on this, I've never really done dev in python, but maybe I can stumble through it.

A couple questions, is there a rule in animation nodes that values are computed as demanded? If I plug frame number into evaluate midi track, with a retrigger, the only state required is the start and end time of the active note. Without retrigger, the state necessary can be many notes if there are many overlapping envelopes. One solution is to just lazy compute from first frame to current frame as values in a list, index with frame if its already computed, or add to list if not. If the retrigger is animated I guess any state can just be thrown out until retrigger is off again. Does this fit in with how animation nodes functions with state and how the evaluate function is called?

@OmarEmaraDev
Copy link
Collaborator

@fabricatedmath It is okay to do pre-evaluation caching in Animation Nodes, so we may do that. However, I would say that caching might not be worth it if the performance benefit is not significant, which might be the case since MIDI evaluation is already relatively fast. Moreover, note that frame numbers can be floats, which makes caching anything with them as keys less ideal.

If you are looking into possible optimizations, then doing a binary search over the notes is probably something that we can look into (We currently do a simple linear search).

Anyways, most of the code of interest is in the MIDITrack class. Let me know if you need anything.

@ghost
Copy link
Author

ghost commented Dec 30, 2021

@OmarEmaraDev Oh good to know frame number is a float I didn't realize that.

I guess we could cache the note value at each noteoff message seeing as that point should already store the state from all overlapped noteon messages before it, and then interpolate from there. But i'd bet that would be pretty easy to add after the code can evaluate the whole sequence up to frame N anyway.

Also, whats the workflow for an add-on like this? Is there an easy way to install the development add-on, change a .py file and try running something again?

Thanks!

@OmarEmaraDev
Copy link
Collaborator

@fabricatedmath In the source directory of Animation Nodes, create a conf.json file that points to the add-on directory of your Blender build as follows:

{
    "Copy Target" : "/home/omar/projects/blender/build/bin/3.1/scripts/addons",
}

Then execute the build setup script with the --copy flag as follows:

python setup.py build --copy --noversioncheck

Every time you change a file, you execute the above command and the add-on will be copied to Blender. Though you have to restart Blender for changes to take effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first contribution New developers can implement this task. to-do Accepted proposal that needs to be implemented.
Projects
None yet
Development

No branches or pull requests

1 participant