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
18 changes: 6 additions & 12 deletions LiveSplit.Sound.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="LiveSplit.Core">
<HintPath>..\..\bin\Debug\LiveSplit.Core.dll</HintPath>
</Reference>
<Reference Include="NAudio">
<HintPath>..\..\Libs\NAudio.1.7.3\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="UpdateManager">
<HintPath>..\..\bin\Debug\UpdateManager.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -67,18 +73,6 @@
<DependentUpon>SoundSettings.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\LiveSplit.Core\LiveSplit.Core.csproj">
<Project>{6de847db-20a3-4848-aeee-1b4364aecdfb}</Project>
<Name>LiveSplit.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\UpdateManager\UpdateManager.csproj">
<Project>{56dea3a0-2eb7-493b-b50f-a5e3aa8ae52a}</Project>
<Name>UpdateManager</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions LiveSplit.Sound.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveSplit.Sound", "LiveSplit.Sound.csproj", "{16B6E638-E21D-4B8A-88B0-4BBA25E95913}"
EndProject
Expand Down
113 changes: 83 additions & 30 deletions UI/Components/SoundComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SoundComponent : LogicComponent, IDeactivatableComponent

private LiveSplitState State { get; set; }
private SoundSettings Settings { get; set; }

private WaveOut Player { get; set; }

public SoundComponent(LiveSplitState state)
Expand Down Expand Up @@ -72,63 +73,115 @@ private void State_OnStart(object sender, EventArgs e)
PlaySound(Settings.StartTimer, Settings.StartTimerVolume);
}

private enum RunState
{
Indetermined,
AheadGaining,
AheadLosing,
BehindGaining,
BehindLosing,
BestSegment
}

private static RunState GetRunState(LiveSplitState state, int splitIndex)
{
if (splitIndex < 0)
{
return RunState.Indetermined;
}

TimeSpan? curSegment = LiveSplitStateHelper.GetPreviousSegmentTime(state, splitIndex, state.CurrentTimingMethod);

if (curSegment != null)
{
if (state.Run[splitIndex].BestSegmentTime[state.CurrentTimingMethod] == null || curSegment < state.Run[splitIndex].BestSegmentTime[state.CurrentTimingMethod])
{
return RunState.BestSegment;
}
}

var timeDifference = state.Run[splitIndex].SplitTime[state.CurrentTimingMethod] - state.Run[splitIndex].Comparisons[state.CurrentComparison][state.CurrentTimingMethod];

if (timeDifference == null)
{
return RunState.Indetermined;
}

if (timeDifference < TimeSpan.Zero)
{
if (LiveSplitStateHelper.GetPreviousSegmentDelta(state, splitIndex, state.CurrentComparison, state.CurrentTimingMethod) > TimeSpan.Zero)
{
return RunState.AheadLosing;
}

return RunState.AheadGaining;
}

if (LiveSplitStateHelper.GetPreviousSegmentDelta(state, splitIndex, state.CurrentComparison, state.CurrentTimingMethod) < TimeSpan.Zero)
{
return RunState.BehindGaining;
}

return RunState.BehindLosing;
}

private void State_OnSplit(object sender, EventArgs e)
{
if (State.CurrentPhase == TimerPhase.Ended)
//if the run is over
{
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);
//if PB
else
PlaySound(Settings.NotAPersonalBest, Settings.NotAPersonalBestVolume);
// not a PB
}
else
{
var path = string.Empty;
int volume = Settings.SplitVolume;

var splitIndex = State.CurrentSplitIndex - 1;
var timeDifference = State.Run[splitIndex].SplitTime[State.CurrentTimingMethod] - State.Run[splitIndex].Comparisons[State.CurrentComparison][State.CurrentTimingMethod];
var curRunState = GetRunState(State, splitIndex);
var prevRunState = GetRunState(State, splitIndex - 1);

if (timeDifference != null)
if (curRunState == prevRunState && curRunState != RunState.BestSegment && Settings.IsSituationModeChecked())
{
if (timeDifference < TimeSpan.Zero)
{
return; // pas de son du tout
}

switch (curRunState)
{
case RunState.AheadGaining:
path = Settings.SplitAheadGaining;
volume = Settings.SplitAheadGainingVolume;
break;

if (LiveSplitStateHelper.GetPreviousSegmentDelta(State, splitIndex, State.CurrentComparison, State.CurrentTimingMethod) > TimeSpan.Zero)
{
path = Settings.SplitAheadLosing;
volume = Settings.SplitAheadLosingVolume;
}
}
else
{
path = Settings.SplitBehindLosing;
volume = Settings.SplitBehindLosingVolume;
case RunState.AheadLosing:
path = Settings.SplitAheadLosing;
volume = Settings.SplitAheadLosingVolume;
break;

if (LiveSplitStateHelper.GetPreviousSegmentDelta(State, splitIndex, State.CurrentComparison, State.CurrentTimingMethod) < TimeSpan.Zero)
{
path = Settings.SplitBehindGaining;
volume = Settings.SplitBehindGainingVolume;
}
}
}
case RunState.BehindGaining:
path = Settings.SplitBehindGaining;
volume = Settings.SplitBehindGainingVolume;
break;

//Check for best segment
TimeSpan? curSegment = LiveSplitStateHelper.GetPreviousSegmentTime(State, splitIndex, State.CurrentTimingMethod);
case RunState.BehindLosing:
path = Settings.SplitBehindLosing;
volume = Settings.SplitBehindLosingVolume;
break;

if (curSegment != null)
{
if (State.Run[splitIndex].BestSegmentTime[State.CurrentTimingMethod] == null || curSegment < State.Run[splitIndex].BestSegmentTime[State.CurrentTimingMethod])
{
case RunState.BestSegment:
path = Settings.BestSegment;
volume = Settings.BestSegmentVolume;
}
break;

default: break; //do nothing by default
}

if (string.IsNullOrEmpty(path))
path = Settings.Split;
if (string.IsNullOrEmpty(path)) path = Settings.Split;

PlaySound(path, volume);
}
Expand Down
Loading