Class: MIDI::TimeSig

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

Overview

Container for time signature events

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

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(numer, denom, clocks, qnotes, delta_time = 0) ⇒ TimeSig

Constructor



548
549
550
# File 'lib/midilib/event.rb', line 548

def initialize(numer, denom, clocks, qnotes, delta_time = 0)
  super(META_TIME_SIG, [numer, denom, clocks, qnotes], delta_time)
end

Instance Method Details

#data_as_bytesObject

Returns the complete event as stored in the sequence



553
554
555
556
557
558
559
560
561
562
# File 'lib/midilib/event.rb', line 553

def data_as_bytes
  data = []
  data << @status
  data << @meta_type
  data << 4
  data << @data[0]
  data << @data[1]
  data << @data[2]
  data << @data[3]
end

#denominatorObject

Returns the denominator of the time signature. Use it as a power of 2 to get the displayed (lower-part) digit of the time signature.



576
577
578
# File 'lib/midilib/event.rb', line 576

def denominator
  @data[1]
end

#measure_duration(ppqn) ⇒ Object

Calculates the duration (in ticks) for a full measure



565
566
567
# File 'lib/midilib/event.rb', line 565

def measure_duration(ppqn)
  (4 * ppqn * @data[0]) / (2**@data[1])
end

#metronome_ticksObject

Returns the metronome tick duration for the time signature. On each quarter note, there’s 24 ticks.



582
583
584
# File 'lib/midilib/event.rb', line 582

def metronome_ticks
  @data[2]
end

#numeratorObject

Returns the numerator (the top digit) for the time signature



570
571
572
# File 'lib/midilib/event.rb', line 570

def numerator
  @data[0]
end

#to_sObject

Returns the time signature for the event as a string. Example: “time sig 3/4”



588
589
590
# File 'lib/midilib/event.rb', line 588

def to_s
  "time sig #{@data[0]}/#{2**@data[1]}"
end