Class: Zgomot::Comp::Progression
- Inherits:
-
Object
- Object
- Zgomot::Comp::Progression
show all
- Defined in:
- lib/zgomot/comp/progression.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Progression.
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/zgomot/comp/progression.rb', line 4
def initialize(args)
@length, @velocity, @item = [args[:length]].flatten, [args[:velocity]].flatten, args[:item]
@items = (1..7).to_a
self.mode!(args[:mode])
@tonic = case args[:tonic]
when Array then args[:tonic]
when Symbol then [args[:tonic], 4]
when nil then [:C,4]
else raise(Zgomot::Error, "#{args[:tonic].inspect} is invalid tonic")
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/zgomot/comp/progression.rb', line 29
def method_missing(meth, *args, &blk)
if item.respond_to?(meth)
item.send(meth, *args, &blk)
elsif notes.any?{|n| n.respond_to?(meth)}
@notes = notes.map do |n|
n.respond_to?(meth) ? n.send(meth, *args, &blk) : n
end
elsif items.respond_to?(meth)
@notes = nil
items.send(meth, *args, &blk)
else
raise(NoMethodError, "undefined method '#{meth}' called for #{self.class}")
end
self
end
|
Instance Attribute Details
Returns the value of attribute clock.
3
4
5
|
# File 'lib/zgomot/comp/progression.rb', line 3
def clock
@clock
end
|
Returns the value of attribute item.
3
4
5
|
# File 'lib/zgomot/comp/progression.rb', line 3
def item
@item
end
|
Returns the value of attribute items.
3
4
5
|
# File 'lib/zgomot/comp/progression.rb', line 3
def items
@items
end
|
Returns the value of attribute length.
3
4
5
|
# File 'lib/zgomot/comp/progression.rb', line 3
def length
@length
end
|
Returns the value of attribute mode.
3
4
5
|
# File 'lib/zgomot/comp/progression.rb', line 3
def mode
@mode
end
|
Returns the value of attribute tonic.
3
4
5
|
# File 'lib/zgomot/comp/progression.rb', line 3
def tonic
@tonic
end
|
Returns the value of attribute velocity.
3
4
5
|
# File 'lib/zgomot/comp/progression.rb', line 3
def velocity
@velocity
end
|
Instance Method Details
#[](*args) ⇒ Object
57
58
59
|
# File 'lib/zgomot/comp/progression.rb', line 57
def [](*args)
@items = args.flatten; self
end
|
#channel=(c) ⇒ Object
84
85
86
|
# File 'lib/zgomot/comp/progression.rb', line 84
def channel=(c)
notes.each{|n| n.channel = c}
end
|
#length_to_sec ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. midi interface .….….….….….….….….….….….….….….….….….….….….….….….….….….
73
74
75
|
# File 'lib/zgomot/comp/progression.rb', line 73
def length_to_sec
notes.inject(0.0){|s,n| s += n.length_to_sec}
end
|
51
52
53
|
# File 'lib/zgomot/comp/progression.rb', line 51
def mode!(v)
@notes = nil; @mode = v.kind_of?(Mode) ? v : Mode.new(v); self
end
|
#new_respond_to?(meth, include_private = false) ⇒ Boolean
Also known as:
respond_to?
22
23
24
25
26
|
# File 'lib/zgomot/comp/progression.rb', line 22
def new_respond_to?(meth, include_private=false)
old_respond_to?(meth) or
notes.any?{|n| n.respond_to?(meth)} or
(items.respond_to?(meth) and [:reverse!, :shift, :pop, :push, :unshift].include?(meth))
end
|
#note(number) ⇒ Object
66
67
68
|
# File 'lib/zgomot/comp/progression.rb', line 66
def note(number)
notes.map{|n| n.note(number)}
end
|
93
94
95
|
# File 'lib/zgomot/comp/progression.rb', line 93
def notes
@notes ||= item.notes(self)
end
|
#octave!(oct) ⇒ Object
54
55
56
|
# File 'lib/zgomot/comp/progression.rb', line 54
def octave!(oct)
@notes = nil; @octave = oct; self
end
|
#offset=(t) ⇒ Object
90
91
92
|
# File 'lib/zgomot/comp/progression.rb', line 90
def offset=(t)
notes.each{|n| n.offset = t}
end
|
15
16
17
18
19
20
21
|
# File 'lib/zgomot/comp/progression.rb', line 15
def pitches
last_pitch, octave = tonic; pitch = [last_pitch]
mode[0..-2].each_index{|i| pitch << PitchClass.next(tonic.first, sum(mode[0..i]))}
pitch[1..-1].map do |p|
octave += 1 if p < last_pitch; last_pitch = p.value; [last_pitch, octave]
end.unshift(tonic)
end
|
#time=(time) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/zgomot/comp/progression.rb', line 76
def time=(time)
@clock = Zgomot::Midi::Clock.new
clock.update(time)
notes.each do |n|
n.time = clock.current_time
clock.update(n.length_to_sec)
end
end
|
87
88
89
|
# File 'lib/zgomot/comp/progression.rb', line 87
def to_midi
notes.map{|n| n.to_midi}
end
|
#tonic!(v) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. transforms .….….….….….….….….….….….….….….….….….….….….….….….….….….
48
49
50
|
# File 'lib/zgomot/comp/progression.rb', line 48
def tonic!(v)
@notes = nil; @tonic = v; self
end
|