Last active
November 1, 2025 22:39
-
-
Save userx14/69fef864898b2fb76734eeb22729ce82 to your computer and use it in GitHub Desktop.
Novation Circuit Tracks chromatic sample playback with MIDI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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(); | |
| } |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.