micromidi 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/TODO +0 -3
- data/lib/micromidi/context.rb +6 -1
- data/lib/micromidi/instructions/composite.rb +24 -7
- data/lib/micromidi.rb +3 -3
- data/test/test_composite.rb +44 -0
- data/test/test_context.rb +22 -1
- metadata +8 -8
data/README.rdoc
CHANGED
data/TODO
CHANGED
data/lib/micromidi/context.rb
CHANGED
@@ -25,7 +25,12 @@ module MicroMIDI
|
|
25
25
|
:sysex => Instructions::SysEx.new(@state)
|
26
26
|
}
|
27
27
|
|
28
|
-
|
28
|
+
edit(&block) unless block.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
# open a block for editing/live coding in this Context
|
32
|
+
def edit(&block)
|
33
|
+
self.instance_eval(&block)
|
29
34
|
end
|
30
35
|
|
31
36
|
def repeat
|
@@ -6,15 +6,32 @@ module MicroMIDI
|
|
6
6
|
|
7
7
|
module Composite
|
8
8
|
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
#
|
10
|
+
# plays a note or notes, for a certain duration.
|
11
|
+
#
|
12
|
+
# the first argument must be a note name (String), MIDIMessage::NoteOn object, or array of either
|
13
|
+
# the last argument must be a Numeric (representing the duration)
|
14
|
+
#
|
15
|
+
# additional arguments should be note names or MIDIMessage::NoteOn objects and will
|
16
|
+
# be played as a chord with the first argument
|
17
|
+
#
|
18
|
+
def play(*args)
|
19
|
+
raise "last argument must be a Numeric duration" unless args.last.kind_of?(Numeric)
|
20
|
+
|
21
|
+
duration = args.pop
|
22
|
+
note_or_notes = [args].flatten
|
23
|
+
|
24
|
+
msgs = note_or_notes.map do |n|
|
25
|
+
case n
|
26
|
+
when Numeric, String then note(n)
|
27
|
+
when MIDIMessage then n
|
28
|
+
end
|
14
29
|
end
|
30
|
+
|
15
31
|
sleep(duration)
|
16
|
-
|
17
|
-
|
32
|
+
msgs.each { |msg| note_off(msg.note, :channel => msg.channel, :velocity => msg.velocity) }
|
33
|
+
|
34
|
+
msgs.size > 1 ? msgs : msgs.first
|
18
35
|
end
|
19
36
|
|
20
37
|
# sends a note off message for every note on every channel
|
data/lib/micromidi.rb
CHANGED
@@ -16,7 +16,7 @@ require "unimidi"
|
|
16
16
|
|
17
17
|
module MicroMIDI
|
18
18
|
|
19
|
-
VERSION = "0.0.
|
19
|
+
VERSION = "0.0.9"
|
20
20
|
|
21
21
|
module Instructions
|
22
22
|
end
|
@@ -35,8 +35,8 @@ module MicroMIDI
|
|
35
35
|
|
36
36
|
module IO
|
37
37
|
|
38
|
-
def self.new(*args)
|
39
|
-
MicroMIDI.message(*args)
|
38
|
+
def self.new(*args, &block)
|
39
|
+
MicroMIDI.message(*args, &block)
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
data/test/test_composite.rb
CHANGED
@@ -28,6 +28,50 @@ class CompositeTest < Test::Unit::TestCase
|
|
28
28
|
assert_equal(0, off_msg.channel)
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_play_chord
|
32
|
+
m = MicroMIDI.message
|
33
|
+
start = Time.now
|
34
|
+
msgs = m.play "C0", "E1", "G2", 0.5
|
35
|
+
|
36
|
+
finish = Time.now
|
37
|
+
dif = finish - start
|
38
|
+
assert_equal(true, dif >= 0.5)
|
39
|
+
|
40
|
+
msg = msgs.first
|
41
|
+
|
42
|
+
assert_equal(NoteOn, msg.class)
|
43
|
+
assert_equal(12, msg.note)
|
44
|
+
assert_equal(0, msg.channel)
|
45
|
+
assert_equal(6, m.state.output_cache.size)
|
46
|
+
|
47
|
+
off_msg = m.state.output_cache.last[:message]
|
48
|
+
assert_equal(NoteOff, off_msg.class)
|
49
|
+
assert_equal(43, off_msg.note)
|
50
|
+
assert_equal(0, off_msg.channel)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_play_chord_array
|
54
|
+
m = MicroMIDI.message
|
55
|
+
start = Time.now
|
56
|
+
msgs = m.play ["C0", "E1", "G2"], 0.5
|
57
|
+
|
58
|
+
finish = Time.now
|
59
|
+
dif = finish - start
|
60
|
+
assert_equal(true, dif >= 0.5)
|
61
|
+
|
62
|
+
msg = msgs.first
|
63
|
+
|
64
|
+
assert_equal(NoteOn, msg.class)
|
65
|
+
assert_equal(12, msg.note)
|
66
|
+
assert_equal(0, msg.channel)
|
67
|
+
assert_equal(6, m.state.output_cache.size)
|
68
|
+
|
69
|
+
off_msg = m.state.output_cache.last[:message]
|
70
|
+
assert_equal(NoteOff, off_msg.class)
|
71
|
+
assert_equal(43, off_msg.note)
|
72
|
+
assert_equal(0, off_msg.channel)
|
73
|
+
end
|
74
|
+
|
31
75
|
def test_all_off
|
32
76
|
|
33
77
|
end
|
data/test/test_context.rb
CHANGED
@@ -8,13 +8,34 @@ class ContextTest < Test::Unit::TestCase
|
|
8
8
|
include MIDIMessage
|
9
9
|
include TestHelper
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_new_with_block
|
12
|
+
msg = nil
|
13
|
+
MIDI::IO.new do
|
14
|
+
msg = note "C0"
|
15
|
+
end
|
16
|
+
assert_equal(NoteOn, msg.class)
|
17
|
+
assert_equal(12, msg.note)
|
18
|
+
assert_equal(0, msg.channel)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_new_with_no_block
|
12
22
|
m = MIDI::IO.new
|
13
23
|
msg = m.note "C0"
|
14
24
|
assert_equal(NoteOn, msg.class)
|
15
25
|
assert_equal(12, msg.note)
|
16
26
|
assert_equal(0, msg.channel)
|
17
27
|
end
|
28
|
+
|
29
|
+
def test_edit
|
30
|
+
msg = nil
|
31
|
+
m = MIDI::IO.new
|
32
|
+
m.edit do
|
33
|
+
msg = m.note "C0"
|
34
|
+
end
|
35
|
+
assert_equal(NoteOn, msg.class)
|
36
|
+
assert_equal(12, msg.note)
|
37
|
+
assert_equal(0, msg.channel)
|
38
|
+
end
|
18
39
|
|
19
40
|
def test_repeat
|
20
41
|
m = MicroMIDI.message
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micromidi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: midi-eye
|
16
|
-
requirement: &
|
16
|
+
requirement: &70167309782300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.1.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70167309782300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: midi-message
|
27
|
-
requirement: &
|
27
|
+
requirement: &70167309781280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.2.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70167309781280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: unimidi
|
38
|
-
requirement: &
|
38
|
+
requirement: &70167309779980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.2.3
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70167309779980
|
47
47
|
description: A Ruby DSL for MIDI
|
48
48
|
email:
|
49
49
|
- ari.russo@gmail.com
|