diff --git a/libao/lib/ao-play-async.dll b/lib/dll/ao-play-async.dll similarity index 100% rename from libao/lib/ao-play-async.dll rename to lib/dll/ao-play-async.dll diff --git a/libao/lib/libao-play-async.so b/lib/linux-x86_64/libao-play-async.so old mode 100755 new mode 100644 similarity index 100% rename from libao/lib/libao-play-async.so rename to lib/linux-x86_64/libao-play-async.so diff --git a/libao/lib/ao-play-async.exp b/libao/lib/ao-play-async.exp deleted file mode 100644 index 405b745..0000000 Binary files a/libao/lib/ao-play-async.exp and /dev/null differ diff --git a/libao/lib/ao-play-async.lib b/libao/lib/ao-play-async.lib deleted file mode 100644 index 6560be1..0000000 Binary files a/libao/lib/ao-play-async.lib and /dev/null differ diff --git a/libao/libao-async-ffi.rkt b/libao/libao-async-ffi.rkt index 03df948..3882956 100644 --- a/libao/libao-async-ffi.rkt +++ b/libao/libao-async-ffi.rkt @@ -3,9 +3,7 @@ (require ffi/unsafe ffi/unsafe/define - setup/dirs "../utils/utils.rkt" - racket/runtime-path "libao-ffi.rkt" ) @@ -17,20 +15,8 @@ ao_clear_async ) -(define-runtime-path libao-async-lib-path "./lib") - -(define lib (if (eq? (system-type 'os) 'windows) - (build-path libao-async-lib-path "ao-play-async") - (build-path libao-async-lib-path "libao-play-async"))) - -(define-ffi-definer define-libao-async - (ffi-lib lib '("0" #f) - #:get-lib-dirs (λ () - (let ((sp (cons (build-path ".") (get-lib-search-dirs)))) - ;(displayln sp) - sp)) - #:fail (λ () (error "Cannot load libao-play-async")) - )) +(define lib (get-lib '("ao-play-async" "libao-play-async") '(#f))) +(define-ffi-definer define-libao-async lib) (define _libao-async-handle-pointer (_cpointer 'ao-async-handle)) diff --git a/libao/libao-ffi.rkt b/libao/libao-ffi.rkt index 3447d83..c37c1c8 100644 --- a/libao/libao-ffi.rkt +++ b/libao/libao-ffi.rkt @@ -2,7 +2,6 @@ (require ffi/unsafe ffi/unsafe/define - setup/dirs "../utils/utils.rkt" ) @@ -27,16 +26,7 @@ ) -(define ao_lib (ffi-lib "libao" '("3" "4" "5" #f) - #:get-lib-dirs (λ () - (let ((sp (cons (build-path ".") (get-lib-search-dirs)))) - (displayln sp) - sp)) - #:fail (λ () - (ffi-lib (get-lib-path "libao-4.dll"))) - )) - - +(define ao_lib (get-lib '("libao") '("5" "4" "3" #f))) (define-ffi-definer define-libao ao_lib) (define _libao-pointer (_cpointer 'ao_device)) diff --git a/libflac/libflac-ffi.rkt b/libflac/libflac-ffi.rkt index ee4bbba..677e4f3 100644 --- a/libflac/libflac-ffi.rkt +++ b/libflac/libflac-ffi.rkt @@ -2,7 +2,6 @@ (require ffi/unsafe ffi/unsafe/define - setup/dirs "../utils/utils.rkt" ) @@ -15,14 +14,9 @@ FLAC__int32** ) -(define-ffi-definer define-libflac - (ffi-lib "libFLAC" '(#f) - #:get-lib-dirs (lambda () - (cons (build-path ".") (get-lib-search-dirs))) - #:fail (lambda () - (ffi-lib (get-lib-path "libFLAC.dll"))) - )) +(define lib (get-lib '("libFLAC") '(#f))) +(define-ffi-definer define-libflac lib) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Some FLAC Constants diff --git a/libtag/taglib-ffi.rkt b/libtag/taglib-ffi.rkt index 0b388be..b239c55 100644 --- a/libtag/taglib-ffi.rkt +++ b/libtag/taglib-ffi.rkt @@ -2,7 +2,6 @@ (require ffi/unsafe ffi/unsafe/define - setup/dirs "../utils/utils.rkt" ) @@ -45,22 +44,30 @@ ) -;(define-ffi-definer define-tag-lib -; (ffi-lib "tag" '("0" #f) -; #:get-lib-dirs (lambda () -; (cons (build-path ".") (get-lib-search-dirs))) -; #:fail (lambda () -; (ffi-lib (get-lib-path "tag.dll"))) -; ))d +;(define-runtime-path lib-path ".."); +; +;(define libs (let ((os-type (system-type 'os*))) +; (if (eq? os-type 'windows) +; (list +; (build-path lib-path "lib" "dll" "tag") +; (build-path lib-path "lib" "dll" "tag_c")) +; (let* ((arch (symbol->string (system-type 'arch))) +; (subdir (string-append (symbol->string os-type) "-" arch))) +; (list +; (build-path lib-path "lib" subdir "libtag") +; (build-path lib-path "lib" subdir "libtag_c")))))) -(define-ffi-definer define-tag-c-lib - (ffi-lib "libtag_c" '("2" #f) - #:get-lib-dirs (lambda () - (cons (build-path ".") (get-lib-search-dirs))) - #:fail (lambda () - (let ((path (get-lib-path "tag_c.dll"))) - (ffi-lib path))) - )) +;(define (get-lib l) +; (ffi-lib l '("2" #f) +; #:get-lib-dirs (λ () +; (cons (build-path ".") (get-lib-search-dirs))) +; #:fail (λ () +; (error (format "Cannot find library ~a" l))) +; )) + +(define libtag (get-lib '("tag" "libtag") '("2" #f))) +(define libtag_c (get-lib '("tag_c" "libtag_c") '("#2" #f))) +(define-ffi-definer define-tag-c-lib libtag_c) (define TagLib_File_Type (_enum '( diff --git a/play-test.rkt b/play-test.rkt index e9ae00f..7321506 100644 --- a/play-test.rkt +++ b/play-test.rkt @@ -1,7 +1,8 @@ #lang racket/base -(require "libao/libao.rkt" - "libflac/flac-decoder.rkt" - data/queue +(require ;"libao/libao.rkt" + ;"libflac/flac-decoder.rkt" + ;data/queue + racket-sound ) (define test-file3 #f) diff --git a/utils/utils.rkt b/utils/utils.rkt index a71ac5b..67b1b1e 100644 --- a/utils/utils.rkt +++ b/utils/utils.rkt @@ -1,8 +1,15 @@ (module utils racket/base + (require racket/path + racket/runtime-path + ffi/unsafe + setup/dirs + ) + (provide while until - get-lib-path + build-lib-path + get-lib do-for ) @@ -47,23 +54,27 @@ (do-for-f)))))) (do-for-f)))))) - (define (get-lib-path lib) - (let ((platform (system-type))) - (cond - [(eq? platform 'windows) - (let ((try1 (build-path (current-directory) ".." "lib" "dll" lib)) - (try2 (build-path (current-directory) "lib" "dll" lib))) - (if (file-exists? try1) - try1 - try2) - )] - [(eq? platform 'unix) - (let ((try1 (build-path (current-directory) "lib" lib))) - (when (file-exists? try1) - try1))] - [else - (error (format "Install the shared library: ~a" lib))] - ))) - + (define-runtime-path lib-path "..") + + (define (build-lib-path) + (let ((os-type (system-type 'os*))) + (if (eq? os-type 'windows) + (build-path lib-path "lib" "dll") + (let* ((arch (symbol->string (system-type 'arch))) + (subdir (string-append (symbol->string os-type) "-" arch))) + (let ((path (build-path lib-path "lib" subdir))) + path))))) + + (define (get-lib* libs-to-try orig-libs versions) + (if (null? libs-to-try) + (error (format "Cannot find library, tried ~a" orig-libs)) + (ffi-lib (car libs-to-try) versions + #:get-lib-dirs (λ () (cons (build-lib-path) (get-lib-search-dirs))) + #:fail (λ () (get-lib* (cdr libs-to-try) orig-libs versions)) + ))) + + (define (get-lib libs-to-try versions) + (get-lib* libs-to-try libs-to-try versions)) + ) ; end of module