@sudobility/music_types 0.13.2 → 0.13.3

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.
@@ -74,6 +74,31 @@ export interface IMusicPosition {
74
74
  * {@link IMusicPosition} and cannot move the playhead by accident.
75
75
  */
76
76
  export interface IMusicPositionSource extends IMusicPosition {
77
+ /**
78
+ * Move the playhead, because something other than the transport decided to.
79
+ *
80
+ * A click on the stave, an arrow key, a note written at the caret: all of
81
+ * them are somebody saying where the position *should be*, and they are the
82
+ * opposite of {@link report}, which is the transport saying where it already
83
+ * is. Keeping the two apart is what lets the transport follow this one
84
+ * without following its own reports around a loop.
85
+ *
86
+ * It is on this interface rather than the read one so a passive follower
87
+ * still cannot move the playhead by accident — but note that moving it is
88
+ * not a transport privilege. The editor moves the playhead; it just has no
89
+ * business knowing that a transport exists, so it says where the position is
90
+ * and whatever is playing follows.
91
+ */
92
+ moveTo(tick: number): void;
93
+ /**
94
+ * Observe deliberate moves, and *only* those.
95
+ *
96
+ * The transport subscribes here to follow a seek. It must not use
97
+ * {@link IMusicPosition.subscribe}, which also fires on its own reports:
98
+ * following those would mean seeking to where it already is, thirty times a
99
+ * second, forever.
100
+ */
101
+ subscribeToMoves(listener: (tick: number) => void): UnsubscribePosition;
77
102
  /**
78
103
  * Report an authoritative position, in score ticks.
79
104
  *
@@ -1 +1 @@
1
- {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/model/position.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,4EAA4E;AAC5E,MAAM,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,2EAA2E;IAC3E,QA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,GAAG,mBAAmB,CAAC;IAExE;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/C,kEAAkE;IAClE,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5D;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC"}
@@ -33,6 +33,8 @@
33
33
  import type { IMusicPositionSource, UnsubscribePosition } from "../model/position.js";
34
34
  export declare class MusicPosition implements IMusicPositionSource {
35
35
  private readonly listeners;
36
+ /** Kept apart from `listeners`: the transport follows these and must not follow its own reports. */
37
+ private readonly moveListeners;
36
38
  /** The last authoritative report, and the clock reading it belongs to. */
37
39
  private anchorTick;
38
40
  private anchorSeconds;
@@ -55,6 +57,17 @@ export declare class MusicPosition implements IMusicPositionSource {
55
57
  */
56
58
  get reportedTick(): number;
57
59
  report(tick: number, atSeconds?: number): void;
60
+ /**
61
+ * Somebody moved the playhead.
62
+ *
63
+ * Anchors exactly as `report` does — the position *is* here now, and a
64
+ * projection from the old anchor would glide away from it — then tells the
65
+ * ordinary subscribers, so anything drawing the caret sees one number change
66
+ * whoever moved it, and finally the movement subscribers, which is how the
67
+ * transport learns to follow.
68
+ */
69
+ moveTo(tick: number): void;
70
+ subscribeToMoves(listener: (tick: number) => void): UnsubscribePosition;
58
71
  /**
59
72
  * Update the tick rate without disturbing the anchor.
60
73
  *
@@ -1 +1 @@
1
- {"version":3,"file":"music-position.d.ts","sourceRoot":"","sources":["../../src/position/music-position.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AA8B9B,qBAAa,aAAc,YAAW,oBAAoB;IACxD,OAAO,CAAC,QAAQ,CAAC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MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAM9C;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ1B,gBAAgB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,mBAAmB;IAKvE;;;;;;OAMG;IACH,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAIrC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI;IAY3D,SAAS,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,mBAAmB;CAIjE"}
@@ -27,6 +27,8 @@ function nowSeconds() {
27
27
  export class MusicPosition {
28
28
  constructor() {
29
29
  this.listeners = new Set();
30
+ /** Kept apart from `listeners`: the transport follows these and must not follow its own reports. */
31
+ this.moveListeners = new Set();
30
32
  /** The last authoritative report, and the clock reading it belongs to. */
31
33
  this.anchorTick = 0;
32
34
  this.anchorSeconds = nowSeconds();
@@ -68,6 +70,28 @@ export class MusicPosition {
68
70
  for (const listener of this.listeners)
69
71
  listener(tick);
70
72
  }
73
+ /**
74
+ * Somebody moved the playhead.
75
+ *
76
+ * Anchors exactly as `report` does — the position *is* here now, and a
77
+ * projection from the old anchor would glide away from it — then tells the
78
+ * ordinary subscribers, so anything drawing the caret sees one number change
79
+ * whoever moved it, and finally the movement subscribers, which is how the
80
+ * transport learns to follow.
81
+ */
82
+ moveTo(tick) {
83
+ const target = Math.max(0, tick);
84
+ this.anchorTick = target;
85
+ this.anchorSeconds = nowSeconds();
86
+ for (const listener of this.listeners)
87
+ listener(target);
88
+ for (const listener of this.moveListeners)
89
+ listener(target);
90
+ }
91
+ subscribeToMoves(listener) {
92
+ this.moveListeners.add(listener);
93
+ return () => this.moveListeners.delete(listener);
94
+ }
71
95
  /**
72
96
  * Update the tick rate without disturbing the anchor.
73
97
  *
@@ -1 +1 @@
1
- {"version":3,"file":"music-position.js","sourceRoot":"","sources":["../../src/position/music-position.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC,kEAAkE;AAClE,SAAS,UAAU;IACjB,OAAO,OAAO,WAAW,KAAK,WAAW;QACvC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI;QAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACxB,CAAC;AAED,MAAM,OAAO,aAAa;IAA1B;QACmB,cAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;QAE/D,0EAA0E;QAClE,eAAU,GAAG,CAAC,CAAC;QACf,kBAAa,GAAG,UAAU,EAAE,CAAC;QAE7B,YAAO,GAAG,KAAK,CAAC;QAChB,mBAAc,GAAG,CAAC,CAAC;IAwE7B,CAAC;IAtEC,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,IAAI;QACN,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,cAAc,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,UAAU,CAAC;QACtE,0EAA0E;QAC1E,+DAA+D;QAC/D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CACtB,UAAU,EAAE,GAAG,IAAI,CAAC,aAAa,EACjC,sBAAsB,CACvB,CAAC;QACF,uEAAuE;QACvE,uDAAuD;QACvD,OAAO,IAAI,CAAC,GAAG,CACb,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC,cAAc,CAChD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,SAAkB;QACrC,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C,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/music_types",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "TypeScript types and Zod schemas for the ScoreSmith music API - scores, generation contracts, project payloads",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",