-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathArpeggiator.h
105 lines (81 loc) · 2.3 KB
/
Arpeggiator.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
/*
* Arpeggiator.h
*
* Created on: Apr 11, 2015
* Author: Martin Baar
*/
#ifndef ARPEGGIATOR_H_
#define ARPEGGIATOR_H_
#define ARPEGGIATOR_MAX_VALUES 20
/**
* Class to generate arpeggiato from set of notes
*/
class Arpeggiator {
public:
/** Enumeration of possible arpeggio flows */
enum ArpeggioAlgorithm {UP, DOWN, UP_DOWN, SORTED, RANDOM};
/** Default constructor */
Arpeggiator();
/**
* Method to add note to arpeggiator
* @param note note to add
* @return true if add successfully otherwise false (buffer full or note already there)
*/
bool addNote(unsigned char note);
/**
* Method to remove note from arpeggiator
* @param note note to remove
* @return true if removed successfully otherwise false (note not there)
*/
bool removeNote(unsigned char note);
/**
* To get next note to play
* @param note return argument filled with next note to play if any exists otherwise kept unchanged
* @return true if there is some note to be played as next
*/
bool getNextNote(unsigned char & note);
//Setters
/**
* Sets the algorithm arpeggiator shall use to generate sequence
* @param algorithm algorithm to be used
*/
void setAlgorithm(ArpeggioAlgorithm algorithm);
/**
* Sets arpeggio sequence length (number of last added steps that will be played)
* @param size window size to be set
*/
void setWindowSize(unsigned char size);
//Controllers
/** resets arpeggiator to be played from beginning */
void reset();
/** clears all arpeggiator notes and resets it */
void clear();
private:
ArpeggioAlgorithm algorithm_;
unsigned char windowSize_;
unsigned char notes_[ARPEGGIATOR_MAX_VALUES];
unsigned char sortedNotes_[ARPEGGIATOR_MAX_VALUES];
unsigned char count_;
bool started_;
unsigned char currentIndex_;
bool upDownGoingUp_;
bool removeNoteAfterGettingNext_;
bool findValue(unsigned char value, unsigned char * array, unsigned char & index);
unsigned char getNextIndex();
void fillSorted();
};
inline void Arpeggiator::setAlgorithm(Arpeggiator::ArpeggioAlgorithm algorithm) {
algorithm_ = algorithm;
upDownGoingUp_ = true;
}
inline void Arpeggiator::setWindowSize(unsigned char size) {
windowSize_ = size;
}
inline void Arpeggiator::reset() {
started_ = false;
}
inline void Arpeggiator::clear() {
count_ = 0;
reset();
}
#endif /* ARPEGGIATOR_H_ */