Class: MIDI::Tempo
Constant Summary collapse
- MICROSECS_PER_MINUTE =
1_000_000 * 60
Instance Attribute Summary
Attributes inherited from MetaEvent
Attributes inherited from Event
#delta_time, #print_channel_numbers_from_one, #print_decimal_numbers, #print_note_names, #status, #time_from_start
Class Method Summary collapse
-
.bpm_to_mpq(bpm) ⇒ Object
Translates beats per minute to microseconds per quarter note (beat).
-
.mpq_to_bpm(mpq) ⇒ Object
Translates microseconds per quarter note (beat) to beats per minute.
Instance Method Summary collapse
- #data_as_bytes ⇒ Object
-
#initialize(msecs_per_qnote, delta_time = 0) ⇒ Tempo
constructor
A new instance of Tempo.
- #tempo ⇒ Object
- #tempo=(val) ⇒ Object
- #to_s ⇒ Object
Methods inherited from MetaEvent
bytes_as_str, #data_as_str, str_as_bytes
Methods inherited from Event
#<=>, #channel_to_s, #number_to_s, #quantize_to
Constructor Details
#initialize(msecs_per_qnote, delta_time = 0) ⇒ Tempo
Returns a new instance of Tempo.
518 519 520 |
# File 'lib/midilib/event.rb', line 518 def initialize(msecs_per_qnote, delta_time = 0) super(META_SET_TEMPO, msecs_per_qnote, delta_time) end |
Class Method Details
.bpm_to_mpq(bpm) ⇒ Object
Translates beats per minute to microseconds per quarter note (beat).
509 510 511 |
# File 'lib/midilib/event.rb', line 509 def self.bpm_to_mpq(bpm) MICROSECS_PER_MINUTE / bpm end |
.mpq_to_bpm(mpq) ⇒ Object
Translates microseconds per quarter note (beat) to beats per minute.
514 515 516 |
# File 'lib/midilib/event.rb', line 514 def self.mpq_to_bpm(mpq) MICROSECS_PER_MINUTE.to_f / mpq.to_f end |
Instance Method Details
#data_as_bytes ⇒ Object
530 531 532 533 534 535 536 537 538 |
# File 'lib/midilib/event.rb', line 530 def data_as_bytes data = [] data << @status data << @meta_type data << 3 data << ((@data >> 16) & 0xff) data << ((@data >> 8) & 0xff) data << (@data & 0xff) end |
#tempo ⇒ Object
522 523 524 |
# File 'lib/midilib/event.rb', line 522 def tempo @data end |
#tempo=(val) ⇒ Object
526 527 528 |
# File 'lib/midilib/event.rb', line 526 def tempo=(val) @data = val end |
#to_s ⇒ Object
540 541 542 |
# File 'lib/midilib/event.rb', line 540 def to_s "tempo #{@data} msecs per qnote (#{Tempo.mpq_to_bpm(@data)} bpm)" end |