-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.h
119 lines (97 loc) · 3.51 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once
#include "../note/note.h"
#include "../octave/octave.h"
#include "../mode/mode.h"
#include "../rhythm/rhythm.h"
namespace midier
{
namespace config
{
struct Packed
{
// we want to be able to represent a configuraion in the minimum
// possible amount of memory, as it is saved for every layer
// therefore, we implement this packed version of it which stores
// its data in a more compact way and not fully spanned and naive
// creation
Packed(); // default configuraion
// argument specification
Packed(Note);
Packed(Note, Accidental);
Packed(Note, Accidental, Octave);
Packed(Note, Accidental, Octave, Mode);
Packed(Note, Accidental, Octave, Mode, Rhythm);
Packed(Note, Accidental, Octave, Mode, Rhythm, unsigned);
Packed(Note, Accidental, Octave, Mode, Rhythm, unsigned, unsigned);
Packed(Note, Accidental, Octave, Mode, Rhythm, unsigned, unsigned, bool);
// getters
Note note() const;
Accidental accidental() const;
Octave octave() const;
Mode mode() const;
Rhythm rhythm() const;
unsigned steps() const;
unsigned perm() const;
bool looped() const;
// in-place setters
Packed & note (Note);
Packed & accidental (Accidental);
Packed & octave (Octave);
Packed & mode (Mode);
Packed & rhythm (Rhythm);
Packed & steps (unsigned);
Packed & perm (unsigned);
Packed & looped (bool);
// copying setters
Packed note (Note) const;
Packed accidental (Accidental) const;
Packed octave (Octave) const;
Packed mode (Mode) const;
Packed rhythm (Rhythm) const;
Packed steps (unsigned) const;
Packed perm (unsigned) const;
Packed looped (bool) const;
// from lsb to msb:
// bits 0:3 - note - [0,11]
// bits 4:5 - accidental - [0,2]
// bits 6:8 - octave - [1,7]
// bits 9:11 - mode - [0,6]
// bits 12:15 - rhythm - [0,10]
// bits 16:18 - steps - [3,6]
// bits 19:28 - permutation - [0,6!=720)
// bit 29 - looped - [0,1]
private: long _data;
};
struct Viewed
{
// every layer may have its own configuraion, but we want to also
// support sharing configuraion among layers.
// therefore, every layer has to have a `Packed` member inside of it,
// so it could hold a specific configuraion if detached from the common one.
// in addition, the layer holds a view to the current configuration,
// which could point to its own configuraion or to a common configuraion
// creation
Viewed(); // by default, statically configured
Viewed(Viewed &&);
Viewed & operator=(Viewed &&);
Viewed(const Viewed &) = delete;
Viewed& operator=(const Viewed &) = delete;
Viewed(Packed *);
// queries
bool inner() const; // is pointing to the inner configuraion
bool outer() const; // is pointing to another configuraion
// getters
const Packed & data();
Packed * view();
// access the viewed configuration
Packed * operator->();
// assign new configuration
void operator=(const Packed & other); // statically - copying `other`
void operator=(Packed * other); // dynamically - pointing to `other`
private:
Packed _data;
Packed * _view;
};
} // config
using Config = config::Packed;
} // midier