micromidi 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Ruby DSL for MIDI
4
4
 
5
- {pic}[http://images.treetrouble.net/images/midi.png]
5
+ {pic}[http://img855.imageshack.us/img855/9804/midi.png]
6
6
 
7
7
  == Features
8
8
 
data/TODO CHANGED
@@ -1,8 +1,5 @@
1
1
  Functionality
2
- * thru issues / strong thru
3
- * Sysex messages
4
2
  * MIDI files?
5
3
 
6
4
  Documentation
7
- * Guide for shorthand aliases
8
5
  * More rdoc
@@ -25,7 +25,12 @@ module MicroMIDI
25
25
  :sysex => Instructions::SysEx.new(@state)
26
26
  }
27
27
 
28
- instance_eval(&block) unless block.nil?
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
- # play note n, wait <em>duration</em> seconds, then do note off for note n
10
- def play(n, duration)
11
- msg = case n
12
- when Numeric, String then note(n)
13
- when MIDIMessage then n
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
- off
17
- msg
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.8"
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
@@ -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 test_no_block
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.8
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-09-18 00:00:00.000000000Z
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: &70309786484140 !ruby/object:Gem::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: *70309786484140
24
+ version_requirements: *70167309782300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: midi-message
27
- requirement: &70309786483360 !ruby/object:Gem::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: *70309786483360
35
+ version_requirements: *70167309781280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: unimidi
38
- requirement: &70309786482900 !ruby/object:Gem::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: *70309786482900
46
+ version_requirements: *70167309779980
47
47
  description: A Ruby DSL for MIDI
48
48
  email:
49
49
  - ari.russo@gmail.com