From 71a9b4398568615ae5d3d23bd8d01033305b70d7 Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Thu, 23 Feb 2023 21:41:43 +0500 Subject: [PATCH 1/9] First draft --- examples/ex2.mid | Bin 0 -> 257 bytes lib/midilib/sequence.rb | 45 ++++++++++++++++++++++++++++++++++++++++ testing.rb | 19 +++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 examples/ex2.mid create mode 100644 testing.rb diff --git a/examples/ex2.mid b/examples/ex2.mid new file mode 100644 index 0000000000000000000000000000000000000000..a89f20ce4c5966ea15268d445489da454f4303c0 GIT binary patch literal 257 zcmeYb$w*;fU|?flWMF1|;2Tnu4dm%E{EuK^VUplr_#epx Date: Fri, 24 Feb 2023 17:39:41 +0500 Subject: [PATCH 2/9] Contribution to #8 --- lib/midilib/sequence.rb | 98 +++++++++++++++++++++++------------------ test/test_sequence.rb | 26 +++++++++++ 2 files changed, 80 insertions(+), 44 deletions(-) diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index 475d342..100d589 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -9,6 +9,7 @@ class Sequence UNNAMED = 'Unnamed Sequence' DEFAULT_TEMPO = 120 + BPM_ROUND = 3 NOTE_TO_LENGTH = { 'whole' => 4.0, @@ -70,50 +71,6 @@ def beats_per_minute event ? Tempo.mpq_to_bpm(event.tempo) : DEFAULT_TEMPO end - def get_tempo_parts - tempo_parts = {} - Array(@tracks).each do |track| - track.events.map do |e| - tempo_parts[e.time_from_start] = Tempo.mpq_to_bpm(e.tempo) if e.is_a?(MIDI::Tempo) - end - end - tempo_parts - end - - def avg_beats_per_minute - return DEFAULT_TEMPO if @tracks.nil? || @tracks.empty? - - bpm_min = tempo_parts.min - bpm_max = tempo_parts.max - tempo_events ? Tempo.mpq_to_bpm(event.tempo) : DEFAULT_TEMPO - # parts_lenght(tempo_parts.keys, self.get_measures.last.end) - end - - def beats_per_minute_now - - end - - # def avg_beats_per_minute - # return DEFAULT_TEMPO if @tracks.nil? || @tracks.empty? - # tempo_parts = {} - # Array(@tracks).each do |track| - # track.events.map do |e| - # tempo_parts[e.time_from_start] = Tempo.mpq_to_bpm(e.tempo) if e.is_a?(MIDI::Tempo) - # end - # end - # # tempo_events ? Tempo.mpq_to_bpm(event.tempo) : DEFAULT_TEMPO - # # parts_lenght(tempo_parts.keys, self.get_measures.last.end) - # end - - # def parts_lenght(start_points, track_ends) - # parts_lenght = [] - # start_points.each_with_index do |start_point, i| - # start_points[i+1].nil? ? part_end = track_ends : part_end = start_points[i+1] - # parts_lenght << part_end - start_point - # end - # parts_lenght - # end - alias bpm beats_per_minute alias tempo beats_per_minute @@ -124,6 +81,12 @@ def pulses_to_seconds(pulses) (pulses.to_f / @ppqn.to_f / beats_per_minute) * 60.0 end + def pulses_to_seconds_current(pulses, offset) + unless beats_per_minute_current(offset).nil? + (pulses.to_f / @ppqn.to_f / beats_per_minute_current(offset)) * 60.0 + end + end + # Given a note length name like "whole", "dotted quarter", or "8th # triplet", return the length of that note in quarter notes as a delta # time. @@ -245,5 +208,52 @@ def get_measures end measures end + + # Returns array of minimum and maximum bpm within sequence + def beats_per_minute_min_max + return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? + tempo_parts = get_tempo_parts + return tempo_parts.values if tempo_parts.length == 1 + [tempo_parts.values.min.round(BPM_ROUND), tempo_parts.values.max.round(BPM_ROUND)] + end + + # Returns array with all tempos parts within sequence + def beats_per_minute_all + return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? + tempo_parts = get_tempo_parts + tempo_parts.values.map { |bpm| bpm.round(BPM_ROUND) } + end + + # Returns bpm value for offset, nil if offset is out of range + def beats_per_minute_current(offset) + return DEFAULT_TEMPO if @tracks.nil? || @tracks.empty? + return nil if offset > self.get_measures.last.end || offset < 0 + current_bpm = 0 + tempo_parts = get_tempo_parts + tempo_parts.each_with_index do |part, i| + if !tempo_parts[i+1].nil? + current_bpm = part[1] if part[0] <= offset && tempo_parts[i+1][0] > offset + else + current_bpm = part[1] if part[0] <= offset + end + end + current_bpm.round(BPM_ROUND) + end + + private + + # Private method to split sequence into parts, if more then one bpm present in sequence + # Returns hash { start_time => bpm } + def get_tempo_parts + tempo_parts = {} + return tempo_parts[0] = DEFAULT_TEMPO if @tracks.nil? || @tracks.empty? + Array(@tracks).each do |track| + track.events.map do |e| + e.is_a?(MIDI::Tempo) ? tempo_parts[e.time_from_start] = Tempo.mpq_to_bpm(e.tempo) : tempo_parts[0] = DEFAULT_TEMPO + end + end + tempo_parts + end + end end diff --git a/test/test_sequence.rb b/test/test_sequence.rb index 6610f31..3ad7c45 100644 --- a/test/test_sequence.rb +++ b/test/test_sequence.rb @@ -13,6 +13,7 @@ def setup @seq.tracks << @track 3.times { @track.events << MIDI::NoteOn.new(0, 64, 64, 100) } @track.recalc_times + @seq_bpm_diff = MIDI::Sequence.new end def test_basics @@ -31,6 +32,12 @@ def test_pulses_to_seconds # An eight note should take 0.25 seconds assert_in_delta 0.25, @seq.pulses_to_seconds(480 / 2), 0.00001 + + # At a tempo of 120 BPM 480 pulses (one quarter note) should take 0.5 seconds + assert_in_delta 0.5, @seq.pulses_to_seconds_current(480, 1000), 0.00001 + + # Should retun nil if offset is out of range + assert_equal(nil, @seq.pulses_to_seconds_current(480, 1920)) end def test_length_to_delta @@ -77,4 +84,23 @@ def test_note_to_delta assert_equal(480 / 16, @seq.note_to_delta('sixtyfourth')) assert_equal(480 / 16, @seq.note_to_delta('64th')) end + + def test_beats_per_minute + # Using file with 2 different tempos whithin sequence (bpm change at 15600) + File.open('examples/ex2.mid', 'rb') do | file | + @seq_bpm_diff.read(file) + assert_equal(nil, @seq_bpm_diff.beats_per_minute_current(-1000)) + assert_equal(120.0, @seq_bpm_diff.beats_per_minute_current(15599)) + assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15600)) + assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15601)) + assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_min_max) + assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_all) + end + + # Using regular testing sequence + assert_equal(120.0, @seq.beats_per_minute_current(1918)) + assert_equal(nil, @seq.beats_per_minute_current(1920)) + assert_equal([120.0], @seq.beats_per_minute_min_max) + assert_equal([120.0], @seq.beats_per_minute_all) + end end From 3ca44bfc665ea87425bf7d3b07a52f2a744cace0 Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Fri, 24 Feb 2023 18:08:28 +0500 Subject: [PATCH 3/9] Removing testing.rb, added comment for pulses_to_seconds_current --- lib/midilib/sequence.rb | 1 + testing.rb | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 testing.rb diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index 100d589..4344975 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -81,6 +81,7 @@ def pulses_to_seconds(pulses) (pulses.to_f / @ppqn.to_f / beats_per_minute) * 60.0 end + # The same with offset. Returns nil if out of range def pulses_to_seconds_current(pulses, offset) unless beats_per_minute_current(offset).nil? (pulses.to_f / @ppqn.to_f / beats_per_minute_current(offset)) * 60.0 diff --git a/testing.rb b/testing.rb deleted file mode 100644 index 92c22a5..0000000 --- a/testing.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative('lib/midilib') - -# Create a new, empty sequence. -seq = MIDI::Sequence.new() - -# Read the contents of a MIDI file into the sequence. -File.open('examples/ex2.mid', 'rb') { | file | - seq.read(file) { | track, num_tracks, i | - Array(track).each do |event| - # if MIDI::Tempo === event - # p event.data - # end - - end - - } - seq.avg_beats_per_minute - # p MIDI::META_TRACK_END -} \ No newline at end of file From 6b0cee5701b6c1901ee9d8a2401cc26b6e9bbad5 Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Fri, 24 Feb 2023 18:49:05 +0500 Subject: [PATCH 4/9] bpm_current behavior fix --- lib/midilib/sequence.rb | 4 ++-- test/test_sequence.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index 4344975..3891e84 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -226,10 +226,10 @@ def beats_per_minute_all end # Returns bpm value for offset, nil if offset is out of range - def beats_per_minute_current(offset) + def beats_per_minute_current(offset = 0) return DEFAULT_TEMPO if @tracks.nil? || @tracks.empty? return nil if offset > self.get_measures.last.end || offset < 0 - current_bpm = 0 + current_bpm = DEFAULT_TEMPO tempo_parts = get_tempo_parts tempo_parts.each_with_index do |part, i| if !tempo_parts[i+1].nil? diff --git a/test/test_sequence.rb b/test/test_sequence.rb index 3ad7c45..1b62c42 100644 --- a/test/test_sequence.rb +++ b/test/test_sequence.rb @@ -90,6 +90,7 @@ def test_beats_per_minute File.open('examples/ex2.mid', 'rb') do | file | @seq_bpm_diff.read(file) assert_equal(nil, @seq_bpm_diff.beats_per_minute_current(-1000)) + assert_equal(120.0, @seq_bpm_diff.beats_per_minute_current) assert_equal(120.0, @seq_bpm_diff.beats_per_minute_current(15599)) assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15600)) assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15601)) From 6cc5a74c36bb1ef2b9f8f142f865020aeccd878e Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Fri, 24 Feb 2023 18:52:49 +0500 Subject: [PATCH 5/9] PTS_current behavior fix --- lib/midilib/sequence.rb | 2 +- test/test_sequence.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index 3891e84..dfdb1d7 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -82,7 +82,7 @@ def pulses_to_seconds(pulses) end # The same with offset. Returns nil if out of range - def pulses_to_seconds_current(pulses, offset) + def pulses_to_seconds_current(pulses, offset = 0) unless beats_per_minute_current(offset).nil? (pulses.to_f / @ppqn.to_f / beats_per_minute_current(offset)) * 60.0 end diff --git a/test/test_sequence.rb b/test/test_sequence.rb index 1b62c42..e313ed7 100644 --- a/test/test_sequence.rb +++ b/test/test_sequence.rb @@ -36,6 +36,9 @@ def test_pulses_to_seconds # At a tempo of 120 BPM 480 pulses (one quarter note) should take 0.5 seconds assert_in_delta 0.5, @seq.pulses_to_seconds_current(480, 1000), 0.00001 + # Should use offset = 0 if offset is not present + assert_in_delta 0.5, @seq.pulses_to_seconds_current(480), 0.00001 + # Should retun nil if offset is out of range assert_equal(nil, @seq.pulses_to_seconds_current(480, 1920)) end From 2cda21cfba8364b63df96b86774a472f95abbc98 Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Fri, 24 Feb 2023 19:19:43 +0500 Subject: [PATCH 6/9] Minor refactoring fixes --- lib/midilib/sequence.rb | 7 +++---- test/test_sequence.rb | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index dfdb1d7..f73ca90 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -213,16 +213,15 @@ def get_measures # Returns array of minimum and maximum bpm within sequence def beats_per_minute_min_max return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - tempo_parts = get_tempo_parts + tempo_parts = get_tempo_parts.transform_values! { |bpm| bpm.round(BPM_ROUND) } return tempo_parts.values if tempo_parts.length == 1 - [tempo_parts.values.min.round(BPM_ROUND), tempo_parts.values.max.round(BPM_ROUND)] + [tempo_parts.values.min, tempo_parts.values.max] end # Returns array with all tempos parts within sequence def beats_per_minute_all return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - tempo_parts = get_tempo_parts - tempo_parts.values.map { |bpm| bpm.round(BPM_ROUND) } + get_tempo_parts.values.map { |bpm| bpm.round(BPM_ROUND) } end # Returns bpm value for offset, nil if offset is out of range diff --git a/test/test_sequence.rb b/test/test_sequence.rb index e313ed7..02da1e7 100644 --- a/test/test_sequence.rb +++ b/test/test_sequence.rb @@ -38,7 +38,7 @@ def test_pulses_to_seconds # Should use offset = 0 if offset is not present assert_in_delta 0.5, @seq.pulses_to_seconds_current(480), 0.00001 - + # Should retun nil if offset is out of range assert_equal(nil, @seq.pulses_to_seconds_current(480, 1920)) end @@ -97,6 +97,7 @@ def test_beats_per_minute assert_equal(120.0, @seq_bpm_diff.beats_per_minute_current(15599)) assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15600)) assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15601)) + assert_equal(nil, @seq_bpm_diff.beats_per_minute_current(5000000)) assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_min_max) assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_all) end @@ -104,7 +105,7 @@ def test_beats_per_minute # Using regular testing sequence assert_equal(120.0, @seq.beats_per_minute_current(1918)) assert_equal(nil, @seq.beats_per_minute_current(1920)) - assert_equal([120.0], @seq.beats_per_minute_min_max) + assert_equal([120], @seq.beats_per_minute_min_max) assert_equal([120.0], @seq.beats_per_minute_all) end end From c7d556438ff547713aa8b4f40659086c50c18ded Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Fri, 24 Feb 2023 19:35:20 +0500 Subject: [PATCH 7/9] Final refactoring --- lib/midilib/sequence.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index f73ca90..c0e55fd 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -213,7 +213,7 @@ def get_measures # Returns array of minimum and maximum bpm within sequence def beats_per_minute_min_max return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - tempo_parts = get_tempo_parts.transform_values! { |bpm| bpm.round(BPM_ROUND) } + tempo_parts = get_tempo_parts return tempo_parts.values if tempo_parts.length == 1 [tempo_parts.values.min, tempo_parts.values.max] end @@ -221,7 +221,7 @@ def beats_per_minute_min_max # Returns array with all tempos parts within sequence def beats_per_minute_all return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - get_tempo_parts.values.map { |bpm| bpm.round(BPM_ROUND) } + get_tempo_parts.values end # Returns bpm value for offset, nil if offset is out of range @@ -237,7 +237,7 @@ def beats_per_minute_current(offset = 0) current_bpm = part[1] if part[0] <= offset end end - current_bpm.round(BPM_ROUND) + current_bpm end private @@ -252,7 +252,7 @@ def get_tempo_parts e.is_a?(MIDI::Tempo) ? tempo_parts[e.time_from_start] = Tempo.mpq_to_bpm(e.tempo) : tempo_parts[0] = DEFAULT_TEMPO end end - tempo_parts + tempo_parts.transform_values! { |bpm| bpm.round(BPM_ROUND) } end end From ec9c86cfb4cb0eff73d38fa6e39a19bfce7a7ad2 Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Thu, 6 Apr 2023 14:57:48 +0500 Subject: [PATCH 8/9] Replaced bpm and ppm with one with time_from_start option --- lib/midilib/sequence.rb | 73 +++++++++++++++++------------------------ test/test_sequence.rb | 22 ++++++------- 2 files changed, 41 insertions(+), 54 deletions(-) diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index c0e55fd..4901611 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -63,12 +63,34 @@ def time_signature(numer, denom, clocks, qnotes) @qnotes = qnotes end - # Returns the song tempo in beats per minute. - def beats_per_minute + # Returns the song tempo in beats per minute, nil if time_from_start is out of range + def beats_per_minute(time_from_start = 0) return DEFAULT_TEMPO if @tracks.nil? || @tracks.empty? + return nil if time_from_start > self.get_measures.last.end || time_from_start < 0 + current_bpm = DEFAULT_TEMPO + tempo_parts = get_tempo_parts + tempo_parts.each_with_index do |part, i| + if !tempo_parts[i+1].nil? + current_bpm = part[1] if part[0] <= time_from_start && tempo_parts[i+1][0] > time_from_start + else + current_bpm = part[1] if part[0] <= time_from_start + end + end + current_bpm + end + + # Returns array of minimum and maximum bpm within sequence + def beats_per_minute_min_max + return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? + tempo_parts = get_tempo_parts + return tempo_parts.values if tempo_parts.length == 1 + [tempo_parts.values.min, tempo_parts.values.max] + end - event = @tracks.first.events.detect { |e| e.is_a?(MIDI::Tempo) } - event ? Tempo.mpq_to_bpm(event.tempo) : DEFAULT_TEMPO + # Returns array with all tempos parts within sequence + def beats_per_minute_all + return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? + get_tempo_parts.values end alias bpm beats_per_minute @@ -76,15 +98,10 @@ def beats_per_minute # Pulses (also called ticks) are the units of delta times and event # time_from_start values. This method converts a number of pulses to a - # float value that is a time in seconds. - def pulses_to_seconds(pulses) - (pulses.to_f / @ppqn.to_f / beats_per_minute) * 60.0 - end - - # The same with offset. Returns nil if out of range - def pulses_to_seconds_current(pulses, offset = 0) - unless beats_per_minute_current(offset).nil? - (pulses.to_f / @ppqn.to_f / beats_per_minute_current(offset)) * 60.0 + # float value that is a time in seconds. Returns nil if time_from_start out of range + def pulses_to_seconds(pulses, time_from_start = 0) + unless beats_per_minute(time_from_start).nil? + (pulses.to_f / @ppqn.to_f / beats_per_minute(time_from_start)) * 60.0 end end @@ -209,36 +226,6 @@ def get_measures end measures end - - # Returns array of minimum and maximum bpm within sequence - def beats_per_minute_min_max - return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - tempo_parts = get_tempo_parts - return tempo_parts.values if tempo_parts.length == 1 - [tempo_parts.values.min, tempo_parts.values.max] - end - - # Returns array with all tempos parts within sequence - def beats_per_minute_all - return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - get_tempo_parts.values - end - - # Returns bpm value for offset, nil if offset is out of range - def beats_per_minute_current(offset = 0) - return DEFAULT_TEMPO if @tracks.nil? || @tracks.empty? - return nil if offset > self.get_measures.last.end || offset < 0 - current_bpm = DEFAULT_TEMPO - tempo_parts = get_tempo_parts - tempo_parts.each_with_index do |part, i| - if !tempo_parts[i+1].nil? - current_bpm = part[1] if part[0] <= offset && tempo_parts[i+1][0] > offset - else - current_bpm = part[1] if part[0] <= offset - end - end - current_bpm - end private diff --git a/test/test_sequence.rb b/test/test_sequence.rb index 02da1e7..0b29ee7 100644 --- a/test/test_sequence.rb +++ b/test/test_sequence.rb @@ -34,13 +34,13 @@ def test_pulses_to_seconds assert_in_delta 0.25, @seq.pulses_to_seconds(480 / 2), 0.00001 # At a tempo of 120 BPM 480 pulses (one quarter note) should take 0.5 seconds - assert_in_delta 0.5, @seq.pulses_to_seconds_current(480, 1000), 0.00001 + assert_in_delta 0.5, @seq.pulses_to_seconds(480, 1000), 0.00001 # Should use offset = 0 if offset is not present - assert_in_delta 0.5, @seq.pulses_to_seconds_current(480), 0.00001 + assert_in_delta 0.5, @seq.pulses_to_seconds(480), 0.00001 # Should retun nil if offset is out of range - assert_equal(nil, @seq.pulses_to_seconds_current(480, 1920)) + assert_equal(nil, @seq.pulses_to_seconds(480, 1920)) end def test_length_to_delta @@ -92,19 +92,19 @@ def test_beats_per_minute # Using file with 2 different tempos whithin sequence (bpm change at 15600) File.open('examples/ex2.mid', 'rb') do | file | @seq_bpm_diff.read(file) - assert_equal(nil, @seq_bpm_diff.beats_per_minute_current(-1000)) - assert_equal(120.0, @seq_bpm_diff.beats_per_minute_current) - assert_equal(120.0, @seq_bpm_diff.beats_per_minute_current(15599)) - assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15600)) - assert_equal(131.34, @seq_bpm_diff.beats_per_minute_current(15601)) - assert_equal(nil, @seq_bpm_diff.beats_per_minute_current(5000000)) + assert_equal(nil, @seq_bpm_diff.beats_per_minute(-1000)) + assert_equal(120.0, @seq_bpm_diff.beats_per_minute) + assert_equal(120.0, @seq_bpm_diff.beats_per_minute(15599)) + assert_equal(131.34, @seq_bpm_diff.beats_per_minute(15600)) + assert_equal(131.34, @seq_bpm_diff.beats_per_minute(15601)) + assert_equal(nil, @seq_bpm_diff.beats_per_minute(5000000)) assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_min_max) assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_all) end # Using regular testing sequence - assert_equal(120.0, @seq.beats_per_minute_current(1918)) - assert_equal(nil, @seq.beats_per_minute_current(1920)) + assert_equal(120.0, @seq.beats_per_minute(1918)) + assert_equal(nil, @seq.beats_per_minute(1920)) assert_equal([120], @seq.beats_per_minute_min_max) assert_equal([120.0], @seq.beats_per_minute_all) end From deba8bfa93ebaa48ba523f04c4341ee92b09e7d2 Mon Sep 17 00:00:00 2001 From: Fukurokudzu Date: Thu, 6 Apr 2023 15:01:51 +0500 Subject: [PATCH 9/9] Got rid of bpm_min_max and bpm_all methods --- lib/midilib/sequence.rb | 14 -------------- test/test_sequence.rb | 4 ---- 2 files changed, 18 deletions(-) diff --git a/lib/midilib/sequence.rb b/lib/midilib/sequence.rb index 4901611..5700f8e 100644 --- a/lib/midilib/sequence.rb +++ b/lib/midilib/sequence.rb @@ -79,20 +79,6 @@ def beats_per_minute(time_from_start = 0) current_bpm end - # Returns array of minimum and maximum bpm within sequence - def beats_per_minute_min_max - return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - tempo_parts = get_tempo_parts - return tempo_parts.values if tempo_parts.length == 1 - [tempo_parts.values.min, tempo_parts.values.max] - end - - # Returns array with all tempos parts within sequence - def beats_per_minute_all - return [DEFAULT_TEMPO] if @tracks.nil? || @tracks.empty? - get_tempo_parts.values - end - alias bpm beats_per_minute alias tempo beats_per_minute diff --git a/test/test_sequence.rb b/test/test_sequence.rb index 0b29ee7..58ad196 100644 --- a/test/test_sequence.rb +++ b/test/test_sequence.rb @@ -98,14 +98,10 @@ def test_beats_per_minute assert_equal(131.34, @seq_bpm_diff.beats_per_minute(15600)) assert_equal(131.34, @seq_bpm_diff.beats_per_minute(15601)) assert_equal(nil, @seq_bpm_diff.beats_per_minute(5000000)) - assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_min_max) - assert_equal([120.0, 131.34], @seq_bpm_diff.beats_per_minute_all) end # Using regular testing sequence assert_equal(120.0, @seq.beats_per_minute(1918)) assert_equal(nil, @seq.beats_per_minute(1920)) - assert_equal([120], @seq.beats_per_minute_min_max) - assert_equal([120.0], @seq.beats_per_minute_all) end end