"""Tidewater Harp: a short D-major harp piece for an in-world harp (a friend's idea, 10-13 stream). 3/4 at 72 (eighths at 144), 34 bars + tail ~ 88 s, cut into three <30 s clips for SL sounds (mono, 44.1 kHz). Uses the stream-music synth (Karplus-Strong `pluck`). Claude Opus 5.5 (Tessel), 2026-10-13. local/hear-venv/Scripts/python.exe life/making/harp/harp_piece.py OUTDIR """ import sys, wave from pathlib import Path import numpy as np MUSIC = Path(__file__).resolve().parent.parent / "music" sys.path.insert(0, str(MUSIC)) import synth as S from synth import SR from pieces import Song import render CLIP = 29.9 def piece(): s = Song("Tidewater Harp", "D major", 144, bars=34, bpb=6, seed=88, tail=4.0, tempo="3/4, 72 bpm") s.cfg = {"harp": dict(gain=0, hp=60, hi=6000, send=0.4), "mel": dict(gain=2, hp=180, hi=7000, send=0.5), "sparkle": dict(gain=-8, hp=600, hi=8000, send=0.7)} s.reverb = {"rt60": 3.2, "wet": -8.0, "dark": 0.9} prog = ["D2 A2 D3 F#3 A3 D4", "C#2 A2 E3 A3 C#4 E4", "B1 F#2 B2 D3 F#3 B3", "G1 D2 G2 B2 D3 G3", "F#1 D2 A2 D3 F#3 A3", "G1 D2 B2 D3 G3 B3", "E2 B2 D3 G3 B3 D4", "A1 E2 G2 C#3 E3 A3"] roll = [0, 1, 2, 3, 4, 3] for bar in range(34): notes = prog[bar % 8].split() for e, i in enumerate(roll): v = 0.7 if e == 0 else 0.48 if e == 3 else 0.4 s.play("harp", S.pluck, bar, e, notes[i], 6 if e == 0 else 3, v, pan=(i - 2) * 0.1, ring=4.0, bright=0.55) if 20 <= bar < 28: # high glints over the middle section s.play("sparkle", S.pluck, bar, 5, notes[5], 3, 0.35, pan=0.3, ring=3.0, bright=0.7) s.play("sparkle", S.pluck, bar, 2, notes[4], 2, 0.3, pan=-0.3, ring=3.0, bright=0.7) A = "F#5:3 E5:1 D5:2 E5:4 C#5:2 D5:2 B4:2 F#4:2 G4:6 A4:2 D5:2 F#5:2 G5:3 F#5:1 E5:2 D5:2 B4:2 E5:2 A4:6" B = "B4:2 C#5:2 D5:2 E5:4 A4:2 F#5:3 E5:1 D5:2 B4:6 D5:2 E5:2 F#5:2 G5:2 F#5:2 E5:2 F#5:3 E5:1 C#5:2 D5:6" for bar, ph in [(4, A), (12, B), (26, A)]: s.line("mel", S.pluck, bar, ph, 0.62, pan=0.05, ring=3.2, bright=0.68) s.chord("harp", S.pluck, 34, 0, "D2 A2 D3 F#3 A3 D4 F#4 A4 D5", 12, 0.55, spread=0.06, ring=5.0, bright=0.55) return s def main(out): out = Path(out) out.mkdir(parents=True, exist_ok=True) s = piece() x, _ = render.mixdown(s) x = render.trim_tail(x) mono = x.mean(axis=0) mono *= 0.89 / np.abs(mono).max() n = int(CLIP * SR) clips = [mono[i:i + n] for i in range(0, len(mono), n)] for k, c in enumerate(clips): f = int(0.004 * SR) # tiny fades so the joins don't click c = c.copy() if k: c[:f] *= np.linspace(0, 1, f) if k < len(clips) - 1: c[-f:] *= np.linspace(1, 0, f) pcm = (np.clip(c, -1, 1) * 32767).round().astype("