Class: Deftones::Instrument::DuoSynth
- Inherits:
-
Core::Instrument
- Object
- Core::AudioNode
- Core::Instrument
- Deftones::Instrument::DuoSynth
- Defined in:
- lib/deftones/instrument/duo_synth.rb
Instance Attribute Summary collapse
-
#envelope ⇒ Object
readonly
Returns the value of attribute envelope.
-
#voice_a ⇒ Object
readonly
Returns the value of attribute voice_a.
-
#voice_b ⇒ Object
readonly
Returns the value of attribute voice_b.
Attributes inherited from Core::Instrument
Attributes inherited from Core::AudioNode
Instance Method Summary collapse
- #detune_ratio(cents) ⇒ Object private
-
#initialize(type: :sawtooth, detune: 7.0, harmonicity: 1.5, attack: 0.01, decay: 0.12, sustain: 0.45, release: 0.4, context: Deftones.context, &block) ⇒ DuoSynth
constructor
A new instance of DuoSynth.
- #play(note, duration: "8n", at: nil, velocity: 1.0) ⇒ Object
- #resolve_time(time) ⇒ Object private
- #trigger_attack(note, time = nil, velocity = 1.0) ⇒ Object
- #trigger_attack_release(note, duration, time = nil, velocity = 1.0) ⇒ Object
- #trigger_release(time = nil) ⇒ Object
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(type: :sawtooth, detune: 7.0, harmonicity: 1.5, attack: 0.01, decay: 0.12, sustain: 0.45, release: 0.4, context: Deftones.context, &block) ⇒ DuoSynth
Returns a new instance of DuoSynth.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/deftones/instrument/duo_synth.rb', line 8 def initialize(type: :sawtooth, detune: 7.0, harmonicity: 1.5, attack: 0.01, decay: 0.12, sustain: 0.45, release: 0.4, context: Deftones.context, &block) super(context: context) @voice_a = Source::OmniOscillator.new(type: type, context: context) @voice_b = Source::OmniOscillator.new(type: type, context: context) @detune = detune.to_f @harmonicity = harmonicity.to_f @envelope = Component::AmplitudeEnvelope.new( attack: attack, decay: decay, sustain: sustain, release: release, context: context ) @voice_a.start(0.0) @voice_b.start(0.0) @voice_a >> @envelope @voice_b >> @envelope @envelope >> @output block&.call(self) end |
Instance Attribute Details
#envelope ⇒ Object (readonly)
Returns the value of attribute envelope.
6 7 8 |
# File 'lib/deftones/instrument/duo_synth.rb', line 6 def envelope @envelope end |
#voice_a ⇒ Object (readonly)
Returns the value of attribute voice_a.
6 7 8 |
# File 'lib/deftones/instrument/duo_synth.rb', line 6 def voice_a @voice_a end |
#voice_b ⇒ Object (readonly)
Returns the value of attribute voice_b.
6 7 8 |
# File 'lib/deftones/instrument/duo_synth.rb', line 6 def voice_b @voice_b end |
Instance Method Details
#detune_ratio(cents) ⇒ Object (private)
57 58 59 |
# File 'lib/deftones/instrument/duo_synth.rb', line 57 def detune_ratio(cents) 2.0**(cents.to_f / 1200.0) end |
#play(note, duration: "8n", at: nil, velocity: 1.0) ⇒ Object
30 31 32 |
# File 'lib/deftones/instrument/duo_synth.rb', line 30 def play(note, duration: "8n", at: nil, velocity: 1.0) trigger_attack_release(note, duration, at, velocity) end |
#resolve_time(time) ⇒ Object (private)
61 62 63 64 65 |
# File 'lib/deftones/instrument/duo_synth.rb', line 61 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
34 35 36 37 38 39 40 41 |
# File 'lib/deftones/instrument/duo_synth.rb', line 34 def trigger_attack(note, time = nil, velocity = 1.0) scheduled_time = resolve_time(time) frequency = Deftones::Music::Note.to_frequency(note) @voice_a.frequency.set_value_at_time(frequency * detune_ratio(-@detune), scheduled_time) @voice_b.frequency.set_value_at_time((frequency * @harmonicity) * detune_ratio(@detune), scheduled_time) @envelope.trigger_attack(scheduled_time, velocity) self end |
#trigger_attack_release(note, duration, time = nil, velocity = 1.0) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/deftones/instrument/duo_synth.rb', line 48 def trigger_attack_release(note, duration, time = nil, velocity = 1.0) scheduled_time = resolve_time(time) trigger_attack(note, scheduled_time, velocity) trigger_release(scheduled_time + Deftones::Music::Time.parse(duration)) self end |
#trigger_release(time = nil) ⇒ Object
43 44 45 46 |
# File 'lib/deftones/instrument/duo_synth.rb', line 43 def trigger_release(time = nil) @envelope.trigger_release(resolve_time(time)) self end |