Class: Zgomot::Comp::Chord
Defined Under Namespace
Classes: Progression
Class Attribute Summary collapse
-
.chord_intervals ⇒ Object
readonly
Returns the value of attribute chord_intervals.
Instance Attribute Summary collapse
-
#arp ⇒ Object
readonly
Returns the value of attribute arp.
-
#chord ⇒ Object
readonly
Returns the value of attribute chord.
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#intervals ⇒ Object
readonly
Returns the value of attribute intervals.
-
#inversion ⇒ Object
readonly
Returns the value of attribute inversion.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#reverse ⇒ Object
readonly
Returns the value of attribute reverse.
-
#time_scale ⇒ Object
readonly
Returns the value of attribute time_scale.
-
#tonic ⇒ Object
readonly
Returns the value of attribute tonic.
-
#velocity ⇒ Object
readonly
Returns the value of attribute velocity.
Instance Method Summary collapse
- #arp!(v) ⇒ Object
- #bpm!(v) ⇒ Object
- #channel=(chan) ⇒ Object
-
#initialize(args) ⇒ Chord
constructor
A new instance of Chord.
- #inv!(v) ⇒ Object
- #length!(v) ⇒ Object
- #length_to_sec ⇒ Object
- #note(number) ⇒ Object
- #notes ⇒ Object
- #octave!(v) ⇒ Object
- #offset=(time) ⇒ Object
- #pitches ⇒ Object
- #rev! ⇒ Object
- #time=(time) ⇒ Object
- #to_midi ⇒ Object
- #valocity!(v) ⇒ Object
Constructor Details
#initialize(args) ⇒ Chord
Returns a new instance of Chord.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zgomot/comp/chord.rb', line 42 def initialize(args) @length, @velocity, @chord = args[:length], args[:velocity], args[:chord] (@intervals = Chord.chord_intervals[chord]) || raise(Zgomot::Error, "#{chord.inspect} is invalid") @time_scale, @inversion, @reverse = 1.0, 0, false @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 |
Class Attribute Details
.chord_intervals ⇒ Object (readonly)
Returns the value of attribute chord_intervals.
36 37 38 |
# File 'lib/zgomot/comp/chord.rb', line 36 def chord_intervals @chord_intervals end |
Instance Attribute Details
#arp ⇒ Object (readonly)
Returns the value of attribute arp.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def arp @arp end |
#chord ⇒ Object (readonly)
Returns the value of attribute chord.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def chord @chord end |
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def clock @clock end |
#intervals ⇒ Object (readonly)
Returns the value of attribute intervals.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def intervals @intervals end |
#inversion ⇒ Object (readonly)
Returns the value of attribute inversion.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def inversion @inversion end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def items @items end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def length @length end |
#reverse ⇒ Object (readonly)
Returns the value of attribute reverse.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def reverse @reverse end |
#time_scale ⇒ Object (readonly)
Returns the value of attribute time_scale.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def time_scale @time_scale end |
#tonic ⇒ Object (readonly)
Returns the value of attribute tonic.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def tonic @tonic end |
#velocity ⇒ Object (readonly)
Returns the value of attribute velocity.
39 40 41 |
# File 'lib/zgomot/comp/chord.rb', line 39 def velocity @velocity end |
Instance Method Details
#arp!(v) ⇒ Object
70 71 72 |
# File 'lib/zgomot/comp/chord.rb', line 70 def arp!(v) @notes = nil; @arp = v; self end |
#bpm!(v) ⇒ Object
79 80 81 |
# File 'lib/zgomot/comp/chord.rb', line 79 def bpm!(v) @time_scale = 1.0/v.to_f; self end |
#channel=(chan) ⇒ Object
97 98 99 |
# File 'lib/zgomot/comp/chord.rb', line 97 def channel=(chan) notes.each{|n| n.channel = chan} end |
#inv!(v) ⇒ Object
73 74 75 |
# File 'lib/zgomot/comp/chord.rb', line 73 def inv!(v) @notes = nil; @inversion = v; self end |
#length!(v) ⇒ Object
85 86 87 |
# File 'lib/zgomot/comp/chord.rb', line 85 def length!(v) @length = v; self end |
#length_to_sec ⇒ Object
91 92 93 |
# File 'lib/zgomot/comp/chord.rb', line 91 def length_to_sec time_scale*Zgomot::Midi::Clock.whole_note_sec*(1.0/length + (arp.to_f.eql?(0.0) ? 0.0 : intervals.length.to_f/arp.to_f)) end |
#note(number) ⇒ Object
62 63 64 |
# File 'lib/zgomot/comp/chord.rb', line 62 def note(number) Zgomot::Midi::Note.new(:pitch => pitches[number], :length => length, :velocity => velocity) end |
#notes ⇒ Object
65 66 67 68 69 |
# File 'lib/zgomot/comp/chord.rb', line 65 def notes @notes ||= pitches.map do |p| Zgomot::Midi::Note.new(:pitch => p, :length => length, :velocity => velocity) end end |
#octave!(v) ⇒ Object
82 83 84 |
# File 'lib/zgomot/comp/chord.rb', line 82 def octave!(v) @notes = nil; @octave = v; self end |
#offset=(time) ⇒ Object
100 101 102 |
# File 'lib/zgomot/comp/chord.rb', line 100 def offset=(time) notes.each{|n| n.offset = time} end |
#pitches ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/zgomot/comp/chord.rb', line 54 def pitches last_pitch, octave = tonic; pitches = [tonic] intervals.each_index{|i| pitches << PitchClass.next(tonic.first, intervals[i])} nts = pitches[1..-1].map do |p| octave += 1 if p < last_pitch; last_pitch = p.value; [last_pitch, octave] end.unshift(tonic) @reverse ? invert(nts).reverse : invert(nts) end |
#rev! ⇒ Object
76 77 78 |
# File 'lib/zgomot/comp/chord.rb', line 76 def rev! @reverse = true; self end |
#time=(time) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/zgomot/comp/chord.rb', line 103 def time=(time) @clock = Zgomot::Midi::Clock.new clock.update(time) notes.each do |n| n.time = clock.current_time clock.update(Zgomot::Midi::Clock.whole_note_sec/arp.to_f) if arp.to_f > 0.0 end end |
#to_midi ⇒ Object
94 95 96 |
# File 'lib/zgomot/comp/chord.rb', line 94 def to_midi notes.map{|n| n.to_midi} end |
#valocity!(v) ⇒ Object
88 89 90 |
# File 'lib/zgomot/comp/chord.rb', line 88 def valocity!(v) @length = v; self end |