updating README and examples with newer v2.2.1 api

develop
midilab 1 week ago
parent d554229f92
commit 94aa9ef674
  1. 89
      README.md
  2. 26
      examples/AVRUartSlaveMidiClockMonitor/AVRUartSlaveMidiClockMonitor.ino
  3. 40
      examples/AcidStepSequencer/AcidStepSequencer.ino
  4. 26
      examples/ESP32UartMasterMidiClock/ESP32UartMasterMidiClock.ino
  5. 19
      examples/GenericMasterOrExternalSync/GenericMasterOrExternalSync.ino
  6. 38
      examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino
  7. 18
      examples/MidiClock/MidiClock.ino
  8. 16
      examples/RP2040UsbUartMasterClock/RP2040UsbUartMasterClock.ino
  9. 24
      examples/STM32UartMasterMidiClock/STM32UartMasterMidiClock.ino
  10. 18
      examples/TeensyUsbMasterMidiClock/TeensyUsbMasterMidiClock.ino
  11. 20
      examples/TeensyUsbSlaveMidiClock/TeensyUsbSlaveMidiClock.ino
  12. 40
      examples/TeensyUsbSlaveMidiClockMonitor/TeensyUsbSlaveMidiClockMonitor.ino
  13. 22
      examples/XiaoUsbMasterMidiClock/XiaoUsbMasterMidiClock.ino

