Class: Chaussettes::Effect::Synth

Inherits:
Object
  • Object
show all
Defined in:
lib/chaussettes/effect/synth.rb

Overview

Represents a synth effect

Constant Summary collapse

OPT_NAMES =
%i(bias shift p1 p2 p3).freeze
DEFAULTS =
{ bias: 0, shift: 0 }.freeze
SWEEPS =
{
  linear: ':',
  square: '+',
  exponential: '/', exp: '/',
  exp2: '-'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length = nil, type = nil) {|_self| ... } ⇒ Synth

Returns a new instance of Synth.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chaussettes/effect/synth.rb', line 8

def initialize(length = nil, type = nil)
  @length = length
  @type = type

  @just_intonation = nil
  @combine = nil
  @start_tone = nil
  @end_tone = nil
  @headroom = true

  yield self if block_given?

  _build_commands
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



6
7
8
# File 'lib/chaussettes/effect/synth.rb', line 6

def commands
  @commands
end

Instance Method Details

#_append_opts(opts) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/chaussettes/effect/synth.rb', line 47

def _append_opts(opts)
  return unless opts && opts.any?

  OPT_NAMES.each do |opt|
    value = opts[opt] || DEFAULTS[opt]
    break unless value
    @commands << value
  end
end

#_append_start_paramsObject



38
39
40
41
42
# File 'lib/chaussettes/effect/synth.rb', line 38

def _append_start_params
  return unless @length
  @commands << @length
  _append_opts @start_opts
end

#_append_tonesObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chaussettes/effect/synth.rb', line 57

def _append_tones
  return unless @start_tone

  tone = if @end_tone
           "#{@start_tone}#{@sweep}#{@end_tone}"
         else
           @start_tone
         end

  @commands << tone

  _append_opts @end_opts
end

#_build_commandsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chaussettes/effect/synth.rb', line 23

def _build_commands
  @commands = [ 'synth' ]
  @commands << '-j' << @just_intonation if @just_intonation
  @commands << '-n' unless @headroom

  _append_start_params

  @commands << @type if @type
  @commands << @combine if @combine

  _append_tones

  @commands.freeze
end

#combine(method) ⇒ Object



81
82
83
84
# File 'lib/chaussettes/effect/synth.rb', line 81

def combine(method)
  @combine = method
  self
end

#end_tone(end_tone, sweep = :linear, opts = {}) ⇒ Object

options are:

bias:
shift:
p1:
p2:
p3:


114
115
116
117
118
119
# File 'lib/chaussettes/effect/synth.rb', line 114

def end_tone(end_tone, sweep = :linear, opts = {})
  @end_tone = end_tone
  @sweep = SWEEPS.fetch(sweep, sweep)
  @end_opts = opts
  self
end

#headroom(enabled) ⇒ Object



71
72
73
74
# File 'lib/chaussettes/effect/synth.rb', line 71

def headroom(enabled)
  @headroom = enabled
  self
end

#just_intonation(semitones) ⇒ Object



76
77
78
79
# File 'lib/chaussettes/effect/synth.rb', line 76

def just_intonation(semitones)
  @just_intonation = semitones
  self
end

#length(len) ⇒ Object



86
87
88
89
# File 'lib/chaussettes/effect/synth.rb', line 86

def length(len)
  @length = len
  self
end

#start_tone(start_tone, opts = {}) ⇒ Object

options are:

bias:
shift:
p1:
p2:
p3:


102
103
104
105
106
# File 'lib/chaussettes/effect/synth.rb', line 102

def start_tone(start_tone, opts = {})
  @start_tone = start_tone
  @start_opts = opts
  self
end

#type(type) ⇒ Object



91
92
93
94
# File 'lib/chaussettes/effect/synth.rb', line 91

def type(type)
  @type = type
  self
end