2023-07-07 02:33:49 +01:00
|
|
|
require_relative "iremote"
|
|
|
|
require_relative "meta"
|
2023-08-10 20:37:35 +01:00
|
|
|
require_relative "logger"
|
2023-07-07 02:33:49 +01:00
|
|
|
|
|
|
|
module Voicemeeter
|
|
|
|
module Button
|
|
|
|
module ButtonEnum
|
|
|
|
STATE = 1
|
|
|
|
STATEONLY = 2
|
|
|
|
TRIGGER = 3
|
2023-08-10 20:37:35 +01:00
|
|
|
|
|
|
|
def identifier(val)
|
|
|
|
[nil, :state, :stateonly, :trigger][val]
|
|
|
|
end
|
|
|
|
|
|
|
|
module_function :identifier
|
2023-07-07 02:33:49 +01:00
|
|
|
end
|
|
|
|
|
2023-07-23 11:04:04 +01:00
|
|
|
module ButtonColorMixin
|
|
|
|
def identifier
|
|
|
|
"command.button[#{@index}]"
|
|
|
|
end
|
|
|
|
|
|
|
|
def color
|
|
|
|
method(:getter).super_method.call("color").to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def color=(val)
|
|
|
|
method(:setter).super_method.call("color", val)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-27 10:58:26 +01:00
|
|
|
class Base
|
|
|
|
# Base class for Button types
|
2023-08-10 20:37:35 +01:00
|
|
|
include Logging
|
2023-07-27 10:58:26 +01:00
|
|
|
include IRemote
|
2023-07-23 11:04:04 +01:00
|
|
|
include ButtonColorMixin
|
|
|
|
|
2023-07-17 14:13:39 +01:00
|
|
|
def getter(mode)
|
2023-08-10 20:37:35 +01:00
|
|
|
logger.debug "getter: button[#{@index}].#{ButtonEnum.identifier(mode)}"
|
2023-07-17 14:13:39 +01:00
|
|
|
@remote.get_buttonstatus(@index, mode)
|
2023-07-07 02:33:49 +01:00
|
|
|
end
|
|
|
|
|
2023-07-17 14:13:39 +01:00
|
|
|
def setter(mode, val)
|
2023-08-10 20:37:35 +01:00
|
|
|
logger.debug "setter: button[#{@index}].#{ButtonEnum.identifier(mode)}=#{val}"
|
2023-07-17 14:13:39 +01:00
|
|
|
@remote.set_buttonstatus(@index, mode, val)
|
2023-07-07 02:33:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def state
|
2023-07-17 14:13:39 +01:00
|
|
|
getter(ButtonEnum::STATE) == 1
|
2023-07-07 02:33:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def state=(value)
|
|
|
|
setter(ButtonEnum::STATE, value && 1 || 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stateonly
|
2023-07-17 14:13:39 +01:00
|
|
|
getter(ButtonEnum::STATEONLY) == 1
|
2023-07-07 02:33:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def stateonly=(value)
|
|
|
|
setter(ButtonEnum::STATEONLY, value && 1 || 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def trigger
|
2023-07-17 14:13:39 +01:00
|
|
|
getter(ButtonEnum::TRIGGER) == 1
|
2023-07-07 02:33:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def trigger=(value)
|
|
|
|
setter(ButtonEnum::TRIGGER, value && 1 || 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|