Class: Deftones::Instrument::PluckSynth

Inherits:
Core::Instrument show all
Defined in:
lib/deftones/instrument/pluck_synth.rb

Instance Attribute Summary collapse

Attributes inherited from Core::Instrument

#mute, #output, #volume

Attributes inherited from Core::AudioNode

#context, #input

Instance Method Summary collapse

Methods inherited from Core::Instrument

#apply_volume!, #dispose, #get, #input, #mute?, #releaseAll, #release_all, #render, #render_block, #set, #triggerAttack, #triggerAttackRelease, #triggerRelease

Methods inherited from Core::AudioNode

#>>, #attach_destination, #attach_source, #block_time, #chain, #channel_count, #channel_count_mode, #channel_interpretation, #connect, #connected?, #default_input_channels, #default_output_channels, #destination_for_connection, #detach_all_destinations, #detach_destination, #detach_source, #disconnect, #dispose, #disposed?, #fan, #get, #immediate, #input_for_index, #inputs, #mix_source_blocks, #multichannel_process?, #name, #normalize_connection_index, #normalize_output_block, #now, #number_of_inputs, #number_of_outputs, #output, #output_for_connection, #output_for_index, #outputs, #process, #raise_connection_index_error!, #reaches_node?, #render, #render_block, #sample_time, #set, #to_destination, #to_frequency, #to_master, #to_midi, #to_output, #to_s, #to_seconds, #to_ticks, #uses_legacy_render_for_block?, #validate_connectable!, #validate_connection_index!

Constructor Details

#initialize(decay: 0.995, damping: 0.5, context: Deftones.context, &block) ⇒ PluckSynth

Returns a new instance of PluckSynth.



8
9
10
11
12
13
# File 'lib/deftones/instrument/pluck_synth.rb', line 8

def initialize(decay: 0.995, damping: 0.5, context: Deftones.context, &block)
  super(context: context)
  @resonator = Source::KarplusStrong.new(decay: decay, damping: damping, context: context)
  @resonator >> @output
  block&.call(self)
end

Instance Attribute Details

#resonatorObject (readonly)

Returns the value of attribute resonator.



6
7
8
# File 'lib/deftones/instrument/pluck_synth.rb', line 6

def resonator
  @resonator
end

Instance Method Details

#play(note, duration: "8n", at: nil, velocity: 1.0) ⇒ Object



15
16
17
# File 'lib/deftones/instrument/pluck_synth.rb', line 15

def play(note, duration: "8n", at: nil, velocity: 1.0)
  trigger_attack_release(note, duration, at, velocity)
end

#resolve_time(time) ⇒ Object (private)



34
35
36
37
38
# File 'lib/deftones/instrument/pluck_synth.rb', line 34

def resolve_time(time)
  return context.current_time if time.nil?

  Deftones::Music::Time.parse(time)
end

#trigger_attack(note, time = nil, velocity = 1.0) ⇒ Object



19
20
21
22
# File 'lib/deftones/instrument/pluck_synth.rb', line 19

def trigger_attack(note, time = nil, velocity = 1.0)
  @resonator.trigger(note, resolve_time(time), velocity)
  self
end

#trigger_attack_release(note, _duration, time = nil, velocity = 1.0) ⇒ Object



28
29
30
# File 'lib/deftones/instrument/pluck_synth.rb', line 28

def trigger_attack_release(note, _duration, time = nil, velocity = 1.0)
  trigger_attack(note, resolve_time(time), velocity)
end

#trigger_release(_time = nil) ⇒ Object



24
25
26
# File 'lib/deftones/instrument/pluck_synth.rb', line 24

def trigger_release(_time = nil)
  self
end