jevstrudel.git / packages / osc / tidal-sniffer.js
1/*
2tidal-sniffer.js - <short description TODO>
3Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/src/branch/main/packages/osc/tidal-sniffer.js>
4This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program.  If not, see <https://www.gnu.org/licenses/>.
5*/
6
7import OSC from 'osc-js';
8
9const config = {
10  receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client
11  udpServer: {
12    host: 'localhost', // @param {string} Hostname of udp server to bind to
13    port: 57120, // @param {number} Port of udp client for messaging
14    exclusive: false, // @param {boolean} Exclusive flag
15  },
16  udpClient: {
17    host: 'localhost', // @param {string} Hostname of udp client for messaging
18    // port: 57120, // @param {number} Port of udp client for messaging
19    port: 41235, // @param {number} Port of udp client for messaging
20  },
21  wsServer: {
22    host: 'localhost', // @param {string} Hostname of WebSocket server
23    port: 8080, // @param {number} Port of WebSocket server
24  },
25};
26const osc = new OSC({ plugin: new OSC.BridgePlugin(config) });
27
28osc.open(); // start a WebSocket server on port 8080
29
30console.log('osc client running on port', config.udpClient.port);
31console.log('osc server running on port', config.udpServer.port);
32console.log('websocket server running on port', config.wsServer.port);
33
34// listen for messages from the client
35osc.on('*', (m) => {
36  console.log('received:', m.address, m.args);
37});
38
39/*
40example tidal messages:
41
42/*
43
44received: /dirt/play [
45  '_id_',
46  '1',
47  'cps',
48  0.5625,
49  'cycle',
50  503.5,
51  'delta',
52  0.8888888359069824,
53  'orbit',
54  0,
55  's',
56  'bd'
57]
58received: /dirt/play [
59  '_id_',  '1',
60  'cps',   0.5625,
61  'cycle', 503.6666564941406,
62  'delta', 0.592592716217041,
63  'orbit', 0,
64  's',     'hh'
65]
66received: /dirt/play [
67  '_id_',
68  '1',
69  'cps',
70  0.5625,
71  'cycle',
72  504,
73  'delta',
74  0.8888888359069824,
75  'orbit',
76  0,
77  's',
78  'bd'
79]
80received: /dirt/play [
81  '_id_',
82  '1',
83  'cps',
84  0.5625,
85  'cycle',
86  504,
87  'delta',
88  0.592592716217041,
89  'orbit',
90  0,
91  's',
92  'hh'
93]
94received: /dirt/play [
95  '_id_',
96  '1',
97  'cps',
98  0.5625,
99  'cycle',
100  504.3333435058594,
101  'delta',
102  0.5925922393798828,
103  'orbit',
104  0,
105  's',
106  'hh'
107]
108received: /dirt/play [
109  '_id_',
110  '1',
111  'cps',
112  0.5625,
113  'cycle',
114  504.5,
115  'delta',
116  0.8888888359069824,
117  'orbit',
118  0,
119  's',
120  'bd'
121]
122received: /dirt/play [
123  '_id_',  '1',
124  'cps',   0.5625,
125  'cycle', 504.6666564941406,
126  'delta', 0.592592716217041,
127  'orbit', 0,
128  's',     'hh'
129]
130
131*/