Class: Mapper

Inherits:
Api show all
Defined in:
lib/api/mapper.rb

Overview

a mapper is a collection of Dist all as long as a Dist being mapped too, each of these Dist have a child who is getting “mapped” with hits across that length. everything that you need a mapper for can be done without one but it is handy, since it is a common patten.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Api

#<<, #>>, #parent

Constructor Details

#initialize(map_to_dist = nil) ⇒ Mapper

Returns a new instance of Mapper.



8
9
10
11
12
# File 'lib/api/mapper.rb', line 8

def initialize(map_to_dist=nil)
  @dist=Dist.new 
  @len=0
  self.map_to= map_to_dist if !map_to_dist.nil?
end

Instance Attribute Details

#distObject

the main Dist containing all mappings



7
8
9
# File 'lib/api/mapper.rb', line 7

def dist
  @dist
end

Instance Method Details

#[](i = 0) ⇒ Object

get a mapper at i from #dist



35
36
37
# File 'lib/api/mapper.rb', line 35

def [] i=0
  dist[i]
end

#countObject



24
25
26
# File 'lib/api/mapper.rb', line 24

def count
  dist.branches
end

#lastObject

return last child



39
40
41
# File 'lib/api/mapper.rb', line 39

def last
  dist.last_born
end

#map_to=(val) ⇒ Object

length of each child is set to length of val, and we get added to val

val

a Dist



29
30
31
32
33
# File 'lib/api/mapper.rb', line 29

def map_to= val
  @len=val.length
  dist.set_child_len @len
  val << dist #add me to him
end

#mapee(i = 0) ⇒ Object

get the child of a mapper (the dist to being mapped) at i



47
48
49
# File 'lib/api/mapper.rb', line 47

def mapee i=0
  dist[i][0]
end

#mapee_lastObject

return last #mapee



43
44
45
# File 'lib/api/mapper.rb', line 43

def mapee_last
  last[0]
end

#mix(mixed_ammount = 0.25) ⇒ Object

set the right hits to mix all children one after eachother. (this can create a dj mix)

mixed_ammount

the ammount of overlap between children



16
17
18
19
20
21
22
23
# File 'lib/api/mapper.rb', line 16

def mix mixed_ammount = 0.25
  last_start = 0.0
  dist.branches.times do |i|
    self[i].clear_hits
    self[i] << last_start
    last_start = last_start + (1.0 - mixed_ammount) * (1.0/dist.branches)
  end
end

#techno_percussion(len) ⇒ Object

add dists with the hits you need for a bar of techno percussion.

len

length of bar

3 children, in order: bass drum, snare, hi hat



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/api/mapper.rb', line 54

def techno_percussion len
  self << len.Dist # bass drum
  mapee_last.clear_hits
  mapee_last << 4.eqly_spaced
  self << len.Dist # snare
  mapee_last.clear_hits
  mapee_last << [0.25,0.75]
  self << len.Dist # hi
  mapee_last.clear_hits
  mapee_last << 4.eqly_spaced
  mapee_last.hits.move(0.125) # offbeats
  self
end