Class: Juicy::Duration
- Inherits:
-
Object
- Object
- Juicy::Duration
- Defined in:
- lib/juicy/duration.rb
Class Method Summary collapse
Instance Method Summary collapse
- #duration_in_milliseconds(tempo) ⇒ Object
-
#initialize(duration) ⇒ Duration
constructor
A new instance of Duration.
- #to_s ⇒ Object
Constructor Details
#initialize(duration) ⇒ Duration
Returns a new instance of Duration.
5 6 7 8 |
# File 'lib/juicy/duration.rb', line 5 def initialize(duration) @duration = parse_duration(duration) end |
Class Method Details
.duration_of_quarter_note_in_milliseconds(tempo) ⇒ Object
10 11 12 |
# File 'lib/juicy/duration.rb', line 10 def self.duration_of_quarter_note_in_milliseconds(tempo) 60_000.0/tempo end |
Instance Method Details
#duration_in_milliseconds(tempo) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/juicy/duration.rb', line 14 def duration_in_milliseconds(tempo) # how long a note is depends on the tempo and the musical duration # e.g. at 120 bpm, and a duration of an eighth note, the duration # in milliseconds would be 60_000.0/120/2 # milliseconds_per_second*seconds_per_minute/bpm/beats_of_given_type_per_quarter_note 60_000.0/tempo*beats_of_given_type_per_quarter_note end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/juicy/duration.rb', line 22 def to_s @duration.to_s end |