midi-message 0.4.3 → 0.4.4

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: 9796cb4569f21bfb836502370ca6329634b35900
4
- data.tar.gz: 8fa9fd01613d569ebb0cb9aec601ebd14faec95f
3
+ metadata.gz: e474d330bc417e19471d1dbd4c931748445db639
4
+ data.tar.gz: 8516f6b1ee25c485bfbb7265d2e4e5620f7800ed
5
5
  SHA512:
6
- metadata.gz: f714e1746e5fbd490f25b2ce0c582714a7e6c11edc0b0bf99a5d200796be8ba60f294aa77162425f3fe5b74f0b69231fbef0e0150565d0a72d40b55294b418ea
7
- data.tar.gz: 21f9e7978fa17ab50f6c5fd8492bf92d1637986f7ba3a7e463a8b1e7a170ef0e1593285c3920b386d5002656045876ec70bb5b135a85640e0a77d7a1ece0a697
6
+ metadata.gz: 28b952c964be9603b65def9802d72fdf7a6c9d5b8641b537601b4b91be8c5889a7aec75cc3d396cecb25d98f62dfcbf1544d657f4a24efa61d012778bb96d46e
7
+ data.tar.gz: 61d515a21f72a2d7fd340d82067fe5401bb1ad142e940b94c6fa9e1fc9114b8bc43e0331558243812cf8334135f2676fa06a962217cb44a1927af911d7a55cde
data/README.md CHANGED
@@ -22,8 +22,6 @@ Or if you're using Bundler, add this to your Gemfile
22
22
 
23
23
  ```ruby
24
24
  require "midi-message"
25
-
26
- include MIDIMessage
27
25
  ```
28
26
 
29
27
  #### Basic Messages
@@ -31,11 +29,11 @@ include MIDIMessage
31
29
  There are a few ways to create a new MIDI message. Here are some examples
32
30
 
33
31
  ```ruby
34
- NoteOn.new(0, 64, 64)
32
+ MIDIMessage::NoteOn.new(0, 64, 64)
35
33
 
36
- NoteOn["E4"].new(0, 100)
34
+ MIDIMessage::NoteOn["E4"].new(0, 100)
37
35
 
38
- with(:channel => 0, :velocity => 100) { note_on("E4") }
36
+ MIDIMessage.with(:channel => 0, :velocity => 100) { note_on("E4") }
39
37
  ```
40
38
 
41
39
  Those expressions all evaluate to the same object
@@ -56,7 +54,7 @@ Those expressions all evaluate to the same object
56
54
  As with any kind of message, you can begin with raw data
57
55
 
58
56
  ```ruby
59
- SystemExclusive.new(0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7)
57
+ MIDIMessage::SystemExclusive.new(0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7)
60
58
  ```
61
59
 
62
60
  Or in a more object oriented way
@@ -1,19 +1,27 @@
1
1
  module MIDIMessage
2
2
 
3
+ # A DSL for instantiating message objects
3
4
  class Context
4
-
5
- attr_accessor :channel,
6
- :velocity
7
-
5
+
6
+ attr_accessor :channel, :velocity
7
+
8
+ # @param [Hash] options
9
+ # @option options [Fixnum] :channel
10
+ # @option options [Fixnum] :velocity
8
11
  def initialize(options = {})
9
12
  @channel = options[:channel]
10
- @velocity = options[:velocity]
13
+ @velocity = options[:velocity]
11
14
  end
12
15
 
16
+ # A note off message
17
+ # @param [Fixnum, String] note
18
+ # @param [Hash] options
19
+ # @option options [Fixnum] :channel
20
+ # @option options [Fixnum] :velocity
13
21
  def note_off(note, options = {})
14
22
  channel = options[:channel] || @channel
15
23
  velocity = options[:velocity] || @velocity
16
- raise 'note_off requires both channel and velocity' if channel.nil? || velocity.nil?
24
+ raise "note_off requires both channel and velocity" if channel.nil? || velocity.nil?
17
25
  if note.kind_of?(String)
18
26
  NoteOff[note].new(channel, velocity, options)
19
27
  else
@@ -21,11 +29,16 @@ module MIDIMessage
21
29
  end
22
30
  end
23
31
  alias_method :NoteOff, :note_off
24
-
32
+
33
+ # A note on message
34
+ # @param [Fixnum, String] note
35
+ # @param [Hash] options
36
+ # @option options [Fixnum] :channel
37
+ # @option options [Fixnum] :velocity
25
38
  def note_on(note, options = {})
26
39
  channel = options[:channel] || @channel
27
40
  velocity = options[:velocity] || @velocity
