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

Add envelope generator script #259

Merged
merged 21 commits into from
Apr 20, 2023

Conversation

roryjamesallen
Copy link
Collaborator

@roryjamesallen roryjamesallen commented Apr 11, 2023

A simple envelope generator script:
din triggers an envelope (and sustains it if on asr mode)
k1 controls rise time
k2 controls fall time
ain is added to k2 to control fall time (i'm planning to allow ain to be routed to other parameters)
b1 changes mode between ar (Attack Release) and asr (Attack Sustain Release)
b2 changes mode between once and looping envelopes

The envelope is displayed as linear (currently) but the actual output is logarithmic, so works well for audio

@awonak
Copy link
Collaborator

awonak commented Apr 19, 2023

Don't forget to add your script to the central contrib readme!
https://github.com/Allen-Synthesis/EuroPi/blob/main/software/contrib/README.md

software/contrib/envelope_generator.py Outdated Show resolved Hide resolved
software/contrib/envelope_generator.py Outdated Show resolved Hide resolved
def update_display(self):
if ticks_ms() - self.last_refreshed_display >= self.display_refresh_rate:
#Save state to file
self.save_state()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] I would suggest instead moving this call closer to where the two state values change, inside change_sustain_mode() and change_looping_mode(). That will avoid unnecessary calls to save state when state has not changed. (I know PolyrhythmSeq sets a bad example, I need to fix that)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

oled.vline(self.envelope_display_bounds[0], self.envelope_display_bounds[1], self.envelope_display_bounds[3], 1)
oled.vline((self.envelope_display_bounds[2] - 1), self.envelope_display_bounds[1], self.envelope_display_bounds[3], 1)

try:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] Pro tip: you want to keep your try/except as tightly narrowed to the scope of where the exception is thrown. When you have this many lines inside of a try/except, you might have a line throw a ZeroDivisionError that you weren't expecting and that would hide the bug from you and make troubleshooting tricky. Additionally, it's not obvious to the reader where in this block the ZeroDivisionError might get thrown.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed! hopefully the code is more clear now

@awonak awonak merged commit 6d9f514 into Allen-Synthesis:main Apr 20, 2023
@roryjamesallen roryjamesallen deleted the add-envelope-generator branch April 27, 2023 09:32
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

2 participants