Skip to content

Commit

Permalink
Fix a problem with events not sent from Jack to RTP
Browse files Browse the repository at this point in the history
  • Loading branch information
oscaracena committed Jan 1, 2025
1 parent fbd332d commit 7eab6ba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
.vscode
jackrtpmidid
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 22 additions & 0 deletions jackrtpmidid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7eab6ba

Please sign in to comment.