Automatic scaling of cadenza-like patterns in metered music

This snippet demonstrates how a (fairly simple) Scheme function may be used similarly to \scaleDurations, to automatically scale all durations in a given music expression to make it fit inside a target duration.

This is especially useful in polyphonic music where one voice has to play a cadenza-like melody while other voices go on providing a regular accompaniment in standard meter, as illustrated in this example from Chopin’s Nocturne op.15 n°2.