Composition Patterns¶
Purpose: How to compose AudioLab components together
Overview¶
Composition patterns show how to combine multiple components into larger systems. These are the "glue" patterns that make AudioLab flexible and modular.
Files¶
dependency_injection.hpp¶
Explicit dependency injection - No globals, no singletons
Pattern: Constructor injection Why: Testability, explicitness, thread-safety
Example:
class MyProcessor {
MyProcessor(
IEventDispatcher& events, // Injected
BufferPool& buffers // Injected
) : events_(events), buffers_(buffers) {}
};
Core Patterns¶
Pattern 1: Processor Chain¶
Compose multiple processors in series:
class ProcessorChain {
void add_processor(IAudioProcessor& processor);
void process(/*...*/); // Calls each processor in order
};
Pattern 2: Parameter Management¶
Centralized parameter handling:
class Processor {
Processor(IParameterManager& params) : params_(params) {
gain_param_ = params_.create_parameter("gain", 0.0f, 1.0f);
}
};
Pattern 3: Event Subscription¶
Loose coupling through events:
class Analyzer : public IEventListener<AudioBufferEvent> {
void on_event(const AudioBufferEvent& event) override {
// Analyze buffer
}
};
Remember: Favor composition over inheritance. Inject dependencies explicitly.