The preset data is a chunk of binary data that comes directly from the plugin and could really consist of almost anything at all; ranging from a little bit of XML, a small bit of binary data, or potentially some huge chunk of binary data from a sampler or something like that.
Whenever possible, Renoise should of course try not to crash, but yeah… this preset data could really be anything, so it’s quite unpredictable what you might see when simply dumping that raw data directly to the terminal, and in general I’d probably recommend against doing that.
An idea… Maybe it won’t hang if you silently iterate the data and strip all non-ascii chars before printing it to screen? See if just a simple char iteration would also hang it, or if it’s only happening when printing it.
(an alternative guess would be that it’s just too many bytes to print)
The data is already encoded as CDATA within the XML, so it should technically be safe to view in most cases, but I honestly couldn’t say for sure right now. My rough guess is that certain presets may simply be far too massive for the terminal to safely handle without overflowing somewhere? Hard to say.
Sure, just to clarify, you are printing a string that is greater than around 8000 characters to the terminal throws a stack overflow. (I agree, now that could be a separate issue also with string.char/string.byte…anyway…)
Firstly, I’d write a program that generates a string > 8000 characters and prints that to the terminal. If okay (no stack overflow, no crash etc…), I’d assume that the string returned from ‘device.active_preset_data’ (which in your case above is around 32226 characters long) causes a crash when printed to the terminal. To me it feels an internal Lua/Renoise thing for taktik to look at (you’ve basically found a bug. [Only Ledger could want to print an entire large CDATA VST parameter string to the terminal, but well done for the effort ])
Maybe work out a command that prints just partially the head and tail of the string? Or make sure you can output the entire string say to a file etc…? Things like that. But I know what you mean Ledger when you say there could be something else going on more here. A bit more testing is definitely needed, but also testing from the internal Renoise/Lua side. Hmm, you go and test string allocation/deallocation in Renoise/Lua Ledger…err… while I put the kettle on
[Edit:] The other thing to note is to see if the same thing happens under Linux x64.
[Edit2:] Actually just quickly testing under Linux, your snippet Ledger seems to be fine. It pauses a moment, but it does print the entire string (at a length of 37656 characters in my case) to the terminal…albeit it doesn’t much care for it been in the terminal.
Whereas my string.char/string.byte combo is still limited to 7997 characters before a stack overflow…Wait! string.byte puts the parameters i.e. each character as a parameter on the stack. Of course! The parameter stack under Lua is probably 8 KB (8192 bytes) in length, hence why you get the stack overflow error. Okay, forget my crude string limiter, it’s confusing the issue.
So ultimately its a Windows issue moreso, Linux seems to handle it a bit better but not maybe ideal (can’t try Mac OSX), only taktik can look at it properly. I still say a cup of tea is in order though
I know! You’re like me, I don’t like bugs in programs either. I avoid the bugs by not programming
Well at least in the emoji section (whilst taktik is deeply contemplating dumping a 32KB string to the terminal without it crashing) we have a regular cafeteria going on, a doughnut with that coffee Ledge?
Just mention something here about that ‘pause’. I’m sure you know yourself Ledger/joule/dblue/Raul, that when a computer pauses for say 1,2,3 seconds (or more) when given a seemingly (on the surface) relatively simple task…I get real nervous. Just thought I’d mention that
Also probably a little bit better way of limiting output from the string ‘active_preset_data’ is to find roughly where the CDATA is in the string and only print up to that point:
local apd_str = renoise.song().selected_instrument.plugin_properties.plugin_device.active_preset_data
local cdata1,cdata2 = string.find(apd_str,"<ParameterChunk><!%[CDATA%[(.+)%]")
if cdata1 ~= nil then
print("--- CDATA HERE ---")
Just looking back on this thread after time to digest: Summary:
active_preset_data printout is useful when using renoise devices, as presets are fully stored as characters. i.e. you can store a preset for the renoise Send-Device locally in a Lua file, to load the Send in a custom preset. I do this in my Send tools for example.
As @dblue points out, plugins can contain all manner of non-charcter data, so to save this data to reload later you would need to save directly to a binary document?
If so, I will limit my Show Device Properties tool to only show active_preset_data for renoise devices and start brushing up on binary file storage in Lua. (Any tips / links welcome!)
The CDATA is base64 encoded data from the plugin. It’s encoded in base64 so that there is no corruption of the binary representation (when the string gets decoded from base64 that is) from the ascii xml text string/file Ledge