@sound2score/player 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,6 +16,9 @@ npx skills add sound2score/player
16
16
 
17
17
  ## Quick start
18
18
 
19
+ Try a working embed right away with `scoreId: "demo"` (synced video and
20
+ notation, works on any site with no account required):
21
+
19
22
  ```ts
20
23
  import { Player } from "@sound2score/player";
21
24
 
@@ -24,7 +27,7 @@ if (!container) {
24
27
  throw new Error("No #score element");
25
28
  }
26
29
  const player = Player.create(container, {
27
- scoreId: "abc123",
30
+ scoreId: "demo",
28
31
  userId: "student-42",
29
32
  options: { start: { speed: 80 } },
30
33
  });
@@ -38,9 +41,9 @@ player.events.on("change", (state) => {
38
41
  });
39
42
  ```
40
43
 
41
- The score's owner has to add your site to the sites in their Embeds settings
42
- on sound2score first. The score ID is the last part of the score's address,
43
- `sound2score.com/s/<scoreId>`.
44
+ When ready to embed your own score, replace `"demo"` with your score ID (the
45
+ last segment of `sound2score.com/s/<scoreId>`) and add your site to Embeds
46
+ settings on sound2score.
44
47
 
45
48
  Already have an iframe pasted from sound2score? Take control of it:
46
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sound2score/player",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Embed sound2score scores on your site and control playback from your page.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,30 +1,25 @@
1
1
  ---
2
2
  name: sound2score-player
3
- description: Embed sound2score sheet music on a website and control it from the page with @sound2score/player. Use when adding a sound2score score to a site, creating or attaching its embed, passing the viewer's user ID, playing, pausing, seeking, looping, changing speed, transposing or toggling the metronome from page code, or reacting to the embed's ready, change and unavailable events.
4
- version: 0.2.5
3
+ description: One-stop guide to embedding sound2score sheet music and synced video on any website with @sound2score/player. Use when prototyping with the built-in demo score, uploading a score and syncing a video in sound2score, configuring allowed embed sites, creating or attaching a Player, passing student userId, handling framework cleanup or SSR URLs, configuring EmbedOptions, sending playback commands, or reacting to ready, change, and unavailable events.
4
+ version: 0.2.7
5
5
  ---
6
6
 
7
7
  # sound2score Player
8
8
 
9
- `@sound2score/player` puts a sound2score score on a web page as an iframe and
10
- lets the page drive it: play, pause, seek, loop bars, slow down, transpose and
11
- click along, and hear back what the Player is doing.
9
+ `@sound2score/player` puts a sound2score score (with optional synced video) on a
10
+ web page as an iframe and lets your page control playback: play, pause, seek,
11
+ loop bars, change speed, transpose, and toggle the metronome, while listening
12
+ for state changes.
12
13
 
13
14
  ```sh
14
15
  npm install @sound2score/player
15
16
  ```
16
17
 
17
- ## Before you start
18
+ ## 1. Quick proof of concept (no account needed)
18
19
 
19
- - The score's owner must be on a plan with embeds and must add your site
20
- (its origin, such as `https://school.example`) to the sites in their Embeds
21
- settings on sound2score. On any other site the embed shows why it can't
22
- play and raises `unavailable` with reason `site`.
23
- - The score ID is the last part of its address: `sound2score.com/s/<scoreId>`.
24
- - Each viewer of an embed counts as one of the owner's students. Pass
25
- `userId` (below) so a student counts once however many browsers they use.
26
-
27
- ## Create a new embed
20
+ Use `scoreId: "demo"` to verify a working embed in minutes. The demo score
21
+ includes synced video and notation and plays on any website with no account or
22
+ site allowlist required.
28
23
 
29
24
  ```ts
30
25
  import { Player } from "@sound2score/player";
@@ -33,26 +28,106 @@ const container = document.getElementById("score");
33
28
  if (!container) {
34
29
  throw new Error("No #score element");
35
30
  }
31
+
36
32
  const player = Player.create(container, {
37
- scoreId: "abc123",
38
- // The ID your site knows this viewer by. Sent once, when the embed loads.
39
- userId: "student-42",
40
- options: {
41
- start: { speed: 80, bars: { from: 9, to: 16 } },
42
- controls: { transpose: "off", mixer: "open" },
43
- layout: { title: false },
44
- look: { theme: "volt", accent: "#ff00aa" },
45
- },
46
- height: 600,
33
+ scoreId: "demo",
34
+ height: 560,
35
+ });
36
+
37
+ player.events.on("ready", (state) => {
38
+ console.log(`loaded ${state.bars} bars`);
39
+ player.setSpeed(85);
40
+ player.setLoop({ from: 1, to: 8 });
41
+ });
42
+
43
+ player.events.on("change", (state) => {
44
+ console.log(`bar ${state.bar} of ${state.bars}`, state.playing);
47
45
  });
48
46
  ```
