Samples Loop_Mode,Loop_Release, Loop_Start, Loop_End

Hiya. I was doing some random grepping along the documentation, and got these;
renoise.song().instruments[].samples[].loop_mode, _observable
renoise.song().instruments[].samples[].loop_release, _observable
renoise.song().instruments[].samples[].loop_start, _observable
renoise.song().instruments[].samples[].loop_end, _observable

Am I to understand that the loop_mode of a sample can be changed via LUA? or that one can LUA script sample loop_start & end lengths, etc? Or?

yes, IT-Alien made it possible to midi control start and end loop points some time back.

Ok, looking further, it seems that there can be a

  
renoise.Sample.LOOP_MODE_OFF  
renoise.Sample.LOOP_MODE_FORWARD  
renoise.Sample.LOOP_MODE_REVERSE  
renoise.Sample.LOOP_MODE_PING_PONG  
  

These seem to be the old foes, constants :)

Only used for rernoise.song().instruments[].samples[].loop_mode

Example:

  
renoise.song().instruments[1].samples[1].loop_mode = renoise.Sample.LOOP_MODE_REVERSE  
  

Think of a constant as a shortcut. Except it’s not shorter, rather verbose and easier to read.

Okay, I got this going now:
renoise.song().selected_sample.loop_mode = renoise.Sample.LOOP_MODE_OFF
renoise.song().selected_sample.loop_mode = renoise.Sample.LOOP_MODE_REVERSE
renoise.song().selected_sample.loop_mode = renoise.Sample.LOOP_MODE_PING_PONG
For some reason, loop_mode_forward just doesn’t want to work, which is weird!

So far so good

  
>>> oprint (renoise.song().selected_sample.loop_end)  
100418  
>>> renoise.song().selected_sample.loop_end=90418  
  

worked :)
I don’t get why FORWARD doesn’t work? :)

Set a loop to forward and then query that samples loop value via the lua console. Maybe things will clarify. I would guess that the constants are 0,1,2,3.

This switches between sample loop mode “off” and “forward”

  
function toggle_sample_looping()  
 local loop_mode = renoise.song().selected_sample.loop_mode  
 if loop_mode == 1 then  
 loop_mode =2  
 else  
 loop_mode = 1  
 end  
 renoise.song().selected_sample.loop_mode = loop_mode  
end  
  

1, 2, 3, 4

Ok, made a little keybind which tries to think in mathematical terms.
LoopTest

  
function selsamploop()  
local selsamp = renoise.song().selected_sample  
  
if selsamp.loop_end <200 then  
selsamp.loop_end = renoise.song().selected_sample.sample_buffer.number_of_frames  
else  
 if selsamp.loop_end >3000 then  
 selsamp.loop_end = selsamp.loop_end - 1000  
 else selsamp.loop_end = selsamp.loop_end -100  
end  
end  
end  
  

If anyone has any suggestions as to how to handle samples of different sizes mathematically so that this kind of loop-setting and re-setting and “closer to sample_start starts increasing resolution” makes more sense, please suggest.

edit: Well, added one more thing, every second press on the keybind will switch from pingpong to forward loop. Just mucking about, really. (didn’t add it to the code, cos why?)
edit: v0.39 Impulsecomplex has cycle off-forward-backward-pingpong and pingpong-backward-forward-off shortcuts and set-off, set-forward, set-backward, set-pingpong shortcuts. :)