他の Nostr クライアント作者向け。投稿内の nostr:naddr... が曲や効果音パックを指していたら、生 JSON ではなく再生・試聴できるカードとして表示する方法をまとめた。形式そのものは曲仕様とパック仕様を参照。
For authors of other Nostr clients: how to render a nostr:naddr... quote that points to a song or sound pack as a playable/auditionable card instead of raw JSON. See the song spec and pack spec for the formats themselves.
naddr を通常どおり解決してイベントを取得したら、汎用の kind:30078 表示へ落とす前に次を判定する。
After resolving an naddr to an event as usual, check the following before falling back to generic kind:30078 rendering.
| kind | d | 表示Render as |
|---|---|---|
| 30078 | sfx-song/<name> | 曲カード(再生ボタン、タイトル、作者、BPM、長さ、トラック数、ループ)Song card (play button, title, author, BPM, duration, track count, loop) |
| 30078 | sfx-pack/<name> | パックカード(タイトル、作者、収録音数、波形、各音の試聴ボタン)Pack card (title, author, sound count, waveform, per-sound audition buttons) |
| その他anything else | — | 従来どおりExisting behavior |
直接表示、イベント詳細、返信プレビューなど、イベントを表示する場所では同じ分岐を使うと一貫する。カードの隅に sfx-song / sfx-pack とそのまま書くと、利用者が仕組みの名前を覚えやすい。
Use the same branch wherever events are shown (direct display, event details, reply previews) for consistency. Labeling the card literally sfx-song / sfx-pack helps users learn the name of the mechanism.
kind、pubkey、identifier(d の値)、任意の relays を得る。Decode with NIP-19 to get kind, pubkey, identifier (the d value), and optional relays.kind === 30078 かつ identifier が sfx-song/ または sfx-pack/ で始まる場合だけ、カード候補にする。Only treat it as a card candidate when kind === 30078 and the identifier starts with sfx-song/ or sfx-pack/.created_at が最大のものを最新版として使う。naddr は常に最新版を指す。古い版を固定したい参照は nevent の役割。If several versions return, use the one with the greatest created_at. An naddr always points at the latest version; pinning an old version is nevent's job.{ "kinds": [30078], "authors": ["<pubkey>"], "#d": ["sfx-song/test-drive"] }
content は JSON 文字列。表示前に必ず検証・正規化し、数値は安全な範囲へ丸める。タイトルは制御文字を取り除いて長さを制限し、HTML へ入れる場合はエスケープする。
content is a JSON string. Always validate and normalize before rendering, clamping numbers to safe ranges. Strip control characters from titles, cap their length, and escape them when inserting into HTML.
| sfx-song | sfx-pack | |
|---|---|---|
| 主な項目Main fields | title, bpm, loop, tracks[] | title, wave, volume, sounds{} |
| 楽譜Score | [周波数 or 音名, 拍][frequency or note name, beats] | [周波数 or 音名, 秒][frequency or note name, seconds] |
| 取り下げWithdrawn | tracks: [] | sounds: {} |
| 読む側の上限例Example reader limits | 4トラック、1トラック8192 steps、4800拍、BPM 40〜300、20〜8000Hz、音量0.01〜0.34 tracks, 8192 steps/track, 4800 beats, BPM 40–300, 20–8000 Hz, volume 0.01–0.3 | 音名32種、1音32音、合計4秒、20〜8000Hz、音量0.01〜0.332 sound names, 32 notes/sound, 4 seconds total, 20–8000 Hz, volume 0.01–0.3 |
取り下げ・不正なイベントでも生 JSON は出さず、「取り下げられています」「再生できません」等の無効カードにする。タイトルがなければ d の <name> 部分を表示名にする。作者名はイベントの pubkey から通常のプロフィール解決で得る。
For withdrawn or invalid events, show a disabled card (“Withdrawn”, “Cannot play”, etc.) instead of raw JSON. If there is no title, use the <name> part of d. Resolve the author name from the event pubkey as usual.
拍 × 60 / BPM。全トラックを同時に開始し、各 step を順に予約する。長い曲では少し先まで予約するスケジューラにすると安定する。Song seconds are beats × 60 / BPM. Start all tracks together and schedule steps in order; for long songs, a lookahead scheduler is more stable.1 が打撃、0 が休み。音名表記("A4" 等)は周波数へ変換してよい。Frequency 0 is a rest. On noise tracks, 1 is a hit and 0 is a rest. Note names ("A4", etc.) may be converted to frequencies.loop: true は停止操作まで繰り返す。One song at a time is recommended: starting another stops the previous one, and the same button stops playback. loop: true repeats until stopped.▶ tab のような試聴ボタンにすると分かりやすい。クライアントに効果音の仕組みがある場合は「このパックを適用」も付けられるが、カード表示だけなら試聴までで十分。For packs, per-sound audition buttons like ▶ tab work well. Clients with a sound-effect system may add “Apply this pack”, but auditioning alone is enough for a card.const decoded = nip19.decode(naddr).data;
if (decoded.kind !== 30078) return renderGenericQuote(decoded);
const isSong = decoded.identifier.startsWith("sfx-song/");
const isPack = decoded.identifier.startsWith("sfx-pack/");
if (!isSong && !isPack) return renderGenericQuote(decoded);
const events = await queryRelays(decoded.relays, {
kinds: [30078],
authors: [decoded.pubkey],
"#d": [decoded.identifier]
});
const event = latestByCreatedAt(events);
if (!event || event.pubkey !== decoded.pubkey || dTag(event) !== decoded.identifier) {
return renderUnavailableCard();
}
const parsed = safeJsonParse(event.content);
if (isSong) return renderSongCard(event, sanitizeSong(parsed));
return renderPackCard(event, sanitizePack(parsed));
以下は実在する公開作品。投稿本文へ nostr: 付きで貼ると、対応クライアントではカードになる。
These are real published works. Paste them with the nostr: prefix into a post and supporting clients will render cards.
| 作品Work | naddr |
|---|---|
| sfx-song/test-drive | nostr:naddr1qvzqqqr40cpzqgdv99tpkh0fpnwzrx2lcpc82fwd0ry22tv8wgdtdqwn6cyarcklqyxhwumn8ghj77tpvf6jumt9qqfhxenc94ek7mn89a6x2um594j8y6tkv5fg80ds |
| sfx-song/kira-kira-days | nostr:naddr1qvzqqqr40cpzqgdv99tpkh0fpnwzrx2lcpc82fwd0ry22tv8wgdtdqwn6cyarcklqyxhwumn8ghj77tpvf6jumt9qqthxenc94ek7mn89a4kjunp944kjunp94jxz7tnls6wql |
| sfx-pack/pink-suikomi | nostr:naddr1qvzqqqr40cpzqgdv99tpkh0fpnwzrx2lcpc82fwd0ry22tv8wgdtdqwn6cyarcklqyxhwumn8ghj77tpvf6jumt9qq2hxenc94cxzcmt9acxjmnt94eh26ttdakkjd4y6x7 |
最小実装は「分岐、検証、タイトルと再生/試聴ボタン」だけでも成立する。まずはそこからどうぞ。
A minimal implementation only needs the branch, validation, a title, and play/audition buttons. Start there.