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
4 changes: 3 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Checks: '-*,clang-analyzer-*,-clang-analyzer-cplusplus*'
Checks: 'performance-*,modernize-*,readability-*,-readability-identifier-length'
CheckOptions:
UnusedIncludes: Strict
5 changes: 5 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ CompileFlags:
Add:
- '-std=c++17'
- '-Iinclude'
Diagnostics:
UnusedIncludes: Strict
ClangTidy:
Add: [performance-*, modernize-*, readability-*]
Remove: [readability-identifier-length]
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "Win32",
"includePath": ["${workspaceFolder}/**", "${workspaceFolder}/include"],
"defines": [],
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.40.33617/bin/Hostx64/x64/cl.exe",
"compilerPath": "${env:VCINSTALLDIR}/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
Expand Down
Empty file added compile_flags.txt
Empty file.
22 changes: 8 additions & 14 deletions include/RhythmGameUtilities/Audio.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <algorithm>
#include <cmath>

#ifdef _WIN32
Expand All @@ -23,10 +24,10 @@ extern "C"
* @public
*/

PACKAGE_API int **ConvertSamplesToWaveform(float *samples, int size,
PACKAGE_API int **ConvertSamplesToWaveform(const float *samples, int size,
int width, int height)
{
auto waveform = new int *[width];
auto *waveform = new int *[width];

auto step = floor(size / width);
auto amp = height / 2;
Expand All @@ -35,24 +36,17 @@ extern "C"
{
waveform[x] = new int[height];

auto min = 1.0f;
auto max = -1.0f;
auto min = 1.0F;
auto max = -1.0F;

for (auto j = 0; j < step; j += 1)
{
auto index = static_cast<int>(x * step + j);
auto index = static_cast<int>((x * step) + j);

auto datum = samples[index];

if (datum < min)
{
min = datum;
}

if (datum > max)
{
max = datum;
}
min = std::min(datum, min);
max = std::max(datum, max);
}

auto minY = static_cast<int>((1 + min) * amp);
Expand Down
10 changes: 5 additions & 5 deletions include/RhythmGameUtilities/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C"

PACKAGE_API float Lerp(float a, float b, float t)
{
return (1 - t) * a + b * t;
return ((1 - t) * a) + (b * t);
}

/**
Expand All @@ -40,7 +40,7 @@ extern "C"

PACKAGE_API float InverseLerp(float a, float b, float v)
{
return std::clamp(((v - a) / (b - a)), 0.0f, 1.0f);
return std::clamp(((v - a) / (b - a)), 0.0F, 1.0F);
}
}

Expand Down Expand Up @@ -82,7 +82,7 @@ inline std::vector<std::string> Split(const char *contents,
}

inline std::vector<std::string> FindAllMatches(const char *contents,
std::regex pattern)
const std::regex &pattern)
{
auto currentMatch =
std::cregex_iterator(contents, contents + strlen(contents), pattern);
Expand All @@ -103,14 +103,14 @@ inline std::vector<std::string> FindAllMatches(const char *contents,
}

inline std::vector<std::string> FindMatchGroups(const char *contents,
std::regex pattern)
const std::regex &pattern)
{
auto currentMatch =
std::cregex_iterator(contents, contents + strlen(contents), pattern);

auto matches = std::vector<std::string>();

auto match = *currentMatch;
const auto &match = *currentMatch;

for (auto i = 0; i < match.size(); i += 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace RhythmGameUtilities

typedef enum Difficulty
{

// Easy Difficulty
Easy,

Expand All @@ -19,7 +18,6 @@ typedef enum Difficulty

// Expert Difficulty
Expert

} DifficultyType;

inline std::string ToString(Difficulty difficulty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace RhythmGameUtilities

typedef enum TypeCode
{

/// BPM Marker
BPM_Marker,

Expand All @@ -19,7 +18,6 @@ typedef enum TypeCode

/// Event Marker
EventMarker

} TypeCodeType;

inline std::string ToString(TypeCode typeCode)
Expand Down
8 changes: 4 additions & 4 deletions include/RhythmGameUtilities/File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inline std::vector<uint8_t> ReadBytesFromFile(const char *path)

if (!file.is_open())
{
std::cerr << "Failed to open " << path << "." << std::endl;
std::cerr << "Failed to open " << path << ".\n";
}

auto fileSize = file.tellg();
Expand All @@ -49,13 +49,13 @@ inline std::string ReadStringFromFile(const char *path)

if (!file)
{
std::cerr << "Failed to open " << path << "." << std::endl;
std::cerr << "Failed to open " << path << ".\n";

return "";
}

return std::string((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
return {(std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>()};
}

} // namespace RhythmGameUtilities
18 changes: 8 additions & 10 deletions include/RhythmGameUtilities/Parsers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include <string>
#include <vector>

#include "Enums/Difficulty.h"
#include "Enums/NamedSection.h"
#include "Enums/TypeCode.h"
#include "Enums/TypeCode.hpp"

#include "Structs/Note.h"
#include "Structs/Tempo.h"
#include "Structs/TimeSignature.h"
#include "Structs/Note.hpp"
#include "Structs/Tempo.hpp"
#include "Structs/TimeSignature.hpp"

#include "Common.hpp"

Expand All @@ -32,12 +30,12 @@ typedef struct
int lineCount;
} ChartSectionInternal;

std::regex CHART_SECTION_PATTERN("\\[([a-z]+)\\]\\s*\\{([^\\}]+)\\}",
std::regex CHART_SECTION_PATTERN(R"(\[([a-z]+)\]\s*\{([^\}]+)\})",
std::regex_constants::icase);

std::regex CHART_SECTION_LINE_PATTERN("([^=]+)\\s*=([^\\r\\n]+)");
std::regex CHART_SECTION_LINE_PATTERN(R"(([^=]+)\s*=([^\r\n]+))");

std::regex JSON_VALUE_PATTERN("(\"[^\"]+\"|\\S+)");
std::regex JSON_VALUE_PATTERN(R"(("[^"]+"|\S+))");

inline std::map<std::string,
std::vector<std::pair<std::string, std::vector<std::string>>>>
Expand Down Expand Up @@ -78,7 +76,7 @@ ParseSectionsFromChart(const char *contents)
std::regex_replace(values[k], std::regex("^\"|\"$"), "");
}

items.push_back(std::make_pair(key, values));
items.emplace_back(key, values);
}

sections.insert({parts[1].c_str(), items});
Expand Down
22 changes: 11 additions & 11 deletions include/RhythmGameUtilities/ParsersInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ extern "C"

*outSize = internalSections.size();

auto sections = (ChartSectionInternal *)malloc(
auto *sections = (ChartSectionInternal *)malloc(
internalSections.size() * sizeof(ChartSectionInternal));

int i = 0;

for (auto section = internalSections.begin();
section != internalSections.end(); section++)
for (auto &internalSection : internalSections)
{
auto nameLength = section->first.size() + 1;
auto nameLength = internalSection.first.size() + 1;
sections[i].name = (char *)malloc(nameLength);
strncpy(sections[i].name, section->first.c_str(), nameLength - 1);
strncpy(sections[i].name, internalSection.first.c_str(),
nameLength - 1);
sections[i].name[nameLength - 1] = '\0';

sections[i].lines = (KeyValuePairInternal *)malloc(
section->second.size() * sizeof(KeyValuePairInternal));
internalSection.second.size() * sizeof(KeyValuePairInternal));

sections[i].lineCount = section->second.size();
sections[i].lineCount = internalSection.second.size();

for (auto j = 0; j < section->second.size(); j += 1)
for (auto j = 0; j < internalSection.second.size(); j += 1)
{
auto keyLength = section->second[j].first.size() + 1;
auto keyLength = internalSection.second[j].first.size() + 1;
sections[i].lines[j].key = (char *)malloc(keyLength);
strncpy(sections[i].lines[j].key,
section->second[j].first.c_str(), keyLength - 1);
internalSection.second[j].first.c_str(), keyLength - 1);
sections[i].lines[j].key[keyLength - 1] = '\0';

auto values = section->second[j].second;
auto values = internalSection.second[j].second;

for (auto k = 0; k < values.size(); k += 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RhythmGameUtilities

struct BeatBar
{

int Position;

int BPM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RhythmGameUtilities

struct Note
{

int Position;

int HandPosition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include <string>
#include <vector>

namespace RhythmGameUtilities
{

struct TrackEvent
{

int Position;

std::string TypeCode;
Expand Down
25 changes: 12 additions & 13 deletions include/RhythmGameUtilities/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
#include <optional>
#include <vector>

#include "Structs/BeatBar.h"
#include "Structs/Note.h"
#include "Structs/Tempo.h"
#include "Structs/TimeSignature.h"
#include "Structs/BeatBar.hpp"
#include "Structs/Note.hpp"
#include "Structs/Tempo.hpp"
#include "Structs/TimeSignature.hpp"

#include "Common.hpp"

namespace RhythmGameUtilities
{

const float SECONDS_PER_MINUTE = 60.0f;
const float SECONDS_PER_MINUTE = 60.0F;

/**
* Convert seconds to ticks.
Expand Down Expand Up @@ -95,7 +95,7 @@ ConvertSecondsToTicks(float seconds, int resolution,
*/

inline std::vector<std::tuple<int, int>>
GenerateAdjacentKeyPairs(std::map<int, int> keyValuePairs)
GenerateAdjacentKeyPairs(const std::map<int, int> &keyValuePairs)
{
auto adjacentKeyPairs = std::vector<std::tuple<int, int>>();

Expand All @@ -110,16 +110,15 @@ GenerateAdjacentKeyPairs(std::map<int, int> keyValuePairs)

for (auto i = 0; i < sortedKeys.size() - 1; i += 1)
{
adjacentKeyPairs.push_back(
std::make_tuple(sortedKeys[i], sortedKeys[i + 1]));
adjacentKeyPairs.emplace_back(sortedKeys[i], sortedKeys[i + 1]);
}

return adjacentKeyPairs;
}

inline std::vector<BeatBar> CalculateBeatBars(std::vector<Tempo> tempoChanges,
int resolution, int ts,
bool includeHalfNotes)
inline std::vector<BeatBar>
CalculateBeatBars(const std::vector<Tempo> &tempoChanges, int resolution,
int ts, bool includeHalfNotes)
{
std::vector<BeatBar> beatBars;

Expand All @@ -146,7 +145,7 @@ inline std::vector<BeatBar> CalculateBeatBars(std::vector<Tempo> tempoChanges,

if (includeHalfNotes && tick != endTick)
{
beatBars.push_back({tick + resolution / 2, bpm});
beatBars.push_back({tick + (resolution / 2), bpm});
}
}
}
Expand Down Expand Up @@ -205,7 +204,7 @@ inline float ConvertTickToPosition(int tick, int resolution)
* @public
*/

inline bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05f)
inline bool IsOnTheBeat(int bpm, float currentTime, float delta = 0.05F)
{
auto beatInterval = SECONDS_PER_MINUTE / static_cast<float>(bpm);

Expand Down
4 changes: 2 additions & 2 deletions include/RhythmGameUtilities/UtilitiesInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern "C"

*outSize = internalBeatBars.size();

auto beatBars =
auto *beatBars =
(BeatBar *)malloc(internalBeatBars.size() * sizeof(BeatBar));

for (auto i = 0; i < internalBeatBars.size(); i += 1)
Expand All @@ -72,7 +72,7 @@ extern "C"
}

PACKAGE_API bool IsOnTheBeatInternal(int bpm, float currentTime,
float delta = 0.05f)
float delta = 0.05F)
{
return IsOnTheBeat(bpm, currentTime, delta);
}
Expand Down
1 change: 0 additions & 1 deletion tests/RhythmGameUtilities/Common.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <cassert>
#include <cmath>
#include <iostream>
#include <tuple>

#include "RhythmGameUtilities/Common.hpp"

Expand Down
Loading