Class: Zgomot::Comp::Pattern

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seq) ⇒ Pattern

Returns a new instance of Pattern.



30
31
32
# File 'lib/zgomot/comp/pattern.rb', line 30

def initialize(seq)
  @seq = [seq].flatten
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zgomot/comp/pattern.rb', line 33

def method_missing(meth, *args, &blk)
  result = seq.map do |p|
           p.respond_to?(meth) ? p.send(meth, *args, &blk) : p
         end
  if [:shift, :pop].include?(meth)
    result
  else
    @seq = result
    self
  end
end

Instance Attribute Details

#seqObject (readonly)

Returns the value of attribute seq.



29
30
31
# File 'lib/zgomot/comp/pattern.rb', line 29

def seq
  @seq
end

Class Method Details

.c(tonic, chord = :maj, opts = {}) ⇒ Object



9
10
11
12
# File 'lib/zgomot/comp/pattern.rb', line 9

def c(tonic, chord = :maj, opts = {})
  l = opts[:l] || 4; v = opts[:v] || 0.6
  Chord.new(:tonic => tonic, :chord => chord, :length => l, :velocity => v)
end

.cp(tonic = [:C,4], mode = 0, opts = {}) ⇒ Object



19
20
21
22
# File 'lib/zgomot/comp/pattern.rb', line 19

def cp(tonic=[:C,4], mode=0, opts = {})
  l = opts[:l] || 4; v = opts[:v] || 0.6
  Progression.new(:item => Chord::Progression.new(:scale), :tonic => tonic, :mode => mode, :length => l, :velocity => v)
end

.n(p = [:C,4], opts = {}) ⇒ Object



4
5
6
7
# File 'lib/zgomot/comp/pattern.rb', line 4

def n(p=[:C,4], opts = {})
  l = opts[:l] || 4; v = opts[:v] || 0.6
  Zgomot::Midi::Note.new(:pitch => p, :length => l, :velocity => v)
end

.np(tonic = [:C,4], mode = 0, opts = {}) ⇒ Object



14
15
16
17
# File 'lib/zgomot/comp/pattern.rb', line 14

def np(tonic=[:C,4], mode=0, opts = {})
  l = opts[:l] || 4; v = opts[:v] || 0.6
  Progression.new(:item => Note::Progression.new, :tonic => tonic, :mode => mode, :length => l, :velocity => v)
end

.pr(perc = :acoustic_bass_drum, opts = {}) ⇒ Object



24
25
26
27
# File 'lib/zgomot/comp/pattern.rb', line 24

def pr(perc = :acoustic_bass_drum, opts = {})
  l = opts[:l] || 4; v = opts[:v] || 0.6
  Perc.new(:perc => perc, :length => l, :velocity => v)
end

Instance Method Details

#map(&blk) ⇒ Object



44
45
46
# File 'lib/zgomot/comp/pattern.rb', line 44

def map(&blk)
  @seq = seq.map(&blk); self
end