How to retain an instrument, wipe song, start a new song and add the instrument in?

Hi, I used to have this nice little script that would take the first sample of the instrument (yep, most of my instruments are 1 sample only), create a new renoise song, paste it in. But it no longer works.

function WipeRetain()
local tmpvariable=os.tmpname("wav")
local s=renoise.song()

s.instruments[s.selected_instrument_index].samples[1].sample_buffer:save_as(tmpvariable, "wav")

if not renoise.tool().app_new_document_observable:has_notifier(WipeRetain_) then
       renoise.tool().app_new_document_observable:add_notifier(WipeRetain_) else
       renoise.tool().app_new_document_observable:remove_notifier(WipeRetain_)end
renoise.app():new_song()
end

function WipeRetain_()
local s=renoise.song()

s.instruments[s.selected_instrument_index].samples[1].sample_buffer:load_from(tmpvariable)
renoise.app().window.active_middle_frame=4
renoise.app():show_status(tmpvariable)
os.remove(tmpvariable)
renoise.tool().app_new_document_observable:remove_notifier(WipeRetain_)
end

I’m wondering what would be required to make this work again in 3.1.1?

Have you looked at the API changes posted on the forum by taktik? Some things are renamed, changed or added.

From the top of my head, I think active_middle_frame was changed sometime. Do you get an error and what does it say?

Hi joule, long time!

Ok, so, there is no error that is shot. It just appears like the “clipboard” is written to, but then there’s nothing when the new document is started. Feels strange