diff --git a/audioooo/src/main.cpp b/audioooo/src/main.cpp index 7e34db0..96fc9b6 100644 --- a/audioooo/src/main.cpp +++ b/audioooo/src/main.cpp @@ -29,9 +29,16 @@ // 'DISABLE_AP' // --> (questioning)... // +// 'REPLICATE_NOTE_REQ' (+ N_SEC_BLOCKING_NOTE_REQ) +// --> for supporting wider area with simple esp_now protocol, +// all receipents will replicate NOTE msg. when they are newly appeared. +// + then, network would be flooded by infinite duplicating msg., +// unless they stop reacting to 'known' req. for some seconds. (e.g. 3 seconds) +// //==================== // #define DISABLE_AP +#define REPLICATE_NOTE_REQ //======================== // @@ -77,6 +84,7 @@ //espnow #include #include +AddressLibrary lib; //task #include @@ -215,6 +223,37 @@ void sample_player_stop() { audio.stopSong(); } Task sample_player_stop_task(0, TASK_ONCE, &sample_player_stop, &runner, false); + +// +#if defined(REPLICATE_NOTE_REQ) +Note note_now = { + -1, // int32_t id; + -1, // float pitch; + -1, // float velocity; + -1, // float onoff; + -1, // float x1; + -1, // float x2; + -1, // float x3; + -1, // float x4; + -1 // float ps; +}; +#define NEW_NOTE_TIMEOUT (3000) +static unsigned long new_note_time = (-1*NEW_NOTE_TIMEOUT); +void repeat() { + // + uint8_t frm_size = sizeof(Note) + 2; + uint8_t frm[frm_size]; + frm[0] = '['; + memcpy(frm + 1, (uint8_t *) ¬e_now, sizeof(Note)); + frm[frm_size - 1] = ']'; + // + esp_now_send(NULL, frm, frm_size); // to all peers in the list. + // + MONITORING_SERIAL.print("repeat! ==> "); + MONITORING_SERIAL.println(note_now.to_string()); +} +Task repeat_task(0, TASK_ONCE, &repeat, &runner, false); +#endif //*-*-*-*-*-*-*-*-*-*-*-*-* // @@ -250,6 +289,21 @@ void hello() { if (hello_delay < 100) hello_delay = 100; hello_task.restartDelayed(hello_delay); } + + // //TEST + // Note n = { + // 10001, // int32_t id; + // 1, // float pitch; + // 127, // float velocity; + // 1, // float onoff; + // 0, // float x1; + // 0, // float x2; + // 0, // float x3; + // 0, // float x4; + // 5000 // float ps; + // }; + // note_now = n; + // repeat_task.restart(); } Task hello_task(0, TASK_ONCE, &hello, &runner, false); @@ -335,6 +389,15 @@ void onDataReceive(const uint8_t * mac, const uint8_t *incomingData, int32_t len } MONITORING_SERIAL.println(note.to_string()); + + #if defined(REPLICATE_NOTE_REQ) + if (millis() - new_note_time > NEW_NOTE_TIMEOUT) { + note_now = note; + repeat_task.restart(); + new_note_time = millis(); + } + #endif + } } @@ -430,6 +493,9 @@ void setup() { #endif #if defined(HAVE_CLIENT_I2C) Serial.println("- ======== 'HAVE_CLIENT_I2C' ========"); +#endif +#if defined(REPLICATE_NOTE_REQ) + Serial.println("- ======== 'REPLICATE_NOTE_REQ' ========"); #endif Serial.println("-"); @@ -450,16 +516,25 @@ void setup() { esp_now_register_send_cb(onDataSent); esp_now_register_recv_cb(onDataReceive); // - Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF)."); - uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - + // Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF)."); + // uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // - esp_now_peer_info_t peerInfo; - memcpy(peerInfo.peer_addr, broadcastmac, 6); - peerInfo.channel = 0; - peerInfo.encrypt = false; - esp_now_add_peer(&peerInfo); + // // + // esp_now_peer_info_t peerInfo; + // memcpy(peerInfo.peer_addr, broadcastmac, 6); + // peerInfo.channel = 0; + // peerInfo.encrypt = false; + // esp_now_add_peer(&peerInfo); + AddressBook * book = lib.getBookByTitle("audioooo"); + for (int idx = 0; idx < book->list.size(); idx++) { + Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'."); + esp_now_peer_info_t peerInfo; + memcpy(peerInfo.peer_addr, book->list[idx].mac, 6); + peerInfo.channel = 0; + peerInfo.encrypt = false; + esp_now_add_peer(&peerInfo); + } // Serial.println("-"); Serial.println("\".-.-.-. :)\""); diff --git a/post.h b/post.h index a1db150..726a413 100644 --- a/post.h +++ b/post.h @@ -107,6 +107,18 @@ struct AddressLibrary { // lib.push_back(book); } + // book #4 + { + AddressBook book = AddressBook("audioooo"); + // + // samplers don't have ID_KEY, they will just get all messages, + // then open the content to get **midi** 'key' in the 'note' message. + book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAE, 0x0C, "audioooo #1")); //WROOM + book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAD, 0xB0, "audioooo #2")); //WROOM + book.add(Address(0xA8, 0x03, 0x2A, 0x6C, 0x88, 0x78, "audioooo #3")); //WROVER + // + lib.push_back(book); + } } // AddressBook* getBookByTitle(String title_) { diff --git a/puredata/audioooo-test.pd b/puredata/audioooo-test.pd new file mode 100644 index 0000000..690586b --- /dev/null +++ b/puredata/audioooo-test.pd @@ -0,0 +1,27 @@ +#N canvas 678 548 450 300 12; +#X obj 73 204 s NOTE; +#X obj 73 142 pack f f; +#X floatatom 73 112 5 0 0 0 - - -; +#X obj 94 81 t b a; +#X obj 94 55 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1 +; +#X obj 202 50 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X obj 232 141 r HELLO; +#X obj 232 166 print HELLO; +#X msg 202 75 5002 1 127 \$1; +#X msg 73 173 10001 \$1 127 \$2; +#X obj 220 9 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1 +; +#X obj 115 6 metro 5000; +#X connect 1 0 9 0; +#X connect 2 0 1 0; +#X connect 3 0 2 0; +#X connect 3 1 1 1; +#X connect 4 0 3 0; +#X connect 5 0 8 0; +#X connect 6 0 7 0; +#X connect 8 0 0 0; +#X connect 9 0 0 0; +#X connect 10 0 11 0; +#X connect 11 0 4 0; diff --git a/puredata/piano_access_radio_comm_only.pd b/puredata/piano_access_radio_comm_only.pd index 537d1b5..dde895d 100644 --- a/puredata/piano_access_radio_comm_only.pd +++ b/puredata/piano_access_radio_comm_only.pd @@ -1,4 +1,4 @@ -#N canvas 503 95 623 400 10; +#N canvas 503 89 623 400 10; #X obj 322 198 spigot; #X obj 371 183 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; @@ -76,18 +76,18 @@ #X obj 34 190 print HELLO; #X text 103 24 * a wireless "field synth" - based on 'esp now' protocol ; -#X msg 243 98 devicename /dev/ttyACM0 \, baud 57600 \, pollintervall -1 \, verbose 1; #X msg 204 58 devicename /dev/tty.usbmodem4871051 \, baud 57600 \, pollintervall 1 \, verbose 1; #X msg 494 315 2000; #X obj 230 203 tgl 15 0 empty empty connected? 17 7 0 10 -262144 -1 -1 1 1; +#X msg 243 98 devicename /dev/ttyACM0 \, baud 57600 \, pollintervall +1 \, verbose 1; #X connect 0 0 16 0; #X connect 1 0 0 1; #X connect 2 0 14 0; #X connect 3 0 8 0; -#X connect 3 1 31 0; +#X connect 3 1 30 0; #X connect 4 0 3 1; #X connect 5 0 3 1; #X connect 6 0 3 0; @@ -104,10 +104,10 @@ pollintervall 1 \, verbose 1; #X connect 20 0 23 0; #X connect 21 0 22 0; #X connect 22 0 20 0; -#X connect 23 0 30 0; +#X connect 23 0 29 0; #X connect 23 1 18 0; #X connect 24 0 26 0; #X connect 25 0 24 1; #X connect 28 0 3 1; -#X connect 29 0 3 1; -#X connect 30 0 18 0; +#X connect 29 0 18 0; +#X connect 31 0 3 1;