Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Add square-visualisation as a default audio visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkalinee committed Apr 9, 2015
1 parent 716f771 commit 3a91192
Show file tree
Hide file tree
Showing 23 changed files with 488 additions and 68 deletions.
4 changes: 2 additions & 2 deletions Hurricane/AppMainWindow/WindowSkins/WindowAdvancedView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid>
<hurricaneControls:AnimatedListView SelectionMode="Extended" ItemsSource="{Binding MusicManager.SelectedPlaylist.ViewSource}" SelectedItem="{Binding MusicManager.SelectedTrack}" BorderThickness="0" SelectionChanged="ListView_SelectionChanged" Background="Transparent"
<hurricaneControls:AnimatedListView behaviors:ItemsControlAnimationBehavior.IsAnimationEnabled="True" SelectionMode="Extended" ItemsSource="{Binding MusicManager.SelectedPlaylist.ViewSource}" SelectedItem="{Binding MusicManager.SelectedTrack}" BorderThickness="0" SelectionChanged="ListView_SelectionChanged" Background="Transparent"
DragEnter="ListView_DragEnter" Drop="ListView_Drop" x:Name="TracksListView" listViewLayoutManager:ListViewLayoutManager.Enabled="True" Style="{StaticResource VisualizingListView}" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DragAdornerTemplate="{StaticResource DragAdornerTrack}" dd:DragDrop.DropHandler="{Binding TrackListDropHandler}" Transition="{Binding MySettings.Config.TrackListAnimation}">
<ListView.Resources>
Expand Down Expand Up @@ -579,7 +579,7 @@
</TextBlock>
<ToggleButton Foreground="#FFB4B4B4" Background="{StaticResource NormalColorBrush}" Style="{StaticResource FavoriteToggleButton}" Height="18" Width="18" HorizontalAlignment="Left" Margin="0,10,0,10" IsChecked="{Binding MusicManager.CSCoreEngine.CurrentTrack.IsFavorite}"/>
</hurricaneControls:AnimatedStackPanel>
<ContentControl Grid.Row="1" Height="100" VerticalAlignment="Bottom" Focusable="False" Margin="0,0,0,10" x:Name="AudioVisualisationContentControl" behaviors:AudioVisualisationBehavior.AudioVisualisationForAdvancedWindow="{Binding MySettings.Config.ApplicationDesign.AudioVisualisation.AudioVisualisationPlugin}">
<ContentControl Grid.Row="1" Height="100" VerticalAlignment="Bottom" Focusable="False" Margin="0,0,0,10" x:Name="AudioVisualisationContentControl" behaviors:AudioVisualisationBehavior.AudioVisualisationForAdvancedWindow="{Binding MySettings.Config.ApplicationDesign.AudioVisualisation.Visualisation}">
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="Opacity" Value="0"/>
Expand Down
16 changes: 3 additions & 13 deletions Hurricane/AppMainWindow/WindowSkins/WindowSmartView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</DockPanel>
<StackPanel Grid.Row="2" Margin="5">
<Grid Margin="0,0,0,10">
<ContentControl x:Name="AudioVisualisationContentControl" behaviors:AudioVisualisationBehavior.AudioVisualisationForSmartWindow="{Binding MySettings.Config.ApplicationDesign.AudioVisualisation.AudioVisualisationPlugin}">
<ContentControl x:Name="AudioVisualisationContentControl" behaviors:AudioVisualisationBehavior.AudioVisualisationForSmartWindow="{Binding MySettings.Config.ApplicationDesign.AudioVisualisation.Visualisation}">
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="Opacity" Value="0"/>
Expand Down Expand Up @@ -247,17 +247,7 @@
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<ToggleButton IsChecked="{Binding MusicManager.FavoriteListIsSelected}" Style="{StaticResource FavoriteListToggleButton}" Width="15" Margin="0,0,5,0"/>
<ComboBox Grid.Column="1" ItemsSource="{Binding MusicManager.Playlists}" DisplayMemberPath="Name" SelectedItem="{Binding MusicManager.SelectedPlaylist}" VerticalAlignment="Center" Margin="0,0,3,0" Height="27">
<ComboBox.Triggers>
<EventTrigger RoutedEvent="ComboBox.SelectionChanged">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0.5" To="1" Storyboard.TargetProperty="Opacity" Storyboard.Target="{Binding ElementName=TracksListView}"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ComboBox.Triggers>
</ComboBox>
<ComboBox Grid.Column="1" ItemsSource="{Binding MusicManager.Playlists}" DisplayMemberPath="Name" SelectedItem="{Binding MusicManager.SelectedPlaylist}" VerticalAlignment="Center" Margin="0,0,3,0" Height="27"/>
<TextBlock Grid.Column="1" Text="{DynamicResource Favorites}" VerticalAlignment="Center" Margin="8,0,0,0">
<TextBlock.Style>
<Style TargetType="TextBlock">
Expand Down Expand Up @@ -332,7 +322,7 @@
</hurricaneControls:VectorMenuItem>
</Menu>
</Grid>
<ListView ItemsSource="{Binding MusicManager.SelectedPlaylist.ViewSource}" SelectionMode="Extended" Grid.Row="1" Drop="listview_Drop" DragEnter="listview_DragEnter" x:Name="TracksListView" SelectedItem="{Binding MusicManager.SelectedTrack}" ScrollViewer.VerticalScrollBarVisibility="Visible"
<ListView behaviors:ItemsControlAnimationBehavior.IsAnimationEnabled="True" ItemsSource="{Binding MusicManager.SelectedPlaylist.ViewSource}" SelectionMode="Extended" Grid.Row="1" Drop="listview_Drop" DragEnter="listview_DragEnter" x:Name="TracksListView" SelectedItem="{Binding MusicManager.SelectedTrack}" ScrollViewer.VerticalScrollBarVisibility="Visible"
Margin="0,5,-1,0" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="listview_SelectionChanged" IsSynchronizedWithCurrentItem="True" Style="{StaticResource VisualizingListView}" Background="{StaticResource WhiteBrush}">
<ListView.InputBindings>
<KeyBinding Key="Delete" Command="{Binding RemoveSelectedTracks}" CommandParameter="{Binding ElementName=TracksListView,Path=SelectedItems}"/>
Expand Down
2 changes: 1 addition & 1 deletion Hurricane/Designer/Data/ThemePack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void Unload()
#region IAudioVisualisationContainer

