Facility Control

 View Only
Expand all | Collapse all

Extracting a variable length value from a String

  • 1.  Extracting a variable length value from a String

    Posted 10-16-2020 12:31

    Hi,

    I'm working on a Panel to control a Yamaha Mixer via their SCP Protocol.
    I can fire TCP strings at the mixer and control it just fine, based off a fader widget and range constraint parameter.

    I can also receive the current value of the fader from the mixer into a parameter on Dashboard which looks like this:

    NOTIFY set MIXER:Current/InCh/Fader/Level 0 0 1000 "10.00" 

    The value highlighted in bold is the actual value of the Fader, this ranges from -32678 to 1000. So the string length varies.

    I can trim off the portion before the fader value but I'm then left with both that and the value in quotations.
    I need this to just be an integer value as I want to write it back to the Fader parameter so its accurate incase someone rides the levels manually.

    Looking at the available Visual logic elements I can't see a way to achieve this as it seems to be for specific character positions and my string length is dynamic.

    Any chance someone could help me out please?

    Cheers,

    Chris



  • 2.  RE: Extracting a variable length value from a String

    Posted 10-16-2020 13:09

    You might have to do this outside of visual logic.   What you probably want is a split.   You take the string and split it on spaces.  This creates an array of elements  Then you want the 5th index.   Something like this:

      var stringToParse = 'NOTIFY set MIXER:Current/InCh/Fader/Level 0 0 1000 "10.00"'
      var arrayToParse = stringToParse.split(" ");
      var highlighted = arrayToParse[5]
      ogscript.debug("highlighted is " + highlighted);

     

    This works if you always get the same number of words back as a response.

    You can also do it in one line:

      var highlighted = stringToParse.split(" ")[5];

     

    There is probably a way to do it in Visual Logic, but it would be a little complicated.  Are you ok doing it in ogscript?   If this is part of a much bigger Visual Logic task, you can also just drop a "Custom Code" block in it just to run that part.

     

     


    #DashBoard


  • 3.  RE: Extracting a variable length value from a String

    Posted 10-16-2020 15:15

    Thanks Ben, 

    I tweaked in a parameter value read and write and it works great.

    Now looking to cleanup my panel a little. I have a TCP sender configured to send a string to my mixer based on a parameter for the fader value. How would I get this to only send when this parameter changes? I guess the "onchange" Ogscript handle?

    Cheers,

    Chris


    #DashBoard


  • 4.  RE: Extracting a variable length value from a String

    Posted 10-16-2020 15:17

    You can use "onchange", but an easier way is just to attach the task to the parameter.   

    Double click on the parameter in Panel Builder mode, and at the bottom, you will see a list of tasks.  

    Those tasks are triggered when the parameter changes.


    #DashBoard


  • 5.  RE: Extracting a variable length value from a String

    Posted 10-16-2020 15:46

    Ah cool, that's what I have set up at the moment.

    Would writing a value to the parameter count as a change? I suppose it would. Which means I have a loop of comms blasting my panel. 

    My aim is to be able to adjust the fader on the screen but also have it read back, so if the mixer levels are ridden locally, that gets reflected on the panel. But writing the value that is read back just creates a loop.


    #DashBoard


  • 6.  RE: Extracting a variable length value from a String

    Posted 10-16-2020 17:27

    You cannot write to the parameter within that task.  As you say, that just creates a loop.


    #DashBoard


  • 7.  RE: Extracting a variable length value from a String

    Posted 10-16-2020 17:51

    So what would be the best way to accomplish this?

    I've tried creating another task and it gives me the same result.

     


    #DashBoard


  • 8.  RE: Extracting a variable length value from a String

    Posted 10-16-2020 18:08

    I'm not clear what you are trying to accomplish.   

    Is it that:

    1. the mixer can send you values for the faders, which you want to display.   

    2. But also you want users to be able to change those values and it would send an update to the mixer?

     

    I think in order to do that, in your task that gets triggered when the parameter changes, you would need to include a flag to say if the parameter change was caused by an incoming message.   If it was, do not relay it forward.

     

      if (ogscript.getObject("incomingmessage") == "false") {

        // send the message to the mixer

      } else {

        // this message just came from the mixer, so don't forward it. and reset the flag.

        ogscript.setObject("incomingmessage", false);

      }

     

     

    In the task that handles the incoming messages, before you set the parameter, you would have to set your flag.

      ogscript.setObject("incomingmessage", true);

      params.setParam("faderval",0, value);

     

    I think that is how I would approach it, although it can get a little messy like that when you get multiple values quickly.

     

     

     


    #DashBoard


  • 9.  RE: Extracting a variable length value from a String

    Posted 10-19-2020 09:56

    Hi Ben,

    Hope you had a good weekend. 

    Yep, that is exactly what I want to accomplish and the way you suggest makes complete sense.

    Just one question regarding the "incomingmessage" part of the IF statement. Presuming this will be my incoming string, can it be chopped down to just include the initial "NOTIFY set MIXER:Current/InCh/Fader/Level" as the value will be changing after this?

    Or is the "incomingmessage" simply telling the param that any string message on the port will be ignored/accepted?

    Thanks so much for your help so far on this!


    #DashBoard


  • 10.  RE: Extracting a variable length value from a String

    Posted 10-19-2020 18:49

    The "incomingmessage" is just the name of the object (or flag) we're using to decide if we need to send it back to the device or not.

    That flag is being used to tell DashBoard: "hey, we just got this message from the device, don't send it back to the device when we change the parameter"

     

     


    #DashBoard


  • 11.  RE: Extracting a variable length value from a String

    Posted 10-21-2020 09:04

    Thanks Ben,

    That makes sense. I've managed to create something that is relatively functional now.

    Thanks for your help.


    #DashBoard