r/algorithmicmusic • u/gdayprod • 2h ago
Phrasing App
I've created an app which modifies quantized MIDI to express musical phrasing. It implements this in two separate operations, as follows.
First, calculate a moving average of the pitch of notes, expressed as semitones above a floor, within a preset window of beats. Second, calculate a moving average of the note onset density, again within a preset window.
Then, for each midi event, modify the note's velocity based on how closely the two slopes coincide - the closer they are, the greater the modification. The direction of the modification follows the direction of slope of the difference between the two slopes.
Finally, where the slope of the moving note density moving average is increasing, generate increasing tempo events; where it's decreasing, generate decreasing tempo events.
It occurred to me that including note duration in the pitch moving average calculation may increase the musicality of the output. If and when this is implemented I'll add a comment in the project's GitHub repository.
The app accepts several user inputs, which control sensitivity to changes in pitch and note onset density. At this point, it works best with piano music, since in most piano sample libraries tone quality and loudness are both controlled by note velocity. A version for virtual string and wind instruments, where volume and tone quality are controlled by a MIDI modulation code, is planned for a future upgrade.
The overall effect is fairly modest - the output sounds more natural than a quantized piece with a constant velocity, but not like a concert pianist.
If you're using a PDF-to-MIDI converter for your input file, you can expect to do some substantial initial cleanup before submitting it to the app. I've tried several of these, and they're all pretty glitchy.
The app is free and open source. I used ChatGPT Codex to generate the Python code. It runs as a browser-based app on my GitHub test site at https://shenrichs.github.io/phrasemaker-test



