Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/LiveSplit.Sound/UI/Components/EventType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace LiveSplit.UI.Components;
public enum EventType
{
Split,
SplitAheadGaining,
SplitAheadLosing,
SplitBehindGaining,
SplitBehindLosing,
BestSegment,
UndoSplit,
SkipSplit,
PersonalBest,
NotAPersonalBest,
Reset,
Pause,
Resume,
StartTimer,
}

public static class EventTypeEx
{
public static string GetName(this EventType type)
{
return type switch
{
EventType.Split => "Split",
EventType.SplitAheadGaining => "Split(Ahead, Gaining Time):",
EventType.SplitAheadLosing => "Split(Ahead, Losing Time):",
EventType.SplitBehindGaining => "Split(Behind, Gaining Time):",
EventType.SplitBehindLosing => "Split(Behind, Losing Time):",
EventType.BestSegment => "Split(Best Segment):",
EventType.UndoSplit => "Undo Split:",
EventType.SkipSplit => "Skip Split:",
EventType.PersonalBest => "Personal Best:",
EventType.NotAPersonalBest => "Not a Personal Best:",
EventType.Reset => "Reset:",
EventType.Pause => "Pause:",
EventType.Resume => "Resume:",
EventType.StartTimer => "Start:",
_ => "no name",
};
}
}
129 changes: 64 additions & 65 deletions src/LiveSplit.Sound/UI/Components/SoundComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override void SetSettings(XmlNode settings)

private void State_OnStart(object sender, EventArgs e)
{
PlaySound(Settings.StartTimer, Settings.StartTimerVolume);
PlaySound(EventType.StartTimer);
}

private void State_OnSplit(object sender, EventArgs e)
Expand All @@ -80,121 +80,120 @@ private void State_OnSplit(object sender, EventArgs e)
{
if (State.Run.Last().PersonalBestSplitTime[State.CurrentTimingMethod] == null || State.Run.Last().SplitTime[State.CurrentTimingMethod] < State.Run.Last().PersonalBestSplitTime[State.CurrentTimingMethod])
{
PlaySound(Settings.PersonalBest, Settings.PersonalBestVolume);
PlaySound(EventType.PersonalBest);
}
else
{
PlaySound(Settings.NotAPersonalBest, Settings.NotAPersonalBestVolume);
PlaySound(EventType.NotAPersonalBest);
}

return;
}
else
{
string path = string.Empty;
int volume = Settings.SplitVolume;

int splitIndex = State.CurrentSplitIndex - 1;
TimeSpan? timeDifference = State.Run[splitIndex].SplitTime[State.CurrentTimingMethod] - State.Run[splitIndex].Comparisons[State.CurrentComparison][State.CurrentTimingMethod];
EventType type = EventType.Split;

if (timeDifference != null)
int splitIndex = State.CurrentSplitIndex - 1;
TimeSpan? timeDifference = State.Run[splitIndex].SplitTime[State.CurrentTimingMethod] - State.Run[splitIndex].Comparisons[State.CurrentComparison][State.CurrentTimingMethod];

if (timeDifference != null)
{
if (timeDifference < TimeSpan.Zero)
{
if (timeDifference < TimeSpan.Zero)
{
path = Settings.SplitAheadGaining;
volume = Settings.SplitAheadGainingVolume;

if (LiveSplitStateHelper.GetPreviousSegmentDelta(State, splitIndex, State.CurrentComparison, State.CurrentTimingMethod) > TimeSpan.Zero)
{
path = Settings.SplitAheadLosing;
volume = Settings.SplitAheadLosingVolume;
}
}
else
type = EventType.SplitAheadGaining;

if (LiveSplitStateHelper.GetPreviousSegmentDelta(State, splitIndex, State.CurrentComparison, State.CurrentTimingMethod) > TimeSpan.Zero)
{
path = Settings.SplitBehindLosing;
volume = Settings.SplitBehindLosingVolume;

if (LiveSplitStateHelper.GetPreviousSegmentDelta(State, splitIndex, State.CurrentComparison, State.CurrentTimingMethod) < TimeSpan.Zero)
{
path = Settings.SplitBehindGaining;
volume = Settings.SplitBehindGainingVolume;
}
type = EventType.SplitAheadLosing;
}
}

//Check for best segment
TimeSpan? curSegment = LiveSplitStateHelper.GetPreviousSegmentTime(State, splitIndex, State.CurrentTimingMethod);

if (curSegment != null)
else
{
if (State.Run[splitIndex].BestSegmentTime[State.CurrentTimingMethod] == null || curSegment < State.Run[splitIndex].BestSegmentTime[State.CurrentTimingMethod])
type = EventType.SplitBehindLosing;

if (LiveSplitStateHelper.GetPreviousSegmentDelta(State, splitIndex, State.CurrentComparison, State.CurrentTimingMethod) < TimeSpan.Zero)
{
path = Settings.BestSegment;
volume = Settings.BestSegmentVolume;
type = EventType.SplitBehindGaining;
}
}
}

//Check for best segment
TimeSpan? curSegment = LiveSplitStateHelper.GetPreviousSegmentTime(State, splitIndex, State.CurrentTimingMethod);

if (string.IsNullOrEmpty(path))
if (curSegment != null)
{
if (State.Run[splitIndex].BestSegmentTime[State.CurrentTimingMethod] == null || curSegment < State.Run[splitIndex].BestSegmentTime[State.CurrentTimingMethod])
{
path = Settings.Split;
type = EventType.BestSegment;
}
}

PlaySound(path, volume);
if (string.IsNullOrEmpty(Settings.SoundDataDictionary[type].FilePath))
{
type = EventType.Split;
}

PlaySound(type);
}

private void State_OnSkipSplit(object sender, EventArgs e)
{
PlaySound(Settings.SkipSplit, Settings.SkipSplitVolume);
PlaySound(EventType.SkipSplit);
}

private void State_OnUndoSplit(object sender, EventArgs e)
{
PlaySound(Settings.UndoSplit, Settings.UndoSplitVolume);
PlaySound(EventType.UndoSplit);
}

private void State_OnPause(object sender, EventArgs e)
{
PlaySound(Settings.Pause, Settings.PauseVolume);
PlaySound(EventType.Pause);
}

private void State_OnResume(object sender, EventArgs e)
{
PlaySound(Settings.Resume, Settings.ResumeVolume);
PlaySound(EventType.Resume);
}

private void State_OnReset(object sender, TimerPhase e)
{
if (e != TimerPhase.Ended)
{
PlaySound(Settings.Reset, Settings.ResetVolume);
PlaySound(EventType.Reset);
}
}

private void PlaySound(string location, int volume)
private void PlaySound(EventType type)
{
Player.Stop();

if (Activated && File.Exists(location))
string location = Settings.SoundDataDictionary[type].FilePath;
int volume = Settings.SoundDataDictionary[type].Volume;

if (!Activated || !File.Exists(location))
{
Task.Factory.StartNew(() =>
return;
}

Task.Factory.StartNew(() =>
{
try
{
try
{
var audioFileReader = new AudioFileReader(location)
{
Volume = volume / 100f * (Settings.GeneralVolume / 100f)
};

Player.DeviceNumber = Settings.OutputDevice;
Player.Init(audioFileReader);
Player.Play();
}
catch (Exception e)
var audioFileReader = new AudioFileReader(location)
{
Log.Error(e);
}
});
}
Volume = volume / 100f * (Settings.GeneralVolume / 100f)
};

Player.DeviceNumber = Settings.OutputDevice;
Player.Init(audioFileReader);
Player.Play();
}
catch (Exception e)
{
Log.Error(e);
}
});
}

public int GetSettingsHashCode()
Expand Down
12 changes: 12 additions & 0 deletions src/LiveSplit.Sound/UI/Components/SoundData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace LiveSplit.UI.Components;
public class SoundData
{
public string FilePath { get; set; }
public int Volume { get; set; }

public SoundData(string filePath, int volume)
{
FilePath = filePath;
Volume = volume;
}
}
99 changes: 99 additions & 0 deletions src/LiveSplit.Sound/UI/Components/SoundFileSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading