Saving Panel data in presets



  • I've used a lot of panels in my latest project - so I can work easily with dbl-click event - but they need to retain an internal state so I use

    myPanel.data.state = whatever;

    Sadly my Panels dont seem to keep this data when I save the instrument presets...do I have to go hide some other widget in my panel to keep state like this?



  • @Lindon You can store an object as the panel's value and put whatever data you like in there. As long as the panel is set to saveInPreset it will be recalled in on init.



  • @d-healey thanks - yes that what i thought but it seems not to be recalling it - let me do some more investigation..





  • @d-healey LOl thanks yes - but I think I've worked out whats happening:

    My "on mouse event" callback redraws the panel based upon the internal data.state, - and this (clearly) isnt getting called when I change presets....

    Anyone know how I can get it to be called?



  • @Lindon Don't use the data.state, store it in the panel's value instead and use that in your mouse callback. Or in the panel's control callback you could set the data.state value from the saved value.



  • @d-healey wha?

    heres what I'm doing in the mouse callback:

     if (event.clicked)
        {
            this.data.state = 1 - this.data.state;
            //Console.print("current state:" + this.data.state);
    
            this.data.target.setBypassed(1 - this.data.state);
        };
        if (event.doubleClick)
        {        
             //set the panel up properly..
             VelocityPanel.set("x", editPanelXPositions[this.data.panelX]);
             VelocityPanel.set("y", this.data.panelY);
             VelocityDepth.setValue(this.data.target.getIntensity());
             
             VelocityTitle.set("text", this.data.targetName + " Velocity - Voice " + this.data.targetVoice);
             //Console.print("VelocityModulatorVoice" + (currentSelectingVoice+1));
             VelocityTable.set("processorId",this.data.targetName + "VelocityModulator" + this.data.targetVoice);
             targetModulator = this.data.target;
             FloatingPanelCloses();
             VelocityPanel.showControl(true);      
        }; 
    
        if (this.data.state)
        {
            this.set("textColour", SELECT_ON_COLOUR);
        }else{
            this.set("textColour", SELECT_OFF_COLOUR);
        };
    
    

    As you can see there are several data elements in the panel e.g.:

    this.data.state - is the on/off state of this (sorta) button
    this.data.target - actually the synth component (modulator) we are trying to control

    So what are you saying I should do?



  • Save your data object into the panel's value and restore it at on init inside the panel's control callback.

    inline function onPanelControl(component, value)
    {
        local data = value.data;
        component.data.state = data.state;
        component.data.target = data.target;
    }
    


  • @d-healey thanks, but Im probably being really dumb but theres(at least) two things i dont get:

    1. How do I populate this value.data?

    Right now I'm doing this:

        VolumeVelocitySelectors[idx].data.targetName = "Volume";
        VolumeVelocitySelectors[idx].data.targetVoice = (idx + 1);
        VolumeVelocitySelectors[idx].data.panelX = idx;
        VolumeVelocitySelectors[idx].data.panelY = 64;
        VolumeVelocitySelectors[idx].data.target =  Synth.getModulator("VolumeVelocityModulator" + (idx + 1));
    

    Theres a bunch of these so - the array of these panels

    are you then saying I simply add the line :

    VolumeVelocitySelectors[idx].value = VolumeVelocitySelectors[idx].data;

    ?

    1. How does this:
    inline function onPanelControl(component, value)
    {
        local data = value.data;
        component.data.state = data.state;
        component.data.target = data.target;
    }
    

    repaint my panel?
    Im guessing it doesnt, so I'd need a seperate paint routine?



  • nope I cant get this worked out in my head;

    heres a snippet:

    HiseSnippet 1214.3ocsVstaaaCElJIZK1KFcEXO.B4WJEttRt45BFlqchKBVShWcVw.1kBFIZahHQZPQEWihfUrmj8y8XrGo8FrcNh1VxNWPgAh.Lf44B4G+NjeG1QICXIIREwpzEiGxHVaX2crPOn0.JWPN4HzPGpfEoYI5DRywCoIIrPhk0puFivpzZjru+86aRinh.VtIB4cRd.6M7XtN2ZmF+.OJpMMjcAOtPza23j.onkLRlBnYUaOxPZvUz9rynXXqXSr9hiC4ZopqlBngXsVSY33tCjiDl3eGOgeYDCG3S5BSjwbaYTHhXzJo0.dTXmo65DBLKcx4fUMbv2XeJOjOydNW70YNbxynHeXsxCAO+hvy6yGdVEf2ZF38T6tAJ9PctGDaek8IBMS0iBkfhvxDKYk+XU6VRHBgtVL8JVaELXVFt654U0YGOusNrR4JkgBQh14ZpxIq1667cNSysOS2RFOTJfAtaZbuoIqdoh.MWJbhG2hFE0DJetrqg31pR4OVorC7w6YrTKHhGbEKbKiYvaI8.dRsPplVKAIPXI8cdtyBVObZfACnh9rPWbkwY3lJkuAwPATLDpZ5SGmAQ29Ewfi6BSaNLbl70uVBtQwCitdenM744YXmrUiEkvdfn87veEvVo90BUzQukEnc+EupdU8A9dOueqZcLHH.CQhSyoxzDFxeWh7WNUZ33735fau2JS0bAys3d0DXkxu3YUJyEQfamYbhTXl.rZpjQtASKkUgpcTJyvRk.2IxHVsgJNVk4BnNvbDRULMxI..jCBtrxdoHIXvA4RnjkMIYD6j89rEX9R6bUzax.7Ce.yPvYfdF2rvlAQyydQgs5YRM6bg6Vk+X4Rkuoryht506N8MY5hXp6zMpZodnDcEowWxTSYzoABWemWev990GJJeEX3kBAJEmH35yGxD2mpAYBYB+6mN4HfqQgjI1f3FxTZNBAqiXWCJzFYkR1GwRtRKGBhsyp.DquTm4sxTQGjxIbPZYcSiAexGlIh+oW2Xbth9gMFwC0ClYnwu1X.i2ePdyf+oaCnXJGMsjlfqSKTZHw4bQz3LTOCIqOORdC8xYHI6+EQBzNo.Rp2XHUAyQwIaJ5W.i+3hXD1SLntQmIcSJLKanmzvv.o1QRJber+EbHXDYOwtno4.35E.3m98Enp+9OuELF0XRAzTsdhcGECtTzTIGkvTjK6Os04F1a6uq2daevN6tOgqYwEbTe+818f56U2ufi5FOG.I366uCI67h0eYmousIdtqK8ZVyTsVJ17aczpTV0Ytx5dotGm3srjaYEuEXR319ZSuVp.ngOEXNmmkhnMMNKmWBZFPeyrSm1uRwoQvyJtUaRnYsLLMhpmuCN9rkINfqsy0pDaGJR35wEeVyiRa8OW39T6Nbcvf6FuqbG3Etn+Xi2IORph8w85A8yxA6Z1s+4G+WDQL875eJUq3v8Ia3nQW3Xb.CPh.tRiRqVqfhflwd3XjY5xDgYC9O3ahSebr0Dm9ScRhoAJ46CLB53yvVOyBfIQ1qQKYeJN1wmjIxC4Y6UyiDCuN78AAHU7b.62cN0Whbd4Rjy1KQN6rD4r6RjydKQN6+f4fOL+UoZYr4ZBXnywFkLqiEn3c1IRx+WqSEZF
    

    this behaves correctly right up until I recall a preset - and it does nothing...



  • You're almost there, but you need your panel's saveInPreset to = true and you need to use the panel's control callback (in addition to the mouse callback) because it is called on init after a preset loads.

    Peek 2019-11-05 14-22.gif

    This is a rather clunky example that I'm sure can be improved but it shows the principle

    HiseSnippet 1300.3ocsWstSabDEdVfsE6FqzT0Gfs7qkHhytNbIoHTcvfinM.twTTk5kngcGaOh0yXM6rPrhPJpOIs+qOF8QpuAsmyNduXykFYUVIDLmKy7c9Nm4LG5njAr3XohXU4jwiXDqGX2crPOn0.JWPNXOTPGpfEoYw5XxtiGQiiYgDKqEeEZgUkkHoe+82rKMhJBXEhHjSk7.1q4C45BocZ9c7nn1zP1I7gkrd8lGDHEsjQxD.MKZ6QFQCNm1mcDEMaAah0mreHWKUc0T.MDqk1UFNt6.4kBi8mxi4mEwvE9jtvFYD2VFEhHFkRZMfGE1IKpiIvtzofCVzvAeo8g7Pdt7Bt3ySU3T3QY9vZg6Bd9kgm2GO7rJAukLv6Q1cCT7Q5BMH19L6CDZlpGERAkgkwVxB+wR1sjfEBc8gzyYsUvhbOb2zyaMmM77Vc6ZUqUERDwZmKnJmzbuuyNNY91moaIGNRJfEtqXTuhwqdIh.MWJbFNtEMJZWH84xt.ra0ZUeespNvGumQR8fHdv4rvUMhAsUveqGviqGR0z5wHIBGquySlU51kMNloOkFkvbyMZ0ozGLfJ5yBcQonvqpU8JDqkP6HH6pObbZn31uLVcbm4nKfqyju9HBLEstduqM744YXwzSiEEytCq87veJgsJ8qGpnW9FVf18m7VyaMeHurk2urVCzHv.CgiaygxjXFxymg7bAkiFVXUGL3diLQyEL2xQpIkUqJWDApbxYCov3LluUxH2frj8ZP8.PzSyOohljr9pc1wIQDx5A6WVhE+x2goyrkbc6BiM+UgKJVJnSyeWkB46tPzPvoPOmalIjxh7ZUe5im23uBnNVFwpORgnaEt.J2XNBoZHMxI.NYG7nSuXTIRBBbvfOOrwEaOarNE8LU89+iQ9ieZoP8Holcrvc0puuZkpWU0YVU85ci5lrcQL0MpF6qqtKGcEICOioxXzLCgFbS2A0916fVtAefgWJYnTbffqOdDSba8UISHSrC6DTAlpS6uVKq+JxcDNzEcYyaf9jT.Sr9B6us6wG89URyOq70NdWQH+vA6Aorr8C1Z33FwTZNFIV6wt.dJzz+th8dr3y0xQvqZ4IR3P9OO82k+Z4GdUywEOctcyK4g5A4BZ9yMGv38GT7p6e0sITSHuLqxHFOmVXO3XmiEQiIwzKXGH5nXPUD.2Evn31P1qomkirz+tLxf2wKgrFMGQUvdTdyxhlYv72OKlgXjAkCz72LIk1kGnm7RsARsijTnEW+S3fwHxdncYQSAvkKAvO7qyPc+4ucMXbYyIITS16g1FVZWk7xXlhbV+rYVdf859a5s05uXiMeNgqYCKonwy2ZyWzXqF9kTzvn4EfC999aPRqer9c6z9qqfkycgrxtIZsT.EYZUBasbUoiMntEk3k23qIEubYb355ZSuPp.ngyfMkxiRPzlLL0mmAshfAVvDvmZ+REmFAyycs4SfojjgIQT8ziNgyKNQAzMXpYTv4PDwb83xySduLO0GKbejcGtNXvMi2EtA7BW7uuw6joSqYueudv.BEfcI61+38+nnDyXD8OjpUb39jMTZzEJiCX.RDvUZris0BXuUyZObMxLcYhvzE+C7MQoOt1ZhR+Lkjgz.k7sAlNx37uKmJAvjH8eCnh8g3Zm7Vw11d08HCgwxeaP.REOAv9M6Si4vmmMG9r9b3yFygOaNG9r0b3yyuSev+inWlnkCMWS.Ac12zIyZeA17Nshj7u.aC88BC
    


  • @d-healey groan.. so this:

    component.repaint();

    thanks.



  • @Lindon Actually thinking about this - I feel this is a pretty clunky solution, three function calls just to get one thing done. So I could do this no?

    HiseSnippet 1378.3ocsWstaaaCElxMZq1qdccXO.Z4WJEoNRt4R6BJlabh6xVShWcWw.1kBFIZahHSZPQkTih.Trmj8y8Xresmm8FrcNhxRxNIdaFqJHIlma7imui343tJY.KNVpHVUe4jwLh0cr6MQnG1dHkKHGtOJnKUvhzrXcLYuIiowwrPhk0sdFZgU0UHoO+4WtGMhJBXEhHjWI4ArmyGw0ER615a3QQcngrWxGUx5MacXfTzVFIS.zbKaOxXZvYzArionYUrIVevAgbsT0SSAzPrVYOY3jdCkWHL1+JdL+zHFtvmzCBjQ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GLcRt6Xuo+1d6r4i2Z6GQ3Z1nRJZ9nc19wM2ooeIEMMZdL3fuu+Vjz5Gqe0Nskwp3aE8.VwTFB0pZUBa8bUoCSotAk3c.wWQJ9NpwgqpqC8boBfFNY5LJONAQaxnTedHbiFLFGR.en8SUbZzLjxJ+GdABHDaq+.xuSvO3jNu7Ul+ClBUFlDQ0yNZJNOdlB35oYlADmySDy0SJOu96k4U+2B26Y2kqCFd83sx0fW7ls2y3Ma5+51GzuOL+UAXWwty2+9eTehYJsAGQ0JNVH.EY8fWHBX.RDvkCXKDqJ3k8l0d3ZLyziIBSW7WvSlRebsUlR+oJIinAJ4qCLWtie+hamJAvjH8qYU09HbsSduAaauFdjQvW640AAXp3A.1udeZtD97vkvmMWBe1ZI7Y6kvmcVBedzB8A+FmOMQKGYdMADz8.ychVGHv1.oUjj+FAHAXK.
    


  • @Lindon nope... OK I think the thing I dont get is this

    What gets saved (in a preset) with a panel is it ONLY this

    myPanel.Value

    or is it also saving this:

    myPanel.data.something

    ???



  • @Lindon Yes only the value gets saved and recalled so anything you want to keep must go in the panel's value and be restored in the panel's control callback.



  • @d-healey right thanks....


Log in to reply
 

12
Online

544
Users

2.1k
Topics

16.2k
Posts