Class: Sunniesnow::Charter::BpmChangeList
- Inherits:
-
Object
- Object
- Sunniesnow::Charter::BpmChangeList
- Defined in:
- lib/sscharter.rb
Defined Under Namespace
Classes: BpmChange
Instance Attribute Summary collapse
-
#offset ⇒ Object
Returns the value of attribute offset.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(beat, bpm) ⇒ Object
-
#initialize(offset) ⇒ BpmChangeList
constructor
A new instance of BpmChangeList.
- #time_at(beat) ⇒ Object
Constructor Details
#initialize(offset) ⇒ BpmChangeList
Returns a new instance of BpmChangeList.
49 50 51 52 |
# File 'lib/sscharter.rb', line 49 def initialize offset @offset = offset @list = [] end |
Instance Attribute Details
#offset ⇒ Object
Returns the value of attribute offset.
47 48 49 |
# File 'lib/sscharter.rb', line 47 def offset @offset end |
Instance Method Details
#[](index) ⇒ Object
70 71 72 |
# File 'lib/sscharter.rb', line 70 def [] index @list[index] end |
#add(beat, bpm) ⇒ Object
54 55 56 57 58 |
# File 'lib/sscharter.rb', line 54 def add beat, bpm @list.push BpmChange.new beat, bpm @list.sort! self end |
#time_at(beat) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/sscharter.rb', line 60 def time_at beat index = @list.bisect(right: true) { _1.beat <=> beat } raise ArgumentError, 'beat is before the first bpm change' if index < 0 bpm = @list[index] (0...index).sum @offset + (beat - bpm.beat) / bpm.bps do |i| bpm = @list[i] (@list[i+1].beat - bpm.beat) / bpm.bps end end |