Skip to content

Commit

Permalink
Merge branch 'release-0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
urs-of-the-backwoods committed Aug 11, 2014
2 parents 71fbec6 + 562a7e7 commit ef86068
Show file tree
Hide file tree
Showing 274 changed files with 9,531 additions and 4,953 deletions.
6 changes: 3 additions & 3 deletions Audio/HGamer3D-Audio.cabal
@@ -1,5 +1,5 @@
Name: HGamer3D-Audio
Version: 0.3.0
Version: 0.4.0
Synopsis: Audio Functionality for HGamer3D
Description:
HGamer3D is a game engine for developing 3D games in the programming
Expand All @@ -18,9 +18,9 @@ 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
Build-Depends: base >= 3 && < 5, containers, HGamer3D-Data >= 0.4.0 && < 0.5.0, HGamer3D-SFML-Binding >= 0.4.0 && < 0.5.0

Exposed-modules: HGamer3D.Audio
Exposed-modules: HGamer3D.Audio.Schema.AudioSource, HGamer3D.Audio.Schema.AudioListener, HGamer3D.Audio.Internal.Base, HGamer3D.Audio.BaseAPI, HGamer3D.Internal.Audio
Other-modules:

c-sources:
Expand Down
78 changes: 78 additions & 0 deletions Audio/HGamer3D/Audio/BaseAPI.hs
@@ -0,0 +1,78 @@
-- 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.hs


-- | Audio functionality for HGamer3D, public API.
module HGamer3D.Audio.BaseAPI

(
-- * Audio Data Types
module HGamer3D.Bindings.SFML.EnumSoundSourceStatus,
AudioSource,
AudioSlots,

-- * 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,

audioSlots,
updateAudioSlots


)

where

import HGamer3D.Audio.Internal.Base
import HGamer3D.Bindings.SFML.EnumSoundSourceStatus
116 changes: 59 additions & 57 deletions Audio/HGamer3D/Audio.hs → Audio/HGamer3D/Audio/Internal/Base.hs
@@ -1,6 +1,9 @@
{-# 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
--
Expand All @@ -16,63 +19,18 @@
-- 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,
-- Audio/Internal/Base.hs

getAudioSourcePosition,
setAudioSourcePosition,

getAudioSourceAttenuation,
setAudioSourceAttenuation,

getAudioSourceMinDistance,
setAudioSourceMinDistance,

setAudioSourcePositionDependent,
isAudioSourcePositionDependent

)

-- | 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.Internal.Base
where

import GHC.Ptr

import HGamer3D.Data
import HGamer3D.Data.HG3DClass

import HGamer3D.Util

import HGamer3D.Bindings.SFML.ClassPtr
Expand All @@ -86,15 +44,21 @@ 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 qualified HGamer3D.Audio.Schema.AudioSource as AS
import qualified HGamer3D.Audio.Schema.AudioListener as AL

import Control.Monad
import qualified Data.Map as M
import Data.Maybe


-- Source types

data AudioSource = Music HG3DClass | Sound HG3DClass HG3DClass

data AudioSlots = AudioSlots (M.Map String AudioSource) AS.AudioSlots

-- Listener Functions

Expand Down Expand Up @@ -129,9 +93,9 @@ _findMusicFile filename = do


-- | create music (stream source, reading from file)
createMusic :: String -- ^ filename of music
musicAudioSource :: String -- ^ filename of music
-> IO (Maybe AudioSource) -- ^ audio source, which can be played
createMusic filename = do
musicAudioSource filename = do
music <- Music.new
-- try to find file in hg3d directories
filepath <-_findMusicFile filename
Expand All @@ -147,9 +111,9 @@ createMusic filename = do
Nothing -> return Nothing

-- | create sound (stream source, loaded into memory)
createSound :: String -- ^ filename of sound without path
soundAudioSource :: String -- ^ filename of sound without path
-> IO (Maybe AudioSource) -- ^ audio source, which can be played
createSound filename = do
soundAudioSource filename = do
sound <- Sound.new
buffer <- SoundBuffer.new
filepath <-_findMusicFile filename
Expand All @@ -167,8 +131,8 @@ createSound filename = do
Nothing -> return Nothing

