Skip to content

Commit

Permalink
hitsound updates.
Browse files Browse the repository at this point in the history
potentially jank/problematic.
feel free to do your own magic on top of this or clean up shit.
  • Loading branch information
Yasu3D authored and Raymonf committed Dec 3, 2023
1 parent 37d75e3 commit f540bd6
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 43 deletions.
5 changes: 4 additions & 1 deletion BAKKA_Editor/Assets/locales/en-US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@
<system:String x:Key="L.Settings.Labels.ColorHint">To revert or choose a game-accurate color, click on a note type and check the palette (second) tab at the top :)</system:String>

<system:String x:Key="L.Settings.Buttons.SelectHitsoundPath">Select File</system:String>
<system:String x:Key="L.Settings.CheckBoxes.EnableHitsound">Enable Hitsounds</system:String>
<system:String x:Key="L.Settings.CheckBoxes.EnableHitsound">Tap Hitsounds</system:String>
<system:String x:Key="L.Settings.CheckBoxes.EnableHitsoundSwipe">Swipe Hitsounds</system:String>
<system:String x:Key="L.Settings.CheckBoxes.EnableHitsoundBonus">Bonus Hitsounds</system:String>
<system:String x:Key="L.Settings.CheckBoxes.EnableHitsoundFlair">Flair Hitsounds</system:String>
<system:String x:Key="L.Settings.Labels.HitsoundOffsetMs">Additional Hitsound Offset (milliseconds):</system:String>
<system:String x:Key="L.Settings.Labels.HitsoundRestartRequiredWarning">Please be advised that changing the hitsound path will require a restart to take effect (for the time being).</system:String>
</ResourceDictionary>
85 changes: 85 additions & 0 deletions BAKKA_Editor/Audio/Hitsounds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using BAKKA_Editor.Enums;
using BAKKA_Editor.SoundEngines;
using BAKKA_Editor.Views;
using System;
using System.Collections.Generic;

namespace BAKKA_Editor.Audio;

internal class Hitsounds
{
private IBakkaSampleChannel? hitsoundChannel;
private IBakkaSampleChannel? hitsoundSwipeChannel;
private IBakkaSampleChannel? hitsoundBonusChannel;
private IBakkaSampleChannel? hitsoundFlairChannel;

private IBakkaSample? hitsoundSample;
private IBakkaSample? hitsoundSwipeSample;
private IBakkaSample? hitsoundBonusSample;
private IBakkaSample? hitsoundFlairSample;
private UserSettings userSettings;
private MainView mainView;

public Hitsounds(UserSettings settings, MainView main)
{
userSettings = settings;
mainView = main;
}

public void LoadSamples(string hitsoundPath, string hitsoundSwipePath, string hitsoundBonusPath, string hitsoundFlairPath)
{
hitsoundSample = new BassBakkaSample(hitsoundPath);
hitsoundSwipeSample = new BassBakkaSample(hitsoundSwipePath);
hitsoundBonusSample = new BassBakkaSample(hitsoundBonusPath);
hitsoundFlairSample = new BassBakkaSample(hitsoundFlairPath);

if (hitsoundSample.Loaded) hitsoundChannel = hitsoundSample.GetChannel();
if (hitsoundSwipeSample.Loaded) hitsoundSwipeChannel = hitsoundSwipeSample.GetChannel();
if (hitsoundBonusSample.Loaded) hitsoundBonusChannel = hitsoundBonusSample.GetChannel();
if (hitsoundFlairSample.Loaded) hitsoundFlairChannel = hitsoundFlairSample.GetChannel();
}

public bool LoadError()
{
if (userSettings.SoundSettings.HitsoundEnabled && !hitsoundSample.Loaded

Check warning on line 44 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

Dereference of a possibly null reference.

Check warning on line 44 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

Dereference of a possibly null reference.

Check warning on line 44 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64)

Dereference of a possibly null reference.

Check warning on line 44 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

Dereference of a possibly null reference.
||(userSettings.SoundSettings.HitsoundSwipeEnabled && !hitsoundSwipeSample.Loaded)

Check warning on line 45 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

Dereference of a possibly null reference.

Check warning on line 45 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

Dereference of a possibly null reference.

Check warning on line 45 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64)

Dereference of a possibly null reference.

Check warning on line 45 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

Dereference of a possibly null reference.
|| (userSettings.SoundSettings.HitsoundBonusEnabled && !hitsoundBonusSample.Loaded)

Check warning on line 46 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

Dereference of a possibly null reference.

Check warning on line 46 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

Dereference of a possibly null reference.

Check warning on line 46 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64)

Dereference of a possibly null reference.

Check warning on line 46 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

