// What the renderer does with a note's clip BEFORE it decides how to change it: // how long the clip may sound in its slot, and the pitch it measures off the // part that will sound. reuse-pass.mjs has to ask the same two questions to say // "this um can play as it was said", and an answer of its own would drift from // the renderer's -- the way the review page's clip window once did (clipwindow.mjs). import { regionPitch, midiOf } from "./pitch.mjs"; // Samples a note's clip may fill. A filling voice (the melody) takes its slot; an // accompaniment voice plays its natural length and stops. export function noteMaxLen(fill, p, sr) { return Math.round((fill ? p.slotDur * 0.97 : Math.min(p.slotDur * 0.97, p.noteDur * 1.15)) * sr); } // The pitch of the part of `raw` that sounds when it may fill `maxLen` samples. export function headPitch(raw, maxLen, sr) { const keep = Math.min(raw.length, maxLen); return regionPitch(raw, Math.round(0.01 * sr), Math.max(Math.round(0.02 * sr), keep - 1), sr, 55, 260); } // Semitones from the sounding part of `raw` up to `targetMidi`; null when no pitch // could be measured, or the measurement is too far off to be the same note. export function headShift(raw, maxLen, sr, targetMidi) { const head = headPitch(raw, maxLen, sr); if (!(head.f0 > 0)) return null; const s = targetMidi - midiOf(head.f0); return Math.abs(s) <= 14 ? s : null; }