Class: Deftones::Core::SyncedSignal

Inherits:
Signal
  • Object
show all
Defined in:
lib/deftones/core/synced_signal.rb

Constant Summary

Constants inherited from Signal

Deftones::Core::Signal::EXPONENTIAL_UNITS

Instance Attribute Summary collapse

Attributes inherited from Signal

#clamp_values, #context, #convert_values, #default_value, #input, #max_value, #min_value, #output, #units

Instance Method Summary collapse

Methods inherited from Signal

#add_event, #apply, #automation_anchor_time, #automation_event_count, #automation_events?, #bounded_value, #cancel_and_hold_at_time, #cancel_scheduled_values, #coerce_value, #connect, #convert, #convert=, #convert_frequency, #convert_generic, #convert_without_units, #curve_value, #db_to_gain, #disconnect, #dispose, #disposed?, #event_sort_key, #exponential_approach_value_at_time, #exponential_ramp_to_value_at_time, #get, #get_defaults, #get_value_at_time, #immediate, #insert_event, #interpolate, #linear_ramp_to_value_at_time, #name, #now, #overridden?, #ramp_to, #safe_exponential_value, #sample_time, #schedule_automation, #set, #set_ramp_point, #set_target_at_time, #set_value_at_time, #set_value_curve_at_time, #target_ramp_to, #target_value, #to_frequency, #to_s, #to_seconds, #to_ticks, #value=, #value_at

Methods included from SignalOperatorMethods

#abs, #add, #equal_power_gain, #greater_than, #greater_than_zero, #modulo, #multiply, #negate, #normalize, #pow, #scale, #scale_exp, #subtract, #to_audio, #to_gain, #wave_shaper

Constructor Details

#initialize(transport: Deftones.transport, **options) ⇒ SyncedSignal

Returns a new instance of SyncedSignal.



8
9
10
11
12
# File 'lib/deftones/core/synced_signal.rb', line 8

def initialize(transport: Deftones.transport, **options)
  @transport = transport
  @synced = true
  super(**options)
end

Instance Attribute Details

#transportObject (readonly)

Returns the value of attribute transport.



6
7
8
# File 'lib/deftones/core/synced_signal.rb', line 6

def transport
  @transport
end

Instance Method Details

#current_base_timeObject (private)



62
63
64
# File 'lib/deftones/core/synced_signal.rb', line 62

def current_base_time
  synced? ? transport.seconds : context.current_time
end

#exponential_ramp_to(target_value, duration) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/deftones/core/synced_signal.rb', line 42

def exponential_ramp_to(target_value, duration)
  resolved_end = current_base_time + Deftones::Music::Time.parse(duration)
  schedule_automation(
    :exponential,
    coerce_value(target_value),
    start_time: resolve_automation_start_time(resolved_end),
    end_time: resolved_end
  )
end

#linear_ramp_to(target_value, duration) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/deftones/core/synced_signal.rb', line 32

def linear_ramp_to(target_value, duration)
  resolved_end = current_base_time + Deftones::Music::Time.parse(duration)
  schedule_automation(
    :linear,
    coerce_value(target_value),
    start_time: resolve_automation_start_time(resolved_end),
    end_time: resolved_end
  )
end

#process(num_frames, start_frame = 0) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/deftones/core/synced_signal.rb', line 52

def process(num_frames, start_frame = 0)
  timeline_offset = synced? ? transport.seconds : 0.0

  Array.new(num_frames) do |offset|
    value_at(timeline_offset + sample_time(start_frame + offset))
  end
end

#resolve_automation_start_time(end_time) ⇒ Object (private)



78
79
80
81
82
83
84
85
# File 'lib/deftones/core/synced_signal.rb', line 78

def resolve_automation_start_time(end_time)
  anchors = @events.filter_map do |event|
    anchor = automation_anchor_time(event)
    anchor if anchor <= end_time
  end

  anchors.max || current_base_time
end

#resolve_time(time) ⇒ Object (private)



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/deftones/core/synced_signal.rb', line 66

def resolve_time(time)
  return current_base_time if time.nil?
  return super unless synced?

  Deftones::Music::Time.parse(
    time,
    bpm: transport.bpm,
    time_signature: transport.time_signature,
    ppq: transport.ppq
  )
end

#syncObject



18
19
20
21
# File 'lib/deftones/core/synced_signal.rb', line 18

def sync
  @synced = true
  self
end

#synced?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/deftones/core/synced_signal.rb', line 28

def synced?
  @synced
end

#unsyncObject



23
24
25
26
# File 'lib/deftones/core/synced_signal.rb', line 23

def unsync
  @synced = false
  self
end

#valueObject



14
15
16
# File 'lib/deftones/core/synced_signal.rb', line 14

def value
  value_at(current_base_time)
end