-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.js
177 lines (157 loc) · 4.18 KB
/
scene.js
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//// DATA DEFINITION HELPERS ////
var
_assign= ["none", "cc", "note"],
_behavior= ["momentary", "toggle"],
_bool= ["disable", "enable"],
_channel= [,,,,,,,,,,,,,,,"global"]
function bool(){
return {
max: 1,
values: _bool
}
}
//// DATA DEFINITIONS ////
// common parameters
export let common= {
globalMidiChannel: {max: 15},
contorlMode: {values: ["cc", "cubase", "dp", "live", "protools", "sonar"]},
ledMode: {values: ["internal", "external"]}
}
// control group params
export let controlGroup= {
groupMidiChannel: {values: _channel},
sliderAssign: bool(),
reserved: {max: 0},
sliderCcNote: {},
sliderMin: {},
sliderMax: {},
reserved2: {max: 0},
knobAssign: bool(),
reserved3: {max: 0},
knobCcNote: {},
knobMin: {},
knobMax: {},
reserved4: {max: 0},
soloAssign: {values: _assign},
soloBehavior: {values: _behavior},
soloCcNote: {},
soloOff: {},
soloOn: {},
reserved5: {max: 0},
muteAssign: {values: _assign},
muteBehavior: {values: _behavior},
muteCcNote: {},
muteOff: {},
muteOn: {},
reserved6: {max: 0},
recAssign: {values: _assign},
recBehavior: {values: _behavior},
recCcNote: {},
recOff: {},
recOn: {},
reserved7: {}
}
// index where each control group begins
export let controlGroupOffsets=[ 3, 34, 65, 96, 127, 158, 189, 220]
export let controlGroups= [ 1, 2, 3, 4, 5, 6, 7, 8]
export let transportChannel= normalize({ index: 251, values: _channel}, "transportChannl")
export let transport= {
assign: {values: _assign},
behavior: {values: _behavior},
ccNote: {},
off: {},
on: {},
reserved: {max: 0}
}
export let transportOffsets=[ 252, 258, 264, 270, 276, 282, 288, 294, 300, 306, 312]
export let transports={
"prev": {},
"next": {},
"cycle": {},
"marker": {},
"prevMarker": {},
"nextMarker": {},
"rew": {},
"ff": {},
"stop": {},
"play": {},
"rec": {}
}
export let customDAW={ max: 255, valid: [ 0, 42, 42, 46, 47, 48, 49, 50, 127, 255]}
// an array with the definition of each byte
// the above data is used to fill out this array
export let scene= new Array( 338)
export default scene
//// BUILD SCENE ////
function normalize( o, name){
o.name= name
if( o.values&& !o.max){
o.max= o.values.length- 1 // calculate max
}
if( o.max=== undefined){
o.max= 127 // default max
}
if( o.min=== undefined){
o.min= 0 // default min
}
for( var i in o.values){
if( o.values[ i]=== undefined){
o.values[ i]= i // values are identity if not defined
}
}
for( var i in o.values|| []){
var key= o.values[ i]
o[ key]= Number.parseInt( i)
}
return o
}
// common
var commonKeys= Object.keys( common)
for( var index= 0; index< commonKeys.length; ++index){
var
name= commonKeys[ index],
o= normalize( common[ name], name)
o.index= index
scene[ index]= o
}
// control groups
var controlGroupKeys= Object.keys( controlGroup)
for( var keyNum= 0; keyNum< controlGroupKeys.length; ++keyNum){
var
name= controlGroupKeys[ keyNum],
o= normalize( controlGroup[ name], name)
// each control group is repeated across all 8 channels,
// with each channel starting at it's own offset
for( var channel= 0; channel< controlGroupOffsets.length;){ // we increment channel in the final Object.assign
var
offset= controlGroupOffsets[ channel],
index= keyNum+ offset
scene[ index]= Object.assign({ channel: ++channel, index}, o)
}
}
// transport
scene[ 251]= transportChannel
// transport groups
var
transportKeys= Object.keys( transport), // fields in a transport
transportNames= Object.keys( transports) // names of all transports
for( var keyNum= 0; keyNum< transportKeys.length; ++keyNum){
var
name= transportKeys[ keyNum],
o= normalize( transport[ name], name)
// each transport group is repeated across all 8 channels,
// with each channel starting at it's own offset
for( var transportIndex= 0; transportIndex< transportOffsets.length;){ // we increment transportIndex in the final Object.assign
var
offset= transportOffsets[ transportIndex],
index= keyNum+ offset,
transportName= transportNames[ transportIndex],
val= Object.assign({ index: ++transportIndex, index}, o)
scene[ index]= val
transports[ transportName][ name]= val
}
}
// custom DAW
for( var i= 318; i<= 322; ++i){
scene[ i]= normalize( customDAW, "customDAW")
}