Geeks making the world a bit better.

Entries Tagged Programming

atool enables DDR pad or webcam input

Atool is an extension to our previous CamKeys project. Like CamKeys, atool allows keyboard input based on a cheap webcam. Atool adds DDR pads (or other game controller buttons) as an additional input and it allows playing recorded sounds on input events.
Continue reading →

Combining WordPress and Flickr to make accessible books for beginning readers

Tar Heel Reader is a web site designed to help teachers make easy-to-read books for children with disabilities. It has a growing selection of books to read and a simple process for creating new books using pictures found on Flickr.
Continue reading →

Creating PowerPoint Slide Shows from Wordpress Posts

For the Tar Heel Reader project I needed to convert very simple multi-page WordPress posts into PowerPoint slide shows. I chose the circuitous route of making an OpenOffice Impress show by bashing XML and then converting it to PowerPoint. I manually created a prototype slide show with a title page and a single book page in Impress and saved it in their native .odp format. These files are simply zip archives containing several XML documents and the images. Why they didn’t include the sounds, I don’t understand. The important file is content.xml. Examining it in Firefox revealed the bits I’d have to change on the title page and for each page of the book. I found several useful hints in a Linux Journal article by Collin Park. I used the PHP DOM module to read in the prototype, update it for the current book (retrieved with the WordPress get_post function), and write it out along with the images. Zipping this result up produces a new Impress presentation for the book.

Then I needed to convert the Impress format to PowerPoint. Thankfully, I found PyODConverter to automate that part of the job. It worked fine when I ran it from the command prompt but I get it to find the server when I ran it from PHP. Again the web came to my rescue with a post by Piero. I’ll reproduce the code here so I don’t forget it.

cd /var/www                                      #www-data user home
sudo mkdir .openoffice.org2                      #create the openoffice working dir
sudo chown -R www-data:www-data .openoffice.org2 #set the owner
sudo chmod 700 .openoffice.org2                  #change permissions
sudo -s                                          #you need to be root
su - www-data                                    #if you want to be www-data

#start openoffice headless
xvfb-run -a soffice -accept="socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" -nologo -headless -invisible

Now I need to figure out how to get this into /etc/init.d so that it will automatically start on reboot.

Wordpress makes a fine application framework

I really like using Wordpress for my website and blog but I hadn’t thought until recently about using it as an application framework. Karen and I talked about a site to enable teachers to quickly build topical beginning readers for people with varied interests and abilities. I began thinking about the features such a site would have and found lots of overlap with what Wordpress already provides. A blog post by Steve Winton over at NixonMcInnes encouraged me to examine the possibilities further.

I’m pleased to report that it is really easy to integrate a PHP web-app into Wordpress. I use ordinary blog posts as the books with the <!–nextpage–> tag for pagination and a bit of Javascript for switch accessibility and text to speech. The book creator wizard is simply a set of pages with custom templates. You select some images, provide some captions and a title, and it creates the blog post that is your book. Wordpress provides logins, all the database manipulation, comments, tags, categories, etc. Redirects work fine because Wordpress is silent until you invoke get_header. Query parameters work fine; Wordpress seems to ignore them. Session variables work fine too. So far Wordpress hasn’t gotten in my way once and has helped a ton.

Tools for classification

Links I found related to classification.

Running Python from within Emacs

Emacs python mode supports running scripts in an inferior python process that is running in an emacs buffer. I really like this idea but have never been able to reliably use it because so much of my work depends on external libraries that may not do a complete job of cleaning up their state. Attempting to reuse them in the same process is, in my experience, a recipe for confusion. Also, emacs seems to be hung waiting on the python subprocess while my GUI app is running. As a result, I always edit in emacs and then switch to a command prompt to run.

It occurred to me that if I my program doesn’t need input (almost all mine have a GUI) I can run them using the emacs compile command. The compile command in emacs is intended for running make and other command-line build tools. The command runs in a separate process and its output is directed to an emacs buffer. I tried it out and it works great!

