Deluge Firmware
1.3.0
Build date: 2026.08.29
Toggle main menu visibility
Loading...
Searching...
No Matches
note_set.h
1
#pragma once
2
3
#include <bit>
4
#include <cstdint>
5
#include <initializer_list>
6
20
class
NoteSet
{
21
public
:
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
106
private
:
107
uint16_t bits;
108
};
109
110
const
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
118
std::ostream& operator<<(std::ostream& output,
const
NoteSet
& set);
119
120
class
TestString {
121
public
:
122
TestString(std::string string_) : string(string_) {}
123
const
char
* asCharString()
const
{
return
string
.c_str(); }
124
125
private
:
126
std::string string;
127
};
128
129
const
TestString StringFrom(
const
NoteSet
&);
130
#endif
NoteSet
Definition
note_set.h:20
NoteSet::addMajorDependentModeNotes
void addMajorDependentModeNotes(uint8_t i, bool preferHigher, const NoteSet notesWithinOctavePresent)
Definition
note_set.cpp:102
NoteSet::scaleSize
int scaleSize() const
Definition
note_set.cpp:202
NoteSet::toImpliedScale
NoteSet toImpliedScale() const
Definition
note_set.cpp:151
NoteSet::isSubsetOf
bool isSubsetOf(NoteSet other) const
Definition
note_set.h:88
NoteSet::count
int count() const
Definition
note_set.h:79
NoteSet::NoteSet
NoteSet()
Definition
note_set.h:23
NoteSet::modulateByOffset
NoteSet modulateByOffset(uint8_t offset)
Definition
note_set.cpp:129
NoteSet::has
bool has(int8_t note) const
Definition
note_set.h:37
NoteSet::operator==
bool operator==(const NoteSet &other) const
Definition
note_set.h:84
NoteSet::toBits
uint16_t toBits() const
Definition
note_set.h:103
NoteSet::clear
void clear()
Definition
note_set.h:66
NoteSet::degreesBelow
int8_t degreesBelow(uint8_t note) const
Definition
note_set.cpp:53
NoteSet::operator|
NoteSet operator|(const NoteSet &other)
Definition
note_set.cpp:70
NoteSet::add
void add(int8_t note)
Definition
note_set.h:31
NoteSet::remove
void remove(int8_t note)
Definition
note_set.h:34
NoteSet::addUntrusted
void addUntrusted(uint8_t note)
Definition
note_set.cpp:10
NoteSet::NoteSet
NoteSet(uint16_t bits_)
Definition
note_set.h:25
NoteSet::operator[]
int8_t operator[](uint8_t index) const
Definition
note_set.cpp:24
NoteSet::highest
uint8_t highest() const
Definition
note_set.h:71
NoteSet::majorness
int8_t majorness() const
Definition
note_set.cpp:76
NoteSet::isEmpty
bool isEmpty() const
Definition
note_set.h:68
NoteSet::degreeOf
int8_t degreeOf(uint8_t note) const
Definition
note_set.cpp:61
NoteSet::fill
void fill()
Definition
note_set.h:63
NoteSet::highestNotIn
int8_t highestNotIn(NoteSet used) const
Definition
note_set.cpp:44