AcidStepSequencer: better note_stack system

pull/7/head
midilab 7 years ago
parent b701e61280
commit 2a11707601
  1. 43
      examples/AcidStepSequencer/AcidStepSequencer.ino

@ -73,13 +73,13 @@ uint16_t _step_length = STEP_MAX_SIZE;
// User Interface data // User Interface data
// 6 buttons to keep last value track // 6 buttons to keep last value track
uint8_t _button_state[6] = {1};
// 4 10k potentiometers to keep lasta value track // 4 10k potentiometers to keep lasta value track
uint8_t _button_state[6] = {1};
uint16_t _pot_state[4] = {0}; uint16_t _pot_state[4] = {0};
uint8_t _last_octave = 3; uint8_t _last_octave = 3;
uint8_t _last_note = 0; uint8_t _last_note = 0;
uint8_t _bpm_blink_timer = 1; uint8_t _bpm_blink_timer = 1;
bool _lock_pots = true; // init locked for octave and note pots bool _lock_pots = true;
void sendMidiMessage(uint8_t command, uint8_t byte1, uint8_t byte2) void sendMidiMessage(uint8_t command, uint8_t byte1, uint8_t byte2)
{ {
@ -94,40 +94,37 @@ void sendMidiMessage(uint8_t command, uint8_t byte1, uint8_t byte2)
// Each call represents exactly one step here. // Each call represents exactly one step here.
void ClockOut16PPQN(uint32_t * tick) void ClockOut16PPQN(uint32_t * tick)
{ {
uint16_t step; uint16_t step, length;
bool glide_ahead;
// get actual step. // get actual step.
_step = *tick % _step_length; _step = *tick % _step_length;
// send note on only if this step are not in rest mode // send note on only if this step are not in rest mode
if ( _sequencer[_step].rest == false ) { if ( _sequencer[_step].rest == false ) {
// send note on
sendMidiMessage(NOTE_ON, _sequencer[_step].note, _sequencer[_step].accent ? ACCENT_VELOCITY : NOTE_VELOCITY); sendMidiMessage(NOTE_ON, _sequencer[_step].note, _sequencer[_step].accent ? ACCENT_VELOCITY : NOTE_VELOCITY);
// do we have a glide ahead us?
// check for glide event ahead of _step
step = _step; step = _step;
for ( uint16_t i = 1; i < _step_length; i++ ) { for ( uint16_t i = 1; i < _step_length; i++ ) {
++step; ++step;
step = step % _step_length; step = step % _step_length;
if ( _sequencer[step].glide == true && _sequencer[step].rest == false ) { if ( _sequencer[step].glide == true && _sequencer[step].rest == false ) {
// find a free note stack. we got 2 for overlap glide notes handle. length = NOTE_LENGTH + (i * 6);
// first position of stack is reserved for common step notes(not glided ahead)
for ( uint8_t j = 1; j < NOTE_STACK_SIZE; j++ ) {
if ( _note_stack[j].length == -1 ) {
_note_stack[j].note = _sequencer[_step].note;
_note_stack[j].length = NOTE_LENGTH + (i * 6);
break;
}
}
glide_ahead = true;
break; break;
} else if ( _sequencer[step].rest == false ) { } else if ( _sequencer[step].rest == false ) {
glide_ahead = false; length = NOTE_LENGTH;
break; break;
} }
} }
if ( glide_ahead == false ) {
_note_stack[0].note = _sequencer[_step].note; // find a free note stack to fit in
_note_stack[0].length = NOTE_LENGTH; for ( uint8_t i = 0; i < NOTE_STACK_SIZE; i++ ) {
if ( _note_stack[i].length == -1 ) {
_note_stack[i].note = _sequencer[_step].note;
_note_stack[i].length = length;
break;
}
} }
} }
} }
@ -375,9 +372,11 @@ void processPots()
if ( _step_edit >= _step_length ) { if ( _step_edit >= _step_length ) {
_step_edit = _step_length-1; _step_edit = _step_length-1;
} }
// send stack note off if ( _step >= _step_length ) {
for ( uint8_t i = 0; i < NOTE_STACK_SIZE; i++ ) { // send stack note off
sendMidiMessage(NOTE_OFF, _note_stack[i].note, 0); for ( uint8_t i = 0; i < NOTE_STACK_SIZE; i++ ) {
sendMidiMessage(NOTE_OFF, _note_stack[i].note, 0);
}
} }
} }

Loading…
Cancel
Save