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_decimal_numbers, #print_note_names, #status, #time_from_start

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Event

#<=>, #channel?, #meta?, #note?, #note_off?, #note_on?, #number_to_s, #quantize_to, #realtime?, #system?

Constructor Details

#initialize(msecs_per_qnote, delta_time = 0) ⇒ Tempo

Returns a new instance of Tempo.



532
533
534
# File 'lib/midilib/event.rb', line 532

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



523
524
525
# File 'lib/midilib/event.rb', line 523

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.



528
529
530
# File 'lib/midilib/event.rb', line 528

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

Instance Method Details

#data_as_bytesObject



544
545
546
547
548
549
550
551
552
553
# File 'lib/midilib/event.rb', line 544

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

#tempoObject



536
537
538
# File 'lib/midilib/event.rb', line 536

def tempo
	return @data
end

#tempo=(val) ⇒ Object



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

def tempo=(val)
	@data = val
end

#to_sObject



555
556
557
# File 'lib/midilib/event.rb', line 555

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