# Experiment: Use Midi Switches To Change Loop Markers

**URL:** <https://forum.renoise.com/t/experiment-use-midi-switches-to-change-loop-markers/29586>\
**Category:** Renoise Tools\
**Created:** [August 17, 2010, 9:27am UTC](https://forum.renoise.com/t/experiment-use-midi-switches-to-change-loop-markers/29586 "2010-08-17T09:27:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![It-Alien](https://forum.renoise.com/user_avatar/forum.renoise.com/it-alien/32/41_2.png) [@It-Alien](https://forum.renoise.com/u/It-Alien)\
**Post date:** [August 17, 2010, 9:27am UTC](https://forum.renoise.com/t/experiment-use-midi-switches-to-change-loop-markers/29586/1 "2010-08-17T09:27:26Z")

</div>

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

```php
  
  
-- 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

---

<div class="post-metadata">

**Author:** ![xrxs](https://forum.renoise.com/letter_avatar/xrxs/32/6_449c533f586939b6e5f246632a46421f.png) [@xrxs](https://forum.renoise.com/u/xrxs)\
**Post date:** [April 12, 2013, 8:25am UTC](https://forum.renoise.com/t/experiment-use-midi-switches-to-change-loop-markers/29586/2 "2013-04-12T08:25:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dblue](https://forum.renoise.com/user_avatar/forum.renoise.com/dblue/32/153_2.png) [@dblue](https://forum.renoise.com/u/dblue)\
**Post date:** [April 12, 2013, 12:37pm UTC](https://forum.renoise.com/t/experiment-use-midi-switches-to-change-loop-markers/29586/3 "2013-04-12T12:37:28Z")

</div>

> [@xrxs](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![vvoois](https://forum.renoise.com/letter_avatar/vvoois/32/6_449c533f586939b6e5f246632a46421f.png) [@vvoois](https://forum.renoise.com/u/vvoois)\
**Post date:** [April 12, 2013, 12:45pm UTC](https://forum.renoise.com/t/experiment-use-midi-switches-to-change-loop-markers/29586/4 "2013-04-12T12:45:28Z")

</div>

> [@xrxs](#):
>
> is it posible to write something like this into Formula device to control and automate loop points?

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

---

<div class="post-metadata">

**Author:** ![xrxs](https://forum.renoise.com/letter_avatar/xrxs/32/6_449c533f586939b6e5f246632a46421f.png) [@xrxs](https://forum.renoise.com/u/xrxs)\
**Post date:** [April 12, 2013, 5:47pm UTC](https://forum.renoise.com/t/experiment-use-midi-switches-to-change-loop-markers/29586/5 "2013-04-12T17:47:41Z")

</div>

OK, thanks!
