Skip to content
Merged
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
25 changes: 20 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
---
AccessModifierOffset: '-4'
AlignEscapedNewlines: Right
AlignTrailingComments:
Kind: Leave
AllowShortBlocksOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: 'Yes'
BreakBeforeBraces: Allman
BraceWrapping:
BeforeLambdaBody: false
AfterNamespace: true
AfterStruct: true
AfterEnum: true
AfterObjCDeclaration: false
AfterClass: true
AfterFunction: true
BeforeWhile: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
AfterControlStatement: Always
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
Expand All @@ -25,8 +42,7 @@ MaxEmptyLinesToKeep: '1'
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: 'false'
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SortIncludes: 'false'
SpaceAfterCStyleCast: 'false'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
Expand All @@ -45,5 +61,4 @@ SpacesInSquareBrackets: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: Never

...
...
26 changes: 26 additions & 0 deletions .github/workflows/ci_clang-format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "CI"

# This is a CI workflow that check if every source files are clang-format compliant

on:
workflow_dispatch:
pull_request:
push:

permissions:
contents: read

jobs:
formatting-check:
name: clang-format Check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.15.0
with:
clang-format-version: '20'
check-path: 'src'
fallback-style: 'Microsoft'
5 changes: 2 additions & 3 deletions src/audioPlayer/Audio_System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Audio_System::~Audio_System()
{
m_pEngine->StopEngine();
m_pMaster->DestroyVoice();

for (auto [name, voice] : m_subVoices)
{
voice->DestroyVoice();
Expand Down Expand Up @@ -222,8 +222,7 @@ void Audio_System::removeChannel(const Channel& channel)
const std::string Target_Mixer = channel.getMixerName();

auto it = std::find_if(std::begin(m_activeChannelPtrs[Target_Mixer]), std::end(m_activeChannelPtrs[Target_Mixer]),
[&channel](const std::unique_ptr<Channel>& pChan)
{
[&channel](const std::unique_ptr<Channel>& pChan) {
return &channel == pChan.get();
});

Expand Down
4 changes: 2 additions & 2 deletions src/audioPlayer/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ Channel::~Channel()
}
}
}

} while (!DeactivatedEveryWhere);
}
while (!DeactivatedEveryWhere);

m_pSource->Stop();
m_pSource->DestroyVoice();
Expand Down
2 changes: 1 addition & 1 deletion src/audioPlayer/FileProcessing_MP3.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if (!MINIMP3_ONLY_SIMD) && _MSC_VER
/* x64 always have SSE2, arm64 always have neon, no need for generic code */
#define MINIMP3_ONLY_SIMD // error in x86 platform if not defined
#define MINIMP3_ONLY_SIMD // error in x86 platform if not defined
#endif // (!MINIMP3_ONLY_SIMD) && _MSC_VER

#define MINIMP3_IMPLEMENTATION
Expand Down
13 changes: 7 additions & 6 deletions src/audioPlayer/FileProcessing_WAV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ bool FileProcessing_WAV::collectData(const BYTE* _fileData, int _fileSize)
bool FileProcessing_WAV::onBufferEnd(Channel& channel)
{
std::lock_guard<std::mutex> lock(m_timeChanging_mutex);
auto it = std::find_if(std::begin(m_timeChanging), std::end(m_timeChanging), [&channel](Channel& _channel)
{ return &channel == &_channel; });
auto it = std::find_if(std::begin(m_timeChanging), std::end(m_timeChanging), [&channel](Channel& _channel) {
return &channel == &_channel;
});

bool TimeChange = it != std::end(m_timeChanging);

if (channel.getSound().isLooping() && !channel.isForcedStop())
Expand Down Expand Up @@ -213,10 +215,9 @@ void FileProcessing_WAV::setPlayTime(Channel& channel, double time)
{
std::this_thread::sleep_for(std::chrono::milliseconds(5));
std::lock_guard<std::mutex> lock(m_timeChanging_mutex);
waitingReset = std::find_if(std::begin(m_timeChanging), std::end(m_timeChanging), [&channel](Channel& _channel)
{ return &channel == &_channel; }) != std::end(m_timeChanging);

} while (waitingReset);
waitingReset = std::find_if(std::begin(m_timeChanging), std::end(m_timeChanging), [&channel](Channel& _channel) { return &channel == &_channel; }) != std::end(m_timeChanging);
}
while (waitingReset);

{
std::lock_guard<std::mutex> lock(channel.getSourceVoiceMutex());
Expand Down
44 changes: 27 additions & 17 deletions src/audioPlayer/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,18 @@ Sound::~Sound()
{
std::lock_guard<std::mutex> lock(m_channelHandles_mutex);

std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel)
{ channel.stop(); });
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel) {
channel.stop();
});
}

bool allChannelsDeactivated = false;
do
{
std::lock_guard<std::mutex> lock(m_channelHandles_mutex);
allChannelsDeactivated = m_channelHandles.empty();
} while (!allChannelsDeactivated);
}
while (!allChannelsDeactivated);

this->m_file.reset();

Expand Down Expand Up @@ -210,22 +212,25 @@ void Sound::play()
void Sound::resume()
{
std::lock_guard<std::mutex> lock(m_channelHandles_mutex);
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel)
{ channel.resume(); });
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel) {
channel.resume();
});
}

void Sound::pause()
{
std::lock_guard<std::mutex> lock(m_channelHandles_mutex);
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel)
{ channel.pause(); });
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel) {
channel.pause();
});
}

void Sound::stop()
{
std::lock_guard<std::mutex> lock(m_channelHandles_mutex);
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel)
{ channel.stop(); });
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel) {
channel.stop();
});
}

void Sound::setMixer(std::string _mixerName)
Expand All @@ -239,17 +244,19 @@ void Sound::setVolume(float volume)
m_volume = std::clamp(volume, 0.f, 100.f);

std::lock_guard<std::mutex> lock(m_channelHandles_mutex);
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [this](Channel& channel)
{ channel.setVolume(m_volume); });
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [this](Channel& channel) {
channel.setVolume(m_volume);
});
}

void Sound::setSpeed(float speed)
{
m_speed = std::clamp(speed, 0.1f, 200.f);

std::lock_guard<std::mutex> lock(m_channelHandles_mutex);
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [this](Channel& channel)
{ channel.setSpeed(m_speed); });
std::for_each(std::begin(m_channelHandles), std::end(m_channelHandles), [this](Channel& channel) {
channel.setSpeed(m_speed);
});
}

double Sound::getAudioDuration() const
Expand Down Expand Up @@ -367,8 +374,10 @@ void Sound::addChannel(Channel& channel)
void Sound::removeChannel(Channel& channel)
{
std::lock_guard<std::mutex> lock(m_channelHandles_mutex);
auto it = std::find_if(std::begin(m_channelHandles), std::end(m_channelHandles), [&channel](Channel& _channel)
{ return &channel == &_channel; });
auto it = std::find_if(std::begin(m_channelHandles), std::end(m_channelHandles), [&channel](Channel& _channel) {
return &channel == &_channel;
});

if (it != std::end(m_channelHandles))
{
m_channelHandles.erase(it);
Expand All @@ -389,8 +398,9 @@ Sound::Statut Sound::getStatus() const
}
else
{
auto num_paused = std::count_if(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel)
{ return channel.getSpeed() <= 0.05f; });
auto num_paused = std::count_if(std::begin(m_channelHandles), std::end(m_channelHandles), [](Channel& channel) {
return channel.getSpeed() <= 0.05f;
});

if (num_paused == 0)
{
Expand Down