[PD-dev] newbie external experiments
André Schmidt
andre at vju-tv.net
Wed Sep 25 19:25:16 CEST 2002
hi devs, (its me again:)
ok, after succesfully compiling the examples from IOhannes
external-how-to's i tried to implement my "own" code. but as i have VERY
little clou what i'm doing i would like to have some help here. the working
(non PD) c code is here:
----------------------------------------------------
#include <stdio.h>
#define bits 8
char* byte2BinStr(char *strOut, unsigned char byteIn) {
int i;
int d;
for(i = 0; i < bits; i++) {
d = (byteIn & 0x80);
byteIn = byteIn << 1;
strOut[i] = (d ? '1' : '0');
} return strOut;
}
int main(void) {
int a;
char strBB[4*bits+1];
scanf("%d", &a);
printf("%s", byte2BinStr(strBB, a));
return 0;
}
--------------------------------------------
actually it's not 100% my own code (found the bit conversion from
newsgroup) but i implemented it so that it ask an integer from user and
gives a 8bit binary string out... then i tried to convert it to be used on
pd, converting incoming ints to symbol strings. this is what i adapted from
v2db.c (iemlib):
----------------------------------------------
#include "m_pd.h"
#define bits 8
char strBB[4*bits+1];
static t_class *bitstr_class;
typedef struct _bitstr {
t_object x_obj;
t_int i_byte;
t_outlet *s_out;
} t_bitstr;
char* byte2BinStr(char *strOut, unsigned char byteIn) {
int i;
int d;
for(i = 0; i < bits; i++) {
d = (byteIn & 0x80);
byteIn = byteIn << 1;
strOut[i] = (d ? '1' : '0');
} return strOut;
}
static void bitstr_symbol(t_object *x, t_int i)
{
outlet_symbol(x->ob_outlet, byte2BinStr(strBB, i));
}
static void *bitstr_new(void)
{
t_object *x = (t_object *)pd_new(bitstr_class);
outlet_new(x, &s_symbol);
return (x);
}
void bitstr_setup(void)
{
bitstr_class = class_new(gensym("bitstr"), bitstr_new, 0,
sizeof(t_object), 0, 0);
class_addsymbol(bitstr_class, (t_method)bitstr_symbol);
class_sethelpsymbol(bitstr_class, gensym("help-bitstr"));
}
-----------------------------------------
yes, you may laugh over my code :) it's just what i logically thougt would
go. please let me know if i'm even on the right way, but i know i have MUCH
to learn and the IOhannes how-to is still too high for me :(. for the
basics i've gone trough this http://www.iota-six.co.uk/c/01_intro.htm (very
good for beginners). would be nice if some1 could point me what i should
learn before i "fully" understand pd-external coding, i know i don't have
to know *ALL* from c. as i ONLY want to code externals for PD. yes, i know
this is WAY over my head, but i like extreme challenges...
cheers, slowing down
-andre
More information about the Pd-dev
mailing list