Wednesday, December 17, 2008

WPF MediaElement Requires Updated Windows Media Player

I just spent several baffled hours trying to figure out why some WPF media playback code that worked just fine on my previous computer was failing to work on my new computer.

It turns out that it wasn't my code at all. It seems that the WPF MediaElement control (which is used to play content using Windows Media Player) doesn't work with WMP version 9 (which is what came installed on my new PC).

Upgrading to the latest (version 11) fixed the problem.

Monday, December 15, 2008

Interactive Function Plotting Using Runtime Compilation of C# Assemblies



Every once in a while I have a need to plot some arbitrary mathematical function to see what it looks like. It happened to me recently when working on my FM Synth project, so I decided to whip up a quick-and-dirty plotting app.

The main issue with creating the app was how to allow for specifying the function(s) to be plotted. Obviously, I did not want to write a custom mathematical function parser. Instead, I leveraged the ability of .NET to create assemblies at runtime using the CodeDomProvider class.

I already had some code to do this that I used to allow runtime evaluation of C# expressions in the console of my city driving game, and I was able to repurpose it with very little effort.

The result is pretty cool. Any number of functions can be specified as arbitrary C# expressions. I dynamically create a class, and add the expressions as methods within it. I also a a special property, 'X', which returns the current X value of the plot. As you can see below, you can call one function from within another and use multiple lines of code.



The start and end values for X are also arbitrary expressions.

The use of CodeDomProvider to generate assemblies at runtime is definitely a very powerful tool that I'm sure I'll find more uses for.

Friday, December 5, 2008

FM Synth W.I.P.



My little FM synth is coming along nicely. C# codebase with a WPF UI.

The shot above is the main editor page. I'm currently using four oscillators which can either be output directly, or used to modulate each other. Fun stuff.

Thursday, December 4, 2008

Changing the text style of a WPF GroupBox header

I wanted to change the style of the header of a WPF GroupBox today and had to do a little digging to figure out how to do it.

The GroupBox header is not limited to just text - it can be any control. Because of this, no header text styling options are available directly as properties of the GroupBox control. Instead, you need to modify the DataTemplate of the GroupBox header.

Here is a style that will make the GroupBox header text black and bold:

<Style x:Key="MyGroupBoxStyle" TargetType="{x:Type GroupBox}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Black" FontWeight="Bold"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>


Note that this method is a bit of a hack, in that it assumes that your header is text. If it isn't, though, you've added your own custom controls to the header and you don't have a styling problem in the first place...

Wednesday, December 3, 2008

The KORG DS-10: A Pocket-Sized Retro-Synth

KORG DS-10

The KORG DS-10 is a new title for the Nintendo DS. It isn't a game, though - it is a faithful reproduction of the Korg MS-10 analog synthesizer.

It features six two-oscillator voices (two synths and four drums), a 16-step pattern editor and a mini song sequencer.

KORG DS-10

It also lets you patch stuff together and apply some simple effects.

KORG DS-10

The DS stylus works great as an interface - particularly when controlling the "KAOSS" pad (essentially an X/Y axis input device for interactively modifying pattern data and synthesizer parameters).

I've been meaning to code my own FM synth for a while now, and playing with the DS-10 has finally got me started. More on that to come.

Here's a video of the original MS-10:

Thursday, October 23, 2008

More Automatic City Generation



I'm still playing with my city generator. I now segment the city into districts of different types, resulting in a more diversity. I also have traffic moving around, path-following through the streets and obeying traffic lights. Fun stuff.

For car dynamics, I'm using the Farseer physics engine - a fully managed codebase that is really easy to integrate with XNA.

Monday, October 6, 2008

Fun with XNA and Automatic City Generation

Auto-generated cityscape

I've been playing around with Microsoft's XNA recently. It is essentially a flavor of managed DirectX targeted specifically at gaming (both on Windows and the Xbox360).

Part of my current project involves auto-generation of cityscapes. Things are starting to shape up a bit, so I figured I would post a few screenshots.

Auto-generated cityscape

I don't have an Xbox360 at the moment (I'm a happy PS3 owner), but I'm considering picking one up since you can build XNA projects for it and download and play them on the console.