In my .emacs file I defined this function

(defun my-compile ()
  "Use compile to run python programs"
  (interactive)
  (compile (concat "python " (buffer-name))))
(setq compilation-scroll-output t)

This function invokes compile with python foo.py when I’m editing a buffer named foo.py. The setq makes the compilation buffer scroll to follow the output.

And then in my python-mode hook function I added:

  (local-set-key "\C-c\C-c" 'my-compile)

This binds Ctrl-C Ctrl-C to compile instead of the usual eval-buffer which I never use anyway.

Now I can edit and type Ctrl-C Ctrl-C to run. If my program raises an exception, I get a traceback in the emacs buffer. emacs parses the buffer looking for error messages. It notices the File lines in the trace back and sets them up so I can click on a filename to visit the file and line associated with the traceback.

I’m loving this! No more directing my program output into a file when I’m printing tons of debug messages. No more constant Alt-Tab to switch between emacs and the command prompt.

I’m using it on Ubuntu, but a quick test indicates this works on Windows also.

Building aubio for windows

What I tried, so I can reconstruct it later.

Install cygwin. Change the Devel category from Default to Install in their setup tool.

Download libsndfile, extract, configure, make make install.
Download libsamplerate, extract, configure, make, make install.

Download aubio and extract it.
cd into its folder

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure --disable-shared
make
make install

Raw Input API

Meg pointed out the Raw Input API for Windows. This would allow us to distinguish among multiple mice and keyboards. It might be interesting to use multiple numeric keyboards as specialized input devices, or multiple mice to provide 2 or 3 switches per hand.

Making CVtypes work on the Mac

I’m writing this down because I don’t see complete working (for me at least) directions anywhere else.

  1. Install xcode from the Mac OS X install CD
  2. MacPorts (everyone calls it DarwinPorts)
  3. Get and unpack the opencv source tarball
  4. cd opencv; mkdir build; cd build
  5. ../configure CPPFLAGS=”-I/opt/local/include” LDFLAGS=”-L/opt/local/lib” –without-python
  6. make
  7. sudo make install

I also needed the macam webcam driver to use my Logitech webcam. I believe the notebooks have a camera built in so you should be good to go on one of those.

I’m getting tons of error messages like these as my app is running and I’m only getting about 5 frames per second. What’s up with that?

2008-02-14 09:00:23.983 Python[85901:6d37] *** Break on _NSLockError() to debug.
2008-02-14 09:00:24.179 Python[85901:880f] *** -[NSLock unlock]: lock ( '(null)') unlocked from thread which did not lock it

Also, I note that video doesn’t start until I move the mouse. Are these macam bugs?

Bringing OS X compatibility to our apps

I regularly get requests from teachers at schools that are Mac based for versions of our software that will work for them. I want every kid to have access to our stuff so I bought a Mac mini for development. I’d rather be running OS X in a virtual machine but Apple won’t let me do that. So I’ve got the mini sitting here with its video out connected to one of the inputs on my right projector and I hacked a python wrapper for synergy server to switch the projector source when I move the mouse off my Ubuntu desktop onto the mini. It works great. Combine that with MacFusion for file sharing and routing the mini’s audio output into the line-in on my Ubuntu machine and it is just about as good as a VM would be.

Pygame seems to work fine on the mini so most of what I need is there. Good deal.

But it sure is frustrating to try to get anything else going. First there is hardly any information online. What I find is often out of date and useless because so much seems to change from release to release. Then when something doesn’t work I don’t know who to ask. In contrast on Windows or Ubuntu there are huge and active communities of hackers like me who 1) figure stuff out and 2) write it down where Google can find it. The problem is usually culling through millions of results. On queries related to OS X the problem is I get 5 hits, 3 of which are asking the same question with no answer. The documentation at Apple is horrible and either not indexed by Google or not indexed well. I seriously don’t know why software developers put up with it. I guess they like being pioneers. I just want to get the job done…