midi-message 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 539a68753cc6d0c17fed06cae7103d1f7b0f95a8
4
- data.tar.gz: 2b3949261e5e5fa7061cb7860c325d6a0c067efb
3
+ metadata.gz: 9796cb4569f21bfb836502370ca6329634b35900
4
+ data.tar.gz: 8fa9fd01613d569ebb0cb9aec601ebd14faec95f
5
5
  SHA512:
6
- metadata.gz: edc31730d5ffc918377fb342f63c3ce095b187e8f17ed194a47756a701286f3a78b7d7102f05850a2eeca59108d90ec3ed1a9cb5e0e78294cea699c6ede821b6
7
- data.tar.gz: 86c8b7a355baa3a46d93ca63294a512538dc8478fbea9844be00c917916fe1d13fde7bd19eb599a2cf61fefff021df45f853a43622d6bb8380322f03136e6e30
6
+ metadata.gz: f714e1746e5fbd490f25b2ce0c582714a7e6c11edc0b0bf99a5d200796be8ba60f294aa77162425f3fe5b74f0b69231fbef0e0150565d0a72d40b55294b418ea
7
+ data.tar.gz: 21f9e7978fa17ab50f6c5fd8492bf92d1637986f7ba3a7e463a8b1e7a170ef0e1593285c3920b386d5002656045876ec70bb5b135a85640e0a77d7a1ece0a697
data/lib/midi-message.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  #
2
2
  # Ruby MIDI message objects
3
3
  #
4
- # (c)2011-2014 Ari Russo and licensed under the Apache 2.0 License
5
- #
4
+ # (c)2011-2014 Ari Russo
5
+ # Apache 2.0 License
6
+ #
6
7
  module MIDIMessage
7
-
8
- VERSION = "0.4.2"
9
-
8
+
9
+ VERSION = "0.4.3"
10
+
10
11
  end
11
12
 
12
13
  # Libs
@@ -26,4 +27,3 @@ require "midi-message/constant"
26
27
  require "midi-message/context"
27
28
  require "midi-message/message"
28
29
  require "midi-message/parser"
29
-
@@ -3,6 +3,7 @@ module MIDIMessage
3
3
  # Common behavior amongst Channel Message types
4
4
  module ChannelMessage
5
5
 
6
+ include MIDIMessage # this enables ..kind_of?(MIDIMessage)
6
7
  attr_reader :data, :name
7
8
 
8
9
  # Shortcut to RawChannelMessage.new
@@ -17,7 +18,7 @@ module MIDIMessage
17
18
  # @param [*Array<Fixnum>] data The status nibbles and data bytes
18
19
  def initialize(*data)
19
20
  data = data.dup
20
- options = data.last.kind_of?(Hash) ? data.pop : {}
21
+ options = data.last.kind_of?(Hash) ? data.pop : {}
21
22
  processed_data = options[:const].nil? ? data : data_with_const(data, options[:const])
22
23
  initialize_channel_message(self.class.type_for_status, *processed_data)
23
24
  end
@@ -29,7 +30,7 @@ module MIDIMessage
29
30
  { :name => :data, :index => 1 }
30
31
  ]
31
32
  properties = self.class.properties
32
- unless properties.nil?
33
+ unless properties.nil?
33
34
  properties.each_with_index do |prop,i|
34
35
  self.class.send(:attr_reader, prop)
35
36
  self.class.send(:define_method, "#{prop}=") do |val|
@@ -55,7 +56,7 @@ module MIDIMessage
55
56
  def data_with_const(data, const)
56
57
  key = self.class.constant_property
57
58
  ind = self.class.properties.index(key) || 0
58
- data.insert(ind, const.value)
59
+ data.insert(ind, const.value)
59
60
  end
60
61
 
61
62
  def initialize_channel_message(status_nibble_1, status_nibble_2, data_byte_1, data_byte_2 = 0)
@@ -72,7 +73,7 @@ module MIDIMessage
72
73
  # Get the status nibble for this particular message type
73
74
  # @return [Fixnum] The status nibble
74
75
  def type_for_status
75
- Status[display_name]
76
+ Status[display_name]
76
77
  end
77
78
 
78
79
  def properties
@@ -104,7 +105,7 @@ module MIDIMessage
104
105
  # @return [RawChannelMessage] The resulting RawChannelMessage object
