Skip to content

Commit

Permalink
Fixing trigger modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Quixotic7 committed Mar 3, 2024
1 parent 16b001f commit d6d25f6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion OMX-27-firmware/OMX-27-firmware.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// OMX-27 MIDI KEYBOARD / SEQUENCER

// v1.13.2
// v1.13.3
// Last update: Feb 2024
//
// Original concept and initial code by Steven Noreyko
Expand Down
6 changes: 4 additions & 2 deletions OMX-27-firmware/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
// #include <cstdarg>

/* * firmware metadata */
// OMX_VERSION = 1.13.2
// OMX_VERSION = 1.13.3
const int MAJOR_VERSION = 1;
const int MINOR_VERSION = 13;
const int POINT_VERSION = 2;
const int POINT_VERSION = 3;

// 1.13.2 - Adds CV Trigger modes for legato and regtrig
// 1.13.3 - Bugfix for CV Trigger modes


const int DEVICE_ID = 2;

Expand Down
60 changes: 46 additions & 14 deletions OMX-27-firmware/src/utils/cvNote_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ uint8_t CVNoteUtil::cv2MidiNote(uint8_t noteNumber)

void CVNoteUtil::cvNoteOn(uint8_t notenum)
{
// Serial.println("cvNoteOn: " + String(notenum));

if (isNoteValid(notenum) == false)
return;

uint8_t cvNoteNum = midi2CVNote(notenum);

// Send the latest pitch
setPitch(cvNoteNum);

bool areNotesHeld = cvNotes_.size() > 0;

if (areNotesHeld)
Expand All @@ -62,6 +67,7 @@ void CVNoteUtil::cvNoteOn(uint8_t notenum)
// if the queue is too large, remove the oldest note at the front
if (cvNotes_.size() >= trackedSize)
{
// Serial.println("removing front, >= trackedSize");
cvNotes_.erase(cvNotes_.begin());
}

Expand All @@ -80,27 +86,47 @@ void CVNoteUtil::cvNoteOn(uint8_t notenum)
break;
case CVTRIGMODE_RETRIG:
{
// if (!pulseGate)
// {
// pulseGate = true;
// setGate(false); // Set gate low for period of time
// turnGateOnTime = sysSettings.timeElasped + 10000;
// }

uint32_t currentTime = micros();

if (areNotesHeld)
{
pulseGate = true;
setGate(false); // Set gate low for period of time
lastNoteOnTime = sysSettings.timeElasped;
if (currentTime > turnGateOnTime)
{
// Serial.println("pulseGate retrig pulse notes held");

pulseGate = true;
setGate(false); // Set gate low for period of time
// turnGateOnTime = sysSettings.timeElasped + 15000;
}
else
{
// Serial.println("retrig notes held");
setGate(true);
}
}
else
{
// Serial.println("retrig pulse no notes held");
// turn gate on with first note
setGate(true);
}
turnGateOnTime = currentTime + 10000;
}
break;
}

setPitch(cvNoteNum);
// Send the latest pitch
}

void CVNoteUtil::cvNoteOff(uint8_t notenum)
{
// Serial.println("cvNoteOff: " + String(notenum));

if (isNoteValid(notenum) == false)
return;

Expand Down Expand Up @@ -132,8 +158,12 @@ void CVNoteUtil::cvNoteOff(uint8_t notenum)

areNotesHeld = cvNotes_.size() > 0;

if(areNotesHeld)
{
setPitch(cvNotes_[cvNotes_.size() - 1].cvNote);
}
// No more held notes, turn gate off
if (areNotesHeld == false)
else
{
pulseGate = false;
setGate(false);
Expand All @@ -143,19 +173,21 @@ void CVNoteUtil::cvNoteOff(uint8_t notenum)
void CVNoteUtil::loopUpdate(unsigned long elapsedTime)
{
// If notes are held and pulseGate is true, turn gate back on after some time
if(cvNotes_.size() > 0 && pulseGate)
if(pulseGate && micros() > turnGateOnTime)
{
if(elapsedTime >= lastNoteOnTime + secs2micros * 0.01f)
{
pulseGate = false;
setGate(true);
}
// Serial.println("pulse gate on loop");
setGate(true);
pulseGate = false;
}
}

void CVNoteUtil::setGate(bool high)
{
digitalWrite(CVGATE_PIN, high ? HIGH : LOW);
// Serial.println("SetGate: " + String(high));

// Serial.println("notes Size: " + String(cvNotes_.size()));

digitalWrite(CVGATE_PIN, high);
}

void CVNoteUtil::setPitch(uint8_t cvNoteNum)
Expand Down
6 changes: 3 additions & 3 deletions OMX-27-firmware/src/utils/cvNote_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class CVNoteUtil
uint8_t cvNote : 6; // 0 - 54, note gets 24 added to it
};

bool pulseGate;
bool pulseGate = false;

unsigned long lastNoteOnTime;
uint32_t turnGateOnTime;

static const uint8_t trackedSize = 16;

std::vector<CVNoteTracker> cvNotes_; // Keeps track of which notes are being played

static bool isNoteValid(uint8_t midiNoteNum);

static void setGate(bool high);
void setGate(bool high);
void setPitch(uint8_t cvNoteNum);

static uint8_t midi2CVNote(uint8_t noteNumber);
Expand Down

0 comments on commit d6d25f6

Please sign in to comment.