gui/collects/mred/private/wx/cocoa/sound.rkt
Matthew Flatt c14bee176f clean up
original commit: d7f1d12ea1c16d5ed062a8ac8fe2fe47db267f15
2010-11-05 15:54:49 -06:00

37 lines
1.0 KiB
Racket

#lang racket/base
(require ffi/unsafe
ffi/unsafe/objc
"utils.rkt"
"types.rkt")
(provide
(protect-out play-sound))
(import-class NSSound)
(define-objc-class MySound NSSound
[result
sema]
[-a _void (sound: [_id sound] didFinishPlaying: [_BOOL ok?])
(set! result ok?)
(semaphore-post sema)
(tellv self release)])
(define (play-sound path async?)
(let ([s (as-objc-allocation
(tell (tell MySound alloc)
initWithContentsOfFile: #:type _NSString (if (path? path)
(path->string path)
path)
byReference: #:type _BOOL #t))]
[sema (make-semaphore)])
(tellv s setDelegate: s)
(set-ivar! s sema sema)
(tellv s retain) ; don't use `retain', because we dont' want auto-release
(tellv s play)
(if async?
(begin
(semaphore-wait sema)
(get-ivar s result))
#t)))