View | Details | Raw Unified | Return to bug 252188 | Differences between
and this patch

Collapse All | Expand All

(-)audio/pd/Makefile (-10 / +36 lines)
Lines 4-9 Link Here
4
PORTNAME=	pd
4
PORTNAME=	pd
5
DISTVERSION=	0.47-1
5
DISTVERSION=	0.47-1
6
DISTVERSIONSUFFIX=	.src
6
DISTVERSIONSUFFIX=	.src
7
PORTREVISION=	1
7
CATEGORIES=	audio
8
CATEGORIES=	audio
8
MASTER_SITES=	http://msp.ucsd.edu/Software/
9
MASTER_SITES=	http://msp.ucsd.edu/Software/
9
10
Lines 17-26 Link Here
17
RUN_DEPENDS=	xdg-open:devel/xdg-utils \
18
RUN_DEPENDS=	xdg-open:devel/xdg-utils \
18
		dejavu>0:x11-fonts/dejavu
19
		dejavu>0:x11-fonts/dejavu
19
20
21
USES=		autoreconf dos2unix gmake libtool pkgconfig shebangfix \
22
		tcl:wrapper tk:wrapper
23
20
WRKSRC=		${WRKDIR}/${DISTNAME:S,${DISTVERSIONSUFFIX},,}
24
WRKSRC=		${WRKDIR}/${DISTNAME:S,${DISTVERSIONSUFFIX},,}
21
25
22
USES=		autoreconf gettext gmake libtool pkgconfig shebangfix \
26
OPTIONS_DEFINE=		PORTMIDI ALSA DOCS JACK NLS
23
		tcl:wrapper tk:wrapper
27
OPTIONS_DEFAULT=	PORTMIDI NLS
28
29
NLS_USES=	gettext
30
31
ALSA_CONFIGURE_ENABLE=	alsa
32
ALSA_LIB_DEPENDS=	libasound.so:audio/alsa-lib
33
JACK_CONFIGURE_ENABLE=	jack
34
JACK_LIB_DEPENDS=	libjack.so:audio/jack
35
36
PORTMIDI_DESC=	Midi device support via portmidi and sndio
37
PORTMIDI_EXTRA_PATCHES=	${PATCHDIR}/extra-patch-configure.ac \
38
	${PATCHDIR}/extra-patch-portmidi_Makefile.am \
39
	${PATCHDIR}/extra-patch-portmidi_pm__common_CMakeLists.txt \
40
	${PATCHDIR}/extra-patch-portmidi_porttime_ptlinux.c \
41
	${PATCHDIR}/extra-patch-src_Makefile.am \
42
	${PATCHDIR}/extra-patch-src_s__midi__oss__pm.c
43
PORTMIDI_LIB_DEPENDS=	libsndio.so:audio/sndio
44
45
.include <bsd.port.options.mk>
46
47
.if ${PORT_OPTIONS:MPORTMIDI}
48
DOS2UNIX_FILES=	portmidi/porttime/ptlinux.c
49
.endif
24
SHEBANG_FILES=	tcl/pkg_mkIndex.tcl
50
SHEBANG_FILES=	tcl/pkg_mkIndex.tcl
25
SHEBANG_LANG=	tclsh
51
SHEBANG_LANG=	tclsh
26
tclsh_CMD=	${LOCALBASE}/bin/tclsh
52
tclsh_CMD=	${LOCALBASE}/bin/tclsh
Lines 29-44 Link Here
29
55
30
CPPFLAGS+=	-I${LOCALBASE}/include
56
CPPFLAGS+=	-I${LOCALBASE}/include
31
LDFLAGS+=	-L${LOCALBASE}/lib -pthread
57
LDFLAGS+=	-L${LOCALBASE}/lib -pthread
58
.if ${PORT_OPTIONS:MPORTMIDI}
59
LDFLAGS+=	-lsndio
60
.endif
32
61
33
DESKTOP_ENTRIES="Pd" "" "${PREFIX}/lib/pd/tcl/pd.ico" "pd" "" false
62
DESKTOP_ENTRIES="Pd" "" "${PREFIX}/lib/pd/tcl/pd.ico" "pd" "" ${FALSE}
34
63
35
OPTIONS_DEFINE=		ALSA DOCS JACK
64
post-extract:
36
OPTIONS_DEFAULT=	JACK
65
.if ${PORT_OPTIONS:MPORTMIDI}
37
66
	${CP} -pr ${FILESDIR}/portmidi/pm_sndio ${WRKSRC}/portmidi/
