public
Description: Ruby MIDI DJing/live-coding thing
Homepage:
Clone URL: git://github.com/gilesbowkett/archaeopteryx.git
archaeopteryx / harmonic_cycle.rb
100644 87 lines (68 sloc) 2.697 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
$clock.bpm = 30
$mutation = L{|measure| 0 == (measure - 1) % 2}
$measures = 4
 
@root = OCTAVES[2].to_a[SCALE[[CIRCLE_OF_FIFTHS,CIRCLE_OF_FOURTHS][rand(2)].next]]
 
def midi_note(midi_note_number, channel, duration)
  Note.create(:channel => channel,
              :number => midi_note_number,
              :duration => duration,
              :velocity => 100 + rand(27))
end
 
notes = []
bass = Drum.new(:note => midi_note(@root - 36, 1, 3.00),
                :when => L{|beat| false},
                :next => L{|queue| queue[queue.size - 1]},
                :number_generator => L{rand},
                :probabilities => [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0])
notes << bass
bass5th = Drum.new(:note => midi_note((@root - 36) + 5, 1, 3.00),
                   :when => L{|beat| false},
                   :next => L{|queue| queue[queue.size - 1]},
                   :number_generator => L{rand},
                   :probabilities => [0.0, 0.0, 0.0, 0.0, 0.15, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.15, 0.0])
notes << bass5th
 
# channel 9 is the easter egg!
pad_channel = [2,2,2,2,2,2,2,2,
               7,7,7,7,7,7,7,7,7,
               8,8,8,8,8,8,8,8,
               9,
               10,10,10,10,10,10,10,
               11,11,11,11,11,11,11,11][rand(41)] # 11 is unassigned - sometimes it's silent
# pad_channel = 8
MAJOR_TRIAD.each do |number|
  notes << Drum.new(:note => midi_note(@root + number, pad_channel, 3.00),
                    :when => L{|beat| false},
                    :next => L{|queue| queue[queue.size - 1]},
                    :number_generator => L{rand},
                    :probabilities => [1.0] + [0.0] * 15)
end
 
def temple_bells
  boost = {}
  # (0..11).each {|note| boost[note] = 0.0}
  # MAJOR_SCALE.each {|note| boost[note] += 0.05}
  # root = MAJOR_SCALE[0] ; boost[root] += 0.2
  MAJOR_TRIAD.each {|note| boost[note] = 0.1}
  
  rhythm = [0.0, 0.0, 0.5, 0.0,
            0.25, 0.0, 0.0, 0.0,
            0.25, 0.0, 0.75, 0.0,
            0.0, 0.05, 0.0, 0.05]
  
  bells = {}
  boost.keys.each do |note|
    bells[note] = rhythm.collect {|probability| probability + boost[note]}
  end
  
  elevated_root = 60 + @root
  wtf = []
  bells.each do |note, probabilities|
    next unless rand > 0.7
    wtf << Drum.new(:note => midi_note(elevated_root + note, 6, 0.25),
                      :when => L{|beat| false},
                      :next => L{|queue| queue[queue.size - 1]},
                      :number_generator => L{rand},
                      :probabilities => probabilities)
  end
  wtf.compact
  wtf
end
 
notes += temple_bells
 
 
 
 
 
 
 
 
 
# this file expected to return array of notes!
notes