Skip to content

Commit

Permalink
LyricsTile implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDotH committed May 7, 2023
1 parent 1c65be4 commit c9ea05e
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using OpenLyricsClient.Shared.Structure.Lyrics;

namespace OpenLyricsClient.Backend.Events.EventArgs;

public class LyricsPercentageUpdatedEventArgs
{
private LyricPart _lyricPart;
private double _percentage;

public LyricsPercentageUpdatedEventArgs(LyricPart lyricPart, double percentage)
{
this._lyricPart = lyricPart;
this._percentage = percentage;
}

public LyricPart LyricPart
{
get => _lyricPart;
set => _lyricPart = value;
}

public double Percentage
{
get => this._percentage;
set => this._percentage = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System;
using OpenLyricsClient.Backend.Events.EventArgs;

namespace OpenLyricsClient.Backend.Events.EventHandler;

public delegate void LyricsPercentageUpdatedEventHandler(Object sender, LyricsPercentageUpdatedEventArgs args);
10 changes: 10 additions & 0 deletions OpenLyricsClient/Backend/Handler/Lyrics/LyricHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class LyricHandler : IHandler

public event LyricChangedEventHandler LyricChanged;
public event LyricsFoundEventHandler LyricsFound;
public event LyricsPercentageUpdatedEventHandler LyricsPercentageUpdated;

public LyricHandler(SongHandler songHandler)
{
Expand Down Expand Up @@ -88,6 +89,7 @@ private void OnLyricChanged(object sender, LyricChangedEventArgs lyricChangedEve
double change = Math.Round((double)(100 * currentTime) / time);

lyricChangedEventArgs.LyricPart.Percentage = change;
PercentageUpdatedEvent(lyricChangedEventArgs.LyricPart, change);
}
}
else
Expand All @@ -99,6 +101,7 @@ private void OnLyricChanged(object sender, LyricChangedEventArgs lyricChangedEve
double change = Math.Round((double)(100 * currentTime) / time);

lyricChangedEventArgs.LyricPart.Percentage = change;
PercentageUpdatedEvent(lyricChangedEventArgs.LyricPart, change);
}
}
}
Expand Down Expand Up @@ -245,6 +248,13 @@ protected virtual void LyricsFoundEvent()
foundEventHandler?.Invoke(this);
}

protected virtual void PercentageUpdatedEvent(LyricPart lyricPart, double percentage)
{
LyricsPercentageUpdatedEventArgs args = new LyricsPercentageUpdatedEventArgs(lyricPart, percentage);
LyricsPercentageUpdatedEventHandler handler = LyricsPercentageUpdated;
handler?.Invoke(this, args);
}

public void Dispose()
{
this._disposed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.IO;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Layout;
using Avalonia.Media;
using DevBase.Api.Serializer;
using DevBase.Generics;
using Newtonsoft.Json;
Expand Down Expand Up @@ -63,7 +66,11 @@ public JObject Defaults()
{
Selection = EnumLyricsDisplayMode.KARAOKE,
ArtworkBackground = false,
LyricsBlur = false
LyricsBlur = false,
LyricsAlignment = HorizontalAlignment.Left,
LyricsMargin = new Thickness(0,0,0,70),
LyricsWeight = FontWeight.Bold,
LyricsSize = 30
};

return new JsonDeserializer().Serialize(structure);
Expand Down
17 changes: 16 additions & 1 deletion OpenLyricsClient/Backend/Settings/Sections/Lyrics/Structure.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Newtonsoft.Json;
using Avalonia;
using Avalonia.Layout;
using Avalonia.Media;
using Newtonsoft.Json;
using OpenLyricsClient.Shared.Structure.Enum;

namespace OpenLyricsClient.Backend.Settings.Sections.Lyrics;
Expand All @@ -8,6 +11,18 @@ public class Structure
[JsonProperty("Selection Mode")]
public EnumLyricsDisplayMode Selection { get; set; }

[JsonProperty("Lyrics Size")]
public double LyricsSize { get; set; }

[JsonProperty("Lyrics Weight")]
public FontWeight LyricsWeight { get; set; }

[JsonProperty("Lyrics Alignment")]
public HorizontalAlignment LyricsAlignment { get; set; }

[JsonProperty("Lyrics Margin")]
public Thickness LyricsMargin { get; set; }

[JsonProperty("Artwork Background")]
public bool ArtworkBackground { get; set; }

Expand Down
10 changes: 0 additions & 10 deletions OpenLyricsClient/Frontend/Animation/SmoothAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,10 @@ public static double Lerp(double a, double b, int tMilliseconds, double speed, E
progress = CircularEaseOut(t, range);
break;
}
default:
{
progress = Linear(t);
break;
}
}

