summaryrefslogtreecommitdiff
path: root/client/lib/scales.js
blob: 8480f9eaf3105cb0351f697c5917514966f8826c (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import Intonation from './intonation'

const meantone = `! meanquar.scl
!
1/4-comma meantone scale. Pietro Aaron's temperament (1523)
 12
!
 76.04900
 193.15686
 310.26471
 5/4
 503.42157
 579.47057
 696.57843
 25/16
 889.73529
 1006.84314
 1082.89214
 2/1
`

const mavila = `! mavila12.scl
!
A 12-note mavila scale (for warping meantone-based music), 5-limit TOP
 12
!
-30.99719
 163.50770
 358.01258
 327.01540
 521.52028
 490.52310
 685.02798
 654.03080
 848.53568
 1043.04057
 1012.04338
 1206.54826
`

const carlos_alpha = `! carlos_alpha.scl
!
Wendy Carlos' Alpha scale with perfect fifth divided in nine
 18
!
 78.00000
 156.00000
 234.00000
 312.00000
 390.00000
 468.00000
 546.00000
 624.00000
 702.00000
 780.00000
 858.00000
 936.00000
 1014.00000
 1092.00000
 1170.00000
 1248.00000
 1326.00000
 1404.00000
`

const lamonte = `! young-lm_piano.scl
!
LaMonte Young's Well-Tempered Piano
12
!
567/512
9/8
147/128
21/16
1323/1024
189/128
3/2
49/32
7/4
441/256
63/32
2/1
`

const scales = [
  {
    intervals: '1/1 9/8 5/4 4/3 3/2 5/3 15/8 2/1',
    name: "harmonic scale",
  },
  {
    root: 450,
    intervals: '1/1 9/8 5/4 4/3 3/2 5/3 15/8 2/1',
    name: "harmonic scale @ 450",
  },
  {
    tet: 5,
  },
  {
    tet: 12,
  },
  {
    tet: 17,
  },
  {
    intervals: '1/1 81/80 33/32 21/20 16/15 12/11 11/10 10/9 9/8 8/7 7/6 32/27 6/5 11/9 5/4 14/11 9/7 21/16 4/3 27/20 11/8 7/5 10/7 16/11 40/27 3/2 32/21 14/9 11/7 8/5 18/11 5/3 27/16 12/7 7/4 16/9 9/5 20/11 11/6 15/8 40/21 64/33 160/81 2/1',
    name: "harry partch scale",
  },
  {
    scl: lamonte,
  },
  {
    scl: meantone,
  },
  {
    scl: mavila,
  },
  {
    scl: carlos_alpha,
  },
].map( (opt) => new Intonation(opt) )

let scale = scales[0]
let handleChange = function(){}

function build () {
  scales.forEach( (scale, i) => {
    scale.heading = document.createElement('div')
    scale.heading.innerHTML = scale.name
    scale.heading.classList.add('heading')
    scale.heading.addEventListener('click', function(){
      pick(i)
    })
    scale_list.appendChild(scale.heading)
  })

  pick(0)
}

function pick (i) {
  if (scale) {
    scale.heading && scale.heading.classList.remove('selected')
  }
  scale = scales[i]
  scale.heading && scale.heading.classList.add('selected')
	handleChange(scale)
}

function current () {
  return scale
}

function onChange (fn) {
	handleChange = fn
}

function names () {
	return scales.map( scale => scale.name )
}


export default { scales, current, build, pick, names, onChange }