Fractional Beats?
See original GitHub issueFirst… amazing library! Thank you, very much.
I want to use drywetmidi
to playback midi events. It seems that my source event times and lengths are not quite compatible with yours.
For example, my program is generating midi events with the following structure:
struct Event<T>
{
public int RelativeBar { get; set; }
public double Position { get; set; }
public double Length { get; set; }
public T Data { get; set; }
}
RelativeBar
: Simply the bar that an event starts.
Position
: The beat that an event starts. 1
would mean first beat. 2.5
would mean halfway before between 2nd and 3rd beat.
Length
: The duration of the event in beats. ‘1.33’ would mean roughly 1 + 1/3 beats.
You can see that I’m representing the number of beats as a double
where the value represents {Beats}.{Cents}
. I borrowed this system directly from my favorite DAW, Reaper:
It doesn’t seem that BarBeatTimeSpan
offers parity with this representation. It has Bars/Beats/Ticks
. Beats
is an whole number and Ticks
seems to store an additional MidiTimeSpan
value that doesn’t really have anything to do with bars/beats.
I’m sure that I can do the math on my own to convert my fractional beats to your ITimeSpan
but I wanted to go ahead and ask you if I was missing something in the library that handles this for me.
Thanks for your help!
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (15 by maintainers)
I’ve added
BarBeatTimeSpanUtilities
withGetBarLength
andGetBeatLength
methods which allow to rewrite your method:New API is in develop branch so if you want to try it right now you can build the library from sources.
Also I’m thinking on providing customizable beat division so it can be ticks or cents.
Hi,
Thanks for using the library!
I took Bar.Beat.Ticks notation from Cubase (another DAW like Reaper). Also it allows to set time and length as accurately as possible.
double
can lead to rounding errors on conversion to ticks (which is required since all timestamps stored as integer numbers inside a MIDI file).Your code is good. I already have plans to expose utilities to get bar/beat length in MIDI ticks so users can easily perform such conversions. It seems I should increase priority of this task 😃 I’ll implement this utilities within this issue so please don’t close it.