Deluge Firmware 1.3.0
Build date: 2025.04.16
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;
57 void fill() { bits = 0xfff; }
60 void clear() { bits = 0; }
62 bool isEmpty() const { return bits == 0; }
65 uint8_t highest() const { return 15 - std::countl_zero(bits); }
70 int8_t highestNotIn(NoteSet used) const;
73 int count() const { return std::popcount(bits); }
76 int scaleSize() const;
78 bool operator==(const NoteSet& other) const { return bits == other.bits; }
80 int8_t majorness() const;
82 bool isSubsetOf(NoteSet other) const { return (other.bits & bits) == bits; }
85 NoteSet operator|(const NoteSet& other);
89 void addMajorDependentModeNotes(uint8_t i, bool preferHigher, const NoteSet notesWithinOctavePresent);
92 NoteSet modulateByOffset(uint8_t offset);
95 NoteSet toImpliedScale() const;
97 uint16_t toBits() const { return bits; }
98 static const int8_t size = 12;
99
100private:
101 uint16_t bits;
102};
103
104const uint8_t kMaxScaleSize = NoteSet::size;
105
106#ifdef IN_UNIT_TESTS
107// For CppUTest CHECK_EQUAL() and debugging convenience
108
109#include <iostream>
110#include <string>
111
112std::ostream& operator<<(std::ostream& output, const NoteSet& set);
113
114class TestString {
115public:
116 TestString(std::string string_) : string(string_) {}
117 const char* asCharString() const { return string.c_str(); }
118
119private:
120 std::string string;
121};
122
123const TestString StringFrom(const NoteSet&);
124#endif
Definition note_set.h:20
void addMajorDependentModeNotes(uint8_t i, bool preferHigher, const NoteSet notesWithinOctavePresent)
Definition note_set.cpp:98
int scaleSize() const
Definition note_set.cpp:198
NoteSet toImpliedScale() const
Definition note_set.cpp:147
bool isSubsetOf(NoteSet other) const
Definition note_set.h:82
int count() const
Definition note_set.h:73
NoteSet()
Definition note_set.h:23
NoteSet modulateByOffset(uint8_t offset)
Definition note_set.cpp:125
bool has(int8_t note) const
Definition note_set.h:37
bool operator==(const NoteSet &other) const
Definition note_set.h:78
uint16_t toBits() const
Definition note_set.h:97
void clear()
Definition note_set.h:60
NoteSet operator|(const NoteSet &other)
Definition note_set.cpp:66
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:65
int8_t majorness() const
Definition note_set.cpp:72
bool isEmpty() const
Definition note_set.h:62
int8_t degreeOf(uint8_t note) const
Definition note_set.cpp:53
void fill()
Definition note_set.h:57
int8_t highestNotIn(NoteSet used) const
Definition note_set.cpp:44