question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fractional Beats?

See original GitHub issue

First… 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:

image

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:closed
  • Created 4 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
melanchallcommented, Aug 28, 2019

I’ve added BarBeatTimeSpanUtilities with GetBarLength and GetBeatLength methods which allow to rewrite your method:

long Convert(int bar, double beats, TempoMap tempoMap)
{
    var barPart = TimeConverter.ConvertFrom(new BarBeatTimeSpan(bar), tempoMap);
    var beatsPart = BarBeatTimeSpanUtilities.GetBeatLength(bar, tempoMap) * beats;
    return barPart + (long)Math.Round(beatsPart);
}

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.

1reaction
melanchallcommented, Aug 28, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fractional Beats
Fractional Beats. @FractionalBeats-gs7yz‧4 subscribers‧14 videos‧. WoodenSpear Records is a music studio production , produces any of type of music,,,.
Read more >
Fractional Beats
WoodenSpear Records is a music studio production , produces any of type of music,,, Studio Located at Zvipani Hurungwe Mashonaland West ZimbabweProducer ...
Read more >
Rhythms & Fractions
Music is made up of all sorts of rhythms, and each rhythm can be broken down into smaller pieces: measures, which are fractions...
Read more >
Time signature
The time signature is a convention in Western music notation to specify how many of a ... These are based on beats expressed...
Read more >
Can beats in fractional meters be grouped? If so, are the ...
Yes, beats in fractional meters can be grouped in integers, but in integers based on subdivisions of the beat. For example, a bar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found