Haunted House

Origo is a funnyface (0,0)

New live coding project 2: a day of fiddling

Posted by Gasten on December 4, 2007

(read the first post here)

I’d love to write more, but I’m too tired. Some of the results from todays fiddling is pasted at the end.

Boy, isn’t Scheme well suited for live coding? It’s very algorithmic, and you can develop fast and abstract. And it’s the most beautiful language out there (is in looking at code as if it was a picture)!

Boy, isn’t Scheme badly suited for live coding. It’s a pain to write, a pain to read, and hell of a pain to debug!

Was a lot harder than I expected, but I managed to hack a cool script for my Xbox360 which will ease joysticking. Pasted below.

I’ve also started to swap the keyboard-controls to joystick-control in the asteroids-example. Unfortunally I managed to break it a little a couple of minutes ago, so you will have to live without it for now.

; joypad
; a joypad input listener, for use with oscjoy 
; (http://www.lcscanada.com/oscjoy/index.html)
; usage:
; (osc-source oscjoy-portnumber)
; (define my-joypad (make-object joypad%))
; ... every frame loop ...
; (send my-joypad update)
; (display (send my-joypad get-button 0))(newline)
; (display (send my-joypad get-axis 0 0))(newline) ; returns a the value
                                            ;  of the axis as a float (-1 to 1)

(require (lib "class.ss"))

(define joypad%
  (class object%
      update ;; update the joylistener
      get-button ;; get the current values for a button
      get-axis ;; get the current value for an axis
    (define buttons '())
    (define axes '())
    (define button-state '())
    (define (joypad-new)
      (set! buttons (make-buttons 16 '()))
      (set! axes (make-axes 16))
      (set! button-state (make-buttons 16 '())))
    (define (make-axes n)
      (make-vector n 0))
    (define (make-buttons n l)
      (if (zero? n)
          (make-buttons (- n 1) (cons 0 l))))

     (define ax-map (vector
        (vector 0 1)    ; left stick
        (vector 3 4)    ; right stick
        (vector 2 5)))  ; l/r triggers
    (define (get-button n)
      (list-ref buttons n))
    (define (button-changed n)
      (list-ref button-state n))
    (define (get-axis n1 n2)    ; return the correct axis. Mapped in ax-map.
      (vector-ref axes (vector-ref (vector-ref ax-map n1) n2)))

    (define (get-axes)      ; can probably be deleted pretty painless
    (define (set-button! n s)
      (list-set! buttons n s))
    (define (update)
      (define (drain path value)       ; drains all osc events for a message and 
        (if (osc-msg path)             ; only reports the last one which is ok for
            (drain path (osc 0))       ; this sort of control
      (define (do-axes n)
        (let ((value (drain (string-append "/oscjoy.0.axis." (number->string n)) #f)))
            ((number? value)
             ; get a vector of all the axes
             ; and set the value (make usre it's in range).
             (vector-set! (get-axes)
                          (* 2 (- value 0.5) )))))
        (if (zero? n)
            (do-axes (- n 1))))
      (define (do-buttons n)
        (let ((value (drain (string-append "/oscjoy.0.button." (number->string n)) #f)))
            ((number? value)
             ; have we changed?
             (if (not (eq? (get-button n) value))
                 (list-set! button-state n #t)
                 (list-set! button-state n #f))
             (set-button! n value))))
        (if (zero? n)
            (do-buttons (- n 1))))
      ;(display (osc-peek)) (newline)
      (do-axes 16)
      (do-buttons 16))


3 Responses to “New live coding project 2: a day of fiddling”

  1. […] they say New live coding project 2: a day of fiddling « Haunted House on New live coding projectGasten on Vim-tip #1Gasten on A walk in the valley of bugs […]

  2. sandrar said

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  3. If you are a real estate professional, be really careful in dealing with KoRes Corp. in Weston Florida. Tulio Rodriguez & Monica Cataluna-Shand are shysters and look for anyway to steal ones customers. They attempt to steal your client by requesting their contact information and later contact them behind your back to get them to deal with them directly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: