Skip to content

Commit

Permalink
Fixed #291
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Dec 14, 2024
1 parent ac66c8e commit 37bac76
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 143 deletions.
11 changes: 7 additions & 4 deletions lib-ltc/include/arm/ltcmidisystemrealtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file ltcmidisystemrealtime.h
*
*/
/* Copyright (C) 2020-2023 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2020-2024 by Arjan van Vught mailto:[email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -42,8 +42,6 @@ class LtcMidiSystemRealtime {

void Start();
void Stop();
void Run();


void SendStart() {
Send(midi::Types::START);
Expand All @@ -59,6 +57,8 @@ class LtcMidiSystemRealtime {

void SetBPM(uint32_t nBPM);

void Input(const uint8_t *pBuffer, uint32_t nSize, uint32_t nFromIp, uint16_t nFromPort);

static LtcMidiSystemRealtime *Get() {
return s_pThis;
}
Expand All @@ -78,11 +78,14 @@ class LtcMidiSystemRealtime {
LtcOutputs::Get()->ShowBPM(nBPM);
}

void static staticCallbackFunctionInput(const uint8_t *pBuffer, uint32_t nSize, uint32_t nFromIp, uint16_t nFromPort) {
s_pThis->Input(pBuffer, nSize, nFromIp, nFromPort);
}

private:
int32_t m_nHandle { -1 };
uint32_t m_nBPMPrevious { 999 };

static inline char *s_pUdpBuffer;
static inline LtcMidiSystemRealtime *s_pThis;
};

Expand Down
1 change: 1 addition & 0 deletions lib-ltc/include/arm/ltcoutputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class LtcOutputs {
bool m_bShowSysTime;
ltc::Type m_TypePrevious { ltc::Type::INVALID };
uint32_t m_nMidiQuarterFramePiece { 0 };
uint32_t m_nRtpMidiQuarterFramePiece { 0 };
char m_aTimeCode[ltc::timecode::CODE_MAX_LENGTH];
char m_aSystemTime[ltc::timecode::SYSTIME_MAX_LENGTH];
int32_t m_nSecondsPrevious { 60 };
Expand Down
4 changes: 0 additions & 4 deletions lib-ltc/src/arm/artnetreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ void ArtNetReader::Handler(const struct artnet::TimeCode *ArtNetTimeCode) {
LtcSender::Get()->SetTimeCode(reinterpret_cast<const struct ltc::TimeCode *>(ArtNetTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(ArtNetTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(ArtNetTimeCode));
}
Expand Down
4 changes: 0 additions & 4 deletions lib-ltc/src/arm/ltcetcreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ void LtcEtcReader::Handler(const midi::Timecode *pTimeCode) {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode *>(pTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(pTimeCode);
}

memcpy(&m_MidiTimeCode, pTimeCode, sizeof(struct midi::Timecode));

LtcOutputs::Get()->Update(reinterpret_cast<const struct ltc::TimeCode*>(pTimeCode));
Expand Down
4 changes: 0 additions & 4 deletions lib-ltc/src/arm/ltcgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,6 @@ void LtcGenerator::Update() {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(&g_ltc_LtcTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(&g_ltc_LtcTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(&g_ltc_LtcTimeCode));
}
Expand Down
56 changes: 27 additions & 29 deletions lib-ltc/src/arm/ltcmidisystemrealtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* THE SOFTWARE.
*/

#if defined (DEBUG_ARM_LTCMIDISYSTEMREALTIME)
# undef NDEBUG
#endif

#pragma GCC push_options
#pragma GCC optimize ("O2")
#pragma GCC optimize ("no-tree-loop-distribute-patterns")
Expand Down Expand Up @@ -74,7 +78,7 @@ static void timer_handler() {
#endif

void LtcMidiSystemRealtime::Start() {
m_nHandle = Network::Get()->Begin(udp::PORT);
m_nHandle = Network::Get()->Begin(udp::PORT, staticCallbackFunctionInput);
assert(m_nHandle != -1);
}

Expand Down Expand Up @@ -104,67 +108,61 @@ void LtcMidiSystemRealtime::SetBPM(uint32_t nBPM) {
}
}

void LtcMidiSystemRealtime::Run() {
uint32_t nIPAddressFrom;
uint16_t nForeignPort;

auto nBytesReceived = Network::Get()->RecvFrom(m_nHandle, const_cast<const void **>(reinterpret_cast<void **>(&s_pUdpBuffer)), &nIPAddressFrom, &nForeignPort);

if (__builtin_expect((nBytesReceived < 9), 1)) {
return;
}

if (__builtin_expect((memcmp("midi!", s_pUdpBuffer, 5) != 0), 0)) {
void LtcMidiSystemRealtime::Input(const uint8_t *pBuffer, uint32_t nSize, [[maybe_unused]] uint32_t nFromIp, [[maybe_unused]] uint16_t nFromPort) {
if (__builtin_expect((memcmp("midi!", pBuffer, 5) != 0), 0)) {
return;
}

if (s_pUdpBuffer[nBytesReceived - 1] == '\n') {
nBytesReceived--;
if (pBuffer[nSize - 1] == '\n') {
nSize--;
}

debug_dump(s_pUdpBuffer, nBytesReceived);
debug_dump(pBuffer, nSize);

if (nBytesReceived == (5 + length::START)) {
if (memcmp(&s_pUdpBuffer[5], cmd::START, length::START) == 0) {
if (nSize == (5 + length::START)) {
if (memcmp(&pBuffer[5], cmd::START, length::START) == 0) {
SendStart();
DEBUG_PUTS("Start");
return;
}
}

if (nBytesReceived == (5 + length::STOP)) {
if (memcmp(&s_pUdpBuffer[5], cmd::STOP, length::STOP) == 0) {
if (nSize == (5 + length::STOP)) {
if (memcmp(&pBuffer[5], cmd::STOP, length::STOP) == 0) {
SendStop();
DEBUG_PUTS("Stop");
return;
}
}

if (nBytesReceived == (5 + length::CONTINUE)) {
if (memcmp(&s_pUdpBuffer[5], cmd::CONTINUE, length::CONTINUE) == 0) {
if (nSize == (5 + length::CONTINUE)) {
if (memcmp(&pBuffer[5], cmd::CONTINUE, length::CONTINUE) == 0) {
SendContinue();
DEBUG_PUTS("Continue");
return;
}
}

if (nBytesReceived == (5 + length::BPM + 3)) {
if (memcmp(&s_pUdpBuffer[5], cmd::BPM, length::BPM) == 0) {
if (nSize == (5 + length::BPM + 3)) {
if (memcmp(&pBuffer[5], cmd::BPM, length::BPM) == 0) {
uint32_t nOfffset = 5 + length::BPM;
uint32_t nBPM;

if (isdigit(s_pUdpBuffer[nOfffset])) {
nBPM = 100U * static_cast<uint32_t>(s_pUdpBuffer[nOfffset++] - '0');
if (isdigit(s_pUdpBuffer[nOfffset])) {
nBPM += 10U * static_cast<uint32_t>(s_pUdpBuffer[nOfffset++] - '0');
if (isdigit(s_pUdpBuffer[nOfffset])) {
nBPM += static_cast<uint32_t>(s_pUdpBuffer[nOfffset++] - '0');
if (isdigit(pBuffer[nOfffset])) {
nBPM = 100U * static_cast<uint32_t>(pBuffer[nOfffset++] - '0');

if (isdigit(pBuffer[nOfffset])) {
nBPM += 10U * static_cast<uint32_t>(pBuffer[nOfffset++] - '0');

if (isdigit(pBuffer[nOfffset])) {
nBPM += static_cast<uint32_t>(pBuffer[nOfffset++] - '0');
SetBPM(nBPM);
ShowBPM(nBPM);
DEBUG_PRINTF("BPM: %u", nBPM);
}
}
}

return;
}
}
Expand Down
24 changes: 18 additions & 6 deletions lib-ltc/src/arm/ltcoutputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ LtcOutputs::LtcOutputs(const ltc::Source source, const bool bShowSysTime): m_bSh
}

void LtcOutputs::Init() {
if (!ltc::g_DisabledOutputs.bMidi) {
if ((!ltc::g_DisabledOutputs.bMidi) || (!ltc::g_DisabledOutputs.bRtpMidi)) {
#if defined (H3)
irq_timer_set(IRQ_TIMER_1, static_cast<thunk_irq_timer_t>(irq_timer1_midi_handler));
#elif defined (GD32)
Expand All @@ -119,13 +119,13 @@ void LtcOutputs::Init() {
void LtcOutputs::Update(const struct ltc::TimeCode *ptLtcTimeCode) {
assert(ptLtcTimeCode != nullptr);

if (!ltc::g_DisabledOutputs.bNtp) {
NtpServer::Get()->SetTimeCode(ptLtcTimeCode);
}

if (ptLtcTimeCode->nType != static_cast<uint8_t>(m_TypePrevious)) {
m_TypePrevious = static_cast<ltc::Type>(ptLtcTimeCode->nType);

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(ptLtcTimeCode));
}

if (!ltc::g_DisabledOutputs.bMidi) {
Midi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(ptLtcTimeCode));
}
Expand All @@ -140,6 +140,7 @@ void LtcOutputs::Update(const struct ltc::TimeCode *ptLtcTimeCode) {
#endif

m_nMidiQuarterFramePiece = 0;
m_nRtpMidiQuarterFramePiece = 0;

if (!ltc::g_DisabledOutputs.bOled) {
Display::Get()->TextLine(2, ltc::get_type(static_cast<ltc::Type>(ptLtcTimeCode->nType)), ltc::timecode::TYPE_MAX_LENGTH);
Expand All @@ -154,6 +155,10 @@ void LtcOutputs::Update(const struct ltc::TimeCode *ptLtcTimeCode) {
m_aTimeCode[ltc::timecode::index::COLON_3] = (ptLtcTimeCode->nType != static_cast<uint8_t>(ltc::Type::DF) ? ':' : ';');
}

if (!ltc::g_DisabledOutputs.bNtp) {
NtpServer::Get()->SetTimeCode(ptLtcTimeCode);
}

ltc::itoa_base10(ptLtcTimeCode, m_aTimeCode);

if (!ltc::g_DisabledOutputs.bOled) {
Expand All @@ -176,7 +181,14 @@ void LtcOutputs::UpdateMidiQuarterFrameMessage(const struct ltc::TimeCode *pltcT

if (__builtin_expect((sv_isMidiQuarterFrameMessage), 0)) {
sv_isMidiQuarterFrameMessage = false;
Midi::Get()->SendQf(reinterpret_cast<const struct midi::Timecode *>(pltcTimeCode), m_nMidiQuarterFramePiece);

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendQf(reinterpret_cast<const struct midi::Timecode *>(pltcTimeCode), m_nRtpMidiQuarterFramePiece);
}

if (!ltc::g_DisabledOutputs.bMidi) {
Midi::Get()->SendQf(reinterpret_cast<const struct midi::Timecode *>(pltcTimeCode), m_nMidiQuarterFramePiece);
}
}
}

Expand Down
8 changes: 1 addition & 7 deletions lib-ltc/src/arm/ltcreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,13 @@ void LtcReader::Run() {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(&ltcTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(const_cast<struct midi::Timecode *>(&s_midiTimeCode)));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(reinterpret_cast<const struct midi::Timecode *>(const_cast<struct midi::Timecode *>(&s_midiTimeCode)));
}

if (m_nTypePrevious != TimeCodeType) {
m_nTypePrevious = TimeCodeType;

Midi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(const_cast<struct midi::Timecode *>(&s_midiTimeCode)));

#if defined (H3)
H3_TIMER->TMR1_INTV = TimeCodeConst::TMR_INTV[static_cast<uint32_t>(TimeCodeType)] / 4;
H3_TIMER->TMR1_CTRL |= (TIMER_CTRL_EN_START | TIMER_CTRL_RELOAD);
Expand All @@ -314,7 +308,7 @@ void LtcReader::Run() {
#endif
}

LtcOutputs::Get()->Update(reinterpret_cast<const struct ltc::TimeCode*>(&ltcTimeCode));
LtcOutputs::Get()->Update(reinterpret_cast<const struct ltc::TimeCode *>(&ltcTimeCode));
}

__DMB();
Expand Down
4 changes: 0 additions & 4 deletions lib-ltc/src/arm/midireader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ void MidiReader::Update() {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(&m_MidiTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(&m_MidiTimeCode);
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(&m_MidiTimeCode);
}
Expand Down
8 changes: 0 additions & 8 deletions lib-ltc/src/arm/systimereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ void SystimeReader::ActionSetRate(const char *pTimeCodeRate) {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(&m_MidiTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(&m_MidiTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(&m_MidiTimeCode);
}
Expand Down Expand Up @@ -285,10 +281,6 @@ void SystimeReader::Run() {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode *>(&m_MidiTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(&m_MidiTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(&m_MidiTimeCode);
}
Expand Down
4 changes: 0 additions & 4 deletions lib-ltc/src/arm/tcnetreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ void TCNetReader::Handler(const struct tcnet::TimeCode *pTimeCode) {
ArtNetNode::Get()->SendTimeCode(reinterpret_cast<const struct artnet::TimeCode*>(pTimeCode));
}

if (!ltc::g_DisabledOutputs.bRtpMidi) {
RtpMidi::Get()->SendTimeCode(reinterpret_cast<const struct midi::Timecode *>(pTimeCode));
}

if (!ltc::g_DisabledOutputs.bEtc) {
LtcEtc::Get()->Send(&m_MidiTimeCode);
}
Expand Down
3 changes: 3 additions & 0 deletions lib-midi/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-h3/CMSIS/Core_A/Include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-h3/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-arm/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-network/include}&quot;"/>
</option>
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input.57520852" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input"/>
</tool>
Expand All @@ -223,6 +224,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-h3/CMSIS/Core_A/Include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-h3/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-arm/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-network/include}&quot;"/>
</option>
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input.749519629" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input"/>
</tool>
Expand All @@ -242,6 +244,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-hal/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-arm/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/lib-network/include}&quot;"/>
</option>
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.input.290390095" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.input"/>
</tool>
Expand Down
4 changes: 2 additions & 2 deletions lib-midi/.settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-868907429938189684" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-868850457862413684" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -14,7 +14,7 @@
</configuration>
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.309283989.303033930.1102356485.534880544.1199730404" name="H3">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="1410606877957839909" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="1326063933164894935" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
Loading

0 comments on commit 37bac76

Please sign in to comment.