diff --git a/CMakeLists.txt b/CMakeLists.txt
index cf083b87bc7..38ce8689855 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,22 @@ set(CMAKE_BUILD_TYPE_INIT "Release")
# quiet output for Makefiles, 'make -s' helps too
# set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
+#-----------------------------------------------------------------------------
+# Set policy
+
+# see "cmake --help-policy CMP0003"
+# So library linking is more sane
+cmake_policy(SET CMP0003 NEW)
+
+# So BUILDINFO and BLENDERPATH strings are automatically quoted
+cmake_policy(SET CMP0005 NEW)
+
+# So syntax problems are errors
+cmake_policy(SET CMP0010 NEW)
+
+# Input directories must have CMakeLists.txt
+cmake_policy(SET CMP0014 NEW)
+
#-----------------------------------------------------------------------------
# Load some macros.
include(build_files/cmake/macros.cmake)
@@ -258,6 +274,11 @@ endif()
TEST_SSE_SUPPORT()
+# don't store paths to libs for portable distrobution
+if(WITH_INSTALL_PORTABLE)
+ set(CMAKE_SKIP_BUILD_RPATH TRUE)
+endif()
+
#-----------------------------------------------------------------------------
# Initialize un-cached vars, avoid unused warning
@@ -429,21 +450,20 @@ if(UNIX AND NOT APPLE)
endif()
if(WITH_OPENCOLLADA)
- set(OPENCOLLADA /usr/local/opencollada CACHE PATH "OpenCollada Directory")
- mark_as_advanced(OPENCOLLADA)
- set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
- set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2)
- set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA})
+ find_package(OpenCOLLADA)
+ if(OPENCOLLADA_FOUND)
+ set(PCRE /usr CACHE PATH "PCRE Directory")
+ mark_as_advanced(PCRE)
+ set(PCRE_LIBPATH ${PCRE}/lib)
+ set(PCRE_LIB pcre)
- set(PCRE /usr CACHE PATH "PCRE Directory")
- mark_as_advanced(PCRE)
- set(PCRE_LIBPATH ${PCRE}/lib)
- set(PCRE_LIB pcre)
-
- set(EXPAT /usr CACHE PATH "Expat Directory")
- mark_as_advanced(EXPAT)
- set(EXPAT_LIBPATH ${EXPAT}/lib)
- set(EXPAT_LIB expat)
+ set(EXPAT /usr CACHE PATH "Expat Directory")
+ mark_as_advanced(EXPAT)
+ set(EXPAT_LIBPATH ${EXPAT}/lib)
+ set(EXPAT_LIB expat)
+ else()
+ set(WITH_OPENCOLLADA OFF)
+ endif()
endif()
if(WITH_MEM_JEMALLOC)
@@ -499,6 +519,9 @@ if(UNIX AND NOT APPLE)
# GNU Compiler
if(CMAKE_COMPILER_IS_GNUCC)
set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
+ # CLang is the same as GCC for now.
+ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
# Intel C++ Compiler
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
# think these next two are broken
@@ -665,9 +688,15 @@ elseif(WIN32)
endif()
if(WITH_OPENCOLLADA)
- set(OPENCOLLADA_INCLUDE_DIR
- ${LIBDIR}/opencollada/include
+
+ set(OPENCOLLADA_INCLUDE_DIRS
+ ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
+ ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
+ ${LIBDIR}/opencollada/include/COLLADAFramework/include
+ ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
+ ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
)
+
set(OPENCOLLADA_LIBRARIES
${LIBDIR}/opencollada/lib/OpenCOLLADASaxFrameworkLoader.lib
${LIBDIR}/opencollada/lib/OpenCOLLADAFramework.lib
@@ -691,11 +720,11 @@ elseif(WIN32)
${LIBDIR}/ffmpeg/include/msvc
)
set(FFMPEG_LIBRARIES
- ${LIBDIR}/ffmpeg/lib/avcodec-52.lib
- ${LIBDIR}/ffmpeg/lib/avformat-52.lib
- ${LIBDIR}/ffmpeg/lib/avdevice-52.lib
- ${LIBDIR}/ffmpeg/lib/avutil-50.lib
- ${LIBDIR}/ffmpeg/lib/swscale-0.lib
+ ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
+ ${LIBDIR}/ffmpeg/lib/avformat-53.lib
+ ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
+ ${LIBDIR}/ffmpeg/lib/avutil-51.lib
+ ${LIBDIR}/ffmpeg/lib/swscale-2.lib
)
endif()
@@ -813,7 +842,13 @@ elseif(WIN32)
if(WITH_OPENCOLLADA)
set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
- set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
+ set(OPENCOLLADA_INCLUDE_DIRS
+ ${LIBDIR}/gcc/opencollada/include/COLLADAStreamWriter/include
+ ${LIBDIR}/gcc/opencollada/include/COLLADABaseUtils/include
+ ${LIBDIR}/gcc/opencollada/include/COLLADAFramework/include
+ ${LIBDIR}/gcc/opencollada/include/COLLADASaxFrameworkLoader/include
+ ${LIBDIR}/gcc/opencollada/include/GeneratedSaxParser/include
+ )
set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
set(PCRE_LIB pcre)
@@ -822,7 +857,7 @@ elseif(WIN32)
if(WITH_CODEC_FFMPEG)
set(FFMPEG ${LIBDIR}/ffmpeg)
set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
- set(FFMPEG_LIBRARIES avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
+ set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
set(FFMPEG_LIBPATH ${FFMPEG}/lib)
endif()
@@ -913,7 +948,7 @@ elseif(APPLE)
# we use precompiled libraries for py 3.2 and up by default
# normally cached but not since we include them with blender
- set(PYTHON_VERSION 3.2)
+ set(PYTHON_VERSION 3.2)
set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
# set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
set(PYTHON_LIBRARY python${PYTHON_VERSION})
@@ -1024,7 +1059,15 @@ elseif(APPLE)
if(WITH_OPENCOLLADA)
set(OPENCOLLADA ${LIBDIR}/opencollada)
- set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
+
+ set(OPENCOLLADA_INCLUDE_DIRS
+ ${LIBDIR}/opencollada/include/COLLADAStreamWriter
+ ${LIBDIR}/opencollada/include/COLLADABaseUtils
+ ${LIBDIR}/opencollada/include/COLLADAFramework
+ ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
+ ${LIBDIR}/opencollada/include/GeneratedSaxParser
+ )
+
set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
#pcre is bundled with openCollada
diff --git a/GNUmakefile b/GNUmakefile
index b6741d7e5f0..8446541cfae 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -35,17 +35,33 @@ OS_NCASE:=$(shell uname -s | tr '[A-Z]' '[a-z]')
# Source and Build DIR's
BLENDER_DIR:=$(shell pwd -P)
BUILD_DIR:=$(shell dirname $(BLENDER_DIR))/build/$(OS_NCASE)
+BUILD_TYPE:=Release
+BUILD_CMAKE_ARGS:=""
+# -----------------------------------------------------------------------------
+# additional targets for the build configuration
+
# support 'make debug'
ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
BUILD_DIR:=$(BUILD_DIR)_debug
BUILD_TYPE:=Debug
-else
- BUILD_TYPE:=Release
+endif
+ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
+ BUILD_DIR:=$(BUILD_DIR)_lite
+ BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake
+endif
+ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
+ BUILD_DIR:=$(BUILD_DIR)_bpy
+ BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake
+endif
+ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
+ BUILD_DIR:=$(BUILD_DIR)_bpy
+ BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake
endif
+# -----------------------------------------------------------------------------
# Get the number of cores for threaded build
NPROCS:=1
ifeq ($(OS), Linux)
@@ -61,14 +77,14 @@ ifeq ($(OS), NetBSD)
NPROCS:=$(shell sysctl -a | grep "hw.ncpu " | cut -d" " -f3 )
endif
-
+# -----------------------------------------------------------------------------
# Build Blender
all:
@echo
@echo Configuring Blender ...
if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
- cmake -H$(BLENDER_DIR) -B$(BUILD_DIR) -DCMAKE_BUILD_TYPE:STRING=$(BUILD_TYPE) ; \
+ cmake $(BUILD_CMAKE_ARGS) -H$(BLENDER_DIR) -B$(BUILD_DIR) -DCMAKE_BUILD_TYPE:STRING=$(BUILD_TYPE); \
fi
@echo
@@ -80,9 +96,40 @@ all:
@echo
debug: all
- # pass
+lite: all
+headless: all
+bpy: all
-# package types
+# -----------------------------------------------------------------------------
+# Helo for build targets
+help:
+ @echo ""
+ @echo "Convenience targets provided for building blender, (multiple at once can be used)"
+ @echo " * debug - build a debug binary"
+ @echo " * lite - disable non essential features for a smaller binary and faster build"
+ @echo " * headless - build without an interface (renderfarm or server automation)"
+ @echo " * bpy - build as a python module which can be loaded from python directly"
+ @echo ""
+ @echo "Project Files for IDE's"
+ @echo " * project_qtcreator - QtCreator Project Files"
+ @echo " * project_netbeans - NetBeans Project Files"
+ @echo " * project_eclipse - Eclipse CDT4 Project Files"
+ @echo ""
+ @echo "Package Targets"
+ @echo " * package_debian - build a debian package"
+ @echo " * package_pacman - build an arch linux pacmanpackage"
+ @echo " * package_archive - build an archive package"
+ @echo ""
+ @echo "Testing Targets (not assosiated with building blender)"
+ @echo " * test - run ctest, currently tests import/export, operator execution and that python modules load"
+ @echo " * test_cmake - runs our own cmake file checker which detects errors in the cmake file list definitions"
+ @echo " * test_pep8 - checks all python script are pep8 which are tagged to use the stricter formatting"
+ @echo " * test_deprecated - checks for deprecation tags in our code which may need to be removed"
+ @echo ""
+
+# -----------------------------------------------------------------------------
+# Packages
+#
package_debian:
cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
@@ -93,7 +140,10 @@ package_archive:
make -C $(BUILD_DIR) -s package_archive
@echo archive in "$(BUILD_DIR)/release"
-# forward build targets
+
+# -----------------------------------------------------------------------------
+# Tests
+#
test:
cd $(BUILD_DIR) ; ctest . --output-on-failure
@@ -111,6 +161,21 @@ test_cmake:
test_deprecated:
python3 source/tests/check_deprecated.py
+
+# -----------------------------------------------------------------------------
+# Project Files
+#
+
+project_qtcreator:
+ python3 build_files/cmake/cmake_qtcreator_project.py $(BUILD_DIR)
+
+project_netbeans:
+ python3 build_files/cmake/cmake_netbeans_project.py $(BUILD_DIR)
+
+project_eclipse:
+ cmake -G"Eclipse CDT4 - Unix Makefiles" -H$(BLENDER_DIR) -B$(BUILD_DIR)
+
+
clean:
$(MAKE) -C $(BUILD_DIR) clean
diff --git a/SConstruct b/SConstruct
index 72a6146bcc0..4690e12c735 100644
--- a/SConstruct
+++ b/SConstruct
@@ -166,6 +166,13 @@ if sys.platform=='win32':
env.SConscriptChdir(0)
+# Remove major kernel version from linux platform.
+# After Linus switched kernel to new version model this major version
+# shouldn't take much sense for building rules.
+
+if re.match('linux[0-9]+', platform):
+ platform = 'linux'
+
crossbuild = B.arguments.get('BF_CROSS', None)
if crossbuild and platform not in ('win32-vc', 'win64-vc'):
platform = 'linuxcross'
@@ -262,14 +269,15 @@ if env['OURPLATFORM']=='darwin':
else:
print B.bc.OKGREEN + "Found recommended sdk :" + B.bc.ENDC + " using MacOSX10.5.sdk"
- # for now, Mac builders must download and install the driver framework from 3Dconnexion
+ # for now, Mac builders must download and install the 3DxWare 10 Beta 4 driver framework from 3Dconnexion
# necessary header file lives here when installed:
# /Library/Frameworks/3DconnexionClient.framework/Versions/Current/Headers/ConnexionClientAPI.h
- if env['WITH_BF_3DMOUSE'] == 1 and not os.path.exists('/Library/Frameworks/3DconnexionClient.framework'):
- print "3D_CONNEXION_CLIENT_LIBRARY not found, disabling WITH_BF_3DMOUSE" # avoid build errors !
- env['WITH_BF_3DMOUSE'] = 0
- env['FOUND_NDOF_DRIVERS'] = 0
-
+ if env['WITH_BF_3DMOUSE'] == 1:
+ if not os.path.exists('/Library/Frameworks/3DconnexionClient.framework'):
+ print "3D_CONNEXION_CLIENT_LIBRARY not found, disabling WITH_BF_3DMOUSE" # avoid build errors !
+ env['WITH_BF_3DMOUSE'] = 0
+ else:
+ env.Append(LINKFLAGS=['-weak_framework','3DconnexionClient'])
if env['WITH_BF_OPENMP'] == 1:
if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
@@ -550,7 +558,7 @@ if env['OURPLATFORM']!='darwin':
scriptinstall.append(env.Install(dir=dir,source=source))
#-- icons
-if env['OURPLATFORM']=='linux2':
+if env['OURPLATFORM']=='linux':
iconlist = []
icontargetlist = []
@@ -629,7 +637,7 @@ textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
if env['OURPLATFORM']=='darwin':
allinstall = [blenderinstall, plugininstall, textinstall]
-elif env['OURPLATFORM']=='linux2':
+elif env['OURPLATFORM']=='linux':
allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall, iconinstall]
else:
allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
diff --git a/build_files/buildbot/config/user-config-i686.py b/build_files/buildbot/config/user-config-i686.py
index e09fecede59..07dc4a9d831 100644
--- a/build_files/buildbot/config/user-config-i686.py
+++ b/build_files/buildbot/config/user-config-i686.py
@@ -22,7 +22,7 @@ BF_EXPAT_LIB = ''
WITH_BF_FFMPEG = True
WITH_BF_STATICFFMPEG = True
-BF_FFMPEG = '/home/sources/staticlibs/ffmpeg-0.8'
+BF_FFMPEG = '/home/sources/staticlibs/ffmpeg'
BF_FFMPEG_LIBPATH = '${BF_FFMPEG}/lib32'
BF_FFMPEG_LIB_STATIC = '${BF_FFMPEG_LIBPATH}/libavformat.a ${BF_FFMPEG_LIBPATH}/libswscale.a ' + \
'${BF_FFMPEG_LIBPATH}/libavcodec.a ${BF_FFMPEG_LIBPATH}/libavdevice.a ${BF_FFMPEG_LIBPATH}/libavutil.a ' + \
diff --git a/build_files/buildbot/config/user-config-player-i686.py b/build_files/buildbot/config/user-config-player-i686.py
index 279f2d66804..54e66e847df 100644
--- a/build_files/buildbot/config/user-config-player-i686.py
+++ b/build_files/buildbot/config/user-config-player-i686.py
@@ -16,7 +16,7 @@ WITH_BF_COLLADA = False
WITH_BF_FFMPEG = True
WITH_BF_STATICFFMPEG = True
-BF_FFMPEG = '/home/sources/staticlibs/ffmpeg-0.8'
+BF_FFMPEG = '/home/sources/staticlibs/ffmpeg'
BF_FFMPEG_LIBPATH = '${BF_FFMPEG}/lib32'
BF_FFMPEG_LIB_STATIC = '${BF_FFMPEG_LIBPATH}/libavformat.a ${BF_FFMPEG_LIBPATH}/libswscale.a ' + \
'${BF_FFMPEG_LIBPATH}/libavcodec.a ${BF_FFMPEG_LIBPATH}/libavdevice.a ${BF_FFMPEG_LIBPATH}/libavutil.a ' + \
diff --git a/build_files/buildbot/config/user-config-player-x86_64.py b/build_files/buildbot/config/user-config-player-x86_64.py
index d1914338510..5d594229d3e 100644
--- a/build_files/buildbot/config/user-config-player-x86_64.py
+++ b/build_files/buildbot/config/user-config-player-x86_64.py
@@ -16,7 +16,7 @@ WITH_BF_COLLADA = False
WITH_BF_FFMPEG = True
WITH_BF_STATICFFMPEG = True
-BF_FFMPEG = '/home/sources/staticlibs/ffmpeg-0.8'
+BF_FFMPEG = '/home/sources/staticlibs/ffmpeg'
BF_FFMPEG_LIBPATH = '${BF_FFMPEG}/lib64'
BF_FFMPEG_LIB_STATIC = '${BF_FFMPEG_LIBPATH}/libavformat.a ${BF_FFMPEG_LIBPATH}/libswscale.a ' + \
'${BF_FFMPEG_LIBPATH}/libavcodec.a ${BF_FFMPEG_LIBPATH}/libavdevice.a ${BF_FFMPEG_LIBPATH}/libavutil.a ' + \
diff --git a/build_files/buildbot/config/user-config-x86_64.py b/build_files/buildbot/config/user-config-x86_64.py
index bdba8892bf8..9c569ff4458 100644
--- a/build_files/buildbot/config/user-config-x86_64.py
+++ b/build_files/buildbot/config/user-config-x86_64.py
@@ -22,7 +22,7 @@ BF_EXPAT_LIB = ''
WITH_BF_FFMPEG = True
WITH_BF_STATICFFMPEG = True
-BF_FFMPEG = '/home/sources/staticlibs/ffmpeg-0.8'
+BF_FFMPEG = '/home/sources/staticlibs/ffmpeg'
BF_FFMPEG_LIBPATH = '${BF_FFMPEG}/lib64'
BF_FFMPEG_LIB_STATIC = '${BF_FFMPEG_LIBPATH}/libavformat.a ${BF_FFMPEG_LIBPATH}/libswscale.a ' + \
'${BF_FFMPEG_LIBPATH}/libavcodec.a ${BF_FFMPEG_LIBPATH}/libavdevice.a ${BF_FFMPEG_LIBPATH}/libavutil.a ' + \
diff --git a/build_files/buildbot/master.cfg b/build_files/buildbot/master.cfg
index 1e70ec5e13e..5aa5a43abf7 100644
--- a/build_files/buildbot/master.cfg
+++ b/build_files/buildbot/master.cfg
@@ -116,7 +116,7 @@ add_builder(c, 'linux_x86_64_scons', '', generic_builder)
add_builder(c, 'salad_linux_x86_64_scons', '', generic_builder, 'soc-2011-salad')
add_builder(c, 'win32_scons', 'windows', generic_builder)
add_builder(c, 'salad_win32_scons', 'windows', generic_builder, 'soc-2011-salad')
-add_builder(c, 'win64_scons', 'windows', generic_builder)
+add_builder(c, 'win64_scons', 'win64', generic_builder)
#add_builder(c, 'freebsd_i386_cmake', '', generic_builder)
#add_builder(c, 'freebsd_x86_64_cmake', '', generic_builder)
diff --git a/build_files/buildbot/slave_compile.py b/build_files/buildbot/slave_compile.py
index b83a65f2466..415f95a516f 100644
--- a/build_files/buildbot/slave_compile.py
+++ b/build_files/buildbot/slave_compile.py
@@ -108,32 +108,12 @@ else:
sys.exit(0)
else:
- bitness = '32'
- # Switch to new FFmpeg library
if builder.find('win') != -1:
- if builder.find('win32') != -1:
- LCGDIR = '#../lib/windows'
- elif builder.find('win64') != -1:
- LCGDIR = '#../lib/win64'
+ bitness = '32'
+
+ if builder.find('win64') != -1:
bitness = '64'
- all_ffmpeg_libs = ['avcodec-53',
- 'avdevice-53',
- 'avformat-53',
- 'avutil-51',
- 'swscale-2']
-
- ffmpeg_lib = []
- ffmpeg_dll = []
-
- for lib in all_ffmpeg_libs:
- ffmpeg_lib.append(lib + '.lib')
- ffmpeg_dll.append('${BF_FFMPEG_LIBPATH}/' + lib + '.dll')
-
- scons_options.append('BF_FFMPEG=' + LCGDIR + '/ffmpeg-0.8')
- scons_options.append('BF_FFMPEG_LIB=' + (' '.join(ffmpeg_lib)))
- scons_options.append('BF_FFMPEG_DLL=' + (' '.join(ffmpeg_dll)))
-
scons_options.append('BF_BITNESS=' + bitness)
retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options)
diff --git a/build_files/buildbot/slave_pack.py b/build_files/buildbot/slave_pack.py
index 5fdeb4a8ad5..af8d99893b4 100644
--- a/build_files/buildbot/slave_pack.py
+++ b/build_files/buildbot/slave_pack.py
@@ -72,32 +72,12 @@ if builder.find('scons') != -1:
retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options)
sys.exit(retcode)
else:
- bitness = '32'
- # Switch to new FFmpeg library
if builder.find('win') != -1:
- if builder.find('win32') != -1:
- LCGDIR = '#../lib/windows'
- elif builder.find('win64') != -1:
- LCGDIR = '#../lib/win64'
+ bitness = '32'
+
+ if builder.find('win64') != -1:
bitness = '64'
- all_ffmpeg_libs = ['avcodec-53',
- 'avdevice-53',
- 'avformat-53',
- 'avutil-51',
- 'swscale-2']
-
- ffmpeg_lib = []
- ffmpeg_dll = []
-
- for lib in all_ffmpeg_libs:
- ffmpeg_lib.append(lib + '.lib')
- ffmpeg_dll.append('${BF_FFMPEG_LIBPATH}/' + lib + '.dll')
-
- scons_options.append('BF_FFMPEG=' + LCGDIR + '/ffmpeg-0.8')
- scons_options.append('BF_FFMPEG_LIB=' + (' '.join(ffmpeg_lib)))
- scons_options.append('BF_FFMPEG_DLL=' + (' '.join(ffmpeg_dll)))
-
scons_options.append('BF_BITNESS=' + bitness)
retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options)
diff --git a/build_files/cmake/Modules/FindOpenCOLLADA.cmake b/build_files/cmake/Modules/FindOpenCOLLADA.cmake
new file mode 100644
index 00000000000..c7637283514
--- /dev/null
+++ b/build_files/cmake/Modules/FindOpenCOLLADA.cmake
@@ -0,0 +1,118 @@
+# - Find OpenCOLLADA library
+# Find the native OpenCOLLADA includes and library
+# This module defines
+# OPENCOLLADA_INCLUDE_DIRS, where to find COLLADABaseUtils/ and
+# COLLADAFramework/, Set when OPENCOLLADA_INCLUDE_DIR is found.
+# OPENCOLLADA_LIBRARIES, libraries to link against to use OpenCOLLADA.
+# OPENCOLLADA_ROOT_DIR, The base directory to search for OpenCOLLADA.
+# This can also be an environment variable.
+# OPENCOLLADA_FOUND, If false, do not try to use OpenCOLLADA.
+#
+# also defined, but not for general use are
+# OPENCOLLADA_LIBRARY, where to find the OpenCOLLADA library.
+
+#=============================================================================
+# Copyright 2011 Blender Foundation.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+# note about include paths, there are 2 ways includes are set
+#
+# Where '/usr/include/opencollada' is the root dir:
+# /usr/include/opencollada/COLLADABaseUtils/COLLADABUPlatform.h
+#
+# Where '/opt/opencollada' is the base dir:
+# /opt/opencollada/COLLADABaseUtils/include/COLLADABUPlatform.h
+
+# If OPENCOLLADA_ROOT_DIR was defined in the environment, use it.
+IF(NOT OPENCOLLADA_ROOT_DIR AND NOT $ENV{OPENCOLLADA_ROOT_DIR} STREQUAL "")
+ SET(OPENCOLLADA_ROOT_DIR $ENV{OPENCOLLADA_ROOT_DIR})
+ENDIF()
+
+SET(_opencollada_FIND_INCLUDES
+ COLLADAStreamWriter
+ COLLADABaseUtils
+ COLLADAFramework
+ COLLADASaxFrameworkLoader
+ GeneratedSaxParser
+)
+
+SET(_opencollada_FIND_COMPONENTS
+ OpenCOLLADAStreamWriter
+ OpenCOLLADASaxFrameworkLoader
+ OpenCOLLADAFramework
+ OpenCOLLADABaseUtils
+ GeneratedSaxParser
+ UTF
+ MathMLSolver
+ pcre
+ ftoa
+ buffer
+ xml2
+)
+
+SET(_opencollada_SEARCH_DIRS
+ ${OPENCOLLADA_ROOT_DIR}
+ /usr/local
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+)
+
+SET(_opencollada_INCLUDES)
+FOREACH(COMPONENT ${_opencollada_FIND_INCLUDES})
+ STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+
+ # need to use this even thouh we are looking for a dir
+ FIND_FILE(OPENCOLLADA_${UPPERCOMPONENT}_INCLUDE_DIR
+ NAMES
+ ${COMPONENT}/include
+ ${COMPONENT}
+ # Ubuntu ppa needs this.
+ # Alternative would be to suffix all members of search path
+ # but this is less trouble, just looks strange.
+ include/opencollada/${COMPONENT}
+ HINTS
+ ${_opencollada_SEARCH_DIRS}
+ )
+ MARK_AS_ADVANCED(OPENCOLLADA_${UPPERCOMPONENT}_INCLUDE_DIR)
+ LIST(APPEND _opencollada_INCLUDES "${OPENCOLLADA_${UPPERCOMPONENT}_INCLUDE_DIR}")
+ENDFOREACH()
+
+
+SET(_opencollada_LIBRARIES)
+FOREACH(COMPONENT ${_opencollada_FIND_COMPONENTS})
+ STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+
+ FIND_LIBRARY(OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY
+ NAMES
+ ${COMPONENT}
+ HINTS
+ ${_opencollada_SEARCH_DIRS}
+ PATH_SUFFIXES
+ lib64 lib
+ # Ubuntu ppa needs this.
+ lib64/opencollada lib/opencollada
+ )
+ MARK_AS_ADVANCED(OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY)
+ LIST(APPEND _opencollada_LIBRARIES "${OPENCOLLADA_${UPPERCOMPONENT}_LIBRARY}")
+ENDFOREACH()
+
+
+# handle the QUIETLY and REQUIRED arguments and set OPENCOLLADA_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenCOLLADA DEFAULT_MSG
+ _opencollada_LIBRARIES _opencollada_INCLUDES)
+
+
+IF(OPENCOLLADA_FOUND)
+ SET(OPENCOLLADA_LIBRARIES ${_opencollada_LIBRARIES})
+ SET(OPENCOLLADA_INCLUDE_DIRS ${_opencollada_INCLUDES})
+ENDIF(OPENCOLLADA_FOUND)
diff --git a/build_files/cmake/buildinfo.cmake b/build_files/cmake/buildinfo.cmake
index bfc17ae2cfe..e68015e36d3 100644
--- a/build_files/cmake/buildinfo.cmake
+++ b/build_files/cmake/buildinfo.cmake
@@ -27,9 +27,9 @@ endif()
# Write a file with the SVNVERSION define
file(WRITE buildinfo.h.txt
- "#define BUILD_REV ${MY_WC_REVISION}\n"
- "#define BUILD_DATE ${BUILD_DATE}\n"
- "#define BUILD_TIME ${BUILD_TIME}\n"
+ "#define BUILD_REV \"${MY_WC_REVISION}\"\n"
+ "#define BUILD_DATE \"${BUILD_DATE}\"\n"
+ "#define BUILD_TIME \"${BUILD_TIME}\"\n"
)
# Copy the file to the final header only if the version changes
diff --git a/build_files/cmake/config/blender_headless.cmake b/build_files/cmake/config/blender_headless.cmake
new file mode 100644
index 00000000000..bd69eed30dd
--- /dev/null
+++ b/build_files/cmake/config/blender_headless.cmake
@@ -0,0 +1,24 @@
+# headless configuration, useful in for servers or renderfarms
+# builds without a windowing system (X11/Windows/Cocoa).
+#
+# Example usage:
+# cmake -C../blender/build_files/cmake/config/blender_headless.cmake ../blender
+#
+
+set(WITH_HEADLESS ON CACHE FORCE BOOL)
+set(WITH_GAMEENGINE OFF CACHE FORCE BOOL)
+
+# disable audio, its possible some devs may want this but for now disable
+# so the python module doesnt hold the audio device and loads quickly.
+set(WITH_AUDASPACE OFF CACHE FORCE BOOL)
+set(WITH_SAMPLERATE OFF CACHE FORCE BOOL)
+set(WITH_FFTW3 OFF CACHE FORCE BOOL)
+set(WITH_JACK OFF CACHE FORCE BOOL)
+set(WITH_SDL OFF CACHE FORCE BOOL)
+set(WITH_OPENAL OFF CACHE FORCE BOOL)
+set(WITH_CODEC_FFMPEG OFF CACHE FORCE BOOL)
+set(WITH_CODEC_SNDFILE OFF CACHE FORCE BOOL)
+
+# other features which are not especially useful as a python module
+set(WITH_X11_XINPUT OFF CACHE FORCE BOOL)
+set(WITH_INPUT_NDOF OFF CACHE FORCE BOOL)
diff --git a/build_files/cmake/config/blender_lite.cmake b/build_files/cmake/config/blender_lite.cmake
new file mode 100644
index 00000000000..f09a8058f14
--- /dev/null
+++ b/build_files/cmake/config/blender_lite.cmake
@@ -0,0 +1,43 @@
+# turn everything OFF except for python which defaults to ON
+# and is needed for the UI
+#
+# Example usage:
+# cmake -C../blender/build_files/cmake/config/blender_lite.cmake ../blender
+#
+
+set(WITH_INSTALL_PORTABLE ON CACHE FORCE BOOL)
+
+set(WITH_BUILDINFO OFF CACHE FORCE BOOL)
+set(WITH_BUILTIN_GLEW OFF CACHE FORCE BOOL)
+set(WITH_BULLET OFF CACHE FORCE BOOL)
+set(WITH_CODEC_FFMPEG OFF CACHE FORCE BOOL)
+set(WITH_CODEC_SNDFILE OFF CACHE FORCE BOOL)
+set(WITH_FFTW3 OFF CACHE FORCE BOOL)
+set(WITH_GAMEENGINE OFF CACHE FORCE BOOL)
+set(WITH_IK_ITASC OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_CINEON OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_DDS OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_FRAMESERVER OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_HDR OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_OPENEXR OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_OPENJPEG OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_REDCODE OFF CACHE FORCE BOOL)
+set(WITH_IMAGE_TIFF OFF CACHE FORCE BOOL)
+set(WITH_INPUT_NDOF OFF CACHE FORCE BOOL)
+set(WITH_INTERNATIONAL OFF CACHE FORCE BOOL)
+set(WITH_JACK OFF CACHE FORCE BOOL)
+set(WITH_LZMA OFF CACHE FORCE BOOL)
+set(WITH_LZO OFF CACHE FORCE BOOL)
+set(WITH_MOD_BOOLEAN OFF CACHE FORCE BOOL)
+set(WITH_MOD_DECIMATE OFF CACHE FORCE BOOL)
+set(WITH_MOD_FLUID OFF CACHE FORCE BOOL)
+set(WITH_MOD_SMOKE OFF CACHE FORCE BOOL)
+set(WITH_AUDASPACE OFF CACHE FORCE BOOL)
+set(WITH_OPENAL OFF CACHE FORCE BOOL)
+set(WITH_OPENCOLLADA OFF CACHE FORCE BOOL)
+set(WITH_OPENMP OFF CACHE FORCE BOOL)
+set(WITH_PYTHON_INSTALL OFF CACHE FORCE BOOL)
+set(WITH_RAYOPTIMIZATION OFF CACHE FORCE BOOL)
+set(WITH_SAMPLERATE OFF CACHE FORCE BOOL)
+set(WITH_SDL OFF CACHE FORCE BOOL)
+set(WITH_X11_XINPUT OFF CACHE FORCE BOOL)
diff --git a/build_files/cmake/config/bpy_module.cmake b/build_files/cmake/config/bpy_module.cmake
new file mode 100644
index 00000000000..5392705f0dc
--- /dev/null
+++ b/build_files/cmake/config/bpy_module.cmake
@@ -0,0 +1,34 @@
+# defaults for building blender as a python module 'bpy'
+#
+# Example usage:
+# cmake -C../blender/build_files/cmake/config/bpy_module.cmake ../blender
+#
+
+set(WITH_PYTHON_MODULE ON CACHE FORCE BOOL)
+
+# install into the systems python dir
+set(WITH_INSTALL_PORTABLE OFF CACHE FORCE BOOL)
+
+# no point int copying python into python
+set(WITH_PYTHON_INSTALL OFF CACHE FORCE BOOL)
+
+# dont build the game engine
+set(WITH_GAMEENGINE OFF CACHE FORCE BOOL)
+
+# disable audio, its possible some devs may want this but for now disable
+# so the python module doesnt hold the audio device and loads quickly.
+set(WITH_AUDASPACE OFF CACHE FORCE BOOL)
+set(WITH_SAMPLERATE OFF CACHE FORCE BOOL)
+set(WITH_FFTW3 OFF CACHE FORCE BOOL)
+set(WITH_JACK OFF CACHE FORCE BOOL)
+set(WITH_SDL OFF CACHE FORCE BOOL)
+set(WITH_OPENAL OFF CACHE FORCE BOOL)
+set(WITH_CODEC_FFMPEG OFF CACHE FORCE BOOL)
+set(WITH_CODEC_SNDFILE OFF CACHE FORCE BOOL)
+
+# other features which are not especially useful as a python module
+set(WITH_X11_XINPUT OFF CACHE FORCE BOOL)
+set(WITH_INPUT_NDOF OFF CACHE FORCE BOOL)
+set(WITH_OPENCOLLADA OFF CACHE FORCE BOOL)
+set(WITH_INTERNATIONAL OFF CACHE FORCE BOOL)
+set(WITH_BULLET OFF CACHE FORCE BOOL)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 27694bcb875..58938c8b0b0 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -145,11 +145,6 @@ endmacro()
macro(SETUP_LIBDIRS)
- # see "cmake --help-policy CMP0003"
- if(COMMAND cmake_policy)
- cmake_policy(SET CMP0003 NEW)
- endif()
-
link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
diff --git a/build_files/cmake/packaging.cmake b/build_files/cmake/packaging.cmake
index 6cda62b487f..c0124fe8199 100644
--- a/build_files/cmake/packaging.cmake
+++ b/build_files/cmake/packaging.cmake
@@ -43,7 +43,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
set(CPACK_PACKAGE_RELOCATABLE "false")
set(CPACK_RPM_PACKAGE_LICENSE "GPLv2")
- set(CPACK_RPM_PACKAGE_GROUP "Amusements/Graphics")
+ set(CPACK_RPM_PACKAGE_GROUP "Amusements/Multimedia")
set(CPACK_RPM_USER_BINARY_SPECFILE "${CMAKE_SOURCE_DIR}/build_files/package_spec/rpm/blender.spec.in")
endif()
endif()
@@ -75,14 +75,14 @@ endmacro()
if(APPLE)
add_package_archive(
- "blender-${BLENDER_VERSION}-r${BUILD_REV}-OSX-${CMAKE_OSX_ARCHITECTURES}"
+ "${PROJECT_NAME}-${BLENDER_VERSION}-r${BUILD_REV}-OSX-${CMAKE_OSX_ARCHITECTURES}"
"zip")
elseif(UNIX)
# platform name could be tweaked, to include glibc, and ensure processor is correct (i386 vs i686)
string(TOLOWER ${CMAKE_SYSTEM_NAME} PACKAGE_SYSTEM_NAME)
add_package_archive(
- "blender-${BLENDER_VERSION}-r${BUILD_REV}-${PACKAGE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}"
+ "${PROJECT_NAME}-${BLENDER_VERSION}-r${BUILD_REV}-${PACKAGE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}"
"tar.bz2")
endif()
diff --git a/build_files/package_spec/rpm/blender.spec.in b/build_files/package_spec/rpm/blender.spec.in
index 502e9f36251..25ad5344721 100644
--- a/build_files/package_spec/rpm/blender.spec.in
+++ b/build_files/package_spec/rpm/blender.spec.in
@@ -9,6 +9,7 @@ Release: @CPACK_RPM_PACKAGE_RELEASE@%{?dist}
License: @CPACK_RPM_PACKAGE_LICENSE@
Group: @CPACK_RPM_PACKAGE_GROUP@
Vendor: @CPACK_RPM_PACKAGE_VENDOR@
+Epoch: 1
%define _rpmdir @CPACK_RPM_DIRECTORY@
%define _rpmfilename @CPACK_RPM_FILE_NAME@
diff --git a/build_files/scons/config/darwin-config.py b/build_files/scons/config/darwin-config.py
index 29695896921..102ec73a4e3 100644
--- a/build_files/scons/config/darwin-config.py
+++ b/build_files/scons/config/darwin-config.py
@@ -14,7 +14,7 @@ USE_SDK=True
################### Cocoa & architecture settings ##################
#############################################################################
WITH_GHOST_COCOA=True
-MACOSX_ARCHITECTURE = 'i386' # valid archs: ppc, i386, ppc64, x86_64
+MACOSX_ARCHITECTURE = 'x86_64' # valid archs: ppc, i386, ppc64, x86_64
cmd = 'uname -p'
@@ -104,14 +104,26 @@ BF_FFMPEG_LIBPATH='${BF_FFMPEG}/lib'
BF_FFMPEG_LIB = 'avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg bz2'
#bz2 is a standard osx dynlib
-# python 3.1 uses precompiled libraries in bf svn /lib by default
BF_PYTHON_VERSION = '3.2'
-BF_PYTHON = LIBDIR + '/python'
-BF_PYTHON_INC = '${BF_PYTHON}/include/python${BF_PYTHON_VERSION}'
-# BF_PYTHON_BINARY = '${BF_PYTHON}/bin/python${BF_PYTHON_VERSION}'
-BF_PYTHON_LIB = 'python${BF_PYTHON_VERSION}'
-BF_PYTHON_LIBPATH = '${BF_PYTHON}/lib/python${BF_PYTHON_VERSION}'
-# BF_PYTHON_LINKFLAGS = ['-u', '_PyMac_Error', '-framework', 'System']
+WITH_OSX_STATICPYTHON = True
+
+if WITH_OSX_STATICPYTHON:
+ # python 3.2 uses precompiled libraries in bf svn /lib by default
+
+ BF_PYTHON = LIBDIR + '/python'
+ BF_PYTHON_INC = '${BF_PYTHON}/include/python${BF_PYTHON_VERSION}'
+ # BF_PYTHON_BINARY = '${BF_PYTHON}/bin/python${BF_PYTHON_VERSION}'
+ BF_PYTHON_LIB = 'python${BF_PYTHON_VERSION}'
+ BF_PYTHON_LIBPATH = '${BF_PYTHON}/lib/python${BF_PYTHON_VERSION}'
+ # BF_PYTHON_LINKFLAGS = ['-u', '_PyMac_Error', '-framework', 'System']
+else:
+ # python 3.2 uses Python-framework additionally installed in /Library/Frameworks
+
+ BF_PYTHON = '/Library/Frameworks/Python.framework/Versions/'
+ BF_PYTHON_INC = '${BF_PYTHON}${BF_PYTHON_VERSION}/include/python${BF_PYTHON_VERSION}m'
+ BF_PYTHON_BINARY = '${BF_PYTHON}${BF_PYTHON_VERSION}/bin/python${BF_PYTHON_VERSION}'
+ #BF_PYTHON_LIB = ''
+ BF_PYTHON_LIBPATH = '${BF_PYTHON}${BF_PYTHON_VERSION}/lib/python${BF_PYTHON_VERSION}/config-3.2m'
WITH_BF_OPENAL = True
#different lib must be used following version of gcc
@@ -284,7 +296,7 @@ if MACOSX_ARCHITECTURE == 'i386':
elif MACOSX_ARCHITECTURE == 'x86_64':
BF_RAYOPTIMIZATION_SSE_FLAGS = ['-msse','-msse2']
-# SpaceNavigator and related 3D mice
+# SpaceNavigator and related 3D mice, driver must be 3DxWare 10 Beta 4 (Mac OS X) or later !
WITH_BF_3DMOUSE = True
#############################################################################
@@ -315,11 +327,16 @@ if WITH_BF_QUICKTIME:
else:
PLATFORM_LINKFLAGS = PLATFORM_LINKFLAGS+['-framework','QuickTime']
-if FOUND_NDOF_DRIVERS:
- PLATFORM_LINKFLAGS = PLATFORM_LINKFLAGS + ['-weak_framework','3DconnexionClient']
+if not WITH_OSX_STATICPYTHON:
+ PLATFORM_LINKFLAGS = PLATFORM_LINKFLAGS+['-framework','Python']
+
#note to build succesfully on 10.3.9 SDK you need to patch 10.3.9 by adding the SystemStubs.a lib from 10.4
-LLIBS = ['stdc++', 'SystemStubs']
+#for 10.7.sdk, SystemStubs needs to be excluded (lib doesn't exist anymore)
+if MACOSX_DEPLOYMENT_TARGET == '10.7':
+ LLIBS = ['stdc++']
+else:
+ LLIBS = ['stdc++', 'SystemStubs']
# some flags shuffling for different OS versions
if MAC_MIN_VERS == '10.3':
diff --git a/build_files/scons/config/linux2-config.py b/build_files/scons/config/linux-config.py
similarity index 98%
rename from build_files/scons/config/linux2-config.py
rename to build_files/scons/config/linux-config.py
index d8e227cfb21..c6613ec0ac1 100644
--- a/build_files/scons/config/linux2-config.py
+++ b/build_files/scons/config/linux-config.py
@@ -1,4 +1,4 @@
-LCGDIR = '../lib/linux2'
+LCGDIR = '../lib/linux'
LIBDIR = "${LCGDIR}"
BF_PYTHON_ABI_FLAGS = 'm' # Most common for linux distros
@@ -241,8 +241,8 @@ BF_PROFILE_LINKFLAGS = ['-pg']
BF_DEBUG = False
BF_DEBUG_CCFLAGS = ['-g', '-D_DEBUG']
-BF_BUILDDIR = '../build/linux2'
-BF_INSTALLDIR='../install/linux2'
+BF_BUILDDIR = '../build/linux'
+BF_INSTALLDIR='../install/linux'
#Link against pthread
PLATFORM_LINKFLAGS = ['-pthread']
diff --git a/build_files/scons/config/linuxcross-config.py b/build_files/scons/config/linuxcross-config.py
index 62474527825..1bdf735f458 100644
--- a/build_files/scons/config/linuxcross-config.py
+++ b/build_files/scons/config/linuxcross-config.py
@@ -126,9 +126,10 @@ WITH_BF_BINRELOC = False
# enable ffmpeg support
WITH_BF_FFMPEG = True # -DWITH_FFMPEG
BF_FFMPEG = LIBDIR + '/ffmpeg'
-BF_FFMPEG_LIB = 'avformat-52 avcodec-52 avdevice-52 avutil-50 swscale-0'
+BF_FFMPEG_LIB = 'avformat-53 avcodec-53 avdevice-53 avutil-51 swscale-2'
BF_FFMPEG_INC = '${BF_FFMPEG}/include'
BF_FFMPEG_LIBPATH = '${BF_FFMPEG}/lib'
+BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-53.dll ${BF_FFMPEG_LIBPATH}/avcodec-53.dll ${BF_FFMPEG_LIBPATH}/avdevice-53.dll ${BF_FFMPEG_LIBPATH}/avutil-51.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll'
WITH_BF_OPENJPEG = True
BF_OPENJPEG = '#extern/libopenjpeg'
diff --git a/build_files/scons/config/win32-mingw-config.py b/build_files/scons/config/win32-mingw-config.py
index 6dac29b37f7..c815b76ef73 100644
--- a/build_files/scons/config/win32-mingw-config.py
+++ b/build_files/scons/config/win32-mingw-config.py
@@ -18,9 +18,10 @@ BF_OPENAL_LIB = 'wrap_oal'
BF_OPENAL_LIBPATH = '${BF_OPENAL}/lib'
WITH_BF_FFMPEG = False
-BF_FFMPEG_LIB = 'avformat-52 avcodec-52 avdevice-52 avutil-50 swscale-0'
+BF_FFMPEG_LIB = 'avformat-53 avcodec-53 avdevice-53 avutil-51 swscale-2'
BF_FFMPEG_LIBPATH = LIBDIR + '/ffmpeg/lib'
BF_FFMPEG_INC = LIBDIR + '/ffmpeg/include'
+BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-53.dll ${BF_FFMPEG_LIBPATH}/avcodec-53.dll ${BF_FFMPEG_LIBPATH}/avdevice-53.dll ${BF_FFMPEG_LIBPATH}/avutil-51.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll'
BF_LIBSAMPLERATE = LIBDIR + '/samplerate'
BF_LIBSAMPLERATE_INC = '${BF_LIBSAMPLERATE}/include'
diff --git a/build_files/scons/config/win32-vc-config.py b/build_files/scons/config/win32-vc-config.py
index 4baada7f9bf..2950ca9380f 100644
--- a/build_files/scons/config/win32-vc-config.py
+++ b/build_files/scons/config/win32-vc-config.py
@@ -6,8 +6,8 @@ WITH_BF_FFMPEG = True # -DWITH_FFMPEG
BF_FFMPEG = LIBDIR +'/ffmpeg'
BF_FFMPEG_INC = '${BF_FFMPEG}/include ${BF_FFMPEG}/include/msvc'
BF_FFMPEG_LIBPATH='${BF_FFMPEG}/lib'
-BF_FFMPEG_LIB = 'avformat-52.lib avcodec-52.lib avdevice-52.lib avutil-50.lib swscale-0.lib'
-BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-52.dll ${BF_FFMPEG_LIBPATH}/avcodec-52.dll ${BF_FFMPEG_LIBPATH}/avdevice-52.dll ${BF_FFMPEG_LIBPATH}/avutil-50.dll ${BF_FFMPEG_LIBPATH}/swscale-0.dll'
+BF_FFMPEG_LIB = 'avformat-53.lib avcodec-53.lib avdevice-53.lib avutil-51.lib swscale-2.lib'
+BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-53.dll ${BF_FFMPEG_LIBPATH}/avcodec-53.dll ${BF_FFMPEG_LIBPATH}/avdevice-53.dll ${BF_FFMPEG_LIBPATH}/avutil-51.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll'
BF_PYTHON = LIBDIR + '/python'
BF_PYTHON_VERSION = '3.2'
@@ -40,7 +40,7 @@ BF_JACK_INC = '${BF_JACK}/include ${BF_FFMPEG}/include/msvc'
BF_JACK_LIB = 'libjack'
BF_JACK_LIBPATH = '${BF_JACK}/lib'
-WITH_BF_SNDFILE = False
+WITH_BF_SNDFILE = True
BF_SNDFILE = LIBDIR + '/sndfile'
BF_SNDFILE_INC = '${BF_SNDFILE}/include'
BF_SNDFILE_LIB = 'libsndfile-1'
diff --git a/build_files/scons/config/win64-vc-config.py b/build_files/scons/config/win64-vc-config.py
index db7c8d09af8..ba9633a6b4c 100644
--- a/build_files/scons/config/win64-vc-config.py
+++ b/build_files/scons/config/win64-vc-config.py
@@ -6,8 +6,8 @@ WITH_BF_FFMPEG = True # -DWITH_FFMPEG
BF_FFMPEG = LIBDIR +'/ffmpeg'
BF_FFMPEG_INC = '${BF_FFMPEG}/include ${BF_FFMPEG}/include/msvc '
BF_FFMPEG_LIBPATH='${BF_FFMPEG}/lib'
-BF_FFMPEG_LIB = 'avformat-52.lib avcodec-52.lib avdevice-52.lib avutil-50.lib swscale-0.lib'
-BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-52.dll ${BF_FFMPEG_LIBPATH}/avcodec-52.dll ${BF_FFMPEG_LIBPATH}/avdevice-52.dll ${BF_FFMPEG_LIBPATH}/avutil-50.dll ${BF_FFMPEG_LIBPATH}/swscale-0.dll'
+BF_FFMPEG_LIB = 'avformat-53.lib avcodec-53.lib avdevice-53.lib avutil-51.lib swscale-2.lib'
+BF_FFMPEG_DLL = '${BF_FFMPEG_LIBPATH}/avformat-53.dll ${BF_FFMPEG_LIBPATH}/avcodec-53.dll ${BF_FFMPEG_LIBPATH}/avdevice-53.dll ${BF_FFMPEG_LIBPATH}/avutil-51.dll ${BF_FFMPEG_LIBPATH}/swscale-2.dll'
BF_PYTHON = LIBDIR + '/python'
BF_PYTHON_VERSION = '3.2'
diff --git a/build_files/scons/tools/Blender.py b/build_files/scons/tools/Blender.py
index 6fae2785192..c537e435de8 100644
--- a/build_files/scons/tools/Blender.py
+++ b/build_files/scons/tools/Blender.py
@@ -206,7 +206,7 @@ def setup_staticlibs(lenv):
if lenv['WITH_BF_STATICJEMALLOC']:
statlibs += Split(lenv['BF_JEMALLOC_LIB_STATIC'])
- if lenv['OURPLATFORM']=='linux2':
+ if lenv['OURPLATFORM']=='linux':
if lenv['WITH_BF_3DMOUSE']:
libincs += Split(lenv['BF_3DMOUSE_LIBPATH'])
if lenv['WITH_BF_STATIC3DMOUSE']:
@@ -277,7 +277,7 @@ def setup_syslibs(lenv):
if not lenv['WITH_BF_STATICJEMALLOC']:
syslibs += Split(lenv['BF_JEMALLOC_LIB'])
- if lenv['OURPLATFORM']=='linux2':
+ if lenv['OURPLATFORM']=='linux':
if lenv['WITH_BF_3DMOUSE']:
if not lenv['WITH_BF_STATIC3DMOUSE']:
syslibs += Split(lenv['BF_3DMOUSE_LIB'])
@@ -364,16 +364,16 @@ def buildinfo(lenv, build_type):
obj = []
if lenv['BF_BUILDINFO']:
- lenv.Append (CPPDEFINES = ['BUILD_TIME="%s"'%(build_time),
- 'BUILD_DATE="%s"'%(build_date),
- 'BUILD_TYPE="%s"'%(build_type),
- 'BUILD_REV="%s"'%(build_rev),
- 'NAN_BUILDINFO',
- 'BUILD_PLATFORM="%s:%s"'%(platform.system(), platform.architecture()[0]),
+ lenv.Append (CPPDEFINES = ['BUILD_TIME=\\"%s\\"'%(build_time),
+ 'BUILD_DATE=\\"%s\\"'%(build_date),
+ 'BUILD_TYPE=\\"%s\\"'%(build_type),
+ 'BUILD_REV=\\"%s\\"'%(build_rev),
+ 'WITH_BUILDINFO',
+ 'BUILD_PLATFORM=\\"%s:%s\\"'%(platform.system(), platform.architecture()[0]),
'BUILD_CFLAGS=\\"%s\\"'%(build_cflags),
'BUILD_CXXFLAGS=\\"%s\\"'%(build_cxxflags),
'BUILD_LINKFLAGS=\\"%s\\"'%(build_linkflags),
- 'BUILD_SYSTEM="SCons"'
+ 'BUILD_SYSTEM=\\"SCons\\"'
])
lenv.Append (CPPPATH = [root_build_dir+'source/blender/blenkernel'])
@@ -536,7 +536,10 @@ def AppIt(target=None, source=None, env=None):
print("Installing to %s"%(installdir))
# TODO, use tar.
python_zip = 'python_' + osxarch + '.zip' # set specific python_arch.zip
- print("unzipping to app-bundle: %s"%(python_zip))
+ if env['WITH_OSX_STATICPYTHON']:
+ print("unzipping to app-bundle: %s"%(python_zip))
+ else:
+ print("dynamic build - make sure to have python3.x-framework installed")
bldroot = env.Dir('.').abspath
binary = env['BINARYKIND']
@@ -569,10 +572,11 @@ def AppIt(target=None, source=None, env=None):
commands.getoutput(cmd)
cmd = 'cp %s/release/bin/%s/.Blanguages %s/%s.app/Contents/Resources/'%(bldroot,VERSION,installdir,binary)
commands.getoutput(cmd)
- cmd = 'mkdir %s/%s.app/Contents/MacOS/%s/python/'%(installdir,binary, VERSION)
- commands.getoutput(cmd)
- cmd = 'unzip -q %s/release/%s -d %s/%s.app/Contents/MacOS/%s/python/'%(libdir,python_zip,installdir,binary,VERSION)
- commands.getoutput(cmd)
+ if env['WITH_OSX_STATICPYTHON']:
+ cmd = 'mkdir %s/%s.app/Contents/MacOS/%s/python/'%(installdir,binary, VERSION)
+ commands.getoutput(cmd)
+ cmd = 'unzip -q %s/release/%s -d %s/%s.app/Contents/MacOS/%s/python/'%(libdir,python_zip,installdir,binary,VERSION)
+ commands.getoutput(cmd)
if binary == 'blender':#not copy everything for blenderplayer
cmd = 'cp -R %s/release/scripts %s/%s.app/Contents/MacOS/%s/'%(bldroot,installdir,binary,VERSION)
@@ -775,7 +779,7 @@ class BlenderEnvironment(SConsEnvironment):
if lenv['OURPLATFORM'] in ('win32-vc', 'cygwin', 'win64-vc'):
if lenv['BF_DEBUG']:
lenv.Prepend(LINKFLAGS = ['/DEBUG','/PDB:'+progname+'.pdb','/NODEFAULTLIB:libcmt'])
- if lenv['OURPLATFORM']=='linux2':
+ if lenv['OURPLATFORM']=='linux':
if lenv['WITH_BF_PYTHON']:
lenv.Append(LINKFLAGS = lenv['BF_PYTHON_LINKFLAGS'])
if lenv['OURPLATFORM']=='sunos5':
diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py
index aac16555df9..be059241727 100644
--- a/build_files/scons/tools/btools.py
+++ b/build_files/scons/tools/btools.py
@@ -78,7 +78,7 @@ def print_arguments(args, bc):
def validate_arguments(args, bc):
opts_list = [
- 'WITH_BF_PYTHON', 'WITH_BF_PYTHON_SAFETY', 'BF_PYTHON', 'BF_PYTHON_VERSION', 'BF_PYTHON_INC', 'BF_PYTHON_BINARY', 'BF_PYTHON_LIB', 'BF_PYTHON_LIBPATH', 'WITH_BF_STATICPYTHON', 'BF_PYTHON_LIB_STATIC', 'BF_PYTHON_DLL', 'BF_PYTHON_ABI_FLAGS',
+ 'WITH_BF_PYTHON', 'WITH_BF_PYTHON_SAFETY', 'BF_PYTHON', 'BF_PYTHON_VERSION', 'BF_PYTHON_INC', 'BF_PYTHON_BINARY', 'BF_PYTHON_LIB', 'BF_PYTHON_LIBPATH', 'WITH_BF_STATICPYTHON', 'WITH_OSX_STATICPYTHON', 'BF_PYTHON_LIB_STATIC', 'BF_PYTHON_DLL', 'BF_PYTHON_ABI_FLAGS',
'WITH_BF_OPENAL', 'BF_OPENAL', 'BF_OPENAL_INC', 'BF_OPENAL_LIB', 'BF_OPENAL_LIBPATH', 'WITH_BF_STATICOPENAL', 'BF_OPENAL_LIB_STATIC',
'WITH_BF_SDL', 'BF_SDL', 'BF_SDL_INC', 'BF_SDL_LIB', 'BF_SDL_LIBPATH',
'BF_LIBSAMPLERATE', 'BF_LIBSAMPLERATE_INC', 'BF_LIBSAMPLERATE_LIB', 'BF_LIBSAMPLERATE_LIBPATH', 'WITH_BF_STATICLIBSAMPLERATE', 'BF_LIBSAMPLERATE_LIB_STATIC',
@@ -136,7 +136,7 @@ def validate_arguments(args, bc):
'BF_NO_ELBEEM',
'WITH_BF_CXX_GUARDEDALLOC',
'WITH_BF_JEMALLOC', 'WITH_BF_STATICJEMALLOC', 'BF_JEMALLOC', 'BF_JEMALLOC_INC', 'BF_JEMALLOC_LIBPATH', 'BF_JEMALLOC_LIB', 'BF_JEMALLOC_LIB_STATIC',
- 'BUILDBOT_BRANCH', 'WITH_BF_3DMOUSE', 'FOUND_NDOF_DRIVERS', 'WITH_BF_STATIC3DMOUSE', 'BF_3DMOUSE', 'BF_3DMOUSE_INC', 'BF_3DMOUSE_LIB', 'BF_3DMOUSE_LIBPATH', 'BF_3DMOUSE_LIB_STATIC'
+ 'BUILDBOT_BRANCH', 'WITH_BF_3DMOUSE', 'WITH_BF_STATIC3DMOUSE', 'BF_3DMOUSE', 'BF_3DMOUSE_INC', 'BF_3DMOUSE_LIB', 'BF_3DMOUSE_LIBPATH', 'BF_3DMOUSE_LIB_STATIC'
]
# Have options here that scons expects to be lists
@@ -230,6 +230,7 @@ def read_opts(env, cfg, args):
('BF_PYTHON_LIBPATH', 'Library path', ''),
('BF_PYTHON_LINKFLAGS', 'Python link flags', ''),
(BoolVariable('WITH_BF_STATICPYTHON', 'Staticly link to python', False)),
+ (BoolVariable('WITH_OSX_STATICPYTHON', 'Staticly link to python', True)),
('BF_PYTHON_ABI_FLAGS', 'Python ABI flags (suffix in library version: m, mu, etc)', ''),
(BoolVariable('BF_NO_ELBEEM', 'Disable Fluid Sim', False)),
@@ -439,7 +440,6 @@ def read_opts(env, cfg, args):
(BoolVariable('WITH_BF_NOBLENDER', 'Do not build blender if true', False)),
(BoolVariable('WITH_BF_3DMOUSE', 'Build blender with support of 3D mouses', False)),
- (BoolVariable('FOUND_NDOF_DRIVERS', 'We detected NDOF libs or framework', False)),
(BoolVariable('WITH_BF_STATIC3DMOUSE', 'Staticly link to 3d mouse library', False)),
('BF_3DMOUSE', '3d mouse library base path', ''),
('BF_3DMOUSE_INC', '3d mouse library include path', ''),
@@ -569,7 +569,7 @@ def buildslave(target=None, source=None, env=None):
extension = '.tar.bz2'
platform = env['OURPLATFORM'].split('-')[0]
- if platform == 'linux2':
+ if platform == 'linux':
import platform
bitness = platform.architecture()[0]
diff --git a/doc/build_systems/scons-dev.txt b/doc/build_systems/scons-dev.txt
index d13ea7c036f..ca1b3924804 100644
--- a/doc/build_systems/scons-dev.txt
+++ b/doc/build_systems/scons-dev.txt
@@ -27,7 +27,7 @@ $Id$
filenames have the form (platform)-config.py, where platform one of:
* darwin
- * linux2
+ * linux
* win32-mingw
* win32-vc
diff --git a/doc/build_systems/scons.txt b/doc/build_systems/scons.txt
index b4d9a905885..9d018bcc790 100644
--- a/doc/build_systems/scons.txt
+++ b/doc/build_systems/scons.txt
@@ -76,7 +76,7 @@ $Id$
$BLENDERHOME/config. Your platform specific defaults are in
(platform)-config.py, where platform is one of:
- - linux2, for machines running Linux
+ - linux, for machines running Linux
- win32-vc, for Windows machines, compiling with a Microsoft compiler
- win32-mingw, for Windows machines, compiling with the MingW compiler
- darwin, for OS X machines
diff --git a/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py b/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
index 42e2a71cc70..5e7022c88b4 100644
--- a/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
+++ b/doc/python_api/examples/bpy.types.BlendDataLibraries.load.py
@@ -23,11 +23,6 @@ with bpy.data.libraries.load(filepath) as (data_from, data_to):
setattr(data_to, attr, getattr(data_from, attr))
-# the 'data_to' variables lists are
-with bpy.data.libraries.load(filepath) as (data_from, data_to):
- data_to.scenes = ["Scene"]
-
-
# the loaded objects can be accessed from 'data_to' outside of the context
# since loading the data replaces the strings for the datablocks or None
# if the datablock could not be loaded.
diff --git a/doc/python_api/examples/bpy.types.ID.user_clear.1.py b/doc/python_api/examples/bpy.types.ID.user_clear.1.py
new file mode 100644
index 00000000000..68c35caa7d4
--- /dev/null
+++ b/doc/python_api/examples/bpy.types.ID.user_clear.1.py
@@ -0,0 +1,19 @@
+"""
+User Clear
+++++++++++
+This function is for advanced use only, misuse can crash blender since the user
+count is used to prevent data being removed when it is used.
+"""
+
+# This example shows what _not_ to do, and will crash blender.
+import bpy
+
+# object which is in the scene.
+obj = bpy.data.objects["Cube"]
+
+# without this, removal would raise an error.
+obj.user_clear()
+
+# runs without an exception
+# but will crash on redraw.
+bpy.data.objects.remove(obj)
diff --git a/doc/python_api/rst/bge.render.rst b/doc/python_api/rst/bge.render.rst
index 10514049a8a..eeb50a833ff 100644
--- a/doc/python_api/rst/bge.render.rst
+++ b/doc/python_api/rst/bge.render.rst
@@ -215,7 +215,19 @@ Functions
:type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
:rtype: boolean
+.. function:: setAnisotropicFiltering(level)
+ Set the anisotropic filtering level for textures.
+
+ :arg level: The new anisotropic filtering level to use
+ :type level: integer (must be one of 1, 2, 4, 8, 16)
+
+.. function:: getAnisotropicFiltering()
+
+ Get the anisotropic filtering level used for textures.
+
+ :rtype: integer (one of 1, 2, 4, 8, 16)
+
.. function:: drawLine(fromVec,toVec,color)
Draw a line in the 3D scene.
diff --git a/doc/python_api/rst/bge.types.rst b/doc/python_api/rst/bge.types.rst
index 36ef9154e17..d9a93a945ed 100644
--- a/doc/python_api/rst/bge.types.rst
+++ b/doc/python_api/rst/bge.types.rst
@@ -1539,6 +1539,67 @@ Game Types (bge.types)
Return the value matching key, or the default value if its not found.
:return: The key value or a default.
+ .. method:: playAction(name, start_frame, end_frame, layer=0, priority=0 blendin=0, play_mode=ACT_MODE_PLAY, layer_weight=0.0, ipo_flags=0, speed=1.0)
+
+ Plays an action.
+
+ :arg name: the name of the action
+ :type name: string
+ :arg start: the start frame of the action
+ :type start: float
+ :arg end: the end frame of the action
+ :type end: float
+ :arg layer: the layer the action will play in (actions in different layers are added/blended together)
+ :type layer: integer
+ :arg priority: only play this action if there isn't an action currently playing in this layer with a higher (lower number) priority
+ :type priority: integer
+ :arg blendin: the amount of blending between this animation and the previous one on this layer
+ :type blendin: float
+ :arg play_mode: the play mode
+ :type play_mode: KX_ACTION_MODE_PLAY, KX_ACTION_MODE_LOOP, or KX_ACTION_MODE_PING_PONG
+ :arg layer_weight: how much of the previous layer to use for blending (0 = add)
+ :type layer_weight: float
+ :arg ipo_flags: flags for the old IPO behaviors (force, etc)
+ :type ipo_flags: int bitfield
+ :arg speed: the playback speed of the action as a factor (1.0 = normal speed, 2.0 = 2x speed, etc)
+ :type speed: float
+
+ .. method:: stopAction(layer=0)
+
+ Stop playing the action on the given layer.
+
+ :arg layer: The layer to stop playing.
+ :type layer: integer
+
+ .. method:: getActionFrame(layer=0)
+
+ Gets the current frame of the action playing in the supplied layer.
+
+ :arg layer: The layer that you want to get the frame from.
+ :type layer: integer
+
+ :return: The current frame of the action
+ :rtype: float
+
+ .. method:: setActionFrame(frame, layer=0)
+
+ Set the current frame of the action playing in the supplied layer.
+
+ :arg layer: The layer where you want to set the frame
+ :type layer: integer
+ :arg frame: The frame to set the action to
+ :type frame: float
+
+ .. method:: isPlayingAction(layer=0)
+
+ Checks to see if there is an action playing in the given layer.
+
+ :arg layer: The layer to check for a playing action.
+ :type layer: integer
+
+ :return: Whether or not the action is playing
+ :rtype: boolean
+
.. class:: KX_IpoActuator(SCA_IActuator)
IPO actuator activates an animation.
diff --git a/doc/python_api/rst/info_gotcha.rst b/doc/python_api/rst/info_gotcha.rst
new file mode 100644
index 00000000000..c97fc3ab427
--- /dev/null
+++ b/doc/python_api/rst/info_gotcha.rst
@@ -0,0 +1,405 @@
+********
+Gotcha's
+********
+
+This document attempts to help you work with the Blender API in areas that can be troublesome and avoid practices that are known to give instability.
+
+
+Using Operators
+===============
+
+Blender's operators are tools for users to access, that python can access them too is very useful nevertheless operators have limitations that can make them cumbersome to script.
+
+Main limits are...
+
+* Can't pass data such as objects, meshes or materials to operate on (operators use the context instead)
+
+* The return value from calling an operator gives the success (if it finished or was canceled),
+ in some cases it would be more logical from an API perspective to return the result of the operation.
+
+* Operators poll function can fail where an API function would raise an exception giving details on exactly why.
+
+
+Why does an operator's poll fail?
+---------------------------------
+
+When calling an operator gives an error like this:
+
+ >>> bpy.ops.action.clean(threshold=0.001)
+ RuntimeError: Operator bpy.ops.action.clean.poll() failed, context is incorrect
+
+Which raises the question as to what the correct context might be?
+
+Typically operators check for the active area type, a selection or active object they can operate on, but some operators are more picky about when they run.
+
+In most cases you can figure out what context an operator needs simply be seeing how its used in Blender and thinking about what it does.
+
+
+Unfortunately if you're still stuck - the only way to **really** know whats going on is to read the source code for the poll function and see what its checking.
+
+For python operators its not so hard to find the source since its included with with Blender and the source file/line is included in the operator reference docs.
+
+Downloading and searching the C code isn't so simple, especially if you're not familiar with the C language but by searching the operator name or description you should be able to find the poll function with no knowledge of C.
+
+.. note::
+
+ Blender does have the functionality for poll functions to describe why they fail, but its currently not used much, if you're interested to help improve our API feel free to add calls to ``CTX_wm_operator_poll_msg_set`` where its not obvious why poll fails.
+
+ >>> bpy.ops.gpencil.draw()
+ RuntimeError: Operator bpy.ops.gpencil.draw.poll() Failed to find Grease Pencil data to draw into
+
+
+The operator still doesn't work!
+--------------------------------
+
+Certain operators in Blender are only intended for use in a specific context, some operators for example are only called from the properties window where they check the current material, modifier or constraint.
+
+Examples of this are:
+
+* :mod:`bpy.ops.texture.slot_move`
+* :mod:`bpy.ops.constraint.limitdistance_reset`
+* :mod:`bpy.ops.object.modifier_copy`
+* :mod:`bpy.ops.buttons.file_browse`
+
+Another possibility is that you are the first person to attempt to use this operator in a script and some modifications need to be made to the operator to run in a different context, if the operator should logically be able to run but fails when accessed from a script it should be reported to the bug tracker.
+
+
+Stale Data
+==========
+
+No updates after setting values
+-------------------------------
+
+Sometimes you want to modify values from python and immediately access the updated values, eg:
+
+Once changing the objects :class:`bpy.types.Object.location` you may want to access its transformation right after from :class:`bpy.types.Object.matrix_world`, but this doesn't work as you might expect.
+
+Consider the calculations that might go into working out the objects final transformation, this includes:
+
+* animation function curves.
+* drivers and their pythons expressions.
+* constraints
+* parent objects and all of their f-curves, constraints etc.
+
+To avoid expensive recalculations every time a property is modified, Blender defers making the actual calculations until they are needed.
+
+However, while the script runs you may want to access the updated values.
+
+This can be done by calling :class:`bpy.types.Scene.update` after modifying values which recalculates all data that is tagged to be updated.
+
+
+Can I redraw during the script?
+-------------------------------
+
+The official answer to this is no, or... *"You don't want to do that"*.
+
+To give some background on the topic...
+
+While a script executes Blender waits for it to finish and is effectively locked until its done, while in this state Blender won't redraw or respond to user input.
+Normally this is not such a problem because scripts distributed with Blender tend not to run for an extended period of time, nevertheless scripts *can* take ages to execute and its nice to see whats going on in the view port.
+
+Tools that lock Blender in a loop and redraw are highly discouraged since they conflict with Blenders ability to run multiple operators at once and update different parts of the interface as the tool runs.
+
+So the solution here is to write a **modal** operator, that is - an operator which defines a modal() function, See the modal operator template in the text editor.
+
+Modal operators execute on user input or setup their own timers to run frequently, they can handle the events or pass through to be handled by the keymap or other modal operators.
+
+Transform, Painting, Fly-Mode and File-Select are example of a modal operators.
+
+Writing modal operators takes more effort then a simple ``for`` loop that happens to redraw but is more flexible and integrates better with Blenders design.
+
+
+**Ok, Ok! I still want to draw from python**
+
+If you insist - yes its possible, but scripts that use this hack wont be considered for inclusion in Blender and any issues with using it wont be considered bugs, this is also not guaranteed to work in future releases.
+
+.. code-block:: python
+
+ bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
+
+
+Matrix multiplication is wrong
+==============================
+
+Every so often users complain that Blenders matrix math is wrong, the confusion comes from mathutils matrices being column-major to match OpenGL and the rest of Blenders matrix operations and stored matrix data.
+
+This is different to **numpy** which is row-major which matches what you would expect when using conventional matrix math notation.
+
+
+I can't edit the mesh in edit-mode!
+===================================
+
+Blenders EditMesh is an internal data structure (not saved and not exposed to python), this gives the main annoyance that you need to exit edit-mode to edit the mesh from python.
+
+The reason we have not made much attempt to fix this yet is because we
+will likely move to BMesh mesh API eventually, so any work on the API now will be wasted effort.
+
+With the BMesh API we may expose mesh data to python so we can
+write useful tools in python which are also fast to execute while in edit-mode.
+
+For the time being this limitation just has to be worked around but we're aware its frustrating needs to be addressed.
+
+
+EditBones, PoseBones, Bone... Bones
+===================================
+
+Armature Bones in Blender have three distinct data structures that contain them. If you are accessing the bones through one of them, you may not have access to the properties you really need.
+
+.. note::
+
+ In the following examples ``bpy.context.object`` is assumed to be an armature object.
+
+
+Edit Bones
+----------
+
+``bpy.context.object.data.edit_bones`` contains a editbones; to access them you must set the armature mode to edit mode first (editbones do not exist in object or pose mode). Use these to create new bones, set their head/tail or roll, change their parenting relationships to other bones, etc.
+
+Example using :class:`bpy.types.EditBone` in armature editmode:
+
+This is only possible in edit mode.
+
+ >>> bpy.context.object.data.edit_bones["Bone"].head = Vector((1.0, 2.0, 3.0))
+
+This will be empty outside of editmode.
+
+ >>> mybones = bpy.context.selected_editable_bones
+
+Returns an editbone only in edit mode.
+
+ >>> bpy.context.active_bone
+
+
+Bones (Object Mode)
+-------------------
+
+``bpy.context.object.data.bones`` contains bones. These *live* in object mode, and have various properties you can change, note that the head and tail properties are read-only.
+
+Example using :class:`bpy.types.Bone` in object or pose mode:
+
+Returns a bone (not an editbone) outside of edit mode
+
+ >>> bpy.context.active_bone
+
+This works, as with blender the setting can be edited in any mode
+
+ >>> bpy.context.object.data.bones["Bone"].use_deform = True
+
+Accessible but read-only
+
+ >>> tail = myobj.data.bones["Bone"].tail
+
+
+Pose Bones
+----------
+
+``bpy.context.object.pose.bones`` contains pose bones. This is where animation data resides, i.e. animatable transformations are applied to pose bones, as are constraints and ik-settings.
+
+Examples using :class:`bpy.types.PoseBone` in object or pose mode:
+
+.. code-block:: python
+
+ # Gets the name of the first constraint (if it exists)
+ bpy.context.object.pose.bones["Bone"].constraints[0].name
+
+ # Gets the last selected pose bone (pose mode only)
+ bpy.context.active_pose_bone
+
+
+.. note::
+
+ Notice the pose is accessed from the object rather than the object data, this is why blender can have 2 or more objects sharing the same armature in different poses.
+
+.. note::
+
+ Strictly speaking PoseBone's are not bones, they are just the state of the armature, stored in the :class:`bpy.types.Object` rather than the :class:`bpy.types.Armature`, the real bones are however accessible from the pose bones - :class:`bpy.types.PoseBone.bone`
+
+
+Armature Mode Switching
+-----------------------
+
+While writing scripts that deal with armatures you may find you have to switch between modes, when doing so take care when switching out of editmode not to keep references to the edit-bones or their head/tail vectors. Further access to these will crash blender so its important the script clearly separates sections of the code which operate in different modes.
+
+This is mainly an issue with editmode since pose data can be manipulated without having to be in pose mode, however for operator access you may still need to enter pose mode.
+
+
+Unicode Problems
+================
+
+Python supports many different encpdings so there is nothing stopping you from writing a script in latin1 or iso-8859-15.
+
+See `pep-0263 `_
+
+However this complicates things for the python api because blend files themselves dont have an encoding.
+
+To simplify the problem for python integration and script authors we have decieded all strings in blend files **must** be UTF-8 or ASCII compatible.
+
+This means assigning strings with different encodings to an object names for instance will raise an error.
+
+Paths are an exception to this rule since we cannot ignore the existane of non-utf-8 paths on peoples filesystems.
+
+This means seemingly harmless expressions can raise errors, eg.
+
+ >>> print(bpy.data.filepath)
+ UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-21: ordinal not in range(128)
+
+ >>> bpy.context.object.name = bpy.data.filepath
+ Traceback (most recent call last):
+ File "", line 1, in
+ TypeError: bpy_struct: item.attr= val: Object.name expected a string type, not str
+
+
+Here are 2 ways around filesystem encoding issues:
+
+ >>> print(repr(bpy.data.filepath))
+
+ >>> import os
+ >>> filepath_bytes = os.fsencode(bpy.data.filepath)
+ >>> filepath_utf8 = filepath_bytes.decode('utf-8', "replace")
+ >>> bpy.context.object.name = filepath_utf8
+
+
+Unicode encoding/decoding is a big topic with comprehensive python documentation, to avoid getting stuck too deep in encoding problems - here are some suggestions:
+
+* Always use utf-8 encoiding or convert to utf-8 where the input is unknown.
+
+* Avoid manipulating filepaths as strings directly, use ``os.path`` functions instead.
+
+* Use ``os.fsencode()`` / ``os.fsdecode()`` rather then the built in string decoding functions when operating on paths.
+
+* To print paths or to include them in the user interface use ``repr(path)`` first or ``"%r" % path`` with string formatting.
+
+* **Possibly** - use bytes instead of python strings, when reading some input its less trouble to read it as binary data though you will still need to deciede how to treat any strings you want to use with Blender, some importers do this.
+
+
+Strange errors using 'threading' module
+=======================================
+
+Python threading with Blender only works properly when the threads finish up before the script does. By using ``threading.join()`` for example.
+
+Heres an example of threading supported by Blender:
+
+.. code-block:: python
+
+ import threading
+ import time
+
+ def prod():
+ print(threading.current_thread().name, "Starting")
+
+ # do something vaguely useful
+ import bpy
+ from mathutils import Vector
+ from random import random
+
+ prod_vec = Vector((random() - 0.5, random() - 0.5, random() - 0.5))
+ print("Prodding", prod_vec)
+ bpy.data.objects["Cube"].location += prod_vec
+ time.sleep(random() + 1.0)
+ # finish
+
+ print(threading.current_thread().name, "Exiting")
+
+ threads = [threading.Thread(name="Prod %d" % i, target=prod) for i in range(10)]
+
+
+ print("Starting threads...")
+
+ for t in threads:
+ t.start()
+
+ print("Waiting for threads to finish...")
+
+ for t in threads:
+ t.join()
+
+
+This an example of a timer which runs many times a second and moves the default cube continuously while Blender runs (Unsupported).
+
+.. code-block:: python
+
+ def func():
+ print("Running...")
+ import bpy
+ bpy.data.objects['Cube'].location.x += 0.05
+
+ def my_timer():
+ from threading import Timer
+ t = Timer(0.1, my_timer)
+ t.start()
+ func()
+
+ my_timer()
+
+Use cases like the one above which leave the thread running once the script finishes may seem to work for a while but end up causing random crashes or errors in Blenders own drawing code.
+
+So far no work has gone into making Blenders python integration thread safe, so until its properly supported, best not make use of this.
+
+.. note::
+
+ Pythons threads only allow co-currency and wont speed up you're scripts on multi-processor systems, the ``subprocess`` and ``multiprocess`` modules can be used with blender and make use of multiple CPU's too.
+
+
+Help! My script crashes Blender
+===============================
+
+Ideally it would be impossible to crash Blender from python however there are some problems with the API where it can be made to crash.
+
+Strictly speaking this is a bug in the API but fixing it would mean adding memory verification on every access since most crashes are caused by the python objects referencing Blenders memory directly, whenever the memory is freed, further python access to it can crash the script. But fixing this would make the scripts run very slow, or writing a very different kind of API which doesn't reference the memory directly.
+
+Here are some general hints to avoid running into these problems.
+
+* Be aware of memory limits, especially when working with large lists since Blender can crash simply by running out of memory.
+
+* Many hard to fix crashes end up being because of referencing freed data, when removing data be sure not to hold any references to it.
+
+* Modules or classes that remain active while Blender is used, should not hold references to data the user may remove, instead, fetch data from the context each time the script is activated.
+
+* Crashes may not happen every time, they may happen more on some configurations/operating-systems.
+
+
+Undo/Redo
+---------
+
+Undo invalidates all :class:`bpy.types.ID` instances (Object, Scene, Mesh etc).
+
+This example shows how you can tell undo changes the memory locations.
+
+ >>> hash(bpy.context.object)
+ -9223372036849950810
+ >>> hash(bpy.context.object)
+ -9223372036849950810
+
+ # ... move the active object, then undo
+
+ >>> hash(bpy.context.object)
+ -9223372036849951740
+
+As suggested above, simply not holding references to data when Blender is used interactively by the user is the only way to ensure the script doesn't become unstable.
+
+
+Array Re-Allocation
+-------------------
+
+When adding new points to a curve or vertices's/edges/faces to a mesh, internally the array which stores this data is re-allocated.
+
+.. code-block:: python
+
+ bpy.ops.curve.primitive_bezier_curve_add()
+ point = bpy.context.object.data.splines[0].bezier_points[0]
+ bpy.context.object.data.splines[0].bezier_points.add()
+
+ # this will crash!
+ point.co = 1.0, 2.0, 3.0
+
+This can be avoided by re-assigning the point variables after adding the new one or by storing indices's to the points rather then the points themselves.
+
+The best way is to sidestep the problem altogether add all the points to the curve at once. This means you don't have to worry about array re-allocation and its faster too since reallocating the entire array for every point added is inefficient.
+
+
+Removing Data
+-------------
+
+**Any** data that you remove shouldn't be modified or accessed afterwards, this includes f-curves, drivers, render layers, timeline markers, modifiers, constraints along with objects, scenes, groups, bones.. etc.
+
+This is a problem in the API at the moment that we should eventually solve.
diff --git a/doc/python_api/rst/info_overview.rst b/doc/python_api/rst/info_overview.rst
new file mode 100644
index 00000000000..fe730088c44
--- /dev/null
+++ b/doc/python_api/rst/info_overview.rst
@@ -0,0 +1,373 @@
+*******************
+Python API Overview
+*******************
+
+This document is to give an understanding of how python and blender fit together, covering some of the functionality that isn't obvious from reading the API reference and example scripts.
+
+
+Python in Blender
+=================
+
+Blender embeds a python interpreter which is started with blender and stays active. This interpreter runs scripts to draw the user interface and is used for some of Blender's internal tools too.
+
+This is a typical python environment so tutorials on how to write python scripts will work running the scripts in blender too. Blender provides the :mod:`bpy` module to the python interpreter. This module can be imported in a script and gives access to blender data, classes, and functions. Scripts that deal with blender data will need to import this module.
+
+Here is a simple example of moving a vertex of the object named **Cube**:
+
+.. code-block:: python
+
+ import bpy
+ bpy.data.objects["Cube"].data.vertices[0].co.x += 1.0
+
+This modifies Blender's internal data directly. When you run this in the interactive console you will see the 3D viewport update.
+
+
+The Default Environment
+=======================
+
+When developing your own scripts it may help to understand how blender sets up its python environment. Many python scripts come bundled with blender and can be used as a reference because they use the same API that script authors write tools in. Typical usage for scripts include: user interface, import/export, scene manipulation, automation, defining your own toolset and customization.
+
+On startup blender scans the ``scripts/startup/`` directory for python modules and imports them. The exact location of this directory depends on your installation. `See the directory layout docs `_
+
+
+Script Loading
+==============
+
+This may seem obvious but it's important to note the difference between executing a script directly or importing it as a module.
+
+Scripts that extend blender - define classes that exist beyond the scripts execution, this makes future access to these classes (to unregister for example) more difficult than importing as a module where class instance is kept in the module and can be accessed by importing that module later on.
+
+For this reason it's preferable to only use directly execute scripts that don't extend blender by registering classes.
+
+
+Here are some ways to run scripts directly in blender.
+
+* Loaded in the text editor and press **Run Script**.
+
+* Typed or pasted into the interactive console.
+
+* Execute a python file from the command line with blender, eg:
+
+ ``blender --python /home/me/my_script.py``
+
+
+To run as modules:
+
+* The obvious way, ``import some_module`` command from the text window or interactive console.
+
+* Open as a text block and tick "Register" option, this will load with the blend file.
+
+* copy into one of the directories ``scripts/startup``, where they will be automatically imported on startup.
+
+* define as an addon, enabling the addon will load it as a python module.
+
+
+Addons
+------
+
+Some of blenders functionality is best kept optional, alongside scripts loaded at startup we have addons which are kept in their own directory ``scripts/addons``, and only load on startup if selected from the user preferences.
+
+The only difference between addons and built-in python modules is that addons must contain a **bl_info** variable which blender uses to read metadata such as name, author, category and URL.
+
+The user preferences addon listing uses **bl_info** to display information about each addon.
+
+`See Addons `_ for details on the **bl_info** dictionary.
+
+
+Integration through Classes
+===========================
+
+Running python scripts in the text editor is useful for testing but you’ll want to extend blender to make tools accessible like other built-in functionality.
+
+The blender python api allows integration for:
+
+* :class:`bpy.types.Panel`
+
+* :class:`bpy.types.Menu`
+
+* :class:`bpy.types.Operator`
+
+* :class:`bpy.types.PropertyGroup`
+
+* :class:`bpy.types.KeyingSet`
+
+* :class:`bpy.types.RenderEngine`
+
+
+This is intentionally limited. Currently, for more advanced features such as mesh modifiers, object types, or shader nodes, C/C++ must be used.
+
+For python intergration Blender defines methods which are common to all types. This works by creating a python subclass of a Blender class which contains variables and functions specified by the parent class which are pre-defined to interface with Blender.
+
+For example:
+
+.. code-block:: python
+
+ import bpy
+ class SimpleOperator(bpy.types.Operator):
+ bl_idname = "object.simple_operator"
+ bl_label = "Tool Name"
+
+ def execute(self, context):
+ print("Hello World")
+ return {'FINISHED'}
+
+ bpy.utils.register_class(SimpleOperator)
+
+First note that we subclass a member of :mod:`bpy.types`, this is common for all classes which can be integrated with blender and used so we know if this is an Operator and not a Panel when registering.
+
+Both class properties start with a **bl_** prefix. This is a convention used to distinguish blender properties from those you add yourself.
+
+Next see the execute function, which takes an instance of the operator and the current context. A common prefix is not used for functions.
+
+Lastly the register function is called, this takes the class and loads it into blender. See `Class Registration`_.
+
+Regarding inheritance, blender doesn't impose restrictions on the kinds of class inheritance used, the registration checks will use attributes and functions defined in parent classes.
+
+class mix-in example:
+
+.. code-block:: python
+
+ import bpy
+ class BaseOperator:
+ def execute(self, context):
+ print("Hello World BaseClass")
+ return {'FINISHED'}
+
+ class SimpleOperator(bpy.types.Operator, BaseOperator):
+ bl_idname = "object.simple_operator"
+ bl_label = "Tool Name"
+
+ bpy.utils.register_class(SimpleOperator)
+
+Notice these classes don't define an ``__init__(self)`` function. While ``__init__()`` and ``__del__()`` will be called if defined, the class instances lifetime only spans the execution. So a panel for example will have a new instance for every redraw, for this reason there is rarely a cause to store variables in the panel instance. Instead, persistent variables should be stored in Blenders data so that the state can be restored when blender is restarted.
+
+.. note:: Modal operators are an exception, keeping their instance variable as blender runs, see modal operator template.
+
+So once the class is registered with blender, instancing the class and calling the functions is left up to blender. In fact you cannot instance these classes from the script as you would expect with most python API's.
+
+To run operators you can call them through the operator api, eg:
+
+.. code-block:: python
+
+ import bpy
+ bpy.ops.object.simple_operator()
+
+User interface classes are given a context in which to draw, buttons window, file header, toolbar etc, then they are drawn when that area is displayed so they are never called by python scripts directly.
+
+
+Registration
+============
+
+
+Module Registration
+-------------------
+
+Blender modules loaded at startup require ``register()`` and ``unregister()`` functions. These are the *only* functions that blender calls from your code, which is otherwise a regular python module.
+
+A simple blender/python module can look like this:
+
+.. code-block:: python
+
+ import bpy
+
+ class SimpleOperator(bpy.types.Operator):
+ """ See example above """
+
+ def register():
+ bpy.utils.register_class(SimpleOperator)
+
+ def unregister():
+ bpy.utils.unregister_class(SimpleOperator)
+
+ if __name__ == "__main__":
+ register()
+
+These functions usually appear at the bottom of the script containing class registration sometimes adding menu items. You can also use them for internal purposes setting up data for your own tools but take care since register won't re-run when a new blend file is loaded.
+
+The register/unregister calls are used so it's possible to toggle addons and reload scripts while blender runs.
+If the register calls were placed in the body of the script, registration would be called on import, meaning there would be no distinction between importing a module or loading its classes into blender.
+
+This becomes problematic when a script imports classes from another module making it difficult to manage which classes are being loaded and when.
+
+The last 2 lines are only for testing:
+
+.. code-block:: python
+
+ if __name__ == "__main__":
+ register()
+
+This allows the script to be run directly in the text editor to test changes.
+This ``register()`` call won't run when the script is imported as a module since ``__main__`` is reserved for direct execution.
+
+
+Class Registration
+------------------
+
+Registering a class with blender results in the class definition being loaded into blender, where it becomes available alongside existing functionality.
+
+Once this class is loaded you can access it from :mod:`bpy.types`, using the bl_idname rather than the classes original name.
+
+When loading a class, blender performs sanity checks making sure all required properties and functions are found, that properties have the correct type, and that functions have the right number of arguments.
+
+Mostly you will not need concern yourself with this but if there is a problem with the class definition it will be raised on registering:
+
+Using the function arguments ``def execute(self, context, spam)``, will raise an exception:
+
+``ValueError: expected Operator, SimpleOperator class "execute" function to have 2 args, found 3``
+
+Using ``bl_idname = 1`` will raise.
+
+``TypeError: validating class error: Operator.bl_idname expected a string type, not int``
+
+
+Multiple-Classes
+^^^^^^^^^^^^^^^^
+
+Loading classes into blender is described above, for simple cases calling :mod:`bpy.utils.register_class` (SomeClass) is sufficient, but when there are many classes or a packages submodule has its own classes it can be tedious to list them all for registration.
+
+For more convenient loading/unloading :mod:`bpy.utils.register_module` (module) and :mod:`bpy.utils.unregister_module` (module) functions exist.
+
+A script which defines many of its own operators, panels menus etc. you only need to write:
+
+.. code-block:: python
+
+ def register():
+ bpy.utils.register_module(__name__)
+
+ def unregister():
+ bpy.utils.unregister_module(__name__)
+
+Internally blender collects subclasses on registrable types, storing them by the module in which they are defined. By passing the module name to :mod:`bpy.utils.register_module` blender can register all classes created by this module and its submodules.
+
+
+Inter Classes Dependencies
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+When customizing blender you may want to group your own settings together, after all, they will likely have to co-exist with other scripts. To group these properties classes need to be defined, for groups within groups or collections within groups you can find yourself having to deal with order of registration/unregistration.
+
+Custom properties groups are themselves classes which need to be registered.
+
+Say you want to store material settings for a custom engine.
+
+.. code-block:: python
+
+ # Create new property
+ # bpy.data.materials[0].my_custom_props.my_float
+ import bpy
+
+ class MyMaterialProps(bpy.types.PropertyGroup):
+ my_float = bpy.props.FloatProperty()
+
+ def register():
+ bpy.utils.register_class(MyMaterialProps)
+ bpy.types.Material.my_custom_props = bpy.props.PointerProperty(type=MyMaterialProps)
+
+ def unregister():
+ del bpy.types.Material.my_custom_props
+ bpy.utils.unregister_class(MyMaterialProps)
+
+ if __name__ == "__main__":
+ register()
+
+.. note::
+
+ *The class must be registered before being used in a property, failing to do so will raise an error:*
+
+ ``ValueError: bpy_struct "Material" registration error: my_custom_props could not register``
+
+
+.. code-block:: python
+
+ # Create new property group with a sub property
+ # bpy.data.materials[0].my_custom_props.sub_group.my_float
+ import bpy
+
+ class MyMaterialSubProps(bpy.types.PropertyGroup):
+ my_float = bpy.props.FloatProperty()
+
+ class MyMaterialGroupProps(bpy.types.PropertyGroup):
+ sub_group = bpy.props.PointerProperty(type=MyMaterialSubProps)
+
+ def register():
+ bpy.utils.register_class(MyMaterialSubProps)
+ bpy.utils.register_class(MyMaterialGroupProps)
+ bpy.types.Material.my_custom_props = bpy.props.PointerProperty(type=MyMaterialGroupProps)
+
+ def unregister():
+ del bpy.types.Material.my_custom_props
+ bpy.utils.unregister_class(MyMaterialGroupProps)
+ bpy.utils.unregister_class(MyMaterialSubProps)
+
+ if __name__ == "__main__":
+ register()
+
+.. note::
+
+ *The lower most class needs to be registered first and that unregister() is a mirror of register()*
+
+
+Manipulating Classes
+^^^^^^^^^^^^^^^^^^^^
+
+Properties can be added and removed as blender runs, normally happens on register or unregister but for some special cases it may be useful to modify types as the script runs.
+
+For example:
+
+.. code-block:: python
+
+ # add a new property to an existing type
+ bpy.types.Object.my_float = bpy.props.FloatProperty()
+ # remove
+ del bpy.types.Object.my_float
+
+This works just as well for PropertyGroup subclasses you define yourself.
+
+.. code-block:: python
+
+ class MyPropGroup(bpy.types.PropertyGroup):
+ pass
+ MyPropGroup.my_float = bpy.props.FloatProperty()
+
+...this is equivalent to:
+
+.. code-block:: python
+
+ class MyPropGroup(bpy.types.PropertyGroup):
+ my_float = bpy.props.FloatProperty()
+
+
+Dynamic Defined-Classes (Advanced)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+In some cases the specifier for data may not be in blender, renderman shader definitions for example and it may be useful to define types and remove them on the fly.
+
+.. code-block:: python
+
+ for i in range(10):
+ idname = "object.operator_%d" % i
+
+ def func(self, context):
+ print("Hello World", self.bl_idname)
+ return {'FINISHED'}
+
+ opclass = type("DynOp%d" % i,
+ (bpy.types.Operator, ),
+ {"bl_idname": idname, "bl_label": "Test", "execute": func},
+ )
+ bpy.utils.register_class(opclass)
+
+.. note::
+
+ Notice ``type()`` is called to define the class. This is an alternative syntax for class creation in python, better suited to constructing classes dynamically.
+
+
+Calling these operators:
+
+ >>> bpy.ops.object.operator_1()
+ Hello World OBJECT_OT_operator_1
+ {'FINISHED'}
+
+ >>> bpy.ops.object.operator_2()
+ Hello World OBJECT_OT_operator_2
+ {'FINISHED'}
+
diff --git a/doc/python_api/rst/info_quickstart.rst b/doc/python_api/rst/info_quickstart.rst
new file mode 100644
index 00000000000..e77e9a76d7f
--- /dev/null
+++ b/doc/python_api/rst/info_quickstart.rst
@@ -0,0 +1,468 @@
+***********************
+Quickstart Introduction
+***********************
+
+Intro
+=====
+
+This API is generally stable but some areas are still being added and improved.
+
+The Blender/Python API can do the following:
+
+* Edit any data the user interface can (Scenes, Meshes, Particles etc.)
+
+* Modify user preferences, keymaps and themes
+
+* Run tools with own settings
+
+* Create user interface elements such as menus, headers and panels
+
+* Create new tools
+
+* Create interactive tools
+
+* Create new rendering engines that integrate with Blender
+
+* Define new settings in existing Blender data
+
+* Draw in the 3D view using OpenGL commands from Python
+
+
+The Blender/Python API **can't** (yet)...
+
+* Create new space types.
+
+* Assign custom properties to every type.
+
+* Define callbacks or listeners to be notified when data is changed.
+
+
+Before Starting
+===============
+
+This document isn't intended to fully cover each topic. Rather, its purpose is to familiarize you with Blender 2.5's new Python API.
+
+
+A quick list of helpful things to know before starting:
+
+* Blender uses Python 3.x; some 3rd party extensions are not available yet.
+
+* The interactive console in Blender 2.5 has been improved; testing one-liners in the console is a good way to learn.
+
+* Button tool tips show Python attributes and operator names.
+
+* Right clicking on buttons and menu items directly links to API documentation.
+
+* For more examples, the text menu has a templates section where some example operators can be found.
+
+* To examine further scripts distributed with Blender, see ``~/.blender/scripts/startup/bl_ui`` for the user interface and ``~/.blender/scripts/startup/bl_op`` for operators.
+
+
+Key Concepts
+============
+
+Data Access
+-----------
+
+Accessing datablocks
+^^^^^^^^^^^^^^^^^^^^
+
+Python accesses Blender's data in the same way as the animation system and user interface, which means any setting that is changed via a button can also be changed from Python.
+
+Accessing data from the currently loaded blend file is done with the module :mod:`bpy.data`. This gives access to library data. For example:
+
+ >>> bpy.data.objects
+
+
+ >>> bpy.data.scenes
+
+
+ >>> bpy.data.materials
+
+
+
+About Collections
+^^^^^^^^^^^^^^^^^
+
+You'll notice that an index as well as a string can be used to access members of the collection.
+
+Unlike Python's dictionaries, both methods are acceptable; however, the index of a member may change while running Blender.
+
+ >>> list(bpy.data.objects)
+ [bpy.data.objects["Cube"], bpy.data.objects["Plane"]]
+
+ >>> bpy.data.objects['Cube']
+ bpy.data.objects["Cube"]
+
+ >>> bpy.data.objects[0]
+ bpy.data.objects["Cube"]
+
+
+Accessing attributes
+^^^^^^^^^^^^^^^^^^^^
+
+Once you have a data block such as a material, object, groups etc. its attributes can be accessed just like changing a setting in the interface; in fact, the button tooltip also displays the Python attribute which can help in finding what settings to change in a script.
+
+ >>> bpy.data.objects[0].name
+ 'Camera'
+
+ >>> bpy.data.scenes["Scene"]
+ bpy.data.scenes['Scene']
+
+ >>> bpy.data.materials.new("MyMaterial")
+ bpy.data.materials['MyMaterial']
+
+
+For testing what data to access it's useful to use the "Console", which is its own space type in Blender 2.5. This supports auto-complete, giving you a fast way to dig into different data in your file.
+
+Example of a data path that can be quickly found via the console:
+
+ >>> bpy.data.scenes[0].render.resolution_percentage
+ 100
+ >>> bpy.data.scenes[0].objects["Torus"].data.vertices[0].co.x
+ 1.0
+
+
+Custom Properties
+^^^^^^^^^^^^^^^^^
+
+Python can access properties on any datablock that has an ID (data that can be linked in and accessed from :mod:`bpy.data`. When assigning a property, you can make up your own names, these will be created when needed or overwritten if they exist.
+
+This data is saved with the blend file and copied with objects.
+
+Example:
+
+.. code-block:: python
+
+ bpy.context.object["MyOwnProperty"] = 42
+
+ if "SomeProp" in bpy.context.object:
+ print("Property found")
+
+ # Use the get function like a python dictionary
+ # which can have a fallback value.
+ value = bpy.data.scenes["Scene"].get("test_prop", "fallback value")
+
+ # dictionaries can be assigned as long as they only use basic types.
+ group = bpy.data.groups.new("MyTestGroup")
+ group["GameSettings"] = {"foo": 10, "bar": "spam", "baz": {}}
+
+ del group["GameSettings"]
+
+
+Note that these properties can only be assigned basic Python types.
+
+* int, float, string
+
+* array of ints/floats
+
+* dictionary (only string keys types on this list)
+
+These properties are valid outside of Python. They can be animated by curves or used in driver paths.
+
+
+Context
+-------
+
+While it's useful to be able to access data directly by name or as a list, it's more common to operate on the user's selection. The context is always available from '''bpy.context''' and can be used to get the active object, scene, tool settings along with many other attributes.
+
+Common-use cases:
+
+ >>> bpy.context.object
+ >>> bpy.context.selected_objects
+ >>> bpy.context.visible_bones
+
+Note that the context is read-only. These values cannot be modified directly, though they may be changed by running API functions or by using the data API.
+
+So ``bpy.context.object = obj`` will raise an error.
+
+But ``bpy.context.scene.objects.active = obj`` will work as expected.
+
+
+The context attributes change depending on where it is accessed. The 3D view has different context members to the Console, so take care when accessing context attributes that the user state is known.
+
+See :mod:`bpy.context` API reference
+
+
+Operators (Tools)
+-----------------
+
+Operators are tools generally accessed by the user from buttons, menu items or key shortcuts. From the user perspective they are a tool but Python can run these with its own settings through the :mod:`bpy.ops` module.
+
+Examples:
+
+ >>> bpy.ops.mesh.flip_normals()
+ {'FINISHED'}
+ >>> bpy.ops.mesh.hide(unselected=False)
+ {'FINISHED'}
+ >>> bpy.ops.object.scale_apply()
+ {'FINISHED'}
+
+.. note::
+
+ The menu item: Help -> Operator Cheat Sheet" gives a list of all operators and their default values in Python syntax, along with the generated docs. This is a good way to get an overview of all blender's operators.
+
+
+Operator Poll()
+^^^^^^^^^^^^^^^
+
+Many operators have a "poll" function which may check that the mouse is a valid area or that the object is in the correct mode (Edit Mode, Weight Paint etc). When an operator's poll function fails within python, an exception is raised.
+
+For example, calling bpy.ops.view3d.render_border() from the console raises the following error:
+
+.. code-block:: python
+
+ RuntimeError: Operator bpy.ops.view3d.render_border.poll() failed, context is incorrect
+
+In this case the context must be the 3d view with an active camera.
+
+To avoid using try/except clauses wherever operators are called you can call the operators own .poll() function to check if it can run in the current context.
+
+.. code-block:: python
+
+ if bpy.ops.view3d.render_border.poll():
+ bpy.ops.view3d.render_border()
+
+
+Integration
+===========
+
+Python scripts can integrate with Blender in the following ways:
+
+* By defining a rendering engine.
+
+* By defining operators.
+
+* By defining menus, headers and panels.
+
+* By inserting new buttons into existing menus, headers and panels
+
+
+In Python, this is done by defining a class, which is a subclass of an existing type.
+
+
+Example Operator
+----------------
+
+.. literalinclude:: ../../../release/scripts/templates/operator_simple.py
+
+Once this script runs, ``SimpleOperator`` is registered with Blender and can be called from the operator search popup or added to the toolbar.
+
+To run the script:
+
+#. Highlight the above code then press Ctrl+C to copy it.
+
+#. Start Blender
+
+#. Press Ctrl+Right twice to change to the Scripting layout.
+
+#. Press Ctrl+V to paste the code into the text panel (the upper left frame).
+
+#. Click on the button **Run Script**.
+
+#. Move you're mouse into the 3D view, press spacebar for the operator search
+ menu, and type "Simple".
+
+#. Click on the "Simple Operator" item found in search.
+
+
+.. seealso:: The class members with the **bl_** prefix are documented in the API
+ reference :class:`bpy.types.Operator`
+
+
+Example Panel
+-------------
+
+Panels register themselves as a class, like an operator. Notice the extra **bl_** variables used to set the context they display in.
+
+.. literalinclude:: ../../../release/scripts/templates/ui_panel_simple.py
+
+To run the script:
+
+#. Highlight the above code then press Ctrl+C to copy it
+
+#. Start Blender
+
+#. Press Ctrl+Right twice to change to the Scripting layout
+
+#. Press Ctrl+V to paste the code into the text panel (the upper left frame)
+
+#. Click on the button **Run Script**.
+
+
+To view the results:
+
+#. Select the the default cube.
+
+#. Click on the Object properties icon in the buttons panel (far right; appears as a tiny cube).
+
+#. Scroll down to see a panel named **Hello World Panel**.
+
+#. Changing the object name also updates **Hello World Panel's** Name: field.
+
+Note the row distribution and the label and properties that are available through the code.
+
+.. seealso:: :class:`bpy.types.Panel`
+
+
+Types
+=====
+
+Blender defines a number of Python types but also uses Python native types.
+
+Blender's Python API can be split up into 3 categories.
+
+
+Native Types
+------------
+
+In simple cases returning a number or a string as a custom type would be cumbersome, so these are accessed as normal python types.
+
+* blender float/int/boolean -> float/int/boolean
+
+* blender enumerator -> string
+
+ >>> C.object.rotation_mode = 'AXIS_ANGLE'
+
+
+* blender enumerator (multiple) -> set of strings
+
+ .. code-block:: python
+
+ # setting multiple camera overlay guides
+ bpy.context.scene.camera.data.show_guide = {'GOLDEN', 'CENTER'}
+
+ # passing as an operator argument for report types
+ self.report({'WARNING', 'INFO'}, "Some message!")
+
+
+Internal Types
+--------------
+
+Used for Blender datablocks and collections: :class:`bpy.types.bpy_struct`
+
+For data that contains its own attributes groups/meshes/bones/scenes... etc.
+
+There are 2 main types that wrap Blenders data, one for datablocks (known internally as bpy_struct), another for properties.
+
+ >>> bpy.context.object
+ bpy.data.objects['Cube']
+
+ >>> C.scene.objects
+ bpy.data.scenes['Scene'].objects
+
+Note that these types reference Blender's data so modifying them is immediately visible.
+
+
+Mathutils Types
+---------------
+
+Used for vectors, quaternion, eulers, matrix and color types, accessible from :mod:`mathutils`
+
+Some attributes such as :class:`bpy.types.Object.location`, :class:`bpy.types.PoseBone.rotation_euler` and :class:`bpy.types.Scene.cursor_location` can be accessed as special math types which can be used together and manipulated in various useful ways.
+
+Example of a matrix, vector multiplication:
+
+.. code-block:: python
+
+ bpy.context.object.matrix_world * bpy.context.object.data.verts[0].co
+
+.. note::
+
+ mathutils types keep a reference to Blender's internal data so changes can
+ be applied back.
+
+
+ Example:
+
+ .. code-block:: python
+
+ # modifies the Z axis in place.
+ bpy.context.object.location.z += 2.0
+
+ # location variable holds a reference to the object too.
+ location = bpy.context.object.location
+ location *= 2.0
+
+ # Copying the value drops the reference so the value can be passed to
+ # functions and modified without unwanted side effects.
+ location = bpy.context.object.location.copy()
+
+
+Animation
+=========
+
+There are 2 ways to add keyframes through Python.
+
+The first is through key properties directly, which is similar to inserting a keyframe from the button as a user. You can also manually create the curves and keyframe data, then set the path to the property. Here are examples of both methods.
+
+Both examples insert a keyframe on the active object's Z axis.
+
+Simple example:
+
+.. code-block:: python
+
+ obj = bpy.context.object
+ obj.location[2] = 0.0
+ obj.keyframe_insert(data_path="location", frame=10.0, index=2)
+ obj.location[2] = 1.0
+ obj.keyframe_insert(data_path="location", frame=20.0, index=2)
+
+Using Low-Level Functions:
+
+.. code-block:: python
+
+ obj = bpy.context.object
+ obj.animation_data_create()
+ obj.animation_data.action = bpy.data.actions.new(name="MyAction")
+ fcu_z = obj.animation_data.action.fcurves.new(data_path="location", index=2)
+ fcu_z.keyframe_points.add(2)
+ fcu_z.keyframe_points[0].co = 10.0, 0.0
+ fcu_z.keyframe_points[1].co = 20.0, 1.0
+
+
+Style Conventions
+=================
+
+For Blender 2.5 we have chosen to follow python suggested style guide to avoid mixing styles amongst our own scripts and make it easier to use python scripts from other projects.
+
+Using our style guide for your own scripts makes it easier if you eventually want to contribute them to blender.
+
+This style guide is known as pep8 and can be found `here `_
+
+A brief listing of pep8 criteria.
+
+* camel caps for class names: MyClass
+
+* all lower case underscore separated module names: my_module
+
+* indentation of 4 spaces (no tabs)
+
+* spaces around operators. ``1 + 1``, not ``1+1``
+
+* only use explicit imports, (no importing '*')
+
+* don't use single line: ``if val: body``, separate onto 2 lines instead.
+
+
+As well as pep8 we have other conventions used for blender python scripts.
+
+* Use single quotes for enums, and double quotes for strings.
+
+ Both are of course strings but in our internal API enums are unique items from a limited set. eg.
+
+ .. code-block:: python
+
+ bpy.context.scene.render.file_format = 'PNG'
+ bpy.context.scene.render.filepath = "//render_out"
+
+* pep8 also defines that lines should not exceed 79 characters, we felt this is too restrictive so this is optional per script.
+
+Periodically we run checks for pep8 compliance on blender scripts, for scripts to be included in this check add this line as a comment at the top of the script.
+
+``# ``
+
+To enable line length checks use this instead.
+
+``# ``
+
diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py
index f8561c719bc..e378dd19e73 100644
--- a/doc/python_api/sphinx_doc_gen.py
+++ b/doc/python_api/sphinx_doc_gen.py
@@ -60,11 +60,13 @@ if __import__("sys").modules.get("bpy") is None:
# Switch for quick testing
if 1:
# full build
+ EXCLUDE_INFO_DOCS = False
EXCLUDE_MODULES = ()
FILTER_BPY_TYPES = None
FILTER_BPY_OPS = None
else:
+ EXCLUDE_INFO_DOCS = False
# for testing so doc-builds dont take so long.
EXCLUDE_MODULES = (
"bpy.context",
@@ -77,7 +79,7 @@ else:
"bpy.types", # supports filtering
"bpy.ops", # supports filtering
"bpy_extras",
- # "bge",
+ "bge",
"aud",
"bgl",
"blf",
@@ -85,7 +87,7 @@ else:
"mathutils.geometry",
)
- FILTER_BPY_TYPES = ("bpy_struct", "Panel", "Menu", "Operator", "RenderEngine") # allow
+ FILTER_BPY_TYPES = ("bpy_struct", "Panel", "ID") # allow
FILTER_BPY_OPS = ("import.scene", ) # allow
# for quick rebuilds
@@ -96,6 +98,13 @@ sphinx-build doc/python_api/sphinx-in doc/python_api/sphinx-out
"""
+# extra info, not api reference docs
+# stored in ./rst/info/
+INFO_DOCS = (
+ ("info_quickstart.rst", "Blender/Python Quickstart: new to blender/scripting and want to get you're feet wet?"),
+ ("info_overview.rst", "Blender/Python API Overview: a more complete explanation of python integration"),
+ ("info_gotcha.rst", "Gotcha's: some of the problems you may come up against when writing scripts"),
+ )
# import rpdb2; rpdb2.start_embedded_debugger('test')
@@ -744,6 +753,8 @@ def pyrna2sphinx(BASEPATH):
descr = prop.name
fw(" `%s`, %s, %s\n\n" % (prop.identifier, descr, type_descr))
+ write_example_ref(" ", fw, "bpy.types." + struct.identifier + "." + func.identifier)
+
fw("\n")
# python methods
@@ -999,14 +1010,17 @@ def rna2sphinx(BASEPATH):
fw("\n")
- fw("============================\n")
- fw("Blender/Python Documentation\n")
- fw("============================\n")
- fw("\n")
- fw("\n")
- fw("* `Quickstart Intro `_ if you are new to scripting in blender and want to get you're feet wet!\n")
- fw("* `Blender/Python Overview `_ for a more complete explanation of python integration in blender\n")
- fw("\n")
+ if not EXCLUDE_INFO_DOCS:
+ fw("============================\n")
+ fw("Blender/Python Documentation\n")
+ fw("============================\n")
+ fw("\n")
+ fw("\n")
+ fw(".. toctree::\n")
+ fw(" :maxdepth: 1\n\n")
+ for info, info_desc in INFO_DOCS:
+ fw(" %s <%s>\n\n" % (info_desc, info))
+ fw("\n")
fw("===================\n")
fw("Application Modules\n")
@@ -1208,6 +1222,10 @@ def rna2sphinx(BASEPATH):
shutil.copy2(os.path.join(BASEPATH, "..", "rst", "change_log.rst"), BASEPATH)
+ if not EXCLUDE_INFO_DOCS:
+ for info, info_desc in INFO_DOCS:
+ shutil.copy2(os.path.join(BASEPATH, "..", "rst", info), BASEPATH)
+
if 0:
filepath = os.path.join(BASEPATH, "bpy.rst")
file = open(filepath, "w")
diff --git a/doc/python_api/sphinx_doc_gen.sh b/doc/python_api/sphinx_doc_gen.sh
index a3befe1b7cb..ea55fbb3907 100755
--- a/doc/python_api/sphinx_doc_gen.sh
+++ b/doc/python_api/sphinx_doc_gen.sh
@@ -3,11 +3,21 @@
# bash source/blender/python/doc/sphinx_doc_gen.sh
# ssh upload means you need an account on the server
+
+# ----------------------------------------------------------------------------
+# Upload vars
+
+# disable for testing
+DO_UPLOAD=true
+
BLENDER="./blender.bin"
SSH_USER="ideasman42"
SSH_HOST=$SSH_USER"@emo.blender.org"
SSH_UPLOAD="/data/www/vhosts/www.blender.org/documentation" # blender_python_api_VERSION, added after
+# ----------------------------------------------------------------------------
+# Blender Version & Info
+
# 'Blender 2.53 (sub 1) Build' --> '2_53_1' as a shell script.
# "_".join(str(v) for v in bpy.app.version)
# custom blender vars
@@ -28,28 +38,52 @@ SSH_UPLOAD_FULL=$SSH_UPLOAD/"blender_python_api_"$BLENDER_VERSION
SPHINXBASE=doc/python_api/
+
+# ----------------------------------------------------------------------------
+# Generate reStructuredText (blender/python only)
+
# dont delete existing docs, now partial updates are used for quick builds.
$BLENDER --background --factory-startup --python $SPHINXBASE/sphinx_doc_gen.py
-# html
-sphinx-build $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
-cp $SPHINXBASE/sphinx-out/contents.html $SPHINXBASE/sphinx-out/index.html
-ssh $SSH_USER@emo.blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
-rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
+# ----------------------------------------------------------------------------
+# Generate HTML (sphinx)
-## symlink the dir to a static URL
-#ssh $SSH_USER@emo.blender.org 'rm '$SSH_UPLOAD'/250PythonDoc && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/250PythonDoc'
+sphinx-build -n -b html $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
-# better redirect
-ssh $SSH_USER@emo.blender.org 'echo "Redirecting...Redirecting..." > '$SSH_UPLOAD'/250PythonDoc/index.html'
-# pdf
-sphinx-build -b latex $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
-cd $SPHINXBASE/sphinx-out
-make
-cd -
+# ----------------------------------------------------------------------------
+# Generate PDF (sphinx/laytex)
-# rename so local PDF has matching name.
+sphinx-build -n -b latex $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
+make -C $SPHINXBASE/sphinx-out
mv $SPHINXBASE/sphinx-out/contents.pdf $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf
-rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.pdf
+
+# ----------------------------------------------------------------------------
+# Upload to blender servers, comment this section for testing
+
+if $DO_UPLOAD ; then
+
+ cp $SPHINXBASE/sphinx-out/contents.html $SPHINXBASE/sphinx-out/index.html
+ ssh $SSH_USER@emo.blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
+ rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
+
+ ## symlink the dir to a static URL
+ #ssh $SSH_USER@emo.blender.org 'rm '$SSH_UPLOAD'/250PythonDoc && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/250PythonDoc'
+
+ # better redirect
+ ssh $SSH_USER@emo.blender.org 'echo "Redirecting...Redirecting..." > '$SSH_UPLOAD'/250PythonDoc/index.html'
+
+ # rename so local PDF has matching name.
+ rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.pdf
+
+fi
+
+
+# ----------------------------------------------------------------------------
+# Print some useful text
+
+echo ""
+echo "Finished! view the docs from: "
+echo " html:" $SPHINXBASE/sphinx-out/contents.html
+echo " pdf:" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf
diff --git a/extern/bullet2/src/SConscript b/extern/bullet2/src/SConscript
index 5cb9185d6a1..fa00ad7bc2e 100644
--- a/extern/bullet2/src/SConscript
+++ b/extern/bullet2/src/SConscript
@@ -11,10 +11,10 @@ if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
defs += ' WIN32 NDEBUG _WINDOWS'
#cflags += ['/MT', '/W3', '/GX', '/O2', '/Op']
cflags += ['/MT', '/W3', '/GX', '/Og', '/Ot', '/Ob1', '/Op', '/G6', '/O3', '/EHcs']
-elif env['OURPLATFORM']=='win32-mingw':
+elif env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
defs += ' NDEBUG'
cflags += ['-O2']
-elif sys.platform=='linux2' or sys.platform=='linux-i386' or sys.platform=='freebsd4' or sys.platform=='freebsd5':
+elif env['OURPLATFORM'] in ('linux', 'freebsd4', 'freebsd5'):
defs += ' NDEBUG'
cflags += ['-O2']
elif sys.platform=='darwin':
diff --git a/intern/audaspace/CMakeLists.txt b/intern/audaspace/CMakeLists.txt
index 7eef13b103b..25510ebd2a5 100644
--- a/intern/audaspace/CMakeLists.txt
+++ b/intern/audaspace/CMakeLists.txt
@@ -41,6 +41,8 @@ set(SRC
FX/AUD_DelayReader.cpp
FX/AUD_DoubleFactory.cpp
FX/AUD_DoubleReader.cpp
+ FX/AUD_DynamicIIRFilterFactory.cpp
+ FX/AUD_DynamicIIRFilterReader.cpp
FX/AUD_EffectFactory.cpp
FX/AUD_EffectReader.cpp
FX/AUD_EnvelopeFactory.cpp
@@ -66,6 +68,8 @@ set(SRC
FX/AUD_SuperposeReader.cpp
FX/AUD_VolumeFactory.cpp
intern/AUD_3DMath.h
+ intern/AUD_AnimateableProperty.cpp
+ intern/AUD_AnimateableProperty.h
intern/AUD_Buffer.cpp
intern/AUD_Buffer.h
intern/AUD_BufferReader.cpp
@@ -82,14 +86,21 @@ set(SRC
intern/AUD_ConverterFunctions.h
intern/AUD_ConverterReader.cpp
intern/AUD_ConverterReader.h
- intern/AUD_DefaultMixer.cpp
- intern/AUD_DefaultMixer.h
intern/AUD_FileFactory.cpp
intern/AUD_FileFactory.h
+ intern/AUD_FileWriter.cpp
+ intern/AUD_FileWriter.h
intern/AUD_I3DDevice.h
+ intern/AUD_I3DHandle.h
intern/AUD_IDevice.h
intern/AUD_IFactory.h
+ intern/AUD_IHandle.h
intern/AUD_IReader.h
+ intern/AUD_IWriter.h
+ intern/AUD_JOSResampleFactory.cpp
+ intern/AUD_JOSResampleFactory.h
+ intern/AUD_JOSResampleReader.cpp
+ intern/AUD_JOSResampleReader.h
intern/AUD_LinearResampleFactory.cpp
intern/AUD_LinearResampleFactory.h
intern/AUD_LinearResampleReader.cpp
@@ -104,9 +115,16 @@ set(SRC
intern/AUD_ReadDevice.cpp
intern/AUD_ReadDevice.h
intern/AUD_Reference.h
+ intern/AUD_ReferenceHandler.cpp
intern/AUD_ResampleFactory.h
+ intern/AUD_ResampleReader.cpp
+ intern/AUD_ResampleReader.h
+ intern/AUD_SequencerEntry.cpp
+ intern/AUD_SequencerEntry.h
intern/AUD_SequencerFactory.cpp
intern/AUD_SequencerFactory.h
+ intern/AUD_SequencerHandle.cpp
+ intern/AUD_SequencerHandle.h
intern/AUD_SequencerReader.cpp
intern/AUD_SequencerReader.h
intern/AUD_SilenceFactory.cpp
@@ -131,6 +149,8 @@ set(SRC
FX/AUD_DelayReader.h
FX/AUD_DoubleFactory.h
FX/AUD_DoubleReader.h
+ FX/AUD_DynamicIIRFilterFactory.h
+ FX/AUD_DynamicIIRFilterReader.h
FX/AUD_EffectFactory.h
FX/AUD_EffectReader.h
FX/AUD_EnvelopeFactory.h
@@ -168,9 +188,11 @@ if(WITH_CODEC_FFMPEG)
list(APPEND SRC
ffmpeg/AUD_FFMPEGFactory.cpp
ffmpeg/AUD_FFMPEGReader.cpp
+ ffmpeg/AUD_FFMPEGWriter.cpp
ffmpeg/AUD_FFMPEGFactory.h
ffmpeg/AUD_FFMPEGReader.h
+ ffmpeg/AUD_FFMPEGWriter.h
)
endif()
@@ -230,9 +252,11 @@ if(WITH_CODEC_SNDFILE)
list(APPEND SRC
sndfile/AUD_SndFileFactory.cpp
sndfile/AUD_SndFileReader.cpp
+ sndfile/AUD_SndFileWriter.cpp
sndfile/AUD_SndFileFactory.h
sndfile/AUD_SndFileReader.h
+ sndfile/AUD_SndFileWriter.h
)
endif()
diff --git a/intern/audaspace/FX/AUD_AccumulatorFactory.cpp b/intern/audaspace/FX/AUD_AccumulatorFactory.cpp
index d60924958b1..0dffa7fc9ea 100644
--- a/intern/audaspace/FX/AUD_AccumulatorFactory.cpp
+++ b/intern/audaspace/FX/AUD_AccumulatorFactory.cpp
@@ -32,7 +32,7 @@
#include "AUD_AccumulatorFactory.h"
#include "AUD_CallbackIIRFilterReader.h"
-sample_t accumulatorFilterAdditive(AUD_CallbackIIRFilterReader* reader, void* useless)
+sample_t AUD_AccumulatorFactory::accumulatorFilterAdditive(AUD_CallbackIIRFilterReader* reader, void* useless)
{
float in = reader->x(0);
float lastin = reader->x(-1);
@@ -42,7 +42,7 @@ sample_t accumulatorFilterAdditive(AUD_CallbackIIRFilterReader* reader, void* us
return out;
}
-sample_t accumulatorFilter(AUD_CallbackIIRFilterReader* reader, void* useless)
+sample_t AUD_AccumulatorFactory::accumulatorFilter(AUD_CallbackIIRFilterReader* reader, void* useless)
{
float in = reader->x(0);
float lastin = reader->x(-1);
@@ -52,14 +52,14 @@ sample_t accumulatorFilter(AUD_CallbackIIRFilterReader* reader, void* useless)
return out;
}
-AUD_AccumulatorFactory::AUD_AccumulatorFactory(AUD_IFactory* factory,
+AUD_AccumulatorFactory::AUD_AccumulatorFactory(AUD_Reference factory,
bool additive) :
AUD_EffectFactory(factory),
m_additive(additive)
{
}
-AUD_IReader* AUD_AccumulatorFactory::createReader() const
+AUD_Reference AUD_AccumulatorFactory::createReader()
{
return new AUD_CallbackIIRFilterReader(getReader(), 2, 2,
m_additive ? accumulatorFilterAdditive : accumulatorFilter);
diff --git a/intern/audaspace/FX/AUD_AccumulatorFactory.h b/intern/audaspace/FX/AUD_AccumulatorFactory.h
index 3c3b32ce071..95246ef5341 100644
--- a/intern/audaspace/FX/AUD_AccumulatorFactory.h
+++ b/intern/audaspace/FX/AUD_AccumulatorFactory.h
@@ -33,9 +33,14 @@
#define AUD_ACCUMULATORFACTORY
#include "AUD_EffectFactory.h"
+class AUD_CallbackIIRFilterReader;
/**
* This factory creates an accumulator reader.
+ *
+ * The accumulator adds the difference at the input to the last output in case
+ * it's positive. In additive mode it additionaly adds the difference always.
+ * So in case the difference is positive, it's added twice.
*/
class AUD_AccumulatorFactory : public AUD_EffectFactory
{
@@ -55,9 +60,12 @@ public:
* \param factory The input factory.
* \param additive Whether the accumulator is additive.
*/
- AUD_AccumulatorFactory(AUD_IFactory* factory, bool additive = false);
+ AUD_AccumulatorFactory(AUD_Reference factory, bool additive = false);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
+
+ static sample_t accumulatorFilterAdditive(AUD_CallbackIIRFilterReader* reader, void* useless);
+ static sample_t accumulatorFilter(AUD_CallbackIIRFilterReader* reader, void* useless);
};
#endif //AUD_ACCUMULATORFACTORY
diff --git a/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp b/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp
index 563722d9213..29ff6d90080 100644
--- a/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp
+++ b/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp
@@ -33,20 +33,20 @@
#include
-#define CC m_channels + m_channel
+#define CC m_specs.channels + m_channel
-AUD_BaseIIRFilterReader::AUD_BaseIIRFilterReader(AUD_IReader* reader, int in,
+AUD_BaseIIRFilterReader::AUD_BaseIIRFilterReader(AUD_Reference reader, int in,
int out) :
AUD_EffectReader(reader),
- m_channels(reader->getSpecs().channels),
+ m_specs(reader->getSpecs()),
m_xlen(in), m_ylen(out),
m_xpos(0), m_ypos(0), m_channel(0)
{
- m_x = new sample_t[in * m_channels];
- m_y = new sample_t[out * m_channels];
+ m_x = new sample_t[m_xlen * m_specs.channels];
+ m_y = new sample_t[m_ylen * m_specs.channels];
- memset(m_x, 0, sizeof(sample_t) * in * m_channels);
- memset(m_y, 0, sizeof(sample_t) * out * m_channels);
+ memset(m_x, 0, sizeof(sample_t) * m_xlen * m_specs.channels);
+ memset(m_y, 0, sizeof(sample_t) * m_ylen * m_specs.channels);
}
AUD_BaseIIRFilterReader::~AUD_BaseIIRFilterReader()
@@ -55,24 +55,77 @@ AUD_BaseIIRFilterReader::~AUD_BaseIIRFilterReader()
delete[] m_y;
}
-void AUD_BaseIIRFilterReader::read(int & length, sample_t* & buffer)
+void AUD_BaseIIRFilterReader::setLengths(int in, int out)
{
- sample_t* buf;
+ if(in != m_xlen)
+ {
+ sample_t* xn = new sample_t[in * m_specs.channels];
+ memset(xn, 0, sizeof(sample_t) * in * m_specs.channels);
- int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
+ for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
+ {
+ for(int i = 1; i <= in && i <= m_xlen; i++)
+ {
+ xn[(in - i) * CC] = x(-i);
+ }
+ }
- m_reader->read(length, buf);
+ delete[] m_x;
+ m_x = xn;
+ m_xpos = 0;
+ m_xlen = in;
+ }
- if(m_buffer.getSize() < length * samplesize)
- m_buffer.resize(length * samplesize);
+ if(out != m_ylen)
+ {
+ sample_t* yn = new sample_t[out * m_specs.channels];
+ memset(yn, 0, sizeof(sample_t) * out * m_specs.channels);
- buffer = m_buffer.getBuffer();
+ for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
+ {
+ for(int i = 1; i <= out && i <= m_ylen; i++)
+ {
+ yn[(out - i) * CC] = y(-i);
+ }
+ }
- for(m_channel = 0; m_channel < m_channels; m_channel++)
+ delete[] m_y;
+ m_y = yn;
+ m_ypos = 0;
+ m_ylen = out;
+ }
+}
+
+void AUD_BaseIIRFilterReader::read(int& length, bool& eos, sample_t* buffer)
+{
+ AUD_Specs specs = m_reader->getSpecs();
+ if(specs.channels != m_specs.channels)
+ {
+ m_specs.channels = specs.channels;
+
+ delete[] m_x;
+ delete[] m_y;
+
+ m_x = new sample_t[m_xlen * m_specs.channels];
+ m_y = new sample_t[m_ylen * m_specs.channels];
+
+ memset(m_x, 0, sizeof(sample_t) * m_xlen * m_specs.channels);
+ memset(m_y, 0, sizeof(sample_t) * m_ylen * m_specs.channels);
+ }
+
+ if(specs.rate != m_specs.rate)
+ {
+ m_specs = specs;
+ sampleRateChanged(m_specs.rate);
+ }
+
+ m_reader->read(length, eos, buffer);
+
+ for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
{
for(int i = 0; i < length; i++)
{
- m_x[m_xpos * CC] = buf[i * CC];
+ m_x[m_xpos * CC] = buffer[i * CC];
m_y[m_ypos * CC] = buffer[i * CC] = filter();
m_xpos = (m_xpos + 1) % m_xlen;
@@ -80,3 +133,7 @@ void AUD_BaseIIRFilterReader::read(int & length, sample_t* & buffer)
}
}
}
+
+void AUD_BaseIIRFilterReader::sampleRateChanged(AUD_SampleRate rate)
+{
+}
diff --git a/intern/audaspace/FX/AUD_BaseIIRFilterReader.h b/intern/audaspace/FX/AUD_BaseIIRFilterReader.h
index 436e6469a58..6bf877d66da 100644
--- a/intern/audaspace/FX/AUD_BaseIIRFilterReader.h
+++ b/intern/audaspace/FX/AUD_BaseIIRFilterReader.h
@@ -42,24 +42,19 @@ class AUD_BaseIIRFilterReader : public AUD_EffectReader
{
private:
/**
- * Channel count.
+ * Specs.
*/
- const int m_channels;
+ AUD_Specs m_specs;
/**
* Length of input samples needed.
*/
- const int m_xlen;
+ int m_xlen;
/**
* Length of output samples needed.
*/
- const int m_ylen;
-
- /**
- * The playback buffer.
- */
- AUD_Buffer m_buffer;
+ int m_ylen;
/**
* The last in samples array.
@@ -97,24 +92,46 @@ protected:
* \param in The count of past input samples needed.
* \param out The count of past output samples needed.
*/
- AUD_BaseIIRFilterReader(AUD_IReader* reader, int in, int out);
+ AUD_BaseIIRFilterReader(AUD_Reference reader, int in, int out);
+
+ void setLengths(int in, int out);
public:
+ /**
+ * Retrieves the last input samples.
+ * \param pos The position, valid are 0 (current) or negative values.
+ * \return The sample value.
+ */
inline sample_t x(int pos)
{
- return m_x[(m_xpos + pos + m_xlen) % m_xlen * m_channels + m_channel];
+ return m_x[(m_xpos + pos + m_xlen) % m_xlen * m_specs.channels + m_channel];
}
+ /**
+ * Retrieves the last output samples.
+ * \param pos The position, valid are negative values.
+ * \return The sample value.
+ */
inline sample_t y(int pos)
{
- return m_y[(m_ypos + pos + m_ylen) % m_ylen * m_channels + m_channel];
+ return m_y[(m_ypos + pos + m_ylen) % m_ylen * m_specs.channels + m_channel];
}
virtual ~AUD_BaseIIRFilterReader();
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
+ /**
+ * Runs the filtering function.
+ * \return The current output sample value.
+ */
virtual sample_t filter()=0;
+
+ /**
+ * Notifies the filter about a sample rate change.
+ * \param rate The new sample rate.
+ */
+ virtual void sampleRateChanged(AUD_SampleRate rate);
};
#endif //AUD_BASEIIRFILTERREADER
diff --git a/intern/audaspace/FX/AUD_ButterworthFactory.cpp b/intern/audaspace/FX/AUD_ButterworthFactory.cpp
index ea957c81ed3..4b45512ffa6 100644
--- a/intern/audaspace/FX/AUD_ButterworthFactory.cpp
+++ b/intern/audaspace/FX/AUD_ButterworthFactory.cpp
@@ -41,19 +41,18 @@
#define BWPB41 0.76536686473
#define BWPB42 1.84775906502
-AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_IFactory* factory,
+AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_Reference factory,
float frequency) :
- AUD_EffectFactory(factory),
+ AUD_DynamicIIRFilterFactory(factory),
m_frequency(frequency)
{
}
-AUD_IReader* AUD_ButterworthFactory::createReader() const
+void AUD_ButterworthFactory::recalculateCoefficients(AUD_SampleRate rate,
+ std::vector &b,
+ std::vector &a)
{
- AUD_IReader* reader = getReader();
-
- // calculate coefficients
- float omega = 2 * tan(m_frequency * M_PI / reader->getSpecs().rate);
+ float omega = 2 * tan(m_frequency * M_PI / rate);
float o2 = omega * omega;
float o4 = o2 * o2;
float x1 = o2 + 2 * BWPB41 * omega + 4;
@@ -62,7 +61,6 @@ AUD_IReader* AUD_ButterworthFactory::createReader() const
float y2 = o2 - 2 * BWPB42 * omega + 4;
float o228 = 2 * o2 - 8;
float norm = x1 * x2;
- std::vector a, b;
a.push_back(1);
a.push_back((x1 + x2) * o228 / norm);
a.push_back((x1 * y2 + x2 * y1 + o228 * o228) / norm);
@@ -73,6 +71,4 @@ AUD_IReader* AUD_ButterworthFactory::createReader() const
b.push_back(6 * o4 / norm);
b.push_back(b[1]);
b.push_back(b[0]);
-
- return new AUD_IIRFilterReader(reader, b, a);
}
diff --git a/intern/audaspace/FX/AUD_ButterworthFactory.h b/intern/audaspace/FX/AUD_ButterworthFactory.h
index c8b731449c4..12d28eb4038 100644
--- a/intern/audaspace/FX/AUD_ButterworthFactory.h
+++ b/intern/audaspace/FX/AUD_ButterworthFactory.h
@@ -32,12 +32,12 @@
#ifndef AUD_BUTTERWORTHFACTORY
#define AUD_BUTTERWORTHFACTORY
-#include "AUD_EffectFactory.h"
+#include "AUD_DynamicIIRFilterFactory.h"
/**
- * This factory creates a butterworth filter reader.
+ * This factory creates a butterworth lowpass filter reader.
*/
-class AUD_ButterworthFactory : public AUD_EffectFactory
+class AUD_ButterworthFactory : public AUD_DynamicIIRFilterFactory
{
private:
/**
@@ -55,9 +55,11 @@ public:
* \param factory The input factory.
* \param frequency The cutoff frequency.
*/
- AUD_ButterworthFactory(AUD_IFactory* factory, float frequency);
+ AUD_ButterworthFactory(AUD_Reference factory, float frequency);
- virtual AUD_IReader* createReader() const;
+ virtual void recalculateCoefficients(AUD_SampleRate rate,
+ std::vector& b,
+ std::vector& a);
};
#endif //AUD_BUTTERWORTHFACTORY
diff --git a/intern/audaspace/FX/AUD_CallbackIIRFilterReader.cpp b/intern/audaspace/FX/AUD_CallbackIIRFilterReader.cpp
index 2f9bb7762a0..e6c83322435 100644
--- a/intern/audaspace/FX/AUD_CallbackIIRFilterReader.cpp
+++ b/intern/audaspace/FX/AUD_CallbackIIRFilterReader.cpp
@@ -31,7 +31,7 @@
#include "AUD_CallbackIIRFilterReader.h"
-AUD_CallbackIIRFilterReader::AUD_CallbackIIRFilterReader(AUD_IReader* reader,
+AUD_CallbackIIRFilterReader::AUD_CallbackIIRFilterReader(AUD_Reference reader,
int in, int out,
doFilterIIR doFilter,
endFilterIIR endFilter,
diff --git a/intern/audaspace/FX/AUD_CallbackIIRFilterReader.h b/intern/audaspace/FX/AUD_CallbackIIRFilterReader.h
index a969db7297e..6d53edeecc2 100644
--- a/intern/audaspace/FX/AUD_CallbackIIRFilterReader.h
+++ b/intern/audaspace/FX/AUD_CallbackIIRFilterReader.h
@@ -76,7 +76,7 @@ public:
* \param endFilter The finishing callback.
* \param data Data pointer for the callbacks.
*/
- AUD_CallbackIIRFilterReader(AUD_IReader* reader, int in, int out,
+ AUD_CallbackIIRFilterReader(AUD_Reference reader, int in, int out,
doFilterIIR doFilter,
endFilterIIR endFilter = 0,
void* data = 0);
diff --git a/intern/audaspace/FX/AUD_DelayFactory.cpp b/intern/audaspace/FX/AUD_DelayFactory.cpp
index 1d2d99adc03..e452870281d 100644
--- a/intern/audaspace/FX/AUD_DelayFactory.cpp
+++ b/intern/audaspace/FX/AUD_DelayFactory.cpp
@@ -33,7 +33,7 @@
#include "AUD_DelayReader.h"
#include "AUD_Space.h"
-AUD_DelayFactory::AUD_DelayFactory(AUD_IFactory* factory, float delay) :
+AUD_DelayFactory::AUD_DelayFactory(AUD_Reference factory, float delay) :
AUD_EffectFactory(factory),
m_delay(delay)
{
@@ -44,7 +44,7 @@ float AUD_DelayFactory::getDelay() const
return m_delay;
}
-AUD_IReader* AUD_DelayFactory::createReader() const
+AUD_Reference AUD_DelayFactory::createReader()
{
return new AUD_DelayReader(getReader(), m_delay);
}
diff --git a/intern/audaspace/FX/AUD_DelayFactory.h b/intern/audaspace/FX/AUD_DelayFactory.h
index 1e67cd68990..5ab7f850d2f 100644
--- a/intern/audaspace/FX/AUD_DelayFactory.h
+++ b/intern/audaspace/FX/AUD_DelayFactory.h
@@ -55,14 +55,14 @@ public:
* \param factory The input factory.
* \param delay The desired delay in seconds.
*/
- AUD_DelayFactory(AUD_IFactory* factory, float delay = 0);
+ AUD_DelayFactory(AUD_Reference factory, float delay = 0);
/**
* Returns the delay in seconds.
*/
float getDelay() const;
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_DELAYFACTORY
diff --git a/intern/audaspace/FX/AUD_DelayReader.cpp b/intern/audaspace/FX/AUD_DelayReader.cpp
index 374b876455d..7d58b3dae4f 100644
--- a/intern/audaspace/FX/AUD_DelayReader.cpp
+++ b/intern/audaspace/FX/AUD_DelayReader.cpp
@@ -33,11 +33,10 @@
#include
-AUD_DelayReader::AUD_DelayReader(AUD_IReader* reader, float delay) :
+AUD_DelayReader::AUD_DelayReader(AUD_Reference reader, float delay) :
AUD_EffectReader(reader),
m_delay(int(delay * reader->getSpecs().rate)),
- m_remdelay(int(delay * reader->getSpecs().rate)),
- m_empty(true)
+ m_remdelay(int(delay * reader->getSpecs().rate))
{
}
@@ -70,49 +69,30 @@ int AUD_DelayReader::getPosition() const
return m_reader->getPosition() + m_delay;
}
-void AUD_DelayReader::read(int & length, sample_t* & buffer)
+void AUD_DelayReader::read(int& length, bool& eos, sample_t* buffer)
{
if(m_remdelay > 0)
{
AUD_Specs specs = m_reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
- if(m_buffer.getSize() < length * samplesize)
- {
- m_buffer.resize(length * samplesize);
- m_empty = false;
- }
-
- buffer = m_buffer.getBuffer();
-
if(length > m_remdelay)
{
- if(!m_empty)
- memset(buffer, 0, m_remdelay * samplesize);
+ memset(buffer, 0, m_remdelay * samplesize);
int len = length - m_remdelay;
- sample_t* buf;
- m_reader->read(len, buf);
+ m_reader->read(len, eos, buffer + m_remdelay * specs.channels);
- memcpy(buffer + m_remdelay * specs.channels,
- buf, len * samplesize);
-
- if(len < length-m_remdelay)
- length = m_remdelay + len;
+ length = m_remdelay + len;
m_remdelay = 0;
- m_empty = false;
}
else
{
- if(!m_empty)
- {
- memset(buffer, 0, length * samplesize);
- m_empty = true;
- }
+ memset(buffer, 0, length * samplesize);
m_remdelay -= length;
}
}
else
- m_reader->read(length, buffer);
+ m_reader->read(length, eos, buffer);
}
diff --git a/intern/audaspace/FX/AUD_DelayReader.h b/intern/audaspace/FX/AUD_DelayReader.h
index 5f0af660bdf..128e589eede 100644
--- a/intern/audaspace/FX/AUD_DelayReader.h
+++ b/intern/audaspace/FX/AUD_DelayReader.h
@@ -36,16 +36,11 @@
#include "AUD_Buffer.h"
/**
- * This class reads another reader and changes it's delay.
+ * This class reads another reader and delays it.
*/
class AUD_DelayReader : public AUD_EffectReader
{
private:
- /**
- * The playback buffer.
- */
- AUD_Buffer m_buffer;
-
/**
* The delay level.
*/
@@ -56,11 +51,6 @@ private:
*/
int m_remdelay;
- /**
- * Whether the buffer is currently filled with zeros.
- */
- bool m_empty;
-
// hide copy constructor and operator=
AUD_DelayReader(const AUD_DelayReader&);
AUD_DelayReader& operator=(const AUD_DelayReader&);
@@ -71,12 +61,12 @@ public:
* \param reader The reader to read from.
* \param delay The delay in seconds.
*/
- AUD_DelayReader(AUD_IReader* reader, float delay);
+ AUD_DelayReader(AUD_Reference reader, float delay);
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_DELAYREADER
diff --git a/intern/audaspace/FX/AUD_DoubleFactory.cpp b/intern/audaspace/FX/AUD_DoubleFactory.cpp
index 7a40f1f8c96..e1e6ba50435 100644
--- a/intern/audaspace/FX/AUD_DoubleFactory.cpp
+++ b/intern/audaspace/FX/AUD_DoubleFactory.cpp
@@ -32,25 +32,15 @@
#include "AUD_DoubleFactory.h"
#include "AUD_DoubleReader.h"
-AUD_DoubleFactory::AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
+AUD_DoubleFactory::AUD_DoubleFactory(AUD_Reference factory1, AUD_Reference factory2) :
m_factory1(factory1), m_factory2(factory2)
{
}
-AUD_IReader* AUD_DoubleFactory::createReader() const
+AUD_Reference AUD_DoubleFactory::createReader()
{
- AUD_IReader* reader1 = m_factory1->createReader();
- AUD_IReader* reader2;
-
- try
- {
- reader2 = m_factory2->createReader();
- }
- catch(AUD_Exception&)
- {
- delete reader1;
- throw;
- }
+ AUD_Reference reader1 = m_factory1->createReader();
+ AUD_Reference reader2 = m_factory2->createReader();
return new AUD_DoubleReader(reader1, reader2);
}
diff --git a/intern/audaspace/FX/AUD_DoubleFactory.h b/intern/audaspace/FX/AUD_DoubleFactory.h
index 52a299c7157..2db2257244c 100644
--- a/intern/audaspace/FX/AUD_DoubleFactory.h
+++ b/intern/audaspace/FX/AUD_DoubleFactory.h
@@ -36,7 +36,6 @@
/**
* This factory plays two other factories behind each other.
- * \note Readers from the underlying factories must have the same sample rate and channel count.
*/
class AUD_DoubleFactory : public AUD_IFactory
{
@@ -44,12 +43,12 @@ private:
/**
* First played factory.
*/
- AUD_IFactory* m_factory1;
+ AUD_Reference m_factory1;
/**
* Second played factory.
*/
- AUD_IFactory* m_factory2;
+ AUD_Reference m_factory2;
// hide copy constructor and operator=
AUD_DoubleFactory(const AUD_DoubleFactory&);
@@ -61,9 +60,9 @@ public:
* \param factory1 The first input factory.
* \param factory2 The second input factory.
*/
- AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
+ AUD_DoubleFactory(AUD_Reference factory1, AUD_Reference factory2);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_DOUBLEFACTORY
diff --git a/intern/audaspace/FX/AUD_DoubleReader.cpp b/intern/audaspace/FX/AUD_DoubleReader.cpp
index 113bed14ce3..3b1d105954c 100644
--- a/intern/audaspace/FX/AUD_DoubleReader.cpp
+++ b/intern/audaspace/FX/AUD_DoubleReader.cpp
@@ -33,28 +33,17 @@
#include
-static const char* specs_error = "AUD_DoubleReader: Both readers have to have "
- "the same specs.";
-
-AUD_DoubleReader::AUD_DoubleReader(AUD_IReader* reader1,
- AUD_IReader* reader2) :
+AUD_DoubleReader::AUD_DoubleReader(AUD_Reference reader1,
+ AUD_Reference reader2) :
m_reader1(reader1), m_reader2(reader2), m_finished1(false)
{
AUD_Specs s1, s2;
s1 = reader1->getSpecs();
s2 = reader2->getSpecs();
- if(memcmp(&s1, &s2, sizeof(AUD_Specs)) != 0)
- {
- delete reader1;
- delete reader2;
- AUD_THROW(AUD_ERROR_SPECS, specs_error);
- }
}
AUD_DoubleReader::~AUD_DoubleReader()
{
- delete m_reader1;
- delete m_reader2;
}
bool AUD_DoubleReader::isSeekable() const
@@ -90,43 +79,36 @@ int AUD_DoubleReader::getPosition() const
AUD_Specs AUD_DoubleReader::getSpecs() const
{
- return m_reader1->getSpecs();
+ return m_finished1 ? m_reader1->getSpecs() : m_reader2->getSpecs();
}
-void AUD_DoubleReader::read(int & length, sample_t* & buffer)
+void AUD_DoubleReader::read(int& length, bool& eos, sample_t* buffer)
{
+ eos = false;
+
if(!m_finished1)
{
int len = length;
- m_reader1->read(len, buffer);
+
+ m_reader1->read(len, m_finished1, buffer);
if(len < length)
{
- AUD_Specs specs = m_reader1->getSpecs();
- int samplesize = AUD_SAMPLE_SIZE(specs);
-
- if(m_buffer.getSize() < length * samplesize)
- m_buffer.resize(length * samplesize);
-
- sample_t* buf = buffer;
- buffer = m_buffer.getBuffer();
-
- memcpy(buffer, buf, len * samplesize);
-
- len = length - len;
- length -= len;
- m_reader2->read(len, buf);
-
- memcpy(buffer + length * specs.channels, buf,
- len * samplesize);
-
- length += len;
-
- m_finished1 = true;
+ AUD_Specs specs1, specs2;
+ specs1 = m_reader1->getSpecs();
+ specs2 = m_reader2->getSpecs();
+ if(AUD_COMPARE_SPECS(specs1, specs2))
+ {
+ int len2 = length - len;
+ m_reader2->read(len2, eos, buffer + specs1.channels * len);
+ length = len + len2;
+ }
+ else
+ length = len;
}
}
else
{
- m_reader2->read(length, buffer);
+ m_reader2->read(length, eos, buffer);
}
}
diff --git a/intern/audaspace/FX/AUD_DoubleReader.h b/intern/audaspace/FX/AUD_DoubleReader.h
index 7b3b812ef80..750868a9400 100644
--- a/intern/audaspace/FX/AUD_DoubleReader.h
+++ b/intern/audaspace/FX/AUD_DoubleReader.h
@@ -34,9 +34,10 @@
#include "AUD_IReader.h"
#include "AUD_Buffer.h"
+#include "AUD_Reference.h"
/**
- * This reader plays two readers with the same specs sequently.
+ * This reader plays two readers sequently.
*/
class AUD_DoubleReader : public AUD_IReader
{
@@ -44,35 +45,29 @@ private:
/**
* The first reader.
*/
- AUD_IReader* m_reader1;
+ AUD_Reference m_reader1;
/**
* The second reader.
*/
- AUD_IReader* m_reader2;
+ AUD_Reference m_reader2;
/**
* Whether we've reached the end of the first reader.
*/
bool m_finished1;
- /**
- * The playback buffer for the intersecting part.
- */
- AUD_Buffer m_buffer;
-
// hide copy constructor and operator=
AUD_DoubleReader(const AUD_DoubleReader&);
AUD_DoubleReader& operator=(const AUD_DoubleReader&);
public:
/**
- * Creates a new ping pong reader.
+ * Creates a new double reader.
* \param reader1 The first reader to read from.
* \param reader2 The second reader to read from.
- * \exception AUD_Exception Thrown if the specs from the readers differ.
*/
- AUD_DoubleReader(AUD_IReader* reader1, AUD_IReader* reader2);
+ AUD_DoubleReader(AUD_Reference reader1, AUD_Reference reader2);
/**
* Destroys the reader.
@@ -84,7 +79,7 @@ public:
virtual int getLength() const;
virtual int getPosition() const;
virtual AUD_Specs getSpecs() const;
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_DOUBLEREADER
diff --git a/intern/audaspace/FX/AUD_EffectFactory.cpp b/intern/audaspace/FX/AUD_EffectFactory.cpp
index a0d9256e691..6173ffb5a97 100644
--- a/intern/audaspace/FX/AUD_EffectFactory.cpp
+++ b/intern/audaspace/FX/AUD_EffectFactory.cpp
@@ -32,7 +32,7 @@
#include "AUD_EffectFactory.h"
#include "AUD_IReader.h"
-AUD_EffectFactory::AUD_EffectFactory(AUD_IFactory* factory)
+AUD_EffectFactory::AUD_EffectFactory(AUD_Reference factory)
{
m_factory = factory;
}
@@ -41,7 +41,7 @@ AUD_EffectFactory::~AUD_EffectFactory()
{
}
-AUD_IFactory* AUD_EffectFactory::getFactory() const
+AUD_Reference AUD_EffectFactory::getFactory() const
{
return m_factory;
}
diff --git a/intern/audaspace/FX/AUD_EffectFactory.h b/intern/audaspace/FX/AUD_EffectFactory.h
index a6a28eea577..72fdb3f0833 100644
--- a/intern/audaspace/FX/AUD_EffectFactory.h
+++ b/intern/audaspace/FX/AUD_EffectFactory.h
@@ -49,7 +49,7 @@ protected:
/**
* If there is no reader it is created out of this factory.
*/
- AUD_IFactory* m_factory;
+ AUD_Reference m_factory;
/**
* Returns the reader created out of the factory.
@@ -57,7 +57,7 @@ protected:
* classes.
* \return The reader created out of the factory.
*/
- inline AUD_IReader* getReader() const
+ inline AUD_Reference getReader() const
{
return m_factory->createReader();
}
@@ -67,7 +67,7 @@ public:
* Creates a new factory.
* \param factory The input factory.
*/
- AUD_EffectFactory(AUD_IFactory* factory);
+ AUD_EffectFactory(AUD_Reference factory);
/**
* Destroys the factory.
@@ -78,7 +78,7 @@ public:
* Returns the saved factory.
* \return The factory or NULL if there has no factory been saved.
*/
- AUD_IFactory* getFactory() const;
+ AUD_Reference getFactory() const;
};
#endif //AUD_EFFECTFACTORY
diff --git a/intern/audaspace/FX/AUD_EffectReader.cpp b/intern/audaspace/FX/AUD_EffectReader.cpp
index 3ad9f67bfd6..4d14af76438 100644
--- a/intern/audaspace/FX/AUD_EffectReader.cpp
+++ b/intern/audaspace/FX/AUD_EffectReader.cpp
@@ -31,14 +31,13 @@
#include "AUD_EffectReader.h"
-AUD_EffectReader::AUD_EffectReader(AUD_IReader* reader)
+AUD_EffectReader::AUD_EffectReader(AUD_Reference reader)
{
m_reader = reader;
}
AUD_EffectReader::~AUD_EffectReader()
{
- delete m_reader;
}
bool AUD_EffectReader::isSeekable() const
@@ -66,7 +65,7 @@ AUD_Specs AUD_EffectReader::getSpecs() const
return m_reader->getSpecs();
}
-void AUD_EffectReader::read(int & length, sample_t* & buffer)
+void AUD_EffectReader::read(int& length, bool& eos, sample_t* buffer)
{
- m_reader->read(length, buffer);
+ m_reader->read(length, eos, buffer);
}
diff --git a/intern/audaspace/FX/AUD_EffectReader.h b/intern/audaspace/FX/AUD_EffectReader.h
index fb8066f36d8..c03abd11828 100644
--- a/intern/audaspace/FX/AUD_EffectReader.h
+++ b/intern/audaspace/FX/AUD_EffectReader.h
@@ -33,6 +33,7 @@
#define AUD_EFFECTREADER
#include "AUD_IReader.h"
+#include "AUD_Reference.h"
/**
* This reader is a base class for all effect readers that take one other reader
@@ -49,14 +50,14 @@ protected:
/**
* The reader to read from.
*/
- AUD_IReader* m_reader;
+ AUD_Reference m_reader;
public:
/**
* Creates a new effect reader.
* \param reader The reader to read from.
*/
- AUD_EffectReader(AUD_IReader* reader);
+ AUD_EffectReader(AUD_Reference reader);
/**
* Destroys the reader.
@@ -68,7 +69,7 @@ public:
virtual int getLength() const;
virtual int getPosition() const;
virtual AUD_Specs getSpecs() const;
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_EFFECTREADER
diff --git a/intern/audaspace/FX/AUD_EnvelopeFactory.cpp b/intern/audaspace/FX/AUD_EnvelopeFactory.cpp
index 069317d1c8b..80df7e9f874 100644
--- a/intern/audaspace/FX/AUD_EnvelopeFactory.cpp
+++ b/intern/audaspace/FX/AUD_EnvelopeFactory.cpp
@@ -42,7 +42,7 @@ struct EnvelopeParameters
float arthreshold;
};
-sample_t envelopeFilter(AUD_CallbackIIRFilterReader* reader, EnvelopeParameters* param)
+sample_t AUD_EnvelopeFactory::envelopeFilter(AUD_CallbackIIRFilterReader* reader, EnvelopeParameters* param)
{
float in = fabs(reader->x(0));
float out = reader->y(-1);
@@ -51,12 +51,12 @@ sample_t envelopeFilter(AUD_CallbackIIRFilterReader* reader, EnvelopeParameters*
return (in > out ? param->attack : param->release) * (out - in) + in;
}
-void endEnvelopeFilter(EnvelopeParameters* param)
+void AUD_EnvelopeFactory::endEnvelopeFilter(EnvelopeParameters* param)
{
delete param;
}
-AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
+AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_Reference factory, float attack,
float release, float threshold,
float arthreshold) :
AUD_EffectFactory(factory),
@@ -67,14 +67,14 @@ AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
{
}
-AUD_IReader* AUD_EnvelopeFactory::createReader() const
+AUD_Reference AUD_EnvelopeFactory::createReader()
{
- AUD_IReader* reader = getReader();
+ AUD_Reference reader = getReader();
EnvelopeParameters* param = new EnvelopeParameters();
param->arthreshold = m_arthreshold;
- param->attack = pow(m_arthreshold, 1.0f/(reader->getSpecs().rate * m_attack));
- param->release = pow(m_arthreshold, 1.0f/(reader->getSpecs().rate * m_release));
+ param->attack = pow(m_arthreshold, 1.0f/(static_cast(reader->getSpecs().rate) * m_attack));
+ param->release = pow(m_arthreshold, 1.0f/(static_cast(reader->getSpecs().rate) * m_release));
param->threshold = m_threshold;
return new AUD_CallbackIIRFilterReader(reader, 1, 2,
diff --git a/intern/audaspace/FX/AUD_EnvelopeFactory.h b/intern/audaspace/FX/AUD_EnvelopeFactory.h
index 45ee811b6e0..a480a05d478 100644
--- a/intern/audaspace/FX/AUD_EnvelopeFactory.h
+++ b/intern/audaspace/FX/AUD_EnvelopeFactory.h
@@ -33,6 +33,8 @@
#define AUD_ENVELOPEFACTORY
#include "AUD_EffectFactory.h"
+class AUD_CallbackIIRFilterReader;
+struct EnvelopeParameters;
/**
* This factory creates an envelope follower reader.
@@ -73,10 +75,13 @@ public:
* \param threshold The threshold value.
* \param arthreshold The attack/release threshold value.
*/
- AUD_EnvelopeFactory(AUD_IFactory* factory, float attack, float release,
+ AUD_EnvelopeFactory(AUD_Reference factory, float attack, float release,
float threshold, float arthreshold);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
+
+ static sample_t envelopeFilter(AUD_CallbackIIRFilterReader* reader, EnvelopeParameters* param);
+ static void endEnvelopeFilter(EnvelopeParameters* param);
};
#endif //AUD_ENVELOPEFACTORY
diff --git a/intern/audaspace/FX/AUD_FaderFactory.cpp b/intern/audaspace/FX/AUD_FaderFactory.cpp
index d887e9e68d9..635873e0ee5 100644
--- a/intern/audaspace/FX/AUD_FaderFactory.cpp
+++ b/intern/audaspace/FX/AUD_FaderFactory.cpp
@@ -32,7 +32,7 @@
#include "AUD_FaderFactory.h"
#include "AUD_FaderReader.h"
-AUD_FaderFactory::AUD_FaderFactory(AUD_IFactory* factory, AUD_FadeType type,
+AUD_FaderFactory::AUD_FaderFactory(AUD_Reference factory, AUD_FadeType type,
float start, float length) :
AUD_EffectFactory(factory),
m_type(type),
@@ -56,7 +56,7 @@ float AUD_FaderFactory::getLength() const
return m_length;
}
-AUD_IReader* AUD_FaderFactory::createReader() const
+AUD_Reference AUD_FaderFactory::createReader()
{
return new AUD_FaderReader(getReader(), m_type, m_start, m_length);
}
diff --git a/intern/audaspace/FX/AUD_FaderFactory.h b/intern/audaspace/FX/AUD_FaderFactory.h
index b85475bc534..d8314c77ed4 100644
--- a/intern/audaspace/FX/AUD_FaderFactory.h
+++ b/intern/audaspace/FX/AUD_FaderFactory.h
@@ -69,7 +69,7 @@ public:
* \param start The time where fading should start in seconds.
* \param length How long fading should last in seconds.
*/
- AUD_FaderFactory(AUD_IFactory* factory,
+ AUD_FaderFactory(AUD_Reference factory,
AUD_FadeType type = AUD_FADE_IN,
float start = 0.0f, float length = 1.0f);
@@ -88,7 +88,7 @@ public:
*/
float getLength() const;
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_FADERFACTORY
diff --git a/intern/audaspace/FX/AUD_FaderReader.cpp b/intern/audaspace/FX/AUD_FaderReader.cpp
index 6114bb486fc..4a6050cf0f3 100644
--- a/intern/audaspace/FX/AUD_FaderReader.cpp
+++ b/intern/audaspace/FX/AUD_FaderReader.cpp
@@ -33,68 +33,39 @@
#include
-AUD_FaderReader::AUD_FaderReader(AUD_IReader* reader, AUD_FadeType type,
+AUD_FaderReader::AUD_FaderReader(AUD_Reference reader, AUD_FadeType type,
float start,float length) :
AUD_EffectReader(reader),
m_type(type),
m_start(start),
- m_length(length),
- m_empty(true)
+ m_length(length)
{
}
-void AUD_FaderReader::read(int & length, sample_t* & buffer)
+void AUD_FaderReader::read(int& length, bool& eos, sample_t* buffer)
{
int position = m_reader->getPosition();
AUD_Specs specs = m_reader->getSpecs();
int samplesize = AUD_SAMPLE_SIZE(specs);
- m_reader->read(length, buffer);
+ m_reader->read(length, eos, buffer);
if((position + length) / (float)specs.rate <= m_start)
{
if(m_type != AUD_FADE_OUT)
{
- if(m_buffer.getSize() < length * samplesize)
- {
- m_buffer.resize(length * samplesize);
- m_empty = false;
- }
-
- buffer = m_buffer.getBuffer();
-
- if(!m_empty)
- {
- memset(buffer, 0, length * samplesize);
- m_empty = true;
- }
+ memset(buffer, 0, length * samplesize);
}
}
else if(position / (float)specs.rate >= m_start+m_length)
{
if(m_type == AUD_FADE_OUT)
{
- if(m_buffer.getSize() < length * samplesize)
- {
- m_buffer.resize(length * samplesize);
- m_empty = false;
- }
-
- buffer = m_buffer.getBuffer();
-
- if(!m_empty)
- {
- memset(buffer, 0, length * samplesize);
- m_empty = true;
- }
+ memset(buffer, 0, length * samplesize);
}
}
else
{
- if(m_buffer.getSize() < length * samplesize)
- m_buffer.resize(length * samplesize);
-
- sample_t* buf = m_buffer.getBuffer();
float volume = 1.0f;
for(int i = 0; i < length * specs.channels; i++)
@@ -111,10 +82,7 @@ void AUD_FaderReader::read(int & length, sample_t* & buffer)
volume = 1.0f - volume;
}
- buf[i] = buffer[i] * volume;
+ buffer[i] = buffer[i] * volume;
}
-
- buffer = buf;
- m_empty = false;
}
}
diff --git a/intern/audaspace/FX/AUD_FaderReader.h b/intern/audaspace/FX/AUD_FaderReader.h
index fb927192b45..e702ac0ec19 100644
--- a/intern/audaspace/FX/AUD_FaderReader.h
+++ b/intern/audaspace/FX/AUD_FaderReader.h
@@ -58,16 +58,6 @@ private:
*/
const float m_length;
- /**
- * The playback buffer.
- */
- AUD_Buffer m_buffer;
-
- /**
- * Whether the buffer is empty.
- */
- bool m_empty;
-
// hide copy constructor and operator=
AUD_FaderReader(const AUD_FaderReader&);
AUD_FaderReader& operator=(const AUD_FaderReader&);
@@ -79,10 +69,10 @@ public:
* \param start The time where fading should start in seconds.
* \param length How long fading should last in seconds.
*/
- AUD_FaderReader(AUD_IReader* reader, AUD_FadeType type,
+ AUD_FaderReader(AUD_Reference reader, AUD_FadeType type,
float start,float length);
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_FADERREADER
diff --git a/intern/audaspace/FX/AUD_HighpassFactory.cpp b/intern/audaspace/FX/AUD_HighpassFactory.cpp
index 61008eea44e..399ec5ca406 100644
--- a/intern/audaspace/FX/AUD_HighpassFactory.cpp
+++ b/intern/audaspace/FX/AUD_HighpassFactory.cpp
@@ -38,30 +38,26 @@
#define M_PI 3.14159265358979323846
#endif
-AUD_HighpassFactory::AUD_HighpassFactory(AUD_IFactory* factory, float frequency,
+AUD_HighpassFactory::AUD_HighpassFactory(AUD_Reference factory, float frequency,
float Q) :
- AUD_EffectFactory(factory),
+ AUD_DynamicIIRFilterFactory(factory),
m_frequency(frequency),
m_Q(Q)
{
}
-AUD_IReader* AUD_HighpassFactory::createReader() const
+void AUD_HighpassFactory::recalculateCoefficients(AUD_SampleRate rate,
+ std::vector &b,
+ std::vector &a)
{
- AUD_IReader* reader = getReader();
-
- // calculate coefficients
- float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
+ float w0 = 2 * M_PI * m_frequency / rate;
float alpha = sin(w0) / (2 * m_Q);
float norm = 1 + alpha;
float c = cos(w0);
- std::vector a, b;
a.push_back(1);
a.push_back(-2 * c / norm);
a.push_back((1 - alpha) / norm);
b.push_back((1 + c) / (2 * norm));
b.push_back((-1 - c) / norm);
b.push_back(b[0]);
-
- return new AUD_IIRFilterReader(reader, b, a);
}
diff --git a/intern/audaspace/FX/AUD_HighpassFactory.h b/intern/audaspace/FX/AUD_HighpassFactory.h
index 48f4c1baefc..c135be27d77 100644
--- a/intern/audaspace/FX/AUD_HighpassFactory.h
+++ b/intern/audaspace/FX/AUD_HighpassFactory.h
@@ -32,16 +32,16 @@
#ifndef AUD_HIGHPASSFACTORY
#define AUD_HIGHPASSFACTORY
-#include "AUD_EffectFactory.h"
+#include "AUD_DynamicIIRFilterFactory.h"
/**
* This factory creates a highpass filter reader.
*/
-class AUD_HighpassFactory : public AUD_EffectFactory
+class AUD_HighpassFactory : public AUD_DynamicIIRFilterFactory
{
private:
/**
- * The attack value in seconds.
+ * The cutoff frequency.
*/
const float m_frequency;
@@ -61,9 +61,9 @@ public:
* \param frequency The cutoff frequency.
* \param Q The Q factor.
*/
- AUD_HighpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f);
+ AUD_HighpassFactory(AUD_Reference factory, float frequency, float Q = 1.0f);
- virtual AUD_IReader* createReader() const;
+ virtual void recalculateCoefficients(AUD_SampleRate rate, std::vector &b, std::vector &a);
};
#endif //AUD_HIGHPASSFACTORY
diff --git a/intern/audaspace/FX/AUD_IIRFilterFactory.cpp b/intern/audaspace/FX/AUD_IIRFilterFactory.cpp
index ff90ce62739..f6ccda6f67e 100644
--- a/intern/audaspace/FX/AUD_IIRFilterFactory.cpp
+++ b/intern/audaspace/FX/AUD_IIRFilterFactory.cpp
@@ -32,14 +32,14 @@
#include "AUD_IIRFilterFactory.h"
#include "AUD_IIRFilterReader.h"
-AUD_IIRFilterFactory::AUD_IIRFilterFactory(AUD_IFactory* factory,
+AUD_IIRFilterFactory::AUD_IIRFilterFactory(AUD_Reference factory,
std::vector b,
std::vector a) :
AUD_EffectFactory(factory), m_a(a), m_b(b)
{
}
-AUD_IReader* AUD_IIRFilterFactory::createReader() const
+AUD_Reference AUD_IIRFilterFactory::createReader()
{
return new AUD_IIRFilterReader(getReader(), m_b, m_a);
}
diff --git a/intern/audaspace/FX/AUD_IIRFilterFactory.h b/intern/audaspace/FX/AUD_IIRFilterFactory.h
index d48ad453ee4..0e92ab1a568 100644
--- a/intern/audaspace/FX/AUD_IIRFilterFactory.h
+++ b/intern/audaspace/FX/AUD_IIRFilterFactory.h
@@ -63,10 +63,10 @@ public:
* \param b The input filter coefficients.
* \param a The output filter coefficients.
*/
- AUD_IIRFilterFactory(AUD_IFactory* factory, std::vector b,
+ AUD_IIRFilterFactory(AUD_Reference factory, std::vector b,
std::vector a);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_IIRFILTERFACTORY
diff --git a/intern/audaspace/FX/AUD_IIRFilterReader.cpp b/intern/audaspace/FX/AUD_IIRFilterReader.cpp
index 0d55421d2b4..1bfb9b97b62 100644
--- a/intern/audaspace/FX/AUD_IIRFilterReader.cpp
+++ b/intern/audaspace/FX/AUD_IIRFilterReader.cpp
@@ -31,9 +31,9 @@
#include "AUD_IIRFilterReader.h"
-AUD_IIRFilterReader::AUD_IIRFilterReader(AUD_IReader* reader,
- std::vector b,
- std::vector a) :
+AUD_IIRFilterReader::AUD_IIRFilterReader(AUD_Reference reader,
+ const std::vector& b,
+ const std::vector& a) :
AUD_BaseIIRFilterReader(reader, b.size(), a.size()), m_a(a), m_b(b)
{
for(int i = 1; i < m_a.size(); i++)
@@ -54,3 +54,11 @@ sample_t AUD_IIRFilterReader::filter()
return out;
}
+
+void AUD_IIRFilterReader::setCoefficients(const std::vector& b,
+ const std::vector& a)
+{
+ setLengths(m_b.size(), m_a.size());
+ m_a = a;
+ m_b = b;
+}
diff --git a/intern/audaspace/FX/AUD_IIRFilterReader.h b/intern/audaspace/FX/AUD_IIRFilterReader.h
index af50b6f1cdc..41de67d4d27 100644
--- a/intern/audaspace/FX/AUD_IIRFilterReader.h
+++ b/intern/audaspace/FX/AUD_IIRFilterReader.h
@@ -63,10 +63,13 @@ public:
* \param b The input filter coefficients.
* \param a The output filter coefficients.
*/
- AUD_IIRFilterReader(AUD_IReader* reader, std::vector b,
- std::vector a);
+ AUD_IIRFilterReader(AUD_Reference reader, const std::vector& b,
+ const std::vector& a);
virtual sample_t filter();
+
+ void setCoefficients(const std::vector& b,
+ const std::vector& a);
};
#endif //AUD_IIRFILTERREADER
diff --git a/intern/audaspace/FX/AUD_LimiterFactory.cpp b/intern/audaspace/FX/AUD_LimiterFactory.cpp
index 62ea01bb761..8d1dd14f3ae 100644
--- a/intern/audaspace/FX/AUD_LimiterFactory.cpp
+++ b/intern/audaspace/FX/AUD_LimiterFactory.cpp
@@ -33,7 +33,7 @@
#include "AUD_LimiterReader.h"
#include "AUD_Space.h"
-AUD_LimiterFactory::AUD_LimiterFactory(AUD_IFactory* factory,
+AUD_LimiterFactory::AUD_LimiterFactory(AUD_Reference factory,
float start, float end) :
AUD_EffectFactory(factory),
m_start(start),
@@ -51,7 +51,7 @@ float AUD_LimiterFactory::getEnd() const
return m_end;
}
-AUD_IReader* AUD_LimiterFactory::createReader() const
+AUD_Reference AUD_LimiterFactory::createReader()
{
return new AUD_LimiterReader(getReader(), m_start, m_end);
}
diff --git a/intern/audaspace/FX/AUD_LimiterFactory.h b/intern/audaspace/FX/AUD_LimiterFactory.h
index f93f4b3276c..c04bfe861b2 100644
--- a/intern/audaspace/FX/AUD_LimiterFactory.h
+++ b/intern/audaspace/FX/AUD_LimiterFactory.h
@@ -62,7 +62,7 @@ public:
* \param end The desired end time, a negative value signals that it should
* play to the end.
*/
- AUD_LimiterFactory(AUD_IFactory* factory,
+ AUD_LimiterFactory(AUD_Reference factory,
float start = 0, float end = -1);
/**
@@ -75,7 +75,7 @@ public:
*/
float getEnd() const;
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_LIMITERFACTORY
diff --git a/intern/audaspace/FX/AUD_LimiterReader.cpp b/intern/audaspace/FX/AUD_LimiterReader.cpp
index d67fbb4d0e5..dc31477d2eb 100644
--- a/intern/audaspace/FX/AUD_LimiterReader.cpp
+++ b/intern/audaspace/FX/AUD_LimiterReader.cpp
@@ -32,30 +32,46 @@
#include "AUD_LimiterReader.h"
#include "AUD_Buffer.h"
-#include
-
-AUD_LimiterReader::AUD_LimiterReader(AUD_IReader* reader,
+AUD_LimiterReader::AUD_LimiterReader(AUD_Reference reader,
float start, float end) :
AUD_EffectReader(reader),
- m_start(int(start * reader->getSpecs().rate)),
- m_end(int(end * reader->getSpecs().rate))
+ m_start(start),
+ m_end(end)
{
if(m_start > 0)
{
+ AUD_Specs specs = m_reader->getSpecs();
+ AUD_Specs specs2;
+
if(m_reader->isSeekable())
- m_reader->seek(m_start);
+ m_reader->seek(m_start * specs.rate);
else
{
// skip first m_start samples by reading them
int length = AUD_DEFAULT_BUFFER_SIZE;
- sample_t* buffer;
- for(int len = m_start;
- length == AUD_DEFAULT_BUFFER_SIZE;
- len -= AUD_DEFAULT_BUFFER_SIZE)
+ AUD_Buffer buffer(AUD_DEFAULT_BUFFER_SIZE * AUD_SAMPLE_SIZE(specs));
+ bool eos = false;
+ for(int len = m_start * specs.rate;
+ length > 0 && !eos;
+ len -= length)
{
if(len < AUD_DEFAULT_BUFFER_SIZE)
length = len;
- m_reader->read(length, buffer);
+
+ m_reader->read(length, eos, buffer.getBuffer());
+
+ specs2 = m_reader->getSpecs();
+ if(specs2.rate != specs.rate)
+ {
+ len = len * specs2.rate / specs.rate;
+ specs.rate = specs2.rate;
+ }
+
+ if(specs2.channels != specs.channels)
+ {
+ specs = specs2;
+ buffer.assureSize(AUD_DEFAULT_BUFFER_SIZE * AUD_SAMPLE_SIZE(specs));
+ }
}
}
}
@@ -63,35 +79,71 @@ AUD_LimiterReader::AUD_LimiterReader(AUD_IReader* reader,
void AUD_LimiterReader::seek(int position)
{
- m_reader->seek(position + m_start);
+ m_reader->seek(position + m_start * m_reader->getSpecs().rate);
}
int AUD_LimiterReader::getLength() const
{
int len = m_reader->getLength();
- if(len < 0 || (len > m_end && m_end >= 0))
- len = m_end;
- return len - m_start;
+ AUD_SampleRate rate = m_reader->getSpecs().rate;
+ if(len < 0 || (len > m_end * rate && m_end >= 0))
+ len = m_end * rate;
+ return len - m_start * rate;
}
int AUD_LimiterReader::getPosition() const
{
int pos = m_reader->getPosition();
- return AUD_MIN(pos, m_end) - m_start;
+ AUD_SampleRate rate = m_reader->getSpecs().rate;
+ return AUD_MIN(pos, m_end * rate) - m_start * rate;
}
-void AUD_LimiterReader::read(int & length, sample_t* & buffer)
+void AUD_LimiterReader::read(int& length, bool& eos, sample_t* buffer)
{
+ eos = false;
if(m_end >= 0)
{
int position = m_reader->getPosition();
- if(position + length > m_end)
- length = m_end - position;
+ AUD_SampleRate rate = m_reader->getSpecs().rate;
+
+ if(position + length > m_end * rate)
+ {
+ length = m_end * rate - position;
+ eos = true;
+ }
+
+ if(position < m_start * rate)
+ {
+ int len2 = length;
+ for(int len = m_start * rate - position;
+ len2 == length && !eos;
+ len -= length)
+ {
+ if(len < length)
+ len2 = len;
+
+ m_reader->read(len2, eos, buffer);
+ position += len2;
+ }
+
+ if(position < m_start * rate)
+ {
+ length = 0;
+ return;
+ }
+ }
+
if(length < 0)
{
length = 0;
return;
}
}
- m_reader->read(length, buffer);
+ if(eos)
+ {
+ m_reader->read(length, eos, buffer);
+ eos = true;
+ }
+ else
+ m_reader->read(length, eos, buffer);
}
diff --git a/intern/audaspace/FX/AUD_LimiterReader.h b/intern/audaspace/FX/AUD_LimiterReader.h
index 4375ed9e10d..9cddd4d57ec 100644
--- a/intern/audaspace/FX/AUD_LimiterReader.h
+++ b/intern/audaspace/FX/AUD_LimiterReader.h
@@ -35,7 +35,7 @@
#include "AUD_EffectReader.h"
/**
- * This reader limits another reader in start and end sample.
+ * This reader limits another reader in start and end times.
*/
class AUD_LimiterReader : public AUD_EffectReader
{
@@ -43,12 +43,12 @@ private:
/**
* The start sample: inclusive.
*/
- const int m_start;
+ const float m_start;
/**
* The end sample: exlusive.
*/
- const int m_end;
+ const float m_end;
// hide copy constructor and operator=
AUD_LimiterReader(const AUD_LimiterReader&);
@@ -58,16 +58,16 @@ public:
/**
* Creates a new limiter reader.
* \param reader The reader to read from.
- * \param start The desired start sample (inclusive).
- * \param end The desired end sample (exklusive), a negative value signals
- * that it should play to the end.
+ * \param start The desired start time (inclusive).
+ * \param end The desired end time (sample exklusive), a negative value
+ * signals that it should play to the end.
*/
- AUD_LimiterReader(AUD_IReader* reader, float start = 0, float end = -1);
+ AUD_LimiterReader(AUD_Reference reader, float start = 0, float end = -1);
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_LIMITERREADER
diff --git a/intern/audaspace/FX/AUD_LoopFactory.cpp b/intern/audaspace/FX/AUD_LoopFactory.cpp
index 49d3481757f..fd39ac901c1 100644
--- a/intern/audaspace/FX/AUD_LoopFactory.cpp
+++ b/intern/audaspace/FX/AUD_LoopFactory.cpp
@@ -32,7 +32,7 @@
#include "AUD_LoopFactory.h"
#include "AUD_LoopReader.h"
-AUD_LoopFactory::AUD_LoopFactory(AUD_IFactory* factory, int loop) :
+AUD_LoopFactory::AUD_LoopFactory(AUD_Reference factory, int loop) :
AUD_EffectFactory(factory),
m_loop(loop)
{
@@ -43,7 +43,7 @@ int AUD_LoopFactory::getLoop() const
return m_loop;
}
-AUD_IReader* AUD_LoopFactory::createReader() const
+AUD_Reference AUD_LoopFactory::createReader()
{
return new AUD_LoopReader(getReader(), m_loop);
}
diff --git a/intern/audaspace/FX/AUD_LoopFactory.h b/intern/audaspace/FX/AUD_LoopFactory.h
index dfbbbe4fd20..03c00dc40ce 100644
--- a/intern/audaspace/FX/AUD_LoopFactory.h
+++ b/intern/audaspace/FX/AUD_LoopFactory.h
@@ -57,14 +57,14 @@ public:
* \param loop The desired loop count, negative values result in endless
* looping.
*/
- AUD_LoopFactory(AUD_IFactory* factory, int loop = -1);
+ AUD_LoopFactory(AUD_Reference factory, int loop = -1);
/**
* Returns the loop count.
*/
int getLoop() const;
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_LOOPFACTORY
diff --git a/intern/audaspace/FX/AUD_LoopReader.cpp b/intern/audaspace/FX/AUD_LoopReader.cpp
index b2e8e97a602..de67a445ab2 100644
--- a/intern/audaspace/FX/AUD_LoopReader.cpp
+++ b/intern/audaspace/FX/AUD_LoopReader.cpp
@@ -34,7 +34,7 @@
#include
-AUD_LoopReader::AUD_LoopReader(AUD_IReader* reader, int loop) :
+AUD_LoopReader::AUD_LoopReader(AUD_Reference reader, int loop) :
AUD_EffectReader(reader), m_count(loop), m_left(loop)
{
}
@@ -68,29 +68,20 @@ int AUD_LoopReader::getPosition() const
return m_reader->getPosition() * (m_count < 0 ? 1 : m_count);
}
-void AUD_LoopReader::read(int & length, sample_t* & buffer)
+void AUD_LoopReader::read(int& length, bool& eos, sample_t* buffer)
{
- AUD_Specs specs = m_reader->getSpecs();
- int samplesize = AUD_SAMPLE_SIZE(specs);
+ const AUD_Specs specs = m_reader->getSpecs();
int len = length;
- m_reader->read(len, buffer);
+ m_reader->read(length, eos, buffer);
- if(len < length && m_left)
+ if(length < len && eos && m_left)
{
- int pos = 0;
+ int pos = length;
+ length = len;
- if(m_buffer.getSize() < length * samplesize)
- m_buffer.resize(length * samplesize);
-
- sample_t* buf = m_buffer.getBuffer();
-
- memcpy(buf + pos * specs.channels, buffer, len * samplesize);
-
- pos += len;
-
- while(pos < length && m_left)
+ while(pos < length && eos && m_left)
{
if(m_left > 0)
m_left--;
@@ -98,20 +89,15 @@ void AUD_LoopReader::read(int & length, sample_t* & buffer)
m_reader->seek(0);
len = length - pos;
- m_reader->read(len, buffer);
+ m_reader->read(len, eos, buffer + pos * specs.channels);
// prevent endless loop
if(!len)
break;
- memcpy(buf + pos * specs.channels, buffer, len * samplesize);
-
pos += len;
}
length = pos;
- buffer = buf;
}
- else
- length = len;
}
diff --git a/intern/audaspace/FX/AUD_LoopReader.h b/intern/audaspace/FX/AUD_LoopReader.h
index 45017901c56..5ccf7e543a0 100644
--- a/intern/audaspace/FX/AUD_LoopReader.h
+++ b/intern/audaspace/FX/AUD_LoopReader.h
@@ -42,11 +42,6 @@
class AUD_LoopReader : public AUD_EffectReader
{
private:
- /**
- * The playback buffer.
- */
- AUD_Buffer m_buffer;
-
/**
* The loop count.
*/
@@ -68,12 +63,12 @@ public:
* \param loop The desired loop count, negative values result in endless
* looping.
*/
- AUD_LoopReader(AUD_IReader* reader, int loop);
+ AUD_LoopReader(AUD_Reference reader, int loop);
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_LOOPREADER
diff --git a/intern/audaspace/FX/AUD_LowpassFactory.cpp b/intern/audaspace/FX/AUD_LowpassFactory.cpp
index d24a04b5a94..3ef25c3c16e 100644
--- a/intern/audaspace/FX/AUD_LowpassFactory.cpp
+++ b/intern/audaspace/FX/AUD_LowpassFactory.cpp
@@ -38,30 +38,26 @@
#define M_PI 3.14159265358979323846
#endif
-AUD_LowpassFactory::AUD_LowpassFactory(AUD_IFactory* factory, float frequency,
+AUD_LowpassFactory::AUD_LowpassFactory(AUD_Reference factory, float frequency,
float Q) :
- AUD_EffectFactory(factory),
+ AUD_DynamicIIRFilterFactory(factory),
m_frequency(frequency),
m_Q(Q)
{
}
-AUD_IReader* AUD_LowpassFactory::createReader() const
+void AUD_LowpassFactory::recalculateCoefficients(AUD_SampleRate rate,
+ std::vector &b,
+ std::vector &a)
{
- AUD_IReader* reader = getReader();
-
- // calculate coefficients
- float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
+ float w0 = 2 * M_PI * m_frequency / rate;
float alpha = sin(w0) / (2 * m_Q);
float norm = 1 + alpha;
float c = cos(w0);
- std::vector a, b;
a.push_back(1);
a.push_back(-2 * c / norm);
a.push_back((1 - alpha) / norm);
b.push_back((1 - c) / (2 * norm));
b.push_back((1 - c) / norm);
b.push_back(b[0]);
-
- return new AUD_IIRFilterReader(reader, b, a);
}
diff --git a/intern/audaspace/FX/AUD_LowpassFactory.h b/intern/audaspace/FX/AUD_LowpassFactory.h
index d60c0bd22d1..644d25ec73d 100644
--- a/intern/audaspace/FX/AUD_LowpassFactory.h
+++ b/intern/audaspace/FX/AUD_LowpassFactory.h
@@ -32,16 +32,16 @@
#ifndef AUD_LOWPASSFACTORY
#define AUD_LOWPASSFACTORY
-#include "AUD_EffectFactory.h"
+#include "AUD_DynamicIIRFilterFactory.h"
/**
* This factory creates a lowpass filter reader.
*/
-class AUD_LowpassFactory : public AUD_EffectFactory
+class AUD_LowpassFactory : public AUD_DynamicIIRFilterFactory
{
private:
/**
- * The attack value in seconds.
+ * The cutoff frequency.
*/
const float m_frequency;
@@ -61,9 +61,9 @@ public:
* \param frequency The cutoff frequency.
* \param Q The Q factor.
*/
- AUD_LowpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f);
+ AUD_LowpassFactory(AUD_Reference factory, float frequency, float Q = 1.0f);
- virtual AUD_IReader* createReader() const;
+ virtual void recalculateCoefficients(AUD_SampleRate rate, std::vector &b, std::vector &a);
};
#endif //AUD_LOWPASSFACTORY
diff --git a/intern/audaspace/FX/AUD_PingPongFactory.cpp b/intern/audaspace/FX/AUD_PingPongFactory.cpp
index fa140555943..e5f2193ea56 100644
--- a/intern/audaspace/FX/AUD_PingPongFactory.cpp
+++ b/intern/audaspace/FX/AUD_PingPongFactory.cpp
@@ -33,26 +33,16 @@
#include "AUD_DoubleReader.h"
#include "AUD_ReverseFactory.h"
-AUD_PingPongFactory::AUD_PingPongFactory(AUD_IFactory* factory) :
+AUD_PingPongFactory::AUD_PingPongFactory(AUD_Reference factory) :
AUD_EffectFactory(factory)
{
}
-AUD_IReader* AUD_PingPongFactory::createReader() const
+AUD_Reference AUD_PingPongFactory::createReader()
{
- AUD_IReader* reader = getReader();
- AUD_IReader* reader2;
+ AUD_Reference reader = getReader();
AUD_ReverseFactory factory(m_factory);
-
- try
- {
- reader2 = factory.createReader();
- }
- catch(AUD_Exception&)
- {
- delete reader;
- throw;
- }
+ AUD_Reference reader2 = factory.createReader();
return new AUD_DoubleReader(reader, reader2);
}
diff --git a/intern/audaspace/FX/AUD_PingPongFactory.h b/intern/audaspace/FX/AUD_PingPongFactory.h
index 4ae0c494eb7..b023501d45b 100644
--- a/intern/audaspace/FX/AUD_PingPongFactory.h
+++ b/intern/audaspace/FX/AUD_PingPongFactory.h
@@ -36,7 +36,7 @@
/**
* This factory plays another factory first normal, then reversed.
- * \note Readers from the underlying factory must be from the buffer type.
+ * \note Readers from the underlying factory must be reversable with seeking.
*/
class AUD_PingPongFactory : public AUD_EffectFactory
{
@@ -50,9 +50,9 @@ public:
* Creates a new ping pong factory.
* \param factory The input factory.
*/
- AUD_PingPongFactory(AUD_IFactory* factory);
+ AUD_PingPongFactory(AUD_Reference factory);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_PINGPONGFACTORY
diff --git a/intern/audaspace/FX/AUD_PitchFactory.cpp b/intern/audaspace/FX/AUD_PitchFactory.cpp
index b4ae8582caf..e52028754e9 100644
--- a/intern/audaspace/FX/AUD_PitchFactory.cpp
+++ b/intern/audaspace/FX/AUD_PitchFactory.cpp
@@ -33,13 +33,13 @@
#include "AUD_PitchReader.h"
#include "AUD_Space.h"
-AUD_PitchFactory::AUD_PitchFactory(AUD_IFactory* factory, float pitch) :
+AUD_PitchFactory::AUD_PitchFactory(AUD_Reference factory, float pitch) :
AUD_EffectFactory(factory),
m_pitch(pitch)
{
}
-AUD_IReader* AUD_PitchFactory::createReader() const
+AUD_Reference AUD_PitchFactory::createReader()
{
return new AUD_PitchReader(getReader(), m_pitch);
}
diff --git a/intern/audaspace/FX/AUD_PitchFactory.h b/intern/audaspace/FX/AUD_PitchFactory.h
index 8fa5be9293f..2642d41af89 100644
--- a/intern/audaspace/FX/AUD_PitchFactory.h
+++ b/intern/audaspace/FX/AUD_PitchFactory.h
@@ -55,9 +55,9 @@ public:
* \param factory The input factory.
* \param pitch The desired pitch.
*/
- AUD_PitchFactory(AUD_IFactory* factory, float pitch);
+ AUD_PitchFactory(AUD_Reference factory, float pitch);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_PITCHFACTORY
diff --git a/intern/audaspace/FX/AUD_PitchReader.cpp b/intern/audaspace/FX/AUD_PitchReader.cpp
index e2e89e2c457..81dd6e4355c 100644
--- a/intern/audaspace/FX/AUD_PitchReader.cpp
+++ b/intern/audaspace/FX/AUD_PitchReader.cpp
@@ -31,7 +31,7 @@
#include "AUD_PitchReader.h"
-AUD_PitchReader::AUD_PitchReader(AUD_IReader* reader, float pitch) :
+AUD_PitchReader::AUD_PitchReader(AUD_Reference reader, float pitch) :
AUD_EffectReader(reader), m_pitch(pitch)
{
}
@@ -39,6 +39,16 @@ AUD_PitchReader::AUD_PitchReader(AUD_IReader* reader, float pitch) :
AUD_Specs AUD_PitchReader::getSpecs() const
{
AUD_Specs specs = m_reader->getSpecs();
- specs.rate = (AUD_SampleRate)((int)(specs.rate * m_pitch));
+ specs.rate *= m_pitch;
return specs;
}
+
+float AUD_PitchReader::getPitch() const
+{
+ return m_pitch;
+}
+
+void AUD_PitchReader::setPitch(float pitch)
+{
+ m_pitch = pitch;
+}
diff --git a/intern/audaspace/FX/AUD_PitchReader.h b/intern/audaspace/FX/AUD_PitchReader.h
index 120cebc58be..ed6adbf02fb 100644
--- a/intern/audaspace/FX/AUD_PitchReader.h
+++ b/intern/audaspace/FX/AUD_PitchReader.h
@@ -43,7 +43,7 @@ private:
/**
* The pitch level.
*/
- const float m_pitch;
+ float m_pitch;
// hide copy constructor and operator=
AUD_PitchReader(const AUD_PitchReader&);
@@ -53,11 +53,23 @@ public:
/**
* Creates a new pitch reader.
* \param reader The reader to read from.
- * \param pitch The size of the buffer.
+ * \param pitch The pitch value.
*/
- AUD_PitchReader(AUD_IReader* reader, float pitch);
+ AUD_PitchReader(AUD_Reference reader, float pitch);
virtual AUD_Specs getSpecs() const;
+
+ /**
+ * Retrieves the pitch.
+ * \return The current pitch value.
+ */
+ float getPitch() const;
+
+ /**
+ * Sets the pitch.
+ * \param pitch The new pitch value.
+ */
+ void setPitch(float pitch);
};
#endif //AUD_PITCHREADER
diff --git a/intern/audaspace/FX/AUD_RectifyFactory.cpp b/intern/audaspace/FX/AUD_RectifyFactory.cpp
index 609d827cce4..cbb676a9a32 100644
--- a/intern/audaspace/FX/AUD_RectifyFactory.cpp
+++ b/intern/audaspace/FX/AUD_RectifyFactory.cpp
@@ -34,17 +34,17 @@
#include
-sample_t rectifyFilter(AUD_CallbackIIRFilterReader* reader, void* useless)
+sample_t AUD_RectifyFactory::rectifyFilter(AUD_CallbackIIRFilterReader* reader, void* useless)
{
return fabs(reader->x(0));
}
-AUD_RectifyFactory::AUD_RectifyFactory(AUD_IFactory* factory) :
+AUD_RectifyFactory::AUD_RectifyFactory(AUD_Reference factory) :
AUD_EffectFactory(factory)
{
}
-AUD_IReader* AUD_RectifyFactory::createReader() const
+AUD_Reference AUD_RectifyFactory::createReader()
{
return new AUD_CallbackIIRFilterReader(getReader(), 1, 1, rectifyFilter);
}
diff --git a/intern/audaspace/FX/AUD_RectifyFactory.h b/intern/audaspace/FX/AUD_RectifyFactory.h
index c3529c7beef..16b44469c05 100644
--- a/intern/audaspace/FX/AUD_RectifyFactory.h
+++ b/intern/audaspace/FX/AUD_RectifyFactory.h
@@ -33,6 +33,7 @@
#define AUD_RECTIFYFACTORY
#include "AUD_EffectFactory.h"
+class AUD_CallbackIIRFilterReader;
/**
* This factory rectifies another factory.
@@ -49,9 +50,11 @@ public:
* Creates a new rectify factory.
* \param factory The input factory.
*/
- AUD_RectifyFactory(AUD_IFactory* factory);
+ AUD_RectifyFactory(AUD_Reference factory);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
+
+ static sample_t rectifyFilter(AUD_CallbackIIRFilterReader* reader, void* useless);
};
#endif //AUD_RECTIFYFACTORY
diff --git a/intern/audaspace/FX/AUD_ReverseFactory.cpp b/intern/audaspace/FX/AUD_ReverseFactory.cpp
index 22b12e31420..060a618dd68 100644
--- a/intern/audaspace/FX/AUD_ReverseFactory.cpp
+++ b/intern/audaspace/FX/AUD_ReverseFactory.cpp
@@ -33,12 +33,12 @@
#include "AUD_ReverseReader.h"
#include "AUD_Space.h"
-AUD_ReverseFactory::AUD_ReverseFactory(AUD_IFactory* factory) :
+AUD_ReverseFactory::AUD_ReverseFactory(AUD_Reference factory) :
AUD_EffectFactory(factory)
{
}
-AUD_IReader* AUD_ReverseFactory::createReader() const
+AUD_Reference AUD_ReverseFactory::createReader()
{
return new AUD_ReverseReader(getReader());
}
diff --git a/intern/audaspace/FX/AUD_ReverseFactory.h b/intern/audaspace/FX/AUD_ReverseFactory.h
index 7b20546302e..f43d37d8f46 100644
--- a/intern/audaspace/FX/AUD_ReverseFactory.h
+++ b/intern/audaspace/FX/AUD_ReverseFactory.h
@@ -36,7 +36,7 @@
/**
* This factory reads another factory reverted.
- * \note Readers from the underlying factory must be from the buffer type.
+ * \note Readers from the underlying factory must be seekable.
*/
class AUD_ReverseFactory : public AUD_EffectFactory
{
@@ -50,9 +50,9 @@ public:
* Creates a new reverse factory.
* \param factory The input factory.
*/
- AUD_ReverseFactory(AUD_IFactory* factory);
+ AUD_ReverseFactory(AUD_Reference factory);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_REVERSEFACTORY
diff --git a/intern/audaspace/FX/AUD_ReverseReader.cpp b/intern/audaspace/FX/AUD_ReverseReader.cpp
index a4a03936c76..73f6830f3fa 100644
--- a/intern/audaspace/FX/AUD_ReverseReader.cpp
+++ b/intern/audaspace/FX/AUD_ReverseReader.cpp
@@ -36,7 +36,7 @@
static const char* props_error = "AUD_ReverseReader: The reader has to be "
"seekable and a finite length.";
-AUD_ReverseReader::AUD_ReverseReader(AUD_IReader* reader) :
+AUD_ReverseReader::AUD_ReverseReader(AUD_Reference reader) :
AUD_EffectReader(reader),
m_length(reader->getLength()),
m_position(0)
@@ -60,7 +60,7 @@ int AUD_ReverseReader::getPosition() const
return m_position;
}
-void AUD_ReverseReader::read(int & length, sample_t* & buffer)
+void AUD_ReverseReader::read(int& length, bool& eos, sample_t* buffer)
{
// first correct the length
if(m_position + length > m_length)
@@ -69,39 +69,39 @@ void AUD_ReverseReader::read(int & length, sample_t* & buffer)
if(length <= 0)
{
length = 0;
+ eos = true;
return;
}
- AUD_Specs specs = getSpecs();
- int samplesize = AUD_SAMPLE_SIZE(specs);
+ const AUD_Specs specs = getSpecs();
+ const int samplesize = AUD_SAMPLE_SIZE(specs);
- // resize buffer if needed
- if(m_buffer.getSize() < length * samplesize)
- m_buffer.resize(length * samplesize);
+ sample_t temp[AUD_CHANNEL_MAX];
- buffer = m_buffer.getBuffer();
-
- sample_t* buf;
int len = length;
// read from reader
m_reader->seek(m_length - m_position - len);
- m_reader->read(len, buf);
+ m_reader->read(len, eos, buffer);
// set null if reader didn't give enough data
if(len < length)
- {
memset(buffer, 0, (length - len) * samplesize);
- buffer += (length - len) * specs.channels;
- }
// copy the samples reverted
- for(int i = 0; i < len; i++)
- memcpy(buffer + i * specs.channels,
- buf + (len - 1 - i) * specs.channels,
+ for(int i = 0; i < length / 2; i++)
+ {
+ memcpy(temp,
+ buffer + (len - 1 - i) * specs.channels,
samplesize);
+ memcpy(buffer + (len - 1 - i) * specs.channels,
+ buffer + i * specs.channels,
+ samplesize);
+ memcpy(buffer + i * specs.channels,
+ temp,
+ samplesize);
+ }
m_position += length;
-
- buffer = m_buffer.getBuffer();
+ eos = false;
}
diff --git a/intern/audaspace/FX/AUD_ReverseReader.h b/intern/audaspace/FX/AUD_ReverseReader.h
index e12f2b21191..197d10dfe00 100644
--- a/intern/audaspace/FX/AUD_ReverseReader.h
+++ b/intern/audaspace/FX/AUD_ReverseReader.h
@@ -37,7 +37,7 @@
/**
* This class reads another reader from back to front.
- * \note The underlying reader must be a buffer.
+ * \note The underlying reader must be seekable.
*/
class AUD_ReverseReader : public AUD_EffectReader
{
@@ -52,11 +52,6 @@ private:
*/
int m_position;
- /**
- * The playback buffer.
- */
- AUD_Buffer m_buffer;
-
// hide copy constructor and operator=
AUD_ReverseReader(const AUD_ReverseReader&);
AUD_ReverseReader& operator=(const AUD_ReverseReader&);
@@ -68,12 +63,12 @@ public:
* \exception AUD_Exception Thrown if the reader specified has an
* undeterminable/infinite length or is not seekable.
*/
- AUD_ReverseReader(AUD_IReader* reader);
+ AUD_ReverseReader(AUD_Reference reader);
virtual void seek(int position);
virtual int getLength() const;
virtual int getPosition() const;
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_REVERSEREADER
diff --git a/intern/audaspace/FX/AUD_SquareFactory.cpp b/intern/audaspace/FX/AUD_SquareFactory.cpp
index a075773d2cb..226085a1814 100644
--- a/intern/audaspace/FX/AUD_SquareFactory.cpp
+++ b/intern/audaspace/FX/AUD_SquareFactory.cpp
@@ -32,7 +32,7 @@
#include "AUD_SquareFactory.h"
#include "AUD_CallbackIIRFilterReader.h"
-sample_t squareFilter(AUD_CallbackIIRFilterReader* reader, float* threshold)
+sample_t AUD_SquareFactory::squareFilter(AUD_CallbackIIRFilterReader* reader, float* threshold)
{
float in = reader->x(0);
if(in >= *threshold)
@@ -43,12 +43,12 @@ sample_t squareFilter(AUD_CallbackIIRFilterReader* reader, float* threshold)
return 0;
}
-void endSquareFilter(float* threshold)
+void AUD_SquareFactory::endSquareFilter(float* threshold)
{
delete threshold;
}
-AUD_SquareFactory::AUD_SquareFactory(AUD_IFactory* factory, float threshold) :
+AUD_SquareFactory::AUD_SquareFactory(AUD_Reference factory, float threshold) :
AUD_EffectFactory(factory),
m_threshold(threshold)
{
@@ -59,7 +59,7 @@ float AUD_SquareFactory::getThreshold() const
return m_threshold;
}
-AUD_IReader* AUD_SquareFactory::createReader() const
+AUD_Reference AUD_SquareFactory::createReader()
{
return new AUD_CallbackIIRFilterReader(getReader(), 1, 1,
(doFilterIIR) squareFilter,
diff --git a/intern/audaspace/FX/AUD_SquareFactory.h b/intern/audaspace/FX/AUD_SquareFactory.h
index 8060e98e281..21284361cca 100644
--- a/intern/audaspace/FX/AUD_SquareFactory.h
+++ b/intern/audaspace/FX/AUD_SquareFactory.h
@@ -33,6 +33,7 @@
#define AUD_SQUAREFACTORY
#include "AUD_EffectFactory.h"
+class AUD_CallbackIIRFilterReader;
/**
* This factory Transforms any signal to a square signal.
@@ -55,14 +56,17 @@ public:
* \param factory The input factory.
* \param threshold The threshold.
*/
- AUD_SquareFactory(AUD_IFactory* factory, float threshold = 0.0f);
+ AUD_SquareFactory(AUD_Reference factory, float threshold = 0.0f);
/**
* Returns the threshold.
*/
float getThreshold() const;
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
+
+ static sample_t squareFilter(AUD_CallbackIIRFilterReader* reader, float* threshold);
+ static void endSquareFilter(float* threshold);
};
#endif //AUD_SQUAREFACTORY
diff --git a/intern/audaspace/FX/AUD_SumFactory.cpp b/intern/audaspace/FX/AUD_SumFactory.cpp
index 6d8368d6e35..befcc30360f 100644
--- a/intern/audaspace/FX/AUD_SumFactory.cpp
+++ b/intern/audaspace/FX/AUD_SumFactory.cpp
@@ -32,12 +32,12 @@
#include "AUD_SumFactory.h"
#include "AUD_IIRFilterReader.h"
-AUD_SumFactory::AUD_SumFactory(AUD_IFactory* factory) :
+AUD_SumFactory::AUD_SumFactory(AUD_Reference factory) :
AUD_EffectFactory(factory)
{
}
-AUD_IReader* AUD_SumFactory::createReader() const
+AUD_Reference AUD_SumFactory::createReader()
{
std::vector a, b;
a.push_back(1);
diff --git a/intern/audaspace/FX/AUD_SumFactory.h b/intern/audaspace/FX/AUD_SumFactory.h
index ed19a0f258a..cdb4caf6e49 100644
--- a/intern/audaspace/FX/AUD_SumFactory.h
+++ b/intern/audaspace/FX/AUD_SumFactory.h
@@ -49,9 +49,9 @@ public:
* Creates a new sum factory.
* \param factory The input factory.
*/
- AUD_SumFactory(AUD_IFactory* factory);
+ AUD_SumFactory(AUD_Reference factory);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_SUMFACTORY
diff --git a/intern/audaspace/FX/AUD_SuperposeFactory.cpp b/intern/audaspace/FX/AUD_SuperposeFactory.cpp
index c13a0d0dd95..d514bfd8fca 100644
--- a/intern/audaspace/FX/AUD_SuperposeFactory.cpp
+++ b/intern/audaspace/FX/AUD_SuperposeFactory.cpp
@@ -32,24 +32,15 @@
#include "AUD_SuperposeFactory.h"
#include "AUD_SuperposeReader.h"
-AUD_SuperposeFactory::AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
+AUD_SuperposeFactory::AUD_SuperposeFactory(AUD_Reference factory1, AUD_Reference factory2) :
m_factory1(factory1), m_factory2(factory2)
{
}
-AUD_IReader* AUD_SuperposeFactory::createReader() const
+AUD_Reference AUD_SuperposeFactory::createReader()
{
- AUD_IReader* reader1 = m_factory1->createReader();
- AUD_IReader* reader2;
- try
- {
- reader2 = m_factory2->createReader();
- }
- catch(AUD_Exception&)
- {
- delete reader1;
- throw;
- }
+ AUD_Reference reader1 = m_factory1->createReader();
+ AUD_Reference reader2 = m_factory2->createReader();
return new AUD_SuperposeReader(reader1, reader2);
}
diff --git a/intern/audaspace/FX/AUD_SuperposeFactory.h b/intern/audaspace/FX/AUD_SuperposeFactory.h
index 32232012e4e..b12da62b497 100644
--- a/intern/audaspace/FX/AUD_SuperposeFactory.h
+++ b/intern/audaspace/FX/AUD_SuperposeFactory.h
@@ -35,8 +35,9 @@
#include "AUD_IFactory.h"
/**
- * This factory plays two other factories behind each other.
- * \note Readers from the underlying factories must have the same sample rate and channel count.
+ * This factory mixes two other factories, playing them the same time.
+ * \note Readers from the underlying factories must have the same sample rate
+ * and channel count.
*/
class AUD_SuperposeFactory : public AUD_IFactory
{
@@ -44,12 +45,12 @@ private:
/**
* First played factory.
*/
- AUD_IFactory* m_factory1;
+ AUD_Reference m_factory1;
/**
* Second played factory.
*/
- AUD_IFactory* m_factory2;
+ AUD_Reference m_factory2;
// hide copy constructor and operator=
AUD_SuperposeFactory(const AUD_SuperposeFactory&);
@@ -61,9 +62,9 @@ public:
* \param factory1 The first input factory.
* \param factory2 The second input factory.
*/
- AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
+ AUD_SuperposeFactory(AUD_Reference factory1, AUD_Reference factory2);
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_SUPERPOSEFACTORY
diff --git a/intern/audaspace/FX/AUD_SuperposeReader.cpp b/intern/audaspace/FX/AUD_SuperposeReader.cpp
index e64cf79188e..c07b7a9febf 100644
--- a/intern/audaspace/FX/AUD_SuperposeReader.cpp
+++ b/intern/audaspace/FX/AUD_SuperposeReader.cpp
@@ -36,30 +36,13 @@
static const char* specs_error = "AUD_SuperposeReader: Both readers have to "
"have the same specs.";
-AUD_SuperposeReader::AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2) :
+AUD_SuperposeReader::AUD_SuperposeReader(AUD_Reference reader1, AUD_Reference reader2) :
m_reader1(reader1), m_reader2(reader2)
{
- try
- {
- AUD_Specs s1, s2;
- s1 = reader1->getSpecs();
- s2 = reader2->getSpecs();
- if(memcmp(&s1, &s2, sizeof(AUD_Specs)))
- AUD_THROW(AUD_ERROR_SPECS, specs_error);
- }
- catch(AUD_Exception&)
- {
- delete reader1;
- delete reader2;
-
- throw;
- }
}
AUD_SuperposeReader::~AUD_SuperposeReader()
{
- delete m_reader1;
- delete m_reader2;
}
bool AUD_SuperposeReader::isSeekable() const
@@ -94,28 +77,31 @@ AUD_Specs AUD_SuperposeReader::getSpecs() const
return m_reader1->getSpecs();
}
-void AUD_SuperposeReader::read(int & length, sample_t* & buffer)
+void AUD_SuperposeReader::read(int& length, bool& eos, sample_t* buffer)
{
AUD_Specs specs = m_reader1->getSpecs();
+ AUD_Specs s2 = m_reader2->getSpecs();
+ if(!AUD_COMPARE_SPECS(specs, s2))
+ AUD_THROW(AUD_ERROR_SPECS, specs_error);
+
int samplesize = AUD_SAMPLE_SIZE(specs);
- if(m_buffer.getSize() < length * samplesize)
- m_buffer.resize(length * samplesize);
- buffer = m_buffer.getBuffer();
+ m_buffer.assureSize(length * samplesize);
int len1 = length;
- sample_t* buf;
- m_reader1->read(len1, buf);
- memcpy(buffer, buf, len1 * samplesize);
+ m_reader1->read(len1, eos, buffer);
if(len1 < length)
memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
int len2 = length;
- m_reader2->read(len2, buf);
+ bool eos2;
+ sample_t* buf = m_buffer.getBuffer();
+ m_reader2->read(len2, eos2, buf);
for(int i = 0; i < len2 * specs.channels; i++)
buffer[i] += buf[i];
length = AUD_MAX(len1, len2);
+ eos &= eos2;
}
diff --git a/intern/audaspace/FX/AUD_SuperposeReader.h b/intern/audaspace/FX/AUD_SuperposeReader.h
index b256aade7ba..07b4b105835 100644
--- a/intern/audaspace/FX/AUD_SuperposeReader.h
+++ b/intern/audaspace/FX/AUD_SuperposeReader.h
@@ -34,9 +34,10 @@
#include "AUD_IReader.h"
#include "AUD_Buffer.h"
+#include "AUD_Reference.h"
/**
- * This reader plays two readers with the same specs sequently.
+ * This reader plays two readers with the same specs in parallel.
*/
class AUD_SuperposeReader : public AUD_IReader
{
@@ -44,15 +45,15 @@ private:
/**
* The first reader.
*/
- AUD_IReader* m_reader1;
+ AUD_Reference m_reader1;
/**
* The second reader.
*/
- AUD_IReader* m_reader2;
+ AUD_Reference m_reader2;
/**
- * The playback buffer for the intersecting part.
+ * Buffer used for mixing.
*/
AUD_Buffer m_buffer;
@@ -67,7 +68,7 @@ public:
* \param reader2 The second reader to read from.
* \exception AUD_Exception Thrown if the specs from the readers differ.
*/
- AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2);
+ AUD_SuperposeReader(AUD_Reference reader1, AUD_Reference reader2);
/**
* Destroys the reader.
@@ -79,7 +80,7 @@ public:
virtual int getLength() const;
virtual int getPosition() const;
virtual AUD_Specs getSpecs() const;
- virtual void read(int & length, sample_t* & buffer);
+ virtual void read(int& length, bool& eos, sample_t* buffer);
};
#endif //AUD_SUPERPOSEREADER
diff --git a/intern/audaspace/FX/AUD_VolumeFactory.cpp b/intern/audaspace/FX/AUD_VolumeFactory.cpp
index 166fbf61512..17cefd4f3c3 100644
--- a/intern/audaspace/FX/AUD_VolumeFactory.cpp
+++ b/intern/audaspace/FX/AUD_VolumeFactory.cpp
@@ -32,7 +32,7 @@
#include "AUD_VolumeFactory.h"
#include "AUD_IIRFilterReader.h"
-AUD_VolumeFactory::AUD_VolumeFactory(AUD_IFactory* factory, float volume) :
+AUD_VolumeFactory::AUD_VolumeFactory(AUD_Reference factory, float volume) :
AUD_EffectFactory(factory),
m_volume(volume)
{
@@ -43,7 +43,7 @@ float AUD_VolumeFactory::getVolume() const
return m_volume;
}
-AUD_IReader* AUD_VolumeFactory::createReader() const
+AUD_Reference AUD_VolumeFactory::createReader()
{
std::vector a, b;
a.push_back(1);
diff --git a/intern/audaspace/FX/AUD_VolumeFactory.h b/intern/audaspace/FX/AUD_VolumeFactory.h
index fa40ca11082..0ca0102b790 100644
--- a/intern/audaspace/FX/AUD_VolumeFactory.h
+++ b/intern/audaspace/FX/AUD_VolumeFactory.h
@@ -57,14 +57,15 @@ public:
* \param factory The input factory.
* \param volume The desired volume.
*/
- AUD_VolumeFactory(AUD_IFactory* factory, float volume);
+ AUD_VolumeFactory(AUD_Reference factory, float volume);
/**
* Returns the volume.
+ * \return The current volume.
*/
float getVolume() const;
- virtual AUD_IReader* createReader() const;
+ virtual AUD_Reference createReader();
};
#endif //AUD_VOLUMEFACTORY
diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
index 71e7b7677e8..d5b365fa62f 100644
--- a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
+++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
@@ -43,56 +43,727 @@
#include
#endif
-#define AUD_OPENAL_CYCLE_BUFFERS 3
-
-/// Saves the data for playback.
-struct AUD_OpenALHandle : AUD_Handle
-{
- /// Whether it's a buffered or a streamed source.
- bool isBuffered;
-
- /// The reader source.
- AUD_IReader* reader;
-
- /// Whether to keep the source if end of it is reached.
- bool keep;
-
- /// OpenAL sample format.
- ALenum format;
-
- /// OpenAL source.
- ALuint source;
-
- /// OpenAL buffers.
- ALuint buffers[AUD_OPENAL_CYCLE_BUFFERS];
-
- /// The first buffer to be read next.
- int current;
-
- /// Whether the stream doesn't return any more data.
- bool data_end;
-
- /// The loop count of the source.
- int loopcount;
-
- /// The stop callback.
- stopCallback stop;
-
- /// Stop callback data.
- void* stop_data;
-};
-
-struct AUD_OpenALBufferedFactory
+/*struct AUD_OpenALBufferedFactory
{
/// The factory.
AUD_IFactory* factory;
/// The OpenAL buffer.
ALuint buffer;
-};
+};*/
-typedef std::list::iterator AUD_HandleIterator;
-typedef std::list::iterator AUD_BFIterator;
+//typedef std::list::iterator AUD_BFIterator;
+
+
+/******************************************************************************/
+/*********************** AUD_OpenALHandle Handle Code *************************/
+/******************************************************************************/
+
+static const char* genbuffer_error = "AUD_OpenALDevice: Buffer couldn't be "
+ "generated.";
+static const char* gensource_error = "AUD_OpenALDevice: Source couldn't be "
+ "generated.";
+static const char* queue_error = "AUD_OpenALDevice: Buffer couldn't be "
+ "queued to the source.";
+static const char* bufferdata_error = "AUD_OpenALDevice: Buffer couldn't be "
+ "filled with data.";
+
+AUD_OpenALDevice::AUD_OpenALHandle::AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, AUD_Reference reader, bool keep) :
+ m_isBuffered(false), m_reader(reader), m_keep(keep), m_format(format), m_current(0),
+ m_eos(false), m_loopcount(0), m_stop(NULL), m_stop_data(NULL), m_status(AUD_STATUS_PLAYING),
+ m_device(device)
+{
+ AUD_DeviceSpecs specs = m_device->m_specs;
+ specs.specs = m_reader->getSpecs();
+
+ // OpenAL playback code
+ alGenBuffers(CYCLE_BUFFERS, m_buffers);
+ if(alGetError() != AL_NO_ERROR)
+ AUD_THROW(AUD_ERROR_OPENAL, genbuffer_error);
+
+ try
+ {
+ m_device->m_buffer.assureSize(m_device->m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
+ int length;
+ bool eos;
+
+ for(int i = 0; i < CYCLE_BUFFERS; i++)
+ {
+ length = m_device->m_buffersize;
+ reader->read(length, eos, m_device->m_buffer.getBuffer());
+ alBufferData(m_buffers[i], m_format, m_device->m_buffer.getBuffer(),
+ length * AUD_DEVICE_SAMPLE_SIZE(specs),
+ specs.rate);
+ if(alGetError() != AL_NO_ERROR)
+ AUD_THROW(AUD_ERROR_OPENAL, bufferdata_error);
+ }
+
+ alGenSources(1, &m_source);
+ if(alGetError() != AL_NO_ERROR)
+ AUD_THROW(AUD_ERROR_OPENAL, gensource_error);
+
+ try
+ {
+ alSourceQueueBuffers(m_source, CYCLE_BUFFERS,
+ m_buffers);
+ if(alGetError() != AL_NO_ERROR)
+ AUD_THROW(AUD_ERROR_OPENAL, queue_error);
+ }
+ catch(AUD_Exception&)
+ {
+ alDeleteSources(1, &m_source);
+ throw;
+ }
+ }
+ catch(AUD_Exception&)
+ {
+ alDeleteBuffers(CYCLE_BUFFERS, m_buffers);
+ throw;
+ }
+ alSourcei(m_source, AL_SOURCE_RELATIVE, 1);
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::pause()
+{
+ if(m_status)
+ {
+ m_device->lock();
+
+ if(m_status == AUD_STATUS_PLAYING)
+ {
+ m_device->m_playingSounds.remove(this);
+ m_device->m_pausedSounds.push_back(this);
+
+ alSourcePause(m_source);
+
+ m_status = AUD_STATUS_PAUSED;
+ m_device->unlock();
+
+ return true;
+ }
+
+ m_device->unlock();
+ }
+
+ return false;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::resume()
+{
+ if(m_status)
+ {
+ m_device->lock();
+
+ if(m_status == AUD_STATUS_PAUSED)
+ {
+ m_device->m_pausedSounds.remove(this);
+ m_device->m_playingSounds.push_back(this);
+
+ m_device->start();
+ m_status = AUD_STATUS_PLAYING;
+ m_device->unlock();
+ return true;
+ }
+
+ m_device->unlock();
+ }
+
+ return false;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::stop()
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ // AUD_XXX Create a reference of our own object so that it doesn't get
+ // deleted before the end of this function
+ AUD_Reference This = this;
+
+ if(m_status == AUD_STATUS_PLAYING)
+ m_device->m_playingSounds.remove(This);
+ else
+ m_device->m_pausedSounds.remove(This);
+
+ m_device->unlock();
+
+ alDeleteSources(1, &m_source);
+ if(!m_isBuffered)
+ alDeleteBuffers(CYCLE_BUFFERS, m_buffers);
+
+ m_status = AUD_STATUS_INVALID;
+ return true;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::getKeep()
+{
+ if(m_status)
+ return m_keep;
+
+ return false;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setKeep(bool keep)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ m_keep = keep;
+
+ m_device->unlock();
+
+ return true;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ if(m_isBuffered)
+ alSourcef(m_source, AL_SEC_OFFSET, position);
+ else
+ {
+ m_reader->seek((int)(position * m_reader->getSpecs().rate));
+ m_eos = false;
+
+ ALint info;
+
+ alGetSourcei(m_source, AL_SOURCE_STATE, &info);
+
+ if(info != AL_PLAYING)
+ {
+ if(info == AL_PAUSED)
+ alSourceStop(m_source);
+
+ alSourcei(m_source, AL_BUFFER, 0);
+ m_current = 0;
+
+ ALenum err;
+ if((err = alGetError()) == AL_NO_ERROR)
+ {
+ int length;
+ AUD_DeviceSpecs specs = m_device->m_specs;
+ specs.specs = m_reader->getSpecs();
+ m_device->m_buffer.assureSize(m_device->m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
+
+ for(int i = 0; i < CYCLE_BUFFERS; i++)
+ {
+ length = m_device->m_buffersize;
+ m_reader->read(length, m_eos, m_device->m_buffer.getBuffer());
+ alBufferData(m_buffers[i], m_format, m_device->m_buffer.getBuffer(),
+ length * AUD_DEVICE_SAMPLE_SIZE(specs), specs.rate);
+
+ if(alGetError() != AL_NO_ERROR)
+ break;
+ }
+
+ if(m_loopcount != 0)
+ m_eos = false;
+
+ alSourceQueueBuffers(m_source, CYCLE_BUFFERS, m_buffers);
+ }
+
+ alSourceRewind(m_source);
+ }
+ }
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getPosition()
+{
+ if(!m_status)
+ return 0.0f;
+
+ m_device->lock();
+
+ float position = 0.0f;
+
+ alGetSourcef(m_source, AL_SEC_OFFSET, &position);
+
+ if(!m_isBuffered)
+ {
+ AUD_Specs specs = m_reader->getSpecs();
+ position += (m_reader->getPosition() - m_device->m_buffersize *
+ CYCLE_BUFFERS) / (float)specs.rate;
+ }
+
+ m_device->unlock();
+
+ return position;
+}
+
+AUD_Status AUD_OpenALDevice::AUD_OpenALHandle::getStatus()
+{
+ return m_status;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getVolume()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_GAIN, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setVolume(float volume)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_GAIN, volume);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getPitch()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_PITCH, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setPitch(float pitch)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_PITCH, pitch);
+
+ m_device->unlock();
+
+ return true;
+}
+
+int AUD_OpenALDevice::AUD_OpenALHandle::getLoopCount()
+{
+ if(!m_status)
+ return 0;
+ return m_loopcount;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setLoopCount(int count)
+{
+ if(!m_status)
+ return false;
+ m_loopcount = count;
+ return true;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setStopCallback(stopCallback callback, void* data)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ m_stop = callback;
+ m_stop_data = data;
+
+ m_device->unlock();
+
+ return true;
+}
+
+/******************************************************************************/
+/********************* AUD_OpenALHandle 3DHandle Code *************************/
+/******************************************************************************/
+
+AUD_Vector3 AUD_OpenALDevice::AUD_OpenALHandle::getSourceLocation()
+{
+ AUD_Vector3 result = AUD_Vector3(0, 0, 0);
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ ALfloat p[3];
+ alGetSourcefv(m_source, AL_POSITION, p);
+
+ m_device->unlock();
+
+ result = AUD_Vector3(p[0], p[1], p[2]);
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceLocation(const AUD_Vector3& location)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcefv(m_source, AL_POSITION, (ALfloat*)location.get());
+
+ m_device->unlock();
+
+ return true;
+}
+
+AUD_Vector3 AUD_OpenALDevice::AUD_OpenALHandle::getSourceVelocity()
+{
+ AUD_Vector3 result = AUD_Vector3(0, 0, 0);
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ ALfloat v[3];
+ alGetSourcefv(m_source, AL_VELOCITY, v);
+
+ m_device->unlock();
+
+ result = AUD_Vector3(v[0], v[1], v[2]);
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceVelocity(const AUD_Vector3& velocity)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcefv(m_source, AL_VELOCITY, (ALfloat*)velocity.get());
+
+ m_device->unlock();
+
+ return true;
+}
+
+AUD_Quaternion AUD_OpenALDevice::AUD_OpenALHandle::getSourceOrientation()
+{
+ return m_orientation;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceOrientation(const AUD_Quaternion& orientation)
+{
+ if(!m_status)
+ return false;
+
+ ALfloat direction[3];
+ direction[0] = -2 * (orientation.w() * orientation.y() +
+ orientation.x() * orientation.z());
+ direction[1] = 2 * (orientation.x() * orientation.w() -
+ orientation.z() * orientation.y());
+ direction[2] = 2 * (orientation.x() * orientation.x() +
+ orientation.y() * orientation.y()) - 1;
+ m_device->lock();
+
+ alSourcefv(m_source, AL_DIRECTION, direction);
+
+ m_device->unlock();
+
+ m_orientation = orientation;
+
+ return true;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::isRelative()
+{
+ int result;
+
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alGetSourcei(m_source, AL_SOURCE_RELATIVE, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setRelative(bool relative)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcei(m_source, AL_SOURCE_RELATIVE, relative);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getVolumeMaximum()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_MAX_GAIN, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setVolumeMaximum(float volume)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_MAX_GAIN, volume);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getVolumeMinimum()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_MIN_GAIN, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setVolumeMinimum(float volume)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_MIN_GAIN, volume);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getDistanceMaximum()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_MAX_DISTANCE, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setDistanceMaximum(float distance)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_MAX_DISTANCE, distance);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getDistanceReference()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_REFERENCE_DISTANCE, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setDistanceReference(float distance)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_REFERENCE_DISTANCE, distance);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getAttenuation()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_ROLLOFF_FACTOR, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setAttenuation(float factor)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_ROLLOFF_FACTOR, factor);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getConeAngleOuter()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_CONE_OUTER_ANGLE, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setConeAngleOuter(float angle)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_CONE_OUTER_ANGLE, angle);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getConeAngleInner()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_CONE_INNER_ANGLE, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setConeAngleInner(float angle)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_CONE_INNER_ANGLE, angle);
+
+ m_device->unlock();
+
+ return true;
+}
+
+float AUD_OpenALDevice::AUD_OpenALHandle::getConeVolumeOuter()
+{
+ float result = std::numeric_limits::quiet_NaN();
+
+ if(!m_status)
+ return result;
+
+ m_device->lock();
+
+ alGetSourcef(m_source, AL_CONE_OUTER_GAIN, &result);
+
+ m_device->unlock();
+
+ return result;
+}
+
+bool AUD_OpenALDevice::AUD_OpenALHandle::setConeVolumeOuter(float volume)
+{
+ if(!m_status)
+ return false;
+
+ m_device->lock();
+
+ alSourcef(m_source, AL_CONE_OUTER_GAIN, volume);
+
+ m_device->unlock();
+
+ return true;
+}
/******************************************************************************/
/**************************** Threading Code **********************************/
@@ -130,16 +801,15 @@ void AUD_OpenALDevice::start(bool join)
void AUD_OpenALDevice::updateStreams()
{
- AUD_OpenALHandle* sound;
+ AUD_Reference sound;
int length;
- sample_t* buffer;
ALint info;
AUD_DeviceSpecs specs = m_specs;
ALCenum cerr;
- std::list stopSounds;
- std::list pauseSounds;
+ std::list > stopSounds;
+ std::list > pauseSounds;
AUD_HandleIterator it;
while(1)
@@ -151,83 +821,86 @@ void AUD_OpenALDevice::updateStreams()
if(cerr == ALC_NO_ERROR)
{
// for all sounds
- for(it = m_playingSounds->begin(); it != m_playingSounds->end(); it++)
+ for(it = m_playingSounds.begin(); it != m_playingSounds.end(); it++)
{
sound = *it;
// is it a streamed sound?
- if(!sound->isBuffered)
+ if(!sound->m_isBuffered)
{
// check for buffer refilling
- alGetSourcei(sound->source, AL_BUFFERS_PROCESSED, &info);
+ alGetSourcei(sound->m_source, AL_BUFFERS_PROCESSED, &info);
if(info)
{
- specs.specs = sound->reader->getSpecs();
+ specs.specs = sound->m_reader->getSpecs();
+ m_buffer.assureSize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
// for all empty buffers
while(info--)
{
// if there's still data to play back
- if(!sound->data_end)
+ if(!sound->m_eos)
{
// read data
length = m_buffersize;
- sound->reader->read(length, buffer);
+ sound->m_reader->read(length, sound->m_eos, m_buffer.getBuffer());
// looping necessary?
- if(length == 0 && sound->loopcount)
+ if(length == 0 && sound->m_loopcount)
{
- if(sound->loopcount > 0)
- sound->loopcount--;
+ if(sound->m_loopcount > 0)
+ sound->m_loopcount--;
- sound->reader->seek(0);
+ sound->m_reader->seek(0);
length = m_buffersize;
- sound->reader->read(length, buffer);
+ sound->m_reader->read(length, sound->m_eos, m_buffer.getBuffer());
}
+ if(sound->m_loopcount != 0)
+ sound->m_eos = false;
+
// read nothing?
if(length == 0)
{
- sound->data_end = true;
break;
}
// unqueue buffer
- alSourceUnqueueBuffers(sound->source, 1,
- &sound->buffers[sound->current]);
+ alSourceUnqueueBuffers(sound->m_source, 1,
+ &sound->m_buffers[sound->m_current]);
ALenum err;
if((err = alGetError()) != AL_NO_ERROR)
{
- sound->data_end = true;
+ sound->m_eos = true;
break;
}
// fill with new data
- alBufferData(sound->buffers[sound->current],
- sound->format,
- buffer, length *
+ alBufferData(sound->m_buffers[sound->m_current],
+ sound->m_format,
+ m_buffer.getBuffer(), length *
AUD_DEVICE_SAMPLE_SIZE(specs),
specs.rate);
if((err = alGetError()) != AL_NO_ERROR)
{
- sound->data_end = true;
+ sound->m_eos = true;
break;
}
// and queue again
- alSourceQueueBuffers(sound->source, 1,
- &sound->buffers[sound->current]);
+ alSourceQueueBuffers(sound->m_source, 1,
+ &sound->m_buffers[sound->m_current]);
if(alGetError() != AL_NO_ERROR)
{
- sound->data_end = true;
+ sound->m_eos = true;
break;
}
- sound->current = (sound->current+1) %
- AUD_OPENAL_CYCLE_BUFFERS;
+ sound->m_current = (sound->m_current+1) %
+ AUD_OpenALHandle::CYCLE_BUFFERS;
}
else
break;
@@ -236,18 +909,18 @@ void AUD_OpenALDevice::updateStreams()
}
// check if the sound has been stopped
- alGetSourcei(sound->source, AL_SOURCE_STATE, &info);
+ alGetSourcei(sound->m_source, AL_SOURCE_STATE, &info);
if(info != AL_PLAYING)
{
// if it really stopped
- if(sound->data_end)
+ if(sound->m_eos)
{
- if(sound->stop)
- sound->stop(sound->stop_data);
+ if(sound->m_stop)
+ sound->m_stop(sound->m_stop_data);
// pause or
- if(sound->keep)
+ if(sound->m_keep)
pauseSounds.push_back(sound);
// stop
else
@@ -255,15 +928,15 @@ void AUD_OpenALDevice::updateStreams()
}
// continue playing
else
- alSourcePlay(sound->source);
+ alSourcePlay(sound->m_source);
}
}
for(it = pauseSounds.begin(); it != pauseSounds.end(); it++)
- pause(*it);
+ (*it)->pause();
for(it = stopSounds.begin(); it != stopSounds.end(); it++)
- stop(*it);
+ (*it)->stop();
pauseSounds.clear();
stopSounds.clear();
@@ -272,7 +945,7 @@ void AUD_OpenALDevice::updateStreams()
}
// stop thread
- if(m_playingSounds->empty() || (cerr != ALC_NO_ERROR))
+ if(m_playingSounds.empty() || (cerr != ALC_NO_ERROR))
{
m_playing = false;
unlock();
@@ -293,19 +966,6 @@ void AUD_OpenALDevice::updateStreams()
/**************************** IDevice Code ************************************/
/******************************************************************************/
-bool AUD_OpenALDevice::isValid(AUD_Handle* handle)
-{
- for(AUD_HandleIterator i = m_playingSounds->begin();
- i != m_playingSounds->end(); i++)
- if(*i == handle)
- return true;
- for(AUD_HandleIterator i = m_pausedSounds->begin();
- i != m_pausedSounds->end(); i++)
- if(*i == handle)
- return true;
- return false;
-}
-
static const char* open_error = "AUD_OpenALDevice: Device couldn't be opened.";
AUD_OpenALDevice::AUD_OpenALDevice(AUD_DeviceSpecs specs, int buffersize)
@@ -358,9 +1018,7 @@ AUD_OpenALDevice::AUD_OpenALDevice(AUD_DeviceSpecs specs, int buffersize)
m_buffersize = buffersize;
m_playing = false;
- m_playingSounds = new std::list();
- m_pausedSounds = new std::list();
- m_bufferedFactories = new std::list();
+// m_bufferedFactories = new std::list();
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
@@ -375,46 +1033,23 @@ AUD_OpenALDevice::AUD_OpenALDevice(AUD_DeviceSpecs specs, int buffersize)
AUD_OpenALDevice::~AUD_OpenALDevice()
{
- AUD_OpenALHandle* sound;
-
lock();
alcSuspendContext(m_context);
- // delete all playing sounds
- while(!m_playingSounds->empty())
- {
- sound = *(m_playingSounds->begin());
- alDeleteSources(1, &sound->source);
- if(!sound->isBuffered)
- {
- delete sound->reader;
- alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
- }
- delete sound;
- m_playingSounds->erase(m_playingSounds->begin());
- }
+ while(!m_playingSounds.empty())
+ m_playingSounds.front()->stop();
+
+ while(!m_pausedSounds.empty())
+ m_pausedSounds.front()->stop();
- // delete all paused sounds
- while(!m_pausedSounds->empty())
- {
- sound = *(m_pausedSounds->begin());
- alDeleteSources(1, &sound->source);
- if(!sound->isBuffered)
- {
- delete sound->reader;
- alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
- }
- delete sound;
- m_pausedSounds->erase(m_pausedSounds->begin());
- }
// delete all buffered factories
- while(!m_bufferedFactories->empty())
+ /*while(!m_bufferedFactories->empty())
{
alDeleteBuffers(1, &(*(m_bufferedFactories->begin()))->buffer);
delete *m_bufferedFactories->begin();
m_bufferedFactories->erase(m_bufferedFactories->begin());
- }
+ }*/
alcProcessContext(m_context);
@@ -422,9 +1057,7 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
unlock();
pthread_join(m_thread, NULL);
- delete m_playingSounds;
- delete m_pausedSounds;
- delete m_bufferedFactories;
+ //delete m_bufferedFactories;
// quit OpenAL
alcMakeContextCurrent(NULL);
@@ -530,120 +1163,54 @@ bool AUD_OpenALDevice::getFormat(ALenum &format, AUD_Specs specs)
return valid;
}
-static const char* genbuffer_error = "AUD_OpenALDevice: Buffer couldn't be "
- "generated.";
-static const char* gensource_error = "AUD_OpenALDevice: Source couldn't be "
- "generated.";
-static const char* queue_error = "AUD_OpenALDevice: Buffer couldn't be "
- "queued to the source.";
-static const char* bufferdata_error = "AUD_OpenALDevice: Buffer couldn't be "
- "filled with data.";
-
-AUD_Handle* AUD_OpenALDevice::play(AUD_IReader* reader, bool keep)
+AUD_Reference AUD_OpenALDevice::play(AUD_Reference reader, bool keep)
{
- AUD_OpenALHandle* sound = NULL;
-
- AUD_DeviceSpecs specs = m_specs;
- specs.specs = reader->getSpecs();
+ AUD_Specs specs = reader->getSpecs();
// check format
- bool valid = specs.channels != AUD_CHANNELS_INVALID;
+ if(specs.channels == AUD_CHANNELS_INVALID)
+ return AUD_Reference();
if(m_specs.format != AUD_FORMAT_FLOAT32)
reader = new AUD_ConverterReader(reader, m_specs);
- // create the handle
- sound = new AUD_OpenALHandle;
- sound->keep = keep;
- sound->reader = reader;
- sound->current = 0;
- sound->isBuffered = false;
- sound->data_end = false;
- sound->loopcount = 0;
- sound->stop = NULL;
- sound->stop_data = NULL;
+ ALenum format;
- valid &= getFormat(sound->format, specs.specs);
-
- if(!valid)
- {
- delete sound;
- delete reader;
- return NULL;
- }
+ if(!getFormat(format, specs))
+ return AUD_Reference();
lock();
alcSuspendContext(m_context);
- // OpenAL playback code
+ AUD_Reference sound;
+
try
{
- alGenBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
- if(alGetError() != AL_NO_ERROR)
- AUD_THROW(AUD_ERROR_OPENAL, genbuffer_error);
-
- try
- {
- sample_t* buf;
- int length;
-
- for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
- {
- length = m_buffersize;
- reader->read(length, buf);
- alBufferData(sound->buffers[i], sound->format, buf,
- length * AUD_DEVICE_SAMPLE_SIZE(specs),
- specs.rate);
- if(alGetError() != AL_NO_ERROR)
- AUD_THROW(AUD_ERROR_OPENAL, bufferdata_error);
- }
-
- alGenSources(1, &sound->source);
- if(alGetError() != AL_NO_ERROR)
- AUD_THROW(AUD_ERROR_OPENAL, gensource_error);
-
- try
- {
- alSourceQueueBuffers(sound->source, AUD_OPENAL_CYCLE_BUFFERS,
- sound->buffers);
- if(alGetError() != AL_NO_ERROR)
- AUD_THROW(AUD_ERROR_OPENAL, queue_error);
- }
- catch(AUD_Exception&)
- {
- alDeleteSources(1, &sound->source);
- throw;
- }
- }
- catch(AUD_Exception&)
- {
- alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
- throw;
- }
+ // create the handle
+ sound = new AUD_OpenALDevice::AUD_OpenALHandle(this, format, reader, keep);
}
catch(AUD_Exception&)
{
- delete sound;
- delete reader;
alcProcessContext(m_context);
unlock();
throw;
}
+ alcProcessContext(m_context);
+
// play sound
- m_playingSounds->push_back(sound);
- alSourcei(sound->source, AL_SOURCE_RELATIVE, 1);
+ m_playingSounds.push_back(sound);
start();
- alcProcessContext(m_context);
unlock();
- return sound;
+ return AUD_Reference(sound);
}
-AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
+AUD_Reference AUD_OpenALDevice::play(AUD_Reference factory, bool keep)
{
+ /* AUD_XXX disabled
AUD_OpenALHandle* sound = NULL;
lock();
@@ -661,7 +1228,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
sound->keep = keep;
sound->current = -1;
sound->isBuffered = true;
- sound->data_end = true;
+ sound->eos = true;
sound->loopcount = 0;
sound->stop = NULL;
sound->stop_data = NULL;
@@ -713,264 +1280,24 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
unlock();
if(sound)
- return sound;
+ return sound;*/
return play(factory->createReader(), keep);
}
-bool AUD_OpenALDevice::pause(AUD_Handle* handle)
+void AUD_OpenALDevice::stopAll()
{
- bool result = false;
-
lock();
+ alcSuspendContext(m_context);
- // only songs that are played can be paused
- for(AUD_HandleIterator i = m_playingSounds->begin();
- i != m_playingSounds->end(); i++)
- {
- if(*i == handle)
- {
- m_pausedSounds->push_back(*i);
- alSourcePause((*i)->source);
- m_playingSounds->erase(i);
- result = true;
- break;
- }
- }
+ while(!m_playingSounds.empty())
+ m_playingSounds.front()->stop();
+ while(!m_pausedSounds.empty())
+ m_pausedSounds.front()->stop();
+
+ alcProcessContext(m_context);
unlock();
-
- return result;
-}
-
-bool AUD_OpenALDevice::resume(AUD_Handle* handle)
-{
- bool result = false;
-
- lock();
-
- // only songs that are paused can be resumed
- for(AUD_HandleIterator i = m_pausedSounds->begin();
- i != m_pausedSounds->end(); i++)
- {
- if(*i == handle)
- {
- m_playingSounds->push_back(*i);
- start();
- m_pausedSounds->erase(i);
- result = true;
- break;
- }
- }
-
- unlock();
-
- return result;
-}
-
-bool AUD_OpenALDevice::stop(AUD_Handle* handle)
-{
- AUD_OpenALHandle* sound;
-
- bool result = false;
-
- lock();
-
- for(AUD_HandleIterator i = m_playingSounds->begin();
- i != m_playingSounds->end(); i++)
- {
- if(*i == handle)
- {
- sound = *i;
- alDeleteSources(1, &sound->source);
- if(!sound->isBuffered)
- {
- delete sound->reader;
- alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
- }
- delete *i;
- m_playingSounds->erase(i);
- result = true;
- break;
- }
- }
- if(!result)
- {
- for(AUD_HandleIterator i = m_pausedSounds->begin();
- i != m_pausedSounds->end(); i++)
- {
- if(*i == handle)
- {
- sound = *i;
- alDeleteSources(1, &sound->source);
- if(!sound->isBuffered)
- {
- delete sound->reader;
- alDeleteBuffers(AUD_OPENAL_CYCLE_BUFFERS, sound->buffers);
- }
- delete *i;
- m_pausedSounds->erase(i);
- result = true;
- break;
- }
- }
- }
-
- unlock();
-
- return result;
-}
-
-bool AUD_OpenALDevice::getKeep(AUD_Handle* handle)
-{
- bool result = false;
-
- lock();
-
- if(isValid(handle))
- result = ((AUD_OpenALHandle*)handle)->keep;
-
- unlock();
-
- return result;
-}
-
-bool AUD_OpenALDevice::setKeep(AUD_Handle* handle, bool keep)
-{
- bool result = false;
-
- lock();
-
- if(isValid(handle))
- {
- ((AUD_OpenALHandle*)handle)->keep = keep;
- result = true;
- }
-
- unlock();
-
- return result;
-}
-
-bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
-{
- bool result = false;
-
- lock();
-
- if(isValid(handle))
- {
- AUD_OpenALHandle* alhandle = (AUD_OpenALHandle*)handle;
- if(alhandle->isBuffered)
- alSourcef(alhandle->source, AL_SEC_OFFSET, position);
- else
- {
- alhandle->reader->seek((int)(position *
- alhandle->reader->getSpecs().rate));
- alhandle->data_end = false;
-
- ALint info;
-
- alGetSourcei(alhandle->source, AL_SOURCE_STATE, &info);
-
- if(info != AL_PLAYING)
- {
- if(info == AL_PAUSED)
- alSourceStop(alhandle->source);
-
- alSourcei(alhandle->source, AL_BUFFER, 0);
- alhandle->current = 0;
-
- ALenum err;
- if((err = alGetError()) == AL_NO_ERROR)
- {
- sample_t* buf;
- int length;
- AUD_DeviceSpecs specs = m_specs;
- specs.specs = alhandle->reader->getSpecs();
-
- for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
- {
- length = m_buffersize;
- alhandle->reader->read(length, buf);
- alBufferData(alhandle->buffers[i], alhandle->format,
- buf,
- length * AUD_DEVICE_SAMPLE_SIZE(specs),
- specs.rate);
-
- if(alGetError() != AL_NO_ERROR)
- break;
- }
-
- alSourceQueueBuffers(alhandle->source,
- AUD_OPENAL_CYCLE_BUFFERS,
- alhandle->buffers);
- }
-
- alSourceRewind(alhandle->source);
- }
- }
- result = true;
- }
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getPosition(AUD_Handle* handle)
-{
- float position = 0.0f;
-
- lock();
-
- if(isValid(handle))
- {
- AUD_OpenALHandle* h = (AUD_OpenALHandle*)handle;
- alGetSourcef(h->source, AL_SEC_OFFSET, &position);
- if(!h->isBuffered)
- {
- AUD_Specs specs = h->reader->getSpecs();
- position += (h->reader->getPosition() - m_buffersize *
- AUD_OPENAL_CYCLE_BUFFERS) /
- (float)specs.rate;
- }
- }
-
- unlock();
- return position;
-}
-
-AUD_Status AUD_OpenALDevice::getStatus(AUD_Handle* handle)
-{
- AUD_Status status = AUD_STATUS_INVALID;
-
- lock();
-
- for(AUD_HandleIterator i = m_playingSounds->begin();
- i != m_playingSounds->end(); i++)
- {
- if(*i == handle)
- {
- status = AUD_STATUS_PLAYING;
- break;
- }
- }
- if(status == AUD_STATUS_INVALID)
- {
- for(AUD_HandleIterator i = m_pausedSounds->begin();
- i != m_pausedSounds->end(); i++)
- {
- if(*i == handle)
- {
- status = AUD_STATUS_PAUSED;
- break;
- }
- }
- }
-
- unlock();
-
- return status;
}
void AUD_OpenALDevice::lock()
@@ -995,80 +1322,6 @@ void AUD_OpenALDevice::setVolume(float volume)
alListenerf(AL_GAIN, volume);
}
-float AUD_OpenALDevice::getVolume(AUD_Handle* handle)
-{
- lock();
- float result = std::numeric_limits::quiet_NaN();
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source,AL_GAIN, &result);
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setVolume(AUD_Handle* handle, float volume)
-{
- lock();
- bool result = isValid(handle);
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_GAIN, volume);
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getPitch(AUD_Handle* handle)
-{
- lock();
- float result = std::numeric_limits::quiet_NaN();
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source,AL_PITCH, &result);
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setPitch(AUD_Handle* handle, float pitch)
-{
- lock();
- bool result = isValid(handle);
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_PITCH, pitch);
- unlock();
- return result;
-}
-
-int AUD_OpenALDevice::getLoopCount(AUD_Handle* handle)
-{
- lock();
- int result = 0;
- if(isValid(handle))
- result = ((AUD_OpenALHandle*)handle)->loopcount;
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setLoopCount(AUD_Handle* handle, int count)
-{
- lock();
- bool result = isValid(handle);
- if(result)
- ((AUD_OpenALHandle*)handle)->loopcount = count;
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setStopCallback(AUD_Handle* handle, stopCallback callback, void* data)
-{
- lock();
- bool result = isValid(handle);
- if(result)
- {
- AUD_OpenALHandle* h = (AUD_OpenALHandle*)handle;
- h->stop = callback;
- h->stop_data = data;
- }
- unlock();
- return result;
-}
-
/* AUD_XXX Temorary disabled
bool AUD_OpenALDevice::bufferFactory(void *value)
@@ -1109,7 +1362,6 @@ bool AUD_OpenALDevice::bufferFactory(void *value)
if(!getFormat(format, specs.specs))
{
- delete reader;
return false;
}
@@ -1147,7 +1399,6 @@ bool AUD_OpenALDevice::bufferFactory(void *value)
catch(AUD_Exception&)
{
delete bf;
- delete reader;
alcProcessContext(m_context);
unlock();
return false;
@@ -1219,8 +1470,7 @@ void AUD_OpenALDevice::setListenerVelocity(const AUD_Vector3& velocity)
AUD_Quaternion AUD_OpenALDevice::getListenerOrientation() const
{
- // AUD_XXX not implemented yet
- return AUD_Quaternion(0, 0, 0, 0);
+ return m_orientation;
}
void AUD_OpenALDevice::setListenerOrientation(const AUD_Quaternion& orientation)
@@ -1239,6 +1489,7 @@ void AUD_OpenALDevice::setListenerOrientation(const AUD_Quaternion& orientation)
direction[5] = 2 * (orientation.w() * orientation.x() +
orientation.y() * orientation.z());
alListenerfv(AL_ORIENTATION, direction);
+ m_orientation = orientation;
}
float AUD_OpenALDevice::getSpeedOfSound() const
@@ -1308,333 +1559,3 @@ void AUD_OpenALDevice::setDistanceModel(AUD_DistanceModel model)
alDistanceModel(AL_NONE);
}
}
-
-AUD_Vector3 AUD_OpenALDevice::getSourceLocation(AUD_Handle* handle)
-{
- AUD_Vector3 result = AUD_Vector3(0, 0, 0);
- ALfloat p[3];
- lock();
-
- if(isValid(handle))
- {
- alGetSourcefv(((AUD_OpenALHandle*)handle)->source, AL_POSITION, p);
- result = AUD_Vector3(p[0], p[1], p[2]);
- }
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setSourceLocation(AUD_Handle* handle, const AUD_Vector3& location)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_POSITION,
- (ALfloat*)location.get());
-
- unlock();
- return result;
-}
-
-AUD_Vector3 AUD_OpenALDevice::getSourceVelocity(AUD_Handle* handle)
-{
- AUD_Vector3 result = AUD_Vector3(0, 0, 0);
- ALfloat v[3];
- lock();
-
- if(isValid(handle))
- {
- alGetSourcefv(((AUD_OpenALHandle*)handle)->source, AL_VELOCITY, v);
- result = AUD_Vector3(v[0], v[1], v[2]);
- }
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setSourceVelocity(AUD_Handle* handle, const AUD_Vector3& velocity)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_VELOCITY,
- (ALfloat*)velocity.get());
-
- unlock();
- return result;
-}
-
-AUD_Quaternion AUD_OpenALDevice::getSourceOrientation(AUD_Handle* handle)
-{
- // AUD_XXX not implemented yet
- return AUD_Quaternion(0, 0, 0, 0);
-}
-
-bool AUD_OpenALDevice::setSourceOrientation(AUD_Handle* handle, const AUD_Quaternion& orientation)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- {
- ALfloat direction[3];
- direction[0] = -2 * (orientation.w() * orientation.y() +
- orientation.x() * orientation.z());
- direction[1] = 2 * (orientation.x() * orientation.w() -
- orientation.z() * orientation.y());
- direction[2] = 2 * (orientation.x() * orientation.x() +
- orientation.y() * orientation.y()) - 1;
- alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_DIRECTION,
- direction);
- }
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::isRelative(AUD_Handle* handle)
-{
- int result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcei(((AUD_OpenALHandle*)handle)->source, AL_SOURCE_RELATIVE,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setRelative(AUD_Handle* handle, bool relative)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcei(((AUD_OpenALHandle*)handle)->source, AL_SOURCE_RELATIVE,
- relative);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getVolumeMaximum(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_GAIN,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setVolumeMaximum(AUD_Handle* handle, float volume)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
-
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_GAIN,
- volume);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getVolumeMinimum(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_MIN_GAIN,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setVolumeMinimum(AUD_Handle* handle, float volume)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_MIN_GAIN,
- volume);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getDistanceMaximum(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_DISTANCE,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setDistanceMaximum(AUD_Handle* handle, float distance)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_DISTANCE,
- distance);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getDistanceReference(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_REFERENCE_DISTANCE,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setDistanceReference(AUD_Handle* handle, float distance)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_REFERENCE_DISTANCE,
- distance);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getAttenuation(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_ROLLOFF_FACTOR,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setAttenuation(AUD_Handle* handle, float factor)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_ROLLOFF_FACTOR,
- factor);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getConeAngleOuter(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_ANGLE,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setConeAngleOuter(AUD_Handle* handle, float angle)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_ANGLE,
- angle);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getConeAngleInner(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_INNER_ANGLE,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setConeAngleInner(AUD_Handle* handle, float angle)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_INNER_ANGLE,
- angle);
-
- unlock();
- return result;
-}
-
-float AUD_OpenALDevice::getConeVolumeOuter(AUD_Handle* handle)
-{
- float result = std::numeric_limits::quiet_NaN();;
-
- lock();
-
- if(isValid(handle))
- alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_GAIN,
- &result);
-
- unlock();
- return result;
-}
-
-bool AUD_OpenALDevice::setConeVolumeOuter(AUD_Handle* handle, float volume)
-{
- lock();
- bool result = isValid(handle);
-
- if(result)
- alSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_GAIN,
- volume);
-
- unlock();
- return result;
-}
diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.h b/intern/audaspace/OpenAL/AUD_OpenALDevice.h
index 127f69beca8..a04b483132a 100644
--- a/intern/audaspace/OpenAL/AUD_OpenALDevice.h
+++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.h
@@ -33,9 +33,11 @@
#define AUD_OPENALDEVICE
#include "AUD_IDevice.h"
+#include "AUD_IHandle.h"
#include "AUD_I3DDevice.h"
-struct AUD_OpenALHandle;
-struct AUD_OpenALBufferedFactory;
+#include "AUD_I3DHandle.h"
+#include "AUD_Buffer.h"
+//struct AUD_OpenALBufferedFactory;
#include
#include
@@ -48,6 +50,110 @@ struct AUD_OpenALBufferedFactory;
class AUD_OpenALDevice : public AUD_IDevice, public AUD_I3DDevice
{
private:
+ /// Saves the data for playback.
+ class AUD_OpenALHandle : public AUD_IHandle, public AUD_I3DHandle
+ {
+ public:
+ static const int CYCLE_BUFFERS = 3;
+
+ /// Whether it's a buffered or a streamed source.
+ bool m_isBuffered;
+
+ /// The reader source.
+ AUD_Reference m_reader;
+
+ /// Whether to keep the source if end of it is reached.
+ bool m_keep;
+
+ /// OpenAL sample format.
+ ALenum m_format;
+
+ /// OpenAL source.
+ ALuint m_source;
+
+ /// OpenAL buffers.
+ ALuint m_buffers[CYCLE_BUFFERS];
+
+ /// The first buffer to be read next.
+ int m_current;
+
+ /// Whether the stream doesn't return any more data.
+ bool m_eos;
+
+ /// The loop count of the source.
+ int m_loopcount;
+
+ /// The stop callback.
+ stopCallback m_stop;
+
+ /// Stop callback data.
+ void* m_stop_data;
+
+ /// Orientation.
+ AUD_Quaternion m_orientation;
+
+ /// Current status of the handle
+ AUD_Status m_status;
+
+ /// Own device.
+ AUD_OpenALDevice* m_device;
+
+ public:
+
+ /**
+ * Creates a new OpenAL handle.
+ * \param device The OpenAL device the handle belongs to.
+ * \param format The AL format.
+ * \param reader The reader this handle plays.
+ * \param keep Whether to keep the handle alive when the reader ends.
+ */
+ AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, AUD_Reference reader, bool keep);
+
+ virtual ~AUD_OpenALHandle() {}
+ virtual bool pause();
+ virtual bool resume();
+ virtual bool stop();
+ virtual bool getKeep();
+ virtual bool setKeep(bool keep);
+ virtual bool seek(float position);
+ virtual float getPosition();
+ virtual AUD_Status getStatus();
+ virtual float getVolume();
+ virtual bool setVolume(float volume);
+ virtual float getPitch();
+ virtual bool setPitch(float pitch);
+ virtual int getLoopCount();
+ virtual bool setLoopCount(int count);
+ virtual bool setStopCallback(stopCallback callback = 0, void* data = 0);
+
+ virtual AUD_Vector3 getSourceLocation();
+ virtual bool setSourceLocation(const AUD_Vector3& location);
+ virtual AUD_Vector3 getSourceVelocity();
+ virtual bool setSourceVelocity(const AUD_Vector3& velocity);
+ virtual AUD_Quaternion getSourceOrientation();
+ virtual bool setSourceOrientation(const AUD_Quaternion& orientation);
+ virtual bool isRelative();
+ virtual bool setRelative(bool relative);
+ virtual float getVolumeMaximum();
+ virtual bool setVolumeMaximum(float volume);
+ virtual float getVolumeMinimum();
+ virtual bool setVolumeMinimum(float volume);
+ virtual float getDistanceMaximum();
+ virtual bool setDistanceMaximum(float distance);
+ virtual float getDistanceReference();
+ virtual bool setDistanceReference(float distance);
+ virtual float getAttenuation();
+ virtual bool setAttenuation(float factor);
+ virtual float getConeAngleOuter();
+ virtual bool setConeAngleOuter(float angle);
+ virtual float getConeAngleInner();
+ virtual bool setConeAngleInner(float angle);
+ virtual float getConeVolumeOuter();
+ virtual bool setConeVolumeOuter(float volume);
+ };
+
+ typedef std::list >::iterator AUD_HandleIterator;
+
/**
* The OpenAL device handle.
*/
@@ -71,17 +177,17 @@ private:
/**
* The list of sounds that are currently playing.
*/
- std::list* m_playingSounds;
+ std::list > m_playingSounds;
/**
* The list of sounds that are currently paused.
*/
- std::list* m_pausedSounds;
+ std::list > m_pausedSounds;
/**
* The list of buffered factories.
*/
- std::list* m_bufferedFactories;
+ //std::list* m_bufferedFactories;
/**
* The mutex for locking.
@@ -104,16 +210,20 @@ private:
int m_buffersize;
/**
- * Starts the streaming thread.
+ * Device buffer.
*/
- void start(bool join = true);
+ AUD_Buffer m_buffer;
/**
- * Checks if a handle is valid.
- * \param handle The handle to check.
- * \return Whether the handle is valid.
+ * Orientation.
*/
- bool isValid(AUD_Handle* handle);
+ AUD_Quaternion m_orientation;
+
+ /**
+ * Starts the streaming thread.
+ * \param Whether the previous thread should be joined.
+ */
+ void start(bool join = true);
/**
* Gets the format according to the specs.
@@ -147,27 +257,13 @@ public:
virtual ~AUD_OpenALDevice();
virtual AUD_DeviceSpecs getSpecs() const;
- virtual AUD_Handle* play(AUD_IReader* reader, bool keep = false);
- virtual AUD_Handle* play(AUD_IFactory* factory, bool keep = false);
- virtual bool pause(AUD_Handle* handle);
- virtual bool resume(AUD_Handle* handle);
- virtual bool stop(AUD_Handle* handle);
- virtual bool getKeep(AUD_Handle* handle);
- virtual bool setKeep(AUD_Handle* handle, bool keep);
- virtual bool seek(AUD_Handle* handle, float position);
- virtual float getPosition(AUD_Handle* handle);
- virtual AUD_Status getStatus(AUD_Handle* handle);
+ virtual AUD_Reference play(AUD_Reference reader, bool keep = false);
+ virtual AUD_Reference play(AUD_Reference factory, bool keep = false);
+ virtual void stopAll();
virtual void lock();
virtual void unlock();
virtual float getVolume() const;
virtual void setVolume(float volume);
- virtual float getVolume(AUD_Handle* handle);
- virtual bool setVolume(AUD_Handle* handle, float volume);
- virtual float getPitch(AUD_Handle* handle);
- virtual bool setPitch(AUD_Handle* handle, float pitch);
- virtual int getLoopCount(AUD_Handle* handle);
- virtual bool setLoopCount(AUD_Handle* handle, int count);
- virtual bool setStopCallback(AUD_Handle* handle, stopCallback callback = NULL, void* data = NULL);
virtual AUD_Vector3 getListenerLocation() const;
virtual void setListenerLocation(const AUD_Vector3& location);
@@ -181,30 +277,6 @@ public:
virtual void setDopplerFactor(float factor);
virtual AUD_DistanceModel getDistanceModel() const;
virtual void setDistanceModel(AUD_DistanceModel model);
- virtual AUD_Vector3 getSourceLocation(AUD_Handle* handle);
- virtual bool setSourceLocation(AUD_Handle* handle, const AUD_Vector3& location);
- virtual AUD_Vector3 getSourceVelocity(AUD_Handle* handle);
- virtual bool setSourceVelocity(AUD_Handle* handle, const AUD_Vector3& velocity);
- virtual AUD_Quaternion getSourceOrientation(AUD_Handle* handle);
- virtual bool setSourceOrientation(AUD_Handle* handle, const AUD_Quaternion& orientation);
- virtual bool isRelative(AUD_Handle* handle);
- virtual bool setRelative(AUD_Handle* handle, bool relative);
- virtual float getVolumeMaximum(AUD_Handle* handle);
- virtual bool setVolumeMaximum(AUD_Handle* handle, float volume);
- virtual float getVolumeMinimum(AUD_Handle* handle);
- virtual bool setVolumeMinimum(AUD_Handle* handle, float volume);
- virtual float getDistanceMaximum(AUD_Handle* handle);
- virtual bool setDistanceMaximum(AUD_Handle* handle, float distance);
- virtual float getDistanceReference(AUD_Handle* handle);
- virtual bool setDistanceReference(AUD_Handle* handle, float distance);
- virtual float getAttenuation(AUD_Handle* handle);
- virtual bool setAttenuation(AUD_Handle* handle, float factor);
- virtual float getConeAngleOuter(AUD_Handle* handle);
- virtual bool setConeAngleOuter(AUD_Handle* handle, float angle);
- virtual float getConeAngleInner(AUD_Handle* handle);
- virtual bool setConeAngleInner(AUD_Handle* handle, float angle);
- virtual float getConeVolumeOuter(AUD_Handle* handle);
- virtual bool setConeVolumeOuter(AUD_Handle* handle, float volume);
};
#endif //AUD_OPENALDEVICE
diff --git a/intern/audaspace/Python/AUD_PyAPI.cpp b/intern/audaspace/Python/AUD_PyAPI.cpp
index 22376a2fcd1..928c67c5196 100644
--- a/intern/audaspace/Python/AUD_PyAPI.cpp
+++ b/intern/audaspace/Python/AUD_PyAPI.cpp
@@ -33,6 +33,7 @@
#include "structmember.h"
#include "AUD_I3DDevice.h"
+#include "AUD_I3DHandle.h"
#include "AUD_NULLDevice.h"
#include "AUD_DelayFactory.h"
#include "AUD_DoubleFactory.h"
@@ -91,7 +92,7 @@ static void
Factory_dealloc(Factory* self)
{
if(self->factory)
- delete self->factory;
+ delete reinterpret_cast*>(self->factory);
Py_XDECREF(self->child_list);
Py_TYPE(self)->tp_free((PyObject*)self);
}
@@ -115,7 +116,7 @@ Factory_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
try
{
- self->factory = new AUD_FileFactory(filename);
+ self->factory = new AUD_Reference(new AUD_FileFactory(filename));
}
catch(AUD_Exception& e)
{
@@ -143,9 +144,9 @@ static PyObject *
Factory_sine(PyTypeObject* type, PyObject* args)
{
float frequency;
- int rate = 44100;
+ double rate = 44100;
- if(!PyArg_ParseTuple(args, "f|i:sine", &frequency, &rate))
+ if(!PyArg_ParseTuple(args, "f|d:sine", &frequency, &rate))
return NULL;
Factory *self;
@@ -155,7 +156,7 @@ Factory_sine(PyTypeObject* type, PyObject* args)
{
try
{
- self->factory = new AUD_SinusFactory(frequency, (AUD_SampleRate)rate);
+ self->factory = new AUD_Reference(new AUD_SinusFactory(frequency, (AUD_SampleRate)rate));
}
catch(AUD_Exception& e)
{
@@ -194,7 +195,7 @@ Factory_file(PyTypeObject* type, PyObject* args)
{
try
{
- self->factory = new AUD_FileFactory(filename);
+ self->factory = new AUD_Reference(new AUD_FileFactory(filename));
}
catch(AUD_Exception& e)
{
@@ -237,7 +238,7 @@ Factory_lowpass(Factory* self, PyObject* args)
try
{
- parent->factory = new AUD_LowpassFactory(self->factory, frequency, Q);
+ parent->factory = new AUD_Reference(new AUD_LowpassFactory(*reinterpret_cast*>(self->factory), frequency, Q));
}
catch(AUD_Exception& e)
{
@@ -278,7 +279,7 @@ Factory_delay(Factory* self, PyObject* args)
try
{
- parent->factory = new AUD_DelayFactory(self->factory, delay);
+ parent->factory = new AUD_Reference(new AUD_DelayFactory(*reinterpret_cast*>(self->factory), delay));
}
catch(AUD_Exception& e)
{
@@ -322,7 +323,7 @@ Factory_join(Factory* self, PyObject* object)
try
{
- parent->factory = new AUD_DoubleFactory(self->factory, child->factory);
+ parent->factory = new AUD_Reference(new AUD_DoubleFactory(*reinterpret_cast*>(self->factory), *reinterpret_cast*>(child->factory)));
}
catch(AUD_Exception& e)
{
@@ -365,7 +366,7 @@ Factory_highpass(Factory* self, PyObject* args)
try
{
- parent->factory = new AUD_HighpassFactory(self->factory, frequency, Q);
+ parent->factory = new AUD_Reference(new AUD_HighpassFactory(*reinterpret_cast*>(self->factory), frequency, Q));
}
catch(AUD_Exception& e)
{
@@ -406,7 +407,7 @@ Factory_limit(Factory* self, PyObject* args)
try
{
- parent->factory = new AUD_LimiterFactory(self->factory, start, end);
+ parent->factory = new AUD_Reference(new AUD_LimiterFactory(*reinterpret_cast*>(self->factory), start, end));
}
catch(AUD_Exception& e)
{
@@ -450,7 +451,7 @@ Factory_pitch(Factory* self, PyObject* args)
try
{
- parent->factory = new AUD_PitchFactory(self->factory, factor);
+ parent->factory = new AUD_Reference(new AUD_PitchFactory(*reinterpret_cast