Home Automation EZine
Volume 3 Issue 2
April 1998

Features
HEADLINES
Uncle Phil Part VIII
Not your father's remote control!
Speaker Wiring?
Adcom - The Ball
Almost Automated Home Theater
CHAC  & Homation
MediaCenter  Software
TVMessenger
International  HA
Home Theater  Control
Sweet Automated Dreams
MultiZone PreAmp

Columns
EDITORIAL
CEBus - Brian Baker
Dave Rye on X-10
Home Theater
What We Need Is ...
Letters to Home Toys
Event Calendar

Home Automation Products & Services

Reviews
Marantz RC2000 MKII

Current Issue
EZine Archive

Return to Main Menu

 

HTINews Article
- Apr98 -
[HTI Home Page]
Read All About It
News Announcements - Updated Hourly
[Click Message To Learn More]

MediaCenter : A Simple Home Entertainment System For Your PC
by Jonathan Somers

"From a home automation perspective MediaCenter is a great way to get started because you don’t need a lot of fancy, expensive equipment to use it. If you have a PC with a sound card and a modem (odds are that you do, since you’re reading this) then you have all the equipment you need."

When he is not debugging the voicemail system at his house, Jonathan Somers is either enjoying a quiet life with his wife Jan and their
two daughters, or he is pursuing a bachelor's degree in computer science at the Georgia Institute of Technology. He also occasionally finds time for his regular job in the Mobile Computing Group of The Coca-Cola Company, helping consumers get their soft drinks a few seconds faster.

www.mindspring.com/~jons 
jons@mindspring.com 


In the Domisilica research group at Georgia Tech, one of our challenges is finding ways in which students can explore home automation when "home" is little more than a dorm room. When the lighting, climate control, and security are completely out of your hands, what can you do?

It turns out that you can do some of the most interesting applications in this limited space. We created the MediaCenter for exactly this purpose. MediaCenter is a simple application that combines a CD player, a wave player, and a speech synthesizer. There are no fancy features in these three components; most commercial programs offer much greater functionality. What MediaCenter offers is programmability. You don’t like the way it behaves? Get inside and write some code to change its behavior. With a few simple lines of Visual Basic – or Visual C++, or just about any programming tool you choose – you can tailor the MediaCenter to suit your own tastes.

From a home automation perspective MediaCenter is a great way to get started because you don’t need a lot of fancy, expensive equipment to use it. If you have a PC with a sound card and a modem (odds are that you do, since you’re reading this) then you have all the equipment you need. This is the appeal in the student population, because while students at Tech don’t have fancy houses, they are all required to own computers. Once you get your feet wet, you’ll be thinking of new ways you can use your PC by adding just one or two little components at a time. Before you know it, you’ll have an automated home making your neighbors green with envy.

About the application

Before I begin to describe it, I should probably let you know how to find it. You can download a copy of MediaCenter from my Web site, at www.mindspring.com/~jons/downloads/MediaCtr.zip. Inside you will find the MediaCenter.exe application, a short readme file, and a .TLB file which is useful for C++ programmers (more on that momentarily). You can unzip the program anywhere you like; there is no rigorous installation, and the program installs its few settings into the Windows registry the first time you run it. (No rebooting necessary!)

If you do not already have the Microsoft runtime libraries on your machine, MediaCenter will complain and tell you exactly what is missing. You can download these from my site as well, at www.mindspring.com/~jons/downloads/mfc.zip. These need to be unZipped into one of two places: the directory where MediaCenter lives (okay) or your windows\system directory (much better for sharing amongst one and all). MediaCenter is a Win32 program and, as such, requires Windows 95. It should work on 98 and Windows NT as well, since I don’t use any OS-specific features – but I haven’t tried it. If you do and you encounter problems, let me know – I’ll try to put it straight for you.

wpe3.jpg (19523 bytes)

As mentioned, MediaCenter is a three-part application. The top third of the window is devoted to a CD player. The CD lacks some of the more esoteric features like shuffle play or named tracks, but it gives you the basic functions everyone needs: play, pause, track forward and reverse. I sometimes get frustrated with the track reverse button on most other CD players, so I changed the behavior slightly in MediaCenter. If you are within the first few seconds of the beginning of a track, the track-reverse button still takes you to the previous track. Once you are well within a track, track reverse takes you to the beginning of the current track. A small detail, perhaps, but very convenient.

