Class: Dist

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

Overview

a consecutave sequence of morphable tones (TonePart) of varying lengths, and rate of morphs, played without gaps.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Api

#<<, #>>, #parent

Constructor Details

#initializeDist

will have a defult hit at 0 if it has a sound and no hits have been made.



6
7
8
9
10
11
12
# File 'lib/api/dist.rb', line 6

def initialize    
  super
  @dist=SndDist.new
  @hits=HitSq.new
  @hits.add_parent self
  persist_hits
end

Instance Attribute Details

#distObject

Returns the value of attribute dist.



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

def dist
  @dist
end

Instance Method Details

#[](i) ⇒ Object

get a Dist child



41
42
43
44
45
46
47
48
49
# File 'lib/api/dist.rb', line 41

def [] i
  child=@dist.get_children[i]
  raise "This Dist has no child at index #{i}. " +
    "It has #{branches} children." if child.nil?
  d=Dist.new
  d.dist=child
  d.make_hits
  d
end

#branchesObject

count children (Dists only)



67
68
69
# File 'lib/api/dist.rb', line 67

def branches
  @dist.get_children.count
end

#clear_hitsObject

delete all hits



35
36
37
38
39
# File 'lib/api/dist.rb', line 35

def clear_hits
  @hits.hits = []
  persist_hits
  self
end

#clear_sndObject

delete all Snd attached to this Dist



93
94
95
96
# File 'lib/api/dist.rb', line 93

def clear_snd
  @dist.tss = []
  self
end

#del(todel) ⇒ Object

delete another Dist



20
21
22
23
# File 'lib/api/dist.rb', line 20

def del todel
  @dist.snd.delete todel.dist
  self
end

#first_bornObject

get first child



59
60
61
62
63
64
65
# File 'lib/api/dist.rb', line 59

def first_born
  child=@dist.get_children.first
  d=Dist.new
  d.dist=child
  d.make_hits
  d
end

#hitsObject

getter for HitSq. Will persist any changes you make to it.



71
72
73
# File 'lib/api/dist.rb', line 71

def hits
  @hits
end

#last_bornObject

get last child



51
52
53
54
55
56
57
# File 'lib/api/dist.rb', line 51

def last_born
  child=@dist.get_children.last
  d=Dist.new
  d.dist=child
  d.make_hits
  d
end

#lengthObject

get the total length in frames



31
32
33
# File 'lib/api/dist.rb', line 31

def length
  @dist.len
end

#length=(set) ⇒ Object

set the total length in frames



25
26
27
28
29
# File 'lib/api/dist.rb', line 25

def length= set
  @dist.len = set
  @dist.tss.each {|tss| tss.len = set }
  self
end

#make(num = 1, i = 0) ⇒ Object

add num TonePart to Snd at i’s ToneSeq, with my #length as max.



15
16
17
# File 'lib/api/dist.rb', line 15

def make(num=1, i=0)
  snd(i).toneseq.make(num)
end

#persist_hitsObject

(internal use only) copy our hits down to the underlining object



109
110
111
112
113
# File 'lib/api/dist.rb', line 109

def persist_hits
  @dist.hits = hits.hits
  @dist.hits = [0.0] if hits.hits.count == 0
  self
end

#snd(i = 0) ⇒ Object

getter for Snd. Will persist any changes you make to it.



75
76
77
78
79
80
81
82
# File 'lib/api/dist.rb', line 75

def snd i=0
  snd=Snd.new
  snd.add_parent self
  new=@dist.tss[i]
  raise "Dist has no sound at index #{i}. It has #{sounds} sounds." if new.nil?
  snd<< new
  snd
end

#snd_eachObject

run on all sounds



98
99
100
101
102
103
# File 'lib/api/dist.rb', line 98

def snd_each
  sounds.times {|i|
    yield(snd i)
  }
  self
end

#soundsObject

count sounds



105
106
107
# File 'lib/api/dist.rb', line 105

def sounds
  @dist.tss.count
end