03 May 2009

Playing around with Syntax Highlighter

 

Feel free to ignore this post. I’m toying around with changing the code on my blog to use the syntax highlighting made possible via:

Rather than the rather bloated (and unfriendly to RSS readers) paste from Visual Studio, I thought I’d try this. The “paste from VS” method retained all the colors and formatting from VS, but just made for bloated posts and left RSS readers (most anyway) with a jumbled mess without any line breaks. I need to actually post this live to see if this approach also gets munged in RSS readers.

XAML (using the XML formatting style)

<UserControl x:Class="PeteBrown.SilverlightSoundTest.Page"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:ui="clr-namespace:PeteBrown.SilverlightSoundTest.UI">
    <Grid x:Name="LayoutRoot" Background="{StaticResource MainBackgroundBrush}">

        <Grid>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="320" />
                <ColumnDefinition Width="320" />
                <ColumnDefinition Width="320" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <ui:OscillatorEditor x:Name="Oscillator1Editor"
                                 Margin="5 5 0 5"
                                 Grid.Column="0"
                                 Grid.Row="0" />
            <ui:OscillatorEditor x:Name="Oscillator2Editor"
                                 Margin="0 5 0 5"
                                 Grid.Column="1"
                                 Grid.Row="0" />
            <ui:OscillatorEditor x:Name="Oscillator3Editor"
                                 Margin="0 5 5 5"
                                 Grid.Column="2"
                                 Grid.Row="0" />


            <ui:MixerEditor x:Name="MixerEditor"
                            Margin="5 5 5 5"
                            Grid.Row="1"
                            Grid.ColumnSpan="2" />



            <MediaElement x:Name="AudioPlayer"
                          AutoPlay="True" />



        </Grid>

C# code (using the C# formatting style)

for (int i = 0; i < MaxWaveforms; i++)
{
    double phase = CalculatePhaseWithOffset(state.PhaseOffset, state.Phase[i]);
    double sample = (state.MaxAmplitude.Value - (state.MaxAmplitude.Value / Math.PI) * phase) * (int)state.Polarity;

    //if (i % 2 != 0)
    //    sample *= -1;

    accumulatedAmplitude += sample;

    state.Phase[i] = CheckPhase(state.Phase[i] + ((MathUtility.TwoPI * detune[i]) / _sampleRate.SamplesPerSecond));

    //accumulatedAmplitude *= .75;    // warning, magic number at work

}
Share |
posted by Pete Brown on Sunday, May 03, 2009
filed under:  

4 comments for “Playing around with Syntax Highlighter”

  1. Pete Brownsays:
    Bummer. Looks like the rendering in RSS readers like outlook is still pretty poor (no line breaks). Not sure how it shows up in other readers.

    Since the rss reader experience doesn't seem any worse, but the online experience is better (automatic line wrapping, much easier copying of the raw source etc.) I'll probably stick with it.

    The copy/paste workflow when writing a post is a bit more cumbersome, but appears worth the final result.

    RSS Readers get no syntax highlighting in the new approach, but if they were getting mushed source in the past anyway, this isn't really any worse.

    Pete
  2. Steve Dunnsays:
    Hi Pete,
    Enjoying the blog - especially the C64 stuff. I loved the old machine! Some of my games are on Lemon 64, e.g. http://www.lemon64.com/games/details.php?ID=259

    I thought you'd like to know about my plug-in for Windows Live Writer that uses different kinds of formatting engines (SyntaxHighlighter (JavaScript), ActiPro (inline styles (also works in aggregators, and bitmap (looks the same everywhere!)). More info at http://stevedunns.blogspot.com/2009/03/update-to-code-formatter-plugin.html

    Cheers,

    Steve
    http://blog.dunnhq.com
  3. Ruurd Boekesays:
    yeah, exact same sentiment here. I've moved to syntax highlighter a few weeks ago and it has definitely been for the better.

    Google reader displays the code perfect (without highlighting ofcourse), but outlook does not.
    There is an option though, convert to br, that might help.

    Cheers,
    rj
  4. Pete Brownsays:
    @Ruurd

    Thanks. The convert to BR doesn't work in the latest version of the highlighter. However, the author is looking into it.

    Pete

Comment on this Post

Remember me