lib/head_music/meter.rb in head_music-0.17.0 vs lib/head_music/meter.rb in head_music-0.18.0
- old
+ new
@@ -1,12 +1,15 @@
+# frozen_string_literal: true
+
+# Meter is the rhythmic size of a measure, such as 4/4 or 6/8
class HeadMusic::Meter
attr_reader :top_number, :bottom_number
NAMED = {
common_time: '4/4',
- cut_time: '2/2'
- }
+ cut_time: '2/2',
+ }.freeze
def self.get(identifier)
identifier = identifier.to_s
hash_key = HeadMusic::Utilities::HashKey.for(identifier)
time_signature_string = NAMED[hash_key] || identifier
@@ -25,11 +28,12 @@
def self.cut_time
get(:cut_time)
end
def initialize(top_number, bottom_number)
- @top_number, @bottom_number = top_number, bottom_number
+ @top_number = top_number
+ @bottom_number = bottom_number
end
def simple?
!compound?
end
@@ -41,11 +45,11 @@
def duple?
top_number == 2
end
def triple?
- top_number % 3 == 0
+ (top_number % 3).zero?
end
def quadruple?
top_number == 4
end
@@ -75,12 +79,11 @@
end
def beat_unit
@beat_unit ||=
if compound?
- unit = HeadMusic::RhythmicUnit.for_denominator_value(bottom_number / 2)
- HeadMusic::RhythmicValue.new(unit, dots: 1)
+ HeadMusic::RhythmicValue.new(HeadMusic::RhythmicUnit.for_denominator_value(bottom_number / 2), dots: 1)
else
HeadMusic::RhythmicValue.new(count_unit)
end
end
@@ -99,14 +102,11 @@
end
end
end
def strong_ticks
- @strong_ticks ||=
- [2,3,4].map do |sixths|
- ticks_per_count * (sixths / 6.0)
- end
+ @strong_ticks ||= [2, 3, 4].map { |sixths| ticks_per_count * (sixths / 6.0) }
end
private
def downbeat?(count, tick = 0)
@@ -120,12 +120,12 @@
def strong_beat_in_duple?(count, tick = 0)
beat?(tick) && (count == counts_per_bar / 2.0 + 1)
end
def strong_beat_in_triple?(count, tick = 0)
- beat?(tick) && counts_per_bar % 3 == 0 && counts_per_bar > 6 && count % 3 == 1
+ beat?(tick) && (counts_per_bar % 3).zero? && counts_per_bar > 6 && count % 3 == 1
end
def beat?(tick)
- tick == 0
+ tick.zero?
end
end