<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>cwbowron</title>
	<atom:link href="http://cwbowron.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cwbowron.wordpress.com</link>
	<description>Nerd Stuff</description>
	<lastBuildDate>Tue, 24 Nov 2009 20:22:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='cwbowron.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>cwbowron</title>
		<link>http://cwbowron.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://cwbowron.wordpress.com/osd.xml" title="cwbowron" />
	<atom:link rel='hub' href='http://cwbowron.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Moving&#8230;</title>
		<link>http://cwbowron.wordpress.com/2009/11/24/moving/</link>
		<comments>http://cwbowron.wordpress.com/2009/11/24/moving/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 20:22:42 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=200</guid>
		<description><![CDATA[I&#8217;m moving my blog over to a wordpress installation on my own domain. New posts will be there. http://www.bowron.us/wordpress/blog/ Please update your feed reader accordingly. Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=200&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m moving my blog over to a wordpress installation on my own domain.  New posts will be there.  </p>
<p>http://www.bowron.us/wordpress/blog/</p>
<p>Please update your feed reader accordingly.</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=200&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/11/24/moving/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>VLC and PLT Scheme [n+1]</title>
		<link>http://cwbowron.wordpress.com/2009/11/20/vlc-and-plt-scheme-n1/</link>
		<comments>http://cwbowron.wordpress.com/2009/11/20/vlc-and-plt-scheme-n1/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 20:45:46 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[PLT-scheme]]></category>
		<category><![CDATA[VLC]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=185</guid>
		<description><![CDATA[I figured out how to playback video inside a PLT Scheme gui window. media-player-window% below is a panel that displays an embedded video and 4 methods for controlling the playback: load, play, stop and release. It is dependent on my vlc foreign function interface, included below the media-player-window% code. Note that for reasons I don&#8217;t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=185&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I figured out how to playback video inside a PLT Scheme gui window.  media-player-window% below is a panel that displays an embedded video and 4 methods for controlling the playback: <em>load</em>, <em>play</em>, <em>stop</em> and <em>release</em>.  It is dependent on my vlc foreign function interface, included below the media-player-window% code.</p>
<p>Note that for reasons I don&#8217;t fully grok, the mrl for a file is actually &#8220;file:///filename.ext&#8221;.  Yes, THREE slashes.</p>
<p><pre class="brush: cpp;">
(define media-player-window%
  (class vertical-panel%
    
    (define vlc-exception (make-vlc-exception #f 0 &quot;&quot;))
    (define vlc-instance
      (let* ([vlc-args (vector
                        &quot;--ignore-config&quot;
                        (string-append &quot;--plugin-path=&quot; VLC-PLUGIN-PATH)
                        )])
        (libvlc_new (vector-length vlc-args) vlc-args vlc-exception)))
    
    (define vlc-media #f)
    (define vlc-player #f)
        
    (define/public (load file)
      (let* ([media-mrl (string-append &quot;file:///&quot; file)])
        (set! vlc-media (libvlc_media_new vlc-instance media-mrl vlc-exception))        
        (set! vlc-player (libvlc_media_player_new_from_media vlc-media vlc-exception))
        (libvlc_media_player_set_drawable vlc-player (send vlc-display-panel get-handle) vlc-exception)))
    
    (define/public (play)
      (libvlc_media_player_play vlc-player vlc-exception))
    
    (define/public (stop)
      (libvlc_media_player_stop vlc-player vlc-exception))
    
    (define/public (release)
      (when vlc-player
        (libvlc_media_player_release vlc-player))
      (when vlc-media
        (libvlc_media_release vlc-media))
      (when vlc-instance
        (libvlc_release vlc-instance))
      (set! vlc-player #f)
      (set! vlc-media #f)
      (set! vlc-instance #f))
        
    (super-new)    
    
    (define vlc-display-panel (new panel% [parent this]))))
</pre></p>
<p>vlc-ffi.ss:<br />
<pre class="brush: cpp;">
#lang scheme

(require scheme/foreign)
(unsafe!)

(provide (all-defined-out))

(define vlc-path &quot;C:\\Program Files (x86)\\VideoLAN\\VLC\\&quot;)

(define libvlccore (ffi-lib (string-append vlc-path &quot;libvlccore&quot;)))
(define libvlc (ffi-lib (string-append vlc-path &quot;libvlc&quot;)))

(define-syntax define-pointer
  (syntax-rules ()
    ((_ ptr-type)
     (define ptr-type 
       (_cpointer/null (quote ptr-type))))))

(define-pointer vlc-instance)
(define-pointer vlc-media)
(define-pointer vlc-media-player)

(define-cstruct _vlc-exception ((raised _bool) (code _int32) (message _string)))

(define vlc-state
  (_enum '(libvlc_NothingSpecial libvlc_Opening libvlc_Buffering libvlc_Playing
           libvlc_Paused libvlc_Stopped 
           ;;; libvlc_Forward libvlc_Backward 
           libvlc_Ended libvlc_Error)))

(define-syntax define-vlc
  (syntax-rules ()
    ((_ fn args)
     (define fn 
       (get-ffi-obj (quote fn) libvlc args)))))



(define-vlc libvlc_exception_init (_fun _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_new         (_fun _int32 (_vector i _string/utf-8)  _vlc-exception-pointer -&gt; vlc-instance))
(define-vlc libvlc_get_version (_fun -&gt; _string/utf-8))
(define-vlc libvlc_release     (_fun vlc-instance -&gt; _void))
(define-vlc libvlc_add_intf    (_fun vlc-instance _string/utf-8 _vlc-exception-pointer -&gt; _void))

;;;
(define-vlc libvlc_media_new          (_fun vlc-instance _string/utf-8 _vlc-exception-pointer -&gt; vlc-media))
(define-vlc libvlc_media_get_duration (_fun vlc-media _vlc-exception-pointer -&gt; _int64))
(define-vlc libvlc_media_get_meta     (_fun vlc-media _int32 _vlc-exception-pointer -&gt; _string))
(define-vlc libvlc_media_get_mrl      (_fun vlc-media _vlc-exception-pointer -&gt; _string))
(define-vlc libvlc_media_release      (_fun vlc-media -&gt; _void))

;;;;;;;;;;;;;;
(define-vlc libvlc_media_player_new_from_media (_fun vlc-media _vlc-exception-pointer -&gt; vlc-media-player))
(define-vlc libvlc_media_player_release        (_fun vlc-media-player -&gt; _void))

(define-vlc libvlc_media_player_play           (_fun vlc-media-player _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_media_player_pause          (_fun vlc-media-player _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_media_player_stop           (_fun vlc-media-player _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_media_player_set_position   (_fun vlc-media-player _float _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_media_player_set_drawable (_fun vlc-media-player _int32 _vlc-exception-pointer -&gt; _void))

(define-vlc libvlc_media_player_get_time       (_fun vlc-media-player _vlc-exception-pointer -&gt; _int64))
(define-vlc libvlc_media_player_get_position   (_fun vlc-media-player _vlc-exception-pointer -&gt; _float))
(define-vlc libvlc_media_player_get_length     (_fun vlc-media-player _vlc-exception-pointer -&gt; _int64))
(define-vlc libvlc_media_player_get_state      (_fun vlc-media-player _vlc-exception-pointer -&gt; vlc-state))
;;;(define-vlc libvlc_media_player_get_state      (_fun vlc-media-player _vlc-exception-pointer -&gt; _fixnum))

</pre></p>
<br />Posted in Programming, Scheme  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/185/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=185&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/11/20/vlc-and-plt-scheme-n1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>Twitter Update from PLT Scheme</title>
		<link>http://cwbowron.wordpress.com/2009/05/29/twitter-update-from-plt-scheme/</link>
		<comments>http://cwbowron.wordpress.com/2009/05/29/twitter-update-from-plt-scheme/#comments</comments>
		<pubDate>Fri, 29 May 2009 20:35:50 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=178</guid>
		<description><![CDATA[I was contemplating doing some automated twittering from schemep3, possibly when I change albums. [For an automatic update on my progress through the 1,001 albums]. Anyway, I got it to work so here&#8217;s the function. No error checking or success fail notification. Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=178&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was contemplating doing some automated twittering from schemep3, possibly when I change albums.  [For an automatic update on my progress through the 1,001 albums].</p>
<p>Anyway, I got it to work so here&#8217;s the function.  No error checking or success fail notification.</p>
<p><pre class="brush: cpp;">
#lang scheme

(provide twitter)

(require net/base64)
(require net/url)

(define (strip-crlf b64-bytes)
  (subbytes b64-bytes 0 (- (bytes-length b64-bytes) 2)))

;;; note that this uses the very insecure basic authorization method...
(define (twitter username password status)
  (let* ([basic-auth (strip-crlf (base64-encode (string-&gt;bytes/utf-8 (string-append username &quot;:&quot; password))))])
    (let ([url 
           (make-url
            &quot;http&quot;
            #f
            &quot;twitter.com&quot;
            80
            #t
            (list 
             (make-path/param &quot;statuses&quot; (list))
             (make-path/param &quot;update.xml&quot; (list)))
            (list
             (cons 'status status))
            #f)])
      (let ([port 
             (post-impure-port
              url
              #&quot;&quot;
              (list
               (string-append &quot;Authorization: Basic &quot; (bytes-&gt;string/utf-8 basic-auth))))])
        (close-input-port port)))))
</pre></p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/178/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=178&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/05/29/twitter-update-from-plt-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>Multiple Return Values</title>
		<link>http://cwbowron.wordpress.com/2009/05/29/multiple-return-values/</link>
		<comments>http://cwbowron.wordpress.com/2009/05/29/multiple-return-values/#comments</comments>
		<pubDate>Fri, 29 May 2009 13:45:53 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=173</guid>
		<description><![CDATA[This one&#8217;s for you Vincent. (But feel free to chime in Ethan) It seems that the best way to elegantly and efficiently write a function to find a key in a hash table, dictionary, etc is to write a function with two return values. First value is whether or not the item was located, second [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=173&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This one&#8217;s for you Vincent.  (But feel free to chime in Ethan)</p>
<ul>
<li> It seems that the best way to elegantly and efficiently write a function to find a key in a hash table, dictionary, etc is to write a function with two return values.  First value is whether or not the item was located, second value is the actual value for the key.  Only problem I&#8217;m not sure that there are any cases where having a key in the hash table with the value of FALSE would be treated any differently then just not having the key in the table in the first place.</li>
<li>If we accept that there are functions that must return multiple values to be useful or efficient, [e.g. HashLookup or yuv2rgb()], then as far as I can see, you have three options:
<ol>
<li>Language support for real multiple values returned from functions
</li>
<li>user kludged multiple values using list or a data structure</li>
<li>language kludge it by using output variables passed by reference or mutable data structure to the function. </li>
<p>I don&#8217;t like option 2 because it forces consing / memory allocation when it could potentially be avoided and option 3 requires mutable data structures or pass by reference, and those are not very Functional Programming friendly.
</li>
</ol>
</ul>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=173&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/05/29/multiple-return-values/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>Hemingway</title>
		<link>http://cwbowron.wordpress.com/2009/05/13/hemingway/</link>
		<comments>http://cwbowron.wordpress.com/2009/05/13/hemingway/#comments</comments>
		<pubDate>Wed, 13 May 2009 17:04:29 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/2009/05/13/hemingway/</guid>
		<description><![CDATA[&#8220;Pour one jigger absinthe into a Champagne glass. Add iced Champagne until it attains the proper opalescent milkiness. Drink three to five of these slowly.&#8221; Delicious. Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=172&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8220;Pour one jigger absinthe into a Champagne glass. Add iced Champagne until it attains the proper opalescent milkiness. Drink three to five of these slowly.&#8221;</p>
<p>Delicious.</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=172&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/05/13/hemingway/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>complete-or</title>
		<link>http://cwbowron.wordpress.com/2009/04/29/complete-or/</link>
		<comments>http://cwbowron.wordpress.com/2009/04/29/complete-or/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 15:33:41 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=168</guid>
		<description><![CDATA[The other day I needed a non-short circuiting or. I thought there might be a SRFI for it, but I looked and couldn&#8217;t find one. So I made my own. This is what I came up with: The basic use case was this&#8230; I had a function that called two other functions and returned true [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=168&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The other day I needed a non-short circuiting <strong>or</strong>.  I thought there might be a SRFI for it, but I looked and couldn&#8217;t find one.  So I made my own.</p>
<p>This is what I came up with:</p>
<p><pre class="brush: cpp;">
(define-syntax complete-or 
  (syntax-rules ()
    ((_) #f)
    ((_ e) e)
    ((_ e1 e2 e3 ...)
     (let ((t e1))
       (if t 
	   (begin0 t e2 e3 ...)
	   (complete-or e2 e3 ...))))))
</pre></p>
<p>The basic use case was this&#8230; I had a function that called two other functions and returned true if either of them returned true, but it needed to call both in either case.  One function checked to see if the duration needed to be updated and returned whether it updated it or not, and the other checked whether metadata had changed in the file and updated the database and returned true if it had.  Then the caller needed to post a signal if any fields had changed.</p>
<p>This seemed like a good approach.</p>
<p>The function that uses it, looks like this:</p>
<p><pre class="brush: cpp;">
(define (schemep3-database-reload-item item force?)
  (let ((filename (schemep3-database-index-&gt;filename item)))
    (if (file-exists? filename)
        (when (complete-or
               (schemep3-database-reload-duration item filename force?)
               (schemep3-database-reload-metadata item filename force?))
            (call-update-hooks item))
        (printf &quot;File Does Not Exist: ~A~%&quot; filename))))
</pre></p>
<p>Without a non-shortcutting or, it looked kinda like this:</p>
<p><pre class="brush: cpp;">
(define (schemep3-database-reload-item item force?)
  (let ((filename (schemep3-database-index-&gt;filename item)))
    (if (file-exists? filename)
        (let ([modified (schemep3-database-reload-duration item filename force?)])
          (when (schemep3-database-reload-metadata item filename force?)
            (set! modified #t))
          (when modified
            (call-update-hooks item)))
        (printf &quot;File Does Not Exist: ~A~%&quot; filename))))
</pre></p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/168/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=168&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/04/29/complete-or/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>Finalized Bindings [Addendum]</title>
		<link>http://cwbowron.wordpress.com/2009/04/22/finalized-bindnings-addendum/</link>
		<comments>http://cwbowron.wordpress.com/2009/04/22/finalized-bindnings-addendum/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 19:24:32 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=160</guid>
		<description><![CDATA[After fiddling with some other code, i realized that I could condense my real code a bit. My finalizers where basically (lambda (value) (finalizer-function value)) where I should just actually pass in finalizer-function Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=160&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After fiddling with some other code, i realized that I could condense my real code a bit.  My finalizers where basically <em>(lambda (value) (finalizer-function value))</em> where I should just actually pass in <em>finalizer-function</em></p>
<p><pre class="brush: cpp;">
    (define/public (play file-index callback)
      (let ((file (schemep3-database-index-&amp;gt;filename file-index)))
        (if (not (file-exists? file))
            (values #f #f)
            (with-finalized-binding           
             (lambda () (call-vlc libvlc_media_new (get-vlc-instance) (path-&amp;gt;mrl file)))
             (lambda (media)
               (with-finalized-binding
                (lambda () (call-vlc libvlc_media_player_new_from_media media))
                (lambda (media-player)
                  (call-vlc libvlc_media_player_play media-player)
                  (internal-playback-loop media-player callback))
                libvlc_media_player_release))
             libvlc_media_release))))
</pre></p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=160&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/04/22/finalized-bindnings-addendum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>Finalized Bindings</title>
		<link>http://cwbowron.wordpress.com/2009/04/22/finalized-bindings/</link>
		<comments>http://cwbowron.wordpress.com/2009/04/22/finalized-bindings/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 18:48:34 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=155</guid>
		<description><![CDATA[In VLC backend for schemep3, I have to use what is a fairly common pattern in procedural languages, that doesn&#8217;t translate as well into a functional language. It looks something like this: In my scheme code, this would end up looking like this: But that isnt very functional&#8230; And it&#8217;s ugly and kludgish&#8230; so, I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=155&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In VLC backend for schemep3, I have to use what is a fairly common pattern in procedural languages, that doesn&#8217;t translate as well into a functional language.  It looks something like this:</p>
<p><pre class="brush: cpp;">
Var Bar = NULL;
Variable Foo = LibrarySprocketNew();
if ( Foo )
{
    Bar = LibrarySprocketBeFancy( Foo );
    LibrarySprocketRelease( Foo );
}
return Bar;
</pre></p>
<p>In my scheme code, this would end up looking like this:</p>
<p><pre class="brush: cpp;">
(let ([return-value #f])
  (and-let* ([foo (library_sprocket_new)])
    (set! return-value (do-something-fancy-with-foo foo))
    (library_sprocket_release foo))
  return-value)
</pre></p>
<p>But that isnt very functional&#8230; And it&#8217;s ugly and kludgish&#8230; </p>
<p>so, I came up with this macro:</p>
<p><pre class="brush: cpp;">
(define-syntax with-finalized-binding 
  (syntax-rules ()
    ((_ initial-value-thunk value-thunk finalize-thunk)
     (and-let* ((v (initial-value-thunk)))
       (dynamic-wind
        void
        (lambda () (value-thunk v))
        (lambda () (finalize-thunk v)))))))
</pre></p>
<p>so now the code would look something like this:</p>
<p><pre class="brush: cpp;">
(with-finalized-binding
 (lambda () (library_sprocket_new))
 (lambda (foo) (do-something-fancy-with-foo foo))
 (lambda (foo) (library_sprocket_release foo)))
</pre></p>
<p>It&#8217;s not perfect, but I think its more elegant than it was.</p>
<p>This is how I actually use it in my vlc backend code:</p>
<p><pre class="brush: cpp;">
    (define/public (play file-index callback)
      (let ((file (schemep3-database-index-&gt;filename file-index)))
        (if (not (file-exists? file))
            (values #f #f)
            (with-finalized-binding           
             (lambda () (call-vlc libvlc_media_new (get-vlc-instance) (path-&gt;mrl file)))
             (lambda (media)
               (with-finalized-binding
                (lambda () (call-vlc libvlc_media_player_new_from_media media))
                (lambda (media-player)
                  (call-vlc libvlc_media_player_play media-player)                  
                  (internal-playback-loop media-player callback))
                (lambda (media-player) (libvlc_media_player_release media-player))))
             (lambda (media) libvlc_media_release media)))))
</pre></p>
<br />Posted in Programming, Scheme  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=155&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/04/22/finalized-bindings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>VLC and PLT Scheme [Part II]</title>
		<link>http://cwbowron.wordpress.com/2009/04/20/vlc-and-plt-scheme-part-ii/</link>
		<comments>http://cwbowron.wordpress.com/2009/04/20/vlc-and-plt-scheme-part-ii/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 15:03:20 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=152</guid>
		<description><![CDATA[As promised in last post, here is an example of playing back an mp3 file using the vlc-ffi code. You may have to change the plugin-path parameter depending on your configuration&#8230; Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=152&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As promised in last post, here is an example of playing back an mp3 file using the vlc-ffi code.  You may have to change the plugin-path parameter depending on your configuration&#8230;</p>
<p><pre class="brush: cpp;">
#lang scheme

(require &quot;vlc-ffi.ss&quot;)

(define (play-to-end media-player e)
  (let loop ()
    (let ([state (libvlc_media_player_get_state media-player e)]
          [time (libvlc_media_player_get_time media-player e)])
      (printf &quot;State: ~A Time: ~A~%&quot; state time)
      (unless (member state '(#f libvlc_Stopped libvlc_Ended libvlc_Error))
        (sleep .5)
        (loop)))))

(define (vlc-play media-path)
  (unless (file-exists? media-path)
    (raise (format &quot;Missing File!: ~A&quot; media-path)))

  (printf &quot;VLC Version: ~A~%&quot; (libvlc_get_version))
  (let ([e (make-vlc-exception #f 0 &quot;&quot;)])
    (let* ([vlc-args (vector
                      &quot;--plugin-path=C:\\Program Files\\VideoLAN\\VLC\\plugins&quot;
                      &quot;-I&quot; &quot;dummy&quot;)]
           [vlc (libvlc_new (vector-length vlc-args) vlc-args e)])
      (let* ([media-mrl (string-append &quot;file://&quot; media-path)]
             [vlc-media
              (libvlc_media_new vlc media-mrl e)]
             [vlc-media-player (libvlc_media_player_new_from_media vlc-media e)])
        (libvlc_media_player_play vlc-media-player e)
        (play-to-end vlc-media-player e)
        (libvlc_media_player_stop vlc-media-player e)
        (libvlc_media_player_release vlc-media-player)
        (libvlc_media_release vlc-media)
        (libvlc_release vlc)))))

(vlc-play &quot;path/to/fiile.mp3&quot;)
</pre></p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=152&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/04/20/vlc-and-plt-scheme-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
		<item>
		<title>VLC and PLT Scheme</title>
		<link>http://cwbowron.wordpress.com/2009/04/19/vlc-and-plt-scheme/</link>
		<comments>http://cwbowron.wordpress.com/2009/04/19/vlc-and-plt-scheme/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 17:56:11 +0000</pubDate>
		<dc:creator>cwbowron</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[PLT-scheme]]></category>
		<category><![CDATA[VLC]]></category>

		<guid isPermaLink="false">http://cwbowron.wordpress.com/?p=143</guid>
		<description><![CDATA[I realized the other day that most of the functionality of VLC lies within a library called libVLC that has a C API. PLT Scheme has a great Foreign Function Interface that makes it fairly easy to interface with such a library. So, I ditched the mplayer playback backend for schemep3 and converted to libvlc. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=143&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I realized the other day that most of the functionality of VLC lies within a library called libVLC that has a C API.  PLT Scheme has a great Foreign Function Interface that makes it fairly easy to interface with such a library.</p>
<p>So, I ditched the mplayer playback backend for schemep3 and converted to libvlc.  The biggest benefit is that with mplayer I was communicating via input and output ports but with libvlc the communication is at the API layer.  </p>
<p>With mplayer, to get the playback position, I had to write a special string to the player input port, and poll its output port and parse every line looking for important strings.  With libvlc, I just call <i>libvlc_media_player_get_time</i>.  </p>
<p>So here&#8217;s the code&#8230; You&#8217;ll probably have to change the location of the actually library [dll,dylib,so] depending on your setup.  In the next few days I will publish a sample that plays back an mp3 file.</p>
<p><pre class="brush: cpp;">
#lang scheme

(require scheme/foreign)
(unsafe!)

(provide (all-defined-out))

(define libvlccore (ffi-lib &quot;bin/libvlccore&quot;))
(define libvlc (ffi-lib &quot;bin/libvlc&quot;))

(define-syntax define-pointer
  (syntax-rules ()
    ((_ ptr-type)
     (define ptr-type 
       (_cpointer/null (quote ptr-type))))))

(define-pointer vlc-instance)
(define-pointer vlc-media)
(define-pointer vlc-media-player)

(define-cstruct _vlc-exception ((raised _bool) (code _int32) (message _string)))

(define vlc-state
  (_enum '(libvlc_NothingSpecial libvlc_Opening libvlc_Buffering libvlc_Playing
           libvlc_Paused libvlc_Stopped libvlc_Ended libvlc_Error)))

(define-syntax define-vlc
  (syntax-rules ()
    ((_ fn args)
     (define fn 
       (get-ffi-obj (quote fn) libvlc args)))))



(define-vlc libvlc_exception_init (_fun _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_new         (_fun _int32 (_vector i _string/utf-8)  _vlc-exception-pointer -&gt; vlc-instance))
(define-vlc libvlc_get_version (_fun -&gt; _string/utf-8))
(define-vlc libvlc_release     (_fun vlc-instance -&gt; _void))
(define-vlc libvlc_add_intf    (_fun vlc-instance _string/utf-8 _vlc-exception-pointer -&gt; _void))

;;;
(define-vlc libvlc_media_new          (_fun vlc-instance _string/utf-8 _vlc-exception-pointer -&gt; vlc-media))
(define-vlc libvlc_media_get_duration (_fun vlc-media _vlc-exception-pointer -&gt; _int64))
(define-vlc libvlc_media_get_meta     (_fun vlc-media _int32 _vlc-exception-pointer -&gt; _string))
(define-vlc libvlc_media_get_mrl      (_fun vlc-media _vlc-exception-pointer -&gt; _string))
(define-vlc libvlc_media_release      (_fun vlc-media -&gt; _void))

;;;;;;;;;;;;;;
(define-vlc libvlc_media_player_new_from_media (_fun vlc-media _vlc-exception-pointer -&gt; vlc-media-player))
(define-vlc libvlc_media_player_release        (_fun vlc-media-player -&gt; _void))

(define-vlc libvlc_media_player_play           (_fun vlc-media-player _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_media_player_pause          (_fun vlc-media-player _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_media_player_stop           (_fun vlc-media-player _vlc-exception-pointer -&gt; _void))
(define-vlc libvlc_media_player_set_position   (_fun vlc-media-player _float _vlc-exception-pointer -&gt; _void))

(define-vlc libvlc_media_player_get_time       (_fun vlc-media-player _vlc-exception-pointer -&gt; _int64))
(define-vlc libvlc_media_player_get_position   (_fun vlc-media-player _vlc-exception-pointer -&gt; _float))
(define-vlc libvlc_media_player_get_length     (_fun vlc-media-player _vlc-exception-pointer -&gt; _int64))
(define-vlc libvlc_media_player_get_state      (_fun vlc-media-player _vlc-exception-pointer -&gt; vlc-state))
</pre></p>
<br />Posted in Programming, Scheme  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cwbowron.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cwbowron.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cwbowron.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cwbowron.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cwbowron.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cwbowron.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cwbowron.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cwbowron.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cwbowron.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cwbowron.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cwbowron.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cwbowron.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cwbowron.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cwbowron.wordpress.com/143/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cwbowron.wordpress.com&amp;blog=5831805&amp;post=143&amp;subd=cwbowron&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cwbowron.wordpress.com/2009/04/19/vlc-and-plt-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd366d70e95e894b42c0d86a94e08ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cwbowron</media:title>
		</media:content>
	</item>
	</channel>
</rss>
