Class: Zgomot::Comp::Progression

Inherits:
Object
  • Object
show all
Defined in:
lib/zgomot/comp/progression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Progression

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/zgomot/comp/progression.rb', line 27

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

#clockObject (readonly)

Returns the value of attribute clock.



3
4
5
# File 'lib/zgomot/comp/progression.rb', line 3

def clock
  @clock
end

#itemObject (readonly)

Returns the value of attribute item.



3
4
5
# File 'lib/zgomot/comp/progression.rb', line 3

def item
  @item
end

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/zgomot/comp/progression.rb', line 3

def items
  @items
end

#lengthObject (readonly)

Returns the value of attribute length.



3
4
5
# File 'lib/zgomot/comp/progression.rb', line 3

def length
  @length
end

#modeObject (readonly)

Returns the value of attribute mode.



3
4
5
# File 'lib/zgomot/comp/progression.rb', line 3

def mode
  @mode
end

#tonicObject (readonly)

Returns the value of attribute tonic.



3
4
5
# File 'lib/zgomot/comp/progression.rb', line 3

def tonic
  @tonic
end

#velocityObject (readonly)

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



55
56
57
# File 'lib/zgomot/comp/progression.rb', line 55

def [](*args)
  @items = args.flatten; self
end

#channel=(c) ⇒ Object



97
98
99
# File 'lib/zgomot/comp/progression.rb', line 97

def channel=(c)
  notes.each{|n| n.channel = c}
end

#length!(v) ⇒ Object



61
62
63
# File 'lib/zgomot/comp/progression.rb', line 61

def length!(v)
  notes.each{|n| n.length!(v)}; self
end

#length_to_secObject

.….….….….….….….….….….….….….….….….….….….….….….….….….…. midi interface .….….….….….….….….….….….….….….….….….….….….….….….….….….



86
87
88
# File 'lib/zgomot/comp/progression.rb', line 86

def length_to_sec
  notes.inject(0.0){|s,n| s += n.length_to_sec}
end

#mode!(v) ⇒ Object



49
50
51
# File 'lib/zgomot/comp/progression.rb', line 49

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?

Returns:

  • (Boolean)


22
23
24
# 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)}
end

#note(number) ⇒ Object



64
65
66
# File 'lib/zgomot/comp/progression.rb', line 64

def note(number)
  notes.map{|n| n.note(number)}
end

#notesObject



106
107
108
# File 'lib/zgomot/comp/progression.rb', line 106

def notes
  @notes ||= item.notes(self)
end

#octave!(oct) ⇒ Object



52
53
54
# File 'lib/zgomot/comp/progression.rb', line 52

def octave!(oct)
  @notes = nil; @octave = oct; self
end

#offset=(t) ⇒ Object



103
104
105
# File 'lib/zgomot/comp/progression.rb', line 103

def offset=(t)
  notes.each{|n| n.offset = t}
end

#pitchesObject



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

#popObject



73
74
75
# File 'lib/zgomot/comp/progression.rb', line 73

def pop
  @notes = nil; @items.pop
end

#push(n) ⇒ Object



76
77
78
# File 'lib/zgomot/comp/progression.rb', line 76

def push(n)
  @notes = nil; @items.push(n); self
end

#reverse!Object



79
80
81
# File 'lib/zgomot/comp/progression.rb', line 79

def reverse!
  @notes = nil; @items.reverse!; self
end

#shiftObject



67
68
69
# File 'lib/zgomot/comp/progression.rb', line 67

def shift
  @notes = nil; @items.shift
end

#time=(time) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/zgomot/comp/progression.rb', line 89

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

#to_midiObject



100
101
102
# File 'lib/zgomot/comp/progression.rb', line 100

def to_midi
  notes.map{|n| n.to_midi}
end

#tonic!(v) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….…. transforms .….….….….….….….….….….….….….….….….….….….….….….….….….….



46
47
48
# File 'lib/zgomot/comp/progression.rb', line 46

def tonic!(v)
  @notes = nil; @tonic = v; self
end

#unshift(n) ⇒ Object



70
71
72
# File 'lib/zgomot/comp/progression.rb', line 70

def unshift(n)
  @notes = nil; @items.unshift(n); self
end

#velocity!(v) ⇒ Object



58
59
60
# File 'lib/zgomot/comp/progression.rb', line 58

def velocity!(v)
  notes.each{|n| n.velocity!(v)}; self
end