diff --git a/osc/src/main.cpp b/osc/src/main.cpp index 042c222..15b4f1c 100644 --- a/osc/src/main.cpp +++ b/osc/src/main.cpp @@ -1,19 +1,34 @@ -//arduino -#include +// +// wirelessly connected cloud (Wireless Mesh Networking) +// MIDI-like +// spacial +// sampler keyboard +// -//osc -#include -#ifdef SLIP_USBSERIAL -#include -SLIPEncodedUSBSerial SLIPSerial(Serial); +// +// COSMO40 @ Incheon w/ Factory2 +// RTA @ Seoul w/ Post Territory Ujeongguk +// -//i2c -#include -const int16_t I2C_ADDR = 3; -#define POST_LENGTH 32 -#define POST_BUFF_LEN (POST_LENGTH + 1) -//==================== -// postman's protocol +// +// 2019 12 11 +// +// (part-2) teensy35 : 'client:osc' (osc over slip --> mesh post) +// +// especially, MIDI-like. +// collect following OSC msg. +// +// "/note/onoff" +// "/note/velocity" +// "/note/key" +// +// and build a MIDI-like letter post. +// and give it to the postman +// + +// +// --[post]--> "sampler" +// // letter frame ( '[' + 30 bytes + ']' ) // : [123456789012345678901234567890] // 'MIDI' letter frame @@ -25,33 +40,45 @@ const int16_t I2C_ADDR = 3; // .substring(4, 7); // : G - Gate (note on/off) // .substring(7, 8); -//=================== +// + +//arduino +#include + +//osc +#include +#include +SLIPEncodedUSBSerial SLIPSerial(Serial); + +//i2c +#include +// --[post]--> "sampler" +#include "../../sampler/post_sampler.h" void receiveEvent(int howMany) { // nothing to expect.. but.. let's just print out.. - while (Wire.available()) - Serial.print(Wire.read()); - Serial.println(); + // while (Wire.available()) + // Serial.print(Wire.read()); + // Serial.println(); } // well. i don't know how fast should i be able to send msg.. to the net.. // first test, and then.. if needed. will come back. -bool new_letter; +bool new_letter = false; char letter_outro[POST_BUFF_LEN] = "................................"; +void letter_outro_clear() { + // clear the letter buff + letter_outro[0] = '['; + for (int i = 1; i < POST_LENGTH-1; i++) letter_outro[i] = '.'; + letter_outro[POST_LENGTH-1] = ']'; +} void requestEvent() { - if (random(1000) == 0) { - Wire.write("[bcdefghabcdefghabcdefghabcdefg]"); //32 bytes + if (new_letter) { + Wire.write(letter_outro, POST_LENGTH); + new_letter = false; } else { Wire.write(" "); // no letter to send } } - -// -void midinote(OSCMessage &msg, int offset) { - // msg.match("/oncnt"); - if (msg.match("/onoff")) { - msg.match("/velocity"); - msg.match("/pitch"); - } -} +void I2CPrint(const String & str); // for DEBUG w/ I2C // void setup() { @@ -64,7 +91,43 @@ void setup() { SLIPSerial.begin(57600); } +// +void midinote(OSCMessage& msg, int offset) { + // matches will happen in the order. that the bundle is packed. + static int pitch = 0; + static int velocity = 0; + static int onoff = 0; + // (1) --> /onoff + if (msg.fullMatch("/onoff", offset)) { + // + pitch = 0; + velocity = 0; + onoff = 0; + // + onoff = msg.getInt(0); + if (onoff != 0) onoff = 1; + } + // (2) --> /velocity + if (msg.fullMatch("/velocity", offset)) { + velocity = msg.getInt(0); + if (velocity < 0) velocity = 0; + if (velocity > 127) velocity = 127; + } + // (3) --> /pitch + if (msg.fullMatch("/pitch", offset)) { + pitch = msg.getInt(0); + if (pitch < 0) pitch = 0; + if (pitch > 127) pitch = 127; + // + // while (new_letter != false) {}; // <-- sort of semaphore.. but it doesn't work yet.. buggy. + sprintf(letter_outro, "[%03d%03d%01d.......................]", pitch, velocity, onoff); + new_letter = true; + } +} + +// void loop() { + static String str = ""; //osc OSCBundle bundleIN; int size; @@ -78,4 +141,28 @@ void loop() { if(!bundleIN.hasError()) { bundleIN.route("/note", midinote); } + // else { + // str = "error! : " + String(bundleIN.getError()); + // I2CPrint(str); + // } } + +//==================== +// utility func. -> for DEBUG w/ I2C +char buff[POST_LENGTH] = ""; +void I2CPrint(const String & str) { + const char * buff = str.c_str(); + int len = str.length(); + // while (new_letter != false) {}; + letter_outro[0] = '['; + if (len > (POST_LENGTH - 2)) len = (POST_LENGTH - 2); + for (int i = 0; i < len; i++) { + letter_outro[i+1] = buff[i]; + } + for (int j = len; j < (POST_LENGTH - 2); j++) { + letter_outro[j+1] = '_'; + } + letter_outro[POST_LENGTH-1] = ']'; + new_letter = true; +} +//=================== diff --git a/post.h b/post.h new file mode 100644 index 0000000..691f996 --- /dev/null +++ b/post.h @@ -0,0 +1,5 @@ +#pragma once + +#define I2C_ADDR 3 +#define POST_LENGTH 32 +#define POST_BUFF_LEN (POST_LENGTH + 1) diff --git a/sampler/post_sampler.h b/sampler/post_sampler.h new file mode 100644 index 0000000..564156a --- /dev/null +++ b/sampler/post_sampler.h @@ -0,0 +1,17 @@ +#pragma once + +#include "../post.h" + +// +// letter frame ( '[' + 30 bytes + ']' ) +// : [123456789012345678901234567890] +// 'MIDI' letter frame +// : [123456789012345678901234567890] +// : [KKKVVVG.......................] +// : KKK - Key +// .substring(1, 4); +// : VVV - Velocity (volume/amp.) +// .substring(4, 7); +// : G - Gate (note on/off) +// .substring(7, 8); +// diff --git a/sampler/src/main.cpp b/sampler/src/main.cpp index 1825cf0..df52f4f 100644 --- a/sampler/src/main.cpp +++ b/sampler/src/main.cpp @@ -1,12 +1,28 @@ +// +// wirelessly connected cloud (Wireless Mesh Networking) +// MIDI-like +// spacial +// sampler keyboard +// + +// +// COSMO40 @ Incheon w/ Factory2 +// RTA @ Seoul w/ Post Territory Ujeongguk +// + +// +// 2019 12 11 +// +// (part-3) teensy35 : 'client:sampler' (mesh post --> play sounds) +// + //HACK: let auto-poweroff speakers stay turned ON! - (creative muvo mini) #define IDLE_FREQ 22000 #define IDLE_AMP 0 // --> creative muvo 2 doesn't need this. they just stay on! //i2c #include -#define I2C_ADDR 3 -#define POST_LENGTH 32 -#define POST_BUFF_LEN (POST_LENGTH + 1) +#include "../post_sampler.h" //teensy audio #include diff --git a/src/main.cpp b/src/main.cpp index 86ea1c1..8b7a3ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,9 +75,7 @@ //i2c #include -#define I2C_ADDR 3 -#define POST_LENGTH 32 -#define POST_BUFF_LEN (POST_LENGTH + 1) +#include "../post.h" //painlessmesh #include