Class: MIDI::Tempo

Inherits:
MetaEvent show all
Defined in:
lib/midilib/event.rb

Constant Summary collapse

MICROSECS_PER_MINUTE =
1_000_000 * 60

Instance Attribute Summary

Attributes inherited from MetaEvent

#data, #meta_type

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

Instance Method Summary collapse

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.



517
518
519
# File 'lib/midilib/event.rb', line 517

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).



508
509
510
# File 'lib/midilib/event.rb', line 508

def Tempo.bpm_to_mpq(bpm)
	return MICROSECS_PER_MINUTE / bpm
end

.mpq_to_bpm(mpq) ⇒ Object

Translates microseconds per quarter note (beat) to beats per minute.



513
514
515
# File 'lib/midilib/event.rb', line 513

def Tempo.mpq_to_bpm(mpq)
	return MICROSECS_PER_MINUTE.to_f / mpq.to_f
end

Instance Method Details

#data_as_bytesObject



529
530
531
532
533
534
535
536
537
# File 'lib/midilib/event.rb', line 529

def data_as_bytes
	data = []
	data << @status
	data << @meta_type
	data << 3
	data << ((@data >> 16) & 0xff)
	data << ((@data >> 8) & 0xff)
	data << (@data & 0xff)
end

#tempoObject



521
522
523
# File 'lib/midilib/event.rb', line 521

def tempo
	return @data
end

#tempo=(val) ⇒ Object



525
526
527
# File 'lib/midilib/event.rb', line 525

def tempo=(val)
	@data = val
end

#to_sObject



539
540
541
# File 'lib/midilib/event.rb', line 539

def to_s
	"tempo #{@data} msecs per qnote (#{Tempo.mpq_to_bpm(@data)} bpm)"
end