sakemin / cog-musicgen-chord

Chord conditioning implemented MusicGen
https://replicate.com/sakemin/musicgen-chord
Apache License 2.0
43 stars 9 forks source link

full support of harte grammar? #3

Closed yocontra closed 5 months ago

yocontra commented 9 months ago

Referencing the paper the notation is: https://ismir2005.ismir.net/proceedings/1080.pdf

<chord> ::= <note> ":" <shorthand> ["("<degree-list>")"]["/"<degree>]
| <note> ":" "("<degree-list>")" ["/"<degree>]
| <note> ["/"<degree>] | "N"
<note> ::= <natural> | <note> <modifier>
<natural> ::= A | B | C | D | E | F | G
<modifier> ::= b | #
<degree-list> ::= ["*"] <degree> ["," <degree-list>]
<degree> ::= <interval> | <modifier> <degree>
<interval> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
<shorthand> ::= maj | min | dim | aug | maj7 | min7 | 7 | dim7 | hdim7
| minmaj7 | maj6 | min6 | 9 | maj9 | min9 | sus4

And looking at the code, the implementation is: https://github.com/sakemin/cog-musicgen-chord/blob/master/audiocraft/modules/btc/utils/chords.py

Does the implementation fully support everything defined in the grammar from the paper? Writing something that generates the text_chords param and want to understand the implementation here better.

Also not sure if you looked at this but a library I found for parsing the Harte grammar: https://jams.readthedocs.io/en/stable/namespaces/chord.html#chord-harte

yocontra commented 9 months ago

Found this paper from this year https://www.nature.com/articles/s41597-023-02410-w

They actually built out converters to support a bunch of notations and convert them all to Harte - https://github.com/smashub/choco/tree/main/choco/converters

It would be really cool and make this easier to use if more common notations were supported, even if they were just converted to Harte. At least one more common one like ABC would make this more interoperable with other tools.

sakemin commented 9 months ago

MusicGen Chord supports a subset of Harte grammar. Since the model converts chords into 12-pitch-bin-chromas, notations like C/G(C/5) will not reflected, because there is no 'root' idea in chromagram.

sakemin commented 9 months ago

Found this paper from this year https://www.nature.com/articles/s41597-023-02410-w

They actually built out converters to support a bunch of notations and convert them all to Harte - https://github.com/smashub/choco/tree/main/choco/converters

It would be really cool and make this easier to use if more common notations were supported, even if they were just converted to Harte. At least one more common one like ABC would make this more interoperable with other tools.

Thanks for sharing it. If this converter is implemented, it would be more nice to use the model. It's not on priority right now, but I will work on it!

yocontra commented 9 months ago

Thanks, I think this is the correct BNF for the text_chords field if helpful to anyone reading this:

<progression> ::= <bar> " " <bar>
<bar> ::= <chord> "," <chord>
<chord> ::= <note> ":" <shorthand>
<note> ::= <natural> | <note> <modifier>
<natural> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G"
<modifier> ::= "b" | "#"
<shorthand> ::= "maj" | "min" | "dim" | "aug" | "maj7" | "min7" | "7" | "dim7" | "hdim7"
| "minmaj7" | "maj6" | "min6" | "9" | "maj9" | "min9" | "sus4"

Might be useful to put in the README or something, or could be used to validate input which leads to better error messages.

sakemin commented 5 months ago

Sorry for the late reflection! Now the grammar sheet is added in the README!