Skip to content

🧹 Refactor instruments to use BaseSynth abstract class#82

Open
Pitrat-wav wants to merge 1 commit intomainfrom
refactor-synth-base-class-4338946224554170690
Open

🧹 Refactor instruments to use BaseSynth abstract class#82
Pitrat-wav wants to merge 1 commit intomainfrom
refactor-synth-base-class-4338946224554170690

Conversation

@Pitrat-wav
Copy link
Owner

This PR introduces a major architectural improvement by consolidating common instrument logic into a new BaseSynth abstract class.

Key Changes:

  • New BaseSynth Class: Provides a unified interface for all instruments, including:
    • initialized state tracking.
    • Standardized outputGain node (supporting both Tone.Volume and Tone.Gain).
    • setVolume(db: number) with smooth rampTo interpolation to prevent audible clicks.
    • dispose() method for cascading resource cleanup.
  • Instrument Refactoring: AcidSynth, FMBass, HarmSynth, PadSynth, DrumMachine, and SamplerInstrument now inherit from BaseSynth. Internal Tone.js nodes are lazily initialized via a standardized init() method.
  • Initialization Synchronization: Updated audioStore.ts to call init() for all instruments during the main audio setup, ensuring that outputGain nodes are ready before they are wired to the mixer channels.
  • Consistent API: Consumers like GlobalSequencer.ts now interact with instruments through a more predictable and type-safe API, replacing direct property mutations with base class methods.

Benefits:

  • Reduced Duplication: Eliminates repetitive boilerplate for volume, init-flags, and disposal.
  • Audio Quality: Standardizes the use of parameter ramping for volume changes.
  • Maintainability: Makes it significantly easier to implement new instruments by following the BaseSynth contract.
  • Memory Management: Ensures consistent disposal of audio nodes across all instrument types.

PR created automatically by Jules for task 4338946224554170690 started by @Pitrat-wav

- Created BaseSynth abstract class in src/logic/BaseSynth.ts
- Refactored AcidSynth, FMBass, HarmSynth, PadSynth, DrumMachine, and SamplerInstrument to extend BaseSynth
- Standardized initialization (init method), volume management (setVolume with rampTo), and disposal logic
- Updated audioStore.ts to ensure instruments are initialized before connection
- Updated GlobalSequencer.ts to use standardized setVolume method
- Improved type safety and reduced code duplication across instrument logic

Co-authored-by: Pitrat-wav <255843145+Pitrat-wav@users.noreply.github.com>
@google-labs-jules
Copy link

👋 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.

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