Fix API errors when panning off the start/end of a sequence
Limit panning to valid sequence positions

Also add 'clamp' helper function to simplify a few spots.