<?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>Lightbulb</title>
	<atom:link href="http://www.benbarefield.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.benbarefield.com/blog</link>
	<description>Ideas from Ben Barefield</description>
	<lastBuildDate>Fri, 11 May 2012 15:19:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>CodeMash 2012</title>
		<link>http://www.benbarefield.com/blog/?p=82</link>
		<comments>http://www.benbarefield.com/blog/?p=82#comments</comments>
		<pubDate>Sun, 15 Jan 2012 15:39:50 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=82</guid>
		<description><![CDATA[I’m back from CodeMash 2012 and it was great! I want to give a huge thank you to all of the organizers for putting so much time into making such a great conference. I also want to thank them again for the opportunity to speak. Thank you to all of you who came out to [...]]]></description>
			<content:encoded><![CDATA[<p>I’m back from CodeMash 2012 and it was great! I want to give a huge thank you to all of the organizers for putting so much time into making such a great conference. I also want to thank them again for the opportunity to speak.</p>
<p>Thank you to all of you who came out to my talk, it was a lot of fun giving it and I hope you took something useful away. I’ve posted my slides and demo code to BitBucket mercurial here:</p>
<p><a title="https://bitbucket.org/benbarefield/kinectcm2012" href="https://bitbucket.org/benbarefield/kinectcm2012">https://bitbucket.org/benbarefield/kinectcm2012</a></p>
<p>The HoverBugz code will be available on the <a href="http://www.srtsolutions.com">SRT</a> website in the next couple of days. If it’s not there yet, check back soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=82</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Answering a Couple Scala.Net questions</title>
		<link>http://www.benbarefield.com/blog/?p=80</link>
		<comments>http://www.benbarefield.com/blog/?p=80#comments</comments>
		<pubDate>Fri, 29 Jul 2011 22:27:33 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=80</guid>
		<description><![CDATA[Bill Wagner recently asked me a couple of Scala.Net questions after reading my recent blog posts. What is the debugging story for Scala.Net? A pdb file is required for debugging in Visual Studio, just like with C#. The pdb file contains all of the debugging symbols that Visual Studio uses to track the run of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/#!/billwagner">Bill Wagner</a> recently asked me a couple of Scala.Net questions after reading my recent blog posts.</p>
<p><strong>What is the debugging story for Scala.Net?</strong></p>
<p>A pdb file is required for debugging in Visual Studio, just like with C#. The pdb file contains all of the debugging symbols that Visual Studio uses to track the run of the program. A pdb file can be generated when running ilasm:</p>
<p>ilasm /PDB &lt;MSIL file&gt;</p>
<p>After running ilasm, open Visual Studio and create a new Blank Solution (found under Other Project Types –&gt; Visual Studio Solutions.) Then right click the Solution and click Add –&gt; Existing Project. Change the filter to show executable files and add the executable generated by ilasm. Now the executable can be run through Visual Studio in various ways; for example, right click the executable –&gt; Debug –&gt; Start new instance.</p>
<p>Before running the executable, make sure that “enable address level debugging” is set by going to Debug –&gt; Options and Settings.</p>
<p>A break point can be set in any of the Scala files associated with the executable by opening the file in Visual Studio (File –&gt; Open) and setting a break point as if it was any other .Net language file.</p>
<p><strong>If you don’t need a using statement, does that mean that all the Scala code goes into the global namespace?</strong></p>
<p>In my <a href="http://www.benbarefield.com/blog/?p=76">Calling Scala from C#</a> post, I said:</p>
<blockquote><p>… [it] surprisingly doesn’t require any extra using statements</p></blockquote>
<p>The reason a using statement was not required was because I did not put the Scala code I wrote into a package. If I had, a using statement would have been needed for the package.</p>
<p>For example, if my Scala code has been:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">package</span> Speaker</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">class</span> ScalaSpeaker {</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    def Speak() {</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        println(<span style="color: #006080;">"Hello"</span>);</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }
    def Speak(name: String) {</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        println(<span style="color: #006080;">"Hi, "</span> + name + <span style="color: #006080;">", glad you could join us!"</span>)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
<p>Then my C# would need “using Speaker;”</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=80</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala XNA</title>
		<link>http://www.benbarefield.com/blog/?p=79</link>
		<comments>http://www.benbarefield.com/blog/?p=79#comments</comments>
		<pubDate>Thu, 28 Jul 2011 14:03:59 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=79</guid>
		<description><![CDATA[One of the things that I thought would be a really cool demonstration of Scala.Net was to have an XNA application that was coded completely in Scala. I have mixed news on the subject. I did successfully get an XNA window opened and the game loop running. However, as far as I can tell, all [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that I thought would be a really cool demonstration of Scala.Net was to have an XNA application that was coded completely in Scala. I have mixed news on the subject. I did successfully get an XNA window opened and the game loop running. However, as far as I can tell, all of the ways to draw in XNA rely on generics, which are not yet supported in Scala.Net.</p>
<p>After a short email exchange with <a href="http://lamp.epfl.ch/~magarcia/">Miguel</a>, I was able to get Scala compiling against some of the XNA assemblies. This allowed me to extend the Game class and open an XNA window. The problem I was having was compiling the Scala against multiple dependent dlls. I expected the “Xassem-path”argument to take multiple parameters, one for each of the assemblies. Instead, the solution was to add another –Xassem-extdirs path that contained the XNA assemblies (and mscorlib.) My compile looks like:</p>
<p>&lt;Scala.Net directory&gt;\bin\scalacompiler.exe&#160; <br />–target:msil&#160; <br />–Xassem-extdirs &lt;Scala.Net directory&gt;\bin    <br />-Xassem-extdirs &lt;directory with XNA assemblies&gt;    <br />-Xshow-class &lt;Scala class with main defined&gt;    <br />-Xassem-name &lt;Name of MSIL file to output&gt;    <br />&lt;scala files&gt;</p>
<p>After running ilasm on the MSIL file generated, corflags needs to be run on the resulting executable to put it into <a href="http://www.benbarefield.com/blog/?p=77">32 bit mode</a>. Running the executable opens the game window.</p>
<p>This is certainly a proof of concept; unfortunately that is as far as I could reasonably get. Miguel seems committed to getting Generics support in Scala.Net, so it should be possible to build a full game soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=79</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>x86 .Net Assembly, Scala, and a x64 processor. Oh My!</title>
		<link>http://www.benbarefield.com/blog/?p=77</link>
		<comments>http://www.benbarefield.com/blog/?p=77#comments</comments>
		<pubDate>Wed, 27 Jul 2011 00:30:29 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=77</guid>
		<description><![CDATA[While playing around with Scala.Net today I ran into an interesting problem. I was trying to build some Scala code against an assembly built for x86 and I got an exception when I ran the executable: Unhandled Exception: System.BadImageFormatException: Could not load file or assembly […]. An attempt was made to load a program with [...]]]></description>
			<content:encoded><![CDATA[<p>While playing around with Scala.Net today I ran into an interesting problem. I was trying to build some Scala code against an assembly built for x86 and I got an exception when I ran the executable:</p>
<p>Unhandled Exception: System.BadImageFormatException: Could not load file or assembly […]. An attempt was made to load a program with an incorrect format…</p>
<p>After a bunch of internet searches, and some help from <a href="http://twitter.com/#!/billwagner">Bill Wagner</a>, I got this working. The executable needs to be set to run in 32 bit mode. This can be done with the corflags tool. corflags will exist in your path from a Visual Studio terminal. The trick is:</p>
<p>corflags &lt;Executable name&gt; /32Bit+</p>
<p>After that everything worked.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=77</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling Scala from C#</title>
		<link>http://www.benbarefield.com/blog/?p=76</link>
		<comments>http://www.benbarefield.com/blog/?p=76#comments</comments>
		<pubDate>Wed, 27 Jul 2011 00:21:16 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=76</guid>
		<description><![CDATA[Yesterday, I figured out how to call some C# code from Scala. It is a small leap to then call Scala from C#. The process just gets turned around: instead of creating a C# class library and referencing it from Scala, you create a dll from Scala code and reference it in .Net. First, I [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I figured out how to call some C# code from Scala. It is a small leap to then call Scala from C#. The process just gets turned around: instead of creating a C# class library and referencing it from Scala, you create a dll from Scala code and reference it in .Net.</p>
<p>First, I built a class in Scala similar to my C# class from yesterday:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">class</span> ScalaSpeaker {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    def Speak() {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        println(<span style="color: #006080">&quot;Hello&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    def Speak(name: String) {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        println(<span style="color: #006080">&quot;Hi, &quot;</span> + name + <span style="color: #006080">&quot;, glad you could join us!&quot;</span>)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre>
<p><!--CRLF--></div>
</div>
<p>Just like before, the Scala needs to be compiled to MSIL. There are fewer arguments needed because the Scala is not referencing any other dlls and does not contain the entry point for the executable:</p>
<p>&lt;Scala.Net directory&gt;\bin\scalacompiler.exe<br />
  <br />–target:msil </p>
<p>–Xassem-extdirs &lt;Scala.Net directory&gt;\bin </p>
<p>&lt;scala files&gt;</p>
<p>Where:</p>
<ul>
<li>&lt;Scala.Net directory&gt; is the directory where the Scala.Net SVN repository was checked out to </li>
</ul>
<p>After the MSIL has been generated, it can be turned into a dll:</p>
<p>ilasm /DLL &lt;MSIL file&gt;</p>
<p>Notice the /DLL flag for ilasm, this is where the magic happens. </p>
<p>After running ilasm, the new Scala dll can be referenced in a .Net application. I created a console application and added a reference to the dll. For the application to run propertly there are a few more dlls that need to be referenced, all of which can be found in the bin directory of the SVN repository:</p>
<p>CSharpFilesForBootstrap.dll<br />
  <br />IKVM.OpenJDK.Core.dll </p>
<p>jfisl.dll </p>
<p>scalalib.dll </p>
<p>scalaruntime.dll</p>
<p>The C# is very straight forward, and surprisingly doesn’t require any extra using statements:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">namespace</span> CallScala</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">class</span> Program</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            var speaker = <span style="color: #0000ff">new</span> ScalaSpeaker();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            speaker.Speak();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            speaker.Speak(<span style="color: #006080">&quot;Jim&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre>
<p><!--CRLF--></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=76</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with Scala.Net</title>
		<link>http://www.benbarefield.com/blog/?p=74</link>
		<comments>http://www.benbarefield.com/blog/?p=74#comments</comments>
		<pubDate>Tue, 26 Jul 2011 15:59:55 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=74</guid>
		<description><![CDATA[Reporting from the Programming Summer Camp in Crested Butte, Colorado. This has got to be one of the better places in the world to code. We had a great warm up bike ride this morning, then settled in for an afternoon of coding. I spent my time figuring out Scala.Net with the goal of calling [...]]]></description>
			<content:encoded><![CDATA[<p>Reporting from the <a href="https://sites.google.com/site/programmingsummercamp/">Programming Summer Camp</a> in Crested Butte, Colorado. This has got to be one of the better places in the world to code. We had a great warm up bike ride this morning, then settled in for an afternoon of coding. I spent my time figuring out <a href="http://www.scala-lang.org/node/10299">Scala.Net</a> with the goal of calling some C# code from Scala.</p>
<p>The Scala.net compiler is in an SVN repository located at: <a title="http://lampsvn.epfl.ch/svn-repos/scala/scala-experimental/trunk/bootstrap" href="http://lampsvn.epfl.ch/svn-repos/scala/scala-experimental/trunk/bootstrap">http://lampsvn.epfl.ch/svn-repos/scala/scala-experimental/trunk/bootstrap</a></p>
<p>I started by writing a small C# class library. I created one class with a couple of methods. This is pretty standard “getting up to speed” stuff:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">using</span> System;</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">namespace</span> Echidna</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">{</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> Speaker</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Speak()</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Console.WriteLine(<span style="color: #006080;">"Hi there."</span>);</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Speak(<span style="color: #0000ff;">string</span> name)</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Console.WriteLine(<span style="color: #0000ff;">string</span>.Format(<span style="color: #006080;">"Hi, {0}, glad you could join us."</span>, name));</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        }</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
<p>&nbsp;</p>
</div>
</div>
<p>Next, I dove into the Scala. For this experiment all I needed was an object whose Main created an instances of my C# class and called its methods:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">import</span> Echidna.Speaker</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">object Test {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    def main(args: Array[String]) {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        val speaker = <span style="color: #0000ff;">new</span> Speaker()</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        speaker.Speak</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        speaker.Speak(<span style="color: #006080;">"Joe"</span>)</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
<p>&nbsp;</p>
</div>
</div>
<p>I’d like to note here that the import is a Scala import statement (not a C# include), so the class name needs to be included. I could also have written “import Echidna._” to get everything from the Echidna namespace. The compiler error did not make it especially obvious that I had messed this up.</p>
<p>With all my code built I could start compiling. Currently, there are two steps to create an executable, but there are plans to get rid of the second step. First, MSIL is created using the Scala.Net compiler:</p>
<p>&lt;Scala.Net directory&gt;\bin\scalacompiler.exe</p>
<p>-target:msil</p>
<p>-Xassem-extdirs &lt;Scala.Net directory&gt;\bin</p>
<p>-Xshow-class &lt;Scala entry class&gt;</p>
<p>-Xassem-path &lt;Dependent Assemblies&gt;<br />
&lt;Scala files&gt;</p>
<p>This is the bare minimum required to compile the Scala into MSIL. I inserted the new lines for ease of reading and to make it more obvious what is going on. Notes:</p>
<ul>
<li><span style="color: #333333;">&lt;Scala.Net directory&gt; should be the directory that you pulled the SVN repository into</span></li>
<li>&lt;Scala entry class&gt; is the Scala class that should serve as the entry point for your program. In my case it was “Test”</li>
<li>&lt;Dependent Assemblies&gt; are the .Net assemblies your Scala program relies on. In my case this was “Echidna.dll”</li>
<li>&lt;Scala files&gt; are your Scala source files. In my case it was “simple.scala”</li>
</ul>
<p>Next, the MSIL needs to be turned into an executable using ilasm. I opened a Visual Studio command prompt so that ilasm was in my Path:</p>
<p>ilasm Test.msil</p>
<p>The last problem I ran into was that the executable couldn’t find scalalib.dll, so I copied it out of the directory where the compiler is (the same as &lt;Scala.Net directory&gt;.) After this, my executable ran perfectly.</p>
<p>More information on the compiler and it’s capabilities (for example, it does not currently support .Net generics) can be found at: <a title="http://lamp.epfl.ch/~magarcia/ScalaNET/2011Q2/PreviewScalaNET.pdf" href="http://lamp.epfl.ch/~magarcia/ScalaNET/2011Q2/PreviewScalaNET.pdf">http://lamp.epfl.ch/~magarcia/ScalaNET/2011Q2/PreviewScalaNET.pdf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=74</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kinect: Getting Started</title>
		<link>http://www.benbarefield.com/blog/?p=69</link>
		<comments>http://www.benbarefield.com/blog/?p=69#comments</comments>
		<pubDate>Fri, 17 Jun 2011 17:12:44 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Kinect]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=69</guid>
		<description><![CDATA[Microsoft released its Kinect SDK yesterday. It can be found here. I spent yesterday afternoon building my own sample application to explore the API and Microsoft’s samples. The API documentation is fairly comprehensive and the getting started guide is a quick read (on the Kinect SDK website, not included in the download). The two samples [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft released its Kinect SDK yesterday. It can be found <a href="http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/default.aspx">here</a>. I spent yesterday afternoon building my own sample application to explore the API and Microsoft’s samples. </p>
<p>The API documentation is fairly comprehensive and the getting started guide is a quick read (on the Kinect SDK website, not included in the download). The two samples are large and cover all the major points of the API. I think I would have preferred smaller, more targeted samples, but they are still good for figuring out how to use pieces of the API.</p>
<p>The Kinect hardware does quite a bit of processing, so the API is fairly easy to work with. Pulling color image data off of the device is almost trivial:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">var kinect = <span style="color: #0000ff">new</span> Runtime();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">kinect.Initialize(RuntimeOptions.UseColor);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">kinect.VideoStream.Open(ImageStreamType.Video,</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">   2, ImageResolution.Resolution640x480, ImageType.Color);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">kinect.VideoFrameReady += HandleNewColorVideoFrame;</pre>
<p><!--CRLF--></div>
</div>
<p>This is all the code needed to start receiving video from the Kinect. Every time there is a new frame available the “HandleNewColorVideoFrame” method will get called. The EventArgs has a property that contains the image data of the new frame.</p>
<p>The really revolutionary part of the Kinect is the depth map it provides of the scene it can see. For each frame of the depth map video it can create detailed skeletal information about two people in the scene. This skeletal information gives the (X, Y, Z) absolute position of 20 points on the body and the confidence of that absolute position. The confidence is mostly for points that the Kinect cannot directly see. For example, the Kinect will still try to track my hand if I put it behind my back. It is just as easy to get the skeletal data as it is to get the color video image:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">kinect = <span style="color: #0000ff">new</span> Runtime();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">kinect.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">   RuntimeOptions.UseSkeletalTracking);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">kinect.DepthStream.Open(ImageStreamType.Depth, 2,</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">  ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">kinect.SkeletonFrameReady += ProcessSkeletonFrame;</pre>
<p><!--CRLF--></div>
</div>
<p>ProcessSkeletonFrame will be called every time the Depth video has a new frame. The EventArgs contains a list of all of the skeletons the Kinect has information about.</p>
<p>This is all the code you need to get up and running with a Kinect. It’s pretty awesome that it takes so little to start working with it; however, working with it is by no means easy. There are a lot of considerations that need to be made to make the Kinect a good user experience. In my next post I will go over a couple gotchas that I encountered while building my sample.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=69</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Immersion</title>
		<link>http://www.benbarefield.com/blog/?p=63</link>
		<comments>http://www.benbarefield.com/blog/?p=63#comments</comments>
		<pubDate>Fri, 08 Apr 2011 17:48:26 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=63</guid>
		<description><![CDATA[So far in my time at SRT I have used both Mercurial and Bazaar, but I hadn’t gotten around to Git until yesterday. I finished the Git Immersion tutorial by Jim Weirich and would highly suggest going through it. There is a lot of good information in the lessons, even for those of us who [...]]]></description>
			<content:encoded><![CDATA[<p>So far in my time at SRT I have used both Mercurial and Bazaar, but I hadn’t gotten around to Git until yesterday. I finished the <a href="http://gitimmersion.com/" target="_blank">Git Immersion</a> tutorial by Jim Weirich and would highly suggest going through it. There is a lot of good information in the lessons, even for those of us who are familiar with other distributed version control systems.</p>
<p>I think Git’s idea of tracking changes instead of files is a really cool way to think about source control. Change tracking instead of file tracking allows us to create much more granular commits, giving even more control over multiple versions of our source.</p>
<p>However, I think the way this is implemented in Git makes using it a bit more of a burden. Needing to add each change to a staging area does not feel like&#160; Git “getting out of the way until you need to deal with source control”. I have to either be constantly adding changes to my source control as I make them, or I have to figure out how everything should be committed after I’ve written the code. It also means that every time I want to add changes to source control I have an additional step to take over a more “traditional” source control system. I would much rather see an “opt-out” model of change tracking than an “opt-in” model. Most of the time, all of my changes should be taken together as a single commit. When I do have changes that should be separated into their own commit they are in the minority of the changes that I have made.</p>
<p>Currently, Git has not convinced me to convert from Mercurial, especially since I currently have a few repositories on BitBucket, but I think it is very worth while to know all of the options out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=63</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight follow-up: WPF memory leak</title>
		<link>http://www.benbarefield.com/blog/?p=62</link>
		<comments>http://www.benbarefield.com/blog/?p=62#comments</comments>
		<pubDate>Thu, 07 Apr 2011 19:41:37 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=62</guid>
		<description><![CDATA[In my last post, I wrote about a memory leak that is easy to come by in WPF. I converted the WPF test application I was using to Silverlight to see whether or not Silverlight suffers from the same memory leak. Turns out it doesn’t! Classes get disposed just as you would expect them to. [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.benbarefield.com/blog/?p=59" target="_blank">last post</a>, I wrote about a memory leak that is easy to come by in WPF. I converted the WPF test application I was using to Silverlight to see whether or not Silverlight suffers from the same memory leak.</p>
<p>Turns out it doesn’t! Classes get disposed just as you would expect them to. It’s nice that at least one of these platforms doesn’t have this bug, but I think it’s too bad that we can’t expect consistency between WPF and Silverlight.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=62</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF Gotcha: Easy Memory Leak</title>
		<link>http://www.benbarefield.com/blog/?p=59</link>
		<comments>http://www.benbarefield.com/blog/?p=59#comments</comments>
		<pubDate>Fri, 11 Mar 2011 15:28:52 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.benbarefield.com/blog/?p=59</guid>
		<description><![CDATA[I strongly suggest that you implement INotifyPropertyChanged on any class that will be a binding source. I’ve been doing some memory profiling recently and ran into a HashTable outside of my code that was holding on to a reference to one of my view models. Here is Microsoft’s listing on the leak. The basic idea [...]]]></description>
			<content:encoded><![CDATA[<p>I strongly suggest that you implement INotifyPropertyChanged on any class that will be a binding source. I’ve been doing some memory profiling recently and ran into a HashTable outside of my code that was holding on to a reference to one of my view models. <a href="http://support.microsoft.com/kb/938416/en-us" target="_blank">Here</a> is Microsoft’s listing on the leak.</p>
<p>The basic idea is that when the source of a binding is a(non-Dependency) property on a class that does not implement INotifyPropertyChanged, WPF creates a ReflectPropertyDescriptor to facilitate the binding. The Microsoft page seems to suggest that this should allow for updating the binding value when the backing property changes, but this doesn’t actually work. The ReflectPropertyDescriptor gets added to a global table and does not get removed, creating a memory leak. </p>
<p>At first glance, it looks like your view model needs to have a reference to the View because of the second condition: </p>
<blockquote><p>Object <b><var>X</var></b> contains a direct reference or an indirect reference to the target of the data-binding operation.</p>
</blockquote>
<p>Later there is a note that says that the binding can cause this “indirect reference” to the view:</p>
<blockquote><p>The reference between object X and the data-binding target is caused by the first condition that is listed in the &quot;Cause&quot; section.</p>
</blockquote>
<p>I have <a href="https://bitbucket.org/benbarefield/wpfmemorybug/overview" target="_blank">created a simple test bed application</a> that shows the problem. Setting a break point in the Finalizer of ViewModelOne shows the memory leak. When INotifyPropertyChanged is not implemented, the Finalizer never gets called. Adding the implementation of INotifyPropertyChanged allows the Finalizer to get called.</p>
<p>The take-away? Make sure you implement INotifyPropertyChanged on view models. Microsoft calls this behavior “by design”. It sounds an awful lot like a bug to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benbarefield.com/blog/?feed=rss2&#038;p=59</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

