Skip to content

Fix sustain key state lost after opening preferences#14

Merged
lrq3000 merged 2 commits intomasterfrom
fix-sustain-restore-3338882354673970821
Feb 5, 2026
Merged

Fix sustain key state lost after opening preferences#14
lrq3000 merged 2 commits intomasterfrom
fix-sustain-restore-3338882354673970821

Conversation

@lrq3000
Copy link
Owner

@lrq3000 lrq3000 commented Feb 5, 2026

Fixes an issue where the sustain key modifier's state was lost when opening the preferences menu and returning. The state is now saved in onPause and restored in onResume. Additionally, the visual state of the sustain key is updated if the keyboard is not fully reloaded.


PR created automatically by Jules for task 3338882354673970821 started by @lrq3000

Summary by CodeRabbit

Bug Fixes

  • Fixed sustain key state not persisting when pausing and resuming the app. The sustain effect now correctly maintains its state across app lifecycle transitions.

The sustain key state was being reset when navigating to the preferences menu because onPause calls cleanStates(), which stops all keys, including the sustain key (which resets the global sustain state).

This commit modifies Play.java to:
1. Save the global sustain state (HexKeyboard.mSustain) in onPause before calling cleanStates().
2. Restore the sustain state in onResume.
3. Manually update the visual state of the SustainKey in onResume if the keyboard was not reloaded (i.e., if no preferences were changed), ensuring the UI reflects the restored state.

Co-authored-by: lrq3000 <1118942+lrq3000@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Warning

Rate limit exceeded

@lrq3000 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Adds sustain state persistence to the Play activity by introducing two static boolean fields (savedSustainState and hasSavedSustainState) that capture sustain state during onPause and reapply it during onResume lifecycle events to synchronize the HexKeyboard and SustainKey UI components.

Changes

Cohort / File(s) Summary
Sustain State Persistence
StarChord/src/main/java/opensource/starchord/Play.java
Added two static boolean fields to persist sustain state across pause/resume lifecycle events. Added save logic in onPause and restoration logic in onResume to reapply sustain state to HexKeyboard and SustainKey when appropriate.

Sequence Diagram

sequenceDiagram
    participant Play as Play Activity
    participant HexKeyboard as HexKeyboard
    participant SustainKey as SustainKey
    
    rect rgba(100, 150, 200, 0.5)
    Note over Play: onPause() called
    Play->>Play: Save current sustain state<br/>to savedSustainState
    Play->>Play: Set hasSavedSustainState = true
    end
    
    rect rgba(150, 200, 100, 0.5)
    Note over Play: onResume() called
    Play->>HexKeyboard: Apply saved sustain state
    Play->>SustainKey: Re-press SustainKey<br/>(if conditions met)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit's note on sustain so sweet,
Through pause and play, the state's replete!
When life resumes, the chords ring true,
Saved sustain brings harmony anew! 🎵

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix sustain key state lost after opening preferences' directly and specifically summarizes the main change: saving and restoring sustain state to prevent data loss during preference menu interactions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-sustain-restore-3338882354673970821

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Previously, opening preferences or pausing the app would call `cleanStates()`, which stopped all keys including modifier keys, resetting their state.
This commit introduces `HexKeyboard.stopAllNotes()` which stops sound-producing keys but preserves the state of `ModifierKey`s (like Sustain).
`Play.cleanStates()` now calls `stopAllNotes()` instead of `stopAll()`.
This allows the sustain key to remain active when returning from the preferences menu, leveraging the existing persistence of the static `mKeys` array.

Co-authored-by: lrq3000 <1118942+lrq3000@users.noreply.github.com>
@lrq3000 lrq3000 merged commit b43c7d9 into master Feb 5, 2026
4 checks passed
@lrq3000 lrq3000 deleted the fix-sustain-restore-3338882354673970821 branch February 5, 2026 22:40
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.

1 participant