From 7eab6ba67f8a51577bf56caac85ff4b9fd6133a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Ace=C3=B1a?= Date: Wed, 1 Jan 2025 02:46:02 +0100 Subject: [PATCH] Fix a problem with events not sent from Jack to RTP --- .gitignore | 3 +++ Makefile | 15 +++++++++++++++ jackrtpmidid.cpp | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbec3f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +.vscode +jackrtpmidid diff --git a/Makefile b/Makefile index 07e5bc2..2264eae 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,24 @@ vpath %.cpp libs/RTP-MIDI libs/BEBSDK all: $(TARGET) +debug: CXXFLAGS += -g -DSHOW_RTP_INFO +debug: all + $(TARGET): $(OBJECTS) $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@ .PHONY: clean clean: $(RM) -frv *.o $(TARGET) + + +## Other helper rules + +run: + ./$(TARGET) + +run-with-gdb: + gdb \ + -ex 'set print pretty on' \ + -ex run \ + $(TARGET) diff --git a/jackrtpmidid.cpp b/jackrtpmidid.cpp index dbee800..bfd8460 100644 --- a/jackrtpmidid.cpp +++ b/jackrtpmidid.cpp @@ -90,7 +90,29 @@ void* RTThreadFunc (CThread* Control) while (Control->ShouldStop==false) { if (RTPMIDIHandler1) + { + // NOTE: writePtr could be modified by Jack thread, but readPtr is not + int readPtr = JACK2RTP.ReadPtr; + int writePtr = JACK2RTP.WritePtr; + + if (writePtr > readPtr) + { + if (RTPMIDIHandler1->SendRTPMIDIBlock(writePtr - readPtr, + JACK2RTP.FIFO + JACK2RTP.ReadPtr)) + JACK2RTP.ReadPtr = writePtr; + } + + else if (readPtr > writePtr) + { + if (RTPMIDIHandler1->SendRTPMIDIBlock( + MIDI_CHAR_FIFO_SIZE - readPtr, JACK2RTP.FIFO + JACK2RTP.ReadPtr)) + if (RTPMIDIHandler1->SendRTPMIDIBlock(writePtr, JACK2RTP.FIFO)) + JACK2RTP.ReadPtr = writePtr; + } + RTPMIDIHandler1->RunSession(); + } + if (RTPMIDIHandler2) RTPMIDIHandler2->RunSession(); SystemSleepMillis(1);