A UI for co-creating music with AI.
This project is initially developed for Segment-Factorized Full-Song Generation on Symbolic Piano Music as a frontend for the proposed SFS model. However, it is designed to be easily adapted to other music generation models as backend.
The UI provides a piano roll editor where user and AI collaborate on music. Both user and AI can create and edit the musical content.
-
Build the frontend:
cd ui npm install npm run build -
Install Python dependencies:
pip install -e server
-
Wrap your music generation model in the
CoComposeServer.generatemethod and run the server.The following example implements a "generation algorithm" that always generates a chromatic scale regardless of the surrounding context:
from co_compose import CoComposeServer, GenerateParams import miditoolkit.midi.parser import asyncio class MyServer(CoComposeServer): async def generate(self, midi: miditoolkit.midi.parser.MidiFile, params: GenerateParams, cancel_event: asyncio.Event): for i in range(params.range.end - params.range.start): yield (params.range.start + i, 60 + i, 100, 1.0) # (onset, pitch, velocity, duration) server = MyServer() server.run('localhost', 8000)
The
generatemethod expects you to implement a music infilling algorithm.midiis the current content on the piano roll.params.rangeis the range to generate in beats.params.song_durationis the total duration of the song in beats.params.segmentsprovides the form information of the song. It is used by the SFS model and can be ignored if your model does not use it.cancel_eventfires when the user cancels the current generation and you can return immediately.- The method should yield the generated notes in the format of (onset, pitch, velocity, duration). The yielded notes are streamed to the frontend in real-time.
onsetanddurationare in beats.
Using pretrained Segment Full Song (SFS) model as backend
-
Install the SFS model:
pip install git+https://github.com/eri24816/segmented-full-song-gen.git
-
Download the pretrained checkpoint to the
sfs_serverdirectory. -
Run the server:
cd sfs_server python main.py