Compare commits
No commits in common. 'master' and 'master' have entirely different histories.
@ -1,18 +0,0 @@
|
|||||||
IndentWidth: 4
|
|
||||||
BreakBeforeBraces: Allman
|
|
||||||
AlignAfterOpenBracket: Align
|
|
||||||
AlignArrayOfStructures: Right
|
|
||||||
AllowShortBlocksOnASingleLine: Empty
|
|
||||||
AllowShortFunctionsOnASingleLine: None
|
|
||||||
BraceWrapping:
|
|
||||||
AfterClass: true
|
|
||||||
AfterControlStatement: true
|
|
||||||
AfterEnum: true
|
|
||||||
AfterFunction: true
|
|
||||||
AfterNamespace: true
|
|
||||||
AfterObjCDeclaration: true
|
|
||||||
AfterStruct: true
|
|
||||||
AfterUnion: true
|
|
||||||
BeforeCatch: true
|
|
||||||
BeforeElse: true
|
|
||||||
IndentBraces: true
|
|
@ -1,32 +0,0 @@
|
|||||||
# project-kyoku
|
|
||||||
|
|
||||||
I am just trying to create a rhythm game inspired by project-diva
|
|
||||||
|
|
||||||
### Initial setup
|
|
||||||
|
|
||||||
- Make sure you have a compiler supporting c++17 and cmake
|
|
||||||
- Make sure you have [sfml](https://www.sfml-dev.org/) installed, either static or not, just make sure to edit impl/ CMake file, you'll see it.
|
|
||||||
- Now clone it
|
|
||||||
```
|
|
||||||
git clone https://dev.udongein.xyz/NaiJi/project-kyoku
|
|
||||||
```
|
|
||||||
|
|
||||||
- Go to the project folder
|
|
||||||
```
|
|
||||||
cd project-kyoku/
|
|
||||||
```
|
|
||||||
|
|
||||||
- Now build it!
|
|
||||||
```
|
|
||||||
cmake CMakeLists.txt -B ./build
|
|
||||||
cd ./build
|
|
||||||
make
|
|
||||||
```
|
|
||||||
|
|
||||||
### Conventional commits
|
|
||||||
|
|
||||||
This project follows [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
|
|
||||||
|
|
||||||
`<type>(optional scope): <description>`
|
|
||||||
|
|
||||||
Example: `feat(classic-mode): Implement something great`
|
|
@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"flake-utils": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1659877975,
|
|
||||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"id": "flake-utils",
|
|
||||||
"type": "indirect"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1663491030,
|
|
||||||
"narHash": "sha256-MVsfBhE9US5DvLtBAaTRjwYdv1tLO8xjahM8qLXTgTo=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "767542707d394ff15ac1981e903e005ba69528b5",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"id": "nixpkgs",
|
|
||||||
"type": "indirect"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
description = "Project Kyoku";
|
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }:
|
|
||||||
flake-utils.lib.eachDefaultSystem
|
|
||||||
(system:
|
|
||||||
let
|
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
devShell = import ./shell.nix { inherit pkgs; };
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,52 +1,55 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/gameevent.h"
|
|
||||||
#include "core/time.h"
|
#include "core/time.h"
|
||||||
|
#include "core/gameevent.h"
|
||||||
|
|
||||||
namespace kku
|
namespace kku
|
||||||
{
|
{
|
||||||
|
|
||||||
class Note
|
class Note
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Note(microsec perfect_offset) : _perfect_offset(perfect_offset) {}
|
explicit Note(microsec perfect_offset) :
|
||||||
|
_perfect_offset(perfect_offset) {}
|
||||||
virtual ~Note() = default;
|
virtual ~Note() = default;
|
||||||
|
|
||||||
virtual bool isActive(const microsec &offset) const = 0;
|
virtual bool isActive(const microsec& offset) const = 0;
|
||||||
virtual void update(const microsec &music_offset) = 0;
|
virtual void update(const microsec& music_offset) = 0;
|
||||||
|
|
||||||
virtual void input(kku::GameEvent &&input) = 0;
|
virtual void input(kku::GameEvent&& input) = 0;
|
||||||
|
|
||||||
inline const microsec &getPerfectOffset() const noexcept
|
inline const microsec& getPerfectOffset() const noexcept
|
||||||
{
|
{
|
||||||
return _perfect_offset;
|
return _perfect_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const Note ¬e) const
|
bool operator<(const Note& note) const
|
||||||
{
|
{
|
||||||
return _perfect_offset < note._perfect_offset;
|
return _perfect_offset < note._perfect_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Note ¬e) const
|
bool operator==(const Note& note) const
|
||||||
{
|
{
|
||||||
return _perfect_offset == note._perfect_offset;
|
return _perfect_offset == note._perfect_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>(const Note ¬e) const
|
bool operator>(const Note& note) const
|
||||||
{
|
{
|
||||||
return _perfect_offset > note._perfect_offset;
|
return _perfect_offset > note._perfect_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
microsec _perfect_offset;
|
microsec _perfect_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NotePtrComparator
|
struct NotePtrComparator
|
||||||
{
|
{
|
||||||
bool operator()(const Note *lhs, const Note *rhs) const noexcept
|
bool operator()(const Note* lhs, const Note* rhs) const noexcept
|
||||||
{
|
{
|
||||||
return lhs->getPerfectOffset() < rhs->getPerfectOffset();
|
return lhs->getPerfectOffset() < rhs->getPerfectOffset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace kku
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/point.h"
|
#include "core/area.h"
|
||||||
#include "core/vector.h"
|
|
||||||
|
|
||||||
namespace kku
|
namespace kku
|
||||||
{
|
{
|
||||||
|
|
||||||
class Sprite
|
class Sprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Sprite() = default;
|
virtual ~Sprite() = default;
|
||||||
|
|
||||||
virtual void setPosition(const Point &position) = 0;
|
virtual void setPosition(const Point& position) = 0;
|
||||||
virtual Point getPosition() const = 0;
|
virtual Point getPosition() const = 0;
|
||||||
virtual void move(const kku::Vector2<float> &delta) = 0;
|
virtual void move(const kku::Vector2<float>& delta) = 0;
|
||||||
|
|
||||||
virtual void display() const = 0;
|
virtual void display() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace kku
|
}
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "core/color.h"
|
#include "core/color.h"
|
||||||
#include "core/point.h"
|
#include "core/point.h"
|
||||||
#include "core/vector.h"
|
#include "core/vector.h"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace kku
|
namespace kku
|
||||||
{
|
{
|
||||||
|
|
||||||
class Text
|
class Text
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Text() = default;
|
virtual ~Text() = default;
|
||||||
virtual void setString(const std::string &string) = 0;
|
virtual void setString(const std::string& string) = 0;
|
||||||
virtual void setCharacterSize(std::size_t pixels) = 0;
|
virtual void setCharacterSize(std::size_t pixels) = 0;
|
||||||
virtual void setPosition(const Point &point) = 0;
|
virtual void setPosition(const Point& point) = 0;
|
||||||
virtual void move(const kku::Vector2<float> &delta) = 0;
|
virtual void move(const kku::Vector2<float>& delta) = 0;
|
||||||
virtual void setColor(const Color &color) = 0;
|
virtual void setColor(const Color& color) = 0;
|
||||||
|
|
||||||
virtual void display() = 0;
|
virtual void display() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace kku
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs ? import <nixpkgs> {},
|
|
||||||
unstable ? import <nixos-unstable> {},
|
|
||||||
}:
|
|
||||||
|
|
||||||
with pkgs;
|
|
||||||
mkShell {
|
|
||||||
buildInputs = [ sfml ];
|
|
||||||
nativeBuildInputs = [ ccls cmake ];
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Basic logging class
|
|
||||||
*
|
|
||||||
* Defines helper functions for logging facility. Configured in
|
|
||||||
* Application::init()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Log
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum LogLevel
|
|
||||||
{
|
|
||||||
FATAL,
|
|
||||||
ERROR,
|
|
||||||
WARN,
|
|
||||||
INFO,
|
|
||||||
DEBUG,
|
|
||||||
};
|
|
||||||
|
|
||||||
LogLevel level = WARN; ///< Default logging level
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Prints message to stdout
|
|
||||||
*
|
|
||||||
* TODO: write to configurable stream, be it stdout, stderr or even a file
|
|
||||||
*
|
|
||||||
* @param level the message level
|
|
||||||
* @param fmt the message format
|
|
||||||
* @param ... variable parameters
|
|
||||||
*/
|
|
||||||
void log(LogLevel level, const std::string &fmt, ...);
|
|
||||||
|
|
||||||
private:
|
|
||||||
inline std::string _getLabel(LogLevel level)
|
|
||||||
{
|
|
||||||
switch (level)
|
|
||||||
{
|
|
||||||
case DEBUG:
|
|
||||||
return "DEBUG";
|
|
||||||
case INFO:
|
|
||||||
return "INFO ";
|
|
||||||
case WARN:
|
|
||||||
return "WARN ";
|
|
||||||
case ERROR:
|
|
||||||
return "ERROR";
|
|
||||||
case FATAL:
|
|
||||||
return "FATAL";
|
|
||||||
default:
|
|
||||||
return "UNK ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern Log LOG; /// Global variable :(
|
|
||||||
|
|
||||||
#define INFO(fmt, ...) LOG.log(Log::INFO, fmt, ##__VA_ARGS__)
|
|
||||||
#define WARN(fmt, ...) LOG.log(Log::WARN, fmt, ##__VA_ARGS__)
|
|
||||||
#define ERROR(fmt, ...) LOG.log(Log::ERROR, fmt, ##__VA_ARGS__)
|
|
||||||
#define FATAL(fmt, ...) LOG.log(Log::FATAL, fmt, ##__VA_ARGS__)
|
|
||||||
#define DEBUG(fmt, ...) LOG.log(Log::DEBUG, fmt, ##__VA_ARGS__)
|
|
@ -1,27 +0,0 @@
|
|||||||
#include <cstdarg>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "application/log.h"
|
|
||||||
|
|
||||||
void Log::log(LogLevel level, const std::string &fmt, ...)
|
|
||||||
{
|
|
||||||
if (level > this->level)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
// First va_start: count how many characters are needed for formatting
|
|
||||||
va_start(args, fmt);
|
|
||||||
size_t len = std::vsnprintf(NULL, 0, fmt.c_str(), args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
std::vector<char> buf(len + 1);
|
|
||||||
|
|
||||||
// Second va_start: actually write formatted message to buffer
|
|
||||||
va_start(args, fmt);
|
|
||||||
std::vsnprintf(&buf[0], len + 1, fmt.c_str(), args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
std::cout << this->_getLabel(level) << " " << &buf[0] << std::endl;
|
|
||||||
}
|
|
@ -1,29 +1,29 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
#include <SFML/Graphics/RenderTarget.hpp>
|
||||||
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "core/rectangle.h"
|
#include "core/rectangle.h"
|
||||||
|
|
||||||
class RectangleSFML : public kku::Rectangle
|
class RectangleSFML : public kku::Rectangle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit RectangleSFML(sf::RenderTarget *const render_target);
|
explicit RectangleSFML(sf::RenderTarget * const render_target);
|
||||||
virtual void setRect(const kku::Area<float> &rect) override;
|
virtual void setRect(const kku::Area<float>& rect) override;
|
||||||
virtual kku::Area<float> getRect() const override;
|
virtual kku::Area<float> getRect() const override;
|
||||||
|
|
||||||
virtual void setPosition(const kku::Point &position) override;
|
virtual void setPosition(const kku::Point& position) override;
|
||||||
virtual kku::Point getPosition() const override;
|
virtual kku::Point getPosition() const override;
|
||||||
virtual void move(const kku::Vector2<float> &delta) override;
|
virtual void move(const kku::Vector2<float>& delta) override;
|
||||||
|
|
||||||
virtual void setColor(const kku::Color &color) override;
|
virtual void setColor(const kku::Color& color) override;
|
||||||
virtual kku::Color getColor() const override;
|
virtual kku::Color getColor() const override;
|
||||||
virtual bool contains(const kku::Point &position) const override;
|
virtual bool contains(const kku::Point& position) const override;
|
||||||
|
|
||||||
virtual void display() override;
|
virtual void display() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sf::RenderTarget *const _render_target;
|
sf::RenderTarget * const _render_target;
|
||||||
sf::RectangleShape _rectangle;
|
sf::RectangleShape _rectangle;
|
||||||
};
|
};
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SFML/Graphics/Font.hpp>
|
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
#include <SFML/Graphics/RenderTarget.hpp>
|
||||||
#include <SFML/Graphics/Text.hpp>
|
#include <SFML/Graphics/Text.hpp>
|
||||||
|
#include <SFML/Graphics/Font.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "core/text.h"
|
#include "core/text.h"
|
||||||
|
|
||||||
class TextSFML : public kku::Text
|
class TextSFML : public kku::Text
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TextSFML(sf::RenderTarget *const render_target,
|
explicit TextSFML(sf::RenderTarget * const render_target,
|
||||||
const std::shared_ptr<const sf::Font> &font);
|
const std::shared_ptr<const sf::Font>& font);
|
||||||
|
|
||||||
virtual void setString(const std::string &string) override;
|
virtual void setString(const std::string& string) override;
|
||||||
virtual void setCharacterSize(std::size_t pixels) override;
|
virtual void setCharacterSize(std::size_t pixels) override;
|
||||||
virtual void setPosition(const kku::Point &point) override;
|
virtual void setPosition(const kku::Point& point) override;
|
||||||
virtual void move(const kku::Vector2<float> &delta) override;
|
virtual void move(const kku::Vector2<float>& delta) override;
|
||||||
virtual void setColor(const kku::Color &color) override;
|
virtual void setColor(const kku::Color& color) override;
|
||||||
|
|
||||||
virtual void display() override;
|
virtual void display() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
sf::RenderTarget *const _render_target;
|
sf::RenderTarget * const _render_target;
|
||||||
sf::Text _text;
|
sf::Text _text;
|
||||||
};
|
};
|
||||||
|
@ -1,53 +1,44 @@
|
|||||||
#include "classicmode/classicfactory.h"
|
#include "classicmode/classicfactory.h"
|
||||||
|
|
||||||
#include "graphics/classicgraphicsfactory.h"
|
|
||||||
#include "graphics/classicscenegraphicsmanager.h"
|
#include "graphics/classicscenegraphicsmanager.h"
|
||||||
#include "graphics/classictimelinegraphicsmanager.h"
|
#include "graphics/classictimelinegraphicsmanager.h"
|
||||||
|
#include "graphics/classicgraphicsfactory.h"
|
||||||
|
|
||||||
#include "core/timeline.h"
|
#include "core/timeline.h"
|
||||||
#include "editor/classiceditor.h"
|
|
||||||
#include "editor/editorcontext.h"
|
|
||||||
#include "editor/selectionmanager.h"
|
|
||||||
#include "game/classicgame.h"
|
#include "game/classicgame.h"
|
||||||
#include "game/gamecontext.h"
|
#include "game/gamecontext.h"
|
||||||
#include "game/holdmanager.h"
|
#include "game/holdmanager.h"
|
||||||
|
#include "editor/classiceditor.h"
|
||||||
|
#include "editor/editorcontext.h"
|
||||||
|
#include "editor/selectionmanager.h"
|
||||||
|
|
||||||
std::unique_ptr<kku::Game>
|
|
||||||
classic::getGame(const std::shared_ptr<kku::CoreFactory> &core_factory)
|
std::unique_ptr<kku::Game> classic::getGame(const std::shared_ptr<kku::CoreFactory>& core_factory)
|
||||||
{
|
{
|
||||||
const kku::microsec visibility_offset = 1648648;
|
const kku::microsec visibility_offset = 1648648;
|
||||||
|
|
||||||
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
|
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
|
||||||
const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
|
const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
|
||||||
const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager>(
|
const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset);
|
||||||
timeline, factory, visibility_offset);
|
|
||||||
const auto hold_manager = std::make_shared<HoldManager>();
|
const auto hold_manager = std::make_shared<HoldManager>();
|
||||||
|
|
||||||
const auto context =
|
const auto context = std::make_shared<GameContext>(hold_manager, graphics_manager);
|
||||||
std::make_shared<GameContext>(hold_manager, graphics_manager);
|
|
||||||
|
|
||||||
return std::make_unique<ClassicGame>(timeline, context);
|
return std::make_unique<ClassicGame>(timeline, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<kku::Editor>
|
std::unique_ptr<kku::Editor> classic::getEditor(const std::shared_ptr<kku::CoreFactory>& core_factory)
|
||||||
classic::getEditor(const std::shared_ptr<kku::CoreFactory> &core_factory)
|
|
||||||
{
|
{
|
||||||
const kku::microsec visibility_offset = 1648648;
|
const kku::microsec visibility_offset = 1648648;
|
||||||
|
|
||||||
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
|
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
|
||||||
const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
|
const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
|
||||||
const auto selection_manager =
|
const auto selection_manager = std::make_shared<SelectionManager<ClassicNote>>();
|
||||||
std::make_shared<SelectionManager<ClassicNote>>();
|
|
||||||
std::vector<std::shared_ptr<ClassicGraphicsManager>> graphics_managers;
|
std::vector<std::shared_ptr<ClassicGraphicsManager>> graphics_managers;
|
||||||
graphics_managers.emplace_back(
|
graphics_managers.emplace_back(std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset));
|
||||||
std::make_shared<ClassicSceneGraphicsManager>(timeline, factory,
|
graphics_managers.emplace_back(std::make_shared<ClassicTimelineGraphicsManager>(timeline, factory, visibility_offset * 2));
|
||||||
visibility_offset));
|
|
||||||
graphics_managers.emplace_back(
|
const auto context = std::make_shared<EditorContext>(selection_manager, std::move(graphics_managers));
|
||||||
std::make_shared<ClassicTimelineGraphicsManager>(
|
|
||||||
timeline, factory, visibility_offset * 2));
|
|
||||||
|
|
||||||
const auto context = std::make_shared<EditorContext>(
|
|
||||||
selection_manager, std::move(graphics_managers));
|
|
||||||
|
|
||||||
return std::make_unique<ClassicEditor>(timeline, context);
|
return std::make_unique<ClassicEditor>(timeline, context);
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
#include "tools/beatutils.h"
|
#include "tools/beatutils.h"
|
||||||
#include <iostream>
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
auto beat_utils::calculateBeatRateInfo(
|
auto beat_utils::calculateBeatRateInfo(const std::vector<kku::microsec>& approximate_deltas) -> BeatInfo
|
||||||
const std::vector<kku::microsec> &approximate_deltas) -> BeatInfo
|
|
||||||
{
|
{
|
||||||
if (approximate_deltas.empty())
|
if (approximate_deltas.empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const long double sum = std::accumulate(approximate_deltas.begin(),
|
const long double sum = std::accumulate(approximate_deltas.begin(), approximate_deltas.end(), 0);
|
||||||
approximate_deltas.end(), 0);
|
|
||||||
const long double amount = approximate_deltas.size();
|
const long double amount = approximate_deltas.size();
|
||||||
|
|
||||||
long double average = sum / amount;
|
long double average = sum / amount;
|
||||||
|
|
||||||
const int bpm = static_cast<int>(60000000. / average);
|
const int bpm = static_cast<int>(60000000. / average);
|
||||||
|
|
||||||
return BeatInfo{bpm, static_cast<kku::microsec>(
|
|
||||||
1. / static_cast<long double>(bpm) * 60000000.)};
|
return BeatInfo
|
||||||
|
{
|
||||||
|
bpm,
|
||||||
|
static_cast<kku::microsec>(1. / static_cast<long double>(bpm) * 60000000.)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue