Skip to content

Instantly share code, notes, and snippets.

@userx14
Last active November 1, 2025 22:39
Show Gist options
  • Select an option

  • Save userx14/69fef864898b2fb76734eeb22729ce82 to your computer and use it in GitHub Desktop.

Select an option

Save userx14/69fef864898b2fb76734eeb22729ce82 to your computer and use it in GitHub Desktop.
Novation Circuit Tracks chromatic sample playback with MIDI.
#include <MIDI.h>
#define MidiInChannel 3 //default setting of MIDI 1 out channel for circuit tracks
#define MidiDrumChannel 10 //drum 1 channel, other drums on 61,62,63
#define MidiDrumNote 60 //drum 1 channel, other drums on 61,62,63
#define pitchRelativeTo 60 //sample is unpitched for c4 = midi note 60
const float twelfthRootOfTwo = 1.0594631; //frequency ratio between adjacent semitones
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
void callbackNoteOn(byte channel, byte pitch, byte velocity){
if (channel == MidiInChannel){
float desiredFreqMul = pow(twelfthRootOfTwo,((int16_t)pitch - pitchRelativeTo));
Serial.println(desiredFreqMul);
float drumPitch = (4*desiredFreqMul-1)*64/3;
Serial.println(drumPitch);
//clip float
if (drumPitch < 0.0){
drumPitch = 0;
}
if (drumPitch > 127.0){
drumPitch = 127;
}
MIDI.sendControlChange(14, (char)drumPitch, MidiDrumChannel);
MIDI.sendNoteOn(MidiDrumNote, velocity, MidiDrumChannel);
Serial.println("noteon");
}
}
void callbackNoteOff(byte channel, byte pitch, byte velocity){
if (channel == MidiInChannel){
MIDI.sendNoteOff(MidiDrumNote, velocity, MidiDrumChannel);
Serial.println("noteoff");
}
}
void setup() {
Serial.begin(115200);
Serial.println("MIDI GO!");
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.turnThruOff();
MIDI.setHandleNoteOn(callbackNoteOn);
MIDI.setHandleNoteOff(callbackNoteOff);
}
void loop() {
MIDI.read();
}
@userx14
Copy link
Author

userx14 commented Aug 16, 2025

setup

@userx14
Copy link
Author

userx14 commented Aug 17, 2025

Measured pitch shifting, notice the stairstepping artifacts and the limited precision for the lower octave notes:
pitchShiftMeasurement

@userx14
Copy link
Author

userx14 commented Aug 18, 2025

Approximation formula (4*freqMul-1)*64/3 vs measured values. Some of the uneven CC14 values seem to be shifted, maybe because of the way the circuit calculated the shift internally?
formulaVsMeasurement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment