Class: MIDI::MetaEvent

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

Direct Known Subclasses

KeySig, Marker, Tempo, TimeSig

Instance Attribute Summary collapse

Attributes inherited from Event

#delta_time, #print_channel_numbers_from_one, #print_decimal_numbers, #print_note_names, #status, #time_from_start

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Event

#<=>, #channel_to_s, #number_to_s, #quantize_to

Constructor Details

#initialize(meta_type, data = nil, delta_time = 0) ⇒ MetaEvent

Returns a new instance of MetaEvent.


430
431
432
433
434
# File 'lib/midilib/event.rb', line 430

def initialize(meta_type, data = nil, delta_time = 0)
  super(META_EVENT, delta_time)
  @meta_type = meta_type
  self.data=(data)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data


414
415
416
# File 'lib/midilib/event.rb', line 414

def data
  @data
end

#meta_typeObject (readonly)

Returns the value of attribute meta_type


413
414
415
# File 'lib/midilib/event.rb', line 413

def meta_type
  @meta_type
end

Class Method Details

.bytes_as_str(bytes) ⇒ Object


416
417
418
# File 'lib/midilib/event.rb', line 416

def self.bytes_as_str(bytes)
  bytes ? bytes.collect { |byte| byte.chr }.join : nil
end

.str_as_bytes(str) ⇒ Object


421
422
423
# File 'lib/midilib/event.rb', line 421

def self.str_as_bytes(str)
  str.split(//).collect { |chr| chr.ord }
end

Instance Method Details

#data_as_bytesObject


436
437
438
439
440
441
442
443
# File 'lib/midilib/event.rb', line 436

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_strObject


445
446
447
# File 'lib/midilib/event.rb', line 445

def data_as_str
  MetaEvent.bytes_as_str(@data)
end

#to_sObject


459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/midilib/event.rb', line 459

def to_s
  str = super()
  str << "meta #{number_to_s(@meta_type)} "
  # I know, I know...this isn't OO.
  case @meta_type
  when META_SEQ_NUM
    str << "sequence number"
  when META_TEXT
    str << "text: #{data_as_str}"
  when META_COPYRIGHT
    str << "copyright: #{data_as_str}"
  when META_SEQ_NAME
    str << "sequence or track name: #{data_as_str}"
  when META_INSTRUMENT
    str << "instrument name: #{data_as_str}"
  when META_LYRIC
    str << "lyric: #{data_as_str}"
  when META_MARKER
    str << "marker: #{data_as_str}"
  when META_CUE
    str << "cue point: #{@data}"
  when META_TRACK_END
    str << "track end"
  when META_SMPTE
    str << "smpte"
  when META_TIME_SIG
    str << "time signature"
  when META_KEY_SIG
    str << "key signature"
  when META_SEQ_SPECIF
    str << "sequence specific"
  else
    # Some other possible @meta_type values are handled by subclasses.
    str << "(other)"
  end
  return str
end