magenta / magenta-js

Magenta.js: Music and Art Generation with Machine Learning in the browser
https://magenta.tensorflow.org
Apache License 2.0
1.96k stars 312 forks source link

Metronome is stuck at 4 beats in the bar #698

Open tbar0970 opened 3 months ago

tbar0970 commented 3 months ago

It would be really great to make this configurable.

https://github.com/magenta/magenta-js/blob/96bad8837da43beb53f2e5aaea9f29f3db4bdddb/music/src/core/metronome.ts#L23

I wonder if anyone can suggest a workaround in the meantime?

notwaldorf commented 3 months ago

I think what you’re looking for is the clicksPerQuarter property, which is public. That constant just says there are 4 quarters in a whole thing, which is the only number of quarters you can have, but it’s then used to calculate how many clicks you actually have in the bar like this:

const clicksInBar = QUARTERS_PER_BAR * this.clicksPerQuarter

So if you change clicksPerQuarter on the metronome object to be something other than 1 (the default), you’ll have more than 4 clicks in the bar.

tbar0970 commented 3 months ago

I did note the clicksPerQuarter property, but it is different.

In 3/4 time there are 3 quarter notes in each bar. I might want 2 clicks for each quarter note - 6 clicks in total, with the first of the 6 accented (high note). This is currently impossible - the accented click has to be a multiple of 4.

I have managed to fork my own version of the class to add a new quartersPerBar property. If i have time i will try to submit a PR.

notwaldorf commented 3 months ago

Ahhhh yes you’re right, my bad. I forgot about good old 3/4 and friends

notwaldorf commented 3 months ago

@tbar0970 one thing you could do is set the clicksPerQuarter property to 0.75 — that would make the math for clicksInBar correct, though you might run into float number nonsense. The real fix would be to just make that const a property.