Skip to content

Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.

4.0 KB
Raw Blame
// ─────────────────────────────────────────────────────────────
// Canvix offline sound pack (the Sound wave) — 16 original
// synthesized effects in four categories, generated by
// scripts/gen-sfx-pack.mjs (pure DSP: oscillators, shaped noise,
// envelopes — NO samples, NO third-party recordings). The pack is
// therefore an original work of the Canvix project, released CC0
// (the licence manifest lives in docs/SOUND.md).
//
// Two consumers:
//   1. The Audio panel's Sound library — click to audition, insert
//      as a native audio element (rides the media store, autoplay
//      in preview/present, beat analysis and all).
//   2. Animation + page-transition SFX (`sfxId` on
//      ElementAnimation / PageTransition) — the same files played
//      by the preview/presenter playback engines.
//
// ids are stable API: documents reference them; renaming an id
// strands saved designs (sanitizeAnimation drops unknown ids).
// ─────────────────────────────────────────────────────────────

export type SfxCategory = 'transitions' | 'impacts' | 'ui' | 'musical'

export interface SfxDef {
  /** stable id — the file is /sfx/<id>.wav */
  id: string
  /** display label */
  label: string
  category: SfxCategory
  /** synthesized duration in seconds (informational) */
  seconds: number
  hint: string
}

export const SFX_CATEGORIES: Record<SfxCategory, string> = {
  transitions: 'Transitions',
  impacts: 'Impacts',
  ui: 'UI',
  musical: 'Musical',
}

export const SFX_PACK: SfxDef[] = [
  // transitions
  { id: 'whoosh-soft', label: 'Whoosh soft', category: 'transitions', seconds: 0.85, hint: 'Gentle page or section change' },
  { id: 'whoosh-fast', label: 'Whoosh fast', category: 'transitions', seconds: 0.45, hint: 'Quick swish between pages' },
  { id: 'swoosh-reverse', label: 'Swoosh reverse', category: 'transitions', seconds: 0.9, hint: 'Rising build-up before a reveal' },
  { id: 'slide-in', label: 'Slide in', category: 'transitions', seconds: 0.5, hint: 'Content sliding into place' },
  // impacts
  { id: 'pop', label: 'Pop', category: 'impacts', seconds: 0.14, hint: 'Light, playful entrance' },
  { id: 'thud', label: 'Thud', category: 'impacts', seconds: 0.35, hint: 'Soft heavy landing' },
  { id: 'boom', label: 'Boom', category: 'impacts', seconds: 0.9, hint: 'Big cinematic hit' },
  { id: 'impact-hit', label: 'Impact hit', category: 'impacts', seconds: 0.5, hint: 'Crisp punch with body' },
  // ui
  { id: 'click', label: 'Click', category: 'ui', seconds: 0.05, hint: 'Minimal UI tick' },
  { id: 'tick', label: 'Tick', category: 'ui', seconds: 0.03, hint: 'Even shorter tick' },
  { id: 'toggle', label: 'Toggle', category: 'ui', seconds: 0.14, hint: 'Two-stage switch' },
  { id: 'camera', label: 'Camera', category: 'ui', seconds: 0.16, hint: 'Shutter double-click' },
  // musical
  { id: 'chime', label: 'Chime', category: 'musical', seconds: 1.1, hint: 'Clean single ping' },
  { id: 'chime-sparkle', label: 'Chime sparkle', category: 'musical', seconds: 0.86, hint: 'Rising shimmer of pings' },
  { id: 'drum-kick', label: 'Drum kick', category: 'musical', seconds: 0.4, hint: 'Classic kick drum' },
  { id: 'hat', label: 'Hat', category: 'musical', seconds: 0.09, hint: 'Hi-hat tick' },
]

const SFX_IDS = new Set(SFX_PACK.map((s) => s.id))

/** Is `id` a known pack sound? (sanitizeAnimation + the player both gate on this) */
export function isSfxId(id: unknown): id is string {
  return typeof id === 'string' && SFX_IDS.has(id)
}

/** The public URL of a pack sound (same-origin, cacheable forever). */
export function sfxUrl(id: string): string {
  return `/sfx/${id}.wav`
}

/** Look up a definition by id (for labels/durations in the UI). */
export function sfxById(id: string): SfxDef | undefined {
  return SFX_PACK.find((s) => s.id === id)
}