MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / TrackList

Class TrackList

packages/playground/src/components/TrackList.ts:15–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13);
14
15export class TrackList implements Mountable {
16 readonly root: HTMLElement;
17 private items: TrackItem[] = [];
18 private selection = new Map<number, alphaTab.model.Track>();
19 private unsubScoreLoaded: () => void;
20 private unsubRenderStarted: () => void;
21
22 constructor(private api: alphaTab.AlphaTabApi) {
23 this.root = parseHtml(html`<div class="at-track-list"></div>`);
24
25 this.unsubScoreLoaded = api.scoreLoaded.on(score => this.rebuild(score));
26 this.unsubRenderStarted = api.renderStarted.on(() => this.refreshActive());
27 }
28
29 private rebuild(score: alphaTab.model.Score): void {
30 for (const item of this.items) {
31 item.dispose();
32 }
33 this.items = [];
34 this.root.replaceChildren();
35 this.selection.clear();
36
37 for (const track of score.tracks) {
38 const item = new TrackItem(this.api, track);
39 item.onSelect = e => {
40 e.stopPropagation();
41 if (!e.ctrlKey) {
42 this.selection.clear();
43 this.selection.set(track.index, track);
44 } else if (this.selection.has(track.index)) {
45 this.selection.delete(track.index);
46 } else {
47 this.selection.set(track.index, track);
48 }
49 this.api.renderTracks(Array.from(this.selection.values()).sort((a, b) => a.index - b.index));
50 };
51 this.items.push(item);
52 this.root.appendChild(item.root);
53 }
54 this.refreshActive();
55 }
56
57 private refreshActive(): void {
58 const active = new Set<number>();
59 for (const t of this.api.tracks) {
60 active.add(t.index);
61 }
62 for (const item of this.items) {
63 item.setActive(active.has(item.track.index));
64 }
65 }
66
67 /** All TrackItem instances, in score order. */
68 getItems(): readonly TrackItem[] {
69 return this.items;
70 }
71
72 dispose(): void {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected