So if anyone is interested, this is what I have right now:
The time-remapping works for one cycle of the markers in the precomp, then starts the loop again and repeats the first linear time-remapping again. I think the problem is the nextMarkerPrecomp = 2. Because After Effects’ expressions are weird to me as the keyframe index seems to start at 1 (?) and there is no console to easily check values, I’m not sure where to tackle the problem.
preComp = comp(name);
var previousMarker;
var nextMarkerPrecomp; // 2 weil scheinbar Marker Index 1 == erster Marker ist, NICHT 0
if(marker.nearestKey(time).time <= time){
previousMarker = marker.nearestKey(time).index;
}
else{
previousMarker = marker.nearestKey(time).index -1;
}
if(previousMarker < marker.numKeys) {
if(time >= marker.key(previousMarker).time && time < marker.key(previousMarker+1).time){
if (previousMarker % preComp.marker.numKeys != 0) { // If next Precomp Marker is NOT the first
nextMarkerPrecomp = (previousMarker % preComp.marker.numKeys) + 1;
}
else { // Else reset the PreCompMarker index ! probably error here
nextMarkerPrecomp = 2;
}
// Then linear Timing between the current and next marker
linear(time, marker.key(previousMarker).time, marker.key(previousMarker+1).time, preComp.marker.key(nextMarkerPrecomp-1).time, preComp.marker.key(nextMarkerPrecomp).time);
}
}