Lisp HUG Maillist Archive

Slider Pane

I'm having problems with the CAPI:SLIDER pane on LWM 6.0.1 (Mac OS X v. 10.6.5, MacBook Pro).

First of all, the documentation seems to be lacking. I don't see where SLIDER or any of its superclasses explains the arguments required by its CALLBACK. I've figured those out, I think: item, value and action.

I see from a 2008 email that SHOW-VALUE-P is ignored on Cocoa. It apparently still does nothing on Cocoa.

I'm trying to use it to set the system sound volume, and I'd like to play a sound sample whenever the slider is used to change the volume. Responding to :MOVE actions seems to be the right thing to do (as opposed to :DRAG). But for some reason, the slider callback is called twice with a :MOVE action every time the slug is moved.

Here's some code to illustrate:


(defun say (what)
  (system:call-system
   (format nil "osascript -e 'say ~C~A~C'" #\" what #\")))

(defun set-loudness (n)
  "Set system sound volume to a number between 0 and 7."
  (system:call-system
   (format nil "osascript -e 'set volume ~D'" n)))


(defun loudness-callback (item value action)
  (when (equal action :move)
      (set-loudness value)
      (say "Loud enough?")))

(capi:contain (make-instance 'capi:slider
             :orientation :vertical
             :start-point :bottom
             :start 0
             :end 7
             :slug-start 5
             :show-value-p t ; no effect on Cocoa
             :callback 'loudness-callback
             :title "Sound Volume"))


P.S. For extra points, does anyone know how I can get the original system sound volume so I can restore it? And how about getting a list of voices available?

Re: Slider Pane


On Dec 19, 2010, at 12:58 AM, Laughing Water wrote:

> And how about getting a list of voices available?

(defparameter *available-voice-list*
  (objc:with-autorelease-pool nil
    (let* ((voice-array (objc:invoke "NSSpeechSynthesizer" "availableVoices"))
           (count (objc:invoke voice-array "count"))
           (voice-identifier-list
            (loop for index from 0 below count
                  collect (objc:ns-string-to-string (objc:invoke voice-array "objectAtIndex:" index))))
           (voice-name-list
            (loop for voice-identifier in voice-identifier-list
                  collect
                  (subseq voice-identifier
                          (length "com.apple.speech.synthesis.voice.")  
                          (length voice-identifier)))))
      voice-name-list)))

(defun speak-string (a-string &key (voice "Alex"))
  (objc:with-autorelease-pool nil
    (let* ((voice-identifier
            (concatenate
             'string
             "com.apple.speech.synthesis.voice."  
             voice))
           (the-synth
            (objc:invoke
             (objc:invoke "NSSpeechSynthesizer" "alloc")
             "initWithVoice:"
             voice-identifier)))
      (objc:invoke the-synth "startSpeakingString:" a-string))))

(defun speak-all-voices ()
  (loop for voice-name in *available-voice-list* do
    (speak-string voice-name :voice voice-name)
      (sleep 2)))

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Re: Slider Pane


On Dec 19, 2010, at 12:58 AM, Laughing Water wrote:

>  For extra points, does anyone know how I can get the original system sound volume so I can restore it?

You almost certainly shouldn't be doing this - they system wide volume is a user preference and applications should not be modifying it. You should be setting the volume (using setVolume:) of the individual NSSound or the NSSpeechSynthesizer that you're playing/using in your app.

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Updated at: 2020-12-10 08:38 UTC