diff options
author | Sakari Bergen <sakari.bergen@beatwaves.net> | 2009-12-27 22:09:40 +0000 |
---|---|---|
committer | Sakari Bergen <sakari.bergen@beatwaves.net> | 2009-12-27 22:09:40 +0000 |
commit | 8da27200d18fe4c471a759dde8e10d85ff29d277 (patch) | |
tree | 8a68123da7cb8539a9818704363e3fd98da4d385 /libs/audiographer/audiographer | |
parent | dde0848a984e06cbc1d4117d9cffa75c191f3b39 (diff) |
- Fix process callbakc handling during export
- Fix filename handling when exporting multiple files
- Some updates to audiographer
git-svn-id: svn://localhost/ardour2/branches/3.0@6402 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/audiographer/audiographer')
-rw-r--r-- | libs/audiographer/audiographer/debug_utils.h | 34 | ||||
-rw-r--r-- | libs/audiographer/audiographer/debuggable.h | 46 | ||||
-rw-r--r-- | libs/audiographer/audiographer/exception.h | 24 | ||||
-rw-r--r-- | libs/audiographer/audiographer/process_context.h | 10 | ||||
-rw-r--r-- | libs/audiographer/audiographer/sndfile_base.h | 3 | ||||
-rw-r--r-- | libs/audiographer/audiographer/sr_converter.h | 10 | ||||
-rw-r--r-- | libs/audiographer/audiographer/threader.h | 3 | ||||
-rw-r--r-- | libs/audiographer/audiographer/throwing.h | 32 | ||||
-rw-r--r-- | libs/audiographer/audiographer/type_utils.h | 59 | ||||
-rw-r--r-- | libs/audiographer/audiographer/types.h | 13 |
10 files changed, 204 insertions, 30 deletions
diff --git a/libs/audiographer/audiographer/debug_utils.h b/libs/audiographer/audiographer/debug_utils.h new file mode 100644 index 0000000000..8b45f0d65c --- /dev/null +++ b/libs/audiographer/audiographer/debug_utils.h @@ -0,0 +1,34 @@ +#ifndef AUDIOGRAPHER_DEBUG_UTILS_H +#define AUDIOGRAPHER_DEBUG_UTILS_H + +#include <string> + +#ifdef __GNUC__ +#include <cxxabi.h> +#endif + +namespace AudioGrapher +{ + +struct DebugUtils +{ + template<typename T> + static std::string demangled_name (T const & obj) + { +#ifdef __GNUC__ + int status; + char * res = abi::__cxa_demangle (typeid(obj).name(), 0, 0, &status); + if (status == 0) { + std::string s(res); + free (res); + return s; + } +#endif + return typeid(obj).name(); + } + +}; + +} // namespace + +#endif // AUDIOGRAPHER_DEBUG_UTILS_H diff --git a/libs/audiographer/audiographer/debuggable.h b/libs/audiographer/audiographer/debuggable.h new file mode 100644 index 0000000000..4126327b86 --- /dev/null +++ b/libs/audiographer/audiographer/debuggable.h @@ -0,0 +1,46 @@ +#ifndef AUDIOGRAPHER_DEBUGGABLE_H +#define AUDIOGRAPHER_DEBUGGABLE_H + +#ifndef DEFAULT_DEBUG_LEVEL +#define DEFAULT_DEBUG_LEVEL DebugNone +#endif + +#include <iostream> + +namespace AudioGrapher +{ + +enum DebugLevel +{ + DebugNone, //< Disabled + DebugObject, //< Object level stuff, ctors, initalizers etc. + DebugProcess, //< Process cycle level stuff + DebugVerbose, //< Lots of output, not on sample level + DebugSample //< Sample level stuff +}; + +/// Class that allows optimizing out debugging code during compile time +template<DebugLevel L = DEFAULT_DEBUG_LEVEL> +class Debuggable +{ + protected: + Debuggable(std::ostream & debug_stream = std::cerr) + : stream (debug_stream) {} + + bool debug_level (DebugLevel level) { + #ifdef NDEBUG + return false; + #else + return L >= level; + #endif + } + std::ostream & debug_stream() { return stream; } + + private: + std::ostream & stream; +}; + + +} // namespace + +#endif // AUDIOGRAPHER_DEBUGGABLE_H diff --git a/libs/audiographer/audiographer/exception.h b/libs/audiographer/audiographer/exception.h index a179b30f91..43891db619 100644 --- a/libs/audiographer/audiographer/exception.h +++ b/libs/audiographer/audiographer/exception.h @@ -3,10 +3,11 @@ #include <exception> #include <string> -#include <cxxabi.h> #include <boost/format.hpp> +#include "audiographer/debug_utils.h" + namespace AudioGrapher { @@ -15,8 +16,9 @@ class Exception : public std::exception public: template<typename T> Exception (T const & thrower, std::string const & reason) - : reason (boost::str (boost::format ( - "Exception thrown by %1%: %2%") % name (thrower) % reason)) + : reason (boost::str (boost::format + ("Exception thrown by %1%: %2%") + % DebugUtils::demangled_name (thrower) % reason)) {} virtual ~Exception () throw() { } @@ -25,22 +27,6 @@ class Exception : public std::exception { return reason.c_str(); } - - protected: - template<typename T> - std::string name (T const & obj) - { -#ifdef __GNUC__ - int status; - char * res = abi::__cxa_demangle (typeid(obj).name(), 0, 0, &status); - if (status == 0) { - std::string s(res); - free (res); - return s; - } -#endif - return typeid(obj).name(); - } private: std::string const reason; diff --git a/libs/audiographer/audiographer/process_context.h b/libs/audiographer/audiographer/process_context.h index 080e492944..654da2565a 100644 --- a/libs/audiographer/audiographer/process_context.h +++ b/libs/audiographer/audiographer/process_context.h @@ -1,9 +1,11 @@ #ifndef AUDIOGRAPHER_PROCESS_CONTEXT_H #define AUDIOGRAPHER_PROCESS_CONTEXT_H -#include "types.h" +#include <boost/static_assert.hpp> +#include <boost/type_traits.hpp> -#include <cstring> +#include "types.h" +#include "type_utils.h" namespace AudioGrapher { @@ -14,7 +16,9 @@ namespace AudioGrapher template <typename T> class ProcessContext { - + + BOOST_STATIC_ASSERT (boost::has_trivial_destructor<T>::value); + public: typedef FlagField::Flag Flag; diff --git a/libs/audiographer/audiographer/sndfile_base.h b/libs/audiographer/audiographer/sndfile_base.h index fd6c5f3552..7f8da752e8 100644 --- a/libs/audiographer/audiographer/sndfile_base.h +++ b/libs/audiographer/audiographer/sndfile_base.h @@ -6,11 +6,12 @@ #include <sigc++/signal.h> #include "types.h" +#include "debuggable.h" namespace AudioGrapher { /// Common interface for templated libsndfile readers/writers -class SndfileBase +class SndfileBase : public Debuggable<> { public: diff --git a/libs/audiographer/audiographer/sr_converter.h b/libs/audiographer/audiographer/sr_converter.h index 073fdc8247..a9bfc7c4c3 100644 --- a/libs/audiographer/audiographer/sr_converter.h +++ b/libs/audiographer/audiographer/sr_converter.h @@ -3,14 +3,20 @@ #include <samplerate.h> -#include "types.h" +#include "debuggable.h" #include "listed_source.h" #include "sink.h" +#include "throwing.h" +#include "types.h" namespace AudioGrapher { -class SampleRateConverter : public ListedSource<float>, public Sink<float> +class SampleRateConverter + : public ListedSource<float> + , public Sink<float> + , public Debuggable<> + , public Throwing<> { public: SampleRateConverter (uint32_t channels); diff --git a/libs/audiographer/audiographer/threader.h b/libs/audiographer/audiographer/threader.h index e6c3aa97bf..ad6a542126 100644 --- a/libs/audiographer/audiographer/threader.h +++ b/libs/audiographer/audiographer/threader.h @@ -23,7 +23,8 @@ class ThreaderException : public Exception ThreaderException (T const & thrower, std::exception const & e) : Exception (thrower, boost::str ( boost::format - ("\n\t- Dynamic type: %1%\n\t- what(): %2%") % name (e) % e.what() )) + ("\n\t- Dynamic type: %1%\n\t- what(): %2%") + % DebugUtils::demangled_name (e) % e.what() )) { } }; diff --git a/libs/audiographer/audiographer/throwing.h b/libs/audiographer/audiographer/throwing.h new file mode 100644 index 0000000000..05a056d5e9 --- /dev/null +++ b/libs/audiographer/audiographer/throwing.h @@ -0,0 +1,32 @@ +#ifndef AUDIOGRAPHER_THROWING_H +#define AUDIOGRAPHER_THROWING_H + +#ifndef DEFAULT_THROW_LEVEL +#define DEFAULT_THROW_LEVEL ThrowStrict +#endif + +namespace AudioGrapher +{ + +enum ThrowLevel +{ + ThrowNone, //< Not allowed to throw + ThrowObject, //< Object level stuff, ctors, initalizers etc. + ThrowProcess, //< Process cycle level stuff + ThrowStrict, //< Stricter checks than ThrowProcess, less than ThrowSample + ThrowSample //< Sample level stuff +}; + +/// Class that allows optimizing out error checking during compile time +template<ThrowLevel L = DEFAULT_THROW_LEVEL> +class Throwing +{ + protected: + Throwing() {} + bool throw_level (ThrowLevel level) { return L >= level; } +}; + + +} // namespace + +#endif // AUDIOGRAPHER_THROWING_H diff --git a/libs/audiographer/audiographer/type_utils.h b/libs/audiographer/audiographer/type_utils.h new file mode 100644 index 0000000000..84a28f3d07 --- /dev/null +++ b/libs/audiographer/audiographer/type_utils.h @@ -0,0 +1,59 @@ +#ifndef AUDIOGRAPHER_TYPE_UTILS_H +#define AUDIOGRAPHER_TYPE_UTILS_H + +#include "types.h" +#include <boost/static_assert.hpp> +#include <boost/type_traits.hpp> +#include <memory> +#include <algorithm> + +namespace AudioGrapher +{ + +class TypeUtilsBase +{ + protected: + + template<typename T, bool b> + static void do_fill(T * buffer, nframes_t frames, const boost::integral_constant<bool, b>&) + { std::uninitialized_fill_n (buffer, frames, T()); } + + template<typename T> + static void do_fill(T * buffer, nframes_t frames, const boost::true_type&) + { memset (buffer, frames * sizeof(T), 0); } + + private: +}; + +template<typename T> +class TypeUtils : private TypeUtilsBase +{ + BOOST_STATIC_ASSERT (boost::has_trivial_destructor<T>::value); + + typedef boost::integral_constant<bool, + boost::is_floating_point<T>::value || + boost::is_signed<T>::value> zero_fillable; + public: + inline static void zero_fill (T * buffer, nframes_t frames) + { do_zero_fill(buffer, frames, zero_fillable()); } + + inline static void copy (T* source, T* destination, nframes_t frames) + { std::uninitialized_copy (source, &source[frames], destination); } + + inline static void move (T* source, T* destination, nframes_t frames) + { + if (destination < source) { + std::copy (source, &source[frames], destination); + } else { + std::copy_backward (source, &source[frames], destination); + } + } + + private: + +}; + + +} // namespace + +#endif // AUDIOGRAPHER_TYPE_UTILS_H diff --git a/libs/audiographer/audiographer/types.h b/libs/audiographer/audiographer/types.h index f48f8f807a..5d31899748 100644 --- a/libs/audiographer/audiographer/types.h +++ b/libs/audiographer/audiographer/types.h @@ -18,10 +18,15 @@ class FlagField { FlagField() : _flags (0) {} FlagField(FlagField const & other) : _flags (other._flags) {} - inline bool has (Flag flag) const { return _flags & (1 << flag); } - inline void set (Flag flag) { _flags |= (1 << flag); } - inline void remove (Flag flag) { _flags &= ~(1 << flag); } - inline storage_type flags () const { return _flags; } + inline bool has (Flag flag) const { return _flags & (1 << flag); } + inline storage_type flags () const { return _flags; } + inline operator bool() const { return _flags; } + inline void set (Flag flag) { _flags |= (1 << flag); } + inline void remove (Flag flag) { _flags &= ~(1 << flag); } + inline void reset () { _flags = 0; } + + inline FlagField & operator+= (FlagField const & other) { _flags |= other._flags; return *this; } + inline bool operator== (FlagField const & other) const { return _flags == other._flags; } private: storage_type _flags; |