Device.active_preset (the index) is 0 for VST3, but 1 for VST2

I stumbled over an error in Fladd’s track splitter tool. It crashes in the device copy loop, simply in the line:

new_device.active_preset = device.active_preset

Now I wondered how this is possible. Tracked down the behaviour and it turns out that for any given VST2, the device.active_preset (index) is 1, but 0 for any VST3 fx. At least in my test, done with A1 Stereo Control, which is available as VST2 and VST3. Also UVI Shade.

I guess this could be considered as a bug? Or is this done for a reason?

This is the whole loop code:

if #current_song.tracks[orig_track].devices > 1 then
        for d = 2, #current_song.tracks[orig_track].devices do
          local device = current_song.tracks[orig_track].devices[d]
          current_song.tracks[group_track]:insert_device_at(
            device.device_path, d)
          local new_device = current_song.tracks[group_track].devices[d]
          new_device.display_name = device.display_name
          new_device.is_active = device.is_active
          new_device.is_maximized = device.is_maximized
          print('index', device.active_preset, device.name)
          new_device.active_preset = device.active_preset
          new_device.active_preset_data = device.active_preset_data
        end
      end

Tested in Renoise 3.5.2 macOS 14.6.1

Here is a debug enabled version of the tool, search for “bug here” in the main.lua:
de.fladd.SplitIntoSeparateTracks.xrnx (5.3 KB)

This code even hard-crashes / force-quits Renoise:

for d = 2, #current_song.tracks[orig_track_index].devices do
          print('grabbbing device at', d)
          local device = current_song.tracks[orig_track_index]:device(d)
          print('done grabbing')
          current_song.tracks[group_track]:insert_device_at(
            device.device_path, d)
          local new_device = current_song.tracks[group_track].devices[d]
          new_device.display_name = device.display_name
          new_device.is_active = device.is_active
          new_device.is_maximized = device.is_maximized
          local fixed_index = device.active_preset == 0 and 1 or device.active_preset
          print('copying active preset at index', device.active_preset, 'of device', device.name, fixed_index)
          -- BUG HERE
          new_device.active_preset = fixed_index
          new_device.active_preset_data = device.active_preset_data
        end

de.fladd.SplitIntoSeparateTracks-HardCrashing.xrnx (5.3 KB)

I guess because there is no index 1.

For the crash, select a VST3 device and then enter simply:

Btw. for a fix of the tool, simply comment out that line:

--new_device.active_preset = device.active_preset

Might be even considered as harmful…

Here is a working version of the tool:
de.fladd.SplitIntoSeparateTracks.xrnx (5.4 KB)