<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Inchoate Thoughts &#187; Programming</title>
	<atom:link href="http://inchoatethoughts.com/tag/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://inchoatethoughts.com</link>
	<description>Drums, Computers, and Disjointed Ramblings</description>
	<lastBuildDate>Tue, 05 Apr 2011 22:27:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Launching Boxee with a Windows Media Center Remote</title>
		<link>http://inchoatethoughts.com/launching-boxee-with-a-windows-media-center-remote</link>
		<comments>http://inchoatethoughts.com/launching-boxee-with-a-windows-media-center-remote#comments</comments>
		<pubDate>Fri, 04 Jun 2010 04:28:49 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Boxee]]></category>
		<category><![CDATA[Green Button]]></category>
		<category><![CDATA[Media Center]]></category>
		<category><![CDATA[Remote]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=322</guid>
		<description><![CDATA[Updated 10/23/2010: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy! I was recently notified that Boxee might [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_324" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2010/06/Boxee.png"><img class="size-medium wp-image-324" title="Boxee" src="http://inchoatethoughts.com/wp-content/uploads/2010/06/Boxee-300x187.png" alt="Boxee" width="300" height="187" /></a><p class="wp-caption-text">Boxee</p></div>
<p><strong>Updated 10/23/2010</strong>: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy!</p>
<p>I was recently notified that Boxee might benefit from the same hack I used to get XBMC working with my Windows Media Center remote (see the <a href="http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote">post</a> before this one). The problem was the same. While you can use a Windows Media Center remote and IR receiver (or a universal remote emulating one) to control Boxee, the green button will continue to launch Windows Media Center. I was asked to modify the little launcher I had written for launching XBMC to launch Boxee instead. About 10 seconds of coding (and another 5 minutes of testing) later, I had what appears to be a working solution.</p>
<p><a title="Download BoxeeLauncher Installer" href="http://inchoatethoughts.com/files/InstallBoxeeLauncher.exe" target="_blank">Download BoxeeLauncher Installer</a><br />
<a title="Download BoxeeLauncher Manual Install" href="http://inchoatethoughts.com/files/BoxeeLauncher_Manual.zip" target="_blank">Download BoxeeLauncher Manual Install</a></p>
<p>Source code, project files, and install scripts can be found at <a title="BoxeeLauncher Subversion Repository" href="http://inchoatethoughts.com/boxeelauncher/" target="_blank">http://inchoatethoughts.com/boxeelauncher/</a> (subversion repository)</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/launching-boxee-with-a-windows-media-center-remote/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Launching XBMC with a Windows Media Center Remote</title>
		<link>http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote</link>
		<comments>http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote#comments</comments>
		<pubDate>Sun, 14 Feb 2010 04:29:57 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Green Button]]></category>
		<category><![CDATA[Media Center]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[XBMC]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=306</guid>
		<description><![CDATA[Updated 10/23/2010: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy! I recently took up the task of [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_307" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2010/02/xbmc.png"><img class="size-medium wp-image-307" title="XBMC" src="http://inchoatethoughts.com/wp-content/uploads/2010/02/xbmc-300x176.png" alt="XBMC" width="300" height="176" /></a><p class="wp-caption-text">XBMC</p></div>
<p><strong>Updated 10/23/2010</strong>: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy!</p>
<p style="text-align: left;">I recently took up the task of switching my media center software from Windows 7 Media Center to the Windows version of XBMC. I found XBMC easier to get working with obscure encodings of video files (it uses mplayer instead of the normal codec engine). But, my reasons for switching are not the point of this post. The point here is that switching to XBMC from Windows Media Center has a few challenges. One such challenge is getting the Windows Media Center remote to work in a nice way. Luckily, some <a href="http://xbmcmce.sourceforge.net/">excellent work</a> has been done on that front. People have already provided premade media center remote configurations for XBMC. However, the &#8220;start&#8221; button on the media center remote <a href="http://forum.xbmc.org/showthread.php?t=65088">still had the nasty habit of launching the Windows 7 Media Center app instead of launching XBMC</a>.</p>
<p style="text-align: left;">I looked around the ol&#8217; Internet for a solution to this problem. Turns out, the behavior of that &#8220;Start&#8221; or &#8220;Green&#8221; button on the media center remote is to cause a special key combination to be pressed. This key combination is bound to launching &#8220;C:\Windows\ehome\ehshell.exe.&#8221; The quickest workaround to the problem is to change ehshell.exe to something that launches XBMC. I then saw some people had written some batch files that launched XBMC. They then used a batch-to-exe converter to make it an executable and replaced ehshell.exe. That was great, but it still had a weakness. If, for some reason, XBMC was taken out of the foreground, it wouldn&#8217;t come back. Bummer. So I fixed it!</p>
<p style="text-align: left;">I wrote a little application to launch XBMC. It does a few things. First, it will check if XBMC is already running. If it is, it will bring it to the foreground for you. If it isn&#8217;t running, it will launch it. It will first try using the install location in the registry to find where to launch XBMC from. If it can&#8217;t find that, it will try the default location of the XBMC.exe file (both 32-bit and 64-bit versions).</p>
<p style="text-align: left;"><a title="XBMC Launcher Installer" href="http://inchoatethoughts.com/files/InstallXBMCLauncher.exe" target="_blank">Download The Installer</a></p>
<p style="text-align: left;"><a title="XBMC Launcher Manual Install" href="http://inchoatethoughts.com/files/XBMCLauncher_Manual.zip" target="_blank">Manual Install Files and Instructions</a></p>
<p>Finally, here is the (very simple) source code:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Diagnostics</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Runtime.InteropServices</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Win32</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> XbmcLauncher<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> Program<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SetForegroundWindow<span style="color: #008000;">&#40;</span>IntPtr hWnd<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">bool</span> ShowWindow<span style="color: #008000;">&#40;</span>IntPtr hWnd, <span style="color: #6666cc; font-weight: bold;">int</span> cmdShow<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> SW_SHOWMAXIMIZED <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The main entry point for the application.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Attempt to bring an existing XBMC to the foreground.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If none exists, open XBMC.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>BringProcessToForeground<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OpenXbmc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> BringProcessToForeground<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> processes <span style="color: #008000;">=</span> Process<span style="color: #008000;">.</span><span style="color: #0000FF;">GetProcessesByName</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;XBMC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>processes<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If XBMC is currently running, bring it to the foreground</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntPtr hWnd <span style="color: #008000;">=</span> processes<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MainWindowHandle</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowWindow<span style="color: #008000;">&#40;</span>hWnd, SW_SHOWMAXIMIZED<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow<span style="color: #008000;">&#40;</span>hWnd<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OpenXbmc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> xbmcPath <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Attempt to find the XBMC executable location via the registry</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RegistryKey key <span style="color: #008000;">=</span> Registry<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentUser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OpenSubKey</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;Software\XBMC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>key <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">// If the path is in the registry use it to open XBMC</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xbmcPath <span style="color: #008000;">=</span> key<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LaunchXbmcProcess<span style="color: #008000;">&#40;</span>xbmcPath <span style="color: #008000;">+</span> <span style="color: #666666;">@&quot;\XBMC.exe&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">// Otherwise, we'll try to use the default locations</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> x86Path <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;C:\Program Files\XBMC\XBMC.exe&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> x64Path <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;C:\Program Files (x86)\XBMC\XBMC.exe&quot;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LaunchXbmcProcess<span style="color: #008000;">&#40;</span>x86Path<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LaunchXbmcProcess<span style="color: #008000;">&#40;</span>x64Path<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> LaunchXbmcProcess<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> path<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>path <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>path<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> args <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process proc <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Process<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;XBMCLaunchArgs.txt&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>StreamReader argStream <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenText</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;XBMCLaunchArgs.txt&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args <span style="color: #008000;">=</span> argStream<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; argStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc<span style="color: #008000;">.</span><span style="color: #0000FF;">StartInfo</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ProcessStartInfo<span style="color: #008000;">&#40;</span>path, args<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BringProcessToForeground<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p style="text-align: left;">Get the full source, project files, and install scripts at <a title="XBMC Launcher Manual Install" href="http://inchoatethoughts.com/xbmclauncher/ " target="_blank">http://inchoatethoughts.com/xbmclauncher/</a> (subversion)</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote/feed</wfw:commentRss>
		<slash:comments>93</slash:comments>
		</item>
		<item>
		<title>foo_g15lcd 0.3c</title>
		<link>http://inchoatethoughts.com/foo_g15lcd-0-3c</link>
		<comments>http://inchoatethoughts.com/foo_g15lcd-0-3c#comments</comments>
		<pubDate>Wed, 27 Jan 2010 00:29:20 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Foobar2000]]></category>
		<category><![CDATA[foo_g15lcd]]></category>
		<category><![CDATA[Logitech]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=296</guid>
		<description><![CDATA[This is just a quick little update to let everyone know I&#8217;ve recompiled the foo_g15lcd component against the latest release version of Foobar 1.0. No new features, but everything still seems to be in excellent working order! Grab it here: Download foo_g15lcd 0.3c]]></description>
			<content:encoded><![CDATA[<div id="attachment_297" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2010/01/foog1503c.png"><img class="size-medium wp-image-297" title="foo_g15lcd 0.3c" src="http://inchoatethoughts.com/wp-content/uploads/2010/01/foog1503c-300x135.png" alt="" width="300" height="135" /></a><p class="wp-caption-text">foo_g15lcd 0.3c</p></div>
<p style="text-align: center;">
<p>This is just a quick little update to let everyone know I&#8217;ve recompiled the foo_g15lcd component against the latest release version of Foobar 1.0. No new features, but everything still seems to be in excellent working order!</p>
<p>Grab it here: <a href="http://www.inchoatethoughts.com/foo_g15lcd/foo_g15lcd_0_3_c.zip">Download foo_g15lcd 0.3c</a></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/foo_g15lcd-0-3c/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Extending ZenLibrary &#8211; Creating New Rules</title>
		<link>http://inchoatethoughts.com/extending-zenlibrary-creating-new-rules</link>
		<comments>http://inchoatethoughts.com/extending-zenlibrary-creating-new-rules#comments</comments>
		<pubDate>Sun, 13 Sep 2009 19:56:20 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ZenLibrary]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=218</guid>
		<description><![CDATA[Hello everyone, this is an article about my ZenLibrary program aimed at those programmers who wish to either extend it or just know more about what&#8217;s going on behind the scenes. If you&#8217;re just interested in obtaining the program, click here. I&#8217;ve *attempted* to make it easy for any programmer to extend the rules in [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone, this is an article about my <a href="http://inchoatethoughts.com/zenlibrary">ZenLibrary</a> program aimed at those <em>programmers </em>who wish to either extend it or just know more about what&#8217;s going on behind the scenes. If you&#8217;re just interested in obtaining the program, <a href="http://inchoatethoughts.com/zenlibrary">click here</a>.</p>
<p>I&#8217;ve *attempted* to make it easy for any programmer to extend the rules in ZenLibrary. Since I&#8217;m releasing this tutorial at roughly the same time as the actual program, I haven&#8217;t actually had a chance to get any feedback on how I might improve the extensibility interface. I do, however, want to make it clear I have no interest in making an elaborate end-user based rule scripting engine. Doing so would a.) screw up the simplicity of the program and b.) drastically change the scope of this software. Throwing in some user-defined regular expressions is about as far as I am willing to go.</p>
<h3><strong>Part 0 &#8211; Getting Set Up and Getting The Source</strong></h3>
<p>Creating new rules in ZenLibrary does NOT require getting the source code. One simply needs to reference &#8220;ZenLibrary.RuleBase.dll&#8221; that comes with the program (version 0.3 and later). However, I think having the source on hand will make debugging things a bit easier on your part. But, it&#8217;s all your call.</p>
<p>This project was done in C#, using WPF, and in Visual Studio 2008. Hopefully none of that made you too uncomfortable. You&#8217;ll pretty much need Visual Studio 2008 to deal with this solution. I suppose the Express edition of C# could work, but I haven&#8217;t tried it.</p>
<p>The source code is controlled in subversion. Everyone has read permissions on the repository. If you&#8217;d like to contribute to the project and need write access, drop me a line. This is an open source project, released using the LGPL.</p>
<address>ZenLibrary SVN Host: http://inchoatethoughts.com/zenlibrarysvn</address>
<h3><strong>Part 1 &#8211; How It Works</strong></h3>
<p>Before we get into how to add our own rules, let&#8217;s talk a bit about how this program runs. First, the user chooses a directory to scan through and the rules he wants to test against, and then he presses start. The program now launches a new thread (as to not stall the user interface thread) and begins to scan each directory. This is where our first set of tests begins to run. There are two different types of tests, or &#8220;rules&#8221; (I&#8217;ll be using the terms interchangeably). There are &#8220;per-directory&#8221; rules. These rules run on any directory with music files. These sorts of rules are useful for doing things like checking for the existence of a particular image file (e.g. album artwork) inside the directory. After the &#8220;per-directory&#8221; tests run, a set of &#8220;per-file&#8221; tests will be run against each of the MP3 files in the directory. The &#8220;per-files&#8221; are useful for checking the content of specific tags, checking for proper file name, etc.</p>
<div id="attachment_250" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2009/09/ZenLibraryFlow.png"><img class="size-medium wp-image-250" title="Rule Scanning Flow" src="http://inchoatethoughts.com/wp-content/uploads/2009/09/ZenLibraryFlow-300x154.png" alt="Rule Scanning Flow" width="300" height="154" /></a><p class="wp-caption-text">Rule Scanning Flow</p></div>
<p>Forgive the terrible flowchart. Continuing on. This is a .NET program, so anyone extending this software will have the full .NET library at their disposal, which is pretty powerful in and of itself. However, since this is an audio library scanner, the program also makes use of <a title="TagLib#" href="http://developer.novell.com/wiki/index.php/TagLib_Sharp" target="_blank">TagLib#</a>. TagLib, for those who aren&#8217;t already familiar, is a pretty powerful tag reader. It actually works on all sorts of media, not just MP3s with ID3 tags. TagLib# is then a .NET version of TagLib. It&#8217;s released under the LGPL, much like ZenLibrary, so packaging it and distributing it with this software is not a problem. ZenLibrary references TagLib, so when designing rules, don&#8217;t forget you have a good hunk of tagging technology to make us of. If you&#8217;re looking to do things with tags, just add a reference to &#8220;taglib-sharp.dll&#8221; as well.</p>
<h3><strong>Part 2 &#8211; Creating a Rule</strong></h3>
<p>Our task today is to essentially create one of the rules/tests that make up the meat of this program. I&#8217;ve done some work to make this as easy as possible. Here is what you&#8217;ll need to do:</p>
<ul>
<li>Inherit from the &#8220;Rule&#8221; class</li>
<li>Give the rule a name (overload the Name property)</li>
<li>Define the TestType (&#8220;per-file&#8221; or &#8220;per-directory&#8221;)</li>
<li>Give it some test logic</li>
</ul>
<p>That&#8217;s it! If you want a more elaborate rule with configurations that are persisted between application sessions, there is a ConfigurableRule class to inherit from and a few more overloads you&#8217;ll need to provide. But, let&#8217;s ignore that for now. We&#8217;re going to create a very simple rule. It&#8217;s purpose will be to detect for the presence of the &#8220;discnumber&#8221; tag in all of our music files.</p>
<div id="attachment_263" class="wp-caption aligncenter" style="width: 245px"><a href="http://inchoatethoughts.com/wp-content/uploads/2009/09/RuleClassDiagram.png"><img class="size-medium wp-image-263" title="Diagram for Abstract Rule Classes" src="http://inchoatethoughts.com/wp-content/uploads/2009/09/RuleClassDiagram-235x300.png" alt="Diagram for Abstract Rule Classes" width="235" height="300" /></a><p class="wp-caption-text">Diagram for Abstract Rule Classes</p></div>
<p><strong>Set Up The Project</strong></p>
<p>First order of business is getting our add-in project created. Open up Visual Studio and create a new &#8220;Class Library&#8221; project. It doesn&#8217;t really matter what you name it, but you may want to indicate your name and that it is a file with ZenLibrary Rules in it. Pretend your name is Billy Bob. You might name the project &#8220;ZenLibrary.BillyBobsRules.&#8221; I&#8217;ve named my project &#8220;SampleRuleLibray.&#8221; Once you&#8217;ve created the Class Library project, go to your references folder, right click and select &#8220;Add Reference,&#8221; click the browse tab and go find &#8220;ZenLibrary.RuleBase.dll&#8221; (it comes packaged with ZenLibrary releases). For this particular &#8220;Discnumber&#8221; tag rule, we&#8217;re also going to be using the TagLib# library as well. Once again, add a reference using &#8220;Browse&#8221; and select &#8220;taglib-sharp.dll,&#8221; which should also be in the ZenLibrary directory.</p>
<div id="attachment_266" class="wp-caption aligncenter" style="width: 337px"><a href="http://inchoatethoughts.com/wp-content/uploads/2009/09/References.PNG"><img class="size-full wp-image-266" title="References Defined" src="http://inchoatethoughts.com/wp-content/uploads/2009/09/References.PNG" alt="References Defined" width="327" height="321" /></a><p class="wp-caption-text">References Defined</p></div>
<p><strong>Inherit From The Rule Class</strong></p>
<p>Now that we have our project set up, we can go ahead and create our rule class. Create a new class file (I called mine &#8220;SampleRule.cs&#8221;). This class should inherit from &#8220;ZenLibrary.RuleBase.Rule.&#8221;</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">ZenLibrary.RuleBase</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> SampleRuleLibrary<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SampleRule <span style="color: #008000;">:</span> Rule<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Give The Rule A Name</strong></p>
<p>The rule needs a name. The name shows up in ZenLibrary&#8217;s rule panel on the left side and is how the user will identify your rule from the other rules. To specify a name, just override the &#8220;Name&#8221; property&#8217;s get. Pretty simple!</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">ZenLibrary.RuleBase</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> SampleRuleLibrary<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SampleRule <span style="color: #008000;">:</span> Rule<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;Discnumber Tag&quot;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Define The Test Type</strong></p>
<p>The test type determines if your test will be run per music directory or per file. It&#8217;s just a simple optimization effort, really. The per-directory test exists so that we don&#8217;t have to check for the existence of &#8220;folder.jpg&#8221; in the directory on every file scan. Conversely, the per-file test exists so we don&#8217;t have to rewrite logic to scan all of the files every time we run on a music directory. To define our Test Type, we override the &#8220;TestType&#8221; property&#8217;s get and specify &#8220;TestType.FileScan&#8221; for per-file and &#8220;TestType.DirectoryScan&#8221; for per-directory. Our test case is something that needs to be done a per-file basis, so we&#8217;ll use &#8220;TestType.FileScan&#8221; in the example.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">ZenLibrary.RuleBase</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> SampleRuleLibrary<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SampleRule <span style="color: #008000;">:</span> Rule<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;Discnumber Tag&quot;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> TestType TestType<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> TestType<span style="color: #008000;">.</span><span style="color: #0000FF;">FileScan</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Give The Test Some Logic</strong></p>
<p>Finally, the meat of the program. Our test. This is where the magic happens. The magic that you define, that is. Anything can happen here, really. Override the &#8220;RunTest()&#8221; method. You&#8217;ll be provided with either a &#8220;System.IO.FileInfo&#8221; for the file you&#8217;re scanning (on a per-file scan) or a &#8220;System.IO.DirectoryInfo&#8221; for the scanning directory (on a per-directory scan). If the scan is per-file, the DirectoryInfo parameter will be the directory where the file is. If the scan is per-directory, the FileInfo parameter will be null. From here on out, it&#8217;s up to you what to do with them. All that matters now is that you return a &#8220;RuleTestResult&#8221; at the end indicating whether the test has passed or failed. If the test has passed, mark &#8220;TestPassed&#8221; in the &#8220;RuleTestResult.IsPassed&#8221; property to true and return it. If it is has failed, mark &#8220;RuleTestResult.IsPassed&#8221; as false. Also, assign the &#8220;RuleTestResult.RuleTestFailedString.&#8221; This string is the message that will be displayed in the results box on the ZenLibrary UI. Additionally, you&#8217;ll want to specify the location where it failed by assigning &#8220;RuleTestResult.ResultPath.&#8221; This can pretty much always be the &#8220;FullName&#8221; property of the provided &#8220;DirectoryInfo.&#8221;</p>
<p>For the sample test case, I&#8217;ve added some logic, using TagLib#, to check whether the &#8220;Discnumber&#8221; tag is &#8220;0.&#8221; This is an indication that the &#8220;Discnumber&#8221; tag has not been assigned, and thus, fails our test.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">ZenLibrary.RuleBase</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> SampleRuleLibrary<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SampleRule <span style="color: #008000;">:</span> Rule<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;Discnumber Tag&quot;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> TestType TestType<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> TestType<span style="color: #008000;">.</span><span style="color: #0000FF;">FileScan</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> RuleTestResult RunTest<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DirectoryInfo</span> directoryInfo, <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">FileInfo</span> fileInfo<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TagLib<span style="color: #008000;">.</span><span style="color: #0000FF;">File</span> file <span style="color: #008000;">=</span> TagLib<span style="color: #008000;">.</span><span style="color: #0000FF;">File</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>fileInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RuleTestResult result <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RuleTestResult<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Disc</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result<span style="color: #008000;">.</span><span style="color: #0000FF;">TestPassed</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result<span style="color: #008000;">.</span><span style="color: #0000FF;">ResultPath</span> <span style="color: #008000;">=</span> directoryInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result<span style="color: #008000;">.</span><span style="color: #0000FF;">RuleTestFailedString</span> <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;File <span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span> does not have the discnumber tag defined.&quot;</span>, fileInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result<span style="color: #008000;">.</span><span style="color: #0000FF;">TestPassed</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> result<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Boom! We&#8217;re done! Yep, that&#8217;s really all there is to it. Compile your Class Library and drop the output DLL in the same directory as ZenLibrary.exe. You don&#8217;t need to register it or anything. ZenLibrary will automatically detect its presence and instantiate any rules within.</p>
<div id="attachment_274" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2009/09/CustomRuleRunning.png"><img class="size-medium wp-image-274" title="The Sample Rule Running!" src="http://inchoatethoughts.com/wp-content/uploads/2009/09/CustomRuleRunning-300x193.png" alt="The Sample Rule Running!" width="300" height="193" /></a><p class="wp-caption-text">The Sample Rule Running!</p></div>
<p>If you want to see more elaborate rules with custom configuration dialogs and the likes, you can grab the source code from the subversion repository and check out the included rules in the ZenLibrary.RuleBase assembly. You may also want to check out how to write a light plug-in infrastructure via reflection by taking a look in &#8220;RuleSet.cs&#8221; to see how I instantiate all the rules without programmers having to manually register them. </p>
<p>You can also <a href="http://inchoatethoughts.com/files/SampleRule.zip">download the sample rule project here.</a></p>
<p>Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/extending-zenlibrary-creating-new-rules/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZenLibrary &#8211; Cleanse Your Music Library (And Thus Your Soul)</title>
		<link>http://inchoatethoughts.com/zenlibrary</link>
		<comments>http://inchoatethoughts.com/zenlibrary#comments</comments>
		<pubDate>Fri, 11 Sep 2009 04:49:01 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Media Library]]></category>
		<category><![CDATA[MP3 Tagging]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[ZenLibrary]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=199</guid>
		<description><![CDATA[Here&#8217;s my latest &#8220;weekend project.&#8221; It was supposed to be a little tool I wrote for myself on a lazy Sunday afternoon. Then I decided I would release it to you all, and that causes a project to really balloon in scope. I had to worry about it crashing, clean up my code so no [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_204" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2009/09/ZenLibrary.png"><img class="size-medium wp-image-204" title="ZenLibrary's Main Screen" src="http://inchoatethoughts.com/wp-content/uploads/2009/09/ZenLibrary-300x193.png" alt="ZenLibrary's Main Screen" width="300" height="193" /></a><p class="wp-caption-text">ZenLibrary&#39;s Main Screen</p></div>
<p>Here&#8217;s my latest &#8220;weekend project.&#8221; It was supposed to be a little tool I wrote for myself on a lazy Sunday afternoon. Then I decided I would release it to you all, and that causes a project to really balloon in scope. I had to worry about it crashing, clean up my code so no one could blackmail me with it later, restructure the architecture to be generic, blah, blah, blah. But, I&#8217;ll save all those boring details for the next blog post aimed at programmers. This is supposed to be the post where I tell you what this project does.</p>
<p>Thus, I present to you: ZenLibrary. It&#8217;s a simple tool for all of you people as obsessed with sanitizing your media library as I am. You give it your music library, and it tells you all the things wrong with it (presumably so you can fix them). Step 1, you tell it where your music library is. Step 2, you choose what rules you want to test against your music library. Step 3, you fix the problems it finds.</p>
<p>Here&#8217;s the feature list:</p>
<ul>
<li>Simple, streamlined UI.</li>
<li>Comes with a set of common criteria for sanitizing a music library</li>
<li>Easily extensible rule architecture</li>
<li>User preferences saved between sessions.</li>
<li>Integrates with MP3Tag to quickly launch an editor on any errors it finds.</li>
<li>Double clicking any result takes you straight to that folder (again, for easy editing)</li>
</ul>
<p>Requirements:</p>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ab99342f-5d1a-413d-8319-81da479ab0d7&amp;displaylang=en">.NET Framework 3.5 SP1</a></li>
</ul>
<p><a href="http://inchoatethoughts.com/files/ZenLibrary_0.4.zip">Download ZenLibrary 0.4</a></p>
<p>For people interested in extending it or getting their hands on the source code, <a href="http://inchoatethoughts.com/extending-zenlibrary-creating-new-rules">be sure to check out my next post on doing just that.</a></p>
<h2>Version Updates:<em><strong> </strong></em></h2>
<p><strong>9-14-2009:</strong> Release 0.4</p>
<p>- Fixed icon error causing crashes in Windows XP and Vista<br />
- Moved included rules out to their own assembly.</p>
<p><strong>9-13-2009:</strong> Release 0.3</p>
<p>- Created ZenLibrary.Rulebase.dll for plugin support</p>
<p><strong>9-12-2009:</strong> Release 0.2</p>
<p>- Added initial support for M4A, OGG, and FLAC files.<br />
- Added detailed error information for tests that are unable to complete (red exclamation circles).<br />
- Changed &#8220;Stereo&#8221; test method to a simple check on the number of audio channels.<br />
- Fixed bug in album art directory scanning<br />
- Disabled rule options while scanning (to prevent thread collisions)</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/zenlibrary/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom Drawing Controls in C# &#8211; Manual Double Buffering</title>
		<link>http://inchoatethoughts.com/custom-drawing-controls-in-c-manual-double-buffering</link>
		<comments>http://inchoatethoughts.com/custom-drawing-controls-in-c-manual-double-buffering#comments</comments>
		<pubDate>Sat, 15 Aug 2009 18:43:10 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[BufferedGraphicsContext]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Double Buffering]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=168</guid>
		<description><![CDATA[I feel like this article is about four years too late. All the cool kids have moved on to WPF or something really awesome, like XNA, for their graphics needs. However, there are still a lot of us playing around in the .NET 2.0 mucky muck for various reasons. Of those still doing .NET 2.0 [...]]]></description>
			<content:encoded><![CDATA[<p>I feel like this article is about four years too late. All the cool kids have moved on to WPF or something really awesome, like XNA, for their graphics needs. However, there are still a lot of us playing around in the .NET 2.0 mucky muck for various reasons. Of those still doing .NET 2.0 / WinForms / GDI+ programming, I&#8217;m surprised to see how many people draw their custom controls the wrong way. Yep, I said &#8220;wrong.&#8221; I blame the majority of the C# books out there. Most of them, in the chapter on System.Drawing, just tell everyone to draw their stuff in OnPaint() or in response to a paint event. PLEASE, STOP DOING THIS. I&#8217;ll explain why.</p>
<p>One should not have a lot going on in one&#8217;s OnPaint method. It should be very small, very straight forward. In 95% of my custom controls, my paint event looks something like this:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnPaint<span style="color: #008000;">&#40;</span>PaintEventArgs e<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>isDisposing <span style="color: #008000;">&amp;&amp;</span> backbufferGraphics <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; backbufferGraphics<span style="color: #008000;">.</span><span style="color: #0000FF;">Render</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Graphics</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s it. Just two lines. Here&#8217;s what&#8217;s going on. OnPaint is the .NET equivalent of the Win32 WM_PAINT message being raised. It happens when a region of your control is &#8220;invalidated.&#8221; Invalidation occurs when Windows thinks your control needs to be redrawn for some reason. Examples include your control being resized, another window moving in front of it, your window losing and regaining focus, etc. Because OnPaint() is called so frequently and unpredictably, it is not wise to have a lot of complex and CPU-intensive operations going on inside of it.</p>
<p>You may be wondering what we do instead. You be smart and efficient about it. Because the drawing logic is often complex and expensive, you&#8217;ll want to do it only as often as necessary. This means having an off-screen buffer that you draw to. When it comes time to actually paint your control on to the screen, your control can just go take a look at our off-screen buffer and copy it to the display. Pretty simple. Now, there is added complexity when you consider that you may be drawing to this buffer at the exact same time your control needs to draw it to the screen. In this scenario, your control would have to site around and wait with an invalidated region until you&#8217;ve finished drawing to your buffer. What this usually looks like to the end user is an irritating flicker on the control. The flicker they see is a rapid switch between invalidated control regions (which are usually painted pure white, black, or some other random bit of color) and the drawn buffer.</p>
<p>A quick look around the net will reveal that the solution to flicker is &#8220;double buffering.&#8221; Now, mind you, none of this is a new concept. People have been doing this for about as long as computer graphics have existed. The difference is, it&#8217;s a lot easier now. .NET literally makes it as easy as setting a property on your forms or controls. Beyond that, a programmer used to have to actually manage two buffers manually and swap between them. This is more automated with the introduction of the BufferedGraphics and BufferedGraphicsContext classes. Basically, you draw to the BufferedGraphics class, and it takes care of the double buffering for you. Here is an example constructor and buffer creation routine.</p>
<p>Constructor setting up the form&#8217;s double buffering properties:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> DoubleBufferedControl<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Set the control style to double buffer.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetStyle</span><span style="color: #008000;">&#40;</span>ControlStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">AllPaintingInWmPaint</span> <span style="color: #008000;">|</span> ControlStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">UserPaint</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetStyle</span><span style="color: #008000;">&#40;</span>ControlStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">SupportsTransparentBackColor</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetStyle</span><span style="color: #008000;">&#40;</span>ControlStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">OptimizedDoubleBuffer</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Assign our buffer context.</span><br />
&nbsp; &nbsp; backbufferContext <span style="color: #008000;">=</span> BufferedGraphicsManager<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; initializationComplete <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; RecreateBuffers<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; Redraw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>And here is an example of creating the buffers</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> RecreateBuffers<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Check initialization has completed so we know backbufferContext has been assigned.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Check that we aren't disposing or this could be invalid.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>initializationComplete <span style="color: #008000;">||</span> isDisposing<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// We recreate the buffer with a width and height of the control. The &quot;+ 1&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// guarantees we never have a buffer with a width or height of 0.</span><br />
&nbsp; &nbsp; backbufferContext<span style="color: #008000;">.</span><span style="color: #0000FF;">MaximumBuffer</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Size<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Dispose of old backbufferGraphics (if one has been created already)</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>backbufferGraphics <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; backbufferGraphics<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Create new backbufferGrpahics that matches the current size of buffer.</span><br />
&nbsp; &nbsp; backbufferGraphics <span style="color: #008000;">=</span> backbufferContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Allocate</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateGraphics</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>, Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Assign the Graphics object on backbufferGraphics to &quot;drawingGraphics&quot; for easy reference elsewhere.</span><br />
&nbsp; &nbsp; drawingGraphics <span style="color: #008000;">=</span> backbufferGraphics<span style="color: #008000;">.</span><span style="color: #0000FF;">Graphics</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// This is a good place to assign drawingGraphics.SmoothingMode if you want a better anti-aliasing technique.</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Invalidate the control so a repaint gets called somewhere down the line.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Invalidate</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now, there is one critical place where we make sure to call RecreateBuffers(). That is when the control is resized. The buffers we create in RecreateBuffers() are all sized to match the control&#8217;s size. If the buffer wasn&#8217;t the size of the control, the control would repaint with a large region of invalid graphics. So, just make sure you have a call to RecreateBuffers in OnResize for your control:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnResize<span style="color: #008000;">&#40;</span>EventArgs e<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnResize</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; RecreateBuffers<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; Redraw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s pretty much all you need to get a custom double buffered control going. You may have noted that I made a few calls to &#8220;Redraw().&#8221; Redraw() is where I put my actual drawing logic. What goes in Redraw() is the meat of how you render your control. Just remember, call it only when needed. Don&#8217;t go and put the call to Redraw() in OnPaint(). That would be against everything this article tried to teach. This method of rendering is very powerful and I&#8217;ve created a number of real-time fast-rendering controls with this mechanism. I&#8217;ve been using this method for many years now, so it is tried and true. One of the first times I started double buffering on a custom control was for a custom chart and spectrogram I made for some spectrum analyzer software I was working on. Here is a screenshot:</p>
<div id="attachment_185" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2009/08/graph-spectrogram.png"><img class="size-medium wp-image-185" title="Realtime Graph and Spectrogram" src="http://inchoatethoughts.com/wp-content/uploads/2009/08/graph-spectrogram-300x225.png" alt="Realtime Graph and Spectrogram" width="300" height="225" /></a><p class="wp-caption-text">Realtime Graph and Spectrogram</p></div>
<p>Thanks for reading. If it helps anyone, I&#8217;ve attached a very simple sample project below that contains all the code I&#8217;ve shown above. If you have any questions or comments, feel free to use the comments below.</p>
<p><a href="http://inchoatethoughts.com/uploads/BufferedGraphicsContextExample.zip">Download Sample Project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/custom-drawing-controls-in-c-manual-double-buffering/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>foo_g15lcd 0.3b</title>
		<link>http://inchoatethoughts.com/foo_g15lcd-0-3b</link>
		<comments>http://inchoatethoughts.com/foo_g15lcd-0-3b#comments</comments>
		<pubDate>Tue, 30 Jun 2009 01:03:59 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Foobar2000]]></category>
		<category><![CDATA[foo_g15lcd]]></category>
		<category><![CDATA[Logitech]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=50</guid>
		<description><![CDATA[I was looking at my bandwidth logs, something I do every year and a half or so, and noticed a lot of my traffic was for something I uploaded a long time ago. Let&#8217;s take a trip back. The year was 2006. Bell-bottoms were the height of fashion and the telephone had just caught on [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at my bandwidth logs, something I do every year and a half or so, and noticed a lot of my traffic was for something I uploaded a long time ago. Let&#8217;s take a trip back.</p>
<div class="wp-caption aligncenter" style="width: 425px"><img title="Title screen - before a song is played." src="http://www.inchoatethoughts.com/foo_g15lcd/foo_g15lcd_title.jpg" alt="Title screen - before a song is played." width="415" height="311" /><p class="wp-caption-text">Title screen - before a song is played.</p></div>
<p>The year was 2006. Bell-bottoms were the height of fashion and the telephone had just caught on (we called it the &#8220;harmonic telegraph&#8221; back then). Anyone who was anyone was using the <a href="http://www.foobar2000.org">foobar2000</a> media player. And anyone who was anyone, but was also a huge geek, was using it with their brand new <a href="http://www.logitech.com/index.cfm/keyboards/keyboard/devices/3498&amp;cl=us,en">Logitech G15 keyboard</a>. However, through some perverseness in the space-time continuum, these two things didn&#8217;t work together.</p>
<div class="wp-caption aligncenter" style="width: 425px"><img title="The song playing display." src="http://www.inchoatethoughts.com/foo_g15lcd/foo_g15lcd_song.jpg" alt="The song playing display." width="415" height="311" /><p class="wp-caption-text">The song playing display.</p></div>
<p>Adrenaline pumping, I ducked into the nearest phone booth, donned my cape, and flexed my mighty C++ muscles (which have now all atrophied). I tossed all sorts of code together, not caring who was hurt in the process. After a good three, maybe four, hours of blood, sweat, and tears, I had a plug-in that made Foobar2000 songs show up on a G15 keyboard.</p>
<p>Here we are, almost 3 years later, and guess what, some people are still using this thing! Weird! I know! Turns out, however, that because I haven&#8217;t recompiled it with the latest SDK, it has some real trouble working with the latest version of Foobar. So I&#8217;ve recompiled it! Grab it below:</p>
<p>Recompiled for Foobar 1.0!:<br />
<a href="http://www.inchoatethoughts.com/foo_g15lcd/foo_g15lcd_0_3_c.zip">Download Foo_G15LCD Component Version 0.3c</a></p>
<p>PS: It looks like some cool dude by the name of &#8220;ectotropic&#8221; has gone ahead and obsoleted my sorry ass. He wrote a plug-in that not only does what mine did, but does all sorts of cool things that I wanted to do (like a spectrum analyzer display!). I encourage you to <a href="http://www.hydrogenaudio.org/forums/index.php?showtopic=72720">check out his plug-in</a>. I don&#8217;t really use a G15 keyboard anymore, so I haven&#8217;t tried it, but it certainly looks cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/foo_g15lcd-0-3b/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

