Static Events for Decoupling Communication Between Classes/Forms/Controls in C#

So I’m new to C#, but I have to admit that the ‘simple’ examples out there really aren’t simple and they really don’t cover what I would consider to be the most common use for events: Communication between forms and controls without having to resort to directly linking one class to another. I’ve been using Cairngorn Events/Delegates for awhile now in Flex/ActionScript3, so I’m not coming at it from a complete novice standpoint. But it seems every example I could find only showed how to raise and use events within the creator of the event. None of them showed how to use events to decouple, or reduce the linkage and increase the usability of your code.

So here goes: Imagine if you will, that you have several forms on your application and you want to allow the user to exit from any of them, while still doing that last minute clean up like saving any data or config, etc. ( I realize there is a way to do this using the Application event handler, but this technique applies all over the place, and this example is easy to understand.)

So first you want to create your event class. I put mine in a handy folder called Events in my C# project.

using System;

namespace Demo.Events
{
    // Declare a delegate for an event.  
    public delegate void ExitAppHandler(object sender);

    // Declare an event class. 
    class AppExitEvent
    {

        public static event ExitAppHandler evtExitApp;

        // This is called to fire the event. 
        public static void OnExitEvent()
        {
            // ok so this calls the handlers we have +='d to listen the event
            if (evtExitApp != null)
                evtExitApp(null);
        }
    }
}

OK, so this sets up a separate event class that has a static handler variable and a static method. This is the glue between our classes. Now we can reuse a form that calls this event, without having to worry about any other code.

Now we want to listen to this in our forms that want to do something when this event is triggered.

namespace Demo {

    public partial class Demo : Form
    {

        public Demo()
        {
            Events.AppExitEvent.evtExitApp += new Events.ExitAppHandler(this.ExitEventHandler);
            InitializeComponent();
        }

        // An event handler. 
        private void ExitEventHandler(object sender)
        {
            // TODO: Do cleanup/save/etc
            this.Close();
        }
       }
}

This could be your main application form for instance, with a lot of other stuff going on in this class, like adding controls, etc. Multiple forms that need to respond to the exit event would simply do the same thing: Add Events.AppExitEvent.evtExitApp += new Events.ExitAppHandler(this.ExitEventHandler); to their class/form, along with an ExitEventHandler method.

Now all we need to do is show another form/control/class calling this as well. In my case, this is a custom toolbar, or a sub form’s right click menu:


namespace Demo
{

    public partial class Caller : UserControl
    {

        public Caller()
        {
                      // If you wanted to have this form respond to the exit event as well, you could simply uncomment this
                     // Events.AppExitEvent.evtExitApp += new Events.ExitAppHandler(this.ExitEventHandler);
                 InitializeComponent();
        }

                //  this is in response to a button click NOT SHOWN
        private void pbExit_Click(object sender, EventArgs e)
        {
            Events.AppExitEvent.OnExitEvent();
        }

    }
}

And finally, we show how to call this static event: Events.AppExitEvent.OnExitEvent();

This is called in response to a button click, that button not shown in this example, but you should hopefully get the idea. I’ve also shown commented out, that this other form could also be a consumer of the same exit event if you wanted.

That does it! I needed another similar event to occur when I minimized the app, and when I wanted to open a popup form from a number of different locations, so this technique is very useful.

Obviously, the above example doesn’t really show how to pass additional info with the event, like mouse coordinates or other data.

To do that you would need to create a class derived from EventArgs (CustomEventArgs let’s say) that held your custom data, and change the declarations to add in your custom event args. The existing examples out there show this aspect pretty well.

Posted by slaingod Thu, 21 Feb 2008 02:02:00 GMT


Why the iPhone is Destroying Windows Mobile in the Market