49
47
 
50
- The iframe fills the container's width. Anything left out of `options`
51
- keeps its default, and look fields you leave out follow the owner's style.
48
+ Once the demo renders and responds to commands in your app, replace `"demo"`
49
+ with your own `scoreId` using the onboarding steps below.
50
+
51
+ ## 2. Add your own score and video in sound2score
52
+
53
+ 1. **Upload or create a score** at `https://sound2score.com/upload`:
54
+ - Supported score files: MusicXML (`.musicxml`, `.xml`), MIDI (`.mid`,
55
+ `.midi`), and guitar tab (`.txt` or pasted).
56
+ - Bulk import accepts a folder of scores or a Soundslice export with its
57
+ recordings and sync points.
58
+ - Where recording transcription is available on your plan, you can also
59
+ upload an audio or video recording to transcribe into a score.
60
+ 2. **Attach an existing video or recording and sync it:**
61
+ - Paste a link from a supported video host: YouTube, Vimeo, Wistia, or Mux.
62
+ - Or upload your own audio or video recording file directly.
63
+ - Sync the video or recording to the score so playback and notation stay
64
+ locked together.
65
+ 3. **Set score visibility:**
66
+ - Set visibility to `Embed`, `Unlisted`, or `Public`. `Private` scores cannot
67
+ be embedded and report `unavailable` with reason `not-found`.
68
+ 4. **Allow your site(s) in Embeds settings:**
69
+ - Your account must be on a plan with embeds.
70
+ - Add each site origin at `https://sound2score.com/account/embeds` (or from
71
+ the score's Embed dialog).
72
+ - Origin rules:
73
+ - Production sites must use `https://` (for example
74
+ `https://school.example`).
75
+ - Local development accepts `http://` on a local loopback origin with its
76
+ port (for example `http://127.0.0.1:3000`).
77
+ - A single leading subdomain wildcard (for example
78
+ `https://*.school.example`) matches subdomains on the same scheme and
79
+ port, does not match the apex domain (`https://school.example`), and is
80
+ refused on shared hosts (such as `https://*.github.io`).
81
+ - On any unlisted origin, the embed shows why it can't play and emits
82
+ `unavailable` with reason `site`.
83
+ 5. **Copy the `scoreId` or embed snippet:**
84
+ - The `scoreId` is the last segment of the score URL:
85
+ `https://sound2score.com/s/<scoreId>`.
86
+ - Pass that `scoreId` to `Player.create`, or paste the iframe from the Embed
87
+ dialog and attach with `Player.attach`.
88
+
89
+ ## 3. App integration patterns
90
+
91
+ ### Create an embed with options and cleanup
92
+
93
+ `Player.create` inserts an iframe filling the container's width (default height
94
+ `520`, with `allow="autoplay; fullscreen"`). In component frameworks (React,
95
+ Vue, Svelte, etc.), dispose the player and remove the iframe on unmount:
52
96
 
53
- ## Attach to an embed already on the page
97
+ ```ts
98
+ import { Player } from "@sound2score/player";
99
+
100
+ export function mountScore(
101
+ container: HTMLElement,
102
+ scoreId: string,
103
+ userId: string,
104
+ ): () => void {
105
+ const player = Player.create(container, {
106
+ scoreId,
107
+ userId,
108
+ height: 600,
109
+ options: {
110
+ start: { speed: 80, bars: { from: 9, to: 16 } },
111
+ controls: { transpose: "off", mixer: "open" },
112
+ layout: { title: false, video: "beside", initial: "video" },
113
+ look: { theme: "volt", accent: "#ff00aa" },
114
+ },
115
+ });
116
+
117
+ return () => {
118
+ player.dispose();
119
+ container.replaceChildren();
120
+ };
121
+ }
122
+ ```
123
+
124
+ `player.dispose()` stops listening to the embed but leaves the iframe in the
125
+ DOM, so remove the iframe yourself if you want it gone.
54
126
 
