feat(library): add bit depth quality label mode

This commit is contained in:
zarzet
2026-08-23 11:42:47 +07:00
parent aec7bf7a1b
commit c6437d8428
6 changed files with 65 additions and 7 deletions
+3 -2
View File
@@ -7,6 +7,7 @@ part 'settings.g.dart';
class AppSettings {
static const String homeFeedProviderOff = '__off__';
static const String libraryQualityLabelBitrate = 'bitrate';
static const String libraryQualityLabelBitDepthOnly = 'bit_depth_only';
static const String libraryQualityLabelBitDepth = 'bit_depth';
static const String libraryQualityLabelBitDepthBitrate = 'bit_depth_bitrate';
@@ -41,8 +42,8 @@ class AppSettings {
/// 'last' (keep last used), 'all', 'albums', 'singles', or 'playlists'.
final String defaultLibraryView;
/// Library badge text: measured bitrate, bit depth/sample rate, or the
/// combined bit depth/bitrate label.
/// Library badge text: measured bitrate, bit depth, bit depth/sample rate,
/// or the combined bit depth/bitrate label.
final String libraryQualityLabelMode;
final bool askQualityBeforeDownload;
final bool enableLogging;
+2
View File
@@ -381,6 +381,8 @@ class SettingsNotifier extends Notifier<AppSettings> {
String _normalizeLibraryQualityLabelMode(String value) {
return switch (value) {
AppSettings.libraryQualityLabelBitDepthOnly =>
AppSettings.libraryQualityLabelBitDepthOnly,
AppSettings.libraryQualityLabelBitDepth =>
AppSettings.libraryQualityLabelBitDepth,
AppSettings.libraryQualityLabelBitDepthBitrate =>
@@ -435,6 +435,9 @@ class _LibrarySettingsPageState extends ConsumerState<LibrarySettingsPage> {
}
String _getQualityLabelModeLabel(BuildContext context, String mode) {
if (mode == AppSettings.libraryQualityLabelBitDepthOnly) {
return context.l10n.audioAnalysisBitDepth;
}
if (mode == AppSettings.libraryQualityLabelBitDepth) {
return '${context.l10n.audioAnalysisBitDepth} & '
'${context.l10n.audioAnalysisSampleRate}';
@@ -454,6 +457,11 @@ class _LibrarySettingsPageState extends ConsumerState<LibrarySettingsPage> {
Icons.speed_rounded,
context.l10n.trackConvertBitrate,
),
(
AppSettings.libraryQualityLabelBitDepthOnly,
Icons.tune_rounded,
context.l10n.audioAnalysisBitDepth,
),
(
AppSettings.libraryQualityLabelBitDepth,
Icons.graphic_eq_rounded,
+21 -1
View File
@@ -11,6 +11,8 @@ final RegExp _bitDepthQualityPattern = RegExp(
String normalizeLibraryQualityLabelMode(String? mode) {
return switch (mode) {
AppSettings.libraryQualityLabelBitDepthOnly =>
AppSettings.libraryQualityLabelBitDepthOnly,
AppSettings.libraryQualityLabelBitDepth =>
AppSettings.libraryQualityLabelBitDepth,
AppSettings.libraryQualityLabelBitDepthBitrate =>
@@ -32,9 +34,13 @@ String? buildLibraryAudioQualityLabel({
}) {
final stored = normalizeOptionalString(storedQuality);
final storedBitrate = _bitrateFromStoredQuality(stored);
final storedBitDepth = _bitDepthFromStoredQuality(stored);
final effectiveBitrate = bitrateKbps != null && bitrateKbps > 0
? bitrateKbps
: storedBitrate;
final effectiveBitDepth = bitDepth != null && bitDepth > 0
? bitDepth
: storedBitDepth;
final bitrateLabel = effectiveBitrate != null
? buildDisplayAudioQuality(bitrateKbps: effectiveBitrate, format: format)
: null;
@@ -42,6 +48,9 @@ String? buildLibraryAudioQualityLabel({
bitDepth != null && bitDepth > 0 && sampleRate != null && sampleRate > 0
? buildDisplayAudioQuality(bitDepth: bitDepth, sampleRate: sampleRate)
: null;
final bitDepthOnlyLabel = effectiveBitDepth != null
? '$effectiveBitDepth-bit'
: null;
final normalizedMode = normalizeLibraryQualityLabelMode(mode);
if (isLossyAudioFormat(format)) {
@@ -49,11 +58,13 @@ String? buildLibraryAudioQualityLabel({
}
return switch (normalizedMode) {
AppSettings.libraryQualityLabelBitDepthOnly =>
bitDepthOnlyLabel ?? bitrateLabel ?? stored,
AppSettings.libraryQualityLabelBitDepth =>
bitDepthLabel ?? bitrateLabel ?? stored,
AppSettings.libraryQualityLabelBitDepthBitrate =>
_buildBitDepthBitrateLabel(
bitDepth: bitDepth,
bitDepth: effectiveBitDepth,
bitrateKbps: effectiveBitrate,
) ??
bitrateLabel ??
@@ -77,6 +88,15 @@ int? _bitrateFromStoredQuality(String? quality) {
return unit == 'mbps' ? (value * 1000).round() : value.round();
}
int? _bitDepthFromStoredQuality(String? quality) {
final match = RegExp(
r'\b(\d{1,3})(?:\s*[- ]?\s*bit\b|(?=/))',
caseSensitive: false,
).firstMatch(quality ?? '');
final value = int.tryParse(match?.group(1) ?? '');
return value != null && value > 0 ? value : null;
}
String? _buildBitDepthBitrateLabel({int? bitDepth, int? bitrateKbps}) {
if (bitDepth == null ||
bitDepth <= 0 ||