From 19908839d8b80aed4864a4477cd874aa8191321c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20=C5=9Eiar=20Baysal?= Date: Sat, 9 Nov 2024 11:34:32 +0100 Subject: [PATCH 1/3] add initial mdns responder for rtp-midi aka applemidi --- src/minidexed.cpp | 19 +++++++++++++------ src/minidexed.h | 1 + src/rtpmididevice.cpp | 14 ++++---------- src/rtpmididevice.h | 22 +--------------------- submod.sh | 2 +- 5 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index f26c8a1..81aa11b 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -1835,7 +1835,8 @@ void CMiniDexed::UpdateNetwork() CString IPString; m_pNet->GetConfig()->GetIPAddress()->Format(&IPString); - LOGNOTE("Network up and running at: %s", static_cast(IPString)); + //LOGNOTE("Network up and running at: %s", static_cast(IPString)); + m_UDPMIDI.Initialize(); @@ -1852,11 +1853,17 @@ void CMiniDexed::UpdateNetwork() LOGNOTE("FTP daemon initialized"); } - m_UI.DisplayWrite ("IP", - "Network", - IPString, - 0, - 1); + m_UI.DisplayWrite ("IP", "Network", IPString, 0, 1); + + CmDNSPublisher *pmDNSPublisher = new CmDNSPublisher (m_pNet); + assert (pmDNSPublisher); + static const char ServiceName[] = "minidexed-rtpmidi"; + static const char *ppText[] = {"RTP-MIDI Receiver", nullptr}; // TXT record strings + if (!pmDNSPublisher->PublishService (ServiceName, CmDNSPublisher::ServiceTypeAppleMIDI, + 5004, ppText)) + { + LOGPANIC ("Cannot publish mdns service"); + } } else if (m_bNetworkReady && !bNetIsRunning) { diff --git a/src/minidexed.h b/src/minidexed.h index c109fac..fbc1b02 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "common.h" #include "effect_mixer.hpp" diff --git a/src/rtpmididevice.cpp b/src/rtpmididevice.cpp index 2c29a94..572a5c9 100644 --- a/src/rtpmididevice.cpp +++ b/src/rtpmididevice.cpp @@ -26,24 +26,21 @@ #include "rtpmididevice.h" #include +#define VIRTUALCABLE 24 + LOGMODULE("rtpmididevice"); CRTPMIDIDevice::CRTPMIDIDevice (CMiniDexed *pSynthesizer, CConfig *pConfig, CUserInterface *pUI) : CMIDIDevice (pSynthesizer, pConfig, pUI), m_pConfig (pConfig) - - //m_Serial (pInterrupt, TRUE), - //m_nSerialState (0), - //m_nSysEx (0), - //m_SendBuffer (&m_Serial) { AddDevice ("rtpdummy"); } CRTPMIDIDevice::~CRTPMIDIDevice (void) { - //m_nSerialState = 255; + } boolean CRTPMIDIDevice::Initialize (void) @@ -63,10 +60,7 @@ boolean CRTPMIDIDevice::Initialize (void) void CRTPMIDIDevice::OnAppleMIDIDataReceived(const u8* pData, size_t nSize) { - LOGNOTE("Recieved RTP MIDI Data"); - printf ("MIDI-RTP: %02X %02X\n", - (unsigned) pData[0], (unsigned) pData[1]); - MIDIMessageHandler(pData, nSize); + MIDIMessageHandler(pData, nSize, VIRTUALCABLE); } void CRTPMIDIDevice::OnAppleMIDIConnect(const CIPAddress* pIPAddress, const char* pName) diff --git a/src/rtpmididevice.h b/src/rtpmididevice.h index 418fcde..870301b 100644 --- a/src/rtpmididevice.h +++ b/src/rtpmididevice.h @@ -27,11 +27,6 @@ #include "config.h" #include "net/applemidi.h" -#include -#include -#include -#include - class CMiniDexed; class CRTPMIDIDevice : CAppleMIDIHandler, CMIDIDevice @@ -44,26 +39,11 @@ public: virtual void OnAppleMIDIDataReceived(const u8* pData, size_t nSize) override; virtual void OnAppleMIDIConnect(const CIPAddress* pIPAddress, const char* pName) override; virtual void OnAppleMIDIDisconnect(const CIPAddress* pIPAddress, const char* pName) override; - //void OnAppleMIDIDataReceived(const u8* pData, size_t nSize); - //void OnAppleMIDIConnect(const CIPAddress* pIPAddress, const char* pName); - //void OnAppleMIDIDisconnect(const CIPAddress* pIPAddress, const char* pName); - - //void Process (void); - - //void Send (const u8 *pMessage, size_t nLength, unsigned nCable = 0) override; private: CConfig *m_pConfig; - - //CSerialDevice m_Serial; - //unsigned m_nSerialState; - //unsigned m_nSysEx; - //u8 m_SerialMessage[MAX_MIDI_MESSAGE]; - - //CWriteBufferDevice m_SendBuffer; CBcmRandomNumberGenerator m_Random; - //CAppleMIDIHandler* m_MIDIHandler; - CAppleMIDIParticipant* m_pAppleMIDIParticipant; // AppleMIDI participant instance + CAppleMIDIParticipant* m_pAppleMIDIParticipant; }; #endif diff --git a/submod.sh b/submod.sh index 2e24228..559aeb0 100755 --- a/submod.sh +++ b/submod.sh @@ -12,7 +12,7 @@ cd - # # Optional update submodules explicitly cd circle-stdlib/libs/circle -git checkout fe09c4b +git checkout tags/Step48 cd - cd circle-stdlib/libs/circle-newlib #git checkout develop From 3e77f72a7ab943edaf399f17e9569a9ac20e5ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20=C5=9Eiar=20Baysal?= Date: Sat, 9 Nov 2024 21:01:59 +0100 Subject: [PATCH 2/3] do not reinitialized network --- src/minidexed.cpp | 33 +++++++++++++++++++++------------ src/minidexed.h | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 81aa11b..ca4d671 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -32,6 +32,7 @@ const char WLANFirmwarePath[] = "SD:firmware/"; const char WLANConfigFile[] = "SD:wpa_supplicant.conf"; #define FTPUSERNAME "admin" #define FTPPASSWORD "admin" +#define MDNSSERVICENAME "MiniDexed" LOGMODULE ("minidexed"); @@ -61,6 +62,7 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, m_WPASupplicant(WLANConfigFile), m_bNetworkReady(false), m_UDPMIDI (this, pConfig, &m_UI), + m_pmDNSPublisher (), m_bSavePerformance (false), m_bSavePerformanceNewFile (false), m_bSetNewPerformance (false), @@ -1826,10 +1828,14 @@ void CMiniDexed::UpdateNetwork() if (!m_pNet) return; + //add wired network check as well bool bNetIsRunning = m_pNet->IsRunning(); - bNetIsRunning &= m_WPASupplicant.IsConnected(); - - if (!m_bNetworkReady && bNetIsRunning) + if ((strcmp(m_pConfig->GetNetworkType(), "ethernet") == 0)) + bNetIsRunning &= m_pNetDevice->IsLinkUp(); + else if ((strcmp(m_pConfig->GetNetworkType(), "wifi") == 0)) + bNetIsRunning &= m_WPASupplicant.IsConnected(); + + if (!m_bNetworkReady && (m_pNet->IsRunning())) { m_bNetworkReady = true; CString IPString; @@ -1837,7 +1843,6 @@ void CMiniDexed::UpdateNetwork() //LOGNOTE("Network up and running at: %s", static_cast(IPString)); - m_UDPMIDI.Initialize(); m_pFTPDaemon = new CFTPDaemon(FTPUSERNAME, FTPPASSWORD); @@ -1855,21 +1860,25 @@ void CMiniDexed::UpdateNetwork() m_UI.DisplayWrite ("IP", "Network", IPString, 0, 1); - CmDNSPublisher *pmDNSPublisher = new CmDNSPublisher (m_pNet); - assert (pmDNSPublisher); - static const char ServiceName[] = "minidexed-rtpmidi"; - static const char *ppText[] = {"RTP-MIDI Receiver", nullptr}; // TXT record strings - if (!pmDNSPublisher->PublishService (ServiceName, CmDNSPublisher::ServiceTypeAppleMIDI, - 5004, ppText)) + m_pmDNSPublisher = new CmDNSPublisher (m_pNet); + assert (m_pmDNSPublisher); + + //static const char *ppText[] = {"RTP-MIDI Receiver", nullptr}; // dont bother adding additional data + if (!m_pmDNSPublisher->PublishService (MDNSSERVICENAME, CmDNSPublisher::ServiceTypeAppleMIDI, + 5004)) { LOGPANIC ("Cannot publish mdns service"); } } else if (m_bNetworkReady && !bNetIsRunning) { - m_bNetworkReady = false; + //m_bNetworkReady = false; + m_pmDNSPublisher->UnpublishService (MDNSSERVICENAME); LOGNOTE("Network disconnected."); - + } + else if (m_bNetworkReady && bNetIsRunning) + { + LOGNOTE("Network connection reestablished."); } } diff --git a/src/minidexed.h b/src/minidexed.h index fbc1b02..189e45e 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -318,6 +318,7 @@ private: bool m_bNetworkReady; CUDPMIDIDevice m_UDPMIDI; CFTPDaemon* m_pFTPDaemon; + CmDNSPublisher *m_pmDNSPublisher; bool m_bSavePerformance; bool m_bSavePerformanceNewFile; From 17d905a1ae150d56a57c85486d5d87ea7a27d47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20=C5=9Eiar=20Baysal?= Date: Sat, 9 Nov 2024 21:10:07 +0100 Subject: [PATCH 3/3] continue publishing mdns after network connection reestablishes --- src/minidexed.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index ca4d671..78f8e69 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -1878,7 +1878,13 @@ void CMiniDexed::UpdateNetwork() } else if (m_bNetworkReady && bNetIsRunning) { + if (!m_pmDNSPublisher->PublishService (MDNSSERVICENAME, CmDNSPublisher::ServiceTypeAppleMIDI, + 5004)) + { + LOGPANIC ("Cannot publish mdns service"); + } LOGNOTE("Network connection reestablished."); + } }