Problem using Kt::Param

Official support for: bluecataudio.com
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi there,

once again I need some help :-D

This time it's about using Kt::Param in order to set up (like an) array of parameters that I can use later on to switch layers of widgets on and off and do other things (by script). As there are "other things", it's not done with just a few layers and display/undisplay them by param ... a bit complicated to explain the entire idea...

I got inspired by Ilias implementation of formulas_viewer
https://github.com/ilyaorlovru/plug-n-s ... ewer.kuiml

..and tried to follow it, but something is wrong and I can't find what.

The problem that i am facing is:
I CAN actually define an array of Kt::param in a Script section, but seemingly I have no access to it from within the script.

Here's the code ( VERY experimental and completely stripped down in order to show my problem, which is the ACCESS to the Kt::param array):

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<SKIN language_version="1.0" name="" margin="0" height="200" width="400">

  <!-- MAIN PART -->
  <EXPOSED_OBJECTS object_ids="" />

  <SCRIPT requires="CB1_SVG1.display;CB1_SVG2.display" script="

    array&lt;Kt::Param@> highlight_params(2);

    void highlightChord( int i)
    {
      CB1_SVG1.display = false;
      CB1_SVG2.display = true;  
      highlight_params[1] = 1;
    }
  "/>

  <STRING id="CHORD0" default="C" exposed="true"/>
  <STRING id="CHORD1" default="Cm" exposed="true"/>
  <STRING id="CHORD2" default="C°" exposed="true"/>
  <STRING id="CHORD3" default="C+" exposed="true"/>

  <TEMPLATE id="CHORDBOX" chordNum="-">
    <PARAM id="$id$_backgroundColor" default="#00ff00"/>
    <WIDGET id="$id$_WIDGET" layout_type="layer_stack">
      <svg id="$id$_SVG1" width="40" height="40" viewBox="0 0 100 100" display="true"> <rect x="0" y="0" width="100%" height="100%" stroke="#ff0000" fill="#ff0000"/></svg>
      <svg id="$id$_SVG2" width="40" height="40" viewBox="0 0 100 100" display="false"> <rect x="0" y="0" width="100%" height="100%" stroke="#00ff00" fill="#00ff00"/></svg>
      <svg id="$id$_SVG3" width="40" height="40" viewBox="0 0 100 100" display="false"> <rect x="0" y="0" width="100%" height="100%" stroke="#0000ff" fill="#0000ff"/></svg>
      <svg id="$id$_SVG4" width="40" height="40" viewBox="0 0 100 100" display="false"> <rect x="0" y="0" width="100%" height="100%" stroke="#ffff00" fill="#ffff00"/></svg>
      <TEXT string_id="CHORD$chordNum$"/>
      <PARAM id="$id$_mouseDown" name="$id$_mouseDown" type="boolean" default="false" exposed="true"/>
      <INVISIBLE_PARAM_TOGGLE_SWITCH param_id="$id$_mouseDown" cursor="system::hand" width="100%" height="100%"/>
      <ACTION_TRIGGER event_ids="$id$_mouseDown.value_changed" script="highlightChord(0);" requires=""/>
    </WIDGET>
  </TEMPLATE>

<!-- ..................................................................................................
                                            LAYOUT
     .................................................................................................. -->
  <ROW spacing="10">

    <COLUMN>
      <WIDGET layout_type="layer_stack" >
        <CHORDBOX id="CB1" chordNum="0"/>
      </WIDGET>
      <WIDGET layout_type="layer_stack" >
        <CHORDBOX id="CB2" chordNum="1"/>
      </WIDGET>
      <WIDGET layout_type="layer_stack" >
        <CHORDBOX id="CB3" chordNum="0"/>
      </WIDGET>
    </COLUMN>
  </ROW>

</SKIN>

So, there is the define of the Kt::param array (as I understand it from Ilias example...an array with 2 Kt::Param):
array&lt;Kt::Param@> highlight_params(2);

In highlightChord(..) I deactivate/activate two svg layers, just to visualise that the function gets actually called, for nothing else ..... It does, as one of the boxes becomes green when I click on a box (by ACTION_TRIGGER). Fine.


When I reverse the order in highlightChord(..) to
highlight_params[1] = 1;
CB1_SVG1.display = false;
CB1_SVG2.display = true;

nothing happens. Which seems to me, as if it stops working at highlight_params[1] = 1, which is my access to the highlight_params array. No errors showing up, it just ends here :-D

So, there's something that I am doing wrong or a misunderstanding of concept, I don't know.

As far as I can see, the example accesses the Kt::Param array in exactly the same manner (see show_graph_a(..) and show_graph_b(..)).

Somebody can help me ?
Thanks.

Cheers
Rudi
http://www.pulpoaudio.com
Virtual Percussion Instruments
email: pulpo@pulpoaudio.com

Post

mmmmh .... think i found the answer: viewtopic.php?p=7271573&hilit=Kt%3A%3AParam#p7271573
Sort of initialisation that I didn't do (the loop) . Will try later...
http://www.pulpoaudio.com
Virtual Percussion Instruments
email: pulpo@pulpoaudio.com

Post

mh... would probably work, but would also mean a parameter overkill :-D

So I tried a different strategy to keep "things, that have to be updated" together in an array.
I tried with this code:

Code: Select all

      <SCRIPT requires="" script="

          array&lt;int> highlights(48);

          void init_highlights() {
            for( uint i=0; i&lt;48; i++) {
              highlights[i] = 0; 
            }
          }
          void set_highlights(uint ndx, uint value) {
            for( uint i=0; i&lt;48; i++) {
              highlights[i] = 0; 
            }
            highlights[ndx] = value; 
          }
:
:
        "/>
        
...works like a charm. Well, at least it compiles.
But when I include this piece into the script:

Code: Select all

          
          void doSomethingWithArray()
          {
            int x = highlights[1];
          }
...it tells me:
"- error: Error: The property has no get accessor in /Applications/Blue Cat's Plug'n Script.app/Contents/Resources/Blue Cat's Plug'n Script data/Skins/default.xml#1(39:603)
"

So....i can define a (global) array of ints, and i seemingly can set values inside this array in a different function .... but i can't read it :-| ?
But then I can, if array definition and access are in the same script function:

Code: Select all

          
          void test()
          {
            array&lt;uint64> test = {1,2,3,4,5};

            int n = test[2];
          }

So.... what am I doing wrong here.. ?

Thanks :-)
Cheers
Rudi
http://www.pulpoaudio.com
Virtual Percussion Instruments
email: pulpo@pulpoaudio.com

Post

The approach with an array of ints is indeed probably the way to go (unless you need persistency or extra services that can only provided with parameters).

The property accessor error is definitely not expected. Are you maybe using other objects with the same name elsewhere?

Post

Hi there 😊

No, I was using the short example from my last post, so there is only the highlights array...
Seems that read access is only provided in the same script function where an array is defined.
In the example, the highlights array is defined globally, so I was expecting read access is possible in any script function. The interesting part is that I can write into the array from anywhere... but not read.

Cheers
http://www.pulpoaudio.com
Virtual Percussion Instruments
email: pulpo@pulpoaudio.com

Post Reply

Return to “Blue Cat Audio”