zgomot 0.1.3 → 1.0.0

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.
Files changed (64) hide show
  1. data/.rvmrc +1 -1
  2. data/README.rdoc +191 -98
  3. data/Rakefile +2 -0
  4. data/VERSION +1 -1
  5. data/bin/zgomot +1 -1
  6. data/examples/arp_chords.rb +1 -4
  7. data/examples/delay.rb +16 -0
  8. data/examples/full_scale_notes.rb +2 -5
  9. data/examples/inv_chords.rb +1 -4
  10. data/examples/modes_notes.rb +2 -5
  11. data/examples/notes.rb +1 -5
  12. data/examples/percs.rb +4 -8
  13. data/examples/percs_multi.rb +1 -5
  14. data/examples/phase_notes.rb +4 -8
  15. data/examples/prog_chords.rb +2 -5
  16. data/examples/prog_chords_multi_vel_length.rb +1 -4
  17. data/examples/prog_chords_rest.rb +1 -4
  18. data/examples/prog_notes.rb +1 -4
  19. data/examples/prog_notes_multi_vel_length.rb +1 -4
  20. data/examples/prog_notes_rest.rb +1 -4
  21. data/examples/progressive_modes.rb +10 -18
  22. data/examples/reverse_chords.rb +1 -4
  23. data/examples/route_chords.rb +22 -0
  24. data/examples/scale_chords.rb +1 -4
  25. data/examples/scale_notes.rb +1 -4
  26. data/examples/scales_notes.rb +1 -5
  27. data/examples/simple_chords.rb +1 -4
  28. data/examples/simple_input.rb +21 -0
  29. data/examples/simple_markov.rb +1 -5
  30. data/examples/simple_notes.rb +2 -5
  31. data/examples/zgomot_streams.rb +19 -0
  32. data/lib/zgomot/boot.rb +5 -31
  33. data/lib/zgomot/comp/chord.rb +16 -70
  34. data/lib/zgomot/comp/markov.rb +8 -26
  35. data/lib/zgomot/comp/mode.rb +9 -32
  36. data/lib/zgomot/comp/note.rb +1 -16
  37. data/lib/zgomot/comp/pattern.rb +1 -24
  38. data/lib/zgomot/comp/permutation.rb +0 -11
  39. data/lib/zgomot/comp/pitch_class.rb +3 -28
  40. data/lib/zgomot/comp/progression.rb +15 -49
  41. data/lib/zgomot/comp/scale.rb +5 -14
  42. data/lib/zgomot/config.rb +3 -18
  43. data/lib/zgomot/drivers/core_midi.rb +129 -92
  44. data/lib/zgomot/drivers/driver.rb +2 -15
  45. data/lib/zgomot/drivers/mgr.rb +5 -21
  46. data/lib/zgomot/main.rb +13 -24
  47. data/lib/zgomot/midi/cc.rb +67 -0
  48. data/lib/zgomot/midi/channel.rb +20 -50
  49. data/lib/zgomot/midi/clock.rb +21 -48
  50. data/lib/zgomot/midi/dispatcher.rb +13 -26
  51. data/lib/zgomot/midi/note.rb +11 -34
  52. data/lib/zgomot/midi/stream.rb +82 -43
  53. data/lib/zgomot/midi.rb +1 -0
  54. data/lib/zgomot/ui/output.rb +67 -0
  55. data/lib/zgomot/ui/windows.rb +359 -0
  56. data/lib/zgomot/ui.rb +3 -0
  57. data/lib/zgomot.rb +6 -1
  58. data/lib/{zlive.rb → zgomot_sh.rb} +1 -0
  59. data/zgomot.gems +14 -0
  60. data/zgomot.gemspec +26 -14
  61. metadata +52 -9
  62. data/default.gems +0 -7
  63. data/examples/simple_notes_length.rb +0 -17
  64. data/examples/simple_notes_velocity.rb +0 -17
@@ -1,40 +1,28 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
2
 
4
- #####-------------------------------------------------------------------------------------------------------
5
3
  class Markov
6
4
 
7
- #####-------------------------------------------------------------------------------------------------------
8
5
  class << self
9
-
10
- #.........................................................................................................
11
6
  def mark
12
- new
7
+ new
13
8
  end
14
-
15
- #### self
16
9
  end
17
-
18
- #.........................................................................................................
10
+
19
11
  attr_reader :current_state, :states
20
-
21
- #.........................................................................................................
12
+
22
13
  def initialize
23
14
  @current_state, @states = 0, []
24
15
  end
25
16
 
26
- #.........................................................................................................
27
17
  def add(trans, &blk)
28
18
  @states << {:trans=>sum_trans(trans), :blk => blk}
29
19
  end
30
20
 
31
- #.........................................................................................................
32
21
  def init(state, args={})
33
22
  @current_state = state
34
23
  states[@current_state][:blk].call(args)
35
24
  end
36
-
37
- #.........................................................................................................
25
+
38
26
  def next(args={})
39
27
  r, state = rand, states[@current_state]
40
28
  @current_state = state[:trans].select{|t| r >= t}.count
@@ -43,18 +31,12 @@ module Zgomot::Comp
43
31
  blk.arity > 0 ? blk.call(args) : blk.call
44
32
  end
45
33
 
46
- #.........................................................................................................
47
- # private
48
- #.........................................................................................................
49
- def sum_trans(trans)
50
- sums = []; trans.each_index{|i| sums[i] = trans[0..i].inject(0){|s,v| s+v}}; sums
34
+ def sum_trans(trans)
35
+ sums = []; trans.each_index{|i| sums[i] = trans[0..i].inject(0){|s,v| s+v}}; sums
51
36
  end
52
-
53
- #.........................................................................................................
37
+
54
38
  private :sum_trans
55
-
56
- #### Markov
39
+
57
40
  end
58
41
 
59
- #### Zgomot::Comp
60
42
  end
@@ -1,33 +1,21 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
-
4
- #####-------------------------------------------------------------------------------------------------------
5
2
  class Mode
6
-
7
- #.........................................................................................................
8
3
  @modes = [:ionian, :dorian, :phrygian, :lydian, :mixolydian, :aeolian, :locrian]
9
4
  @intervals = [2,2,1,2,2,2,1]
10
5
  @chords = {:scale => [:maj, :min, :min, :maj, :maj, :min, :dim],
11
6
  :maj => [:maj, nil, nil, :maj, :maj, nil, nil],
12
- :min => [nil, :min, :min, nil, nil, :min, nil],
13
- :dim => [nil, nil, nil, nil, nil, nil, :dim],
7
+ :min => [nil, :min, :min, nil, nil, :min, nil],
8
+ :dim => [nil, nil, nil, nil, nil, nil, :dim],
14
9
  :sus2 => [:sus2, :sus2, nil, :sus2, :sus2, :sus2, nil],
15
10
  :sus4 => [:sus4, :sus4, :sus4, nil, :sus4, :sus4, nil],
16
11
  :aug => [nil, nil, nil, nil, nil, nil, nil]}
17
-
18
- #####-------------------------------------------------------------------------------------------------------
12
+
19
13
  class << self
20
-
21
- #.........................................................................................................
22
14
  attr_reader :modes, :intervals, :chords
23
-
24
- #### self
25
15
  end
26
-
27
- #####-------------------------------------------------------------------------------------------------------
16
+
28
17
  attr_reader :scale, :mode
29
-
30
- #.........................................................................................................
18
+
31
19
  def initialize(mode = 1)
32
20
  @mode = case mode
33
21
  when Symbol then self.class.modes.index(mode)+1
@@ -35,32 +23,21 @@ module Zgomot::Comp
35
23
  when nil then 1
36
24
  else raise(Zgomot::Error, "#{mode.inspect} is invalid mode")
37
25
  end
38
- raise(Zgomot::Error, "'#{mode}' is invalid mode") if @mode.nil?
39
- @scale = Scale.new(self.class.intervals, @mode)
26
+ @scale = Scale.new(self.class.intervals, @mode)
40
27
  end
41
-
42
- #.........................................................................................................
28
+
43
29
  def chords(chord = :scale)
44
30
  cycle_chords(Mode.chords[chord].clone)
45
31
  end
46
-
47
- #.........................................................................................................
32
+
48
33
  def method_missing(meth, *args, &blk )
49
34
  scale.send(meth, *args, &blk)
50
35
  end
51
36
 
52
- #.........................................................................................................
53
- # private
54
- #.........................................................................................................
55
37
  def cycle_chords(cs)
56
- (mode-1).times{cs.push(cs.shift)}; cs
38
+ (mode-1).times{cs.push(cs.shift)}; cs
57
39
  end
58
40
 
59
- #.........................................................................................................
60
41
  private :cycle_chords
61
-
62
- #### Mode
63
42
  end
64
-
65
- #### Zgomot::Comp
66
43
  end
@@ -1,29 +1,14 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
-
4
- #####-------------------------------------------------------------------------------------------------------
5
2
  class Note
6
-
7
- #####-------------------------------------------------------------------------------------------------------
8
- # progession interface
9
- #####-------------------------------------------------------------------------------------------------------
10
3
  class Progression
11
-
12
- #.........................................................................................................
13
4
  def notes(prog)
14
5
  count = -1
15
- prog.items.map do |d|
6
+ prog.items.map do |d|
16
7
  count += 1; idx_length, idx_velocity = count % prog.length.length, count % prog.velocity.length
17
8
  pitch = d.eql?(:R) ? :R : prog.pitches[d-1]
18
9
  Zgomot::Midi::Note.new(:pitch => pitch, :length => prog.length[idx_length], :velocity => prog.velocity[idx_velocity])
19
10
  end
20
11
  end
21
-
22
- #### Progression
23
12
  end
24
-
25
- #### Note
26
13
  end
27
-
28
- #### Zgomot::Comp
29
14
  end
@@ -1,63 +1,40 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
-
4
- #####-------------------------------------------------------------------------------------------------------
5
2
  class Pattern
6
-
7
- #####-------------------------------------------------------------------------------------------------------
8
3
  class << self
9
-
10
- #.......................................................................................................
11
4
  def n(p=[:C,4], opts = {})
12
5
  l = opts[:l] || 4; v = opts[:v] || 0.6
13
6
  Zgomot::Midi::Note.new(:pitch => p, :length => l, :velocity => v)
14
7
  end
15
8
 
16
- #.........................................................................................................
17
9
  def c(tonic, chord = :maj, opts = {})
18
10
  l = opts[:l] || 4; v = opts[:v] || 0.6
19
11
  Chord.new(:tonic => tonic, :chord => chord, :length => l, :velocity => v)
20
12
  end
21
13
 
22
- #.........................................................................................................
23
14
  def np(tonic=[:C,4], mode=0, opts = {})
24
15
  l = opts[:l] || 4; v = opts[:v] || 0.6
25
16
  Progression.new(:item => Note::Progression.new, :tonic => tonic, :mode => mode, :length => l, :velocity => v)
26
17
  end
27
18
 
28
- #.........................................................................................................
29
19
  def cp(tonic=[:C,4], mode=0, opts = {})
30
20
  l = opts[:l] || 4; v = opts[:v] || 0.6
31
21
  Progression.new(:item => Chord::Progression.new(:scale), :tonic => tonic, :mode => mode, :length => l, :velocity => v)
32
22
  end
33
23
 
34
- #.........................................................................................................
35
24
  def pr(percs = acoustic_bass_drum, opts = {})
36
25
  l = opts[:l] || 4; v = opts[:v] || 0.6
37
26
  Perc.new(:percs => percs, :length => l, :velocity => v)
38
27
  end
39
-
40
- #### self
41
28
  end
42
-
43
- #...........................................................................................................
44
29
  attr_reader :seq
45
-
46
- #...........................................................................................................
47
30
  def initialize(seq)
48
31
  @seq = [seq].flatten
49
32
  end
50
-
51
- #.........................................................................................................
52
- def method_missing(meth, *args, &blk )
33
+ def method_missing(meth, *args, &blk)
53
34
  @seq = seq.map do |p|
54
35
  p.respond_to?(meth) ? p.send(meth, *args, &blk) : p
55
36
  end
56
37
  self
57
38
  end
58
-
59
- #### Pattern
60
39
  end
61
-
62
- #### Zgomot ::Comp
63
40
  end
@@ -1,17 +1,6 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
-
4
- #####-------------------------------------------------------------------------------------------------------
5
2
  class Permutation
6
-
7
- #.........................................................................................................
8
-
9
- #.........................................................................................................
10
3
  def initialize
11
4
  end
12
-
13
- #### Markov
14
5
  end
15
-
16
- #### Zgomot::Comp
17
6
  end
@@ -1,63 +1,38 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
-
4
- #####-------------------------------------------------------------------------------------------------------
5
2
  class PitchClass
6
-
7
- #.........................................................................................................
8
3
  PITCH_CLASS = {
9
- :C => 0,
4
+ :C => 0,
10
5
  :Cs => 1,
11
6
  :D => 2,
12
7
  :Ds => 3,
13
8
  :E => 4,
14
9
  :F => 5,
15
10
  :Fs => 6,
16
- :G => 7,
11
+ :G => 7,
17
12
  :Gs => 8,
18
13
  :A => 9,
19
14
  :As => 10,
20
- :B => 11
15
+ :B => 11
21
16
  }
22
-
23
- #####-------------------------------------------------------------------------------------------------------
24
17
  class << self
25
-
26
- #.........................................................................................................
27
18
  def next(pc, interval)
28
19
  start_pos = PITCH_CLASS[to_value(pc)]
29
20
  new(PITCH_CLASS.inject([]){|r,(c,p)| p.eql?((start_pos+interval) % 12) ? r << c : r}.first) if start_pos
30
21
  end
31
-
32
- #.........................................................................................................
33
22
  def to_value(p)
34
23
  p.kind_of?(PitchClass) ? p.value : p
35
24
  end
36
-
37
- #### self
38
25
  end
39
-
40
- #.........................................................................................................
41
26
  attr_reader :value
42
-
43
- #.........................................................................................................
44
27
  def initialize(p)
45
28
  raise(Zgomot::Error, "#{p} is invalid pitch class") unless PITCH_CLASS.include?(p)
46
29
  @value = p
47
30
  end
48
-
49
- #.........................................................................................................
50
31
  def <(p)
51
32
  PITCH_CLASS[value] < PITCH_CLASS[self.class.to_value(p)]
52
33
  end
53
-
54
- #.........................................................................................................
55
34
  def >(p)
56
35
  PITCH_CLASS[value] > PITCH_CLASS[self.class.to_value(p)]
57
36
  end
58
-
59
- #### PitchClass
60
37
  end
61
-
62
- #### Zgomot::Comp
63
38
  end
@@ -1,13 +1,6 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
-
4
- #####-------------------------------------------------------------------------------------------------------
5
2
  class Progression
6
-
7
- #.........................................................................................................
8
3
  attr_reader :mode, :length, :velocity, :clock, :tonic, :items, :item
9
-
10
- #.........................................................................................................
11
4
  def initialize(args)
12
5
  @length, @velocity, @item = [args[:length]].flatten, [args[:velocity]].flatten, args[:item]
13
6
  @items = (1..7).to_a
@@ -19,8 +12,6 @@ module Zgomot::Comp
19
12
  else raise(Zgomot::Error, "#{args[:tonic].inspect} is invalid tonic")
20
13
  end
21
14
  end
22
-
23
- #.........................................................................................................
24
15
  def pitches
25
16
  last_pitch, octave = tonic; pitch = [last_pitch]
26
17
  mode[0..-2].each_index{|i| pitch << PitchClass.next(tonic.first, sum(mode[0..i]))}
@@ -28,23 +19,25 @@ module Zgomot::Comp
28
19
  octave += 1 if p < last_pitch; last_pitch = p.value; [last_pitch, octave]
29
20
  end.unshift(tonic)
30
21
  end
31
-
32
- #.........................................................................................................
33
22
  def new_respond_to?(meth, include_private=false)
34
- old_respond_to?(meth) || (not notes.select{|n| n.respond_to?(meth)}.empty?)
23
+ old_respond_to?(meth) or
24
+ notes.any?{|n| n.respond_to?(meth)} or
25
+ (items.respond_to?(meth) and [:reverse!, :shift, :pop, :push, :unshift].include?(meth))
35
26
  end
36
27
  alias_method :old_respond_to?, :respond_to?
37
28
  alias_method :respond_to?, :new_respond_to?
38
-
39
- #.........................................................................................................
40
29
  def method_missing(meth, *args, &blk)
41
- if not notes.select{|n| n.respond_to?(meth)}.empty?
30
+ if item.respond_to?(meth)
31
+ item.send(meth, *args, &blk)
32
+ elsif notes.any?{|n| n.respond_to?(meth)}
42
33
  @notes = notes.map do |n|
43
34
  n.respond_to?(meth) ? n.send(meth, *args, &blk) : n
44
35
  end
45
- else
36
+ elsif items.respond_to?(meth)
46
37
  @notes = nil
47
38
  items.send(meth, *args, &blk)
39
+ else
40
+ raise(NoMethodError, "undefined method '#{meth}' called for #{self.class}")
48
41
  end
49
42
  self
50
43
  end
@@ -55,39 +48,31 @@ module Zgomot::Comp
55
48
  def tonic!(v)
56
49
  @notes = nil; @tonic = v; self
57
50
  end
58
-
59
- #.........................................................................................................
60
51
  def mode!(v)
61
52
  @notes = nil; @mode = v.kind_of?(Mode) ? v : Mode.new(v); self
62
53
  end
63
-
64
- #.........................................................................................................
65
54
  def octave!(oct)
66
55
  @notes = nil; @octave = oct; self
67
56
  end
68
-
69
- #.........................................................................................................
70
57
  def [](*args)
71
58
  @items = args.flatten; self
72
59
  end
73
-
74
- #.........................................................................................................
75
60
  def velocity=(v)
76
61
  notes.each{|n| n.velocity = v}
77
62
  end
78
-
79
- #.........................................................................................................
80
63
  def length=(v)
81
64
  notes.each{|n| n.length = v}
82
65
  end
66
+ def note(number)
67
+ notes.map{|n| n.note(number)}
68
+ end
83
69
 
84
70
  #.........................................................................................................
85
71
  # midi interface
72
+ #.........................................................................................................
86
73
  def length_to_sec
87
74
  notes.inject(0.0){|s,n| s += n.length_to_sec}
88
75
  end
89
-
90
- #.........................................................................................................
91
76
  def time=(time)
92
77
  @clock = Zgomot::Midi::Clock.new
93
78
  clock.update(time)
@@ -96,42 +81,23 @@ module Zgomot::Comp
96
81
  clock.update(n.length_to_sec)
97
82
  end
98
83
  end
99
-
100
- #.........................................................................................................
101
84
  def channel=(c)
102
85
  notes.each{|n| n.channel = c}
103
86
  end
104
-
105
- #.........................................................................................................
106
87
  def to_midi
107
88
  notes.map{|n| n.to_midi}
108
89
  end
109
-
110
- #.........................................................................................................
111
90
  def offset_time=(t)
112
91
  notes.each{|n| n.offset_time = t}
113
92
  end
114
-
115
- #.........................................................................................................
116
- def to_ary
117
- notes
118
- end
119
-
120
- #.........................................................................................................
121
93
  def notes
122
94
  @notes ||= item.notes(self)
123
95
  end
124
-
125
- #.........................................................................................................
96
+
126
97
  def sum(a)
127
98
  a.inject(0) {|s,n| s+n}
128
99
  end
129
-
130
- #.........................................................................................................
100
+
131
101
  private :sum
132
-
133
- #### Progression
134
102
  end
135
-
136
- #### Zgomot::Comp
137
103
  end
@@ -1,13 +1,9 @@
1
- ##############################################################################################################
2
1
  module Zgomot::Comp
3
2
 
4
- #####-------------------------------------------------------------------------------------------------------
5
3
  class Scale
6
-
7
- #####-------------------------------------------------------------------------------------------------------
4
+
8
5
  attr_reader :intervals, :shift, :scale
9
-
10
- #.........................................................................................................
6
+
11
7
  def initialize(int, shift)
12
8
  @intervals = int
13
9
  @shift = shift - 1
@@ -15,18 +11,13 @@ module Zgomot::Comp
15
11
  self.shift.times{self.next}
16
12
  end
17
13
 
18
- #.........................................................................................................
19
14
  def next
20
- scale.push(scale.shift)
15
+ scale.push(scale.shift)
21
16
  end
22
-
23
- #.........................................................................................................
17
+
24
18
  def method_missing(method, *args, &blk )
25
19
  scale.send(method, *args, &blk)
26
20
  end
27
-
28
- #### Scale
29
- end
30
21
 
31
- #### Zgomot::Comp
22
+ end
32
23
  end
data/lib/zgomot/config.rb CHANGED
@@ -1,51 +1,36 @@
1
- ##############################################################################################################
2
1
  module Zgomot
3
2
 
4
- #####-------------------------------------------------------------------------------------------------------
5
3
  class Error < Exception; end
6
4
 
7
- #.........................................................................................................
8
5
  VERSION = "0.0.0"
9
6
  PLAY_DELAY = 1.0
10
7
  DISPATCHER_POLL = 1.133
11
8
 
12
- #.........................................................................................................
13
9
  DEFAULT_CONFIG = {
14
10
  :beats_per_minute => 120,
15
11
  :time_signature => '4/4',
16
12
  :resolution => '1/32'
17
13
  }
18
14
 
19
- #.........................................................................................................
20
15
  @config_file = "zgomot.yml"
21
16
  @app_path = File.dirname($0)
22
17
  @log_file = STDOUT
23
18
  @live = false
24
-
25
- ####......................................................................................................
26
- class << self
27
19
 
28
- #.......................................................................................................
20
+ class << self
29
21
  attr_accessor :config_file, :app_path, :log_file, :config, :live
30
-
31
- #.......................................................................................................
32
22
  def logger; @logger ||= Logger.new(STDOUT); end
33
23
  def logger=(logger); @logger = logger; end
34
-
35
- #.......................................................................................................
36
24
  def add_path(dir)
37
25
  File.join(Zgomot.app_path, dir)
38
26
  end
39
-
40
- #### self
41
27
  end
42
28
 
43
- #.......................................................................................................
44
29
  @config_file = add_path(config_file)
45
30
  user_config = if File.exist?(config_file)
46
31
  (c = File.open(config_file) {|yf| YAML::load(yf)}) ? c : {}
47
32
  else; {}; end
48
- @config = DEFAULT_CONFIG.inject({}){|r,(k,v)| r.update(k => (user_config[k.to_s] || v))}
49
-
33
+ @config = DEFAULT_CONFIG.inject({}){|r,(k,v)| r.update(k => (user_config[k.to_s] || v))}
34
+
50
35
  end
51
36