Skip to content

Commit

Permalink
now with support for Python arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoyeurny committed Nov 30, 2010
1 parent 453970c commit 30addec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
35 changes: 31 additions & 4 deletions python/pylibpd.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@

%module pylibpd

%include "carrays.i"
%array_class(float, float_array)

void libpd_clear_search_path();
void libpd_add_to_search_path(const char *s);

int libpd_blocksize();
int libpd_init_audio(int, int, int, int);

%typemap(in) float * {
$1 = (float *)PyInt_AsLong($input);
}
%typemap(in) double * {
$1 = (double *)PyInt_AsLong($input);
}
%typemap(in) short * {
$1 = (short *)PyInt_AsLong($input);
}
%rename(__libpd_process_raw) libpd_process_raw;
%rename(__libpd_process_float) libpd_process_float;
%rename(__libpd_process_short) libpd_process_short;
%rename(__libpd_process_double) libpd_process_double;
int libpd_process_raw(float *, float *);
int libpd_process_float(float *, float *);
int libpd_process_float(float*, float *);
int libpd_process_short(short *, short *);
int libpd_process_double(double *, double *);

int libpd_bang(const char *);
int libpd_float(const char *, float);
Expand Down Expand Up @@ -64,6 +77,18 @@ SET_CALLBACK(aftertouch)
SET_CALLBACK(polyaftertouch)

%pythoncode %{
def libpd_process_raw(inp, outp):
return __libpd_process_raw(inp.buffer_info()[0], outp.buffer_info()[0])

def libpd_process_float(inp, outp):
return __libpd_process_float(inp.buffer_info()[0], outp.buffer_info()[0])

def libpd_process_short(inp, outp):
return __libpd_process_short(inp.buffer_info()[0], outp.buffer_info()[0])

def libpd_process_double(inp, outp):
return __libpd_process_double(inp.buffer_info()[0], outp.buffer_info()[0])

def __process_args(args):
n = __libpd_start_message();
if (len(args) > n): return -1
Expand All @@ -82,6 +107,7 @@ def libpd_list(dest, *args):

def libpd_message(dest, sym, *args):
return __process_args(args) or __libpd_finish_message(dest, sym)

%}

%{
Expand Down Expand Up @@ -155,6 +181,7 @@ MAKE_CALLBACK(aftertouch, (int ch, int v),
Py_BuildValue, ("(ii)", ch, v))
MAKE_CALLBACK(polyaftertouch, (int ch, int n, int v),
Py_BuildValue, ("(iii)", ch, n, v))

%}

%init %{
Expand Down
5 changes: 3 additions & 2 deletions python/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pylibpd import *
import array

def pd_receive(*s):
print 'received:', s
Expand All @@ -20,8 +21,8 @@ def pd_receive(*s):
libpd_symbol('spam', "don't panic")
libpd_list('spam', "test", 1, "foo", 2)

inp = float_array(64)
outp = float_array(128)
inp = array.array('f', '\x00\x00\x00\x00' * 64)
outp = array.array('f', '\x00\x00\x00\x00' * 128)

for i in range(64):
inp[i] = i
Expand Down

0 comments on commit 30addec

Please sign in to comment.