Permalink
Browse files

1.52.B3 : Midi clock sync added to LFO Oscillators

  • Loading branch information...
1 parent a0de806 commit 05f8ec1882fa65a2946b6f6b8d1857fd3270d109 xhosxe committed Feb 5, 2012
Showing with 309 additions and 54 deletions.
  1. +1 −1 Makefile
  2. +15 −0 src/FMDisplay.cpp
  3. +7 −0 src/Lfo.h
  4. +71 −0 src/LfoOsc.cpp
  5. +29 −8 src/LfoOsc.h
  6. +91 −39 src/LfoStepSeq.cpp
  7. +10 −0 src/LfoStepSeq.h
  8. +24 −2 src/MidiDecoder.cpp
  9. +6 −0 src/MidiDecoder.h
  10. +3 −1 src/Synth.cpp
  11. +43 −0 src/Synth.h
  12. +3 −1 src/SynthParamListener.h
  13. +6 −2 src/SynthState.cpp
View
@@ -1,6 +1,6 @@
.DEFAULT_GOAL := r3
-PREENFM_VERSION_NUMBER=1.52.B1
+PREENFM_VERSION_NUMBER=1.52.B3
PREENFM_VERSION=\"$(PREENFM_VERSION_NUMBER)\"
LIB_MAPLE_HOME=/home/xhosxe/libmaple
View
@@ -18,6 +18,9 @@
#include "FMDisplay.h"
+extern const char* lfoSeqMidiClock[];
+extern const char* lfoOscMidiClock[];
+
const char* stepChars = "_123456789ABCDEF";
FMDisplay::FMDisplay() {
@@ -78,6 +81,12 @@ void FMDisplay::updateEncoderValue(int row, int encoder, ParameterDisplay* param
case DISPLAY_TYPE_STRINGS :
lcd->print(param->valueName[newValue]);
break;
+ case DISPLAY_TYPE_LFO_HZ:
+ if (newValue > 246) {
+ lcd->print(lfoOscMidiClock[newValue-247]);
+ break;
+ }
+ // else what follows :
case DISPLAY_TYPE_FLOAT_4_4:
displayFloat44:
lcd->print(newValue>>4);
@@ -140,6 +149,12 @@ void FMDisplay::updateEncoderValue(int row, int encoder, ParameterDisplay* param
lcd->print(' ');
break;
}
+ case DISPLAY_TYPE_STEP_SEQ_BPM:
+ if (newValue > 240) {
+ lcd->print(lfoSeqMidiClock[newValue-241]);
+ break;
+ }
+ goto displaySignedChar;
case DISPLAY_TYPE_UNSIGNED_CHAR_OR_NONE:
if (newValue == 255) {
lcd->print("None");
View
@@ -39,12 +39,19 @@ class Lfo : public SynthStateAware {
virtual void nextValueInMatrix() = 0 ;
virtual void noteOn() = 0;
virtual void noteOff() = 0;
+ virtual void midiClock(int songPosition) {};
+ void midiContinue() {
+ ticks = 0;
+ };
+
protected:
Matrix *matrix;
DestinationEnum destination;
SourceEnum source;
int index;
+ // Midi Clock sync
+ int ticks;
};
#endif /* LFO_H_ */
View
@@ -32,3 +32,74 @@ void LfoOsc::init(int number, Matrix *matrix, SourceEnum source, DestinationEnum
}
+
+void LfoOsc::midiClock(int songPosition) {
+ switch (lfo->freq) {
+ case LFO_MIDICLOCK_MC_DIV_16:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0xfff / ticks;
+ ticks = 0;
+ index = (songPosition & 0x3C) * 0x3ff ;
+ }
+ break;
+ case LFO_MIDICLOCK_MC_DIV_8:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0x1fff / ticks;
+ ticks = 0;
+ index = (songPosition & 0x1C) * 0x7ff ;
+ }
+ break;
+ case LFO_MIDICLOCK_MC_DIV_4:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0x3fff / ticks;
+ ticks = 0;
+ index = (songPosition & 0xC) * 0xfff ;
+ }
+ break;
+ case LFO_MIDICLOCK_MC_DIV_2:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0x7fff / ticks;
+ ticks = 0;
+ index = (songPosition & 0x4) * 0x1fff ;
+ }
+ break;
+ case LFO_MIDICLOCK_MC:
+ // Midi Clock
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0xffff / ticks;
+ ticks = 0;
+ index = 0;
+ }
+ break;
+ case LFO_MIDICLOCK_MC_TIME_2:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0x1ffff / ticks;
+ ticks = 0;
+ index = 0;
+ }
+ break;
+ case LFO_MIDICLOCK_MC_TIME_3:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0xffff / ticks * 3;
+ ticks = 0;
+ index = 0;
+ }
+ break;
+ case LFO_MIDICLOCK_MC_TIME_4:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0x3ffff / ticks;
+ ticks = 0;
+ index = 0;
+ }
+ break;
+ case LFO_MIDICLOCK_MC_TIME_8:
+ if ((songPosition & 0x3)==0) {
+ stepPlusMatrix = 0x7ffff / ticks;
+ ticks = 0;
+ index = 0;
+ }
+ break;
+ }
+}
+
+
View
@@ -21,6 +21,19 @@
#include "Lfo.h"
#include "Osc.h"
+
+enum {
+ LFO_MIDICLOCK_MC_DIV_16 = 247,
+ LFO_MIDICLOCK_MC_DIV_8,
+ LFO_MIDICLOCK_MC_DIV_4,
+ LFO_MIDICLOCK_MC_DIV_2,
+ LFO_MIDICLOCK_MC,
+ LFO_MIDICLOCK_MC_TIME_2,
+ LFO_MIDICLOCK_MC_TIME_3,
+ LFO_MIDICLOCK_MC_TIME_4,
+ LFO_MIDICLOCK_MC_TIME_8
+};
+
class LfoOsc: public Lfo {
public:
@@ -30,31 +43,36 @@ class LfoOsc: public Lfo {
ramp = lfo->keybRamp << 4; // * 16
}
+ void midiClock(int songPosition);
+
void nextValueInMatrix() {
int lfoValue = 0;
+ ticks ++;
// then new value
// index = (index + ((lfo->freq << 16) / LFO_SAMPLE_RATE_x_8 )) & 0xffff;
// int jmp = lfo->freq << 3 ; // << 16 >> 13
- int realfreq = lfo->freq + (this->matrix->getDestination(destination) >> 7);
+ if (lfo->freq <LFO_MIDICLOCK_MC_DIV_16) {
+ stepPlusMatrix = (lfo->freq + (this->matrix->getDestination(destination) >> 7)) << 3;
+ }
switch (lfo->shape) {
- case LFO_RAMP:
- index = (index + (realfreq << 3)) & 0xffff;
- lfoValue = (index>>8)-128;
- break;
case LFO_SAW:
{
- index = (index + (realfreq << 3)) & 0xffff;
+ index = (index + stepPlusMatrix) & 0xffff;
if (index < 32768) {
lfoValue = (index>>7) - 128;
} else {
lfoValue = 383 - (index>>7);
}
break;
}
+ case LFO_RAMP:
+ index = (index + stepPlusMatrix) & 0xffff;
+ lfoValue = (index>>8)-128;
+ break;
case LFO_SQUARE:
- index = (index + (realfreq << 3)) & 0xffff;
+ index = (index + stepPlusMatrix) & 0xffff;
if ((index) < 32768) {
lfoValue = -128;
} else {
@@ -63,7 +81,7 @@ class LfoOsc: public Lfo {
break;
case LFO_RANDOM:
- index = (index + (realfreq << 3));
+ index += stepPlusMatrix;
if (index > 0xffff) {
index &= 0xffff;
currentRandomValue = (RANDOM >> 8);
@@ -96,13 +114,16 @@ class LfoOsc: public Lfo {
}
+
private:
LfoType type;
LfoParams* lfo ;
int index, rampIndex, ramp;
DestinationEnum destination;
int currentRandomValue;
+ int stepPlusMatrix ;
+
};
#endif /* LFOOSC_H_ */
View
@@ -18,69 +18,121 @@
#include "LfoStepSeq.h"
-int expValues[] = { 0,15, 31, 48, 67, 86, 106, 128, 150, 175, 200, 227, 256, 286, 319, 353 };
+int expValues[] = { 0, 15, 31, 48, 67, 86, 106, 128, 150, 175, 200, 227, 256,
+ 286, 319, 353 };
-void LfoStepSeq::init(int number, Matrix *matrix, SourceEnum source, DestinationEnum dest) {
+void LfoStepSeq::init(int number, Matrix *matrix, SourceEnum source,
+ DestinationEnum dest) {
Lfo::init(number, matrix, source, dest);
switch (source) {
case MATRIX_SOURCE_LFO5:
- this->seqParams = (StepSequencerParams *)&this->synthState->params.lfo5;
- this->seqSteps = (StepSequencerSteps*)&this->synthState->params.steps5;
+ this->seqParams =
+ (StepSequencerParams *) &this->synthState->params.lfo5;
+ this->seqSteps = (StepSequencerSteps*) &this->synthState->params.steps5;
this->matrixGateDestination = LFO5_GATE;
break;
case MATRIX_SOURCE_LFO6:
- this->seqParams = (StepSequencerParams *)&this->synthState->params.lfo6;
- this->seqSteps = (StepSequencerSteps*)&this->synthState->params.steps6;
+ this->seqParams =
+ (StepSequencerParams *) &this->synthState->params.lfo6;
+ this->seqSteps = (StepSequencerSteps*) &this->synthState->params.steps6;
this->matrixGateDestination = LFO6_GATE;
break;
}
gated = false;
+ ticks = 0;
+}
+
+void LfoStepSeq::midiClock(int songPosition) {
+ switch (seqParams->bpm) {
+ case LFO_SEQ_MIDICLOCK_DIV_4:
+ // Midi Clock / 4
+ if ((songPosition & 0x3)==0) {
+ step = 0xffff / ticks;
+ ticks = 0;
+ index = ((songPosition >> 2)& 0xf) << 16;
+ }
+ break;
+ case LFO_SEQ_MIDICLOCK_DIV_2:
+ if ((songPosition & 0x3)==0) {
+ step = 0x1ffff / ticks;
+ ticks = 0;
+ index = ((songPosition >> 1) & 0xf) << 16;
+ }
+ break;
+ case LFO_SEQ_MIDICLOCK:
+ if ((songPosition & 0x3)==0) {
+ step = 0x3ffff / ticks;
+ ticks = 0;
+ index = (songPosition& 0xf) << 16;
+ }
+ break;
+ case LFO_SEQ_MIDICLOCK_TIME_2:
+ if ((songPosition & 0x3)==0) {
+ step = 0x7ffff / ticks;
+ ticks = 0;
+ index = ((songPosition * 2) & 0xf) << 16;
+ }
+ break;
+ case LFO_SEQ_MIDICLOCK_TIME_4:
+ if ((songPosition & 0x3)==0) {
+ step = 0xfffff / ticks;
+ ticks = 0;
+ index = ((songPosition * 4) & 0xf) << 16;
+ }
+ break;
+ }
}
+
void LfoStepSeq::valueChanged(int encoder) {
if (encoder < 2) {
- step = (seqParams->bpm << 16) / 15360;
+ if (seqParams->bpm <= 240 ) {
+ // We're called 1024 times per seconds
+ // Each step must last (1024 / 4 * 60/bpm)
+ // = 64*60/bmp = 15360 / bmp
+ // We must going forward bpm / 15360
+ // fix point stepForward = (bpm << 16) / 15360;
+
+ step = (seqParams->bpm << 16) / 15360;
+ }
}
}
void LfoStepSeq::nextValueInMatrix() {
- // We're called 1024 times per seconds
- // Each step must last (1024 / 4 * 60/bpm)
- // = 64*60/bmp = 15360 / bmp
- // We must going forward bpm / 15360
- // fix point stepForward = (bpm << 16) / 15360;
-
- index += step;
- index &= 0xfffff;
-
- // Add gate and matrix value
- int gatePlusMatrix = seqParams->gate + (this->matrix->getDestination(matrixGateDestination) >> 7);
-
- // We'll reach the new value step by step to reduce audio click !
- if (gatePlusMatrix <= 0) {
- target = 0;
- } else if (gatePlusMatrix < 32) {
- // Gated ?
- if (!gated && ((index & 0xffff) >= (gatePlusMatrix<< 11))) {
+
+ ticks++;
+
+ index += step;
+ index &= 0xfffff;
+
+ // Add gate and matrix value
+ int gatePlusMatrix = seqParams->gate + (this->matrix->getDestination(matrixGateDestination) >> 7);
+
+ // We'll reach the new value step by step to reduce audio click !
+ if (gatePlusMatrix <= 0) {
+ target = 0;
+ } else if (gatePlusMatrix < 32) {
+ // Gated ?
+ if (!gated && ((index & 0xffff) >= (gatePlusMatrix << 11))) {
target = 0;
gated = true;
- }
+ }
// End of gate ?
- if (gated && ((index & 0xffff) < (gatePlusMatrix<< 11))) {
- target = seqSteps->steps[index>>16];
+ if (gated && ((index & 0xffff) < (gatePlusMatrix << 11))) {
+ target = seqSteps->steps[index >> 16];
gated = false;
- }
- } else {
- target = seqSteps->steps[index>>16];
- }
-
- if (currentValue < target) {
- currentValue ++;
- }
- if (currentValue > target) {
- currentValue --;
- }
+ }
+ } else {
+ target = seqSteps->steps[index >> 16];
+ }
+
+ if (currentValue < target) {
+ currentValue++;
+ }
+ if (currentValue > target) {
+ currentValue--;
+ }
matrix->setSource(source, expValues[currentValue]);
}
Oops, something went wrong.

0 comments on commit 05f8ec1

Please sign in to comment.