Skip to content

Commit

Permalink
#189 sequence octave touch pads (mono only)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottc11 committed Dec 3, 2022
1 parent b44aa3f commit 8147769
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 118 deletions.
21 changes: 13 additions & 8 deletions Degree/Inc/SuperSeq.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define SEQ_EVENT_STATUS_BIT 5
#define SEQ_EVENT_GATE_BIT 4
#define SEQ_EVENT_INDEX_BIT_MASK 0b00001111
#define SEQ_EVENT_OCTAVE_BIT_MASK 0b11000000

#define SEQ_LENGTH_BLOCK_1 (MAX_SEQ_LENGTH / 4) // 1 bar
#define SEQ_LENGTH_BLOCK_2 (MAX_SEQ_LENGTH / 2) // 2 bars
Expand All @@ -18,11 +19,12 @@
typedef struct SequenceNode
{
uint8_t activeDegrees; // byte for holding active/inactive notes for a chord
uint8_t data; // bits 0..3: Degree Index || bit 4: Gate || bit 5: status
uint8_t data; // bits 0..3: Degree Index || bit 4: Gate || bit 5: status || bits 6,7: octave
uint16_t bend; // raw ADC value from pitch bend
bool getStatus() { return bitwise_read_bit(data, SEQ_EVENT_STATUS_BIT); }
uint8_t getDegree() { return data & SEQ_EVENT_INDEX_BIT_MASK; }
bool getGate() { return bitwise_read_bit(data, SEQ_EVENT_GATE_BIT); }
uint8_t getOctave() { return (data & SEQ_EVENT_OCTAVE_BIT_MASK) >> 6; }
} SequenceNode;