Dereference of a possibly null reference.
|| (userSettings.SoundSettings.HitsoundFlairEnabled && !hitsoundFlairSample.Loaded))

Check warning on line 47 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

Dereference of a possibly null reference.

Check warning on line 47 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

Dereference of a possibly null reference.

Check warning on line 47 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64)

Dereference of a possibly null reference.

Check warning on line 47 in BAKKA_Editor/Audio/Hitsounds.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

Dereference of a possibly null reference.
return true;

return false;
}

public bool ChannelsExist()
{
if ((userSettings.SoundSettings.HitsoundEnabled && hitsoundChannel != null)
|| (userSettings.SoundSettings.HitsoundSwipeEnabled && hitsoundSwipeChannel != null)
|| (userSettings.SoundSettings.HitsoundBonusEnabled && hitsoundBonusChannel != null)
|| (userSettings.SoundSettings.HitsoundFlairEnabled && hitsoundFlairChannel != null))
return true;

return false;
}

public void SetVolume(float volume)
{
hitsoundChannel?.SetVolume(volume);
hitsoundSwipeChannel?.SetVolume(volume);
hitsoundBonusChannel?.SetVolume(volume);
hitsoundFlairChannel?.SetVolume(volume);
}

public void Play(Note note, float lastMeasure)
{
if (note.NoteType is NoteType.EndOfChart or NoteType.MaskAdd or NoteType.MaskRemove or NoteType.HoldJoint) return;

if (note.BeatInfo.MeasureDecimal > lastMeasure)
{
if ((note.IsSnap || note.IsSlide) && userSettings.SoundSettings.HitsoundSwipeEnabled) hitsoundSwipeChannel?.Play(true);
else if (userSettings.SoundSettings.HitsoundEnabled) hitsoundChannel?.Play(true);
if (note.IsBonus && userSettings.SoundSettings.HitsoundBonusEnabled) hitsoundBonusChannel?.Play(true);
if (note.IsFlair && userSettings.SoundSettings.HitsoundFlairEnabled) hitsoundFlairChannel?.Play(true);
}
}
}

22 changes: 11 additions & 11 deletions BAKKA_Editor/BAKKA_Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**"/>
<TrimmerRootDescriptor Include="Roots.xml"/>
<AvaloniaResource Include="Assets\**" />
<TrimmerRootDescriptor Include="Roots.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1"/>
<PackageReference Include="FluentAvaloniaUI" Version="2.0.4"/>
<PackageReference Include="ManagedBass" Version="3.1.1"/>
<PackageReference Include="ManagedBass.Flac" Version="3.1.1"/>
<PackageReference Include="ManagedBass.Fx" Version="3.1.1"/>
<PackageReference Include="Tomlyn" Version="0.16.2"/>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="FluentAvaloniaUI" Version="2.0.4" />
<PackageReference Include="ManagedBass" Version="3.1.1" />
<PackageReference Include="ManagedBass.Flac" Version="3.1.1" />
<PackageReference Include="ManagedBass.Fx" Version="3.1.1" />
<PackageReference Include="Tomlyn" Version="0.16.2" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)"/>
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions BAKKA_Editor/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ public class HotkeySettings
public class SoundSettings
{
public bool HitsoundEnabled { get; set; } = false;
public bool HitsoundSwipeEnabled { get; set; } = false;
public bool HitsoundBonusEnabled { get; set; } = false;
public bool HitsoundFlairEnabled { get; set; } = false;
public string HitsoundPath { get; set; } = "";
public string HitsoundSwipePath { get; set; } = "";
public string HitsoundBonusPath { get; set; } = "";
public string HitsoundFlairPath { get; set; } = "";
public int HitsoundVolume { get; set; } = 50;
public int HitsoundAdditionalOffsetMs { get; set; } = 0;
}
Expand Down
124 changes: 122 additions & 2 deletions BAKKA_Editor/ViewModels/AppSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using BAKKA_Editor.Rendering;
using Avalonia.Styling;
using Avalonia;
using BAKKA_Editor.Audio;

namespace BAKKA_Editor.ViewModels;

Expand All @@ -22,6 +23,7 @@ public partial class AppSettingsViewModel : ViewModelBase
private UserSettings? UserSettings { get; }
private MainViewModel? MainViewModel { get; }
private Localizer? Localizer { get; }
private Hitsounds? Hitsounds { get; }
public ContentDialog? Dialog { get; set; }

private Dictionary<string, string> SupportedLanguages { get; } = new()
Expand Down Expand Up @@ -60,9 +62,18 @@ public void Setup(UserSettings userSettings)
ShowMaskEffects = userSettings.ViewSettings.ShowMaskEffects;

UseSpaceKeyToPlay = userSettings.ViewSettings.UseSpaceToPlaySink;

