Module: MIDIMessage::ChannelMessage

Included in:
ChannelAftertouch, ControlChange, NoteOff, NoteOn, PitchBend, PolyphonicAftertouch, ProgramChange, RawChannelMessage
Defined in:
lib/midi-message/channel_message.rb

Overview

common behavior amongst Channel Message types

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/midi-message/channel_message.rb', line 8

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/midi-message/channel_message.rb', line 8

def name
  @name
end

Class Method Details

.new(*a, &block) ⇒ Object



11
12
13
# File 'lib/midi-message/channel_message.rb', line 11

def self.new(*a, &block)
  RawChannelMessage.new(*a, &block)
end

Instance Method Details

#initialize(*a) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/midi-message/channel_message.rb', line 15

def initialize(*a)
  options = a.last.kind_of?(Hash) ? a.pop : {}
  @const = options[:const]        
  unless @const.nil?
    key = self.class.map_constants_to
    ind = self.class.properties.index(key)
    ind ||= 0
    a.insert(ind, @const.value)               
  end
  initialize_channel_message(self.class.type_for_status, *a)
end

#initialize_propertiesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/midi-message/channel_message.rb', line 27

def initialize_properties
  props = [
    { :name => :status, :index => 1 },
    { :name => :data, :index => 0 },
    { :name => :data, :index => 1 }
  ]
  properties = self.class.properties
  unless properties.nil? 
    properties.each_with_index do |prop,i|
      self.class.send(:attr_reader, prop)
      self.class.send(:define_method, "#{prop}=") do |val|
        send(:instance_variable_set, "@#{prop.to_s}", val)
        send(props[i][:name])[props[i][:index]] = val
        update
        return self
      end
      instance_variable_set("@#{prop}", send(props[i][:name])[props[i][:index]])
    end
  end
end