Skip to content

Commit

Permalink
fixed str[0] = '\0'; bug...
Browse files Browse the repository at this point in the history
  • Loading branch information
tebjan committed Apr 12, 2012
1 parent b562d4a commit 1c6239d
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions libpd_wrapper/z_libpd.c
Expand Up @@ -56,54 +56,54 @@ void libpd_set_messagehook(const t_libpd_messagehook hook){
}

//pointer to string memory
char *arg_str;
static char *arg_str;
static char *list_arg_str;

//convert atom list to space separated string
//convert atom list to space seperated string
char* args_to_str(char *str, int argc, t_atom *args) {

//free mem
free(str);

int i;
int size;
int size = argc;
char float_buff[64];

//determine size
for (i = 0; i < argc; i++) {
t_atom a = args[i];
if (libpd_is_float(a)) {
sprintf(float_buff, "%f", libpd_get_float(a));
size = size + strlen(float_buff);
sprintf(float_buff, "%f", libpd_get_float(a));
size = size + strlen(float_buff);

} else if (libpd_is_symbol(a)) {
size = size + strlen(libpd_get_symbol(a));
size = size + strlen(libpd_get_symbol(a));
}
}

//get mem
str = malloc(size+argc);
char *space = " ";
str = malloc(size);
str[0] = '\0';

//build string
for (i = 0; i < argc; i++) {
t_atom a = args[i];
if (libpd_is_float(a)) {
sprintf(float_buff, "%f ", libpd_get_float(a));
strcat(str, float_buff);
sprintf(float_buff, "%f ", libpd_get_float(a));
strcat(str, float_buff);

} else if (libpd_is_symbol(a)) {
strcat(str, libpd_get_symbol(a));
strcat(str, space);
strcat(str, libpd_get_symbol(a));
strcat(str, " ");
}
}

return str;
}

//list
void str_listhook(const char *recv, int argc, t_atom *argv)
{
if (libpd_liststrhook) (*libpd_liststrhook)(recv, argc, args_to_str(arg_str, argc, argv));
void str_listhook(const char *recv, int argc, t_atom *argv) {
if (libpd_liststrhook) (*libpd_liststrhook)(recv, argc, args_to_str(list_arg_str, argc, argv));
}

void libpd_set_liststrhook(const t_libpd_liststrhook hook){
Expand All @@ -112,12 +112,11 @@ void libpd_set_liststrhook(const t_libpd_liststrhook hook){
}

//message
void str_messagehook(const char *recv, const char *msg, int argc, t_atom *argv)
{
void str_messagehook(const char *recv, const char *msg, int argc, t_atom *argv) {
if (libpd_messagestrhook) (*libpd_messagestrhook)(recv, msg, argc, args_to_str(arg_str, argc, argv));
}

void libpd_set_messagestrhook(const t_libpd_messagestrhook hook){
void libpd_set_messagestrhook(const t_libpd_messagestrhook hook) {
libpd_messagestrhook = hook;
libpd_messagehook = (t_libpd_messagehook)str_messagehook;
}
Expand All @@ -130,38 +129,31 @@ t_libpd_aftertouchhook libpd_aftertouchhook = NULL;
t_libpd_polyaftertouchhook libpd_polyaftertouchhook = NULL;
t_libpd_midibytehook libpd_midibytehook = NULL;

void libpd_set_noteonhook(const t_libpd_noteonhook hook)
{
void libpd_set_noteonhook(const t_libpd_noteonhook hook) {
libpd_noteonhook = hook;
}

void libpd_set_controlchangehook(const t_libpd_controlchangehook hook)
{
void libpd_set_controlchangehook(const t_libpd_controlchangehook hook) {
libpd_controlchangehook = hook;
}

void libpd_set_programchangehook(const t_libpd_programchangehook hook)
{
void libpd_set_programchangehook(const t_libpd_programchangehook hook) {
libpd_programchangehook = hook;
}

void libpd_set_pitchbendhook(const t_libpd_pitchbendhook hook)
{
void libpd_set_pitchbendhook(const t_libpd_pitchbendhook hook) {
libpd_pitchbendhook = hook;
}

void libpd_set_aftertouchhook(const t_libpd_aftertouchhook hook)
{
void libpd_set_aftertouchhook(const t_libpd_aftertouchhook hook) {
libpd_aftertouchhook = hook;
}

void libpd_set_polyaftertouchhook(const t_libpd_polyaftertouchhook hook)
{
void libpd_set_polyaftertouchhook(const t_libpd_polyaftertouchhook hook) {
libpd_polyaftertouchhook = hook;
}

void libpd_set_midibytehook(const t_libpd_midibytehook hook)
{
void libpd_set_midibytehook(const t_libpd_midibytehook hook) {
libpd_midibytehook = hook;
}

Expand Down

0 comments on commit 1c6239d

Please sign in to comment.