105
106
  def initialize(*data)
106
107
  initialize_channel_message(*data)
107
- end
108
+ end
108
109
 
109
110
  # Convert this RawChannelMessage to one of the more specific ChannelMessage types
110
111
  # eg. RawChannelMessage.new(0x9, 0x0, 0x40, 0x40).to_type would result in
@@ -13,7 +13,7 @@ module MIDIMessage
13
13
  (note / 12) - 1
14
14
  end
15
15
  alias_method :oct, :octave
16
-
16
+
17
17
  # Set the octave number of the note
18
18
  # @param [Fixnum] value
19
19
  # @return [NoteMessage] self
@@ -22,19 +22,19 @@ module MIDIMessage
22
22
  self
23
23
  end
24
24
  alias_method :oct=, :octave=
25
-
25
+
26
26
  # How many half-steps is this note above the closest C
27
27
  # @return [Fixnum]
28
28
  def abs_note
29
29
  note - ((note / 12) * 12)
30
30
  end
31
-
31
+
32
32
  # The name of the note without its octave e.g. F#
33
33
  # @return [String]
34
34
  def note_name
35
35
  name.split(/-?\d\z/).first
36
36
  end
37
-
37
+
38
38
  end
39
-
39
+
40
40
  end
@@ -3,10 +3,12 @@ module MIDIMessage
3
3
  # Common behavior amongst all Message types
4
4
  module ShortMessage
5
5
 
6
+ include MIDIMessage # this enables ..kind_of?(MIDIMessage)
7
+
6
8
  attr_reader :name,
7
9
  :status,
8
10
  :verbose_name
9
-
11
+
10
12
  # Initialize the message status
11
13
  # @param [Fixnum] status_nibble_1 The first nibble of the status
12
14
  # @param [Fixnum] status_nibble_2 The second nibble of the status
@@ -14,11 +16,11 @@ module MIDIMessage
14
16
  @status = [status_nibble_1, status_nibble_2]
15
17
  populate_using_const
16
18
  end
17
-
19
+
18
20
  # Byte array representation of the message eg [0x90, 0x40, 0x40] for NoteOn(0x40, 0x40)
19
21
  # @return [Array<Fixnum>] The array of bytes in the MIDI message
20
22
  def to_a
21
- data = @data.nil? ? [] : [@data[0], @data[1]]
23
+ data = @data.nil? ? [] : [@data[0], @data[1]]
22
24
  [(@status[0] << 4) + @status[1], *data].compact
23
25
  end
24
26
  alias_method :to_byte_a, :to_a
@@ -31,19 +33,19 @@ module MIDIMessage
31
33
  TypeConversion.numeric_byte_array_to_hex_string(to_a)
32
34
  end
33
35
  alias_method :to_bytestr, :to_hex_s
34
-
36
+
35
37
  protected
36
-
38
+
37
39
  def self.included(base)
38
40
  base.send(:extend, ClassMethods)
39
41
  end
40
-
42
+
41
43
  def update
42
44
  populate_using_const
43
45
  end
44
-
46
+
45
47
  private
46
-
48
+
47
49
  # This will populate message metadata with information gathered from midi.yml
48
50
  def populate_using_const
49
51
  const_group_name = self.class.display_name
@@ -57,22 +59,22 @@ module MIDIMessage
57
59
  unless const.nil?
58
60
  @const = const
59
61
  @name = @const.nil? ? const.key : @const.key
60
- @verbose_name = "#{self.class.display_name}: #{@name}"
62
+ @verbose_name = "#{self.class.display_name}: #{@name}"
61
63
  end
62
- end
64
+ end
63
65
  end
64
66
 
65
67
  module ClassMethods
66
-
68
+
67
69
  # Find a constant value in this class's group for the passed in key
68
70
  # @param [String] name The constant key
69
71
  # @return [String] The constant value
70
- def get_constant(name)
72
+ def get_constant(name)
71
73
  key = constant_name || display_name
72
74
  unless key.nil?
73
75
  group = ConstantGroup[key]
74
76
  group.find(name)
75
- end
77
+ end
76
78
  end
77
79
 
78
80
  def display_name
@@ -98,7 +100,7 @@ module MIDIMessage
98
100
  const = get_constant(const_name.to_s)
99
101
  MessageBuilder.new(self, const) unless const.nil?
100
102
  end
101
-
103
+
102
104
  end
103
105
 
104
106
  end
@@ -107,29 +109,29 @@ module MIDIMessage
107
109
 
108
110
  # @param [MIDIMessage] klass The message class to build
109
111
  # @param [String] const The constant to build the message with
110
- def initialize(klass, const)
111
- @klass = klass
112
+ def initialize(klass, const)
113
+ @klass = klass
112
114
  @const = const
113
115
  end
114
116
 
115
- def new(*a)
116
- a.last.kind_of?(Hash) ? a.last[:const] = @const : a.push(:const => @const)
117
+ def new(*a)
118
+ a.last.kind_of?(Hash) ? a.last[:const] = @const : a.push(:const => @const)
117
119
  @klass.new(*a)
118
120
  end
119
121
 
120
122
  end
121
-
123
+
122
124
  # Shortcuts for dealing with message status
123
125
  module Status
124
-
126
+
125
127
  # The value of the Status constant with the name status_name
126
128
  # @param [String] status_name The key to use to look up a constant value
127
129
  # @return [String] The constant value that was looked up
128
130
  def self.[](status_name)
129
131
  const = Constant.find("Status", status_name)
130
132
  const.value unless const.nil?
131
- end
132
-
133
+ end
134
+
133
135
  end
134
136
 
135
137
  end
@@ -3,6 +3,8 @@ module MIDIMessage
3
3
  # MIDI System-Exclusive Messages (SysEx)
4
4
  module SystemExclusive
5
5
 
6
+ include MIDIMessage # this enables ..kind_of?(MIDIMessage)
7
+
6
8
  def self.included(base)
7
9
  base.send(:include, InstanceMethods)
8
10
  end
@@ -18,7 +20,7 @@ module MIDIMessage
18
20
 
19
21
  # an array of message parts. multiple byte parts will be represented as an array of bytes
20
22
  def to_a(options = {})
21
- omit = options[:omit] || []
23
+ omit = options[:omit] || []
22
24
  node = @node.to_a(options) unless @node.nil? || omit.include?(:node)
23
25
  # this may need to be cached when properties are updated
24
26
  # might be worth benchmarking
@@ -44,7 +46,7 @@ module MIDIMessage
44
46
 
45
47
  # string representation of the object's bytes
46
48
  def to_hex_s
47
- strings = to_bytes.map do |byte|
49
+ strings = to_bytes.map do |byte|
48
50
  string = byte.to_s(16)
49
51
  string = "0#{string}" if string.length == 1
50
52
  string
@@ -73,7 +75,7 @@ module MIDIMessage
73
75
  # alternate method from
74
76
  # http://www.2writers.com/eddie/TutSysEx.htm
75
77
  def checksum
76
- sum = (address + [value].flatten).inject(&:+)
78
+ sum = (address + [value].flatten).inject(&:+)
77
79
  mod = sum.divmod(128)[1]
78
80
  128 - mod
79
81
  end
@@ -107,7 +109,7 @@ module MIDIMessage
107
109
 
108
110
  # an array of message parts. multiple byte parts will be represented as an array of bytes
109
111
  def to_a(options = {})
110
- omit = options[:omit] || []
112
+ omit = options[:omit] || []
111
113
  node = @node.to_a(options) unless @node.nil? || omit.include?(:node)
112
114
  # this may need to be cached when properties are updated
113
115
  # might be worth benchmarking
@@ -122,7 +124,7 @@ module MIDIMessage
122
124
  end
123
125
 
124
126
  #
125
- # The SystemExclusive::Node represents a destination for a message. For example a hardware
127
+ # The SystemExclusive::Node represents a destination for a message. For example a hardware
126
128
  # synthesizer or sampler
127
129
  #
128
130
  class Node
@@ -196,7 +198,7 @@ module MIDIMessage
196
198
  msg_class = Request
197
199
  elsif type_byte == 0x12
198
200
  msg_class = Command
199
- else
201
+ else
200
202
  return Message.new(bytes)
201
203
  end
202
204
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midi-message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-27 00:00:00.000000000 Z
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Objects and classes for dealing with MIDI messages.
14
14
  email: