Class: HitSq

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

Overview

a pattern of hits to time a Snd

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Api

#<<, #>>, #parent

Constructor Details

#initializeHitSq

Returns a new instance of HitSq.



4
5
6
7
# File 'lib/api/hit_sq.rb', line 4

def initialize
  @hits=[]    
  super
end

Instance Attribute Details

#hitsObject

Returns the value of attribute hits.



3
4
5
# File 'lib/api/hit_sq.rb', line 3

def hits
  @hits
end

Instance Method Details

#*(mult) ⇒ Object

multiply all hits by mult



13
14
15
16
17
# File 'lib/api/hit_sq.rb', line 13

def * mult
  hn = []
  self.hits.collect! {|hit| hit = hit*mult}
  persist
end

#+(val) ⇒ Object



128
129
130
131
# File 'lib/api/hit_sq.rb', line 128

def +(val)
  move val
  persist
end

#countObject

return number of hits



133
134
135
# File 'lib/api/hit_sq.rb', line 133

def count
  hits.count
end

#delete_arr(to_del) ⇒ Object



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

def delete_arr to_del
  to_del.each {|di| self.hits.delete_at di }
  persist
end

#delete_random(chance = 0.5) ⇒ Object

chance

how likely it is a hit will be DELETED



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/api/hit_sq.rb', line 53

def delete_random chance = 0.5
  to_del = []
  hits.each do |h|
    if rand < chance
      to_del << h
    end
  end
  to_del.each {|d| self.hits.delete d }
  persist
  self
end

#eqly_spaced(possible_hits = 4, chance = 1, ignore_first = 0, ignore_last = 0) ⇒ Object

Adds into #hits.

possible_hits

number of hits that can occur. Must be int

chance

chance a hit will be included. range: 0 to 1

ignore_first

skip the first n possible hits

ignore_first

skip the last n possible hits

e.g. disperse_hits(16,1,4,4) makes this pattern [-|-|-|-|+|+|+|+|+|+|+|+|-|-|-|-|]



118
119
120
121
122
123
124
125
126
# File 'lib/api/hit_sq.rb', line 118

def eqly_spaced(possible_hits = 4, chance = 1, ignore_first=0, ignore_last=0)
  possible_hits.times do |i|
    if ignore_first <= i && possible_hits - ignore_last > i
      delay = i/possible_hits.to_f
      @hits.push delay if (rand + chance >= 1)
    end
  end
  self
end

#move(val = 0.5) ⇒ Object

Shift all hits by val, no validation atm



137
138
139
140
141
142
143
# File 'lib/api/hit_sq.rb', line 137

def move(val=0.5)
  self.hits.collect! {|x| 
    z = (x+val)
    x = z
  } # delay all
  self
end

#persistObject

(internal use only)



109
110
111
# File 'lib/api/hit_sq.rb', line 109

def persist
  parent.dist.hits = hits if parent
end

#trim_both(portion = 0.25) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/api/hit_sq.rb', line 89

def trim_both portion=0.25
  save = []
  hits.count.times do |i|
    upto = i.to_f / hits.count
    if upto < 1.0 - portion
      save << hits[i]
    end
  end
  
  save2 = []
  hits.count.times do |i|
    upto = i.to_f / hits.count
    if upto >= portion
      save2 << hits[i]
    end
  end
  self.hits = save&save2
  persist
end

#trim_end(portion = 0.25) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/api/hit_sq.rb', line 77

def trim_end portion=0.25
  save = []
  hits.count.times do |i|
    upto = i.to_f / hits.count
    if upto < 1.0 - portion
      save << hits[i]
    end
  end
  self.hits = save
  persist
end

#trim_start(portion = 0.25) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/api/hit_sq.rb', line 65

def trim_start portion=0.25
  save = []
  hits.count.times do |i|
    upto = i.to_f / hits.count
    if upto >= portion
      save << hits[i]
    end
  end
  self.hits = save
  persist
end