DMP Photobooth: On the Road to 2.0

It’s been a busy few months for me, and things have been quiet here. Quiet, but not forgotten; big things are in the works! What big things you ask?

Back in June, I reflected on DMP Photobooth. The completion of the photobooth was a major accomplishment for me: it worked perfectly (dead camera batteries and jammed printers aside) for a good six hours, and was a hit with the guests! However, like many things in life, it has problems. On my list of things to fix are a wonky UI, and an aggressively imperative code style.

A few months of reflection later, and I’ve had time to consider these issues. I thought about why I wrote DMP Photobooth. Aside from saving ~ $1,000 on renting a photobooth, it was really an opportunity for me to truly explore the C programming language.

While I had some experience with it, it was mostly in an academic capacity. Writing linked lists and trees and such is one thing, creating a real program is another entirely. DMP Photobooth gave me a chance to truly do something with it. Having implemented a non-trivial application in it has given me an appreciation of the strengths and weaknesses of the language. I’ve seen what’s easy, and what’s hard. I’ve made questionable design choices, and attempted to fix them. I’ve made good design choices that made my life easier. I can truly say that I’ve been there and done that.

But let’s be honest with ourselves: C wasn’t really an appropriate choice for this sort of program. Java, Python, or something along those lines really would have been the correct choice. But where’s the fun in that? However, now that the project is “complete” its time to find a way forward. C no longer has the allure for me that it once did, and since my customers include me and my wife, I feel confident that a re-write won’t lose me any business.

That’s right: DMP Photobooth is being completely re-written. Version 2.0 will be re-implemented in Haskell. However, this doesn’t mean that I have to completely walk away from all the work I did. Early versions will likely use the original Camera, Printer, and Trigger modules via FFI.

Why re-write? I thought about it for a while, I’ve wanted to do something with Haskell to cement my knowledge as I did with C, but I was lacking inspiration. Since DMP Photobooth was really a playground to explore C, why not do the same with Haskell? It seems like a logical choice, implementing a non-trivial application in Haskell will cement my knowledge in the same way it did in C. Additionally, trying to solve the same problem in a different way will give me an appreciation of the pros and cons of each approach.

Change in the Wind

So, surely this isn’t going to be a one-to-one port of DMP Photobooth to Haskell, right?

With this new version, I am making some fundamental changes to the program. Probably the biggest change is the elimination of runtime loading of modules. In 2.0, all modules will be set at compile time. I feel that the machinery of loading and operating modules at runtime was a bit wonky. Too much effort was put into “not restricting a module developer’s freedom”. In 2.0, modules will in place at compile time, and they will be treated as a first-class part of the program.

This isn’t to say that the module concept is going away. In fact, it is being expanded. There are now six total modules. The Camera, Trigger, and Printer modules return in 2.0; but the Photostrip, Persistence, and Interface modules are new in this version. The original modules will continue to work as they did, but let’s discuss the newcomers.

Interface

The interface is fairly straightforward. This module is responsible for the user’s interaction with the program through the computer. Triggering the capture process will still be the trigger module’s domain, but anything that appears on the computer monitor is the domain of the Interface module. All log messages generated by the program will be sent to the Interface module for presentation to the user. Additionally, the Core will provide callbacks to the Interface that the interface will be responsible for enabling the user to call these. There will no longer be a concept of “starting” or “stopping” the photobooth; the photobooth will start when the program starts, and it will stop when the program exits. However, the interface will likely be responsible for allowing a user to print a previously processed strip, alter the configuration, and close the program.

Photostrip

Another fairly self-explanatory module. This module encompasses all the functions that were previously defined in photo_strip.c. In 2.0, the use of temporary files will be limited, therefore all images will be passed in ByteStrings.

Persistence

Of the three new modules, this one is probably the most novel. This module’s responsibility is persisting data between invocations of the program. This will include at the very least program configuration, but it can also include things like log history or even photo sessions. All modules will be given hooks into the persistence module, so they can persist and restore anything that they see fit.

The functionality here closely resembles that of configuration.c. It will work in a similar way. I have defined the following data type:

data Property = IntProperty {propName :: String, intValue :: Integer} | StringProperty {propName :: String, stringValue :: String} | DoubleProperty {propName :: String, doubleValue :: Double} | BoolProperty {propName :: String, boolValue :: Bool} | ListProperty {propName :: String, listValue :: [Property]} deriving (Eq, Show)

The persistence module will be able to persist and restore this data type. The modules can store anything in this, including arbitrary types if they are instances of Show and Read. This list of types will probably change over time, but its a good start.

The Way Ahead

Its going to be a long road to 2.0, but as the project progresses, expect to see updates here. The codebase for DMP Photobooth has been uploaded to GitHub, and can be found here. Version 1.0’s repository has been renamed to dmp-photo-booth-legacy. I have no plans to take this version down, so it should remain available for the foreseeable future.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: