Clamps value to the allowed priority range.
value
int clamp(int value) { if (value < min) return min; if (value > max) return max; return value; }