@viritura/score-engine 0.2.0 → 0.2.1-next.34

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/dist/index.js CHANGED
@@ -143,21 +143,22 @@ function isRest(event) {
143
143
 
144
144
  // packages/core/src/model/sequenceWalk.ts
145
145
  init_define_import_meta_env();
146
+ var ROOT_EVENT_PATH = [];
146
147
  function isEventContainer(item) {
147
148
  return item.type === "tuplet" || item.type === "grace" || item.type === "tremolo";
148
149
  }
149
150
  function eventContainerContent(item) {
150
151
  return isEventContainer(item) ? item.content : null;
151
152
  }
152
- function* walkSequenceEvents(content, prefix = []) {
153
+ function* walkSequenceEvents(content, prefix = ROOT_EVENT_PATH, include) {
153
154
  for (let i = 0; i < content.length; i++) {
154
155
  let item = content[i];
155
156
  if (item.type === "event") {
156
- yield { event: item, path: [...prefix, i] };
157
+ (!include || include(item)) && (yield { event: item, path: [...prefix, i] });
157
158
  continue;
158
159
  }
159
160
  let inner = eventContainerContent(item);
160
- inner && (yield* walkSequenceEvents(inner, [...prefix, i]));
161
+ inner && (yield* walkSequenceEvents(inner, [...prefix, i], include));
161
162
  }
162
163
  }
163
164
 
@@ -2213,9 +2214,9 @@ function interpolateBeatAnchors(bounds, beat, endX) {
2213
2214
 
2214
2215
  // packages/score-engine/src/buildInfo.ts
2215
2216
  init_define_import_meta_env();
2216
- var PACKAGE_VERSION = "0.2.0", BUNDLE_WORKER_FILE = "score-engine.worker.js";
2217
+ var PACKAGE_VERSION = "0.2.1-next.34", BUNDLE_WORKER_FILE = "score-engine.worker.js";
2217
2218
  function buildCommit() {
2218
- return "90b89f13680a7855b46725024057cc9919dfbc20";
2219
+ return "8164ae9c9c954a817a39c240b583d1e5b93e70f0";
2219
2220
  }
2220
2221
  function bundledAssetBase() {
2221
2222
  let moduleUrl = import.meta.url;
@@ -16669,8 +16670,8 @@ function nextInstruction(measure, cursor, length, state, fine, taken, initialOrd
16669
16670
  };
16670
16671
  }
16671
16672
  function compileNavigation(measures, initialOrder, measureLengths) {
16672
- let { markers, required } = resolveDestinations(measures, measureLengths), result = [], taken = /* @__PURE__ */ new Set(), state = { fineArmed: !1, codaArmed: !1, replay: !1, orderIndex: 0 }, cursor = { measureIndex: initialOrder[0] ?? 0, beat: 0 }, transitions = 0;
16673
- for (; cursor.measureIndex < measures.length && (state.replay || state.orderIndex < initialOrder.length); ) {
16673
+ let { markers, required } = resolveDestinations(measures, measureLengths), result = [], order = initialOrder, taken = /* @__PURE__ */ new Set(), state = { fineArmed: !1, codaArmed: !1, replay: !1, orderIndex: 0 }, cursor = { measureIndex: order[0] ?? 0, beat: 0 }, transitions = 0;
16674
+ for (; cursor.measureIndex < measures.length && (state.replay || state.orderIndex < order.length); ) {
16674
16675
  if (++transitions > MAX_SPANS)
16675
16676
  throw new NavigationError("Navigation exceeds the safe playback traversal limit", ["/global/measures"]);
16676
16677
  let index = cursor.measureIndex, measure = measures[index], length = measureLengths[index], { type, jumpActive, jumpBeat, fineReached, endBeat } = nextInstruction(
@@ -16680,17 +16681,26 @@ function compileNavigation(measures, initialOrder, measureLengths) {
16680
16681
  state,
16681
16682
  markers.fine[0],
16682
16683
  taken,
16683
- initialOrder
16684
+ order
16684
16685
  );
16685
16686
  if (endBeat > cursor.beat + EPS && result.push({ measureIndex: index, startBeat: cursor.beat, endBeat, measureBeats: length }), state.fineArmed && fineReached) {
16686
16687
  state.fineArmed = !1;
16687
16688
  break;
16688
16689
  }
16689
16690
  if (jumpActive && jumpBeat <= endBeat + EPS) {
16690
- taken.add(index), state.replay = !0, type === "toCoda" ? (state.codaArmed = !1, cursor = required("coda", index)) : (state.fineArmed = type === "dcAlFine" || type === "dsAlFine", state.codaArmed = type === "dcAlCoda" || type === "dsAlCoda", cursor = ["segno", "dsAlFine", "dsAlCoda"].includes(type) ? required("segno", index) : { measureIndex: 0, beat: 0 });
16691
+ if (taken.add(index), type === "toCoda") {
16692
+ if (state.codaArmed = !1, cursor = required("coda", index), state.orderIndex = order.indexOf(cursor.measureIndex), state.orderIndex < 0) {
16693
+ let nextRepeat = measures.findIndex(
16694
+ (measure2, measureIndex) => measureIndex > cursor.measureIndex && measure2.repeatStart && order.includes(measureIndex)
16695
+ ), end = nextRepeat < 0 ? measures.length : nextRepeat;
16696
+ order = [...Array.from({ length: end - cursor.measureIndex }, (_, offset) => cursor.measureIndex + offset), ...nextRepeat < 0 ? [] : order.slice(order.indexOf(nextRepeat))], state.orderIndex = 0;
16697
+ }
16698
+ state.replay = !1;
16699
+ } else
16700
+ state.replay = !0, state.fineArmed = type === "dcAlFine" || type === "dsAlFine", state.codaArmed = type === "dcAlCoda" || type === "dsAlCoda", cursor = ["segno", "dsAlFine", "dsAlCoda"].includes(type) ? required("segno", index) : { measureIndex: 0, beat: 0 };
16691
16701
  continue;
16692
16702
  }
16693
- state.orderIndex++, cursor = { measureIndex: state.replay ? index + 1 : initialOrder[state.orderIndex] ?? measures.length, beat: 0 };
16703
+ state.orderIndex++, cursor = { measureIndex: state.replay ? index + 1 : order[state.orderIndex] ?? measures.length, beat: 0 };
16694
16704
  }
16695
16705
  if (state.fineArmed || state.codaArmed)
16696
16706
  throw new NavigationError("The armed Fine or To Coda instruction is not reachable on replay", ["/global/measures"]);