Arm And Record Script, Some Problems

I’ve been working on a session recorder tool, which almost works (code below, not super tidy). It arms a track by a hotkey, automatically records when starting to play pattern and automatically inserts the note (with autoseek) on position where the recording started.

I’m learning to script by reading the documentation and googling a lot, but I take the liberty of asking some questions here. I hope that’s ok.

  1. When using to stop recording, AND recording to the same instrument, the sample doesn’t update. Am I making some obvious mistake?
  2. Is there a better way to do the notifier function? Maybe it introduces some latency when recording now?
  3. Is there a way to make global variables that will be accessible the next time I trigger the script? (no0b question)
  4. Proper handling of track colors and inserting on the right column will be fixed, don’t worry :)
local trackcolor = false  
local armed_track = false  
local record_pos = false  
local is_armed = false  
function initialize() = false -- stops playback in case it was playing  
 armed_track =  
 trackcolor =[].color -- save track color so it can be reset after recording  
function arm_and_record()[].color = { 255, 0, 0 } -- sets track color to red to indicate it is armed -- triggers notifier() when playback is started or stopped  
function notifier()  
 if then = true -- open record dialogue. unwanted(?) but needed.  
 record_pos = -- position of where the recording is being started -- starts recording  
 else -- stops recording = false -- close record dialogue = record_pos -- go to the start of the recording (unwanted?)  
 insert_recorded_instrument() -- insert note where the recording was started  
 disarm() -- disarms and quits  
function insert_recorded_instrument()[record_pos.sequence].tracks[armed_track].lines[1].note_columns[1].note_string = "C-4"[record_pos.sequence].tracks[armed_track].lines[1].note_columns[1].instrument_string = string.sub(bit.tohex(, 7)[].samples[1].autoseek = true -- everyone wants this?  
function disarm()[].color = trackcolor -- resets track color -- cleanup  
renoise.tool():add_menu_entry {  
 name = "Pattern Editor:Arm and record",  
 invoke = initialize  
renoise.tool():add_keybinding {  
name = "Pattern Editor:Record:Arm and record",  
invoke = initialize  

Perhaps you need the prepare_sample_data_changes() and finalize_sample_data_changes() on the sample-buffer of the target sample to get it updated.

local sample_buffer =[instrument].samples[targetslot].sample_buffer  
... Do your stuff....  

Hmm. I don’t think so. I am not doing any kind of sample manipulation and the should be doing its thing independently?

Sometimes it works and sometimes it doesn’t. I think i need to check my syntax and the structure of the script. Maybe some of the actions are happening too fast for renoise to react properly? :)

These functions are not frankly for manipulating the sample but for preparing the undo buffer. If someone would accidently overwrite an existing sample, he/she can undo the action.
If you don’t use these functions, the overwriting cannot be undone.

That could perhaps be very well a thing.
You could add delay timers to prevent users from acting too quick.

Can you explain what a delay timer is and how to build one?
Does it have something to do with os.clock() ?

Yes it has to do with os.clock.
I believe conner gave you a reasonable snippet in the other thread where you wanted to delay the closure of the sample recorder dialog.

I tried but I couldn’t find the thread conner posted in… Which should say something about the piles and piles of new forumthreads xD

I guess that is me mixing up Conner with Joel. He mentioned os.time instead as well, but os.clock you can go a biut more precise.

Btw:The sample recording only works when the recording dialog is prominent visible according to the API docs.

Yep, that’s why I’m working on a shortcut (which is half-functional now), which
First shortcut press:

  1. Opens Sample Recorder Dialog
  2. Starts Sample Recording
    Second shortcut press:
  3. Stops Sample Recording
  4. Keeps Sample Recorder Dialog open.

Once a functional report of the sample having been saved can be generated, the 4 will change to "detect sample saved, close sample recorder dialog)