# Reference:
# https://gitlab.manjaro.org/manjaro-arm/packages/community/pinebookpro-post-install/-/blob/4b4206c57b21044bf9c00848bd1f8b6f710d19eb/asound.state
# https://gitlab.manjaro.org/manjaro-arm/packages/community/pinebookpro-audio/-/blob/1f567db09495acc3beb5405c9ef85c3c07b86785/audio_jack_plugged_in.sh
Define.MainCardId "rockchipes8326c"
Define.BtCardId "rockchipbt"
Define.Bluetooth "bluealsa"

SectionVerb {
	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info Hii_dvt:SectionVerb:EnableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Speakers Switch' off"
		cset "name='Main Mic Switch' off"
		cset "name='Headphone Switch' off"
		cset "name='Headset Mic Switch' off"
	]

	Value {
		Priority 200
	}
}

SectionDevice."Speakers" {
	Comment "Speakers"

	ConflictingDevice [
		"Headphones"
		"Headset"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Speakers:EnableSequence"
		# Enable Speakers
		cdev "hw:${var:MainCardId}"
		cset "name='Speakers Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Speakers:DisableSequence"
		# Disable Speaker
		cdev "hw:${var:MainCardId}"
		cset "name='Speakers Switch' off"
	]

	Value {
		PlaybackPriority 100
		PlaybackPCM "hw:${var:MainCardId}"
		PlaybackMasterElem "DAC Playback Volume"
		PlaybackVolume "DAC Playback Volume"
		PlaybackSwitch "Speakers Switch"
	}
}

SectionDevice."Mic" {
	Comment "Internal Microphone"

	ConflictingDevice [
		"Headset"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Mic:EnableSequence"
		# Enable Mic
		cdev "hw:${var:MainCardId}"
		cset "name='Main Mic Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Mic:DisableSequence"
		# Disable Mic
		cdev "hw:${var:MainCardId}"
		cset "name='Main Mic Switch' off"
	]

	Value {
		CapturePriority 100
		CaptureChannels "6"
		CapturePCM "hw:${var:MainCardId},1"
		CaptureMixerElem "ADC"
		CaptureSwitch "Main Mic Switch"
	}
}

SectionDevice."Headphones" {
	Comment "Headphones"

	ConflictingDevice [
		"Speakers"
		"Headset"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headphones:EnableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headphones:DisableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' off"
	]

	Value {
		PlaybackPriority 200
		PlaybackPCM "hw:${var:MainCardId}"
		PlaybackMasterElem "DAC Playback Volume"
		PlaybackVolume "DAC Playback Volume"
		PlaybackSwitch "Headphone Switch"
		JackControl "Headphone Jack"
		JackHWMute "Speakers"
	}
}

SectionDevice."Headset" {
	Comment "Headset"

	ConflictingDevice [
		"Speakers"
		"Headphones"
		"Mic"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headset:EnableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' on"
		cset "name='Headset Mic Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headset:DisableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' off"
		cset "name='Headset Mic Switch' off"
	]

	Value {
		PlaybackPriority 200
		PlaybackPCM "hw:${var:MainCardId}"
		CapturePCM "hw:${var:MainCardId}"
		PlaybackMasterElem "DAC Playback Volume"
		PlaybackVolume "DAC Playback Volume"
		PlaybackSwitch "Headphone Switch"
		CaptureMasterElem "ADC Capture Volume"
		CaptureVolume "ADC Capture Volume"
		CaptureSwitch "Headset Mic Switch"
		JackControl "Headphone Jack"
		JackHWMute "Speakers"
	}
}
