micromidi 0.1.4 → 0.1.5

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: d899af108dba8fc0eb7b830cdc53ecf65f8a9946
4
- data.tar.gz: 947eb84dfbba8084a55359b460effd7da0bfa881
3
+ metadata.gz: 34add3c5d0d82e3fe9ac1ea773a574d8f29b43ca
4
+ data.tar.gz: 77bb91ec4695c2aeea7cfa4b589d1cdef3864d6a
5
5
  SHA512:
6
- metadata.gz: 738e6469b03feff4fdf5f64027ca32f2d6341c18f0f2767b0dcc810b265c16cf4290fc13ac862ec0eeedc339ef43d6379ba590c93612fccce2d68e15450a697e
7
- data.tar.gz: c9b87df40f972394d975d23d3ba35de7b8bf145efce20857504f069d02857e4c53401ce9358a7e88d1b401c09d1d536734a7f5efc84360db143ad0c4430586a4
6
+ metadata.gz: 330ba95c70c88f7a493a2df2a9ac06877aebb500173dc19761c2aa07fc82f356566f5098b28fd2672bb82e0a31161e0bace2df950b9b97483c2c74996461fe60
7
+ data.tar.gz: b4ec59d0664aa536713fedfa736edcda4536ff54ac73b5224ad6f1d44b6caa6bcf75eab420adf9f73029887514fdec4d75a113a3bd4c9980a9c46b02beca94b4
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2011-2014 Ari Russo
1
+ Copyright 2011-2015 Ari Russo
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -5,7 +5,7 @@ A Ruby DSL for MIDI
5
5
  ![micromidi](http://img855.imageshack.us/img855/9804/midi.png)
6
6
 
7
7
  ## Features
8
-
8
+
9
9
  * Cross-platform compatible using MRI or JRuby.
10
10
  * Simplified MIDI and Sysex message output
11
11
  * MIDI Thru, processing and custom input events
@@ -30,17 +30,17 @@ require "midi"
30
30
 
31
31
  @input = UniMIDI::Input.gets
32
32
  @output = UniMIDI::Output.gets
33
-
33
+
34
34
  MIDI.using(@output) do
35
-
35
+
36
36
  5.times do |oct|
37
37
  octave oct
38
- %w{C E G B}.each { |n| play n 0.5 }
38
+ %w{C E G B}.each { |n| play n, 0.5 }
39
39
  end
40
40
 
41
41
  end
42
42
  ```
43
-
43
+
44
44
  This next example filters outs notes if their octave is between 1 and 3. All other messages are sent thru.
45
45
 
46
46
  Output is also printed to the console by passing `$stdout` as though it's a MIDI device
@@ -66,26 +66,26 @@ M(@input, @output) do
66
66
 
67
67
  end
68
68
  ```
69
-
69
+
70
70
  Finally, here is an example that maps some MIDI Control Change messages to SysEx
71
-
71
+
72
72
  ```ruby
73
73
  MIDI.using(@input, @output) do
74
-
74
+
75
75
  *@the_map =
76
76
  [0x40, 0x7F, 0x00],
77
77
  [0x41, 0x7F, 0x00],
78
78
  [0x42, 0x7F, 0x00]
79
-
79
+
80
80
  node :roland, :model_id => 0x42, :device_id => 0x10
81
-
81
+
82
82
  receive :cc do |message|
83
-
83
+
84
84
  command @the_map[message.index - 1], message.value
85
-
85
+
86
86
  end
87
-
88
- end
87
+
88
+ end
89
89
  ```
90
90
 
91
91
  Here are a few posts explaining each of the concepts used here in greater detail:
@@ -96,7 +96,7 @@ Here are a few posts explaining each of the concepts used here in greater detail
96
96
  * [Shorthand](http://tx81z.blogspot.com/2011/08/micromidi-shorthand.html)
97
97
  * [Sysex](http://tx81z.blogspot.com/2011/09/generating-sysex-messages-with.html)
98
98
  * [Etc](http://tx81z.blogspot.com/2011/09/more-micromidi-tricks.html)
99
-
99
+
100
100
  ## Documentation
101
101
 
102
102
  * [rdoc](http://rubydoc.info/github/arirusso/micromidi)
@@ -109,4 +109,4 @@ Here are a few posts explaining each of the concepts used here in greater detail
109
109
 
110
110
  Apache 2.0, See the file LICENSE
111
111
 
112
- Copyright (c) 2011-2014 Ari Russo
112
+ Copyright (c) 2011-2015 Ari Russo
data/lib/micromidi.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  #
2
2
  # MicroMIDI
3
- #
4
3
  # A Ruby DSL for MIDI
5
4
  #
6
- # (c)2011-2014 Ari Russo
5
+ # (c)2011-2015 Ari Russo
7
6
  # Apache 2.0 License
8
7
  #
9
8
 
@@ -34,7 +33,14 @@ require "micromidi/instructions/shorthand"
34
33
 
35
34
  module MicroMIDI
36
35
 
37
- VERSION = "0.1.4"
36
+ VERSION = "0.1.5"
38
37
 
39
38
  end
39
+
40
40
  MIDI = MicroMIDI
41
+
42
+ # Shortcuts to UniMIDI modules
43
+ module MIDI
44
+ Input = UniMIDI::Input
45
+ Output = UniMIDI::Output
46
+ end
@@ -19,12 +19,12 @@ module MicroMIDI
19
19
 
20
20
  @instructions = {
21
21
  :process => Instructions::Process.new(@state),
22
- :input => Instructions::Input.new(@state),
23
22
  :message => Instructions::Message.new(@state),
24
23
  :output => Instructions::Output.new(@state),
25
24
  :sticky => Instructions::Sticky.new(@state),
26
25
  :sysex => Instructions::SysEx.new(@state)
27
26
  }
27
+ @instructions[:input] = Instructions::Input.new(@state) { |message| @instructions[:output].output(message) }
28
28
 
29
29
  edit(&block) if block_given?
30
30
  end
@@ -6,8 +6,10 @@ module MicroMIDI
6
6
  class Input
7
7
 
8
8
  # @param [State] state
9
- def initialize(state)
9
+ # @param [Proc] thru_action Output module to send thru messages to
10
+ def initialize(state, &thru_action)
10
11
  @state = state
12
+ @thru_action = thru_action
11
13
  end
12
14
 
13
15
  # Bind an event that will be fired when a message is received
@@ -58,7 +60,7 @@ module MicroMIDI
58
60
  # @return [Boolean]
59
61
  def thru_if(*args)
60
62
  receive_options = thru_arguments(args)
61
- receive(*receive_options) { |message, timestamp| output(message) }
63
+ receive(*receive_options) { |message, timestamp| @thru_action.call(message) }
62
64
  true
63
65
  end
64
66
 
@@ -67,7 +69,7 @@ module MicroMIDI
67
69
  # @return [Boolean]
68
70
  def thru_unless(*args)
69
71
  receive_options = thru_arguments(args)
70
- receive_unless(*receive_options) { |message, timestamp| output(message) }
72
+ receive_unless(*receive_options) { |message, timestamp| @thru_action.call(message) }
71
73
  end
72
74
 
73
75
  # Similar to Input#thru_unless except a callback can be passed that will be fired when notes specified arrive
@@ -14,6 +14,7 @@ module MicroMIDI
14
14
  module Instructions
15
15
 
16
16
  module Composite
17
+ alias_method :console, :p # move Kernel#p
17
18
  alias_method :p, :play
18
19
  alias_method :q!, :all_off
19
20
  alias_method :x, :all_off
data/test/context_test.rb CHANGED
@@ -20,6 +20,16 @@ class ContextTest < Minitest::Test
20
20
  assert_equal(0, msg.channel)
21
21
  end
22
22
 
23
+ def test_exception
24
+ msg = nil
25
+ m = MIDI::IO.new
26
+ assert_raises(ArgumentError) do
27
+ m.edit do
28
+ msg = m.note
29
+ end
30
+ end
31
+ end
32
+
23
33
  def test_edit
24
34
  msg = nil
25
35
  m = MIDI::IO.new
data/test/helper.rb CHANGED
@@ -2,6 +2,7 @@ dir = File.dirname(File.expand_path(__FILE__))
2
2
  $LOAD_PATH.unshift dir + "/../lib"
3
3
 
4
4
  require "minitest/autorun"
5
+ require "shoulda-context"
5
6
  require "midi"
6
7
 
7
8
  module TestHelper
@@ -0,0 +1,19 @@
1
+ require "helper"
2
+
3
+ class ModuleTest < Minitest::Test
4
+
5
+ context "MIDI" do
6
+
7
+ should "have MIDI module" do
8
+ refute_nil MIDI
9
+ assert_equal MicroMIDI, MIDI
10
+ end
11
+
12
+ should "add UniMIDI modules" do
13
+ assert_equal UniMIDI::Input, MIDI::Input
14
+ assert_equal UniMIDI::Output, MIDI::Output
15
+ end
16
+
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micromidi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-03 00:00:00.000000000 Z
11
+ date: 2015-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -199,6 +199,7 @@ files:
199
199
  - test/helper.rb
200
200
  - test/input_test.rb
201
201
  - test/message_test.rb
202
+ - test/module_test.rb
202
203
  - test/output_test.rb
203
204
  - test/state_test.rb
204
205
  - test/sticky_test.rb