The bug happens when one clicks 'Align Audio to Reference' before
the computations triggered by 'Set Audio Reference' have completed.
In this case, the alignment can be completely arbitrary.
Namely, aligning a child audio track ('Align Audio to Reference')
triggers AudioCorrelation::addChild(), which ultimately calls
AudioCorrelation::slotProcessChild(). This function uses the reference
envelope (m_mainTrackEnvelope->envelope()) in order to compute
the cross-correlation, which might contain arbitrary data if the
computation of the main envelope is not finished. We fix this by
ensuring that m_mainTrackEnvelope->envelope() blocks until the envelope
is computed.
In this commit we also do small code cleanups, and fix another (tiny)
race condition where we connect the signal corresponding to the end
of the envelope computation after the computation has started. If the
computation is really fast, it means the signal could be lost.