class SuperSeq {
Expand Down Expand Up @@ -68,7 +70,7 @@ class SuperSeq {
void copyPaste(int prevPosition, int newPosition);
void cutPaste(int prevPosition, int newPosition);

void createTouchEvent(int position, int degree, bool gate);
void createTouchEvent(int position, uint8_t degree, uint8_t octave, bool gate);
void createBendEvent(int position, uint16_t bend);
void createChordEvent(int position, uint8_t notes);

Expand All @@ -85,13 +87,19 @@ class SuperSeq {
void enableRecording();
void disableRecording();

void enablePlayback();
void disablePlayback();

void enableOverdub();
void disableOverdub();

void quantize();
void setQuantizeAmount(QUANT value);

uint8_t constructEventData(uint8_t degree, bool gate, bool status);
void setEventData(int position, uint8_t degree, bool gate, bool status);
void setEventData(int position, uint8_t degree, uint8_t octave, bool gate, bool status);

uint8_t getEventDegree(int position);
uint8_t getEventOctave(int position);
uint8_t getActiveDegrees(int position);
bool getEventGate(int position);
bool getEventStatus(int position);
Expand All @@ -101,13 +109,10 @@ class SuperSeq {
void setEventStatus(int position, bool status);

uint8_t setIndexBits(uint8_t degree, uint8_t byte);
uint8_t readDegreeBits(uint8_t byte);
uint8_t setGateBits(bool state, uint8_t byte);
uint8_t readGateBits(uint8_t byte);
uint8_t setStatusBits(bool status, uint8_t byte);
uint8_t readStatusBits(uint8_t byte);
uint8_t setOctaveBits(uint8_t octave, uint8_t byte);

void quantizationTest();
void logSequenceToConsole();

private:
Expand Down
1 change: 0 additions & 1 deletion Degree/Inc/TouchChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ namespace DEGREE {
// UI Handler
void updateUI(UIMode mode);

void setOctave(int octave);
void updateOctaveLeds(int octave, bool isPlaybackEvent);

void setLED(int io_pin, LedState state, bool isPlaybackEvent); // if you use a "scene" here, you could remove the boolean
Expand Down
98 changes: 45 additions & 53 deletions Degree/Src/SuperSeq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ void SuperSeq::disableRecording() {
}
}

void SuperSeq::enablePlayback()
{
playbackEnabled = true;
}

void SuperSeq::disablePlayback()
{
playbackEnabled = false;
}

void SuperSeq::enableOverdub()
{
overdub = true;
}

void SuperSeq::disableOverdub()
{
overdub = false;
}

/**
* @brief reset the sequence
*/
Expand Down Expand Up @@ -224,7 +244,7 @@ void SuperSeq::cutPaste(int prevPosition, int newPosition)
/**
* @brief Create new event at position
*/
void SuperSeq::createTouchEvent(int position, int degree, bool gate)
void SuperSeq::createTouchEvent(int position, uint8_t degree, uint8_t octave, bool gate)
{
if (!containsTouchEvents)
containsTouchEvents = true;
Expand All @@ -236,12 +256,12 @@ void SuperSeq::createTouchEvent(int position, int degree, bool gate)
{
// move that events associated gate LOW event one pulse before new events position
// there is a potential bug if by chance the prev position returns an index associated with an active HIGH event
setEventData(this->getPrevPosition(position), events[prevEventPos].getDegree(), false, true);
setEventData(this->getPrevPosition(position), events[prevEventPos].getDegree(), events[prevEventPos].getOctave(), false, true);
}
}

newEventPos = position;
setEventData(newEventPos, degree, gate, true);
setEventData(newEventPos, degree, octave, gate, true);
};

/**
Expand Down Expand Up @@ -371,27 +391,6 @@ void SuperSeq::quantize()
// logger_log("\n");
}

void SuperSeq::quantizationTest()
{
setLength(8); // set sequence length to two steps, ie. 96 * 2 PPQN
setQuantizeAmount(QUANT::EIGTH);

createTouchEvent(370, 7, true);
createTouchEvent(387, 7, false);
createTouchEvent(388, 6, true);
createTouchEvent(389, 6, false);
createTouchEvent(400, 6, false);
createTouchEvent(401, 5, true);
createTouchEvent(413, 4, true);
createTouchEvent(426, 3, true);
createTouchEvent(439, 2, true);
createTouchEvent(451, 2, false);
createTouchEvent(452, 1, true);
createTouchEvent(466, 0, true);

quantize();
}

void SuperSeq::logSequenceToConsole() {
logger_log("\nlengthPPQN: ");
logger_log(lengthPPQN);
Expand All @@ -414,23 +413,14 @@ void SuperSeq::logSequenceToConsole() {
}

/**
* @brief contruct an 8-bit value which holds the degree index, gate state, and status of a sequence event.
* @brief contruct an 8-bit value which holds the degree index, octave, gate state, and status of a sequence event.
*
* @param degree the degree index
* @param degree the degree index (0..7)
* @param octave the octave (0..3)
* @param gate the state of the gate output (high or low)
* @param status the status of the event
* @return uint8_t
*/
uint8_t SuperSeq::constructEventData(uint8_t degree, bool gate, bool status)
{
uint8_t data = 0x00;
data = setIndexBits(degree, data);
data = setGateBits(gate, data);
data = setStatusBits(status, data);
return data;
}

void SuperSeq::setEventData(int position, uint8_t degree, bool gate, bool status)
void SuperSeq::setEventData(int position, uint8_t degree, uint8_t octave, bool gate, bool status)
{
if (gate == LOW) // avoid overwriting any active HIGH event with a active LOW event
{
Expand All @@ -439,12 +429,22 @@ void SuperSeq::setEventData(int position, uint8_t degree, bool gate, bool status
return;
}
}
events[position].data = constructEventData(degree, gate, status);
uint8_t data = 0b00000000;
data = setIndexBits(degree, data);
data = setGateBits(gate, data);
data = setStatusBits(status, data);
data = setOctaveBits(octave, data);
events[position].data = data;
}

uint8_t SuperSeq::getEventDegree(int position)
{
return readDegreeBits(events[position].data);
return events[position].getDegree();
}

uint8_t SuperSeq::getEventOctave(int position)
{
return events[position].getOctave();
}

uint8_t SuperSeq::getActiveDegrees(int position)
Expand All @@ -454,12 +454,12 @@ uint8_t SuperSeq::getActiveDegrees(int position)

bool SuperSeq::getEventGate(int position)
{
return readGateBits(events[position].data);
return events[position].getGate();
}

bool SuperSeq::getEventStatus(int position)
{
return readStatusBits(events[position].data);
return events[position].getStatus();
}

void SuperSeq::setEventStatus(int position, bool status)
Expand All @@ -486,27 +486,19 @@ uint8_t SuperSeq::setIndexBits(uint8_t degree, uint8_t byte)
return byte | degree;
}

uint8_t SuperSeq::readDegreeBits(uint8_t byte)
{
return byte & SEQ_EVENT_INDEX_BIT_MASK;
}

uint8_t SuperSeq::setGateBits(bool state, uint8_t byte)
{
return state ? bitwise_set_bit(byte, SEQ_EVENT_GATE_BIT) : bitwise_clear_bit(byte, SEQ_EVENT_GATE_BIT);
}

uint8_t SuperSeq::readGateBits(uint8_t byte)
{
return bitwise_read_bit(byte, SEQ_EVENT_GATE_BIT);
}

uint8_t SuperSeq::setStatusBits(bool status, uint8_t byte)
{
return status ? bitwise_set_bit(byte, SEQ_EVENT_STATUS_BIT) : bitwise_clear_bit(byte, SEQ_EVENT_STATUS_BIT);
}

uint8_t SuperSeq::readStatusBits(uint8_t byte)
uint8_t SuperSeq::setOctaveBits(uint8_t octave, uint8_t byte)
{
return bitwise_read_bit(byte, SEQ_EVENT_STATUS_BIT);
octave = octave << 6; // shift octave value from bits 0 and 1 to bits 7 and 8
byte = byte & 0b00111111; // clear bits 7 and 8
return byte | octave; // set bits 7 and 8:
}
Loading

0 comments on commit 8147769

Please sign in to comment.