Class: Wavesync::TrackPadding
- Inherits:
-
Object
- Object
- Wavesync::TrackPadding
- Defined in:
- lib/wavesync/track_padding.rb
Constant Summary collapse
- BEATS_PER_BAR =
4
Class Method Summary collapse
-
.bar_counts(duration_seconds, bpm, bar_multiple) ⇒ Object
: ((Float | Integer)? duration_seconds, (Integer | Float | String)? bpm, (Integer | Float)? bar_multiple) -> [Integer?, Integer?].
-
.compute(duration_seconds, bpm, bar_multiple) ⇒ Object
: ((Float | Integer)? duration_seconds, (Integer | Float | String)? bpm, (Integer | Float)? bar_multiple) -> (Float | Integer).
Class Method Details
.bar_counts(duration_seconds, bpm, bar_multiple) ⇒ Object
: ((Float | Integer)? duration_seconds, (Integer | Float | String)? bpm, (Integer | Float)? bar_multiple) -> [Integer?, Integer?]
21 22 23 24 25 26 27 28 |
# File 'lib/wavesync/track_padding.rb', line 21 def self.(duration_seconds, bpm, ) return [nil, nil] if bpm.nil? || bpm.to_f.zero? || duration_seconds.nil? || duration_seconds <= 0 || .nil? = BEATS_PER_BAR * 60.0 / bpm.to_f = (duration_seconds / ).round = ((.to_f / ).ceil * .to_f).to_i [, ] end |
.compute(duration_seconds, bpm, bar_multiple) ⇒ Object
: ((Float | Integer)? duration_seconds, (Integer | Float | String)? bpm, (Integer | Float)? bar_multiple) -> (Float | Integer)
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wavesync/track_padding.rb', line 9 def self.compute(duration_seconds, bpm, ) return 0 if bpm.nil? || bpm.to_f.zero? || duration_seconds.nil? || duration_seconds <= 0 || .nil? = BEATS_PER_BAR * 60.0 / bpm.to_f = (duration_seconds / ).round(6) = ( / .to_f).ceil * .to_f padding = ( * ) - duration_seconds padding < 0.001 ? 0 : padding end |