Class: TEF::Animation::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/tef/Animation/Value.rb

Constant Summary collapse

PARAM_TYPES =
[:add, :multiply, :dampen, :delay, :from, :jump, :velocity]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_num) ⇒ Value

Initialize a new Value.

Parameters:

  • value_num (Integer)

    The hardware ID of this Value. must match the ID defined in the animation slaves.



62
63
64
65
66
67
68
69
# File 'lib/tef/Animation/Value.rb', line 62

def initialize(value_num)
	@ID = value_num;

	@current = Hash.new(0);
	@changes = {}

	@is_animated = false;
end

Instance Attribute Details

#addNumeric

nil), or to specify an offset of the number grabbed from #from.

Returns:

  • (Numeric)

    The add-offset to apply to this Value. Can be used either to set the absolute target (with #from being



# File 'lib/tef/Animation/Value.rb', line 24

#dampenNumeric

Returns dampening factor. Causes the actual output value to smoothly transition to the target value ((from + add) * multiply). Larger values take longer (higher dampening).

Returns:

  • (Numeric)

    dampening factor. Causes the actual output value to smoothly transition to the target value ((from + add) * multiply). Larger values take longer (higher dampening)



# File 'lib/tef/Animation/Value.rb', line 33

#delayNumeric

Returns delay factor. If it and #dampen are nonzero, will cause the actual output to oscillate slightly. Also causes #velocity to have an effect. Higher delays cause slower transitions, and may need more #dampening to mitigate overshoot.

Returns:

  • (Numeric)

    delay factor. If it and #dampen are nonzero, will cause the actual output to oscillate slightly. Also causes #velocity to have an effect. Higher delays cause slower transitions, and may need more #dampening to mitigate overshoot.



# File 'lib/tef/Animation/Value.rb', line 38

#fromString?

Returns If not set to nil, defines the other TEF::Animation::Value that this Value will take the output from. Allows the user to follow some other parameter and create interesting linkages.

Returns:

  • (String, nil)

    If not set to nil, defines the other TEF::Animation::Value that this Value will take the output from. Allows the user to follow some other parameter and create interesting linkages.



# File 'lib/tef/Animation/Value.rb', line 45

#IDInteger (readonly)

Returns Hardware-Number of this Value.

Returns:

  • (Integer)

    Hardware-Number of this Value



18
19
20
# File 'lib/tef/Animation/Value.rb', line 18

def ID
  @ID
end

#jump=(value) ⇒ Numeric (writeonly)

Returns Instantly jump to the given number, skipping animation and smoothing. Will not reconfigure the actual target, and can thusly be used to temporarily “bump” the value.

Returns:

  • (Numeric)

    Instantly jump to the given number, skipping animation and smoothing. Will not reconfigure the actual target, and can thusly be used to temporarily “bump” the value.



# File 'lib/tef/Animation/Value.rb', line 50

#module_idString?

Returns Module-ID of the Animatable that this Value belongs to.

Returns:

  • (String, nil)

    Module-ID of the Animatable that this Value belongs to.



22
23
24
# File 'lib/tef/Animation/Value.rb', line 22

def module_id
  @module_id
end

#multiplyNumeric

Returns Multiplication factor. Will be applied to (#from + #add) * #multiply. 0 means no multiplication.

Returns:

  • (Numeric)

    Multiplication factor. Will be applied to (#from + #add) * #multiply. 0 means no multiplication.



# File 'lib/tef/Animation/Value.rb', line 29

#velocity=(value) ⇒ Numeric (writeonly)

Returns Set the velocity of the value. Only has an effect if #dampen and #delay are nonzero.

Returns:

  • (Numeric)

    Set the velocity of the value. Only has an effect if #dampen and #delay are nonzero.



# File 'lib/tef/Animation/Value.rb', line 55

Instance Method Details

#configure(data) ⇒ Object

Configure the Value with a Hash.

This lets the user configure the Value by passing a Hash. The data will be passed into the six attributes of this Value according to their key.

Examples:

a_color.configure({ add: 2, dampen: 10 })


125
126
127
128
129
130
131
132
133
134
135
# File 'lib/tef/Animation/Value.rb', line 125

def configure(data)
	if data.is_a? Numeric
		self.add = data
	elsif data.is_a? Hash
		data.each do |key, value|
			generic_set key, value
		end
	else
		self.from = data;
	end
end

#generic_set(key, value) ⇒ Object

Internal function to set any of the Value’s parameters.

This can be called by the user, but it is preferrable to use #configure or the matching parameter setter functions.

Raises:

  • (ArgumentError)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/tef/Animation/Value.rb', line 89

def generic_set(key, value)
	if key == :from
		self.from = value
		return
	end

	raise ArgumentError, 'Key does not exist!' unless PARAM_TYPES.include? key
	raise ArgumentError, "Input must be numeric!" unless value.is_a? Numeric

	return if (value == @current[key] && ![:jump, :velocity].include?(key))

	if [:multiply, :dampen, :delay].include? key
		@is_animated = true
	end

	@current[key] = value
	@changes[key] = true
end

#has_changes?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/tef/Animation/Value.rb', line 159

def has_changes?
	return !@changes.empty?
end

#set_stringObject

Note:

Do not call this as user unless you know what you are doing! This will delete the retrieved changes, which may cause loss of data if they are not properly sent to the animation slaves!

Internal function to retrieve the list of changes for this Value.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/tef/Animation/Value.rb', line 173

def set_string()
	return nil unless has_changes?

	if !@is_animated
		return nil unless @changes[:add]

		out_str = "J#{rcut(@current[:add])};"

		@changes = {}

		return out_str
	end

	out_str = [];

	out_str << "J#{rcut(@current[:jump])}" if @changes[:jump]
	out_str << "V#{rcut(@current[:velocity])}" if @changes[:velocity]

	out_str << @current[:from] if @changes[:from]

	config_strs = [];
	config_strs_out = [];
	[:add, :multiply, :dampen, :delay].each do |k|
		config_strs << rcut(@current[k])

		config_strs_out = config_strs.dup if @changes[k]
	end

	@changes = {}

	(out_str + config_strs_out).join(' ') + ';'
end

#total_idString

Returns Total ID of this Value, in the form ‘SxxMxxVxx’.

Returns:

  • (String)

    Total ID of this Value, in the form ‘SxxMxxVxx’



81
82
83
# File 'lib/tef/Animation/Value.rb', line 81

def total_id()
	"#{@module_id}V#{@ID.to_s(16)}"
end