Skip to content

Commit

Permalink
Merge pull request #37 from twistedelectrons/finerTuner
Browse files Browse the repository at this point in the history
Finer tuner
  • Loading branch information
twisted-electrons authored Nov 22, 2023
2 parents ecd25b8 + 4191cea commit 3ec46d4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define MEGAFM_CONSTANTS_H

const byte kVersion0 = 3;
const byte kVersion1 = 4;
const byte kVersion1 = 5;

const byte kDefaultSeq[16] = {0, 0, 0, 0, 12, 12, 12, 12, 0, 0, 12, 0, 0, 12, 12, 0};

Expand Down
6 changes: 5 additions & 1 deletion include/megafm.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ extern bool setupMode;
extern bool fineChanged;

extern byte arpMidiSpeedPending, arpMidiSpeed;
extern byte fine;
extern int fine;
extern byte presetCounts;
extern bool presetTargetMode;
extern byte presetTargetModeChanged;
extern int targetPresetModeTimer;
extern bool targetPresetFlasher;
extern int scrollDelay, scrollCounter;
extern byte noiseTableLength[3];
extern byte finePot;

extern int finerFine; // more precise tuning
extern bool movedFineKnob; // track if we adjusted tune to override glide knob for finer tuning

extern byte mem[3950];

Expand Down
2 changes: 2 additions & 0 deletions src/FM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void updateSSEG(byte op) {
}

void updateFine() {

// scale and offset finer tuning
fineChanged = true;
finey = fine;
finey /= 255;
Expand Down
6 changes: 4 additions & 2 deletions src/MEGAfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ bool secPast = false;
byte lastSentCC[2];
byte lastSentMega[2];
byte lastSentYm[2];

int finerFine; // more precise tuning
bool movedFineKnob; // track if we adjusted tune to override glide knob for finer tuning
byte finePot;
// when true we play chords (captured with rec+voicing)
bool chord;
// 0=chip1 down chip2 up 1=both chips go up and down (mixed)
Expand Down Expand Up @@ -139,7 +141,7 @@ bool arpJustWentOff;
bool setupMode;
bool fineChanged;
byte arpMidiSpeedPending, arpMidiSpeed;
byte fine;
int fine;
byte presetCounts;
bool presetTargetMode;
byte presetTargetModeChanged;
Expand Down
2 changes: 2 additions & 0 deletions src/buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ void buttChanged(Button number, bool value) {
break; // arp mode

case kButtonVoiceMode:
movedFineKnob = false;
justQuitSetup = false;
fineChanged = false;
voiceHeld = true;
Expand Down Expand Up @@ -602,6 +603,7 @@ void buttChanged(Button number, bool value) {
// Released
switch (number) {
case kButtonVoiceMode:
movedFineKnob = false;
voiceHeld = false;
if (recHeld) {
noRecAction = false;
Expand Down
2 changes: 1 addition & 1 deletion src/pitchEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

float innerNoteToFreq(float note) {
note += x12[octOffset];
static float baseFreq = 440.f / 32.f;
static float baseFreq = (440.f / 32.f);
return baseFreq * float(pow(2, ((note - 9) / 12)));
}

Expand Down
35 changes: 23 additions & 12 deletions src/pots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ void movedPot(byte number, byte data, bool isMidi) {
showPickupAnimation = false;
setupCounter = 0; // prevent entering setup
if (voiceHeld) {
fine = data;
movedFineKnob = true;

fine = finePot = data;
updateFine();

if (fine > 127) {
Expand Down Expand Up @@ -643,18 +645,27 @@ void movedPot(byte number, byte data, bool isMidi) {
case 28:
showPickupAnimation = false;
setupCounter = 0; // prevent entering setup
if (voiceHeld) {
glide = data >> 4;
updateGlideIncrements();
fineChanged = true;
ledNumber(data >> 2);

if (voiceHeld && movedFineKnob) {
fine = finePot + map(data, 0, 255, -10, 10);
fine = constrain(fine, 0, 255);
updateFine();

} else {
fmBase[50] = data;
updateFMifNecessary(50);
ledNumber(data >> 2);
if (!isMidi) {
targetPot = 50;
sendCC(number, data >> 1);

if (voiceHeld) {
glide = data >> 4;
updateGlideIncrements();
fineChanged = true;
ledNumber(data >> 2);
} else {
fmBase[50] = data;
updateFMifNecessary(50);
ledNumber(data >> 2);
if (!isMidi) {
targetPot = 50;
sendCC(number, data >> 1);
}
}
}
break; // fat 1-127
Expand Down

0 comments on commit 3ec46d4

Please sign in to comment.