Skip to content

Commit

Permalink
closes #193 , changed default dac note index from 0 to 12 to allow fo…
Browse files Browse the repository at this point in the history
…r downwards pitch bend
  • Loading branch information
scottc11 committed Dec 5, 2022
1 parent 951a6aa commit 9ed3a1e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
7 changes: 4 additions & 3 deletions Degree/Inc/VoltPerOctave.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace DEGREE {
uint16_t maxPitchBend; // must be a float!
uint16_t minPitchBend = 0; // should always be 0
uint16_t currPitchBend; // the amount of pitch bend to apply to the 1v/o DAC output. Can be positive/negative centered @ 0
bool bendDirection; // pitch bend up = true, down = false

VoltPerOctave(DAC8554 *_dac, DAC8554::Channel _chan, AnalogHandle *_adc)
{
Expand All @@ -50,12 +51,12 @@ namespace DEGREE {
};

void init();
void updateDAC(int index, uint16_t pitchBend, bool direction = false);
void setPitch(int index);
void setPitchBend(uint16_t value, bool direction = false);
void updateDAC();
void resetDAC();
void setPitchBendRange(int value);
int getPitchBendRange();
void setPitchBend(uint16_t value, bool direction = false);
void bend(uint16_t value);
uint16_t calculatePitchBend(uint16_t input, uint16_t min, uint16_t max);
void resetVoltageMap();
void logVoltageMap();
Expand Down
7 changes: 2 additions & 5 deletions Degree/Src/TouchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ void TouchChannel::triggerNote(int degree, int octave, Action action)
setOctaveLed(currOctave, ON, true);
}
}
output.updateDAC(dacIndex, 0);
output.setPitch(dacIndex);
break;
case NOTE_OFF:
setGate(LOW);
Expand All @@ -473,7 +473,7 @@ void TouchChannel::triggerNote(int degree, int octave, Action action)
{
setDegreeLed(degree, ON, true); // new active note HIGH
}
output.updateDAC(dacIndex, 0);
output.setPitch(dacIndex);
break;
case PREV_NOTE:
/* code */
Expand Down Expand Up @@ -1111,9 +1111,6 @@ void TouchChannel::handleSequence(int position)
// Handle Bend Events (only if the bender is currently idle / inactive)
if (sequence.containsBendEvents)
{
// somewhere in here, if bend events exists and ratcheting is enabled, then
// an idle bend value is going to set the gate LOW (each PPQN). What needs to happen,
// is if bend idle && sequence bend is == idle, then don't trigger the gate
if (bender->isIdle())
{
this->handleBend(sequence.getBend(position));
Expand Down
22 changes: 15 additions & 7 deletions Degree/Src/VoltPerOctave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ int VoltPerOctave::getPitchBendRange() {
void VoltPerOctave::setPitchBend(uint16_t value, bool direction)
{
currPitchBend = value;
this->updateDAC(currNoteIndex, currPitchBend, direction);
bendDirection = direction;
this->updateDAC();
}

void VoltPerOctave::setPitch(int index)
{
if (index < DAC_1VO_ARR_SIZE) {
currNoteIndex = index + 12;
this->updateDAC();
}
}

/**
Expand All @@ -47,20 +56,19 @@ uint16_t VoltPerOctave::calculatePitchBend(uint16_t input, uint16_t min, uint16_
* @param index index to be mapped to voltage map. ranging 0..DAC_1VO_ARR_SIZE
* @param pitchBend DAC value corrosponing to the amount of pitch bend to apply to output. positive or negative
*/
void VoltPerOctave::updateDAC(int index, uint16_t pitchBend, bool direction)
void VoltPerOctave::updateDAC()
{
if (index < DAC_1VO_ARR_SIZE)
if (currNoteIndex < DAC_1VO_ARR_SIZE)
{
currNoteIndex = index;
if (!direction)
if (!bendDirection)
{
uint16_t nValue = dacVoltageMap[currNoteIndex] - pitchBend;
uint16_t nValue = dacVoltageMap[currNoteIndex] - currPitchBend;
if (nValue <= dacVoltageMap[currNoteIndex])
{
currOutput = nValue;
}
} else {
uint16_t pValue = dacVoltageMap[currNoteIndex] + pitchBend;
uint16_t pValue = dacVoltageMap[currNoteIndex] + currPitchBend;
if (pValue >= dacVoltageMap[currNoteIndex])
{
currOutput = pValue;
Expand Down

0 comments on commit 9ed3a1e

Please sign in to comment.