From a64d6e27ecc0a1b3673277aedbdc3a981a9f91a2 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 16 Feb 2010 22:31:21 -0800 Subject: [PATCH] move alut stuff to openal.alut so alut only gets deployed if we use it --- extra/morse/morse.factor | 2 +- extra/openal/alut/alut.factor | 103 ++++++++++++++++++ extra/openal/{ => alut}/backend/authors.txt | 0 .../openal/{ => alut}/backend/backend.factor | 2 +- extra/openal/{ => alut}/macosx/authors.txt | 0 extra/openal/{ => alut}/macosx/macosx.factor | 4 +- extra/openal/{ => alut}/macosx/tags.txt | 0 extra/openal/{ => alut}/other/authors.txt | 0 extra/openal/{ => alut}/other/other.factor | 4 +- extra/openal/example/example.factor | 2 +- extra/openal/openal.factor | 95 +--------------- extra/space-invaders/space-invaders.factor | 1 + extra/synth/example/example.factor | 2 +- extra/synth/synth.factor | 2 +- 14 files changed, 115 insertions(+), 102 deletions(-) mode change 100644 => 100755 extra/morse/morse.factor create mode 100755 extra/openal/alut/alut.factor rename extra/openal/{ => alut}/backend/authors.txt (100%) rename extra/openal/{ => alut}/backend/backend.factor (79%) mode change 100644 => 100755 rename extra/openal/{ => alut}/macosx/authors.txt (100%) rename extra/openal/{ => alut}/macosx/macosx.factor (84%) mode change 100644 => 100755 rename extra/openal/{ => alut}/macosx/tags.txt (100%) rename extra/openal/{ => alut}/other/authors.txt (100%) rename extra/openal/{ => alut}/other/other.factor (89%) mode change 100644 => 100755 mode change 100644 => 100755 extra/openal/example/example.factor mode change 100644 => 100755 extra/openal/openal.factor mode change 100644 => 100755 extra/space-invaders/space-invaders.factor mode change 100644 => 100755 extra/synth/example/example.factor mode change 100644 => 100755 extra/synth/synth.factor diff --git a/extra/morse/morse.factor b/extra/morse/morse.factor old mode 100644 new mode 100755 index cbe3c0f2fa..c6f1601955 --- a/extra/morse/morse.factor +++ b/extra/morse/morse.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2007, 2008, 2009 Alex Chapman, 2009 Diego Martinelli ! See http://factorcode.org/license.txt for BSD license. -USING: accessors ascii assocs biassocs combinators hashtables kernel lists literals math namespaces make multiline openal parser sequences splitting strings synth synth.buffers ; +USING: accessors ascii assocs biassocs combinators hashtables kernel lists literals math namespaces make multiline openal openal.alut parser sequences splitting strings synth synth.buffers ; IN: morse ERROR: no-morse-ch ch ; diff --git a/extra/openal/alut/alut.factor b/extra/openal/alut/alut.factor new file mode 100755 index 0000000000..d1b8d2600d --- /dev/null +++ b/extra/openal/alut/alut.factor @@ -0,0 +1,103 @@ +! Copyright (C) 2007 Chris Double. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel accessors arrays alien system combinators +alien.syntax namespaces alien.c-types sequences vocabs.loader +shuffle openal openal.alut.backend alien.libraries generalizations +specialized-arrays alien.destructors ; +FROM: alien.c-types => float short ; +SPECIALIZED-ARRAY: uint +IN: openal.alut + +<< "alut" { + { [ os windows? ] [ "alut.dll" ] } + { [ os macosx? ] [ + "/System/Library/Frameworks/OpenAL.framework/OpenAL" + ] } + { [ os unix? ] [ "libalut.so" ] } + } cond "cdecl" add-library >> + +<< os macosx? [ "alut" deploy-library ] unless >> + +LIBRARY: alut + +CONSTANT: ALUT_API_MAJOR_VERSION 1 +CONSTANT: ALUT_API_MINOR_VERSION 1 +CONSTANT: ALUT_ERROR_NO_ERROR 0 +CONSTANT: ALUT_ERROR_OUT_OF_MEMORY HEX: 200 +CONSTANT: ALUT_ERROR_INVALID_ENUM HEX: 201 +CONSTANT: ALUT_ERROR_INVALID_VALUE HEX: 202 +CONSTANT: ALUT_ERROR_INVALID_OPERATION HEX: 203 +CONSTANT: ALUT_ERROR_NO_CURRENT_CONTEXT HEX: 204 +CONSTANT: ALUT_ERROR_AL_ERROR_ON_ENTRY HEX: 205 +CONSTANT: ALUT_ERROR_ALC_ERROR_ON_ENTRY HEX: 206 +CONSTANT: ALUT_ERROR_OPEN_DEVICE HEX: 207 +CONSTANT: ALUT_ERROR_CLOSE_DEVICE HEX: 208 +CONSTANT: ALUT_ERROR_CREATE_CONTEXT HEX: 209 +CONSTANT: ALUT_ERROR_MAKE_CONTEXT_CURRENT HEX: 20A +CONSTANT: ALUT_ERROR_DESTRY_CONTEXT HEX: 20B +CONSTANT: ALUT_ERROR_GEN_BUFFERS HEX: 20C +CONSTANT: ALUT_ERROR_BUFFER_DATA HEX: 20D +CONSTANT: ALUT_ERROR_IO_ERROR HEX: 20E +CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_TYPE HEX: 20F +CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE HEX: 210 +CONSTANT: ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA HEX: 211 +CONSTANT: ALUT_WAVEFORM_SINE HEX: 100 +CONSTANT: ALUT_WAVEFORM_SQUARE HEX: 101 +CONSTANT: ALUT_WAVEFORM_SAWTOOTH HEX: 102 +CONSTANT: ALUT_WAVEFORM_WHITENOISE HEX: 103 +CONSTANT: ALUT_WAVEFORM_IMPULSE HEX: 104 +CONSTANT: ALUT_LOADER_BUFFER HEX: 300 +CONSTANT: ALUT_LOADER_MEMORY HEX: 301 + +FUNCTION: ALboolean alutInit ( int* argcp, char** argv ) ; +FUNCTION: ALboolean alutInitWithoutContext ( int* argcp, char** argv ) ; +FUNCTION: ALboolean alutExit ( ) ; +FUNCTION: ALenum alutGetError ( ) ; +FUNCTION: char* alutGetErrorString ( ALenum error ) ; +FUNCTION: ALuint alutCreateBufferFromFile ( char* fileName ) ; +FUNCTION: ALuint alutCreateBufferFromFileImage ( void* data, ALsizei length ) ; +FUNCTION: ALuint alutCreateBufferHelloWorld ( ) ; +FUNCTION: ALuint alutCreateBufferWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration ) ; +FUNCTION: void* alutLoadMemoryFromFile ( char* fileName, ALenum* format, ALsizei* size, ALfloat* frequency ) ; +FUNCTION: void* alutLoadMemoryFromFileImage ( void* data, ALsizei length, ALenum* format, ALsizei* size, ALfloat* frequency ) ; +FUNCTION: void* alutLoadMemoryHelloWorld ( ALenum* format, ALsizei* size, ALfloat* frequency ) ; +FUNCTION: void* alutLoadMemoryWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration, ALenum* format, ALsizei* size, ALfloat* freq ) ; +FUNCTION: char* alutGetMIMETypes ( ALenum loader ) ; +FUNCTION: ALint alutGetMajorVersion ( ) ; +FUNCTION: ALint alutGetMinorVersion ( ) ; +FUNCTION: ALboolean alutSleep ( ALfloat duration ) ; + +FUNCTION: void alutUnloadWAV ( ALenum format, void* data, ALsizei size, ALsizei frequency ) ; + +SYMBOL: init + +: init-openal ( -- ) + init get-global expired? [ + f f alutInit 0 = [ "Could not initialize OpenAL" throw ] when + 1337 init set-global + ] when ; + +: exit-openal ( -- ) + init get-global expired? [ + alutExit 0 = [ "Could not close OpenAL" throw ] when + f init set-global + ] unless ; + +: create-buffer-from-file ( filename -- buffer ) + alutCreateBufferFromFile dup AL_NONE = [ + "create-buffer-from-file failed" throw + ] when ; + +os macosx? "openal.alut.macosx" "openal.alut.other" ? require + +: create-buffer-from-wav ( filename -- buffer ) + gen-buffer dup rot load-wav-file + [ alBufferData ] 4 nkeep alutUnloadWAV ; + +: check-error ( -- ) + alGetError dup ALUT_ERROR_NO_ERROR = [ + drop + ] [ + alGetString throw + ] if ; + diff --git a/extra/openal/backend/authors.txt b/extra/openal/alut/backend/authors.txt similarity index 100% rename from extra/openal/backend/authors.txt rename to extra/openal/alut/backend/authors.txt diff --git a/extra/openal/backend/backend.factor b/extra/openal/alut/backend/backend.factor old mode 100644 new mode 100755 similarity index 79% rename from extra/openal/backend/backend.factor rename to extra/openal/alut/backend/backend.factor index 41069dcddf..fc50d3d15e --- a/extra/openal/backend/backend.factor +++ b/extra/openal/alut/backend/backend.factor @@ -1,4 +1,4 @@ USING: namespaces system ; -IN: openal.backend +IN: openal.alut.backend HOOK: load-wav-file os ( filename -- format data size frequency ) diff --git a/extra/openal/macosx/authors.txt b/extra/openal/alut/macosx/authors.txt similarity index 100% rename from extra/openal/macosx/authors.txt rename to extra/openal/alut/macosx/authors.txt diff --git a/extra/openal/macosx/macosx.factor b/extra/openal/alut/macosx/macosx.factor old mode 100644 new mode 100755 similarity index 84% rename from extra/openal/macosx/macosx.factor rename to extra/openal/alut/macosx/macosx.factor index f0a6b928e9..3c0a4672cb --- a/extra/openal/macosx/macosx.factor +++ b/extra/openal/alut/macosx/macosx.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2007 Chris Double. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types kernel alien alien.syntax shuffle -openal openal.backend namespaces system generalizations ; -IN: openal.macosx +openal openal.alut.backend namespaces system generalizations ; +IN: openal.alut.macosx LIBRARY: alut diff --git a/extra/openal/macosx/tags.txt b/extra/openal/alut/macosx/tags.txt similarity index 100% rename from extra/openal/macosx/tags.txt rename to extra/openal/alut/macosx/tags.txt diff --git a/extra/openal/other/authors.txt b/extra/openal/alut/other/authors.txt similarity index 100% rename from extra/openal/other/authors.txt rename to extra/openal/alut/other/authors.txt diff --git a/extra/openal/other/other.factor b/extra/openal/alut/other/other.factor old mode 100644 new mode 100755 similarity index 89% rename from extra/openal/other/other.factor rename to extra/openal/alut/other/other.factor index ada8d6b1fb..b19579286b --- a/extra/openal/other/other.factor +++ b/extra/openal/alut/other/other.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2007 Chris Double. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types alien.syntax combinators generalizations -kernel openal openal.backend ; -IN: openal.other +kernel openal openal.alut.backend ; +IN: openal.alut.other LIBRARY: alut diff --git a/extra/openal/example/example.factor b/extra/openal/example/example.factor old mode 100644 new mode 100755 index 4d979a8fa7..7789ee6e0a --- a/extra/openal/example/example.factor +++ b/extra/openal/example/example.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2007 Chris Double. ! See http://factorcode.org/license.txt for BSD license. -USING: calendar kernel openal sequences threads ; +USING: calendar kernel openal openal.alut sequences threads ; IN: openal.example : play-hello ( -- ) diff --git a/extra/openal/openal.factor b/extra/openal/openal.factor old mode 100644 new mode 100755 index d3c2b0a5cc..bbe61f9dc3 --- a/extra/openal/openal.factor +++ b/extra/openal/openal.factor @@ -2,20 +2,12 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors arrays alien system combinators alien.syntax namespaces alien.c-types sequences vocabs.loader -shuffle openal.backend alien.libraries generalizations +shuffle alien.libraries generalizations specialized-arrays alien.destructors ; FROM: alien.c-types => float short ; SPECIALIZED-ARRAY: uint IN: openal -<< "alut" { - { [ os windows? ] [ "alut.dll" ] } - { [ os macosx? ] [ - "/System/Library/Frameworks/OpenAL.framework/OpenAL" - ] } - { [ os unix? ] [ "libalut.so" ] } - } cond "cdecl" add-library >> - << "openal" { { [ os windows? ] [ "OpenAL32.dll" ] } { [ os macosx? ] [ @@ -24,7 +16,7 @@ IN: openal { [ os unix? ] [ "libopenal.so" ] } } cond "cdecl" add-library >> -<< os macosx? [ "openal" deploy-library "alut" deploy-library ] unless >> +<< os macosx? [ "openal" deploy-library ] unless >> LIBRARY: openal @@ -254,71 +246,6 @@ FUNCTION: void alcCaptureSamples ( ALCdevice* device, void* buf, ALCsizei samps DESTRUCTOR: alcCloseDevice* DESTRUCTOR: alcDestroyContext -LIBRARY: alut - -CONSTANT: ALUT_API_MAJOR_VERSION 1 -CONSTANT: ALUT_API_MINOR_VERSION 1 -CONSTANT: ALUT_ERROR_NO_ERROR 0 -CONSTANT: ALUT_ERROR_OUT_OF_MEMORY HEX: 200 -CONSTANT: ALUT_ERROR_INVALID_ENUM HEX: 201 -CONSTANT: ALUT_ERROR_INVALID_VALUE HEX: 202 -CONSTANT: ALUT_ERROR_INVALID_OPERATION HEX: 203 -CONSTANT: ALUT_ERROR_NO_CURRENT_CONTEXT HEX: 204 -CONSTANT: ALUT_ERROR_AL_ERROR_ON_ENTRY HEX: 205 -CONSTANT: ALUT_ERROR_ALC_ERROR_ON_ENTRY HEX: 206 -CONSTANT: ALUT_ERROR_OPEN_DEVICE HEX: 207 -CONSTANT: ALUT_ERROR_CLOSE_DEVICE HEX: 208 -CONSTANT: ALUT_ERROR_CREATE_CONTEXT HEX: 209 -CONSTANT: ALUT_ERROR_MAKE_CONTEXT_CURRENT HEX: 20A -CONSTANT: ALUT_ERROR_DESTRY_CONTEXT HEX: 20B -CONSTANT: ALUT_ERROR_GEN_BUFFERS HEX: 20C -CONSTANT: ALUT_ERROR_BUFFER_DATA HEX: 20D -CONSTANT: ALUT_ERROR_IO_ERROR HEX: 20E -CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_TYPE HEX: 20F -CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE HEX: 210 -CONSTANT: ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA HEX: 211 -CONSTANT: ALUT_WAVEFORM_SINE HEX: 100 -CONSTANT: ALUT_WAVEFORM_SQUARE HEX: 101 -CONSTANT: ALUT_WAVEFORM_SAWTOOTH HEX: 102 -CONSTANT: ALUT_WAVEFORM_WHITENOISE HEX: 103 -CONSTANT: ALUT_WAVEFORM_IMPULSE HEX: 104 -CONSTANT: ALUT_LOADER_BUFFER HEX: 300 -CONSTANT: ALUT_LOADER_MEMORY HEX: 301 - -FUNCTION: ALboolean alutInit ( int* argcp, char** argv ) ; -FUNCTION: ALboolean alutInitWithoutContext ( int* argcp, char** argv ) ; -FUNCTION: ALboolean alutExit ( ) ; -FUNCTION: ALenum alutGetError ( ) ; -FUNCTION: char* alutGetErrorString ( ALenum error ) ; -FUNCTION: ALuint alutCreateBufferFromFile ( char* fileName ) ; -FUNCTION: ALuint alutCreateBufferFromFileImage ( void* data, ALsizei length ) ; -FUNCTION: ALuint alutCreateBufferHelloWorld ( ) ; -FUNCTION: ALuint alutCreateBufferWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration ) ; -FUNCTION: void* alutLoadMemoryFromFile ( char* fileName, ALenum* format, ALsizei* size, ALfloat* frequency ) ; -FUNCTION: void* alutLoadMemoryFromFileImage ( void* data, ALsizei length, ALenum* format, ALsizei* size, ALfloat* frequency ) ; -FUNCTION: void* alutLoadMemoryHelloWorld ( ALenum* format, ALsizei* size, ALfloat* frequency ) ; -FUNCTION: void* alutLoadMemoryWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration, ALenum* format, ALsizei* size, ALfloat* freq ) ; -FUNCTION: char* alutGetMIMETypes ( ALenum loader ) ; -FUNCTION: ALint alutGetMajorVersion ( ) ; -FUNCTION: ALint alutGetMinorVersion ( ) ; -FUNCTION: ALboolean alutSleep ( ALfloat duration ) ; - -FUNCTION: void alutUnloadWAV ( ALenum format, void* data, ALsizei size, ALsizei frequency ) ; - -SYMBOL: init - -: init-openal ( -- ) - init get-global expired? [ - f f alutInit 0 = [ "Could not initialize OpenAL" throw ] when - 1337 init set-global - ] when ; - -: exit-openal ( -- ) - init get-global expired? [ - alutExit 0 = [ "Could not close OpenAL" throw ] when - f init set-global - ] unless ; - : gen-sources ( size -- seq ) dup [ alGenSources ] keep ; @@ -327,17 +254,6 @@ SYMBOL: init : gen-buffer ( -- buffer ) 1 gen-buffers first ; -: create-buffer-from-file ( filename -- buffer ) - alutCreateBufferFromFile dup AL_NONE = [ - "create-buffer-from-file failed" throw - ] when ; - -os macosx? "openal.macosx" "openal.other" ? require - -: create-buffer-from-wav ( filename -- buffer ) - gen-buffer dup rot load-wav-file - [ alBufferData ] 4 nkeep alutUnloadWAV ; - : queue-buffers ( source buffers -- ) [ length ] [ >uint-array ] bi alSourceQueueBuffers ; @@ -360,12 +276,5 @@ os macosx? "openal.macosx" "openal.other" ? require : source-stop ( source -- ) alSourceStop ; -: check-error ( -- ) - alGetError dup ALUT_ERROR_NO_ERROR = [ - drop - ] [ - alGetString throw - ] if ; - : source-playing? ( source -- bool ) AL_SOURCE_STATE get-source-param AL_PLAYING = ; diff --git a/extra/space-invaders/space-invaders.factor b/extra/space-invaders/space-invaders.factor old mode 100644 new mode 100755 index 17e277fb6a..01bf621769 --- a/extra/space-invaders/space-invaders.factor +++ b/extra/space-invaders/space-invaders.factor @@ -18,6 +18,7 @@ USING: math math.order openal + openal.alut opengl.gl sequences ui diff --git a/extra/synth/example/example.factor b/extra/synth/example/example.factor old mode 100644 new mode 100755 index 747cfb9c86..e09d903afb --- a/extra/synth/example/example.factor +++ b/extra/synth/example/example.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Alex Chapman ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays kernel namespaces make openal sequences +USING: accessors arrays kernel namespaces make openal openal.alut sequences synth synth.buffers ; IN: synth.example diff --git a/extra/synth/synth.factor b/extra/synth/synth.factor old mode 100644 new mode 100755 index def610d356..90645e3562 --- a/extra/synth/synth.factor +++ b/extra/synth/synth.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Alex Chapman ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel locals math math.constants math.functions memoize openal synth.buffers sequences sequences.modified sequences.repeating ; +USING: accessors kernel locals math math.constants math.functions memoize openal openal.alut synth.buffers sequences sequences.modified sequences.repeating ; IN: synth MEMO: single-sine-wave ( samples/wave -- seq ) -- 2.34.1