Skip to content

Instantly share code, notes, and snippets.

@kinoshita-lab
Last active September 7, 2016 12:28
Show Gist options
  • Save kinoshita-lab/dc8883e4b62ca3718e5267cef3aa7b31 to your computer and use it in GitHub Desktop.
Save kinoshita-lab/dc8883e4b62ca3718e5267cef3aa7b31 to your computer and use it in GitHub Desktop.
Shiromono-chan a sync utility for trakor and hardware
/*
* shiromono-chan.ino
* Small syncing utility for traktor->hardware
*
* Instructions
* 1. Write this program to Arduino Uno
* 2. Burn "Midi Firmware for Arduino Uno (Moco)" to Arduino Uno's USB chip http://morecatlab.akiba.coocan.jp/lab/index.php/aruino/midi-firmware-for-arduino-uno-moco/?lang=en
* 3. Connect to your Computer
* 4. Start Traktor
* 5. Go to Preferences->"MIDI Clock" and enable clocking
* 6. Go to Preferences->"Controller Manager", confirm output is set to "All Ports" or "MIDI/MOCO.."
* 7. Play your tune on traktor
* 8. Press "> | ||" button on the left top
* 9. Start your hardware sequencer
* 10. Adjust tick head with "Sending Offset" on Preferences->"MIDI Clock"
* 11. Explode your creativity.
*
*/
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// port defs
enum {
BPM_LED = 13,
};
// states
enum State {
Init,
Start,
Working,
};
// constants
enum {
//Tick_Per_Clock = 6, // 16th note tick(Sharin tick)
Tick_Per_Clock = 12, // 8th note tick(for some K*** volca series)
};
State state = Init;
int8_t tickCounter = 0;
bool needTickOut = false;
void initialize()
{
state = Init;
tickCounter = 0;
needTickOut = false;
}
void setup()
{
initialize();
pinMode(BPM_LED, OUTPUT);
MIDI.begin(); // Launch MIDI with default options
MIDI.turnThruOff();
}
void ClockReceived()
{
if (state != Start) {
return;
}
tickCounter++; // assume nearest clock after start is always head of the 16th note
if (tickCounter == Tick_Per_Clock) {
tickCounter = 0;
needTickOut = true;
} else {
needTickOut = false;
}
}
void StartReceived()
{
initialize();
state = Start;
}
void StopReceived()
{
initialize();
}
void Midi()
{
if (!MIDI.read()) {
return;
}
const auto type = MIDI.getType();
switch (type) {
case midi::Clock:
ClockReceived();
break;
case midi::Start:
StartReceived();
break;
case midi::Stop:
StopReceived();
break;
default:
break;
}
}
void loop()
{
Midi();
if (needTickOut) {
digitalWrite(BPM_LED, HIGH);
} else {
digitalWrite(BPM_LED, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment