javaaudiopuredatasynthesizerlibpd

How to setup libpd for use in Java?


PureData is a programming language for sound synthesis. LibPD is a wrapper around it so we can use patches in Java/C#/Android etc. Here is the GitHub page containing it: https://github.com/libpd/libpd

Now to use LibPD in Java, I think first I should import the its library to my project then use its Classes and methods to call my patch and tweak it. Problem is, I can't find a jar file to add to my project. Do I have to "build" something so jar file is generated?

I'd be grateful if someone explains the procedure to me.
Thanks

Update 1[2017-01-11]:
After following @umläute 's post, I'm getting the following error: (I'm using MinGW in Windows 7/64 bit and MinGW-make for make)

C:\Users\Name\Documents\GitHub>cd libpd

C:\Users\Name\Documents\GitHub\libpd>git submodule init

C:\Users\Name\Documents\GitHub\libpd>git submodule update

C:\Users\Name\Documents\GitHub\libpd>make javalib
'make' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Name\Documents\GitHub\libpd>mingw32-make javalib
process_begin: CreateProcess(NULL, uname, ...) failed.
'sed' is not recognized as an internal or external command,
operable program or batch file.
'sed' is not recognized as an internal or external command,
operable program or batch file.
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_arithmetic.o pure-data/src/d_arithmetic.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_array.o pure-data/src/d_array.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_ctl.o pure-data/src/d_ctl.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_dac.o pure-data/src/d_dac.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_delay.o pure-data/src/d_delay.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_fft.o pure-data/src/d_fft.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_fft_fftsg.o pure-data/src/d_fft_fftsg.c
pure-data/src/d_fft_fftsg.c: In function 'mayer_dofft':
pure-data/src/d_fft_fftsg.c:88:11: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
default]
     buf = alloca(n * (2 * sizeof(FFTFLT)));
           ^
pure-data/src/d_fft_fftsg.c: In function 'mayer_realfft':
pure-data/src/d_fft_fftsg.c:121:11: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
 default]
     buf = alloca(n * sizeof(FFTFLT));
           ^
pure-data/src/d_fft_fftsg.c: In function 'mayer_realifft':
pure-data/src/d_fft_fftsg.c:139:11: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
 default]
     buf = alloca(n * sizeof(FFTFLT));
           ^
pure-data/src/d_fft_fftsg.c: In function 'pd_fft':
pure-data/src/d_fft_fftsg.c:156:30: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
 default]
     FFTFLT *buf2 = (FFTFLT *)alloca(2 * npoints * sizeof(FFTFLT)), *bp2;
                              ^
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_filter.o pure-data/src/d_filter.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_global.o pure-data/src/d_global.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_math.o pure-data/src/d_math.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_osc.o pure-data/src/d_osc.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_resample.o pure-data/src/d_resample.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_soundfile.o pure-data/src/d_soundfile.c
pure-data/src/d_soundfile.c:17:21: fatal error: pthread.h: No such file or directory
 #include <pthread.h>
                     ^
compilation terminated.
<builtin>: recipe for target 'pure-data/src/d_soundfile.o' failed
mingw32-make: *** [pure-data/src/d_soundfile.o] Error 1

Update 2 [2017-01-11]:
I've installed MSYS2, mingw32 and 64 and make (thanks to the helps of @milleniumbug). I've added directories for mingw64 and make to PATH. Now when I do make javalib I get this error:

C:\Users\Name\Documents\GitHub\libpd>make javalib
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o jni/z_jni_plain.o jni/z_jni_plain.c
In file included from jni/z_jni_shared.c:8:0,
                 from jni/z_jni_plain.c:8:
jni/z_jni.h:2:10: fatal error: jni.h: No such file or directory
 #include <jni.h>
          ^~~~~~~

Update 3 [4-11-2017]: fixed jni.h problem. My PATH pointed to the old jdk instead of the updated one. Now I'm getting this error:

C:/msys32/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Cannot export libpd
_set_concatenated_printhook: symbol not found
C:/msys32/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture o
f input file `libpd_wrapper/util/z_print_util.o' is incompatible with i386:x86-64 output
libpd_wrapper/util/z_print_util.o:z_print_util.c:(.text+0x3a): undefined reference to `_strlen'
libpd_wrapper/util/z_print_util.o:z_print_util.c:(.text+0x75): undefined reference to `_strncat'
libpd_wrapper/util/z_print_util.o:z_print_util.c:(.text+0xad): undefined reference to `_strncat'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:163: java-build/org/puredata/core/natives/windows/x86_64//pdnative.dll] Error 1

Tested it with 32bit MinGW gcc...Still the same error...

Update 4 [6-11-2017]:
Fixed the problem
It seems I've managed to solve it. Here is what I did in general:
1- First I've installed msys2 and thorough it, MinGW32 and MinGW64 and make
Note: Remove mingw32 if you've got it from old original site. It is no longer updated and you may encounter dependency issues.
2- Changed PATH to use MinGW32 (so gcc -v should report 32 bit version)
3- Changed JAVA_HOME to the updated jdk directory. It seems updating java does not automatically update env. variables (this fixed the jni header not found issue).
4- install git and get libpd via git commands (as instructed in the repository's readme)
5- make clean
6- make clean libpd
7- make clean javalib

I hope this helps someone


Solution

  • the libpd Github project contains (like other source code repositories) the sources for libpd (rather than pre-built binaries).

    From the README

    To download libpd & checkout the pure-data submodule do the following:

    git clone https://github.com/libpd/libpd.git
    cd libpd
    git submodule init
    git submodule update
    

    and it goes on about building:

    Currently the main Makefile builds a dynamic lib on Windows (in MinGW), Linux, & Mac OSX and has the following targets:

    • libpd: (default) builds if no target is specified, builds the libpd.so/dylib/dll
    • [...]
    • javalib: builds libpdnative and the jni wrapper
    • clean: removes the object files

    So, in order to create your libs/libpd.jar simply do:

    make javalib