[PD] new [list tosymbol] / [list fromsymbol]

2014-02-11 Thread Roman Haefeli
Hey Miller

This is a quantum leap for Pd. This extension to the [list] family opens
a whole lot of new possibility. Thanks for including it into the
upcoming Pure Data. And thanks to Chris McCormick who I believe provided
the patch.

As a native German speaker, I had to try it out with ä ö ü, of course.
[list fromsymbol] gives me '-61 -92' for ä. Is there a reason it outputs
signed numbers (-128 to 127) instead of the (supposedly more common)
byte representation (0 to 255)?

[list tosymbol] deals with both the same way. Both '-61 -92' and '195
164' return an 'ä'. 

Roman



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] how to specify literals as type t_float

2014-02-11 Thread katja
Hi Miller,

My intention is to write Pd code in such a way that it is maximally
efficient for tiny computers which aren't fond of doubles (RPi and
friends), while keeping the option open to compile with maximum precision
for fast machines.

The advent of RPi has prompted me to focus more on efficiency, even though
I rarely use a Pi myself. Reckoning with ARM, I guess we're sort of back in
the days of Pentium 2 when it comes to precious clock cycles (but I didn't
program C at that time).

Overlooked precision conversions happen so easily. Here is an example from
tabread4~ in d_array.c:

  *out++ = b + frac * (
cminusb - 0.167f * (1.-frac) * (
(d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
)
);

All literals have float suffixes, except in (1.-frac). So here is a double
which makes the compiler do the first half of the interpolation routine on
the FPU with extended precision (on Linux i386).

A few years ago I wouldn't have noticed it, and my own code my be full of
unspecified literals. That's what I want to repair now. Not by adding the
regular float specifier 'f' though, since that would defy the purpose of
Pd's own float type definition.

Katja


On Tue, Feb 11, 2014 at 6:39 AM, Miller Puckette  wrote:

> Hi Katya -
>
> I think there's no simpler way.  On the other hand, for constants like
> 0.125 and 2, it would be equivalent to say 0.125f, etc - but for other
> constants (1/3 for example), casting as t_float would be more accurate in
> case t_float is set to double.  I think people rarely use t_float as higher
> precision than 32 bits though, and even if they did the difference between
> (t_float)1/(t_float)3 and 1.f/3.f is pretty small.
>
> cheers
> Miller
>
> On Mon, Feb 10, 2014 at 10:53:02PM +0100, katja wrote:
> > Hello,
> >
> > When working on parabolic interpolation in a Pd class, I wondered again
> > what is the best method to specify literal constants as Pd's type t_float
> > (which could be float or double). The interpolation goes like:
> >
> > ...
> > t_float a = buf[peakindex-1];
> > t_float b = buf[peakindex];
> > t_float c = buf[peakindex+1];
> > t_float realpeak;
> >
> > realpeak = b + 0.125 * (c - a) * (c - a) / (2. * b - a - c);
> > ...
> >
> > Without float suffixes for the literals, single precision t_float
> variables
> > would be promoted to double here, which would be an unintended waste of
> CPU
> > cycles. For some time, I've worked around this by using const variables
> > instead of literals, like:
> >
> > ...
> > const t_float two = 2.;
> > const t_float eighth = 0.125;
> > t_float a = buf[peakindex-1];
> > t_float b = buf[peakindex];
> > t_float c = buf[peakindex+1];
> > t_float realpeak;
> >
> > realpeak = b + eighth * (c - a) * (c - a) / (two * b - a - c);
> > ...
> >
> > While this avoids redundant type conversions, it clutters the code and
> does
> > not result in such fast instructions as literals do. Therefore I am now
> > using type casts where type specifiers are normally used:
> >
> > ...
> > t_float a = buf[peakindex-1];
> > t_float b = buf[peakindex];
> > t_float c = buf[peakindex+1];
> > t_float realpeak;
> >
> > realpeak = b + (t_float)0.125 * (c - a) * (c - a) / ((t_float)2. * b
> -
> > a - c);
> > ...
> >
> > For the above code I have checked assembly output as generated by GCC
> with
> > -O3 optimization on Linux i386. Using literals without type
> specification,
> > the whole routine is done on the FPU (80 bits precision). With the
> literals
> > cast to t_float, it is done with single precision instructions for XMM
> > registers.
> >
> > As far as I can see, casting literals to t_float results in the same
> > assembly output as using the float specifier. For single precision
> > t_float,  '(t_float)0.125' is equivalent to '0.125f'. I can't think of a
> > disadvantage, but let me know if I overlooked something.
> >
> > Katja
>
> > ___
> > Pd-list@iem.at mailing list
> > UNSUBSCRIBE and account-management ->
> http://lists.puredata.info/listinfo/pd-list
>
>
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] [SOLVED] check mail with pd ?

