2.6 KiB
chorus/schemas
(no submodules)
Purpose
Zod schemas validating the construction-time options and preset payload of ChorusPlugin. These run on the public boundary between user code and the plugin: any malformed object hitting the constructor or applyPreset is rejected with AUDIO_FX.INVALID_OPTIONS / AUDIO_FX.INVALID_PRESET before it can corrupt runtime state.
Separating schemas from the plugin module lets index.ts re-export them so callers can introspect the option surface (for forms, editors, RPC validation) without importing the audio implementation.
Features
ChorusPluginOptionsSchema— validates all five optional construction fields with their documented ranges (rate0.05..10 Hz,depth0..20 ms,feedback0..0.95,wet0..1,baseDelay5..30 ms).ChorusPresetDataSchema— empty strict object: the chorus has no plugin-specific preset payload, so any extra keys are rejected by.strict().- Both schemas use
z.number().finite()soNaNandInfinitycannot sneak through.
Usage: Basic Example
import { ChorusPluginOptionsSchema } from "@suaveplan/audio-fx-plugin-chorus";
const parsed = ChorusPluginOptionsSchema.parse({ initialWet: 0.4 });
Usage: Advanced Example
import {
ChorusPluginOptionsSchema,
ChorusPresetDataSchema,
} from "@suaveplan/audio-fx-plugin-chorus";
// Build a form from the schema's shape keys.
const fields = ChorusPluginOptionsSchema.keyof().options;
for (const field of fields) {
form.addRow(field);
}
// Reject foreign preset payloads at the IPC boundary before they
// reach the plugin.
function validateChorusPreset(blob: unknown): boolean {
return ChorusPresetDataSchema.safeParse(blob).success;
}
API Reference
ChorusPluginOptionsSchema: z.ZodObject<{ initialRateHz?, initialDepthMs?, initialFeedback?, initialWet?, initialBaseDelayMs? }>ChorusPresetDataSchema: z.ZodObject<{}, "strict">
Implementation Notes
The maximum feedback is 0.95, not 1.0. Allowing feedback at unity would create a marginally stable system whose output diverges for any non-zero input; clamping at 0.95 leaves enough headroom that even a noise-floor leak stays bounded over arbitrarily long renders. The test "max feedback over a long sine never produces non-finite samples" exercises this boundary.
ChorusPresetDataSchema is .strict() for the same reason as the other plugins: unknown fields almost always indicate a payload from a sibling plugin or a forwards-incompatible schema. Silent rejection at the boundary is much less harmful than partial application, which can leave the plugin in a half-restored state.