Module: Stretto::MusicElements::AttackDecay

Included in:
Chord, Note
Defined in:
lib/stretto/music_elements/modifiers/attack_decay.rb

Overview

This module encapsulates behavior for all elements that specify attack and decay values

Attack represents the “warm up” of the note, and decay its “cool down”, that is, the times it takes to the note to reach its main volume form 0 when building, and the inverse when going into silence. The default value for both is 0

Constant Summary collapse

DEFAULT_ATTACK =
64
DEFAULT_DECAY =
64

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_attackObject (readonly)

Returns the value of attribute original_attack.



14
15
16
# File 'lib/stretto/music_elements/modifiers/attack_decay.rb', line 14

def original_attack
  @original_attack
end

#original_decayObject (readonly)

Returns the value of attribute original_decay.



14
15
16
# File 'lib/stretto/music_elements/modifiers/attack_decay.rb', line 14

def original_decay
  @original_decay
end

Instance Method Details

#attackNumber

Returns Numeric value for attack, or the default one.

Returns:

  • (Number)

    Numeric value for attack, or the default one



43
44
45
# File 'lib/stretto/music_elements/modifiers/attack_decay.rb', line 43

def attack
  @original_attack.to_i(@pattern) || DEFAULT_ATTACK
end

#attack=(attack) ⇒ Object

Sets the instance variable ‘@attack` and performs validation in range

Raises:



25
26
27
28
29
30
# File 'lib/stretto/music_elements/modifiers/attack_decay.rb', line 25

def attack=(attack)
  @attack = attack || DEFAULT_ATTACK
  if @attack < 0 or @attack > 127
    raise Exceptions::InvalidValueException.new("Attack should be in the range 0..127")
  end
end

#build_attack_and_decay(original_attack, original_decay) ⇒ Object

Sets up the original attack and decay tokens



17
18
19
20
# File 'lib/stretto/music_elements/modifiers/attack_decay.rb', line 17

def build_attack_and_decay(original_attack, original_decay)
  @original_attack = original_attack
  @original_decay  = original_decay
end

#decayNumber

Returns Numeric value for delay, or the default one.

Returns:

  • (Number)

    Numeric value for delay, or the default one



48
49
50
# File 'lib/stretto/music_elements/modifiers/attack_decay.rb', line 48

def decay
  @original_decay.to_i(@pattern) || DEFAULT_DECAY
end

#decay=(decay) ⇒ Object

Sets the instance variable ‘@decay` and performs validation in range

Raises:



35
36
37
38
39
40
# File 'lib/stretto/music_elements/modifiers/attack_decay.rb', line 35

def decay=(decay)
  @decay = decay || DEFAULT_DECAY
  if @decay < 0 or @decay > 127
    raise Exceptions::InvalidValueException.new("Decay should be in the range 0..127")
  end
end