generated from pietschj/y4Project_repo
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Keyboard logic rework #1
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Why? - The previous logic was full of bugs 🐛🐛 - Most annoying of these was "sticky" keys - This was due to the event handling of web-audio-controls - As well as the nature of the focus event.. - So I needed to create global keyboard listening instead # New Logic - Computer keyboard now emulates MIDI - Each key is handled the same way - Works no matter what is focused on the page - Octave/detune controls now update notes in real-time - This fixes the sticky note bug! 😄 # Global Octave Modifier - GUI now includes global octave slider - This increases/decreases all octaves - Allowing for 4 extra octaves to be reached # Arpeggiator - Now 3xTone.Patterns, one per synth - GUI now includes ARP switches per-oscillator - As well as sliders for ARP controls - Tone.Transport now in use (no BPM adjust yet) # Extras / Other - TODO list updated - Code cleaned up & rearranged - SYNTH Object created for all stateful data - PRESET Object updated with new data - Key maps updated to C3 root note - Arpeggiator key maps added # Known Bugs 🐛 - Changing note modifiers with arpeggiator enabled - Preset loading doesn't work with arpeggiator or global octave - Activating old logic with mouse duplicates keys - Switching octaves while playing doesn't update GUI keys - Arpeggiator doesn't update GUI keys - Input boxes can't be typed in (likely due to preventDefault) - Large arp patterns can cause glitches - Quickly inputting Keydown-A->Keydown-B->Keyup-A glitches, causing a phantom Keydown-B to fire, which triggers an extra voice
# Apreggiator Bug - Changing note modifier while arp was enabled wasn't handled correctly - Now determines target arpeggiator & its state - Before running a minified startArp() and stopArp() - Allowing for note modification during arp playback # Extra - New stopArp() logic reduces possibility of sticky bugs # Known Bugs - Changing note modifiers per-oscillator can cause that arpeggiator to desync if playing
- Input boxes stopped working after new key logic was implemented - This was mainly due to preventDefault being applied to all key events - Another issue was notes triggering while typing in input boxes - Keyboard event listening is now disabled while inputs are focused
# Logic - Removed old GUI keyboard event listening logic - Replaced with slightly modified handleNote trigger - Over 100 lines of code reduced to three! # Variables - physicalKeyboardActive moved to SYNTH.STATE - octave / subOctave maps incremented by one # Other - Code rearranged - Old comments updated - New comments added
- Now using local script file instead of CDN URL - This is so I can edit the library to fix a bug
- Commented-out all relevant "keydown" event handling - This disables native keyboard events - Allowing my new logic to run without any conflicts
- This new control adjusts the Tone.Transport BPM - Allowing for the arpeggiator's base timing to be adjusted
# Extra / Other - Added/updated comments - Mostly fixed newly introduced BPM change bugs - These caused arpeggiators to break if changing while playing - Seems to work fine now, except for when double-key bug occurs - This is due to keysHeld ending up with an incorrect value - Started fixing, hence new lastEvents array - Will try to fix this for next commit, as it is the last major key bug
- It couldn't be bundled as it wasn't a module - So it had to be moved to /public
# The bug: - The sequence: keyDown_a->keyDown_b->keyUp_a - Would fire a phantom keyDown_b while held - Leading to two tones being audible instead of one - As well as bugs with keysHeld Tone.Transport logic # The fix: - Store last keyDown events in an array - Only fire keyDown logic if key does not exist in array - The event bug definitely still happens, but it doesn't affect the app anymore
- Renamed SYNTH.STATE.p5_enabled to SYNTH.STATE.enabled - Now only handles notes when synth state is enabled - Deactivates when returning to welcome screen - Then activates again without duplicating the p5 instance
- Now seamlessly switches between arp on/off states # Known bugs: - Aggressively toggling arp/osc switches while playing causes note duplication - Arrays look clean so it must be duplicate triggers - Will look into it!
- 65-key isn't a very common keyboard size... Oops! - 61-key is the usual size-up from a 49-key!
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
The previous logic was full of bugs 🐛🐛🐛
The most annoying of these was "sticky" keys, where notes would stay triggered when octave/detune was change while playing.
This was due to the webaudio-controls library event handling, as well as the nature of focus in the browser.
So I needed to create my own global keyboard listening instead, bypassing the native logic.
New Logic
Each input type now uses the same logic to cut down on duplicate code.
Each key on the computer keyboard acts like a MIDI keyboard key.
Keyboard listening is now active no matter what is focused on the page (except text inputs).
Octave/detune controls now update notes in real-time, no more sticky keys! 😄
Note: The webaudio-controls library had to be modified directly to deactivate the native keyboard logic.
Global Octave Modifier
MS24 now includes a global octave slider, positioned beside the GUI keyboard.
This increases/decreases all octaves at once, allowing for 4 extra octaves to be reached.
Arpeggiator
Arpeggiator functionality is now enabled!
This is done with three Tone.js Pattern Objects, one per synth.
GUI now includes switches for each oscillator's arpeggiator, as well as sliders for arp controls
Tone.Transport is now in use so that the arpeggiators have a timeline to play along.
GUI now includes a BPM knob beside the master gain knob, to adjust the Transport BPM.
Extras / Other
Loads of code cleaned up & rearranged.
Lots of comments added/updated.
GUI keyboard keys increased from 49 (4 octaves + 1 semitone) to 61 (5 octaves + 1 semitone).
Fixed double keyDown bug.
Known Bugs 🐛
While holding keys, if the octave is changed while the arp is off, and then arp is turned on, the arp will play the old octave.