Skip to content

Commit

Permalink
remove boom mixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Oct 9, 2024
1 parent 327bab4 commit 0a55c5a
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 5 deletions.
114 changes: 114 additions & 0 deletions MusicX/Controls/Blocks/AudioMixesBlock.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<UserControl
x:Class="MusicX.Controls.Blocks.AudioMixesBlock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MusicX.Controls.Blocks"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:shaders="clr-namespace:MusicX.Shaders"
xmlns:wpfui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:converters="clr-namespace:MusicX.Converters"
Name="Control"
mc:Ignorable="d">

<UserControl.Resources>
<converters:InversionBooleanToVisibilityConverter x:Key="InversionBooleanToVisibilityConverter" />
</UserControl.Resources>

<Grid MinHeight="500">
<Rectangle Name="MixRect"
Fill="White"
RadiusY="8"
RadiusX="8">
<Rectangle.OpacityMask>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0"
Color="Black" />
<GradientStop Offset="1"
Color="Transparent" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.OpacityMask>

<Rectangle.Effect>
<shaders:MixNoiseEffect XSize="{Binding ActualWidth, ElementName=MixRect}"
YSize="{Binding ActualHeight, ElementName=MixRect}" />
</Rectangle.Effect>
</Rectangle>

<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button HorizontalAlignment="Center"
VerticalAlignment="Bottom"
BorderThickness="0"
Margin="0 0 0 30"
Click="Button_Click">
<Button.Style>
<Style TargetType="Button">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="White"
Opacity="0.7" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Padding="12"
Background="{TemplateBinding Background}"
CornerRadius="99"
Name="ContentBorder">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="White" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>

<wpfui:SymbolIcon Foreground="Black"
FontSize="32">
<wpfui:SymbolIcon.Style>
<Style TargetType="wpfui:SymbolIcon">
<Setter Property="Symbol"
Value="Play32" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsPlaying, ElementName=Control}" Value="True">
<Setter Property="Symbol"
Value="Pause32" />
</DataTrigger>
</Style.Triggers>
</Style>
</wpfui:SymbolIcon.Style>
</wpfui:SymbolIcon>

</Button>

<!-- the foreground on top of the shader should always be white -->
<TextBlock Foreground="White"
Text="VK mix"
FontSize="70"
TextAlignment="Center"
FontFamily="{StaticResource VKSansDemiBold}" />
<TextBlock Foreground="White"
Text="Динамический плейлист, который подстраивается под Ваш вкус"
FontSize="17"
FontFamily="{StaticResource VKSansRegular}" />
</StackPanel>
</Grid>
</UserControl>
59 changes: 59 additions & 0 deletions MusicX/Controls/Blocks/AudioMixesBlock.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Microsoft.Extensions.DependencyInjection;
using MusicX.Core.Services;
using MusicX.Services;
using MusicX.Services.Player;
using MusicX.Services.Player.Playlists;
using System;
using System.Windows;
using System.Windows.Controls;

namespace MusicX.Controls.Blocks;

public sealed partial class AudioMixesBlock : UserControl
{

public bool IsPlaying
{
get => (bool)GetValue(IsPlayingProperty);
set => SetValue(IsPlayingProperty, value);
}

public static readonly DependencyProperty IsPlayingProperty =
DependencyProperty.Register("IsPlaying", typeof(bool), typeof(AudioMixesBlock));
private readonly PlayerService _player;

public AudioMixesBlock()
{
InitializeComponent();

_player = StaticService.Container.GetRequiredService<PlayerService>();

_player.CurrentPlaylistChanged += Player_CurrentPlaylistChanged;
_player.PlayStateChangedEvent += Player_CurrentPlaylistChanged;
Player_CurrentPlaylistChanged(_player, EventArgs.Empty);
}

private void Player_CurrentPlaylistChanged(object? sender, EventArgs e)
{
IsPlaying = _player.CurrentPlaylist is MixPlaylist && _player.IsPlaying;
}

private async void Button_Click(object sender, RoutedEventArgs e)
{
if (IsPlaying)
{
_player.Pause();
return;
}

if (_player.CurrentPlaylist is MixPlaylist)
{
_player.Play();
return;
}

var data = new MixOptions("common");

await _player.PlayAsync(new MixPlaylist(data, StaticService.Container.GetRequiredService<VkService>()));
}
}
10 changes: 5 additions & 5 deletions MusicX/RootWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
{ Tag = "test", Icon = SymbolRegular.AppFolder24, Content = "TEST", PageType = typeof(TestPage) };
navigationBar.Items.Add(item);
#endif
navigationBar.Items.Add(new()
{
Tag = "vkmix", PageDataContext = StaticService.Container.GetRequiredService<VKMixViewModel>(),
Icon = SymbolRegular.Stream24, Content = "Микс", PageType = typeof(VKMixView)
});
// navigationBar.Items.Add(new()
// {
// Tag = "vkmix", PageDataContext = StaticService.Container.GetRequiredService<VKMixViewModel>(),
// Icon = SymbolRegular.Stream24, Content = "Микс", PageType = typeof(VKMixView)
// });
navigationBar.Items.Add(new()
{
Tag = "downloads",
Expand Down
49 changes: 49 additions & 0 deletions MusicX/Services/Player/Playlists/MixPlaylist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using MusicX.Core.Services;
using MusicX.Shared.Player;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace MusicX.Services.Player.Playlists;

[JsonConverter(typeof(PlaylistJsonConverter<MixPlaylist, MixOptions>))]
public class MixPlaylist(MixOptions data, VkService vkService) : PlaylistBase<MixOptions>
{
public override bool CanLoad => true;
public override MixOptions Data => data;

public override async IAsyncEnumerable<PlaylistTrack> LoadAsync()
{
var tracks = await vkService.GetStreamMixAudios(data.Id, data.Append, options: data.Options);

foreach (var track in tracks)
{
yield return track.ToTrack();
}

data = data with { Append = data.Append + 1 };
}
}

public record MixOptions(string Id, int Append = 0, ImmutableDictionary<string, ImmutableArray<string>>? Options = null)
{
public override int GetHashCode()
{
var hashCode = new HashCode();

hashCode.Add(Id);
hashCode.Add(Append);
if (Options is not null)
foreach (var (key, values) in Options)
{
hashCode.Add(key);
foreach (var item in values)
{
hashCode.Add(item);
}
}

return hashCode.ToHashCode();
}
}

0 comments on commit 0a55c5a

Please sign in to comment.