collavoce 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,35 @@
1
1
  = collavoce
2
2
 
3
- Powering MIDI through ruby.
3
+ Powering MIDI through JRuby.
4
4
 
5
+ = Installation
5
6
 
7
+ gem install collavoce
8
+
9
+ Or get the repo and run `rake gem` to make your own gem to install. Or point bundler at it, or tweak your load path, your call really.
10
+
11
+ Oh, and this is JRuby only at the moment. MRI should be doable I just haven't gotten around to it yet.
12
+
13
+ = Usage
14
+
15
+ Right now this is still a little raw, but have a look at examples/zelda.rb to get a feel for it.
16
+
17
+ The basic idea is just a DSL for building melodies from arrays of strings. These notes and timings are then used to send MIDI events. Currently the MIDI device isn't configuratable (see lib/collavoce/voice.rb on that one). But that should get cleaned up soon.
18
+
19
+ The note syntax is inspired by jFugue. The pattern is:
20
+
21
+ NOTE - OCTAVE - TIMING
22
+
23
+ So note can be "C" or "C#" or "Ebb". Follow that with an optional octave number (default is 4). Then timing characters. Options are "w"hole, "h"alf, "q"uarter, "s"ixteenth, "t"hirtysecond. And you can combine timings. So a dotted quarter note would be "qe".
24
+
25
+ Additionall if you use "R" as the note it will produce a rest in the melody. Same timing pattern applies. Octave will be, of course, ignored.
26
+
27
+ So "Twinkle Twinkle little star" could be: %w(C C G G A A Gh)
28
+
29
+ Each Voice represents a part of the song. It gets a channel and notes, then you can put it in a tracker like this:
30
+
31
+ Collavoce::Tracker.new([TwinkleTwinkle]).run
32
+
33
+ The tracker allows for multiple parallel tracks of voice sequences. This uses threading right now, but I could see moving to Ruck if timing ever got a little off.
34
+
35
+ If you want a Voice to have more interesting characteristics than just the notes you can override Voice#run and do whatever you want. I've included helpers for diminishing (half step down) and augmenting (half step up) sets of notes. So far this has been enough for me, but I'm sure we'll start adding more helpers once more people try making things with this.
@@ -79,5 +79,9 @@ module Collavoce
79
79
  copy.dim!
80
80
  copy
81
81
  end
82
+
83
+ def ==(other)
84
+ value == other.value && duration == other.duration
85
+ end
82
86
  end
83
87
  end
@@ -15,5 +15,9 @@ module Collavoce
15
15
  end
16
16
  @threads.map(&:join)
17
17
  end
18
+
19
+ def loop(bpm=120)
20
+ run(bpm) while true
21
+ end
18
22
  end
19
23
  end
@@ -41,13 +41,18 @@ module Collavoce
41
41
  end
42
42
 
43
43
  def send_note(note, channel)
44
- noteon = ShortMessage.new
45
- noteon.set_message(ShortMessage::NOTE_ON, channel, note.value, 127);
46
- noteoff = ShortMessage.new
47
- noteoff.set_message(ShortMessage::NOTE_OFF, channel, note.value, 127);
48
- receiver.send(noteon, 0)
49
- sleep @bar_duration * note.duration
50
- receiver.send(noteoff, 0)
44
+ duration = @bar_duration * note.duration
45
+ if note.value
46
+ noteon = ShortMessage.new
47
+ noteon.set_message(ShortMessage::NOTE_ON, channel, note.value, 127);
48
+ noteoff = ShortMessage.new
49
+ noteoff.set_message(ShortMessage::NOTE_OFF, channel, note.value, 127);
50
+ receiver.send(noteon, 0)
51
+ sleep duration
52
+ receiver.send(noteoff, 0)
53
+ else
54
+ sleep duration
55
+ end
51
56
  end
52
57
 
53
58
  def play(this_many = 1)
@@ -57,5 +62,32 @@ module Collavoce
57
62
  end
58
63
  end
59
64
  end
65
+
66
+ def run
67
+ play
68
+ end
69
+
70
+ def mod_notes(*indices)
71
+ if indices.empty?
72
+ notes_to_mod = notes
73
+ else
74
+ notes_to_mod = notes.values_at(*indices)
75
+ end
76
+ notes_to_mod.each do |n|
77
+ yield n
78
+ end
79
+ end
80
+
81
+ def dim_notes(*indices)
82
+ mod_notes(*indices) do |n|
83
+ n.dim!
84
+ end
85
+ end
86
+
87
+ def aug_notes(*indices)
88
+ mod_notes(*indices) do |n|
89
+ n.aug!
90
+ end
91
+ end
60
92
  end
61
93
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mat Schaffer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-01 00:00:00 -05:00
17
+ date: 2010-12-03 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency