Adding Preset to Edit Box

For general discussion related FlowStone
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Adding Preset to Edit Box

Post by Perfect Human Interface »

I'm using edit boxes to set MIDI port numbers in my schematic. I need the plugin to remember the settings on load so I'm adding preset parameters to the edit boxes.

I've uploaded what I've done below. The problem is that when I set it to a value (say 8), on reload the value loaded is 7. This suggests a rounding error (the schematic multiplies the value by 1/127 to achieve a 0-1 scale and then multiplies by 127 after the preset prim). However, I don't get any rounding errors with this math while testing within the schematic. Not sure what else to do at this point.

Any help is appreciated.
Attachments
MIDI Port Edit Box.fsm
(1.31 KiB) Downloaded 1068 times
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Adding Preset to Edit Box

Post by KG_is_back »

Works perfectly fine here, except for one minor thing - you are missing a "last switch" just before the "edit control" primitive's string input. If you input value via the module input, you get the number written twice.
I do not experience the rounding problems either. In preset manager, when the preset is saved it is saved as decimal number (with exactly 6 decimal places, no matter the size - pretty much the same thing you get when connecting text prim to float array output). On the other hand, float is converted to int by removing everything after decimal dot, so maybe using rounding to int will help.

Following ruby code should do the trick

Code: Select all

output 0,'%.0f' % @ins[0]

the input should be float and output can be anything (string, float or int - all give the same result, in your case I recommend string, cos that is being processed afterwards)
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Adding Preset to Edit Box

Post by Perfect Human Interface »

I dropped your rounding code in and that seems to keep the values from changing. But when I export the plugin it won't save the values in a project. It will save the values in a preset, but reloading the project the plugin is loaded in loads them as default. That's actually the opposite of what I want, since I don't want/need the values to save in a preset but it's important they are remembered in a project save.

Uploaded current module. Same as before, just with the last switch and rounding code KG mentioned.

Edit: note that I'm talking about an exported plugin and not just loading the schematic inside Flowstone.
Attachments
MIDI Port Edit Box 2.fsm
(1.39 KiB) Downloaded 1047 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Adding Preset to Edit Box

Post by tulamide »

The ruby component supports saving and loading data on schematic save/load via the functions loadState and saveState. Try this (not tested):

Code: Select all

@value = '%.0f' % @ins[0]
output 0, @value

def loadState v
   @value = v
end

def saveState
   @value
end
"There lies the dog buried" (German saying translated literally)
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Adding Preset to Edit Box

Post by Perfect Human Interface »

tulamide wrote:The ruby component supports saving and loading data on schematic save/load via the functions loadState and saveState. Try this (not tested):

Code: Select all

@value = '%.0f' % @ins[0]
output 0, @value

def loadState v
   @value = v
end

def saveState
   @value
end


Thanks for the suggestion. I don't know Ruby so I can only guess at how this works. Where is the data saved?
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Adding Preset to Edit Box

Post by tulamide »

I just know what I read in the user guide (You'll find it under the Ruby chapter, section 'Persistence'). It is a convenience function that seems to use the same 'store in schematic' function than all other modules/prims. That's why I thought it should restore its state when loading as a plugin.
"There lies the dog buried" (German saying translated literally)
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Adding Preset to Edit Box

Post by Perfect Human Interface »

That's interesting. Maybe that will work. I still don't understand why the preset param isn't working as it is though.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Adding Preset to Edit Box

Post by billv »

Perfect Human Interface wrote: I still don't understand why the preset param isn't working as it is though

My fist question was "what method is he using to re-load project"...
So I used my preset manager, where it autoloads whatever you save.
Didn't get correct result.., so went back a changed the Edit box circuit,
and set everything to int. Back in VST mode, works fine. re-loads exactly what is saved.
But this is using my PM, you'll have to try it using your own save/reload set-up.
MIDI Port Edit Box 2_fix.fsm
(12.7 KiB) Downloaded 1060 times

Solution 2: :idea:
Instead of a Edit box, you can use a number knob.
This is probably much better idea, as user dosn't have to type in value.
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Adding Preset to Edit Box

Post by Perfect Human Interface »

billv wrote:My fist question was "what method is he using to re-load project"...


I'm just using the stock preset manager. I notice that yours apparently takes any value. The stock manager needs a 0-1 value so I can't make everything into ints unfortunately.

So I tried removing the string input since it wasn't being used anyways. That didn't help. But I did notice while testing that when the plugin loaded into the project, it had the value it should have saved in the text field for a brief moment before the default value popped in there. So the thing is overwriting itself with the value saved with the plugin export. Preset manager y u do dis
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Adding Preset to Edit Box

Post by billv »

Perfect Human Interface wrote:The stock manager needs a 0-1 value so I can't make everything into ints unfortunately.

hey man, what made you think that..??...
If change your way of thinking on this and a whole new world will open up... ;)
The stock PM handles int just fine.
Perfect Human Interface wrote:So the thing is overwriting itself with the value saved with the plugin export.

My question still remains...
"What method are you using to re-load data on plug-in start-up"
Post Reply