packages feed

HGamer3D-Audio 0.3.0 → 0.5.0

raw patch · 9 files changed

Files

HGamer3D-Audio.cabal view
@@ -1,33 +1,33 @@-Name:                HGamer3D-Audio
-Version:             0.3.0
-Synopsis:            Audio Functionality for HGamer3D
-Description:         
-	HGamer3D is a game engine for developing 3D games in the programming 
-	language Haskell. This package provides the Audio functionality, 
-	based on the package HGamer3D-SFML-Binding. HGamer3D-Audio
-	is available on Windows and Linux.
-	
-License:             OtherLicense
-License-file:        LICENSE
-Author:              Peter Althainz
-Maintainer:          althainz@gmail.com
-Build-Type:          Simple
-Cabal-Version:       >=1.4
-Homepage:            http://www.hgamer3d.org
-Category:            Game Engine
-Extra-source-files:  Setup.hs 
-
-Library
-  Build-Depends:     base >= 3 && < 5, HGamer3D-Data >= 0.3.0 && < 0.4.0, HGamer3D-SFML-Binding >= 0.3.0 && < 0.4.0
-
-  Exposed-modules:   HGamer3D.Audio
-  Other-modules:     
-
-  c-sources:         
-  
-  ghc-options:       
-  cc-options:        -Wno-attributes 
-  hs-source-dirs:    .
-  Include-dirs:      . 
-  build-depends:     
-  extra-libraries:   
+Name:                HGamer3D-Audio+Version:             0.5.0+Synopsis:            Toolset for the Haskell Game Programmer - Audio Functionality+Description:         +	HGamer3D is a toolset for developing 3D games in the programming +	language Haskell. This package provides the Audio functionality, +	based on the package HGamer3D-SFML-Binding. HGamer3D-Audio+	is available on Windows and Linux.+	+License:             OtherLicense+License-file:        LICENSE+Author:              Peter Althainz+Maintainer:          althainz@gmail.com+Build-Type:          Simple+Cabal-Version:       >=1.4+Homepage:            http://www.hgamer3d.org+Category:            Game Engine+Extra-source-files:  Setup.hs ++Library+  Build-Depends:     base >= 3 && < 5, containers, HGamer3D-Data >= 0.5.0 && < 0.6.0, HGamer3D-SFML-Binding >= 0.5.0 && < 0.6.0, HGamer3D-Common >= 0.5.0 && < 0.6.0++  Exposed-modules:   HGamer3D.Audio.AudioBase, HGamer3D.Audio.AudioSource, HGamer3D.Audio.AudioListener, HGamer3D.Audio.SystemAudio, HGamer3D.BaseAPI.Audio, HGamer3D.Audio+  Other-modules:     ++  c-sources:         +  +  ghc-options:       -O2+  cc-options:        -Wno-attributes +  hs-source-dirs:    .+  Include-dirs:      . +  build-depends:     +  extra-libraries:   
HGamer3D/Audio.hs view
@@ -1,8 +1,8 @@ -- This source file is part of HGamer3D -- (A project to enable 3D game development in Haskell)--- For the latest info, see http://www.hgamer3d.org+-- For the latest info, see http://www.althainz.de/HGamer3D.html ----- (c) 2011-2013 Peter Althainz+-- (c) 2014 Peter Althainz -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License.@@ -16,283 +16,23 @@ -- See the License for the specific language governing permissions and -- limitations under the License. --- Audio.hs----- | Audio functionality for HGamer3D module HGamer3D.Audio  (-	-- * Types-	module HGamer3D.Bindings.SFML.EnumSoundSourceStatus,-	-	AudioSource (..), -	-	-- * Audio Listener Functions-	setAudioMainVolume,-	getAudioMainVolume,-	setAudioListenerPosition,-	setAudioListenerDirection,-	-	-- * Audio Source creation and delete Functions-	createMusic,-	createSound,-	deleteAudioSource,-	-	-- * Audio Source play function-	playAudioSource,-	pauseAudioSource,-	stopAudioSource,--	-- * Audio Source property functions-	setAudioSourceLoop,-	getAudioSourceLoop,--	getAudioSourceVolume,-	setAudioSourceVolume,--	getAudioSourcePitch,-	setAudioSourcePitch,--	getAudioSourcePosition,-	setAudioSourcePosition,--	getAudioSourceAttenuation,-	setAudioSourceAttenuation,--	getAudioSourceMinDistance,-	setAudioSourceMinDistance,--	setAudioSourcePositionDependent,-	isAudioSourcePositionDependent-	-)--where--import GHC.Ptr--import HGamer3D.Data-import HGamer3D.Util--import HGamer3D.Bindings.SFML.ClassPtr-import HGamer3D.Bindings.SFML.Utils--import qualified HGamer3D.Bindings.SFML.ClassListener as Listener-import qualified HGamer3D.Bindings.SFML.ClassMusic as Music -import qualified HGamer3D.Bindings.SFML.ClassSound as Sound-import qualified HGamer3D.Bindings.SFML.ClassSoundBuffer as SoundBuffer-import qualified HGamer3D.Bindings.SFML.ClassSoundSource as SoundSource-import qualified HGamer3D.Bindings.SFML.ClassSoundStream as SoundStream---import HGamer3D.Bindings.SFML.EnumSoundSourceStatus--import Control.Monad----- Source types--data AudioSource = Music HG3DClass | Sound HG3DClass HG3DClass----- Listener Functions---- | set overall main audio volume-setAudioMainVolume :: Float -- ^ volume in a scale between 0 and 100.0-					-> IO ()-setAudioMainVolume vol = Listener.setGlobalVolume vol---- | get overall main audio volume-getAudioMainVolume :: IO Float -- ^ volume in a scale between 0 and 100.0-getAudioMainVolume = Listener.getGlobalVolume---- | set position of the listener, this is where the \"micro\" is located-setAudioListenerPosition :: Vec3 -- ^ position of listener-							-> IO ()-setAudioListenerPosition (Vec3 x y z) = Listener.setPosition x y z---- | set direction of the listener-setAudioListenerDirection :: Vec3 -- ^ direction, in which listener hears-                             -> IO ()-setAudioListenerDirection (Vec3 x y z) = Listener.setDirection x y z-+  AudioListener (..),+  AudioSlotParameter (..),+  AudioSlot (..),+  AudioSource (..),+  AudioCmd (..), --- Music Functions, deletion and cretion of Audio types---+  musicSlot,+  soundSlot, -_findMusicFile filename = do-        dirs <- liftM (fmap (++ osSep ++ "sound")) (sequence [getAppMediaDirectory, getExeMediaDirectory])-        filepath <- findFileInDirs filename dirs-        return filepath-  +  forkAudioWorld   ---- | create music (stream source, reading from file)-createMusic :: String -- ^ filename of music -			-> IO (Maybe AudioSource) -- ^ audio source, which can be played-createMusic filename = do-	music <- Music.new-        -- try to find file in hg3d directories-        filepath <-_findMusicFile filename-	-- try to open-        case filepath of-          Just f -> do-            fOk <- Music.openFromFile music (f)-            if fOk then-		return (Just (Music music))-		else do-                      Music.delete music-                      return Nothing-          Nothing -> return Nothing---- | create sound (stream source, loaded into memory)-createSound :: String -- ^ filename of sound without path-					-> IO (Maybe AudioSource) -- ^ audio source, which can be played-createSound filename = do-	sound <- Sound.new-	buffer <- SoundBuffer.new-        filepath <-_findMusicFile filename-	-- try to open-        case filepath of-          Just f -> do-            fOk <- SoundBuffer.loadFromFile buffer (f)-            if fOk then do-		Sound.setBuffer sound buffer		-		return (Just (Sound sound buffer))-		else do-                    Sound.delete sound-                    SoundBuffer.delete buffer-                    return Nothing-          Nothing -> return Nothing---- | delete audio source-deleteAudioSource :: AudioSource -> IO ()-deleteAudioSource (Music music) = do-	Music.delete music-deleteAudioSource (Sound sound buffer) = do-	Sound.delete sound-	SoundBuffer.delete buffer----- Source play, pause, stop------- | starts playing audio source-playAudioSource :: AudioSource -- ^the audio source-					-> IO ()-playAudioSource (Music music) = do-	SoundStream.play music-playAudioSource (Sound sound buffer) = do-	Sound.play sound---- | pause playing audio source, remembers location-pauseAudioSource :: AudioSource -> IO ()-pauseAudioSource (Music music) = do-	SoundStream.pause music-pauseAudioSource (Sound sound buffer) = do-	Sound.pause sound---- | completely stops audio playing-stopAudioSource :: AudioSource -> IO ()-stopAudioSource (Music music) = do-	SoundStream.stop music-stopAudioSource (Sound sound buffer) = do-	Sound.stop sound---- | is audio play looping-getAudioSourceLoop :: AudioSource -- ^audio source-				-> IO Bool -- ^true, loop is enabled, false loop is disabled-getAudioSourceLoop (Music music) = do-	fLoop <- SoundStream.getLoop music-	return fLoop-getAudioSourceLoop (Sound sound buffer) = do-	fLoop <- Sound.getLoop sound-	return fLoop---- | set audio play is looping-setAudioSourceLoop :: AudioSource -- ^audio source-				-> Bool -- ^loop enabled-				-> IO ()-setAudioSourceLoop (Music music) fLoop = do-	SoundStream.setLoop music fLoop-setAudioSourceLoop (Sound sound buffer) fLoop = do-	Sound.setLoop sound fLoop----- Sound Source Functions------- | get volume of a single audio source-getAudioSourceVolume :: AudioSource -- ^audio source-					-> IO Float -- ^volume of audio source in scale of 0 to 100.0-					-getAudioSourceVolume (Music s) = SoundSource.getVolume s-getAudioSourceVolume (Sound s b) = SoundSource.getVolume s---- | set volume of a single audio source-setAudioSourceVolume :: AudioSource -- ^audio source-				-> Float -> IO () -- ^volume of this audio source in scale of 0 to 100.0-				-setAudioSourceVolume (Music s) v = SoundSource.setVolume s v-setAudioSourceVolume (Sound s b) v = SoundSource.setVolume s v---- | get audio source pitch--- the pitch is the frequency of the sound which also influences playing speed. The default value is 1.0.-getAudioSourcePitch :: AudioSource -- ^audio source-				-> IO Float -- ^pitch, a 1.0 is no change to original sound-				-getAudioSourcePitch (Music s) = SoundSource.getPitch s-getAudioSourcePitch (Sound s b) = SoundSource.getPitch s---- | sets the pitch of an audio source-setAudioSourcePitch :: AudioSource -> Float -> IO ()-setAudioSourcePitch (Music s) p = SoundSource.setPitch s p-setAudioSourcePitch (Sound s b) p = SoundSource.setPitch s p---- | sets the position of an audio source-setAudioSourcePosition :: AudioSource -- ^audio source-					-> Vec3 -> IO () -- ^new position of this source-					-setAudioSourcePosition (Music s) (Vec3 x y z) = SoundSource.setPosition s x y z-setAudioSourcePosition (Sound s b) (Vec3 x y z) = SoundSource.setPosition s x y z---- | gets the position of an audio source-getAudioSourcePosition :: AudioSource -- ^audio source-					-> IO Vec3 -- ^position of the audio source-					-getAudioSourcePosition (Music s) = SoundSource.getPosition s-getAudioSourcePosition (Sound s b) = SoundSource.getPosition s---- | gets the attenuation factor of an audio source-getAudioSourceAttenuation :: AudioSource -- ^audio source-			-> IO Float -- ^attenuation is the damping factor by distance, default value is 1.0, 0.0 means no damping-getAudioSourceAttenuation (Music s) = SoundSource.getAttenuation s-getAudioSourceAttenuation (Sound s b) = SoundSource.getAttenuation s---- | sets the attenuation factor of an audio source-setAudioSourceAttenuation :: AudioSource -- ^audio source-				-> Float -> IO () -- ^attenuation factor-setAudioSourceAttenuation (Music s) a = SoundSource.setAttenuation s a-setAudioSourceAttenuation (Sound s b) a = SoundSource.setAttenuation s a---- | gets audio source min distance, distance at which sound is played a volume 100.0-getAudioSourceMinDistance :: AudioSource -> IO Float-getAudioSourceMinDistance (Music s) = SoundSource.getMinDistance s-getAudioSourceMinDistance (Sound s b) = SoundSource.getMinDistance s---- | sets audio source min distance, distance at which sound is played a volume 100.0-setAudioSourceMinDistance :: AudioSource -> Float -> IO ()-setAudioSourceMinDistance (Music s) d = SoundSource.setMinDistance s d-setAudioSourceMinDistance (Sound s b) d = SoundSource.setMinDistance s d---- | set flag if audio source depends on position, default is FALSE (not dependent on position)-setAudioSourcePositionDependent :: AudioSource -> Bool -> IO ()-setAudioSourcePositionDependent (Music s) isR = SoundSource.setRelativeToListener s isR-setAudioSourcePositionDependent (Sound s b) isR = SoundSource.setRelativeToListener s isR+) where --- | get flag if audio source depends on position, default is FALSE (not dependent on position)-isAudioSourcePositionDependent :: AudioSource -> IO Bool-isAudioSourcePositionDependent (Music s) = SoundSource.isRelativeToListener s-isAudioSourcePositionDependent (Sound s b) = SoundSource.isRelativeToListener s+  import HGamer3D.Audio.AudioListener+  import HGamer3D.Audio.AudioSource+  import HGamer3D.Audio.SystemAudio 
+ HGamer3D/Audio/AudioBase.hs view
@@ -0,0 +1,255 @@+{-# OPTIONS_HADDOCK hide #-}++-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org++--+-- (c) 2011-2013 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+--     http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- | Audio functionality for HGamer3D, internal implementation. This module also exports internal data declarations, in case they are needed. Normally you should only use HGamer3D.Audio and import that, which exhibits the public API.+module HGamer3D.Audio.AudioBase+where++import GHC.Ptr++import HGamer3D.Data+import HGamer3D.Data.HG3DClass++import HGamer3D.Common++import HGamer3D.Bindings.SFML.ClassPtr+import HGamer3D.Bindings.SFML.Utils++import qualified HGamer3D.Bindings.SFML.ClassListener as Listener+import qualified HGamer3D.Bindings.SFML.ClassMusic as Music +import qualified HGamer3D.Bindings.SFML.ClassSound as Sound+import qualified HGamer3D.Bindings.SFML.ClassSoundBuffer as SoundBuffer+import qualified HGamer3D.Bindings.SFML.ClassSoundSource as SoundSource+import qualified HGamer3D.Bindings.SFML.ClassSoundStream as SoundStream+++import HGamer3D.Bindings.SFML.EnumSoundSourceStatus+import HGamer3D.Bindings.SFML.EnumSoundSourceStatus++import Control.Monad+import qualified Data.Map as M+import Data.Maybe+++-- Source types++data AudioSource = Music HG3DClass | Sound HG3DClass HG3DClass++-- Listener Functions++-- | set overall main audio volume+setAudioMainVolume :: Float -- ^ volume in a scale between 0 and 100.0+					-> IO ()+setAudioMainVolume vol = Listener.setGlobalVolume vol++-- | get overall main audio volume+getAudioMainVolume :: IO Float -- ^ volume in a scale between 0 and 100.0+getAudioMainVolume = Listener.getGlobalVolume++-- | set position of the listener, this is where the \"micro\" is located+setAudioListenerPosition :: Vec3 -- ^ position of listener+							-> IO ()+setAudioListenerPosition (Vec3 x y z) = Listener.setPosition x y z++-- | set direction of the listener+setAudioListenerDirection :: Vec3 -- ^ direction, in which listener hears+                             -> IO ()+setAudioListenerDirection (Vec3 x y z) = Listener.setDirection x y z+++-- Music Functions, deletion and cretion of Audio types+--++_findMusicFile filename = do+        dirs <- liftM (fmap (++ osSep ++ "sound")) (sequence [getAppMediaDirectory])+        filepath <- findFileInDirs filename dirs+        return filepath+  +  ++-- | create music (stream source, reading from file)+musicAudioSource :: String -- ^ filename of music +			-> IO (Maybe AudioSource) -- ^ audio source, which can be played+musicAudioSource filename = do+	music <- Music.new+        -- try to find file in hg3d directories+        filepath <-_findMusicFile filename+	-- try to open+        case filepath of+          Just f -> do+            fOk <- Music.openFromFile music (f)+            if fOk then+		return (Just (Music music))+		else do+                      Music.delete music+                      return Nothing+          Nothing -> return Nothing++-- | create sound (stream source, loaded into memory)+soundAudioSource :: String -- ^ filename of sound without path+					-> IO (Maybe AudioSource) -- ^ audio source, which can be played+soundAudioSource filename = do+	sound <- Sound.new+	buffer <- SoundBuffer.new+        filepath <-_findMusicFile filename+	-- try to open+        case filepath of+          Just f -> do+            fOk <- SoundBuffer.loadFromFile buffer (f)+            if fOk then do+		Sound.setBuffer sound buffer		+		return (Just (Sound sound buffer))+		else do+                    Sound.delete sound+                    SoundBuffer.delete buffer+                    return Nothing+          Nothing -> return Nothing++-- | delete audio source+freeAudioSource :: AudioSource -> IO ()+freeAudioSource (Music music) = do+	Music.delete music+deleteAudioSource (Sound sound buffer) = do+	Sound.delete sound+	SoundBuffer.delete buffer+++-- Source play, pause, stop+--++-- | starts playing audio source+playAudioSource :: AudioSource -- ^the audio source+					-> IO ()+playAudioSource (Music music) = do+	SoundStream.play music+playAudioSource (Sound sound buffer) = do+	Sound.play sound++-- | pause playing audio source, remembers location+pauseAudioSource :: AudioSource -> IO ()+pauseAudioSource (Music music) = do+	SoundStream.pause music+pauseAudioSource (Sound sound buffer) = do+	Sound.pause sound++-- | completely stops audio playing+stopAudioSource :: AudioSource -> IO ()+stopAudioSource (Music music) = do+	SoundStream.stop music+stopAudioSource (Sound sound buffer) = do+	Sound.stop sound++-- | is audio play looping+getAudioSourceLoop :: AudioSource -- ^audio source+				-> IO Bool -- ^true, loop is enabled, false loop is disabled+getAudioSourceLoop (Music music) = do+	fLoop <- SoundStream.getLoop music+	return fLoop+getAudioSourceLoop (Sound sound buffer) = do+	fLoop <- Sound.getLoop sound+	return fLoop++-- | set audio play is looping+setAudioSourceLoop :: AudioSource -- ^audio source+				-> Bool -- ^loop enabled+				-> IO ()+setAudioSourceLoop (Music music) fLoop = do+	SoundStream.setLoop music fLoop+setAudioSourceLoop (Sound sound buffer) fLoop = do+	Sound.setLoop sound fLoop+++-- Sound Source Functions+--++-- | get volume of a single audio source+getAudioSourceVolume :: AudioSource -- ^audio source+					-> IO Float -- ^volume of audio source in scale of 0 to 100.0+					+getAudioSourceVolume (Music s) = SoundSource.getVolume s+getAudioSourceVolume (Sound s b) = SoundSource.getVolume s++-- | set volume of a single audio source+setAudioSourceVolume :: AudioSource -- ^audio source+				-> Float -> IO () -- ^volume of this audio source in scale of 0 to 100.0+				+setAudioSourceVolume (Music s) v = SoundSource.setVolume s v+setAudioSourceVolume (Sound s b) v = SoundSource.setVolume s v++-- | get audio source pitch+-- the pitch is the frequency of the sound which also influences playing speed. The default value is 1.0.+getAudioSourcePitch :: AudioSource -- ^audio source+				-> IO Float -- ^pitch, a 1.0 is no change to original sound+				+getAudioSourcePitch (Music s) = SoundSource.getPitch s+getAudioSourcePitch (Sound s b) = SoundSource.getPitch s++-- | sets the pitch of an audio source+setAudioSourcePitch :: AudioSource -> Float -> IO ()+setAudioSourcePitch (Music s) p = SoundSource.setPitch s p+setAudioSourcePitch (Sound s b) p = SoundSource.setPitch s p++-- | sets the position of an audio source+setAudioSourcePosition :: AudioSource -- ^audio source+					-> Vec3 -> IO () -- ^new position of this source+					+setAudioSourcePosition (Music s) (Vec3 x y z) = SoundSource.setPosition s x y z+setAudioSourcePosition (Sound s b) (Vec3 x y z) = SoundSource.setPosition s x y z++-- | gets the position of an audio source+getAudioSourcePosition :: AudioSource -- ^audio source+					-> IO Vec3 -- ^position of the audio source+					+getAudioSourcePosition (Music s) = SoundSource.getPosition s+getAudioSourcePosition (Sound s b) = SoundSource.getPosition s++-- | gets the attenuation factor of an audio source+getAudioSourceAttenuation :: AudioSource -- ^audio source+			-> IO Float -- ^attenuation is the damping factor by distance, default value is 1.0, 0.0 means no damping+getAudioSourceAttenuation (Music s) = SoundSource.getAttenuation s+getAudioSourceAttenuation (Sound s b) = SoundSource.getAttenuation s++-- | sets the attenuation factor of an audio source+setAudioSourceAttenuation :: AudioSource -- ^audio source+				-> Float -> IO () -- ^attenuation factor+setAudioSourceAttenuation (Music s) a = SoundSource.setAttenuation s a+setAudioSourceAttenuation (Sound s b) a = SoundSource.setAttenuation s a++-- | gets audio source min distance, distance at which sound is played a volume 100.0+getAudioSourceMinDistance :: AudioSource -> IO Float+getAudioSourceMinDistance (Music s) = SoundSource.getMinDistance s+getAudioSourceMinDistance (Sound s b) = SoundSource.getMinDistance s++-- | sets audio source min distance, distance at which sound is played a volume 100.0+setAudioSourceMinDistance :: AudioSource -> Float -> IO ()+setAudioSourceMinDistance (Music s) d = SoundSource.setMinDistance s d+setAudioSourceMinDistance (Sound s b) d = SoundSource.setMinDistance s d++-- | set flag if audio source depends on position, default is FALSE (not dependent on position)+setAudioSourcePositionDependent :: AudioSource -> Bool -> IO ()+setAudioSourcePositionDependent (Music s) isR = SoundSource.setRelativeToListener s isR+setAudioSourcePositionDependent (Sound s b) isR = SoundSource.setRelativeToListener s isR++-- | get flag if audio source depends on position, default is FALSE (not dependent on position)+isAudioSourcePositionDependent :: AudioSource -> IO Bool+isAudioSourcePositionDependent (Music s) = SoundSource.isRelativeToListener s+isAudioSourcePositionDependent (Sound s b) = SoundSource.isRelativeToListener s+
+ HGamer3D/Audio/AudioListener.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}+{-# OPTIONS_HADDOCK hide #-}++-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2011-2014 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+--     http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- | data types which describes the one Audio Listener+module HGamer3D.Audio.AudioListener++where++import qualified HGamer3D.Data as D+import Data.Typeable++-- | The Source itself+data AudioListener = AudioListener {+  mainVolume :: Float  -- ^ Main Volume+} deriving (Eq, Show, Typeable)
+ HGamer3D/Audio/AudioSource.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}+{-# OPTIONS_HADDOCK hide #-}++-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2011-2014 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+--     http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- | data types which describes an Audio Source+module HGamer3D.Audio.AudioSource++where++import qualified HGamer3D.Data as D+import qualified Data.Map as M+import Data.Typeable++data AudioSlotParameter = AudioSlotParameter {+  aspFile :: String,         -- ^ Audio file on disk+  aspVolume :: Float,        -- ^ Volume 0.0 - 100.0+  aspLoopFlag :: Bool,       -- ^ is sound looping+  aspPositionFlag :: Bool,   -- ^ is sound position dependent+  aspPitch :: Float,         -- ^ Frequency change, 1.0 no change+  aspAttenuation :: Float,   -- ^ Damping factor by distance, default 1.0, 0.0 no damping+  aspMinDistance :: Float    -- ^ at min distance, sound is played with volume 100.0+} deriving (Eq, Show, Typeable)++data AudioSlot = Music AudioSlotParameter+               | Sound AudioSlotParameter deriving (Eq, Show, Typeable)++type AudioSource = M.Map String AudioSlot++musicSlot :: String -> AudioSlot+musicSlot file = Music (AudioSlotParameter file 100.0 False True 1.0 1.0 10.0)++soundSlot :: String -> AudioSlot+soundSlot file = Sound (AudioSlotParameter file 100.0 False True 1.0 1.0 10.0)+++data AudioCmd   = PlayAudio String+                | StopAudio String+                  deriving (Eq, Typeable, Show)++
+ HGamer3D/Audio/SystemAudio.hs view
@@ -0,0 +1,144 @@+{-# Language StandaloneDeriving, DeriveDataTypeable #-}+{-# OPTIONS_HADDOCK hide #-}++-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2011-2014 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+--     http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++module HGamer3D.Audio.SystemAudio++where++import qualified Data.Map as M+import Data.Maybe+import Data.Typeable+import Data.Dynamic+import Data.IORef+import Data.Traversable+import Control.Concurrent++import qualified HGamer3D.Data as D+import HGamer3D.Common+import qualified HGamer3D.BaseAPI.Audio as A++import qualified HGamer3D.Audio.AudioSource as AS+import qualified HGamer3D.Audio.AudioListener as AL++data AudioMap = AudioMap (M.Map String A.AudioSource) AS.AudioSource++{- In this module the AS.AudioSource is a map of AS.AudioSlots, where each slot aligns to a+   AudioSource from the base Audio module. So the AS.AudioSource is a map of real sources, +   to be able to have multiple sounds played by one object.+-}++-- | create AudioMap from pure data definition out of Schema+audioMap :: AS.AudioSource -> IO AudioMap+audioMap mapAS = do++  let makeSource asource = do+        -- create source+        (source, parameter) <- case asource of+          AS.Music parameter -> A.musicAudioSource (AS.aspFile parameter) >>= \s -> return (fromJust s, parameter)+          AS.Sound parameter -> A.soundAudioSource (AS.aspFile parameter) >>= \s -> return (fromJust s, parameter)+        -- set all parameters+        A.setAudioSourceVolume source (AS.aspVolume parameter)+        A.setAudioSourceLoop source (AS.aspLoopFlag parameter)+        A.setAudioSourcePositionDependent source (AS.aspPositionFlag parameter)+        A.setAudioSourcePitch source (AS.aspPitch parameter)+        A.setAudioSourceAttenuation source (AS.aspAttenuation parameter)+        A.setAudioSourceMinDistance source (AS.aspMinDistance parameter)+        return source++  obMap <- traverse makeSource mapAS+  return $ AudioMap obMap mapAS++-- | update AudioSlots from change in data definition, tbd+updateAudioMap :: AudioMap -> AS.AudioSource -> IO AudioMap+updateAudioMap inSlots newSlots = return inSlots++-- | remove AudioSlots, tbd+removeAudioMap :: AudioMap -> IO ()+removeAudioMap as = return ()++setPosition :: AudioMap -> D.Position -> IO ()+setPosition (AudioMap obMap schema) pos = do+            traverse ((flip A.setAudioSourcePosition) pos) obMap+            return ()++playCmd :: AudioMap -> Maybe AS.AudioCmd -> IO ()+playCmd (AudioMap obMap schema) (Just (AS.PlayAudio slot)) = A.playAudioSource (fromJust (M.lookup slot obMap))+playCmd (AudioMap obMap schema) (Just (AS.StopAudio slot)) = A.stopAudioSource (fromJust (M.lookup slot obMap))+playCmd _ _ = return ()++data ECSAudio = ECSAudio     -- no audio specific data here, but never mind++instance System ECSAudio where++    initializeSystem = do+         +      lock <- newMVar ()+      newERefs <- newIORef []+      delERefs <- newIORef []+      let records = []+      let system = ECSAudio++      let systemFunction system eref = do++          e <- readE eref -- this e is used to create the representation++          if e #? CTASr then do++             rep <- audioMap ((e # CTASr) :: AS.AudioSource)+             ref <- newIORef rep+             if e #? CTPos then setPosition rep (e # CTPos) else return ()++             let createRecord ct = do+                 if e #? ct then do+                    l <- componentListener eref ct+                    let uf = case ct of+                                  CTASr -> \ _ e' -> do+                                                              updateAudioMap rep (e' # CTASr)+                                                              if e #? CTPos then setPosition rep (e' # CTPos) else return ()+                                                              return () +                                  CTCmd -> \ _ e' -> do+                                                              playCmd rep (e' ?# CTCmd)+                                                              return ()+                                  _ -> \ _ _ -> return ()++                    let df = return ()+                    return $ Just (l, uf, df)+                    else return Nothing++             newRecords <- Prelude.mapM createRecord [CTASr, CTCmd]+             return (map fromJust (filter isJust newRecords))++             else return []+        +      return (SystemData lock newERefs delERefs records system systemFunction)++    stepSystem (SystemData lock newERefs delERefs records system systemFunction) = do+      return False++forkAudioWorld :: D.GameTime -> IO [SomeSystem]+forkAudioWorld sleepT = do+                       system <- (runSystem sleepT) :: IO (SystemData ECSAudio)+                       return $ [SomeSystem system]+++++
+ HGamer3D/BaseAPI/Audio.hs view
@@ -0,0 +1,70 @@+-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2011-2013 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+--     http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- | Audio functionality for HGamer3D, public API.+module HGamer3D.BaseAPI.Audio++(+	-- * Audio Data Types+	module HGamer3D.Bindings.SFML.EnumSoundSourceStatus,+	AudioSource, +	+	-- * Audio Listener Functions+	setAudioMainVolume,+	getAudioMainVolume,+	setAudioListenerPosition,+	setAudioListenerDirection,+	+	-- * Audio Source Creation Functions+	musicAudioSource,+	soundAudioSource,+	freeAudioSource,+	+	-- * Audio Source Play Functions+	playAudioSource,+	pauseAudioSource,+	stopAudioSource,++	-- * Audio Source Property Functions+	setAudioSourceLoop,+	getAudioSourceLoop,++	getAudioSourceVolume,+	setAudioSourceVolume,++	getAudioSourcePitch,+	setAudioSourcePitch,++	getAudioSourcePosition,+	setAudioSourcePosition,++	getAudioSourceAttenuation,+	setAudioSourceAttenuation,++	getAudioSourceMinDistance,+	setAudioSourceMinDistance,++	setAudioSourcePositionDependent,+	isAudioSourcePositionDependent,++)++where++import HGamer3D.Audio.AudioBase+import HGamer3D.Bindings.SFML.EnumSoundSourceStatus
LICENSE view
@@ -1,42 +1,42 @@-LICENSE
--------
-
-(c) 2011-2014 Peter Althainz
-
-
-HGamer3D (http://www.hgamer3d.org)
-----------------------------------
-
-HGamer3D is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
- 
-Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
-
-Source Code
------------
-You can obtain the latest version of the source code under http://www.bitbucket.org/althainz/HGamer3D
-
-
-Open Source Software Used - Module HGamer3D
--------------------------------------------
-
-HGamer3D uses a number of open source software libraries. You are responsible to comply to the licenses of those packages and the licenses of software used by those packages if you use HGamer3D. 
-
-The HGamer3D module uses the following Haskell libraries from Hackage:
-
-base, license: BSD3
-containers, license: BSD3
-text,  license: BSD3
-directory, license: BSD3
-mtl, license: BSD3
-FindBin, license: BSD3
-monad-loops, license: PublicDomain, BSD3 similar
-split, license: BSD3
-netwire, license: BSD3
-HGamer3D-Data, license: Apache 2.0
-HGamer3D-Ogre-Binding, license: Apache 2.0 and dependencies see in that module
-HGamer3D-SFML-Binding, license: Apache 2.0 and dependencies see in that module 
-HGamer3D-CEGUI-Binding, license: Apache 2.0 and dependencies see in that module
-HGamer3D-Enet-Binding, license: Apache 2.0 and dependencies see in that module
+LICENSE+-------++(c) 2011-2014 Peter Althainz+++HGamer3D (http://www.hgamer3d.org)+----------------------------------++HGamer3D is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0+ +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.+++Source Code+-----------+You can obtain the latest version of the source code under http://www.bitbucket.org/althainz/HGamer3D+++Open Source Software Used - Module HGamer3D+-------------------------------------------++HGamer3D uses a number of open source software libraries. You are responsible to comply to the licenses of those packages and the licenses of software used by those packages if you use HGamer3D. ++The HGamer3D module uses the following Haskell libraries from Hackage:++base, license: BSD3+containers, license: BSD3+text,  license: BSD3+directory, license: BSD3+mtl, license: BSD3+FindBin, license: BSD3+monad-loops, license: PublicDomain, BSD3 similar+split, license: BSD3+netwire, license: BSD3+HGamer3D-Data, license: Apache 2.0+HGamer3D-Ogre-Binding, license: Apache 2.0 and dependencies see in that module+HGamer3D-SFML-Binding, license: Apache 2.0 and dependencies see in that module +HGamer3D-CEGUI-Binding, license: Apache 2.0 and dependencies see in that module+HGamer3D-Enet-Binding, license: Apache 2.0 and dependencies see in that module
Setup.hs view
@@ -1,22 +1,22 @@--- This source file is part of HGamer3D
--- (A project to enable 3D game development in Haskell)
--- For the latest info, see http://www.hgamer3d.org
---
--- (c) 2011-2013 Peter Althainz
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
---     http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
-
--- Setup.hs
-
-import Distribution.Simple
-main = defaultMain
+-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2011-2013 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+--     http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- Setup.hs++import Distribution.Simple+main = defaultMain