class ZXUtils::MusicBox::Envelope
MusicBox
Envelope
¶ ↑
Instances of this class represent the envelopes applicable to the volume level or the noise pitch.
Attributes
code[R]
A compiled body of the evelope as a binary string.
Public Class Methods
new [counter, delta], ...
click to toggle source
new [counter, delta], ..., :loop, ..., [counter, delta]
Creates an instance of the Envelope
with the given tuples shaping the envelope.
counter
-
How many ticks should pass to reach the desired
delta
: 1 to 255. delta
-
A floating point number in the range: from -1 to 1.
:loop
-
An indicator where to go back when the end of the envelope is being reached. If not present the whole envelope is being repeated.
# File lib/zxutils/music_box/song.rb, line 438 def initialize(*args) loop_offset = nil bytes = [] args.each do |arg| case arg when Array bytes.concat Array(tuple_to_value(*arg)) when :loop raise ArgumentError, "There's more than one loop marker" unless loop_offset.nil? loop_offset = bytes.length else raise ArgumentError, "A tuple of [counter, value] is expected or :loop" end end raise ArgumentError, "Envelope requires at least one tuple argument" if bytes.empty? loop_offset = loop_offset.to_i raise ArgumentError, "Loop indicator must be placed before at least one argument tuple" if loop_offset == bytes.length raise ArgumentError, "Loop offset too large" if loop_offset > 255 @code = [loop_offset].concat(bytes).pack('c*') end