private IAudioVisualisationPlugin _audioVisualisationPlugin;
IAudioVisualisationPlugin IAudioVisualisationContainer.AudioVisualisationPlugin
IAudioVisualisationPlugin IAudioVisualisationContainer.Visualisation
{
get { return _audioVisualisationPlugin; }
}
Expand Down
134 changes: 134 additions & 0 deletions Hurricane/GUI/Behaviors/ItemsControlAnimationBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using Hurricane.Utilities;

namespace Hurricane.GUI.Behaviors
{
class ItemsControlAnimationBehavior
{
public static readonly DependencyProperty IsAnimationEnabledProperty = DependencyProperty.RegisterAttached(
"IsAnimationEnabled", typeof(bool), typeof(ItemsControlAnimationBehavior), new PropertyMetadata(false, PropertyChangedCallback));

private static void PropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var itemsControl = dependencyObject as ItemsControl;
if (itemsControl == null)
throw new ArgumentException("The dependencyObject isn't an ItemsControl");

var dependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(ItemsControl));
if ((bool)dependencyPropertyChangedEventArgs.NewValue)
{
dependencyPropertyDescriptor.AddValueChanged(dependencyObject, ItemsSourceChanged);
}
else
{
dependencyPropertyDescriptor.RemoveValueChanged(itemsControl, ItemsSourceChanged);
}
}

private static readonly Dictionary<ItemsControl, DispatcherTimer> Timers = new Dictionary<ItemsControl, DispatcherTimer>();

private async static void ItemsSourceChanged(object sender, EventArgs eventArgs)
{
var itemsControl = (ItemsControl)sender;
if (itemsControl.ItemsSource == null) return;

//TODO: Hier die Animationen ändern
var opacityAnimation = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(260), FillBehavior.Stop);
var marginAnimation = new ThicknessAnimation(new Thickness(-20, 0, 20, 0), new Thickness(0),
TimeSpan.FromMilliseconds(240), FillBehavior.Stop)
{
EasingFunction = new CircleEase { EasingMode = EasingMode.EaseOut }
};

if (Timers.ContainsKey(itemsControl))
{
Timers[itemsControl].Stop();
Timers.Remove(itemsControl);
}

List<ListBoxItem> visibleItems;

while (true)
{
visibleItems = DependencyObjectExtensions.GetVisibleItemsFromItemsControl(itemsControl,
Window.GetWindow(itemsControl));
if (visibleItems.Count > 0 || itemsControl.Items.Count == 0)
break;
await Task.Delay(1);
}

foreach (var item in visibleItems)
{
item.Opacity = 0;
}

DispatcherTimer dispatcherTimer;

var enumerator = visibleItems.GetEnumerator();
if (enumerator.MoveNext())
{
ScrollChangedEventHandler scrollChangedEventHandler = null;
scrollChangedEventHandler = (o, args) =>
{
var handler = scrollChangedEventHandler;

if (handler != null)
itemsControl.RemoveHandler(ScrollViewer.ScrollChangedEvent, handler);

if (!Timers.ContainsKey(itemsControl) || !Timers[itemsControl].IsEnabled)
return;

var timer = Timers[itemsControl];
timer.Stop();

while (true)
{
var item = enumerator.Current;
if (item == null)
break;
item.Opacity = 1;
if (!enumerator.MoveNext()) break;
}
};

dispatcherTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(30) }; //TODO: Hier könnt ihr die Zeitspanne zwischen den Animationen für die Element einstellen
dispatcherTimer.Tick += (s, timerE) =>
{
var item = enumerator.Current; //Bei jedem Tick animieren wir das nächte Item
if (item == null) return;
item.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
item.BeginAnimation(UIElement.OpacityProperty, opacityAnimation);
item.Opacity = 1;
if (!enumerator.MoveNext()) //Wenn keines mehr da ist, stoppen wir den Timer und löschen den Handler für das Scroll-Event
{
dispatcherTimer.Stop();
itemsControl.RemoveHandler(ScrollViewer.ScrollChangedEvent, scrollChangedEventHandler);
}
};

if (Timers.ContainsKey(itemsControl)) Timers.Remove(itemsControl);
Timers.Add(itemsControl, dispatcherTimer);
dispatcherTimer.Start();

itemsControl.AddHandler(ScrollViewer.ScrollChangedEvent, scrollChangedEventHandler);
}
}

public static void SetIsAnimationEnabled(DependencyObject element, bool value)
{
element.SetValue(IsAnimationEnabledProperty, value);
}

