<br><br><div class="gmail_quote">2008/10/27 Peter Hildebrandt <span dir="ltr"><<a href="mailto:peter.hildebrandt@gmail.com">peter.hildebrandt@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Lemme know if I can help.</blockquote><div><br>Right now I figure out if it is feasible to control a microscope with cells.<br>In the end I would capture from a camera, move the focus, change objectives...<br></div></div>
<br>But for the beginning I just try to create something similar to baudline (<a href="http://www.baudline.com/">http://www.baudline.com/</a>).<br>Just capture sound, fft and display in an opengl texture. That should be easier as there is not as<br>
much hardware involved.<br><br>What I've come up with is the following code. And I have several questions:<br><br>1) Can how somehow prevent the introduction of the extra defmodel graphics with the<br>    cell rotation and just connect my the hscale value to the gl-rotate?<br>
<br>2) What's the best way to continuously call the draw function in graphics, so that the<br>    display gets updated with 30 Hz? I searched the graphics instance with (inspect *win*)<br>    but I didn't find it. Otherwise I could have called (redraw (graphics (vbox *win*))) from an endless<br>
    loop in another thread.<br><br>Ideally I want to have the application running in several threads. One thread should capture sound and fill it in a queue.<br>That should be easy in sbcl:<br><a href="http://www.sbcl.org/manual/Waitqueue_002fcondition-variables.html#Waitqueue_002fcondition-variables">http://www.sbcl.org/manual/Waitqueue_002fcondition-variables.html#Waitqueue_002fcondition-variables</a><br>
when 2) is solved.<br><br>remark:<br>I think :resize isn't called when my program starts. (In early versions of my program it was called. I don't know what<br>change introduced this bug)<br><br>(require :asdf)<br>
(require :cells-gtk)<br>(require :sb-simple-audio)<br><br>(defpackage :martin (:use :cl :cgtk :cells))<br><br>(in-package :martin)<br><br>(defparameter *tex* #x0)<br>(defparameter *field* (cffi:make-shareable-byte-vector (* 256 256 3)))<br>
(defparameter *sound-buf-n* 1024)<br>(defparameter *sound-buf* (make-array *sound-buf-n*))<br>(defparameter *sound-stream* (sb-simple-audio:open-audio :sample-rate 8000<br>                             :direction :input))<br>
<br><br>(defun plot (x y r g b)<br>  (setf (aref *field* (+ 0 (* 3 (+ x (* 256 y))))) r)<br>  (setf (aref *field* (+ 1 (* 3 (+ x (* 256 y))))) g)<br>  (setf (aref *field* (+ 2 (* 3 (+ x (* 256 y))))) b))<br><br>(defmodel graphics (gl-drawing-area)<br>
  ((rotation :cell t :initarg :rotation :initform 0 :accessor rotation))<br>  (:default-initargs<br>      :expand t :fill t<br>      :init #'(lambda (self)<br>        ;;(declare (ignorable self))<br>        (loop for i below 256 do<br>
              (loop for j below 256 do<br>                (plot i j i j 0)))<br>        (setf *tex* (first (gl:gen-textures 1)))<br>        (gl:bind-texture :texture-2d *tex*)<br>        (gl:tex-parameter :texture-2d :texture-mag-filter :nearest)<br>
        (gl:tex-parameter :texture-2d :texture-min-filter :nearest)<br>        (cffi::with-pointer-to-vector-data (addr *field*)<br>          (gl:tex-image-2d :texture-2d 0 :rgba 256 256 0 :rgb<br>                   :unsigned-byte addr)))<br>
      :resize #'(lambda (self)<br>          (format t "RESIZE~%")<br>          (with-matrix-mode (:projection)<br>            (glu:perspective 50 (/ (allocated-width self)<br>                       (allocated-height self))<br>
                     .5 20)))<br>      :draw #'(lambda (self)<br>        (declare (ignorable self))<br>        (gl:clear :color-buffer-bit)<br>        (gl:load-identity)<br>                    ;(gl:translate 0 0 -5)<br>
        (gl:rotate (* 360 (rotation self)) 0 0 1)<br>        (gl:color 1 1 1)<br>        (gl:enable :texture-2d)<br>        (gl:with-primitive :quads<br>          (gl:tex-coord 0 0)(gl:vertex 0 0)<br>          (gl:tex-coord 1 0)(gl:vertex 1 0)<br>
          (gl:tex-coord 1 1)(gl:vertex 1 1)<br>          (gl:tex-coord 0 1)(gl:vertex 0 1))<br>        (read-sequence *sound-buf* *sound-stream*)<br>        ;;(format t "~a~%" *sound-buf*)<br>        (gl:disable :texture-2d)<br>
        (gl:with-primitive :points<br>          (loop for i below *sound-buf-n* do<br>            (gl:vertex (/ i *sound-buf-n*)<br>                   (/ (aref *sound-buf* i) 5000))))<br>        (gl:flush))))<br><br><br>(defobserver rotation ((self graphics))<br>
  (redraw self))<br><br>(defmodel my-app (gtk-app)<br>  ()<br>  (:default-initargs :title "minimal gl control test"<br>    :position :center :width 500 :height 380 <br>    :kids <br>    (kids-list? (mk-vbox :kids<br>
             (kids-list?<br>              (mk-hscale :md-name :scale :value-type 'single-float<br>                     :min .01 :max 1. :step .01 :init .5)<br>              (make-kid 'graphics :md-name :graphics<br>
                    :height 300<br>                    :rotation (c? (widget-value :scale))))))))<br><br>(cells-gtk-init)<br><br>;(defparameter *win* (start-win 'my-app))<br><br>(start-app 'my-app)<br><br>(*<br>(inspect *win*)<br>
(sb-thread:list-all-threads)<br>(make-thread (lambda () (write-line "test")))<br>*)<br>