Module: XRVG::FloatFunctor

Included in:
Samplable, Splittable
Defined in:
lib/samplation.rb

Overview

  • by default, FloatFunctor provides “transforms” and “transform” to be used by “type” processing

Instance Method Summary collapse

Instance Method Details

#addfilter(newfilter) ⇒ Object

building recursivity method

is private => no for Array



31
32
33
34
35
36
37
38
# File 'lib/samplation.rb', line 31

def addfilter( newfilter )
  if not @subfilter
    @subfilter = newfilter
  else
    @subfilter.addfilter( newfilter )
  end
  return self
end

#alternateObject

alternate filter



156
157
158
# File 'lib/samplation.rb', line 156

def alternate()
  return self.addfilter( AlternateFilter.new )
end

#apply(data, type, &block) ⇒ Object

must not be overloaded (apart from Samplable containers)



110
111
112
113
114
115
116
117
# File 'lib/samplation.rb', line 110

def apply( data, type, &block )
  @applyhash = self.applyhash
  if not @applyhash.key? type
    Kernel::raise("FloatFunctor::apply no regsitration for type #{type} and  object #{self.inspect}")
  else
    return self.send(@applyhash[type], data, &block )
  end
end

#applyhashObject

must be refactored with some meta hooks



102
103
104
105
106
107
# File 'lib/samplation.rb', line 102

def applyhash
  result = {}
  result[:sample] = :apply_samples
  result[:split]  = :apply_splits
  return result
end

#compute(indata, type, &block) ⇒ Object

hook for Array



55
56
57
# File 'lib/samplation.rb', line 55

def compute( indata, type, &block )
  return self.apply( self.modify( indata, type ), type, &block )
end

#filter(samplemethod = :sample, &block) ⇒ Object

shortcut method to build a sampler from self and a block



161
162
163
# File 'lib/samplation.rb', line 161

def filter(samplemethod=:sample,&block)
  return Filter.new( self, samplemethod, &block )
end

#generate(nsamples) ⇒ Object

default generator method



90
91
92
# File 'lib/samplation.rb', line 90

def generate( nsamples )
  return (0.0..1.0).generate( nsamples )
end

#geo(speed) ⇒ Object

geometric filter



124
125
126
# File 'lib/samplation.rb', line 124

def geo( speed )
  return self.addfilter( Filter.with {|x| 1.0 - Math.exp(-speed * x)} )
end

#geofull(factor) ⇒ Object

geometric filter full



129
130
131
# File 'lib/samplation.rb', line 129

def geofull( factor )
  return self.addfilter( GeoFullFilter.new( factor ) )
end

#modify(inputs, type) ⇒ Object

recursive method to compose modifications.

must not be overloaded



71
72
73
74
75
76
77
# File 'lib/samplation.rb', line 71

def modify( inputs, type )
  if @subfilter
    inputs = @subfilter.modify( inputs, type )
  end
  result = self.transforms( inputs, type )
  return result    
end

#process(indata, type, &block) ⇒ Object

hook for rand()



60
61
62
63
64
65
66
# File 'lib/samplation.rb', line 60

def process( indata, type, &block )
  if not block
    return self.compute( indata, type )
  else
    self.compute( indata, type, &block )
  end
end

#random(*args) ⇒ Object

random filter



140
141
142
# File 'lib/samplation.rb', line 140

def random(*args)
  return self.addfilter( RandomFilter.new(*args) )
end

#shuffleObject

shuffle filter



150
151
152
# File 'lib/samplation.rb', line 150

def shuffle()
  return self.addfilter( ShuffleFilter.new )
end

#sin(speed = 1.0, phase = 0.0) ⇒ Object

sin filter



135
136
137
# File 'lib/samplation.rb', line 135

def sin( speed=1.0, phase=0.0 )
  return self.addfilter( Filter.with {|x| Math.sin( speed * x * Math::PI + phase) } )
end

#ssortObject

sorting filter



145
146
147
# File 'lib/samplation.rb', line 145

def ssort()
  return self.addfilter( SortFilter.new )
end

#transform(abs) ⇒ Object

to be overloaded



85
86
87
# File 'lib/samplation.rb', line 85

def transform( abs )
  return abs
end

#transforms(inputs, type) ⇒ Object

to be overloaded if needed



80
81
82
# File 'lib/samplation.rb', line 80

def transforms( inputs, type )
  return inputs.map {|abs| self.transform( abs )}
end

#trigger(nsamples, type, &block) ⇒ Object

must not be overloaded



45
46
47
48
49
50
51
52
# File 'lib/samplation.rb', line 45

def trigger( nsamples, type, &block )
  if nsamples.is_a? Integer
    indata     = self.generate( nsamples )
  else
    indata     = nsamples
  end
  return self.process( indata, type, &block )
end