autonic Posted January 12, 2022 Report Share Posted January 12, 2022 If anyone is interested I found a fairly simple way to send OSC commands from WatchOut 6.6. Use the attached google sheet to input the target OSC adress (and any neccessary arguments) and the script will format the string into UDP-messages that are recognized as valid OSC commands. Just create a String Output, set it to UDP network data and set the target IP and adress. Then use this form to generate valid OSC-commands and paste them in the string field. In case the google sheet doesnt export/import the custom function I'll paste the javascript code for the function here: function stringToHex(str){ string = str.split(':') const typeTags = [','] var oscAddress = '' const arguments = [] for (let i = 0; i <= string.length-1; i++) { // encode osc address if (i == 0) { oscAddress = addPadding(hexEncodeString(string[i])) // handle optional arguments } else if (i > 0 && !isEmpty(string[i])) { // determine argument type if (isNaN(string[i])) { type = 's' arguments.push(addPadding(hexEncodeString(string[i]) + '$00')) } else if (isInteger(parseInt(string[i]))) { type = 'i' arguments.push(addPadding(hexEncodeInt(parseInt(string[i])))) } else if (isFloat(parseFloat(string[i]))) { type = 'f' arguments.push(addPadding(hexEncodeFloat(string[i]))) } // push osc type tag array typeTags.push(type) } } // return output if (string.length == 1) return oscAddress + addPadding(hexEncodeString(typeTags.join(''))) if (string.length > 1) return oscAddress + addPadding(hexEncodeString(typeTags.join(''))) + arguments.join('') return 'incorrect string input format' } function hexEncodeString(string) { try{ hex = unescape(encodeURIComponent(string)) .split('').map(function(v){ return v.charCodeAt(0).toString(16) }).join('$') } catch(e){ hex = string[i] console.log('invalid text input: ' + string) return 'error' } return '$' + hex } function hexEncodeInt(s) { var a = s.toString(16); if ((a.length % 2) > 0) { a = "0" + a; } hexString = a.padStart(8, '0'); return '$' + addItemEvery(hexString, '$', 2) } function hexEncodeFloat(number) { const getHex = i => ('00' + i.toString(16)).slice(-2); var view = new DataView(new ArrayBuffer(4)), result; view.setFloat32(0, number); result = Array .apply(null, { length: 4 }) .map((_, i) => getHex(view.getUint8(i))) .join(''); return '$' + addItemEvery(result, '$', 2) } function addItemEvery (str, item, every){ for(let i = 0; i < str.length; i++){ if(!(i % (every + 1))){ str = str.substring(0, i) + item + str.substring(i); } } return str.substring(1); } function addPadding(byteString) { addressLength = byteString.split('$').length - 1 // string is divisible by 4 if(addressLength % 4 === 0) { byteString = byteString // string is not divisible by 4, needs padding } else { var padding = '' divisibleBy = '' + addressLength / 4 decimals = divisibleBy.split('.') if (decimals[1] == '25') padding = '$00$00$00' if (decimals[1] == '5') padding = '$00$00' if (decimals[1] == '75') padding = '$00' byteString = byteString + padding } return byteString } function isFloat(n) { return n === +n && n !== (n|0); } function isInteger(n) { return n % 1 === 0; } function isEmpty(str) { return (!str || /^\s*$/.test(str)); } OSC to UDP-string converter.xlsx Quote Link to comment Share on other sites More sharing options...
Benoit Posted January 12, 2022 Report Share Posted January 12, 2022 Nice trick! Quote Link to comment Share on other sites More sharing options...
Quim Posted January 13, 2022 Report Share Posted January 13, 2022 Thank you for sharing. Quote Link to comment Share on other sites More sharing options...
kai Posted February 15, 2022 Report Share Posted February 15, 2022 Thank you for sharing this Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.