-- | delete audio source
deleteAudioSource :: AudioSource -> IO ()
deleteAudioSource (Music music) = do
freeAudioSource :: AudioSource -> IO ()
freeAudioSource (Music music) = do
Music.delete music
deleteAudioSource (Sound sound buffer) = do
Sound.delete sound
Expand Down Expand Up @@ -296,3 +260,41 @@ isAudioSourcePositionDependent :: AudioSource -> IO Bool
isAudioSourcePositionDependent (Music s) = SoundSource.isRelativeToListener s
isAudioSourcePositionDependent (Sound s b) = SoundSource.isRelativeToListener s


-- | create AudioSlots from pure data definition out of Schema
audioSlots :: AS.AudioSlots -> IO AudioSlots
audioSlots schema@(AS.AudioSlots asList) = do
let makeSource asource = do
-- create source
(source, parameter) <- case asource of
AS.MusicSource name parameter -> musicAudioSource name >>= \s -> return (fromJust s, parameter)
AS.SoundSource name parameter -> soundAudioSource name >>= \s -> return (fromJust s, parameter)
-- set all parameters
setAudioSourceVolume source (AS.volume parameter)
setAudioSourceLoop source (AS.loopFlag parameter)
setAudioSourcePositionDependent source (AS.positionFlag parameter)
setAudioSourcePitch source (AS.pitch parameter)
setAudioSourceAttenuation source (AS.attenuation parameter)
setAudioSourceMinDistance source (AS.minDistance parameter)
return source

obList <- mapM (\(s, as) -> makeSource as >>= \ob -> return (s, ob)) asList
return $ AudioSlots (M.fromList obList) schema

-- | update AudioSlots from change in data definition, tbd
updateAudioSlots :: AudioSlots -> AS.AudioSlots -> IO AudioSlots
updateAudioSlots inSlots newSlots = return inSlots

-- | remove AudioSlots, tbd
removeAudioSlots :: AudioSlots -> IO ()
removeAudioSlots as = return ()

instance HasPosition AudioSource where
position = getAudioSourcePosition
positionTo = setAudioSourcePosition

instance HasPosition AudioSlots where
position (AudioSlots map _) = position (snd ((M.toList map) !! 0))
positionTo (AudioSlots map _) pos = (mapM (\as -> positionTo as pos) (fmap snd (M.toList map))) >> return ()


34 changes: 34 additions & 0 deletions Audio/HGamer3D/Audio/Schema/AudioListener.hs
@@ -0,0 +1,34 @@
{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}

-- 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.

-- HGamer3D/Audio/Schema/AudioListener.hs

-- | data types which describes the one Audio Listener
module HGamer3D.Audio.Schema.AudioListener

where

import qualified HGamer3D.Data as D
import Data.Typeable

-- | The Source itself
data AudioListener = AudioListener {
mainVolume :: Float -- ^ Main Volume
}
50 changes: 50 additions & 0 deletions Audio/HGamer3D/Audio/Schema/AudioSource.hs
@@ -0,0 +1,50 @@
{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}

-- 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.

-- HGamer3D/Audio/Schema/AudioSource.hs

-- | data types which describes an Audio Source
module HGamer3D.Audio.Schema.AudioSource

where

import qualified HGamer3D.Data as D
import Data.Typeable

-- | The Source itself
data AudioSource = MusicSource String AudioSourceParameter
| SoundSource String AudioSourceParameter
deriving (Eq, Show, Typeable)

-- | Audio Parameter
data AudioSourceParameter = Parameter {
volume :: Float, -- ^ Volume 0.0 - 100.0
loopFlag :: Bool, -- ^ is sound looping
positionFlag :: Bool, -- ^ is sound position dependent
pitch :: Float, -- ^ Frequency change, 1.0 no change
attenuation :: Float, -- ^ Damping factor by distance, default 1.0, 0.0 no damping
minDistance :: Float -- ^ at min distance, sound is played with volume 100.0
} deriving (Eq, Show, Typeable)

-- | Audio Slots
data AudioSlots = AudioSlots [(String, AudioSource)] deriving (Eq, Show, Typeable)



12 changes: 9 additions & 3 deletions Wire/Setup.hs → Audio/HGamer3D/Internal/Audio.hs
Expand Up @@ -16,7 +16,13 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- Setup.hs
-- Audio.hs

import Distribution.Simple
main = defaultMain

-- | Audio functionality for HGamer3D, internal API.
module HGamer3D.Internal.Audio
(
module HGamer3D.Audio.Internal.Base
)
where
import HGamer3D.Audio.Internal.Base

0 comments on commit ef86068

Please sign in to comment.