Ok, so this post is a little premature, but it just has to be said.  The reason the Windows Mobile (WM) is dying on the vine lies firmly on the shoulders of the .Net Compact Framework( the C# library used for many application ) and the main WIN32 CE  API in general. Now this is a little unfair of a characterization, because Apple has yet to release its SDK for the iPhone, but it is obvious that it is running a real OS.  So many things have been stripped out of the Windows Mobile OS, that it is an effort in frustration to do even the simplest things.  The documentation is a nightmare as well, with everything from the full .Net Framework listed with the Compact stuff, and there are no/few examples. To be fair also, as with all Microsoft products, backwards compatibility is always one of the main skeletons in the closet.  WM has been around for 10 years now, and that legacy, along with the WIN32 legacy in general, has really held it back. But there is also this sense that they said: “This is what we think you should do, so we won’t give you any other way.”

Here is a hit list of issues that I’ve come across:

  • There is no Rich Edit control, only a RichInk control.  And for some retarded reason they decided not to support full justification in the RichInk control, so almost no WM apps do either, from PocketWord on.  This means if you want justified text (like for an eBook reader), you have to roll your own.  It would have taken maybe another 100-200 bytes to support it.
  • Little transparency support.  Any decent design takes advantage of transparency these days, and I am spending an hour googling trying to figure out why my toolbar buttons look like shit.
  • No animation support.  Think Flash here (move button A to X,Y over 1 second and add a drop shadow) .  I imagine that Vista Aero has some better animation now, but WM has none. 
  • Just plain missing API calls, like OemToChar, and some other Unicode/Wide character support.  I’m trying to compile an unrar DLL for WM and it just isn’t pretty, even though unrar doesn’t use much craziness.
  • The WebBrowser control is completely crippled.
  • And because it is all closed source you can’t see a damned thing about how it is done. This would solve almost any problem out, there, making the Compact Framework source viewable so you could make your own versions without having to start from scratch. [Updated: I have since discovered that you can look at a lot of the underlying NETCF (and .NET Framework in general) source code using .NET Decompilers like Reflector.

I have a C/Win32 API app I need to modify, and I would like to port it to C# but it is turning into a nightmare. And of course I would even consider getting an iPhone once the SDK comes out if they had a Verizon version, but I get no GSM reception in my apartment in NYC. I’ll keep you posted.

UPDATED: So I’ve gone ahead and just started from scratch with my project (an eBook reader), in C# NETCF v1.0. I’ve got pagination down within 30 seconds for a 300 page paperback on a mobile device, and it now does full expand/squeeze justification of the text.

Posted by slaingod Mon, 18 Feb 2008 14:26:00 GMT


Put Your Monitor To Sleep at the Press of a Button (Windows)

Here is a little AutoIt script I found while trolling their forums that will put your monitor into sleep mode at the push of a button.  Both the script and a compiled EXE version are included, so you don’t have to install AutoIt to use. I put a shortcut to the script into my QuickLaunch bar, then changed the icon to the power button icon, and now whenever I am done with my computer for the time being I can press this button and my monitor goes off right away!  There are plenty of other shareware, etc. tools out there to do this, but this one is so simple, it’s basically a single line of code. I grabbed this off of the AutoIt forums, and commented out some of the existing code.  That code originally would turn off the monitor after 10 seconds of non-use (which is usually useful in a Network Operations Center but not much else).

 

Download the script!

Posted by slaingod Thu, 14 Feb 2008 13:13:00 GMT


Why I Still Use Windows

So I’ve thought more and more in recent months about why I still use Windows, as opposed to Mac OSX or Linux.

In my grand tradition of bulleted lists, here are the main reasons I am sticking with Windows currently:

  • Newsleecher: Best USENET client period. I could give 2 shakes about the Supersearch feature, but for raw indexing speed, download speed, unRAR and PAR checking, etc., Newsleecher has no competitors.
  • uTorrent: Best BitTorrent client period, though I could probably find a suitable replacement on OSX if necessary.
  • mIRC: Best IRC Chat client out there, though I could probably find a suitable replacement on OSX if necessary.
  • Microsoft Office VBA (Visual Basic for Applications): I have a number of VBA macros/forms for Word I’ve created over the years that I use. I believe that some older versions of Mac Office may have VBA support, but have never looked into it.  I’ve tried out Open Office, and it just doesn’t have everything I need or look as nice as Office 2k7. I know a lot of people hate the new Ribbon interface, but I actually like it.  With just a couple of customizations, I rarely have to leave the ‘Home’ ribbon now to do anything.
  • Abbyy FineReader OCR/Omnipage Pro: Still the best  platform for OCR period. 
  • HP Scanjet Drivers: For some reason my ADF scanners drivers cost $10 to get a CD from HP for OSX. Retarded.
  • Directory Opus: The best file manager on the planet. Hands down.
  • G-Force Visualization Software: The best audio visualization (trippy lights) software on the planet.
  • Hardware selection: I build my own systems from the various parts suppliers out there for cool and quiet yet powerful systems, such as custom cases, top of the line motherboards, good memory, etc.
  • Occasional gameplay: Windows is still king when it comes to games. Wine/Cedega may be usable, but that isn’t enough for me.
  • Overall familiarity: I just have a lot more experience solving problems on Windows than on Linux/OSX.
  • No official support for my Logitech diNovo Edge.  Supposedly most features can be made to work in OSX using ControllerMate, but I haven’t seen mention of the scrolling features, which would be a deal breaker.
  • It is nice that TV Guide data is built-in to the Media Center (though obviously it is also theoretically built-in to the price of the Windows).

Updated:

  • AutoIt automation script language: a great way to do some things people never intended you to do with their programs…I’m sure there are others out there that do the same, but AutoIt is a great piece of software that can do almost anything, even if the code is a little ugly at times.

 

I would like to get off of Windows for a number of reasons:

  • Tabbed consoles/command lines: Windows doesn’t support tabbed command line prompts properly
  • Cost/DRM: Windows is getting more and more expensive and paying for a product laden with restrictive DRM is counterintuitive. I don’t trust Trusted Computing initiatives.
  • Virus whoring: Windows just has more security issues than I would like.  I haven’t had too many problems personally, but the way things work on Windows, it is too easy for garbage to get into the registry/startup folder/services that you don’t want or need.

It is possible to run OSX on typical Windows hardware if you are resourceful. This would almost certainly be more palatable to me than Linux:

  • Nicer interface than say Ubuntu, although the gap is narrowing.
  • All of the benefits of Linux software generally (through MacPorts).
  • Adobe CS3 Products: Flash, Photoshop mainly… It might be possible to use these with Wine on Linux but I just couldn’t trust critical developer apps to Wine at this stage.
  • True Microsoft Office, although the latest Mac Office gets rid of VBA support, so there is a limited timeframe of say a couple of years before the one with VBA becomes completely outdated. Again, MS Office is supposed to work in Wine, just not sure I would trust it completely.
  • Non-alpha version of Adobe Flex Builder (though this will obviously get better once it reaches full release build, but I’m just not sure how committed they are to a Linux Flex Builder).
  • Safari:  I use Firefox almost exclusively because of Firebug, but being able to test on Safari is helpful as a developer.
  • G-force Visualizer: Apparently there is a Mac version.
  • Drivers are at least available for my HP Scanjet scanner, even if they do cost $10.

In either OSX or Linux, I could set up my system to be Dual bootable, meaning I could say put aside 20-30GB of harddsisk drive space just for installing Windows and a couple of apps or games that I needed to use occasionally.  Or I could look further into Parallels/VMWare on OSX which let you run full Windows applications inside a ‘virtual machine’, typically with better compatibility than Wine, though with lower performance historically. I have a dual boot MacBook now, and it spends about half its time in Windows XP simply because my Vista x64 doesn’t support my HP Scanner.

Maybe when I get a free weekend, I will look at putting OSX on my Windows hardware, just to try it out. And I do have multiple systems, so I could leave one as Windows and move the others as needed.

 

Posted by slaingod Fri, 01 Feb 2008 13:28:00 GMT


Western Digital Caviar GP 500GB 5400 to 7200 RPM SATA Hard Drive

So I needed a new hard drive for my mp3’s and went to my fav site newegg.com, since they deliver next day in NYC from Edison NJ for most items for free or with just standard shipping. I found a new class of hard drives (if you consider one to be a class), that I decided to give a whirl, the new Western Digital Caviar GP WD5000AACS 500GB 5400 to 7200 RPM 16MB Cache SATA 3.0Gb/s Hard Drive. In general, I am not looking for the highest performance from an mp3 hard drive, and most of my hard drives in general really.  What I focus on is cool and quiet operation, and reliability.  Man, is this thing cool and quiet!  It uses a lot less power since it can spin down to 5400 rpm, and essentially feels room temperature when running at 5MB/s when transferring my collection over the network.  It can ramp up to 7200 rpm if it gets under serious load, but I doubt I will stress it too much with my usage patterns.  I’ve had problems with drive heat in some of my recent drives, a just had to RMA my Maxtor MaxLine 500GB drive that started developing the ‘click of death’.  This drive only comes with a 3 year warranty, though that is much better than the standard 1 year warranty of a couple of years ago from most consumer grade devices.  That was why I originally switched to MaxLine, as they had 3 year warranties back when everyone else had 1 year, and now they have 5 year warranties.  But this thing is so much cooler and quieter (less vibration), that my gut instinct says it should fare very well. The only other thing I’m not sure of is if this drive is suited to be used in a hardware RAID setup.  Seems more and more drives come in ‘RAID’ editions these days, or you may need to upgrade the firmware, etc.

Drive noise, and drive cooling fan noise is a major contributor to overall system noise in many cool and quiet designs.  Cool and quiet is important for me, as my main system is in my bedroom.  This thing is sitting right next to me in a usb enclosure and I can’t hear a thing. I’ve never really used Western Digital drives, though for speed I know the Raptor is the best out there.  They certainly got it right with this drive.  And the price is the same as regular 500GB hard drives, so you don’t have to pay extra for the privilege.

UPDATE: It’s come to my attention that these drives are simply 5400RPM, not some hybrid speed changer.  That said, these are still green, quiet drives.  While you might not want to use them for a system disk, they are great for anything else that would actually need 500GB, like videos/mp3/downloads/etc.

 

Posted by slaingod Tue, 22 Jan 2008 19:00:00 GMT


Docuverse: Idea for Peer to Peer Anonymous Document Repository

So in my dealings with various document communities out there (first rule of Fight Club = Don’t talk about Fight Club), I see a huge inefficiency out there, and single points of failure.  This has led me to the think about ways in which these various problems could be solved.  Here are the main problems with these communities I see:

  • Format proliferation: Everyone has a favorite document type they want for their particular viewer/reader application. HTML, TEXT, RTF, DOC, PDB, LIT, etc. 
  • Versioning Issues: Many times these documents are flawed when initially released and require iterative improvements.  And while many documents adhere to the community standard version rules (which are themselves pretty lax), many do not.  So when combined with the format proliferation mentioned above, it can be challenging to find the best version of a document out there, and clogs up hard drives with all of the various versions. Both this and format proliferation also increase the time it takes to search for and retrieve the document the user wants.
  • Single or few points of failure: Many documents that are older no longer get served by many of the community members, or if those members decide to no longer be involved in the community, whole swathes of documents may be lost.  While there is a certain level of redundancy built in to the system, it is not the type of redundancy that leads to a long-term healthy document library. Also, in many cases there are choke points for document distribution.  There are several brave and dedicated souls who contribute the bulk of the effort and bandwidth required to provide the  document library maintenance and distribution capability. But this leads to longer download times and strain on these ‘backbone’ users.
  • Proofing Effort: Again, because of the release cycle and existing methods, there is a barrier to entry for new and less dedicated users to contributing to the community by editing flaws found in the documents. Ideally, as each and every reader was reading their document, they would be able to easily indicate corrections, that would then propagate to the rest of the community without having to deal with the whole verisoning/format/duplicate files issues.
  • Lack of Anonymity: Due to the nature of some of documents, there may be liability if any individual is recognized as the creator/distributor of the document, so creating some sense of anonymity would be preferable.

So my idea is to create a p2p application that incorporates solutions to these issues, while hiding much of the complexity needed to solve them.

  • Create a standardized, extensible format (XML based presumably) for document encoding. Provide converters for all of the major file types, with user customizable styles, so when files are released they can be converted to the user’s contentment. Provide for all standard document entities and formatting, as well as the aforementioned extensibility to allow for more arcane formatting innovations. 
  • Provide for Wiki style versioning of these documents, where anyone may be allowed to edit a document for corrections, but that the entire history of corrections is preserved so that malicious edits can easily be reverted.  Limit edit size and frequency to prevent mass malicious corruption.  Create a voting/approval system whereby corrections can easily be undone for any malicious edits on a mass level.
  • Create a giant massively redundant distributed and encrypted database to store these encoded documents.  Users would be required to provide a minimum amount of shared space on their hard drives to store file indexing information and database storage (say 1GB minimum).  Many ‘power users’ would obviously provide much more space.  Most document communities are around the 1TB range.  Ideally, many users providing 100GB or more of storage would allow for redundancy on the order of 10x.  Users would not know which files/portions of files they were hosting.  Popularity would be used to provide more redundancy for those files requested by many users, while still maintaining a certain level of redundancy for unpopular files or for users entering and leaving the peer group.   This would avoid the problems of other p2p communities hopefully, where files may be available shortly after release, but quickly disappear if not for a few dedicated seeders.
  • Provide for decentralized pseudo-anonymity where all file requests would be delivered through an intermediary user, who acted strictly as a conduit for that request.  This would double the bandwidth requirements for the system, but should fall well within the realm of acceptability considering these are mostly text documents, while providing a level of security to everyone in the community.  More research would be required to see if there was a way to make it truly anonymous, without the need for centralized servers.
  • Create reader/viewers for all major operating systems and devices, that allowed the user to read and edit the documents seamlessly.

Anyway, this is an idea rattling around in my head. Not sure if it could ever go anywhere, but it would go a long way in my opinion to solving a lot of the inefficiencies inherent in the existing communities.

Posted by slaingod Mon, 21 Jan 2008 20:05:00 GMT


I Like Bulleted Lists

If you haven’t noticed from my blog postings, I like bulleted lists.  It just helps me order my thoughts as well as makes it easier for me to edit/correct/add ideas without having to search for the right place to say it.  This probably corresponds to the ‘outline’ phase of actual writing, but then I was never really that great at writing to begin with. :P

Posted by slaingod Mon, 21 Jan 2008 18:17:00 GMT


Biting the Hand That Feeds Me

So this is a note to all of the uploaders of the world.  Your efforts are much appreciated…but…I do have a few gripes about some of the more annoying and time consuming aspects of poorly uploaded files. All of these fall in the ‘if you spend the 30 seconds to do it, then you will save hundreds or thousands of other people that 30 seconds and the added frustration’ category.

 General

  • It is OK to use spaces in file names. No, really.  If you are using an OS that doesn’t handle spaces in the filenames, then you probably aren’t reading this blog. Underscores (_) are NOT spaces.  There was probably some rational against using spaces in file names years and years ago, but that ship has long since sailed.  The ONLY possible issue I could see is if you are using bash or some other shell that escapes spaces with a slash (\).  Or maybe you have a MIRC server script that is older than you are.  There really is no excuse.
  • When creating PAR2 repair volumes, do NOT put other crap into the volume set that isn’t part of the final product.  That means, I shouldn’t need to have an SFV, and NFO, a 100mb sample file, or any other garbage besides the RAR files to get my download to repair.

MP3s

  • If you are going to go to the trouble of uploading MP3s somewhere, have the decency to put accurate id3 tags in the files. Seriously.  It just wastes a ton of time for a ton of people to have to redo them.
  • It is a good idea to upload par2 files with your mp3s, so people can fix them.  This mostly means NNTP these days, since p2p does a good job of validating these days.
  • If you do upload par2 files, then please name them appropriately…don’t name them .par2.  Because, sadly this seems like a common issue, and you just end up with overwritten par2 files.  Or ‘D.par2’ isn’t really helpful either.
  • Rip your stuff at least at 192 VBR.  That’s pretty much the sweet spot for size/quality.  Go higher if you want, but definitely don’t upload stuff at 128 CBR.
  • Don’t tag your mp3’s with spaces between the characters. ‘R E D   H O T   C H I L I   P E P P E R S’ is not really helpful.  Maybe it’s a UNICODE thing, but how often do you actually see unicode in id3 tags?

Movies

  • Along with the spaces thing…File names no longer need to by 8.3. You can use literally hundreds of characters if you want.  ‘tia-ree.iso’ is sooo not helpful. Why not just name it ‘Resident Evil Extinction.iso’ instead?  Then we won’t have to waste time mounting the iso’s and opening our media players just to see what it is. I have no problem with including a group name in the filename, just make the whole thing actually useful.  ‘Resident Evil Extinction.DVD9.TIA.iso’ is fine too.
  • Do NOT ask me to join some IRC channel just so I can find out what your 5GB upload actually is,  I like the idea of being able to go somewhere and request something, and think it is a handy way to add value to some of the larger USENET groups, but still, just leeching shouldn’t require me to join an IRC channel.
  • Don’t release a 9GB HD rip of something.  If your encode went over, then suck it up and reencode it to DVD9 size (which is more like 8GB).  Same with 5GB files and DVDR size.  Maybe in another year or so, when harddrives are 10 cents a GB, that would make less non-sense, but until then, lets stick to the program.
  • Don’t have your release NFO files have spaces between everything: ‘h t t p : / / u s . i m d b . c o m / s o m e t h i n g’ just pisses everyone off since the are just going to have to type the name now anyway rather than deal with the spaces.
  • This one may just be me, but I actually prefer RAR volume sets that have ‘part001’ in the name, only because it means that the only RAR file you care about, the first one, shows up first in a directory listing, rather than what happens with ‘R01’, etc.
  • Learn how to post in USENET so that the files are ordered properly in an alphabetic list!  Starting your post with [001/100] is not acceptable. It just leads to dozens of uploads being ignored. Always put the title of your upload first, like ‘The Bourne Ultimatum.rar [001/100]’ so the files stick together and are easy to select without having to use search filters.

TV

  • Consistency in naming would be nice. ‘tds’, ’the daily show’, ’the.daily.show’, ’daily_show’: just go with ‘the daily show’ and be done with it.  ‘s01e21`, ‘01x21’, ‘121’: Executive decision here, go with s01e21.  It isn’t any better or worse than the others. but just stick with one.
  • Don’t put the episode name into the file name, unless you are releasing an entire season at once, especially on bittorrent.  Everyone’s uTorrent RSS feed regular expressions break if you start throwing stuff other than the show name and episode number in there.

These are all minor things, I know. But like so many ‘little things’ in life they add up. So take this with a grain of salt, but it’s something I needed to say. :)

Posted by slaingod Mon, 21 Jan 2008 09:39:00 GMT


Flivver: Building a SWF to FLV server application

Working in the ‘media sharing’ space, I’ve come across the need for a SWF to FLV application (swf2flv).  There are a number of products out there, and some oldish Python scripts, but none of them really satisfied my needs. Some of the products out there are by Sothink and Scout.  I needed something that could be called from a command line/console, and Scout does have a version that does that, though it costs $1000ish for a single server license. But it didn’t have one key feature I needed, so I started to look into what it would take to build my own.  Hence Flivver (think FLV, not Aldous Huxley).

Here are the basic things that Flivver needed, with the one extra feature that I haven’t seen in any other SWF2FLV app:

  • Process a SWF without any human interaction from a server: This won’t work with swf’s that require button presses, but for my needs I needed to take an audio/visual playlist created by a user and have it converted into something that user could possibly upload to YouTube.
  • Video/Visual capture: Capture everything that happened in the FLV, including bitmap manipulations, and text, effects and transitions.  While it wouldn’t be too hard to append a bunch of video files together, once you start adding affects like ‘Black & White’ to the video, you have to really consider how you are going to integrate you playlist with some pretty serious Adobe Premiere/iMovie type application to replicate it in a standalone video file.
  • Audio Capture: In the same way as video, you need to be able to capture the audio as it occurs in the playlist, with transitions and effects.
  • Be able to assign a playlist id to the SWF, so it can load the playlist from the internet. One of the key things missing in all of the SWF2FLV and SWF2AVI apps is the ability to set flashvars or otherwise interact with the SWF in any meaningful way.  Specifically for my needs, I have to load the playlist from a web server application that stores the playlists created by the users.  As far as all of the other server/console style converters, they don’t support any way of interacting with the swf being processed.

So as any good hacker would, I started searching google for info on how to do the various pieces: Video Capture, Audio Capture, Hosting Flash in an Application, & Talking to Flash from a Hosting Application. I found a lot of good information, but it is all about weeding out the bad.  The first decision I made was that I was going to have to use the Windows environment for the application, simply because I am more familiar with it as far as GUI programming goes, and there was a lot more information on screen capture out there for it, as well as using video card acceleration to speed up the process. I had done some work with xine back in the day (dealing with the Via EPIA Hardware a few years ago, though nothing official), and just felt that for my needs the effort would have been to great to get a working version on linux. Also, in general our production servers didn’t have X11 running or sound cards anyway, so we needed our own GUI server for everything to work.

So then the question was whether to do it in C++ or C#.  Although there are more examples in C++, I decided to go with C#, because I wanted to try something new. So that decision helped me narrow down my google searches.

First I needed to find C# versions of the DirectShow SDK, with examples, as I really didn’t want to learn all the ins and outs of dealing with DirectShow filters & COM.  I finally came across the DirectX.Capture demo at CodeProject, which had about 50% of what I needed, and was the scariest part for me.  The next piece I needed was a DirectShow Filter that did screen capture. I found a couple of those: UScreenCapture and VH Screen Capture filters. VH Screen Capture has a few more options I believe, but for now I am using UScreenCapture. So another 25% of the project down. Next I needed a way to capture the audio that was being played through the sound card.  This is easily accomplished by setting the Audio source to ‘Stereo Mix’, and capturing with a reasonable volume at 44khz, 16 bit stereo. (NOTE TO LAPTOP/MACBOOK BOOT CAMP USERS: You may need to download some hacked SigmaTel HD Audio drivers or make some changes to your driver installation files to get ‘Stereo Mix’ to be an option for your Volume Mixer. Do some googling for “Sigmatel MacBook Stereo Mix”.) Finally, I needed a way to embed Flash into my C# application in a way that allowed me to call Flash methods. I found the instructions to this at this site. Note: that if you are using Visual Studio 2005 or newer, you will need to download a Flash ActiveX COM definition file as Microsoft stopped shipping one after VS2k3. You can find information here.

One challenge I wasn’t able to solve is having the output be in FLV format directly form the C# app. I specifically wanted to output On2 VP6 format rather than Sorenson, as it is much better quality at the same or even lower bitrates.  I couldn’t find any free DirectShow filters for this, and the one’s from On2 cost $1000 per server again.  The way to work around this is to use MPlayer’s MEncoder with the VP6.2 codec/filter installed (which even works on Linux although you need to create the settings vcf file on Windows). So  Flivver is a bit of a misnomer, since it actually outputs AVI in xvid/mp3 formats, which is then converted by mencoder.

Now that I had all of my major technological hurdles taken care of, it was just a matter of integrating them into a single application. The basics pieces were:

  • Add command line handling to the application so it could have information passed in from the server.  Specifically, this app is called by a Ruby on Rails library.  The app receives a post from the production Rails servers telling it which playlist needs to be processed, and this is then passed in on the command line.
  • Get rid of any of the DirectX.Capture settings and UI that we don’t need.  We know which specific filters we want to use, so we don’t need to deal with all of the selection menus, etc.
  • Add some timing handling.  There is no way I could tell to discover automatically the state of the SWF being loaded into the ActiveX control. The Flash onReadyStateChange didn’t really give me anything useful.  Because I had access to the code for the SWF I wished to capture, I was able to add some communication between the the SWF and the C# app, so that things could be coordinated, like when to start capturing and when to end.

That’s basically it.  I have created a SourceForge project for Flivver, though there is nothing there at the moment.  I am still finishing up some of the integration details, and changing things from hard-coded stuff I needed for my particular usage to more flexible settings/command line based options.  While there may be limited usage for something like this, I think it is still a cool little project and maybe will help someone else who has to solve a similar challenge. I’ve picked an MIT license for release, though I still need to go through all of the code I cribbed off of and see what the details for those licenses are, so that may change.  At the very least you can use my instructions here to get going on your own if need be. 

Sadly, flivver.com is a parked domain as a misspelling of ‘flower’.

And finally, thanks to my peeps at UGENmedia for paying my bills and encouraging me to put this out there for others.

Let me know what you think!

 

 

Posted by slaingod Thu, 17 Jan 2008 22:53:00 GMT


Aveda Anti-Humectant Pomade Replacement?

Ok. so I’m finally getting fed up with the crazy prices for Aveda Anti-Humectant Pomade(AAHP).  It’s not that I can’t afford it, it’s just the principal. It’s the only product I’ve found that tamed my wooly mane, and back when I first started using it, it was $10 a jar for 2.5oz.  Now it is approaching $20 a jar.  One would think that as Aveda has become more popular, that economies of scale would kick in and the price would at least be able to maintain.  In fact, it probably has, but in the standard ‘if it’s expensive it must be better’ mentality surrounding all things beauty, inflating the prices is probably part of the marketing strategy.

In response, I’ve decided to go on a hair product odyssey, trying out everything that drugstore.com has in the pomade/wax section in the $5-6 range.  Since I spend over $100 a year on the AAHP, I’ve got a little leeway to see if I can’t find something else that’s as good. So if you see me having a bad hair day, you know the reason.  If anyone out there in the Intarweb has any thoughts or recommendations, let me know!

Update:

So far, the only product that I’ve found that even comes close is Canu’s Shea Butter, lol.  It’s basically like putting petroleum jelly in your hair.  It does a pretty good job, not quite as good as Aveda, but at a quarter of the price. Though it makes me think of those hair/AstroGlide moments.

I actually found a site that sells raw ingredients for beauty products: The Personal Formulator. They have most of the main ingredients for AAHP, Capric/Caprylic Triglycerides for 12$ for 32oz., Isopropyl Palmitate for 8$ for 32oz., and others.  I’m almost tempted to try my hand at making my own since the price is so nice: $1 for 2.5oz-ish versus $20.  If I get up the nerve and actually try it, I’ll let you know.

Posted by slaingod Thu, 17 Jan 2008 22:36:00 GMT


Older posts: 1 2 3