55
- An iframe pasted from sound2score's Embed dialog works too:
127
+ ### Attach to an existing iframe
128
+
129
+ An iframe pasted from the Embed dialog or rendered by your server works with
130
+ `Player.attach`:
56
131
 
57
132
  ```ts
58
133
  import { Player } from "@sound2score/player";
@@ -66,10 +141,81 @@ if (!iframe) {
66
141
  const player = Player.attach(iframe);
67
142
  ```
68
143
 
69
- To pass a `userId` to a pasted iframe, add `u=<id>` to its `src` before it
70
- loads. It can't be added later.
144
+ ### Server-rendered URLs (`EmbedUrlBuilder`)
145
+
146
+ For SSR pages, `EmbedUrlBuilder` builds the exact iframe `src` that
147
+ `Player.create` uses:
148
+
149
+ ```ts
150
+ import {
151
+ DEFAULT_EMBED_OPTIONS,
152
+ EmbedOptionsCodec,
153
+ EmbedUrlBuilder,
154
+ } from "@sound2score/player";
155
+
156
+ const urls = new EmbedUrlBuilder(
157
+ "https://sound2score.com",
158
+ new EmbedOptionsCodec(),
159
+ );
160
+ const src = urls.build(
161
+ "abc123",
162
+ {
163
+ ...DEFAULT_EMBED_OPTIONS,
164
+ start: { ...DEFAULT_EMBED_OPTIONS.start, speed: 70 },
165
+ },
166
+ "student-42",
167
+ );
168
+ ```
71
169
 
72
- ## Commands
170
+ Keep `allow="autoplay; fullscreen"` on server-rendered iframes so playback and
171
+ fullscreen work.
172
+
173
+ ### Student `userId` (`?u=`)
174
+
175
+ - Each viewer of an embed counts as one of the score owner's students.
176
+ - Pass an opaque internal ID from your own database (for example
177
+ `"student-42"`), never an email address or name.
178
+ - A `userId` covers up to 3 browsers per month for that student so they count
179
+ once across their devices.
180
+ - `userId` is read once when the embed loads and cannot be added or changed
181
+ later. For pasted or server-rendered iframes, include `u=<id>` on the iframe
182
+ `src` before it loads.
183
+
184
+ ## 4. Player reference
185
+
186
+ ### `EmbedOptions`
187
+
188
+ Anything left out of `options` keeps its default; `look` fields left out follow
189
+ the score owner's Embeds style.
190
+
191
+ - **`controls`** (`EmbedControls`):
192
+ - `tempo`, `metronome`, `loop`, `transpose`, `fullscreen`: `"off" | "on"`
193
+ (default `"on"`).
194
+ - `mixer`, `fretboard`, `piano`: `ControlMode` (`"off" | "on" | "open"`,
195
+ default `"on"`). `"open"` also opens that panel when the embed loads.
196
+ - **`start`** (`EmbedStart`):
197
+ - `speed`: percent of written tempo, `25` to `200` (default `100`).
198
+ - `semitones`: transposition from `-12` to `12` (default `0`).
199
+ - `metronome`: `boolean` (default `false`).
200
+ - `bars`: `{ from: number; to: number } | null` initial loop, counted from 1
201
+ (default `null`).
202
+ - `bar`: `number | null` starting bar when `bars` is `null`, counted from 1
203
+ (default `null`).
204
+ - **`layout`** (`EmbedLayout`):
205
+ - `title`: `boolean` show or hide the title header (default `true`).
206
+ - `video`: `VideoPlacement` (`"beside" | "above"`, default `"beside"`).
207
+ `"beside"` places video beside the score when it fits, else above; `"above"`
208
+ always stacks it above.
209
+ - `initial`: `InitialLayout` (`"video" | "firstLine" | "score"`, default
210
+ `"video"`). Sets how the page first splits between video and score.
211
+ - **`look`** (`Partial<EmbedLook>`):
212
+ - `appearance`: `"auto" | "light" | "dark"`.
213
+ - `theme`: `"neon" | "volt" | "electric" | "plasma"`.
214
+ - `accent`: `#rrggbb` hex string or `null`.
215
+ - `background`: `"transparent"`, `#rrggbb` hex string, or `null`.
216
+ - `credit`: `CreditPlacement` (`"header" | "corner" | "hidden"`).
217
+
218
+ ### Commands
73
219
 
