Skip to content

Commit

Permalink
Portmidi
Browse files Browse the repository at this point in the history
  • Loading branch information
giulioz committed Apr 3, 2024
1 parent 904286f commit 50e3208
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 97 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "3rdparty/rtmidi"]
path = 3rdparty/rtmidi
url = https://github.com/Wohlstand/rtmidi.git
[submodule "3rdparty/portmidi"]
path = 3rdparty/portmidi
url = https://github.com/PortMidi/portmidi.git
1 change: 1 addition & 0 deletions 3rdparty/portmidi
Submodule portmidi added at 392030
1 change: 0 additions & 1 deletion 3rdparty/rtmidi
Submodule rtmidi deleted from 722703
26 changes: 8 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,14 @@ endif()
include(3rdparty/Utf8Main/utf8main.cmake)

if(NOT WIN32 AND PKG_CONFIG_FOUND)
set(USE_RTMIDI TRUE)
option(USE_SYSTEM_RTMIDI "Use system libraries for RtMidi" OFF)
set(USE_PORTMIDI TRUE)
option(USE_SYSTEM_PORTMIDI "Use system libraries for PortMidi" OFF)
endif()

find_package(SDL2 REQUIRED)

if(USE_RTMIDI)
if(USE_SYSTEM_RTMIDI)
pkg_check_modules(SYSTEM_RTMIDI rtmidi REQUIRED)
else()
include(RtMidi)
endif()
if(USE_PORTMIDI)
add_subdirectory(3rdparty/portmidi)
endif()


Expand All @@ -200,8 +196,8 @@ set(SC55_SRC
src/utils/files.cpp src/utils/files.h
)

if(USE_RTMIDI)
list(APPEND SC55_SRC src/midi_rtmidi.cpp)
if(USE_PORTMIDI)
list(APPEND SC55_SRC src/midi_portmidi.cpp)
elseif(WIN32)
list(APPEND SC55_SRC src/midi_win32.cpp)
endif()
Expand All @@ -217,14 +213,8 @@ else()
target_link_libraries(nuked-sc55 PRIVATE ${SDL2_LIBRARIES})
endif()

if(USE_RTMIDI)
if(USE_SYSTEM_RTMIDI)
target_compile_options(nuked-sc55 PRIVATE ${SYSTEM_RTMIDI_CFLAGS})
target_include_directories(nuked-sc55 PRIVATE ${SYSTEM_RTMIDI_INCLUDE_DIRS})
target_link_libraries(nuked-sc55 PRIVATE ${SYSTEM_RTMIDI_LIBRARIES})
else()
target_link_libraries(nuked-sc55 PRIVATE RtMidi)
endif()
if(USE_PORTMIDI)
target_link_libraries(nuked-sc55 PRIVATE portmidi)
endif()

if(WIN32)
Expand Down
15 changes: 0 additions & 15 deletions cmake/RtMidi.cmake

This file was deleted.

2 changes: 2 additions & 0 deletions src/mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ int SDLCALL work_thread(void* data)
SM_Update(mcu.cycles);

MCU_UpdateAnalog(mcu.cycles);

MIDI_Update();
}
MCU_WorkThread_Unlock();

Expand Down
1 change: 1 addition & 0 deletions src/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@

int MIDI_Init(void);
void MIDI_Quit(void);
void MIDI_Update(void);

67 changes: 67 additions & 0 deletions src/midi_portmidi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <stdio.h>
#include "mcu.h"
#include "submcu.h"
#include "midi.h"
#include <portmidi.h>

static PmStream *midiInStream;
static bool sysExMode = false;

void MIDI_Update()
{
PmEvent event;
while (Pm_Read(midiInStream, &event, 1)) {
uint8_t command = (Pm_MessageStatus(event.message) >> 4);

SM_PostUART(Pm_MessageStatus(event.message));

if (sysExMode && Pm_MessageStatus(event.message) == 0xF7) {
sysExMode = false;
} else if (sysExMode || Pm_MessageStatus(event.message) == 0xF0) {
sysExMode = true;
SM_PostUART(Pm_MessageData1(event.message));
if (Pm_MessageData1(event.message) == 0xF7) {
sysExMode = false;
return;
}
SM_PostUART(Pm_MessageData2(event.message));
if (Pm_MessageData2(event.message) == 0xF7) {
sysExMode = false;
return;
}
SM_PostUART((((event.message) >> 24) & 0xFF));
if ((((event.message) >> 24) & 0xFF) == 0xF7) {
sysExMode = false;
return;
}
} else if (command == 0xC || command == 0xD || Pm_MessageStatus(event.message) == 0xF3) {
SM_PostUART(Pm_MessageData1(event.message));
} else if (command == 0x8 || command == 0x9 || command == 0xA || command == 0xB || command == 0xE){
SM_PostUART(Pm_MessageData1(event.message));
SM_PostUART(Pm_MessageData2(event.message));
}
}
}

int MIDI_Init(void)
{
Pm_Initialize();

int in_id = Pm_CreateVirtualInput("Virtual SC55", NULL, NULL);

Pm_OpenInput(&midiInStream, in_id, NULL, 0, NULL, NULL);
Pm_SetFilter(midiInStream, PM_FILT_ACTIVE | PM_FILT_CLOCK);

// Empty the buffer, just in case anything got through
PmEvent receiveBuffer[1];
while (Pm_Poll(midiInStream)) {
Pm_Read(midiInStream, receiveBuffer, 1);
}

return 1;
}

void MIDI_Quit()
{
Pm_Terminate();
}
60 changes: 0 additions & 60 deletions src/midi_rtmidi.cpp

This file was deleted.

4 changes: 4 additions & 0 deletions src/midi_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,7 @@ void MIDI_Quit()
midi_handle = 0;
}
}

void MIDI_Update()
{
}

0 comments on commit 50e3208

Please sign in to comment.