Experiment: Use Midi Switches To Change Loop Markers

try putting the following into your GlobalMidiActions.lua, located into the “Scripts” folder (at the end of the file is fine)

  
  
-- BEGIN: moving loop markers with MIDI actions  
  
add_action("Selected Sample:Set Loop markers to 1/4th of sample [Trigger]",  
function(message)  
  
 local sample = song().selected_sample;  
 local int_frames = sample.sample_buffer.number_of_frames;  
 local int_message = message.int_value + 1;  
  
 if message:is_trigger() then  
 local int_end_new = int_frames * .25;  
 sample.loop_start = 1;  
 sample.loop_end = int_frames * .25;  
 end  
  
end)  
  
add_action("Selected Sample:Set Loop markers to 2/4th of sample [Trigger]",  
function(message)  
  
 local sample = song().selected_sample;  
 local int_frames = sample.sample_buffer.number_of_frames;  
 local int_message = message.int_value + 1;  
  
 if message:is_trigger() then  
 local int_end_new = int_frames * .5;  
 if int_end_new < sample.loop_start then  
 sample.loop_start = int_frames*.25+1;  
 sample.loop_end = int_frames * .5;  
 else  
 sample.loop_end = int_frames * .5;  
 sample.loop_start = int_frames*.25+1;  
 end  
 end  
  
end)  
  
add_action("Selected Sample:Set Loop markers to 3/4th of sample [Trigger]",  
function(message)  
  
 local sample = song().selected_sample;  
 local int_frames = sample.sample_buffer.number_of_frames;  
 local int_message = message.int_value + 1;  
  
 if message:is_trigger() then  
 local int_end_new = int_frames * .75;  
 if int_end_new < sample.loop_start then  
 sample.loop_start = int_frames*.5+1;  
 sample.loop_end = int_frames * .75;  
 else  
 sample.loop_end = int_frames * .75;  
 sample.loop_start = int_frames*.5+1;  
 end  
  
 end  
  
end)  
  
add_action("Selected Sample:Set Loop markers to 4/4th of sample [Trigger]",  
function(message)  
  
 local sample = song().selected_sample;  
 local int_frames = sample.sample_buffer.number_of_frames;  
 local int_message = message.int_value + 1;  
  
 if message:is_trigger() then  
 sample.loop_end = int_frames;  
 sample.loop_start = int_frames*.75+1;  
 end  
  
  
end)  
  
-- BEGIN: moving loop markers with MIDI actions  
  
  

this will create four new mappable MIDI actions:

Selected Sample => Set Loop markers to 1/4th of sample [Trigger]
Selected Sample => Set Loop markers to 2/4th of sample [Trigger]
Selected Sample => Set Loop markers to 3/4th of sample [Trigger]
Selected Sample => Set Loop markers to 4/4th of sample [Trigger]

assigning them to MIDI controls will change the current sample loop markers to quarters of the sample data

is it posible to write something like this into Formula device to control and automate loop points?

The Formula device does not have full access to the song document (pattern data, instruments, samples, etc), so unfortunately it cannot do anything like this. It’s only designed to calculate some kind of value and then output it to another Meta Device in the DSP chain.

No, the formula device has no access to the Lua API engine because that engine runs in a completely different thread.

OK, thanks!