  Real-time emotion-based music arrangement, which aims to transform a given
music piece into another one that evokes specific emotional resonance with the
user in real-time, holds significant application value in various scenarios,
e.g., music therapy, video game soundtracks, and movie scores. However,
balancing emotion real-time fit with soft emotion transition is a challenge due
to the fine-grained and mutable nature of the target emotion. Existing studies
mainly focus on achieving emotion real-time fit, while the issue of soft
transition remains understudied, affecting the overall emotional coherence of
the music. In this paper, we propose SongDriver2 to address this balance.
Specifically, we first recognize the last timestep's music emotion and then
fuse it with the current timestep's target input emotion. The fused emotion
then serves as the guidance for SongDriver2 to generate the upcoming music
based on the input melody data. To adjust music similarity and emotion
real-time fit flexibly, we downsample the original melody and feed it into the
generation model. Furthermore, we design four music theory features to leverage
domain knowledge to enhance emotion information and employ semi-supervised
learning to mitigate the subjective bias introduced by manual dataset
annotation. According to the evaluation results, SongDriver2 surpasses the
state-of-the-art methods in both objective and subjective metrics. These
results demonstrate that SongDriver2 achieves real-time fit and soft
transitions simultaneously, enhancing the coherence of the generated music.