38
ALSA_CONFIGURE_ENABLE=	alsa
67
.endif
39
ALSA_LIB_DEPENDS=	libasound.so:audio/alsa-lib
40
JACK_CONFIGURE_ENABLE=	jack
41
JACK_LIB_DEPENDS=	libjack.so:audio/jack
42
68
43
post-patch:
69
post-patch:
44
	${FIND} ${PATCH_WRKSRC} -name "*.[ch]" | ${XARGS} ${REINPLACE_CMD} -e \
70
	${FIND} ${PATCH_WRKSRC} -name "*.[ch]" | ${XARGS} ${REINPLACE_CMD} -e \
(-)audio/pd/files/extra-patch-configure.ac (+10 lines)
Line 0 Link Here
1
--- configure.ac.orig	2016-06-18 15:02:47.000000000 -0700
2
+++ configure.ac	2020-07-06 19:37:37.638911000 -0700
3
@@ -38,6 +38,7 @@
4
 	if test "x${ANDROID}" = "xno"; then
5
 	 LINUX=yes
6
 	 portaudio=yes
7
+	 portmidi=yes
8
 	 CFLAGS="-g -O3 -funroll-loops -fomit-frame-pointer $CFLAGS"
9
 	fi
10
 	EXTERNAL_CFLAGS="-fPIC"
(-)audio/pd/files/extra-patch-portmidi_Makefile.am (+27 lines)
Line 0 Link Here
1
--- portmidi/Makefile.am.orig	2015-05-13 13:58:54.000000000 -0700
2
+++ portmidi/Makefile.am	2020-07-07 02:39:30.587648000 -0700
3
@@ -9,10 +9,9 @@
4
 libportmidi_la_SOURCES = pm_common/pmutil.c pm_common/portmidi.c
5
 
6
 if LINUX
7
-INCLUDES +=  -Ipm_linux
8
+INCLUDES +=  -Ipm_sndio
9
 libportmidi_la_SOURCES += porttime/ptlinux.c \
10
-		pm_linux/pmlinux.c \
11
-		pm_linux/pmlinuxalsa.c
12
+		pm_sndio/pmsndio.c
13
 endif
14
 
15
 if MACOSX
16
@@ -37,10 +36,5 @@
17
 	pm_common/pminternal.h \
18
 	pm_common/pmutil.h \
19
 	pm_common/portmidi.h \
20
-	pm_linux/pmlinux.h \
21
-	pm_linux/pmlinuxalsa.h \
22
-	pm_mac/pmmac.h \
23
-	pm_mac/pmmacosxcm.h \
24
-	pm_win/pmdll.h \
25
-	pm_win/pmwinmm.h \
26
+	pm_sndio/pmsndio.h \
27
 	porttime/porttime.h
(-)audio/pd/files/extra-patch-portmidi_pm__common_CMakeLists.txt (+54 lines)
Line 0 Link Here
1
--- portmidi/pm_common/CMakeLists.txt.orig	2010-09-20 19:57:48 UTC
2
+++ portmidi/pm_common/CMakeLists.txt
3
@@ -66,21 +66,12 @@ if(UNIX)
4
     set(JAVA_INCLUDE_PATHS ${JAVAVM_LIB}/Headers)
5
     message(STATUS "SYSROOT: " ${CMAKE_OSX_SYSROOT})
6
   else(APPLE)