@ -11,15 +11,23 @@ With uClock, you can create professional-grade sequencers, sync boxes, or genera
## Interface ## Interface
The uClock library API operates through an attached callback function mechanism: The uClock library API operates through an attached callback function mechanism:
1. **setOnOutputPPQN(onPPQNCallback) > onOutputPPQNCallback(uint32_t tick)** Calls are made on each new output pulse based on the selected PPQN resolution (if no PPQN is set, the default is 96 PPQN). 1. **setOnOutputPPQN(onPPQNCallback) > onOutputPPQNCallback(uint32_t tick)** Callback are made on each new output pulse based on the selected PPQN resolution (if no PPQN is set, the default is 96 PPQN).
2. **setOnInputPPQN(onPPQNCallback) > onInputPPQNCallback(uint32_t tick)** Set the expected input PPQN (Pulses Per Quarter Note) resolution for external clock sync. 2. **setOnStep(onStepCallback) > onStepCallback(uint32_t step)** A good way to code an old-style step sequencer based on a 16th-note schema, which is not dependent on PPQN (Pulses Per Quarter Note) output config.
3. **setOnStep(onStepCallback) > onStepCallback(uint32_t step)** A good way to code an old-style step sequencer based on a 16th-note schema, which is not dependent on PPQN (Pulses Per Quarter Note) output config. 3. **setOnSync24(onSync24Callback) > onSync24Callback(uint32_t tick)** A good way to code a clock machine or keep your devices in sync with your system is to use setOnSyncXX(), where XX represents the PPQN (Pulses Per Quarter Note) value you want to use. MIDI specifications typically expect 24 PPQN, but if you're working with other devices that are not MIDI standard, you can choose a different PPQN value. Please refer to the supported PPQNs to select from. You can use one or more setOnSyncXX callbacks for different sync output signatures.
4. **setOnSync24(onSync24Callback) > onSync24Callback(uint32_t tick)** A good way to code a clock machine or keep your devices in sync with your system is to use setOnSyncXX(), where XX represents the PPQN (Pulses Per Quarter Note) value you want to use. MIDI specifications typically expect 24 PPQN, but if you're working with other devices that are not MIDI standard, you can choose a different PPQN value. Please refer to the supported PPQNs to select from. You can use one or more setOnSyncXX callbacks for different sync output signatures. 4. **setOnClockStart(onClockStartCallback) > onClockStartCallback()** On the uClock Start event.
5. **setOnClockStart(onClockStartCallback) > onClockStartCallback()** On the uClock Start event. 5. **setOnClockStop(onClockStopCallback) > onClockStopCallback()** On the uClock Stop event.
6. **setOnClockStop(onClockStopCallback) > onClockStopCallback()** On the uClock Stop event.
### Clock input/output resolutions ### Clock input/output resolutions
You can setup multiple clock resolutions for clock generation and clock sync signals.
#### Set internal output clock and external input clock resolution
1. **void setOutputPPQN(PPQNResolution resolution);** sets the main clock output(independent from clock input).
2. **void setInputPPQN(PPQNResolution resolution);** sets the expected external clock resolution for input(independent from clock output).
#### PPQNResolution Avaliable Resolutions
1. **PPQN_1** 1 Pulses Per Quarter Note (only input) 1. **PPQN_1** 1 Pulses Per Quarter Note (only input)
2. **PPQN_2** 2 Pulses Per Quarter Note (only input) 2. **PPQN_2** 2 Pulses Per Quarter Note (only input)
3. **PPQN_4** 4 Pulses Per Quarter Note 3. **PPQN_4** 4 Pulses Per Quarter Note
@ -82,7 +90,7 @@ You will find more complete examples on examples/ folder:
bool _external_sync_on = false; bool _external_sync_on = false;
// the main uClock PPQN resolution ticking // the main uClock PPQN resolution ticking
void onPPQNCallback(uint32_t tick) { void onOutputPPQNCallback(uint32_t tick) {
// tick your sequencers or tickable devices... // tick your sequencers or tickable devices...
} }
@ -90,11 +98,31 @@ void onStepCallback(uint32_t step) {
// triger step data for sequencer device... // triger step data for sequencer device...
} }
// The callback function called by uClock each Pulse of 1PPQN clock resolution.
void onSync1Callback(uint32_t tick) {
// send sync signal to...
}
// The callback function called by uClock each Pulse of 2PPQN clock resolution.
void onSync2Callback(uint32_t tick) {
// send sync signal to...
}
// The callback function called by uClock each Pulse of 4PPQN clock resolution.
void onSync4Callback(uint32_t tick) {
// send sync signal to...
}
// The callback function called by uClock each Pulse of 24PPQN clock resolution. // The callback function called by uClock each Pulse of 24PPQN clock resolution.
void onSync24Callback(uint32_t tick) { void onSync24Callback(uint32_t tick) {
// send sync signal to... // send sync signal to...
} }
// The callback function called by uClock each Pulse of 48PPQN clock resolution.
void onSync48Callback(uint32_t tick) {
// send sync signal to...
}
// The callback function called when clock starts by using uClock.start() method. // The callback function called when clock starts by using uClock.start() method.
void onClockStartCallback() { void onClockStartCallback() {
// send start signal to... // send start signal to...
@ -106,28 +134,41 @@ void onClockStopCallback() {
} }
void setup() { void setup() {
// setup clock library
// inits the clock library // avaliable output resolutions
uClock.init(); // [ uClock.PPQN_4, uClock.PPQN_8, uClock.PPQN_12, uClock.PPQN_24, uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
// avaliable resolutions
// [ uClock.PPQN_24, uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
// not mandatory to call, the default is 96PPQN if not set // not mandatory to call, the default is 96PPQN if not set
uClock.setPPQN(uClock.PPQN_96); uClock.setOutputPPQN(uClock.PPQN_96);
// you need to use at least one! // you need to use at least one!
uClock.setOnOutputPPQN(onPPQNCallback); uClock.setOnOutputPPQN(onOutputPPQNCallback);
uClock.setOnStep(onStepCallback); uClock.setOnStep(onStepCallback);
// multi sync output signatures avaliable
// normaly used by eurorack modular modules
uClock.setOnSync1(onSync1Callback);
uClock.setOnSync2(onSync2Callback);
uClock.setOnSync4(onSync4Callback);
// midi sync standard
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// some korg machines do 48ppqn
uClock.setOnSync48(onSync48Callback);
uClock.setOnClockStart(onClockStartCallback); uClock.setOnClockStart(onClockStartCallback);
uClock.setOnClockStop(onClockStopCallback); uClock.setOnClockStop(onClockStopCallback);
// set external sync mode? // set external sync mode?
if (_external_sync_on) { if (_external_sync_on) {
uClock.setMode(uClock.EXTERNAL_CLOCK); uClock.setClockMode(uClock.EXTERNAL_CLOCK);
// what is the clock of incomming signal to sync with?
// not mandatory to call, the default is 24PPQN if not set
// avaliable input resolutions - should be always InputPPQN <= OutputPPQN
// [ uClock.PPQN_1, uClock.PPQN_2, uClock.PPQN_4, uClock.PPQN_8, uClock.PPQN_12, uClock.PPQN_24, uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
uClock.setInputPPQN(uClock.PPQN_24);
} }
// inits the clock library
uClock.init();
// starts clock // starts clock
uClock.start(); uClock.start();
} }
@ -184,8 +225,6 @@ void setup() {
// Initialize serial communication at 31250 bits per second, the default MIDI serial speed communication: // Initialize serial communication at 31250 bits per second, the default MIDI serial speed communication:
Serial.begin(31250); Serial.begin(31250);
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message based on 24PPQN // Set the callback function for the clock output to send MIDI Sync message based on 24PPQN
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
@ -194,6 +233,9 @@ void setup() {
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
// Inits the clock
uClock.init();
// Starts the clock, tick-tac-tick-tac... // Starts the clock, tick-tac-tick-tac...
uClock.start(); uClock.start();
@ -227,8 +269,6 @@ void onClockStop() {
} }
void setup() { void setup() {
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. based on 24PPQN // Set the callback function for the clock output to send MIDI Sync message. based on 24PPQN
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
@ -236,6 +276,9 @@ void setup() {
uClock.setOnClockStopOutput(onClockStop); uClock.setOnClockStopOutput(onClockStop);
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
// Inits the clock
uClock.init();
// Starts the clock, tick-tac-tick-tac... // Starts the clock, tick-tac-tick-tac...
uClock.start(); uClock.start();
} }
@ -395,9 +438,6 @@ void setup()
// the default MIDI serial speed communication at 31250 bits per second // the default MIDI serial speed communication at 31250 bits per second
Serial.begin(31250); Serial.begin(31250);
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnOutputPPQN(onPPQNCallback); uClock.setOnOutputPPQN(onPPQNCallback);
@ -428,6 +468,9 @@ void setup()
// pins, buttons, leds and pots config // pins, buttons, leds and pots config
//configureYourUserInterface(); //configureYourUserInterface();
// Inits the clock
uClock.init();
// start sequencer // start sequencer
uClock.start(); uClock.start();
} }

@ -1,10 +1,10 @@
/* Uart MIDI Sync Slave Box Monitor /* Uart MIDI Sync Slave Box Monitor
* *
* This example demonstrates how to create a * This example demonstrates how to create a
* MIDI slave clock box with * MIDI slave clock box with
* monitor support using oled display * monitor support using oled display
* *
* MIDI in must be provided via an opto-isolator to pin RX/D0 * MIDI in must be provided via an opto-isolator to pin RX/D0
* Tested on an Arduino Uno. * Tested on an Arduino Uno.
* *
* You need the following libraries to make it work * You need the following libraries to make it work
@ -103,20 +103,28 @@ void setup() {
//u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); //u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE);
u8x8 = new U8X8_SSD1306_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); u8x8 = new U8X8_SSD1306_128X64_NONAME_HW_I2C(U8X8_PIN_NONE);
u8x8->begin(); u8x8->begin();
u8x8->setFont(u8x8_font_pressstart2p_r); u8x8->setFont(u8x8_font_pressstart2p_r);
u8x8->clear(); u8x8->clear();
u8x8->setFlipMode(true); u8x8->setFlipMode(true);
u8x8->drawUTF8(0, 0, "uClock"); u8x8->drawUTF8(0, 0, "uClock");
// //
// uClock Setup // uClock Setup
// //
uClock.init();
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// For MIDI Sync Start and Stop // For MIDI Sync Start and Stop
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
uClock.setMode(uClock.EXTERNAL_CLOCK); uClock.setClockMode(uClock.EXTERNAL_CLOCK);
// for smooth slave tempo calculate display you should raise the
// buffer_size of ext_interval_buffer in between 64 to 128. 254 max size.
// note: this doesn't impact on sync time, only display time getTempo()
// if you dont want to use it, it is default set it to 1 for memory save
uClock.setExtIntervalBuffer(128);
// inits uClock
uClock.init();
//uClock.setTempo(136.5); //uClock.setTempo(136.5);
//uClock.start(); //uClock.start();
} }
@ -124,7 +132,7 @@ void setup() {
void loop() { void loop() {
while(MIDI.read()) {} while(MIDI.read()) {}
// DO NOT ADD MORE PROCESS HERE AT THE COST OF LOSING CLOCK SYNC // DO NOT ADD MORE PROCESS HERE AT THE COST OF LOSING CLOCK SYNC
// Since arduino make use of Serial RX interruption we need to // Since arduino make use of Serial RX interruption we need to
// read Serial as fast as we can on the loop // read Serial as fast as we can on the loop
if (bpm != uClock.getTempo()) { if (bpm != uClock.getTempo()) {
bpm = uClock.getTempo(); bpm = uClock.getTempo();

@ -54,7 +54,7 @@ bool _playing = false;
uint16_t _step = 0; uint16_t _step = 0;
void sendMidiMessage(uint8_t command, uint8_t byte1, uint8_t byte2) void sendMidiMessage(uint8_t command, uint8_t byte1, uint8_t byte2)
{ {
// send midi message // send midi message
command = command | (uint8_t)MIDI_CHANNEL; command = command | (uint8_t)MIDI_CHANNEL;
Serial.write(command); Serial.write(command);
@ -63,14 +63,14 @@ void sendMidiMessage(uint8_t command, uint8_t byte1, uint8_t byte2)
} }
// Each call represents exactly one step. // Each call represents exactly one step.
void onStepCallback(uint32_t tick) void onStepCallback(uint32_t tick)
{ {
uint16_t step; uint16_t step;
uint16_t length = NOTE_LENGTH; uint16_t length = NOTE_LENGTH;
// get actual step. // get actual step.
_step = tick % _step_length; _step = tick % _step_length;
// send note on only if this step are not in rest mode // send note on only if this step are not in rest mode
if ( _sequencer[_step].rest == false ) { if ( _sequencer[_step].rest == false ) {
@ -93,15 +93,15 @@ void onStepCallback(uint32_t tick)
_note_stack[i].note = _sequencer[_step].note; _note_stack[i].note = _sequencer[_step].note;
_note_stack[i].length = length; _note_stack[i].length = length;
// send note on // send note on
sendMidiMessage(NOTE_ON, _sequencer[_step].note, _sequencer[_step].accent ? ACCENT_VELOCITY : NOTE_VELOCITY); sendMidiMessage(NOTE_ON, _sequencer[_step].note, _sequencer[_step].accent ? ACCENT_VELOCITY : NOTE_VELOCITY);
return; return;
} }
} }
} }
} }
// The callback function wich will be called by uClock each Pulse of 96PPQN clock resolution. // The callback function wich will be called by uClock each Pulse of 96PPQN clock resolution.
void onOutputPPQNCallback(uint32_t tick) void onOutputPPQNCallback(uint32_t tick)
{ {
// handle note on stack // handle note on stack
for ( uint8_t i = 0; i < NOTE_STACK_SIZE; i++ ) { for ( uint8_t i = 0; i < NOTE_STACK_SIZE; i++ ) {
@ -111,7 +111,7 @@ void onOutputPPQNCallback(uint32_t tick)
sendMidiMessage(NOTE_OFF, _note_stack[i].note, 0); sendMidiMessage(NOTE_OFF, _note_stack[i].note, 0);
_note_stack[i].length = -1; _note_stack[i].length = -1;
} }
} }
} }
// user feedback about sequence time events // user feedback about sequence time events
@ -124,14 +124,14 @@ void onSync24Callback(uint32_t tick) {
} }
// The callback function wich will be called when clock starts by using Clock.start() method. // The callback function wich will be called when clock starts by using Clock.start() method.
void onClockStart() void onClockStart()
{ {
Serial.write(MIDI_START); Serial.write(MIDI_START);
_playing = true; _playing = true;
} }
// The callback function wich will be called when clock stops by using Clock.stop() method. // The callback function wich will be called when clock stops by using Clock.stop() method.
void onClockStop() void onClockStop()
{ {
Serial.write(MIDI_STOP); Serial.write(MIDI_STOP);
// send all note off on sequencer stop // send all note off on sequencer stop
@ -142,21 +142,18 @@ void onClockStop()
_playing = false; _playing = false;
} }
void setup() void setup()
{ {
// Initialize serial communication // Initialize serial communication
#ifdef MIDI_MODE #ifdef MIDI_MODE
// the default MIDI serial speed communication at 31250 bits per second // the default MIDI serial speed communication at 31250 bits per second
Serial.begin(31250); Serial.begin(31250);
#endif #endif
#ifdef SERIAL_MODE #ifdef SERIAL_MODE
// for usage with a PC with a serial to MIDI bridge // for usage with a PC with a serial to MIDI bridge
Serial.begin(115200); Serial.begin(115200);
#endif #endif
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnOutputPPQN(onOutputPPQNCallback); uClock.setOnOutputPPQN(onOutputPPQNCallback);
@ -164,12 +161,15 @@ void setup()
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for the step sequencer on 16ppqn // Set the callback function for the step sequencer on 16ppqn
uClock.setOnStep(onStepCallback); uClock.setOnStep(onStepCallback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// Inits the clock
uClock.init();
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
@ -192,7 +192,7 @@ void setup()
} }
// User interaction goes here // User interaction goes here
void loop() void loop()
{ {
processInterface(); processInterface();
} }

@ -1,12 +1,12 @@
/* Uart MIDI Sync Box /* Uart MIDI Sync Box
* *
* This example demonstrates how to change the Uart MIDI * This example demonstrates how to change the Uart MIDI
* device name on ESP32 family. * device name on ESP32 family.
* *
* This example code is in the public domain. * This example code is in the public domain.
* *
* ... * ...
* *
*/ */
#include <uClock.h> #include <uClock.h>
@ -54,15 +54,17 @@ void setup() {
// A led to count bpms // A led to count bpms
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
// Setup our clock system // Setup our clock system
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// Inits the clock
uClock.init();
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
// Starts the clock, tick-tac-tick-tac... // Starts the clock, tick-tac-tick-tac...
@ -71,5 +73,5 @@ void setup() {
// Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment... // Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment...
void loop() { void loop() {
} }

@ -48,12 +48,9 @@ void onClockStopCallback() {
} }
void setup() { void setup() {
// setup clock library
// inits the clock library // avaliable output resolutions
uClock.init(); // [ uClock.PPQN_4, uClock.PPQN_8, uClock.PPQN_12, uClock.PPQN_24, uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
// avaliable output PPQN resolutions for this example
// [ uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
// not mandatory to call, the default is 96PPQN if not set // not mandatory to call, the default is 96PPQN if not set
uClock.setOutputPPQN(uClock.PPQN_96); uClock.setOutputPPQN(uClock.PPQN_96);
@ -76,8 +73,16 @@ void setup() {
// set external sync mode? // set external sync mode?
if (_external_sync_on) { if (_external_sync_on) {
uClock.setClockMode(uClock.EXTERNAL_CLOCK); uClock.setClockMode(uClock.EXTERNAL_CLOCK);
// what is the clock of incomming signal to sync with?
// not mandatory to call, the default is 24PPQN if not set
// avaliable input resolutions - should be always InputPPQN <= OutputPPQN
// [ uClock.PPQN_1, uClock.PPQN_2, uClock.PPQN_4, uClock.PPQN_8, uClock.PPQN_12, uClock.PPQN_24, uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
uClock.setInputPPQN(uClock.PPQN_24);
} }
// inits the clock library
uClock.init();
// starts clock // starts clock
uClock.start(); uClock.start();
} }
@ -92,4 +97,4 @@ void loop() {
uClock.clockMe(); uClock.clockMe();
} }
} }
} }

@ -1,9 +1,9 @@
/* USB MIDI Sync Slave Box Monitor /* USB MIDI Sync Slave Box Monitor
* *
* This example demonstrates how to create a * This example demonstrates how to create a
* MIDI hid compilant slave clock box with * MIDI hid compilant slave clock box with
* monitor support using oled displays * monitor support using oled displays
* *
* You need the following libraries to make it work * You need the following libraries to make it work
* - Midi Library * - Midi Library
* - USB-MIDI and MIDIUSB * - USB-MIDI and MIDIUSB
@ -94,20 +94,28 @@ void setup() {
//u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); //u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE);
u8x8 = new U8X8_SSD1306_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); u8x8 = new U8X8_SSD1306_128X64_NONAME_HW_I2C(U8X8_PIN_NONE);
u8x8->begin(); u8x8->begin();
u8x8->setFont(u8x8_font_pressstart2p_r); u8x8->setFont(u8x8_font_pressstart2p_r);
u8x8->clear(); u8x8->clear();
u8x8->setFlipMode(true); u8x8->setFlipMode(true);
u8x8->drawUTF8(0, 0, "uClock"); u8x8->drawUTF8(0, 0, "uClock");
// //
// uClock Setup // uClock Setup
// //
uClock.init();
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// For MIDI Sync Start and Stop // For MIDI Sync Start and Stop
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
uClock.setMode(uClock.EXTERNAL_CLOCK); uClock.setClockMode(uClock.EXTERNAL_CLOCK);
// for smooth slave tempo calculate display you should raise the
// buffer_size of ext_interval_buffer in between 64 to 128. 254 max size.
// note: this doesn't impact on sync time, only display time getTempo()
// if you dont want to use it, it is default set it to 1 for memory save
uClock.setExtIntervalBuffer(128);
// init uClock
uClock.init();
//uClock.setTempo(136.5); //uClock.setTempo(136.5);
//uClock.start(); //uClock.start();
} }
@ -115,7 +123,7 @@ void setup() {
void loop() { void loop() {
while(MIDI.read()) {} while(MIDI.read()) {}
// DO NOT ADD MORE PROCESS HERE AT THE COST OF LOSING CLOCK SYNC // DO NOT ADD MORE PROCESS HERE AT THE COST OF LOSING CLOCK SYNC
// Since arduino make use of Serial RX interruption we need to // Since arduino make use of Serial RX interruption we need to
// read Serial as fast as we can on the loop // read Serial as fast as we can on the loop
if (bpm != uClock.getTempo()) { if (bpm != uClock.getTempo()) {
bpm = uClock.getTempo(); bpm = uClock.getTempo();
@ -127,20 +135,20 @@ void loop() {
u8x8->drawUTF8(8+4, 7, " "); u8x8->drawUTF8(8+4, 7, " ");
} }
} }
if (clock_state != uClock.state) { if (clock_state != uClock.state) {
clock_state = uClock.state; clock_state = uClock.state;
if (clock_state >= 1) { if (clock_state >= 1) {
u8x8->drawUTF8(0, 7, "Playing"); u8x8->drawUTF8(0, 7, "Playing");
} else { } else {
u8x8->drawUTF8(0, 7, "Stopped"); u8x8->drawUTF8(0, 7, "Stopped");
} }
} }
if (clock_mode != uClock.getMode()) { if (clock_mode != uClock.getMode()) {
clock_mode = uClock.getMode(); clock_mode = uClock.getMode();
if (clock_mode == uClock.EXTERNAL_CLOCK) { if (clock_mode == uClock.EXTERNAL_CLOCK) {
u8x8->drawUTF8(10, 0, "Slave "); u8x8->drawUTF8(10, 0, "Slave ");
} else { } else {
u8x8->drawUTF8(10, 0, "Master"); u8x8->drawUTF8(10, 0, "Master");
} }
} }
} }

@ -7,37 +7,39 @@
#define MIDI_STOP 0xFC #define MIDI_STOP 0xFC
// The callback function wich will be called by Clock each Pulse of 24PPQN clock resolution. // The callback function wich will be called by Clock each Pulse of 24PPQN clock resolution.
void onSync24Callback(uint32_t tick) void onSync24Callback(uint32_t tick)
{ {
// Send MIDI_CLOCK to external gears // Send MIDI_CLOCK to external gears
Serial.write(MIDI_CLOCK); Serial.write(MIDI_CLOCK);
} }
// The callback function wich will be called when clock starts by using Clock.start() method. // The callback function wich will be called when clock starts by using Clock.start() method.
void onClockStart() void onClockStart()
{ {
Serial.write(MIDI_START); Serial.write(MIDI_START);
} }
// The callback function wich will be called when clock stops by using Clock.stop() method. // The callback function wich will be called when clock stops by using Clock.stop() method.
void onClockStop() void onClockStop()
{ {
Serial.write(MIDI_STOP); Serial.write(MIDI_STOP);
} }
void setup() void setup()
{ {
// Initialize serial communication at 31250 bits per second, the default MIDI serial speed communication: // Initialize serial communication at 31250 bits per second, the default MIDI serial speed communication:
Serial.begin(31250); Serial.begin(31250);
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// Inits the clock
uClock.init();
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
@ -47,7 +49,7 @@ void setup()
} }
// Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment... // Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment...
void loop() void loop()
{ {
} }

@ -1,8 +1,8 @@
/* /*
* USB/Uart MIDI Sync Box * USB/Uart MIDI Sync Box
* *
* This example code is in the public domain. * This example code is in the public domain.
* *
*/ */
#include <Adafruit_TinyUSB.h> #include <Adafruit_TinyUSB.h>
@ -68,13 +68,15 @@ void setup() {
initBlinkLed(); initBlinkLed();
// Setup our clock system // Setup our clock system
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// Inits the clock
uClock.init();
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
// Starts the clock, tick-tac-tick-tac.. // Starts the clock, tick-tac-tick-tac..

@ -1,13 +1,13 @@
/* Uart MIDI out /* Uart MIDI out
* *
* This example demonstrates how to send MIDI data via Uart * This example demonstrates how to send MIDI data via Uart
* interface on STM32 family. * interface on STM32 family.
* *
* This example code is in the public domain. * This example code is in the public domain.
* *
* Requires STM32Duino board manager to be installed. * Requires STM32Duino board manager to be installed.
* *
* Define HardwareSerial using any available UART/USART. * Define HardwareSerial using any available UART/USART.
* Nucleo boards have UART/USART pins that are used by the ST-LINK interface (unless using solder bridging). * Nucleo boards have UART/USART pins that are used by the ST-LINK interface (unless using solder bridging).
* *
* Tested on Nucleo-F401RE and Nucleo-F072RB (PA9=D8 PA10=D2 on the Arduino pins) * Tested on Nucleo-F401RE and Nucleo-F072RB (PA9=D8 PA10=D2 on the Arduino pins)
@ -62,15 +62,17 @@ void setup() {
// An led to display BPM // An led to display BPM
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
// Setup our clock system // Setup our clock system
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// Inits the clock
uClock.init();
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(120); uClock.setTempo(120);
// Starts the clock, tick-tac-tick-tac... // Starts the clock, tick-tac-tick-tac...
@ -79,5 +81,5 @@ void setup() {
// Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment... // Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment...
void loop() { void loop() {
} }

@ -1,6 +1,6 @@
/* USB MIDI Sync Box /* USB MIDI Sync Box
* *
* This example demonstrates how to change the USB MIDI * This example demonstrates how to change the USB MIDI
* device name on Teensy LC, 3.x and 4.x. When creating more * device name on Teensy LC, 3.x and 4.x. When creating more
* that one MIDI device, custom names are much easier to * that one MIDI device, custom names are much easier to
* use when selecting each device in MIDI software on * use when selecting each device in MIDI software on
@ -12,9 +12,9 @@
* steps to get your operating system to "forget" the * steps to get your operating system to "forget" the
* cached info. (TODO: wanted... can anyone contribute * cached info. (TODO: wanted... can anyone contribute
* instructions for these systems) * instructions for these systems)
* *
* You must select MIDI from the "Tools > USB Type" menu * You must select MIDI from the "Tools > USB Type" menu
* *
* This example code is in the public domain. * This example code is in the public domain.
*/ */
@ -53,15 +53,17 @@ void onClockStop() {
void setup() { void setup() {
// A led to count bpms // A led to count bpms
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
// Setup our clock system // Setup our clock system
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// Inits the clock
uClock.init();
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
// Starts the clock, tick-tac-tick-tac... // Starts the clock, tick-tac-tick-tac...

@ -1,6 +1,6 @@
/* USB MIDI Sync Slave Box /* USB MIDI Sync Slave Box
* *
* This example demonstrates how to change the USB MIDI * This example demonstrates how to change the USB MIDI
* device name on Teensy LC, 3.x and 4.x. When creating more * device name on Teensy LC, 3.x and 4.x. When creating more
* that one MIDI device, custom names are much easier to * that one MIDI device, custom names are much easier to
* use when selecting each device in MIDI software on * use when selecting each device in MIDI software on
@ -12,9 +12,9 @@
* steps to get your operating system to "forget" the * steps to get your operating system to "forget" the
* cached info. (TODO: wanted... can anyone contribute * cached info. (TODO: wanted... can anyone contribute
* instructions for these systems) * instructions for these systems)
* *
* You must select MIDI from the "Tools > USB Type" menu * You must select MIDI from the "Tools > USB Type" menu
* *
* This example code is in the public domain. * This example code is in the public domain.
*/ */
@ -69,22 +69,24 @@ void onExternalStop()
void setup() { void setup() {
// A led to count bpms // A led to count bpms
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
// Setup realtime midi event handlers // Setup realtime midi event handlers
usbMIDI.setHandleClock(onExternalClock); usbMIDI.setHandleClock(onExternalClock);
usbMIDI.setHandleStart(onExternalStart); usbMIDI.setHandleStart(onExternalStart);
usbMIDI.setHandleStop(onExternalStop); usbMIDI.setHandleStop(onExternalStop);
// Setup our clock system // Setup our clock system
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// set to external sync mode // set to external sync mode
uClock.setMode(1); uClock.setClockMode(uClock.EXTERNAL_CLOCK);
// Inits the clock
uClock.init();
} }
void loop() { void loop() {

@ -1,20 +1,20 @@
/* USB MIDI Sync Slave Box Monitor /* USB MIDI Sync Slave Box Monitor
* *
* This example demonstrates how to create a * This example demonstrates how to create a
* MIDI hid compilant slave clock box using * MIDI hid compilant slave clock box using
* Teensy LC, 3.x and 4.x with * Teensy LC, 3.x and 4.x with
* monitor support using oled displays * monitor support using oled displays
* *
* Making use of a 250 usceconds timer to * Making use of a 250 usceconds timer to
* handle MIDI input to avoid jitter on clock * handle MIDI input to avoid jitter on clock
* *
* You need the following libraries to make it work * You need the following libraries to make it work
* - u8g2 * - u8g2
* - uClock * - uClock
* *
* This example code is in the public domain. * This example code is in the public domain.
*/ */
#include <U8x8lib.h> #include <U8x8lib.h>
// //
@ -100,23 +100,31 @@ void setup() {
//u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); //u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE);
u8x8 = new U8X8_SSD1306_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); u8x8 = new U8X8_SSD1306_128X64_NONAME_HW_I2C(U8X8_PIN_NONE);
u8x8->begin(); u8x8->begin();
u8x8->setFont(u8x8_font_pressstart2p_r); u8x8->setFont(u8x8_font_pressstart2p_r);
u8x8->clear(); u8x8->clear();
u8x8->setFlipMode(true); u8x8->setFlipMode(true);
u8x8->drawUTF8(0, 0, "uClock"); u8x8->drawUTF8(0, 0, "uClock");
// //
// uClock Setup // uClock Setup
// //
// Setup our clock system // Setup our clock system
uClock.init();
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// For MIDI Sync Start and Stop // For MIDI Sync Start and Stop
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
uClock.setMode(uClock.EXTERNAL_CLOCK); uClock.setClockMode(uClock.EXTERNAL_CLOCK);
// for smooth slave tempo calculate display you should raise the
// buffer_size of ext_interval_buffer in between 64 to 128. 254 max size.
// note: this doesn't impact on sync time, only display time getTempo()
// if you dont want to use it, it is default set it to 1 for memory save
uClock.setExtIntervalBuffer(128);
// inits uClock
uClock.init();
// make use of 250us timer to handle midi input sync // make use of 250us timer to handle midi input sync
teensyTimer.begin(handleMidiInput, 250); teensyTimer.begin(handleMidiInput, 250);
teensyTimer.priority(80); teensyTimer.priority(80);
} }
@ -136,20 +144,20 @@ void loop() {
u8x8->drawUTF8(8+4, 7, " "); u8x8->drawUTF8(8+4, 7, " ");
} }
} }
if (clock_state != uClock.state) { if (clock_state != uClock.state) {
clock_state = uClock.state; clock_state = uClock.state;
if (clock_state >= 1) { if (clock_state >= 1) {
u8x8->drawUTF8(0, 7, "Playing"); u8x8->drawUTF8(0, 7, "Playing");
} else { } else {
u8x8->drawUTF8(0, 7, "Stopped"); u8x8->drawUTF8(0, 7, "Stopped");
} }
} }
if (clock_mode != uClock.getMode()) { if (clock_mode != uClock.getMode()) {
clock_mode = uClock.getMode(); clock_mode = uClock.getMode();
if (clock_mode == uClock.EXTERNAL_CLOCK) { if (clock_mode == uClock.EXTERNAL_CLOCK) {
u8x8->drawUTF8(10, 0, "Slave "); u8x8->drawUTF8(10, 0, "Slave ");
} else { } else {
u8x8->drawUTF8(10, 0, "Master"); u8x8->drawUTF8(10, 0, "Master");
} }
} }
} }