MediaCenter does offer a disc loop. Most people will use it for music playback, but we also wanted to experiment with ambient sonic environments. The disc loop lets us play endless rounds of ocean waves, rainforests, and other ambient sounds. More on this in a moment.

The center third of the display represents the wave player. MediaCenter lets you browse and play any Windows .WAV file. Again there is a loop capability, so that long wave files can be played endlessly. Wave files can be used several different ways in home automation. They can be used to replace conventional sounds in the domicile; for example, you can turn off the ringers in your real telephones and watch your modem’s ring-indicate signal to play a custom phone "bell" file (which you can change with your mood, the time of day, or whatever). Furthermore, wave files can be used to signal interesting events such as the arrival of email or the presence of virtual visitors. This last application is very useful when combined with ambient CDs; I will discuss this in the programming section.

The lower third of the display is a speech synthesizer interface. If present, MediaCenter will make use of the Monologue for Windows speech synthesizer, which shipped with the original generation of Sound Blaster 16s. This lets us substitute generated speech for audio icons when an interruption is required. If you have more current hardware, and if you are willing to register your copy of MediaCenter, you can get an enhanced version which also supports the TextAssist voice synthesizer shipping with today's Sound Blasters.

A few words about OLE Automation

My house is automated with a number of Windows programs I’ve written. All of them support external programming via Microsoft’s OLE technology (in one form or another). The simplest form of program control is OLE Automation, which is what MediaCenter uses – making it an ideal first project for your custom home automation programming.

A note on case: It is very inconvenient for us home automators that Microsoft has chosen the name "OLE Automation" for it's programming control technology. Microsoft’s marketing geniuses love to change names just to make yesterday’s tools sound like the latest gee-whiz feature; we used to deal with OCX controls, which then became OLE controls, which then became ActiveX controls… Unfortunately for us, OLE Automation missed out on this fad and still goes by its original name. So, now and henceforth, if I use the lower-case "automation", I’m referring to the craft of controlling one’s home. If I capitalize it to "Automation", I’m referring to OLE Automation.

Basically, OLE Automation is a means through which one program can "drive" another. Depending on how the driven program (the Automation "server") is written, the driving program (the Automation "container") may be able to press every button, choose every menu, and operate every control it pleases.

The nice thing about OLE Automation is that many, many tools can use it. You can use Visual Basic, Visual C++, and most any other Win32 programming language. (C++ programmers will need to create a proxy class from a Type Library file - the .TLB file I provided in the original ZIP. VB folks can ignore it, however.) You can also use the scripting language in many commercial programs. For the sample program I describe in this article, I’ll use VB; in future articles I will use other tools.

MediaCenter lends itself to Automation because it is simply taking dictation. It has a very simple server interface that lets you "press its buttons" from other applications. Other types of programs, such as X-10 controllers, may not be great choices for OLE Automation; a controlling program may want to get notifications of interesting events which originate from the controlled program (such as an incoming X-10 command from a controller elsewhere in the house). ActiveX controls support this functionality, and we’ll talk about them in upcoming articles.

Programming the MediaCenter

By itself, MediaCenter is an unremarkable program. Its main virtue is its ability to be controlled by other programs. I’ve already mentioned one possible application: replacing your telephone ringers. You can change wave files based on time of day or the mood you’re in. The time of day feature is a nice way to get a feature usually present only in homes with expensive PBX’s: automatic night mode, so you won’t be disturbed while you’re asleep. If your modem supports Caller*ID, or if you have a Caller*ID box with an RS-232 output, you can have the voice synthesizer announce who is calling. If you have an X-10 TW523 controller on your PC and you put a dry contact sensor on your doorbell, you can play various .WAV files for your doorbell (again based on your mood or on the time of day). And so on.

The reason for adding .WAV support is to superimpose sonic icons onto an ambient environment. If MediaCenter is playing an ocean waves CD, for example, and an email arrives, you can program MediaCenter to announce the incoming email with the wave file for a foghorn. If you’re not paying close attention, the foghorn blends directly into the overall ocean soundscape. Normal priority emails could produce foghorn "icons" while a high-priority email could trigger speech announcing the sender and subject. You could also write filters to signal the arrival of messages from certain individuals (perhaps those in your address book) with a spoken announcement. The distinction between awareness and attention is useful when trying to reduce the number of interruptions in our daily lives.

