Skip to content

Conversation

@gunjanghate
Copy link
Contributor

🎵 Summary of Changes

This PR adds Cmajor stored state synchronization for UI preferences, starting with the selected instrument.

Previously, only parameter values were persisted across plugin sessions in DAWs. With this PR, the selected instrument is now saved and restored automatically, allowing users to continue where they left off. The implementation is future-friendly additional UI state keys can be persisted with minimal effort.


🏷️ Type of Change

  • ✨ Feature enhancement
  • 🧪 Test improvements

💡 Motivation/Reason

Persisting only parameter data caused UI selections (like instrument choice) to reset every time a DAW session was reopened. This was frustrating and inconsistent with user expectations.

By syncing StoredStateStore ↔ PatchConnection stored state, we achieve session continuity, making the user experience more polished and professional.


🧪 Testing Done

  • ✅ All existing tests pass (npm test)
  • 🧪 Added StoredStateStore.test.tsx covering sync logic
  • 📨 Verified outbound delta sends via sendStoredStateValue
  • 🔄 Verified inbound updates via state_key_value listeners
  • 🚫 No breaking changes to existing functionality

🔗 Related Issues

Fixes #61


📝 Additional Notes

  • Falls back gracefully when no PatchConnection is present (e.g., dev mode / tests)
  • Silently ignores malformed full-state payloads to avoid breaking UX
  • Registered listeners only apply updates when values actually change
  • Internal ref avoids stale closure bugs in listener callbacks

📋 Checklist

  • 📖 I have read the contributing guidelines
  • 🌿 My code follows the project conventions
  • 💬 I have written clear commit messages
  • 🎯 This PR focuses on a single change

@lilyvanoekel
Copy link
Owner

@gunjanghate I'm running into an issue trying to test these changes. When running the patch with Cmajor: Run patch I get a black screen. Would you be able to have a look at it?

Screen.Recording.2025-10-01.at.4.39.00.PM.mov

@gunjanghate
Copy link
Contributor Author

Sure, will check this

@gunjanghate
Copy link
Contributor Author

Can you share logs or console output from Cmajor when the black screen appears?

@lilyvanoekel
Copy link
Owner

Can you share logs or console output from Cmajor when the black screen appears?

@gunjanghate unfortunately I've not been able to get any console output or other logs from cmajor. I think the best approach is to take it one step at a time and see where it breaks. Keep in mind you need to build the view with npm run build for any changes to affect the Cmajor panel in vscode.

@gunjanghate
Copy link
Contributor Author

image @lilyvanoekel The black screen issue is fixed now

@lilyvanoekel
Copy link
Owner

@gunjanghate thank you! I've tested it and it works for me as well. Could you clean up the PR a little? I think you can remove any console logs, maybe error handling could be simplified?

@gunjanghate gunjanghate changed the title feat(state): sync stored state with patch connection Connected view/src/StoredStateStore.tsx to patchConnection. Oct 3, 2025
@gunjanghate
Copy link
Contributor Author

gunjanghate commented Oct 3, 2025

@lilyvanoekel Check now !

@lilyvanoekel lilyvanoekel merged commit de1d6d8 into lilyvanoekel:main Oct 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connect view/src/StoredStateStore.tsx to patchConnection.

2 participants