# Channel mapping
#
# +----+---------------+-----------------+
# | Ch |     Inputs    |      Outputs    |
# +====+===============+=================+
# |  0 |   Line/XLR 1  |      Line 1     |
# |    |               | (Speaker Out L) |
# +----+---------------+-----------------+
# |  1 |   Line/XLR 2  |      Line 2     |
# |    |               | (Speaker Out R) |
# +----+---------------+-----------------+
# |  2 |     Line 3    |      Line 3     |
# +----+---------------+-----------------+
# |  3 |     Line 4    |      Line 4     |
# +----+---------------+-----------------+
# |  4 |     Line 5    |      Line 5     |
# +----+---------------+-----------------+
# |  5 |     Line 6    |      Line 6     |
# +----+---------------+-----------------+
# |  6 |     Line 7    |      Line 7     |
# |    |               | (Mirrored for   |
# |    |               |  Headphone 1 L) |
# +----+---------------+-----------------+
# |  7 |     Line 8    |      Line 8     |
# |    |               | (Mirrored for   |
# |    |               |  Headphone 1 R) |
# +----+---------------+-----------------+
# |  8 |               |      Line 9     |
# |    |               |  (Mirrored for  |
# |    |               |  Headphone 2 L) |
# +----+---------------+-----------------+
# |  9 |               |     Line 10     |
# |    |               | (Mirrored for   |
# |    |               |  Headphone 2 R) |
# +----+---------------+-----------------+
# | 10 |   S/PDIF 1    |     S/PDIF 1    |
# +----+---------------+-----------------+
# | 11 |   S/PDIF 2    |     S/PDIF 2    |
# +----+---------------+-----------------+
# | 12 |   ADAT 1.1    |     ADAT 1.1    |
# +----+---------------+-----------------+
# | 13 |   ADAT 1.2    |     ADAT 1.2    |
# +----+---------------+-----------------+
# | 14 |   ADAT 1.3    |     ADAT 1.3    |
# +----+---------------+-----------------+
# | 15 |   ADAT 1.4    |     ADAT 1.4    |
# +----+---------------+-----------------+
# | 16 |   ADAT 1.5    |     ADAT 1.5    |
# +----+---------------+-----------------+
# | 17 |   ADAT 1.6    |     ADAT 1.6    |
# +----+---------------+-----------------+
# | 18 |   ADAT 1.7    |     ADAT 1.7    |
# +----+---------------+-----------------+
# | 19 |   ADAT 1.8    |     ADAT 1.8    |
# +----+---------------+-----------------+
#

Define.Generation "1st"
Define.DirectPlaybackChannels 20
Define.DirectCaptureChannels 20  # fallback; overridden per generation

If.gen1 {
	Condition {
		Type RegexMatch
		String "${CardComponents}"
		Regex "USB1235:800c"
	}
	True.Define {
		DirectCaptureChannels 18
	}
}

If.gen2 {
	Condition {
		Type RegexMatch
		String "${CardComponents}"
		Regex "USB1235:8201"
	}
	True.Define {
		Generation "2nd"
		DirectCaptureChannels 18
	}
}

If.gen3 {
	Condition {
		Type RegexMatch
		String "${CardComponents}"
		Regex "USB1235:8215"
	}
	True.Define {
		Generation "3rd"
		DirectCaptureChannels 20
	}
}

If.gen4 {
	Condition {
		Type RegexMatch
		String "${CardComponents}"
		Regex "USB1235:821d"
	}
	True {
		Define {
			Generation "4th"
			DirectPlaybackChannels 26
			DirectCaptureChannels 26
			bcdDevice "${sys-card:device/../bcdDevice}"
		}
		If.fwp {
			# bcdNumbers 0900-097a
			Condition {
				Type RegexMatch
				String "${var:bcdDevice}"
				Regex "(09[0-6].|097[0-9a])"
			}
			True.Define.DirectPlaybackChannels 24
		}
		If.fwc {
			# bcdNumbers 0000-08ff, 0900-097a
			Condition {
				Type RegexMatch
				String "${var:bcdDevice}"
				Regex "(0[0-8]..|09[0-6].|097[0-9a])"
			}
			True.Define.DirectCaptureChannels 20
		}
	}
}

Comment "Focusrite Scarlett 18i20 ${var:Generation} Gen"

SectionUseCase."HiFi" {
	Comment "HiFi"
	File "/USB-Audio/Focusrite/Scarlett-18i20-HiFi.conf"
}

Include.dhw.File "/common/directm.conf"

Macro.0.DirectUseCase {
	Id="Direct 48kHz"
	PlaybackChannels="${var:DirectPlaybackChannels}"
	PlaybackRate=48000
	CaptureChannels="${var:DirectCaptureChannels}"
	CaptureRate=48000
}
#
# Uncomment when tested!
#
#Macro.1.DirectUseCase {
#	Id="Direct 96kHz"
#	PlaybackChannels=16
#	PlaybackRate=96000
#	CaptureChannels=16
#	CaptureRate=96000
#}
#Macro.2.DirectUseCase {
#	Id="Direct 192kHz"
#	PlaybackChannels=10
#	PlaybackRate=192000
#	CaptureChannels=10
#	CaptureRate=192000
#}
