-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathMuteEditor.ts
52 lines (42 loc) · 2.13 KB
/
MuteEditor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) John Nesky and contributing authors, distributed under the MIT license, see accompanying the LICENSE.md file.
import {SongDocument} from "./SongDocument.js";
import {HTML} from "imperative-html/dist/esm/elements-strict.js";
import {ColorConfig} from "./ColorConfig.js";
import {ChannelRow} from "./ChannelRow.js";
export class MuteEditor {
private _cornerFiller: HTMLDivElement = HTML.div({style: `background: ${ColorConfig.editorBackground}; position: sticky; bottom: 0; left: 0; width: 32px; height: 30px;`});
public readonly container: HTMLElement = HTML.div({class: "muteEditor"});
private readonly _buttons: HTMLButtonElement[] = [];
constructor(private _doc: SongDocument) {
this.container.addEventListener("click", this._onClick);
}
private _onClick = (event: MouseEvent): void => {
const index = this._buttons.indexOf(<HTMLButtonElement> event.target);
if (index == -1) return;
this._doc.song.channels[index].muted = !this._doc.song.channels[index].muted;
this._doc.notifier.changed();
}
public render(): void {
if (!this._doc.prefs.enableChannelMuting) return;
if (this._buttons.length != this._doc.song.getChannelCount()) {
for (let y: number = this._buttons.length; y < this._doc.song.getChannelCount(); y++) {
const muteButton: HTMLButtonElement = HTML.button({class: "mute-button", title: "Mute (M), Mute All (⇧M), Solo (S), Exclude (⇧S)", style: `height: ${ChannelRow.patternHeight - 4}px; margin: 2px;`});
this.container.appendChild(muteButton);
this._buttons[y] = muteButton;
}
for (let y: number = this._doc.song.getChannelCount(); y < this._buttons.length; y++) {
this.container.removeChild(this._buttons[y]);
}
this._buttons.length = this._doc.song.getChannelCount();
// Always put this at the bottom, below all the other buttons, to cover up the loop editor when scrolling.
this.container.appendChild(this._cornerFiller);
}
for (let y: number = 0; y < this._doc.song.getChannelCount(); y++) {
if (this._doc.song.channels[y].muted) {
this._buttons[y].classList.add("muted");
} else {
this._buttons[y].classList.remove("muted");
}
}
}
}