Music is everywhere in the world, and its applications in commerce are extremely versatile. Generally speaking, in order to create some music for background music, it is necessary to engage sound recordists and instrumental performers. However, the process is very time-consuming and costly. In this paper, a real-time emotion-based music accompaniment system is proposed to solve this issue. For different emotions, a fuzzy logic controller is designed to adjust the tempo of the music, and an adaptive partition evolutionary genetic algorithm is developed to create corresponding melodies. The chord progressions are generated via music theory, and the instrumentation is disposed by the conception of the probability. What is noteworthy is that all the processes can be output by Virtual Studio Technology in real time so that users can listen directly to the composing results from any emotions. From the experimental results, the proposed adaptive partition evolutionary genetic algorithm performs better than other optimal algorithms in such topics.