Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Song tempo incorrectly calculated #8

Open
blakeley opened this issue Jan 10, 2014 · 1 comment · May be fixed by #29
Open

Song tempo incorrectly calculated #8

blakeley opened this issue Jan 10, 2014 · 1 comment · May be fixed by #29
Assignees
Labels

Comments

@blakeley
Copy link

MIDIs (even in format 1) can have multiple tempos.

method beats_per_minute in sequence.rb assumes that there is one single tempo on the first track for the entire song. Tempo events can occur on any track, but more importantly, multiple tempo events often occur throughout a song to account for accelerandos, etc.

# Returns the song tempo in beats per minute.
def beats_per_minute
  return DEFAULT_TEMPO if @tracks.nil? || @tracks.empty?
  event = @tracks.first.events.detect { |e| e.kind_of?(MIDI::Tempo) }
  return event ? (Tempo.mpq_to_bpm(event.tempo)) : DEFAULT_TEMPO
end

As a consequence, pulses per second is also incorrect. You can't make the assumption that there is a single, static tempo. A correct implementation of this requires summation across multiple tempos.

def pulses_to_seconds(pulses)
  (pulses.to_f / @ppqn.to_f / beats_per_minute()) * 60.0
end
@jimm
Copy link
Owner

jimm commented Nov 24, 2015

Would it make more sense to have these two methods take an argument that says at what offset in the song the BPM is being requested? By default, if no argument was given it would behave as it currently does by using the first tempo of the first track.

@jimm jimm added the bug label Nov 24, 2015
@jimm jimm self-assigned this Mar 7, 2021
jimm pushed a commit that referenced this issue Mar 7, 2021
jimm pushed a commit that referenced this issue Mar 7, 2021
Fukurokudzu added a commit to Fukurokudzu/midilib that referenced this issue Feb 24, 2023
@Fukurokudzu Fukurokudzu linked a pull request Feb 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants