Scripting the Stereo Expander via Lua

I am hacking together some tools to help me mix my songs. I started with Master Muter (https://github.com/Neurogami/renoise-ng/tree/master/lua/com.neurogami.MisterMaster.xrnx, renamed to Mister Master) which adds a Gainer device to the master track; this can then be switched on and off using OSC.

I decided would like to be able to use OSC to toggle mono/stereo master output, so I now have my tool add a Stereo Expander device.

When the device is added the Lua code sets “Expand” to 0 (i.e. mono). But I also want to set “Mono Mix” to “L+R”. The device defaults to just “R”. I can not figure out how to set this to “L+R” using Lua.

I ran some code posted at https://forum.renoise.com/t/using-a-for-loop-for-good/33741 to get a list of parameters for all device (very handy!).

This is what I get for Stereo Expander:

[Audio/Effects/Native/Stereo Expander] => table
[1] => Expand
[2] => Surround

Is there an API call for this device that will let me change the mono mix value?

A dirty way to access “any” property of a device would be to feed it preset data as an XML snippet.

For example, I can add a Stereo Expander, select it and run the following code in the console:

print(renoise.song().selected_device.active_preset_data)

This will print the following

<?xml version="1.0" encoding="UTF-8"?>
<FilterDevicePreset doc_version="10">
  <DeviceSlot type="StereoExpanderDevice">
    <IsMaximized>true</IsMaximized>
    <MonoMixMode>R</MonoMixMode>
    <StereoWidth>
      <Value>0.5</Value>
    </StereoWidth>
    <SurroundWidth>
      <Value>0.0</Value>
    </SurroundWidth>
  </DeviceSlot>
</FilterDevicePreset>

A dirty way to access “any” property of a device would be to feed it preset data as an XML snippet.

How do you “feed it preset data as an XML excerpt”?

I tried assigning XML to the property but got an error

renoise.song().selected_device.active_preset_data = "<?xml version='1.0' encoding='UTF-8'?><FilterDevicePreset doc_version='10'> <DeviceSlot type='StereoExpanderDevice'> <IsMaximized>true</IsMaximized> <MonoMixMode>L+R</MonoMixMode> <StereoWidth> <Value>0.5</Value> </StereoWidth> <SurroundWidth> <Value>0.0</Value> </SurroundWidth> </DeviceSlot></FilterDevicePreset>"

*** exception: ''[BinStream]' was saved with an incompatible, more recent version of Renoise.'
*** stack traceback:
*** [C]: ?
*** [C]: in function '__newindex'
*** [string "do..."]:22: in function <[string "do..."]:11>
*** __assign-xml.lua:1: in main chunk

(It’s such an odd error it makes me wonder if it has nothing to do with trying to assign XML.)

Update: This seems to be an issue with my install of 2.8.2, since the same thing works fine in 3.0.1.

Update 2: Changing the doc_version attribute from “10” to “9” gets it working in 2.8.2 and 3.0.1.

Sweet, thanks.