c.on_hold every time after c.on_press

I’m trying to make a button to paste a table of note and to modify it if the name of the track is blablabla or blabla. It works but every time i press the button it makes the function c.on_hold after the function c.on_press. I must have made a error in the elseif cause when i make this simple thing it works.

 --------------------------------------------------------------------------------  
  
function StepSequencerL:_build_copydenote2()  
  
 if self.mappings.copydenote2.group_name then  
  
 local c = UIButton(self.display)  
 c.group_name = self.mappings.copydenote2.group_name  
 c.tooltip = self.mappings.copydenote2.description  
 c:set_pos(self.mappings.copydenote2.index)  
 c.active = false  
 c:set(self.palette.copydenote2)  
  
 c.on_press = function(obj)  
  
 if (not self.active) then   
 return false  
 end  
  
  
  
  
local tablo = 1  
local msg = ""..tablo  
 renoise.app():show_status(msg)  
  
  
  
 end  
  
  
 --------------------------------  
 c.on_hold = function(obj)  
  
 if (not self.active) then   
 return false  
 end   
  
local tablo = 2  
local msg = ""..tablo  
 renoise.app():show_status(msg)  
  
  
end   
 -------------------------------   
  
  
  
  
  
 self:_add_component(c)  
 self._copydenote2 = c  
  
 end   
  
end  

this code return 1 when i presse the button and 2 when i hold it

The next code works like i want but will always return 2 even if i only press the button. I tried to change the different “end” places and so but can’t find a solution. I made other buttons and the difference between on.press and on.hold work. But not this time, i must certainly don’t see a simple error or miss understand something. If someone see where’s the fault, your help will be appreciate.

  
  
function StepSequencerL:_build_copydenote2()  
  
 if self.mappings.copydenote2.group_name then  
  
 local c = UIButton(self.display)  
 c.group_name = self.mappings.copydenote2.group_name  
 c.tooltip = self.mappings.copydenote2.description  
 c:set_pos(self.mappings.copydenote2.index)  
 c.active = false  
 c:set(self.palette.copydenote2)  
  
 c.on_press = function(obj)  
  
 if (not self.active) then   
 return false  
 end  
  
  
 if (renoise.song().selection_in_pattern == nil)then  
  
 renoise.song().selection_in_pattern = {start_line=1,start_track=renoise.song().selected_track_index,end_line=renoise.song().selected_pattern.number_of_lines,end_track=renoise.song().selected_track_index}  
else  
end  
  
  
  
  
  
local startl = renoise.song().selection_in_pattern.start_line  
local endl = renoise.song().selection_in_pattern.end_line   
local x = (endl - startl+1)  
local ligne = startl  
local g = 1  
local a = 1  
local tdernier = x  
  
while (a <= tdernier) do  
  
self._tcpydenote2[a] = self._tcpydenote[g]  
  
g = g + 1  
a = a + 1  
  
  
if (g == #self._tcpydenote) then   
g = 1  
else  
g = g  
end  
  
end---III  
  
  
  
  
local a = 1  
local tdernier = #self._tcpydenote2  
while (a <= tdernier) do  
  
  
 if (renoise.song().tracks[renoise.song().selected_track_index].name == "LXR Drum 1" and self._tcpydenote2[a]<120) then  
self._tcpydenote2[a] = 36  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "LXR Drum 2" and self._tcpydenote2[a]<120) then  
self._tcpydenote2[a] = 37  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "LXR Drum 3" and self._tcpydenote2[a]<120) then  
self._tcpydenote2[a] = 38  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "LXR Snare" and self._tcpydenote2[a]<120) then  
self._tcpydenote2[a] = 39  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "LXR Clap_Cym" and self._tcpydenote2[a]<120) then  
self._tcpydenote2[a] = 40  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "LXR CL_HiHat" and self._tcpydenote2[a]<120) then  
self._tcpydenote2[a] = 41  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "LXR OP_HiHat" and self._tcpydenote2[a]<120) then  
self._tcpydenote2[a] = 42  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "Doepfer Dark Link" and self._tcpydenote2[a]<120 and self._tcpydenote2[a]<48) then  
self._tcpydenote2[a] = 48  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "Doepfer Dark Link Module" and self._tcpydenote2[a]<120 and self._tcpydenote2[a]<48) then  
self._tcpydenote2[a] = 48  
  
 elseif (renoise.song().tracks[renoise.song().selected_track_index].name == "Dominion X" and self._tcpydenote2[a]<120 and self._tcpydenote2[a]<36) then  
self._tcpydenote2[a] = 36  
  
else  
  
self._tcpydenote2[a] = self._tcpydenote2[a]  
  
end  
  
a = a + 1  
end  
  
  
local x = (endl - startl+1)  
  
local ligne = startl  
local g = 1  
local tdernier = x  
  
while (g <= tdernier) do  
  
 local note =  
renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[ligne].note_columns[1]  
note.note_value = self._tcpydenote2[g]  
note.volume_value = note.volume_value---self._base_volume  
note.instrument_value = renoise.song().selected_instrument_index-1  
ligne = ligne + 1  
g = g + 1  
end   
  
  
end  
  
 c.on_hold = function(obj)  
  
 if (not self.active) then   
 return false  
 end   
  
  
local startl = renoise.song().selection_in_pattern.start_line  
local endl = renoise.song().selection_in_pattern.end_line   
local x = (endl - startl+1)  
  
local ligne = startl  
local g = 1  
local tdernier = x  
  
while (g <= tdernier) do  
  
 local note =  
renoise.song().patterns[renoise.song().selected_pattern_index].tracks[renoise.song().selected_track_index].lines[ligne].note_columns[1]  
if (self._tcpydenote2[g]<120)then  
note.note_value = self._tcpydenote2[g]  
else  
note.note_value = math.random(120,121)  
end  
note.volume_value = note.volume_value  
note.instrument_value = renoise.song().selected_instrument_index-1  
ligne = ligne + 1  
g = g + 1  
end   
  
  
  
local tablo = 2  
local msg = ""..tablo  
 renoise.app():show_status(msg)  
  
end  
  
  
 self:_add_component(c)  
 self._copydenote2 = c  
  
 end   
  
end  
  

I edit the post with the last version of the code that i use. After some more test. It seem’s to work with a small selection of lines (16). But when i select more lines (60) the button react like i was holding it.