jskripchuk / music-analysis

Teaching basic computer science principles and concepts through the lens of music. Hooktheory music analysis toolkit for MUSC106: Computational Thinking in Music.
8 stars 1 forks source link

Questions about working with .hkt songs #2

Open xhevahir opened 4 years ago

xhevahir commented 4 years ago

Hi, I'm trying to use Hookpad as a sort of frontend to an old program called Melody Generator, and I can't find out much about Hooktheory's file format. Basically, I'm looking to convert a monophonic melody and chords into a very simple text file that encodes note onsets and Roman numerals, which the other program would then turn into a melody. I notice that your parser can handle notes and chords, but the .hkt format is kind of mysterious. Also, other parts of your library indicate that only 4/4 time is supported; can the parser by itself handle other time signatures?

Also, do you know if the .hkt format is specified somewhere? Thanks in advance for any help.

jskripchuk commented 4 years ago

Hey! First off, it's cool that someone found this outside of the academic circles I was working with. Sorry the code is such a mess, I never really expected anyone outside of me to actually peak at the innards (bad software engineering practice, I know, I know)

So about Hooktheory's file format, I'd be very surprised if you did actually find any specifications about their file format(s). There's no official spec that I know of, so I had to sort of figure it out as I went along. If you somehow do come across an official spec please let me know!

When I first started this project around 2017 they used .hkt files, which are basically just XML files with their own custom structure. So if you open .hkt file in a text editor (if they didn't change the format), you'll see something like

`

... ... ` Most of the stuff you want is in the data tags. You'll see a couple of segment objects ` ... ` Each segment is a row of chords+melody you see in hooktheory. ` ... ... ` **Melody** In the melody section, you'll see a bunch of note objects. They give you the start beats and the length of the notes. If you want to get the end time of a note you'll have to calculate it yourself. It also gives you the scale degrees and the octaves of the notes. **Harmony** As with notes, you'll see a bunch of chord objects. These are trickier than the note since they have so many more options. < sd > - the scale degree that the chord starts on. (You're going to have to infer the quality of the chord, [major, minor, etc. based off of the mode the song is in. They don't make it easy. This is why the chord parser file is so long...) < fb > - I assume "figured bass". The type of chord inversion of said chord < sec > - if the chord is a secondary dominant, and of which type < emb > - embellishments like add9's < sus > - suspensions < borrowed > - EXTREMELY difficult to handle borrowed chords. They do this weird thing based off of relative modes and it's a whole hassle, I explain their madness in chord_to_roman.py As for the 4/4 of the parser, I don't think that's an inherent limitation of the .hkt files, I think it just has something to do with the other code in the codebase and what we as a group are doing with the data. Now, Hooktheory has moved on to JSON files after their big update a year ago, but if you're still using .hkt files you can find some XML parsers to get the data you want from the file format. I hope this sort of helps, but it would be cool if you just reach out to me and ask on whatever other questions you have about the file format. I'm probably the only guy outside of HT who sort of knows what's going on with it. **However**, my advisor does want to make the course open source soon, so in a few months this code will probably have consistent documentation and everything. Thanks for reaching out :)