module Utils

Attributes

is_bool[R]
is_float[R]
is_int[R]
is_natural_number[R]
is_real_number[R]
m1[R]
m2[R]
m3[R]
vban_ranges[R]

Public Instance Methods

bool_to_float(value) click to toggle source
# File lib/utils.rb, line 56
def bool_to_float(value)
    (value ? 1 : 0).to_f
end
bool_to_int(value) click to toggle source
# File lib/utils.rb, line 60
def bool_to_int(value)
    (value ? 1 : 0)
end
define_types() click to toggle source
# File lib/utils.rb, line 70
def define_types
    @is_bool = [
        "mono", "solo", "mute", "mc", "k",
        "A1", "A2", "A3", "B1", "B2", "B3",
        "EQ.on",
        "macrobutton",
        "on"
    ]

    @is_int = [
        "sr", "channel", "bit", "quality", "route"
    ]

    @is_float = ["gain", "comp", "gate", "limit"]

    self.is_natural_number = @is_bool.|(@is_int)
    self.is_real_number = @is_float.|(@is_natural_number)

    self.vban_ranges = {
        "on" => [0,1],
        "port" => [0,65535],
        "sr" => [11025, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000],
        "channel" => [1,8],
        "quality" => [0,4],
        "route" => [0,8],
        "bit" => [1,2]
    }
end
is_natural_number=(value) click to toggle source
# File lib/utils.rb, line 25
def is_natural_number=(value)
    @is_natural_number = value
end
is_real_number=(value) click to toggle source
# File lib/utils.rb, line 29
def is_real_number=(value)
    @is_real_number = value
end
m1=(value) click to toggle source
# File lib/utils.rb, line 5
def m1=(value)
    @m1 = value.downcase
end
m2=(value) click to toggle source
# File lib/utils.rb, line 9
def m2=(value)
    if value.to_i.to_s == value
        @m2 = value.to_i
    else
        @m2 = value
    end
end
m3=(value) click to toggle source
# File lib/utils.rb, line 17
def m3=(value)
    if value.to_i.to_s == value
        @m3 = value
    else
        @m3 = value
    end
end
shiftdn(oldnum) click to toggle source
# File lib/utils.rb, line 48
def shiftdn(oldnum)
    oldnum.to_i - 1
end
shiftup(oldnum) click to toggle source
# File lib/utils.rb, line 52
def shiftup(oldnum)
    oldnum.to_i + 1
end
test_regex(regex, param) click to toggle source
# File lib/utils.rb, line 37
def test_regex(regex, param)
    regex.match(param) do |m|
        self.m1 = m[1]
        self.m2 = m[2]
        self.m3 = m[3]
        matches = 0
        (1..m.size).each { |num| matches += 1 if m[num] }
        return matches
    end
end
type_return(param, value) click to toggle source
# File lib/utils.rb, line 64
def type_return(param, value)
    return value.to_i if @is_natural_number.include? param
    return value.round(1) if @is_float.include? param
    value
end
validate(name, num = nil) click to toggle source
# File lib/utils.rb, line 99
def validate(name, num = nil)
    """
    Validate boundaries unless param requires none
    """
    if name == "strip"
        return num < @strip_total
    elsif name == "bus"
        return num < @bus_total
    elsif name == "mb"
        return num.between?(0, 69)
    elsif ["vban", "instream", "outstream"].include? name
        return num < @vban_total
    elsif name == "composite"
        return num < @composite_total
    elsif name == "insert"
        return (num < @insert_total) if @type == POTATO
        raise VersionError
    elsif name == "reverb" || name == "delay"
        return @type == POTATO
        raise VersionError
    elsif @is_bool.include? name
        return [0,1].include? num
    elsif name == "gain"
        return num.between?(-60, 12)
    elsif name == "comp" || name == "gate"
        return num.between?(0, 10)
    elsif name == "limit"
        return num.between?(-40, 12)
    elsif @vban_ranges.has_key? name
        return @vban_ranges[name].include? num if name == "bit" || name == "sr"
        return num.between?(*@vban_ranges[name])
    end
    true
end
vban_ranges=(value) click to toggle source
# File lib/utils.rb, line 33
def vban_ranges=(value)
    @vban_ranges = value
end