Skip to content

Commit

Permalink
Merge pull request #86 from dan0v/master
Browse files Browse the repository at this point in the history
Code cleanup, use OpenSans
  • Loading branch information
dan0v authored Sep 10, 2024
2 parents 1d671fe + d3d6e49 commit d85d6b4
Show file tree
Hide file tree
Showing 41 changed files with 125 additions and 97 deletions.
9 changes: 1 addition & 8 deletions AmplitudeSoundboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<RootNamespace>Amplitude</RootNamespace>
<NeutralLanguage>en</NeutralLanguage>
<Platforms>AnyCPU;x64</Platforms>
<Version>2.10.1</Version>
<Version>2.10.2</Version>
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode>
Expand Down Expand Up @@ -47,13 +47,6 @@
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
<Choose>
<When Condition="'$(Configuration)' == 'Debug'">
<ItemGroup>
<PackageReference Include="Avalonia.Diagnostics" Version="11.1.3"/>
</ItemGroup>
</When>
</Choose>
<ItemGroup>
<Compile Update="Localization\Language.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Copyright 2012 Google Inc. All Rights Reserved.
Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
https://openfontlicense.org


-----------------------------------------------------------
Expand Down
Binary file added Assets/Fonts/OpenSans/OpenSans-Italic.ttf
Binary file not shown.
Binary file added Assets/Fonts/OpenSans/OpenSans-Light.ttf
Binary file not shown.
Binary file added Assets/Fonts/OpenSans/OpenSans-LightItalic.ttf
Binary file not shown.
Binary file added Assets/Fonts/OpenSans/OpenSans-Regular.ttf
Binary file not shown.
Binary file added Assets/Fonts/OpenSans/OpenSans-SemiBold.ttf
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Helpers/BlankHotkeysManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Amplitude.Helpers
public class BlankHotkeysManager : IKeyboardHook
{
private static BlankHotkeysManager? _instance;
public static BlankHotkeysManager Instance => _instance ??= new BlankHotkeysManager();
public static IKeyboardHook Instance => _instance ??= new BlankHotkeysManager();

public void Dispose()
{
Expand Down
10 changes: 5 additions & 5 deletions Helpers/HotkeysManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void RegisterHotkeyAtStartup(string? id, string hotkeyString)
}

// Add hotkey to dict
if (Hotkeys.TryGetValue(hotkeyString, out List<string> val))
if (Hotkeys.TryGetValue(hotkeyString, out List<string>? val))
{
val.Add(id);
val?.Add(id);
}
else
{
Expand Down Expand Up @@ -119,15 +119,15 @@ public void RemoveHotkey(string? id, string? hotkeyString)
return;
}

if (Hotkeys.TryGetValue(hotkeyString, out List<string> val))
if (Hotkeys.TryGetValue(hotkeyString, out List<string>? val))
{
if (val.Count <= 1)
if (val?.Count <= 1)
{
Hotkeys.Remove(hotkeyString);
}
else
{
val.Remove(id);
val?.Remove(id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Helpers/IKeyboardHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Amplitude.Helpers
{
public interface IKeyboardHook : IDisposable
{
public static IKeyboardHook Instance { get; }
public static abstract IKeyboardHook Instance { get; }
public void SetSoundClipHotkey(SoundClip clip, Action<SoundClip, string> callback);
public void SetGlobalStopHotkey(Config config, Action<Config, string> callback);
}
Expand Down
2 changes: 1 addition & 1 deletion Helpers/ISoundEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Amplitude.Helpers
{
public interface ISoundEngine : IDisposable
{
public static ISoundEngine Instance { get; }
public static abstract ISoundEngine Instance { get; }

public ObservableCollection<PlayingClip> CurrentlyPlaying { get; }
public ObservableCollection<SoundClip> Queued { get; }
Expand Down
12 changes: 6 additions & 6 deletions Helpers/MSoundEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ namespace Amplitude.Helpers
class MSoundEngine : ISoundEngine
{
private static MSoundEngine? _instance;
public static MSoundEngine Instance => _instance ??= new MSoundEngine();
public static ISoundEngine Instance => _instance ??= new MSoundEngine();

object currentlyPlayingLock = new object();
object currentlyPlayingLock = new();

private ObservableCollection<PlayingClip> _currentlyPlaying = new ObservableCollection<PlayingClip>();
private ObservableCollection<PlayingClip> _currentlyPlaying = [];
public ObservableCollection<PlayingClip> CurrentlyPlaying => _currentlyPlaying;

object queueLock = new object();
object queueLock = new();

private ObservableCollection<SoundClip> _queued = new ObservableCollection<SoundClip>();
private ObservableCollection<SoundClip> _queued = [];
public ObservableCollection<SoundClip> Queued => _queued;


private const long TIMER_MS = 200;
private Timer timer = new Timer(TIMER_MS)
private Timer timer = new(TIMER_MS)
{
AutoReset = true,
};
Expand Down
21 changes: 16 additions & 5 deletions Helpers/SharpKeyboardHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ public class SharpKeyboardHook : IKeyboardHook
private readonly object keySetLock = new();

private static SharpKeyboardHook? _instance;
public static SharpKeyboardHook Instance => _instance ??= new SharpKeyboardHook();
public static IKeyboardHook Instance => _instance ??= new SharpKeyboardHook();

static bool disposed = false;

private SharpKeyboardHook()
{
sharpHook.KeyPressed += HandleKeyPressed;
sharpHook.KeyReleased += HandleKeyReleased;
sharpHook.RunAsync();
if (!disposed)
{
sharpHook.KeyPressed += HandleKeyPressed;
sharpHook.KeyReleased += HandleKeyReleased;
sharpHook.RunAsync();
}
}

private void HandleKeyReleased(object? sender, KeyboardHookEventArgs e)
Expand Down Expand Up @@ -95,7 +100,7 @@ private void ProcessHotkey(string currentKey)
}
soundClipCallbacks.Clear();
}
else if (currentKey != HotkeysManager.UNBIND_HOTKEY && App.HotkeysManager.Hotkeys.TryGetValue(fullKey, out List<string> values))
else if (currentKey != HotkeysManager.UNBIND_HOTKEY && App.HotkeysManager.Hotkeys.TryGetValue(fullKey, out List<string>? values))
{
// Go through and call all the Play methods on these id's
foreach (string item in values)
Expand Down Expand Up @@ -233,6 +238,12 @@ public void SetGlobalStopHotkey(Config config, Action<Config, string> callback)

public void Dispose()
{
if (disposed)
{
return;
}

disposed = true;
_instance = null;
sharpHook.KeyPressed -= HandleKeyPressed;
sharpHook.KeyReleased -= HandleKeyReleased;
Expand Down
13 changes: 8 additions & 5 deletions Helpers/SoundClipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ private void ValidateSoundClip(SoundClip clip)
}

App.OutputProfileManager.ValidateOutputProfile(profile);
App.SoundEngine.CheckDeviceExistsAndGenerateErrors(profile);
if (profile != null)
{
App.SoundEngine.CheckDeviceExistsAndGenerateErrors(profile);
}
}

/// <summary>
Expand All @@ -184,10 +187,10 @@ public void SaveClip(SoundClip clip)
}
}
}
else if (SoundClips.TryGetValue(clip.Id, out SoundClip oldClip))
else if (SoundClips.TryGetValue(clip.Id, out SoundClip? oldClip))
{
// Overwrite existing clip
App.HotkeysManager.RemoveHotkey(clip.Id, oldClip.Hotkey);
App.HotkeysManager.RemoveHotkey(clip.Id, oldClip?.Hotkey);
if (!string.IsNullOrEmpty(clip.Hotkey))
{
App.HotkeysManager.RegisterHotkeyAtStartup(clip.Id, clip.Hotkey);
Expand All @@ -211,9 +214,9 @@ public void RemoveSoundClip(string? id)
return;
}

if (SoundClips.TryGetValue(id, out SoundClip clip))
if (SoundClips.TryGetValue(id, out SoundClip? clip))
{
App.HotkeysManager.RemoveHotkey(id, clip.Hotkey);
App.HotkeysManager.RemoveHotkey(id, clip?.Hotkey);

SoundClips.Remove(id);

Expand Down
2 changes: 1 addition & 1 deletion Helpers/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private ThemeManager()
];

public FontFamily TitleFont => FontFamily.Parse("avares://amplitude_soundboard/Assets/Fonts/JosefinSans/#Josefin Sans");
public FontFamily BodyFont => FontFamily.Parse("avares://amplitude_soundboard/Assets/Fonts/NotoSansDisplay/#Noto Sans Display");
public FontFamily BodyFont => FontFamily.Parse("avares://amplitude_soundboard/Assets/Fonts/OpenSans/#Open Sans");

public Bitmap ArrowLeft => GetBitmap(folder + "/ArrowLeft.png");
public Bitmap ArrowRight => GetBitmap(folder + "/ArrowRight.png");
Expand Down
16 changes: 8 additions & 8 deletions Helpers/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public Dictionary<string, EditOutputProfile> EditOutputProfileWindows

public void OpenEditOutputProfileWindow(string? Id = null)
{
if (Id != null && EditOutputProfileWindows.TryGetValue(Id, out EditOutputProfile window))
if (Id != null && EditOutputProfileWindows.TryGetValue(Id, out EditOutputProfile? window))
{
if (window.WindowState == WindowState.Minimized)
if (window?.WindowState == WindowState.Minimized)
{
window.WindowState = WindowState.Normal;
}
window.Activate();
window?.Activate();
}
else
{
Expand Down Expand Up @@ -149,13 +149,13 @@ public void ClosedEditOutputProfileWindow(string Id)

public void OpenEditSoundClipWindow(string? id = null)
{
if (id != null && EditSoundClipWindows.TryGetValue(id, out EditSoundClip window))
if (id != null && EditSoundClipWindows.TryGetValue(id, out EditSoundClip? window))
{
if (window.WindowState == WindowState.Minimized)
if (window?.WindowState == WindowState.Minimized)
{
window.WindowState = WindowState.Normal;
}
window.Activate();
window?.Activate();
}
else
{
Expand Down Expand Up @@ -193,7 +193,7 @@ public void OpenEditSoundClipWindow((int row, int col) addToCell)
sound.Show();
}

public void OpenedEditSoundClipWindow(string id, EditSoundClip editSoundClip)
public void OpenedEditSoundClipWindow(string? id, EditSoundClip editSoundClip)
{
if (!string.IsNullOrEmpty(id) && !EditSoundClipWindows.ContainsKey(id))
{
Expand All @@ -202,7 +202,7 @@ public void OpenedEditSoundClipWindow(string id, EditSoundClip editSoundClip)
}
}

public void ClosedEditSoundClipWindow(string id)
public void ClosedEditSoundClipWindow(string? id)
{
if (!string.IsNullOrEmpty(id) && EditSoundClipWindows.ContainsKey(id))
{
Expand Down
4 changes: 2 additions & 2 deletions Models/ErrorContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ErrorContainer(string errorMessage, SoundClip clip)
if (!string.IsNullOrEmpty(clip?.Id))
{
this.LinkedSoundClip = true;
this.SoundClipId = clip?.Id;
this.SoundClipId = clip.Id;
}
}

Expand All @@ -52,7 +52,7 @@ public ErrorContainer(string errorMessage, OutputProfile profile)
if (!string.IsNullOrEmpty(profile?.Id))
{
this.LinkedOutputProfile = true;
this.OutputProfileId = profile?.Id;
this.OutputProfileId = profile.Id;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Models/SoundClip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ public bool LoopClip
}

[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public ObservableCollection<OutputSettings> OutputSettingsFromProfile => App.OutputProfileManager.GetOutputProfile(OutputProfileId)?.OutputSettings;
public ObservableCollection<OutputSettings> OutputSettingsFromProfile => App.OutputProfileManager.GetOutputProfile(OutputProfileId)?.OutputSettings ?? [];

private ObservableCollection<OutputSettings> _outputSettings = new ObservableCollection<OutputSettings>();
private ObservableCollection<OutputSettings> _outputSettings = [];
[Obsolete]
public ObservableCollection<OutputSettings> OutputSettings
{
Expand Down
9 changes: 5 additions & 4 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Copyright (c) .NET Foundation and Contributors All Rights Reserved
https://github.com/AvaloniaUI/Avalonia

BASS, BASS_AAC, BASSALAC, BASSFLAC, BASSmix, BASSOPUS
Copyright (C) 2003-2021 un4seen developments
Copyright (c) 2003-2021 un4seen developments
https://www.un4seen.com/

Josefin Sans
Copyright (C) 2010 Santiago Orozco (hi@typemade.mx)
Copyright (c) 2010 Santiago Orozco (hi@typemade.mx)
https://github.com/googlefonts/josefinsans

ManagedBass
Expand All @@ -19,8 +19,9 @@ https://github.com/ManagedBass/ManagedBass
Material Design Icons
https://github.com/google/material-design-icons

Noto Sans Display
https://github.com/googlefonts/noto-fonts
Open Sans
Copyright (c) 2020 The Open Sans Project Authors
https://github.com/googlefonts/opensans

SharpHook
Copyright (c) 2021 Anatoliy Pylypchuk
Expand Down
5 changes: 3 additions & 2 deletions ViewModels/EditSoundClipViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ private void Model_PropertyChanged(object? sender, System.ComponentModel.Propert

public void OutputProfileSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0 && ((OutputProfile)e.AddedItems[0]).Id != Model.OutputProfileId)
var id = ((OutputProfile?)e.AddedItems[0])?.Id;
if (e.AddedItems.Count > 0 && id != null && id != Model.OutputProfileId)
{
Model.OutputProfileId = ((OutputProfile)e.AddedItems[0]).Id;
Model.OutputProfileId = id;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class ViewModelBase : ReactiveObject, INotifyPropertyChanged, ID

public virtual void Dispose() { }

public event PropertyChangedEventHandler? PropertyChanged;
public new event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
Expand Down
2 changes: 1 addition & 1 deletion Views/About.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<TextBlock IsVisible="{Binding CanUseCustomTitlebar}" Text="{i18n:Localize AboutTitle}" Classes="TITLE" FontWeight="Bold" FontFamily="{Binding ThemeManager.TitleFont}" Margin="10,10,10,10" HorizontalAlignment="Center" IsHitTestVisible="False" ></TextBlock>

<Grid RowDefinitions="*,Auto" Margin="0,30,0,0">
<Grid RowDefinitions="*,Auto" Margin="0,30,0,0" Name="styleroot">
<DockPanel Grid.Row="0">
<Grid RowDefinitions="Auto,*,*">
<!--Copyright-->
Expand Down
Loading

0 comments on commit d85d6b4

Please sign in to comment.