74
220
  ```ts
75
221
  import { Player } from "@sound2score/player";
@@ -82,21 +228,20 @@ player.seek(30); // seconds from the start
82
228
  player.goToBar(17); // bars count from 1, in playback order
83
229
  player.setLoop({ from: 9, to: 16 }); // both bars included
84
230
  player.setLoop(null); // stop looping
85
- player.setSpeed(75); // percent of the written tempo, 25 to 200
231
+ player.setSpeed(75); // percent of written tempo, 25 to 200
86
232
  player.setTranspose(-2); // semitones from as written, -12 to 12
87
233
  player.setMetronome(true);
88
234
  ```
89
235
 
90
- - Commands given before the score is ready wait, then run in order.
91
- - Commands work even when the embed's options hide that control, so you can
92
- hide the Player's own buttons and build your own.
93
- - Inside a loop, `seek` and `goToBar` keep the playhead in the loop. Call
94
- `setLoop(null)` first to leave it.
95
- - Browsers start sound only after the viewer has interacted with the page.
96
- On phones, the viewer has to tap inside the embed once before `play()`
97
- makes a sound.
236
+ - Commands sent before `ready` are queued and run in order once ready.
237
+ - Commands work even when `options.controls` hides the matching UI control, so
238
+ you can build your own transport controls.
239
+ - Inside a loop, `seek` and `goToBar` stay within the loop. Call `setLoop(null)`
240
+ first to move outside it.
241
+ - Browsers allow sound only after user interaction. On phones, the viewer must
242
+ tap inside the embed once before `play()` produces sound.
98
243
 
99
- ## Events
244
+ ### Events and `PlayerState`
100
245
 
101
246
  ```ts
102
247
  import { Player, type PlayerState } from "@sound2score/player";
@@ -125,47 +270,17 @@ player.events.on("unavailable", ({ reason, resetsAt, upgradeTo }) => {
125
270
  });
126
271
  ```
127
272
 
128
- `PlayerState` holds `playing`, `seconds`, `duration`, `bar`, `bars`, `loop`,
129
- `speed`, `semitones` and `metronome`. `player.getState()` returns the last
130
- one, or null before `ready`.
273
+ - `PlayerState` fields: `playing`, `seconds`, `duration`, `bar`, `bars`, `loop`,
274
+ `speed`, `semitones`, `metronome`.
275
+ - Inspect synchronously with `player.getState()` (`null` before `ready`),
276
+ `player.isReady()`, and `player.getUnavailable()`.
131
277
 
132
- Call `player.dispose()` to stop listening. The iframe stays on the page;
133
- remove it yourself if you want it gone.
134
-
135
- ## What it can't do
278
+ ### What it can't do
136
279
 
137
280
  These are deliberate:
138
281
 
139
- - No `load(scoreId)`. To show another score, create a new Player.
140
- - No printing, exporting or downloading the score or its recordings.
282
+ - No `load(scoreId)`. To show another score, dispose the current Player and
283
+ create a new one.
284
+ - No printing, exporting, or downloading the score or its recordings.
141
285
  - No preloading recordings.
142
286
  - `userId` is read only when the embed loads.
143
-
144
- ## Building URLs yourself
145
-
146
- For a server-rendered page, `EmbedUrlBuilder` writes the same `src` that
147
- `create` does:
148
-
149
- ```ts
150
- import {
151
- DEFAULT_EMBED_OPTIONS,
152
- EmbedOptionsCodec,
153
- EmbedUrlBuilder,
154
- } from "@sound2score/player";
155
-
156
- const urls = new EmbedUrlBuilder(
157
- "https://sound2score.com",
158
- new EmbedOptionsCodec(),
159
- );
160
- const src = urls.build(
161
- "abc123",
162
- {
163
- ...DEFAULT_EMBED_OPTIONS,
164
- start: { ...DEFAULT_EMBED_OPTIONS.start, speed: 70 },
165
- },
166
- "student-42",
167
- );
168
- ```
169
-
170
- Keep `allow="autoplay; fullscreen"` on the iframe so playback and fullscreen
171
- work.