Class: MIDIMessage::ChannelMessage::Accessors

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-message/channel_message.rb

Constant Summary collapse

SCHEMA =
[
  { :name => :status, :index => 1 }, # second status nibble
  { :name => :data, :index => 0 }, # first data byte
  { :name => :data, :index => 1 } # second data byte
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Accessors


83
84
85
# File 'lib/midi-message/channel_message.rb', line 83

def initialize(klass)
  @klass = klass
end

Class Method Details

.decorate(klass) ⇒ Class


64
65
66
67
# File 'lib/midi-message/channel_message.rb', line 64

def self.decorate(klass)
  decorator = new(klass)
  decorator.decorate
end

.initialize(message) ⇒ Boolean

Initialize a message object with it's properties


72
73
74
75
76
77
78
79
80
# File 'lib/midi-message/channel_message.rb', line 72

def self.initialize(message)
  message.class.properties.each_with_index do |property, i|
    data_mapping = SCHEMA[i]
    container = message.send(data_mapping[:name])
    index = data_mapping[:index]
    message.send(:instance_variable_set, "@#{property.to_s}", container[index])
  end
  true
end

Instance Method Details

#decorateClass


88
89
90
91
92
93
94
95
# File 'lib/midi-message/channel_message.rb', line 88

def decorate
  @klass.properties.each_with_index do |property, i|
    data_mapping = SCHEMA[i]
    define_getter(property)
    define_setter(property, data_mapping)
  end
  @klass
end