How to set autofade + interpolation + oversample _after_ sample has finished recording?

Hi, I’m trying to set up my samples so that autofade, interpolation and oversample are set after a sample has been recorded.

But when I try to just do this:

renoise.tool():add_menu_entry{name = "--Sample Editor:Paketti:Start Sampling (Record)", invoke=function() sample_and_to_sample_editor()
renoise.app().window.sample_record_dialog_is_visible=true 

  renoise.song().instruments[renoise.song().selected_instrument_index].samples[renoise.song().selected_sample_index].autofade=true
  renoise.song().instruments[renoise.song().selected_instrument_index].samples[renoise.song().selected_sample_index].interpolation_mode=4
  renoise.song().instruments[renoise.song().selected_instrument_index].samples[renoise.song().selected_sample_index].oversample_enabled=true

it says:

*** ./recorder.lua:82: attempt to index field '?' (a nil value)
*** stack traceback:
***   ./recorder.lua:82: in function <./recorder.lua:79>

so, what should i do, can i set some sort of a “create notifier before starting sampling, use notifier to set sample preferences, delete notifier” mess?

and how complex would it be?

i’m still sure this is some sort of notifier thing. but i worrry about notifiers, i’d prefer to not have them confuse the matter of starting Renoise - if i start Renoise and the notifier runs and shoots an error, its’ been done in the wrong way, right?

A couple of comments.

renoise.song().instruments[renoise.song().selected_instrument_index].samples[renoise.song().selected_sample_index].autofade=true

Better this:

local sng=renoise.song()
local sii=sng.selected_instrument_index
local ssi=sng.selected_sample_index
local sam=sng:instrument(sii):sample(ssi)
sam.autofade=true
sam.interpolation_mode=4
sam.oversample_enabled=true

However, the API allows “shortcuts”. Also, the example above is not error-proofed. Renoise has fixed elements, which always exist, and elements that may or may not exist. For the latter case, you must first check if it exists. This way you avoid mistakes.

With check and shortcut:

local sam=renoise.song().selected_sample --api shortcut
if (sam)  then --check!
  sam.autofade=true
  sam.interpolation_mode=4
  sam.oversample_enabled=true
else
  print(This sample not exist, Please check if it exist before!!!)
end