[CM] PortMidi

Fernando Lopez-Lezcano nando@ccrma.Stanford.EDU
Wed, 14 Dec 2005 12:44:17 -0800


--=-LjZvAjN/RFp1W9JtlYN3
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2005-12-14 at 20:50 +0100, R. Mattes wrote:
> Hello list,
> 
> i'm trying to get the portmidi interface to work: somehow the download
> zip file from the PortMidi website seems to lack the modified Makefile 
> with shared library support? Before i start hacking that file:  has
> anyone done that and is willing to share it? 

I'm using a couple of patches from the Debian portmidi package...
(attached to this email). 

-- Fernando


--=-LjZvAjN/RFp1W9JtlYN3
Content-Disposition: attachment; filename=portmidi-20041117-debian.patch
Content-Type: text/x-patch; name=portmidi-20041117-debian.patch; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

--- portmidi-20041117.orig/pm_linux/pmlinux.c
+++ portmidi-20041117/pm_linux/pmlinux.c
@@ -20,10 +20,10 @@
 PmError pm_init()
 {
     #ifdef PMALSA
-	pm_linuxalsa_init();
+	return pm_linuxalsa_init();
     #endif
     #ifdef PMNULL
-        pm_linuxnull_init();
+        return pm_linuxnull_init();
     #endif
 }
 
--- portmidi-20041117.orig/pm_linux/pmlinuxalsa.c
+++ portmidi-20041117/pm_linux/pmlinuxalsa.c
@@ -207,8 +207,8 @@
             if (when == 0) when = now;
             when = (when - now) + midi->latency;
             if (when < 0) when = 0;
-            VERBOSE printf("timestamp %d now %d latency %d, ", 
-                           timestamp, now, midi->latency);
+            VERBOSE printf("timestamp %d now %d latency %li,", 
+                           (int)timestamp, (int)now, midi->latency);
             VERBOSE printf("scheduling event after %d\n", when);
             /* message is sent in relative ticks, where 1 tick = 1 ms */
             snd_seq_ev_schedule_tick(&ev, queue, 1, when);
