Realtime Trouble Setting Song().Transport.Edit_Pos

Hi there,

this code works perfectly in non-playing mode, but makes trouble while song is being played.
Basically this code fragement was taken from GlobalMidiActions.lua, so I expected it to work.

-- transport forward button pressed  
function FaderPort:transport_forward  
 local new_edit_pos = song().transport.edit_pos  
 new_edit_pos.sequence =   
 clamp_value(new_edit_pos.sequence + 1,1,   
 song().transport.edit_pos = new_edit_pos  

The Problem: despite the fact I clamp the value correctly sometimes it seems that an invalid
position is set when pressing the forward button very often/quickly.
I guess it’s an realtime issue. This is the error message:

*** std::logic_error: ‘invalid edit pos. valid values -> (1 - song_end)’
*** stack traceback:
*** [C]: ?
*** [C]: in function ‘__newindex’
*** [string “do…”]:22: in function <[string “do…”]:11>
*** .\/Duplex/Controllers/FaderPort/FaderPort.lua:1493: in function <.\/Duplex/Controllers/FaderPort/FaderPort.lua:1363>

Any ideas ?

What if you disable duplex?

You will have to clamp “new_edit_pos.line” as well, in case that the new sequence’s pattern has less lines lines than the last edited one. Or always set it to 1.

Alternatively you could also use the beat_pos accessors, or we are adding some helpers which only move forward by sequences and do the clipping by their own.

Thank you very much ! The song had different pattern lengths. Guess that was the problem. Should actually also occur in non-playing mode.
I’ll try to clamp it or set it to 1 as you’ve suggested I’ll have a look at beat_pos, too.

Maybe a helper would make sense if more people stumble upon this ?

thanks, but that’s actually not Duplex-related. Was more a general question even if duplex appears in the error message.

The line-clamp method works very well !