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

Holiday Hacking 1: Architecture: Flatten key press handling #83

Merged
merged 8 commits into from
Jan 2, 2024

Conversation

juleskers
Copy link
Collaborator

@juleskers juleskers commented Dec 1, 2023

Hi @nicolasbrailo , hi @pserwylo ,

I hope your lead-up to the holiday season is going well!
I've scraped some free time together to play more with PianOli in my own holiday prep 👼

This is a big architecture decoupling: disentangling the key-press handling into some semblance of "architecture", via a new PianoListener interface.
The new interface is implemented by everything that responds to key-presses, which includes the 'old' PianoCanvas and AppConfigTrigger, as well as newly-extracted stuff (see below)
This turns the up-and-down calling from PianoCanvas->Piano->PianoCanvas->AppConfigTrigger into one 'flat' listener-loop in Piano, with some new tests that guarantee that Piano calls its listeners.

Given that new Listener-infrastructure, I could finally realize my long-held wish of ridding Piano of all Android-Context.
It's now the pure "geometry-only" thing I envisioned.
I've achieved this by disentangling the note-playing from the melody-handling (see the KeySoundMaker and SoundSet classes), which I personally think makes it easier to grok.
It definitely makes it easier to test!

I think this is best reviewed commit-by-commit, since that tells the "story" of the refactoring better.
That story was written over several evenings, so sometimes I needed multiple steps to reach a sane end-state.

Jules Kerssemakers added 8 commits December 1, 2023 15:33
- Rely on default init values
- Deduplicate range check
The hub itself shouldn't implement its own listener-interface, to avoid
infititely-recursive triggers, so un-implement PianoListener, and rename the
'onKey*'-methods to 'doKey*' to signal their importance.
…ic helpers.

The old `SOUNDSET_DIR_PREFIX` already indicated in its name it wanted to live
in a SoundSet class.
Additionally, it's not just for DIRs, since it's also (ab?)used to get at the
translation keys.
As such, move the prefix to SoundSet, and isntead use SoundSet helpers
everywhere the prefix is currently used.

Also, the SoundSet class, which is already handling the raw folder access,
is a far better candidate for scanning that folder, than the current SettingsFragment.
An interface for something with only one sane implementation (SampledSoundSet)
might seem like overkill, but this allows us to write tests without adding
a dependency on a mocking framework, which would be worse overkill.
…istener.

Move the last context-awareness out of piano, by converting `play_sound()`,
including all its supporting infrastructure, to external PianoListener.

Rather than one single, complex Melody-Preference-checking Listener,
use a strategy pattern with two simple listeners:
 - one for 'normal' behaviour: StraightKeySoundMaker
 - one for melodies: MelodicKeySoundMaker

Choose which one to listen with only once during piano-init, rather than
checking melody-not-null on every key-press.
It was getting cluttered in the main package.
@juleskers juleskers self-assigned this Dec 1, 2023
@juleskers juleskers changed the title Architecture: Flatten key press handling Holiday Hacking 1: Architecture: Flatten key press handling Dec 16, 2023
@pserwylo
Copy link
Collaborator

Awesome. I've been putting this off as I worked on separate projects over the past several weeks, but over the next few days I'll review these changes.

I'm looking forward to this one, because I am keen to have the preferences screen "Theme chooser" actually render a small piano for each theme. However when I looked at the rendering code, I also noticed the Piano / PianoCanvas / AppConfigTrigger issue which makes it hard to extract the rendering code. I then noticed the same thing when trying to resolve the "Touching the black key anywhere triggers settings" which you've eluded to elsewhere. Hopefully this tidies it all up a little.

Might take a few nights to review though.

Happy new year!

@juleskers
Copy link
Collaborator Author

juleskers commented Dec 31, 2023

Happy new year!
I'm typing this as the fireworks are going off outside my windows, so it feels extra apt 🎇🎆
(so I guess you're having lunch? Gotta love timezones!)

Take all the time you need. It took me many evenings to put together, so it should be normal that it takes multiple to review too. 💙

Copy link
Collaborator

@pserwylo pserwylo left a comment

Choose a reason for hiding this comment

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

Looks awesome from reading through. Will just give one quick test, and if all is good, will merge.

@pserwylo
Copy link
Collaborator

pserwylo commented Jan 2, 2024

On device test works well. Merging. Thanks!

@pserwylo pserwylo merged commit 88d4697 into master Jan 2, 2024
1 check passed
@juleskers juleskers deleted the flatten-key-press-handling branch January 2, 2024 12:23
juleskers pushed a commit that referenced this pull request Jan 2, 2024
juleskers pushed a commit that referenced this pull request Jan 2, 2024
juleskers pushed a commit that referenced this pull request Jan 2, 2024
juleskers pushed a commit that referenced this pull request Jan 2, 2024
juleskers pushed a commit to juleskers/PianOli that referenced this pull request Jan 2, 2024
juleskers pushed a commit to juleskers/PianOli that referenced this pull request Jan 3, 2024
juleskers pushed a commit to juleskers/PianOli that referenced this pull request Jan 3, 2024
@juleskers juleskers mentioned this pull request Jan 3, 2024
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.

2 participants