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


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

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


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

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.


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

def denominator
  @data[1]
end

#measure_duration(ppqn) ⇒ Object

Calculates the duration (in ticks) for a full measure


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

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.


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

def metronome_ticks
  @data[2]
end

#numeratorObject

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


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

def numerator
  @data[0]
end

#to_sObject

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


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

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