@@ -238,12 +238,11 @@
 
 static PmError alsa_out_close(PmInternal *midi)
 {
-    int err;
     alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
     if (!desc) return pmBadPtr;
 
-    if (pm_hosterror = snd_seq_disconnect_to(seq, desc->this_port, 
-                                             desc->client, desc->port)) {
+    if ((pm_hosterror = snd_seq_disconnect_to(seq, desc->this_port, 
+                                             desc->client, desc->port))) {
         // if there's an error, try to delete the port anyway, but don't
         // change the pm_hosterror value so we retain the first error
         snd_seq_delete_port(seq, desc->this_port);
@@ -329,11 +328,10 @@
 
 static PmError alsa_in_close(PmInternal *midi)
 {
-    int err;
     alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
     if (!desc) return pmBadPtr;
-    if (pm_hosterror = snd_seq_disconnect_from(seq, desc->this_port, 
-                                               desc->client, desc->port)) {
+    if ((pm_hosterror = snd_seq_disconnect_from(seq, desc->this_port, 
+                                               desc->client, desc->port))) {
         snd_seq_delete_port(seq, desc->this_port); /* try to close port */
     } else {
         pm_hosterror = snd_seq_delete_port(seq, desc->this_port);
@@ -351,7 +349,7 @@
 
 static PmError alsa_abort(PmInternal *midi)
 {
-    alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
+    //alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
     /* This is supposed to flush any pending output. */
     printf("WARNING: alsa_abort not implemented\n");
     return pmNoError;
@@ -411,7 +409,7 @@
 static PmError alsa_write_flush(PmInternal *midi)
 {
     alsa_descriptor_type desc = (alsa_descriptor_type) midi->descriptor;
-    VERBOSE printf("snd_seq_drain_output: 0x%x\n", seq);
+    VERBOSE printf("snd_seq_drain_output: 0x%x\n", (unsigned int)seq);
     desc->error = snd_seq_drain_output(seq);
     if (desc->error < 0) return pmHostError;
 
@@ -584,8 +582,6 @@
     case SND_SEQ_EVENT_SYSEX: {
         const BYTE *ptr = (const BYTE *) ev->data.ext.ptr;
         int i;
-        long msg = 0;
-        int shift = 0;
         if (!(midi->filters & PM_FILT_SYSEX)) {
             for (i = 0; i < ev->data.ext.len; i++) {
                 pm_read_byte(midi, *ptr++, timestamp);
@@ -678,7 +674,7 @@
     unsigned int caps;
 
     err = snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK);
-    if (err < 0) return;
+    if (err < 0) return err;
     
     snd_seq_client_info_alloca(&cinfo);
     snd_seq_port_info_alloca(&pinfo);
@@ -715,10 +711,15 @@
             }
         }
     }
+    return 0;
 }
     
 
 void pm_linuxalsa_term(void)
 {
     snd_seq_close(seq);
+    free(descriptors);
+    descriptors=NULL;
+    pm_descriptor_index=0;
+    pm_descriptor_max=0;
 }
--- portmidi-20041117.orig/pm_test/Makefile
+++ portmidi-20041117/pm_test/Makefile
@@ -0,0 +1,32 @@
+# For debugging, define PM_CHECK_ERRORS
+PMFLAGS = -DPM_CHECK_ERRORS
+# Use this for linux alsa (0.9x) version
+ALSALIB = -lasound
+pmlib = -lportmidi
+ptlib = -lporttime
+VFLAGS = -DPMALSA
+
+CC = gcc $(CFLAGS) $(VFLAGS) $(PMFLAGS) -g
+
+all: test sysex midithread latency midithru
+
+test: test.o
+	$(CC) test.c -o test $(pmlib) $(ptlib) $(ALSALIB)
+
+sysex: sysex.o
+	$(CC) sysex.c -o sysex $(pmlib) $(ptlib) $(ALSALIB)
+
+midithread: midithread.o
+	$(CC) midithread.c -o midithread \
+		$(pmlib) $(ptlib) $(ALSALIB)
+
+latency: latency.o
+	$(CC) latency.c -o latency $(pmlib) $(ptlib) \
+		$(ALSALIB) -lpthread -lm
+
+midithru: midithru.o
+	$(CC) midithru.c -o midithru $(pmlib) $(ptlib) \
+		$(ALSALIB) -lpthread -lm
+
+clean:
+	rm -f midithru latency midithread sysex test
--- portmidi-20041117.orig/porttime/ptlinux.c
+++ portmidi-20041117/porttime/ptlinux.c
@@ -22,6 +22,10 @@
 
 */
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
 #include "porttime.h"
 #include "sys/time.h"
 #include "sys/resource.h"
--- portmidi-20041117.orig/debian/changelog
+++ portmidi-20041117/debian/changelog
@@ -0,0 +1,10 @@
+portmidi (20041117-1) unstable; urgency=low
+
+  * Initial release (closes: #280656)
+  * Add shared libraries and installation target to Makefile, add
+    pm_test/Makefile for examples/.
+  * Patch pm_linuxalsa_term as suggested by Predrag Viceic, freecycle author.
+  * Minor fixes to prevent compilation warnings.
+
+ -- Paul Brossier <piem@debian.org>  Tue, 27 Sep 2005 02:04:20 +0100
+
--- portmidi-20041117.orig/debian/compat
+++ portmidi-20041117/debian/compat
@@ -0,0 +1 @@
+4
--- portmidi-20041117.orig/debian/libportmidi-dev.examples
+++ portmidi-20041117/debian/libportmidi-dev.examples
@@ -0,0 +1,4 @@
+pm_test/*.c
+pm_test/Makefile
+pm_common/pminternal.h
+pm_common/pmutil.h
--- portmidi-20041117.orig/debian/rules
+++ portmidi-20041117/debian/rules
@@ -0,0 +1,76 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+CFLAGS = -Wall -g -fPIC
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+	CFLAGS += -O0
+else
+	CFLAGS += -O2
+endif
+
+version=`ls pm_linux/lib*.so.* | \
+ awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
+major=`ls pm_linux/lib*.so.* | \
+ awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`
+
+configure: configure-stamp
+configure-stamp:
+	dh_testdir
+	# nothing to do by default
+	touch configure-stamp
+
+build: build-stamp
+build-stamp: configure-stamp 
+	dh_testdir
+	CFLAGS='$(CFLAGS)' $(MAKE)
+	touch build-stamp
+
+clean:
+	dh_testdir
+	dh_testroot
+	rm -f build-stamp configure-stamp
+	-$(MAKE) cleanest
+	dh_clean 
+
+install: build
+	dh_testdir
+	dh_testroot
+	dh_clean -k 
+	dh_installdirs
+	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
+	dh_install --sourcedir=$(CURDIR)/debian/tmp
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+	dh_testdir
+	dh_testroot
+	dh_installchangelogs 
+	dh_installdocs
+	dh_installexamples
+	dh_installman
+	dh_link
+	dh_strip
+	dh_compress -X.c
+	dh_fixperms
+	dh_makeshlibs
+	dh_installdeb
+	dh_shlibdeps
+	dh_gencontrol
+	dh_md5sums
+	dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
--- portmidi-20041117.orig/debian/libportmidi0.links
+++ portmidi-20041117/debian/libportmidi0.links
@@ -0,0 +1,2 @@
+usr/lib/libportmidi.so.0.0.0 usr/lib/libportmidi.so.0
+usr/lib/libporttime.so.0.0.0 usr/lib/libporttime.so.0
--- portmidi-20041117.orig/debian/libportmidi-dev.links
+++ portmidi-20041117/debian/libportmidi-dev.links
@@ -0,0 +1,2 @@
+usr/lib/libportmidi.so.0.0.0 usr/lib/libportmidi.so
+usr/lib/libporttime.so.0.0.0 usr/lib/libporttime.so
--- portmidi-20041117.orig/debian/copyright
+++ portmidi-20041117/debian/copyright
@@ -0,0 +1,35 @@
+This package was debianized by Paul Brossier <piem@debian.org> on
+Fri,  5 Aug 2005 18:37:26 +0100.
+
+It was downloaded from http://www.cs.cmu.edu/~music/portmusic/
+
+Copyright Holders:
+
+ Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ Copyright (c) 2001 Roger B. Dannenberg
+
+License:
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ 
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
--- portmidi-20041117.orig/debian/libportmidi-dev.dirs
+++ portmidi-20041117/debian/libportmidi-dev.dirs
@@ -0,0 +1,2 @@
+usr/lib
+usr/include
--- portmidi-20041117.orig/debian/libportmidi-dev.docs
+++ portmidi-20041117/debian/libportmidi-dev.docs
@@ -0,0 +1,2 @@
+README.txt
+pm_linux/README_LINUX.txt
--- portmidi-20041117.orig/debian/libportmidi0.dirs
+++ portmidi-20041117/debian/libportmidi0.dirs
@@ -0,0 +1 @@
+usr/lib
--- portmidi-20041117.orig/debian/libportmidi-dev.install
+++ portmidi-20041117/debian/libportmidi-dev.install
@@ -0,0 +1,6 @@
+usr/include/*
+usr/lib/lib*.a
+usr/lib/lib*.so.0
+usr/lib/pkgconfig/*
+usr/lib/*.la
+usr/share/pkgconfig/*
--- portmidi-20041117.orig/debian/libportmidi0.install
+++ portmidi-20041117/debian/libportmidi0.install
@@ -0,0 +1 @@
+usr/lib/lib*.so.*
--- portmidi-20041117.orig/debian/control
+++ portmidi-20041117/debian/control
@@ -0,0 +1,22 @@
+Source: portmidi
+Priority: optional
+Maintainer: Paul Brossier <piem@debian.org>
+Build-Depends: debhelper (>= 4.0.0), libasound2-dev
+Standards-Version: 3.6.2.0
+Section: libs
+
+Package: libportmidi-dev
+Section: libdevel
+Architecture: any
+Depends: libportmidi0 (= ${Source-Version})
+Description: library for real-time MIDI input/output
+ PortMidi is a platform independent library for MIDI input/output.
+ This package provides the header files for PortMidi and PortTime.
+
+Package: libportmidi0
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: library for real-time MIDI input/output
+ PortMidi is a platform independent library for MIDI input/output.
+ This package provide the PortMidi and PortTime libraries.
--- portmidi-20041117.orig/debian/watch
+++ portmidi-20041117/debian/watch
@@ -0,0 +1,4 @@
+version=3
+# a hacky way which should be fixed
+options="uversionmangle=s/([0-9]+)([a-z]+)([0-9]+)/$3$2$1/,dversionmangle=s/200411/04nov/" \
+http://www.cs.cmu.edu/~music/portmusic/portmidi/ portmidi(.*)\.zip
--- portmidi-20041117.orig/Makefile
+++ portmidi-20041117/Makefile
@@ -17,13 +17,17 @@
 # VFLAGS = -DPMNULL
 
 pmlib = pm_linux/libportmidi.a
+pmslib = pm_linux/libportmidi.so.0.0.0
 
 ptlib = porttime/libporttime.a
+ptslib = porttime/libporttime.so.0.0.0
 
-CC = gcc $(VFLAGS) $(PMFLAGS) -g -Ipm_common -Iporttime
+CC = gcc $(CFLAGS) $(VFLAGS) $(PMFLAGS) -g -Ipm_common -Iporttime
+
+INSTALL = install
 
 pmobjects = pm_common/pmutil.o $(versions) pm_linux/pmlinux.o  \
-	pm_common/portmidi.o pm_linux/pmlinuxalsa.o
+	pm_common/portmidi.o
 
 ptobjects = porttime/porttime.o porttime/ptlinux.o 
 
@@ -34,9 +38,12 @@
 
 $(pmlib): Makefile $(pmobjects)
 	ar -cr $(pmlib) $(pmobjects)
+	$(CC) -shared $(ALSALIB) $(pmobjects) -Wl,-soname -Wl,libportmidi.so.0 -o $(pmslib)
 
 $(ptlib): Makefile $(ptobjects)
 	ar -cr $(ptlib) $(ptobjects)
+	$(CC) -shared $(ptobjects) -Wl,-soname -Wl,libporttime.so.0 -o $(ptslib)
+
 
 pm_linux/pmlinuxalsa.o: Makefile pm_linux/pmlinuxalsa.c pm_linux/pmlinuxalsa.h
 	$(CC) -c pm_linux/pmlinuxalsa.c -o pm_linux/pmlinuxalsa.o
@@ -62,8 +69,16 @@
 porttime/ptlinux.o: Makefile porttime/ptlinux.c
 	$(CC) -c porttime/ptlinux.c -o porttime/ptlinux.o
 
+install: 
+	$(INSTALL) -d $(DESTDIR)/usr/include/
+	$(INSTALL) -m 644 pm_common/portmidi.h $(DESTDIR)/usr/include/
+	$(INSTALL) -m 644 porttime/porttime.h $(DESTDIR)/usr/include/
+	$(INSTALL) -d $(DESTDIR)/usr/lib/
+	$(INSTALL) -m 644 pm_linux/libportmidi* $(DESTDIR)/usr/lib/
+	$(INSTALL) -m 644 porttime/libporttime* $(DESTDIR)/usr/lib/
+
 clean:
-	rm -f *.o *~ core* */*.o */*~ */core* pm_test/*/pm_dll.dll 
+	rm -f *.o *~ core* */*.o */*.so */*~ */core* pm_test/*/pm_dll.dll 
 	rm -f *.opt *.ncb *.plg pm_win/Debug/pm_dll.lib pm_win/Release/pm_dll.lib
 	rm -f pm_test/*.opt pm_test/*.ncb
 
@@ -72,6 +87,10 @@
 cleanest: cleaner
 	rm -f $(pmlib) $(ptlib) pm_test/test pm_test/sysex pm_test/midithread
 	rm -f pm_test/latency pm_test/midithru
+	rm -f pm_linux/libportmidi.a pm_linux/libportmidi.so.0.0.0 pm_test/test pm_test/sysex \
+	    pm_test/midithread pm_test/latency pm_test/midithru porttime/libporttime.a \
+	    porttime/libporttime.so.0.0.0
+
 
 backup: cleanest
 	cd ..; zip -r portmidi.zip portmidi

--=-LjZvAjN/RFp1W9JtlYN3
Content-Disposition: attachment; filename=portmidi-20041117-pthread.patch
Content-Type: text/x-patch; name=portmidi-20041117-pthread.patch; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

--- portmidi/Makefile~	2005-11-10 16:08:07.000000000 -0800
+++ portmidi/Makefile	2005-11-10 16:47:09.000000000 -0800
@@ -42,7 +42,7 @@
 
 $(ptlib): Makefile $(ptobjects)
 	ar -cr $(ptlib) $(ptobjects)
-	$(CC) -shared $(ptobjects) -Wl,-soname -Wl,libporttime.so.0 -o $(ptslib)
+	$(CC) -shared $(ptobjects) -Wl,-soname -Wl,libporttime.so.0 -Wl,-l,pthread -o $(ptslib)
 
 
 pm_linux/pmlinuxalsa.o: Makefile pm_linux/pmlinuxalsa.c pm_linux/pmlinuxalsa.h

--=-LjZvAjN/RFp1W9JtlYN3--