Let’s walk through a very simple application program that always gets the "wows" from guests: pausing the CD player whenever the phone rings. Just a dozen or so lines of VB code is all it takes. I’m no VB whiz, but I whipped up this sample application using VB 5.0 in a few hours – and you should be able to duplicate it in a lot less, since I’ve already made the mistakes for you. If you’re using a different version of VB, MediaCenter should still work, but you may need to follow a different sequence of steps to get there.

  1. Start Visual Basic. Create a new Standard .EXE, and immediately save it as PhonePause.
  2. Set the name of the main form, and its caption, to PhonePause.
  3. First things first: If you want to trigger an event when the phone rings, you need to learn about the ring from your modem. Go to the Project menu and select Components. On the Controls tab, check the box for "Microsoft Comm Control 5.0" and then press OK. A telephone and modem icon should appear on your tools bar.
  4. Select the phone/modem tool and draw a modem object on the lower-right corner of your main window. (This object will be invisible at runtime.)
  5. In the modem object’s properties, set the name of the object to "Modem" and set the comm port to the port on which your actual modem lives.
  6. Set the DTREnable and RTSEnable properties to True, and set the Rthreshold to 1. This will allow your program to receive strings from your modem; we will be watching for the "RING" strings.
  7. Set the Handshaking property to 2 – comRTS.
  8. Double-click on your Modem object, and enter the following code for its OnEvent method:

    Private Sub Modem_OnComm()
        Select Case Modem.CommEvent
            Case comEvReceive ' Received RThreshold # of chars
      
             Instring = Modem.Input
             If InStr(Instring, "RING") > 0 Then
                  MsgBox ("RING")
             End If
        End Select
    End Sub

  1. Now double-click on your main form, and enter the following code for its Load method:

    Private Sub Form_Load()
         Modem.PortOpen = True
        Modem.Output = "AT" + Chr$(13)
        ' Wait for data to come back to the serial port.
        Do
            DoEvents
        Loop Until Modem.InBufferCount >= 2
        ' Read the "OK" response data in the serial port.
        Instring = Modem.Input
    End Sub

  2. This is a good stopping point to make sure your program is working so far. Run the program and call your modem; you should get a message box every time the phone rings.
  3. Now let’s pull MediaCenter into your application. For this to work, you must have run MediaCenter at least once so that Windows knows where to find it. First create the MediaCenter object at the application’s General level:
        Dim MediaCenter As Object
  4. Back in your main form’s Load method, add the following lines at the top:
    Private Sub Form_Load()
        Set MediaCenter = CreateObject("MediaCenter.Application")
  5. Now let’s pause the CD player and play a wave file whenever the phone rings, and get rid of that silly message box. In your modem’s OnComm event, change the message box to:
            If InStr(Instring, "RING") > 0 Then
                MediaCenter.CdPause
                MediaCenter.WavePlay ("c:\windows\media\ding.wav")
            End If
  6. Presto! You’re done. You can substitute any wave files you like, add radio buttons to the main window to decide when to pause or not pause, and so on. Customize to your heart’s content.

Wrap-up

It’s true that MediaCenter alone is a very uninteresting application. I view it as a valuable springboard. Folks who are just getting started in programming can find life very difficult and not particularly rewarding. Tools like MediaCenter let you get very fast results – and some well-deserved gratification. More importantly, they let you work towards the dream automation system that does everything you want it to do.

I haven’t closed the book on MediaCenter. It is a constantly evolving program. Do you find that it still doesn’t do exactly what you like? Drop me an email at jons@mindspring.com and let me know. You may find that badly-needed feature in the next release, and if your request is a new and useful one, you may just wind up with a registered copy at no charge. If you come up with a really interesting use, email me and let me know – I’d love to describe it on my Web site, and if you want to share your code with others, I’m happy to add a pointer to your files as well.

What if what you really want to do is control real CD players – or radio tuners, televisions, VCRs, and so on? Take heart. I was in the same boat once upon a time, and so I wrote an infrared remote application which you can also program via OLE automation. That’s my topic for the next issue.