alias Light.isAutoOp (match, channel) {
	if (0 == match) return 0
	@function_return = (-1 != findw($channel $LIGHT.AutoOp.opList[$match]))
}

alias Light.isAutoVoice (match, channel) {
	if (0 == match) return 0
	@function_return = (-1 != findw($channel $LIGHT.AutoOp.voiceList[$match]))
}

alias Light.addAutoOp (match, channel) {
	if (0 == match) return
	@LIGHT.AutoOp.opList[$match] = uniq($LIGHT.AutoOp.opList[$match] $channel)
}

alias Light.addAutoVoice (match, channel) {
	if (0 == match) return
	@LIGHT.AutoOp.voiceList[$match] = uniq($LIGHT.AutoOp.voiceList[$match] $channel)
}

alias Light.removeAutoOp (mask, channels) {
	if ([] == channels) {
		return 0
	}
	@:match = Light.findAutoPattern($mask)
	unless (match) {
		return 0
	}
	if ([*] == channels) {
		^assign -LIGHT.AutoOp.opList.$match
	} {
		@LIGHT.AutoOp.opList[$match] = remws($channels / $LIGHT.AutoOp.opList[$match])
	}
	return 1
}

alias Light.removeAutoVoice (mask, channels) {
	if ([] == channels) {
		return 0
	}
	@:match = Light.findAutoPattern($mask)
	unless (match) {
		return 0
	}
	if ([*] == channels) {
		^assign -LIGHT.AutoOp.voiceList.$match
	} {
		@LIGHT.AutoOp.voiceList[$match] = remws($channels / $LIGHT.AutoOp.voiceList[$match])
	}
	return 1
}

alias Light.findAutoPattern (mask) {
	if (!match(*@* $mask)) {
		return 0
	}
	@function_return = findw($mask $LIGHT.AutoOp.patternList) + 1
}

alias Light.removeAutoPattern (match) {
	if (0 == match) return
	@:lim = numwords($LIGHT.AutoOp.patternList)
	for ii from $match to $lim {
		@LIGHT.AutoOp.opList[$ii] = LIGHT.AutoOp.opList[${ii+1}]
		@LIGHT.AutoOp.voiceList[$ii] = LIGHT.AutoOp.voiceList[${ii+1}]
	}
	@:match--
	@splice(LIGHT.AutoOp.patternList $match 1)
}

alias Light.addAutoPattern (mask) {
	if (!match(*@* $mask)) return 0
	push LIGHT.AutoOp.patternList $mask
	return 1
}

