forked from jummbus/jummbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSustainPrompt.ts
More file actions
74 lines (63 loc) · 3.27 KB
/
SustainPrompt.ts
File metadata and controls
74 lines (63 loc) · 3.27 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
// Copyright (c) 2012-2022 John Nesky and contributing authors, distributed under the MIT license, see accompanying the LICENSE.md file.
import {Config} from "../synth/SynthConfig";
import {Instrument} from "../synth/synth";
import {HTML} from "imperative-html/dist/esm/elements-strict";
import {SongDocument} from "./SongDocument";
import {Prompt} from "./Prompt";
import {ChangeGroup} from "./Change";
import {ChangeStringSustainType} from "./changes";
const {button, div, h2, p, select, option} = HTML;
export class SustainPrompt implements Prompt {
private readonly _typeSelect: HTMLSelectElement = select({style: "width: 100%;"},
option({value: "acoustic"}, "(A) Acoustic"),
option({value: "bright"}, "(B) Bright"),
);
private readonly _cancelButton: HTMLButtonElement = button({class: "cancelButton"});
private readonly _okayButton: HTMLButtonElement = button({class: "okayButton", style: "width:45%;"}, "Okay");
public readonly container: HTMLDivElement = div({class: "prompt", style: "width: 300px;"},
div(
h2("String Sustain"),
p("This setting controls how quickly the picked string vibration decays."),
p("Unlike most of BeepBox's instrument synthesizer features, a picked string cannot change frequency suddenly while maintaining its decay. If a tone's pitch changes suddenly (e.g. if the chord type is set to \"arpeggio\" or the transition type is set to \"continues\") then the string will be re-picked and start decaying from the beginning again, even if the envelopes don't otherwise restart."),
),
div({style: {display: Config.enableAcousticSustain ? undefined : "none"}},
p("BeepBox comes with two slightly different sustain designs. You can select one here and press \"Okay\" to confirm it."),
div({class: "selectContainer", style: "width: 100%;"}, this._typeSelect),
),
div({style: {display: Config.enableAcousticSustain ? "flex" : "none", "flex-direction": "row-reverse", "justify-content": "space-between"}},
this._okayButton,
),
this._cancelButton,
);
constructor(private _doc: SongDocument) {
const instrument: Instrument = this._doc.song.channels[this._doc.channel].instruments[this._doc.getCurrentInstrument()];
this._typeSelect.value = Config.sustainTypeNames[instrument.stringSustainType];
setTimeout(()=>this._cancelButton.focus());
this._okayButton.addEventListener("click", this._saveChanges);
this._cancelButton.addEventListener("click", this._close);
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);
}
private _whenKeyPressed = (event: KeyboardEvent): void => {
if ((<Element> event.target).tagName != "BUTTON" && event.keyCode == 13) { // Enter key
this._saveChanges();
}
}
private _saveChanges = (): void => {
if (Config.enableAcousticSustain) {
const group: ChangeGroup = new ChangeGroup();
group.append(new ChangeStringSustainType(this._doc, <any> Config.sustainTypeNames.indexOf(this._typeSelect.value)));
this._doc.prompt = null;
this._doc.record(group, true);
} else {
this._close();
}
}
}