-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsettings.js
More file actions
85 lines (77 loc) · 1.63 KB
/
settings.js
File metadata and controls
85 lines (77 loc) · 1.63 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
78
79
80
81
82
83
84
85
import css from './settings.css.js';
class Settings extends HTMLElement {
static get observedAttributes() {
return ['step-duration'];
}
constructor() {
super();
this.drum = 1;
this.control = 14;
this.synth = 8;
this.stepDuration = 0;
this.shadow = this.attachShadow({ mode: 'open' });
this.shadow.innerHTML = `
<style>
${css}
</style>
<section id="root"></section>
`;
}
connectedCallback() {
this.render();
this.addEventListener('click', evt => {
const target = evt.path
.find(
e =>
e.classList &&
(e.classList.contains('drum') ||
e.classList.contains('control') ||
e.classList.contains('synth'))
)
.classList.toString();
this[target]++;
if (this[target] === 17) {
this[target] = 1;
}
this.dispatchEvent(
new CustomEvent(`${target}-channel`, {
detail: this[target]
})
);
this.render();
});
}
attributeChangedCallback(name, oldVal, newVal) {
if (name === 'step-duration') {
this.stepDuration = parseFloat(newVal);
}
}
render() {
this.shadow.getElementById('root').innerHTML = `
<div class="drum">
<span class="i">y</span>
${this._numToSpans(this.drum)}
</div>
<div class="control">
<span class="i">z</span>
${this._numToSpans(this.control)}
</div>
<div class="synth">
<span class="i">x</span>
${this._numToSpans(this.synth)}
</div>
`;
}
_numToSpans(num) {
if (num < 10) {
num = `0${num}`;
} else {
num = num.toString();
}
return num
.split('')
.map(n => `<span class="n${n}">${n}</span>`)
.join('');
}
}
customElements.define('finger-settings', Settings);