Skip to content

Commit

Permalink
perf: miniplayer & others ui performance/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed May 9, 2024
1 parent 2fcfd1e commit 6c041c0
Show file tree
Hide file tree
Showing 14 changed files with 1,634 additions and 1,743 deletions.
16 changes: 12 additions & 4 deletions lib/controller/waveform_controller.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:waveform_extractor/waveform_extractor.dart';

import 'package:namida/controller/settings_controller.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/ui/widgets/waveform.dart';

class WaveformController {
static WaveformController get inst => _instance;
static final WaveformController _instance = WaveformController._internal();
WaveformController._internal();

List<double> _currentWaveform = [];
final waveBarsKey = GlobalKey<WaveformComponentState>();
final waveBarsAltKey = GlobalKey<WaveformComponentState>();

List<double> currentWaveformUI = [];

final currentWaveformUI = <double>[].obs;
List<double> _currentWaveform = [];

final RxMap<int, double> _currentScaleMap = <int, double>{}.obs;

bool get isDummy => _currentWaveform.isEmpty;

void resetWaveform() {
_currentWaveform = [];
currentWaveformUI.value = List.filled(settings.waveformTotalBars.value, 2.0);
waveBarsKey.currentState?.setEnabled(false);
waveBarsAltKey.currentState?.setEnabled(false);
}

/// Extracts waveform data from a given track, or immediately read from .wave file if exists, then assigns wavedata to [_currentWaveform].
Expand Down Expand Up @@ -62,7 +68,9 @@ class WaveformController {
targetSize: userBars,
original: _currentWaveform,
));
currentWaveformUI.value = waveform;
currentWaveformUI = waveform;
waveBarsKey.currentState?.setEnabled(true);
waveBarsAltKey.currentState?.setEnabled(true);
}

static List<double> _calculateUIWaveformIsolate(({List<double> original, int targetSize}) params) {
Expand Down
127 changes: 66 additions & 61 deletions lib/packages/lyrics_lrc_parsed_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:namida/controller/current_color.dart';
import 'package:namida/controller/lyrics_controller.dart';
import 'package:namida/controller/player_controller.dart';
import 'package:namida/controller/settings_controller.dart';
import 'package:namida/controller/waveform_controller.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/core/icon_fonts/broken_icons.dart';
import 'package:namida/packages/miniplayer_base.dart';
Expand Down Expand Up @@ -177,6 +178,67 @@ class LyricsLRCParsedViewState extends State<LyricsLRCParsedView> {
final initialFontSize = fullscreen ? 25.0 : 15.0;
final normalTextStyle = context.textTheme.displayMedium!.copyWith(fontSize: _fontMultiplier * initialFontSize.multipliedFontScale);

final bottomControlsChildren = fullscreen
? [
WaveformMiniplayer(fixPadding: true, waveKey: WaveformController.inst.waveBarsAltKey),
const SizedBox(height: 8.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
NamidaHero(
enabled: false,
tag: 'MINIPLAYER_POSITION',
child: Obx(
() => Text(
Player.inst.nowPlayingPosition.milliSecondsLabel,
style: context.textTheme.displaySmall,
),
),
),
const Spacer(),
NamidaIconButton(
icon: Broken.previous,
iconSize: 24.0,
onPressed: () {
Player.inst.previous();
},
),
Obx(
() => NamidaIconButton(
horizontalPadding: 18.0,
icon: Player.inst.isPlaying ? Broken.pause : Broken.play,
iconSize: 32.0,
onPressed: () {
Player.inst.togglePlayPause();
},
),
),
NamidaIconButton(
icon: Broken.next,
iconSize: 24.0,
onPressed: () {
Player.inst.next();
},
),
const Spacer(),
NamidaHero(
enabled: false,
tag: 'MINIPLAYER_DURATION',
child: Obx(
() => Text(
Player.inst.nowPlayingTrack.duration.secondsLabel,
style: context.textTheme.displaySmall,
),
),
),
const Spacer(),
],
),
const SizedBox(height: 12.0),
SizedBox(height: MediaQuery.paddingOf(context).bottom),
]
: [];
return Stack(
alignment: Alignment.center,
children: [
Expand Down Expand Up @@ -235,15 +297,16 @@ class LyricsLRCParsedViewState extends State<LyricsLRCParsedView> {
final text = Lyrics.inst.currentLyricsText.value;
if (text != '') {
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
controller: Lyrics.inst.textScrollController,
child: Column(
children: [
SizedBox(height: context.height * 0.3),
const SizedBox(height: 48.0),
Text(
text,
style: normalTextStyle,
),
SizedBox(height: context.height * 0.3),
const SizedBox(height: 48.0),
],
),
);
Expand Down Expand Up @@ -355,65 +418,7 @@ class LyricsLRCParsedViewState extends State<LyricsLRCParsedView> {
],
),
),
if (fullscreen) ...[
const WaveformMiniplayer(fixPadding: true),
const SizedBox(height: 8.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
NamidaHero(
enabled: false,
tag: 'MINIPLAYER_POSITION',
child: Obx(
() => Text(
Player.inst.nowPlayingPosition.milliSecondsLabel,
style: context.textTheme.displaySmall,
),
),
),
const Spacer(),
NamidaIconButton(
icon: Broken.previous,
iconSize: 24.0,
onPressed: () {
Player.inst.previous();
},
),
Obx(
() => NamidaIconButton(
horizontalPadding: 18.0,
icon: Player.inst.isPlaying ? Broken.pause : Broken.play,
iconSize: 32.0,
onPressed: () {
Player.inst.togglePlayPause();
},
),
),
NamidaIconButton(
icon: Broken.next,
iconSize: 24.0,
onPressed: () {
Player.inst.next();
},
),
const Spacer(),
NamidaHero(
enabled: false,
tag: 'MINIPLAYER_DURATION',
child: Obx(
() => Text(
Player.inst.nowPlayingTrack.duration.secondsLabel,
style: context.textTheme.displaySmall,
),
),
),
const Spacer(),
],
),
const SizedBox(height: 12.0),
SizedBox(height: MediaQuery.paddingOf(context).bottom),
]
...bottomControlsChildren,
],
),
),
Expand Down
Loading

0 comments on commit 6c041c0

Please sign in to comment.