1 |
|
|
/** |
2 |
|
|
* @file PlayState.hpp |
3 |
|
|
* @brief Header for blink1_lib::PlayState |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
#pragma once |
7 |
|
|
|
8 |
|
|
#include <cstdint> |
9 |
|
|
#include <ostream> |
10 |
|
|
|
11 |
|
|
namespace blink1_lib { |
12 |
|
|
|
13 |
|
|
/** |
14 |
|
|
* The state of the blink1 devive playing patterns |
15 |
|
|
*/ |
16 |
|
|
struct PlayState { |
17 |
|
|
/** |
18 |
|
|
* Whether a pattern is currently playing |
19 |
|
|
*/ |
20 |
|
|
bool playing{false}; |
21 |
|
|
|
22 |
|
|
/** |
23 |
|
|
* The index in the pattern where the play/loop started |
24 |
|
|
*/ |
25 |
|
|
std::uint8_t playStart{0}; |
26 |
|
|
|
27 |
|
|
/** |
28 |
|
|
* The index in the pattern where the play/loop will end |
29 |
|
|
*/ |
30 |
|
|
std::uint8_t playEnd{0}; |
31 |
|
|
|
32 |
|
|
/** |
33 |
|
|
* Number of repetitions left in a loop |
34 |
|
|
*/ |
35 |
|
|
std::uint8_t playCount{0}; |
36 |
|
|
|
37 |
|
|
/** |
38 |
|
|
* The current index in the pattern |
39 |
|
|
*/ |
40 |
|
|
std::uint8_t playPos{0}; |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* Default constructor |
44 |
|
|
* |
45 |
|
|
* Initializes all values to 0 |
46 |
|
|
*/ |
47 |
|
79 |
PlayState() noexcept = default; |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* @param _playing Whether a pattern is currently playing |
51 |
|
|
* @param _playStart The index in the pattern where the play/loop started |
52 |
|
|
* @param _playEnd The index in the pattern where the play/loop will end |
53 |
|
|
* @param _playCount The number of repetitions left in the loop |
54 |
|
|
* @param _playPos The current index in the pattern |
55 |
|
|
*/ |
56 |
|
|
PlayState(const bool _playing, const std::uint8_t _playStart, const std::uint8_t _playEnd, const std::uint8_t _playCount, const std::uint8_t _playPos) noexcept; |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Equality operator |
60 |
|
|
* |
61 |
|
|
* @param other Object to compare to |
62 |
|
|
* @return true if the objects are equal, false otherwise |
63 |
|
|
*/ |
64 |
|
|
[[nodiscard]] bool operator==(const PlayState& other) const noexcept; |
65 |
|
|
|
66 |
|
|
/** |
67 |
|
|
* Inequality operator |
68 |
|
|
* |
69 |
|
|
* @param other Object to compare to |
70 |
|
|
* @return true if the objects are not equal, false otherwise |
71 |
|
|
*/ |
72 |
|
|
[[nodiscard]] bool operator!=(const PlayState& other) const noexcept; |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* Output operator |
76 |
|
|
* |
77 |
|
|
* @param os Output stream |
78 |
|
|
* @param playState PlayState to output |
79 |
|
|
*/ |
80 |
|
|
friend std::ostream& operator<<(std::ostream& os, const PlayState& playState); |
81 |
|
|
}; |
82 |
|
|
} |