public static bool GetIsAnimationEnabled(DependencyObject element)
{
return (bool)element.GetValue(IsAnimationEnabledProperty);
}
}
}
6 changes: 4 additions & 2 deletions Hurricane/GUI/Controls/AnimatedListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public AnimatedListView()
private async void ItemsSourceChanged(object sender, EventArgs eventArgs)
{
if (!_currentMargin.HasValue) _currentMargin = Margin;
if (ItemsSource == null) return;

switch (Transition)
{
Expand All @@ -51,6 +52,7 @@ private async void ItemsSourceChanged(object sender, EventArgs eventArgs)
break;

case TrackListAnimation.FadeEveryItem:
break;
var opacityAnimation = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(255), FillBehavior.Stop);
var marginAnimation = new ThicknessAnimation(new Thickness(-20, 0, 20, 0), new Thickness(0), TimeSpan.FromMilliseconds(200), FillBehavior.Stop)
{
Expand All @@ -59,11 +61,11 @@ private async void ItemsSourceChanged(object sender, EventArgs eventArgs)

if (_dispatcherTimer != null) _dispatcherTimer.Stop();

List<ListViewItem> visibleItems;
List<ListBoxItem> visibleItems;

while (true)
{
visibleItems = DependencyObjectExtensions.GetVisibleItemsFromListView(this,
visibleItems = DependencyObjectExtensions.GetVisibleItemsFromItemsControl(this,
Window.GetWindow(this));
if (visibleItems.Count > 0 || Items.Count == 0)
break;
Expand Down
13 changes: 9 additions & 4 deletions Hurricane/Hurricane.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<Compile Include="DragDrop\PlaylistListDropHandler.cs" />
<Compile Include="DragDrop\TrackListDropHandler.cs" />
<Compile Include="GUI\Behaviors\FrameworkElementBehavior.cs" />
<Compile Include="GUI\Behaviors\ItemsControlAnimationBehavior.cs" />
<Compile Include="GUI\Controls\AnimatedListView.cs" />
<Compile Include="GUI\Controls\AnimatedStackPanel.cs" />
<Compile Include="GUI\Behaviors\AudioVisualisationBehavior.cs" />
Expand Down Expand Up @@ -225,13 +226,17 @@
<Compile Include="Settings\Converter\GroupConverter.cs" />
<Compile Include="Settings\Converter\TransitionConverter.cs" />
<Compile Include="Settings\SaveLocationManager.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\AudioVisualisationBase.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\AudioVisualisationPluginHelper.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\CustomAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\DefaultAudioVisualisation\AdvancedWindowAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\DefaultAudioVisualisation\DefaultAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\DefaultAudioVisualisation\SmartWindowAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\DefaultAudioVisualisation\SpectrumPlayerWrapper.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\BarAudioVisualisation\AdvancedWindowAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\BarAudioVisualisation\BarAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\BarAudioVisualisation\SmartWindowAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\SpectrumPlayerWrapper.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\IAudioVisualisationContainer.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\SquareAudioVisualisation\AdvancedWindowAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\SquareAudioVisualisation\SquareAudioVisualisation.cs" />
<Compile Include="Settings\Themes\AudioVisualisation\SquareAudioVisualisation\SmartWindowAudioVisualisation.cs" />
<Compile Include="Settings\Themes\Background\CustomApplicationBackground.cs" />
<Compile Include="GUI\Converter\FalseOnNullValue.cs" />
<Compile Include="GUI\Converter\FormatLargeNumber.cs" />
Expand Down
3 changes: 3 additions & 0 deletions Hurricane/Resources/Languages/Hurricane.de-de.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,7 @@
<system:String x:Key="AddCustomStream">Eigenen Stream hinzufügen</system:String>
<system:String x:Key="InvalidUrl">Ungültige Url</system:String>
<system:String x:Key="TrackListAnimation">Trackliste-Animation</system:String>

<system:String x:Key="Bars">Balken</system:String>
<system:String x:Key="Squares">Kästchen</system:String>
</ResourceDictionary>
3 changes: 3 additions & 0 deletions Hurricane/Resources/Languages/Hurricane.en-us.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,7 @@
<system:String x:Key="AddCustomStream">Add custom stream</system:String>
<system:String x:Key="InvalidUrl">Invalid url</system:String>
<system:String x:Key="TrackListAnimation">Track list animation</system:String>

<system:String x:Key="Bars">Bars</system:String>
<system:String x:Key="Squares">Squares</system:String>
</ResourceDictionary>
Loading

0 comments on commit 3a91192

Please sign in to comment.