Class: Shmidi::Event
- Inherits:
-
Object
- Object
- Shmidi::Event
- Defined in:
- lib/shmidi/clock.rb,
lib/shmidi/event.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#message_int ⇒ Object
readonly
Returns the value of attribute message_int.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#note_int ⇒ Object
readonly
Returns the value of attribute note_int.
-
#source ⇒ Object
readonly
TODO: eat symbols and strings as needed for shmidi piping.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .new_cc(channel, cc, value) ⇒ Object
- .new_off(channel, note, value = 0) ⇒ Object
- .new_on(channel, note, value = 127) ⇒ Object
Instance Method Summary collapse
-
#initialize(h) ⇒ Event
constructor
A new instance of Event.
- #octave ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(h) ⇒ Event
Returns a new instance of Event.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shmidi/event.rb', line 24 def initialize(h) @source = h[:source] @timestamp = (h[:timestamp] || 0).floor @data = h[:data].clone if h[:data] if @data @channel = (@data[0] & 0x0f) + 1 @message_int= @data[0] >> 4 @message = @message_int @message = MESSAGES[@message_int] || @message_int @note_int = @data[1] @note = @note_int parse_note_int if [:on, :off].include?(@message) @value = @data[2] else # no numeric data array @message_int = h[:message_int] || MESSAGES[h[:message]] || h[:message] @message = MESSAGES[@message_int] @value = h[:value] || 0 @channel = h[:channel] || 1 @note = h[:note] @note_int = h[:note] if h[:note].kind_of?(Numeric) && [:on, :off].include?(@message) parse_note_int elsif h[:note].kind_of?(String) @note = h[:note] #@note += h[:note][1] if h[:note][1] == '#' h[:note] =~ /^(.#?)(-?\d+)$/ @note_int = ($2.to_i + 1) * 12 + 'C C#D D#E F F#G G#A A#B '.index($1) / 2 end @data = [0,0,0] @data[1] = @note_int @data[2] = @value @data[0] = (@message_int << 4) + (@channel - 1) end end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
7 8 9 |
# File 'lib/shmidi/event.rb', line 7 def channel @channel end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/shmidi/event.rb', line 6 def data @data end |
#destination ⇒ Object
Returns the value of attribute destination.
4 5 6 |
# File 'lib/shmidi/clock.rb', line 4 def destination @destination end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/shmidi/event.rb', line 8 def @message end |
#message_int ⇒ Object (readonly)
Returns the value of attribute message_int.
7 8 9 |
# File 'lib/shmidi/event.rb', line 7 def @message_int end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
8 9 10 |
# File 'lib/shmidi/event.rb', line 8 def note @note end |
#note_int ⇒ Object (readonly)
Returns the value of attribute note_int.
7 8 9 |
# File 'lib/shmidi/event.rb', line 7 def note_int @note_int end |
#source ⇒ Object (readonly)
TODO: eat symbols and strings as needed for shmidi piping
5 6 7 |
# File 'lib/shmidi/event.rb', line 5 def source @source end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/shmidi/event.rb', line 6 def @timestamp end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/shmidi/event.rb', line 7 def value @value end |
Class Method Details
.new_cc(channel, cc, value) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/shmidi/event.rb', line 75 def self.new_cc(channel, cc, value) Event.new( :channel => channel, :message => :cc, :note => cc, :value => value) end |
Instance Method Details
#octave ⇒ Object
19 20 21 22 |
# File 'lib/shmidi/event.rb', line 19 def octave return nil unless @note.kind_of?(String) (@note_int / 12) - 1 end |
#to_hash ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/shmidi/event.rb', line 87 def to_hash hash = {} instance_variables.each do |var| hash[var[1..-1].to_sym] = instance_variable_get(var) end hash end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/shmidi/event.rb', line 83 def to_s "CH:#{@channel}\t#{@message}\t#{@note}\t=#{@value}" end |