1

Is there a way to get millisecond duration of a jfugue duration like w, given a specific BPM rate?

Something like:

int millisDuration = durationManager.getMillis("w", 120);
BabaNew
  • 884
  • 1
  • 13
  • 27

1 Answers1

1

At the moment, the closest thing is a method in NoteSubparser called getDurationForString("UPPERCASE STRING"), which will return a double that represents the portion of a whole note that the string is. For example, passing "H" for a half-note will return 0.5. The string can be arbitrarily complex, such as "WWWH." (three whole notes and a dotted half), which will return 3.75. Since the value returned is relative to beats, and you have a BPM in mind, you should be able to calculate the milliseconds from that.

Use NoteSubparser.getInstance() to get an instance of NoteSubparser, then call getDurationForString("W") (Edit: It's necessary to use capital letters when calling parser code directly like this).

David Koelle
  • 20,726
  • 23
  • 93
  • 130
  • 1
    Hello David :) Thanks for your library and your quick follow up! I am a big fan! double millis = noteSubparser.getDurationForString("w"); --> Is retrieving 0.25. Am i missing something here? – BabaNew Apr 25 '22 at 11:40
  • First, getDurationForString returns a value relative to beats, not millis. But also, I would expect 'w' to return 1.0, and I'm wondering if there's a calculation that is assuming 4 whole notes makes a beat. I'll look into this. – David Koelle Apr 25 '22 at 15:46
  • Try using capital W. When using JFugue, the code converts the string to uppercase before processing it, but when calling a method directly like this, there is no uppercasing happening inside the code. I should fix this. (With the lowercase 'w', a case statement is falling through to the default condition, which is a quarter note) – David Koelle Apr 26 '22 at 13:37
  • Very nice! With capital letter works perfectly! Thanks again! – BabaNew Apr 26 '22 at 13:53