Thursday, September 25, 2014

DMX Lighting Control Application - And Then Some!

There's been a bit of a dry spell around here, eh?  Shifting from the scholastic world to the professional world comes with it's share of changes, and some projects had to be put on hold for a bit.  Let's get back on that horse!

I've always had a love for stage technologies - pro sound, stage lighting, all that good stuff.  Once I got a real job, I was able to start getting some of my own equipment to use on the side - soundboards, speakers, and stage lights.  The next logical step (well, to me anyway) was to use those stage lights in my apartment instead of normal things like lamps.  They're all RGB LED fixtures (that is, each contains red, green, and blue LEDs in an array) positioned on the floor pointing up at the wall, so they give off a nice indirect, diffused glow.  The lights are all controlled via DMX (standard stage lighting control), so logically, I needed to make an application that would control them using a USB to DMX interface.



I started off with a very modular setup from the outset.  I set up a database that allowed for configured Light Types (each fixture has a specific way it needs to be controlled, as certain number of DMX channels it requires, etc), Lights (the actual devices, with their associated Type), Groups of lights, and Scenes (conglomerations of groups and their lighting state, like bright red).  I made a super-simple Windows Forms application to be able to configure all those settings in a tabular format.  Now that I had information about all the lights and their current state when various things happened, I was able to build a 'universe' of information about what value every DMX channel needed to be configured for in the current setup.  Using a USB > DMX interface with an API that plays nicely with C# (http://www.amazon.com/Velleman-VM116-Usb-Controlled-Interface/dp/B001IRMFUW, using K8062D.dll), I was able to commune with the lights to my heart's content.



Except the heart wanted more.  The nest step was to make the application web-accessable so that I could set the lights from my phone.  Obviously.  So, I updated the application to host a REST endpoint that allowed it to load requested scenes.  I then created a simple PHP web page that connected to the database, retrieved a list of all configured scenes, and then displayed them on the screen as big buttons that, when clicked, triggered a call to the application's service endpoint to enact the change.  Simple, and highly effective - my lights were now mobile-friendly!  And I saw that it was good.



And yet, there was something missing.  Sure, it was nice being able to take out my phone and set the lights, but shouldn't they be able to do that themselves?  I added a new tab to my rapidly growing application for Schedule items.  These had information about what Scene should be triggered, at what time, and on what days.  Once set up, my lights turned on a bright white in the morning when I was supposed to be awake (during the week, that is), green when I should start heading out, red when I really-no-kidding-for-realzies need to leave, then turn off when I sure as heck should be out of the house.  They then turn back on a nice bright white just before I get home in the evening, a soothing blue when I need to start heading to bed, and turn off when I should be falling asleep.  And thus, the lights gained a speck of artificial sentience, and my heart was happy for a time.



But alas, one cannot stem the torrent of need from the heart.  Yet another use case presented itself that seemed to be a wonderful fit for my little application.  One of my good friends was getting married, and he asked if I could provide sound and lights for the reception.  Never one to go into something halfway, I added to grant the application the ability to function as fully automated DJ.  I added a new tab to the interface for Songs.  Each song had an associated lead-in and end buffer (to trim out introductions and fade-outs to keep the party jammin'), as well as it's own scene (yep, I made a scene for each song).  These are mostly empty because I cleaned the lists out for everyday use.



Once started, the application cross-fades through each song in the list (using WMPLib.WindowsMediaPlayer objects), fades the lights from one scene to the next, and in general takes care of itself.  It also allowed for skipping and re-ordering songs (which, for those of you who have never played the role of music selection master, happens.  A.  Lot.)  There were a couple minor glitches like songs repeating, but in general, it worked out quite nicely, and allowed me to enjoy the reception as well.



What's next for Moody?  Who knows - the heart is a fickle organ; you can never quite tell what it's going to pine after next.

No comments:

Post a Comment