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 0 Quote Link to comment Share on other sites More sharing options...
Dataton Partner Benoit Posted January 12, 2022 Dataton Partner Report Share Posted January 12, 2022 Nice trick! 0 Quote Link to comment Share on other sites More sharing options...
Member Quim Posted January 13, 2022 Member Report Share Posted January 13, 2022 Thank you for sharing. 0 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 0 Quote Link to comment Share on other sites More sharing options...
Jericksondesign Posted February 25, 2023 Report Share Posted February 25, 2023 Would it be possible for you to post a step by step instruction? Trying to trigger Bitfocus Companion with Watchout and this sounds like my best solution but I am quite inexperienced with code. To be specific I want to send the osc command /press/bank/1/2 Thanks! 0 Quote Link to comment Share on other sites More sharing options...
Member matkeane Posted February 26, 2023 Member Report Share Posted February 26, 2023 @Jericksondesign If you just want to control the Streamdeck, you don't need to use OSC. As long as the option is activated in the Companion settings, you can send UDP commands instead. I've used it to change the colour of buttons when aux timelines are active. To communicate with Companion I added a String output to Watchout, selected the 'Network Port' option and added the IP address of the PC running companion, with the port 51235 and selected UDP. Then, in an Aux Timeline, I added an output cue with the text (without the quotes) : "STYLE BANK 1 2 BGCOLOR CC00FF" (Note, no # symbol before the hex colour code!) In your case - until OSC support is added - I think a cue with the text "PRESS BANK 1 2" would do what you want. 0 Quote Link to comment Share on other sites More sharing options...
Jericksondesign Posted February 28, 2023 Report Share Posted February 28, 2023 Thanks so much @matkeane! We ended up building a TouchDesigner patch that converts UDP messages to OSC messages (which I'll post once it's a little more cleaned up) but I'll also give this a shot. Thanks again! 0 Quote Link to comment Share on other sites More sharing options...
Alex Ramos Posted March 5, 2023 Report Share Posted March 5, 2023 Nicely done 0 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.