Skip to content

Commit

Permalink
Merge pull request #2 from timweiss/history-semantic-search
Browse files Browse the repository at this point in the history
History semantic search (without semantic)
  • Loading branch information
timweiss authored Jun 24, 2017
2 parents 3c68f61 + 1e0f0e7 commit 85608bf
Show file tree
Hide file tree
Showing 18 changed files with 482 additions and 77 deletions.
5 changes: 1 addition & 4 deletions LunaticPlayer.GRadioAPI/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class ApiClient
public StructuredApiData CurrentStructuredApiData { get; private set; }

/// <summary>
/// Converts the raw API data into the song class.
/// <seealso cref="LunaticPlayer.Classes.Song">
/// Converts the raw API data into the <seealso cref="Song" /> class.
/// </summary>
/// <returns>The song fetched from the API.</returns>
public Song PlayingSong()
Expand Down Expand Up @@ -162,8 +161,6 @@ public async Task<bool> CheckApiAccess()
Console.WriteLine(e);
return false;
}

return false;
}
}

Expand Down
84 changes: 84 additions & 0 deletions LunaticPlayer/Client/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace LunaticPlayer.Client
{
class ConfigurationData
{
public double Volume { get; set; }
}

class Configuration
{
private const string Filename = "config.json";

private static Configuration _instance;

public ConfigurationData Data { get; set; }

/// <summary>
/// The source of configuration data (Filesystem, Default Object, ...).
/// </summary>
public string Source { get; set; }

public static Configuration GetInstance()
{
if (_instance == null)
{
_instance = new Configuration();
_instance.Initialize();
}

return _instance;
}

/// <summary>
/// Loads the configuration and stores it to the filesystem if necessary.
/// </summary>
private void Initialize()
{

if (File.Exists(Filename))
{
Data = JsonConvert.DeserializeObject<ConfigurationData>(File.ReadAllText(Filename));
Source = "Filesystem";
}
else
{
Source = "DefaultDataObject";

SetupData();

// Erstellt eine Konfigurationsdatei für das nächste Mal.
Save();
}
}

/// <summary>
/// Creates a <seealso cref="ConfigurationData"/> object with default values.
/// </summary>
private void SetupData()
{
var data = new ConfigurationData()
{
Volume = 0.4
};

Data = data;
}

/// <summary>
/// Saves the current configuration to the file specified at <see cref="Filename"/>.
/// </summary>
public void Save()
{
Console.WriteLine("Saving configuration to filesystem.");
File.WriteAllText(Filename, JsonConvert.SerializeObject(Data));
}
}
}
14 changes: 14 additions & 0 deletions LunaticPlayer/Controls/VolumeBar.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="LunaticPlayer.Controls.VolumeBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LunaticPlayer.Controls"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="100">
<Grid Background="Transparent">
<Border Padding="5,15">
<Slider Name="VolumeSlider" Orientation="Horizontal" Maximum="1" Value="{Binding Volume}" ValueChanged="VolumeSlider_ValueChanged"/>
</Border>
</Grid>
</UserControl>
45 changes: 45 additions & 0 deletions LunaticPlayer/Controls/VolumeBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LunaticPlayer.Controls
{
public class VolumeBarData
{
public double Volume { get; set; }
}

/// <summary>
/// Interaktionslogik für VolumeBar.xaml
/// </summary>
public partial class VolumeBar : UserControl
{
public VolumeBarData Data { get; set; }
public Action OnValueChange { get; set; }

public VolumeBar(VolumeBarData data)
{
InitializeComponent();

DataContext = Data = data;
}

private void VolumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Data.Volume = VolumeSlider.Value;

OnValueChange?.Invoke();
}
}
}
28 changes: 26 additions & 2 deletions LunaticPlayer/LunaticPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Client\Configuration.cs" />
<Compile Include="Controls\VolumeBar.xaml.cs">
<DependentUpon>VolumeBar.xaml</DependentUpon>
</Compile>
<Compile Include="PopupBanner.xaml.cs">
<DependentUpon>PopupBanner.xaml</DependentUpon>
</Compile>
Expand All @@ -78,6 +82,13 @@
<Compile Include="SongHistoryWindow.xaml.cs">
<DependentUpon>SongHistoryWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\DialogWindow.xaml.cs">
<DependentUpon>DialogWindow.xaml</DependentUpon>
</Compile>
<Page Include="Controls\VolumeBar.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PlayerInterface.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -106,6 +117,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\DialogWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Player\RadioPlayer.cs" />
Expand Down Expand Up @@ -156,8 +171,8 @@
<Resource Include="Resources\unmute_mat.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\mute_92.png" />
<Resource Include="Resources\unmute_92.png" />
<Resource Include="Resources\voloff_92.png" />
<Resource Include="Resources\volume_92.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\list_92.png" />
Expand Down Expand Up @@ -187,6 +202,15 @@
<ItemGroup>
<Resource Include="Resources\info_black_92.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\help_black_92.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\help_white_92.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\mute_92.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.105.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.105.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
17 changes: 16 additions & 1 deletion LunaticPlayer/Player/RadioPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RadioPlayer
{
private readonly MediaPlayer _player;

public bool Muted => _player.Volume == 0.0;
public bool Muted { get; set; }

public double Volume => _player.Volume;

Expand All @@ -26,6 +26,7 @@ public void PlayFromUrl(string url)
public void Stop()
{
_player.Stop();
_player.Close();
}

//TODO: Lautstärke richtig einstellen
Expand All @@ -38,5 +39,19 @@ public void ToggleMute()
{
_player.Volume = _player.Volume == 0.0 ? 0.5 : 0.0;
}

public void ToggleMute(double volume)
{
if (Muted)
{
_player.Volume = volume;
Muted = false;
}
else
{
_player.Volume = 0.0;
Muted = true;
}
}
}
}
22 changes: 13 additions & 9 deletions LunaticPlayer/Player/SongHistoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ private void InitializeHistory()
}