return min + progress * (max - min);
}

private static double Linear(double t)
{
return Math.Pow(t, 3);
}

private static double Sigmoid(double t, double range)
{
Expand Down
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 Avalonia;
using Avalonia.Layout;
using Avalonia.Media;
using OpenLyricsClient.Backend;
using OpenLyricsClient.Backend.Events.EventArgs;
using OpenLyricsClient.Backend.Settings.Sections.Lyrics;

namespace OpenLyricsClient.Frontend.Models.Custom.Tile.Overlays;

public class TextOverlayViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;

public TextOverlayViewModel()
{
Core.INSTANCE.SettingsHandler.SettingsChanged += SettingsHandlerOnSettingsChanged;
}

private void SettingsHandlerOnSettingsChanged(object sender, SettingsChangedEventArgs settingschangedeventargs)
{
OnPropertyChanged("LyricsSize");
OnPropertyChanged("LyricsWeight");
OnPropertyChanged("LyricsAlignment");
OnPropertyChanged("LyricsMargin");
}

public double LyricsSize
{
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>().GetValue<double>("Lyrics Size");
}

public FontWeight LyricsWeight
{
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>().GetValue<FontWeight>("Lyrics Weight");
}

public HorizontalAlignment LyricsAlignment
{
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>().GetValue<HorizontalAlignment>("Lyrics Alignment");
}

public Thickness LyricsMargin
{
get => Core.INSTANCE.SettingsHandler.Settings<LyricsSection>().GetValue<Thickness>("Lyrics Margin");
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum EnumAnimationStyle
{
LINEAR, CIRCULAREASEOUT, SIGMOID
CIRCULAREASEOUT, SIGMOID
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void UiThreadRenderTimerOnTick(TimeSpan obj)
y = SmoothAnimator.Lerp(
this._currentScrollOffset,
this._nextScrollOffset,
(int)obj.Milliseconds, this._speed, EnumAnimationStyle.SIGMOID);
(int)obj.Milliseconds, this._speed, EnumAnimationStyle.CIRCULAREASEOUT);
}
else if (!this.IsSynced && this._isSyncing)
{
Expand Down Expand Up @@ -295,7 +295,6 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
if (e.Delta.Y != 0)
{
this.IsSynced = false;
this.IsSynced = false;
}

if (e.Delta.Y > 0)
Expand Down
8 changes: 8 additions & 0 deletions OpenLyricsClient/Frontend/View/Custom/Tile/LyricsTile.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="OpenLyricsClient.Frontend.View.Custom.Tile.LyricsTile">
<Decorator Name="PART_Decorator"/>
</UserControl>
35 changes: 35 additions & 0 deletions OpenLyricsClient/Frontend/View/Custom/Tile/LyricsTile.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using OpenLyricsClient.Backend;
using OpenLyricsClient.Backend.Events.EventArgs;
using OpenLyricsClient.Shared.Structure.Lyrics;

namespace OpenLyricsClient.Frontend.View.Custom.Tile;

public partial class LyricsTile : UserControl
{
private LyricPart _lyricPart;
private Decorator _decorator;

public LyricsTile()
{
AvaloniaXamlLoader.Load(this);

this._decorator = this.Get<Decorator>(nameof(PART_Decorator));

Core.INSTANCE.LyricHandler.LyricsPercentageUpdated += LyricHandlerOnLyricsPercentageUpdated;
}

private void LyricHandlerOnLyricsPercentageUpdated(object sender, LyricsPercentageUpdatedEventArgs args)
{

}

public LyricPart Lyric
{
get => this._lyricPart;
set => this._lyricPart = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="OpenLyricsClient.Frontend.View.Custom.Tile.Overlays.TextOverlay">



Welcome to Avalonia!
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace OpenLyricsClient.Frontend.View.Custom.Tile.Overlays;

public partial class TextOverlay : UserControl
{
public TextOverlay()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}

0 comments on commit c9ea05e

Please sign in to comment.