Class: MIDI::Measure

Inherits:
Object
  • Object
show all
Defined in:
lib/midilib/measure.rb

Overview

The Measure class contains information about a measure from the sequence. The measure data is based on the time signature information from the sequence and is not stored in the sequence itself

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meas_no, start_time, duration, numer, denom, met_ticks) ⇒ Measure

Constructor


23
24
25
26
27
28
29
30
# File 'lib/midilib/measure.rb', line 23

def initialize(meas_no, start_time, duration, numer, denom, met_ticks)
  @measure_number = meas_no
  @start = start_time
  @end = start_time + duration - 1
  @numerator = numer
  @denominator = denom
  @metronome_ticks = met_ticks
end

Instance Attribute Details

#denominatorObject (readonly)

The denominator for the measure's time signature


12
13
14
# File 'lib/midilib/measure.rb', line 12

def denominator
  @denominator
end

#endObject (readonly)

End clock tick for the measure (inclusive)


16
17
18
# File 'lib/midilib/measure.rb', line 16

def end
  @end
end

#measure_numberObject (readonly)

The measure number (1-based)


18
19
20
# File 'lib/midilib/measure.rb', line 18

def measure_number
  @measure_number
end

#metronome_ticksObject (readonly)

The metronome tick for the measure


20
21
22
# File 'lib/midilib/measure.rb', line 20

def metronome_ticks
  @metronome_ticks
end

#numeratorObject (readonly)

The numerator (top digit) for the measure's time signature


10
11
12
# File 'lib/midilib/measure.rb', line 10

def numerator
  @numerator
end

#startObject (readonly)

Start clock tick for the measure


14
15
16
# File 'lib/midilib/measure.rb', line 14

def start
  @start
end

Instance Method Details

#contains_event?(e) ⇒ Boolean

Returns true if the event is in the measure

Returns:

  • (Boolean)

40
41
42
# File 'lib/midilib/measure.rb', line 40

def contains_event?(e)
  (e.time_from_start >= @start) && (e.time_from_start <= @end)
end

#to_sObject

Returns a detailed string with information about the measure


33
34
35
36
37
# File 'lib/midilib/measure.rb', line 33

def to_s
  t = "#{@numerator}/#{2**@denominator}"
  m = @metronome_ticks.to_f / 24
  "measure #{@measure_number}  #{@start}-#{@end}  #{t}   #{m} qs metronome"
end