At every moment, innumerable emotions can indicate and provide questions about daily attitudes. These emotions can interfere or stimulate different goals. Whether in school, home or social life, the environment increases the itinerant part of the process of attitudes. The musician is also passive of these emotions and incorporates them into his compositions for various reasons. Thus, the musical composition has innumerable sources, for example, academic formation, experiences, influences and perceptions of the musical scene. In this way, this work develops the mAchine learning Algorithm Applied to emotions in melodies (3A). The 3A recognizes the musician’s melodies in real time to generate accompaniment melody. As input, The 3A used MIDI data from a synthesizer to generate accompanying MIDI output or sound file by the programming language Chuck. Initially in this work, it is using the Gregorian modes for each intention of composition. In case, the musician changes the mode or tone, the 3A has an adaptation to continuing the musical sequence. Currently, The 3A uses artificial neural networks to predict and adapt melodies. It started from mathematical series for the formation of melodies that present interesting results for both mathematicians and musicians.