/// <summary>
/// Loads the song history from the JSON file.
/// Adds the last song to the database.
/// </summary>
private void StoreHistory(Song lastSong)
{
Database.AddSong(lastSong);
}

/// <summary>
/// Loads the song history from the JSON file.
/// This should not be used in favor of storing history in the database.
/// </summary>
[Obsolete]
private void InitializeHistoryJson()
{
if (System.IO.File.Exists("songhist.json"))
Expand All @@ -62,17 +72,11 @@ private void InitializeHistoryJson()
}
}

/// <summary>
/// Adds the last song to the database.
/// </summary>
private void StoreHistory(Song lastSong)
{
Database.AddSong(lastSong);
}

/// <summary>
/// Stores the current state of the song history in the JSON file.
/// As with <see cref="InitializeHistoryJson"/>, this shouldn't be used in favor of the database.
/// </summary>
[Obsolete]
private void StoreHistoryJson()
{
var json = JsonConvert.SerializeObject(SongHistory);
Expand Down
22 changes: 15 additions & 7 deletions LunaticPlayer/PlayerInterface.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:LunaticPlayer"
xmlns:controls="clr-namespace:LunaticPlayer.Controls"
mc:Ignorable="d"
Title="Lunatic Player" Height="245" Width="375" Closed="Window_Closed" Loaded="Window_Loaded">

Expand Down Expand Up @@ -79,29 +80,36 @@
</Border>
</DockPanel>
</Grid>

<Grid Height="45" VerticalAlignment="Bottom" Background="#FF767676">
<Grid.Effect>
<DropShadowEffect Direction="90" Opacity="0.2" ShadowDepth="4"/>
</Grid.Effect>
<StackPanel Orientation="Horizontal" Height="45" VerticalAlignment="Bottom" Margin="0,0,50,0">
<Border Padding="5" Height="45" Width="45" HorizontalAlignment="Left">
<StackPanel Name="ButtonToolbar" Orientation="Horizontal" Height="45" VerticalAlignment="Bottom" Margin="0,0,50,0">
<Border ToolTip="Change Volume" Padding="5" Height="45" Width="45" HorizontalAlignment="Left">
<Button Style="{StaticResource TransparentImageButton}" Name="VolumeMeterButton" Click="VolumeButton_OnClick" >
<Button.Background>
<ImageBrush ImageSource="Resources/volume_92.png"/>
</Button.Background>
</Button>
</Border>
<Border ToolTip="Mute" Padding="5" Height="45" Width="45" HorizontalAlignment="Left">
<Button Style="{StaticResource TransparentImageButton}" Name="MuteButton" Click="MuteButton_Click">
<Button.Background>
<ImageBrush ImageSource="Resources/mute_92.png"/>
<ImageBrush ImageSource="Resources/voloff_92.png"/>
</Button.Background>
</Button>
</Border>
<Border Padding="5" Height="45" Width="45" HorizontalAlignment="Left">
<Border ToolTip="Show History" Padding="5" Height="45" Width="45" HorizontalAlignment="Left">
<Button Style="{StaticResource TransparentImageButton}" Name="SongListButton" Click="SongListButton_OnClick" >
<Button.Background>
<ImageBrush ImageSource="Resources/list_92.png"/>
</Button.Background>
</Button>
</Border>
</StackPanel>
<Border Padding="5" Height="45" Width="45" HorizontalAlignment="Right">

<Border ToolTip="Settings" Padding="5" Height="45" Width="45" HorizontalAlignment="Right">
<Button Style="{StaticResource TransparentImageButton}" Name="OptionsButton" Click="OptionsButton_OnClick" >
<Button.Background>
<ImageBrush ImageSource="Resources/settings_92.png"/>
Expand Down
Loading

0 comments on commit 85608bf

Please sign in to comment.