@dsebastien/music-notation 0.10.0 → 0.11.0

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.
@@ -36,6 +36,8 @@ export interface StrumEventOptions {
36
36
  tail?: number;
37
37
  /** Varies the small differences between strums from pass to pass (the pass's number). */
38
38
  seed?: number;
39
+ /** The most time between a strum's strings, in seconds: 0.012 by default (0 a block). */
40
+ spread?: number;
39
41
  }
40
42
  /**
41
43
  * MIDI velocities: a down strum (`normal`), an up strum, an accent, a ghost strum, a muted one
@@ -106,6 +108,17 @@ export interface StrumFollower {
106
108
  heard(): void;
107
109
  stop(): void;
108
110
  }
111
+ /** One pass of a piece played in time: its notes, its length in seconds, and what to light. */
112
+ export interface Pass {
113
+ events: NoteEvent[];
114
+ /** Seconds until the next pass starts when it loops (the last note's ring not counted). */
115
+ length: number;
116
+ strums: StrumTiming[];
117
+ /** When each bar starts and how long it lasts (`slot` is the bar's index), when known. */
118
+ bars?: StrumTiming[];
119
+ }
120
+ /** What each pass is made from: the settings read at that pass, the first pass or not, its number. */
121
+ export type PassMaker = (settings: StrumSettings, first: boolean, id: number) => Pass;
109
122
  /**
110
123
  * Plays a score through `player`, pass after pass while `settings().loop` is on. Each next pass
111
124
  * is started on a timer at the exact end of the previous one, counted from the first pass's start
@@ -117,6 +130,11 @@ export interface StrumFollower {
117
130
  * them from the moment they sound.
118
131
  */
119
132
  export declare function runStrum(score: StrumScore, player: () => NotePlayer, settings: () => StrumSettings, timers: Pick<Window, 'setTimeout' | 'clearTimeout'>, onEnd?: () => void, follow?: (strums: StrumTiming[], player: NotePlayer) => StrumFollower): PlayHandle;
133
+ /**
134
+ * Plays the passes `make` returns, as `runStrum` plays a strumming pattern's (see there): the
135
+ * timing of progressions (#46) and picking patterns (#51) too.
136
+ */
137
+ export declare function runPasses(make: PassMaker, player: () => NotePlayer, settings: () => StrumSettings, timers: Pick<Window, 'setTimeout' | 'clearTimeout'>, onEnd?: () => void, follow?: (strums: StrumTiming[], player: NotePlayer, pass: Pass) => StrumFollower): PlayHandle;
120
138
  export interface PlayStrumOptions {
121
139
  /** Beats a minute: the pattern's `tempo:`, else 90 (60 dotted quarters in compound time). */
122
140
  bpm?: number;
@@ -108,6 +108,11 @@ export interface TabResult {
108
108
  }>;
109
109
  /** The alphaTab API, for exports and playback. */
110
110
  api: AT.AlphaTabApi | null;
111
+ /**
112
+ * The speed set on the player bar (0.25 to 1.5; 1 without a bar). alphaTab's `playbackSpeed`
113
+ * takes it only once the player starts (the first Play), so an app reads it here.
114
+ */
115
+ speed(): number;
111
116
  destroy(): void;
112
117
  }
113
118
  /**
package/dist/tab/index.js CHANGED
@@ -896,9 +896,16 @@ function splitUnbarred(measures, meter) {
896
896
  if (eighths <= perBar || m.width - m.pad < span * 1.5)
897
897
  return [m];
898
898
  const count = Math.floor((cols.at(-1) - m.pad) / span) + 1;
899
- return Array.from({ length: count }, (_, k) => {
900
- const from = m.pad + k * span;
901
- const beats = m.beats.filter((b) => (k === 0 || b.col >= from) && (k === count - 1 || b.col < from + span)).map((b) => ({ notes: b.notes, col: b.col - k * span }));
899
+ const pieces = Array.from({ length: count }, () => []);
900
+ for (const b of m.beats) {
901
+ let k = Math.min(count - 1, Math.max(0, Math.floor((b.col - m.pad) / span)));
902
+ while (k < count - 1 && b.col >= m.pad + (k + 1) * span)
903
+ k++;
904
+ while (k > 0 && b.col < m.pad + k * span)
905
+ k--;
906
+ pieces[k].push({ notes: b.notes, col: b.col - k * span });
907
+ }
908
+ return pieces.map((beats, k) => {
902
909
  return {
903
910
  beats,
904
911
  width: m.pad + span,
@@ -1714,6 +1721,7 @@ function playerBar(doc, api, alphaTab, assets) {
1714
1721
  });
1715
1722
  return {
1716
1723
  bar,
1724
+ speed: () => state.speed,
1717
1725
  failed: (message) => {
1718
1726
  cantStart?.();
1719
1727
  play.disabled = true;
@@ -1776,6 +1784,7 @@ function renderTab(language, source, host, options) {
1776
1784
  const el = html(doc, "div", `mn-block mn-block-${language} mn-tab`);
1777
1785
  host.appendChild(el);
1778
1786
  let api = null;
1787
+ let speedOf = () => 1;
1779
1788
  let gone = false;
1780
1789
  let settled = false;
1781
1790
  let settle = () => {};
@@ -1847,6 +1856,7 @@ function renderTab(language, source, host, options) {
1847
1856
  return;
1848
1857
  if (options.player !== false) {
1849
1858
  bar = playerBar(doc, current, at, assets);
1859
+ speedOf = bar.speed;
1850
1860
  el.appendChild(bar.bar);
1851
1861
  if (options.views !== false && tablature)
1852
1862
  bar.bar.appendChild(viewControl(doc, own, (staves) => {
@@ -1903,6 +1913,7 @@ function renderTab(language, source, host, options) {
1903
1913
  get api() {
1904
1914
  return api;
1905
1915
  },
1916
+ speed: () => speedOf(),
1906
1917
  destroy() {
1907
1918
  gone = true;
1908
1919
  try {
@@ -2079,5 +2090,5 @@ export {
2079
2090
  textTabToAlphaTex
2080
2091
  };
2081
2092
 
2082
- //# debugId=676F0DA21BF6D94464756E2164756E21
2093
+ //# debugId=2EE54AC69188D00D64756E2164756E21
2083
2094
  //# sourceMappingURL=index.js.map