The Algorithmic Composer: Integrating Music Theory into AI for Real-time Adaptive Music Generation