44 template <
unsigned int NUM_PHASES,
unsigned int CONTROL_UPDATE_RATE,
unsigned int LERP_RATE>
49 const unsigned int LERPS_PER_CONTROL;
51 unsigned int update_step_counter;
52 unsigned int num_update_steps;
59 unsigned int update_steps;
64 phase phases[NUM_PHASES];
65 unsigned int current_phase_num;
67 phase * current_phase;
73 unsigned int convertMsecToControlUpdateSteps(
unsigned int msec){
74 return (uint16_t) (((uint32_t)msec*CONTROL_UPDATE_RATE)>>10);
79 void setPhase(phase * next_phase) {
80 update_step_counter = 0;
81 num_update_steps = next_phase->update_steps;
82 transition.set(next_phase->level, next_phase->lerp_steps);
83 current_phase = next_phase;
89 void checkForAndSetNextPhase() {
90 if (++update_step_counter >= num_update_steps){
91 if(current_phase_num < NUM_PHASES) current_phase_num++;
92 setPhase(&(phases[current_phase_num]));
99 void setTime(phase * p,
unsigned int msec)
101 p->update_steps = convertMsecToControlUpdateSteps(msec);
102 p->lerp_steps = (
long) p->update_steps * LERPS_PER_CONTROL;
107 void setUpdateSteps(phase * p,
unsigned int steps)
109 p->update_steps = steps;
110 p->lerp_steps = (
long) steps * LERPS_PER_CONTROL;
119 MultiLine():LERPS_PER_CONTROL(LERP_RATE/CONTROL_UPDATE_RATE)
128 current_phase_num = NUM_PHASES-1;
129 current_phase = &phases[current_phase_num];
138 checkForAndSetNextPhase();
150 return transition.next();
159 current_phase_num = 0;
160 setPhase(&(phases[current_phase_num]));
169 setPhase(&(phases[NUM_PHASES-1]));
181 phases[phase_num].level=value;
194 setTime(&(phases[phase_num]), msec);
204 setUpdateSteps(&(phases[phase_num]), steps);
214 return current_phase_num != NUM_PHASES-1;
void setTargetLevel(uint8_t phase_num, Q15n16 value)
Set the target level of one of the phases.
int32_t Q15n16
signed fractional number using 15 integer bits and 16 fractional bits, represents -32767...
void stop()
Jump to to the final phase in the sequence.
bool playing()
Tells if the MultiLine is currently playing.
void setTargetTime(uint8_t phase_num, unsigned int msec)
Set the time taken to reach the target level of a phase, in milliseconds.
void update()
Updates the internal controls of the MultiLine.
void setTargetUpdateSteps(uint8_t phase_num, unsigned int steps)
Set the target1 time of the MultiLine, expressed as the number of update steps (not MultiLine::next()...
For linear changes with a minimum of calculation at each step.
Q15n16 next()
Advances one step along the MultiLine and returns the level.
void start()
Start the target1 phase of the MultiLine.