c64cryptoboy / ChiptuneSAK

A pipeline for processing music and creating output for various constrained playback environments
MIT License
19 stars 1 forks source link

How to read out PPQ (Pulses Per Quarter note) in Chirp representation #20

Open minstreldragon opened 1 year ago

minstreldragon commented 1 year ago

Use case: I use the MIDI importer for importing a MIDI file into a Chirp representation. The notes in ChirpTracks.notes all have a start_time and a duration. However, from the documentation it was not clear to me how the integer time values used for start_time and duration relate to the unit of a quarter note, which is the base for tempo specifications (tempo changes are specified in Quarter notes Per Minute).

The missing link seems to be the PPQ (Pulses Per Quarter note) value, which is a parameter in a MIDI file and usually specified in its header[3]. According to Wikipedia [1] the PPQ value may range depending on the tool that was used to create the MIDI file. In my specific case it seems like 960 was used, but this can not universally be relied on. In any case, it would be great if there was a way of retrieving the PPQ value from a ChirpSong. Maybe it could be made a member variable of ChirpSong, i.e. in the ChirpSong documentation it would be something like:

ppq - Pulses Per Quarter note, the smallest unit of time used for sequencing note and automation events. Together with tempo specifications in Quarter notes Per Minute (QPM) specifies how fast a song should be played back. Chirp Note start_time and duration are based on this value.

References: [1] https://en.wikipedia.org/wiki/Pulses_per_quarter_note [2] https://sites.uci.edu/camp2014/2014/05/19/timing-in-midi-files/ [3] http://www.music.mcgill.ca/~ich/classes/mumt306/StandardMIDIfileformat.html#BM2_1

minstreldragon commented 1 year ago

It seems like the ppq value is available as part of the ChirpSong Metadata and will be correctly set from the MIDI input file on import: ChirpSong.metadata.ppq

I believe the issue can be resolved by merely updating the documentation (ChirpSong.metadata is missing from the ChiptuneSAK Class Reference.)