@ -1,12 +1,12 @@
/* USB MIDI Sync Box /* USB MIDI Sync Box
* *
* This example demonstrates how to change the USB MIDI * This example demonstrates how to change the USB MIDI
* device name on Seeedstudio XIAO M0. * device name on Seeedstudio XIAO M0.
* *
* This example code is in the public domain. * This example code is in the public domain.
* *
* Tested with Adafruit TinyUSB version 0.10.5 * Tested with Adafruit TinyUSB version 0.10.5
* *
*/ */
#include <Adafruit_TinyUSB.h> #include <Adafruit_TinyUSB.h>
#include <MIDI.h> #include <MIDI.h>
@ -52,15 +52,17 @@ void setup() {
// A led to count bpms // A led to count bpms
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
// Setup our clock system // Setup our clock system
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message. // Set the callback function for the clock output to send MIDI Sync message.
uClock.setOnSync24(onSync24Callback); uClock.setOnSync24(onSync24Callback);
// Set the callback function for MIDI Start and Stop messages. // Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStart(onClockStart); uClock.setOnClockStart(onClockStart);
uClock.setOnClockStop(onClockStop); uClock.setOnClockStop(onClockStop);
// Inits the clock
uClock.init();
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(126);
// Starts the clock, tick-tac-tick-tac... // Starts the clock, tick-tac-tick-tac...

Loading…
Cancel
Save