Class: Zgomot::Comp::Perc

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

Overview


Constant Summary collapse

PERC_MAP =

.….….….….….….….….….….….….….….….….….….….….….….….….….….

{
:acoustic_bass_drum => [:B,1], 
:bass_drum_1        => [:C,2],  :side_stick     => [:Cs,2], :acoustic_snare => [:D,2],
:hand_clap          => [:Ds,2], :electric_snare => [:E,2],  :low_floor_tom  => [:F,2],
:closed_hi_hat      => [:Fs,2], :high_floor_tom => [:G,2],  :pedal_hi_hat   => [:Gs,2],
:low_tom            => [:A,2],  :open_hi_hat    => [:As,2], :low_mid_tom    => [:B,2],
:high_mid_tom       => [:C,3],  :crash_cymbal_1 => [:Cs,3], :high_tom       => [:D,3], 
:ride_cymbal_1      => [:Ds,3], :chinese_cymbal => [:E,3],  :ride_bell      => [:F,3], 
:tambourine         => [:Fs,3], :splash_cymbal  => [:G,3],  :cowbell        => [:Gs,3], 
:crash_cymbal_2     => [:A,3],  :vibraslap      => [:As,3], :ride_cymbal_2  => [:B,3],
:high_bongo         => [:C,4],  :low_bongo      => [:Cs,4], :mute_hi_conga  => [:D,4], 
:open_hi_conga      => [:Ds,4], :low_conga      => [:E,4],  :high_timbale   => [:F,4], 
:low_timbale        => [:Fs,4], :high_agogo     => [:G,4],  :low_agogo      => [:Gs,4], 
:cabasa             => [:A,4],  :maracas        => [:As,4], :short_whistle  => [:B,4],
:long_whistle       => [:C,5],  :short_guiro    => [:Cs,5], :long_guiro     => [:D,5],  
:claves             => [:Ds,5], :hi_woodblock   => [:E,5],  :low_woodblock  => [:F,5], 
:mute_cuica         => [:Fs,5], :open_cuica     => [:G,5],  :mute_triangle  => [:Gs,5], 
:open_triangle      => [:A,5],
:R                  => :R,      
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Perc

.….….….….….….….….….….….….….….….….….….….….….….….….….….



39
40
41
42
# File 'lib/zgomot/comp/perc.rb', line 39

def initialize(args)
  @length, @velocity, @percs = args[:length], args[:velocity], [args[:percs]].flatten
  @time_scale = 1.0
end

Instance Attribute Details

#lengthObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….….….



36
37
38
# File 'lib/zgomot/comp/perc.rb', line 36

def length
  @length
end

#percsObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….….….



36
37
38
# File 'lib/zgomot/comp/perc.rb', line 36

def percs
  @percs
end

#time_scaleObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….….….



36
37
38
# File 'lib/zgomot/comp/perc.rb', line 36

def time_scale
  @time_scale
end

#velocityObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….….….



36
37
38
# File 'lib/zgomot/comp/perc.rb', line 36

def velocity
  @velocity
end

Instance Method Details

#bpm_scale!(v) ⇒ Object

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



59
60
61
# File 'lib/zgomot/comp/perc.rb', line 59

def bpm_scale!(v)
  @time_scale = 1.0/v.to_f; self
end

#channel=(chan) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….…. channel and dispatch interface .….….….….….….….….….….….….….….….….….….….….….….….….….….



66
67
68
# File 'lib/zgomot/comp/perc.rb', line 66

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

#length_to_secObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



81
82
83
# File 'lib/zgomot/comp/perc.rb', line 81

def length_to_sec
  time_scale*Zgomot::Midi::Clock.whole_note_sec/length
end

#notesObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



50
51
52
53
54
# File 'lib/zgomot/comp/perc.rb', line 50

def notes
  @notes ||= pitches.map do |p| 
               Zgomot::Midi::Note.new(:pitch => p, :length => length, :velocity => velocity)
             end                          
end

#offset_time=(time) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



71
72
73
# File 'lib/zgomot/comp/perc.rb', line 71

def offset_time=(time)
  notes.each{|n| n.offset_time = time}
end

#pitchesObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



45
46
47
# File 'lib/zgomot/comp/perc.rb', line 45

def pitches
  percs.inject([]){|p,r| (m = Perc::PERC_MAP[r]).nil? ? p : p << m}
end

#time=(time) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



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

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

#to_midiObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



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

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