2014-02-11 Thread Fero Kiraly
Hi all,

here i've found a great manual to build pyext:
http://puredata.hurleur.com/viewtopic.php?pid=37639#p37639

in attachement is example og my [pyext gmail.box] object, which can check
and count emails with given 'subject'

fero

try:
	import pyext
except:
	print "ERROR: This script must be loaded by the PD pyext external"
	sys.exit()

import imaplib
import email




mail = ''
user = 'user'
passw = 'pass'
subject = ''
uidsList = ''
data = ''

class box(pyext._class):


# number of inlets and outlets
	_inlets=1
	_outlets=2
  


# constructor
	def __init__(self,*args):
		if len(args) == 2: 
			global user, passw
			user = args[0]
			passw = "%s" % args[1]


 	def subject_1(self, *args):
		global subject
		subject = " ".join(str(e) for e in args)
		print "Subject changed to '",subject,"'"
		#print args

def login_1(self, *args):
		global mail, user, passw
		if len(args) == 2: 
			user = args[0]
			passw = "%s" % args[1]

		print "Logging to gmail as", user
		mail = imaplib.IMAP4_SSL('imap.gmail.com')
		mail.login( user, passw)
		mail.list()
		mail.select("inbox") # connect to inbox.

	def logout_1(self):
		print "Logging out from gmail..."
		global mail
		mail.close()
		mail.logout() 
  
	def check_1(self):
		global mail, subject, uidsList, data
		print ""
		print "Checking mail for SUBJECT ", subject
		tmp =  '(HEADER Subject "%s")' % subject
		result, data = mail.uid('search', None, tmp) # search and return uids instead
		#print data
		str = ''.join(data)
if (len(str)>0):
	uidsList = str.split(' ')
			#print mylist
			size = len(uidsList)
		else:
			size = 0
		
		if(size > 0 ):
			latest_email_uid = data[0].split()[-1]
			result, data = mail.uid('fetch', latest_email_uid, '(RFC822)')
			raw_email = data[0][1] # here's the body, which is raw text of the whole email
		# including headers and alternate payloads
			email_message = email.message_from_string(raw_email)
			#print email.utils.parseaddr(email_message['From'])  
			self._outlet(2,email.utils.parseaddr(email_message['From']))
			self._outlet(2,uidsList)
		#else:
			#print "No emails ;("

		print "Found ", size, "emails."
		self._outlet(1,float(size))
		
		

	def delete_1(self,argv):
		global mail
		print "Deleting mail ", argv
		mail.uid('STORE', argv, '+FLAGS', '\\Deleted')
		mail.expunge()

	def deleteall_1(self):
		global mail, subject, uidsList
		print "Deleting all mail with subject '",subject ,"'"
		for n in uidsList:
			mail.uid('STORE', n, '+FLAGS', '\\Deleted')
		mail.expunge()

	def list_1(self):
		global uidsList
		print uidsList
		
		

#N canvas 591 94 698 581 10;
#X declare -lib py;
#X symbolatom 91 204 40 0 0 0 - - -;
#X obj 91 183 zexy/list2symbol;
#X obj 533 -5 import py;
#X msg 139 69 check;
#X msg 30 12 logout;
#X msg 142 120 delete 16437;
#X symbolatom 204 183 40 0 0 0 - - -;
#X text 89 222 uuids of emails;
#X text 338 198 email adress of newest;
#X msg 150 89 list;
#X obj 24 152 pyext gmail.box;
#X obj 203 161 zexy/list2symbol;
#X msg 13 98 deleteall;
#X floatatom 33 223 5 0 0 0 - - -;
#X text 222 7 1.fill your login data;
#X text 266 37 2.fill with some subject string of your emails;
#X text 260 65 3.press;
#X text 29 243 num of emails with given subject;
#X msg 113 10 login user pass;
#X msg 126 38 subject some subject;
#X connect 1 0 0 0;
#X connect 3 0 10 1;
#X connect 4 0 10 1;
#X connect 5 0 10 1;
#X connect 9 0 10 1;
#X connect 10 0 13 0;
#X connect 10 1 1 0;
#X connect 10 2 11 0;
#X connect 11 0 6 0;
#X connect 12 0 10 1;
#X connect 18 0 10 1;
#X connect 19 0 10 1;
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list