Jump to content

OSC output from WatchOut (I solved it!)


autonic

Recommended Posts

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

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 year later...
  • Member

@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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...