7
-    # LINUX settings...
8
-    include(FindJNI)
9
-    message(STATUS "JAVA_JVM_LIB_PATH is " ${JAVA_JVM_LIB_PATH})
10
-    message(STATUS "JAVA_INCLUDE_PATH is " ${JAVA_INCLUDE_PATH})
11
-    message(STATUS "JAVA_INCLUDE_PATH2 is " ${JAVA_INCLUDE_PATH2})
12
-    message(STATUS "JAVA_JVM_LIBRARY is " ${JAVA_JVM_LIBRARY})
13
-    set(JAVA_INCLUDE_PATHS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
14
-    # libjvm.so is found relative to JAVA_INCLUDE_PATH:
15
-    set(JAVAVM_LIB ${JAVA_JVM_LIBRARY}/libjvm.so)
16
 
17
-    set(LINUXSRC pmlinuxalsa pmlinux finddefault)
18
-    prepend_path(LIBSRC ../pm_linux/ ${LINUXSRC})
19
+    set(LINUXSRC pmsndio)
20
+    prepend_path(LIBSRC ../pm_sndio/ ${LINUXSRC})
21
     list(APPEND LIBSRC ../porttime/ptlinux)
22
 
23
-    set(PM_NEEDED_LIBS pthread asound)
24
+    set(PM_NEEDED_LIBS pthread sndio)
25
   endif(APPLE)
26
 else(UNIX)
27
   if(WIN32)
28
@@ -99,7 +90,6 @@ else(UNIX)
29
     set(PM_NEEDED_LIBS winmm.lib)
30
   endif(WIN32)
31
 endif(UNIX)
32
-set(JNI_EXTRA_LIBS ${PM_NEEDED_LIBS} ${JAVA_JVM_LIBRARY})
33
 
34
 # this completes the list of library sources by adding shared code
35
 list(APPEND LIBSRC pmutil portmidi)
36
@@ -109,17 +99,10 @@ add_library(portmidi-static ${LIBSRC})
37
 set_target_properties(portmidi-static PROPERTIES OUTPUT_NAME "portmidi_s")
38
 target_link_libraries(portmidi-static ${PM_NEEDED_LIBS})
39
 
40
-# define the jni library
41
-include_directories(${JAVA_INCLUDE_PATHS})
42
 
43
-set(JNISRC ${LIBSRC} ../pm_java/pmjni/pmjni.c)
44
-add_library(pmjni SHARED ${JNISRC})
45
-target_link_libraries(pmjni ${JNI_EXTRA_LIBS})
46
-set_target_properties(pmjni PROPERTIES EXECUTABLE_EXTENSION "jnilib")
47
-
48
 # install the libraries (Linux and Mac OS X command line)
49
 if(UNIX)
50
-  INSTALL(TARGETS portmidi-static pmjni
51
+  INSTALL(TARGETS portmidi-static
52
     LIBRARY DESTINATION /usr/local/lib
53
     ARCHIVE DESTINATION /usr/local/lib)
54
 # .h files installed by pm_dylib/CMakeLists.txt, so don't need them here
(-)audio/pd/files/extra-patch-portmidi_porttime_ptlinux.c (+46 lines)
Line 0 Link Here
1
--- portmidi/porttime/ptlinux.c.orig	2020-07-07 04:53:18 UTC
2
+++ portmidi/porttime/ptlinux.c
3
@@ -31,14 +31,13 @@ CHANGE LOG
4
 #include "porttime.h"
5
 #include "sys/time.h"
6
 #include "sys/resource.h"
7
-#include "sys/timeb.h"
8
 #include "pthread.h"
9
 
10
 #define TRUE 1
11
 #define FALSE 0
12
 
13
 static int time_started_flag = FALSE;
14
-static struct timeb time_offset = {0, 0, 0, 0};
15
+static struct timespec time_offset = {0, 0};
16
 static pthread_t pt_thread_pid;
17
 static int pt_thread_created = FALSE;
18
 
19
@@ -79,7 +78,7 @@ static void *Pt_CallbackProc(void *p)
20
 PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
21
 {
22
     if (time_started_flag) return ptNoError;
23
-    ftime(&time_offset); /* need this set before process runs */
24
+    clock_gettime(CLOCK_MONOTONIC, &time_offset); /* need this set before process runs */
25
     if (callback) {
26
         int res;
27
         pt_callback_parameters *parms = (pt_callback_parameters *) 
28
@@ -120,12 +119,12 @@ int Pt_Started()
29
 
30
 PtTimestamp Pt_Time()
31
 {
32
-    long seconds, milliseconds;
33
-    struct timeb now;
34
-    ftime(&now);
35
-    seconds = now.time - time_offset.time;
36
-    milliseconds = now.millitm - time_offset.millitm;
37
-    return seconds * 1000 + milliseconds;
38
+    long seconds, nanoseconds;
39
+    struct timespec now;
40
+    clock_gettime(CLOCK_MONOTONIC, &now);
41
+    seconds = now.tv_sec - time_offset.tv_sec;
42
+    nanoseconds = now.tv_nsec - time_offset.tv_nsec;
43
+    return seconds * 1000 + nanoseconds / 1000000;
44
 }
45
 
46
 
(-)audio/pd/files/extra-patch-src_Makefile.am (+11 lines)
Line 0 Link Here
1
--- src/Makefile.am.orig	2016-04-03 04:55:23 UTC
2
+++ src/Makefile.am
3
@@ -81,7 +81,7 @@ endif
4
 if OSS
5
 if !WINDOWS
6
 pd_CFLAGS += -DUSEAPI_OSS
7
-pd_SOURCES += s_audio_oss.c s_midi_oss.c
8
+pd_SOURCES += s_audio_oss.c s_midi_oss_pm.c
9
 endif
10
 endif
11
 
(-)audio/pd/files/extra-patch-src_s__midi__oss__pm.c (+147 lines)
Line 0 Link Here
1
--- src/s_midi_oss_pm.c.orig	2020-07-07 04:07:26.811553000 -0700
2
+++ src/s_midi_oss_pm.c	2020-07-07 04:05:55.736126000 -0700
3
@@ -0,0 +1,144 @@
4
+/* Copyright (c) 1997-1999 Guenter Geiger, Miller Puckette, Larry Troxler,
5
+* Winfried Ritsch, Karl MacMillan, and others.
6
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
7
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
8
+
9
+/* MIDI I/O for Linux using OSS */
10
+
11
+#include <stdio.h>
12
+#ifdef HAVE_UNISTD_H
13
+#include <unistd.h>
14
+#endif
15
+#include <stdlib.h>
16
+#include <sys/types.h>
17
+#include <sys/stat.h>
18
+#include <fcntl.h>
19
+#include <errno.h>
20
+#include <string.h>
21
+#include "m_pd.h"
22
+#include "s_stuff.h"
23
+
24
+#define NSEARCH 10
25
+static int oss_nmidiindevs, oss_nmidioutdevs;
26
+static char oss_indevnames[NSEARCH][4], oss_outdevnames[NSEARCH][4];
27
+static int oss_nmidiin;
28
+static int oss_midiinfd[MAXMIDIINDEV];
29
+static int oss_nmidiout;
30
+static int oss_midioutfd[MAXMIDIOUTDEV];
31
+
32
+static void oss_midiout(int fd, int n)
33
+{
34
+    char b = n;
35
+    if ((write(fd, (char *) &b, 1)) != 1)
36
+        perror("midi write");
37
+}
38
+
39
+#define O_MIDIFLAG O_NDELAY
40
+
41
+#define md_msglen(x) (((x)<0xC0)?2:((x)<0xE0)?1:((x)<0xF0)?2:\
42
+    ((x)==0xF2)?2:((x)<0xF4)?1:0)
43
+
44
+
45
+#if 0   /* this is the "select" version which doesn't work with OSS
46
+        driver for emu10k1 (it doesn't implement select.) */
47
+#else
48
+
49
+    /* this version uses the asynchronous "read()" ... */
50
+void sys_poll_midi_oss_pm(void)
51
+{
52
+    int i, throttle = 100;
53
+    struct timeval timout;
54
+    int did = 1, maxfd = 0;
55
+    while (did)
56
+    {
57
+        fd_set readset, writeset, exceptset;
58
+        did = 0;
59
+        if (throttle-- < 0)
60
+            break;
61
+        for (i = 0; i < oss_nmidiin; i++)
62
+        {
63
+            char c;
64
+            int ret = read(oss_midiinfd[i], &c, 1);
65
+            if (ret < 0)
66
+            {
67
+                if (errno != EAGAIN)
68
+                    perror("MIDI");
69
+            }
70
+            else if (ret != 0)
71
+            {
72
+                sys_midibytein(i, (c & 0xff));
73
+                did = 1;
74
+            }
75
+        }
76
+    }
77
+}
78
+#endif
79
+
80
+void midi_oss_init(void)
81
+{
82
+    int fd, devno;
83
+    struct stat statbuf;
84
+    char namebuf[80];
85
+         /* we only try to detect devices before trying to open them, because
86
+         when they're open, they migth not be possible to reopen here */
87
+    static int initted = 0;
88
+    if (initted)
89
+        return;
90
+    initted = 1;
91
+    oss_nmidiindevs = oss_nmidioutdevs = 0;
92
+
93
+    for (devno = 0; devno < NSEARCH; devno++)
94
+    {
95
+        if (devno == 0)
96
+        {
97
+                /* try to open the device for reading */
98
+            fd = open("/dev/midi", O_RDONLY | O_NDELAY);
99
+            if (fd >= 0)
100
+            {
101
+                close(fd);
102
+                strcpy(oss_indevnames[oss_nmidiindevs++], "");
103
+            }
104
+            fd = open("/dev/midi", O_WRONLY | O_NDELAY);
105
+            if (fd >= 0)
106
+            {
107
+                close(fd);
108
+                strcpy(oss_outdevnames[oss_nmidioutdevs++], "");
109
+            }
110
+        }
111
+        if (oss_nmidiindevs >= NSEARCH || oss_nmidioutdevs >= NSEARCH)
112
+            break;
113
+
114
+        sprintf(namebuf, "/dev/midi%d", devno);
115
+        fd = open(namebuf, O_RDONLY | O_NDELAY);
116
+        if (fd >= 0)
117
+        {
118
+            close(fd);
119
+            sprintf(oss_indevnames[oss_nmidiindevs++], "%d", devno);
120
+        }
121
+        fd = open(namebuf, O_WRONLY | O_NDELAY);
122
+        if (fd >= 0)
123
+        {
124
+            close(fd);
125
+            sprintf(oss_outdevnames[oss_nmidioutdevs++], "%d", devno);
126
+        }
127
+        if (oss_nmidiindevs >= NSEARCH || oss_nmidioutdevs >= NSEARCH)
128
+            break;
129
+
130
+        sprintf(namebuf, "/dev/midi%2.2d", devno);
131
+        fd = open(namebuf, O_RDONLY | O_NDELAY);
132
+        if (fd >= 0)
133
+        {
134
+            close(fd);
135
+            sprintf(oss_indevnames[oss_nmidiindevs++], "%d", devno);
136
+        }
137
+        fd = open(namebuf, O_WRONLY | O_NDELAY);
138
+        if (fd >= 0)
139
+        {
140
+            close(fd);
141
+            sprintf(oss_outdevnames[oss_nmidioutdevs++], "%d", devno);
142
+        }
143
+        if (oss_nmidiindevs >= NSEARCH || oss_nmidioutdevs >= NSEARCH)
144
+            break;
145
+
146
+    }
147
+}
(-)audio/pd/files/portmidi/pm_sndio/pmsndio.c (+382 lines)
Line 0 Link Here
1
/* pmsndio.c -- PortMidi os-dependent code */
2
3
#include <stdlib.h>
4
#include <stdio.h>
5
#include <sndio.h>
6
#include <string.h>
7
#include <poll.h>
8
#include <errno.h>
9
#include <pthread.h>
10
#include <glob.h>
11
#include "portmidi.h"
12
#include "pmutil.h"
13
#include "pminternal.h"
14
#include "porttime.h"
15
16
#define NDEVS 1024
17
#define SYSEX_MAXLEN 1024
18
19
#define SYSEX_START     0xf0
20
#define SYSEX_END       0xf7
21
22
PmDeviceID pm_default_input_device_id = -1;
23
PmDeviceID pm_default_output_device_id = -1;
24
25
extern pm_fns_node pm_sndio_in_dictionary;
26
extern pm_fns_node pm_sndio_out_dictionary;
27
28
/* length of voice and common messages (status byte included) */
29
unsigned int voice_len[] = { 3, 3, 3, 3, 2, 2, 3 };
30
unsigned int common_len[] = { 0, 2, 3, 2, 0, 0, 1, 1 };
31
32
struct mio_dev {
33
    char name[16];
34
    struct mio_hdl *hdl;
35
    int mode;
36
    char errmsg[PM_HOST_ERROR_MSG_LEN];
37
    pthread_t thread;
38
} devs[NDEVS];
39
40
static void set_mode(struct mio_dev *, unsigned int);
41
42
void pm_init()
43
{
44
    int i, j, k = 0;
45
    char devices[][16] = {"midithru", "rmidi", "midi", "snd"};
46
    glob_t out;
47
48
    /* default */
49
    strcpy(devs[0].name, MIO_PORTANY);
50
    pm_add_device("SNDIO", devs[k].name, TRUE, (void *) &devs[k],
51
        &pm_sndio_in_dictionary);
52
    pm_add_device("SNDIO", devs[k].name, FALSE, (void *) &devs[k],
53
        &pm_sndio_out_dictionary);
54
    k++;
55
56
    glob("/dev/umidi*.0", GLOB_TILDE, NULL, &out);
57
    int umidi_num_major_devs = out.gl_pathc;
58
    globfree(&out);
59
60
    for (i = 0; i < 4; i++) {
61
        for (j = 0; j < umidi_num_major_devs; j++) {
62
            sprintf(devs[k].name, "%s/%d", devices[i], j);
63
            pm_add_device("SNDIO", devs[k].name, TRUE, (void *) &devs[k],
64
              &pm_sndio_in_dictionary);
65
            pm_add_device("SNDIO", devs[k].name, FALSE, (void *) &devs[k],
66
              &pm_sndio_out_dictionary);
67
            k++;
68
        }
69
    }
70
71
    // this is set when we return to Pm_Initialize, but we need it
72
    // now in order to (successfully) call Pm_CountDevices()
73
    pm_initialized = TRUE;
74
    pm_default_input_device_id = 0;
75
    pm_default_output_device_id = 1;
76
}
77
78
void pm_term(void)
79
{
80
    int i;
81
    glob_t out;
82
83
    glob("/dev/umidi*.0", GLOB_TILDE, NULL, &out);
84
    int umidi_num_major_devs = out.gl_pathc;
85
    /* each device has matching midithru, rmidi, midi and snd devices */
86
    int ndevs = (umidi_num_major_devs * 4) + 1;
87
    globfree(&out);
88
89
    for(i = 0; i < ndevs; i++) {
90
        if (devs[i].mode != 0) {
91
            set_mode(&devs[i], 0);
92
            if (devs[i].thread) {
93
                pthread_join(devs[i].thread, NULL);
94
                devs[i].thread = NULL;
95
            }
96
        }
97
    }
98
}
99
100
PmDeviceID Pm_GetDefaultInputDeviceID() {
101
    Pm_Initialize();
102
    return pm_default_input_device_id; 
103
}
104
105
PmDeviceID Pm_GetDefaultOutputDeviceID() {
106
    Pm_Initialize();
107
    return pm_default_output_device_id;
108
}
109
110
void *pm_alloc(size_t s) { return malloc(s); }
111
112
void pm_free(void *ptr) { free(ptr); }
113
114
/* midi_message_length -- how many bytes in a message? */
115
static int midi_message_length(PmMessage message)
116
{
117
    unsigned char st = message & 0xff;
118
    if (st >= 0xf8)
119
	return 1;
120
    else if (st >= 0xf0)
121
        return common_len[st & 7];
122
    else if (st >= 0x80)
123
        return voice_len[(st >> 4) & 7];
124
    else 
125
        return 0;
126
}
127
128
void* input_thread(void *param)
129
{
130
    PmInternal *midi = (PmInternal*)param;
131
    struct mio_dev *dev = (struct mio_dev *) midi->descriptor;
132
    struct pollfd pfd[1];
133
    nfds_t nfds;
134
    unsigned char st = 0, c = 0;
135
    int rc, revents, idx = 0, len = 0;
136
    size_t todo = 0;
137
    unsigned char buf[0x200], *p;
138
    PmEvent pm_ev, pm_ev_rt;
139
    unsigned char sysex_data[SYSEX_MAXLEN];
140
141
    while(dev->mode & MIO_IN) {
142
        if (todo == 0) {
143
            nfds = mio_pollfd(dev->hdl, pfd, POLLIN);
144
            rc = poll(pfd, nfds, 100);
145
            if (rc < 0) {
146
                if (errno == EINTR)
147
                    continue;
148
                break;
149
            }
150
            revents = mio_revents(dev->hdl, pfd);
151
            if (!(revents & POLLIN))
152
                continue;
153
154
            todo = mio_read(dev->hdl, buf, sizeof(buf));
155
            if (todo == 0)
156
                continue;
157
            p = buf;
158
        }
159
        c = *p++;
160
        todo--;
161
162
        if (c >= 0xf8) {
163
            pm_ev_rt.message = c;
164
            pm_ev_rt.timestamp = Pt_Time();
165
            pm_read_short(midi, &pm_ev_rt);
166
        } else if (c == SYSEX_END) {
167
            if (st == SYSEX_START) {
168
                sysex_data[idx++] = c;
169
                pm_read_bytes(midi, sysex_data, idx, Pt_Time());
170
            }
171
            st = 0;
172
            idx = 0;
173
        } else if (c == SYSEX_START) {
174
            st = c;
175
            idx = 0;
176
            sysex_data[idx++] = c;
177
        } else if (c >= 0xf0) {
178
            pm_ev.message = c;
179
            len = common_len[c & 7];
180
            st = c;
181
            idx = 1;
182
        } else if (c >= 0x80) {
183
            pm_ev.message = c;
184
            len = voice_len[(c >> 4) & 7];
185
            st = c;
186
            idx = 1;
187
        } else if (st == SYSEX_START) {
188
            if (idx == SYSEX_MAXLEN) {
189
                fprintf(stderr, "the message is too long\n");
190
                idx = st = 0;
191
            } else {
192
                sysex_data[idx++] = c;
193
            }
194
        } else if (st) {
195
            if (idx == 0 && st != SYSEX_START)
196
                pm_ev.message |= (c << (8 * idx++));
197
            pm_ev.message |= (c << (8 * idx++));
198
            if (idx == len) {
199
                pm_read_short(midi, &pm_ev);
200
                if (st >= 0xf0)
201
                    st = 0;
202
                idx = 0;
203
            }
204
        }
205
    }
206
207
    pthread_exit(NULL);
208
    return NULL;
209
}
210
211
static void set_mode(struct mio_dev *dev, unsigned int mode) {
212
    if (dev->mode != 0)
213
        mio_close(dev->hdl);
214
    dev->mode = 0;
215
    if (mode != 0)
216
        dev->hdl = mio_open(dev->name, mode, 0);
217
    if (dev->hdl)
218
        dev->mode = mode;
219
}
220
221
static PmError sndio_out_open(PmInternal *midi, void *driverInfo)
222
{
223
    descriptor_type desc = &descriptors[midi->device_id];
224
    struct mio_dev *dev = (struct mio_dev *) desc->descriptor;
225
226
    if (dev->mode & MIO_OUT)
227
        return pmNoError;
228
229
    set_mode(dev, dev->mode | MIO_OUT);
230
    if (!(dev->mode & MIO_OUT)) {
231
        snprintf(dev->errmsg, PM_HOST_ERROR_MSG_LEN,
232
          "mio_open (output) failed: %s\n", dev->name);
233
        return pmHostError;
234
    }
235
236
    midi->descriptor = (void *)dev;
237
    return pmNoError;
238
}
239
240
static PmError sndio_in_open(PmInternal *midi, void *driverInfo)
241
{
242
    descriptor_type desc = &descriptors[midi->device_id];
243
    struct mio_dev *dev = (struct mio_dev *) desc->descriptor;
244
245
    if (dev->mode & MIO_IN)
246
        return pmNoError;
247
248
    set_mode(dev, dev->mode | MIO_IN);
249
    if (!(dev->mode & MIO_IN)) {
250
        snprintf(dev->errmsg, PM_HOST_ERROR_MSG_LEN,
251
          "mio_open (input) failed: %s\n", dev->name);
252
        return pmHostError;
253
    }
254
    midi->descriptor = (void *)dev;
255
    pthread_attr_t attr;
256
    pthread_attr_init(&attr);
257
    pthread_create(&dev->thread, &attr, input_thread, ( void* )midi);
258
    return pmNoError;
259
}
260
261
static PmError sndio_out_close(PmInternal *midi)
262
{
263
    struct mio_dev *dev = (struct mio_dev *) midi->descriptor;
264
265
    if (dev->mode & MIO_OUT)
266
        set_mode(dev, dev->mode & ~MIO_OUT);
267
    return pmNoError;
268
}
269
270
static PmError sndio_in_close(PmInternal *midi)
271
{
272
    struct mio_dev *dev = (struct mio_dev *) midi->descriptor;
273
274
    if (dev->mode & MIO_IN) {
275
        set_mode(dev, dev->mode & ~MIO_IN);
276
        pthread_join(dev->thread, NULL);
277
        dev->thread = NULL;
278
    }
279
    return pmNoError;
280
}
281
282
static PmError sndio_abort(PmInternal *midi)
283
{
284
    return pmNoError;
285
}
286
287
static PmTimestamp sndio_synchronize(PmInternal *midi)
288
{
289
    return 0;
290
}
291
292
static PmError do_write(struct mio_dev *dev, const void *addr, size_t nbytes)
293
{
294
    size_t w = mio_write(dev->hdl, addr, nbytes);
295
296
    if (w != nbytes) {
297
        snprintf(dev->errmsg, PM_HOST_ERROR_MSG_LEN, 
298
          "mio_write failed, bytes written:%zu\n", w);
299
        return pmHostError;
300
    }
301
    return pmNoError;
302
}
303
304
static PmError sndio_write_byte(PmInternal *midi, unsigned char byte,
305
                        PmTimestamp timestamp)
306
{
307
    struct mio_dev *dev = (struct mio_dev *) midi->descriptor;
308
309
    return do_write(dev, &byte, 1);
310
}
311
312
static PmError sndio_write_short(PmInternal *midi, PmEvent *event)
313
{
314
    struct mio_dev *dev = (struct mio_dev *) midi->descriptor;
315
    int nbytes = midi_message_length(event->message);
316
317
    if (midi->latency > 0) {
318
        /* XXX the event should be queued for later playback */
319
        return do_write(dev, &event->message, nbytes);
320
    } else {
321
        return do_write(dev, &event->message, nbytes);
322
    }
323
    return pmNoError;
324
}
325
326
static PmError sndio_write_flush(PmInternal *midi, PmTimestamp timestamp)
327
{
328
    return pmNoError;
329
}
330
331
PmError sndio_sysex(PmInternal *midi, PmTimestamp timestamp)
332
{
333
    return pmNoError;
334
}
335
336
static unsigned int sndio_has_host_error(PmInternal *midi)
337
{
338
    struct mio_dev *dev = (struct mio_dev *) midi->descriptor;
339
340
    return (dev->errmsg[0] != '\0');
341
}
342
343
static void sndio_get_host_error(PmInternal *midi, char *msg, unsigned int len)
344
{
345
    struct mio_dev *dev = (struct mio_dev *) midi->descriptor;
346
347
    strlcpy(msg, dev->errmsg, len);
348
    dev->errmsg[0] = '\0';
349
}
350
351
pm_fns_node pm_sndio_in_dictionary = {
352
    none_write_short,
353
    none_sysex,
354
    none_sysex,
355
    none_write_byte,
356
    none_write_short,
357
    none_write_flush,
358
    sndio_synchronize,
359
    sndio_in_open,
360
    sndio_abort,
361
    sndio_in_close,
362
    success_poll,
363
    sndio_has_host_error,
364
    sndio_get_host_error
365
};
366
367
pm_fns_node pm_sndio_out_dictionary = {
368
    sndio_write_short,
369
    sndio_sysex,
370
    sndio_sysex,
371
    sndio_write_byte,
372
    sndio_write_short,
373
    sndio_write_flush,
374
    sndio_synchronize,
375
    sndio_out_open,
376
    sndio_abort,
377
    sndio_out_close,
378
    none_poll,
379
    sndio_has_host_error,
380
    sndio_get_host_error
381
};
382
(-)audio/pd/files/portmidi/pm_sndio/pmsndio.h (+5 lines)
Line 0 Link Here
1
/* pmsndio.h */
2
3
extern PmDeviceID pm_default_input_device_id;
4
extern PmDeviceID pm_default_output_device_id;
5
(-)audio/pd/pkg-descr (+7 lines)
Lines 5-10 Link Here
5
animation and computer audio.  Second, an experimental facility is provided
5
animation and computer audio.  Second, an experimental facility is provided
6
for defining and accessing data structures.
6
for defining and accessing data structures.
7
7
8
The MIDI support implemented in this port is derived from Raphael Graf's
9
patches for a sndio backend on the OpenBSD audio/portmidi port, applied to an
10
embedded PortMIDI library, enhanced to detect a variable number of MIDI (umidi)
11
devices:
12
http://openbsd-archive.7691.n7.nabble.com/audio-portmidi-input-td363848.html
13
https://marc.info/?l=openbsd-ports&m=155221816900336&w=2
14
8
Unofficial web site: http://puredata.org/
15
Unofficial web site: http://puredata.org/
9
16
10
WWW: http://msp.ucsd.edu/software.html
17
WWW: http://msp.ucsd.edu/software.html

Return to bug 252188