-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked the LyricsScroller a little bit.
- Not finished yet the LyricsCard has to be reworked too but its usable rn
- Loading branch information
AlexanderDotH
committed
May 4, 2023
1 parent
e0c0d05
commit 0340576
Showing
12 changed files
with
512 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenLyricsClient.Backend.Utils; | ||
|
||
public class Debouncer | ||
{ | ||
public static Func<T, Task<R>> Debounce<T, R>(Func<T, Task<R>> func, int milliseconds) | ||
{ | ||
int last = 0; | ||
return async arg => | ||
{ | ||
int current = Interlocked.Increment(ref last); | ||
await Task.Delay(milliseconds); | ||
if (current == last) | ||
return await func(arg); | ||
return default(R); | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
|
||
namespace OpenLyricsClient.Frontend.Animation; | ||
|
||
public class SmoothAnimator | ||
namespace OpenLyricsClient.Frontend.Animation | ||
{ | ||
public static float CalculateStep(float start, float end, float current, float speed) | ||
public class SmoothAnimator | ||
{ | ||
float divisor = (end - start); | ||
|
||
if (divisor == 0) | ||
return end; | ||
|
||
if (divisor == 0) | ||
divisor = 0.1F; | ||
|
||
if (current == 0) | ||
current = 1; | ||
|
||
float t = (current - start) / divisor; | ||
|
||
float speedC = (1.0F / 100.0F) * speed; | ||
float sMul = 1 + speedC; | ||
|
||
t = SmoothStep(start, end, t) / sMul; | ||
|
||
return (start + (end - start) * t); | ||
} | ||
public static double CalculateStep(double start, double end, double current, double speed) | ||
{ | ||
double divisor = (end - start); | ||
|
||
private static float SmoothStep(float start, float end, float t) | ||
{ | ||
t = Math.Clamp(((t - start) / ((end - start))), 0, 1); | ||
return t * t * (3 - 2 * t); | ||
if (divisor == 0) | ||
return end; | ||
|
||
divisor = Math.Abs(divisor) < 0.0001 ? 0.1 : divisor; | ||
|
||
if (current == 0) | ||
current = 1; | ||
|
||
double t = (current - start) / divisor; | ||
|
||
double speedC = (1.0 / 100.0) * speed; | ||
double sMul = 1 + speedC; | ||
|
||
t = SmoothStep(start, end, t) / sMul; | ||
|
||
return (start + (end - start) * t); | ||
} | ||
|
||
private static double SmoothStep(double start, double end, double t) | ||
{ | ||
t = Math.Clamp(((t - start) / ((end - start))), 0, 1); | ||
return t * t * (3 - 2 * t); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
OpenLyricsClient/Frontend/Models/Custom/NewLyricsScrollerViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using OpenLyricsClient.Backend; | ||
using OpenLyricsClient.Backend.Events.EventArgs; | ||
using OpenLyricsClient.Backend.Structure.Lyrics; | ||
|
||
namespace OpenLyricsClient.Frontend.Models.Custom; | ||
|
||
public class NewLyricsScrollerViewModel : ViewModelBase, INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
private LyricPart? _lyric; | ||
|
||
public NewLyricsScrollerViewModel() | ||
{ | ||
Core.INSTANCE.LyricHandler.LyricChanged += LyricHandlerOnLyricChanged; | ||
Core.INSTANCE.LyricHandler.LyricsFound += LyricHandlerOnLyricsFound; | ||
Core.INSTANCE.SongHandler.SongChanged += SongHandlerOnSongChanged; | ||
} | ||
|
||
private void SongHandlerOnSongChanged(object sender, SongChangedEventArgs songchangedevent) | ||
{ | ||
Lyric = null; | ||
OnPropertyChanged("Lyrics"); | ||
} | ||
|
||
private void LyricHandlerOnLyricsFound(object sender) | ||
{ | ||
OnPropertyChanged("Lyrics"); | ||
} | ||
|
||
private void LyricHandlerOnLyricChanged(object sender, LyricChangedEventArgs lyricchangedeventargs) | ||
{ | ||
Lyric = lyricchangedeventargs.LyricPart; | ||
} | ||
|
||
public LyricPart[]? Lyrics | ||
{ | ||
get => Core.INSTANCE?.SongHandler?.CurrentSong?.Lyrics?.LyricParts!; | ||
} | ||
|
||
public LyricPart? Lyric | ||
{ | ||
get => this._lyric; | ||
set => SetField(ref this._lyric, value); | ||
} | ||
|
||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null) | ||
{ | ||
if (EqualityComparer<T>.Default.Equals(field, value)) return false; | ||
field = value; | ||
OnPropertyChanged(propertyName); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
OpenLyricsClient/Frontend/View/Custom/NewLyricsScroller.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:custom="clr-namespace:OpenLyricsClient.Frontend.Models.Custom" | ||
xmlns:elements="clr-namespace:OpenLyricsClient.Frontend.Models.Elements" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="OpenLyricsClient.Frontend.View.Custom.NewLyricsScroller"> | ||
|
||
<UserControl.DataContext> | ||
<custom:NewLyricsScrollerViewModel/> | ||
</UserControl.DataContext> | ||
|
||
<Grid> | ||
<custom:CustomScrollViewer Name="CTRL_Viewer"> | ||
<Panel> | ||
<ItemsRepeater Name="HIDDEN_CTRL_Repeater" | ||
Items="{Binding Lyrics}" | ||
IsVisible="False"> | ||
<ItemsRepeater.ItemTemplate> | ||
<DataTemplate> | ||
<elements:LyricsCard Text="{Binding Part}" | ||
LyricPart="{Binding}" | ||
IgnoreEvents="False" | ||
HorizontalAlignment="Left" | ||
FontWeight="Bold" | ||
FontSize="30" | ||
Margin="0,0,0,70"/> | ||
</DataTemplate> | ||
</ItemsRepeater.ItemTemplate> | ||
</ItemsRepeater> | ||
|
||
<ItemsRepeater Name="CTRL_Repeater" | ||
Items="{Binding Lyrics}"> | ||
<ItemsRepeater.ItemTemplate> | ||
<DataTemplate> | ||
<elements:LyricsCard Text="{Binding Part}" | ||
LyricPart="{Binding}" | ||
IgnoreEvents="False" | ||
HorizontalAlignment="Left" | ||
FontWeight="Bold" | ||
FontSize="30" | ||
Margin="0,0,0,70"/> | ||
</DataTemplate> | ||
</ItemsRepeater.ItemTemplate> | ||
<ItemsRepeater.Transitions> | ||
<Transitions> | ||
<ThicknessTransition Property="Margin" Duration="0:0:0.5" Easing="CubicEaseOut" /> | ||
<DoubleTransition Property="Opacity" Duration="0:0:5.0" Easing="CubicEaseOut"></DoubleTransition> | ||
</Transitions> | ||
</ItemsRepeater.Transitions> | ||
</ItemsRepeater> | ||
</Panel> | ||
</custom:CustomScrollViewer> | ||
</Grid> | ||
|
||
</UserControl> |
Oops, something went wrong.