class MIDI::MetaEvent

Attributes

data[R]
meta_type[R]

Public Class Methods

bytes_as_str(bytes) click to toggle source
# File lib/midilib/event.rb, line 423
def self.bytes_as_str(bytes)
  bytes ? bytes.collect { |byte| byte.chr }.join : nil
end
new(meta_type, data = nil, delta_time = 0) click to toggle source
Calls superclass method MIDI::Event::new
# File lib/midilib/event.rb, line 431
def initialize(meta_type, data = nil, delta_time = 0)
  super(META_EVENT, delta_time)
  @meta_type = meta_type
  self.data = (data)
end
str_as_bytes(str) click to toggle source
# File lib/midilib/event.rb, line 427
def self.str_as_bytes(str)
  str.split(//).collect { |chr| chr.ord }
end

Public Instance Methods

data=(data) click to toggle source

Stores bytes. If data is a string, splits it into an array of bytes.

# File lib/midilib/event.rb, line 451
def data=(data)
  @data = case data
          when String
            MetaEvent.str_as_bytes(data)
          else
            data
          end
end
data_as_bytes() click to toggle source
# File lib/midilib/event.rb, line 437
def data_as_bytes
  data = []
  data << @status
  data << @meta_type
  data << (@data ? Utils.as_var_len(@data.length) : 0)
  data << @data if @data
  data.flatten
end
data_as_str() click to toggle source
# File lib/midilib/event.rb, line 446
def data_as_str
  MetaEvent.bytes_as_str(@data)
end
to_s() click to toggle source
Calls superclass method MIDI::Event#to_s
# File lib/midilib/event.rb, line 460
def to_s
  str = super()
  str << "meta #{number_to_s(@meta_type)} "
  # I know, I know...this isn't OO.
  str << case @meta_type
         when META_SEQ_NUM
           'sequence number'
         when META_TEXT
           "text: #{data_as_str}"
         when META_COPYRIGHT
           "copyright: #{data_as_str}"
         when META_SEQ_NAME
           "sequence or track name: #{data_as_str}"
         when META_INSTRUMENT
           "instrument name: #{data_as_str}"
         when META_LYRIC
           "lyric: #{data_as_str}"
         when META_MARKER
           "marker: #{data_as_str}"
         when META_CUE
           "cue point: #{@data}"
         when META_TRACK_END
           'track end'
         when META_SMPTE
           'smpte'
         when META_TIME_SIG
           'time signature'
         when META_KEY_SIG
           'key signature'
         when META_SEQ_SPECIF
           'sequence specific'
         else
           # Some other possible @meta_type values are handled by subclasses.
           '(other)'
         end
  str
end