Skip to content

Commit

Permalink
chore: refactor waveform scale map to list
Browse files Browse the repository at this point in the history
- allow offset for waveform scale list
  • Loading branch information
MSOB7YY committed Nov 20, 2024
1 parent e898206 commit 1e9389d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
5 changes: 2 additions & 3 deletions lib/base/settings_file_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ import 'dart:io';

import 'package:flutter/foundation.dart';

import 'package:namida/core/constants.dart';
import 'package:namida/core/extensions.dart';

mixin SettingsFileWriter {
String get filePath;
Object get jsonToWrite;
Duration get delay => const Duration(seconds: 2);

static const _isKuru = bool.fromEnvironment('IS_KURU_BUILD');

void applyKuruSettings();

@protected
dynamic prepareSettingsFile_() {
final file = File(filePath);
if (!file.existsSync()) {
if (_isKuru) applyKuruSettings();
if (isKuru) applyKuruSettings();
return null;
}
try {
Expand Down
19 changes: 13 additions & 6 deletions lib/controller/waveform_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:namida/controller/platform/waveform_extractor/waveform_extractor.dart';
import 'package:namida/controller/settings_controller.dart';
import 'package:namida/core/constants.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/core/utils.dart';

Expand All @@ -17,13 +18,15 @@ class WaveformController {

List<double> _currentWaveform = [];

var _currentScaleMap = <int, double>{};
var _currentScaleLookup = <double>[];
int _currentScaleMaxIndex = -1;

bool get isDummy => _currentWaveform.isEmpty;

void resetWaveform() {
_currentWaveform = [];
_currentScaleMap = {};
_currentScaleLookup = [];
_currentScaleMaxIndex = -1;
_isWaveformUIEnabled.value = false;
}

Expand All @@ -50,14 +53,15 @@ class WaveformController {
if (waveformData.isNotEmpty && stillPlaying(path)) {
// ----- Updating [_currentWaveform]
const maxWaveformCount = 2000;
final numberOfScales = duration.inMilliseconds ~/ 50;
final numberOfScales = duration.inMilliseconds ~/ _positionDividor;
final downscaledLists = await _downscaledWaveformLists.thready((
targetSizes: [maxWaveformCount, numberOfScales],
original: waveformData,
));

_currentWaveform = downscaledLists[maxWaveformCount] ?? [];
_currentScaleMap = downscaledLists[numberOfScales]?.asMap() ?? {};
_currentScaleLookup = downscaledLists[numberOfScales] ?? [];
_currentScaleMaxIndex = _currentScaleLookup.length - 1;

calculateUIWaveform();
}
Expand Down Expand Up @@ -104,9 +108,12 @@ class WaveformController {
return newLists;
}

static const _positionDividor = 50;
static const _positionDividorWithOffset = isKuru ? _positionDividor - 3.58 : 50;

double getCurrentAnimatingScale(int positionInMs) {
final posInMap = positionInMs ~/ 50;
final dynamicScale = _currentScaleMap[posInMap] ?? 0.01;
final posInMap = positionInMs ~/ _positionDividorWithOffset;
final dynamicScale = posInMap > _currentScaleMaxIndex ? 0.01 : _currentScaleLookup[posInMap];
final intensity = settings.animatingThumbnailIntensity.value;
final finalScale = dynamicScale * intensity * 0.00005;
if (finalScale.isNaN || finalScale > 0.3) return 0.01;
Expand Down
2 changes: 2 additions & 0 deletions lib/core/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ final Set<String> kInitialDirectoriesToScan = {};
const Color kMainColorLight = Color(0xFF9c99c1);
const Color kMainColorDark = Color(0xFF4e4c72);

const isKuru = bool.fromEnvironment('IS_KURU_BUILD');

abstract class NamidaLinkRegex {
static const url = r'https?://([\w-]+\.)+[\w-]+(/[\w-./?%&@\$=~#+]*)?';
static const phoneNumber = r'[+0]\d+[\d-]+\d';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 4.7.02-beta+241120011
version: 4.7.04-beta+241120012

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 1e9389d

Please sign in to comment.