1 /************************** BEGIN gramophone-midi.h **************************/ 2 /************************************************************************ 3 FAUST Architecture File 4 Copyright (C) 2019-2020 GRAME, Centre National de Creation Musicale 5 --------------------------------------------------------------------- 6 This Architecture section is free software; you can redistribute it 7 and/or modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 3 of 9 the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; If not, see <http://www.gnu.org/licenses/>. 18 19 EXCEPTION : As a special exception, you may create a larger work 20 that contains this FAUST architecture section and distribute 21 that work under terms of your choice, so long as this FAUST 22 architecture section is not modified. 23 ************************************************************************/ 24 25 #ifndef __gramophone_midi__ 26 #define __gramophone_midi__ 27 28 #include "blemidi.h" 29 #include "esp_log.h" 30 #include "faust/gui/meta.h" 31 32 struct bt_meta : Meta 33 { 34 // default values 35 std::string localName = "Gramophone"; 36 std::string remoteName = ""; declarebt_meta37 void declare(const char* key, const char* value) 38 { 39 if (strstr(key,"btmidi_device_name") != NULL) { 40 localName = value; 41 } 42 else if (strstr(key,"btmidi_remote_name") != NULL) { 43 remoteName = value; 44 } 45 } 46 }; 47 48 #define GMH_TAG "GramoMidiHandler" 49 50 class gramophone_midi : public midi_handler { 51 52 private: 53 54 bt_meta fBTMeta; 55 callback_midi_message_received(uint8_t blemidi_port,uint16_t timestamp,uint8_t midi_status,uint8_t * remaining_message,size_t len,size_t continued_sysex_pos,void * arg)56 static void callback_midi_message_received(uint8_t blemidi_port, 57 uint16_t timestamp, 58 uint8_t midi_status, 59 uint8_t* remaining_message, 60 size_t len, 61 size_t continued_sysex_pos, 62 void* arg) 63 { 64 gramophone_midi* midi = static_cast<gramophone_midi*>(arg); 65 if (len == 1) { 66 midi->handleData1(timestamp,(int)midi_status,0, 67 (int)remaining_message[0]); 68 } else if (len == 2) { 69 midi->handleData2(timestamp,(int)midi_status,0, 70 (int)remaining_message[0], 71 (int)remaining_message[1]); 72 } 73 } 74 75 public: 76 gramophone_midi(bt_meta & btMeta)77 gramophone_midi(bt_meta& btMeta) : midi_handler("gramophone") 78 { 79 fBTMeta = btMeta; 80 } 81 ~gramophone_midi()82 virtual ~gramophone_midi() 83 { 84 stopMidi(); 85 } 86 startMidi()87 bool startMidi() 88 { 89 int status = blemidi_init((void*)callback_midi_message_received, fBTMeta.localName.c_str(), fBTMeta.remoteName.c_str(), (void*)this); 90 if (status < 0) { 91 ESP_LOGE(GMH_TAG, "BLE MIDI Driver returned status=%d", status); 92 return false; 93 } else { 94 ESP_LOGI(GMH_TAG, "BLE MIDI Driver initialized successfully"); 95 return true; 96 } 97 } 98 stopMidi()99 void stopMidi() 100 { 101 // This should probably implemented eventually but it can remaind as is for now 102 } 103 104 }; 105 106 #endif 107 /************************** END gramophone-midi.h **************************/ 108