logo

overlay

My own overlay for experimentations, use with caution, no support is provided
commit: 8b3fe0e64321e010c8b0746be5d0bb3f2623d105
parent: 5c9320cb2129e113314d2dd8f6920c5de74744f3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 31 May 2020 02:08:05 +0200

media-libs/portmidi: Import + add sndio

Diffstat:

Amedia-libs/portmidi/Manifest1+
Amedia-libs/portmidi/files/portmidi-217-cmake.patch332+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amedia-libs/portmidi/files/portmidi-217-pmsndio.c368+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amedia-libs/portmidi/files/portmidi-217-pmsndio.h5+++++
Amedia-libs/portmidi/files/portmidi-217-r4-python.patch49+++++++++++++++++++++++++++++++++++++++++++++++++
Amedia-libs/portmidi/files/portmidi-217-sndio.patch34++++++++++++++++++++++++++++++++++
Amedia-libs/portmidi/metadata.xml10++++++++++
Amedia-libs/portmidi/portmidi-217-r3.ebuild148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 947 insertions(+), 0 deletions(-)

diff --git a/media-libs/portmidi/Manifest b/media-libs/portmidi/Manifest @@ -0,0 +1 @@ +DIST portmidi-src-217.zip 1030830 BLAKE2B ab197c7f9a5c2b4d2740d56841459fbac97d510e4d12e5d0cd7cecc0ba6035929b6596140d42c575a9513862a66127d19253dbee1d3a7b7b84b69c88fec7fcae SHA512 d08d4d57429d26d292b5fe6868b7c7a32f2f1d2428f6695cd403a697e2d91629bd4380242ab2720e8f21c895bb75cb56b709fb663a20e8e623120e50bfc5d90b diff --git a/media-libs/portmidi/files/portmidi-217-cmake.patch b/media-libs/portmidi/files/portmidi-217-cmake.patch @@ -0,0 +1,332 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4919b78..9dc6e58 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,12 +9,11 @@ if(UNIX) + set(CMAKE_BUILD_TYPE Release CACHE STRING + "Semicolon-separate list of supported configuration types") + # set default directories but don't override cached values... +- set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CACHEFILE_DIR}/${CMAKE_BUILD_TYPE} ++ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + CACHE STRING "libraries go here") +- set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CACHEFILE_DIR}/${CMAKE_BUILD_TYPE} ++ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + CACHE STRING "libraries go here") +- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY +- ${CMAKE_CACHEFILE_DIR}/${CMAKE_BUILD_TYPE} ++ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + CACHE STRING "executables go here") + + else(UNIX) +@@ -68,10 +67,20 @@ endif(UNIX) + include_directories(pm_common porttime) + add_subdirectory(pm_common) + +-add_subdirectory(pm_test) ++option(PORTMIDI_ENABLE_JAVA "Enable Java bindings support" ON) ++option(PORTMIDI_ENABLE_STATIC "Build and install static libraries" OFF) ++option(PORTMIDI_ENABLE_TEST "Build test programs" ON) ++ ++if(PORTMIDI_ENABLE_TEST) ++ add_subdirectory(pm_test) ++endif(PORTMIDI_ENABLE_TEST) + + add_subdirectory(pm_dylib) + + # Cannot figure out how to make an xcode Java application with CMake +-add_subdirectory(pm_java) ++if(PORTMIDI_ENABLE_JAVA) ++ set(JAR_INSTALL_DIR share/java ++ CACHE STRING "Define directory name for jar installation") ++ add_subdirectory(pm_java) ++endif(PORTMIDI_ENABLE_JAVA) + +diff --git a/pm_common/CMakeLists.txt b/pm_common/CMakeLists.txt +index e171047..d23442d 100644 +--- a/pm_common/CMakeLists.txt ++++ b/pm_common/CMakeLists.txt +@@ -44,9 +44,6 @@ set(CMAKE_C_FLAGS_RELEASE "${DEFAULT_RELEASE_FLAGS} ${LINUX_FLAGS}" + + # first include the appropriate system-dependent file: + if(UNIX) +- # add the -g switch for Linux and Mac OS X (not used in Win32) +- set (CMAKE_C_FLAGS_DEBUG "-g ${CMAKE_C_FLAGS_DEBUG}" +- CACHE STRING "enable extra checks for debugging" FORCE) + if(APPLE) + set(MACSRC pmmacosxcm pmmac readbinaryplist finddefault) + prepend_path(LIBSRC ../pm_mac/ ${MACSRC}) +@@ -62,19 +59,23 @@ if(UNIX) + ${COREMIDI_LIB} ${CORESERVICES_LIB} + CACHE INTERNAL "") + +- set(JAVAVM_LIB "${FRAMEWORK_PATH}/JavaVM.framework") +- set(JAVA_INCLUDE_PATHS ${JAVAVM_LIB}/Headers) ++ if(PORTMIDI_ENABLE_JAVA) ++ set(JAVAVM_LIB "${FRAMEWORK_PATH}/JavaVM.framework") ++ set(JAVA_INCLUDE_PATHS ${JAVAVM_LIB}/Headers) ++ endif(PORTMIDI_ENABLE_JAVA) + message(STATUS "SYSROOT: " ${CMAKE_OSX_SYSROOT}) + else(APPLE) + # LINUX settings... +- include(FindJNI) +- message(STATUS "JAVA_JVM_LIB_PATH is " ${JAVA_JVM_LIB_PATH}) +- message(STATUS "JAVA_INCLUDE_PATH is " ${JAVA_INCLUDE_PATH}) +- message(STATUS "JAVA_INCLUDE_PATH2 is " ${JAVA_INCLUDE_PATH2}) +- message(STATUS "JAVA_JVM_LIBRARY is " ${JAVA_JVM_LIBRARY}) +- set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) +- # libjvm.so is found relative to JAVA_INCLUDE_PATH: +- set(JAVAVM_LIB ${JAVA_JVM_LIBRARY}/libjvm.so) ++ if(PORTMIDI_ENABLE_JAVA) ++ include(FindJNI) ++ message(STATUS "JAVA_JVM_LIB_PATH is " ${JAVA_JVM_LIB_PATH}) ++ message(STATUS "JAVA_INCLUDE_PATH is " ${JAVA_INCLUDE_PATH}) ++ message(STATUS "JAVA_INCLUDE_PATH2 is " ${JAVA_INCLUDE_PATH2}) ++ message(STATUS "JAVA_JVM_LIBRARY is " ${JAVA_JVM_LIBRARY}) ++ set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) ++ # libjvm.so is found relative to JAVA_INCLUDE_PATH: ++ set(JAVAVM_LIB ${JAVA_JVM_LIBRARY}/libjvm.so) ++ endif(PORTMIDI_ENABLE_JAVA) + + set(LINUXSRC pmlinuxalsa pmlinux finddefault) + prepend_path(LIBSRC ../pm_linux/ ${LINUXSRC}) +@@ -88,10 +89,12 @@ else(UNIX) + # /MD is multithread DLL, /MT is multithread. Change to static: + include(../pm_win/static.cmake) + +- include(FindJNI) ++ if(PORTMIDI_ENABLE_JAVA) ++ include(FindJNI) + +- set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) +- # message(STATUS "JAVA_INCLUDE_PATHS: " ${JAVA_INCLUDE_PATHS}) ++ set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) ++ # message(STATUS "JAVA_INCLUDE_PATHS: " ${JAVA_INCLUDE_PATHS}) ++ endif(PORTMIDI_ENABLE_JAVA) + + set(WINSRC pmwin pmwinmm) + prepend_path(LIBSRC ../pm_win/ ${WINSRC}) +@@ -99,29 +102,43 @@ else(UNIX) + set(PM_NEEDED_LIBS winmm.lib) + endif(WIN32) + endif(UNIX) +-set(JNI_EXTRA_LIBS ${PM_NEEDED_LIBS} ${JAVA_JVM_LIBRARY}) ++ ++if(PORTMIDI_ENABLE_JAVA) ++ set(JNI_EXTRA_LIBS ${PM_NEEDED_LIBS} ${JAVA_JVM_LIBRARY}) ++endif(PORTMIDI_ENABLE_JAVA) + + # this completes the list of library sources by adding shared code + list(APPEND LIBSRC pmutil portmidi) + + # now add the shared files to make the complete list of library sources +-add_library(portmidi-static ${LIBSRC}) +-set_target_properties(portmidi-static PROPERTIES OUTPUT_NAME "portmidi_s") +-target_link_libraries(portmidi-static ${PM_NEEDED_LIBS}) +- +-# define the jni library +-include_directories(${JAVA_INCLUDE_PATHS}) +- +-set(JNISRC ${LIBSRC} ../pm_java/pmjni/pmjni.c) +-add_library(pmjni SHARED ${JNISRC}) +-target_link_libraries(pmjni ${JNI_EXTRA_LIBS}) +-set_target_properties(pmjni PROPERTIES EXECUTABLE_EXTENSION "jnilib") ++if(PORTMIDI_ENABLE_STATIC) ++ add_library(portmidi-static ${LIBSRC}) ++ set_target_properties(portmidi-static PROPERTIES OUTPUT_NAME "portmidi") ++ target_link_libraries(portmidi-static ${PM_NEEDED_LIBS}) ++endif(PORTMIDI_ENABLE_STATIC) ++ ++if(PORTMIDI_ENABLE_JAVA) ++ # define the jni library ++ include_directories(${JAVA_INCLUDE_PATHS}) ++ ++ set(JNISRC ${LIBSRC} ../pm_java/pmjni/pmjni.c) ++ add_library(pmjni SHARED ${JNISRC}) ++ target_link_libraries(pmjni ${JNI_EXTRA_LIBS}) ++ set_target_properties(pmjni PROPERTIES EXECUTABLE_EXTENSION "jnilib") ++endif(PORTMIDI_ENABLE_JAVA) + + # install the libraries (Linux and Mac OS X command line) + if(UNIX) +- INSTALL(TARGETS portmidi-static pmjni +- LIBRARY DESTINATION /usr/local/lib +- ARCHIVE DESTINATION /usr/local/lib) ++ if(PORTMIDI_ENABLE_STATIC) ++ INSTALL(TARGETS portmidi-static ++ LIBRARY DESTINATION lib${LIB_SUFFIX} ++ ARCHIVE DESTINATION lib${LIB_SUFFIX}) ++ endif(PORTMIDI_ENABLE_STATIC) ++ if(PORTMIDI_ENABLE_JAVA) ++ INSTALL(TARGETS pmjni ++ LIBRARY DESTINATION lib${LIB_SUFFIX} ++ ARCHIVE DESTINATION lib${LIB_SUFFIX}) ++ endif(PORTMIDI_ENABLE_JAVA) + # .h files installed by pm_dylib/CMakeLists.txt, so don't need them here + # INSTALL(FILES portmidi.h ../porttime/porttime.h + # DESTINATION /usr/local/include) +diff --git a/pm_dylib/CMakeLists.txt b/pm_dylib/CMakeLists.txt +index f693dd6..c0e1449 100644 +--- a/pm_dylib/CMakeLists.txt ++++ b/pm_dylib/CMakeLists.txt +@@ -39,9 +39,6 @@ set(CMAKE_C_FLAGS_RELEASE "${DEFAULT_RELEASE_FLAGS} ${LINUX_FLAGS}" + + # first include the appropriate system-dependent file: + if(UNIX) +- # add the -g switch for Linux and Mac OS X (not used in Win32) +- set (CMAKE_C_FLAGS_DEBUG "-g ${CMAKE_C_FLAGS_DEBUG}" +- CACHE STRING "enable extra checks for debugging" FORCE) + if(APPLE) + set(MACSRC pmmacosxcm pmmac readbinaryplist finddefault) + prepend_path(LIBSRC ../pm_mac/ ${MACSRC}) +@@ -63,7 +60,8 @@ if(UNIX) + message(STATUS "SYSROOT: " ${CMAKE_OSX_SYSROOT}) + else(APPLE) + # LINUX settings... +- include(FindJNI) ++ if(PORTMIDI_ENABLE_JAVA) ++ include(FindJNI) + # message(STATUS "JAVA_JVM_LIB_PATH is " ${JAVA_JVM_LIB_PATH}) + # message(STATUS "JAVA_INCLUDE_PATH is " ${JAVA_INCLUDE_PATH}) + # note: should use JAVA_JVM_LIB_PATH, but it is not set properly +@@ -75,11 +73,8 @@ if(UNIX) + # JAVA_INCLUDE_PATH2; if no, then we need to make both JAVA_INCLUDE_PATH + # and JAVA_INCLUDE_PATH2 set by user (will need clear documentation + # because JAVA_INCLUDE_PATH2 is pretty obscure) +- set(JAVA_INCLUDE_PATH ${JAVA_INCLUDE_PATH-UNKNOWN} +- CACHE STRING "where to find Java SDK include directory") +- set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH}/linux) +- # libjvm.so is found relative to JAVA_INCLUDE_PATH: +- set(JAVAVM_LIB ${JAVA_INCLUDE_PATH}/../jre/lib/i386/client/libjvm.so) ++ set(JAVAVM_LIB ${JAVA_JVM_LIBRARY}) ++ endif(PORTMIDI_ENABLE_JAVA) + + set(LINUXSRC pmlinuxalsa pmlinux finddefault) + prepend_path(LIBSRC ../pm_linux/ ${LINUXSRC}) +@@ -91,13 +86,15 @@ else(UNIX) + if(WIN32) + # /MDd is multithread debug DLL, /MTd is multithread debug + # /MD is multithread DLL, /MT is multithread +- +- include(FindJNI) +- # note: should use JAVA_JVM_LIB_PATH, but it is not set properly +- set(JAVAVM_LIB ${JAVA_INCLUDE_PATH}/../lib/jvm.lib) + +- set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) +- # message(STATUS "JAVA_INCLUDE_PATHS: " ${JAVA_INCLUDE_PATHS}) ++ if(PORTMIDI_ENABLE_JAVA) ++ include(FindJNI) ++ # note: should use JAVA_JVM_LIB_PATH, but it is not set properly ++ set(JAVAVM_LIB ${JAVA_INCLUDE_PATH}/../lib/jvm.lib) ++ ++ set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) ++ # message(STATUS "JAVA_INCLUDE_PATHS: " ${JAVA_INCLUDE_PATHS}) ++ endif(PORTMIDI_ENABLE_JAVA) + + set(WINSRC pmwin pmwinmm) + prepend_path(LIBSRC ../pm_win/ ${WINSRC}) +@@ -106,7 +103,10 @@ else(UNIX) + # message(STATUS "JAVAVM_LIB: " ${JAVAVM_LIB}) + endif(WIN32) + endif(UNIX) ++ ++if(PORTMIDI_ENABLE_JAVA) + set(JNI_EXTRA_LIBS ${PM_NEEDED_LIBS} ${JAVAVM_LIB}) ++endif(PORTMIDI_ENABLE_JAVA) + + # this completes the list of library sources by adding shared code + set(SHARED_FILES pmutil portmidi) +@@ -120,8 +120,8 @@ target_link_libraries(portmidi-dynamic ${PM_NEEDED_LIBS}) + # install the libraries (Linux and Mac OS X command line) + if(UNIX) + INSTALL(TARGETS portmidi-dynamic +- LIBRARY DESTINATION /usr/local/lib +- ARCHIVE DESTINATION /usr/local/lib) ++ LIBRARY DESTINATION lib${LIB_SUFFIX} ++ ARCHIVE DESTINATION lib${LIB_SUFFIX}) + INSTALL(FILES ../pm_common/portmidi.h ../porttime/porttime.h +- DESTINATION /usr/local/include) ++ DESTINATION include) + endif(UNIX) +diff --git a/pm_java/CMakeLists.txt b/pm_java/CMakeLists.txt +index a350620..9cbee1c 100644 +--- a/pm_java/CMakeLists.txt ++++ b/pm_java/CMakeLists.txt +@@ -5,43 +5,24 @@ if(UNIX) + # java not dealt with in CMake -- see pm_mac/pm_mac.xcodeproj + else(APPLE) + # linux +- set(JPORTMIDICLASS JPortMidi.class JPortMidiException.class +- JPortMidiApi.class) +- set(PMDEFAULTSCLASS PmDefaultsFrame.class PmDefaults.class) +- prepend_path(JPORTMIDICLASS2 jportmidi/ ${JPORTMIDICLASS}) +- prepend_path(PMDEFAULTSCLASS2 pmdefaults/ ${PMDEFAULTSCLASS}) +- set(PMDEFAULTS_ALL_CLASSES ${JPORTMIDICLASS2} ${PMDEFAULTSCLASS2}) +- # message(STATUS "PMDEFAULTS_ALL_CLASSES is " ${PMDEFAULTS_ALL_CLASSES}) +- add_custom_command(OUTPUT pmdefaults/PmDefaultsFrame.class +- COMMAND javac -classpath . pmdefaults/PmDefaultsFrame.java +- MAIN_DEPENDENCY pmdefaults/PmDefaultsFrame.java +- DEPENDS pmdefaults/PmDefaults.java +- WORKING_DIRECTORY pm_java) +- add_custom_command(OUTPUT pmdefaults/PmDefaults.class +- COMMAND javac -classpath . pmdefaults/PmDefaults.java +- MAIN_DEPENDENCY pmdefaults/PmDefaults.java +- DEPENDS pmdefaults/PmDefaultsFrame.java +- WORKING_DIRECTORY pm_java) +- add_custom_command(OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pmdefaults.jar +- COMMAND cp pmdefaults/portmusic_logo.png . +- COMMAND jar cmf pmdefaults/manifest.txt pmdefaults.jar +- pmdefaults/*.class portmusic_logo.png jportmidi/*.class +- COMMAND chmod +x pmdefaults/pmdefaults +- COMMAND cp pmdefaults/pmdefaults ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} +- COMMAND mv pmdefaults.jar ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} +- COMMAND rm portmusic_logo.png +- MAIN_DEPENDENCY pmdefaults/PmDefaults.class +- DEPENDS ${PMDEFAULTS_ALL_CLASSES} +- WORKING_DIRECTORY pm_java) +- add_custom_target(pmdefaults_target ALL +- DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pmdefaults.jar) +- # message(STATUS "add_custom_target: pmdefaults.jar") ++ set(JAVA_CLASSES jportmidi pmdefaults) ++ add_custom_command(OUTPUT ${JAVA_CLASSES} ++ COMMAND javac -d ${CMAKE_CURRENT_BINARY_DIR} jportmidi/*.java pmdefaults/*.java ++ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ++ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pmdefaults.jar ++ DEPENDS ${JAVA_CLASSES} ++ COMMAND jar cmf pmdefaults/manifest.txt ${CMAKE_CURRENT_BINARY_DIR}/pmdefaults.jar ++ -C pmdefaults portmusic_logo.png -C ${CMAKE_CURRENT_BINARY_DIR} jportmidi ++ -C ${CMAKE_CURRENT_BINARY_DIR} pmdefaults ++ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ++ add_custom_target(pmdefaults.jar ALL ++ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pmdefaults.jar) + + # install the libraries (Linux only) +- INSTALL(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pmdefaults.jar +- DESTINATION /usr/share/java) +- INSTALL(PROGRAMS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pmdefaults +- DESTINATION /usr/local/bin) ++ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/pmdefaults.jar ++ DESTINATION ${JAR_INSTALL_DIR}) ++ INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/pmdefaults/pmdefaults ++ DESTINATION bin) + endif(APPLE) + endif(UNIX) + # In windows, use pm_java/make.bat +diff --git a/pm_test/CMakeLists.txt b/pm_test/CMakeLists.txt +index b89074b..236ff49 100644 +--- a/pm_test/CMakeLists.txt ++++ b/pm_test/CMakeLists.txt +@@ -10,10 +10,12 @@ if(WIN32) + include(../pm_win/static.cmake) + endif(WIN32) + ++set(CMAKE_SKIP_BUILD_RPATH TRUE) ++ + macro(make_a_test name) + add_executable(${name} ${name}.c) +- target_link_libraries(${name} portmidi-static ${PM_NEEDED_LIBS}) +- add_dependencies(${name} portmidi-static) ++ target_link_libraries(${name} portmidi-dynamic ${PM_NEEDED_LIBS}) ++ add_dependencies(${name} portmidi-dynamic) + endmacro(make_a_test) + + make_a_test(test) diff --git a/media-libs/portmidi/files/portmidi-217-pmsndio.c b/media-libs/portmidi/files/portmidi-217-pmsndio.c @@ -0,0 +1,368 @@ +/* pmsndio.c -- PortMidi os-dependent code */ + +#include <stdlib.h> +#include <stdio.h> +#include <sndio.h> +#include <string.h> +#include <poll.h> +#include <errno.h> +#include <pthread.h> +#include "portmidi.h" +#include "pmutil.h" +#include "pminternal.h" +#include "porttime.h" + +#define NDEVS 9 +#define SYSEX_MAXLEN 1024 + +#define SYSEX_START 0xf0 +#define SYSEX_END 0xf7 + +PmDeviceID pm_default_input_device_id = -1; +PmDeviceID pm_default_output_device_id = -1; + +extern pm_fns_node pm_sndio_in_dictionary; +extern pm_fns_node pm_sndio_out_dictionary; + +/* length of voice and common messages (status byte included) */ +unsigned int voice_len[] = { 3, 3, 3, 3, 2, 2, 3 }; +unsigned int common_len[] = { 0, 2, 3, 2, 0, 0, 1, 1 }; + +struct mio_dev { + char name[16]; + struct mio_hdl *hdl; + int mode; + char errmsg[PM_HOST_ERROR_MSG_LEN]; + pthread_t thread; +} devs[NDEVS]; + +static void set_mode(struct mio_dev *, unsigned int); + +void pm_init() +{ + int i, j, k = 0; + char devices[][16] = {"midithru", "rmidi", "midi", "snd"}; + + /* default */ + strcpy(devs[0].name, MIO_PORTANY); + pm_add_device("SNDIO", devs[k].name, TRUE, (void *) &devs[k], + &pm_sndio_in_dictionary); + pm_add_device("SNDIO", devs[k].name, FALSE, (void *) &devs[k], + &pm_sndio_out_dictionary); + k++; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 2; j++) { + sprintf(devs[k].name, "%s/%d", devices[i], j); + pm_add_device("SNDIO", devs[k].name, TRUE, (void *) &devs[k], + &pm_sndio_in_dictionary); + pm_add_device("SNDIO", devs[k].name, FALSE, (void *) &devs[k], + &pm_sndio_out_dictionary); + k++; + } + } + + // this is set when we return to Pm_Initialize, but we need it + // now in order to (successfully) call Pm_CountDevices() + pm_initialized = TRUE; + pm_default_input_device_id = 0; + pm_default_output_device_id = 1; +} + +void pm_term(void) +{ + int i; + for(i = 0; i < NDEVS; i++) { + if (devs[i].mode != 0) { + set_mode(&devs[i], 0); + if (devs[i].thread) { + pthread_join(devs[i].thread, NULL); + devs[i].thread = NULL; + } + } + } +} + +PmDeviceID Pm_GetDefaultInputDeviceID() { + Pm_Initialize(); + return pm_default_input_device_id; +} + +PmDeviceID Pm_GetDefaultOutputDeviceID() { + Pm_Initialize(); + return pm_default_output_device_id; +} + +void *pm_alloc(size_t s) { return malloc(s); } + +void pm_free(void *ptr) { free(ptr); } + +/* midi_message_length -- how many bytes in a message? */ +static int midi_message_length(PmMessage message) +{ + unsigned char st = message & 0xff; + if (st >= 0xf8) + return 1; + else if (st >= 0xf0) + return common_len[st & 7]; + else if (st >= 0x80) + return voice_len[(st >> 4) & 7]; + else + return 0; +} + +void* input_thread(void *param) +{ + PmInternal *midi = (PmInternal*)param; + struct mio_dev *dev = (struct mio_dev *) midi->descriptor; + struct pollfd pfd[1]; + nfds_t nfds; + unsigned char st = 0, c = 0; + int rc, revents, idx = 0, len = 0; + size_t todo = 0; + unsigned char buf[0x200], *p; + PmEvent pm_ev, pm_ev_rt; + unsigned char sysex_data[SYSEX_MAXLEN]; + + while(dev->mode & MIO_IN) { + if (todo == 0) { + nfds = mio_pollfd(dev->hdl, pfd, POLLIN); + rc = poll(pfd, nfds, 100); + if (rc < 0) { + if (errno == EINTR) + continue; + break; + } + revents = mio_revents(dev->hdl, pfd); + if (!(revents & POLLIN)) + continue; + + todo = mio_read(dev->hdl, buf, sizeof(buf)); + if (todo == 0) + continue; + p = buf; + } + c = *p++; + todo--; + + if (c >= 0xf8) { + pm_ev_rt.message = c; + pm_ev_rt.timestamp = Pt_Time(); + pm_read_short(midi, &pm_ev_rt); + } else if (c == SYSEX_END) { + if (st == SYSEX_START) { + sysex_data[idx++] = c; + pm_read_bytes(midi, sysex_data, idx, Pt_Time()); + } + st = 0; + idx = 0; + } else if (c == SYSEX_START) { + st = c; + idx = 0; + sysex_data[idx++] = c; + } else if (c >= 0xf0) { + pm_ev.message = c; + len = common_len[c & 7]; + st = c; + idx = 1; + } else if (c >= 0x80) { + pm_ev.message = c; + len = voice_len[(c >> 4) & 7]; + st = c; + idx = 1; + } else if (st == SYSEX_START) { + if (idx == SYSEX_MAXLEN) { + fprintf(stderr, "the message is too long\n"); + idx = st = 0; + } else { + sysex_data[idx++] = c; + } + } else if (st) { + if (idx == 0 && st != SYSEX_START) + pm_ev.message |= (c << (8 * idx++)); + pm_ev.message |= (c << (8 * idx++)); + if (idx == len) { + pm_read_short(midi, &pm_ev); + if (st >= 0xf0) + st = 0; + idx = 0; + } + } + } + + pthread_exit(NULL); + return NULL; +} + +static void set_mode(struct mio_dev *dev, unsigned int mode) { + if (dev->mode != 0) + mio_close(dev->hdl); + dev->mode = 0; + if (mode != 0) + dev->hdl = mio_open(dev->name, mode, 0); + if (dev->hdl) + dev->mode = mode; +} + +static PmError sndio_out_open(PmInternal *midi, void *driverInfo) +{ + descriptor_type desc = &descriptors[midi->device_id]; + struct mio_dev *dev = (struct mio_dev *) desc->descriptor; + + if (dev->mode & MIO_OUT) + return pmNoError; + + set_mode(dev, dev->mode | MIO_OUT); + if (!(dev->mode & MIO_OUT)) { + snprintf(dev->errmsg, PM_HOST_ERROR_MSG_LEN, + "mio_open (output) failed: %s\n", dev->name); + return pmHostError; + } + + midi->descriptor = (void *)dev; + return pmNoError; +} + +static PmError sndio_in_open(PmInternal *midi, void *driverInfo) +{ + descriptor_type desc = &descriptors[midi->device_id]; + struct mio_dev *dev = (struct mio_dev *) desc->descriptor; + + if (dev->mode & MIO_IN) + return pmNoError; + + set_mode(dev, dev->mode | MIO_IN); + if (!(dev->mode & MIO_IN)) { + snprintf(dev->errmsg, PM_HOST_ERROR_MSG_LEN, + "mio_open (input) failed: %s\n", dev->name); + return pmHostError; + } + midi->descriptor = (void *)dev; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_create(&dev->thread, &attr, input_thread, ( void* )midi); + return pmNoError; +} + +static PmError sndio_out_close(PmInternal *midi) +{ + struct mio_dev *dev = (struct mio_dev *) midi->descriptor; + + if (dev->mode & MIO_OUT) + set_mode(dev, dev->mode & ~MIO_OUT); + return pmNoError; +} + +static PmError sndio_in_close(PmInternal *midi) +{ + struct mio_dev *dev = (struct mio_dev *) midi->descriptor; + + if (dev->mode & MIO_IN) { + set_mode(dev, dev->mode & ~MIO_IN); + pthread_join(dev->thread, NULL); + dev->thread = NULL; + } + return pmNoError; +} + +static PmError sndio_abort(PmInternal *midi) +{ + return pmNoError; +} + +static PmTimestamp sndio_synchronize(PmInternal *midi) +{ + return 0; +} + +static PmError do_write(struct mio_dev *dev, const void *addr, size_t nbytes) +{ + size_t w = mio_write(dev->hdl, addr, nbytes); + + if (w != nbytes) { + snprintf(dev->errmsg, PM_HOST_ERROR_MSG_LEN, + "mio_write failed, bytes written:%zu\n", w); + return pmHostError; + } + return pmNoError; +} + +static PmError sndio_write_byte(PmInternal *midi, unsigned char byte, + PmTimestamp timestamp) +{ + struct mio_dev *dev = (struct mio_dev *) midi->descriptor; + + return do_write(dev, &byte, 1); +} + +static PmError sndio_write_short(PmInternal *midi, PmEvent *event) +{ + struct mio_dev *dev = (struct mio_dev *) midi->descriptor; + int nbytes = midi_message_length(event->message); + + if (midi->latency > 0) { + /* XXX the event should be queued for later playback */ + return do_write(dev, &event->message, nbytes); + } else { + return do_write(dev, &event->message, nbytes); + } + return pmNoError; +} + +static PmError sndio_write_flush(PmInternal *midi, PmTimestamp timestamp) +{ + return pmNoError; +} + +PmError sndio_sysex(PmInternal *midi, PmTimestamp timestamp) +{ + return pmNoError; +} + +static unsigned int sndio_has_host_error(PmInternal *midi) +{ + struct mio_dev *dev = (struct mio_dev *) midi->descriptor; + + return (dev->errmsg[0] != '\0'); +} + +static void sndio_get_host_error(PmInternal *midi, char *msg, unsigned int len) +{ + struct mio_dev *dev = (struct mio_dev *) midi->descriptor; + + strlcpy(msg, dev->errmsg, len); + dev->errmsg[0] = '\0'; +} + +pm_fns_node pm_sndio_in_dictionary = { + none_write_short, + none_sysex, + none_sysex, + none_write_byte, + none_write_short, + none_write_flush, + sndio_synchronize, + sndio_in_open, + sndio_abort, + sndio_in_close, + success_poll, + sndio_has_host_error, + sndio_get_host_error +}; + +pm_fns_node pm_sndio_out_dictionary = { + sndio_write_short, + sndio_sysex, + sndio_sysex, + sndio_write_byte, + sndio_write_short, + sndio_write_flush, + sndio_synchronize, + sndio_out_open, + sndio_abort, + sndio_out_close, + none_poll, + sndio_has_host_error, + sndio_get_host_error +}; + diff --git a/media-libs/portmidi/files/portmidi-217-pmsndio.h b/media-libs/portmidi/files/portmidi-217-pmsndio.h @@ -0,0 +1,5 @@ +/* pmsndio.h */ + +extern PmDeviceID pm_default_input_device_id; +extern PmDeviceID pm_default_output_device_id; + diff --git a/media-libs/portmidi/files/portmidi-217-r4-python.patch b/media-libs/portmidi/files/portmidi-217-r4-python.patch @@ -0,0 +1,49 @@ +diff -Naur portmidi-a/pm_python/setup.py portmidi-b/pm_python/setup.py +--- portmidi-a/pm_python/setup.py 2010-09-26 15:32:44.000000000 -0400 ++++ portmidi-b/pm_python/setup.py 2020-03-19 12:34:34.398365103 -0400 +@@ -15,12 +15,10 @@ + + + DESCRIPTION = open('README_PYTHON.txt').read() +-CHANGES = open('CHANGES.txt').read() +-TODO = open('TODO.txt').read() + + EXTRAS = {} + +-long_description = DESCRIPTION + CHANGES + TODO ++long_description = DESCRIPTION + #import sys + #if "checkdocs" in sys.argv: + # print long_description +@@ -142,7 +140,7 @@ + + + if sys.platform == 'win32': +- print "Found Win32 platform" ++ print("Found Win32 platform") + EXTENSION = dict( + ext_modules=[ + Extension("pyportmidi._pyportmidi", [os.path.join("pyportmidi", "_pyportmidi.pyx")], +@@ -154,7 +152,7 @@ + ] + ) + elif sys.platform == 'darwin': +- print "Found darwin (OS X) platform" ++ print("Found darwin (OS X) platform") + library_dirs = ["/usr/local/lib"] + include_dirs = ["/usr/local/include"] + EXTENSION = dict( +@@ -169,11 +167,11 @@ + ] + ) + else: +- print "Assuming Linux platform" ++ print("Assuming Linux platform") + EXTENSION = dict( + ext_modules=[ + Extension("pyportmidi._pyportmidi", [os.path.join("pyportmidi", "_pyportmidi.pyx")], +- library_dirs=["./linux"], ++ include_dirs=["../pm_common", "../porttime"], + libraries = ["portmidi", "asound", "pthread"] + ) + ] diff --git a/media-libs/portmidi/files/portmidi-217-sndio.patch b/media-libs/portmidi/files/portmidi-217-sndio.patch @@ -0,0 +1,34 @@ +diff --git a/pm_common/CMakeLists.txt b/pm_common/CMakeLists.txt +index e171047..2f191f9 100644 +--- a/pm_common/CMakeLists.txt ++++ b/pm_common/CMakeLists.txt +@@ -78,9 +78,11 @@ if(UNIX) + + set(LINUXSRC pmlinuxalsa pmlinux finddefault) + prepend_path(LIBSRC ../pm_linux/ ${LINUXSRC}) ++ set(SNDIOSRC pmsndio) ++ prepend_path(LIBSRC ../pm_sndio/ ${SNDIOSRC}) + list(APPEND LIBSRC ../porttime/ptlinux) + +- set(PM_NEEDED_LIBS pthread asound) ++ set(PM_NEEDED_LIBS pthread asound sndio) + endif(APPLE) + else(UNIX) + if(WIN32) +diff --git a/pm_dylib/CMakeLists.txt b/pm_dylib/CMakeLists.txt +index f693dd6..aa57173 100644 +--- a/pm_dylib/CMakeLists.txt ++++ b/pm_dylib/CMakeLists.txt +@@ -83,9 +83,11 @@ if(UNIX) + + set(LINUXSRC pmlinuxalsa pmlinux finddefault) + prepend_path(LIBSRC ../pm_linux/ ${LINUXSRC}) ++ set(SNDIOSRC pmsndio) ++ prepend_path(LIBSRC ../pm_sndio/ ${SNDIOSRC}) + list(APPEND LIBSRC ../porttime/ptlinux) + +- set(PM_NEEDED_LIBS pthread asound) ++ set(PM_NEEDED_LIBS pthread asound sndio) + endif(APPLE) + else(UNIX) + if(WIN32) diff --git a/media-libs/portmidi/metadata.xml b/media-libs/portmidi/metadata.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> + <use> + <flag name="test-programs">Install various example programs</flag> + </use> + <upstream> + <remote-id type="sourceforge">portmedia</remote-id> + </upstream> +</pkgmetadata> diff --git a/media-libs/portmidi/portmidi-217-r3.ebuild b/media-libs/portmidi/portmidi-217-r3.ebuild @@ -0,0 +1,148 @@ +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +PYTHON_COMPAT=( python3_{6,7,8} ) +DISTUTILS_OPTIONAL=1 +# ninja: error: build.ninja:521: multiple rules generate pm_java/pmdefaults.jar [-w dupbuild=err] +CMAKE_MAKEFILE_GENERATOR="emake" +inherit cmake desktop xdg distutils-r1 java-pkg-opt-2 flag-o-matic + +DESCRIPTION="Library for real time MIDI input and output" +HOMEPAGE="http://portmedia.sourceforge.net/" +SRC_URI="mirror://sourceforge/portmedia/${PN}-src-${PV}.zip" + +LICENSE="MIT" +SLOT="0" +KEYWORDS="~alpha amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ppc ~ppc64 ~sparc x86" +IUSE="debug doc java python static-libs sndio test-programs" + +REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )" + +BDEPEND=" + app-arch/unzip + doc? ( + app-doc/doxygen + dev-texlive/texlive-fontsrecommended + dev-texlive/texlive-latexextra + virtual/latex-base + ) + python? ( >=dev-python/cython-0.12.1[${PYTHON_USEDEP}] ) +" +CDEPEND=" + media-libs/alsa-lib + sndio? ( media-sound/sndio:= ) + python? ( ${PYTHON_DEPS} ) +" +RDEPEND="${CDEPEND} + java? ( >=virtual/jre-1.8 ) +" +DEPEND=" + ${CDEPEND} + java? ( >=virtual/jdk-1.8 ) +" + +S="${WORKDIR}/${PN}" + +PATCHES=( + # fix parallel make failures, fix java support, and allow optional + # components like test programs and static libs to be skipped + "${FILESDIR}"/${P}-cmake.patch + + # add include directories and remove references to missing files + "${FILESDIR}"/${P}-r4-python.patch +) + +pkg_setup() { + use java && java-pkg-opt-2_pkg_setup +} + +src_prepare() { + cmake_src_prepare + + if use sndio + then + mkdir "${S}"/pm_sndio || die + cp "${FILESDIR}/${P}"-pmsndio.c "${S}"/pm_sndio/pmsndio.c || die + cp "${FILESDIR}/${P}"-pmsndio.h "${S}"/pm_sndio/pmsndio.h || die + eapply "${FILESDIR}/${P}"-sndio.patch + fi + + # install wrapper for pmdefaults + if use java ; then + cat > pm_java/pmdefaults/pmdefaults <<-EOF + #!/bin/sh + java -Djava.library.path="${EPREFIX}/usr/$(get_libdir)/" \\ + -jar "${EPREFIX}/usr/share/${PN}/lib/pmdefaults.jar" + EOF + [[ $? -ne 0 ]] && die "cat pmdefaults failed" + fi +} + +src_configure() { + if use debug ; then + CMAKE_BUILD_TYPE=Debug + else + CMAKE_BUILD_TYPE=Release + fi + + local mycmakeargs=( + -DPORTMIDI_ENABLE_JAVA=$(usex java) + -DPORTMIDI_ENABLE_STATIC=$(usex static-libs) + -DPORTMIDI_ENABLE_TEST=$(usex test-programs) + ) + + if use java ; then + mycmakeargs+=(-DJAR_INSTALL_DIR="${EPREFIX}/usr/share/${PN}/lib") + fi + + cmake_src_configure +} + +src_compile() { + cmake_src_compile + + if use python ; then + sed -i -e "/library_dirs=.*linux/s#./linux#${CMAKE_BUILD_DIR}#" pm_python/setup.py || die + pushd pm_python > /dev/null + append-ldflags -L"${BUILD_DIR}" + distutils-r1_src_compile + popd > /dev/null + fi + + if use doc ; then + doxygen || die "doxygen failed" + pushd latex > /dev/null + VARTEXFONTS="${T}"/fonts emake + popd > /dev/null + fi +} + +src_install() { + cmake_src_install + + dodoc CHANGELOG.txt README.txt pm_linux/README_LINUX.txt + + use doc && dodoc latex/refman.pdf + + if use python ; then + pushd pm_python > /dev/null + distutils-r1_src_install + popd > /dev/null + fi + + if use java ; then + newdoc pm_java/README.txt README_JAVA.txt + newicon pm_java/pmdefaults/pmdefaults-icon.png pmdefaults.png + make_desktop_entry pmdefaults Pmdefaults pmdefaults "AudioVideo;Audio;Midi;" + fi + + if use test-programs ; then + exeinto /usr/$(get_libdir)/${PN} + local app + for app in latency midiclock midithread midithru mm qtest sysex test ; do + doexe "${BUILD_DIR}"/${app} + done + fi +}