-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCustomScalePrompt.ts
More file actions
77 lines (64 loc) · 3.15 KB
/
Copy pathCustomScalePrompt.ts
File metadata and controls
77 lines (64 loc) · 3.15 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2020 John Nesky, distributed under the MIT license.
import { Config } from "../synth/SynthConfig";
import { HTML } from "imperative-html/dist/esm/elements-strict";
import { SongDocument } from "./SongDocument";
import { Prompt } from "./Prompt";
import { ChangeCustomScale } from "./changes";
//namespace beepbox {
const { button, div, h2, input, p } = HTML;
export class CustomScalePrompt implements Prompt {
private readonly _flags: boolean[] = [];
private readonly _scaleFlags: HTMLInputElement[] = [];
private readonly _scaleRows: HTMLDivElement[] = [];
private readonly _cancelButton: HTMLButtonElement = button({ class: "cancelButton" });
private readonly _okayButton: HTMLButtonElement = button({ class: "okayButton", style: "width:45%;" }, "Okay");
public readonly container: HTMLDivElement;
constructor(private _doc: SongDocument) {
this._flags = _doc.song.scaleCustom.slice();
let scaleHolder: HTMLDivElement = div({});
for (var i = Config.pitchesPerOctave - 1; i > 0; i--) {
this._scaleFlags[i] = input({ type: "checkbox", style: "width: 1em; padding: 0; margin-right: 4em;", "checked": this._flags[i], "value": i });
this._scaleRows[i] = div({ style: "text-align: right; height: 2em;" },
"Note " + i + ":",
this._scaleFlags[i]
);
scaleHolder.appendChild(this._scaleRows[i]);
console.log("new!");
}
this._okayButton.addEventListener("click", this._saveChanges);
this._cancelButton.addEventListener("click", this._close);
this.container = div({ class: "prompt noSelection", style: "width: 250px;" },
h2("Custom Scale"),
p("Here, you can make your own scale like a pro gamer. Press the checkboxes below to toggle which notes of an octave are in the scale. For this to work, you'll need to have the \"Custom\" scale selected."),
div({ style: "display: flex; flex-direction: row; align-items: center; justify-content: flex-end;" },
scaleHolder,
),
div({ style: "display: flex; flex-direction: row-reverse; justify-content: space-between;" },
this._okayButton,
),
this._cancelButton,
)
this.container.addEventListener("keydown", this.whenKeyPressed);
}
private _close = (): void => {
this._doc.undo();
}
public cleanUp = (): void => {
this._okayButton.removeEventListener("click", this._saveChanges);
this._cancelButton.removeEventListener("click", this._close);
this.container.removeEventListener("keydown", this.whenKeyPressed);
}
public whenKeyPressed = (event: KeyboardEvent): void => {
if ((<Element>event.target).tagName != "BUTTON" && event.keyCode == 13) { // Enter key
this._saveChanges();
}
}
private _saveChanges = (): void => {
for (var i = 1; i < this._scaleFlags.length; i++) {
this._flags[i] = this._scaleFlags[i].checked;
}
this._doc.prompt = null;
this._doc.record(new ChangeCustomScale(this._doc, this._flags));
}
}
//}