forked from featherbear/presonus-studiolive-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
151 lines (125 loc) · 4.41 KB
/
test.ts
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
import { CHANNELS, ChannelSelector, Client, MESSAGETYPES, ZlibPayload } from './src/api'
import { intToLE } from './src/lib/util/bufferUtil'
// const stream = createWriteStream('100.csv', { flags: 'a' })
function doIt() {
const client = new Client('192.168.0.18', 53000)
// client.on('data', function ({ code, data }) {
// // console.log('Got payload with code', code, data)
// })
// client.on(MESSAGETYPES.FaderPosition, function (MS) {
// // LINEAR
// function OPLog(d: { [a: string]: number | number[] }) {
// console.log(
// Object.entries(d).reduce(
// (o, [k, v]) => ({
// ...o,
// [k]:
// (Array.isArray(v) ? v : [v]).map(
// (v) =>
// v.toString().padStart(5, ' ')).join(', ')
// }), {}
// )
// )
// }
// // OPLog(MS)
// // console.log(MS.length, MS);
// })
// client.on(MESSAGETYPES.Setting, function (PV) {
// // LOGARITHMIC
// const { name, value }: { name: string, value: Buffer } = PV
// if (!name.startsWith('line')) return
// const r = {
// name
// }
// const R: any = r
// let pv: any = {
// buffer: value
// }
// if (Buffer.isBuffer(value)) {
// // Logarithmic?
// pv = {
// ...pv,
// value: value.readUInt32LE(0),
// value_scaled: value.readUInt32LE(0) - 1063699898, // 0x3f66c5ba,
// value_scaled_ratio: (value.readUInt32LE(0) - 1063699898) / 143369 // 0x23009,
// }
// }
// R.PV = pv
// /* Volume controls are sent from 0x3af..... to 0x00000000 */
// if (ZB) {
// const zbVal = getZlibValue<number>(ZB, name)
// R.ZB = {
// value: zbVal,
// value_scaled: Math.max(0, (zbVal - 1008981765)),
// value_scaled_ratio: Math.max(0, (zbVal - 1008981765)) / 56371451
// }
// // y = 0.2292ln(x) - 0.06
// // upper bound - 1065353216
// // lower bound - 1008981765
// // stream.write(`${R.PV.value_scaled_ratio},${R.ZB.value_scaled_ratio}\n`)
// }
// if (name.endsWith('/volume')) {
// (r as any).type = 'volume'
// // Here, have some random constants
// // console.info('S', value.slice(0, 4), value.readUInt32LE(0) - 0x3f66c5ba, (value.readUInt32LE(0) - 0x3f66c5ba) / 0x23009)
// }
// console.log(r)
// // client.close().then(() => {
// // doIt()
// // })
// })
let ZB = null
client.on(MESSAGETYPES.ZLIB, function (_ZB) {
ZB = _ZB
console.log('ready')
})
// console.log('access code', getZlibValue(ZB, 'permissions.access_code'))
// console.log(getZlibValue(ZB, 'global'))
// )
// function intToLE(i) {
// const res = Buffer.allocUnsafe(4)
// res.writeUInt32BE(i)
// return res
// }
// const floor = 0x3a970133
// const { chnum, name, username, color, select, solo, volume, mute, pan } = ZB.children.line.children.ch1.values
// console.log({
// chnum,
// name,
// username,
// color,
// select,
// solo,
// volume,
// volume2: intToLE(volume),
// volume3:
// intToLE(volume).readInt32LE() === 0 ? 0 : (intToLE(volume).readInt32LE() - floor) / (0X3f800000 - floor),
// mute,
// pan
// })
// big endian actually hey
// ["00000000", "3d76bf3a", "3e018acb", "3e4b90f6", "3ea062b2", "3ec25031", "3ed4d1bb", "3f031597", "3f250315", "3f2e43da", "3f3a9a36", 0, "3f3f3a9b", "3f4a062c", "3f565c88", "3f62b2e6", "3f73a9a2", "3f7b5f9d", "3f800000"]
// writeFileSync('file.json', JSON.stringify([...JSON.parse(readFileSync('file.json', 'utf8')), intToLE(volume).toString('hex')]))
// exit(1)
// client.on('discover', console.table)
// client.discoverySubscribe()
client.on(MESSAGETYPES.FaderPosition, function (MS) {
console.log(MS);
})
client.connect().then(() => {
// setInterval(() => {
// console.log(
// {
// consoleName: client.state.get('global.mixer_name'),
// consoleType: client.state.get('global.devicename'),
// version: client.state.get('global.mixer_version'),
// versionDate: client.state.get('global.mixer_version_date'),
// serial: client.state.get('global.mixer_serial'),
// registeredUser: client.state.get('global.registered_user'),
// }
// )
// }, 500)
})
}
console.log('go')
doIt()