HitsoundEnabled = userSettings.SoundSettings.HitsoundEnabled;
HitsoundOffsetMs = userSettings.SoundSettings.HitsoundAdditionalOffsetMs;
HitsoundSwipeEnabled = userSettings.SoundSettings.HitsoundSwipeEnabled;
HitsoundBonusEnabled = userSettings.SoundSettings.HitsoundBonusEnabled;
HitsoundFlairEnabled = userSettings.SoundSettings.HitsoundFlairEnabled;

HitsoundPath = userSettings.SoundSettings.HitsoundPath;
HitsoundSwipePath = userSettings.SoundSettings.HitsoundSwipePath;
HitsoundBonusPath = userSettings.SoundSettings.HitsoundBonusPath;
HitsoundFlairPath = userSettings.SoundSettings.HitsoundFlairPath;

HitsoundOffsetMs = userSettings.SoundSettings.HitsoundAdditionalOffsetMs;

ColorNoteTap = Color.Parse(userSettings.ColorSettings.ColorNoteTap);
ColorNoteChain = Color.Parse(userSettings.ColorSettings.ColorNoteChain);
Expand Down Expand Up @@ -305,6 +316,48 @@ partial void OnHitsoundPathChanged(string value)
UserSettings.SoundSettings.HitsoundPath = value;
}

[ObservableProperty] private bool hitsoundSwipeEnabled = false;
partial void OnHitsoundSwipeEnabledChanged(bool value)
{
if (UserSettings != null)
UserSettings.SoundSettings.HitsoundSwipeEnabled = value;
}

[ObservableProperty] private string hitsoundSwipePath = "";
partial void OnHitsoundSwipePathChanged(string value)
{
if (UserSettings != null)
UserSettings.SoundSettings.HitsoundSwipePath = value;
}

[ObservableProperty] private bool hitsoundBonusEnabled = false;
partial void OnHitsoundBonusEnabledChanged(bool value)
{
if (UserSettings != null)
UserSettings.SoundSettings.HitsoundBonusEnabled = value;
}

[ObservableProperty] private string hitsoundBonusPath = "";
partial void OnHitsoundBonusPathChanged(string value)
{
if (UserSettings != null)
UserSettings.SoundSettings.HitsoundBonusPath = value;
}

[ObservableProperty] private bool hitsoundFlairEnabled = false;
partial void OnHitsoundFlairEnabledChanged(bool value)
{
if (UserSettings != null)
UserSettings.SoundSettings.HitsoundFlairEnabled = value;
}

[ObservableProperty] private string hitsoundFlairPath = "";
partial void OnHitsoundFlairPathChanged(string value)
{
if (UserSettings != null)
UserSettings.SoundSettings.HitsoundFlairPath = value;
}

[ObservableProperty] private decimal hitsoundOffsetMs = 0;

partial void OnHitsoundOffsetMsChanged(decimal value)
Expand All @@ -331,7 +384,74 @@ public async Task SelectHitsoundPathCommand()

if (files.Count >= 1)
{
HitsoundPath = files[0].Path.AbsolutePath;
HitsoundPath = System.Uri.UnescapeDataString(files[0].Path.AbsolutePath);
}
}

public async Task SelectHitsoundSwipePathCommand()
{
// TODO: MOVE THIS OUT MOVE THIS OUT MOVE THIS OUT

var topLevel = TopLevel.GetTopLevel(Dialog);
if (topLevel == null)
{
return;
}

var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Open Hitsound File",
AllowMultiple = false
});

if (files.Count >= 1)
{
HitsoundSwipePath = System.Uri.UnescapeDataString(files[0].Path.AbsolutePath);
}
}

public async Task SelectHitsoundBonusPathCommand()
{
// TODO: MOVE THIS OUT MOVE THIS OUT MOVE THIS OUT

var topLevel = TopLevel.GetTopLevel(Dialog);
if (topLevel == null)
{
return;
}

var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Open Hitsound File",
AllowMultiple = false
});

if (files.Count >= 1)
{
HitsoundBonusPath = System.Uri.UnescapeDataString(files[0].Path.AbsolutePath);
}
}

public async Task SelectHitsoundFlairPathCommand()
{
// TODO: MOVE THIS OUT MOVE THIS OUT MOVE THIS OUT

var topLevel = TopLevel.GetTopLevel(Dialog);
if (topLevel == null)
{
return;
}

var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Open Hitsound File",
AllowMultiple = false
});

if (files.Count >= 1)
{
// unescape path to allow for spaces in filenames/directories
HitsoundFlairPath = System.Uri.UnescapeDataString(files[0].Path.AbsolutePath);
}
}
}
Loading

0 comments on commit f540bd6

Please sign in to comment.