Deluge Firmware 1.3.0
Build date: 2026.08.29
Loading...
Searching...
No Matches
note_set.h
1#pragma once
2
3#include <bit>
4#include <cstdint>
5#include <initializer_list>
6
20class NoteSet {
21public:
23 NoteSet() : bits(0) {}
25 NoteSet(uint16_t bits_) : bits(bits_) {}
28 NoteSet(std::initializer_list<uint8_t> notes);
31 void add(int8_t note) { bits = 0xfff & (bits | (1 << note)); }
34 void remove(int8_t note) { bits = 0xfff & (bits & ~(1 << note)); }
37 bool has(int8_t note) const { return (bits >> note) & 1; }
40 void addUntrusted(uint8_t note);
49 int8_t operator[](uint8_t index) const;
54 int8_t degreeOf(uint8_t note) const;
60 int8_t degreesBelow(uint8_t note) const;
63 void fill() { bits = 0xfff; }
66 void clear() { bits = 0; }
68 bool isEmpty() const { return bits == 0; }
71 uint8_t highest() const { return 15 - std::countl_zero(bits); }
76 int8_t highestNotIn(NoteSet used) const;
79 int count() const { return std::popcount(bits); }
82 int scaleSize() const;
84 bool operator==(const NoteSet& other) const { return bits == other.bits; }
86 int8_t majorness() const;
88 bool isSubsetOf(NoteSet other) const { return (other.bits & bits) == bits; }
91 NoteSet operator|(const NoteSet& other);
95 void addMajorDependentModeNotes(uint8_t i, bool preferHigher, const NoteSet notesWithinOctavePresent);
98 NoteSet modulateByOffset(uint8_t offset);
101 NoteSet toImpliedScale() const;
103 uint16_t toBits() const { return bits; }
104 static const int8_t size = 12;
105
106private:
107 uint16_t bits;
108};
109
110const uint8_t kMaxScaleSize = NoteSet::size;
111
112#ifdef IN_UNIT_TESTS
113// For CppUTest CHECK_EQUAL() and debugging convenience
114
115#include <iostream>
116#include <string>
117
118std::ostream& operator<<(std::ostream& output, const NoteSet& set);
119
120class TestString {
121public:
122 TestString(std::string string_) : string(string_) {}
123 const char* asCharString() const { return string.c_str(); }
124
125private:
126 std::string string;
127};
128
129const TestString StringFrom(const NoteSet&);
130#endif
Definition note_set.h:20
void addMajorDependentModeNotes(uint8_t i, bool preferHigher, const NoteSet notesWithinOctavePresent)
Definition note_set.cpp:102
int scaleSize() const
Definition note_set.cpp:202
NoteSet toImpliedScale() const
Definition note_set.cpp:151
bool isSubsetOf(NoteSet other) const
Definition note_set.h:88
int count() const
Definition note_set.h:79
NoteSet()
Definition note_set.h:23
NoteSet modulateByOffset(uint8_t offset)
Definition note_set.cpp:129
bool has(int8_t note) const
Definition note_set.h:37
bool operator==(const NoteSet &other) const
Definition note_set.h:84
uint16_t toBits() const
Definition note_set.h:103
void clear()
Definition note_set.h:66
int8_t degreesBelow(uint8_t note) const
Definition note_set.cpp:53
NoteSet operator|(const NoteSet &other)
Definition note_set.cpp:70
void add(int8_t note)
Definition note_set.h:31
void remove(int8_t note)
Definition note_set.h:34
void addUntrusted(uint8_t note)
Definition note_set.cpp:10
NoteSet(uint16_t bits_)
Definition note_set.h:25
int8_t operator[](uint8_t index) const
Definition note_set.cpp:24
uint8_t highest() const
Definition note_set.h:71
int8_t majorness() const
Definition note_set.cpp:76
bool isEmpty() const
Definition note_set.h:68
int8_t degreeOf(uint8_t note) const
Definition note_set.cpp:61
void fill()
Definition note_set.h:63
int8_t highestNotIn(NoteSet used) const
Definition note_set.cpp:44