28
- raise 'note_on requires both channel and velocity' if channel.nil? || velocity.nil?
41
+ raise "note_on requires both channel and velocity" if channel.nil? || velocity.nil?
29
42
  if note.kind_of?(String)
30
43
  NoteOn[note].new(channel, velocity, options)
31
44
  else
@@ -33,68 +46,98 @@ module MIDIMessage
33
46
  end
34
47
  end
35
48
  alias_method :NoteOn, :note_on
36
-
49
+
50
+ # A program change message
51
+ # @param [Fixnum, String] program
52
+ # @param [Hash] options
53
+ # @option options [Fixnum] :channel
37
54
  def program_change(program, options = {})
38
55
  channel = options[:channel] || @channel
39
- raise 'program_change requires channel' if channel.nil?
56
+ raise "program_change requires channel" if channel.nil?
40
57
  if program.kind_of?(String)
41
58
  ProgramChange[program].new(channel, options)
42
59
  else
43
60
  ProgramChange.new(channel, program, options)
44
- end
61
+ end
45
62
  end
46
63
  alias_method :ProgramChange, :program_change
47
-
64
+
65
+ # A control change message
66
+ # @param [Fixnum, String] index
67
+ # @param [Fixnum] value
68
+ # @param [Hash] options
69
+ # @option options [Fixnum] :channel
70
+ # @option options [Fixnum] :velocity
48
71
  def control_change(index, value, options = {})
49
72
  channel = options[:channel] || @channel
50
- raise 'control_change requires channel' if channel.nil?
73
+ raise "control_change requires channel" if channel.nil?
51
74
  if index.kind_of?(String)
52
75
  ControlChange[index].new(channel, value, options)
53
76
  else
54
77
  ControlChange.new(channel, index, value, options)
55
- end
78
+ end
56
79
  end
57
80
  alias_method :ControlChange, :control_change
58
81
  alias_method :Controller, :control_change
59
82
  alias_method :controller, :control_change
60
-
83
+
84
+ # A poly pressure message
85
+ # @param [Fixnum, String] note
86
+ # @param [Fixnum] value
87
+ # @param [Hash] options
88
+ # @option options [Fixnum] :channel
61
89
  def polyphonic_aftertouch(note, value, options = {})
62
90
  channel = options[:channel] || @channel
63
- raise 'channel_aftertouch requires a channel' if channel.nil?
91
+ raise "channel_aftertouch requires a channel" if channel.nil?
64
92
  if note.kind_of?(String)
65
93
  PolyphonicAftertouch[note].new(channel, value, options)
66
94
  else
67
95
  PolyphonicAftertouch.new(channel, note, value, options)
68
- end
96
+ end
69
97
  end
70
98
  alias_method :PolyphonicAftertouch, :polyphonic_aftertouch
71
- alias_method :PolyAftertouch, :polyphonic_aftertouch
99
+ alias_method :PolyAftertouch, :polyphonic_aftertouch
72
100
  alias_method :PolyphonicPressure, :polyphonic_aftertouch
73
- alias_method :PolyPressure, :polyphonic_aftertouch
101
+ alias_method :PolyPressure, :polyphonic_aftertouch
74
102
  alias_method :poly_aftertouch, :polyphonic_aftertouch
75
103
  alias_method :poly_pressure, :polyphonic_aftertouch
76
-
104
+
105
+ # A channel pressure message
106
+ # @param [Fixnum] value
107
+ # @param [Hash] options
108
+ # @option options [Fixnum] :channel
77
109
  def channel_aftertouch(value, options = {})
78
110
  channel = options[:channel] || @channel
79
- raise 'channel_aftertouch requires a channel' if channel.nil?
80
- ChannelAftertouch.new(channel, value, options)
111
+ raise "channel_aftertouch requires a channel" if channel.nil?
112
+ ChannelAftertouch.new(channel, value, options)
81
113
  end
82
114
  alias_method :ChannelAftertouch, :channel_aftertouch
83
- alias_method :ChannelPressure, :channel_aftertouch
115
+ alias_method :ChannelPressure, :channel_aftertouch
84
116
  alias_method :channel_pressure, :channel_aftertouch
85
-
117
+
118
+ # A poly pressure message
119
+ # @param [Fixnum] low
120
+ # @param [Fixnum] high
121
+ # @param [Hash] options
122
+ # @option options [Fixnum] :channel
86
123
  def pitch_bend(low, high, options = {})
87
124
  channel = options[:channel] || @channel
88
- raise 'channel_aftertouch requires a channel' if channel.nil?
89
- PitchBend.new(channel, low, high, options)
125
+ raise "channel_aftertouch requires a channel" if channel.nil?
126
+ PitchBend.new(channel, low, high, options)
90
127
  end
91
128
  alias_method :PitchBend, :pitch_bend
92
-
129
+
93
130
  end
94
-
95
- def with_context(options = {}, &block)
131
+
132
+ # @param [Hash] options
133
+ # @param [Proc] block
134
+ # @option options [Fixnum] :channel
135
+ # @option options [Fixnum] :velocity
136
+ def self.with_context(options = {}, &block)
96
137
  Context.new(options, &block).instance_eval(&block)
97
138
  end
98
- alias_method :with, :with_context
139
+ class << self
140
+ alias_method :with, :with_context
141
+ end
99
142
 
100
143
  end
data/lib/midi-message.rb CHANGED
@@ -4,11 +4,6 @@
4
4
  # (c)2011-2014 Ari Russo
5
5
  # Apache 2.0 License
6
6
  #
7
- module MIDIMessage
8
-
9
- VERSION = "0.4.3"
10
-
11
- end
12
7
 
13
8
  # Libs
14
9
  require "forwardable"
@@ -27,3 +22,9 @@ require "midi-message/constant"
27
22
  require "midi-message/context"
28
23
  require "midi-message/message"
29
24
  require "midi-message/parser"
25
+
26
+ module MIDIMessage
27
+
28
+ VERSION = "0.4.4"
29
+
30
+ end
data/test/context_test.rb CHANGED
@@ -4,10 +4,10 @@ require 'helper'
4
4
 
5
5
  class ContextTest < Test::Unit::TestCase
6
6
 
7
- include MIDIMessage
8
7
  include TestHelper
8
+
9
9
  def test_note_off
10
- msg = with(:channel => 0, :velocity => 64) do
10
+ msg = MIDIMessage.with(:channel => 0, :velocity => 64) do
11
11
  note_off(55)
12
12
  end
13
13
  assert_equal(0, msg.channel)
@@ -18,7 +18,7 @@ class ContextTest < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  def test_note_on
21
- msg = with(:channel => 0, :velocity => 64) do
21
+ msg = MIDIMessage.with(:channel => 0, :velocity => 64) do
22
22
  note_on(55)
23
23
  end
24
24
  assert_equal(0, msg.channel)
@@ -29,7 +29,7 @@ class ContextTest < Test::Unit::TestCase
29
29
  end
30
30
 
31
31
  def test_control_change
32
- msg = with(:channel => 2) do
32
+ msg = MIDIMessage.with(:channel => 2) do
33
33
  control_change(0x20, 0x30)
34
34
  end
35
35
  assert_equal(msg.channel, 2)
@@ -41,7 +41,7 @@ class ContextTest < Test::Unit::TestCase
41
41
  end
42
42
 
43
43
  def test_polyphonic_aftertouch
44
- msg = with(:channel => 1) do
44
+ msg = MIDIMessage.with(:channel => 1) do
45
45
  polyphonic_aftertouch(0x40, 0x40)
46
46
  end
47
47
  assert_equal(1, msg.channel)
@@ -52,7 +52,7 @@ class ContextTest < Test::Unit::TestCase
52
52
  end
53
53
 
54
54
  def test_program_change
55
- msg = with(:channel => 3) do
55
+ msg = MIDIMessage.with(:channel => 3) do
56
56
  program_change(0x40)
57
57
  end
58
58
  assert_equal(3, msg.channel)
@@ -63,7 +63,7 @@ class ContextTest < Test::Unit::TestCase
63
63
  end
64
64
 
65
65
  def test_channel_aftertouch
66
- msg = with(:channel => 3) do
66
+ msg = MIDIMessage.with(:channel => 3) do
67
67
  channel_aftertouch(0x50)
68
68
  end
69
69
  assert_equal(3, msg.channel)
@@ -73,7 +73,7 @@ class ContextTest < Test::Unit::TestCase
73
73
  end
74
74
 
75
75
  def test_pitch_bend
76
- msg = with(:channel => 0) do
76
+ msg = MIDIMessage.with(:channel => 0) do
77
77
  pitch_bend(0x50, 0xA0)
78
78
  end
79
79
  assert_equal(0, msg.channel)
@@ -83,4 +83,4 @@ class ContextTest < Test::Unit::TestCase
83
83
  assert_equal("E050A0", msg.to_bytestr)
84
84
  end
85
85
 
86
- end
86
+ end
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.3
4
+ version: 0.4.4
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-10-26 00:00:00.000000000 Z
11
+ date: 2014-10-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Objects and classes for dealing with MIDI messages.
14
14
  email: