Code style cleanup -- NO FUNCTIONAL CHANGES
Massive cleanup of code formatting style. This was deemed necessary, as
the original codebase is a mix of styles varying from file to file, and
occasionally from line to line. Honestly, it was messy enough to be a
major distraction.
This is a styling change only, and is functionally identical to the
immediately previous version. (The only change that could be described
as a functional change was to collect all the various 'isnan'
definitions in one place.)
The style employed is a Google-ewhac hybrid. Indentation is now two
spaces per level. All TAB characters and (nearly all) trailing blanks
have been removed. All files now use UNIX-style newlines.
Some effort was made to improve inline spacing and formatting,
including:
- Spaces before non-consecutive open-parens,
- No space after open-parens,
- No space before close-parens,
- Two spaces after the semicolon in each 'for' clause,
- Two spaces surrounding each logic op (&& and ||),
- Return type on separate line from function declaration,
- Open-brace for function on its own line.
This effort was applied irregularly.
ewhac's style has been developed over 30 years, and is optimized for C.
It falls apart a bit for C++. But then, pure ewhac style uses 8-space
TAB characters, so shaddup.
diff --git a/src/libprojectM/Common.hpp b/src/libprojectM/Common.hpp
index b325f80..843422b 100644
--- a/src/libprojectM/Common.hpp
+++ b/src/libprojectM/Common.hpp
@@ -26,20 +26,22 @@
#ifndef COMMON_HPP
#define COMMON_HPP
+
#include <vector>
#include <typeinfo>
#include <cstdarg>
#include <cassert>
+
#ifdef _MSC_sVER
-#define strcasecmp(s, t) _strcmpi(s, t)
+#define strcasecmp(s, t) _strcmpi(s, t)
#endif
#ifdef _MSC_VER
- #pragma warning( disable : 4244 4305 4996; once : 4018 )
- #define WIN32_LEAN_AND_MEAN
- #define NOMINMAX
- #include <windows.h>
- typedef unsigned int uint;
+ #pragma warning( disable : 4244 4305 4996; once : 4018 )
+ #define WIN32_LEAN_AND_MEAN
+ #define NOMINMAX
+ #include <windows.h>
+ typedef unsigned int uint;
#endif
#ifdef DEBUG
@@ -48,193 +50,180 @@
#ifdef MACOS
#include <cstdio>
-extern FILE *fmemopen(void *buf, size_t len, const char *pMode);
+extern FILE *fmemopen (void *buf, size_t len, const char *pMode);
#endif /** MACOS */
#include "dlldefs.h"
-#define DEFAULT_FONT_PATH "/home/carm/fonts/courier1.glf"
-#define MAX_TOKEN_SIZE 512
-#define MAX_PATH_SIZE 4096
+#define DEFAULT_FONT_PATH "/home/carm/fonts/courier1.glf"
+#define MAX_TOKEN_SIZE 512
+#define MAX_PATH_SIZE 4096
-#define STRING_BUFFER_SIZE 1024*150
-#define STRING_LINE_SIZE 1024
+#define STRING_BUFFER_SIZE 1024*150
+#define STRING_LINE_SIZE 1024
#ifdef LINUX
#include <cstdlib>
-#define projectM_isnan std::isnan
-
+#define projectM_isnan std::isnan
+#define projectM_fmax fmax
+#define projectM_fmin fmin
#endif
#ifdef WIN32
-#define projectM_isnan(x) ((x) != (x))
+#define projectM_isnan(x) ((x) != (x))
+#define projectM_fmax(x,y) ((x) >= (y) ? (x): (y))
+#define projectM_fmin(x,y) ((x) <= (y) ? (x): (y))
#endif
#ifdef MACOS
-#define projectM_isnan(x) ((x) != (x))
-#endif
-
-#ifdef LINUX
-#define projectM_fmax fmax
-#endif
-
-#ifdef WIN32
-#define projectM_fmax(x,y) ((x) >= (y) ? (x): (y))
-#endif
-
-#ifdef MACOS
-#define projectM_fmax(x,y) ((x) >= (y) ? (x): (y))
-#endif
-
-#ifdef LINUX
-#define projectM_fmin fmin
-#endif
-
-#ifdef WIN32
-#define projectM_fmin(x,y) ((x) <= (y) ? (x): (y))
-#endif
-
-#ifdef MACOS
-#define projectM_fmin(x,y) ((x) <= (y) ? (x): (y))
+#define projectM_isnan(x) ((x) != (x))
+#define projectM_fmax(x,y) ((x) >= (y) ? (x): (y))
+#define projectM_fmin(x,y) ((x) <= (y) ? (x): (y))
#endif
#ifndef TRUE
-#define TRUE true
+#define TRUE true
#endif
#ifndef FALSE
-#define FALSE false
+#define FALSE false
#endif
-#define MAX_DOUBLE_SIZE 10000000.0
-#define MIN_DOUBLE_SIZE -10000000.0
+#define MAX_DOUBLE_SIZE 10000000.0
+#define MIN_DOUBLE_SIZE -10000000.0
-#define MAX_INT_SIZE 10000000
-#define MIN_INT_SIZE -10000000
+#define MAX_INT_SIZE 10000000
+#define MIN_INT_SIZE -10000000
/* default float initial value */
-#define DEFAULT_DOUBLE_IV 0.0
+#define DEFAULT_DOUBLE_IV 0.0
/* default float lower bound */
-#define DEFAULT_DOUBLE_LB MIN_DOUBLE_SIZE
+#define DEFAULT_DOUBLE_LB MIN_DOUBLE_SIZE
/* default float upper bound */
-#define DEFAULT_DOUBLE_UB MAX_DOUBLE_SIZE
+#define DEFAULT_DOUBLE_UB MAX_DOUBLE_SIZE
#ifdef WIN32
#include <float.h>
-#define isnan _isnan
+#define isnan _isnan
#endif /** WIN32 */
/** Per-platform path separators */
-#define WIN32_PATH_SEPARATOR '\\'
-#define UNIX_PATH_SEPARATOR '/'
+#define WIN32_PATH_SEPARATOR '\\'
+#define UNIX_PATH_SEPARATOR '/'
#ifdef WIN32
-#define PATH_SEPARATOR WIN32_PATH_SEPARATOR
+#define PATH_SEPARATOR WIN32_PATH_SEPARATOR
#else
-#define PATH_SEPARATOR UNIX_PATH_SEPARATOR
+#define PATH_SEPARATOR UNIX_PATH_SEPARATOR
#endif /** WIN32 */
+
#include <string>
-const unsigned int NUM_Q_VARIABLES(32);
-const std::string PROJECTM_FILE_EXTENSION("prjm");
-const std::string MILKDROP_FILE_EXTENSION("milk");
-const std::string PROJECTM_MODULE_EXTENSION("so");
- template <class TraverseFunctor, class Container>
- void traverse(Container & container)
+const unsigned int NUM_Q_VARIABLES (32);
+const std::string PROJECTM_FILE_EXTENSION ("prjm");
+const std::string MILKDROP_FILE_EXTENSION ("milk");
+const std::string PROJECTM_MODULE_EXTENSION ("so");
+
+
+template <class TraverseFunctor, class Container>
+void traverse (Container & container)
+{
+ TraverseFunctor functor;
+
+ for (typename Container::iterator pos = container.begin ();
+ pos != container.end ();
+ ++pos)
{
-
- TraverseFunctor functor;
-
- for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos)
- {
- assert(pos->second);
- functor(pos->second);
- }
-
+ assert (pos->second);
+ functor (pos->second);
}
-
- template <class TraverseFunctor, class Container>
- void traverseVector(Container & container)
- {
-
- TraverseFunctor functor;
-
- for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos)
- {
- assert(*pos);
- functor(*pos);
- }
-
- }
-
- template <class TraverseFunctor, class Container>
- void traverse(Container & container, TraverseFunctor & functor)
- {
-
- for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos)
- {
- assert(pos->second);
- functor(pos->second);
- }
-
- }
-
- namespace TraverseFunctors
- {
- template <class Data>
- class Delete
- {
-
- public:
-
- void operator() (Data * data)
- {
- assert(data);
- delete(data);
- }
-
- };
- }
-
-
-inline std::string parseExtension(const std::string & filename) {
-
-const std::size_t start = filename.find_last_of('.');
-
-if (start == std::string::npos || start >= (filename.length()-1))
- return "";
-else
- return filename.substr(start+1, filename.length());
-
}
-inline std::string parseFilename(const std::string & filename) {
-const std::size_t start = filename.find_last_of('/');
+template <class TraverseFunctor, class Container>
+void traverseVector (Container & container)
+{
+ TraverseFunctor functor;
-if (start == std::string::npos || start >= (filename.length()-1))
- return "";
-else
- return filename.substr(start+1, filename.length());
+ for (typename Container::iterator pos = container.begin ();
+ pos != container.end ();
+ ++pos)
+ {
+ assert (*pos);
+ functor (*pos);
+ }
}
-inline double meanSquaredError(const double & x, const double & y) {
- return (x-y)*(x-y);
+template <class TraverseFunctor, class Container>
+void traverse (Container & container, TraverseFunctor & functor)
+{
+ for (typename Container::iterator pos = container.begin ();
+ pos != container.end ();
+ ++pos)
+ {
+ assert (pos->second);
+ functor (pos->second);
+ }
+
+}
+
+namespace TraverseFunctors
+{
+ template <class Data>
+ class Delete
+ {
+
+ public:
+
+ void
+ operator () (Data * data)
+ {
+ assert (data);
+ delete (data);
+ }
+
+ };
+} /* namespace TraverseFunctors */
+
+
+inline std::string
+parseExtension (const std::string & filename) {
+ const std::size_t start = filename.find_last_of ('.');
+
+ if (start == std::string::npos || start >= (filename.length ()-1))
+ return "";
+ else
+ return filename.substr (start+1, filename.length ());
+}
+
+inline std::string
+parseFilename (const std::string & filename) {
+ const std::size_t start = filename.find_last_of ('/');
+
+ if (start == std::string::npos || start >= (filename.length ()-1))
+ return "";
+ else
+ return filename.substr (start+1, filename.length ());
+}
+
+inline double
+meanSquaredError (const double & x, const double & y) {
+ return (x-y)*(x-y);
}
enum PresetRatingType {
- FIRST_RATING_TYPE = 0,
- HARD_CUT_RATING_TYPE = FIRST_RATING_TYPE,
- SOFT_CUT_RATING_TYPE,
- LAST_RATING_TYPE = SOFT_CUT_RATING_TYPE,
- TOTAL_RATING_TYPES = SOFT_CUT_RATING_TYPE+1
+ FIRST_RATING_TYPE = 0,
+ HARD_CUT_RATING_TYPE = FIRST_RATING_TYPE,
+ SOFT_CUT_RATING_TYPE,
+ LAST_RATING_TYPE = SOFT_CUT_RATING_TYPE,
+ TOTAL_RATING_TYPES = SOFT_CUT_RATING_TYPE+1
};
diff --git a/src/libprojectM/ConfigFile.cpp b/src/libprojectM/ConfigFile.cpp
index f041064..c10662d 100644
--- a/src/libprojectM/ConfigFile.cpp
+++ b/src/libprojectM/ConfigFile.cpp
@@ -1,142 +1,158 @@
-// ConfigFile.cpp
-
-#include "ConfigFile.h"
-
-using std::string;
-
-ConfigFile::ConfigFile( string filename, string delimiter,
- string comment, string sentry )
- : myDelimiter(delimiter), myComment(comment), mySentry(sentry)
-{
- // Construct a ConfigFile, getting keys and values from given file
-
- std::ifstream in( filename.c_str() );
-
- if( !in ) throw file_not_found( filename );
-
- in >> (*this);
-}
-
-
-ConfigFile::ConfigFile()
- : myDelimiter( string(1,'=') ), myComment( string(1,'#') )
-{
- // Construct a ConfigFile without a file; empty
-}
-
-
-void ConfigFile::remove( const string& key )
-{
- // Remove key and its value
- myContents.erase( myContents.find( key ) );
- return;
-}
-
-
-bool ConfigFile::keyExists( const string& key ) const
-{
- // Indicate whether key is found
- mapci p = myContents.find( key );
- return ( p != myContents.end() );
-}
-
-
-/* static */
-void ConfigFile::trim( string& s )
-{
- // Remove leading and trailing whitespace
- static const char whitespace[] = " \n\t\v\r\f";
- s.erase( 0, s.find_first_not_of(whitespace) );
- s.erase( s.find_last_not_of(whitespace) + 1U );
-}
-
-
-std::ostream& operator<<( std::ostream& os, const ConfigFile& cf )
-{
- // Save a ConfigFile to os
- for( ConfigFile::mapci p = cf.myContents.begin();
- p != cf.myContents.end();
- ++p )
- {
- os << p->first << " " << cf.myDelimiter << " ";
- os << p->second << std::endl;
- }
- return os;
-}
-
-
-std::istream& operator>>( std::istream& is, ConfigFile& cf )
-{
- // Load a ConfigFile from is
- // Read in keys and values, keeping internal whitespace
- typedef string::size_type pos;
- const string& delim = cf.myDelimiter; // separator
- const string& comm = cf.myComment; // comment
- const string& sentry = cf.mySentry; // end of file sentry
- const pos skip = delim.length(); // length of separator
-
- string nextline = ""; // might need to read ahead to see where value ends
-
- while( is || nextline.length() > 0 )
- {
- // Read an entire line at a time
- string line;
- if( nextline.length() > 0 )
- {
- line = nextline; // we read ahead; use it now
- nextline = "";
- }
- else
- {
- std::getline( is, line );
- }
-
- // Ignore comments
- line = line.substr( 0, line.find(comm) );
-
- // Check for end of file sentry
- if( sentry != "" && line.find(sentry) != string::npos ) return is;
-
- // Parse the line if it contains a delimiter
- pos delimPos = line.find( delim );
- if( delimPos < string::npos )
- {
- // Extract the key
- string key = line.substr( 0, delimPos );
- line.replace( 0, delimPos+skip, "" );
-
- // See if value continues on the next line
- // Stop at blank line, next line with a key, end of stream,
- // or end of file sentry
- bool terminate = false;
- while( !terminate && is )
- {
- std::getline( is, nextline );
- terminate = true;
-
- string nlcopy = nextline;
- ConfigFile::trim(nlcopy);
- if( nlcopy == "" ) continue;
-
- nextline = nextline.substr( 0, nextline.find(comm) );
- if( nextline.find(delim) != string::npos )
- continue;
- if( sentry != "" && nextline.find(sentry) != string::npos )
- continue;
-
- nlcopy = nextline;
- ConfigFile::trim(nlcopy);
- if( nlcopy != "" ) line += "\n";
- line += nextline;
- terminate = false;
- }
-
- // Store key and value
- ConfigFile::trim(key);
- ConfigFile::trim(line);
- cf.myContents[key] = line; // overwrites if key is repeated
- }
- }
-
- return is;
-}
+// ConfigFile.cpp
+
+#include "ConfigFile.h"
+
+
+using std::string;
+
+ConfigFile::ConfigFile (
+string filename,
+string delimiter,
+string comment,
+string sentry
+)
+ : myDelimiter (delimiter),
+ myComment (comment),
+ mySentry (sentry)
+{
+ // Construct a ConfigFile, getting keys and values from given file
+
+ std::ifstream in (filename.c_str ());
+
+ if (!in) throw file_not_found (filename);
+
+ in >> (*this);
+}
+
+
+ConfigFile::ConfigFile ()
+ : myDelimiter (string (1,'=')),
+ myComment (string (1,'#'))
+{
+ // Construct a ConfigFile without a file; empty
+}
+
+
+void
+ConfigFile::remove (const string& key)
+{
+ // Remove key and its value
+ myContents.erase (myContents.find (key));
+ return;
+}
+
+
+bool
+ConfigFile::keyExists (const string& key) const
+{
+ // Indicate whether key is found
+ mapci p = myContents.find (key);
+
+ return (p != myContents.end ());
+}
+
+
+/* static */
+void
+ConfigFile::trim (string& s)
+{
+ // Remove leading and trailing whitespace
+ static const char whitespace[] = " \n\t\v\r\f";
+
+ s.erase (0, s.find_first_not_of (whitespace));
+ s.erase (s.find_last_not_of (whitespace) + 1U);
+}
+
+
+std::ostream&
+operator<< (std::ostream& os, const ConfigFile& cf)
+{
+ // Save a ConfigFile to os
+ for (ConfigFile::mapci p = cf.myContents.begin ();
+ p != cf.myContents.end ();
+ ++p)
+ {
+ os << p->first << " " << cf.myDelimiter << " ";
+ os << p->second << std::endl;
+ }
+ return os;
+}
+
+
+std::istream&
+operator>> (std::istream& is, ConfigFile& cf)
+{
+ // Load a ConfigFile from is
+ // Read in keys and values, keeping internal whitespace
+ typedef string::size_type pos;
+ const string &delim = cf.myDelimiter; // separator
+ const string &comm = cf.myComment; // comment
+ const string &sentry = cf.mySentry; // end of file sentry
+ const pos skip = delim.length (); // length of separator
+
+ string nextline = ""; // might need to read ahead to see where value ends
+
+ while (is || nextline.length () > 0)
+ {
+ // Read an entire line at a time
+ string line;
+
+ if (nextline.length () > 0)
+ {
+ line = nextline; // we read ahead; use it now
+ nextline = "";
+ }
+ else
+ {
+ std::getline (is, line);
+ }
+
+ // Ignore comments
+ line = line.substr (0, line.find (comm));
+
+ // Check for end of file sentry
+ if (sentry != "" && line.find (sentry) != string::npos) return is;
+
+ // Parse the line if it contains a delimiter
+ pos delimPos = line.find (delim);
+ if (delimPos < string::npos)
+ {
+ // Extract the key
+ string key = line.substr (0, delimPos);
+ line.replace (0, delimPos+skip, "");
+
+ // See if value continues on the next line
+ // Stop at blank line, next line with a key, end of stream,
+ // or end of file sentry
+ bool terminate = false;
+ while (!terminate && is)
+ {
+ std::getline (is, nextline);
+ terminate = true;
+
+ string nlcopy = nextline;
+ ConfigFile::trim (nlcopy);
+ if (nlcopy == "") continue;
+
+ nextline = nextline.substr (0, nextline.find (comm));
+ if (nextline.find (delim) != string::npos)
+ continue;
+ if (sentry != "" && nextline.find (sentry) != string::npos)
+ continue;
+
+ nlcopy = nextline;
+ ConfigFile::trim (nlcopy);
+ if (nlcopy != "") line += "\n";
+ line += nextline;
+ terminate = false;
+ }
+
+ // Store key and value
+ ConfigFile::trim (key);
+ ConfigFile::trim (line);
+ cf.myContents[key] = line; // overwrites if key is repeated
+ }
+ }
+
+ return is;
+}
diff --git a/src/libprojectM/ConfigFile.h b/src/libprojectM/ConfigFile.h
index c2f0024..7e93ae4 100644
--- a/src/libprojectM/ConfigFile.h
+++ b/src/libprojectM/ConfigFile.h
@@ -1,253 +1,258 @@
-// ConfigFile.h
-// Class for reading named values from configuration files
-// Richard J. Wagner v2.1 24 May 2004 wagnerr@umich.edu
-
-// Copyright (c) 2004 Richard J. Wagner
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to
-// deal in the Software without restriction, including without limitation the
-// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-// sell copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-
-// Typical usage
-// -------------
-//
-// Given a configuration file "settings.inp":
-// atoms = 25
-// length = 8.0 # nanometers
-// name = Reece Surcher
-//
-// Named values are read in various ways, with or without default values:
-// ConfigFile config( "settings.inp" );
-// int atoms = config.read<int>( "atoms" );
-// double length = config.read( "length", 10.0 );
-// string author, title;
-// config.readInto( author, "name" );
-// config.readInto( title, "title", string("Untitled") );
-//
-// See file example.cpp for more examples.
-
-#ifndef CONFIGFILE_H
-#define CONFIGFILE_H
-
-#include <string>
-#include <map>
-#include <iostream>
-#include <fstream>
-#include <sstream>
-
-using std::string;
-
-class ConfigFile {
-// Data
-protected:
- string myDelimiter; // separator between key and value
- string myComment; // separator between value and comments
- string mySentry; // optional string to signal end of file
- std::map<string,string> myContents; // extracted keys and values
-
- typedef std::map<string,string>::iterator mapi;
- typedef std::map<string,string>::const_iterator mapci;
-
-// Methods
-public:
- ConfigFile( string filename,
- string delimiter = "=",
- string comment = "#",
- string sentry = "EndConfigFile" );
- ConfigFile();
-
- // Search for key and read value or optional default value
- template<class T> T read( const string& key ) const; // call as read<T>
- template<class T> T read( const string& key, const T& value ) const;
- template<class T> bool readInto( T& var, const string& key ) const;
- template<class T>
- bool readInto( T& var, const string& key, const T& value ) const;
-
- // Modify keys and values
- template<class T> void add( string key, const T& value );
- void remove( const string& key );
-
- // Check whether key exists in configuration
- bool keyExists( const string& key ) const;
-
- // Check or change configuration syntax
- string getDelimiter() const { return myDelimiter; }
- string getComment() const { return myComment; }
- string getSentry() const { return mySentry; }
- string setDelimiter( const string& s )
- { string old = myDelimiter; myDelimiter = s; return old; }
- string setComment( const string& s )
- { string old = myComment; myComment = s; return old; }
-
- // Write or read configuration
- friend std::ostream& operator<<( std::ostream& os, const ConfigFile& cf );
- friend std::istream& operator>>( std::istream& is, ConfigFile& cf );
-
-protected:
- template<class T> static string T_as_string( const T& t );
- template<class T> static T string_as_T( const string& s );
- static void trim( string& s );
-
-
-// Exception types
-public:
- struct file_not_found {
- string filename;
- file_not_found( const string& filename_ = string() )
- : filename(filename_) {} };
- struct key_not_found { // thrown only by T read(key) variant of read()
- string key;
- key_not_found( const string& key_ = string() )
- : key(key_) {} };
-};
-
-
-/* static */
-template<class T>
-string ConfigFile::T_as_string( const T& t )
-{
- // Convert from a T to a string
- // Type T must support << operator
- std::ostringstream ost;
- ost << t;
- return ost.str();
-}
-
-
-/* static */
-template<class T>
-T ConfigFile::string_as_T( const string& s )
-{
- // Convert from a string to a T
- // Type T must support >> operator
- T t;
- std::istringstream ist(s);
- ist >> t;
- return t;
-}
-
-
-/* static */
-template<>
-inline string ConfigFile::string_as_T<string>( const string& s )
-{
- // Convert from a string to a string
- // In other words, do nothing
- return s;
-}
-
-
-/* static */
-template<>
-inline bool ConfigFile::string_as_T<bool>( const string& s )
-{
- // Convert from a string to a bool
- // Interpret "false", "F", "no", "n", "0" as false
- // Interpret "true", "T", "yes", "y", "1", "-1", or anything else as true
- bool b = true;
- string sup = s;
- for( string::iterator p = sup.begin(); p != sup.end(); ++p )
- *p = toupper(*p); // make string all caps
- if( sup==string("FALSE") || sup==string("F") ||
- sup==string("NO") || sup==string("N") ||
- sup==string("0") || sup==string("NONE") )
- b = false;
- return b;
-}
-
-
-template<class T>
-T ConfigFile::read( const string& key ) const
-{
- // Read the value corresponding to key
- mapci p = myContents.find(key);
- if( p == myContents.end() ) throw key_not_found(key);
- return string_as_T<T>( p->second );
-}
-
-
-template<class T>
-T ConfigFile::read( const string& key, const T& value ) const
-{
- // Return the value corresponding to key or given default value
- // if key is not found
- mapci p = myContents.find(key);
- if( p == myContents.end() ) return value;
- return string_as_T<T>( p->second );
-}
-
-
-template<class T>
-bool ConfigFile::readInto( T& var, const string& key ) const
-{
- // Get the value corresponding to key and store in var
- // Return true if key is found
- // Otherwise leave var untouched
- mapci p = myContents.find(key);
- bool found = ( p != myContents.end() );
- if( found ) var = string_as_T<T>( p->second );
- return found;
-}
-
-
-template<class T>
-bool ConfigFile::readInto( T& var, const string& key, const T& value ) const
-{
- // Get the value corresponding to key and store in var
- // Return true if key is found
- // Otherwise set var to given default
- mapci p = myContents.find(key);
- bool found = ( p != myContents.end() );
- if( found )
- var = string_as_T<T>( p->second );
- else
- var = value;
- return found;
-}
-
-
-template<class T>
-void ConfigFile::add( string key, const T& value )
-{
- // Add a key with given value
- string v = T_as_string( value );
- trim(key);
- trim(v);
- myContents[key] = v;
- return;
-}
-
-#endif // CONFIGFILE_H
-
-// Release notes:
-// v1.0 21 May 1999
-// + First release
-// + Template read() access only through non-member readConfigFile()
-// + ConfigurationFileBool is only built-in helper class
-//
-// v2.0 3 May 2002
-// + Shortened name from ConfigurationFile to ConfigFile
-// + Implemented template member functions
-// + Changed default comment separator from % to #
-// + Enabled reading of multiple-line values
-//
-// v2.1 24 May 2004
-// + Made template specializations inline to avoid compiler-dependent linkage
-// + Allowed comments within multiple-line values
-// + Enabled blank line termination for multiple-line values
-// + Added optional sentry to detect end of configuration file
-// + Rewrote messy trimWhitespace() function as elegant trim()
+// ConfigFile.h
+// Class for reading named values from configuration files
+// Richard J. Wagner v2.1 24 May 2004 wagnerr@umich.edu
+
+// Copyright (c) 2004 Richard J. Wagner
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+
+// Typical usage
+// -------------
+//
+// Given a configuration file "settings.inp":
+// atoms = 25
+// length = 8.0 # nanometers
+// name = Reece Surcher
+//
+// Named values are read in various ways, with or without default values:
+// ConfigFile config ("settings.inp");
+// int atoms = config.read<int>( "atoms");
+// double length = config.read ("length", 10.0);
+// string author, title;
+// config.readInto (author, "name");
+// config.readInto (title, "title", string("Untitled"));
+//
+// See file example.cpp for more examples.
+
+#ifndef CONFIGFILE_H
+#define CONFIGFILE_H
+
+#include <string>
+#include <map>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+using std::string;
+
+class ConfigFile {
+// Data
+protected:
+ string myDelimiter; // separator between key and value
+ string myComment; // separator between value and comments
+ string mySentry; // optional string to signal end of file
+ std::map<string,string> myContents; // extracted keys and values
+
+ typedef std::map<string,string>::iterator mapi;
+ typedef std::map<string,string>::const_iterator mapci;
+
+// Methods
+public:
+ ConfigFile (string filename,
+ string delimiter = "=",
+ string comment = "#",
+ string sentry = "EndConfigFile");
+ ConfigFile();
+
+ // Search for key and read value or optional default value
+ template<class T> T read (const string& key) const; // call as read<T>
+ template<class T> T read (const string& key, const T& value) const;
+ template<class T> bool readInto (T& var, const string& key) const;
+ template<class T> bool readInto (T& var, const string& key, const T& value) const;
+
+ // Modify keys and values
+ template<class T> void add (string key, const T& value);
+ void remove (const string& key);
+
+ // Check whether key exists in configuration
+ bool keyExists (const string& key) const;
+
+ // Check or change configuration syntax
+ string getDelimiter() const { return myDelimiter; }
+ string getComment() const { return myComment; }
+ string getSentry() const { return mySentry; }
+ string setDelimiter (const string& s)
+ { string old = myDelimiter; myDelimiter = s; return old; }
+ string setComment (const string& s)
+ { string old = myComment; myComment = s; return old; }
+
+ // Write or read configuration
+ friend std::ostream& operator<<(std::ostream& os, const ConfigFile& cf);
+ friend std::istream& operator>>(std::istream& is, ConfigFile& cf);
+
+protected:
+ template<class T> static string T_as_string (const T& t);
+ template<class T> static T string_as_T (const string& s);
+ static void trim (string& s);
+
+
+// Exception types
+public:
+ struct file_not_found {
+ string filename;
+ file_not_found (const string& filename_ = string())
+ : filename(filename_) {} };
+ struct key_not_found { // thrown only by T read(key) variant of read()
+ string key;
+ key_not_found (const string& key_ = string())
+ : key(key_) {} };
+};
+
+
+/* static */
+template<class T>
+string ConfigFile::T_as_string (const T& t)
+{
+ // Convert from a T to a string
+ // Type T must support << operator
+ std::ostringstream ost;
+
+ ost << t;
+ return ost.str();
+}
+
+
+/* static */
+template<class T>
+T ConfigFile::string_as_T (const string& s)
+{
+ // Convert from a string to a T
+ // Type T must support >> operator
+ T t;
+ std::istringstream ist (s);
+
+ ist >> t;
+ return t;
+}
+
+
+/* static */
+template<>
+inline string ConfigFile::string_as_T<string>(const string& s)
+{
+ // Convert from a string to a string
+ // In other words, do nothing
+ return s;
+}
+
+
+/* static */
+template<>
+inline bool ConfigFile::string_as_T<bool>(const string& s)
+{
+ // Convert from a string to a bool
+ // Interpret "false", "F", "no", "n", "0" as false
+ // Interpret "true", "T", "yes", "y", "1", "-1", or anything else as true
+ bool b = true;
+ string sup = s;
+
+ for (string::iterator p = sup.begin(); p != sup.end(); ++p)
+ *p = toupper (*p); // make string all caps
+ if ( sup==string ("FALSE") || sup==string ("F")
+ || sup==string ("NO") || sup==string ("N")
+ || sup==string ("0") || sup==string ("NONE"))
+ b = false;
+ return b;
+}
+
+
+template<class T>
+T ConfigFile::read (const string& key) const
+{
+ // Read the value corresponding to key
+ mapci p = myContents.find (key);
+ if (p == myContents.end()) throw key_not_found (key);
+ return string_as_T<T>(p->second);
+}
+
+
+template<class T>
+T ConfigFile::read (const string& key, const T& value) const
+{
+ // Return the value corresponding to key or given default value
+ // if key is not found
+ mapci p = myContents.find (key);
+ if (p == myContents.end()) return value;
+ return string_as_T<T>(p->second);
+}
+
+
+template<class T>
+bool ConfigFile::readInto (T& var, const string& key) const
+{
+ // Get the value corresponding to key and store in var
+ // Return true if key is found
+ // Otherwise leave var untouched
+ mapci p = myContents.find (key);
+ bool found = (p != myContents.end());
+
+ if (found) var = string_as_T<T>(p->second);
+ return found;
+}
+
+
+template<class T>
+bool ConfigFile::readInto (T& var, const string& key, const T& value) const
+{
+ // Get the value corresponding to key and store in var
+ // Return true if key is found
+ // Otherwise set var to given default
+ mapci p = myContents.find (key);
+ bool found = (p != myContents.end());
+
+ if (found)
+ var = string_as_T<T>(p->second);
+ else
+ var = value;
+ return found;
+}
+
+
+template<class T>
+void ConfigFile::add (string key, const T& value)
+{
+ // Add a key with given value
+ string v = T_as_string (value);
+
+ trim (key);
+ trim (v);
+ myContents[key] = v;
+ return;
+}
+
+#endif // CONFIGFILE_H
+
+// Release notes:
+// v1.0 21 May 1999
+// + First release
+// + Template read() access only through non-member readConfigFile()
+// + ConfigurationFileBool is only built-in helper class
+//
+// v2.0 3 May 2002
+// + Shortened name from ConfigurationFile to ConfigFile
+// + Implemented template member functions
+// + Changed default comment separator from % to #
+// + Enabled reading of multiple-line values
+//
+// v2.1 24 May 2004
+// + Made template specializations inline to avoid compiler-dependent linkage
+// + Allowed comments within multiple-line values
+// + Enabled blank line termination for multiple-line values
+// + Added optional sentry to detect end of configuration file
+// + Rewrote messy trimWhitespace() function as elegant trim()
diff --git a/src/libprojectM/HungarianMethod.hpp b/src/libprojectM/HungarianMethod.hpp
index 4b6b93c..e68f5d8 100644
--- a/src/libprojectM/HungarianMethod.hpp
+++ b/src/libprojectM/HungarianMethod.hpp
@@ -1,11 +1,13 @@
#ifndef HUNGARIAN_METHOD_HPP
#define HUNGARIAN_METHOD_HPP
+//
//#include "Common.hpp"
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <limits>
+
/// A function object which calculates the maximum-weighted bipartite matching between
/// two sets via the hungarian method.
template <int N=20>
@@ -14,15 +16,15 @@
static const int MAX_SIZE = N;
private:
-int n, max_match; //n workers and n jobs
-double lx[N], ly[N]; //labels of X and Y parts
-int xy[N]; //xy[x] - vertex that is matched with x,
-int yx[N]; //yx[y] - vertex that is matched with y
-bool S[N], T[N]; //sets S and T in algorithm
-double slack[N]; //as in the algorithm description
-double slackx[N]; //slackx[y] such a vertex, that
- // l(slackx[y]) + l(y) - w(slackx[y],y) = slack[y]
-int prev[N]; //array for memorizing alternating paths
+int n, max_match; // n workers and n jobs
+double lx[N], ly[N]; // labels of X and Y parts
+int xy[N]; // xy[x] - vertex that is matched with x,
+int yx[N]; // yx[y] - vertex that is matched with y
+bool S[N], T[N]; // sets S and T in algorithm
+double slack[N]; // as in the algorithm description
+double slackx[N]; // slackx[y] such a vertex, that
+ // l(slackx[y]) + l(y) - w(slackx[y],y) = slack[y]
+int prev[N]; // array for memorizing alternating paths
void init_labels(const double cost[N][N])
{
@@ -56,7 +58,7 @@
slack[y] = lx[root] + ly[y] - cost[root][y];
slackx[y] = root;
}
- while (true) //main cycle
+ while (true) //main cycle
{
while (rd < wr) //building tree with bfs cycle
{
@@ -174,7 +176,7 @@
/// \param i the index of the ith element in the first set (passed in operator())
/// \returns an index j, denoting the matched jth element of the 2nd set
inline int matching(int i) const {
- return xy[i];
+ return xy[i];
}
@@ -183,7 +185,7 @@
/// \returns an index i, denoting the matched ith element of the 1st set
/// \note inverseMatching(matching(i)) == i
inline int inverseMatching(int j) const {
- return yx[j];
+ return yx[j];
}
};
diff --git a/src/libprojectM/KeyHandler.cpp b/src/libprojectM/KeyHandler.cpp
index 3661f2b..5ff80a4 100644
--- a/src/libprojectM/KeyHandler.cpp
+++ b/src/libprojectM/KeyHandler.cpp
@@ -18,7 +18,6 @@
* See 'LICENSE.txt' included within this release
*
*/
-
#include <stdio.h>
#include "Common.hpp"
@@ -34,17 +33,19 @@
#include "TimeKeeper.hpp"
+void selectRandom (const bool hardCut);
+void selectNext (const bool hardCut);
+void selectPrevious (const bool hardCut);
+
+
class Preset;
interface_t current_interface = DEFAULT_INTERFACE;
-void selectRandom(const bool hardCut);
-void selectNext(const bool hardCut);
-void selectPrevious(const bool hardCut);
-void refreshConsole() {
-
+void
+refreshConsole ()
+{
switch (current_interface) {
-
case MENU_INTERFACE:
// unimplemented
break;
@@ -62,192 +63,223 @@
default:
break;
}
-
}
-void projectM::key_handler( projectMEvent event,
- projectMKeycode keycode, projectMModifier modifier ) {
+void
+projectM::key_handler (
+projectMEvent event,
+projectMKeycode keycode,
+projectMModifier modifier
+)
+{
+ switch (event) {
+ case PROJECTM_KEYDOWN:
- switch( event ) {
+ //default_key_handler ();
+ switch (current_interface) {
+ case MENU_INTERFACE:
+// menu_key_handler (this, event, keycode);
+ break;
+ case SHELL_INTERFACE:
+// shell_key_handler ();
+ break;
- case PROJECTM_KEYDOWN:
+ case EDITOR_INTERFACE:
+// editor_key_handler (event,keycode);
+ break;
- //default_key_handler();
- switch (current_interface)
- {
+ case BROWSER_INTERFACE:
+// browser_key_handler (event,keycode,modifier);
+ break;
- case MENU_INTERFACE:
-// menu_key_handler(this, event, keycode);
- break;
- case SHELL_INTERFACE:
- //shell_key_handler();
- break;
- case EDITOR_INTERFACE:
-// editor_key_handler(event,keycode);
- break;
- case BROWSER_INTERFACE:
-// browser_key_handler(event,keycode,modifier);
- break;
- case DEFAULT_INTERFACE:
- default_key_handler(event,keycode);
- break;
- default:
- default_key_handler(event,keycode);
- break;
+ case DEFAULT_INTERFACE:
+ default_key_handler (event, keycode);
+ break;
- }
- break;
- default:
- break;
+ default:
+ default_key_handler (event, keycode);
+ break;
+ }
+ break;
- }
+ default:
+ break;
+ }
}
-void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode) {
+void
+projectM::default_key_handler (projectMEvent event, projectMKeycode keycode)
+{
+ switch (event) {
- switch( event ) {
+ case PROJECTM_KEYDOWN:
- case PROJECTM_KEYDOWN:
+ switch (keycode) {
+ case PROJECTM_K_UP:
+ beatDetect->beat_sensitivity += 0.25;
+ if (beatDetect->beat_sensitivity > 5.0) beatDetect->beat_sensitivity = 5.0;
+ break;
- switch( keycode )
- {
- case PROJECTM_K_UP:
- beatDetect->beat_sensitivity += 0.25;
- if (beatDetect->beat_sensitivity > 5.0) beatDetect->beat_sensitivity = 5.0;
- break;
- case PROJECTM_K_DOWN:
- beatDetect->beat_sensitivity -= 0.25;
- if (beatDetect->beat_sensitivity < 0) beatDetect->beat_sensitivity = 0;
- break;
- case PROJECTM_K_h:
- renderer->showhelp = !renderer->showhelp;
- renderer->showstats= false;
- renderer->showfps=false;
- case PROJECTM_K_F1:
- renderer->showhelp = !renderer->showhelp;
- renderer->showstats=false;
- renderer->showfps=false;
- break;
- case PROJECTM_K_y:
- this->setShuffleEnabled(!this->isShuffleEnabled());
- break;
+ case PROJECTM_K_DOWN:
+ beatDetect->beat_sensitivity -= 0.25;
+ if (beatDetect->beat_sensitivity < 0) beatDetect->beat_sensitivity = 0;
+ break;
- case PROJECTM_K_F5:
- if (!renderer->showhelp)
- renderer->showfps = !renderer->showfps;
- break;
- case PROJECTM_K_F4:
- if (!renderer->showhelp)
- renderer->showstats = !renderer->showstats;
- break;
- case PROJECTM_K_F3: {
- renderer->showpreset = !renderer->showpreset;
- break;
- }
- case PROJECTM_K_F2:
- renderer->showtitle = !renderer->showtitle;
- break;
+ case PROJECTM_K_h:
+ renderer->showhelp = !renderer->showhelp;
+ renderer->showstats = false;
+ renderer->showfps = false;
+ /* FIXME: should be 'break' here or folded into following case. */
+
+ case PROJECTM_K_F1:
+ renderer->showhelp = !renderer->showhelp;
+ renderer->showstats = false;
+ renderer->showfps = false;
+ break;
+
+ case PROJECTM_K_y:
+ this->setShuffleEnabled (!this->isShuffleEnabled());
+ break;
+
+ case PROJECTM_K_F5:
+ if (!renderer->showhelp)
+ renderer->showfps = !renderer->showfps;
+ break;
+
+ case PROJECTM_K_F4:
+ if (!renderer->showhelp)
+ renderer->showstats = !renderer->showstats;
+ break;
+
+ case PROJECTM_K_F3:
+ {
+ renderer->showpreset = !renderer->showpreset;
+ break;
+ }
+
+ case PROJECTM_K_F2:
+ renderer->showtitle = !renderer->showtitle;
+ break;
#ifndef MACOS
- case PROJECTM_K_F9:
+ case PROJECTM_K_F9:
#else
- case PROJECTM_K_F8:
+ case PROJECTM_K_F8:
#endif
- renderer->studio = !renderer->studio;
- break;
+ renderer->studio = !renderer->studio;
+ break;
- case PROJECTM_K_ESCAPE: {
-// exit( 1 );
- break;
- }
- case PROJECTM_K_f:
+ case PROJECTM_K_ESCAPE:
+ {
+ // exit (1);
+ break;
+ }
- break;
- case PROJECTM_K_a:
- renderer->correction = !renderer->correction;
- break;
- case PROJECTM_K_b:
- break;
- case PROJECTM_K_n:
- selectNext(true);
- break;
- case PROJECTM_K_N:
- selectNext(false);
- break;
- case PROJECTM_K_r:
- selectRandom(true);
- break;
- case PROJECTM_K_R:
- selectRandom(false);
- break;
- case PROJECTM_K_p:
- selectPrevious(true);
- break;
- case PROJECTM_K_P:
- selectPrevious(false);
- break;
- case PROJECTM_K_l:
- renderer->noSwitch=!renderer->noSwitch;
- break;
- case PROJECTM_K_s:
- renderer->studio = !renderer->studio;
- case PROJECTM_K_i:
- break;
- case PROJECTM_K_z:
- break;
- case PROJECTM_K_0:
-// nWaveMode=0;
- break;
- case PROJECTM_K_6:
-// nWaveMode=6;
- break;
- case PROJECTM_K_7:
-// nWaveMode=7;
- break;
- case PROJECTM_K_m:
- break;
- case PROJECTM_K_t:
- break;
- case PROJECTM_K_EQUALS:
- case PROJECTM_K_PLUS:
+ case PROJECTM_K_f:
+ break;
- unsigned int index;
+ case PROJECTM_K_a:
+ renderer->correction = !renderer->correction;
+ break;
- if (selectedPresetIndex(index)) {
+ case PROJECTM_K_b:
+ break;
- const int oldRating = getPresetRating(index, HARD_CUT_RATING_TYPE);
+ case PROJECTM_K_n:
+ selectNext (true);
+ break;
- if (oldRating >= 6)
- break;
+ case PROJECTM_K_N:
+ selectNext (false);
+ break;
- const int rating = oldRating + 1;
+ case PROJECTM_K_r:
+ selectRandom (true);
+ break;
- changePresetRating(index, rating, HARD_CUT_RATING_TYPE);
- }
+ case PROJECTM_K_R:
+ selectRandom (false);
+ break;
- break;
+ case PROJECTM_K_p:
+ selectPrevious (true);
+ break;
- case PROJECTM_K_MINUS:
- if (selectedPresetIndex(index)) {
+ case PROJECTM_K_P:
+ selectPrevious (false);
+ break;
- const int oldRating = getPresetRating(index, HARD_CUT_RATING_TYPE);
+ case PROJECTM_K_l:
+ renderer->noSwitch=!renderer->noSwitch;
+ break;
- if (oldRating <= 1)
- break;
+ case PROJECTM_K_s:
+ renderer->studio = !renderer->studio;
- const int rating = oldRating - 1;
+ case PROJECTM_K_i:
+ break;
- changePresetRating(index, rating, HARD_CUT_RATING_TYPE);
- }
- break;
+ case PROJECTM_K_z:
+ break;
- default:
- break;
- }
- default:
- break;
+ case PROJECTM_K_0:
+ // nWaveMode=0;
+ break;
- }
+ case PROJECTM_K_6:
+ // nWaveMode=6;
+ break;
+
+ case PROJECTM_K_7:
+ // nWaveMode=7;
+ break;
+
+ case PROJECTM_K_m:
+ break;
+
+ case PROJECTM_K_t:
+ break;
+
+ case PROJECTM_K_EQUALS:
+ case PROJECTM_K_PLUS:
+ {
+ unsigned int index;
+
+ if (selectedPresetIndex (index)) {
+ const int oldRating = getPresetRating (index, HARD_CUT_RATING_TYPE);
+
+ if (oldRating >= 6)
+ break;
+
+ const int rating = oldRating + 1;
+
+ changePresetRating (index, rating, HARD_CUT_RATING_TYPE);
+ }
+ break;
+ }
+
+ case PROJECTM_K_MINUS:
+ {
+ unsigned int index;
+
+ if (selectedPresetIndex (index)) {
+ const int oldRating = getPresetRating (index, HARD_CUT_RATING_TYPE);
+
+ if (oldRating <= 1)
+ break;
+
+ const int rating = oldRating - 1;
+
+ changePresetRating (index, rating, HARD_CUT_RATING_TYPE);
+ }
+ break;
+ }
+
+ default:
+ break;
+ }
+ default:
+ break;
+ }
}
-
diff --git a/src/libprojectM/KeyHandler.hpp b/src/libprojectM/KeyHandler.hpp
index b9a7563..7143e56 100644
--- a/src/libprojectM/KeyHandler.hpp
+++ b/src/libprojectM/KeyHandler.hpp
@@ -1,39 +1,39 @@
-/**
- * projectM -- Milkdrop-esque visualisation SDK
- * Copyright (C)2003-2007 projectM Team
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * See 'LICENSE.txt' included within this release
- *
- */
-/**
- * $Id: console_interface.h,v 1.1.1.1 2005/12/23 18:05:03 psperl Exp $
- *
- * $Log$
- */
-
-#ifndef _KEY_HANDLER_HPP
-#define _KEY_HANDLER_HPP
-
-#include "event.h"
-class projectM;
-void default_key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode);
-void refreshConsole();
-#if defined(__CPLUSPLUS) && !defined(MACOS)
-extern "C" void key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode, projectMModifier modifier );
-#else
-extern void key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode, projectMModifier modifier );
-#endif
-#endif /** !_KEY_HANDLER_HPP */
+/**
+ * projectM -- Milkdrop-esque visualisation SDK
+ * Copyright (C)2003-2007 projectM Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * See 'LICENSE.txt' included within this release
+ *
+ */
+/**
+ * $Id: console_interface.h,v 1.1.1.1 2005/12/23 18:05:03 psperl Exp $
+ *
+ * $Log$
+ */
+
+#ifndef _KEY_HANDLER_HPP
+#define _KEY_HANDLER_HPP
+
+#include "event.h"
+class projectM;
+void default_key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode);
+void refreshConsole();
+#if defined(__CPLUSPLUS) && !defined(MACOS)
+extern "C" void key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode, projectMModifier modifier );
+#else
+extern void key_handler(projectM *PM, projectMEvent event, projectMKeycode keycode, projectMModifier modifier );
+#endif
+#endif /** !_KEY_HANDLER_HPP */
diff --git a/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.cpp b/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.cpp
index 1063fd9..a539154 100644
--- a/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.cpp
@@ -1,8 +1,8 @@
//
// C++ Implementation: BuiltinFuncs
//
-// Description:
-//
+// Description:
+//
//
// Author: Carmelo Piccione <carmelo.piccione@gmail.com>, (C) 2007
//
@@ -19,97 +19,104 @@
#include <iostream>
#include "fatal.h"
+
std::map<std::string, Func*> BuiltinFuncs::builtin_func_tree;
-int BuiltinFuncs::load_builtin_func(const std::string & name, float (*func_ptr)(float*), int num_args) {
-
- Func * func;
- int retval;
+
+int
+BuiltinFuncs::load_builtin_func (
+const std::string & name,
+float (*func_ptr)(float*),
+int num_args
+)
+{
+ Func * func;
+ int retval;
/* Create new function */
- func = new Func(name, func_ptr, num_args);
+ func = new Func (name, func_ptr, num_args);
if (func == 0)
return PROJECTM_OUTOFMEM_ERROR;
- retval = insert_func( func );
+ retval = insert_func (func);
return retval;
-
}
-Func * BuiltinFuncs::find_func(const std::string & name) {
-
- std::map<std::string, Func*>::iterator pos = builtin_func_tree.find(name);
+Func *
+BuiltinFuncs::find_func (const std::string & name)
+{
+ std::map<std::string, Func*>::iterator pos = builtin_func_tree.find (name);
// Case: function not found, return null
if (pos == builtin_func_tree.end())
- return 0;
+ return 0;
// Case: function found, return a pointer to it
return pos->second;
-
}
-int BuiltinFuncs::load_all_builtin_func() {
-
- if (load_builtin_func("int", FuncWrappers::int_wrapper, 1) < 0)
+int
+BuiltinFuncs::load_all_builtin_func()
+{
+ if (load_builtin_func ("int", FuncWrappers::int_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("abs", FuncWrappers::abs_wrapper, 1) < 0)
+ if (load_builtin_func ("abs", FuncWrappers::abs_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("sin", FuncWrappers::sin_wrapper, 1) < 0)
+ if (load_builtin_func ("sin", FuncWrappers::sin_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("cos", FuncWrappers::cos_wrapper, 1) < 0)
+ if (load_builtin_func ("cos", FuncWrappers::cos_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("tan", FuncWrappers::tan_wrapper, 1) < 0)
+ if (load_builtin_func ("tan", FuncWrappers::tan_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("asin", FuncWrappers::asin_wrapper, 1) < 0)
+ if (load_builtin_func ("asin", FuncWrappers::asin_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("acos", FuncWrappers::acos_wrapper, 1) < 0)
+ if (load_builtin_func ("acos", FuncWrappers::acos_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("atan", FuncWrappers::atan_wrapper, 1) < 0)
+ if (load_builtin_func ("atan", FuncWrappers::atan_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("sqr", FuncWrappers::sqr_wrapper, 1) < 0)
+ if (load_builtin_func ("sqr", FuncWrappers::sqr_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("sqrt", FuncWrappers::sqrt_wrapper, 1) < 0)
+ if (load_builtin_func ("sqrt", FuncWrappers::sqrt_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("pow", FuncWrappers::pow_wrapper, 2) < 0)
+ if (load_builtin_func ("pow", FuncWrappers::pow_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("exp", FuncWrappers::exp_wrapper, 1) < 0)
+ if (load_builtin_func ("exp", FuncWrappers::exp_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("log", FuncWrappers::log_wrapper, 1) < 0)
+ if (load_builtin_func ("log", FuncWrappers::log_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("log10", FuncWrappers::log10_wrapper, 1) < 0)
+ if (load_builtin_func ("log10", FuncWrappers::log10_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("sign", FuncWrappers::sign_wrapper, 1) < 0)
+ if (load_builtin_func ("sign", FuncWrappers::sign_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("min", FuncWrappers::min_wrapper, 2) < 0)
+ if (load_builtin_func ("min", FuncWrappers::min_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("max", FuncWrappers::max_wrapper, 2) < 0)
+ if (load_builtin_func ("max", FuncWrappers::max_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("sigmoid", FuncWrappers::sigmoid_wrapper, 2) < 0)
+ if (load_builtin_func ("sigmoid", FuncWrappers::sigmoid_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("atan2", FuncWrappers::atan2_wrapper, 2) < 0)
+ if (load_builtin_func ("atan2", FuncWrappers::atan2_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("rand", FuncWrappers::rand_wrapper, 1) < 0)
+ if (load_builtin_func ("rand", FuncWrappers::rand_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("band", FuncWrappers::band_wrapper, 2) < 0)
+ if (load_builtin_func ("band", FuncWrappers::band_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("bor", FuncWrappers::bor_wrapper, 2) < 0)
+ if (load_builtin_func ("bor", FuncWrappers::bor_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("bnot", FuncWrappers::bnot_wrapper, 1) < 0)
+ if (load_builtin_func ("bnot", FuncWrappers::bnot_wrapper, 1) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("if", FuncWrappers::if_wrapper, 3) < 0)
+ if (load_builtin_func ("if", FuncWrappers::if_wrapper, 3) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("equal", FuncWrappers::equal_wrapper, 2) < 0)
+ if (load_builtin_func ("equal", FuncWrappers::equal_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("above", FuncWrappers::above_wrapper, 2) < 0)
+ if (load_builtin_func ("above", FuncWrappers::above_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("below", FuncWrappers::below_wrapper, 2) < 0)
+ if (load_builtin_func ("below", FuncWrappers::below_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("nchoosek", FuncWrappers::nchoosek_wrapper, 2) < 0)
+ if (load_builtin_func ("nchoosek", FuncWrappers::nchoosek_wrapper, 2) < 0)
return PROJECTM_ERROR;
- if (load_builtin_func("fact", FuncWrappers::fact_wrapper, 1) < 0)
+ if (load_builtin_func ("fact", FuncWrappers::fact_wrapper, 1) < 0)
return PROJECTM_ERROR;
return PROJECTM_SUCCESS;
@@ -119,14 +126,16 @@
/* Initialize the builtin function database.
Should only be necessary once */
-int BuiltinFuncs::init_builtin_func_db() {
+int
+BuiltinFuncs::init_builtin_func_db()
+{
int retval;
if (initialized) {
return 0;
} else
initialized = true;
-
+
retval = load_all_builtin_func();
return retval;
}
@@ -135,40 +144,40 @@
/* Destroy the builtin function database.
Generally, do this on projectm exit */
-int BuiltinFuncs::destroy_builtin_func_db() {
+int
+BuiltinFuncs::destroy_builtin_func_db()
+{
+ traverse<TraverseFunctors::Delete<Func> >(builtin_func_tree);
-traverse<TraverseFunctors::Delete<Func> >(builtin_func_tree);
-
-builtin_func_tree.clear();
-initialized = false;
-return PROJECTM_SUCCESS;
+ builtin_func_tree.clear();
+ initialized = false;
+ return PROJECTM_SUCCESS;
}
/* Insert a function into the database */
-int BuiltinFuncs::insert_func( Func *func ) {
+int
+BuiltinFuncs::insert_func (Func *func)
+{
+ assert (func);
- assert(func);
-
if (func == 0) {
- std::cerr << "Received a null function object, ignoring...." << std::endl;
- return PROJECTM_ERROR;
+ std::cerr << "Received a null function object, ignoring...." << std::endl;
+ return PROJECTM_ERROR;
}
-
+
// //std::cout << "inserting function " << func->getName() << std::endl;
-
- const std::pair<std::string, Func*> pair = std::make_pair(std::string(func->getName()), func);
-
- assert(pair.second);
-
+
+ const std::pair<std::string, Func*> pair = std::make_pair (std::string (func->getName()), func);
+
+ assert (pair.second);
+
const std::pair<std::map<std::string, Func*>::iterator, bool> inserteePair =
- builtin_func_tree.insert(pair);
-
+ builtin_func_tree.insert (pair);
+
if (!inserteePair.second) {
- std::cerr << "Failed to insert builtin function \"" << func->getName() << "\" into collection! Bailing..." << std::endl;
- abort();
+ std::cerr << "Failed to insert builtin function \"" << func->getName() << "\" into collection! Bailing..." << std::endl;
+ abort();
}
return PROJECTM_SUCCESS;
}
-
-
diff --git a/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.hpp b/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.hpp
index 8b1e7e2..777eb5c 100644
--- a/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/BuiltinFuncs.hpp
@@ -21,6 +21,7 @@
#include "RandomNumberGenerators.hpp"
+
/* Wrappers for all the builtin functions
The arg_list pointer is a list of floats. Its
size is equal to the number of arguments the parameter
@@ -33,203 +34,252 @@
public:
-static inline float int_wrapper(float * arg_list) {
-
-return floor(arg_list[0]);
-
-}
-
-
-static inline float sqr_wrapper(float * arg_list) {
- return pow(arg_list[0], 2);
-}
-
-
-static inline float sigmoid_wrapper(float * arg_list)
+static inline float
+int_wrapper(float * arg_list)
{
- const double t = (1+exp(-arg_list[0]*arg_list[1]));
- return (fabs(t) > 0.00001) ? 1.0/t : 0;
-}
-
-static inline float sign_wrapper(float * arg_list) {
-
-return -arg_list[0];
-}
-
-static inline float min_wrapper(float * arg_list) {
-
-if (arg_list[0] > arg_list[1])
-return arg_list[1];
-
-return arg_list[0];
-}
-
-static inline float max_wrapper(float * arg_list) {
-
-if (arg_list[0] > arg_list[1])
-return arg_list[0];
-
-return arg_list[1];
+ return floor(arg_list[0]);
}
-static inline float bor_wrapper(float * arg_list) {
-
-return (float)((int)arg_list[0] || (int)arg_list[1]);
-}
-
-static inline float band_wrapper(float * arg_list) {
-return (float)((int)arg_list[0] && (int)arg_list[1]);
-}
-
-static inline float bnot_wrapper(float * arg_list) {
-return (float)(!(int)arg_list[0]);
-}
-
-static inline float if_wrapper(float * arg_list) {
-
-if ((int)arg_list[0] == 0)
-return arg_list[2];
-return arg_list[1];
+static inline float
+sqr_wrapper(float * arg_list)
+{
+ return pow(arg_list[0], 2);
}
-static inline float rand_wrapper(float * arg_list) {
-float l=1;
-
-// printf("RAND ARG:(%d)\n", (int)arg_list[0]);
-if ((int)arg_list[0] > 0)
- l = (float) RandomNumberGenerators::uniformInteger((int)arg_list[0]);
-
-return l;
+static inline float
+sigmoid_wrapper(float * arg_list)
+{
+ const double t = (1+exp(-arg_list[0]*arg_list[1]));
+ return (fabs(t) > 0.00001) ? 1.0/t : 0;
}
-static inline float equal_wrapper(float * arg_list) {
- return (arg_list[0] == arg_list[1]);
+static inline float
+sign_wrapper(float * arg_list)
+{
+ return -arg_list[0];
+}
+
+static inline float
+min_wrapper(float * arg_list)
+{
+ if (arg_list[0] > arg_list[1])
+ return arg_list[1];
+
+ return arg_list[0];
+}
+
+static inline float
+max_wrapper(float * arg_list)
+{
+ if (arg_list[0] > arg_list[1])
+ return arg_list[0];
+
+ return arg_list[1];
}
-static inline float above_wrapper(float * arg_list) {
+static inline float
+bor_wrapper(float * arg_list)
+{
+ return (float)((int)arg_list[0] || (int)arg_list[1]);
+}
-return (arg_list[0] > arg_list[1]);
+static inline float
+band_wrapper(float * arg_list)
+{
+ return (float)((int)arg_list[0] && (int)arg_list[1]);
+}
+
+static inline float
+bnot_wrapper(float * arg_list)
+{
+ return (float)(!(int)arg_list[0]);
+}
+
+static inline float
+if_wrapper(float * arg_list)
+{
+ if ((int)arg_list[0] == 0)
+ return arg_list[2];
+ return arg_list[1];
}
-static inline float below_wrapper(float * arg_list) {
+static inline float
+rand_wrapper(float * arg_list)
+{
+ float l=1;
-return (arg_list[0] < arg_list[1]);
+ // printf("RAND ARG:(%d)\n", (int)arg_list[0]);
+ if ((int)arg_list[0] > 0)
+ l = (float) RandomNumberGenerators::uniformInteger((int)arg_list[0]);
+
+ return l;
}
-static float sin_wrapper(float * arg_list) {
+static inline float
+equal_wrapper(float * arg_list)
+{
+ return (arg_list[0] == arg_list[1]);
+}
+
+static inline float
+above_wrapper(float * arg_list)
+{
+ return (arg_list[0] > arg_list[1]);
+}
+
+
+static inline float
+below_wrapper(float * arg_list)
+{
+ return (arg_list[0] < arg_list[1]);
+}
+
+static float
+sin_wrapper(float * arg_list)
+{
assert(arg_list);
-//return .5;
-float d = sinf(*arg_list);
-return d;
-//return (sin (arg_list[0]));
+ //return .5;
+ float d = sinf(*arg_list);
+ return d;
+ //return (sin (arg_list[0]));
}
-static inline float cos_wrapper(float * arg_list) {
-return (cos (arg_list[0]));
-}
-
-static inline float tan_wrapper(float * arg_list) {
-return (tan(arg_list[0]));
-}
-
-static inline float asin_wrapper(float * arg_list) {
-return (asin (arg_list[0]));
-}
-
-static inline float acos_wrapper(float * arg_list) {
-return (acos (arg_list[0]));
-}
-
-static inline float atan_wrapper(float * arg_list) {
-return (atan (arg_list[0]));
-}
-
-static inline float atan2_wrapper(float * arg_list) {
-return (atan2 (arg_list[0], arg_list[1]));
-}
-
-static inline float pow_wrapper(float * arg_list) {
-return (pow (arg_list[0], arg_list[1]));
-}
-
-static inline float exp_wrapper(float * arg_list) {
-return (exp(arg_list[0]));
-}
-
-static inline float abs_wrapper(float * arg_list) {
-return (fabs(arg_list[0]));
-}
-
-static inline float log_wrapper(float* arg_list) {
-return (log (arg_list[0]));
-}
-
-static inline float log10_wrapper(float * arg_list) {
-return (log10 (arg_list[0]));
-}
-
-static inline float sqrt_wrapper(float * arg_list) {
-return (sqrt (arg_list[0]));
-}
-
-
-static inline float nchoosek_wrapper(float * arg_list) {
-unsigned long cnm = 1UL;
-int i, f;
-int n, m;
-
-n = (int)arg_list[0];
-m = (int)arg_list[1];
-
-if (m*2 >n) m = n-m;
-for (i=1 ; i <= m; n--, i++)
+static inline float
+cos_wrapper(float * arg_list)
{
-if ((f=n) % i == 0)
-f /= i;
-else cnm /= i;
-cnm *= f;
+ return (cos (arg_list[0]));
}
-return (float)cnm;
+
+static inline float
+tan_wrapper(float * arg_list)
+{
+ return (tan(arg_list[0]));
+}
+
+static inline float
+asin_wrapper(float * arg_list)
+{
+ return (asin (arg_list[0]));
+}
+
+static inline float
+acos_wrapper(float * arg_list)
+{
+ return (acos (arg_list[0]));
+}
+
+static inline float
+atan_wrapper(float * arg_list)
+{
+ return (atan (arg_list[0]));
+}
+
+static inline float
+atan2_wrapper(float * arg_list)
+{
+ return (atan2 (arg_list[0], arg_list[1]));
+}
+
+static inline float
+pow_wrapper(float * arg_list)
+{
+ return (pow (arg_list[0], arg_list[1]));
+}
+
+static inline float
+exp_wrapper(float * arg_list)
+{
+ return (exp(arg_list[0]));
+}
+
+static inline float
+abs_wrapper(float * arg_list)
+{
+ return (fabs(arg_list[0]));
+}
+
+static inline float
+log_wrapper(float* arg_list)
+{
+ return (log (arg_list[0]));
+}
+
+static inline float
+log10_wrapper(float * arg_list)
+{
+ return (log10 (arg_list[0]));
+}
+
+static inline float
+sqrt_wrapper(float * arg_list)
+{
+ return (sqrt (arg_list[0]));
}
-static inline float fact_wrapper(float * arg_list) {
+static inline float
+nchoosek_wrapper(float * arg_list)
+{
+ unsigned long cnm = 1UL;
+ int i, f;
+ int n, m;
+ n = (int)arg_list[0];
+ m = (int)arg_list[1];
-int result = 1;
-
-int n = (int)arg_list[0];
-
-while (n > 1) {
-result = result * n;
-n--;
+ if (m * 2 > n)
+ m = n - m;
+ for (i = 1; i <= m; n--, i++)
+ {
+ if ((f = n) % i == 0)
+ f /= i;
+ else
+ cnm /= i;
+ cnm *= f;
+ }
+ return (float)cnm;
}
-return (float)result;
+
+
+static inline float
+fact_wrapper(float * arg_list)
+{
+ int result = 1;
+
+ int n = (int)arg_list[0];
+
+ while (n > 1) {
+ result = result * n;
+ n--;
+ }
+ return (float)result;
}
-};
+
+}; /* class FuncWrappers */
#include <map>
+
+
class BuiltinFuncs {
-
public:
-
- static int init_builtin_func_db();
- static int destroy_builtin_func_db();
- static int load_all_builtin_func();
- static int load_builtin_func( const std::string & name, float (*func_ptr)(float*), int num_args );
+ static int init_builtin_func_db();
+ static int destroy_builtin_func_db();
+ static int load_all_builtin_func();
+ static int load_builtin_func( const std::string & name, float (*func_ptr)(float*), int num_args );
- static int insert_func( Func *func );
- static int remove_func( Func *func );
- static Func *find_func( const std::string & name );
+ static int insert_func( Func *func );
+ static int remove_func( Func *func );
+ static Func *find_func( const std::string & name );
+
private:
- static std::map<std::string, Func*> builtin_func_tree;
- static volatile bool initialized;
+ static std::map<std::string, Func*> builtin_func_tree;
+ static volatile bool initialized;
};
#endif
diff --git a/src/libprojectM/MilkdropPresetFactory/BuiltinParams.cpp b/src/libprojectM/MilkdropPresetFactory/BuiltinParams.cpp
index e33149b..880caa7 100644
--- a/src/libprojectM/MilkdropPresetFactory/BuiltinParams.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/BuiltinParams.cpp
@@ -1,4 +1,3 @@
-
#include "fatal.h"
#include "BuiltinParams.hpp"
#include <cassert>
@@ -9,18 +8,18 @@
#include <stdio.h>
#include "Common.hpp"
+
BuiltinParams::BuiltinParams() {}
BuiltinParams::BuiltinParams(PresetInputs & presetInputs, PresetOutputs & presetOutputs)
{
-
presetInputs.Initialize(presetOutputs.gx, presetOutputs.gy);
int ret;
if ((ret = init_builtin_param_db(presetInputs, presetOutputs)) != PROJECTM_SUCCESS)
{
- std::cout << "failed to allocate builtin parameter database with error " << ret << std::endl;;
- throw ret;
+ std::cout << "failed to allocate builtin parameter database with error " << ret << std::endl;;
+ throw ret;
}
}
@@ -31,12 +30,20 @@
}
/* Loads a float parameter into the builtin database */
-int BuiltinParams::load_builtin_param_float(const std::string & name, void * engine_val, void * matrix, short int flags,
- float init_val, float upper_bound, float lower_bound, const std::string & alt_name)
+int
+BuiltinParams::load_builtin_param_float (
+const std::string & name,
+void * engine_val,
+void * matrix,
+short int flags,
+float init_val,
+float upper_bound,
+float lower_bound,
+const std::string & alt_name
+)
{
-
- Param * param = NULL;
- CValue iv, ub, lb;
+ Param * param = NULL;
+ CValue iv, ub, lb;
iv.float_val = init_val;
ub.float_val = upper_bound;
@@ -49,8 +56,9 @@
fflush(stdout);
}
-std::string lowerName(name);
-std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), tolower);
+ std::string lowerName(name);
+
+ std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), tolower);
if ((param = new Param(lowerName, P_TYPE_DOUBLE, flags, engine_val, matrix, iv, ub, lb)) == NULL)
{
@@ -82,6 +90,7 @@
if (alt_name != "")
{
std::string alt_lower_name(alt_name);
+
std::transform(alt_lower_name.begin(), alt_lower_name.end(), alt_lower_name.begin(), tolower);
insert_param_alt_name(param,alt_lower_name);
@@ -90,8 +99,6 @@
printf("alt_name inserted...");
fflush(stdout);
}
-
-
}
if (BUILTIN_PARAMS_DEBUG == 2) printf("finished\n");
@@ -104,18 +111,18 @@
/* Destroy the builtin parameter database.
Generally, do this on projectm exit */
-int BuiltinParams::destroy_builtin_param_db()
+int
+BuiltinParams::destroy_builtin_param_db()
{
-
traverse<TraverseFunctors::Delete<Param> >(builtin_param_tree);
return PROJECTM_SUCCESS;
}
/* Insert a parameter into the database with an alternate name */
-int BuiltinParams::insert_param_alt_name(Param * param, const std::string & alt_name)
+int
+BuiltinParams::insert_param_alt_name(Param * param, const std::string & alt_name)
{
-
assert(param);
aliasMap.insert(std::make_pair(alt_name, param->name));
@@ -123,45 +130,49 @@
return PROJECTM_SUCCESS;
}
-Param * BuiltinParams::find_builtin_param(const std::string & name)
+Param *
+BuiltinParams::find_builtin_param(const std::string & name)
{
+ AliasMap::iterator pos = aliasMap.find(name);
+ Param * param = 0;
-
-
- AliasMap::iterator pos = aliasMap.find(name);
- Param * param = 0;
//std::cerr << "[BuiltinParams] find_builtin_param: name is " << name << std::endl;
if (pos == aliasMap.end())
{
std::map<std::string, Param*>::iterator builtinPos = builtin_param_tree.find(name);
if (builtinPos != builtin_param_tree.end()) {
- // std::cerr << "[BuiltinParams] find_builtin_param: found it directly." << std::endl;
+ // std::cerr << "[BuiltinParams] find_builtin_param: found it directly." << std::endl;
param = builtinPos->second;
- }
+ }
}
else
{
-
std::map<std::string, Param*>::iterator builtinPos = builtin_param_tree.find(pos->second);
if (builtinPos != builtin_param_tree.end()) {
//std::cerr << "[BuiltinParams] find_builtin_param: found it indirectly." << std::endl;
param = builtinPos->second;
-
-}
+ }
}
return param;
}
/* Loads a integer parameter into the builtin database */
-int BuiltinParams::load_builtin_param_int(const std::string & name, void * engine_val, short int flags,
- int init_val, int upper_bound, int lower_bound, const std::string &alt_name)
+int
+BuiltinParams::load_builtin_param_int (
+const std::string &name,
+void *engine_val,
+short int flags,
+int init_val,
+int upper_bound,
+int lower_bound,
+const std::string &alt_name
+)
{
-
- Param * param;
- CValue iv, ub, lb;
+ Param * param;
+ CValue iv, ub, lb;
iv.int_val = init_val;
ub.int_val = upper_bound;
@@ -169,6 +180,7 @@
// normalize to lower case as milkdrop scripts depend on this
std::string lowerName(name);
+
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), tolower);
param = new Param(lowerName, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb);
@@ -187,42 +199,52 @@
if (alt_name != "")
{
std::string alt_lower_name(alt_name);
+
std::transform(alt_lower_name.begin(), alt_lower_name.end(), alt_lower_name.begin(), tolower);
insert_param_alt_name(param,alt_lower_name);
-
}
return PROJECTM_SUCCESS;
-
}
-int BuiltinParams::load_builtin_param_string( const std::string & name, std::string * engine_val, short int flags) {
+int
+BuiltinParams::load_builtin_param_string (
+const std::string &name,
+std::string *engine_val,
+short int flags
+)
+{
+ /* Creates a new parameter of type string */
+ Param * param = Param::new_param_string(name.c_str(), flags, engine_val);
- /* Creates a new parameter of type string */
- Param * param = Param::new_param_string(name.c_str(), flags, engine_val);
-
- if (insert_builtin_param( param ) < 0)
- {
- delete param;
- return PROJECTM_ERROR;
- }
- return PROJECTM_SUCCESS;
+ if (insert_builtin_param( param ) < 0)
+ {
+ delete param;
+ return PROJECTM_ERROR;
+ }
+ return PROJECTM_SUCCESS;
}
/* Loads a boolean parameter */
-int BuiltinParams::load_builtin_param_bool(const std:: string & name, void * engine_val, short int flags,
- int init_val, const std::string &alt_name)
+int
+BuiltinParams::load_builtin_param_bool (
+const std::string &name,
+void *engine_val,
+short int flags,
+int init_val,
+const std::string &alt_name
+)
{
-
- Param * param;
- CValue iv, ub, lb;
+ Param * param;
+ CValue iv, ub, lb;
iv.int_val = init_val;
ub.int_val = TRUE;
lb.int_val = false;
-std::string lowerName(name);
-std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), tolower);
+ std::string lowerName(name);
+
+ std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), tolower);
param = new Param(lowerName, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb);
@@ -240,16 +262,17 @@
if (alt_name != "")
{
std::string alt_lower_name(alt_name);
+
std::transform(alt_lower_name.begin(), alt_lower_name.end(), alt_lower_name.begin(), tolower);
insert_param_alt_name(param,alt_lower_name);
}
return PROJECTM_SUCCESS;
-
}
/* Inserts a parameter into the builtin database */
-int BuiltinParams::insert_builtin_param( Param *param )
+int
+BuiltinParams::insert_builtin_param( Param *param )
{
std::pair<std::map<std::string, Param*>::iterator, bool> inserteePos = builtin_param_tree.insert(std::make_pair(param->name, param));
@@ -260,9 +283,12 @@
/* Initialize the builtin parameter database.
Should only be necessary once */
-int BuiltinParams::init_builtin_param_db(const PresetInputs & presetInputs, PresetOutputs & presetOutputs)
+int
+BuiltinParams::init_builtin_param_db (
+const PresetInputs & presetInputs,
+PresetOutputs & presetOutputs
+)
{
-
if (BUILTIN_PARAMS_DEBUG)
{
printf("init_builtin_param: loading database...");
@@ -273,7 +299,7 @@
if (load_all_builtin_param(presetInputs, presetOutputs) < 0)
{
if (BUILTIN_PARAMS_DEBUG) printf("failed loading builtin parameters (FATAL)\n");
- return PROJECTM_ERROR;
+ return PROJECTM_ERROR;
}
if (BUILTIN_PARAMS_DEBUG) printf("success!\n");
@@ -285,9 +311,12 @@
/* Loads all builtin parameters, limits are also defined here */
-int BuiltinParams::load_all_builtin_param(const PresetInputs & presetInputs, PresetOutputs & presetOutputs)
+int
+BuiltinParams::load_all_builtin_param (
+const PresetInputs & presetInputs,
+PresetOutputs & presetOutputs
+)
{
-
load_builtin_param_float("frating", (void*)&presetOutputs.fRating, NULL, P_FLAG_NONE, 0.0 , 5.0, 0.0, "");
load_builtin_param_float("fwavescale", (void*)&presetOutputs.wave.scale, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
load_builtin_param_float("gamma", (void*)&presetOutputs.fGammaAdj, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fGammaAdj");
@@ -386,19 +415,25 @@
load_builtin_param_int("fps", (void*)&presetInputs.fps, P_FLAG_READONLY, 15, MAX_INT_SIZE, 0, "");
load_builtin_param_float("x", (void*)&presetInputs.x_per_pixel, presetInputs.origx, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_NONE,
- 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
+ 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
load_builtin_param_float("y", (void*)&presetInputs.y_per_pixel, presetInputs.origy, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX |P_FLAG_READONLY | P_FLAG_NONE,
- 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
+ 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
load_builtin_param_float("ang", (void*)&presetInputs.ang_per_pixel, presetInputs.origtheta, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_NONE,
- 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
+ 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
load_builtin_param_float("rad", (void*)&presetInputs.rad_per_pixel, presetInputs.origrad, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_NONE,
- 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
+ 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
- for (unsigned int i = 0; i < NUM_Q_VARIABLES;i++) {
- std::ostringstream os;
- os << "q" << i;
- load_builtin_param_float(os.str().c_str(), (void*)&presetOutputs.q[i], NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, "");
+ for (unsigned int i = 0; i < NUM_Q_VARIABLES; i++) {
+ std::ostringstream os;
+ os << "q" << i;
+ load_builtin_param_float (os.str().c_str(),
+ (void*)&presetOutputs.q[i],
+ NULL,
+ P_FLAG_PER_PIXEL | P_FLAG_QVAR,
+ 0,
+ MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE,
+ "");
}
/* variables added in 1.04 */
@@ -406,6 +441,4 @@
load_builtin_param_int("meshy", (void*)&presetInputs.gy, P_FLAG_READONLY, 24, 72, 6, "");
return PROJECTM_SUCCESS;
-
}
-
diff --git a/src/libprojectM/MilkdropPresetFactory/BuiltinParams.hpp b/src/libprojectM/MilkdropPresetFactory/BuiltinParams.hpp
index dbe60f1..3cf3f9d 100644
--- a/src/libprojectM/MilkdropPresetFactory/BuiltinParams.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/BuiltinParams.hpp
@@ -33,54 +33,56 @@
#include <map>
#include <cstdio>
+
class BuiltinParams {
public:
- typedef std::map<std::string, std::string> AliasMap;
+ typedef std::map<std::string, std::string> AliasMap;
- /** Default constructor leaves database in an uninitialized state. */
- BuiltinParams();
+ /** Default constructor leaves database in an uninitialized state. */
+ BuiltinParams();
- /** Construct a new builtin parameter database with variables references given by
- * the preset input and output structures */
- BuiltinParams(PresetInputs & presetInputs, PresetOutputs & presetOutputs);
+ /** Construct a new builtin parameter database with variables references given by
+ * the preset input and output structures */
+ BuiltinParams(PresetInputs & presetInputs, PresetOutputs & presetOutputs);
- ~BuiltinParams();
+ ~BuiltinParams();
- /** Param database initalizer / destructor functions */
- int init_builtin_param_db(const PresetInputs & presetInputs, PresetOutputs & presetOutputs);
- int load_all_builtin_param(const PresetInputs & presetInputs, PresetOutputs & presetOutputs);
- int destroy_builtin_param_db();
+ /** Param database initalizer / destructor functions */
+ int init_builtin_param_db(const PresetInputs & presetInputs, PresetOutputs & presetOutputs);
+ int load_all_builtin_param(const PresetInputs & presetInputs, PresetOutputs & presetOutputs);
+ int destroy_builtin_param_db();
- int insert_param_alt_name( Param *param, const std::string& salt_name );
- Param *find_builtin_param( const std::string & name );
- int load_builtin_param_float( const std::string & name, void *engine_val, void *matrix,
- short int flags,
- float init_val, float upper_bound,
- float lower_bound, const std::string & alt_name );
- int load_builtin_param_int( const std::string & name, void *engine_val, short int flags,
- int init_val, int upper_bound,
- int lower_bound, const std::string & alt_name );
- int load_builtin_param_bool( const std::string & name, void *engine_val, short int flags,
- int init_val, const std::string & alt_name );
+ int insert_param_alt_name( Param *param, const std::string& salt_name );
+ Param *find_builtin_param( const std::string & name );
+ int load_builtin_param_float( const std::string & name, void *engine_val, void *matrix,
+ short int flags,
+ float init_val, float upper_bound,
+ float lower_bound, const std::string & alt_name );
+ int load_builtin_param_int( const std::string & name, void *engine_val, short int flags,
+ int init_val, int upper_bound,
+ int lower_bound, const std::string & alt_name );
+ int load_builtin_param_bool( const std::string & name, void *engine_val, short int flags,
+ int init_val, const std::string & alt_name );
- int load_builtin_param_string( const std::string & name, std::string * engine_val, short int flags);
+ int load_builtin_param_string( const std::string & name, std::string * engine_val, short int flags);
- int insert_builtin_param( Param *param );
+ int insert_builtin_param( Param *param );
- template <class Fun>
- void apply(Fun & fun) {
- traverse(builtin_param_tree, fun);
- }
+ template <class Fun>
+ void apply(Fun & fun) {
+ traverse(builtin_param_tree, fun);
+ }
private:
- static const bool BUILTIN_PARAMS_DEBUG = false;
+ static const bool BUILTIN_PARAMS_DEBUG = false;
- // Used to associate multiple string names to one parameter
- AliasMap aliasMap;
+ // Used to associate multiple string names to one parameter
+ AliasMap aliasMap;
- // Internal datastructure to store the parameters
- std::map<std::string,Param*> builtin_param_tree;
+ // Internal datastructure to store the parameters
+ std::map<std::string,Param*> builtin_param_tree;
};
+
#endif
diff --git a/src/libprojectM/MilkdropPresetFactory/CValue.hpp b/src/libprojectM/MilkdropPresetFactory/CValue.hpp
index 7c2f557..aa8eb5b 100644
--- a/src/libprojectM/MilkdropPresetFactory/CValue.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/CValue.hpp
@@ -30,9 +30,9 @@
#define _CVALUE_H
typedef union CValue_t {
- bool bool_val;
- int int_val;
- float float_val;
- } CValue;
+ bool bool_val;
+ int int_val;
+ float float_val;
+} CValue;
#endif /** _CVALUE_H */
diff --git a/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp b/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp
index 4d2c283..5be0daa 100644
--- a/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp
@@ -39,217 +39,216 @@
CustomShape::CustomShape() : Shape()
{
- CustomShape(0);
+ CustomShape(0);
};
CustomShape::CustomShape ( int id ) : Shape()
{
+ Param * param;
- Param * param;
+ this->id = id;
+ this->per_frame_count = 0;
- this->id = id;
- this->per_frame_count = 0;
-
- /* Start: Load custom shape parameters */
- param = Param::new_param_float ( "r", P_FLAG_NONE, &this->r, NULL, 1.0, 0.0, 0.5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "g", P_FLAG_NONE, &this->g, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "b", P_FLAG_NONE, &this->b, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "a", P_FLAG_NONE, &this->a, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "border_r", P_FLAG_NONE, &this->border_r, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "border_g", P_FLAG_NONE, &this->border_g, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "border_b", P_FLAG_NONE, &this->border_b, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "border_a", P_FLAG_NONE, &this->border_a, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "r2", P_FLAG_NONE, &this->r2, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "g2", P_FLAG_NONE, &this->g2, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "b2", P_FLAG_NONE, &this->b2, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "a2", P_FLAG_NONE, &this->a2, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "x", P_FLAG_NONE, &this->x, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "y", P_FLAG_NONE, &this->y, NULL, 1.0, 0.0, .5 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_bool ( "thickoutline", P_FLAG_NONE, &this->thickOutline, 1, 0, 0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_bool ( "enabled", P_FLAG_NONE, &this->enabled, 1, 0, 0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_int ( "sides", P_FLAG_NONE, &this->sides, 100, 3, 3 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_bool ( "additive", P_FLAG_NONE, &this->additive, 1, 0, 0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_bool ( "textured", P_FLAG_NONE, &this->textured, 1, 0, 0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "rad", P_FLAG_NONE, &this->radius, NULL, MAX_DOUBLE_SIZE, 0, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "ang", P_FLAG_NONE, &this->ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "tex_zoom", P_FLAG_NONE, &this->tex_zoom, NULL, MAX_DOUBLE_SIZE, .00000000001, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "tex_ang", P_FLAG_NONE, &this->tex_ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
-
- param = Param::new_param_float ( "t1", P_FLAG_TVAR, &this->t1, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "t2", P_FLAG_TVAR, &this->t2, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "t3", P_FLAG_TVAR, &this->t3, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "t4", P_FLAG_TVAR, &this->t4, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "t5", P_FLAG_TVAR, &this->t5, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "t6", P_FLAG_TVAR, &this->t6, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "t7", P_FLAG_TVAR, &this->t7, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
- param = Param::new_param_float ( "t8", P_FLAG_TVAR, &this->t8, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
- if ( !ParamUtils::insert( param, &this->param_tree ) )
- {
- abort();
- }
-
- for (unsigned int i = 1; i <= NUM_Q_VARIABLES;i++) {
- std::ostringstream os;
- os << "q" << i;
- param = Param::new_param_float ( os.str().c_str(), P_FLAG_QVAR, &this->q[i], NULL, MAX_DOUBLE_SIZE,
- -MAX_DOUBLE_SIZE, 0.0 );
- if ( ParamUtils::insert ( param, &this->param_tree ) < 0 )
- {
- abort();
- }
+ /* Start: Load custom shape parameters */
+ param = Param::new_param_float ( "r", P_FLAG_NONE, &this->r, NULL, 1.0, 0.0, 0.5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "g", P_FLAG_NONE, &this->g, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "b", P_FLAG_NONE, &this->b, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "a", P_FLAG_NONE, &this->a, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "border_r", P_FLAG_NONE, &this->border_r, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "border_g", P_FLAG_NONE, &this->border_g, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "border_b", P_FLAG_NONE, &this->border_b, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "border_a", P_FLAG_NONE, &this->border_a, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "r2", P_FLAG_NONE, &this->r2, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "g2", P_FLAG_NONE, &this->g2, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "b2", P_FLAG_NONE, &this->b2, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "a2", P_FLAG_NONE, &this->a2, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "x", P_FLAG_NONE, &this->x, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "y", P_FLAG_NONE, &this->y, NULL, 1.0, 0.0, .5 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_bool ( "thickoutline", P_FLAG_NONE, &this->thickOutline, 1, 0, 0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_bool ( "enabled", P_FLAG_NONE, &this->enabled, 1, 0, 0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_int ( "sides", P_FLAG_NONE, &this->sides, 100, 3, 3 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_bool ( "additive", P_FLAG_NONE, &this->additive, 1, 0, 0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_bool ( "textured", P_FLAG_NONE, &this->textured, 1, 0, 0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "rad", P_FLAG_NONE, &this->radius, NULL, MAX_DOUBLE_SIZE, 0, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "ang", P_FLAG_NONE, &this->ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "tex_zoom", P_FLAG_NONE, &this->tex_zoom, NULL, MAX_DOUBLE_SIZE, .00000000001, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "tex_ang", P_FLAG_NONE, &this->tex_ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
}
- param = Param::new_param_string ( "imageurl", P_FLAG_NONE, &this->imageUrl);
- if ( !ParamUtils::insert( param, &this->text_properties_tree ) )
- {
- abort();
- }
+ param = Param::new_param_float ( "t1", P_FLAG_TVAR, &this->t1, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "t2", P_FLAG_TVAR, &this->t2, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "t3", P_FLAG_TVAR, &this->t3, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "t4", P_FLAG_TVAR, &this->t4, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "t5", P_FLAG_TVAR, &this->t5, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "t6", P_FLAG_TVAR, &this->t6, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "t7", P_FLAG_TVAR, &this->t7, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ param = Param::new_param_float ( "t8", P_FLAG_TVAR, &this->t8, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( !ParamUtils::insert( param, &this->param_tree ) )
+ {
+ abort();
+ }
+ for (unsigned int i = 1; i <= NUM_Q_VARIABLES; i++) {
+ std::ostringstream os;
+
+ os << "q" << i;
+ param = Param::new_param_float ( os.str().c_str(), P_FLAG_QVAR, &this->q[i], NULL,
+ MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( ParamUtils::insert ( param, &this->param_tree ) < 0 )
+ {
+ abort();
+ }
+ }
+
+ param = Param::new_param_string ( "imageurl", P_FLAG_NONE, &this->imageUrl);
+ if ( !ParamUtils::insert( param, &this->text_properties_tree ) )
+ {
+ abort();
+ }
}
/* Frees a custom shape form object */
CustomShape::~CustomShape()
{
-
- traverseVector<TraverseFunctors::Delete<PerFrameEqn> > ( per_frame_eqn_tree );
- traverse<TraverseFunctors::Delete<InitCond> > ( init_cond_tree );
- traverse<TraverseFunctors::Delete<Param> > ( param_tree );
- traverse<TraverseFunctors::Delete<InitCond> > ( per_frame_init_eqn_tree );
- traverse<TraverseFunctors::Delete<Param> > ( text_properties_tree );
-
+ traverseVector<TraverseFunctors::Delete<PerFrameEqn> > ( per_frame_eqn_tree );
+ traverse<TraverseFunctors::Delete<InitCond> > ( init_cond_tree );
+ traverse<TraverseFunctors::Delete<Param> > ( param_tree );
+ traverse<TraverseFunctors::Delete<InitCond> > ( per_frame_init_eqn_tree );
+ traverse<TraverseFunctors::Delete<Param> > ( text_properties_tree );
}
-void CustomShape::loadUnspecInitConds()
+void
+CustomShape::loadUnspecInitConds()
{
-
- InitCondUtils::LoadUnspecInitCond fun ( this->init_cond_tree, this->per_frame_init_eqn_tree );
- traverse ( param_tree, fun );
+ InitCondUtils::LoadUnspecInitCond fun ( this->init_cond_tree, this->per_frame_init_eqn_tree );
+ traverse ( param_tree, fun );
}
-void CustomShape::evalInitConds()
+void
+CustomShape::evalInitConds()
{
- // NOTE: This is verified to be same behavior as trunk
- for ( std::map<std::string, InitCond*>::iterator pos = per_frame_init_eqn_tree.begin();
- pos != per_frame_init_eqn_tree.end();++pos )
- pos->second->evaluate();
+ // NOTE: This is verified to be same behavior as trunk
+ for (std::map<std::string, InitCond*>::iterator pos = per_frame_init_eqn_tree.begin();
+ pos != per_frame_init_eqn_tree.end();
+ ++pos)
+ pos->second->evaluate();
}
diff --git a/src/libprojectM/MilkdropPresetFactory/CustomShape.hpp b/src/libprojectM/MilkdropPresetFactory/CustomShape.hpp
index eb9a8e8..6fbbe34 100644
--- a/src/libprojectM/MilkdropPresetFactory/CustomShape.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/CustomShape.hpp
@@ -25,7 +25,6 @@
*
* $Log$
*/
-
#ifndef _CUSTOM_SHAPE_H
#define _CUSTOM_SHAPE_H
@@ -37,54 +36,53 @@
#include "Renderer/Renderable.hpp"
#include <vector>
+
class Preset;
class CustomShape : public Shape {
public:
- /* Numerical id */
- int id;
- int per_frame_count;
+ /* Numerical id */
+ int id;
+ int per_frame_count;
- /* Parameter tree associated with this custom shape */
- std::map<std::string,Param*> param_tree;
+ /* Parameter tree associated with this custom shape */
+ std::map<std::string,Param*> param_tree;
- /* Engine variables */
+ /* Engine variables */
- bool enabled;
+ bool enabled;
- /* stupid t variables */
- float t1;
- float t2;
- float t3;
- float t4;
- float t5;
- float t6;
- float t7;
- float t8;
+ /* stupid t variables */
+ float t1;
+ float t2;
+ float t3;
+ float t4;
+ float t5;
+ float t6;
+ float t7;
+ float t8;
- /* stupider q variables */
- float q[NUM_Q_VARIABLES];
+ /* stupider q variables */
+ float q[NUM_Q_VARIABLES];
- // Data structure to hold per frame / per frame init equations
- std::map<std::string,InitCond*> init_cond_tree;
- std::vector<PerFrameEqn*> per_frame_eqn_tree;
- std::map<std::string,InitCond*> per_frame_init_eqn_tree;
+ // Data structure to hold per frame / per frame init equations
+ std::map<std::string,InitCond*> init_cond_tree;
+ std::vector<PerFrameEqn*> per_frame_eqn_tree;
+ std::map<std::string,InitCond*> per_frame_init_eqn_tree;
- std::map<std::string, Param*> text_properties_tree;
+ std::map<std::string, Param*> text_properties_tree;
- /// Allocate a new custom shape, including param associations, per point equations, and initial values.
- /// \param id an integer id to associate with this custom wave. Future line parsing uses this as a reference key.
- CustomShape( int id );
- CustomShape();
- ~CustomShape();
+ /// Allocate a new custom shape, including param associations, per point equations, and initial values.
+ /// \param id an integer id to associate with this custom wave. Future line parsing uses this as a reference key.
+ CustomShape( int id );
+ CustomShape();
+ ~CustomShape();
- void loadUnspecInitConds();
- void evalInitConds();
-
- };
+ void loadUnspecInitConds();
+ void evalInitConds();
+};
#endif /** !_CUSTOM_SHAPE_H */
-
diff --git a/src/libprojectM/MilkdropPresetFactory/CustomWave.cpp b/src/libprojectM/MilkdropPresetFactory/CustomWave.cpp
index 935cea7..305d663 100644
--- a/src/libprojectM/MilkdropPresetFactory/CustomWave.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/CustomWave.cpp
@@ -40,10 +40,12 @@
#include "ParamUtils.hpp"
#include "InitCondUtils.hpp"
#include "wipemalloc.h"
+
#define MAX_SAMPLE_SIZE 4096
-CustomWave::CustomWave(int _id) : Waveform(512),
+CustomWave::CustomWave(int _id)
+ : Waveform(512),
id(_id),
per_frame_count(0),
r(0),
@@ -51,7 +53,6 @@
b(0),
a(0)
{
-
Param * param;
/// @bug deprecate the use of wipemalloc
@@ -147,10 +148,8 @@
if (ParamUtils::insert(param, &this->param_tree) < 0)
{
;
-
/// @bug make exception
abort();
-
}
if ((param = Param::new_param_bool("enabled", P_FLAG_NONE, &this->enabled, 1, 0, 0)) == NULL)
@@ -158,17 +157,13 @@
;
/// @bug make exception
abort();
-
-
}
if (ParamUtils::insert(param, &this->param_tree) < 0)
{
;
-
/// @bug make exception
abort();
-
}
if ((param = Param::new_param_int("sep", P_FLAG_NONE, &this->sep, 100, -100, 0)) == NULL)
@@ -176,8 +171,6 @@
;
/// @bug make exception
abort();
-
-
}
if (ParamUtils::insert(param, &this->param_tree) < 0)
@@ -185,23 +178,18 @@
;
/// @bug make exception
abort();
-
-
}
if ((param = Param::new_param_bool("bspectrum", P_FLAG_NONE, &this->spectrum, 1, 0, 0)) == NULL)
{
/// @bug make exception
abort();
-
-
}
if (ParamUtils::insert(param, &this->param_tree) < 0)
{
/// @bug make exception
abort();
-
}
if ((param = Param::new_param_bool("bdrawthick", P_FLAG_NONE, &this->thick, 1, 0, 0)) == NULL)
@@ -214,12 +202,10 @@
{
/// @bug make exception
abort();
-
}
if ((param = Param::new_param_bool("busedots", P_FLAG_NONE, &this->dots, 1, 0, 0)) == NULL)
{
-
/// @bug make exception
abort();
}
@@ -255,7 +241,7 @@
}
if ((param = Param::new_param_float("sample", P_FLAG_READONLY | P_FLAG_NONE | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT,
- &this->sample, this->sample_mesh, 1.0, 0.0, 0.0)) == NULL)
+ &this->sample, this->sample_mesh, 1.0, 0.0, 0.0)) == NULL)
{
;
abort();
@@ -341,12 +327,11 @@
if (ParamUtils::insert(param, &this->param_tree) < 0)
{
-
abort();
}
+
if ((param = Param::new_param_float("t4", P_FLAG_PER_POINT |P_FLAG_TVAR, &this->t4, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL)
{
-
abort();
}
@@ -354,6 +339,7 @@
{
abort();
}
+
if ((param = Param::new_param_float("t5", P_FLAG_TVAR, &this->t5, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL)
{
abort();
@@ -363,7 +349,7 @@
{
abort();
}
-
+
if ((param = Param::new_param_float("t6", P_FLAG_TVAR | P_FLAG_PER_POINT, &this->t6, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL)
{
abort();
@@ -371,12 +357,11 @@
if (ParamUtils::insert(param, &this->param_tree) < 0)
{
-
abort();
}
+
if ((param = Param::new_param_float("t7", P_FLAG_TVAR | P_FLAG_PER_POINT, &this->t7, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL)
{
-
abort();
}
@@ -398,27 +383,25 @@
abort();
}
- for (unsigned int i = 1; i <= NUM_Q_VARIABLES;i++) {
- std::ostringstream os;
- os << "q" << i;
- param = Param::new_param_float ( os.str().c_str(), P_FLAG_QVAR, &this->q[i], NULL, MAX_DOUBLE_SIZE,
- -MAX_DOUBLE_SIZE, 0.0 );
- if ( ParamUtils::insert ( param, &this->param_tree ) < 0 )
- {
- abort();
- }
+ for (unsigned int i = 1; i <= NUM_Q_VARIABLES; i++) {
+ std::ostringstream os;
+
+ os << "q" << i;
+ param = Param::new_param_float ( os.str().c_str(), P_FLAG_QVAR, &this->q[i], NULL,
+ MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 );
+ if ( ParamUtils::insert ( param, &this->param_tree ) < 0 )
+ {
+ abort();
+ }
}
-
- /* End of parameter loading. Note that the read only parameters associated
+
+ /* End of parameter loading. Note that the read only parameters associated
with custom waves (ie, sample) are variables stored in PresetFrameIO.hpp,
and not specific to the custom wave datastructure. */
-
}
CustomWave::~CustomWave()
{
-
-
for (std::vector<PerPointEqn*>::iterator pos = per_point_eqn_tree.begin(); pos != per_point_eqn_tree.end(); ++pos)
delete(*pos);
@@ -434,23 +417,23 @@
for (std::map<std::string, Param*>::iterator pos = param_tree.begin(); pos != param_tree.end(); ++pos)
delete(pos->second);
- free(r_mesh);
- free(g_mesh);
- free(b_mesh);
- free(a_mesh);
- free(x_mesh);
- free(y_mesh);
- free(value1);
- free(value2);
- free(sample_mesh);
-
+ free (r_mesh);
+ free (g_mesh);
+ free (b_mesh);
+ free (a_mesh);
+ free (x_mesh);
+ free (y_mesh);
+ free (value1);
+ free (value2);
+ free (sample_mesh);
}
// Comments: index is not passed, so we assume monotonic increment by 1 is ok here
-int CustomWave::add_per_point_eqn(char * name, GenExpr * gen_expr)
+int
+CustomWave::add_per_point_eqn(char * name, GenExpr * gen_expr)
{
PerPointEqn * per_point_eqn;
@@ -469,9 +452,9 @@
if ((param = ParamUtils::find<ParamUtils::AUTO_CREATE>(name,¶m_tree)) == NULL)
{
- if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: failed to allocate a new parameter!\n");
+ if (CUSTOM_WAVE_DEBUG)
+ printf("add_per_point_eqn: failed to allocate a new parameter!\n");
return PROJECTM_FAILURE;
-
}
/* Get largest index in the tree */
@@ -480,6 +463,7 @@
/* Create the per point equation given the index, parameter, and general expression */
if ((per_point_eqn = new PerPointEqn(index, param, gen_expr, samples)) == NULL)
return PROJECTM_FAILURE;
+
if (CUSTOM_WAVE_DEBUG)
printf("add_per_point_eqn: created new equation (index = %d) (name = \"%s\")\n", per_point_eqn->index, per_point_eqn->param->name.c_str());
@@ -492,48 +476,51 @@
}
-void CustomWave::evalInitConds()
+void
+CustomWave::evalInitConds()
{
-
- for (std::map<std::string, InitCond*>::iterator pos = per_frame_init_eqn_tree.begin(); pos != per_frame_init_eqn_tree.end(); ++pos)
+ for (std::map<std::string, InitCond*>::iterator pos = per_frame_init_eqn_tree.begin();
+ pos != per_frame_init_eqn_tree.end();
+ ++pos)
{
assert(pos->second);
pos->second->evaluate();
}
-
}
-ColoredPoint CustomWave::PerPoint(ColoredPoint p, const WaveformContext context)
+ColoredPoint
+CustomWave::PerPoint (ColoredPoint p, const WaveformContext context)
{
- r_mesh[context.sample_int] = r;
- g_mesh[context.sample_int] = g;
- b_mesh[context.sample_int] = b;
- a_mesh[context.sample_int] = a;
- x_mesh[context.sample_int] = x;
- y_mesh[context.sample_int] = y;
- sample = context.sample;
- sample_mesh[context.sample_int] = context.sample;
- v1 = context.left;
- v2 = context.right;
+ r_mesh[context.sample_int] = r;
+ g_mesh[context.sample_int] = g;
+ b_mesh[context.sample_int] = b;
+ a_mesh[context.sample_int] = a;
+ x_mesh[context.sample_int] = x;
+ y_mesh[context.sample_int] = y;
+ sample = context.sample;
+ sample_mesh[context.sample_int] = context.sample;
+ v1 = context.left;
+ v2 = context.right;
- for (std::vector<PerPointEqn*>::iterator pos = per_point_eqn_tree.begin(); pos != per_point_eqn_tree.end();++pos)
- (*pos)->evaluate(context.sample_int);
+ for (std::vector<PerPointEqn*>::iterator pos = per_point_eqn_tree.begin();
+ pos != per_point_eqn_tree.end();
+ ++pos)
+ (*pos)->evaluate(context.sample_int);
- p.a = a_mesh[context.sample_int];
- p.r = r_mesh[context.sample_int];
- p.g = g_mesh[context.sample_int];
- p.b = b_mesh[context.sample_int];
- p.x = x_mesh[context.sample_int];
- p.y = y_mesh[context.sample_int];
+ p.a = a_mesh[context.sample_int];
+ p.r = r_mesh[context.sample_int];
+ p.g = g_mesh[context.sample_int];
+ p.b = b_mesh[context.sample_int];
+ p.x = x_mesh[context.sample_int];
+ p.y = y_mesh[context.sample_int];
- return p;
+ return p;
}
-void CustomWave::loadUnspecInitConds()
+void
+CustomWave::loadUnspecInitConds()
{
-
InitCondUtils::LoadUnspecInitCond fun(this->init_cond_tree, this->per_frame_init_eqn_tree);
traverse(param_tree, fun);
}
-
diff --git a/src/libprojectM/MilkdropPresetFactory/CustomWave.hpp b/src/libprojectM/MilkdropPresetFactory/CustomWave.hpp
index a951fed..a29a4e3 100644
--- a/src/libprojectM/MilkdropPresetFactory/CustomWave.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/CustomWave.hpp
@@ -29,6 +29,7 @@
#ifndef _CUSTOM_WAVE_H
#define _CUSTOM_WAVE_H
+
#define CUSTOM_WAVE_DEBUG 0
class CustomWave;
@@ -45,84 +46,84 @@
#include <map>
+
class CustomWave : public Waveform
{
-public:
+ public:
- /** Empty constructor leaves wave in undefined state **/
- //CustomWave() {}
+ /** Empty constructor leaves wave in undefined state **/
+ //CustomWave() {}
- /** Initializes a custom wave id given the integer id */
- CustomWave(int id);
+ /** Initializes a custom wave id given the integer id */
+ CustomWave(int id);
- /** Destructor is necessary so we can free the per point matrices **/
- ~CustomWave();
+ /** Destructor is necessary so we can free the per point matrices **/
+ ~CustomWave();
- ColoredPoint PerPoint(ColoredPoint p, const WaveformContext context);
+ ColoredPoint PerPoint(ColoredPoint p, const WaveformContext context);
- /* Numerical id */
- int id;
- int per_frame_count;
+ /* Numerical id */
+ int id;
+ int per_frame_count;
- /* Parameter tree associated with this custom wave */
- std::map<std::string,Param*> param_tree;
+ /* Parameter tree associated with this custom wave */
+ std::map<std::string,Param*> param_tree;
- /* Engine variables */
- float x; /* x position for per point equations */
- float y; /* y position for per point equations */
- float r; /* red color value */
- float g; /* green color value */
- float b; /* blue color value */
- float a; /* alpha color value */
- float * x_mesh;
- float * y_mesh;
- float * r_mesh;
- float * b_mesh;
- float * g_mesh;
- float * a_mesh;
- float * value1;
- float * value2;
- float * sample_mesh;
+ /* Engine variables */
+ float x; /* x position for per point equations */
+ float y; /* y position for per point equations */
+ float r; /* red color value */
+ float g; /* green color value */
+ float b; /* blue color value */
+ float a; /* alpha color value */
+ float * x_mesh;
+ float * y_mesh;
+ float * r_mesh;
+ float * b_mesh;
+ float * g_mesh;
+ float * a_mesh;
+ float * value1;
+ float * value2;
+ float * sample_mesh;
- bool enabled; /* if true then wave is visible, hidden otherwise */
+ bool enabled; /* if true then wave is visible, hidden otherwise */
- float sample;
+ float sample;
- /* stupid t variables */
- float t1;
- float t2;
- float t3;
- float t4;
- float t5;
- float t6;
- float t7;
- float t8;
+ /* stupid t variables */
+ float t1;
+ float t2;
+ float t3;
+ float t4;
+ float t5;
+ float t6;
+ float t7;
+ float t8;
- /* stupider q variables */
- float q[NUM_Q_VARIABLES];
+ /* stupider q variables */
+ float q[NUM_Q_VARIABLES];
- float v1,v2;
+ float v1,v2;
- /* Data structures to hold per frame and per point equations */
- std::map<std::string,InitCond*> init_cond_tree;
- std::vector<PerFrameEqn*> per_frame_eqn_tree;
- std::vector<PerPointEqn*> per_point_eqn_tree;
- std::map<std::string,InitCond*> per_frame_init_eqn_tree;
+ /* Data structures to hold per frame and per point equations */
+ std::map<std::string,InitCond*> init_cond_tree;
+ std::vector<PerFrameEqn*> per_frame_eqn_tree;
+ std::vector<PerPointEqn*> per_point_eqn_tree;
+ std::map<std::string,InitCond*> per_frame_init_eqn_tree;
- /* Denotes the index of the last character for each string buffer */
- int per_point_eqn_string_index;
- int per_frame_eqn_string_index;
- int per_frame_init_eqn_string_index;
+ /* Denotes the index of the last character for each string buffer */
+ int per_point_eqn_string_index;
+ int per_frame_eqn_string_index;
+ int per_frame_init_eqn_string_index;
- int add_per_point_eqn(char * name, GenExpr * gen_expr);
- void evalCustomWaveInitConditions(Preset *preset);
-
+ int add_per_point_eqn(char * name, GenExpr * gen_expr);
+ void evalCustomWaveInitConditions(Preset *preset);
- void loadUnspecInitConds();
- void evalInitConds();
+ void loadUnspecInitConds();
+ void evalInitConds();
};
#endif /** !_CUSTOM_WAVE_H */
diff --git a/src/libprojectM/MilkdropPresetFactory/Eval.cpp b/src/libprojectM/MilkdropPresetFactory/Eval.cpp
index 1810f74..3183754 100644
--- a/src/libprojectM/MilkdropPresetFactory/Eval.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/Eval.cpp
@@ -34,58 +34,61 @@
#include "BuiltinFuncs.hpp"
-InfixOp *Eval::infix_add = NULL;
-InfixOp *Eval::infix_minus = NULL;
-InfixOp *Eval::infix_div = NULL;
-InfixOp *Eval::infix_mult = NULL;
-InfixOp *Eval::infix_or = NULL;
-InfixOp *Eval::infix_and = NULL;
-InfixOp *Eval::infix_mod = NULL;
+
+InfixOp *Eval::infix_add = NULL;
+InfixOp *Eval::infix_minus = NULL;
+InfixOp *Eval::infix_div = NULL;
+InfixOp *Eval::infix_mult = NULL;
+InfixOp *Eval::infix_or = NULL;
+InfixOp *Eval::infix_and = NULL;
+InfixOp *Eval::infix_mod = NULL;
InfixOp *Eval::infix_negative = NULL;
InfixOp *Eval::infix_positive = NULL;
+
/* Initializes all infix operators */
-int Eval::init_infix_ops() {
+int
+Eval::init_infix_ops()
+{
+ Eval::infix_add = new InfixOp (INFIX_ADD, 4);
+ Eval::infix_minus = new InfixOp (INFIX_MINUS, 3);
+ Eval::infix_div = new InfixOp (INFIX_DIV, 2);
+ Eval::infix_or = new InfixOp (INFIX_OR, 5);
+ Eval::infix_and = new InfixOp (INFIX_AND,4);
+ Eval::infix_mod = new InfixOp (INFIX_MOD, 1);
+ Eval::infix_mult = new InfixOp (INFIX_MULT, 2);
- Eval::infix_add = new InfixOp(INFIX_ADD, 4);
- Eval::infix_minus = new InfixOp(INFIX_MINUS, 3);
- Eval::infix_div = new InfixOp(INFIX_DIV, 2);
- Eval::infix_or = new InfixOp(INFIX_OR, 5);
- Eval::infix_and = new InfixOp(INFIX_AND,4);
- Eval::infix_mod = new InfixOp(INFIX_MOD, 1);
- Eval::infix_mult = new InfixOp(INFIX_MULT, 2);
-
- /* Prefix operators */
- Eval::infix_positive = new InfixOp(INFIX_ADD, 0);
- Eval::infix_negative = new InfixOp(INFIX_MINUS, 0);
+ /* Prefix operators */
+ Eval::infix_positive = new InfixOp (INFIX_ADD, 0);
+ Eval::infix_negative = new InfixOp (INFIX_MINUS, 0);
- return PROJECTM_SUCCESS;
+ return PROJECTM_SUCCESS;
}
/* Destroys the infix operator list. This should
be done on program exit */
-int Eval::destroy_infix_ops()
+int
+Eval::destroy_infix_ops()
{
+ delete (Eval::infix_add);
+ delete (Eval::infix_minus);
+ delete (Eval::infix_div);
+ delete (Eval::infix_or);
+ delete (Eval::infix_and);
+ delete (Eval::infix_mod);
+ delete (Eval::infix_mult);
+ delete (Eval::infix_positive);
+ delete (Eval::infix_negative);
- delete(Eval::infix_add);
- delete(Eval::infix_minus);
- delete(Eval::infix_div);
- delete(Eval::infix_or);
- delete(Eval::infix_and);
- delete(Eval::infix_mod);
- delete(Eval::infix_mult);
- delete(Eval::infix_positive);
- delete(Eval::infix_negative);
-
- Eval::infix_add = NULL;
- Eval::infix_minus = NULL;
- Eval::infix_div = NULL;
- Eval::infix_or = NULL;
- Eval::infix_and = NULL;
- Eval::infix_mod = NULL;
- Eval::infix_mult = NULL;
- Eval::infix_positive = NULL;
- Eval::infix_negative = NULL;
+ Eval::infix_add = NULL;
+ Eval::infix_minus = NULL;
+ Eval::infix_div = NULL;
+ Eval::infix_or = NULL;
+ Eval::infix_and = NULL;
+ Eval::infix_mod = NULL;
+ Eval::infix_mult = NULL;
+ Eval::infix_positive = NULL;
+ Eval::infix_negative = NULL;
return PROJECTM_SUCCESS;
}
diff --git a/src/libprojectM/MilkdropPresetFactory/Eval.hpp b/src/libprojectM/MilkdropPresetFactory/Eval.hpp
index 51bd22f..6be653c 100644
--- a/src/libprojectM/MilkdropPresetFactory/Eval.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/Eval.hpp
@@ -36,59 +36,62 @@
#include "Func.hpp"
#include "Param.hpp"
-#define EVAL_DEBUG 0
+
+#define EVAL_DEBUG 0
//#define EVAL_DEBUG_DOUBLE 2
-#define VAL_T 1
-#define PREFUN_T 3
-#define TREE_T 4
-#define NONE_T 0
+#define VAL_T 1
+#define PREFUN_T 3
+#define TREE_T 4
+#define NONE_T 0
#define CONSTANT_TERM_T 0
-#define PARAM_TERM_T 1
+#define PARAM_TERM_T 1
-#define INFIX_ADD 0
-#define INFIX_MINUS 1
-#define INFIX_MOD 2
-#define INFIX_DIV 3
-#define INFIX_MULT 4
-#define INFIX_OR 5
-#define INFIX_AND 6
+#define INFIX_ADD 0
+#define INFIX_MINUS 1
+#define INFIX_MOD 2
+#define INFIX_DIV 3
+#define INFIX_MULT 4
+#define INFIX_OR 5
+#define INFIX_AND 6
+
class DLLEXPORT InfixOp;
+
class Eval {
public:
- static InfixOp *infix_add,
- *infix_minus,
- *infix_div,
- *infix_mult,
- *infix_or,
- *infix_and,
- *infix_mod,
- *infix_negative,
- *infix_positive;
+ static InfixOp *infix_add,
+ *infix_minus,
+ *infix_div,
+ *infix_mult,
+ *infix_or,
+ *infix_and,
+ *infix_mod,
+ *infix_negative,
+ *infix_positive;
- float eval_gen_expr(GenExpr * gen_expr);
- inline GenExpr * opt_gen_expr(GenExpr * gen_expr, int ** param_list);
+ float eval_gen_expr(GenExpr * gen_expr);
+ inline GenExpr * opt_gen_expr(GenExpr * gen_expr, int ** param_list);
- GenExpr * const_to_expr(float val);
- GenExpr * param_to_expr(Param * param);
- GenExpr * prefun_to_expr(float (*func_ptr)(), GenExpr ** expr_list, int num_args);
+ GenExpr * const_to_expr(float val);
+ GenExpr * param_to_expr(Param * param);
+ GenExpr * prefun_to_expr(float (*func_ptr)(), GenExpr ** expr_list, int num_args);
- static TreeExpr * new_tree_expr(InfixOp * infix_op, GenExpr * gen_expr, TreeExpr * left, TreeExpr * right);
- static GenExpr * new_gen_expr(int type, void * item);
- static ValExpr * new_val_expr(int type, Term *term);
+ static TreeExpr * new_tree_expr(InfixOp * infix_op, GenExpr * gen_expr, TreeExpr * left, TreeExpr * right);
+ static GenExpr * new_gen_expr(int type, void * item);
+ static ValExpr * new_val_expr(int type, Term *term);
- static InfixOp * new_infix_op(int type, int precedence);
- static int init_infix_ops();
- static int destroy_infix_ops();
- void reset_engine_vars();
-
- GenExpr * clone_gen_expr(GenExpr * gen_expr);
- TreeExpr * clone_tree_expr(TreeExpr * tree_expr);
- ValExpr * clone_val_expr(ValExpr * val_expr);
- PrefunExpr * clone_prefun_expr(PrefunExpr * prefun_expr);
- };
+ static InfixOp * new_infix_op(int type, int precedence);
+ static int init_infix_ops();
+ static int destroy_infix_ops();
+ void reset_engine_vars();
+
+ GenExpr * clone_gen_expr(GenExpr * gen_expr);
+ TreeExpr * clone_tree_expr(TreeExpr * tree_expr);
+ ValExpr * clone_val_expr(ValExpr * val_expr);
+ PrefunExpr * clone_prefun_expr(PrefunExpr * prefun_expr);
+};
#endif /** !_EVAL_H */
diff --git a/src/libprojectM/MilkdropPresetFactory/Expr.cpp b/src/libprojectM/MilkdropPresetFactory/Expr.cpp
index 58142ad..877fc12 100644
--- a/src/libprojectM/MilkdropPresetFactory/Expr.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/Expr.cpp
@@ -27,308 +27,310 @@
#include <iostream>
#include "Eval.hpp"
-float GenExpr::eval_gen_expr ( int mesh_i, int mesh_j )
+
+float
+GenExpr::eval_gen_expr ( int mesh_i, int mesh_j )
{
- float l;
+ float l;
- assert ( item );
- switch ( this->type )
- {
- case VAL_T:
- return ( ( ValExpr* ) item )->eval_val_expr ( mesh_i, mesh_j );
- case PREFUN_T:
- l = ( ( PrefunExpr * ) item )->eval_prefun_expr ( mesh_i, mesh_j );
- //if (EVAL_DEBUG) DWRITE( "eval_gen_expr: prefix function return value: %f\n", l);
- return l;
- case TREE_T:
- return ( ( TreeExpr* ) ( item ) )->eval_tree_expr ( mesh_i, mesh_j );
- default:
- return EVAL_ERROR;
- }
-
+ assert ( item );
+ switch ( this->type )
+ {
+ case VAL_T:
+ return ( ( ValExpr* ) item )->eval_val_expr ( mesh_i, mesh_j );
+ case PREFUN_T:
+ l = ( ( PrefunExpr * ) item )->eval_prefun_expr ( mesh_i, mesh_j );
+ //if (EVAL_DEBUG) DWRITE( "eval_gen_expr: prefix function return value: %f\n", l);
+ return l;
+ case TREE_T:
+ return ( ( TreeExpr* ) ( item ) )->eval_tree_expr ( mesh_i, mesh_j );
+ default:
+ return EVAL_ERROR;
+ }
}
/* Evaluates functions in prefix form */
-float PrefunExpr::eval_prefun_expr ( int mesh_i, int mesh_j )
+float
+PrefunExpr::eval_prefun_expr ( int mesh_i, int mesh_j )
{
+ assert ( func_ptr );
+ float * arg_list = new float[this->num_args];
- assert ( func_ptr );
+ assert(arg_list);
- float * arg_list = new float[this->num_args];
+ //printf("numargs %d", num_args);
- assert(arg_list);
+ /* Evaluate each argument before calling the function itself */
+ for ( int i = 0; i < num_args; i++ )
+ {
+ arg_list[i] = expr_list[i]->eval_gen_expr ( mesh_i, mesh_j );
+ //printf("numargs %x", arg_list[i]);
+ }
+ /* Now we call the function, passing a list of
+ floats as its argument */
- //printf("numargs %d", num_args);
+ const float value = ( func_ptr ) ( arg_list );
- /* Evaluate each argument before calling the function itself */
- for ( int i = 0; i < num_args; i++ )
- {
- arg_list[i] = expr_list[i]->eval_gen_expr ( mesh_i, mesh_j );
- //printf("numargs %x", arg_list[i]);
-
-
- }
- /* Now we call the function, passing a list of
- floats as its argument */
-
- const float value = ( func_ptr ) ( arg_list );
-
- delete[](arg_list);
- return value;
+ delete[](arg_list);
+ return value;
}
/* Evaluates a value expression */
-float ValExpr::eval_val_expr ( int mesh_i, int mesh_j )
+float
+ValExpr::eval_val_expr ( int mesh_i, int mesh_j )
{
+ /* Value is a constant, return the float value */
+ if ( type == CONSTANT_TERM_T )
+ {
+ return ( term.constant );
+ }
+ /* Value is variable, dereference it */
+ if ( type == PARAM_TERM_T )
+ {
+ switch ( term.param->type )
+ {
+ case P_TYPE_BOOL:
+ return ( float ) ( * ( ( bool* ) ( term.param->engine_val ) ) );
- /* Value is a constant, return the float value */
- if ( type == CONSTANT_TERM_T )
- {
- return ( term.constant );
- }
+ case P_TYPE_INT:
+ return ( float ) ( * ( ( int* ) ( term.param->engine_val ) ) );
- /* Value is variable, dereference it */
- if ( type == PARAM_TERM_T )
- {
- switch ( term.param->type )
- {
+ case P_TYPE_DOUBLE:
+ if ( term.param->matrix_flag | ( term.param->flags & P_FLAG_ALWAYS_MATRIX ) )
+ {
+ /* Sanity check the matrix is there... */
+ assert ( term.param->matrix != NULL );
- case P_TYPE_BOOL:
+ /// @slow boolean check could be expensive in this critical (and common) step of evaluation
+ if ( mesh_i >= 0 )
+ {
+ if ( mesh_j >= 0 )
+ {
+ return ( ( ( float** ) term.param->matrix ) [mesh_i][mesh_j] );
+ }
+ else
+ {
+ return ( ( ( float* ) term.param->matrix ) [mesh_i] );
+ }
+ }
+ //assert(mesh_i >=0);
+ }
+ //std::cout << term.param->name << ": " << (*((float*)term.param->engine_val)) << std::endl;
+ return * ( ( float* ) ( term.param->engine_val ) );
-
- return ( float ) ( * ( ( bool* ) ( term.param->engine_val ) ) );
- case P_TYPE_INT:
-
-
- return ( float ) ( * ( ( int* ) ( term.param->engine_val ) ) );
- case P_TYPE_DOUBLE:
-
-
- if ( term.param->matrix_flag | ( term.param->flags & P_FLAG_ALWAYS_MATRIX ) )
- {
-
- /* Sanity check the matrix is there... */
- assert ( term.param->matrix != NULL );
-
- /// @slow boolean check could be expensive in this critical (and common) step of evaluation
- if ( mesh_i >= 0 )
- {
- if ( mesh_j >= 0 )
- {
- return ( ( ( float** ) term.param->matrix ) [mesh_i][mesh_j] );
- }
- else
- {
- return ( ( ( float* ) term.param->matrix ) [mesh_i] );
- }
- }
- //assert(mesh_i >=0);
- }
- //std::cout << term.param->name << ": " << (*((float*)term.param->engine_val)) << std::endl;
- return * ( ( float* ) ( term.param->engine_val ) );
- default:
- return EVAL_ERROR;
- }
- }
- /* Unknown type, return failure */
- return PROJECTM_FAILURE;
+ default:
+ return EVAL_ERROR;
+ }
+ }
+ /* Unknown type, return failure */
+ return PROJECTM_FAILURE;
}
/* Evaluates an expression tree */
-float TreeExpr::eval_tree_expr ( int mesh_i, int mesh_j )
+float
+TreeExpr::eval_tree_expr ( int mesh_i, int mesh_j )
{
- float left_arg, right_arg;
+ float left_arg, right_arg;
- /* A leaf node, evaluate the general expression. If the expression is null as well, return zero */
- if ( infix_op == NULL )
- {
- if ( gen_expr == NULL )
- return 0;
- else
- return gen_expr->eval_gen_expr ( mesh_i, mesh_j );
- }
+ /* A leaf node, evaluate the general expression. If the expression is null as well, return zero */
+ if ( infix_op == NULL )
+ {
+ if ( gen_expr == NULL )
+ return 0;
+ else
+ return gen_expr->eval_gen_expr ( mesh_i, mesh_j );
+ }
- /* Otherwise, this node is an infix operator. Evaluate
- accordingly */
+ /* Otherwise, this node is an infix operator. Evaluate
+ accordingly */
- assert(left);
- left_arg = left->eval_tree_expr ( mesh_i, mesh_j );
+ assert(left);
+ left_arg = left->eval_tree_expr ( mesh_i, mesh_j );
- assert(right);
- right_arg = right->eval_tree_expr ( mesh_i, mesh_j );
+ assert(right);
+ right_arg = right->eval_tree_expr ( mesh_i, mesh_j );
- switch ( infix_op->type )
- {
- case INFIX_ADD:
- return ( left_arg + right_arg );
- case INFIX_MINUS:
- return ( left_arg - right_arg );
- case INFIX_MULT:
- return ( left_arg * right_arg );
- case INFIX_MOD:
- if ( ( int ) right_arg == 0 )
- {
- return PROJECTM_DIV_BY_ZERO;
- }
- return ( ( int ) left_arg % ( int ) right_arg );
- case INFIX_OR:
- return ( ( int ) left_arg | ( int ) right_arg );
- case INFIX_AND:
- return ( ( int ) left_arg & ( int ) right_arg );
- case INFIX_DIV:
- if ( right_arg == 0 )
- {
- return MAX_DOUBLE_SIZE;
- }
- return ( left_arg / right_arg );
- default:
- return EVAL_ERROR;
- }
+ switch ( infix_op->type )
+ {
+ case INFIX_ADD:
+ return ( left_arg + right_arg );
+ case INFIX_MINUS:
+ return ( left_arg - right_arg );
+ case INFIX_MULT:
+ return ( left_arg * right_arg );
+ case INFIX_MOD:
+ if ( ( int ) right_arg == 0 )
+ {
+ return PROJECTM_DIV_BY_ZERO;
+ }
+ return ( ( int ) left_arg % ( int ) right_arg );
+ case INFIX_OR:
+ return ( ( int ) left_arg | ( int ) right_arg );
+ case INFIX_AND:
+ return ( ( int ) left_arg & ( int ) right_arg );
+ case INFIX_DIV:
+ if ( right_arg == 0 )
+ {
+ return MAX_DOUBLE_SIZE;
+ }
+ return ( left_arg / right_arg );
+ default:
+ return EVAL_ERROR;
+ }
- return EVAL_ERROR;
+ return EVAL_ERROR;
}
/* Converts a float value to a general expression */
-GenExpr * GenExpr::const_to_expr ( float val )
+GenExpr *
+GenExpr::const_to_expr ( float val )
{
- GenExpr * gen_expr;
- ValExpr * val_expr;
- Term term;
+ GenExpr * gen_expr;
+ ValExpr * val_expr;
+ Term term;
- term.constant = val;
+ term.constant = val;
- if ( ( val_expr = new ValExpr ( CONSTANT_TERM_T, &term ) ) == NULL )
- return NULL;
+ if ( ( val_expr = new ValExpr ( CONSTANT_TERM_T, &term ) ) == NULL )
+ return NULL;
- gen_expr = new GenExpr ( VAL_T, ( void* ) val_expr );
+ gen_expr = new GenExpr ( VAL_T, ( void* ) val_expr );
- if ( gen_expr == NULL )
- {
- delete val_expr;
- }
+ if ( gen_expr == NULL )
+ {
+ delete val_expr;
+ }
- return gen_expr;
+ return gen_expr;
}
/* Converts a regular parameter to an expression */
-GenExpr * GenExpr::param_to_expr ( Param * param )
+GenExpr *
+GenExpr::param_to_expr ( Param * param )
{
- GenExpr * gen_expr = NULL;
- ValExpr * val_expr = NULL;
- Term term;
+ GenExpr * gen_expr = NULL;
+ ValExpr * val_expr = NULL;
+ Term term;
- if ( param == NULL )
- return NULL;
+ if ( param == NULL )
+ return NULL;
- /* This code is still a work in progress. We need
- to figure out if the initial condition is used for
- each per frame equation or not. I am guessing that
- it isn't, and it is thusly implemented this way */
+ /* This code is still a work in progress. We need
+ to figure out if the initial condition is used for
+ each per frame equation or not. I am guessing that
+ it isn't, and it is thusly implemented this way */
- /* Current guess of true behavior (08/01/03) note from carm
- First try to use the per_pixel_expr (with cloning)
- If it is null however, use the engine variable instead. */
+ /* Current guess of true behavior (08/01/03) note from carm
+ First try to use the per_pixel_expr (with cloning)
+ If it is null however, use the engine variable instead. */
- /* 08/20/03 : Presets are now objects, as well as per pixel equations. This ends up
- making the parser handle the case where parameters are essentially per pixel equation
- substitutions */
+ /* 08/20/03 : Presets are now objects, as well as per pixel equations. This ends up
+ making the parser handle the case where parameters are essentially per pixel equation
+ substitutions */
- term.param = param;
- if ( ( val_expr = new ValExpr ( PARAM_TERM_T, &term ) ) == NULL )
- return NULL;
+ term.param = param;
+ if ( ( val_expr = new ValExpr ( PARAM_TERM_T, &term ) ) == NULL )
+ return NULL;
- if ( ( gen_expr = new GenExpr ( VAL_T, ( void* ) val_expr ) ) == NULL )
- {
- delete val_expr;
- return NULL;
- }
- return gen_expr;
+ if ( ( gen_expr = new GenExpr ( VAL_T, ( void* ) val_expr ) ) == NULL )
+ {
+ delete val_expr;
+ return NULL;
+ }
+ return gen_expr;
}
/* Converts a prefix function to an expression */
-GenExpr * GenExpr::prefun_to_expr ( float ( *func_ptr ) ( void * ), GenExpr ** expr_list, int num_args )
+GenExpr *
+GenExpr::prefun_to_expr ( float ( *func_ptr ) ( void * ), GenExpr ** expr_list, int num_args )
{
- GenExpr * gen_expr;
- PrefunExpr * prefun_expr;
+ GenExpr * gen_expr;
+ PrefunExpr * prefun_expr;
- prefun_expr = new PrefunExpr();
+ prefun_expr = new PrefunExpr();
- if ( prefun_expr == NULL )
- return NULL;
+ if ( prefun_expr == NULL )
+ return NULL;
- prefun_expr->num_args = num_args;
- prefun_expr->func_ptr = ( float ( * ) ( void* ) ) func_ptr;
- prefun_expr->expr_list = expr_list;
+ prefun_expr->num_args = num_args;
+ prefun_expr->func_ptr = ( float ( * ) ( void* ) ) func_ptr;
+ prefun_expr->expr_list = expr_list;
- gen_expr = new GenExpr ( PREFUN_T, ( void* ) prefun_expr );
+ gen_expr = new GenExpr ( PREFUN_T, ( void* ) prefun_expr );
- if ( gen_expr == NULL )
- delete prefun_expr;
+ if ( gen_expr == NULL )
+ delete prefun_expr;
- return gen_expr;
+ return gen_expr;
}
/* Creates a new tree expression */
-TreeExpr::TreeExpr ( InfixOp * _infix_op, GenExpr * _gen_expr, TreeExpr * _left, TreeExpr * _right ) :
- infix_op ( _infix_op ), gen_expr ( _gen_expr ),
- left ( _left ), right ( _right ) {}
+TreeExpr::TreeExpr (
+InfixOp * _infix_op,
+GenExpr * _gen_expr,
+TreeExpr * _left,
+TreeExpr * _right
+)
+ : infix_op ( _infix_op ),
+ gen_expr ( _gen_expr ),
+ left ( _left ),
+ right ( _right )
+{}
/* Creates a new value expression */
ValExpr::ValExpr ( int _type, Term * _term ) :type ( _type )
{
+ //val_expr->type = _type;
+ term.constant = _term->constant;
+ term.param = _term->param;
-
- //val_expr->type = _type;
- term.constant = _term->constant;
- term.param = _term->param;
-
- //return val_expr;
+ //return val_expr;
}
/* Creates a new general expression */
-GenExpr::GenExpr ( int _type, void * _item ) :type ( _type ), item ( _item ) {}
+GenExpr::GenExpr ( int _type, void * _item )
+ : type ( _type ), item ( _item )
+{}
/* Frees a general expression */
GenExpr::~GenExpr()
{
-
- switch ( type )
- {
- case VAL_T:
- delete ( ( ValExpr* ) item );
- break;
- case PREFUN_T:
- delete ( ( PrefunExpr* ) item );
- break;
- case TREE_T:
- delete ( ( TreeExpr* ) item );
- break;
- }
+ switch ( type )
+ {
+ case VAL_T:
+ delete ( ( ValExpr* ) item );
+ break;
+ case PREFUN_T:
+ delete ( ( PrefunExpr* ) item );
+ break;
+ case TREE_T:
+ delete ( ( TreeExpr* ) item );
+ break;
+ }
}
/* Frees a function in prefix notation */
PrefunExpr::~PrefunExpr()
{
+ int i;
- int i;
-
- /* Free every element in expression list */
- for ( i = 0 ; i < num_args; i++ )
- {
- delete expr_list[i];
- }
- free ( expr_list );
+ /* Free every element in expression list */
+ for ( i = 0 ; i < num_args; i++ )
+ {
+ delete expr_list[i];
+ }
+ free ( expr_list );
}
/* Frees values of type VARIABLE and CONSTANT */
@@ -338,36 +340,34 @@
/* Frees a tree expression */
TreeExpr::~TreeExpr()
{
+ /* free left tree */
+ if ( left != NULL )
+ {
+ delete left;
+ }
- /* free left tree */
- if ( left != NULL )
- {
- delete left;
- }
+ /* free general expression object */
+ if ( gen_expr != NULL )
+ {
+ delete gen_expr;
+ }
- /* free general expression object */
- if ( gen_expr != NULL )
- {
- delete gen_expr;
- }
+ /* Note that infix operators are always
+ stored in memory unless the program
+ exits, so we don't remove them here */
- /* Note that infix operators are always
- stored in memory unless the program
- exits, so we don't remove them here */
-
- /* free right tree */
- if ( right != NULL )
- {
- delete right;
- }
+ /* free right tree */
+ if ( right != NULL )
+ {
+ delete right;
+ }
}
/* Initializes an infix operator */
InfixOp::InfixOp ( int type, int precedence )
{
-
- this->type = type;
- this->precedence = precedence;
+ this->type = type;
+ this->precedence = precedence;
}
diff --git a/src/libprojectM/MilkdropPresetFactory/Expr.hpp b/src/libprojectM/MilkdropPresetFactory/Expr.hpp
index b732531..be6af29 100644
--- a/src/libprojectM/MilkdropPresetFactory/Expr.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/Expr.hpp
@@ -25,13 +25,13 @@
*
* $Log$
*/
-
#ifndef _EXPR_H
#define _EXPR_H
#include "dlldefs.h"
#include "CValue.hpp"
+
class Param;
#define CONST_STACK_ELEMENT 0
@@ -39,6 +39,7 @@
#define EVAL_ERROR -1
+
/* Infix Operator Function */
class InfixOp
{
@@ -70,7 +71,7 @@
GenExpr( int type, void *item );
float eval_gen_expr(int mesh_i, int mesh_j);
-
+
static GenExpr *const_to_expr( float val );
static GenExpr *param_to_expr( Param *param );
static GenExpr *prefun_to_expr( float (*func_ptr)(void *), GenExpr **expr_list, int num_args );
@@ -85,7 +86,7 @@
~ValExpr();
ValExpr( int type, Term *term );
-
+
float eval_val_expr(int mesh_i, int mesh_j);
};
@@ -100,7 +101,7 @@
~TreeExpr();
TreeExpr( InfixOp *infix_op, GenExpr *gen_expr,
TreeExpr *left, TreeExpr *right );
-
+
float eval_tree_expr(int mesh_i, int mesh_j);
};
diff --git a/src/libprojectM/MilkdropPresetFactory/Func.cpp b/src/libprojectM/MilkdropPresetFactory/Func.cpp
index 71a9b29..4385f6f 100644
--- a/src/libprojectM/MilkdropPresetFactory/Func.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/Func.cpp
@@ -30,8 +30,9 @@
#include "Func.hpp"
#include <map>
+
Func::Func (const std::string & _name, float (*_func_ptr)(float*), int _num_args):
- name(_name), func_ptr(_func_ptr), num_args(_num_args) {}
+ name(_name), func_ptr(_func_ptr), num_args(_num_args) {}
/* Frees a function type, real complicated... */
Func::~Func() {}
diff --git a/src/libprojectM/MilkdropPresetFactory/Func.hpp b/src/libprojectM/MilkdropPresetFactory/Func.hpp
index ae571b7..6a240f4 100644
--- a/src/libprojectM/MilkdropPresetFactory/Func.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/Func.hpp
@@ -32,32 +32,33 @@
#include "Common.hpp"
#include <string>
+
/* Function Type */
class DLLEXPORT Func {
public:
- /// Create a new function wrapper object
- /// \param name a name to uniquely identify the function.
- /// \param func_ptr a pointer to a function of floating point arguments
- /// \param num_args the number of floating point arguments this function requires
- Func(const std::string & name, float (*func_ptr)(float*), int num_args );
+ /// Create a new function wrapper object
+ /// \param name a name to uniquely identify the function.
+ /// \param func_ptr a pointer to a function of floating point arguments
+ /// \param num_args the number of floating point arguments this function requires
+ Func(const std::string & name, float (*func_ptr)(float*), int num_args );
- /* Public Prototypes */
- ~Func();
+ /* Public Prototypes */
+ ~Func();
- inline const std::string & getName() const {
- return name;
- }
+ inline const std::string & getName() const {
+ return name;
+ }
- inline int getNumArgs() const {
- return num_args;
- }
+ inline int getNumArgs() const {
+ return num_args;
+ }
- float (*func_ptr)(float*);
-private:
- std::string name;
- int num_args;
+ float (*func_ptr)(float*);
+private:
+ std::string name;
+ int num_args;
};
#endif /** !_FUNC_H */
diff --git a/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp b/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp
index 5a48532..4dcd008 100644
--- a/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp
@@ -2,208 +2,211 @@
#include <sstream>
#include <string>
#include "MilkdropPreset.hpp"
+
+
const std::string IdlePresets::IDLE_PRESET_NAME
- ("Geiss & Sperl - Feedback (projectM idle HDR mix).milk");
+ ("Geiss & Sperl - Feedback (projectM idle HDR mix).milk");
-std::string IdlePresets::presetText() {
-std::ostringstream out;
+std::string
+IdlePresets::presetText()
+{
+ std::ostringstream out;
-out << "[preset00]\n" <<
-"fRating=2.000000\n" <<
-"fGammaAdj=1.700000\n" <<
-"fDecay=0.940000\n" <<
-"fVideoEchoZoom=1.000000\n" <<
-"fVideoEchoAlpha=0.000000\n" <<
-"nVideoEchoOrientation=0\n" <<
-"nWaveMode=0\n" <<
-"bAdditiveWaves=1\n" <<
-"bWaveDots=0\n" <<
-"bWaveThick=0\n" <<
-"bModWaveAlphaByVolume=0\n" <<
-"bMaximizeWaveColor=0\n" <<
-"bTexWrap=1\n" <<
-"bDarkenCenter=0\n" <<
-"bRedBlueStereo=0\n" <<
-"bBrighten=0\n" <<
-"bDarken=0\n" <<
-"bSolarize=0\n" <<
-"bInvert=0\n" <<
-"fWaveAlpha=0.001000\n" <<
-"fWaveScale=0.010000\n" <<
-"fWaveSmoothing=0.630000\n" <<
-"fWaveParam=-1.000000\n" <<
-"fModWaveAlphaStart=0.710000\n" <<
-"fModWaveAlphaEnd=1.300000\n" <<
-"fWarpAnimSpeed=1.000000\n" <<
-"fWarpScale=1.331000\n" <<
-"fZoomExponent=1.000000\n" <<
-"fShader=0.000000\n" <<
-"zoom=13.290894\n" <<
-"rot=-0.020000\n" <<
-"cx=0.500000\n" <<
-"cy=0.500000\n" <<
-"dx=-0.280000\n" <<
-"dy=-0.320000\n" <<
-"warp=0.010000\n" <<
-"sx=1.000000\n" <<
-"sy=1.000000\n" <<
-"wave_r=0.650000\n" <<
-"wave_g=0.650000\n" <<
-"wave_b=0.650000\n" <<
-"wave_x=0.500000\n" <<
-"wave_y=0.500000\n" <<
-"ob_size=0.000000\n" <<
-"ob_r=0.010000\n" <<
-"ob_g=0.000000\n" <<
-"ob_b=0.000000\n" <<
-"ob_a=1.000000\n" <<
-"ib_size=0.000000\n" <<
-"ib_r=0.950000\n" <<
-"ib_g=0.850000\n" <<
-"ib_b=0.650000\n" <<
-"ib_a=1.000000\n" <<
-"nMotionVectorsX=64.000000\n" <<
-"nMotionVectorsY=0.000000\n" <<
-"mv_dx=0.000000\n" <<
-"mv_dy=0.000000\n" <<
-"mv_l=0.900000\n" <<
-"mv_r=1.000000\n" <<
-"mv_g=1.000000\n" <<
-"mv_b=1.000000\n" <<
-"mv_a=0.000000\n" <<
-"shapecode_3_enabled=1\n" <<
-"shapecode_3_sides=20\n" <<
-"shapecode_3_additive=0\n" <<
-"shapecode_3_thickOutline=0\n" <<
-"shapecode_3_textured=1\n" <<
-"shapecode_3_ImageURL=M.tga\n" <<
-"shapecode_3_x=0.68\n" <<
-"shapecode_3_y=0.5\n" <<
-"shapecode_3_rad=0.41222\n" <<
-"shapecode_3_ang=0\n" <<
-"shapecode_3_tex_ang=0\n" <<
-"shapecode_3_tex_zoom=0.71\n" <<
-"shapecode_3_r=1\n" <<
-"shapecode_3_g=1\n" <<
-"shapecode_3_b=1\n" <<
-"shapecode_3_a=1\n" <<
-"shapecode_3_r2=1\n" <<
-"shapecode_3_g2=1\n" <<
-"shapecode_3_b2=1\n" <<
-"shapecode_3_a2=1\n" <<
-"shapecode_3_border_r=0\n" <<
-"shapecode_3_border_g=0\n" <<
-"shapecode_3_border_b=0\n" <<
-"shapecode_3_border_a=0\n" <<
-"shape_3_per_frame1=x = x + q1;\n" <<
-"shape_3_per_frame2=y = y + q2;\n" <<
-"shape_3_per_frame3=r =0.5 + 0.5*sin(q8*0.613 + 1);\n" <<
-"shape_3_per_frame4=g = 0.5 + 0.5*sin(q8*0.763 + 2);\n" <<
-"shape_3_per_frame5=b = 0.5 + 0.5*sin(q8*0.771 + 5);\n" <<
-"shape_3_per_frame6=r2 = 0.5 + 0.5*sin(q8*0.635 + 4);\n" <<
-"shape_3_per_frame7=g2 = 0.5 + 0.5*sin(q8*0.616+ 1);\n" <<
-"shape_3_per_frame8=b2 = 0.5 + 0.5*sin(q8*0.538 + 3);\n" <<
-"shapecode_4_enabled=1\n" <<
-"shapecode_4_sides=4\n" <<
-"shapecode_4_additive=0\n" <<
-"shapecode_4_thickOutline=0\n" <<
-"shapecode_4_textured=1\n" <<
-"shapecode_4_ImageURL=headphones.tga\n" <<
-"shapecode_4_x=0.68\n" <<
-"shapecode_4_y=0.58\n" <<
-"shapecode_4_rad=0.6\n" <<
-"shapecode_4_ang=0\n" <<
-"shapecode_4_tex_ang=0\n" <<
-"shapecode_4_tex_zoom=0.71\n" <<
-"shapecode_4_r=1\n" <<
-"shapecode_4_g=1\n" <<
-"shapecode_4_b=1\n" <<
-"shapecode_4_a=1\n" <<
-"shapecode_4_r2=1\n" <<
-"shapecode_4_g2=1\n" <<
-"shapecode_4_b2=1\n" <<
-"shapecode_4_a2=1\n" <<
-"shapecode_4_border_r=0\n" <<
-"shapecode_4_border_g=0\n" <<
-"shapecode_4_border_b=0\n" <<
-"shapecode_4_border_a=0\n" <<
-"shape_4_per_frame1=x = x + q1;\n" <<
-"shape_4_per_frame2=y = y + q2;\n" <<
-"shape_4_per_frame3=rad = rad + bass * 0.1;\n" <<
-"shape_4_per_frame4=a = q3;\n" <<
-"shape_4_per_frame5=a2 = q3;\n" <<
-"shapecode_6_enabled=1\n" <<
-"shapecode_6_sides=4\n" <<
-"shapecode_6_additive=0\n" <<
-"shapecode_6_thickOutline=0\n" <<
-"shapecode_6_textured=1\n" <<
-"shapecode_6_ImageURL=project.tga\n" <<
-"shapecode_6_x=0.38\n" <<
-"shapecode_6_y=0.435\n" <<
-"shapecode_6_rad=0.8\n" <<
-"shapecode_6_ang=0\n" <<
-"shapecode_6_tex_ang=0\n" <<
-"shapecode_6_tex_zoom=0.71\n" <<
-"shapecode_6_r=1\n" <<
-"shapecode_6_g=1\n" <<
-"shapecode_6_b=1\n" <<
-"shapecode_6_a=1\n" <<
-"shapecode_6_r2=1\n" <<
-"shapecode_6_g2=1\n" <<
-"shapecode_6_b2=1\n" <<
-"shapecode_6_a2=1\n" <<
-"shapecode_6_border_r=0\n" <<
-"shapecode_6_border_g=0\n" <<
-"shapecode_6_border_b=0\n" <<
-"shapecode_6_border_a=0\n" <<
-"shape_6_per_frame1=x = x + q1;\n" <<
-"shape_6_per_frame2=y = y + q2;\n" <<
-"shape_6_per_frame3=a = q3;\n" <<
-"shape_6_per_frame4=a2 = q3;\n" <<
-"per_frame_1=ob_r = 0.5 + 0.4*sin(time*1.324);\n" <<
-"per_frame_2=ob_g = 0.5 + 0.4*cos(time*1.371);\n" <<
-"per_frame_3=ob_b = 0.5+0.4*sin(2.332*time);\n" <<
-"per_frame_4=ib_r = 0.5 + 0.25*sin(time*1.424);\n" <<
-"per_frame_5=ib_g = 0.25 + 0.25*cos(time*1.871);\n" <<
-"per_frame_6=ib_b = 1-ob_b;\n" <<
-"per_frame_7=volume = 0.15*(bass+bass_att+treb+treb_att+mid+mid_att);\n" <<
-"per_frame_8=xamptarg = if(equal(frame%15,0),min(0.5*volume*bass_att,0.5),xamptarg);\n" <<
-"per_frame_9=xamp = xamp + 0.5*(xamptarg-xamp);\n" <<
-"per_frame_10=xdir = if(above(abs(xpos),xamp),-sign(xpos),if(below(abs(xspeed),0.1),2*above(xpos,0)-1,xdir));\n" <<
-"per_frame_11=xaccel = xdir*xamp - xpos - xspeed*0.055*below(abs(xpos),xamp);\n" <<
-"per_frame_12=xspeed = xspeed + xdir*xamp - xpos - xspeed*0.055*below(abs(xpos),xamp);\n" <<
-"per_frame_13=xpos = xpos + 0.001*xspeed;\n" <<
-"per_frame_14=dx = xpos*0.05;\n" <<
-"per_frame_15=yamptarg = if(equal(frame%15,0),min(0.3*volume*treb_att,0.5),yamptarg);\n" <<
-"per_frame_16=yamp = yamp + 0.5*(yamptarg-yamp);\n" <<
-"per_frame_17=ydir = if(above(abs(ypos),yamp),-sign(ypos),if(below(abs(yspeed),0.1),2*above(ypos,0)-1,ydir));\n" <<
-"per_frame_18=yaccel = ydir*yamp - ypos - yspeed*0.055*below(abs(ypos),yamp);\n" <<
-"per_frame_19=yspeed = yspeed + ydir*yamp - ypos - yspeed*0.055*below(abs(ypos),yamp);\n" <<
-"per_frame_20=ypos = ypos + 0.001*yspeed;\n" <<
-"per_frame_21=dy = ypos*0.05;\n" <<
-"per_frame_22=wave_a = 0;\n" <<
-"per_frame_23=q8 = oldq8 + 0.0003*(pow(1+1.2*bass+0.4*bass_att+0.1*treb+0.1*treb_att+0.1*mid+0.1*mid_att,6)/fps);\n" <<
-"per_frame_24=oldq8 = q8;\n" <<
-"per_frame_25=q7 = 0.003*(pow(1+1.2*bass+0.4*bass_att+0.1*treb+0.1*treb_att+0.1*mid+0.1*mid_att,6)/fps);\n" <<
-"per_frame_26=rot = 0.4 + 1.5*sin(time*0.273) + 0.4*sin(time*0.379+3);\n" <<
-"per_frame_27=q1 = 0.05*sin(time*1.14);\n" <<
-"per_frame_28=q2 = 0.03*sin(time*0.93+2);\n" <<
-"per_frame_29=q3 = if(above(frame,60),1, frame/60.0);\n" <<
-"per_frame_30=oldq8 = if(above(oldq8,1000),0,oldq8);\n" <<
-"per_pixel_1=zoom =( log(sqrt(2)-rad) -0.24)*1;\n";
+ out << "[preset00]\n"
+ << "fRating=2.000000\n"
+ << "fGammaAdj=1.700000\n"
+ << "fDecay=0.940000\n"
+ << "fVideoEchoZoom=1.000000\n"
+ << "fVideoEchoAlpha=0.000000\n"
+ << "nVideoEchoOrientation=0\n"
+ << "nWaveMode=0\n"
+ << "bAdditiveWaves=1\n"
+ << "bWaveDots=0\n"
+ << "bWaveThick=0\n"
+ << "bModWaveAlphaByVolume=0\n"
+ << "bMaximizeWaveColor=0\n"
+ << "bTexWrap=1\n"
+ << "bDarkenCenter=0\n"
+ << "bRedBlueStereo=0\n"
+ << "bBrighten=0\n"
+ << "bDarken=0\n"
+ << "bSolarize=0\n"
+ << "bInvert=0\n"
+ << "fWaveAlpha=0.001000\n"
+ << "fWaveScale=0.010000\n"
+ << "fWaveSmoothing=0.630000\n"
+ << "fWaveParam=-1.000000\n"
+ << "fModWaveAlphaStart=0.710000\n"
+ << "fModWaveAlphaEnd=1.300000\n"
+ << "fWarpAnimSpeed=1.000000\n"
+ << "fWarpScale=1.331000\n"
+ << "fZoomExponent=1.000000\n"
+ << "fShader=0.000000\n"
+ << "zoom=13.290894\n"
+ << "rot=-0.020000\n"
+ << "cx=0.500000\n"
+ << "cy=0.500000\n"
+ << "dx=-0.280000\n"
+ << "dy=-0.320000\n"
+ << "warp=0.010000\n"
+ << "sx=1.000000\n"
+ << "sy=1.000000\n"
+ << "wave_r=0.650000\n"
+ << "wave_g=0.650000\n"
+ << "wave_b=0.650000\n"
+ << "wave_x=0.500000\n"
+ << "wave_y=0.500000\n"
+ << "ob_size=0.000000\n"
+ << "ob_r=0.010000\n"
+ << "ob_g=0.000000\n"
+ << "ob_b=0.000000\n"
+ << "ob_a=1.000000\n"
+ << "ib_size=0.000000\n"
+ << "ib_r=0.950000\n"
+ << "ib_g=0.850000\n"
+ << "ib_b=0.650000\n"
+ << "ib_a=1.000000\n"
+ << "nMotionVectorsX=64.000000\n"
+ << "nMotionVectorsY=0.000000\n"
+ << "mv_dx=0.000000\n"
+ << "mv_dy=0.000000\n"
+ << "mv_l=0.900000\n"
+ << "mv_r=1.000000\n"
+ << "mv_g=1.000000\n"
+ << "mv_b=1.000000\n"
+ << "mv_a=0.000000\n"
+ << "shapecode_3_enabled=1\n"
+ << "shapecode_3_sides=20\n"
+ << "shapecode_3_additive=0\n"
+ << "shapecode_3_thickOutline=0\n"
+ << "shapecode_3_textured=1\n"
+ << "shapecode_3_ImageURL=M.tga\n"
+ << "shapecode_3_x=0.68\n"
+ << "shapecode_3_y=0.5\n"
+ << "shapecode_3_rad=0.41222\n"
+ << "shapecode_3_ang=0\n"
+ << "shapecode_3_tex_ang=0\n"
+ << "shapecode_3_tex_zoom=0.71\n"
+ << "shapecode_3_r=1\n"
+ << "shapecode_3_g=1\n"
+ << "shapecode_3_b=1\n"
+ << "shapecode_3_a=1\n"
+ << "shapecode_3_r2=1\n"
+ << "shapecode_3_g2=1\n"
+ << "shapecode_3_b2=1\n"
+ << "shapecode_3_a2=1\n"
+ << "shapecode_3_border_r=0\n"
+ << "shapecode_3_border_g=0\n"
+ << "shapecode_3_border_b=0\n"
+ << "shapecode_3_border_a=0\n"
+ << "shape_3_per_frame1=x = x + q1;\n"
+ << "shape_3_per_frame2=y = y + q2;\n"
+ << "shape_3_per_frame3=r =0.5 + 0.5*sin(q8*0.613 + 1);\n"
+ << "shape_3_per_frame4=g = 0.5 + 0.5*sin(q8*0.763 + 2);\n"
+ << "shape_3_per_frame5=b = 0.5 + 0.5*sin(q8*0.771 + 5);\n"
+ << "shape_3_per_frame6=r2 = 0.5 + 0.5*sin(q8*0.635 + 4);\n"
+ << "shape_3_per_frame7=g2 = 0.5 + 0.5*sin(q8*0.616+ 1);\n"
+ << "shape_3_per_frame8=b2 = 0.5 + 0.5*sin(q8*0.538 + 3);\n"
+ << "shapecode_4_enabled=1\n"
+ << "shapecode_4_sides=4\n"
+ << "shapecode_4_additive=0\n"
+ << "shapecode_4_thickOutline=0\n"
+ << "shapecode_4_textured=1\n"
+ << "shapecode_4_ImageURL=headphones.tga\n"
+ << "shapecode_4_x=0.68\n"
+ << "shapecode_4_y=0.58\n"
+ << "shapecode_4_rad=0.6\n"
+ << "shapecode_4_ang=0\n"
+ << "shapecode_4_tex_ang=0\n"
+ << "shapecode_4_tex_zoom=0.71\n"
+ << "shapecode_4_r=1\n"
+ << "shapecode_4_g=1\n"
+ << "shapecode_4_b=1\n"
+ << "shapecode_4_a=1\n"
+ << "shapecode_4_r2=1\n"
+ << "shapecode_4_g2=1\n"
+ << "shapecode_4_b2=1\n"
+ << "shapecode_4_a2=1\n"
+ << "shapecode_4_border_r=0\n"
+ << "shapecode_4_border_g=0\n"
+ << "shapecode_4_border_b=0\n"
+ << "shapecode_4_border_a=0\n"
+ << "shape_4_per_frame1=x = x + q1;\n"
+ << "shape_4_per_frame2=y = y + q2;\n"
+ << "shape_4_per_frame3=rad = rad + bass * 0.1;\n"
+ << "shape_4_per_frame4=a = q3;\n"
+ << "shape_4_per_frame5=a2 = q3;\n"
+ << "shapecode_6_enabled=1\n"
+ << "shapecode_6_sides=4\n"
+ << "shapecode_6_additive=0\n"
+ << "shapecode_6_thickOutline=0\n"
+ << "shapecode_6_textured=1\n"
+ << "shapecode_6_ImageURL=project.tga\n"
+ << "shapecode_6_x=0.38\n"
+ << "shapecode_6_y=0.435\n"
+ << "shapecode_6_rad=0.8\n"
+ << "shapecode_6_ang=0\n"
+ << "shapecode_6_tex_ang=0\n"
+ << "shapecode_6_tex_zoom=0.71\n"
+ << "shapecode_6_r=1\n"
+ << "shapecode_6_g=1\n"
+ << "shapecode_6_b=1\n"
+ << "shapecode_6_a=1\n"
+ << "shapecode_6_r2=1\n"
+ << "shapecode_6_g2=1\n"
+ << "shapecode_6_b2=1\n"
+ << "shapecode_6_a2=1\n"
+ << "shapecode_6_border_r=0\n"
+ << "shapecode_6_border_g=0\n"
+ << "shapecode_6_border_b=0\n"
+ << "shapecode_6_border_a=0\n"
+ << "shape_6_per_frame1=x = x + q1;\n"
+ << "shape_6_per_frame2=y = y + q2;\n"
+ << "shape_6_per_frame3=a = q3;\n"
+ << "shape_6_per_frame4=a2 = q3;\n"
+ << "per_frame_1=ob_r = 0.5 + 0.4*sin(time*1.324);\n"
+ << "per_frame_2=ob_g = 0.5 + 0.4*cos(time*1.371);\n"
+ << "per_frame_3=ob_b = 0.5+0.4*sin(2.332*time);\n"
+ << "per_frame_4=ib_r = 0.5 + 0.25*sin(time*1.424);\n"
+ << "per_frame_5=ib_g = 0.25 + 0.25*cos(time*1.871);\n"
+ << "per_frame_6=ib_b = 1-ob_b;\n"
+ << "per_frame_7=volume = 0.15*(bass+bass_att+treb+treb_att+mid+mid_att);\n"
+ << "per_frame_8=xamptarg = if(equal(frame%15,0),min(0.5*volume*bass_att,0.5),xamptarg);\n"
+ << "per_frame_9=xamp = xamp + 0.5*(xamptarg-xamp);\n"
+ << "per_frame_10=xdir = if(above(abs(xpos),xamp),-sign(xpos),if(below(abs(xspeed),0.1),2*above(xpos,0)-1,xdir));\n"
+ << "per_frame_11=xaccel = xdir*xamp - xpos - xspeed*0.055*below(abs(xpos),xamp);\n"
+ << "per_frame_12=xspeed = xspeed + xdir*xamp - xpos - xspeed*0.055*below(abs(xpos),xamp);\n"
+ << "per_frame_13=xpos = xpos + 0.001*xspeed;\n"
+ << "per_frame_14=dx = xpos*0.05;\n"
+ << "per_frame_15=yamptarg = if(equal(frame%15,0),min(0.3*volume*treb_att,0.5),yamptarg);\n"
+ << "per_frame_16=yamp = yamp + 0.5*(yamptarg-yamp);\n"
+ << "per_frame_17=ydir = if(above(abs(ypos),yamp),-sign(ypos),if(below(abs(yspeed),0.1),2*above(ypos,0)-1,ydir));\n"
+ << "per_frame_18=yaccel = ydir*yamp - ypos - yspeed*0.055*below(abs(ypos),yamp);\n"
+ << "per_frame_19=yspeed = yspeed + ydir*yamp - ypos - yspeed*0.055*below(abs(ypos),yamp);\n"
+ << "per_frame_20=ypos = ypos + 0.001*yspeed;\n"
+ << "per_frame_21=dy = ypos*0.05;\n"
+ << "per_frame_22=wave_a = 0;\n"
+ << "per_frame_23=q8 = oldq8 + 0.0003*(pow(1+1.2*bass+0.4*bass_att+0.1*treb+0.1*treb_att+0.1*mid+0.1*mid_att,6)/fps);\n"
+ << "per_frame_24=oldq8 = q8;\n"
+ << "per_frame_25=q7 = 0.003*(pow(1+1.2*bass+0.4*bass_att+0.1*treb+0.1*treb_att+0.1*mid+0.1*mid_att,6)/fps);\n"
+ << "per_frame_26=rot = 0.4 + 1.5*sin(time*0.273) + 0.4*sin(time*0.379+3);\n"
+ << "per_frame_27=q1 = 0.05*sin(time*1.14);\n"
+ << "per_frame_28=q2 = 0.03*sin(time*0.93+2);\n"
+ << "per_frame_29=q3 = if(above(frame,60),1, frame/60.0);\n"
+ << "per_frame_30=oldq8 = if(above(oldq8,1000),0,oldq8);\n"
+ << "per_pixel_1=zoom =( log(sqrt(2)-rad) -0.24)*1;\n";
-return out.str();
-
+ return out.str();
}
-std::auto_ptr<Preset> IdlePresets::allocate(const std::string & name, PresetOutputs & presetOutputs)
+std::auto_ptr<Preset>
+IdlePresets::allocate(const std::string & name, PresetOutputs & presetOutputs)
{
-
if (name == IDLE_PRESET_NAME) {
- std::istringstream in(presetText());
- return std::auto_ptr<Preset>(new MilkdropPreset(in, IDLE_PRESET_NAME, presetOutputs));
+ std::istringstream in(presetText());
+ return std::auto_ptr<Preset>(new MilkdropPreset(in, IDLE_PRESET_NAME, presetOutputs));
}
else
- return std::auto_ptr<Preset>(0);
+ return std::auto_ptr<Preset>(0);
}
diff --git a/src/libprojectM/MilkdropPresetFactory/IdlePreset.hpp b/src/libprojectM/MilkdropPresetFactory/IdlePreset.hpp
index 3231d43..31bb01a 100644
--- a/src/libprojectM/MilkdropPresetFactory/IdlePreset.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/IdlePreset.hpp
@@ -3,18 +3,20 @@
#include <memory>
#include <string>
+
class PresetOutputs;
class Preset;
/// A preset that does not depend on the file system to be loaded. This allows projectM to render
/// something (ie. self indulgent project advertising) even when no valid preset directory is found.
class IdlePresets {
- public:
- /// Allocate a new idle preset instance
- /// \returns a newly allocated auto pointer of an idle preset instance
- static std::auto_ptr<Preset> allocate(const std::string & path, PresetOutputs & outputs);
- private:
- static std::string presetText();
- static const std::string IDLE_PRESET_NAME;
+public:
+ /// Allocate a new idle preset instance
+ /// \returns a newly allocated auto pointer of an idle preset instance
+ static std::auto_ptr<Preset> allocate(const std::string & path, PresetOutputs & outputs);
+private:
+ static std::string presetText();
+ static const std::string IDLE_PRESET_NAME;
};
+
#endif
diff --git a/src/libprojectM/MilkdropPresetFactory/InitCond.cpp b/src/libprojectM/MilkdropPresetFactory/InitCond.cpp
index 2dae471..e171ce5 100644
--- a/src/libprojectM/MilkdropPresetFactory/InitCond.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/InitCond.cpp
@@ -36,15 +36,16 @@
#include <cassert>
#include <iostream>
+
char InitCond::init_cond_string_buffer[STRING_BUFFER_SIZE];
int InitCond::init_cond_string_buffer_index = 0;
+
/* Creates a new initial condition */
-InitCond::InitCond( Param * _param, CValue _init_val ):param(_param), init_val(_init_val) {
-
-
+InitCond::InitCond( Param * _param, CValue _init_val ):param(_param), init_val(_init_val)
+{
// std::cerr << "InitCond::InitCond: " << this->param->name << std::endl;
-
+
assert(param);
assert(param->engine_val);
}
@@ -52,55 +53,55 @@
/* Frees initial condition structure */
InitCond::~InitCond() {}
-void InitCond::evaluate()
+void
+InitCond::evaluate()
{
evaluate(false);
}
/* Evaluate an initial conditon */
-void InitCond::evaluate(bool evalUser) {
+void
+InitCond::evaluate(bool evalUser)
+{
+ assert(this);
+ assert(param);
+ if (param->flags & P_FLAG_USERDEF && !evalUser)
+ return;
-
- assert(this);
- assert(param);
-
-if (param->flags & P_FLAG_USERDEF && !evalUser)
- return;
-
- /* Set matrix flag to zero. This ensures
- its constant value will be used rather than a matrix value
+ /* Set matrix flag to zero. This ensures
+ its constant value will be used rather than a matrix value
*/
-param->matrix_flag = false;
-
+ param->matrix_flag = false;
+
/* Parameter is of boolean type, either true/false */
-
+
if (param->type == P_TYPE_BOOL) {
- // printf( "init_cond: %s = %d (TYPE BOOL)\n", param->name.c_str(), init_val.bool_val);
- //std::cerr << "[InitCond] param is a boolean of with name "
- // << param->name << std::endl;
+ // printf( "init_cond: %s = %d (TYPE BOOL)\n", param->name.c_str(), init_val.bool_val);
+ //std::cerr << "[InitCond] param is a boolean of with name "
+ // << param->name << std::endl;
- assert(param->engine_val);
+ assert(param->engine_val);
- *((bool*)param->engine_val) = init_val.bool_val;
+ *((bool*)param->engine_val) = init_val.bool_val;
- return;
+ return;
}
-
+
/* Parameter is an integer type, just like C */
-
+
if ( param->type == P_TYPE_INT) {
- assert(param->engine_val);
- *((int*)param->engine_val) = init_val.int_val;
- return;
+ assert(param->engine_val);
+ *((int*)param->engine_val) = init_val.int_val;
+ return;
}
/* Parameter is of a float type, just like C */
if (param->type == P_TYPE_DOUBLE) {
- assert(param->engine_val);
- *((float*)param->engine_val) = init_val.float_val;
+ assert(param->engine_val);
+ *((float*)param->engine_val) = init_val.float_val;
return;
}
@@ -109,39 +110,39 @@
}
/* WIP */
-void InitCond::init_cond_to_string() {
-
- int string_length;
- char string[MAX_TOKEN_SIZE];
-
- /* Create a string "param_name=val" */
- switch (param->type) {
-
- case P_TYPE_BOOL:
- sprintf(string, "%s=%d\n", param->name.c_str(), init_val.bool_val);
- break;
- case P_TYPE_INT:
- sprintf(string, "%s=%d\n", param->name.c_str(), init_val.int_val);
- break;
- case P_TYPE_DOUBLE:
- sprintf(string, "%s=%f\n", param->name.c_str(), init_val.float_val);
- break;
- default:
- return;
- }
-
- /* Compute the length of the string */
- string_length = strlen(string);
-
- /* Buffer overflow check */
- if ((init_cond_string_buffer_index + string_length + 1) > (STRING_BUFFER_SIZE - 1))
- return;
-
- /* Copy the string into the initial condition string buffer */
- strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length);
-
- /* Increment the string buffer, offset by one for the null terminator, which will be
- overwritten by the next call to this function */
- init_cond_string_buffer_index+= string_length + 1;
-}
+void
+InitCond::init_cond_to_string()
+{
+ int string_length;
+ char string[MAX_TOKEN_SIZE];
+ /* Create a string "param_name=val" */
+ switch (param->type) {
+
+ case P_TYPE_BOOL:
+ sprintf(string, "%s=%d\n", param->name.c_str(), init_val.bool_val);
+ break;
+ case P_TYPE_INT:
+ sprintf(string, "%s=%d\n", param->name.c_str(), init_val.int_val);
+ break;
+ case P_TYPE_DOUBLE:
+ sprintf(string, "%s=%f\n", param->name.c_str(), init_val.float_val);
+ break;
+ default:
+ return;
+ }
+
+ /* Compute the length of the string */
+ string_length = strlen(string);
+
+ /* Buffer overflow check */
+ if ((init_cond_string_buffer_index + string_length + 1) > (STRING_BUFFER_SIZE - 1))
+ return;
+
+ /* Copy the string into the initial condition string buffer */
+ strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length);
+
+ /* Increment the string buffer, offset by one for the null terminator, which will be
+ overwritten by the next call to this function */
+ init_cond_string_buffer_index+= string_length + 1;
+}
diff --git a/src/libprojectM/MilkdropPresetFactory/InitCond.hpp b/src/libprojectM/MilkdropPresetFactory/InitCond.hpp
index a4b124b..43717b3 100644
--- a/src/libprojectM/MilkdropPresetFactory/InitCond.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/InitCond.hpp
@@ -39,22 +39,23 @@
class Param;
#include <map>
+
class InitCond {
public:
- Param *param;
- CValue init_val;
+ Param *param;
+ CValue init_val;
- static char init_cond_string_buffer[STRING_BUFFER_SIZE];
- static int init_cond_string_buffer_index;
+ static char init_cond_string_buffer[STRING_BUFFER_SIZE];
+ static int init_cond_string_buffer_index;
- InitCond( Param * param, CValue init_val);
- ~InitCond();
- void evaluate(); //Wrapper around following declaration
- void evaluate(bool evalUser);
+ InitCond( Param * param, CValue init_val);
+ ~InitCond();
+ void evaluate(); //Wrapper around following declaration
+ void evaluate(bool evalUser);
- void init_cond_to_string();
- void write_init();
- };
+ void init_cond_to_string();
+ void write_init();
+};
#endif /** !_INIT_COND_H */
diff --git a/src/libprojectM/MilkdropPresetFactory/InitCondUtils.hpp b/src/libprojectM/MilkdropPresetFactory/InitCondUtils.hpp
index 2186199..493d249 100644
--- a/src/libprojectM/MilkdropPresetFactory/InitCondUtils.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/InitCondUtils.hpp
@@ -5,75 +5,78 @@
#include <iostream>
#include <stdlib.h>
+
namespace InitCondUtils {
+
class LoadUnspecInitCond {
- public:
+public:
- LoadUnspecInitCond(std::map<std::string,InitCond*> & initCondTree, std::map<std::string,InitCond*> & perFrameInitEqnTree):
- m_initCondTree(initCondTree), m_perFrameInitEqnTree(perFrameInitEqnTree) {}
+ LoadUnspecInitCond(std::map<std::string,InitCond*> & initCondTree, std::map<std::string,InitCond*> & perFrameInitEqnTree):
+ m_initCondTree(initCondTree), m_perFrameInitEqnTree(perFrameInitEqnTree) {}
- void operator()(Param * param);
+ void operator()(Param * param);
- private:
- std::map<std::string,InitCond*> & m_initCondTree;
- std::map<std::string,InitCond*> & m_perFrameInitEqnTree;
+private:
+ std::map<std::string,InitCond*> & m_initCondTree;
+ std::map<std::string,InitCond*> & m_perFrameInitEqnTree;
};
-inline void LoadUnspecInitCond::operator() (Param * param) {
+inline void
+LoadUnspecInitCond::operator() (Param * param)
+{
+ InitCond * init_cond = 0;
+ CValue init_val;
- InitCond * init_cond = 0;
- CValue init_val;
-
- assert(param);
- assert(param->engine_val);
+ assert(param);
+ assert(param->engine_val);
- /* Don't count these parameters as initial conditions */
- if (param->flags & P_FLAG_READONLY)
- return;
- if (param->flags & P_FLAG_QVAR)
- return;
-// if (param->flags & P_FLAG_TVAR)
- // return;
- if (param->flags & P_FLAG_USERDEF)
- return;
+ /* Don't count these parameters as initial conditions */
+ if (param->flags & P_FLAG_READONLY)
+ return;
+ if (param->flags & P_FLAG_QVAR)
+ return;
+ //if (param->flags & P_FLAG_TVAR)
+ // return;
+ if (param->flags & P_FLAG_USERDEF)
+ return;
- /* If initial condition was not defined by the preset file, force a default one
- with the following code */
+ /* If initial condition was not defined by the preset file, force a default one
+ with the following code */
- if (m_initCondTree.find(param->name) == m_initCondTree.end()) {
+ if (m_initCondTree.find(param->name) == m_initCondTree.end()) {
- /* Make sure initial condition does not exist in the set of per frame initial equations */
- if (m_perFrameInitEqnTree.find(param->name) != m_perFrameInitEqnTree.end())
- return;
+ /* Make sure initial condition does not exist in the set of per frame initial equations */
+ if (m_perFrameInitEqnTree.find(param->name) != m_perFrameInitEqnTree.end())
+ return;
- // Set an initial vialue via correct union member
- if (param->type == P_TYPE_BOOL)
- init_val.bool_val = param->default_init_val.bool_val;
- else if (param->type == P_TYPE_INT)
- init_val.int_val = param->default_init_val.int_val;
+ // Set an initial vialue via correct union member
+ if (param->type == P_TYPE_BOOL)
+ init_val.bool_val = param->default_init_val.bool_val;
+ else if (param->type == P_TYPE_INT)
+ init_val.int_val = param->default_init_val.int_val;
- else if (param->type == P_TYPE_DOUBLE) {
- init_val.float_val = param->default_init_val.float_val;
- }
+ else if (param->type == P_TYPE_DOUBLE) {
+ init_val.float_val = param->default_init_val.float_val;
+ }
- //printf("%s\n", param->name);
- /* Create new initial condition */
- //std::cerr << "[InitCondUtils] creating an unspecified initial condition of name " << param->name << std::endl;
- if ((init_cond = new InitCond(param, init_val)) == NULL) {
- abort();
- }
+ //printf("%s\n", param->name);
+ /* Create new initial condition */
+ //std::cerr << "[InitCondUtils] creating an unspecified initial condition of name " << param->name << std::endl;
+ if ((init_cond = new InitCond(param, init_val)) == NULL) {
+ abort();
+ }
- /* Insert the initial condition into this presets tree */
- std::pair<std::map<std::string, InitCond*>::iterator, bool> inserteePair =
- m_initCondTree.insert(std::make_pair(init_cond->param->name, init_cond));
- assert(inserteePair.second);
- assert(inserteePair.first->second);
- } else
- assert(m_initCondTree.find(param->name)->second);
+ /* Insert the initial condition into this presets tree */
+ std::pair<std::map<std::string, InitCond*>::iterator, bool> inserteePair =
+ m_initCondTree.insert(std::make_pair(init_cond->param->name, init_cond));
-
+ assert(inserteePair.second);
+ assert(inserteePair.first->second);
+ } else
+ assert(m_initCondTree.find(param->name)->second);
}
-}
+
+} /* namespace InitCondUtils */
#endif
diff --git a/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp b/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp
index d6acc7b..8f2d429 100644
--- a/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp
@@ -18,7 +18,6 @@
* See 'LICENSE.txt' included within this release
*
*/
-
#include <cstdio>
#include <cstring>
#include <cstdlib>
@@ -40,29 +39,27 @@
#include "PresetFrameIO.hpp"
-MilkdropPreset::MilkdropPreset(std::istream & in, const std::string & presetName, PresetOutputs & presetOutputs):
- Preset(presetName),
- builtinParams(_presetInputs, presetOutputs),
- _presetOutputs(presetOutputs)
+
+MilkdropPreset::MilkdropPreset(std::istream & in, const std::string & presetName, PresetOutputs & presetOutputs)
+ : Preset(presetName),
+ builtinParams(_presetInputs, presetOutputs),
+ _presetOutputs(presetOutputs)
{
initialize(in);
-
}
-MilkdropPreset::MilkdropPreset(const std::string & absoluteFilePath, const std::string & presetName, PresetOutputs & presetOutputs):
- Preset(presetName),
+MilkdropPreset::MilkdropPreset (const std::string & absoluteFilePath, const std::string & presetName, PresetOutputs & presetOutputs)
+ : Preset(presetName),
builtinParams(_presetInputs, presetOutputs),
_absoluteFilePath(absoluteFilePath),
_presetOutputs(presetOutputs),
_filename(parseFilename(absoluteFilePath))
{
-
initialize(absoluteFilePath);
-
}
+
MilkdropPreset::~MilkdropPreset()
{
-
traverse<TraverseFunctors::Delete<InitCond> >(init_cond_tree);
traverse<TraverseFunctors::Delete<InitCond> >(per_frame_init_eqn_tree);
@@ -73,38 +70,41 @@
traverse<TraverseFunctors::Delete<Param> >(user_param_tree);
- /// Testing deletion of render items by the preset. would be nice if it worked,
+ /// Testing deletion of render items by the preset. would be nice if it worked,
/// and seems to be working if you use a mutex on the preset switching.
-
- for (PresetOutputs::cwave_container::iterator pos = customWaves.begin();
- pos != customWaves.end(); ++pos ) {
- // __android_log_print(ANDROID_LOG_ERROR, "projectM", "not freeing wave %x", *pos);
+
+ for (PresetOutputs::cwave_container::iterator pos = customWaves.begin();
+ pos != customWaves.end();
+ ++pos )
+ {
+ // __android_log_print(ANDROID_LOG_ERROR, "projectM", "not freeing wave %x", *pos);
delete(*pos);
}
- for (PresetOutputs::cshape_container::iterator pos = customShapes.begin();
- pos != customShapes.end(); ++pos ) {
-//__android_log_print(ANDROID_LOG_ERROR, "projectM", "not freeing shape %x", *pos);
-
- delete(*pos);
+ for (PresetOutputs::cshape_container::iterator pos = customShapes.begin();
+ pos != customShapes.end();
+ ++pos )
+ {
+ //__android_log_print(ANDROID_LOG_ERROR, "projectM", "not freeing shape %x", *pos);
+ delete(*pos);
}
- customWaves.clear();
- customShapes.clear();
- presetOutputs().customWaves.clear();
- presetOutputs().customShapes.clear();
- presetOutputs().drawables.clear();
+ customWaves.clear();
+ customShapes.clear();
+ presetOutputs().customWaves.clear();
+ presetOutputs().customShapes.clear();
+ presetOutputs().drawables.clear();
}
/* Adds a per pixel equation according to its string name. This
will be used only by the parser */
-int MilkdropPreset::add_per_pixel_eqn(char * name, GenExpr * gen_expr)
+int
+MilkdropPreset::add_per_pixel_eqn(char * name, GenExpr * gen_expr)
{
-
PerPixelEqn * per_pixel_eqn = NULL;
- int index;
- Param * param = NULL;
+ int index;
+ Param * param = NULL;
assert(gen_expr);
assert(name);
@@ -117,7 +117,7 @@
if ( !param )
{
if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to allocate a new parameter!\n");
- return PROJECTM_FAILURE;
+ return PROJECTM_FAILURE;
}
index = per_pixel_eqn_tree.size();
@@ -126,14 +126,14 @@
if ((per_pixel_eqn = new PerPixelEqn(index, param, gen_expr)) == NULL)
{
if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to create new per pixel equation!\n");
- return PROJECTM_FAILURE;
+ return PROJECTM_FAILURE;
}
/* Insert the per pixel equation into the preset per pixel database */
- std::pair<std::map<int, PerPixelEqn*>::iterator, bool> inserteeOption = per_pixel_eqn_tree.insert
- (std::make_pair(per_pixel_eqn->index, per_pixel_eqn));
+ std::pair<std::map<int, PerPixelEqn*>::iterator, bool> inserteeOption =
+ per_pixel_eqn_tree.insert (std::make_pair(per_pixel_eqn->index, per_pixel_eqn));
if (!inserteeOption.second)
{
@@ -146,99 +146,124 @@
return PROJECTM_SUCCESS;
}
-void MilkdropPreset::evalCustomShapeInitConditions()
+void
+MilkdropPreset::evalCustomShapeInitConditions()
{
- for (PresetOutputs::cshape_container::iterator pos = customShapes.begin(); pos != customShapes.end(); ++pos) {
+ for (PresetOutputs::cshape_container::iterator pos = customShapes.begin();
+ pos != customShapes.end();
+ ++pos)
+ {
assert(*pos);
(*pos)->evalInitConds();
}
}
-void MilkdropPreset::evalCustomWaveInitConditions()
+void
+MilkdropPreset::evalCustomWaveInitConditions()
{
- for (PresetOutputs::cwave_container::iterator pos = customWaves.begin(); pos != customWaves.end(); ++pos) {
+ for (PresetOutputs::cwave_container::iterator pos = customWaves.begin();
+ pos != customWaves.end();
+ ++pos)
+ {
assert(*pos);
- (*pos)->evalInitConds();
-}
+ (*pos)->evalInitConds();
+ }
}
-void MilkdropPreset::evalCustomWavePerFrameEquations()
+void
+MilkdropPreset::evalCustomWavePerFrameEquations()
{
- for (PresetOutputs::cwave_container::iterator pos = customWaves.begin(); pos != customWaves.end(); ++pos)
+ for (PresetOutputs::cwave_container::iterator pos = customWaves.begin();
+ pos != customWaves.end();
+ ++pos)
{
-
std::map<std::string, InitCond*> & init_cond_tree = (*pos)->init_cond_tree;
- for (std::map<std::string, InitCond*>::iterator _pos = init_cond_tree.begin(); _pos != init_cond_tree.end(); ++_pos)
+
+ for (std::map<std::string, InitCond*>::iterator _pos = init_cond_tree.begin();
+ _pos != init_cond_tree.end();
+ ++_pos)
{
assert(_pos->second);
_pos->second->evaluate();
}
std::vector<PerFrameEqn*> & per_frame_eqn_tree = (*pos)->per_frame_eqn_tree;
- for (std::vector<PerFrameEqn*>::iterator _pos = per_frame_eqn_tree.begin(); _pos != per_frame_eqn_tree.end(); ++_pos)
+ for (std::vector<PerFrameEqn*>::iterator _pos = per_frame_eqn_tree.begin();
+ _pos != per_frame_eqn_tree.end();
+ ++_pos)
{
(*_pos)->evaluate();
}
}
-
}
-void MilkdropPreset::evalCustomShapePerFrameEquations()
+void
+MilkdropPreset::evalCustomShapePerFrameEquations()
{
- for (PresetOutputs::cshape_container::iterator pos = customShapes.begin(); pos != customShapes.end(); ++pos)
+ for (PresetOutputs::cshape_container::iterator pos = customShapes.begin();
+ pos != customShapes.end();
+ ++pos)
{
-
std::map<std::string, InitCond*> & init_cond_tree = (*pos)->init_cond_tree;
- for (std::map<std::string, InitCond*>::iterator _pos = init_cond_tree.begin(); _pos != init_cond_tree.end(); ++_pos)
+
+ for (std::map<std::string, InitCond*>::iterator _pos = init_cond_tree.begin();
+ _pos != init_cond_tree.end();
+ ++_pos)
{
assert(_pos->second);
_pos->second->evaluate();
}
std::vector<PerFrameEqn*> & per_frame_eqn_tree = (*pos)->per_frame_eqn_tree;
- for (std::vector<PerFrameEqn*>::iterator _pos = per_frame_eqn_tree.begin(); _pos != per_frame_eqn_tree.end(); ++_pos)
+ for (std::vector<PerFrameEqn*>::iterator _pos = per_frame_eqn_tree.begin();
+ _pos != per_frame_eqn_tree.end();
+ ++_pos)
{
(*_pos)->evaluate();
}
}
-
}
-void MilkdropPreset::evalPerFrameInitEquations()
+void
+MilkdropPreset::evalPerFrameInitEquations()
{
+ for (std::map<std::string, InitCond*>::iterator pos = per_frame_init_eqn_tree.begin();
+ pos != per_frame_init_eqn_tree.end();
+ ++pos)
+ {
+ assert(pos->second);
+ pos->second->evaluate();
+ }
+}
- for (std::map<std::string, InitCond*>::iterator pos = per_frame_init_eqn_tree.begin(); pos != per_frame_init_eqn_tree.end(); ++pos)
+void
+MilkdropPreset::evalPerFrameEquations()
+{
+ for (std::map<std::string, InitCond*>::iterator pos = init_cond_tree.begin();
+ pos != init_cond_tree.end();
+ ++pos)
{
assert(pos->second);
pos->second->evaluate();
}
-}
-
-void MilkdropPreset::evalPerFrameEquations()
-{
-
- for (std::map<std::string, InitCond*>::iterator pos = init_cond_tree.begin(); pos != init_cond_tree.end(); ++pos)
- {
- assert(pos->second);
- pos->second->evaluate();
- }
-
- for (std::vector<PerFrameEqn*>::iterator pos = per_frame_eqn_tree.begin(); pos != per_frame_eqn_tree.end(); ++pos)
+ for (std::vector<PerFrameEqn*>::iterator pos = per_frame_eqn_tree.begin();
+ pos != per_frame_eqn_tree.end();
+ ++pos)
{
(*pos)->evaluate();
}
-
}
-void MilkdropPreset::preloadInitialize() {
-
+void
+MilkdropPreset::preloadInitialize()
+{
/// @note commented this out because it should be unnecessary
// Clear equation trees
//init_cond_tree.clear();
@@ -246,12 +271,11 @@
//per_frame_eqn_tree.clear();
//per_pixel_eqn_tree.clear();
//per_frame_init_eqn_tree.clear();
-
-
}
-void MilkdropPreset::postloadInitialize() {
-
+void
+MilkdropPreset::postloadInitialize()
+{
/* It's kind of ugly to reset these values here. Should definitely be placed in the parser somewhere */
this->per_frame_eqn_count = 0;
this->per_frame_init_eqn_count = 0;
@@ -261,41 +285,42 @@
this->loadCustomShapeUnspecInitConds();
-/// @bug are you handling all the q variables conditions? in particular, the un-init case?
-//m_presetOutputs.q1 = 0;
-//m_presetOutputs.q2 = 0;
-//m_presetOutputs.q3 = 0;
-//m_presetOutputs.q4 = 0;
-//m_presetOutputs.q5 = 0;
-//m_presetOutputs.q6 = 0;
-//m_presetOutputs.q7 = 0;
-//m_presetOutputs.q8 = 0;
-
+ /// @bug are you handling all the q variables conditions? in particular, the un-init case?
+ //m_presetOutputs.q1 = 0;
+ //m_presetOutputs.q2 = 0;
+ //m_presetOutputs.q3 = 0;
+ //m_presetOutputs.q4 = 0;
+ //m_presetOutputs.q5 = 0;
+ //m_presetOutputs.q6 = 0;
+ //m_presetOutputs.q7 = 0;
+ //m_presetOutputs.q8 = 0;
}
-void MilkdropPreset::Render(const BeatDetect &music, const PipelineContext &context)
+void
+MilkdropPreset::Render(const BeatDetect &music, const PipelineContext &context)
{
- _presetInputs.update(music, context);
+ _presetInputs.update(music, context);
- evaluateFrame();
- pipeline().Render(music, context);
-
+ evaluateFrame();
+ pipeline().Render(music, context);
}
-void MilkdropPreset::initialize(const std::string & pathname)
+void
+MilkdropPreset::initialize(const std::string & pathname)
{
int retval;
preloadInitialize();
-if (MILKDROP_PRESET_DEBUG)
- std::cerr << "[Preset] loading file \"" << pathname << "\"..." << std::endl;
+ if (MILKDROP_PRESET_DEBUG)
+ std::cerr << "[Preset] loading file \"" << pathname << "\"..." << std::endl;
if ((retval = loadPresetFile(pathname)) < 0)
{
-if (MILKDROP_PRESET_DEBUG)
- std::cerr << "[Preset] failed to load file \"" <<
- pathname << "\"!" << std::endl;
+ if (MILKDROP_PRESET_DEBUG)
+ std::cerr << "[Preset] failed to load file \""
+ << pathname << "\"!"
+ << std::endl;
/// @bug how should we handle this problem? a well define exception?
throw retval;
@@ -304,7 +329,8 @@
postloadInitialize();
}
-void MilkdropPreset::initialize(std::istream & in)
+void
+MilkdropPreset::initialize(std::istream & in)
{
int retval;
@@ -313,8 +339,8 @@
if ((retval = readIn(in)) < 0)
{
- if (MILKDROP_PRESET_DEBUG)
- std::cerr << "[Preset] failed to load from stream " << std::endl;
+ if (MILKDROP_PRESET_DEBUG)
+ std::cerr << "[Preset] failed to load from stream " << std::endl;
/// @bug how should we handle this problem? a well define exception?
throw retval;
@@ -323,7 +349,9 @@
postloadInitialize();
}
-void MilkdropPreset::loadBuiltinParamsUnspecInitConds() {
+void
+MilkdropPreset::loadBuiltinParamsUnspecInitConds()
+{
InitCondUtils::LoadUnspecInitCond loadUnspecInitCond(this->init_cond_tree, this->per_frame_init_eqn_tree);
@@ -332,22 +360,24 @@
}
-void MilkdropPreset::loadCustomWaveUnspecInitConds()
+void
+MilkdropPreset::loadCustomWaveUnspecInitConds()
{
-
- for (PresetOutputs::cwave_container::iterator pos = customWaves.begin(); pos != customWaves.end(); ++pos)
+ for (PresetOutputs::cwave_container::iterator pos = customWaves.begin();
+ pos != customWaves.end();
+ ++pos)
{
assert(*pos);
(*pos)->loadUnspecInitConds();
}
-
}
-void MilkdropPreset::loadCustomShapeUnspecInitConds()
+void
+MilkdropPreset::loadCustomShapeUnspecInitConds()
{
-
for (PresetOutputs::cshape_container::iterator pos = customShapes.begin();
- pos != customShapes.end(); ++pos)
+ pos != customShapes.end();
+ ++pos)
{
assert(*pos);
(*pos)->loadUnspecInitConds();
@@ -355,9 +385,9 @@
}
-void MilkdropPreset::evaluateFrame()
+void
+MilkdropPreset::evaluateFrame()
{
-
// Evaluate all equation objects according to milkdrop flow diagram
evalPerFrameInitEquations();
@@ -382,110 +412,102 @@
/// @slow an extra O(N) per frame, could do this during eval
_presetOutputs.customWaves = PresetOutputs::cwave_container(customWaves);
_presetOutputs.customShapes = PresetOutputs::cshape_container(customShapes);
-
}
-void MilkdropPreset::initialize_PerPixelMeshes()
+void
+MilkdropPreset::initialize_PerPixelMeshes()
{
-
int x,y;
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.cx_mesh[x][y]=presetOutputs().cx;
- }}
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.cx_mesh[x][y]=presetOutputs().cx;
+ }
+ }
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.cy_mesh[x][y]=presetOutputs().cy;
+ }
+ }
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.sx_mesh[x][y]=presetOutputs().sx;
+ }
+ }
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.cy_mesh[x][y]=presetOutputs().cy;
- }}
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.sy_mesh[x][y]=presetOutputs().sy;
+ }
+ }
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.dx_mesh[x][y]=presetOutputs().dx;
+ }
+ }
+ //std::cout<<presetOutputs().cx<<","<<presetOutputs().cy<<" "<<presetOutputs().dx<<","<<presetOutputs().dy<<std::endl;
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.sx_mesh[x][y]=presetOutputs().sx;
- }}
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.dy_mesh[x][y]=presetOutputs().dy;
+ }
+ }
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.zoom_mesh[x][y]=presetOutputs().zoom;
+ }
+ }
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.zoomexp_mesh[x][y]=presetOutputs().zoomexp;
+ }
+ }
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.rot_mesh[x][y]=presetOutputs().rot;
+ }
+ }
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.sy_mesh[x][y]=presetOutputs().sy;
- }}
-
-
-
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.dx_mesh[x][y]=presetOutputs().dx;
- }}
-
-//std::cout<<presetOutputs().cx<<","<<presetOutputs().cy<<" "<<presetOutputs().dx<<","<<presetOutputs().dy<<std::endl;
-
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.dy_mesh[x][y]=presetOutputs().dy;
- }}
-
-
-
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.zoom_mesh[x][y]=presetOutputs().zoom;
- }}
-
-
-
-
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.zoomexp_mesh[x][y]=presetOutputs().zoomexp;
- }}
-
-
-
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.rot_mesh[x][y]=presetOutputs().rot;
- }}
-
-
- for (x=0;x<presetInputs().gx;x++){
- for(y=0;y<presetInputs().gy;y++){
- _presetOutputs.warp_mesh[x][y]=presetOutputs().warp;
- }}
-
-
-
+ for (x=0;x<presetInputs().gx;x++){
+ for(y=0;y<presetInputs().gy;y++){
+ _presetOutputs.warp_mesh[x][y]=presetOutputs().warp;
+ }
+ }
}
-// Evaluates all per-pixel equations
-void MilkdropPreset::evalPerPixelEqns()
-{
+// Evaluates all per-pixel equations
+void
+MilkdropPreset::evalPerPixelEqns()
+{
/* Evaluate all per pixel equations in the tree datastructure */
for (int mesh_x = 0; mesh_x < presetInputs().gx; mesh_x++)
- for (int mesh_y = 0; mesh_y < presetInputs().gy; mesh_y++)
- for (std::map<int, PerPixelEqn*>::iterator pos = per_pixel_eqn_tree.begin();
- pos != per_pixel_eqn_tree.end(); ++pos)
- pos->second->evaluate(mesh_x, mesh_y);
-
+ for (int mesh_y = 0; mesh_y < presetInputs().gy; mesh_y++)
+ for (std::map<int, PerPixelEqn*>::iterator pos = per_pixel_eqn_tree.begin();
+ pos != per_pixel_eqn_tree.end();
+ ++pos)
+ pos->second->evaluate(mesh_x, mesh_y);
}
-int MilkdropPreset::readIn(std::istream & fs) {
-
+int
+MilkdropPreset::readIn(std::istream & fs)
+{
line_mode_t line_mode;
+
presetOutputs().compositeShader.programSource.clear();
presetOutputs().warpShader.programSource.clear();
/* Parse any comments */
if (Parser::parse_top_comment(fs) < 0)
{
- if (MILKDROP_PRESET_DEBUG)
- std::cerr << "[Preset::readIn] no left bracket found..." << std::endl;
+ if (MILKDROP_PRESET_DEBUG)
+ std::cerr << "[Preset::readIn] no left bracket found..." << std::endl;
return PROJECTM_FAILURE;
}
@@ -512,35 +534,34 @@
}
}
-// std::cerr << "loadPresetFile: finished line parsing successfully" << std::endl;
+ // std::cerr << "loadPresetFile: finished line parsing successfully" << std::endl;
/* Now the preset has been loaded.
Evaluation calls can be made at appropiate
times in the frame loop */
-return PROJECTM_SUCCESS;
+ return PROJECTM_SUCCESS;
}
/* loadPresetFile: private function that loads a specific preset denoted
by the given pathname */
-int MilkdropPreset::loadPresetFile(const std::string & pathname)
+int
+MilkdropPreset::loadPresetFile(const std::string & pathname)
{
-
-
/* Open the file corresponding to pathname */
std::ifstream fs(pathname.c_str());
+
if (!fs || fs.eof()) {
if (MILKDROP_PRESET_DEBUG)
- std::cerr << "loadPresetFile: loading of file \"" << pathname << "\" failed!\n";
+ std::cerr << "loadPresetFile: loading of file \"" << pathname << "\" failed!\n";
return PROJECTM_ERROR;
}
- return readIn(fs);
-
+ return readIn(fs);
}
-const std::string & MilkdropPreset::name() const {
-
- return name().empty() ? filename() : name();
+const std::string &
+MilkdropPreset::name() const
+{
+ return name().empty() ? filename() : name();
}
-
diff --git a/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.hpp b/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.hpp
index 89fc7f8..ddfbd52 100644
--- a/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.hpp
@@ -1,4 +1,3 @@
-
/**
* projectM -- Milkdrop-esque visualisation SDK
* Copyright (C)2003-2007 projectM Team
@@ -26,7 +25,6 @@
*
* $Log$
*/
-
#ifndef _MilkdropPreset_HPP
#define _MilkdropPreset_HPP
@@ -47,6 +45,7 @@
#include "InitCond.hpp"
#include "Preset.hpp"
+
class CustomWave;
class CustomShape;
class InitCond;
@@ -109,18 +108,16 @@
/// \returns A MilkdropPreset output instance with values computed from most recent evaluateFrame()
PresetOutputs & presetOutputs() const
{
-
return _presetOutputs;
}
const PresetInputs & presetInputs() const
{
-
return _presetInputs;
}
-// @bug encapsulate
+ // @bug encapsulate
PresetOutputs::cwave_container customWaves;
PresetOutputs::cshape_container customShapes;
@@ -134,13 +131,13 @@
std::map<std::string,Param*> user_param_tree; /* user parameter splay tree */
- PresetOutputs & pipeline() { return _presetOutputs; }
+ PresetOutputs & pipeline() { return _presetOutputs; }
void Render(const BeatDetect &music, const PipelineContext &context);
const std::string & name() const;
- const std::string & filename() const { return _filename; }
-private:
- std::string _filename;
+ const std::string & filename() const { return _filename; }
+ private:
+ std::string _filename;
PresetInputs _presetInputs;
/// Evaluates the MilkdropPreset for a frame given the current values of MilkdropPreset inputs / outputs
/// All calculated values are stored in the associated MilkdropPreset outputs instance
@@ -173,53 +170,52 @@
void preloadInitialize();
void postloadInitialize();
-
+
PresetOutputs & _presetOutputs;
-template <class CustomObject>
-void transfer_q_variables(std::vector<CustomObject*> & customObjects);
+ template <class CustomObject>
+ void transfer_q_variables(std::vector<CustomObject*> & customObjects);
};
-template <class CustomObject>
-void MilkdropPreset::transfer_q_variables(std::vector<CustomObject*> & customObjects)
+template <class CustomObject> void
+MilkdropPreset::transfer_q_variables(std::vector<CustomObject*> & customObjects)
{
- CustomObject * custom_object;
+ CustomObject * custom_object;
- for (typename std::vector<CustomObject*>::iterator pos = customObjects.begin(); pos != customObjects.end();++pos) {
-
- custom_object = *pos;
- for (unsigned int i = 0; i < NUM_Q_VARIABLES; i++)
- custom_object->q[i] = _presetOutputs.q[i];
- }
-
-
+ for (typename std::vector<CustomObject*>::iterator pos = customObjects.begin();
+ pos != customObjects.end();
+ ++pos)
+ {
+ custom_object = *pos;
+ for (unsigned int i = 0; i < NUM_Q_VARIABLES; i++)
+ custom_object->q[i] = _presetOutputs.q[i];
+ }
}
-template <class CustomObject>
-CustomObject * MilkdropPreset::find_custom_object(int id, std::vector<CustomObject*> & customObjects)
+template <class CustomObject> CustomObject *
+MilkdropPreset::find_custom_object(int id, std::vector<CustomObject*> & customObjects)
{
-
CustomObject * custom_object = NULL;
-
- for (typename std::vector<CustomObject*>::iterator pos = customObjects.begin(); pos != customObjects.end();++pos) {
- if ((*pos)->id == id) {
- custom_object = *pos;
- break;
- }
+ for (typename std::vector<CustomObject*>::iterator pos = customObjects.begin();
+ pos != customObjects.end();
+ ++pos)
+ {
+ if ((*pos)->id == id) {
+ custom_object = *pos;
+ break;
+ }
}
if (custom_object == NULL)
{
-
if ((custom_object = new CustomObject(id)) == NULL)
{
return NULL;
}
- customObjects.push_back(custom_object);
-
+ customObjects.push_back(custom_object);
}
assert(custom_object);
@@ -227,5 +223,4 @@
}
-
#endif /** !_MilkdropPreset_HPP */
diff --git a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp
index 0418a7c..3bcd620 100644
--- a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.cpp
@@ -17,211 +17,217 @@
#include "IdlePreset.hpp"
#include "PresetFrameIO.hpp"
-MilkdropPresetFactory::MilkdropPresetFactory(int gx, int gy): _usePresetOutputs(false)
+
+MilkdropPresetFactory::MilkdropPresetFactory(int gx, int gy)
+ : _usePresetOutputs(false)
{
- /* Initializes the builtin function database */
- BuiltinFuncs::init_builtin_func_db();
+ /* Initializes the builtin function database */
+ BuiltinFuncs::init_builtin_func_db();
- /* Initializes all infix operators */
- Eval::init_infix_ops();
+ /* Initializes all infix operators */
+ Eval::init_infix_ops();
- _presetOutputs = createPresetOutputs(gx,gy);
- _presetOutputs2 = createPresetOutputs(gx, gy);
+ _presetOutputs = createPresetOutputs(gx,gy);
+ _presetOutputs2 = createPresetOutputs(gx, gy);
}
-MilkdropPresetFactory::~MilkdropPresetFactory() {
-
- std::cerr << "[~MilkdropPresetFactory] destroy infix ops" << std::endl;
- Eval::destroy_infix_ops();
- std::cerr << "[~MilkdropPresetFactory] destroy builtin func" << std::endl;
- BuiltinFuncs::destroy_builtin_func_db();
- std::cerr << "[~MilkdropPresetFactory] delete preset out puts" << std::endl;
- delete(_presetOutputs);
- delete(_presetOutputs2);
- std::cerr << "[~MilkdropPresetFactory] done" << std::endl;
-
+MilkdropPresetFactory::~MilkdropPresetFactory()
+{
+ std::cerr << "[~MilkdropPresetFactory] destroy infix ops" << std::endl;
+ Eval::destroy_infix_ops();
+ std::cerr << "[~MilkdropPresetFactory] destroy builtin func" << std::endl;
+ BuiltinFuncs::destroy_builtin_func_db();
+ std::cerr << "[~MilkdropPresetFactory] delete preset out puts" << std::endl;
+ delete(_presetOutputs);
+ delete(_presetOutputs2);
+ std::cerr << "[~MilkdropPresetFactory] done" << std::endl;
}
/* Reinitializes the engine variables to a default (conservative and sane) value */
-void resetPresetOutputs(PresetOutputs * presetOutputs)
+void
+resetPresetOutputs(PresetOutputs * presetOutputs)
{
+ presetOutputs->zoom = 1.0;
+ presetOutputs->zoomexp = 1.0;
+ presetOutputs->rot = 0.0;
+ presetOutputs->warp = 0.0;
- presetOutputs->zoom=1.0;
- presetOutputs->zoomexp = 1.0;
- presetOutputs->rot= 0.0;
- presetOutputs->warp= 0.0;
+ presetOutputs->sx = 1.0;
+ presetOutputs->sy = 1.0;
+ presetOutputs->dx = 0.0;
+ presetOutputs->dy = 0.0;
+ presetOutputs->cx = 0.5;
+ presetOutputs->cy = 0.5;
- presetOutputs->sx= 1.0;
- presetOutputs->sy= 1.0;
- presetOutputs->dx= 0.0;
- presetOutputs->dy= 0.0;
- presetOutputs->cx= 0.5;
- presetOutputs->cy= 0.5;
+ presetOutputs->screenDecay = .98;
- presetOutputs->screenDecay=.98;
+ presetOutputs->wave.r = 1.0;
+ presetOutputs->wave.g = 0.2;
+ presetOutputs->wave.b = 0.0;
+ presetOutputs->wave.x = 0.5;
+ presetOutputs->wave.y = 0.5;
+ presetOutputs->wave.mystery = 0.0;
- presetOutputs->wave.r= 1.0;
- presetOutputs->wave.g= 0.2;
- presetOutputs->wave.b= 0.0;
- presetOutputs->wave.x= 0.5;
- presetOutputs->wave.y= 0.5;
- presetOutputs->wave.mystery= 0.0;
+ presetOutputs->border.outer_size = 0.0;
+ presetOutputs->border.outer_r = 0.0;
+ presetOutputs->border.outer_g = 0.0;
+ presetOutputs->border.outer_b = 0.0;
+ presetOutputs->border.outer_a = 0.0;
- presetOutputs->border.outer_size= 0.0;
- presetOutputs->border.outer_r= 0.0;
- presetOutputs->border.outer_g= 0.0;
- presetOutputs->border.outer_b= 0.0;
- presetOutputs->border.outer_a= 0.0;
+ presetOutputs->border.inner_size = 0.0;
+ presetOutputs->border.inner_r = 0.0;
+ presetOutputs->border.inner_g = 0.0;
+ presetOutputs->border.inner_b = 0.0;
+ presetOutputs->border.inner_a = 0.0;
- presetOutputs->border.inner_size = 0.0;
- presetOutputs->border.inner_r = 0.0;
- presetOutputs->border.inner_g = 0.0;
- presetOutputs->border.inner_b = 0.0;
- presetOutputs->border.inner_a = 0.0;
-
- presetOutputs->mv.a = 0.0;
- presetOutputs->mv.r = 0.0;
- presetOutputs->mv.g = 0.0;
- presetOutputs->mv.b = 0.0;
- presetOutputs->mv.length = 1.0;
- presetOutputs->mv.x_num = 16.0;
- presetOutputs->mv.y_num = 12.0;
- presetOutputs->mv.x_offset = 0.02;
- presetOutputs->mv.y_offset = 0.02;
+ presetOutputs->mv.a = 0.0;
+ presetOutputs->mv.r = 0.0;
+ presetOutputs->mv.g = 0.0;
+ presetOutputs->mv.b = 0.0;
+ presetOutputs->mv.length = 1.0;
+ presetOutputs->mv.x_num = 16.0;
+ presetOutputs->mv.y_num = 12.0;
+ presetOutputs->mv.x_offset = 0.02;
+ presetOutputs->mv.y_offset = 0.02;
- /* PER_FRAME CONSTANTS END */
- presetOutputs->fRating = 0;
- presetOutputs->fGammaAdj = 1.0;
- presetOutputs->videoEcho.zoom = 1.0;
- presetOutputs->videoEcho.a = 0;
- presetOutputs->videoEcho.orientation = Normal;
+ /* PER_FRAME CONSTANTS END */
+ presetOutputs->fRating = 0;
+ presetOutputs->fGammaAdj = 1.0;
+ presetOutputs->videoEcho.zoom = 1.0;
+ presetOutputs->videoEcho.a = 0;
+ presetOutputs->videoEcho.orientation = Normal;
- presetOutputs->wave.additive = false;
- presetOutputs->wave.dots = false;
- presetOutputs->wave.thick = false;
- presetOutputs->wave.modulateAlphaByVolume = 0;
- presetOutputs->wave.maximizeColors = 0;
- presetOutputs->textureWrap = 0;
- presetOutputs->bDarkenCenter = 0;
- presetOutputs->bRedBlueStereo = 0;
- presetOutputs->bBrighten = 0;
- presetOutputs->bDarken = 0;
- presetOutputs->bSolarize = 0;
- presetOutputs->bInvert = 0;
- presetOutputs->bMotionVectorsOn = 1;
+ presetOutputs->wave.additive = false;
+ presetOutputs->wave.dots = false;
+ presetOutputs->wave.thick = false;
+ presetOutputs->wave.modulateAlphaByVolume = 0;
+ presetOutputs->wave.maximizeColors = 0;
+ presetOutputs->textureWrap = 0;
+ presetOutputs->bDarkenCenter = 0;
+ presetOutputs->bRedBlueStereo = 0;
+ presetOutputs->bBrighten = 0;
+ presetOutputs->bDarken = 0;
+ presetOutputs->bSolarize = 0;
+ presetOutputs->bInvert = 0;
+ presetOutputs->bMotionVectorsOn = 1;
- presetOutputs->wave.a =1.0;
- presetOutputs->wave.scale = 1.0;
- presetOutputs->wave.smoothing = 0;
- presetOutputs->wave.mystery = 0;
- presetOutputs->wave.modOpacityEnd = 0;
- presetOutputs->wave.modOpacityStart = 0;
- presetOutputs->fWarpAnimSpeed = 0;
- presetOutputs->fWarpScale = 0;
- presetOutputs->fShader = 0;
+ presetOutputs->wave.a =1.0;
+ presetOutputs->wave.scale = 1.0;
+ presetOutputs->wave.smoothing = 0;
+ presetOutputs->wave.mystery = 0;
+ presetOutputs->wave.modOpacityEnd = 0;
+ presetOutputs->wave.modOpacityStart = 0;
+ presetOutputs->fWarpAnimSpeed = 0;
+ presetOutputs->fWarpScale = 0;
+ presetOutputs->fShader = 0;
- /* PER_PIXEL CONSTANT END */
- /* Q VARIABLES START */
+ /* PER_PIXEL CONSTANT END */
+ /* Q VARIABLES START */
- for (int i = 0;i< 32;i++)
- presetOutputs->q[i] = 0;
+ for (int i = 0;i< 32;i++)
+ presetOutputs->q[i] = 0;
-// for ( std::vector<CustomWave*>::iterator pos = presetOutputs->customWaves.begin();
-// pos != presetOutputs->customWaves.end(); ++pos )
-// if ( *pos != 0 ) delete ( *pos );
-
-// for ( std::vector<CustomShape*>::iterator pos = presetOutputs->customShapes.begin();
-// pos != presetOutputs->customShapes.end(); ++pos )
-// if ( *pos != 0 ) delete ( *pos );
-
- presetOutputs->customWaves.clear();
- presetOutputs->customShapes.clear();
+ // for ( std::vector<CustomWave*>::iterator pos = presetOutputs->customWaves.begin();
+ // pos != presetOutputs->customWaves.end(); ++pos )
+ // if ( *pos != 0 ) delete ( *pos );
- /* Q VARIABLES END */
+ // for ( std::vector<CustomShape*>::iterator pos = presetOutputs->customShapes.begin();
+ // pos != presetOutputs->customShapes.end(); ++pos )
+ // if ( *pos != 0 ) delete ( *pos );
+ presetOutputs->customWaves.clear();
+ presetOutputs->customShapes.clear();
+
+ /* Q VARIABLES END */
}
/* Reinitializes the engine variables to a default (conservative and sane) value */
-void MilkdropPresetFactory::reset()
+void
+MilkdropPresetFactory::reset()
{
-
- resetPresetOutputs(_presetOutputs);
- resetPresetOutputs(_presetOutputs2);
+ resetPresetOutputs(_presetOutputs);
+ resetPresetOutputs(_presetOutputs2);
}
-PresetOutputs* MilkdropPresetFactory::createPresetOutputs(int gx, int gy)
+PresetOutputs*
+MilkdropPresetFactory::createPresetOutputs(int gx, int gy)
{
+ PresetOutputs *presetOutputs = new PresetOutputs();
- PresetOutputs *presetOutputs = new PresetOutputs();
+ presetOutputs->Initialize(gx,gy);
- presetOutputs->Initialize(gx,gy);
+ /* PER FRAME CONSTANTS BEGIN */
+ presetOutputs->zoom = 1.0;
+ presetOutputs->zoomexp = 1.0;
+ presetOutputs->rot = 0.0;
+ presetOutputs->warp = 0.0;
- /* PER FRAME CONSTANTS BEGIN */
- presetOutputs->zoom=1.0;
- presetOutputs->zoomexp = 1.0;
- presetOutputs->rot= 0.0;
- presetOutputs->warp= 0.0;
+ presetOutputs->sx = 1.0;
+ presetOutputs->sy = 1.0;
+ presetOutputs->dx = 0.0;
+ presetOutputs->dy = 0.0;
+ presetOutputs->cx = 0.5;
+ presetOutputs->cy = 0.5;
- presetOutputs->sx= 1.0;
- presetOutputs->sy= 1.0;
- presetOutputs->dx= 0.0;
- presetOutputs->dy= 0.0;
- presetOutputs->cx= 0.5;
- presetOutputs->cy= 0.5;
-
- presetOutputs->screenDecay=.98;
+ presetOutputs->screenDecay =.98;
-//_presetInputs.meshx = 0;
-//_presetInputs.meshy = 0;
+ //_presetInputs.meshx = 0;
+ //_presetInputs.meshy = 0;
- /* PER_FRAME CONSTANTS END */
- presetOutputs->fRating = 0;
- presetOutputs->fGammaAdj = 1.0;
- presetOutputs->videoEcho.zoom = 1.0;
- presetOutputs->videoEcho.a = 0;
- presetOutputs->videoEcho.orientation = Normal;
+ /* PER_FRAME CONSTANTS END */
+ presetOutputs->fRating = 0;
+ presetOutputs->fGammaAdj = 1.0;
+ presetOutputs->videoEcho.zoom = 1.0;
+ presetOutputs->videoEcho.a = 0;
+ presetOutputs->videoEcho.orientation = Normal;
- presetOutputs->textureWrap = 0;
- presetOutputs->bDarkenCenter = 0;
- presetOutputs->bRedBlueStereo = 0;
- presetOutputs->bBrighten = 0;
- presetOutputs->bDarken = 0;
- presetOutputs->bSolarize = 0;
- presetOutputs->bInvert = 0;
- presetOutputs->bMotionVectorsOn = 1;
+ presetOutputs->textureWrap = 0;
+ presetOutputs->bDarkenCenter = 0;
+ presetOutputs->bRedBlueStereo = 0;
+ presetOutputs->bBrighten = 0;
+ presetOutputs->bDarken = 0;
+ presetOutputs->bSolarize = 0;
+ presetOutputs->bInvert = 0;
+ presetOutputs->bMotionVectorsOn = 1;
- presetOutputs->fWarpAnimSpeed = 0;
- presetOutputs->fWarpScale = 0;
- presetOutputs->fShader = 0;
+ presetOutputs->fWarpAnimSpeed = 0;
+ presetOutputs->fWarpScale = 0;
+ presetOutputs->fShader = 0;
- /* PER_PIXEL CONSTANTS BEGIN */
+ /* PER_PIXEL CONSTANTS BEGIN */
- /* PER_PIXEL CONSTANT END */
+ /* PER_PIXEL CONSTANT END */
- /* Q AND T VARIABLES START */
+ /* Q AND T VARIABLES START */
- for (int i = 0;i<NUM_Q_VARIABLES;i++)
- presetOutputs->q[i] = 0;
-
- /* Q AND T VARIABLES END */
- return presetOutputs;
+ for (int i = 0; i < NUM_Q_VARIABLES; i++)
+ presetOutputs->q[i] = 0;
+
+ /* Q AND T VARIABLES END */
+ return presetOutputs;
}
-std::auto_ptr<Preset> MilkdropPresetFactory::allocate(const std::string & url, const std::string & name, const std::string & author) {
+std::auto_ptr<Preset>
+MilkdropPresetFactory::allocate(
+const std::string & url,
+const std::string & name,
+const std::string & author
+)
+{
+ PresetOutputs *presetOutputs = _usePresetOutputs ? _presetOutputs : _presetOutputs2;
- PresetOutputs *presetOutputs = _usePresetOutputs ? _presetOutputs : _presetOutputs2;
+ _usePresetOutputs = !_usePresetOutputs;
+ resetPresetOutputs(presetOutputs);
- _usePresetOutputs = !_usePresetOutputs;
- resetPresetOutputs(presetOutputs);
+ std::string path;
- std::string path;
- if (PresetFactory::protocol(url, path) == PresetFactory::IDLE_PRESET_PROTOCOL) {
- return IdlePresets::allocate(path, *presetOutputs);
- } else
- return std::auto_ptr<Preset>(new MilkdropPreset(url, name, *presetOutputs));
+ if (PresetFactory::protocol(url, path) == PresetFactory::IDLE_PRESET_PROTOCOL) {
+ return IdlePresets::allocate(path, *presetOutputs);
+ } else
+ return std::auto_ptr<Preset>(new MilkdropPreset(url, name, *presetOutputs));
}
diff --git a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp
index 2a5a46a..4dff790 100644
--- a/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPresetFactory.hpp
@@ -9,35 +9,37 @@
// Copyright: See COPYING file that comes with this distribution
//
//
-
#ifndef __MILKDROP_PRESET_FACTORY_HPP
#define __MILKDROP_PRESET_FACTORY_HPP
#include <memory>
#include "../PresetFactory.hpp"
+
+
class DLLEXPORT PresetOutputs;
class DLLEXPORT PresetInputs;
+
class MilkdropPresetFactory : public PresetFactory {
public:
- MilkdropPresetFactory(int gx, int gy);
+ MilkdropPresetFactory(int gx, int gy);
- virtual ~MilkdropPresetFactory();
+ virtual ~MilkdropPresetFactory();
- std::auto_ptr<Preset> allocate(const std::string & url, const std::string & name = std::string(),
- const std::string & author = std::string());
+ std::auto_ptr<Preset> allocate(const std::string & url, const std::string & name = std::string(),
+ const std::string & author = std::string());
- std::string supportedExtensions() const { return "milk prjm"; }
+ std::string supportedExtensions() const { return "milk prjm"; }
private:
- static PresetOutputs* createPresetOutputs(int gx, int gy);
- void reset();
- PresetOutputs * _presetOutputs;
- PresetOutputs * _presetOutputs2;
- bool _usePresetOutputs;
- //PresetInputs _presetInputs;
+ static PresetOutputs* createPresetOutputs(int gx, int gy);
+ void reset();
+ PresetOutputs * _presetOutputs;
+ PresetOutputs * _presetOutputs2;
+ bool _usePresetOutputs;
+ //PresetInputs _presetInputs;
};
#endif
diff --git a/src/libprojectM/MilkdropPresetFactory/Param.cpp b/src/libprojectM/MilkdropPresetFactory/Param.cpp
index ca21e8f..ebc854f 100644
--- a/src/libprojectM/MilkdropPresetFactory/Param.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/Param.cpp
@@ -39,161 +39,181 @@
#include <iostream>
#include <cassert>
+
/** Constructor */
Param::Param( std::string _name, short int _type, short int _flags, void * _engine_val, void * _matrix,
- CValue _default_init_val, CValue _upper_bound, CValue _lower_bound):
- name(_name),
- type(_type),
- flags (_flags),
- matrix_flag (0),
- engine_val(_engine_val),
- matrix (_matrix),
- default_init_val (_default_init_val),
- upper_bound (_upper_bound),
- lower_bound (_lower_bound)
- {
+ CValue _default_init_val, CValue _upper_bound, CValue _lower_bound)
+ : name(_name),
+ type(_type),
+ flags (_flags),
+ matrix_flag (0),
+ engine_val(_engine_val),
+ matrix (_matrix),
+ default_init_val (_default_init_val),
+ upper_bound (_upper_bound),
+ lower_bound (_lower_bound)
+{
}
/* Creates a user defined parameter */
-Param::Param(std::string _name) :
- name(_name),
- type(P_TYPE_DOUBLE),
- flags(P_FLAG_USERDEF),
- matrix_flag(0),
- matrix(0)
- {
+Param::Param(std::string _name)
+ : name(_name),
+ type(P_TYPE_DOUBLE),
+ flags(P_FLAG_USERDEF),
+ matrix_flag(0),
+ matrix(0)
+{
+ engine_val = new float();
- engine_val = new float();
+ default_init_val.float_val = DEFAULT_DOUBLE_IV;
+ upper_bound.float_val = DEFAULT_DOUBLE_UB;
+ lower_bound.float_val = DEFAULT_DOUBLE_LB;
- default_init_val.float_val = DEFAULT_DOUBLE_IV;
- upper_bound.float_val = DEFAULT_DOUBLE_UB;
- lower_bound.float_val = DEFAULT_DOUBLE_LB;
-
- /// @note may have fixed a recent bug. testing
- *((float*)engine_val) = default_init_val.float_val;
-
-
+ /// @note may have fixed a recent bug. testing
+ *((float*)engine_val) = default_init_val.float_val;
}
/* Free's a parameter type */
-Param::~Param() {
+Param::~Param()
+{
+ // I hate this, but will let it be for now
+ if (flags & P_FLAG_USERDEF) {
+ delete((double*)engine_val);
+ }
- // I hate this, but will let it be for now
- if (flags & P_FLAG_USERDEF) {
- delete((double*)engine_val);
- }
-
- if (PARAM_DEBUG) printf("~Param: freeing \"%s\".\n", name.c_str());
+ if (PARAM_DEBUG) printf("~Param: freeing \"%s\".\n", name.c_str());
}
/* Returns nonzero if the string is valid parameter name */
-bool Param::is_valid_param_string( const char * string ) {
+bool
+Param::is_valid_param_string( const char * string )
+{
- if (string == NULL)
- return false;
+ if (string == NULL)
+ return false;
- /* This ensures the first character is non numeric */
- if ( ((*string) >= 48) && ((*string) <= 57))
- return false;
+ /* This ensures the first character is non numeric */
+ if ( ((*string) >= 48) && ((*string) <= 57))
+ return false;
- /* These probably should never happen */
- if (*string == '.')
- return false;
+ /* These probably should never happen */
+ if (*string == '.')
+ return false;
- if (*string == '+')
- return false;
+ if (*string == '+')
+ return false;
- if (*string == '-')
- return false;
+ if (*string == '-')
+ return false;
- /* Could also add checks for other symbols. May do later */
+ /* Could also add checks for other symbols. May do later */
- return true;
-
+ return true;
}
/* Loads a float parameter into the builtin database */
-Param * Param::new_param_float(const char * name, short int flags, void * engine_val, void * matrix,
- float upper_bound, float lower_bound, float init_val) {
+Param *
+Param::new_param_float (
+const char * name,
+short int flags,
+void * engine_val,
+void * matrix,
+float upper_bound,
+float lower_bound,
+float init_val
+)
+{
+ Param * param;
+ CValue iv, ub, lb;
+ assert(engine_val);
- Param * param;
- CValue iv, ub, lb;
- assert(engine_val);
+ iv.float_val = init_val;
+ ub.float_val = upper_bound;
+ lb.float_val = lower_bound;
- iv.float_val = init_val;
- ub.float_val = upper_bound;
- lb.float_val = lower_bound;
-
- if ((param = new Param(name, P_TYPE_DOUBLE, flags, engine_val, matrix,iv, ub, lb)) == NULL)
- return NULL;
+ if ((param = new Param(name, P_TYPE_DOUBLE, flags, engine_val, matrix,iv, ub, lb)) == NULL)
+ return NULL;
- /* Finished, return success */
- return param;
+ /* Finished, return success */
+ return param;
}
/* Creates a new parameter of type int */
-Param * Param::new_param_int(const char * name, short int flags, void * engine_val,
- int upper_bound, int lower_bound, int init_val) {
+Param *
+Param::new_param_int (
+const char * name,
+short int flags,
+void * engine_val,
+int upper_bound,
+int lower_bound,
+int init_val
+)
+{
+ Param * param;
+ CValue iv, ub, lb;
+ assert(engine_val);
- Param * param;
- CValue iv, ub, lb;
- assert(engine_val);
+ iv.int_val = init_val;
+ ub.int_val = upper_bound;
+ lb.int_val = lower_bound;
- iv.int_val = init_val;
- ub.int_val = upper_bound;
- lb.int_val = lower_bound;
-
- if ((param = new Param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb)) == NULL)
- return NULL;
+ if ((param = new Param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb)) == NULL)
+ return NULL;
- /* Finished, return success */
- return param;
+ /* Finished, return success */
+ return param;
}
/* Creates a new parameter of type bool */
-Param * Param::new_param_bool(const char * name, short int flags, void * engine_val,
- bool upper_bound, bool lower_bound, bool init_val) {
+Param *
+Param::new_param_bool (
+const char * name,
+short int flags,
+void * engine_val,
+bool upper_bound,
+bool lower_bound,
+bool init_val
+)
+{
+ Param * param;
+ CValue iv, ub, lb;
+ assert(engine_val);
- Param * param;
- CValue iv, ub, lb;
- assert(engine_val);
+ iv.bool_val = init_val;
+ ub.bool_val = upper_bound;
+ lb.bool_val = lower_bound;
- iv.bool_val = init_val;
- ub.bool_val = upper_bound;
- lb.bool_val = lower_bound;
-
- if ((param = new Param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb)) == NULL)
- return NULL;
+ if ((param = new Param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb)) == NULL)
+ return NULL;
- /* Finished, return success */
- return param;
+ /* Finished, return success */
+ return param;
}
/* Creates a new parameter of type string */
-Param * Param::new_param_string(const char * name, short int flags, void * engine_val) {
+Param *
+Param::new_param_string (const char * name, short int flags, void * engine_val)
+{
+ Param * param;
+ CValue iv, ub, lb;
+ assert(engine_val);
- Param * param;
- CValue iv, ub, lb;
- assert(engine_val);
+ iv.bool_val = 0;
+ ub.bool_val = 0;
+ lb.bool_val = 0;
- iv.bool_val = 0;
- ub.bool_val = 0;
- lb.bool_val = 0;
-
- if ((param = new Param(name, P_TYPE_STRING, flags, engine_val, NULL, iv, ub, lb)) == NULL)
- return NULL;
+ if ((param = new Param(name, P_TYPE_STRING, flags, engine_val, NULL, iv, ub, lb)) == NULL)
+ return NULL;
- /* Finished, return success */
- return param;
+ /* Finished, return success */
+ return param;
}
-
-
diff --git a/src/libprojectM/MilkdropPresetFactory/Param.hpp b/src/libprojectM/MilkdropPresetFactory/Param.hpp
index 1f6bcf2..c422819 100644
--- a/src/libprojectM/MilkdropPresetFactory/Param.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/Param.hpp
@@ -25,7 +25,6 @@
*
* $Log$
*/
-
#ifndef _PARAM_H
#define _PARAM_H
@@ -54,6 +53,8 @@
#include "Common.hpp"
#include <cmath>
#include <string>
+
+
class InitCond;
class Param;
class Preset;
@@ -62,90 +63,88 @@
/* Parameter Type */
class Param {
public:
- std::string name; /* name of the parameter, not necessary but useful neverthless */
- short int type; /* parameter number type (int, bool, or float) */
- short int flags; /* read, write, user defined, etc */
- short int matrix_flag; /* for optimization purposes */
- void * engine_val; /* pointer to the engine variable */
- void * matrix; /* per pixel / per point matrix for this variable */
- CValue default_init_val; /* a default initial condition value */
- CValue upper_bound; /* this parameter's upper bound */
- CValue lower_bound; /* this parameter's lower bound */
+ std::string name; /* name of the parameter, not necessary but useful neverthless */
+ short int type; /* parameter number type (int, bool, or float) */
+ short int flags; /* read, write, user defined, etc */
+ short int matrix_flag; /* for optimization purposes */
+ void * engine_val; /* pointer to the engine variable */
+ void * matrix; /* per pixel / per point matrix for this variable */
+ CValue default_init_val; /* a default initial condition value */
+ CValue upper_bound; /* this parameter's upper bound */
+ CValue lower_bound; /* this parameter's lower bound */
- /// Create a new parameter
- Param(std::string name, short int type, short int flags,
- void * eqn_val, void *matrix,
- CValue default_init_val, CValue upper_bound,
- CValue lower_bound);
+ /// Create a new parameter
+ Param (std::string name, short int type, short int flags,
+ void * eqn_val, void *matrix,
+ CValue default_init_val, CValue upper_bound,
+ CValue lower_bound);
- ~Param();
+ ~Param();
- /// Create a user defined floating point parameter
- Param( std::string name );
+ /// Create a user defined floating point parameter
+ Param( std::string name );
- static bool is_valid_param_string( const char *string );
- void set_param( float val );
+ static bool is_valid_param_string( const char *string );
+ void set_param( float val );
- static Param *new_param_float( const char *name, short int flags, void *engine_val,
- void *matrix, float upper_bound,
- float lower_bound,
- float init_val );
- static Param *new_param_double(const char *name, short int flags, void *engine_val,
- void *matrix, double upper_bound,
- double lower_bound,
- double init_val );
- static Param * new_param_int(const char * name, short int flags, void * engine_val,
- int upper_bound, int lower_bound, int init_val );
- static Param * new_param_bool(const char * name, short int flags, void * engine_val,
- bool upper_bound, bool lower_bound, bool init_val );
- static Param * new_param_string(const char * name, short int flags, void * engine_val);
-
+ static Param *new_param_float( const char *name, short int flags, void *engine_val,
+ void *matrix, float upper_bound,
+ float lower_bound,
+ float init_val );
+ static Param *new_param_double(const char *name, short int flags, void *engine_val,
+ void *matrix, double upper_bound,
+ double lower_bound,
+ double init_val );
+ static Param * new_param_int(const char * name, short int flags, void * engine_val,
+ int upper_bound, int lower_bound, int init_val );
+ static Param * new_param_bool(const char * name, short int flags, void * engine_val,
+ bool upper_bound, bool lower_bound, bool init_val );
+ static Param * new_param_string(const char * name, short int flags, void * engine_val);
};
/* Sets the parameter engine value to value val.
- clipping occurs if necessary */
-inline void Param::set_param( float val) {
+ clipping occurs if necessary */
+inline void
+Param::set_param( float val)
+{
+ switch (type) {
+ case P_TYPE_BOOL:
+ if (val < 0)
+ *((bool*)engine_val) = false;
+ else if (val > 0)
+ *((bool*)engine_val) = true;
+ else
+ *((bool*)engine_val) = false;
+ break;
- switch (type) {
+ case P_TYPE_INT:
+ /* Make sure value is an integer */
+ val = floor(val);
+ if (val < lower_bound.int_val)
+ *((int*)engine_val) = lower_bound.int_val;
+ else if (val > upper_bound.int_val)
+ *((int*)engine_val) = upper_bound.int_val;
+ else
+ *((int*)engine_val) = (int)val;
+ break;
- case P_TYPE_BOOL:
- if (val < 0)
- *((bool*)engine_val) = false;
- else if (val > 0)
- *((bool*)engine_val) = true;
- else
- *((bool*)engine_val) = false;
- break;
- case P_TYPE_INT:
- /* Make sure value is an integer */
- val = floor(val);
- if (val < lower_bound.int_val)
- *((int*)engine_val) = lower_bound.int_val;
- else if (val > upper_bound.int_val)
- *((int*)engine_val) = upper_bound.int_val;
- else
- *((int*)engine_val) = (int)val;
- break;
- case P_TYPE_DOUBLE:
- /* Make sure value is an integer */
+ case P_TYPE_DOUBLE:
+ /* Make sure value is an integer */
+ if (val < lower_bound.float_val)
+ *((float*)engine_val) = lower_bound.float_val;
+ else if (val > upper_bound.float_val)
+ *((float*)engine_val) = upper_bound.float_val;
+ else
+ *((float*)engine_val) = val;
+ break;
+ default:
+ //abort();
+ break;
+ }
- if (val < lower_bound.float_val)
- *((float*)engine_val) = lower_bound.float_val;
- else if (val > upper_bound.float_val)
- *((float*)engine_val) = upper_bound.float_val;
- else
- *((float*)engine_val) = val;
- break;
- default:
- //abort();
- break;
-
- }
-
- return;
+ return;
}
#endif /** !_PARAM_TYPES_H */
-
diff --git a/src/libprojectM/MilkdropPresetFactory/ParamUtils.hpp b/src/libprojectM/MilkdropPresetFactory/ParamUtils.hpp
index dd94ff7..2a574e4 100644
--- a/src/libprojectM/MilkdropPresetFactory/ParamUtils.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/ParamUtils.hpp
@@ -10,34 +10,33 @@
#include <cassert>
#include "BuiltinParams.hpp"
+
class ParamUtils
{
public:
- static bool insert(Param * param, std::map<std::string,Param*> * paramTree)
+ static bool
+ insert(Param * param, std::map<std::string,Param*> * paramTree)
{
-
assert(param);
assert(paramTree);
-
- return ((paramTree->insert(std::make_pair(param->name,param))).second);
+ return ((paramTree->insert(std::make_pair(param->name,param))).second);
}
static const int AUTO_CREATE = 1;
static const int NO_CREATE = 0;
- template <int FLAGS>
- static Param * find(std::string name, std::map<std::string,Param*> * paramTree)
+ template <int FLAGS> static Param *
+ find(std::string name, std::map<std::string,Param*> * paramTree)
{
-
assert(paramTree);
Param * param;
/* First look in the suggested database */
std::map<std::string,Param*>::iterator pos = paramTree->find(name);
-
+
if ((FLAGS == AUTO_CREATE) && ((pos == paramTree->end())))
{
@@ -50,26 +49,24 @@
return NULL;
/* Finally, insert the new parameter into this preset's parameter tree */
- std::pair<std::map<std::string,Param*>::iterator, bool> insertRetPair =
- paramTree->insert(std::make_pair(param->name, param));
+ std::pair<std::map<std::string,Param*>::iterator, bool> insertRetPair =
+ paramTree->insert(std::make_pair(param->name, param));
assert(insertRetPair.second);
-
+
} else if (pos != paramTree->end())
- param = pos->second;
+ param = pos->second;
else
- param = NULL;
+ param = NULL;
/* Return the found (or created) parameter. Note that this could be null */
return param;
-
-
}
- static Param * find(const std::string & name, BuiltinParams * builtinParams, std::map<std::string,Param*> * insertionTree)
+ static Param *
+ find(const std::string & name, BuiltinParams * builtinParams, std::map<std::string,Param*> * insertionTree)
{
-
Param * param;
// Check first db
@@ -78,7 +75,6 @@
// Check second db, create if necessary
return find<AUTO_CREATE>(name, insertionTree);
-
}
};
diff --git a/src/libprojectM/MilkdropPresetFactory/Parser.cpp b/src/libprojectM/MilkdropPresetFactory/Parser.cpp
index 16c3c82..8a71f6d 100644
--- a/src/libprojectM/MilkdropPresetFactory/Parser.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/Parser.cpp
@@ -19,7 +19,6 @@
*
*/
/* parser.c */
-
#include <stdio.h>
#include <string>
#include <cstring>
@@ -47,29 +46,31 @@
#include <sstream>
#include "BuiltinFuncs.hpp"
+
/* Grabs the next token from the file. The second argument points
to the raw string */
-line_mode_t Parser::line_mode;
-CustomWave *Parser::current_wave;
-CustomShape *Parser::current_shape;
-int Parser::string_line_buffer_index;
-char Parser::string_line_buffer[STRING_LINE_SIZE];
-unsigned int Parser::line_count;
-int Parser::per_frame_eqn_count;
-int Parser::per_frame_init_eqn_count;
-int Parser::last_custom_wave_id;
-int Parser::last_custom_shape_id;
-char Parser::last_eqn_type[MAX_TOKEN_SIZE];
-int Parser::last_token_size;
+line_mode_t Parser::line_mode;
+CustomWave *Parser::current_wave;
+CustomShape *Parser::current_shape;
+int Parser::string_line_buffer_index;
+char Parser::string_line_buffer[STRING_LINE_SIZE];
+unsigned int Parser::line_count;
+int Parser::per_frame_eqn_count;
+int Parser::per_frame_init_eqn_count;
+int Parser::last_custom_wave_id;
+int Parser::last_custom_shape_id;
+char Parser::last_eqn_type[MAX_TOKEN_SIZE];
+int Parser::last_token_size;
std::string Parser::lastLinePrefix("");
bool Parser::tokenWrapAroundEnabled(false);
-token_t Parser::parseToken(std::istream & fs, char * string)
-{
+token_t
+Parser::parseToken(std::istream & fs, char * string)
+{
int c;
int i;
@@ -128,7 +129,6 @@
return tEOL;
}
}
-
}
/* Otherwise, just a regular division operator */
@@ -166,43 +166,44 @@
if (tokenWrapAroundEnabled)
{
- std::ostringstream buffer;
+ std::ostringstream buffer;
if (PARSE_DEBUG) std::cerr << "token wrap! line " << line_count << std::endl;
while (c != '=')
{
-
if (!fs || fs.eof())
{
line_count = 1;
line_mode = UNSET_LINE_MODE;
- if (PARSE_DEBUG) std::cerr << "token wrap: end of file" << std::endl;
+ if (PARSE_DEBUG) std::cerr << "token wrap: end of file" << std::endl;
return tEOF;
}
-
else {
- c = fs.get();
- if ( c != '=')
- buffer << (char)c;
- }
-
+ c = fs.get();
+ if ( c != '=')
+ buffer << (char)c;
+ }
}
- if (PARSE_DEBUG) std::cerr << "parseToken: parsed away equal sign, line prefix is \"" << buffer.str()
- << "\"" << std::endl;
+
+ if (PARSE_DEBUG)
+ std::cerr << "parseToken: parsed away equal sign, line prefix is \""
+ << buffer.str()
+ << "\""
+ << std::endl;
--i;
- if (!wrapsToNextLine(buffer.str())) {
- tokenWrapAroundEnabled = false;
- int buf_size = (int)buffer.str().length();
- // <= to also remove equal sign parsing from stream
- for (int k = 0; k <= buf_size; k++) {
- if (fs)
- fs.unget();
- else
- abort();
- }
- return tEOL;
- }
+ if (!wrapsToNextLine(buffer.str())) {
+ tokenWrapAroundEnabled = false;
+ int buf_size = (int)buffer.str().length();
+ // <= to also remove equal sign parsing from stream
+ for (int k = 0; k <= buf_size; k++) {
+ if (fs)
+ fs.unget();
+ else
+ abort();
+ }
+ return tEOL;
+ }
break;
@@ -228,29 +229,28 @@
case '\r':
i--;
break;
- default:
- if (c == EOF)
- std::cerr << "shouldn't happen: " << c << "(LINE " << line_count << ")" << std::endl;
- string[i] = tolower(c);
- //string[i+1] = 0;
- //std::cerr << "string is \n\"" << string << "\"" << std::endl;
- }
+ default:
+ if (c == EOF)
+ std::cerr << "shouldn't happen: " << c << "(LINE " << line_count << ")" << std::endl;
+ string[i] = tolower(c);
+ //string[i+1] = 0;
+ //std::cerr << "string is \n\"" << string << "\"" << std::endl;
+ }
}
/* String reached maximum length, return special token error */
return tStringTooLong;
-
}
/* Parse input in the form of "exp, exp, exp, ...)"
Returns a general expression list */
-GenExpr **Parser::parse_prefix_args(std::istream & fs, int num_args, MilkdropPreset * preset)
+GenExpr **
+Parser::parse_prefix_args(std::istream & fs, int num_args, MilkdropPreset * preset)
{
-
- int i, j;
+ int i, j;
GenExpr ** expr_list; /* List of arguments to function */
GenExpr * gen_expr;
@@ -287,7 +287,8 @@
}
/* Parses a comment at the top of the file. Stops when left bracket is found */
-int Parser::parse_top_comment(std::istream & fs)
+int
+Parser::parse_top_comment(std::istream & fs)
{
char string[MAX_TOKEN_SIZE];
@@ -306,9 +307,9 @@
/* Right Bracket is parsed by this function.
puts a new string into name */
-int Parser::parse_preset_name(std::istream & fs, char * name)
+int
+Parser::parse_preset_name(std::istream & fs, char * name)
{
-
token_t token;
if (name == NULL)
@@ -322,21 +323,18 @@
/* Parses per pixel equations */
-int Parser::parse_per_pixel_eqn(std::istream & fs, MilkdropPreset * preset, char * init_string)
+int
+Parser::parse_per_pixel_eqn(std::istream & fs, MilkdropPreset * preset, char * init_string)
{
-
-
char string[MAX_TOKEN_SIZE];
GenExpr * gen_expr;
-
if (init_string != 0)
{
strncpy(string, init_string, strlen(init_string));
}
else
{
-
if (parseToken(fs, string) != tEq)
{ /* parse per pixel operator name */
return PROJECTM_PARSE_ERROR;
@@ -364,12 +362,13 @@
}
/* Parses an equation line, this function is way too big, should add some helper functions */
-int Parser::parse_line(std::istream & fs, MilkdropPreset * preset)
+int
+Parser::parse_line(std::istream & fs, MilkdropPreset * preset)
{
- char eqn_string[MAX_TOKEN_SIZE];
- token_t token;
- InitCond * init_cond;
+ char eqn_string[MAX_TOKEN_SIZE];
+ token_t token;
+ InitCond * init_cond;
PerFrameEqn * per_frame_eqn;
/* Clear the string line buffer */
@@ -379,7 +378,7 @@
tokenWrapAroundEnabled = false;
token = parseToken( fs, eqn_string );
- switch (token )
+ switch (token)
{
/* Invalid Cases */
@@ -397,7 +396,7 @@
case tDiv:
if (PARSE_DEBUG) std::cerr << "parse_line: invalid token found at start of line (LINE "
- << line_count << ")" << std::endl;
+ << line_count << ")" << std::endl;
/* Invalid token found, return a parse error */
return PROJECTM_PARSE_ERROR;
@@ -425,35 +424,36 @@
if (!fs)
return PROJECTM_PARSE_ERROR;
-// char z = fs.get();
- char tmpChar;
- if ((tmpChar = fs.get()) == '\n') {
- tokenWrapAroundEnabled = false;
- return PROJECTM_PARSE_ERROR;
- } else if (tmpChar == '\r') {
- tokenWrapAroundEnabled = false;
- return PROJECTM_PARSE_ERROR;
- } else
- fs.unget();
+ // char z = fs.get();
+ char tmpChar;
+
+ if ((tmpChar = fs.get()) == '\n') {
+ tokenWrapAroundEnabled = false;
+ return PROJECTM_PARSE_ERROR;
+ } else if (tmpChar == '\r') {
+ tokenWrapAroundEnabled = false;
+ return PROJECTM_PARSE_ERROR;
+ } else
+ fs.unget();
- /* CASE: WARP CODE */
- if (!strncmp(eqn_string, WARP_STRING, WARP_STRING_LENGTH))
- {
- //std::cout << "parsing warp string block\n" << std::endl;
- parse_string_block(fs, &preset->presetOutputs().warpShader.programSource);
- return PROJECTM_SUCCESS;
- }
+ /* CASE: WARP CODE */
+ if (!strncmp(eqn_string, WARP_STRING, WARP_STRING_LENGTH))
+ {
+ //std::cout << "parsing warp string block\n" << std::endl;
+ parse_string_block(fs, &preset->presetOutputs().warpShader.programSource);
+ return PROJECTM_SUCCESS;
+ }
- /* CASE: COMPOSITE CODE */
- if (!strncmp(eqn_string, COMPOSITE_STRING, COMPOSITE_STRING_LENGTH))
- {
- //std::cout << "parsing composite string block\n" << std::endl;
- parse_string_block(fs, &preset->presetOutputs().compositeShader.programSource);
- return PROJECTM_SUCCESS;
- }
+ /* CASE: COMPOSITE CODE */
+ if (!strncmp(eqn_string, COMPOSITE_STRING, COMPOSITE_STRING_LENGTH))
+ {
+ //std::cout << "parsing composite string block\n" << std::endl;
+ parse_string_block(fs, &preset->presetOutputs().compositeShader.programSource);
+ return PROJECTM_SUCCESS;
+ }
/* CASE: PER FRAME INIT EQUATION */
if (!strncmp(eqn_string, PER_FRAME_INIT_STRING, PER_FRAME_INIT_STRING_LENGTH))
@@ -479,7 +479,7 @@
/* Per frame equation case */
if (!strncmp(eqn_string, PER_FRAME_STRING, PER_FRAME_STRING_LENGTH))
{
- tokenWrapAroundEnabled = true;
+ tokenWrapAroundEnabled = true;
/* Sometimes per frame equations are implicitly defined without the
per_frame_ prefix. This informs the parser that one could follow */
line_mode = PER_FRAME_LINE_MODE;
@@ -504,28 +504,25 @@
/* Wavecode initial condition case */
if (!strncmp(eqn_string, WAVECODE_STRING, WAVECODE_STRING_LENGTH))
{
-
line_mode = CUSTOM_WAVE_WAVECODE_LINE_MODE;
return parse_wavecode(eqn_string, fs, preset);
}
/* Custom Wave Prefix */
- if ((!strncmp(eqn_string, WAVE_STRING, WAVE_STRING_LENGTH)) &&
- ((eqn_string[5] >= 48) && (eqn_string[5] <= 57)))
+ if ( (!strncmp(eqn_string, WAVE_STRING, WAVE_STRING_LENGTH))
+ && ((eqn_string[5] >= 48) && (eqn_string[5] <= 57)))
{
- tokenWrapAroundEnabled = true;
+ tokenWrapAroundEnabled = true;
// if (PARSE_DEBUG) printf("parse_line wave prefix found: \"%s\"\n", eqn_string);
return parse_wave(eqn_string, fs, preset);
-
}
/* Shapecode initial condition case */
if (!strncmp(eqn_string, SHAPECODE_STRING, SHAPECODE_STRING_LENGTH))
{
-
line_mode = CUSTOM_SHAPE_SHAPECODE_LINE_MODE;
if (PARSE_DEBUG) printf("parse_line: shapecode prefix found: \"%s\"\n", eqn_string);
@@ -534,13 +531,12 @@
}
/* Custom Shape Prefix */
- if ((!strncmp(eqn_string, SHAPE_STRING, SHAPE_STRING_LENGTH)) &&
- ((eqn_string[6] >= 48) && (eqn_string[6] <= 57)))
+ if ( (!strncmp(eqn_string, SHAPE_STRING, SHAPE_STRING_LENGTH))
+ && ((eqn_string[6] >= 48) && (eqn_string[6] <= 57)))
{
tokenWrapAroundEnabled = true;
if (PARSE_DEBUG) printf("parse_line shape prefix found: \"%s\"\n", eqn_string);
return parse_shape(eqn_string, fs, preset);
-
}
/* Per pixel equation case */
@@ -563,20 +559,20 @@
/* Sometimes equations are written implicitly in milkdrop files, in the form
- per_frame_1 = p1 = eqn1; p2 = eqn2; p3 = eqn3;..;
+ per_frame_1 = p1 = eqn1; p2 = eqn2; p3 = eqn3;..;
- which is analagous to:
+ which is analagous to:
- per_frame_1 = p1 = eqn1; per_frame_2 = p2 = eqn2; per_frame_3 = p3 = eqn3; ...;
+ per_frame_1 = p1 = eqn1; per_frame_2 = p2 = eqn2; per_frame_3 = p3 = eqn3; ...;
- The following line mode hack allows such implicit declaration of the
- prefix that specifies the equation type. An alternative method
- may be to associate each equation line as list of equations separated
- by semicolons (and a new line ends the list). Instead, however, a global
- variable called "line_mode" specifies the last type of equation found,
- and bases any implicitly typed input on this fact
+ The following line mode hack allows such implicit declaration of the
+ prefix that specifies the equation type. An alternative method
+ may be to associate each equation line as list of equations separated
+ by semicolons (and a new line ends the list). Instead, however, a global
+ variable called "line_mode" specifies the last type of equation found,
+ and bases any implicitly typed input on this fact
- Note added by Carmelo Piccione (carmelo.piccione@gmail.com) 10/19/03
+ Note added by Carmelo Piccione (carmelo.piccione@gmail.com) 10/19/03
*/
/* Per frame line mode previously, try to parse the equation implicitly */
@@ -594,7 +590,6 @@
return PROJECTM_SUCCESS;
-
}
else if (line_mode == PER_FRAME_INIT_LINE_MODE)
{
@@ -618,8 +613,6 @@
tokenWrapAroundEnabled = true;
if (PARSE_DEBUG) printf("parse_line: implicit per pixel eqn (LINE %d)\n", line_count);
return parse_per_pixel_eqn(fs, preset, eqn_string);
-
-
}
else if (line_mode == CUSTOM_WAVE_PER_POINT_LINE_MODE)
{
@@ -644,7 +637,6 @@
if ((custom_wave = MilkdropPreset::find_custom_object(last_custom_wave_id, preset->customWaves)) == NULL)
return PROJECTM_FAILURE;
return parse_wave_per_frame_eqn(fs, custom_wave, preset);
-
}
else if (line_mode == CUSTOM_WAVE_WAVECODE_LINE_MODE)
{
@@ -667,7 +659,6 @@
return PROJECTM_FAILURE;
return parse_shape_per_frame_eqn(fs, custom_shape, preset);
-
}
else if (line_mode == CUSTOM_SHAPE_PER_FRAME_INIT_LINE_MODE)
{
@@ -679,7 +670,6 @@
return PROJECTM_FAILURE;
return parse_shape_per_frame_init_eqn(fs, custom_shape, preset);
-
}
if (PARSE_DEBUG) printf("parse_line: found initial condition: name = \"%s\" (LINE %d)\n", eqn_string, line_count);
@@ -713,16 +703,16 @@
/* Parses a general expression, this function is the meat of the parser */
-GenExpr * Parser::parse_gen_expr ( std::istream & fs, TreeExpr * tree_expr, MilkdropPreset * preset)
+GenExpr *
+Parser::parse_gen_expr ( std::istream & fs, TreeExpr * tree_expr, MilkdropPreset * preset)
{
-
- int i;
- char string[MAX_TOKEN_SIZE];
+ int i;
+ char string[MAX_TOKEN_SIZE];
token_t token;
GenExpr * gen_expr;
- float val;
- Param * param = NULL;
- Func * func;
+ float val;
+ Param * param = NULL;
+ Func * func;
GenExpr ** expr_list;
switch (token = parseToken(fs,string))
@@ -736,7 +726,9 @@
if (PARSE_DEBUG)
{
std::cerr << "parse_gen_expr: found prefix function (name = \""
- << func->getName() << "\") (LINE " << line_count << ")" << std::endl;
+ << func->getName()
+ << "\") (LINE " << line_count << ")"
+ << std::endl;
}
/* Parse the functions arguments */
@@ -745,7 +737,8 @@
if (PARSE_DEBUG)
{
std::cerr << "parse_prefix_args: failed to generate an expresion list! (LINE "
- << line_count << ")" << std::endl;
+ << line_count << ")"
+ << std::endl;
}
if ( tree_expr != NULL )
{
@@ -757,8 +750,8 @@
/* Convert function to expression */
if ((gen_expr = GenExpr::prefun_to_expr((float (*)(void *))func->func_ptr, expr_list, func->getNumArgs())) == NULL)
{
- if (PARSE_DEBUG) printf("parse_prefix_args: failed to convert prefix function to general expression (LINE %d) \n",
- line_count);
+ if (PARSE_DEBUG)
+ printf("parse_prefix_args: failed to convert prefix function to general expression (LINE %d) \n", line_count);
if (tree_expr)
delete tree_expr;
for (i = 0; i < func->getNumArgs();i++)
@@ -781,7 +774,7 @@
/* Case 2: (Left Parentice), a string coupled with a left parentice. Either an error or implicit
- multiplication operator. For now treat it as an error */
+ multiplication operator. For now treat it as an error */
if (*string != 0)
{
std::cerr << "token prefix is " << *string << std::endl;
@@ -792,13 +785,13 @@
}
/* CASE 3 (Left Parentice): the following is enclosed parentices to change order
- of operations. So we create a new expression tree */
+ of operations. So we create a new expression tree */
if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL)
{
if (PARSE_DEBUG) printf("parse_gen_expr: found left parentice, but failed to create new expression tree \n");
if (tree_expr)
- delete tree_expr;
+ delete tree_expr;
return NULL;
}
@@ -810,7 +803,6 @@
case tPlus:
if (*string == 0)
{
-
if (PARSE_DEBUG) printf("parse_gen_expr: plus used as prefix (LINE %d)\n", line_count);
/* Treat prefix plus as implict 0 preceding operator */
@@ -823,7 +815,6 @@
case tMinus:
if (*string == 0)
{
-
/* Use the negative infix operator, but first add an implicit zero to the operator tree */
gen_expr = GenExpr::const_to_expr(0);
//return parse_gen_expr(fs, insert_gen_expr(gen_expr, &tree_expr), preset);
@@ -838,7 +829,7 @@
case tComma:
/* CASE 1 (terminal): string is empty, but not null. Not sure if this will actually happen
- any more. */
+ any more. */
if (*string == 0)
{
if (PARSE_DEBUG) printf("parse_gen_expr: empty string coupled with terminal (LINE %d) \n", line_count);
@@ -861,14 +852,13 @@
{
if ((gen_expr = GenExpr::const_to_expr(val)) == NULL)
{
- if (tree_expr)
- delete tree_expr;
- return NULL;
+ if (tree_expr)
+ delete tree_expr;
+ return NULL;
}
/* Parse the rest of the line */
return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
-
}
@@ -881,7 +871,7 @@
if ((param = ParamUtils::find<ParamUtils::AUTO_CREATE>(std::string(string), ¤t_shape->param_tree)) == NULL)
{
if (tree_expr)
- delete tree_expr;
+ delete tree_expr;
return NULL;
}
}
@@ -889,7 +879,8 @@
if (PARSE_DEBUG)
{
std::cerr << "parse_gen_expr: custom shape parameter (name = "
- << param->name << ")" << std::endl;
+ << param->name << ")"
+ << std::endl;
}
@@ -915,7 +906,7 @@
if ((param = ParamUtils::find<ParamUtils::AUTO_CREATE>(std::string(string), ¤t_wave->param_tree)) == NULL)
{
if (tree_expr)
- delete tree_expr;
+ delete tree_expr;
return NULL;
}
}
@@ -924,7 +915,6 @@
if (PARSE_DEBUG)
{
std::cerr << "parse_gen_expr: custom wave parameter (name = " << param->name << ")" << std::endl;
-
}
/* Convert parameter to an expression */
@@ -938,13 +928,11 @@
/* Parse the rest of the line */
return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
-
}
/* CASE 6: regular parameter. Will be created if necessary and the string has no invalid characters */
if ((param = ParamUtils::find(string, &preset->builtinParams, &preset->user_param_tree)) != NULL)
{
-
if (PARSE_DEBUG)
{
std::cerr << "parse_gen_expr: parameter (name = \"" << param->name << "\")..." << std::endl;
@@ -961,14 +949,12 @@
/* Parse the rest of the line */
return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
-
}
/* CASE 7: Bad string, give up */
if (PARSE_DEBUG)
{
printf( "parse_gen_expr: syntax error [string = \"%s\"] (LINE %d)\n", string, line_count);
-
}
if (tree_expr)
delete tree_expr;
@@ -981,9 +967,9 @@
/* Inserts expressions into tree according to operator precedence.
If root is null, a new tree is created, with infix_op as only element */
-TreeExpr * Parser::insert_infix_op(InfixOp * infix_op, TreeExpr **root)
+TreeExpr *
+Parser::insert_infix_op(InfixOp * infix_op, TreeExpr **root)
{
-
TreeExpr * new_root;
/* Sanity check */
@@ -1027,13 +1013,12 @@
insert_infix_rec(infix_op, *root);
return *root;
-
}
-TreeExpr * Parser::insert_gen_expr(GenExpr * gen_expr, TreeExpr ** root)
+TreeExpr *
+Parser::insert_gen_expr(GenExpr * gen_expr, TreeExpr ** root)
{
-
TreeExpr * new_root;
/* If someone foolishly passes a null
@@ -1063,9 +1048,9 @@
}
/* A recursive helper function to insert general expression elements into the operator tree */
-int Parser::insert_gen_rec(GenExpr * gen_expr, TreeExpr * root)
+int
+Parser::insert_gen_rec(GenExpr * gen_expr, TreeExpr * root)
{
-
/* Trivial Case: root is null */
if (root == NULL)
@@ -1110,9 +1095,9 @@
/* A recursive helper function to insert infix arguments by operator precedence */
-int Parser::insert_infix_rec(InfixOp * infix_op, TreeExpr * root)
+int
+Parser::insert_infix_rec(InfixOp * infix_op, TreeExpr * root)
{
-
/* Shouldn't happen, implies a parse error */
if (root == NULL)
@@ -1160,13 +1145,12 @@
root->right = new TreeExpr(infix_op, NULL, root->right, NULL);
return PROJECTM_SUCCESS;
-
}
/* Parses an infix operator */
-GenExpr * Parser::parse_infix_op(std::istream & fs, token_t token, TreeExpr * tree_expr, MilkdropPreset * preset)
+GenExpr *
+Parser::parse_infix_op(std::istream & fs, token_t token, TreeExpr * tree_expr, MilkdropPreset * preset)
{
-
GenExpr * gen_expr;
switch (token)
@@ -1219,17 +1203,16 @@
/* Will never happen */
return NULL;
-
}
/* Parses an integer, checks for +/- prefix */
-int Parser::parse_int(std::istream & fs, int * int_ptr)
+int
+Parser::parse_int(std::istream & fs, int * int_ptr)
{
-
- char string[MAX_TOKEN_SIZE];
+ char string[MAX_TOKEN_SIZE];
token_t token;
- int sign;
- char * end_ptr = (char*)" ";
+ int sign;
+ char * end_ptr = (char*)" ";
token = parseToken(fs, string);
@@ -1265,12 +1248,12 @@
return PROJECTM_SUCCESS;
return PROJECTM_PARSE_ERROR;
-
}
-/* Parses a floating point number */
-int Parser::string_to_float(char * string, float * float_ptr)
-{
+/* Parses a floating point number */
+int
+Parser::string_to_float(char * string, float * float_ptr)
+{
char ** error_ptr;
if (*string == 0)
@@ -1295,13 +1278,13 @@
}
/* Parses a floating point number */
-int Parser::parse_float(std::istream & fs, float * float_ptr)
+int
+Parser::parse_float(std::istream & fs, float * float_ptr)
{
-
- char string[MAX_TOKEN_SIZE];
- char ** error_ptr;
+ char string[MAX_TOKEN_SIZE];
+ char ** error_ptr;
token_t token;
- int sign;
+ int sign;
error_ptr =(char**) wipemalloc(sizeof(char**));
@@ -1344,17 +1327,16 @@
free(error_ptr);
error_ptr = NULL;
return PROJECTM_PARSE_ERROR;
-
}
/* Parses a per frame equation. That is, interprets a stream of data as a per frame equation */
-PerFrameEqn * Parser::parse_per_frame_eqn(std::istream & fs, int index, MilkdropPreset * preset)
+PerFrameEqn *
+Parser::parse_per_frame_eqn(std::istream & fs, int index, MilkdropPreset * preset)
{
-
- char string[MAX_TOKEN_SIZE];
- Param * param;
+ char string[MAX_TOKEN_SIZE];
+ Param * param;
PerFrameEqn * per_frame_eqn;
- GenExpr * gen_expr;
+ GenExpr * gen_expr;
if (parseToken(fs, string) != tEq)
@@ -1399,12 +1381,12 @@
}
/* Parses an 'implicit' per frame equation. That is, interprets a stream of data as a per frame equation without a prefix */
-PerFrameEqn * Parser::parse_implicit_per_frame_eqn(std::istream & fs, char * param_string, int index, MilkdropPreset * preset)
+PerFrameEqn *
+Parser::parse_implicit_per_frame_eqn(std::istream & fs, char * param_string, int index, MilkdropPreset * preset)
{
-
- Param * param;
+ Param * param;
PerFrameEqn * per_frame_eqn;
- GenExpr * gen_expr;
+ GenExpr * gen_expr;
if (fs == NULL)
return NULL;
@@ -1452,12 +1434,12 @@
}
/* Parses an initial condition */
-InitCond * Parser::parse_init_cond(std::istream & fs, char * name, MilkdropPreset * preset)
+InitCond *
+Parser::parse_init_cond(std::istream & fs, char * name, MilkdropPreset * preset)
{
-
- Param * param;
- CValue init_val;
- InitCond * init_cond;
+ Param * param;
+ CValue init_val;
+ InitCond * init_cond;
if (name == NULL)
return NULL;
@@ -1479,7 +1461,7 @@
}
/* At this point, a parameter has been created or was found
- in the database. */
+ in the database. */
if (PARSE_DEBUG) printf("parsed_init_cond: parsing initial condition value... (LINE %d)\n", line_count);
@@ -1494,7 +1476,6 @@
}
init_val.bool_val = bool_test;
}
-
else if ((param->type == P_TYPE_INT))
{
if ((parse_int(fs, (int*)&init_val.int_val)) == PROJECTM_PARSE_ERROR)
@@ -1503,7 +1484,6 @@
return NULL;
}
}
-
/* float value */
else if (param->type == P_TYPE_DOUBLE)
{
@@ -1513,7 +1493,6 @@
return NULL;
}
}
-
/* Unknown value */
else
{
@@ -1533,30 +1512,29 @@
}
-void Parser::parse_string_block(std::istream & fs, std::string * out_string) {
+void
+Parser::parse_string_block(std::istream & fs, std::string * out_string)
+{
+ char name[MAX_TOKEN_SIZE];
+ token_t token;
+ std::set<char> skipList;
+ skipList.insert('`');
+ readStringUntil(fs, out_string, false, skipList);
- char name[MAX_TOKEN_SIZE];
- token_t token;
-
- std::set<char> skipList;
- skipList.insert('`');
- readStringUntil(fs, out_string, false, skipList);
-
- //std::cout << "out_string:\n " << *out_string << "\n" << std::endl;
-
+ //std::cout << "out_string:\n " << *out_string << "\n" << std::endl;
}
-InitCond * Parser::parse_per_frame_init_eqn(std::istream & fs, MilkdropPreset * preset, std::map<std::string,Param*> * database)
+InitCond *
+Parser::parse_per_frame_init_eqn(std::istream & fs, MilkdropPreset * preset, std::map<std::string,Param*> * database)
{
-
- char name[MAX_TOKEN_SIZE];
- Param * param = NULL;
- CValue init_val;
- InitCond * init_cond;
- GenExpr * gen_expr;
- float val;
- token_t token;
+ char name[MAX_TOKEN_SIZE];
+ Param * param = NULL;
+ CValue init_val;
+ InitCond * init_cond;
+ GenExpr * gen_expr;
+ float val;
+ token_t token;
if (preset == NULL)
@@ -1589,7 +1567,7 @@
}
/* At this point, a parameter has been created or was found
- in the database. */
+ in the database. */
if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: parsing right hand side of per frame init equation.. (LINE %d)\n", line_count);
@@ -1610,18 +1588,15 @@
{
init_val.bool_val = (bool)val;
}
-
else if ((param->type == P_TYPE_INT))
{
init_val.int_val = (int)val;
}
-
/* float value */
else if (param->type == P_TYPE_DOUBLE)
{
init_val.float_val = val;
}
-
/* Unknown value */
else
{
@@ -1643,133 +1618,130 @@
return init_cond;
}
-bool Parser::scanForComment(std::istream & fs) {
-
+bool
+Parser::scanForComment(std::istream & fs)
+{
int c;
+
c = fs.get();
if (c == '/') {
- while (true)
- {
- if (!fs || fs.eof())
- return true;
- else
- c = fs.get();
- if (c == EOF)
- return true;
+ while (true)
+ {
+ if (!fs || fs.eof())
+ return true;
+ else
+ c = fs.get();
+ if (c == EOF)
+ return true;
- if (c == '\n')
- {
- return true;
- }
- }
+ if (c == '\n')
+ {
+ return true;
+ }
+ }
} else {
- fs.unget();
- return false;
+ fs.unget();
+ return false;
}
}
-void Parser::readStringUntil(std::istream & fs, std::string * out_buffer, bool wrapAround, const std::set<char> & skipList) {
-
- int string_line_buffer_index = 0;
- int c;
-
- /* Loop until a delimiter is found, or the maximum string size is found */
- while (true)
- {
-
- if (!fs || fs.eof())
- c = EOF;
- else
- c = fs.get();
-
- /* Now interpret the character */
- switch (c)
- {
- case '/':
- {
- bool commentExisted = scanForComment(fs);
- if (!commentExisted) {
- out_buffer->push_back(c);
- break;
- } else {
- line_count++;
- return;
- }
- }
- case '\n':
- if (!out_buffer->empty() && ((*out_buffer)[out_buffer->length() -1] == '\n'))
- return;
-
- line_count++;
- if (wrapAround)
- {
- std::ostringstream buffer;
-
- // if (PARSE_DEBUG) std::cerr << "token wrap! line " << line_count << std::endl;
- while (c != '=')
- {
-
- if (!fs || fs.eof())
- {
- line_count = 1;
- line_mode = UNSET_LINE_MODE;
- // if (PARSE_DEBUG) std::cerr << "token wrap: end of file" << std::endl;
- return;
- }
-
- else {
- c = fs.get();
- if ( c != '=')
- buffer << c;
- }
-
- }
-
-
- if (!wrapsToNextLine(buffer.str())) {
- wrapAround = false;
- int buf_size = (int)buffer.str().length();
- // <= to also remove equal sign parsing from stream
- for (int k = 0; k <= buf_size; k++) {
- if (fs)
- fs.unget();
- else
- abort();
- }
- return;
- }
-
- break;
- } else
- out_buffer->push_back(c);
- return;
- case EOF:
- line_count = 1;
- return;
- default:
-
- if (out_buffer != NULL)
- {
- if (skipList.find(c) == skipList.end())
- out_buffer->push_back(c);
-
- }
- }
-
- }
-
-
-}
-int Parser::parse_wavecode(char * token, std::istream & fs, MilkdropPreset * preset)
+void
+Parser::readStringUntil(std::istream & fs, std::string * out_buffer, bool wrapAround, const std::set<char> & skipList)
{
+ int string_line_buffer_index = 0;
+ int c;
- char * var_string;
- InitCond * init_cond;
- CustomWave * custom_wave;
- int id;
- CValue init_val;
- Param * param;
+ /* Loop until a delimiter is found, or the maximum string size is found */
+ while (true)
+ {
+ if (!fs || fs.eof())
+ c = EOF;
+ else
+ c = fs.get();
+
+ /* Now interpret the character */
+ switch (c)
+ {
+ case '/':
+ {
+ bool commentExisted = scanForComment(fs);
+
+ if (!commentExisted) {
+ out_buffer->push_back(c);
+ break;
+ } else {
+ line_count++;
+ return;
+ }
+ }
+ case '\n':
+ if (!out_buffer->empty() && ((*out_buffer)[out_buffer->length() -1] == '\n'))
+ return;
+
+ line_count++;
+ if (wrapAround)
+ {
+ std::ostringstream buffer;
+
+ // if (PARSE_DEBUG) std::cerr << "token wrap! line " << line_count << std::endl;
+ while (c != '=')
+ {
+ if (!fs || fs.eof())
+ {
+ line_count = 1;
+ line_mode = UNSET_LINE_MODE;
+ // if (PARSE_DEBUG) std::cerr << "token wrap: end of file" << std::endl;
+ return;
+ }
+ else {
+ c = fs.get();
+ if ( c != '=')
+ buffer << c;
+ }
+ }
+
+
+ if (!wrapsToNextLine(buffer.str())) {
+ wrapAround = false;
+ int buf_size = (int)buffer.str().length();
+ // <= to also remove equal sign parsing from stream
+ for (int k = 0; k <= buf_size; k++) {
+ if (fs)
+ fs.unget();
+ else
+ abort();
+ }
+ return;
+ }
+
+ break;
+ } else
+ out_buffer->push_back(c);
+ return;
+ case EOF:
+ line_count = 1;
+ return;
+ default:
+
+ if (out_buffer != NULL)
+ {
+ if (skipList.find(c) == skipList.end())
+ out_buffer->push_back(c);
+ }
+ }
+ }
+}
+
+int
+Parser::parse_wavecode(char * token, std::istream & fs, MilkdropPreset * preset)
+{
+ char * var_string;
+ InitCond * init_cond;
+ CustomWave * custom_wave;
+ int id;
+ CValue init_val;
+ Param * param;
assert(preset);
assert(fs);
@@ -1789,7 +1761,8 @@
if ((custom_wave = MilkdropPreset::find_custom_object(id, preset->customWaves)) == NULL)
{
std::cerr << "parse_wavecode: failed to load (or create) custom wave (id = "
- << id << ")!\n" << std::endl;
+ << id << ")!\n"
+ << std::endl;
return PROJECTM_FAILURE;
}
@@ -1807,9 +1780,9 @@
if ((param->type == P_TYPE_BOOL))
{
int bool_test;
+
if ((parse_int(fs, &bool_test)) == PROJECTM_PARSE_ERROR)
{
-
if (PARSE_DEBUG) printf("parse_wavecode: error parsing integer!\n");
return PROJECTM_PARSE_ERROR;
}
@@ -1819,12 +1792,10 @@
{
if ((parse_int(fs, (int*)&init_val.int_val)) == PROJECTM_PARSE_ERROR)
{
-
if (PARSE_DEBUG) printf("parse_wavecode: error parsing integer!\n");
return PROJECTM_PARSE_ERROR;
}
}
-
/* float value */
else if (param->type == P_TYPE_DOUBLE)
{
@@ -1834,7 +1805,6 @@
return PROJECTM_PARSE_ERROR;
}
}
-
/* Unknown value */
else
{
@@ -1852,9 +1822,9 @@
}
std::pair<std::map<std::string, InitCond*>::iterator, bool> inserteePair =
- custom_wave->init_cond_tree.insert(std::make_pair(init_cond->param->name, init_cond));
+ custom_wave->init_cond_tree.insert(std::make_pair(init_cond->param->name, init_cond));
- // assert(inserteePair.second);
+ // assert(inserteePair.second);
line_mode = CUSTOM_WAVE_WAVECODE_LINE_MODE;
@@ -1862,15 +1832,16 @@
return PROJECTM_SUCCESS;
}
-int Parser::parse_shapecode(char * token, std::istream & fs, MilkdropPreset * preset)
+int
+Parser::parse_shapecode(char * token, std::istream & fs, MilkdropPreset * preset)
{
- char * var_string;
- InitCond * init_cond;
+ char * var_string;
+ InitCond * init_cond;
CustomShape * custom_shape;
- int id;
- CValue init_val;
- Param * param;
+ int id;
+ CValue init_val;
+ Param * param;
/* Null argument checks */
if (preset == NULL)
@@ -1892,7 +1863,7 @@
/* Retrieve custom shape information from preset. The 3rd argument
- if true creates a custom shape if one does not exist */
+ if true creates a custom shape if one does not exist */
if ((custom_shape = MilkdropPreset::find_custom_object(id, preset->customShapes)) == NULL)
{
@@ -1903,7 +1874,6 @@
if ((param = ParamUtils::find<ParamUtils::NO_CREATE>(var_string, &custom_shape->text_properties_tree)) != NULL)
{
-
std::string text;//[MAX_TOKEN_SIZE];
//token_t token = parseToken(fs, text);
@@ -1912,7 +1882,8 @@
*((std::string*)param->engine_val) = text;
if (PARSE_DEBUG)
std::cerr << "parse_shapecode: found image url, text is \""
- << text << "\"" << std::endl;
+ << text << "\""
+ << std::endl;
return PROJECTM_SUCCESS;
}
@@ -1933,6 +1904,7 @@
if ((param->type == P_TYPE_BOOL))
{
int bool_test;
+
if ((parse_int(fs, &bool_test)) == PROJECTM_PARSE_ERROR)
{
if (PARSE_DEBUG) printf("parse_shapecode: error parsing integer!\n");
@@ -1948,7 +1920,6 @@
return PROJECTM_PARSE_ERROR;
}
}
-
/* float value */
else if (param->type == P_TYPE_DOUBLE)
{
@@ -1958,7 +1929,6 @@
return PROJECTM_PARSE_ERROR;
}
}
-
/* Unknown value */
else
{
@@ -1981,9 +1951,9 @@
}
-int Parser::parse_wavecode_prefix(char * token, int * id, char ** var_string)
+int
+Parser::parse_wavecode_prefix(char * token, int * id, char ** var_string)
{
-
int len, i, j;
if (token == NULL)
@@ -2022,13 +1992,12 @@
*var_string = token + i + 1;
return PROJECTM_SUCCESS;
-
}
-int Parser::parse_shapecode_prefix(char * token, int * id, char ** var_string)
+int
+Parser::parse_shapecode_prefix(char * token, int * id, char ** var_string)
{
-
int len, i, j;
if (token == NULL)
@@ -2067,12 +2036,11 @@
*var_string = token + i + 1;
return PROJECTM_SUCCESS;
-
}
-int Parser::parse_wave_prefix(char * token, int * id, char ** eqn_string)
+int
+Parser::parse_wave_prefix(char * token, int * id, char ** eqn_string)
{
-
int len, i, j;
if (token == NULL)
@@ -2110,12 +2078,11 @@
if (PARSE_DEBUG) printf("parse_wave_prefix: prefix = %s\n (LINE %d)", *eqn_string, line_count);
return PROJECTM_SUCCESS;
-
}
-int Parser::parse_shape_prefix(char * token, int * id, char ** eqn_string)
+int
+Parser::parse_shape_prefix(char * token, int * id, char ** eqn_string)
{
-
int len, i, j;
if (token == NULL)
@@ -2152,15 +2119,14 @@
*eqn_string = token + i + 1;
return PROJECTM_SUCCESS;
-
}
/* Parses custom wave equations */
-int Parser::parse_wave(char * token, std::istream & fs, MilkdropPreset * preset)
+int
+Parser::parse_wave(char * token, std::istream & fs, MilkdropPreset * preset)
{
-
- int id;
- char * eqn_type;
+ int id;
+ char * eqn_type;
if (PARSE_DEBUG) printf("parse_wave:begin\n");
@@ -2181,18 +2147,17 @@
strncpy(last_eqn_type, eqn_type, MAX_TOKEN_SIZE);
return parse_wave_helper(fs, preset, id, eqn_type, 0);
-
}
-int Parser::parse_wave_helper(std::istream & fs, MilkdropPreset * preset, int id, char * eqn_type, char * init_string)
+int
+Parser::parse_wave_helper(std::istream & fs, MilkdropPreset * preset, int id, char * eqn_type, char * init_string)
{
-
- Param * param;
- GenExpr * gen_expr;
- char string[MAX_TOKEN_SIZE];
+ Param * param;
+ GenExpr * gen_expr;
+ char string[MAX_TOKEN_SIZE];
PerFrameEqn * per_frame_eqn;
- CustomWave * custom_wave;
- InitCond * init_cond;
+ CustomWave * custom_wave;
+ InitCond * init_cond;
/* Retrieve custom wave associated with this id */
if ((custom_wave = MilkdropPreset::find_custom_object(id, preset->customWaves)) == NULL)
@@ -2204,7 +2169,6 @@
/* per frame init equation case */
if (!strncmp(eqn_type, WAVE_INIT_STRING, WAVE_INIT_STRING_LENGTH))
{
-
if (PARSE_DEBUG) printf("parse_wave_helper (per frame init): [begin] (LINE %d)\n", line_count);
/* Parse the per frame init equation */
@@ -2220,13 +2184,11 @@
line_mode = CUSTOM_WAVE_PER_FRAME_INIT_LINE_MODE;
init_cond->evaluate(true);
return PROJECTM_SUCCESS;
-
}
/* per frame equation case */
if (!strncmp(eqn_type, PER_FRAME_STRING_NO_UNDERSCORE, PER_FRAME_STRING_NO_UNDERSCORE_LENGTH))
{
-
if (PARSE_DEBUG) printf("parse_wave_helper (per_frame): [start] (custom wave id = %d)\n", custom_wave->id);
if (parseToken(fs, string) != tEq)
@@ -2275,11 +2237,11 @@
custom_wave->per_frame_eqn_tree.push_back(per_frame_eqn);
if (PARSE_DEBUG) printf("parse_wave (per_frame): equation %d associated with custom wave %d [success]\n",
- per_frame_eqn->index, custom_wave->id);
+ per_frame_eqn->index, custom_wave->id);
/* Need to add stuff to string buffer so the editor can read the equations.
- Why not make a nice little helper function for this? - here it is: */
+ Why not make a nice little helper function for this? - here it is: */
line_mode = CUSTOM_WAVE_PER_FRAME_LINE_MODE;
return PROJECTM_SUCCESS;
@@ -2289,7 +2251,6 @@
/* per point equation case */
if (!strncmp(eqn_type, PER_POINT_STRING, PER_POINT_STRING_LENGTH))
{
-
if (PARSE_DEBUG) printf("parse_wave_helper (per_point): per_pixel equation parsing start...(LINE %d)\n", line_count);
/// HACK the parse_line code already parsed the per_pixel variable name. This handles that case
@@ -2337,16 +2298,15 @@
}
/* Parses custom shape equations */
-int Parser::parse_shape(char * token, std::istream & fs, MilkdropPreset * preset)
+int
+Parser::parse_shape(char * token, std::istream & fs, MilkdropPreset * preset)
{
-
- int id;
- char * eqn_type;
+ int id;
+ char * eqn_type;
CustomShape * custom_shape;
if (token == NULL)
-
return PROJECTM_FAILURE;
if (fs == NULL)
return PROJECTM_FAILURE;
@@ -2392,9 +2352,9 @@
Returns -1 if syntax error
*/
-int Parser::get_string_prefix_len(char * string)
+int
+Parser::get_string_prefix_len(char * string)
{
-
int i = 0;
/* Null argument check */
@@ -2430,7 +2390,8 @@
return i;
}
-int Parser::parse_shape_per_frame_init_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset)
+int
+Parser::parse_shape_per_frame_init_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset)
{
InitCond * init_cond;
@@ -2450,11 +2411,11 @@
return PROJECTM_SUCCESS;
}
-int Parser::parse_shape_per_frame_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset)
+int
+Parser::parse_shape_per_frame_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset)
{
-
- Param * param;
- GenExpr * gen_expr;
+ Param * param;
+ GenExpr * gen_expr;
PerFrameEqn * per_frame_eqn;
char string[MAX_TOKEN_SIZE];
@@ -2512,11 +2473,11 @@
return PROJECTM_SUCCESS;
}
-int Parser::parse_wave_per_frame_eqn(std::istream & fs, CustomWave * custom_wave, MilkdropPreset * preset)
+int
+Parser::parse_wave_per_frame_eqn(std::istream & fs, CustomWave * custom_wave, MilkdropPreset * preset)
{
-
- Param * param;
- GenExpr * gen_expr;
+ Param * param;
+ GenExpr * gen_expr;
PerFrameEqn * per_frame_eqn;
char string[MAX_TOKEN_SIZE];
@@ -2568,29 +2529,26 @@
custom_wave->per_frame_eqn_tree.push_back(per_frame_eqn);
if (PARSE_DEBUG) printf("parse_wave (per_frame): equation %d associated with custom wave %d [success]\n",
- per_frame_eqn->index, custom_wave->id);
+ per_frame_eqn->index, custom_wave->id);
/* Need to add stuff to string buffer so the editor can read the equations.
- Why not make a nice little helper function for this? - here it is: */
+ Why not make a nice little helper function for this? - here it is: */
line_mode = CUSTOM_WAVE_PER_FRAME_LINE_MODE;
return PROJECTM_SUCCESS;
}
-bool Parser::wrapsToNextLine(const std::string & str) {
+bool
+Parser::wrapsToNextLine(const std::string & str)
+{
+ std::size_t lastLineEndIndex = lastLinePrefix.find_last_not_of("0123456789");
+ std::size_t thisLineEndIndex = str.find_last_not_of("0123456789");
+ std::size_t startIndex = 0;
-std::size_t lastLineEndIndex =
- lastLinePrefix.find_last_not_of("0123456789");
-
-std::size_t thisLineEndIndex =
- str.find_last_not_of("0123456789");
-
-std::size_t startIndex = 0;
-if ((str.compare(startIndex, lastLineEndIndex, lastLinePrefix.c_str(), thisLineEndIndex)) == 0)
- return true;
-else
- return false;
-
+ if ((str.compare(startIndex, lastLineEndIndex, lastLinePrefix.c_str(), thisLineEndIndex)) == 0)
+ return true;
+ else
+ return false;
}
diff --git a/src/libprojectM/MilkdropPresetFactory/Parser.hpp b/src/libprojectM/MilkdropPresetFactory/Parser.hpp
index 8c0e19d..f9ff507 100644
--- a/src/libprojectM/MilkdropPresetFactory/Parser.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/Parser.hpp
@@ -25,9 +25,9 @@
*
* $Log$
*/
-
#ifndef _PARSER_H
#define _PARSER_H
+
//#define PARSE_DEBUG 2
#define PARSE_DEBUG 0
@@ -38,46 +38,47 @@
#include "InitCond.hpp"
#include "MilkdropPreset.hpp"
+
/* Strings that prefix (and denote the type of) equations */
-#define PER_FRAME_STRING "per_frame_"
-#define PER_FRAME_STRING_LENGTH 10
+#define PER_FRAME_STRING "per_frame_"
+#define PER_FRAME_STRING_LENGTH 10
-#define PER_PIXEL_STRING "per_pixel_"
-#define PER_PIXEL_STRING_LENGTH 10
+#define PER_PIXEL_STRING "per_pixel_"
+#define PER_PIXEL_STRING_LENGTH 10
-#define PER_FRAME_INIT_STRING "per_frame_init_"
-#define PER_FRAME_INIT_STRING_LENGTH 15
+#define PER_FRAME_INIT_STRING "per_frame_init_"
+#define PER_FRAME_INIT_STRING_LENGTH 15
-#define WAVECODE_STRING "wavecode_"
-#define WAVECODE_STRING_LENGTH 9
+#define WAVECODE_STRING "wavecode_"
+#define WAVECODE_STRING_LENGTH 9
-#define WAVE_STRING "wave_"
-#define WAVE_STRING_LENGTH 5
+#define WAVE_STRING "wave_"
+#define WAVE_STRING_LENGTH 5
-#define PER_POINT_STRING "per_point"
-#define PER_POINT_STRING_LENGTH 9
+#define PER_POINT_STRING "per_point"
+#define PER_POINT_STRING_LENGTH 9
-#define PER_FRAME_STRING_NO_UNDERSCORE "per_frame"
+#define PER_FRAME_STRING_NO_UNDERSCORE "per_frame"
#define PER_FRAME_STRING_NO_UNDERSCORE_LENGTH 9
-#define SHAPECODE_STRING "shapecode_"
-#define SHAPECODE_STRING_LENGTH 10
+#define SHAPECODE_STRING "shapecode_"
+#define SHAPECODE_STRING_LENGTH 10
-#define WARP_STRING "warp_"
-#define WARP_STRING_LENGTH 5
+#define WARP_STRING "warp_"
+#define WARP_STRING_LENGTH 5
-#define COMPOSITE_STRING "comp_"
-#define COMPOSITE_STRING_LENGTH 5
+#define COMPOSITE_STRING "comp_"
+#define COMPOSITE_STRING_LENGTH 5
-#define SHAPE_STRING "shape_"
-#define SHAPE_STRING_LENGTH 6
+#define SHAPE_STRING "shape_"
+#define SHAPE_STRING_LENGTH 6
-#define SHAPE_INIT_STRING "init"
-#define SHAPE_INIT_STRING_LENGTH 4
+#define SHAPE_INIT_STRING "init"
+#define SHAPE_INIT_STRING_LENGTH 4
-#define WAVE_INIT_STRING "init"
-#define WAVE_INIT_STRING_LENGTH 4
+#define WAVE_INIT_STRING "init"
+#define WAVE_INIT_STRING_LENGTH 4
#include <set>
@@ -98,27 +99,27 @@
/** Token enumeration type */
typedef enum {
- tEOL, /* end of a line, usually a '/n' or '/r' */
- tEOF, /* end of file */
- tLPr, /* ( */
- tRPr, /* ) */
- tLBr, /* [ */
- tRBr, /* ] */
- tEq, /* = */
- tPlus, /* + */
- tMinus, /* - */
- tMult, /* * */
- tMod, /* % */
- tDiv, /* / */
- tOr, /* | */
- tAnd, /* & */
- tComma, /* , */
- tPositive, /* + as a prefix operator */
- tNegative, /* - as a prefix operator */
- tSemiColon, /* ; */
- tStringTooLong, /* special token to indicate an invalid string length */
- tStringBufferFilled /* the string buffer for this line is maxed out */
- } token_t;
+ tEOL, /* end of a line, usually a '/n' or '/r' */
+ tEOF, /* end of file */
+ tLPr, /* ( */
+ tRPr, /* ) */
+ tLBr, /* [ */
+ tRBr, /* ] */
+ tEq, /* = */
+ tPlus, /* + */
+ tMinus, /* - */
+ tMult, /* * */
+ tMod, /* % */
+ tDiv, /* / */
+ tOr, /* | */
+ tAnd, /* & */
+ tComma, /* , */
+ tPositive, /* + as a prefix operator */
+ tNegative, /* - as a prefix operator */
+ tSemiColon, /* ; */
+ tStringTooLong, /* special token to indicate an invalid string length */
+ tStringBufferFilled /* the string buffer for this line is maxed out */
+} token_t;
class CustomShape;
class CustomWave;
@@ -130,63 +131,62 @@
class Parser {
public:
- static std::string lastLinePrefix;
- static line_mode_t line_mode;
- static CustomWave *current_wave;
- static CustomShape *current_shape;
- static int string_line_buffer_index;
- static char string_line_buffer[STRING_LINE_SIZE];
- static unsigned int line_count;
- static int per_frame_eqn_count;
- static int per_frame_init_eqn_count;
- static int last_custom_wave_id;
- static int last_custom_shape_id;
- static char last_eqn_type[MAX_TOKEN_SIZE];
- static int last_token_size;
- static bool tokenWrapAroundEnabled;
+ static std::string lastLinePrefix;
+ static line_mode_t line_mode;
+ static CustomWave *current_wave;
+ static CustomShape *current_shape;
+ static int string_line_buffer_index;
+ static char string_line_buffer[STRING_LINE_SIZE];
+ static unsigned int line_count;
+ static int per_frame_eqn_count;
+ static int per_frame_init_eqn_count;
+ static int last_custom_wave_id;
+ static int last_custom_shape_id;
+ static char last_eqn_type[MAX_TOKEN_SIZE];
+ static int last_token_size;
+ static bool tokenWrapAroundEnabled;
- static PerFrameEqn *parse_per_frame_eqn( std::istream & fs, int index,
- MilkdropPreset * preset);
- static int parse_per_pixel_eqn( std::istream & fs, MilkdropPreset * preset,
- char * init_string);
- static InitCond *parse_init_cond( std::istream & fs, char * name, MilkdropPreset * preset );
- static int parse_preset_name( std::istream & fs, char * name );
- static int parse_top_comment( std::istream & fs );
- static int parse_line( std::istream & fs, MilkdropPreset * preset );
+ static PerFrameEqn *parse_per_frame_eqn( std::istream & fs, int index,
+ MilkdropPreset * preset);
+ static int parse_per_pixel_eqn( std::istream & fs, MilkdropPreset * preset,
+ char * init_string);
+ static InitCond *parse_init_cond( std::istream & fs, char * name, MilkdropPreset * preset );
+ static int parse_preset_name( std::istream & fs, char * name );
+ static int parse_top_comment( std::istream & fs );
+ static int parse_line( std::istream & fs, MilkdropPreset * preset );
- static int get_string_prefix_len(char * string);
- static TreeExpr * insert_gen_expr(GenExpr * gen_expr, TreeExpr ** root);
- static TreeExpr * insert_infix_op(InfixOp * infix_op, TreeExpr ** root);
- static token_t parseToken(std::istream & fs, char * string);
- static GenExpr ** parse_prefix_args(std::istream & fs, int num_args, MilkdropPreset * preset);
- static GenExpr * parse_infix_op(std::istream & fs, token_t token, TreeExpr * tree_expr, MilkdropPreset * preset);
- static GenExpr * parse_sign_arg(std::istream & fs);
- static int parse_float(std::istream & fs, float * float_ptr);
- static int parse_int(std::istream & fs, int * int_ptr);
- static int insert_gen_rec(GenExpr * gen_expr, TreeExpr * root);
- static int insert_infix_rec(InfixOp * infix_op, TreeExpr * root);
- static GenExpr * parse_gen_expr(std::istream & fs, TreeExpr * tree_expr, MilkdropPreset * preset);
- static PerFrameEqn * parse_implicit_per_frame_eqn(std::istream & fs, char * param_string, int index, MilkdropPreset * preset);
- static InitCond * parse_per_frame_init_eqn(std::istream & fs, MilkdropPreset * preset, std::map<std::string,Param*> * database);
- static int parse_wavecode_prefix(char * token, int * id, char ** var_string);
- static int parse_wavecode(char * token, std::istream & fs, MilkdropPreset * preset);
- static int parse_wave_prefix(char * token, int * id, char ** eqn_string);
- static int parse_wave_helper(std::istream & fs, MilkdropPreset * preset, int id, char * eqn_type, char * init_string);
- static int parse_shapecode(char * eqn_string, std::istream & fs, MilkdropPreset * preset);
- static int parse_shapecode_prefix(char * token, int * id, char ** var_string);
- static void parse_string_block(std::istream & fs, std::string * out_string);
- static bool scanForComment(std::istream & fs);
- static int parse_wave(char * eqn_string, std::istream & fs, MilkdropPreset * preset);
- static int parse_shape(char * eqn_string, std::istream & fs, MilkdropPreset * preset);
- static int parse_shape_prefix(char * token, int * id, char ** eqn_string);
- static void readStringUntil(std::istream & fs, std::string * out_buffer, bool wrapAround = true, const std::set<char> & skipList = std::set<char>()) ;
+ static int get_string_prefix_len(char * string);
+ static TreeExpr * insert_gen_expr(GenExpr * gen_expr, TreeExpr ** root);
+ static TreeExpr * insert_infix_op(InfixOp * infix_op, TreeExpr ** root);
+ static token_t parseToken(std::istream & fs, char * string);
+ static GenExpr ** parse_prefix_args(std::istream & fs, int num_args, MilkdropPreset * preset);
+ static GenExpr * parse_infix_op(std::istream & fs, token_t token, TreeExpr * tree_expr, MilkdropPreset * preset);
+ static GenExpr * parse_sign_arg(std::istream & fs);
+ static int parse_float(std::istream & fs, float * float_ptr);
+ static int parse_int(std::istream & fs, int * int_ptr);
+ static int insert_gen_rec(GenExpr * gen_expr, TreeExpr * root);
+ static int insert_infix_rec(InfixOp * infix_op, TreeExpr * root);
+ static GenExpr * parse_gen_expr(std::istream & fs, TreeExpr * tree_expr, MilkdropPreset * preset);
+ static PerFrameEqn * parse_implicit_per_frame_eqn(std::istream & fs, char * param_string, int index, MilkdropPreset * preset);
+ static InitCond * parse_per_frame_init_eqn(std::istream & fs, MilkdropPreset * preset, std::map<std::string,Param*> * database);
+ static int parse_wavecode_prefix(char * token, int * id, char ** var_string);
+ static int parse_wavecode(char * token, std::istream & fs, MilkdropPreset * preset);
+ static int parse_wave_prefix(char * token, int * id, char ** eqn_string);
+ static int parse_wave_helper(std::istream & fs, MilkdropPreset * preset, int id, char * eqn_type, char * init_string);
+ static int parse_shapecode(char * eqn_string, std::istream & fs, MilkdropPreset * preset);
+ static int parse_shapecode_prefix(char * token, int * id, char ** var_string);
+ static void parse_string_block(std::istream & fs, std::string * out_string);
+ static bool scanForComment(std::istream & fs);
+ static int parse_wave(char * eqn_string, std::istream & fs, MilkdropPreset * preset);
+ static int parse_shape(char * eqn_string, std::istream & fs, MilkdropPreset * preset);
+ static int parse_shape_prefix(char * token, int * id, char ** eqn_string);
+ static void readStringUntil(std::istream & fs, std::string * out_buffer, bool wrapAround = true, const std::set<char> & skipList = std::set<char>()) ;
- static int string_to_float(char * string, float * float_ptr);
- static int parse_shape_per_frame_init_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset);
- static int parse_shape_per_frame_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset);
- static int parse_wave_per_frame_eqn(std::istream & fs, CustomWave * custom_wave, MilkdropPreset * preset);
- static bool wrapsToNextLine(const std::string & str);
- };
+ static int string_to_float(char * string, float * float_ptr);
+ static int parse_shape_per_frame_init_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset);
+ static int parse_shape_per_frame_eqn(std::istream & fs, CustomShape * custom_shape, MilkdropPreset * preset);
+ static int parse_wave_per_frame_eqn(std::istream & fs, CustomWave * custom_wave, MilkdropPreset * preset);
+ static bool wrapsToNextLine(const std::string & str);
+};
#endif /** !_PARSER_H */
-
diff --git a/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.cpp b/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.cpp
index 30e2342..96bd10f 100644
--- a/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.cpp
@@ -18,7 +18,6 @@
* See 'LICENSE.txt' included within this release
*
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -35,33 +34,33 @@
#include "wipemalloc.h"
#include <cassert>
+
/* Evaluate an equation */
-void PerFrameEqn::evaluate() {
+void
+PerFrameEqn::evaluate()
+{
+ if (PER_FRAME_EQN_DEBUG) {
+ printf("per_frame_%d=%s= ", index, param->name.c_str());
+ fflush(stdout);
+ }
- if (PER_FRAME_EQN_DEBUG) {
- printf("per_frame_%d=%s= ", index, param->name.c_str());
- fflush(stdout);
- }
-
- //*((float*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr);
- assert(gen_expr);
- assert(param);
- param->set_param(gen_expr->eval_gen_expr(-1,-1));
+ //*((float*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr);
+ assert(gen_expr);
+ assert(param);
+ param->set_param(gen_expr->eval_gen_expr(-1,-1));
- if (PER_FRAME_EQN_DEBUG) printf(" = %.4f\n", *((float*)param->engine_val));
-
+ if (PER_FRAME_EQN_DEBUG) printf(" = %.4f\n", *((float*)param->engine_val));
}
/* Frees perframe equation structure. Warning: assumes gen_expr pointer is not freed by anyone else! */
-PerFrameEqn::~PerFrameEqn() {
-
+PerFrameEqn::~PerFrameEqn()
+{
delete gen_expr;
// param is freed in param_tree container of some other class
-
}
/* Create a new per frame equation */
-PerFrameEqn::PerFrameEqn(int _index, Param * _param, GenExpr * _gen_expr) :
- index(_index), param(_param), gen_expr(_gen_expr) {}
+PerFrameEqn::PerFrameEqn(int _index, Param * _param, GenExpr * _gen_expr)
+ : index(_index), param(_param), gen_expr(_gen_expr) {}
diff --git a/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.hpp b/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.hpp
index 3964080..155560f 100644
--- a/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/PerFrameEqn.hpp
@@ -29,25 +29,27 @@
#ifndef _PER_FRAME_EQN_H
#define _PER_FRAME_EQN_H
+
#define PER_FRAME_EQN_DEBUG 0
+
class GenExpr;
class Param;
class PerFrameEqn;
class PerFrameEqn {
public:
- int index; /* a unique id for each per frame eqn (generated by order in preset files) */
- Param *param; /* parameter to be assigned a value */
- GenExpr *gen_expr; /* expression that paremeter is equal to */
-
- PerFrameEqn(int index, Param * param, GenExpr * gen_expr);
- ~PerFrameEqn();
+ int index; /* a unique id for each per frame eqn (generated by order in preset files) */
+ Param *param; /* parameter to be assigned a value */
+ GenExpr *gen_expr; /* expression that paremeter is equal to */
- /// Evaluate the per frame equation
- void evaluate();
+ PerFrameEqn(int index, Param * param, GenExpr * gen_expr);
+ ~PerFrameEqn();
- };
+ /// Evaluate the per frame equation
+ void evaluate();
+
+};
#endif /** !_PER_FRAME_EQN_H */
diff --git a/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.cpp b/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.cpp
index 3f7c7bd..8a0d760 100644
--- a/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.cpp
@@ -18,7 +18,6 @@
* See 'LICENSE.txt' included within this release
*
*/
-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -35,47 +34,48 @@
#include "wipemalloc.h"
#include <cassert>
-/* Evaluates a per pixel equation */
-void PerPixelEqn::evaluate(int mesh_i, int mesh_j) {
+
+/* Evaluates a per pixel equation */
+void
+PerPixelEqn::evaluate(int mesh_i, int mesh_j)
+{
GenExpr * eqn_ptr = 0;
- eqn_ptr = this->gen_expr;
+ eqn_ptr = this->gen_expr;
- float ** param_matrix = (float**)this->param->matrix;
+ float ** param_matrix = (float**)this->param->matrix;
- if (param_matrix == 0) {
- assert(param->engine_val);
- (*(float*)param->engine_val) = eqn_ptr->eval_gen_expr(mesh_i, mesh_j);
+ if (param_matrix == 0) {
+ assert(param->engine_val);
+ (*(float*)param->engine_val) = eqn_ptr->eval_gen_expr(mesh_i, mesh_j);
} else {
- assert(!(eqn_ptr == NULL || param_matrix == NULL));
+ assert(!(eqn_ptr == NULL || param_matrix == NULL));
- param_matrix[mesh_i][mesh_j] = eqn_ptr->eval_gen_expr(mesh_i, mesh_j);
+ param_matrix[mesh_i][mesh_j] = eqn_ptr->eval_gen_expr(mesh_i, mesh_j);
- /* Now that this parameter has been referenced with a per
- pixel equation, we let the evaluator know by setting
- this flag */
- /// @bug review and verify this behavior
- param->matrix_flag = true;
- param->flags |= P_FLAG_PER_PIXEL;
+ /* Now that this parameter has been referenced with a per
+ pixel equation, we let the evaluator know by setting
+ this flag */
+ /// @bug review and verify this behavior
+ param->matrix_flag = true;
+ param->flags |= P_FLAG_PER_PIXEL;
}
}
-PerPixelEqn::PerPixelEqn(int _index, Param * _param, GenExpr * _gen_expr):index(_index), param(_param), gen_expr(_gen_expr) {
-
- assert(index >= 0);
- assert(param != 0);
- assert(gen_expr != 0);
-
+PerPixelEqn::PerPixelEqn(int _index, Param * _param, GenExpr * _gen_expr):index(_index), param(_param), gen_expr(_gen_expr)
+{
+ assert(index >= 0);
+ assert(param != 0);
+ assert(gen_expr != 0);
}
PerPixelEqn::~PerPixelEqn()
{
- if (gen_expr)
- delete (gen_expr);
-
+ if (gen_expr)
+ delete (gen_expr);
}
diff --git a/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.hpp b/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.hpp
index 9410d76..95ad52e 100644
--- a/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/PerPixelEqn.hpp
@@ -25,7 +25,6 @@
*
* $Log$
*/
-
#ifndef _PER_PIXEL_EQN_H
#define _PER_PIXEL_EQN_H
@@ -43,6 +42,7 @@
#define WARP_OP 9
#define NUM_OPS 10 /* obviously, this number is dependent on the number of existing per pixel operations */
+
class GenExpr;
class Param;
class PerPixelEqn;
@@ -50,18 +50,18 @@
class PerPixelEqn {
public:
- int index; /* used for splay tree ordering. */
- int flags; /* primarily to specify if this variable is user-defined */
- Param *param;
- GenExpr *gen_expr;
+ int index; /* used for splay tree ordering. */
+ int flags; /* primarily to specify if this variable is user-defined */
+ Param *param;
+ GenExpr *gen_expr;
- void evalPerPixelEqns( Preset *preset );
- void evaluate(int mesh_i, int mesh_j);
- virtual ~PerPixelEqn();
+ void evalPerPixelEqns( Preset *preset );
+ void evaluate(int mesh_i, int mesh_j);
+ virtual ~PerPixelEqn();
- PerPixelEqn(int index, Param * param, GenExpr * gen_expr);
+ PerPixelEqn(int index, Param * param, GenExpr * gen_expr);
- };
+};
#endif /** !_PER_PIXEL_EQN_H */
diff --git a/src/libprojectM/MilkdropPresetFactory/PerPointEqn.cpp b/src/libprojectM/MilkdropPresetFactory/PerPointEqn.cpp
index e921916..eef886c 100644
--- a/src/libprojectM/MilkdropPresetFactory/PerPointEqn.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/PerPointEqn.cpp
@@ -18,7 +18,6 @@
* See 'LICENSE.txt' included within this release
*
*/
-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -37,11 +36,12 @@
#include <iostream>
#include "wipemalloc.h"
-/* Evaluates a per point equation for the current custom wave given by interface_wave ptr */
-void PerPointEqn::evaluate(int i)
-{
- float * param_matrix;
+/* Evaluates a per point equation for the current custom wave given by interface_wave ptr */
+void
+PerPointEqn::evaluate(int i)
+{
+ float * param_matrix;
GenExpr * eqn_ptr;
// samples = CustomWave::interface_wave->samples;
@@ -53,35 +53,30 @@
assert(param->matrix_flag == false);
(*(float*)param->engine_val) = eqn_ptr->eval_gen_expr(i,-1);
-
return;
}
-
else
{
param_matrix = (float*)param->matrix;
-
- // -1 is because per points only use one dimension
- param_matrix[i] = eqn_ptr->eval_gen_expr(i, -1);
-
+
+ // -1 is because per points only use one dimension
+ param_matrix[i] = eqn_ptr->eval_gen_expr(i, -1);
+
/* Now that this parameter has been referenced with a per
- point equation, we let the evaluator know by setting
- this flag */
+ point equation, we let the evaluator know by setting
+ this flag */
if (!param->matrix_flag)
param->matrix_flag = true;
-
}
-
}
-PerPointEqn::PerPointEqn(int _index, Param * _param, GenExpr * _gen_expr, int _samples):
- index(_index),
+PerPointEqn::PerPointEqn(int _index, Param * _param, GenExpr * _gen_expr, int _samples)
+ : index(_index),
samples(_samples),
param(_param),
gen_expr(_gen_expr)
-
{}
diff --git a/src/libprojectM/MilkdropPresetFactory/PerPointEqn.hpp b/src/libprojectM/MilkdropPresetFactory/PerPointEqn.hpp
index 90ba5ca..60b1a43 100644
--- a/src/libprojectM/MilkdropPresetFactory/PerPointEqn.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/PerPointEqn.hpp
@@ -25,10 +25,10 @@
*
* $Log$
*/
-
#ifndef _PER_POINT_EQN_H
#define _PER_POINT_EQN_H
+
class CustomWave;
class GenExpr;
class Param;
@@ -36,14 +36,14 @@
class PerPointEqn {
public:
- int index;
- int samples; // the number of samples to iterate over
- Param *param;
- GenExpr * gen_expr;
- ~PerPointEqn();
- void evaluate(int i);
- PerPointEqn( int index, Param *param, GenExpr *gen_expr, int samples);
- };
+ int index;
+ int samples; // the number of samples to iterate over
+ Param *param;
+ GenExpr * gen_expr;
+ ~PerPointEqn();
+ void evaluate(int i);
+ PerPointEqn( int index, Param *param, GenExpr *gen_expr, int samples);
+};
//inline void eval_per_point_eqn_helper( void *per_point_eqn ) {
diff --git a/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.cpp b/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.cpp
index 5a4c882..fa0986e 100644
--- a/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.cpp
+++ b/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.cpp
@@ -6,102 +6,103 @@
#include <cmath>
#include "Renderer/BeatDetect.hpp"
+
PresetInputs::PresetInputs() : PipelineContext()
{
}
-void PresetInputs::update(const BeatDetect & music, const PipelineContext & context) {
+void
+PresetInputs::update(const BeatDetect & music, const PipelineContext & context)
+{
- // Reflect new values form the beat detection unit
- this->bass = music.bass;
- this->mid = music.mid;
- this->treb = music.treb;
- this->bass_att = music.bass_att;
- this->mid_att = music.mid_att;
- this->treb_att = music.treb_att;
+ // Reflect new values form the beat detection unit
+ this->bass = music.bass;
+ this->mid = music.mid;
+ this->treb = music.treb;
+ this->bass_att = music.bass_att;
+ this->mid_att = music.mid_att;
+ this->treb_att = music.treb_att;
- // Reflect new values from the pipeline context
- this->fps = context.fps;
- this->time = context.time;
+ // Reflect new values from the pipeline context
+ this->fps = context.fps;
+ this->time = context.time;
- this->frame = context.frame;
- this->progress = context.progress;
+ this->frame = context.frame;
+ this->progress = context.progress;
}
-void PresetInputs::Initialize ( int gx, int gy )
+void
+PresetInputs::Initialize ( int gx, int gy )
{
- int x, y;
+ int x, y;
- this->gx =gx;
- this->gy= gy;
+ this->gx =gx;
+ this->gy= gy;
- /// @bug no clue if this block belongs here
- // ***
- progress = 0;
- frame = 1;
+ /// @bug no clue if this block belongs here
+ // ***
+ progress = 0;
+ frame = 1;
- x_per_pixel = 0;
- y_per_pixel = 0;
- rad_per_pixel = 0;
- ang_per_pixel = 0;
- // ***
+ x_per_pixel = 0;
+ y_per_pixel = 0;
+ rad_per_pixel = 0;
+ ang_per_pixel = 0;
+ // ***
- this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x <gx; x++ )
- {
- this->y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->rad_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->rad_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->theta_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x <gx; x++ )
- {
- this->theta_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
+ this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x <gx; x++ )
+ {
+ this->y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->rad_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->rad_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->theta_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x <gx; x++ )
+ {
+ this->theta_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
- this->origtheta= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->origtheta[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->origrad= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->origrad[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->origx= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->origx[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->origy= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->origy[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
+ this->origtheta= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->origtheta[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->origrad= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->origrad[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->origx= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->origx[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->origy= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->origy[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
- for ( x=0;x<gx;x++ )
- {
- for ( y=0;y<gy;y++ )
- {
- this->origx[x][y]=x/ ( float ) ( gx-1 );
- this->origy[x][y]=- ( ( y/ ( float ) ( gy-1 ) )-1 );
- this->origrad[x][y]=hypot ( ( this->origx[x][y]-.5 ) *2, ( this->origy[x][y]-.5 ) *2 ) * .7071067;
- this->origtheta[x][y]=atan2 ( ( ( this->origy[x][y]-.5 ) *2 ), ( ( this->origx[x][y]-.5 ) *2 ) );
- }
- }
-
-
-
+ for ( x=0;x<gx;x++ )
+ {
+ for ( y=0;y<gy;y++ )
+ {
+ this->origx[x][y]=x/ ( float ) ( gx-1 );
+ this->origy[x][y]=- ( ( y/ ( float ) ( gy-1 ) )-1 );
+ this->origrad[x][y]=hypot ( ( this->origx[x][y]-.5 ) *2, ( this->origy[x][y]-.5 ) *2 ) * .7071067;
+ this->origtheta[x][y]=atan2 ( ( ( this->origy[x][y]-.5 ) *2 ), ( ( this->origx[x][y]-.5 ) *2 ) );
+ }
+ }
}
PresetOutputs::PresetOutputs() : Pipeline()
@@ -109,341 +110,339 @@
PresetOutputs::~PresetOutputs()
{
- assert(this->gx > 0);
+ assert(this->gx > 0);
- for ( int x = 0; x < this->gx; x++ )
- {
- free(this->sx_mesh[x]);
- free(this->sy_mesh[x]);
- free(this->dy_mesh[x]);
- free(this->dx_mesh[x]);
- free(this->cy_mesh[x]);
- free(this->cx_mesh[x]);
+ for ( int x = 0; x < this->gx; x++ )
+ {
+ free (this->sx_mesh[x]);
+ free (this->sy_mesh[x]);
+ free (this->dy_mesh[x]);
+ free (this->dx_mesh[x]);
+ free (this->cy_mesh[x]);
+ free (this->cx_mesh[x]);
- free(this->warp_mesh[x]);
- free(this->zoom_mesh[x]);
- free(this->zoomexp_mesh[x]);
- free(this->rot_mesh[x]);
- free(this->orig_x[x]);
- free(this->orig_y[x]);
- free(this->rad_mesh[x]);
- }
+ free (this->warp_mesh[x]);
+ free (this->zoom_mesh[x]);
+ free (this->zoomexp_mesh[x]);
+ free (this->rot_mesh[x]);
+ free (this->orig_x[x]);
+ free (this->orig_y[x]);
+ free (this->rad_mesh[x]);
+ }
- free(this->rad_mesh);
- free(this->sx_mesh);
- free(this->sy_mesh);
- free(this->dy_mesh);
- free(this->dx_mesh);
- free(this->cy_mesh);
- free(this->cx_mesh);
- free(this->warp_mesh);
- free(this->zoom_mesh);
- free(this->zoomexp_mesh);
- free(this->rot_mesh);
- free(this->orig_x);
- free(this->orig_y);
+ free (this->rad_mesh);
+ free (this->sx_mesh);
+ free (this->sy_mesh);
+ free (this->dy_mesh);
+ free (this->dx_mesh);
+ free (this->cy_mesh);
+ free (this->cx_mesh);
+ free (this->warp_mesh);
+ free (this->zoom_mesh);
+ free (this->zoomexp_mesh);
+ free (this->rot_mesh);
+ free (this->orig_x);
+ free (this->orig_y);
}
-void PresetOutputs::Render(const BeatDetect &music, const PipelineContext &context)
+void
+PresetOutputs::Render(const BeatDetect &music, const PipelineContext &context)
{
- PerPixelMath(context);
+ PerPixelMath(context);
- drawables.clear();
+ drawables.clear();
- drawables.push_back(&mv);
+ drawables.push_back(&mv);
- for (PresetOutputs::cshape_container::iterator pos = customShapes.begin();
- pos != customShapes.end(); ++pos)
- {
- if( (*pos)->enabled==1) drawables.push_back((*pos));
- }
+ for (PresetOutputs::cshape_container::iterator pos = customShapes.begin();
+ pos != customShapes.end();
+ ++pos)
+ {
+ if( (*pos)->enabled==1) drawables.push_back((*pos));
+ }
- for (PresetOutputs::cwave_container::iterator pos = customWaves.begin();
- pos != customWaves.end(); ++pos)
- {
- if( (*pos)->enabled==1) drawables.push_back((*pos));
- }
+ for (PresetOutputs::cwave_container::iterator pos = customWaves.begin();
+ pos != customWaves.end();
+ ++pos)
+ {
+ if( (*pos)->enabled==1) drawables.push_back((*pos));
+ }
- drawables.push_back(&wave);
- if(bDarkenCenter==1) drawables.push_back(&darkenCenter);
- drawables.push_back(&border);
+ drawables.push_back(&wave);
+ if(bDarkenCenter==1) drawables.push_back(&darkenCenter);
+ drawables.push_back(&border);
- compositeDrawables.clear();
- compositeDrawables.push_back(&videoEcho);
+ compositeDrawables.clear();
+ compositeDrawables.push_back(&videoEcho);
- if (bBrighten==1)
- compositeDrawables.push_back(&brighten);
+ if (bBrighten==1)
+ compositeDrawables.push_back(&brighten);
- if (bDarken==1)
- compositeDrawables.push_back(&darken);
+ if (bDarken==1)
+ compositeDrawables.push_back(&darken);
- if (bSolarize==1)
- compositeDrawables.push_back(&solarize);
+ if (bSolarize==1)
+ compositeDrawables.push_back(&solarize);
- if (bInvert==1)
- compositeDrawables.push_back(&invert);
+ if (bInvert==1)
+ compositeDrawables.push_back(&invert);
}
-void PresetOutputs::PerPixelMath(const PipelineContext &context)
+void
+PresetOutputs::PerPixelMath(const PipelineContext &context)
{
+ int x, y;
+ float fZoom2, fZoom2Inv;
- int x, y;
- float fZoom2, fZoom2Inv;
+ for (x = 0; x < gx; x++)
+ {
+ for (y = 0; y < gy; y++)
+ {
+ fZoom2 = std::pow(this->zoom_mesh[x][y], std::pow(this->zoomexp_mesh[x][y],
+ rad_mesh[x][y] * 2.0f - 1.0f));
+ fZoom2Inv = 1.0f / fZoom2;
+ this->x_mesh[x][y] = this->orig_x[x][y] * 0.5f * fZoom2Inv + 0.5f;
+ this->y_mesh[x][y] = this->orig_y[x][y] * 0.5f * fZoom2Inv + 0.5f;
+ }
+ }
- for (x = 0; x < gx; x++)
- {
- for (y = 0; y < gy; y++)
- {
- fZoom2 = std::pow(this->zoom_mesh[x][y], std::pow(this->zoomexp_mesh[x][y],
- rad_mesh[x][y] * 2.0f - 1.0f));
- fZoom2Inv = 1.0f / fZoom2;
- this->x_mesh[x][y] = this->orig_x[x][y] * 0.5f * fZoom2Inv + 0.5f;
- this->y_mesh[x][y] = this->orig_y[x][y] * 0.5f * fZoom2Inv + 0.5f;
- }
- }
+ for (x = 0; x < gx; x++)
+ {
+ for (y = 0; y < gy; y++)
+ {
+ this->x_mesh[x][y] = (this->x_mesh[x][y] - this->cx_mesh[x][y])
+ / this->sx_mesh[x][y] + this->cx_mesh[x][y];
+ }
+ }
- for (x = 0; x < gx; x++)
- {
- for (y = 0; y < gy; y++)
- {
- this->x_mesh[x][y] = (this->x_mesh[x][y] - this->cx_mesh[x][y])
- / this->sx_mesh[x][y] + this->cx_mesh[x][y];
- }
- }
+ for (x = 0; x < gx; x++)
+ {
+ for (y = 0; y < gy; y++)
+ {
+ this->y_mesh[x][y] = (this->y_mesh[x][y] - this->cy_mesh[x][y])
+ / this->sy_mesh[x][y] + this->cy_mesh[x][y];
+ }
+ }
- for (x = 0; x < gx; x++)
- {
- for (y = 0; y < gy; y++)
- {
- this->y_mesh[x][y] = (this->y_mesh[x][y] - this->cy_mesh[x][y])
- / this->sy_mesh[x][y] + this->cy_mesh[x][y];
- }
- }
+ float fWarpTime = context.time * this->fWarpAnimSpeed;
+ float fWarpScaleInv = 1.0f / this->fWarpScale;
+ float f[4];
+ f[0] = 11.68f + 4.0f * cosf(fWarpTime * 1.413f + 10);
+ f[1] = 8.77f + 3.0f * cosf(fWarpTime * 1.113f + 7);
+ f[2] = 10.54f + 3.0f * cosf(fWarpTime * 1.233f + 3);
+ f[3] = 11.49f + 4.0f * cosf(fWarpTime * 0.933f + 5);
- float fWarpTime = context.time * this->fWarpAnimSpeed;
- float fWarpScaleInv = 1.0f / this->fWarpScale;
- float f[4];
- f[0] = 11.68f + 4.0f * cosf(fWarpTime * 1.413f + 10);
- f[1] = 8.77f + 3.0f * cosf(fWarpTime * 1.113f + 7);
- f[2] = 10.54f + 3.0f * cosf(fWarpTime * 1.233f + 3);
- f[3] = 11.49f + 4.0f * cosf(fWarpTime * 0.933f + 5);
+ for (x = 0; x < gx; x++)
+ {
+ for (y = 0; y < gy; y++)
+ {
+ this->x_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.333f
+ + fWarpScaleInv * (this->orig_x[x][y] * f[0] - this->orig_y[x][y] * f[3]));
+ this->y_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.375f
+ - fWarpScaleInv * (this->orig_x[x][y] * f[2] + this->orig_y[x][y] * f[1]));
+ this->x_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.753f
+ - fWarpScaleInv * (this->orig_x[x][y] * f[1] - this->orig_y[x][y] * f[2]));
+ this->y_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.825f
+ + fWarpScaleInv * (this->orig_x[x][y] * f[0] + this->orig_y[x][y] * f[3]));
+ }
+ }
+ for (x = 0; x < gx; x++)
+ {
+ for (y = 0; y < gy; y++)
+ {
+ float u2 = this->x_mesh[x][y] - this->cx_mesh[x][y];
+ float v2 = this->y_mesh[x][y] - this->cy_mesh[x][y];
- for (x = 0; x < gx; x++)
- {
- for (y = 0; y < gy; y++)
- {
- this->x_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.333f
- + fWarpScaleInv * (this->orig_x[x][y] * f[0] - this->orig_y[x][y] * f[3]));
- this->y_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.375f
- - fWarpScaleInv * (this->orig_x[x][y] * f[2] + this->orig_y[x][y] * f[1]));
- this->x_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * cosf(fWarpTime * 0.753f
- - fWarpScaleInv * (this->orig_x[x][y] * f[1] - this->orig_y[x][y] * f[2]));
- this->y_mesh[x][y] += this->warp_mesh[x][y] * 0.0035f * sinf(fWarpTime * 0.825f
- + fWarpScaleInv * (this->orig_x[x][y] * f[0] + this->orig_y[x][y] * f[3]));
- }
- }
- for (x = 0; x < gx; x++)
- {
- for (y = 0; y < gy; y++)
- {
- float u2 = this->x_mesh[x][y] - this->cx_mesh[x][y];
- float v2 = this->y_mesh[x][y] - this->cy_mesh[x][y];
+ float cos_rot = cosf(this->rot_mesh[x][y]);
+ float sin_rot = sinf(this->rot_mesh[x][y]);
- float cos_rot = cosf(this->rot_mesh[x][y]);
- float sin_rot = sinf(this->rot_mesh[x][y]);
+ this->x_mesh[x][y] = u2 * cos_rot - v2 * sin_rot + this->cx_mesh[x][y];
+ this->y_mesh[x][y] = u2 * sin_rot + v2 * cos_rot + this->cy_mesh[x][y];
+ }
+ }
- this->x_mesh[x][y] = u2 * cos_rot - v2 * sin_rot + this->cx_mesh[x][y];
- this->y_mesh[x][y] = u2 * sin_rot + v2 * cos_rot + this->cy_mesh[x][y];
+ for (x = 0; x < gx; x++)
+ for (y = 0; y < gy; y++)
+ this->x_mesh[x][y] -= this->dx_mesh[x][y];
- }
- }
-
- for (x = 0; x < gx; x++)
- for (y = 0; y < gy; y++)
- this->x_mesh[x][y] -= this->dx_mesh[x][y];
-
- for (x = 0; x < gx; x++)
- for (y = 0; y < gy; y++)
- this->y_mesh[x][y] -= this->dy_mesh[x][y];
-
+ for (x = 0; x < gx; x++)
+ for (y = 0; y < gy; y++)
+ this->y_mesh[x][y] -= this->dy_mesh[x][y];
}
-void PresetOutputs::Initialize ( int gx, int gy )
+void
+PresetOutputs::Initialize ( int gx, int gy )
{
+ assert(gx > 0);
+ this->gx = gx;
+ this->gy= gy;
- assert(gx > 0);
- this->gx = gx;
- this->gy= gy;
+ staticPerPixel = true;
+ setStaticPerPixel(gx,gy);
- staticPerPixel = true;
- setStaticPerPixel(gx,gy);
+ assert(this->gx > 0);
+ int x;
+ this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->sx_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->sx_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->sy_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->sy_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->dx_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->dx_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->dy_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->dy_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->cx_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->cx_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->cy_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->cy_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->zoom_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->zoom_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->zoomexp_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->zoomexp_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->rot_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->rot_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
- assert(this->gx > 0);
- int x;
- this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->sx_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->sx_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->sy_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->sy_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->dx_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->dx_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->dy_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->dy_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->cx_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->cx_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->cy_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->cy_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->zoom_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->zoom_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->zoomexp_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->zoomexp_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->rot_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->rot_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
+ this->warp_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->warp_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->rad_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( x = 0; x < gx; x++ )
+ {
+ this->rad_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->orig_x = (float **) wipemalloc(gx * sizeof(float *));
+ for (x = 0; x < gx; x++)
+ {
+ this->orig_x[x] = (float *) wipemalloc(gy * sizeof(float));
+ }
+ this->orig_y = (float **) wipemalloc(gx * sizeof(float *));
+ for (x = 0; x < gx; x++)
+ {
+ this->orig_y[x] = (float *) wipemalloc(gy * sizeof(float));
+ }
- this->warp_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->warp_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->rad_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( x = 0; x < gx; x++ )
- {
- this->rad_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->orig_x = (float **) wipemalloc(gx * sizeof(float *));
- for (x = 0; x < gx; x++)
- {
- this->orig_x[x] = (float *) wipemalloc(gy * sizeof(float));
- }
- this->orig_y = (float **) wipemalloc(gx * sizeof(float *));
- for (x = 0; x < gx; x++)
- {
- this->orig_y[x] = (float *) wipemalloc(gy * sizeof(float));
- }
+ //initialize reference grid values
+ for (x = 0; x < gx; x++)
+ {
+ for (int y = 0; y < gy; y++)
+ {
+ float origx = x / (float) (gx - 1);
+ float origy = -((y / (float) (gy - 1)) - 1);
- //initialize reference grid values
- for (x = 0; x < gx; x++)
- {
- for (int y = 0; y < gy; y++)
- {
- float origx = x / (float) (gx - 1);
- float origy = -((y / (float) (gy - 1)) - 1);
-
- rad_mesh[x][y]=hypot ( ( origx-.5 ) *2, ( origy-.5 ) *2 ) * .7071067;
- orig_x[x][y] = (origx - .5) * 2;
- orig_y[x][y] = (origy - .5) * 2;
- }
- }
+ rad_mesh[x][y]=hypot ( ( origx-.5 ) *2, ( origy-.5 ) *2 ) * .7071067;
+ orig_x[x][y] = (origx - .5) * 2;
+ orig_y[x][y] = (origy - .5) * 2;
+ }
+ }
}
PresetInputs::~PresetInputs()
{
- for ( int x = 0; x < this->gx; x++ )
- {
+ for ( int x = 0; x < this->gx; x++ )
+ {
+ free ( this->origtheta[x] );
+ free ( this->origrad[x] );
+ free ( this->origx[x] );
+ free ( this->origy[x] );
+
+ free ( this->x_mesh[x] );
+ free ( this->y_mesh[x] );
+ free ( this->rad_mesh[x] );
+ free ( this->theta_mesh[x] );
+ }
- free ( this->origtheta[x] );
- free ( this->origrad[x] );
- free ( this->origx[x] );
- free ( this->origy[x] );
+ free ( this->origx );
+ free ( this->origy );
+ free ( this->origrad );
+ free ( this->origtheta );
- free ( this->x_mesh[x] );
- free ( this->y_mesh[x] );
- free ( this->rad_mesh[x] );
- free ( this->theta_mesh[x] );
+ free ( this->x_mesh );
+ free ( this->y_mesh );
+ free ( this->rad_mesh );
+ free ( this->theta_mesh );
- }
+ this->origx = NULL;
+ this->origy = NULL;
+ this->origtheta = NULL;
+ this->origrad = NULL;
-
- free ( this->origx );
- free ( this->origy );
- free ( this->origrad );
- free ( this->origtheta );
-
- free ( this->x_mesh );
- free ( this->y_mesh );
- free ( this->rad_mesh );
- free ( this->theta_mesh );
-
- this->origx = NULL;
- this->origy = NULL;
- this->origtheta = NULL;
- this->origrad = NULL;
-
- this->x_mesh = NULL;
- this->y_mesh = NULL;
- this->rad_mesh = NULL;
- this->theta_mesh = NULL;
+ this->x_mesh = NULL;
+ this->y_mesh = NULL;
+ this->rad_mesh = NULL;
+ this->theta_mesh = NULL;
}
void PresetInputs::resetMesh()
{
- int x,y;
+ int x,y;
- assert ( x_mesh );
- assert ( y_mesh );
- assert ( rad_mesh );
- assert ( theta_mesh );
+ assert ( x_mesh );
+ assert ( y_mesh );
+ assert ( rad_mesh );
+ assert ( theta_mesh );
- for ( x=0;x<this->gx;x++ )
- {
- for ( y=0;y<this->gy;y++ )
- {
- x_mesh[x][y]=this->origx[x][y];
- y_mesh[x][y]=this->origy[x][y];
- rad_mesh[x][y]=this->origrad[x][y];
- theta_mesh[x][y]=this->origtheta[x][y];
- }
- }
-
+ for ( x=0;x<this->gx;x++ )
+ {
+ for ( y=0;y<this->gy;y++ )
+ {
+ x_mesh[x][y]=this->origx[x][y];
+ y_mesh[x][y]=this->origy[x][y];
+ rad_mesh[x][y]=this->origrad[x][y];
+ theta_mesh[x][y]=this->origtheta[x][y];
+ }
+ }
}
#ifdef USE_MERGE_PRESET_CODE
-void PresetMerger::MergePresets(PresetOutputs & A, PresetOutputs & B, double ratio, int gx, int gy)
+void
+PresetMerger::MergePresets(PresetOutputs & A, PresetOutputs & B, double ratio, int gx, int gy)
{
-double invratio = 1.0 - ratio;
+ double invratio = 1.0 - ratio;
//Merge Simple Waveforms
//
// All the mess is because of Waveform 7, which is two lines.
@@ -453,65 +452,69 @@
//Merge Custom Shapes and Custom Waves
for (PresetOutputs::cshape_container::iterator pos = A.customShapes.begin();
- pos != A.customShapes.end(); ++pos)
- {
- (*pos)->a *= invratio;
- (*pos)->a2 *= invratio;
- (*pos)->border_a *= invratio;
- }
+ pos != A.customShapes.end();
+ ++pos)
+ {
+ (*pos)->a *= invratio;
+ (*pos)->a2 *= invratio;
+ (*pos)->border_a *= invratio;
+ }
for (PresetOutputs::cshape_container::iterator pos = B.customShapes.begin();
- pos != B.customShapes.end(); ++pos)
- {
- (*pos)->a *= ratio;
- (*pos)->a2 *= ratio;
- (*pos)->border_a *= ratio;
+ pos != B.customShapes.end();
+ ++pos)
+ {
+ (*pos)->a *= ratio;
+ (*pos)->a2 *= ratio;
+ (*pos)->border_a *= ratio;
- A.customShapes.push_back(*pos);
+ A.customShapes.push_back(*pos);
+ }
- }
- for (PresetOutputs::cwave_container::iterator pos = A.customWaves.begin();
- pos != A.customWaves.end(); ++pos)
+ for (PresetOutputs::cwave_container::iterator pos = A.customWaves.begin();
+ pos != A.customWaves.end();
+ ++pos)
+ {
+ (*pos)->a *= invratio;
+ for (int x=0; x < (*pos)->samples; x++)
{
- (*pos)->a *= invratio;
- for (int x=0; x < (*pos)->samples; x++)
- {
- (*pos)->a_mesh[x]= (*pos)->a_mesh[x]*invratio;
- }
+ (*pos)->a_mesh[x]= (*pos)->a_mesh[x]*invratio;
}
+ }
for (PresetOutputs::cwave_container::iterator pos = B.customWaves.begin();
- pos != B.customWaves.end(); ++pos)
+ pos != B.customWaves.end();
+ ++pos)
+ {
+ (*pos)->a *= ratio;
+ for (int x=0; x < (*pos)->samples; x++)
{
- (*pos)->a *= ratio;
- for (int x=0; x < (*pos)->samples; x++)
- {
- (*pos)->a_mesh[x]= (*pos)->a_mesh[x]*ratio;
- }
- A.customWaves.push_back(*pos);
+ (*pos)->a_mesh[x]= (*pos)->a_mesh[x]*ratio;
}
+ A.customWaves.push_back(*pos);
+ }
//Interpolate Per-Pixel mesh
for (int x=0;x<gx;x++)
+ {
+ for(int y=0;y<gy;y++)
{
- for(int y=0;y<gy;y++)
- {
- A.x_mesh[x][y] = A.x_mesh[x][y]* invratio + B.x_mesh[x][y]*ratio;
- }
+ A.x_mesh[x][y] = A.x_mesh[x][y]* invratio + B.x_mesh[x][y]*ratio;
}
- for (int x=0;x<gx;x++)
+ }
+ for (int x=0;x<gx;x++)
+ {
+ for(int y=0;y<gy;y++)
{
- for(int y=0;y<gy;y++)
- {
- A.y_mesh[x][y] = A.y_mesh[x][y]* invratio + B.y_mesh[x][y]*ratio;
- }
+ A.y_mesh[x][y] = A.y_mesh[x][y]* invratio + B.y_mesh[x][y]*ratio;
}
+ }
- //Interpolate PerFrame floats
+ //Interpolate PerFrame floats
A.screenDecay = A.screenDecay * invratio + B.screenDecay * ratio;
@@ -559,17 +562,17 @@
//Switch bools and discrete values halfway. Maybe we should do some interesting stuff here.
if (ratio > 0.5)
- {
- A.videoEcho.orientation = B.videoEcho.orientation;
- A.textureWrap = B.textureWrap;
- A.bDarkenCenter = B.bDarkenCenter;
- A.bRedBlueStereo = B.bRedBlueStereo;
- A.bBrighten = B.bBrighten;
- A.bDarken = B.bDarken;
- A.bSolarize = B.bSolarize;
- A.bInvert = B.bInvert;
- A.bMotionVectorsOn = B.bMotionVectorsOn;
- }
+ {
+ A.videoEcho.orientation = B.videoEcho.orientation;
+ A.textureWrap = B.textureWrap;
+ A.bDarkenCenter = B.bDarkenCenter;
+ A.bRedBlueStereo = B.bRedBlueStereo;
+ A.bBrighten = B.bBrighten;
+ A.bDarken = B.bDarken;
+ A.bSolarize = B.bSolarize;
+ A.bInvert = B.bInvert;
+ A.bMotionVectorsOn = B.bMotionVectorsOn;
+ }
return;
}
diff --git a/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.hpp b/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.hpp
index 229879c..9b7a5a4 100644
--- a/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.hpp
+++ b/src/libprojectM/MilkdropPresetFactory/PresetFrameIO.hpp
@@ -1,5 +1,6 @@
#ifndef PRESET_FRAME_IO_HPP
#define PRESET_FRAME_IO_HPP
+
#include <vector>
#include "Renderer/MilkdropWaveform.hpp"
#include "Renderer/Pipeline.hpp"
@@ -14,51 +15,51 @@
class PresetInputs : public PipelineContext {
public:
- /* PER_PIXEL VARIBLES BEGIN */
+ /* PER_PIXEL VARIBLES BEGIN */
- float x_per_pixel;
- float y_per_pixel;
- float rad_per_pixel;
- float ang_per_pixel;
+ float x_per_pixel;
+ float y_per_pixel;
+ float rad_per_pixel;
+ float ang_per_pixel;
- /* PER_PIXEL VARIBLES END */
+ /* PER_PIXEL VARIBLES END */
- float bass;
- float mid;
- float treb;
- float bass_att;
- float mid_att;
- float treb_att;
+ float bass;
+ float mid;
+ float treb;
+ float bass_att;
+ float mid_att;
+ float treb_att;
- /* variables were added in milkdrop 1.04 */
- int gx, gy;
+ /* variables were added in milkdrop 1.04 */
+ int gx, gy;
- float **x_mesh;
- float **y_mesh;
- float **rad_mesh;
- float **theta_mesh;
+ float **x_mesh;
+ float **y_mesh;
+ float **rad_mesh;
+ float **theta_mesh;
- float **origtheta; //grid containing interpolated mesh reference values
- float **origrad;
- float **origx; //original mesh
- float **origy;
+ float **origtheta; //grid containing interpolated mesh reference values
+ float **origrad;
+ float **origx; //original mesh
+ float **origy;
- void resetMesh();
+ void resetMesh();
- ~PresetInputs();
- PresetInputs();
+ ~PresetInputs();
+ PresetInputs();
- /// Initializes this preset inputs given a mesh size.
- /// \param gx the width of the mesh
- /// \param gy the height of the mesh
- /// \note This must be called before reading values from this class
- void Initialize(int gx, int gy);
+ /// Initializes this preset inputs given a mesh size.
+ /// \param gx the width of the mesh
+ /// \param gy the height of the mesh
+ /// \note This must be called before reading values from this class
+ void Initialize(int gx, int gy);
- /// Updates this preset inputs with the latest values from the
- /// the pipeline context and beat detection unit
- void update (const BeatDetect & music, const PipelineContext & context);
+ /// Updates this preset inputs with the latest values from the
+ /// the pipeline context and beat detection unit
+ void update (const BeatDetect & music, const PipelineContext & context);
- private:
+private:
};
@@ -67,77 +68,77 @@
/// Every preset object needs a reference to one of these.
class PresetOutputs : public Pipeline {
public:
- typedef std::vector<CustomWave*> cwave_container;
- typedef std::vector<CustomShape*> cshape_container;
+ typedef std::vector<CustomWave*> cwave_container;
+ typedef std::vector<CustomShape*> cshape_container;
- cwave_container customWaves;
- cshape_container customShapes;
+ cwave_container customWaves;
+ cshape_container customShapes;
- void Initialize(int gx, int gy);
- PresetOutputs();
- ~PresetOutputs();
- virtual void Render(const BeatDetect &music, const PipelineContext &context);
- void PerPixelMath( const PipelineContext &context);
- /* PER FRAME VARIABLES BEGIN */
+ void Initialize(int gx, int gy);
+ PresetOutputs();
+ ~PresetOutputs();
+ virtual void Render(const BeatDetect &music, const PipelineContext &context);
+ void PerPixelMath( const PipelineContext &context);
+ /* PER FRAME VARIABLES BEGIN */
- float zoom;
- float zoomexp;
- float rot;
- float warp;
+ float zoom;
+ float zoomexp;
+ float rot;
+ float warp;
- float sx;
- float sy;
- float dx;
- float dy;
- float cx;
- float cy;
+ float sx;
+ float sy;
+ float dx;
+ float dy;
+ float cx;
+ float cy;
- VideoEcho videoEcho;
+ VideoEcho videoEcho;
- MilkdropWaveform wave;
- Border border;
- MotionVectors mv;
- DarkenCenter darkenCenter;
+ MilkdropWaveform wave;
+ Border border;
+ MotionVectors mv;
+ DarkenCenter darkenCenter;
- Brighten brighten;
- Darken darken;
- Invert invert;
- Solarize solarize;
+ Brighten brighten;
+ Darken darken;
+ Invert invert;
+ Solarize solarize;
- int gy,gx;
- /* PER_FRAME VARIABLES END */
+ int gy,gx;
+ /* PER_FRAME VARIABLES END */
- float fRating;
- float fGammaAdj;
+ float fRating;
+ float fGammaAdj;
- bool bDarkenCenter;
- bool bRedBlueStereo;
- bool bBrighten;
- bool bDarken;
- bool bSolarize;
- bool bInvert;
- bool bMotionVectorsOn;
+ bool bDarkenCenter;
+ bool bRedBlueStereo;
+ bool bBrighten;
+ bool bDarken;
+ bool bSolarize;
+ bool bInvert;
+ bool bMotionVectorsOn;
- float fWarpAnimSpeed;
- float fWarpScale;
- float fShader;
+ float fWarpAnimSpeed;
+ float fWarpScale;
+ float fShader;
- float **zoom_mesh;
- float **zoomexp_mesh;
- float **rot_mesh;
+ float **zoom_mesh;
+ float **zoomexp_mesh;
+ float **rot_mesh;
- float **sx_mesh;
- float **sy_mesh;
- float **dx_mesh;
- float **dy_mesh;
- float **cx_mesh;
- float **cy_mesh;
- float **warp_mesh;
+ float **sx_mesh;
+ float **sy_mesh;
+ float **dx_mesh;
+ float **dy_mesh;
+ float **cx_mesh;
+ float **cy_mesh;
+ float **warp_mesh;
- float **orig_x; //original mesh
- float **orig_y;
- float **rad_mesh;
+ float **orig_x; //original mesh
+ float **orig_y;
+ float **rad_mesh;
};
diff --git a/src/libprojectM/PCM.cpp b/src/libprojectM/PCM.cpp
index 5ce9d9a..1caebd4 100644
--- a/src/libprojectM/PCM.cpp
+++ b/src/libprojectM/PCM.cpp
@@ -1,6 +1,6 @@
/**
* projectM -- Milkdrop-esque visualisation SDK
- * Copyright (C)2003-2004 projectM Team
+ * Copyright (C) 2003-2004 projectM Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -24,7 +24,6 @@
* Takes sound data from wherever and hands it back out.
* Returns PCM Data or spectrum data, or the derivative of the PCM data
*/
-
#include <stdlib.h>
#include <stdio.h>
@@ -33,225 +32,234 @@
#include "fftsg.h"
#include "PCM.hpp"
#include <cassert>
+#include <iostream>
+
int PCM::maxsamples = 2048;
-//initPCM(int samples)
+
+//initPCM (int samples)
//
//Initializes the PCM buffer to
// number of samples specified.
-#include <iostream>
-PCM::PCM() {
- initPCM( 2048 );
- #ifdef DEBUG
- std::cerr << "[PCM] MAX SAMPLES:" << maxsamples << std::endl;
- #endif
- }
+PCM::PCM ()
+{
+ initPCM (2048);
-void PCM::initPCM(int samples) {
+#ifdef DEBUG
+ std::cerr << "[PCM] MAX SAMPLES:" << maxsamples << std::endl;
+#endif
+}
+
+void
+PCM::initPCM (int samples)
+{
int i;
- waveSmoothing = 0;
+ waveSmoothing = 0;
//Allocate memory for PCM data buffer
- assert(samples == 2048);
- PCMd = (float **)wipemalloc(2 * sizeof(float *));
- PCMd[0] = (float *)wipemalloc(samples * sizeof(float));
- PCMd[1] = (float *)wipemalloc(samples * sizeof(float));
+ assert (samples == 2048);
+ PCMd = (float **) wipemalloc (2 * sizeof (float *));
+ PCMd[0] = (float *) wipemalloc (samples * sizeof (float));
+ PCMd[1] = (float *) wipemalloc (samples * sizeof (float));
//maxsamples=samples;
- newsamples=0;
- numsamples = maxsamples;
+ newsamples = 0;
+ numsamples = maxsamples;
//Initialize buffers to 0
- for (i=0;i<samples;i++)
- {
- PCMd[0][i]=0;
- PCMd[1][i]=0;
- }
+ for (i = 0; i < samples; i++) {
+ PCMd[0][i] =
+ PCMd[1][i] = 0;
+ }
- start=0;
+ start = 0;
//Allocate FFT workspace
- w= (double *)wipemalloc(maxsamples*sizeof(double));
- ip= (int *)wipemalloc(maxsamples*sizeof(int));
- ip[0]=0;
+ w = (double *) wipemalloc (maxsamples * sizeof (double));
+ ip = (int *) wipemalloc (maxsamples * sizeof (int));
+ ip[0] = 0;
- /** PCM data */
-// this->maxsamples = 2048;
-// this->numsamples = 0;
-// this->pcmdataL = NULL;
-// this->pcmdataR = NULL;
+ /** PCM data */
+ // this->maxsamples = 2048;
+ // this->numsamples = 0;
+ // this->pcmdataL = NULL;
+ // this->pcmdataR = NULL;
- /** Allocate PCM data structures */
- pcmdataL=(float *)wipemalloc(this->maxsamples*sizeof(float));
- pcmdataR=(float *)wipemalloc(this->maxsamples*sizeof(float));
+ /** Allocate PCM data structures */
+ pcmdataL = (float *) wipemalloc (this->maxsamples * sizeof (float));
+ pcmdataR = (float *) wipemalloc (this->maxsamples * sizeof (float));
}
-PCM::~PCM() {
-
- free(pcmdataL);
- free(pcmdataR);
- free(w);
- free(ip);
-
- free(PCMd[0]);
- free(PCMd[1]);
- free(PCMd);
-
-}
-
-#include <iostream>
-
-void PCM::addPCMfloat(const float *PCMdata, int samples)
+PCM::~PCM ()
{
- int i,j;
+ free (pcmdataL);
+ free (pcmdataR);
+ free (w);
+ free (ip);
- for(i=0;i<samples;i++)
- {
- j=i+start;
+ free (PCMd[0]);
+ free (PCMd[1]);
+ free (PCMd);
+}
- if (PCMdata[i] != 0 ) {
- PCMd[0][j%maxsamples] = PCMdata[i];
- PCMd[1][j%maxsamples] = PCMdata[i];
+void
+PCM::addPCMfloat (const float *PCMdata, int samples)
+{
+ int i, j;
- }
- else
- {
- PCMd[0][j % maxsamples] = 0;
- PCMd[1][j % maxsamples] = 0;
- }
+ for (i = 0; i < samples; i++)
+ {
+ j = i + start;
+
+ if (PCMdata[i] != 0 ) {
+ PCMd[0][j % maxsamples] = PCMdata[i];
+ PCMd[1][j % maxsamples] = PCMdata[i];
+ } else {
+ PCMd[0][j % maxsamples] = 0;
+ PCMd[1][j % maxsamples] = 0;
}
+ }
- start+=samples;
- start=start%maxsamples;
+ start += samples;
+ start = start % maxsamples;
- newsamples+=samples;
- if (newsamples>maxsamples) newsamples=maxsamples;
- numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0);
- getPCMnew(pcmdataL,0,0,waveSmoothing,0,1);
- getPCM(vdataL,512,0,1,0,0);
- getPCM(vdataR,512,1,1,0,0);
+ newsamples += samples;
+ if (newsamples > maxsamples)
+ newsamples = maxsamples;
+
+ numsamples = getPCMnew (pcmdataR, 1, 0, waveSmoothing, 0, 0);
+ getPCMnew (pcmdataL, 0, 0, waveSmoothing, 0, 1);
+ getPCM (vdataL, 512, 0, 1, 0, 0);
+ getPCM (vdataR, 512, 1, 1, 0, 0);
}
-void PCM::addPCM16Data(const short* pcm_data, short samples) {
- int i, j;
-
- for (i = 0; i < samples; ++i) {
- j=i+start;
- PCMd[0][j % maxsamples]=(pcm_data[i * 2 + 0]/16384.0);
- PCMd[1][j % maxsamples]=(pcm_data[i * 2 + 1]/16384.0);
- }
-
- start = (start + samples) % maxsamples;
-
- newsamples+=samples;
- if (newsamples>maxsamples) newsamples=maxsamples;
- numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0);
- getPCMnew(pcmdataL,0,0,waveSmoothing,0,1);
- getPCM(vdataL,512,0,1,0,0);
- getPCM(vdataR,512,1,1,0,0);
-}
-
-
-void PCM::addPCM16(short PCMdata[2][512])
+void
+PCM::addPCM16Data (const short* pcm_data, short samples)
{
- int i,j;
+ int i, j;
+
+ for (i = 0; i < samples; ++i) {
+ j = i + start;
+ PCMd[0][j % maxsamples] = (pcm_data[i * 2 + 0] / 16384.0);
+ PCMd[1][j % maxsamples] = (pcm_data[i * 2 + 1] / 16384.0);
+ }
+
+ start = (start + samples) % maxsamples;
+
+ newsamples += samples;
+ if (newsamples > maxsamples)
+ newsamples = maxsamples;
+
+ numsamples = getPCMnew (pcmdataR, 1, 0, waveSmoothing, 0, 0);
+ getPCMnew (pcmdataL, 0, 0, waveSmoothing, 0, 1);
+ getPCM (vdataL, 512, 0, 1, 0, 0);
+ getPCM (vdataR, 512, 1, 1, 0, 0);
+}
+
+
+void
+PCM::addPCM16 (short PCMdata[2][512])
+{
+ int i, j;
int samples=512;
- for(i=0;i<samples;i++)
- {
- j=i+start;
- if ( PCMdata[0][i] != 0 && PCMdata[1][i] != 0 ) {
- PCMd[0][j%maxsamples]=(PCMdata[0][i]/16384.0);
- PCMd[1][j%maxsamples]=(PCMdata[1][i]/16384.0);
- } else {
- PCMd[0][j % maxsamples] = (float)0;
- PCMd[1][j % maxsamples] = (float)0;
- }
- }
+ for (i = 0; i < samples; i++) {
+ j = i + start;
+ if (PCMdata[0][i] != 0 && PCMdata[1][i] != 0) {
+ PCMd[0][j % maxsamples] = (PCMdata[0][i] / 16384.0);
+ PCMd[1][j % maxsamples] = (PCMdata[1][i] / 16384.0);
+ } else {
+ PCMd[0][j % maxsamples] = (float) 0;
+ PCMd[1][j % maxsamples] = (float) 0;
+ }
+ }
- // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]);
+ // printf ("Added %d samples %d %d %f\n", samples, start,(start+samples)%maxsamples, PCM[0][start+10]);
- start+=samples;
- start=start%maxsamples;
+ start += samples;
+ start = start % maxsamples;
- newsamples+=samples;
- if (newsamples>maxsamples) newsamples=maxsamples;
+ newsamples += samples;
+ if (newsamples > maxsamples)
+ newsamples = maxsamples;
- numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0);
- getPCMnew(pcmdataL,0,0,waveSmoothing,0,1);
- getPCM(vdataL,512,0,1,0,0);
- getPCM(vdataR,512,1,1,0,0);
+ numsamples = getPCMnew (pcmdataR, 1, 0, waveSmoothing, 0, 0);
+ getPCMnew (pcmdataL, 0, 0, waveSmoothing, 0, 1);
+ getPCM (vdataL, 512, 0, 1, 0, 0);
+ getPCM (vdataR, 512, 1, 1, 0, 0);
}
-void PCM::addPCM8( unsigned char PCMdata[2][1024])
+void
+PCM::addPCM8 (unsigned char PCMdata[2][1024])
{
- int i,j;
- int samples=1024;
+ int i, j;
+ int samples = 1024;
+
+ for (i = 0; i < samples; i++) {
+ j = i + start;
+ if (PCMdata[0][i] != 0 && PCMdata[1][i] != 0) {
+ PCMd[0][j % maxsamples] = ((float) (PCMdata[0][i] - 128.0) / 64);
+ PCMd[1][j % maxsamples] = ((float) (PCMdata[1][i] - 128.0) / 64);
+ } else {
+ PCMd[0][j % maxsamples] = 0;
+ PCMd[1][j % maxsamples] = 0;
+ }
+ }
- for(i=0;i<samples;i++)
- {
- j=i+start;
- if ( PCMdata[0][i] != 0 && PCMdata[1][i] != 0 ) {
- PCMd[0][j%maxsamples]=( (float)( PCMdata[0][i] - 128.0 ) / 64 );
- PCMd[1][j%maxsamples]=( (float)( PCMdata[1][i] - 128.0 ) / 64 );
- } else {
- PCMd[0][j % maxsamples] = 0;
- PCMd[1][j % maxsamples] = 0;
- }
- }
+ // printf ("Added %d samples %d %d %f\n", samples, start,(start+samples)%maxsamples, PCM[0][start+10]);
+ start += samples;
+ start = start % maxsamples;
- // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]);
+ newsamples += samples;
+ if (newsamples > maxsamples)
+ newsamples = maxsamples;
- start+=samples;
- start=start%maxsamples;
-
- newsamples+=samples;
- if (newsamples>maxsamples) newsamples=maxsamples;
- numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0);
- getPCMnew(pcmdataL,0,0,waveSmoothing,0,1);
- getPCM(vdataL,512,0,1,0,0);
- getPCM(vdataR,512,1,1,0,0);
+ numsamples = getPCMnew (pcmdataR, 1, 0, waveSmoothing, 0, 0);
+ getPCMnew (pcmdataL, 0, 0, waveSmoothing, 0, 1);
+ getPCM (vdataL, 512, 0, 1, 0, 0);
+ getPCM (vdataR, 512, 1, 1, 0, 0);
}
-void PCM::addPCM8_512( const unsigned char PCMdata[2][512])
+void
+PCM::addPCM8_512 (const unsigned char PCMdata[2][512])
{
- int i,j;
- int samples=512;
+ int i, j;
+ int samples = 512;
+
+ for (i = 0; i < samples; i++) {
+ j = i + start;
+ if (PCMdata[0][i] != 0 && PCMdata[1][i] != 0) {
+ PCMd[0][j % maxsamples] = ((float) (PCMdata[0][i] - 128.0) / 64);
+ PCMd[1][j % maxsamples] = ((float) (PCMdata[1][i] - 128.0) / 64);
+ } else {
+ PCMd[0][j % maxsamples] = 0;
+ PCMd[1][j % maxsamples] = 0;
+ }
+ }
- for(i=0;i<samples;i++)
- {
- j=i+start;
- if ( PCMdata[0][i] != 0 && PCMdata[1][i] != 0 ) {
- PCMd[0][j%maxsamples]=( (float)( PCMdata[0][i] - 128.0 ) / 64 );
- PCMd[1][j%maxsamples]=( (float)( PCMdata[1][i] - 128.0 ) / 64 );
- } else {
- PCMd[0][j % maxsamples] = 0;
- PCMd[1][j % maxsamples] = 0;
- }
- }
+ // printf ("Added %d samples %d %d %f\n", samples, start,(start+samples)%maxsamples, PCM[0][start+10]);
+ start += samples;
+ start = start % maxsamples;
- // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]);
+ newsamples += samples;
+ if (newsamples > maxsamples)
+ newsamples = maxsamples;
- start+=samples;
- start=start%maxsamples;
-
- newsamples+=samples;
- if (newsamples>maxsamples) newsamples=maxsamples;
- numsamples = getPCMnew(pcmdataR,1,0,waveSmoothing,0,0);
- getPCMnew(pcmdataL,0,0,waveSmoothing,0,1);
- getPCM(vdataL,512,0,1,0,0);
- getPCM(vdataR,512,1,1,0,0);
+ numsamples = getPCMnew (pcmdataR, 1, 0, waveSmoothing, 0, 0);
+ getPCMnew (pcmdataL, 0, 0, waveSmoothing, 0, 1);
+ getPCM (vdataL, 512, 0, 1, 0, 0);
+ getPCM (vdataR, 512, 1, 1, 0, 0);
}
@@ -264,46 +272,54 @@
//returned values are normalized from -1 to 1
-void PCM::getPCM(float *PCMdata, int samples, int channel, int freq, float smoothing, int derive)
+void
+PCM::getPCM (
+float *PCMdata,
+int samples,
+int channel,
+int freq,
+float smoothing,
+int derive
+)
{
- int i,index;
+ int i, index;
- index=start-1;
+ index = start - 1;
- if (index<0) index=maxsamples+index;
+ if (index < 0)
+ index = maxsamples + index;
- PCMdata[0]=PCMd[channel][index];
+ PCMdata[0] = PCMd[channel][index];
- for(i=1;i<samples;i++)
- {
- index=start-1-i;
- if (index<0) index=maxsamples+index;
+ for (i = 1; i < samples; i++) {
+ index = start - 1 - i;
+ if (index < 0)
+ index = maxsamples + index;
- PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1];
- }
+ PCMdata[i] = (1 - smoothing) * PCMd[channel][index]
+ + smoothing * PCMdata[i - 1];
+ }
- //return derivative of PCM data
- if(derive)
- {
- for(i=0;i<samples-1;i++)
- {
- PCMdata[i]=PCMdata[i]-PCMdata[i+1];
- }
- PCMdata[samples-1]=0;
- }
+ //return derivative of PCM data
+ if (derive) {
+ for (i = 0; i < samples - 1; i++) {
+ PCMdata[i] = PCMdata[i] - PCMdata[i + 1];
+ }
+ PCMdata[samples-1] = 0;
+ }
- //return frequency data instead of PCM (perform FFT)
+ //return frequency data instead of PCM (perform FFT)
- if (freq)
+ if (freq) {
+ double temppcm[1024];
- {
- double temppcm[1024];
- for (int i=0;i<samples;i++)
- {temppcm[i]=(double)PCMdata[i];}
- rdft(samples, 1, temppcm, ip, w);
- for (int j=0;j<samples;j++)
- {PCMdata[j]=(float)temppcm[j];}
- }
+ for (int i = 0; i < samples; i++)
+ {temppcm[i] = (double) PCMdata[i];}
+
+ rdft (samples, 1, temppcm, ip, w);
+ for (int j = 0; j < samples; j++)
+ {PCMdata[j] = (float) temppcm[j];}
+ }
}
//getPCMnew
@@ -311,49 +327,59 @@
//Like getPCM except it returns all new samples in the buffer
//the actual return value is the number of samples, up to maxsamples.
//the passed pointer, PCMData, must bee able to hold up to maxsamples
-
-int PCM::getPCMnew(float *PCMdata, int channel, int freq, float smoothing, int derive, int reset)
+//
+int
+PCM::getPCMnew (
+float *PCMdata,
+int channel,
+int freq,
+float smoothing,
+int derive,
+int reset
+)
{
- int i,index;
+ int i, index;
- index=start-1;
+ index = start - 1;
- if (index<0) index=maxsamples+index;
+ if (index < 0)
+ index = maxsamples + index;
- PCMdata[0]=PCMd[channel][index];
- for(i=1;i<newsamples;i++)
- {
- index=start-1-i;
- if (index<0) index=maxsamples+index;
+ PCMdata[0] = PCMd[channel][index];
+ for (i = 1; i < newsamples; i++) {
+ index = start - 1 - i;
+ if (index < 0)
+ index = maxsamples + index;
- PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1];
- }
+ PCMdata[i] = (1 - smoothing) * PCMd[channel][index]
+ + smoothing * PCMdata[i-1];
+ }
- //return derivative of PCM data
- if(derive)
- {
- for(i=0;i<newsamples-1;i++)
- {
- PCMdata[i]=PCMdata[i]-PCMdata[i+1];
- }
- PCMdata[newsamples-1]=0;
- }
+ //return derivative of PCM data
+ if (derive) {
+ for (i = 0; i < newsamples - 1; i++) {
+ PCMdata[i] = PCMdata[i] - PCMdata[i + 1];
+ }
+ PCMdata[newsamples-1] = 0;
+ }
- //return frequency data instead of PCM (perform FFT)
- // if (freq) rdft(samples, 1, PCMdata, ip, w);
- i=newsamples;
- if (reset) newsamples=0;
+ //return frequency data instead of PCM (perform FFT)
+ // if (freq) rdft (samples, 1, PCMdata, ip, w);
+ i = newsamples;
+ if (reset) newsamples = 0;
- return i;
+ return i;
}
//Free stuff
-void PCM::freePCM() {
- free(PCMd[0]);
- free(PCMd[1]);
- free(PCMd);
- free(ip);
- free(w);
+void
+PCM::freePCM ()
+{
+ free (PCMd[0]);
+ free (PCMd[1]);
+ free (PCMd);
+ free (ip);
+ free (w);
PCMd = NULL;
ip = NULL;
diff --git a/src/libprojectM/PCM.hpp b/src/libprojectM/PCM.hpp
index 5888e84..92330a6 100644
--- a/src/libprojectM/PCM.hpp
+++ b/src/libprojectM/PCM.hpp
@@ -29,46 +29,47 @@
#ifndef _PCM_H
#define _PCM_H
+
#include "dlldefs.h"
+
class
#ifdef WIN32
DLLEXPORT
#endif
PCM {
public:
- float **PCMd;
- int start;
+ float **PCMd;
+ int start;
- /** Use wave smoothing */
- float waveSmoothing;
+ /** Use wave smoothing */
+ float waveSmoothing;
- int *ip;
- double *w;
- int newsamples;
+ int *ip;
+ double *w;
+ int newsamples;
- int numsamples; //size of new PCM info
- float *pcmdataL; //holder for most recent pcm data
- float *pcmdataR; //holder for most recent pcm data
+ int numsamples; //size of new PCM info
+ float *pcmdataL; //holder for most recent pcm data
+ float *pcmdataR; //holder for most recent pcm data
- /** PCM data */
- float vdataL[512]; //holders for FFT data (spectrum)
- float vdataR[512];
+ /** PCM data */
+ float vdataL[512]; //holders for FFT data (spectrum)
+ float vdataR[512];
- static int maxsamples;
- PCM();
- ~PCM();
- void initPCM(int maxsamples);
- void addPCMfloat(const float *PCMdata, int samples);
- void addPCM16(short [2][512]);
- void addPCM16Data(const short* pcm_data, short samples);
- void addPCM8( unsigned char [2][1024]);
- void addPCM8_512( const unsigned char [2][512]);
- void getPCM(float *data, int samples, int channel, int freq, float smoothing, int derive);
- void freePCM();
- int getPCMnew(float *PCMdata, int channel, int freq, float smoothing, int derive,int reset);
+ static int maxsamples;
-
- };
+ PCM();
+ ~PCM();
+ void initPCM (int maxsamples);
+ void addPCMfloat (const float *PCMdata, int samples);
+ void addPCM16 (short [2][512]);
+ void addPCM16Data (const short* pcm_data, short samples);
+ void addPCM8 (unsigned char [2][1024]);
+ void addPCM8_512 (const unsigned char [2][512]);
+ void getPCM (float *data, int samples, int channel, int freq, float smoothing, int derive);
+ void freePCM ();
+ int getPCMnew (float *PCMdata, int channel, int freq, float smoothing, int derive,int reset);
+};
#endif /** !_PCM_H */
diff --git a/src/libprojectM/PipelineMerger.cpp b/src/libprojectM/PipelineMerger.cpp
index 56640c9..ffb7be2 100644
--- a/src/libprojectM/PipelineMerger.cpp
+++ b/src/libprojectM/PipelineMerger.cpp
@@ -2,122 +2,134 @@
#include "RenderItemMatcher.hpp"
#include "RenderItemMergeFunction.hpp"
+
+/* FIXME: Use math.h constants. */
const double PipelineMerger::e(2.71828182845904523536);
const double PipelineMerger::s(0.5);
-void PipelineMerger::mergePipelines(const Pipeline & a, const Pipeline & b, Pipeline & out, RenderItemMatcher::MatchResults & results, RenderItemMergeFunction & mergeFunction, float ratio)
+void
+PipelineMerger::mergePipelines (
+const Pipeline &a,
+const Pipeline &b,
+Pipeline &out,
+RenderItemMatcher::MatchResults &results,
+RenderItemMergeFunction &mergeFunction,
+float ratio
+)
{
+ const double x = (ratio - 0.5) * 20;
+ const double sigmoid = 1.0 / (1.0 + e - s * x);
+ const double invratio = 1.0 - ratio;
- const double x = ( ratio - 0.5 ) * 20;
- const double sigmoid = 1.0 / ( 1.0 + e - s * x );
- const double invratio = 1.0 - ratio;
+ out.textureWrap = (ratio < 0.5) ? a.textureWrap : b.textureWrap;
- out.textureWrap = ( ratio < 0.5 ) ? a.textureWrap : b.textureWrap;
+ out.screenDecay = lerp (b.screenDecay, a.screenDecay, ratio);
- out.screenDecay = lerp ( b.screenDecay, a.screenDecay, ratio );
+ out.drawables.clear();
+ out.compositeDrawables.clear();
- out.drawables.clear();
- out.compositeDrawables.clear();
+ for (std::vector<RenderItem*>::const_iterator pos = a.drawables.begin();
+ pos != a.drawables.end();
+ ++pos)
+ {
+ (*pos)->masterAlpha = invratio;
+ out.drawables.push_back (*pos);
+ }
- for ( std::vector<RenderItem*>::const_iterator pos = a.drawables.begin();
- pos != a.drawables.end(); ++pos )
- {
- ( *pos )->masterAlpha = invratio;
- out.drawables.push_back ( *pos );
- }
+ for (std::vector<RenderItem*>::const_iterator pos = b.drawables.begin();
+ pos != b.drawables.end();
+ ++pos)
+ {
+ (*pos)->masterAlpha = ratio;
+ out.drawables.push_back (*pos);
+ }
- for ( std::vector<RenderItem*>::const_iterator pos = b.drawables.begin();
- pos != b.drawables.end();++pos )
- {
- ( *pos )->masterAlpha = ratio;
- out.drawables.push_back ( *pos );
- }
+ if (ratio < 0.5) {
+ const double local_ratio = (invratio - 0.5) * 2;
- if(ratio < 0.5)
+ for (std::vector<RenderItem*>::const_iterator pos = a.compositeDrawables.begin();
+ pos != a.compositeDrawables.end();
+ ++pos)
{
- const double local_ratio = (invratio - 0.5) * 2;
-
- for (std::vector<RenderItem*>::const_iterator pos = a.compositeDrawables.begin();
- pos != a.compositeDrawables.end(); ++pos)
- {
- (*pos)->masterAlpha = local_ratio;
- out.compositeDrawables.push_back(*pos);
- }
+ (*pos)->masterAlpha = local_ratio;
+ out.compositeDrawables.push_back (*pos);
}
- else
+ } else {
+ const double local_ratio = (ratio - 0.5) * 2;
+
+ for (std::vector<RenderItem*>::const_iterator pos = b.compositeDrawables.begin();
+ pos != b.compositeDrawables.end();
+ ++pos)
{
- const double local_ratio = (ratio - 0.5) * 2;
-
- for (std::vector<RenderItem*>::const_iterator pos = b.compositeDrawables.begin();
- pos != b.compositeDrawables.end();++pos)
- {
- (*pos)->masterAlpha = local_ratio;
- out.compositeDrawables.push_back(*pos);
- }
+ (*pos)->masterAlpha = local_ratio;
+ out.compositeDrawables.push_back (*pos);
}
+ }
- /*
- for (RenderItemMatchList::iterator pos = results.matches.begin(); pos != results.matches.end(); ++pos) {
+ /*
+ for (RenderItemMatchList::iterator pos = results.matches.begin();
+ pos != results.matches.end();
+ ++pos)
+ {
+ RenderItem * itemA = pos->first;
+ RenderItem * itemB = pos->second;
- RenderItem * itemA = pos->first;
- RenderItem * itemB = pos->second;
+ RenderItem * itemC = mergeFunction(itemA, itemB, ratio);
- RenderItem * itemC = mergeFunction(itemA, itemB, ratio);
-
- if (itemC == 0) {
- itemA->masterAlpha = ratio;
- out.drawables.push_back(itemA);
- itemB->masterAlpha = invratio;
- out.drawables.push_back(itemB);
- } else
- out.drawables.push_back(itemC);
-
- }
+ if (itemC == 0) {
+ itemA->masterAlpha = ratio;
+ out.drawables.push_back (itemA);
+ itemB->masterAlpha = invratio;
+ out.drawables.push_back (itemB);
+ } else
+ out.drawables.push_back (itemC);
+ }
- for (std::vector<RenderItem*>::const_iterator pos = results.unmatchedLeft.begin();
- pos != results.unmatchedLeft.end(); ++pos)
- {
- (*pos)->masterAlpha = invratio;
- out.drawables.push_back(*pos);
- }
+ for (std::vector<RenderItem*>::const_iterator pos = results.unmatchedLeft.begin();
+ pos != results.unmatchedLeft.end();
+ ++pos)
+ {
+ (*pos)->masterAlpha = invratio;
+ out.drawables.push_back (*pos);
+ }
- for (std::vector<RenderItem*>::const_iterator pos = results.unmatchedRight.begin();
- pos != results.unmatchedRight.end(); ++pos)
- {
- (*pos)->masterAlpha = ratio;
- out.drawables.push_back(*pos);
- }
- */
+ for (std::vector<RenderItem*>::const_iterator pos = results.unmatchedRight.begin();
+ pos != results.unmatchedRight.end();
+ ++pos)
+ {
+ (*pos)->masterAlpha = ratio;
+ out.drawables.push_back (*pos);
+ }
+ */
- if (a.staticPerPixel && b.staticPerPixel)
- {
- out.staticPerPixel = true;
- for (int x=0;x<a.gx;x++)
- {
- for(int y=0;y<a.gy;y++)
- {
- out.x_mesh[x][y] = a.x_mesh[x][y]* invratio + b.x_mesh[x][y]*ratio;
- }
- }
- for (int x=0;x<a.gx;x++)
- {
- for(int y=0;y<a.gy;y++)
- {
- out.y_mesh[x][y] = a.y_mesh[x][y]* invratio + b.y_mesh[x][y]*ratio;
- }
- }
- }
-
- if(ratio < 0.5)
+ if (a.staticPerPixel && b.staticPerPixel) {
+ out.staticPerPixel = true;
+ for (int x = 0; x < a.gx; x++)
{
- out.compositeShader = a.compositeShader;
- out.warpShader = a.warpShader;
+ for (int y = 0; y < a.gy; y++)
+ {
+ out.x_mesh[x][y] = a.x_mesh[x][y] * invratio + b.x_mesh[x][y] * ratio;
+ }
}
- else
+ for (int x = 0; x < a.gx; x++)
{
- out.compositeShader = b.compositeShader;
- out.warpShader = b.warpShader;
+ for (int y = 0; y < a.gy; y++)
+ {
+ out.y_mesh[x][y] = a.y_mesh[x][y] * invratio + b.y_mesh[x][y] * ratio;
+ }
}
+ }
+
+ if (ratio < 0.5)
+ {
+ out.compositeShader = a.compositeShader;
+ out.warpShader = a.warpShader;
+ }
+ else
+ {
+ out.compositeShader = b.compositeShader;
+ out.warpShader = b.warpShader;
+ }
}
diff --git a/src/libprojectM/PipelineMerger.hpp b/src/libprojectM/PipelineMerger.hpp
index a0bba91..5d37bae 100644
--- a/src/libprojectM/PipelineMerger.hpp
+++ b/src/libprojectM/PipelineMerger.hpp
@@ -1,28 +1,31 @@
#ifndef PRESET_MERGE_HPP
#define PRESET_MERGE_HPP
+
#include "Preset.hpp"
#include "Pipeline.hpp"
#include "RenderItemMatcher.hpp"
#include "RenderItemMergeFunction.hpp"
+
class PipelineMerger
{
- template <class T> inline static T lerp(T a, T b, float ratio)
-{
- return a * ratio + b * (1 - ratio);
-}
+ template <class T> inline static T lerp(T a, T b, float ratio)
+ {
+ return a * ratio + b * (1 - ratio);
+ }
public:
-
- static void mergePipelines(const Pipeline &a, const Pipeline &b, Pipeline &out,
- RenderItemMatcher::MatchResults & matching, RenderItemMergeFunction & merger, float ratio);
-private :
+ static void mergePipelines(const Pipeline &a, const Pipeline &b, Pipeline &out,
+ RenderItemMatcher::MatchResults & matching,
+ RenderItemMergeFunction & merger, float ratio);
-static const double s;
-static const double e;
+private:
+
+ static const double s;
+ static const double e;
};
-#endif
+#endif /* PRESET_MERGE_HPP */
diff --git a/src/libprojectM/Preset.cpp b/src/libprojectM/Preset.cpp
index 84e823a..91175d8 100644
--- a/src/libprojectM/Preset.cpp
+++ b/src/libprojectM/Preset.cpp
@@ -7,6 +7,7 @@
#include "Preset.hpp"
+
Preset::~Preset() {}
Preset::Preset(const std::string & presetName, const std::string & presetAuthor):
@@ -19,5 +20,3 @@
void Preset::setAuthor(const std::string & value) { _author = value; }
const std::string & Preset::author() const { return _author; }
-
-
diff --git a/src/libprojectM/Preset.hpp b/src/libprojectM/Preset.hpp
index 4171e97..53ede8e 100644
--- a/src/libprojectM/Preset.hpp
+++ b/src/libprojectM/Preset.hpp
@@ -8,31 +8,32 @@
#ifndef PRESET_HPP_
#define PRESET_HPP_
+
#include <string>
#include "Renderer/BeatDetect.hpp"
#include "Renderer/Pipeline.hpp"
#include "Renderer/PipelineContext.hpp"
+
class Preset {
public:
+ Preset(const std::string & name = std::string(),
+ const std::string & author = std::string());
+ virtual ~Preset();
-
- Preset(const std::string & name=std::string(), const std::string & author = std::string());
- virtual ~Preset();
+ void setName(const std::string & value);
+ const std::string & name() const;
- void setName(const std::string & value);
- const std::string & name() const;
+ void setAuthor(const std::string & value);
+ const std::string & author() const;
- void setAuthor(const std::string & value);
- const std::string & author() const;
-
- virtual Pipeline & pipeline() = 0;
- virtual void Render(const BeatDetect &music, const PipelineContext &context) = 0;
+ virtual Pipeline & pipeline() = 0;
+ virtual void Render(const BeatDetect &music, const PipelineContext &context) = 0;
private:
- std::string _name;
- std::string _author;
+ std::string _name;
+ std::string _author;
};
#endif /* PRESET_HPP_ */
diff --git a/src/libprojectM/PresetChooser.cpp b/src/libprojectM/PresetChooser.cpp
index b239759..253b2d9 100644
--- a/src/libprojectM/PresetChooser.cpp
+++ b/src/libprojectM/PresetChooser.cpp
@@ -11,4 +11,3 @@
//
#include "PresetChooser.hpp"
-
diff --git a/src/libprojectM/PresetChooser.hpp b/src/libprojectM/PresetChooser.hpp
index ab88b2a..8b645fb 100644
--- a/src/libprojectM/PresetChooser.hpp
+++ b/src/libprojectM/PresetChooser.hpp
@@ -8,46 +8,48 @@
#include <cassert>
#include <memory>
#include <iostream>
+
+
class PresetChooser;
/// A simple iterator class to traverse back and forth a preset directory
class PresetIterator {
public:
- PresetIterator() {}
+ PresetIterator() {}
- /// Instantiate a preset iterator at the given starting position
- PresetIterator(std::size_t start);
+ /// Instantiate a preset iterator at the given starting position
+ PresetIterator(std::size_t start);
- /// Move iterator forward
- void operator++();
+ /// Move iterator forward
+ void operator++();
- /// Move iterator backword
- void operator--() ;
+ /// Move iterator backword
+ void operator--() ;
- /// Not equal comparator
- bool operator !=(const PresetIterator & presetPos) const ;
+ /// Not equal comparator
+ bool operator !=(const PresetIterator & presetPos) const ;
- /// Equality comparator
- bool operator ==(const PresetIterator & presetPos) const ;
+ /// Equality comparator
+ bool operator ==(const PresetIterator & presetPos) const ;
- /// Returns an integer value representing the iterator position
- /// @bug might become internal
- /// \brief Returns the indexing value used by the current iterator.
- std::size_t operator*() const;
+ /// Returns an integer value representing the iterator position
+ /// @bug might become internal
+ /// \brief Returns the indexing value used by the current iterator.
+ std::size_t operator*() const;
- /// Allocate a new preset given this iterator's associated preset name
- /// \param presetInputs the preset inputs to associate with the preset upon construction
- /// \param presetOutputs the preset outputs to associate with the preset upon construction
- /// \returns an autopointer of the newly allocated preset
- std::auto_ptr<Preset> allocate();
+ /// Allocate a new preset given this iterator's associated preset name
+ /// \param presetInputs the preset inputs to associate with the preset upon construction
+ /// \param presetOutputs the preset outputs to associate with the preset upon construction
+ /// \returns an autopointer of the newly allocated preset
+ std::auto_ptr<Preset> allocate();
- /// Set the chooser asocciated with this iterator
- void setChooser(const PresetChooser & chooser);
+ /// Set the chooser asocciated with this iterator
+ void setChooser(const PresetChooser & chooser);
private:
- std::size_t _currentIndex;
- const PresetChooser * _presetChooser;
+ std::size_t _currentIndex;
+ const PresetChooser * _presetChooser;
};
@@ -55,187 +57,217 @@
class PresetChooser {
public:
- typedef PresetIterator iterator;
+ typedef PresetIterator iterator;
- /// Initializes a chooser with an established preset loader.
- /// \param presetLoader an initialized preset loader to choose presets from
- /// \note The preset loader is refreshed via events or otherwise outside this class's scope
- PresetChooser(const PresetLoader & presetLoader, bool softCutRatingsEnabled);
+ /// Initializes a chooser with an established preset loader.
+ /// \param presetLoader an initialized preset loader to choose presets from
+ /// \note The preset loader is refreshed via events or otherwise outside this class's scope
+ PresetChooser(const PresetLoader & presetLoader, bool softCutRatingsEnabled);
- inline void setSoftCutRatingsEnabled(bool enabled) {
- _softCutRatingsEnabled = enabled;
- }
+ inline void setSoftCutRatingsEnabled(bool enabled) {
+ _softCutRatingsEnabled = enabled;
+ }
- /// Choose a preset via the passed in index. Must be between 0 and num valid presets in directory
- /// \param index An index lying in the interval [0, this->getNumPresets())
- /// \param presetInputs the preset inputs to associate with the preset upon construction
- /// \param presetOutputs the preset outputs to associate with the preset upon construction
- /// \returns an auto pointer of the newly allocated preset
- std::auto_ptr<Preset> directoryIndex(std::size_t index) const;
+ /// Choose a preset via the passed in index. Must be between 0 and num valid presets in directory
+ /// \param index An index lying in the interval [0, this->getNumPresets())
+ /// \param presetInputs the preset inputs to associate with the preset upon construction
+ /// \param presetOutputs the preset outputs to associate with the preset upon construction
+ /// \returns an auto pointer of the newly allocated preset
+ std::auto_ptr<Preset> directoryIndex(std::size_t index) const;
- /// Gets the number of presets last believed to exist in the preset loader's filename collection
- /// \returns the number of presets in the collection
- std::size_t size() const;
+ /// Gets the number of presets last believed to exist in the preset loader's filename collection
+ /// \returns the number of presets in the collection
+ std::size_t size() const;
- /// An STL-esque iterator to begin traversing presets from a directory
- /// \param index the index to begin iterating at. Assumed valid between [0, num presets)
- /// \returns the position of the first preset in the collection
- PresetIterator begin(unsigned int index) const;
+ /// An STL-esque iterator to begin traversing presets from a directory
+ /// \param index the index to begin iterating at. Assumed valid between [0, num presets)
+ /// \returns the position of the first preset in the collection
+ PresetIterator begin(unsigned int index) const;
- /// An STL-esque iterator to begin traversing presets from a directory
- /// \returns the position of the first preset in the collection
- PresetIterator begin();
+ /// An STL-esque iterator to begin traversing presets from a directory
+ /// \returns the position of the first preset in the collection
+ PresetIterator begin();
- /// An STL-esque iterator to retrieve an end position from a directory
- /// \returns the end position of the collection
- PresetIterator end() const;
+ /// An STL-esque iterator to retrieve an end position from a directory
+ /// \returns the end position of the collection
+ PresetIterator end() const;
- /// Perform a weighted sample to select a preset (uses preset rating values)
- /// \returns an iterator to the randomly selected preset
- iterator weightedRandom(bool hardCut) const;
+ /// Perform a weighted sample to select a preset (uses preset rating values)
+ /// \returns an iterator to the randomly selected preset
+ iterator weightedRandom(bool hardCut) const;
- /// True if no presets in directory
- bool empty() const;
+ /// True if no presets in directory
+ bool empty() const;
- inline void nextPreset(PresetIterator & presetPos);
- inline void previousPreset(PresetIterator & presetPos);
+ inline void nextPreset(PresetIterator & presetPos);
+ inline void previousPreset(PresetIterator & presetPos);
private:
- std::vector<float> sampleWeights;
- const PresetLoader * _presetLoader;
- bool _softCutRatingsEnabled;
+ std::vector<float> sampleWeights;
+ const PresetLoader * _presetLoader;
+ bool _softCutRatingsEnabled;
};
-inline PresetChooser::PresetChooser(const PresetLoader & presetLoader, bool softCutRatingsEnabled):_presetLoader(&presetLoader), _softCutRatingsEnabled(softCutRatingsEnabled) {
+inline
+PresetChooser::PresetChooser (
+const PresetLoader &presetLoader,
+bool softCutRatingsEnabled
+)
+ : _presetLoader(&presetLoader),
+ _softCutRatingsEnabled(softCutRatingsEnabled)
+{
}
-inline std::size_t PresetChooser::size() const {
- return _presetLoader->size();
+inline std::size_t
+PresetChooser::size() const
+{
+ return _presetLoader->size();
}
-inline void PresetIterator::setChooser(const PresetChooser & chooser) {
- _presetChooser = &chooser;
+inline void
+PresetIterator::setChooser(const PresetChooser & chooser)
+{
+ _presetChooser = &chooser;
}
-inline std::size_t PresetIterator::operator*() const {
- return _currentIndex;
+inline std::size_t
+PresetIterator::operator*() const
+{
+ return _currentIndex;
}
inline PresetIterator::PresetIterator(std::size_t start):_currentIndex(start) {}
-inline void PresetIterator::operator++() {
- assert(_currentIndex < _presetChooser->size());
- _currentIndex++;
+inline void
+PresetIterator::operator++()
+{
+ assert(_currentIndex < _presetChooser->size());
+ _currentIndex++;
}
-inline void PresetIterator::operator--() {
- assert(_currentIndex > 0);
- _currentIndex--;
+inline void
+PresetIterator::operator--()
+{
+ assert(_currentIndex > 0);
+ _currentIndex--;
}
-inline bool PresetIterator::operator !=(const PresetIterator & presetPos) const {
- return (*presetPos != **this);
+inline bool
+PresetIterator::operator !=(const PresetIterator & presetPos) const
+{
+ return (*presetPos != **this);
}
-inline bool PresetIterator::operator ==(const PresetIterator & presetPos) const {
- return (*presetPos == **this);
+inline bool
+PresetIterator::operator ==(const PresetIterator & presetPos) const
+{
+ return (*presetPos == **this);
}
-inline std::auto_ptr<Preset> PresetIterator::allocate() {
- return _presetChooser->directoryIndex(_currentIndex);
+inline std::auto_ptr<Preset>
+PresetIterator::allocate()
+{
+ return _presetChooser->directoryIndex(_currentIndex);
}
-inline void PresetChooser::nextPreset(PresetIterator & presetPos) {
+inline void
+PresetChooser::nextPreset(PresetIterator & presetPos)
+{
+ if (this->empty()) {
+ return;
+ }
+ // Case: idle preset currently running, selected first preset of chooser
+ else if (presetPos == this->end())
+ presetPos = this->begin();
+ else
+ ++(presetPos);
- if (this->empty()) {
- return;
- }
-
- // Case: idle preset currently running, selected first preset of chooser
- else if (presetPos == this->end())
- presetPos = this->begin();
- else
- ++(presetPos);
-
- // Case: already at last preset, loop to beginning
- if (((presetPos) == this->end())) {
- presetPos = this->begin();
- }
-
+ // Case: already at last preset, loop to beginning
+ if (((presetPos) == this->end())) {
+ presetPos = this->begin();
+ }
}
-inline void PresetChooser::previousPreset(PresetIterator & presetPos) {
- if (this->empty())
- return;
+inline void
+PresetChooser::previousPreset(PresetIterator & presetPos)
+{
+ if (this->empty())
+ return;
- // Case: idle preset currently running, selected last preset of chooser
- else if (presetPos == this->end()) {
- --(presetPos);
- }
-
- else if (presetPos != this->begin()) {
- --(presetPos);
- }
-
- else {
- presetPos = this->end();
- --(presetPos);
- }
+ // Case: idle preset currently running, selected last preset of chooser
+ else if (presetPos == this->end()) {
+ --(presetPos);
+ }
+ else if (presetPos != this->begin()) {
+ --(presetPos);
+ }
+ else {
+ presetPos = this->end();
+ --(presetPos);
+ }
}
-inline PresetIterator PresetChooser::begin() {
- PresetIterator pos(0);
- pos.setChooser(*this);
- return pos;
+inline PresetIterator
+PresetChooser::begin()
+{
+ PresetIterator pos(0);
+ pos.setChooser(*this);
+ return pos;
}
-inline PresetIterator PresetChooser::begin(unsigned int index) const{
- PresetIterator pos(index);
- pos.setChooser(*this);
- return pos;
+inline PresetIterator
+PresetChooser::begin(unsigned int index) const
+{
+ PresetIterator pos(index);
+ pos.setChooser(*this);
+ return pos;
}
-inline PresetIterator PresetChooser::end() const {
- PresetIterator pos(_presetLoader->size());
- pos.setChooser(*this);
- return pos;
+inline PresetIterator
+PresetChooser::end() const
+{
+ PresetIterator pos(_presetLoader->size());
+ pos.setChooser(*this);
+ return pos;
}
-inline bool PresetChooser::empty() const {
- return _presetLoader->size() == 0;
+inline bool
+PresetChooser::empty() const
+{
+ return _presetLoader->size() == 0;
}
-inline std::auto_ptr<Preset> PresetChooser::directoryIndex(std::size_t index) const {
-
- return _presetLoader->loadPreset(index);
+inline std::auto_ptr<Preset>
+PresetChooser::directoryIndex(std::size_t index) const
+{
+ return _presetLoader->loadPreset(index);
}
-inline PresetChooser::iterator PresetChooser::weightedRandom(bool hardCut) const {
+inline PresetChooser::iterator
+PresetChooser::weightedRandom(bool hardCut) const
+{
+ // TODO make a sophisticated function object interface to determine why a certain rating
+ // category is chosen, or weighted distribution thereover.
+ const PresetRatingType ratingType = hardCut || (!_softCutRatingsEnabled) ?
+ HARD_CUT_RATING_TYPE :
+ SOFT_CUT_RATING_TYPE;
-
-
+ const std::size_t ratingsTypeIndex = static_cast<std::size_t>(ratingType);
- // TODO make a sophisticated function object interface to determine why a certain rating
- // category is chosen, or weighted distribution thereover.
- const PresetRatingType ratingType = hardCut || (!_softCutRatingsEnabled) ?
- HARD_CUT_RATING_TYPE : SOFT_CUT_RATING_TYPE;
+ const std::vector<int> & weights = _presetLoader->getPresetRatings()[ratingsTypeIndex];
- const std::size_t ratingsTypeIndex = static_cast<std::size_t>(ratingType);
-
- const std::vector<int> & weights = _presetLoader->getPresetRatings()[ratingsTypeIndex];
+ const std::size_t index = RandomNumberGenerators::weightedRandom
+ (weights,
+ _presetLoader->getPresetRatingsSums()[ratingsTypeIndex]);
- const std::size_t index = RandomNumberGenerators::weightedRandom
- (weights,
- _presetLoader->getPresetRatingsSums()[ratingsTypeIndex]);
-
- return begin(index);
+ return begin(index);
}
#endif
diff --git a/src/libprojectM/PresetFactory.cpp b/src/libprojectM/PresetFactory.cpp
index bd7ac16..78e5031 100644
--- a/src/libprojectM/PresetFactory.cpp
+++ b/src/libprojectM/PresetFactory.cpp
@@ -1,24 +1,25 @@
#include "PresetFactory.hpp"
+
const std::string PresetFactory::IDLE_PRESET_PROTOCOL("idle");
-std::string PresetFactory::protocol(const std::string & url, std::string & path) {
+std::string
+PresetFactory::protocol (const std::string & url, std::string & path)
+{
#ifdef __APPLE__
- // NOTE: Brian changed this from url.find_first_of to url.find, since presumably we want to find the first occurence of
- // :// and not the first occurence of any colon or forward slash. At least that fixed a bug in the Mac OS X build.
- std::size_t pos = url.find("://");
+ // NOTE: Brian changed this from url.find_first_of to url.find, since presumably we want to find the first occurence of
+ // :// and not the first occurence of any colon or forward slash. At least that fixed a bug in the Mac OS X build.
+ std::size_t pos = url.find("://");
#else
- std::size_t pos = url.find_first_of("://");
+ std::size_t pos = url.find_first_of("://");
#endif
- if (pos == std::string::npos)
- return std::string();
- else {
- path = url.substr(pos + 3, url.length());
- std::cout << "[PresetFactory] path is " << path << std::endl;
- std::cout << "[PresetFactory] url is " << url << std::endl;
- return url.substr(0, pos);
- }
-
+ if (pos == std::string::npos)
+ return std::string();
+ else {
+ path = url.substr (pos + 3, url.length());
+ std::cout << "[PresetFactory] path is " << path << std::endl;
+ std::cout << "[PresetFactory] url is " << url << std::endl;
+ return url.substr (0, pos);
+ }
}
-
diff --git a/src/libprojectM/PresetFactory.hpp b/src/libprojectM/PresetFactory.hpp
index e9c8a4c..4e883e2 100644
--- a/src/libprojectM/PresetFactory.hpp
+++ b/src/libprojectM/PresetFactory.hpp
@@ -9,33 +9,34 @@
// Copyright: See COPYING file that comes with this distribution
//
//
-
#include "Preset.hpp"
#include <memory>
#ifndef __PRESET_FACTORY_HPP
#define __PRESET_FACTORY_HPP
+
class PresetFactory {
public:
- static const std::string IDLE_PRESET_PROTOCOL;
- static std::string protocol(const std::string & url, std::string & path);
+ static const std::string IDLE_PRESET_PROTOCOL;
+ static std::string protocol(const std::string & url, std::string & path);
- inline PresetFactory() {}
+ inline PresetFactory() {}
- inline virtual ~PresetFactory() {}
+ inline virtual ~PresetFactory() {}
- /// Constructs a new preset given an url and optional meta data
- /// \param url a locational identifier referencing the preset
- /// \param name the preset name
- /// \param author the preset author
- /// \returns a valid preset object
- virtual std::auto_ptr<Preset> allocate(const std::string & url, const std::string & name=std::string(),
- const std::string & author=std::string()) = 0;
+ /// Constructs a new preset given an url and optional meta data
+ /// \param url a locational identifier referencing the preset
+ /// \param name the preset name
+ /// \param author the preset author
+ /// \returns a valid preset object
+ virtual std::auto_ptr<Preset> allocate (const std::string & url,
+ const std::string & name=std::string(),
+ const std::string & author=std::string()) = 0;
- /// Returns a space separated list of supported extensions
- virtual std::string supportedExtensions() const = 0;
+ /// Returns a space separated list of supported extensions
+ virtual std::string supportedExtensions() const = 0;
};
diff --git a/src/libprojectM/PresetFactoryManager.cpp b/src/libprojectM/PresetFactoryManager.cpp
index 7dea038..b383107 100644
--- a/src/libprojectM/PresetFactoryManager.cpp
+++ b/src/libprojectM/PresetFactoryManager.cpp
@@ -1,7 +1,7 @@
//
// C++ Implementation: PresetFactoryManager
//
-// Description:
+// Description:
//
//
// Author: Carmelo Piccione <carmelo.piccione@gmail.com>, (C) 2008
@@ -20,71 +20,92 @@
#endif
#include <sstream>
-PresetFactoryManager::PresetFactoryManager() : _gx(0), _gy(0), initialized(false) {}
-PresetFactoryManager::~PresetFactoryManager() {
- for (std::vector<PresetFactory *>::iterator pos = _factoryList.begin();
- pos != _factoryList.end(); ++pos) {
- assert(*pos);
- delete(*pos);
- }
+
+PresetFactoryManager::PresetFactoryManager()
+ : _gx (0), _gy (0), initialized (false)
+{}
+
+PresetFactoryManager::~PresetFactoryManager()
+{
+ for (std::vector<PresetFactory *>::iterator pos = _factoryList.begin();
+ pos != _factoryList.end();
+ ++pos)
+ {
+ assert (*pos);
+ delete (*pos);
+ }
initialized = false;
}
-void PresetFactoryManager::initialize(int gx, int gy) {
- _gx = gx;
- _gy = gy;
-
- if (!initialized) {
- initialized = true;
- } else {
- std::cout << "already initialized " << std::endl;
- return;
- }
-
- PresetFactory * factory;
-
- #ifndef DISABLE_MILKDROP_PRESETS
- factory = new MilkdropPresetFactory(_gx, _gy);
- registerFactory(factory->supportedExtensions(), factory);
- #endif
-
- #ifndef DISABLE_NATIVE_PRESETS
- factory = new NativePresetFactory();
- registerFactory(factory->supportedExtensions(), factory);
- #endif
+void
+PresetFactoryManager::initialize (int gx, int gy)
+{
+ _gx = gx;
+ _gy = gy;
+
+ if (!initialized) {
+ initialized = true;
+ } else {
+ std::cout << "already initialized " << std::endl;
+ return;
+ }
+
+ PresetFactory * factory;
+
+ #ifndef DISABLE_MILKDROP_PRESETS
+ factory = new MilkdropPresetFactory (_gx, _gy);
+ registerFactory (factory->supportedExtensions(), factory);
+ #endif
+
+ #ifndef DISABLE_NATIVE_PRESETS
+ factory = new NativePresetFactory();
+ registerFactory (factory->supportedExtensions(), factory);
+ #endif
}
// Current behavior if a conflict is occurs is to override the previous request
-void PresetFactoryManager::registerFactory(const std::string & extensions, PresetFactory * factory) {
-
- std::stringstream ss(extensions);
- std::string extension;
+void
+PresetFactoryManager::registerFactory
+(
+const std::string &extensions,
+PresetFactory *factory
+)
+{
+ std::stringstream ss (extensions);
+ std::string extension;
- _factoryList.push_back(factory);
+ _factoryList.push_back (factory);
- while (ss >> extension) {
- if (_factoryMap.count(extension)) {
- std::cerr << "[PresetFactoryManager] Warning: extension \"" << extension <<
- "\" already has a factory. New factory handler ignored." << std::endl;
- } else {
- _factoryMap.insert(std::make_pair(extension, factory));
- }
- }
+ while (ss >> extension) {
+ if (_factoryMap.count (extension)) {
+ std::cerr << "[PresetFactoryManager] Warning: extension \""
+ << extension
+ << "\" already has a factory. New factory handler ignored."
+ << std::endl;
+ } else {
+ _factoryMap.insert (std::make_pair (extension, factory));
+ }
+ }
}
-PresetFactory & PresetFactoryManager::factory(const std::string & extension) {
+PresetFactory &
+PresetFactoryManager::factory (const std::string & extension)
+{
- if (!_factoryMap.count(extension)) {
- std::ostringstream os;
- os << "No factory associated with \"" << extension << "\"." << std::endl;
- throw PresetFactoryException(os.str());
- }
- return *_factoryMap[extension];
+ if (!_factoryMap.count (extension)) {
+ std::ostringstream os;
+
+ os << "No factory associated with \"" << extension << "\"." << std::endl;
+ throw PresetFactoryException (os.str());
+ }
+ return *_factoryMap[extension];
}
-bool PresetFactoryManager::extensionHandled(const std::string & extension) const {
- return _factoryMap.count(extension);
+bool
+PresetFactoryManager::extensionHandled (const std::string & extension) const
+{
+ return _factoryMap.count (extension);
}
diff --git a/src/libprojectM/PresetFactoryManager.hpp b/src/libprojectM/PresetFactoryManager.hpp
index 2dfa0a0..899b229 100644
--- a/src/libprojectM/PresetFactoryManager.hpp
+++ b/src/libprojectM/PresetFactoryManager.hpp
@@ -11,49 +11,53 @@
//
#ifndef __PRESET_FACTORY_MANAGER_HPP
#define __PRESET_FACTORY_MANAGER_HPP
+
#include "PresetFactory.hpp"
+
/// A simple exception class to strongly type all preset factory related issues
class PresetFactoryException : public std::exception
{
- public:
- inline PresetFactoryException(const std::string & message) : _message(message) {}
- virtual ~PresetFactoryException() throw() {}
- const std::string & message() const { return _message; }
+public:
+ inline PresetFactoryException (const std::string & message) : _message(message) {}
+ virtual ~PresetFactoryException() throw() {}
+ const std::string &message() const { return _message; }
- private:
- std::string _message;
+private:
+ std::string _message;
};
/// A manager of preset factories
class PresetFactoryManager {
- public:
- PresetFactoryManager();
- ~PresetFactoryManager();
+public:
+ PresetFactoryManager();
+ ~PresetFactoryManager();
- /// Initializes the manager with mesh sizes specified
- /// \param gx the width of the mesh
- /// \param gy the height of the mesh
- /// \note This must be called once before any other methods
- void initialize(int gx, int gy);
-
- /// Requests a factory given a preset extension type
- /// \param extension a string denoting the preset suffix type
- /// \throws PresetFactoryException if the extension is unhandled
- /// \returns a valid preset factory associated with the extension
- PresetFactory & factory(const std::string & extension);
+ /// Initializes the manager with mesh sizes specified
+ /// \param gx the width of the mesh
+ /// \param gy the height of the mesh
+ /// \note This must be called once before any other methods
+ void initialize (int gx, int gy);
- /// Tests if an extension has been registered with a factory
- /// \param extension the file name extension to verify
- /// \returns true if a factory exists, false otherwise
- bool extensionHandled(const std::string & extension) const;
+ /// Requests a factory given a preset extension type
+ /// \param extension a string denoting the preset suffix type
+ /// \throws PresetFactoryException if the extension is unhandled
+ /// \returns a valid preset factory associated with the extension
+ PresetFactory & factory (const std::string & extension);
- private:
- int _gx, _gy;
- mutable std::map<std::string, PresetFactory *> _factoryMap;
- mutable std::vector<PresetFactory *> _factoryList;
- void registerFactory(const std::string & extension, PresetFactory * factory);
- volatile bool initialized;
+ /// Tests if an extension has been registered with a factory
+ /// \param extension the file name extension to verify
+ /// \returns true if a factory exists, false otherwise
+ bool extensionHandled (const std::string & extension) const;
+
+private:
+ mutable std::map<std::string, PresetFactory *> _factoryMap;
+ mutable std::vector<PresetFactory *> _factoryList;
+ int _gx, _gy;
+ volatile bool initialized;
+
+ void registerFactory (const std::string & extension, PresetFactory * factory);
};
+
#endif
diff --git a/src/libprojectM/PresetLoader.cpp b/src/libprojectM/PresetLoader.cpp
index e0afec5..1542db3 100644
--- a/src/libprojectM/PresetLoader.cpp
+++ b/src/libprojectM/PresetLoader.cpp
@@ -35,249 +35,281 @@
#include "Common.hpp"
-PresetLoader::PresetLoader (int gx, int gy, std::string dirname = std::string()) :_dirname ( dirname ), _dir ( 0 )
+
+PresetLoader::PresetLoader (int gx, int gy, std::string dirname = std::string())
+ : _dirname (dirname),
+ _dir (0)
{
- _presetFactoryManager.initialize(gx,gy);
- // Do one scan
- if ( _dirname != std::string() )
- rescan();
- else
- clear();
+ _presetFactoryManager.initialize (gx, gy);
+ // Do one scan
+ if (_dirname != std::string())
+ rescan();
+ else
+ clear();
}
PresetLoader::~PresetLoader()
{
- if ( _dir )
- closedir ( _dir );
+ if (_dir)
+ closedir (_dir);
}
-void PresetLoader::setScanDirectory ( std::string dirname )
+void
+PresetLoader::setScanDirectory (std::string dirname)
{
- _dirname = dirname;
+ _dirname = dirname;
}
-void PresetLoader::rescan()
+void
+PresetLoader::rescan()
{
- // std::cerr << "Rescanning..." << std::endl;
+ // std::cerr << "Rescanning..." << std::endl;
- // Clear the directory entry collection
- clear();
-
- // If directory already opened, close it first
- if ( _dir )
- {
- closedir ( _dir );
- _dir = 0;
- }
+ // Clear the directory entry collection
+ clear();
- // Allocate a new a stream given the current directory name
- if ( ( _dir = opendir ( _dirname.c_str() ) ) == NULL )
- {
- handleDirectoryError();
- return; // no files loaded. _entries is empty
- }
+ // If directory already opened, close it first
+ if (_dir)
+ {
+ closedir (_dir);
+ _dir = 0;
+ }
- struct dirent * dir_entry;
- std::set<std::string> alphaSortedFileSet;
- std::set<std::string> alphaSortedPresetNameSet;
+ // Allocate a new a stream given the current directory name
+ if ((_dir = opendir (_dirname.c_str())) == NULL)
+ {
+ handleDirectoryError();
+ return; // no files loaded. _entries is empty
+ }
- while ( ( dir_entry = readdir ( _dir ) ) != NULL )
- {
+ struct dirent *dir_entry;
+ std::set<std::string> alphaSortedFileSet;
+ std::set<std::string> alphaSortedPresetNameSet;
+
+ while ((dir_entry = readdir (_dir)) != NULL)
+ {
if (dir_entry->d_name == 0)
continue;
- std::ostringstream out;
- // Convert char * to friendly string
- std::string filename ( dir_entry->d_name );
+ std::ostringstream out;
+ // Convert char * to friendly string
+ std::string filename (dir_entry->d_name);
- // Verify extension is projectm or milkdrop
- if (!_presetFactoryManager.extensionHandled(parseExtension(filename)))
- continue;
+ // Verify extension is projectm or milkdrop
+ if (!_presetFactoryManager.extensionHandled (parseExtension (filename)))
+ continue;
- if ( filename.length() > 0 && filename[0] == '.' )
- continue;
+ if (filename.length() > 0 && filename[0] == '.')
+ continue;
- // Create full path name
- out << _dirname << PATH_SEPARATOR << filename;
+ // Create full path name
+ out << _dirname << PATH_SEPARATOR << filename;
- // Add to our directory entry collection
- alphaSortedFileSet.insert ( out.str() );
- alphaSortedPresetNameSet.insert ( filename );
+ // Add to our directory entry collection
+ alphaSortedFileSet.insert (out.str());
+ alphaSortedPresetNameSet.insert (filename);
- // the directory entry struct is freed elsewhere
- }
+ // the directory entry struct is freed elsewhere
+ }
- // Push all entries in order from the file set to the file entries member (which is an indexed vector)
- for ( std::set<std::string>::iterator pos = alphaSortedFileSet.begin();
- pos != alphaSortedFileSet.end();++pos )
- _entries.push_back ( *pos );
+ // Push all entries in order from the file set to the file entries member (which is an indexed vector)
+ for (std::set<std::string>::iterator pos = alphaSortedFileSet.begin();
+ pos != alphaSortedFileSet.end();
+ ++pos)
+ {
+ _entries.push_back (*pos);
+ }
- // Push all preset names in similar fashion
- for ( std::set<std::string>::iterator pos = alphaSortedPresetNameSet.begin();
- pos != alphaSortedPresetNameSet.end();++pos )
- _presetNames.push_back ( *pos );
+ // Push all preset names in similar fashion
+ for (std::set<std::string>::iterator pos = alphaSortedPresetNameSet.begin();
+ pos != alphaSortedPresetNameSet.end();
+ ++pos)
+ {
+ _presetNames.push_back (*pos);
+ }
- // Give all presets equal rating of 3 - why 3? I don't know
- _ratings = std::vector<RatingList>(TOTAL_RATING_TYPES, RatingList( _presetNames.size(), 3 ));
- _ratingsSums = std::vector<int>(TOTAL_RATING_TYPES, 3 * _presetNames.size());
-
-
- assert ( _entries.size() == _presetNames.size() );
+ // Give all presets equal rating of 3 - why 3? I don't know
+ _ratings = std::vector<RatingList>(TOTAL_RATING_TYPES, RatingList (_presetNames.size(), 3));
+ _ratingsSums = std::vector<int>(TOTAL_RATING_TYPES, 3 * _presetNames.size());
-
+ assert (_entries.size() == _presetNames.size());
}
-std::auto_ptr<Preset> PresetLoader::loadPreset ( unsigned int index ) const
+std::auto_ptr<Preset>
+PresetLoader::loadPreset (unsigned int index) const
{
+ // Check that index isn't insane
+ assert (index >= 0);
+ assert (index < _entries.size());
- // Check that index isn't insane
- assert ( index >= 0 );
- assert ( index < _entries.size() );
+ // Return a new autopointer to a preset
+ const std::string extension = parseExtension (_entries[index]);
- // Return a new autopointer to a preset
- const std::string extension = parseExtension ( _entries[index] );
-
- return _presetFactoryManager.factory(extension).allocate
- ( _entries[index], _presetNames[index] );
-
+ return _presetFactoryManager
+ .factory (extension)
+ .allocate (_entries[index], _presetNames[index]);
}
-std::auto_ptr<Preset> PresetLoader::loadPreset ( const std::string & url ) const
+std::auto_ptr<Preset>
+PresetLoader::loadPreset (const std::string & url) const
{
+ // Return a new autopointer to a preset
+ const std::string extension = parseExtension (url);
- // Return a new autopointer to a preset
- const std::string extension = parseExtension ( url );
-
- /// @bug probably should not use url for preset name
- return _presetFactoryManager.factory(extension).allocate
- (url, url);
-
+ /// @bug probably should not use url for preset name
+ return _presetFactoryManager
+ .factory (extension)
+ .allocate (url, url);
}
-void PresetLoader::handleDirectoryError()
+void
+PresetLoader::handleDirectoryError()
{
#ifdef WIN32
- std::cerr << "[PresetLoader] warning: errno unsupported on win32 platforms. fix me" << std::endl;
+ std::cerr << "[PresetLoader] warning: errno unsupported on win32 platforms. fix me" << std::endl;
#else
- switch ( errno )
- {
- case ENOENT:
- std::cerr << "[PresetLoader] ENOENT error. The path \"" << this->_dirname << "\" probably does not exist. \"man open\" for more info." << std::endl;
- break;
- case ENOMEM:
- std::cerr << "[PresetLoader] out of memory! Are you running Windows?" << std::endl;
- abort();
- case ENOTDIR:
- std::cerr << "[PresetLoader] directory specified is not a preset directory! Trying to continue..." << std::endl;
- break;
- case ENFILE:
- std::cerr << "[PresetLoader] Your system has reached its open file limit. Trying to continue..." << std::endl;
- break;
- case EMFILE:
- std::cerr << "[PresetLoader] too many files in use by projectM! Bailing!" << std::endl;
- break;
- case EACCES:
- std::cerr << "[PresetLoader] permissions issue reading the specified preset directory." << std::endl;
- break;
- default:
- break;
- }
+ switch (errno) {
+ case ENOENT:
+ std::cerr << "[PresetLoader] ENOENT error. The path \""
+ << this->_dirname
+ << "\" probably does not exist. \"man open\" for more info."
+ << std::endl;
+ break;
+ case ENOMEM:
+ std::cerr << "[PresetLoader] out of memory! Are you running Windows?"
+ << std::endl;
+ abort();
+ case ENOTDIR:
+ std::cerr << "[PresetLoader] directory specified is not a preset directory! Trying to continue..."
+ << std::endl;
+ break;
+ case ENFILE:
+ std::cerr << "[PresetLoader] Your system has reached its open file limit. Trying to continue..."
+ << std::endl;
+ break;
+ case EMFILE:
+ std::cerr << "[PresetLoader] too many files in use by projectM! Bailing!"
+ << std::endl;
+ break;
+ case EACCES:
+ std::cerr << "[PresetLoader] permissions issue reading the specified preset directory."
+ << std::endl;
+ break;
+ default:
+ break;
+ }
#endif
}
-void PresetLoader::setRating(unsigned int index, int rating, const PresetRatingType ratingType)
+void
+PresetLoader::setRating (unsigned int index, int rating, const PresetRatingType ratingType)
{
- assert ( index >=0 );
-
- const unsigned int ratingTypeIndex = static_cast<unsigned int>(ratingType);
- assert (index < _ratings[ratingTypeIndex].size());
-
- _ratingsSums[ratingTypeIndex] -= _ratings[ratingTypeIndex][index];
+ assert (index >=0);
- _ratings[ratingTypeIndex][index] = rating;
- _ratingsSums[ratingType] += rating;
+ const unsigned int ratingTypeIndex = static_cast<unsigned int>(ratingType);
+ assert (index < _ratings[ratingTypeIndex].size());
+ _ratingsSums[ratingTypeIndex] -= _ratings[ratingTypeIndex][index];
+
+ _ratings[ratingTypeIndex][index] = rating;
+ _ratingsSums[ratingType] += rating;
}
-unsigned int PresetLoader::addPresetURL ( const std::string & url, const std::string & presetName, const std::vector<int> & ratings)
+unsigned int
+PresetLoader::addPresetURL (
+const std::string & url,
+const std::string & presetName,
+const std::vector<int> & ratings
+)
{
- _entries.push_back(url);
- _presetNames.push_back ( presetName );
+ _entries.push_back (url);
+ _presetNames.push_back (presetName);
- assert(ratings.size() == TOTAL_RATING_TYPES);
- assert(ratings.size() == _ratings.size());
+ assert (ratings.size() == TOTAL_RATING_TYPES);
+ assert (ratings.size() == _ratings.size());
- for (int i = 0; i < _ratings.size(); i++)
- _ratings[i].push_back(ratings[i]);
+ for (int i = 0; i < _ratings.size(); i++)
+ _ratings[i].push_back (ratings[i]);
- for (int i = 0; i < ratings.size(); i++)
- _ratingsSums[i] += ratings[i];
-
- return _entries.size()-1;
+ for (int i = 0; i < ratings.size(); i++)
+ _ratingsSums[i] += ratings[i];
+
+ return _entries.size() - 1;
}
-void PresetLoader::removePreset ( unsigned int index )
+void
+PresetLoader::removePreset (unsigned int index)
{
+ _entries.erase (_entries.begin() + index);
+ _presetNames.erase (_presetNames.begin() + index);
- _entries.erase ( _entries.begin() + index );
- _presetNames.erase ( _presetNames.begin() + index );
-
- for (int i = 0; i < _ratingsSums.size(); i++) {
- _ratingsSums[i] -= _ratings[i][index];
- _ratings[i].erase ( _ratings[i].begin() + index );
- }
-
-
+ for (int i = 0; i < _ratingsSums.size(); i++) {
+ _ratingsSums[i] -= _ratings[i][index];
+ _ratings[i].erase (_ratings[i].begin() + index);
+ }
}
-const std::string & PresetLoader::getPresetURL ( unsigned int index ) const
+const std::string &
+PresetLoader::getPresetURL (unsigned int index) const
{
- return _entries[index];
+ return _entries[index];
}
-const std::string & PresetLoader::getPresetName ( unsigned int index ) const
+const std::string &
+PresetLoader::getPresetName (unsigned int index) const
{
- return _presetNames[index];
+ return _presetNames[index];
}
-int PresetLoader::getPresetRating ( unsigned int index, const PresetRatingType ratingType ) const
+int
+PresetLoader::getPresetRating (
+unsigned int index,
+const PresetRatingType ratingType
+) const
{
- return _ratings[ratingType][index];
+ return _ratings[ratingType][index];
}
-const std::vector<RatingList> & PresetLoader::getPresetRatings () const
+const std::vector<RatingList> &
+PresetLoader::getPresetRatings() const
{
- return _ratings;
+ return _ratings;
}
-const std::vector<int> & PresetLoader::getPresetRatingsSums() const {
- return _ratingsSums;
-}
-
-void PresetLoader::setPresetName(unsigned int index, std::string name) {
- _presetNames[index] = name;
-}
-
-void PresetLoader::insertPresetURL ( unsigned int index, const std::string & url, const std::string & presetName, const RatingList & ratings)
+const std::vector<int> &
+PresetLoader::getPresetRatingsSums() const
{
- _entries.insert ( _entries.begin() + index, url );
- _presetNames.insert ( _presetNames.begin() + index, presetName );
-
-
+ return _ratingsSums;
+}
- for (int i = 0; i < _ratingsSums.size();i++) {
- _ratingsSums[i] += _ratings[i][index];
- _ratings[i].insert ( _ratings[i].begin() + index, ratings[i] );
- }
+void
+PresetLoader::setPresetName (unsigned int index, std::string name)
+{
+ _presetNames[index] = name;
+}
- assert ( _entries.size() == _presetNames.size() );
-
-
+void
+PresetLoader::insertPresetURL (
+unsigned int index,
+const std::string & url,
+const std::string & presetName,
+const RatingList & ratings
+)
+{
+ _entries.insert (_entries.begin() + index, url);
+ _presetNames.insert (_presetNames.begin() + index, presetName);
+
+ for (int i = 0; i < _ratingsSums.size(); i++) {
+ _ratingsSums[i] += _ratings[i][index];
+ _ratings[i].insert (_ratings[i].begin() + index, ratings[i]);
+ }
+
+ assert (_entries.size() == _presetNames.size());
}
diff --git a/src/libprojectM/PresetLoader.hpp b/src/libprojectM/PresetLoader.hpp
index 02d43c1..d83e548 100644
--- a/src/libprojectM/PresetLoader.hpp
+++ b/src/libprojectM/PresetLoader.hpp
@@ -21,98 +21,98 @@
#include <map>
#include "PresetFactoryManager.hpp"
+
class Preset;
class PresetFactory;
class PresetLoader {
- public:
-
-
- /// Initializes the preset loader with the target directory specified
- PresetLoader(int gx, int gy, std::string dirname);
-
- ~PresetLoader();
-
- /// Load a preset by specifying it's unique identifier given when the preset url
- /// was added to this loader
- std::auto_ptr<Preset> loadPreset(unsigned int index) const;
- std::auto_ptr<Preset> loadPreset ( const std::string & url ) const;
- /// Add a preset to the loader's collection.
- /// \param url an url referencing the preset
- /// \param presetName a name for the preset
- /// \param rating an integer representing the goodness of the preset
- /// \returns The unique index assigned to the preset in the collection. Used with loadPreset
- unsigned int addPresetURL ( const std::string & url, const std::string & presetName, const RatingList & ratings);
-
- /// Add a preset to the loader's collection.
- /// \param index insertion index
- /// \param url an url referencing the preset
- /// \param presetName a name for the preset
- /// \param rating an integer representing the goodness of the preset
- void insertPresetURL (unsigned int index, const std::string & url, const std::string & presetName, const RatingList & ratings);
-
- /// Clears all presets from the collection
- inline void clear() {
- _entries.clear(); _presetNames.clear();
- _ratings = std::vector<RatingList>(TOTAL_RATING_TYPES, RatingList());
- clearRatingsSum();
- }
+public:
- inline void clearRatingsSum() {
- _ratingsSums = std::vector<int>(TOTAL_RATING_TYPES, 0);
- }
-
- const std::vector<RatingList> & getPresetRatings() const;
- const std::vector<int> & getPresetRatingsSums() const;
+ /// Initializes the preset loader with the target directory specified
+ PresetLoader(int gx, int gy, std::string dirname);
- /// Removes a preset from the loader
- /// \param index the unique identifier of the preset url to be removed
- void removePreset(unsigned int index);
+ ~PresetLoader();
- /// Sets the rating of a preset to a new value
- void setRating(unsigned int index, int rating, const PresetRatingType ratingType);
-
- /// Get a preset rating given an index
- int getPresetRating ( unsigned int index, const PresetRatingType ratingType) const;
-
- /// Get a preset url given an index
- const std::string & getPresetURL ( unsigned int index) const;
-
- /// Get a preset name given an index
- const std::string & getPresetName ( unsigned int index) const;
-
- /// Returns the number of presets in the active directory
- inline std::size_t size() const {
- return _entries.size();
- }
-
- /// Sets the directory where the loader will search for files
- void setScanDirectory(std::string pathname);
+ /// Load a preset by specifying it's unique identifier given when the preset url
+ /// was added to this loader
+ std::auto_ptr<Preset> loadPreset(unsigned int index) const;
+ std::auto_ptr<Preset> loadPreset ( const std::string & url ) const;
+ /// Add a preset to the loader's collection.
+ /// \param url an url referencing the preset
+ /// \param presetName a name for the preset
+ /// \param rating an integer representing the goodness of the preset
+ /// \returns The unique index assigned to the preset in the collection. Used with loadPreset
+ unsigned int addPresetURL ( const std::string & url, const std::string & presetName, const RatingList & ratings);
- /// Returns the directory path associated with this preset chooser
- inline const std::string & directoryName() const {
- return _dirname;
- }
-
- /// Rescans the active preset directory
- void rescan();
- void setPresetName(unsigned int index, std::string name);
- private:
- void handleDirectoryError();
- std::string _dirname;
- DIR * _dir;
- std::vector<int> _ratingsSums;
- mutable PresetFactoryManager _presetFactoryManager;
+ /// Add a preset to the loader's collection.
+ /// \param index insertion index
+ /// \param url an url referencing the preset
+ /// \param presetName a name for the preset
+ /// \param rating an integer representing the goodness of the preset
+ void insertPresetURL (unsigned int index, const std::string & url, const std::string & presetName, const RatingList & ratings);
- // vector chosen for speed, but not great for reverse index lookups
- std::vector<std::string> _entries;
- std::vector<std::string> _presetNames;
+ /// Clears all presets from the collection
+ inline void clear() {
+ _entries.clear(); _presetNames.clear();
+ _ratings = std::vector<RatingList>(TOTAL_RATING_TYPES, RatingList());
+ clearRatingsSum();
+ }
- // Indexed by ratingType, preset position.
- std::vector<RatingList> _ratings;
-
+ inline void clearRatingsSum() {
+ _ratingsSums = std::vector<int>(TOTAL_RATING_TYPES, 0);
+ }
+ const std::vector<RatingList> & getPresetRatings() const;
+ const std::vector<int> & getPresetRatingsSums() const;
+
+ /// Removes a preset from the loader
+ /// \param index the unique identifier of the preset url to be removed
+ void removePreset(unsigned int index);
+
+ /// Sets the rating of a preset to a new value
+ void setRating(unsigned int index, int rating, const PresetRatingType ratingType);
+
+ /// Get a preset rating given an index
+ int getPresetRating ( unsigned int index, const PresetRatingType ratingType) const;
+
+ /// Get a preset url given an index
+ const std::string & getPresetURL ( unsigned int index) const;
+
+ /// Get a preset name given an index
+ const std::string & getPresetName ( unsigned int index) const;
+
+ /// Returns the number of presets in the active directory
+ inline std::size_t size() const {
+ return _entries.size();
+ }
+
+ /// Sets the directory where the loader will search for files
+ void setScanDirectory(std::string pathname);
+
+ /// Returns the directory path associated with this preset chooser
+ inline const std::string & directoryName() const {
+ return _dirname;
+ }
+
+ /// Rescans the active preset directory
+ void rescan();
+ void setPresetName(unsigned int index, std::string name);
+
+private:
+ void handleDirectoryError();
+
+ std::string _dirname;
+ DIR *_dir;
+ std::vector<int> _ratingsSums;
+ mutable PresetFactoryManager _presetFactoryManager;
+
+ // vector chosen for speed, but not great for reverse index lookups
+ std::vector<std::string> _entries;
+ std::vector<std::string> _presetNames;
+
+ // Indexed by ratingType, preset position.
+ std::vector<RatingList> _ratings;
};
#endif
diff --git a/src/libprojectM/RandomNumberGenerators.hpp b/src/libprojectM/RandomNumberGenerators.hpp
index 862e43b..008585a 100644
--- a/src/libprojectM/RandomNumberGenerators.hpp
+++ b/src/libprojectM/RandomNumberGenerators.hpp
@@ -7,116 +7,136 @@
#define WEIGHTED_RANDOM_DEBUG 0
+
namespace RandomNumberGenerators {
-inline float uniform()
-/* Uniform random number generator x(n+1)= a*x(n) mod c
- with a = pow(7,5) and c = pow(2,31)-1.
- Copyright (c) Tao Pang 1997. */
- {
- const int ia=16807,ic=2147483647,iq=127773,ir=2836;
- int il,ih,it;
- float rc;
- static int iseed = rand();
- ih = iseed/iq;
- il = iseed%iq;
- it = ia*il-ir*ih;
- if (it > 0)
- {
- iseed = it;
- }
- else
- {
- iseed = ic+it;
- }
- rc = ic;
- return iseed/rc;
- }
-inline float gaussian(float mean, float sigma)
+inline float
+uniform()
+/* Uniform random number generator x(n+1)= a*x(n) mod c
+ with a = pow(7,5) and c = pow(2,31)-1.
+ Copyright (c) Tao Pang 1997. */
+{
+ const int ia=16807,
+ ic=2147483647,
+ iq=127773,
+ ir=2836;
+ int il,ih,it;
+ float rc;
+ static int iseed = rand();
+
+ ih = iseed / iq;
+ il = iseed % iq;
+ it = ia * il - ir * ih;
+ if (it > 0)
+ {
+ iseed = it;
+ }
+ else
+ {
+ iseed = ic+it;
+ }
+ rc = ic;
+ return iseed / rc;
+}
+
+inline float
+gaussian (float mean, float sigma)
{
- float x1, x2, w, y1, y2;
-
- do {
- x1 = 2.0 * uniform() - 1.0;
- x2 = 2.0 * uniform() - 1.0;
- w = x1 * x1 + x2 * x2;
- } while ( w >= 1.0 );
+ float x1, x2, w, y1, y2;
- w = sqrt( (-2.0 * log( w ) ) / w );
- y1 = x1 * w;
- y2 = x2 * w;
-
- float ret = y1*sigma + mean;
+ do {
+ x1 = 2.0 * uniform() - 1.0;
+ x2 = 2.0 * uniform() - 1.0;
+ w = x1 * x1 + x2 * x2;
+ } while ( w >= 1.0 );
- return ret;
+ w = sqrt( (-2.0 * log( w ) ) / w );
+ y1 = x1 * w;
+ y2 = x2 * w;
+
+ float ret = y1*sigma + mean;
+
+ return ret;
}
-inline std::size_t uniformInteger(std::size_t upperBound=1) {
-
-
- /// @bug there was a man entry about how this leads to a lousy uniform
- /// @bug distribution in practice. should probably review
- assert(upperBound > 0);
- return ((rand()) % ((int)upperBound));
+inline std::size_t
+uniformInteger (std::size_t upperBound = 1)
+{
+ /// @bug there was a man entry about how this leads to a lousy uniform
+ /// @bug distribution in practice. should probably review
+ assert(upperBound > 0);
+ return ((rand()) % ((int)upperBound));
}
-
-
+
+
/// Randomizes from probabilistically weighted distribution. Thus,
/// sum of passed in weights should be 1.0
-inline std::size_t weightedRandomNormalized(std::vector<float> weights) {
+inline std::size_t
+weightedRandomNormalized(std::vector<float> weights)
+{
+ // Choose a random bounded mass between 0 and 1
+ float cutoff = ((float) (rand())) / (float) RAND_MAX;
- // Choose a random bounded mass between 0 and 1
- float cutoff = ((float)(rand())) / (float)RAND_MAX;
+ //std::cout << "cutoff : " << cutoff << std::endl;
- //std::cout << "cutoff : " << cutoff << std::endl;
+ // Sum up mass, stopping when cutoff is reached. This is the typical
+ // weighted sampling algorithm.
+ float mass = 0;
+ for (std::size_t i = 0; i < weights.size(); i++) {
+ mass += weights[i];
+ //std::cout << "mass: " << mass << std::endl;
+ if (mass >= cutoff)
+ return i;
+ }
- // Sum up mass, stopping when cutoff is reached. This is the typical
- // weighted sampling algorithm.
- float mass = 0;
- for (std::size_t i = 0; i< weights.size() ; i++) {
- mass += weights[i];
- //std::cout << "mass: " << mass << std::endl;
- if (mass >= cutoff)
- return i;
- }
-
- // Just in case something slips through the cracks
- return weights.size()-1;
+ // Just in case something slips through the cracks
+ return weights.size()-1;
}
-inline std::size_t weightedRandom(const std::vector<int> & weights, unsigned int weightTotalHint = 0) {
-
+inline std::size_t
+weightedRandom (const std::vector<int> & weights, unsigned int weightTotalHint = 0)
+{
+ if (weightTotalHint == 0) {
+ for (std::size_t i = 0; i < weights.size(); i++)
+ weightTotalHint += weights[i];
+ }
- if (weightTotalHint == 0) {
- for (std::size_t i = 0; i < weights.size();i++)
- weightTotalHint += weights[i];
- }
-
- const int sampledSum = uniformInteger(weightTotalHint);
- int sum = 0;
- if (WEIGHTED_RANDOM_DEBUG) std::cout << "[RNG::weightedRandom()] weightTotal = " << weightTotalHint <<
- std::endl;
+ const int sampledSum = uniformInteger(weightTotalHint);
+ int sum = 0;
- for (std::size_t i = 0; i < weights.size();i++) {
- if (WEIGHTED_RANDOM_DEBUG)
- std::cout << "[RNG::weightedRandom()] weight[" << i << "] = " << weights[i] <<
- std::endl;
+ if (WEIGHTED_RANDOM_DEBUG)
+ std::cout << "[RNG::weightedRandom()] weightTotal = "
+ << weightTotalHint
+ << std::endl;
- sum += weights[i];
- if (sampledSum <= sum) {
- if (WEIGHTED_RANDOM_DEBUG)
- std::cout << "[RNG::weightedRandom()] sampled index " << i << "(" <<
- "running sum = " << sum << ", sampled sum = " << sampledSum << std::endl;
- return i;
- }
- }
+ for (std::size_t i = 0; i < weights.size(); i++) {
+ if (WEIGHTED_RANDOM_DEBUG)
+ std::cout << "[RNG::weightedRandom()] weight[" << i << "] = "
+ << weights[i]
+ << std::endl;
- return weights.size()-1;
+ sum += weights[i];
+ if (sampledSum <= sum) {
+ if (WEIGHTED_RANDOM_DEBUG)
+ std::cout << "[RNG::weightedRandom()] sampled index "
+ << i
+ << "("
+ << "running sum = "
+ << sum
+ << ", sampled sum = "
+ << sampledSum
+ << std::endl;
+ return i;
+ }
+ }
+
+ return weights.size() - 1;
}
-}
+} /* namespace RandomNumberGenerators */
+
#endif
diff --git a/src/libprojectM/Renderer/BeatDetect.cpp b/src/libprojectM/Renderer/BeatDetect.cpp
index 106b544..e7f79ea 100644
--- a/src/libprojectM/Renderer/BeatDetect.cpp
+++ b/src/libprojectM/Renderer/BeatDetect.cpp
@@ -21,11 +21,10 @@
/**
* Takes sound data from wherever and returns beat detection values
* Uses statistical Energy-Based methods. Very simple
- *
+ *
* Some stuff was taken from Frederic Patin's beat-detection article,
* you'll find it online
*/
-
#include <stdlib.h>
#include <stdio.h>
@@ -36,151 +35,153 @@
#include <cmath>
#include "BeatDetect.hpp"
-BeatDetect::BeatDetect(PCM *pcm) {
- int x,y;
+
+BeatDetect::BeatDetect (PCM *pcm)
+{
+ int x,y;
this->pcm=pcm;
- this->vol_instant=0;
- this->vol_history=0;
+ this->vol_instant = 0;
+ this->vol_history = 0;
- for (y=0;y<80;y++)
- {
- this->vol_buffer[y]=0;
- }
-
- this->beat_buffer_pos=0;
-
- for (x=0;x<32;x++) {
- this->beat_instant[x]=0;
- this->beat_history[x]=0;
- this->beat_val[x]=1.0;
- this->beat_att[x]=1.0;
- this->beat_variance[x]=0;
- for (y=0;y<80;y++) {
- this->beat_buffer[x][y]=0;
- }
- }
-
- this->treb = 0;
- this->mid = 0;
- this->bass = 0;
- this->vol_old = 0;
- this->beat_sensitivity = 10.00;
- this->treb_att = 0;
- this->mid_att = 0;
- this->bass_att = 0;
- this->vol = 0;
-
-
+ for (y = 0; y < 80; y++)
+ {
+ this->vol_buffer[y] = 0;
}
-BeatDetect::~BeatDetect()
+ this->beat_buffer_pos = 0;
+
+ for (x = 0; x < 32; x++) {
+ this->beat_instant[x] = 0;
+ this->beat_history[x] = 0;
+ this->beat_val[x] = 1.0;
+ this->beat_att[x] = 1.0;
+ this->beat_variance[x] = 0;
+ for (y = 0; y < 80; y++) {
+ this->beat_buffer[x][y] = 0;
+ }
+ }
+
+ this->treb = 0;
+ this->mid = 0;
+ this->bass = 0;
+ this->vol_old = 0;
+ this->beat_sensitivity = 10.00;
+ this->treb_att = 0;
+ this->mid_att = 0;
+ this->bass_att = 0;
+ this->vol = 0;
+}
+
+BeatDetect::~BeatDetect()
{
}
-void BeatDetect::reset() {
- this->treb = 0;
- this->mid = 0;
- this->bass = 0;
- this->treb_att = 0;
- this->mid_att = 0;
- this->bass_att = 0;
- }
-
-void BeatDetect::detectFromSamples() {
- vol_old = vol;
- bass=0;mid=0;treb=0;
-
- getBeatVals(pcm->pcmdataL,pcm->pcmdataR);
- }
-
-void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) {
-
- int linear=0;
- int x,y;
- float temp2=0;
-
- vol_instant=0;
- for ( x=0;x<16;x++)
- {
-
- beat_instant[x]=0;
- for ( y=linear*2;y<(linear+8+x)*2;y++)
- {
- beat_instant[x]+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/(8+x));
-// printf( "beat_instant[%d]: %f %f %f\n", x, beat_instant[x], vdataL[y], vdataR[y] );
- vol_instant+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/512.0);
-
- }
-//printf("1");
- linear=y/2;
- beat_history[x]-=(beat_buffer[x][beat_buffer_pos])*.0125;
- beat_buffer[x][beat_buffer_pos]=beat_instant[x];
- beat_history[x]+=(beat_instant[x])*.0125;
-
- beat_val[x]=(beat_instant[x])/(beat_history[x]);
-
- beat_att[x]+=(beat_instant[x])/(beat_history[x]);
-
-//printf("2\n");
-
- }
-//printf("b\n");
- vol_history-=(vol_buffer[beat_buffer_pos])*.0125;
- vol_buffer[beat_buffer_pos]=vol_instant;
- vol_history+=(vol_instant)*.0125;
-
- mid=0;
- for(x=1;x<10;x++)
- {
- mid+=(beat_instant[x]);
- temp2+=(beat_history[x]);
-
- }
-
- mid=mid/(1.5*temp2);
- temp2=0;
- treb=0;
- for(x=10;x<16;x++)
- {
- treb+=(beat_instant[x]);
- temp2+=(beat_history[x]);
- }
-//printf("c\n");
- treb=treb/(1.5*temp2);
-// *vol=vol_instant/(1.5*vol_history);
- vol=vol_instant/(1.5*vol_history);
-
- bass=(beat_instant[0])/(1.5*beat_history[0]);
-
-
- if ( projectM_isnan( treb ) ) {
- treb = 0.0;
- }
- if ( projectM_isnan( mid ) ) {
- mid = 0.0;
- }
- if ( projectM_isnan( bass ) ) {
- bass = 0.0;
- }
- treb_att=.6 * treb_att + .4 * treb;
- mid_att=.6 * mid_att + .4 * mid;
- bass_att=.6 * bass_att + .4 * bass;
-
- if(bass_att>100)bass_att=100;
- if(bass >100)bass=100;
- if(mid_att>100)mid_att=100;
- if(mid >100)mid=100;
- if(treb_att>100)treb_att=100;
- if(treb >100)treb=100;
- if(vol>100)vol=100;
-
- // *vol=(beat_instant[3])/(beat_history[3]);
- beat_buffer_pos++;
- if( beat_buffer_pos>79)beat_buffer_pos=0;
-
+void
+BeatDetect::reset()
+{
+ this->treb = 0;
+ this->mid = 0;
+ this->bass = 0;
+ this->treb_att = 0;
+ this->mid_att = 0;
+ this->bass_att = 0;
}
+void
+BeatDetect::detectFromSamples()
+{
+ vol_old = vol;
+ bass = 0; mid = 0; treb = 0;
+ getBeatVals (pcm->pcmdataL, pcm->pcmdataR);
+}
+
+void
+BeatDetect::getBeatVals (float *vdataL, float *vdataR)
+{
+ int linear=0;
+ int x,y;
+ float temp2=0;
+
+ vol_instant = 0;
+ for (x = 0; x < 16; x++)
+ {
+ beat_instant[x]=0;
+ for (y = linear * 2; y < (linear + 8 + x) * 2; y++)
+ {
+ beat_instant[x] += ((vdataL[y] * vdataL[y])
+ + (vdataR[y] * vdataR[y])) * (1.0 / (8 + x));
+ // printf ("beat_instant[%d]: %f %f %f\n", x, beat_instant[x], vdataL[y], vdataR[y]);
+ vol_instant += ((vdataL[y] * vdataL[y])
+ + (vdataR[y] * vdataR[y])) * (1.0 / 512.0);
+
+ }
+ //printf ("1");
+ linear = y / 2;
+ beat_history[x] -= (beat_buffer[x][beat_buffer_pos])*.0125;
+ beat_buffer[x][beat_buffer_pos] = beat_instant[x];
+ beat_history[x] += (beat_instant[x]) * .0125;
+
+ beat_val[x] = (beat_instant[x]) / (beat_history[x]);
+
+ beat_att[x] += (beat_instant[x]) / (beat_history[x]);
+
+ //printf ("2\n");
+
+ }
+ //printf ("b\n");
+ vol_history -= (vol_buffer[beat_buffer_pos]) * .0125;
+ vol_buffer[beat_buffer_pos] = vol_instant;
+ vol_history += (vol_instant) * .0125;
+
+ mid = 0;
+ for (x = 1; x < 10; x++)
+ {
+ mid += (beat_instant[x]);
+ temp2 += (beat_history[x]);
+ }
+
+ mid = mid / (1.5 * temp2);
+ temp2 = 0;
+ treb = 0;
+ for (x = 10; x < 16; x++)
+ {
+ treb += (beat_instant[x]);
+ temp2 += (beat_history[x]);
+ }
+ //printf ("c\n");
+ treb = treb / (1.5 * temp2);
+ // *vol=vol_instant/(1.5*vol_history);
+ vol = vol_instant / (1.5 * vol_history);
+
+ bass = (beat_instant[0]) / (1.5 * beat_history[0]);
+
+
+ if (projectM_isnan (treb)) {
+ treb = 0.0;
+ }
+ if (projectM_isnan (mid)) {
+ mid = 0.0;
+ }
+ if (projectM_isnan (bass)) {
+ bass = 0.0;
+ }
+ treb_att = .6 * treb_att + .4 * treb;
+ mid_att = .6 * mid_att + .4 * mid;
+ bass_att = .6 * bass_att + .4 * bass;
+
+ if (bass_att > 100) bass_att =100;
+ if (bass > 100) bass = 100;
+ if (mid_att > 100) mid_att = 100;
+ if (mid > 100) mid = 100;
+ if (treb_att > 100) treb_att = 100;
+ if (treb > 100) treb = 100;
+ if (vol > 100) vol = 100;
+
+ // *vol=(beat_instant[3])/(beat_history[3]);
+ beat_buffer_pos++;
+ if (beat_buffer_pos > 79) beat_buffer_pos = 0;
+}
diff --git a/src/libprojectM/Renderer/BeatDetect.hpp b/src/libprojectM/Renderer/BeatDetect.hpp
index 4dc3881..5da9831 100644
--- a/src/libprojectM/Renderer/BeatDetect.hpp
+++ b/src/libprojectM/Renderer/BeatDetect.hpp
@@ -27,7 +27,6 @@
* $Log$
*
*/
-
#ifndef _BEAT_DETECT_H
#define _BEAT_DETECT_H
@@ -37,38 +36,39 @@
class DLLEXPORT BeatDetect
{
- public:
- float treb ;
- float mid ;
- float bass ;
- float vol_old ;
- float beat_sensitivity;
- float treb_att ;
- float mid_att ;
- float bass_att ;
- float vol;
+public:
+ float treb;
+ float mid;
+ float bass;
+ float vol_old;
+ float beat_sensitivity;
+ float treb_att;
+ float mid_att;
+ float bass_att;
+ float vol;
- PCM *pcm;
+ PCM *pcm;
- /** Methods */
- BeatDetect(PCM *pcm);
- ~BeatDetect();
- void initBeatDetect();
- void reset();
- void detectFromSamples();
- void getBeatVals ( float *vdataL, float *vdataR );
- private:
- /** Vars */
- float beat_buffer[32][80],
- beat_instant[32],
- beat_history[32];
- float beat_val[32],
- beat_att[32],
- beat_variance[32];
- int beat_buffer_pos;
- float vol_buffer[80],
- vol_instant,
- vol_history;
+ /** Methods */
+ BeatDetect(PCM *pcm);
+ ~BeatDetect();
+ void initBeatDetect();
+ void reset();
+ void detectFromSamples();
+ void getBeatVals ( float *vdataL, float *vdataR );
+
+private:
+ /** Vars */
+ float beat_buffer[32][80],
+ beat_instant[32],
+ beat_history[32];
+ float beat_val[32],
+ beat_att[32],
+ beat_variance[32];
+ int beat_buffer_pos;
+ float vol_buffer[80],
+ vol_instant,
+ vol_history;
};
#endif /** !_BEAT_DETECT_H */
diff --git a/src/libprojectM/Renderer/FBO.cpp b/src/libprojectM/Renderer/FBO.cpp
index 2bc1dd3..fe86e8f 100644
--- a/src/libprojectM/Renderer/FBO.cpp
+++ b/src/libprojectM/Renderer/FBO.cpp
@@ -23,7 +23,6 @@
*
* Render this methods
*/
-
#include <stdio.h>
//#include <GL/gl.h>
#include <iostream>
@@ -32,274 +31,270 @@
-RenderTarget::~RenderTarget() {
-
-
- glDeleteTextures( 1, &this->textureID[0]);
+RenderTarget::~RenderTarget()
+{
+ glDeleteTextures (1, &this->textureID[0]);
#ifdef USE_FBO
- if (useFBO)
- {
- glDeleteTextures( 1, &this->textureID[1] );
- glDeleteRenderbuffersEXT(1, &this->depthb[0]);
- glDeleteFramebuffersEXT(1, &this->fbuffer[0]);
- if(renderToTexture)
- {
- glDeleteTextures( 1, &this->textureID[2] );
- glDeleteRenderbuffersEXT(1, &this->depthb[1]);
- glDeleteFramebuffersEXT(1, &this->fbuffer[1]);
- }
- }
+ if (useFBO)
+ {
+ glDeleteTextures (1, &this->textureID[1]);
+ glDeleteRenderbuffersEXT (1, &this->depthb[0]);
+ glDeleteFramebuffersEXT (1, &this->fbuffer[0]);
+ if (renderToTexture)
+ {
+ glDeleteTextures (1, &this->textureID[2]);
+ glDeleteRenderbuffersEXT (1, &this->depthb[1]);
+ glDeleteFramebuffersEXT (1, &this->fbuffer[1]);
+ }
+ }
#endif
-
}
GLuint RenderTarget::initRenderToTexture()
{
#ifdef USE_FBO
-
if (this->useFBO==1)
- {
- this->renderToTexture=1;
-
- GLuint fb2, depth_rb2;
- glGenFramebuffersEXT(1, &fb2);
- glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fb2 );
- glGenRenderbuffersEXT(1, &depth_rb2);
- glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb2 );
-
- glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, this->texsize,this->texsize );
- glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb2 );
- this->fbuffer[1] = fb2;
- this->depthb[1]= depth_rb2;
- glGenTextures(1, &this->textureID[2]);
- glBindTexture(GL_TEXTURE_2D, this->textureID[2]);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->textureID[2], 0 );
- return this->textureID[2];
- }
-#endif
-return -1;
-
+ {
+ this->renderToTexture=1;
+
+ GLuint fb2, depth_rb2;
+
+ glGenFramebuffersEXT (1, &fb2);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fb2);
+ glGenRenderbuffersEXT (1, &depth_rb2);
+ glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, depth_rb2);
+
+ glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, this->texsize,this->texsize );
+ glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb2);
+ this->fbuffer[1] = fb2;
+ this->depthb[1]= depth_rb2;
+ glGenTextures (1, &this->textureID[2]);
+ glBindTexture (GL_TEXTURE_2D, this->textureID[2]);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->textureID[2], 0);
+ return this->textureID[2];
+ }
+#endif
+ return -1;
}
/** Creates new pbuffers */
-RenderTarget::RenderTarget(int texsize, int width, int height) : useFBO(false) {
+RenderTarget::RenderTarget (int texsize, int width, int height)
+ : useFBO (false)
+{
+ int mindim = 0;
+ int origtexsize = 0;
- int mindim = 0;
- int origtexsize = 0;
-
- this->renderToTexture = 0;
- this->texsize = texsize;
+ this->renderToTexture = 0;
+ this->texsize = texsize;
#ifdef USE_FBO
- // Forceably disable FBO if user requested it but the video card / driver lacks
- // the appropraite frame buffer extension.
- useFBO = !!strstr ((char const *) glGetString (GL_EXTENSIONS),
+ // Forceably disable FBO if user requested it but the video card / driver lacks
+ // the appropraite frame buffer extension.
+ useFBO = !!strstr ((char const *) glGetString (GL_EXTENSIONS),
#ifdef USE_GLES1
- "GL_OES_framebuffer_object"
+ "GL_OES_framebuffer_object"
#else
- "GL_EXT_framebuffer_object"
+ "GL_EXT_framebuffer_object"
#endif
- );
- if (useFBO)
- {
-
- GLuint fb, depth_rb, rgba_tex, other_tex;
- glGenFramebuffersEXT(1, &fb);
- glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fb );
-
- glGenRenderbuffersEXT(1, &depth_rb);
- glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb );
- glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, this->texsize,this->texsize );
- glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb );
- this->fbuffer[0] = fb;
- this->depthb[0]= depth_rb;
-
- glGenTextures(1, &other_tex);
- glBindTexture(GL_TEXTURE_2D,other_tex);
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- //glGenerateMipmapEXT(GL_TEXTURE_2D);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
-
-
- glGenTextures(1, &rgba_tex);
- glBindTexture(GL_TEXTURE_2D, rgba_tex);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- //glGenerateMipmapEXT(GL_TEXTURE_2D);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
-
-
- glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, rgba_tex, 0 );
- this->textureID[0] = rgba_tex;
- this->textureID[1] = other_tex;
-
- GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-
- glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
-
- if (status == GL_FRAMEBUFFER_COMPLETE_EXT) {
- return;
- }
- std::cerr << "[projecM] warning: FBO support not detected. Using fallback." << std::endl;
- }
-
-#endif
-
-// Can reach here via two code paths:
-// (1) useFBO was set to false externally by cmake / system setting / etc.
-// (2) useFBO was true but forced to false as it failed to pass all the GLU extension checks.
-
- /** Fallback pbuffer creation via teximage hack */
- /** Check the texture size against the viewport size */
- /** If the viewport is smaller, then we'll need to scale the texture size down */
- /** If the viewport is larger, scale it up */
- mindim = width < height ? width : height;
- origtexsize = this->texsize;
- this->texsize = nearestPower2( mindim, SCALE_MINIFY );
- glGenTextures(1, &this->textureID[0] );
-
- glBindTexture(GL_TEXTURE_2D, this->textureID[0] );
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexImage2D(GL_TEXTURE_2D,
- 0,
- GL_RGBA,
- this->texsize, this->texsize,
- 0,
- GL_RGBA,
- GL_UNSIGNED_BYTE,
- NULL);
-
-
-
- return;
- }
-
- void RenderTarget::fallbackRescale(int width, int height)
+ );
+ if (useFBO)
{
- int mindim = width < height ? width : height;
- int origtexsize = this->texsize;
- this->texsize = nearestPower2( mindim, SCALE_MINIFY );
+ GLuint fb, depth_rb, rgba_tex, other_tex;
+ glGenFramebuffersEXT (1, &fb);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fb);
- if (origtexsize == texsize)
+ glGenRenderbuffersEXT (1, &depth_rb);
+ glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, depth_rb);
+ glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, this->texsize,this->texsize );
+ glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);
+ this->fbuffer[0] = fb;
+ this->depthb[0]= depth_rb;
+
+ glGenTextures (1, &other_tex);
+ glBindTexture (GL_TEXTURE_2D,other_tex);
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ //glGenerateMipmapEXT (GL_TEXTURE_2D);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+
+
+
+ glGenTextures (1, &rgba_tex);
+ glBindTexture (GL_TEXTURE_2D, rgba_tex);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, texsize, texsize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ //glGenerateMipmapEXT (GL_TEXTURE_2D);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+
+
+
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, rgba_tex, 0);
+ this->textureID[0] = rgba_tex;
+ this->textureID[1] = other_tex;
+
+ GLenum status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
+
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
+
+ if (status == GL_FRAMEBUFFER_COMPLETE_EXT) {
return;
-
- /* Create the texture that will be bound to the render this */
- /*
-
- if ( this->texsize != origtexsize ) {
-
- glDeleteTextures( 1, &this->textureID[0] );
- }
- */
-
- glGenTextures(1, &this->textureID[0] );
-
- glBindTexture(GL_TEXTURE_2D, this->textureID[0] );
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexImage2D(GL_TEXTURE_2D,
- 0,
- GL_RGBA,
- this->texsize, this->texsize,
- 0,
- GL_RGBA,
- GL_UNSIGNED_BYTE,
- NULL);
-
-
+ }
+ std::cerr << "[projecM] warning: FBO support not detected. Using fallback." << std::endl;
}
+#endif /* USE_FBO */
+
+ // Can reach here via two code paths:
+ // (1) useFBO was set to false externally by cmake / system setting / etc.
+ // (2) useFBO was true but forced to false as it failed to pass all the GLU extension checks.
+
+ /** Fallback pbuffer creation via teximage hack */
+ /** Check the texture size against the viewport size */
+ /** If the viewport is smaller, then we'll need to scale the texture size down */
+ /** If the viewport is larger, scale it up */
+ mindim = width < height ? width : height;
+ origtexsize = this->texsize;
+ this->texsize = nearestPower2 (mindim, SCALE_MINIFY);
+ glGenTextures (1, &this->textureID[0]);
+
+ glBindTexture (GL_TEXTURE_2D, this->textureID[0]);
+ //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glTexImage2D (GL_TEXTURE_2D,
+ 0,
+ GL_RGBA,
+ this->texsize, this->texsize,
+ 0,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ NULL);
+
+ return;
+}
+
+void
+RenderTarget::fallbackRescale (int width, int height)
+{
+ int mindim = width < height ? width : height;
+ int origtexsize = this->texsize;
+
+ this->texsize = nearestPower2 (mindim, SCALE_MINIFY);
+
+ if (origtexsize == texsize)
+ return;
+
+ /* Create the texture that will be bound to the render this */
+ /*
+
+ if (this->texsize != origtexsize) {
+ glDeleteTextures (1, &this->textureID[0]);
+ }
+ */
+
+ glGenTextures (1, &this->textureID[0]);
+
+ glBindTexture (GL_TEXTURE_2D, this->textureID[0]);
+ //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glTexImage2D (GL_TEXTURE_2D,
+ 0,
+ GL_RGBA,
+ this->texsize, this->texsize,
+ 0,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ NULL);
+}
/** Destroys the pbuffer */
/** Locks the pbuffer */
-void RenderTarget::lock() {
-
+void
+RenderTarget::lock()
+{
#ifdef USE_FBO
- if(this->useFBO)
- {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->fbuffer[0]);
- }
+ if (this->useFBO)
+ {
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, this->fbuffer[0]);
+ }
#endif
- }
+}
/** Unlocks the pbuffer */
-void RenderTarget::unlock() {
-
+void
+RenderTarget::unlock()
+{
#ifdef USE_FBO
- if(this->useFBO)
- {
- glBindTexture( GL_TEXTURE_2D, this->textureID[1] );
- glCopyTexSubImage2D( GL_TEXTURE_2D,
- 0, 0, 0, 0, 0,
- this->texsize, this->texsize );
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- return;
- }
-#endif
- /** Fallback texture path */
-
- glBindTexture( GL_TEXTURE_2D, this->textureID[0] );
-
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, this->texsize, this->texsize );
+ if (this->useFBO)
+ {
+ glBindTexture (GL_TEXTURE_2D, this->textureID[1]);
+ glCopyTexSubImage2D (GL_TEXTURE_2D,
+ 0, 0, 0, 0, 0,
+ this->texsize, this->texsize);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
+ return;
}
+#endif
+ /** Fallback texture path */
-/**
+ glBindTexture (GL_TEXTURE_2D, this->textureID[0]);
+
+ glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 0, 0, this->texsize, this->texsize);
+}
+
+/**
* Calculates the nearest power of two to the given number using the
* appropriate rule
*/
-int RenderTarget::nearestPower2( int value, TextureScale scaleRule ) {
+int
+RenderTarget::nearestPower2 (int value, TextureScale scaleRule)
+{
+ int x = value;
+ int power = 0;
- int x = value;
- int power = 0;
-
- while ( ( x & 0x01 ) != 1 ) {
- x >>= 1;
- }
-
- if ( x == 1 ) {
- return value;
- } else {
- x = value;
- while ( x != 0 ) {
- x >>= 1;
- power++;
- }
- switch ( scaleRule ) {
- case SCALE_NEAREST:
- if ( ( ( 1 << power ) - value ) <= ( value - ( 1 << ( power - 1 ) ) ) ) {
- return 1 << power;
- } else {
- return 1 << ( power - 1 );
- }
- case SCALE_MAGNIFY:
- return 1 << power;
- case SCALE_MINIFY:
- return 1 << ( power - 1 );
- default:
- break;
- }
- }
- return 0;
+ while ((x & 0x01) != 1) {
+ x >>= 1;
}
+
+ if (x == 1) {
+ return value;
+ } else {
+ x = value;
+ while (x != 0) {
+ x >>= 1;
+ power++;
+ }
+ switch (scaleRule) {
+ case SCALE_NEAREST:
+ if (((1 << power) - value) <= (value - (1 << (power - 1)))) {
+ return 1 << power;
+ } else {
+ return 1 << (power - 1);
+ }
+ case SCALE_MAGNIFY:
+ return 1 << power;
+ case SCALE_MINIFY:
+ return 1 << (power - 1);
+ default:
+ break;
+ }
+ }
+ return 0;
+}
diff --git a/src/libprojectM/Renderer/FBO.hpp b/src/libprojectM/Renderer/FBO.hpp
index 77a1272..21f13ec 100644
--- a/src/libprojectM/Renderer/FBO.hpp
+++ b/src/libprojectM/Renderer/FBO.hpp
@@ -24,7 +24,6 @@
* Opaque render target
*
*/
-
#ifndef _RENDERTARGET_H
#define _RENDERTARGET_H
@@ -47,15 +46,19 @@
#endif
#endif
-typedef enum { SCALE_NEAREST, SCALE_MAGNIFY, SCALE_MINIFY } TextureScale;
+
+typedef enum {
+ SCALE_NEAREST,
+ SCALE_MAGNIFY,
+ SCALE_MINIFY
+} TextureScale;
+
class RenderTarget {
-
-
public:
- /** Texture size */
- int texsize;
-
+ /** Texture size */
+ int texsize;
+
int useFBO;
int renderToTexture;
@@ -68,22 +71,21 @@
int nearestPower2( int value, TextureScale scaleRule );
void fallbackRescale(int width, int height);
- /** Opaque pbuffer context and pbuffer */
-/*
+ /** Opaque pbuffer context and pbuffer */
+ /*
#ifdef MACOS
- void *origContext;
- void *pbufferContext;
- void *pbuffer;
+ void *origContext;
+ void *pbufferContext;
+ void *pbuffer;
#endif
-*/
- /** Render target texture ID for non-pbuffer systems */
- GLuint textureID[3];
+ */
+ /** Render target texture ID for non-pbuffer systems */
+ GLuint textureID[3];
#ifdef USE_FBO
- GLuint fbuffer[2];
- GLuint depthb[2];
+ GLuint fbuffer[2];
+ GLuint depthb[2];
#endif
- };
-
+};
#endif /** !_RENDERTARGET_H */
diff --git a/src/libprojectM/Renderer/Filters.cpp b/src/libprojectM/Renderer/Filters.cpp
index 3e831f9..f064552 100644
--- a/src/libprojectM/Renderer/Filters.cpp
+++ b/src/libprojectM/Renderer/Filters.cpp
@@ -4,7 +4,6 @@
* Created on: Jun 18, 2008
* Author: pete
*/
-
#include "Common.hpp"
#ifdef USE_GLES1
@@ -21,78 +20,82 @@
#include "Filters.hpp"
-void Brighten::Draw(RenderContext &context)
+
+void
+Brighten::Draw(RenderContext &context)
{
- float points[4][2] = {{-0.5, -0.5},
- {-0.5, 0.5},
- { 0.5, 0.5},
- { 0.5, -0.5}};
+ float points[4][2] = {{-0.5, -0.5},
+ {-0.5, 0.5},
+ { 0.5, 0.5},
+ { 0.5, -0.5}};
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2,GL_FLOAT,0,points);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2,GL_FLOAT,0,points);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
- glBlendFunc(GL_ZERO, GL_DST_COLOR);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
- glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBlendFunc(GL_ZERO, GL_DST_COLOR);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
-void Darken::Draw(RenderContext &context)
+void
+Darken::Draw(RenderContext &context)
{
- float points[4][2] = {{-0.5, -0.5},
- {-0.5, 0.5},
- { 0.5, 0.5},
- { 0.5, -0.5}};
+ float points[4][2] = {{-0.5, -0.5},
+ {-0.5, 0.5},
+ { 0.5, 0.5},
+ { 0.5, -0.5}};
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2,GL_FLOAT,0,points);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glBlendFunc(GL_ZERO, GL_DST_COLOR);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glBlendFunc(GL_ZERO, GL_DST_COLOR);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
-void Invert::Draw(RenderContext &context)
+void
+Invert::Draw(RenderContext &context)
{
- float points[4][2] = {{-0.5, -0.5},
- {-0.5, 0.5},
- { 0.5, 0.5},
- { 0.5, -0.5}};
+ float points[4][2] = {{-0.5, -0.5},
+ {-0.5, 0.5},
+ { 0.5, 0.5},
+ { 0.5, -0.5}};
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2,GL_FLOAT,0,points);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
-void Solarize::Draw(RenderContext &context)
+void
+Solarize::Draw(RenderContext &context)
{
- float points[4][2] = {{-0.5, -0.5},
- {-0.5, 0.5},
- { 0.5, 0.5},
- { 0.5, -0.5}};
+ float points[4][2] = {{-0.5, -0.5},
+ {-0.5, 0.5},
+ { 0.5, 0.5},
+ { 0.5, -0.5}};
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2,GL_FLOAT,0,points);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2,GL_FLOAT,0,points);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glBlendFunc(GL_ZERO, GL_ONE_MINUS_DST_COLOR);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
- glBlendFunc(GL_DST_COLOR, GL_ONE);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glBlendFunc(GL_ZERO, GL_ONE_MINUS_DST_COLOR);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBlendFunc(GL_DST_COLOR, GL_ONE);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
-
diff --git a/src/libprojectM/Renderer/Filters.hpp b/src/libprojectM/Renderer/Filters.hpp
index 6ce64da..c27668a 100644
--- a/src/libprojectM/Renderer/Filters.hpp
+++ b/src/libprojectM/Renderer/Filters.hpp
@@ -4,38 +4,38 @@
* Created on: Jun 18, 2008
* Author: pete
*/
-
#ifndef FILTERS_HPP_
#define FILTERS_HPP_
#include "Renderable.hpp"
+
class Brighten : public RenderItem
{
public:
- Brighten(){}
- void Draw(RenderContext &context);
+ Brighten(){}
+ void Draw(RenderContext &context);
};
class Darken : public RenderItem
{
public:
- Darken(){}
- void Draw(RenderContext &context);
+ Darken(){}
+ void Draw(RenderContext &context);
};
class Invert : public RenderItem
{
public:
- Invert(){}
- void Draw(RenderContext &context);
+ Invert(){}
+ void Draw(RenderContext &context);
};
class Solarize : public RenderItem
{
public:
- Solarize(){}
- void Draw(RenderContext &context);
+ Solarize(){}
+ void Draw(RenderContext &context);
};
#endif /* FILTERS_HPP_ */
diff --git a/src/libprojectM/Renderer/MilkdropWaveform.cpp b/src/libprojectM/Renderer/MilkdropWaveform.cpp
index db1181f..d6859c9 100644
--- a/src/libprojectM/Renderer/MilkdropWaveform.cpp
+++ b/src/libprojectM/Renderer/MilkdropWaveform.cpp
@@ -23,351 +23,366 @@
#include "math.h"
#include "BeatDetect.hpp"
-MilkdropWaveform::MilkdropWaveform(): RenderItem(),
- x(0.5), y(0.5), r(1), g(0), b(0), a(1), mystery(0), mode(Line), scale(10), smoothing(0), rot(0), samples(0),modOpacityStart(0),modOpacityEnd(1),
- modulateAlphaByVolume(false), maximizeColors(false), additive(false), dots(false), thick(false), loop(false) {}
-void MilkdropWaveform::Draw(RenderContext &context)
+MilkdropWaveform::MilkdropWaveform()
+ : RenderItem(),
+ x(0.5), y(0.5),
+ r(1), g(0), b(0), a(1),
+ mystery(0),
+ mode(Line),
+ scale(10),
+ smoothing(0),
+ rot(0),
+ samples(0),
+ modOpacityStart(0),
+ modOpacityEnd(1),
+ modulateAlphaByVolume(false),
+ maximizeColors(false),
+ additive(false),
+ dots(false),
+ thick(false),
+ loop(false)
+{}
+
+void
+MilkdropWaveform::Draw(RenderContext &context)
{
- WaveformMath(context);
+ WaveformMath(context);
- glMatrixMode( GL_MODELVIEW );
- glPushMatrix();
- glLoadIdentity();
+ glMatrixMode( GL_MODELVIEW );
+ glPushMatrix();
+ glLoadIdentity();
- if(modulateAlphaByVolume) ModulateOpacityByVolume(context);
- else temp_a = a;
- MaximizeColors(context);
+ if (modulateAlphaByVolume) ModulateOpacityByVolume(context);
+ else temp_a = a;
+ MaximizeColors(context);
- #ifndef USE_GLES1
- if(dots==1) glEnable(GL_LINE_STIPPLE);
- #endif
+#ifndef USE_GLES1
+ if(dots==1) glEnable(GL_LINE_STIPPLE);
+#endif
- //Thick wave drawing
- if (thick==1) glLineWidth( (context.texsize < 512 ) ? 2 : 2*context.texsize/512);
- else glLineWidth( (context.texsize < 512 ) ? 1 : context.texsize/512);
+ //Thick wave drawing
+ if (thick == 1) glLineWidth( (context.texsize < 512 ) ? 2 : 2*context.texsize/512);
+ else glLineWidth( (context.texsize < 512 ) ? 1 : context.texsize/512);
- //Additive wave drawing (vice overwrite)
- if (additive==1)glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ //Additive wave drawing (vice overwrite)
+ if (additive == 1) glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glTranslatef(.5, .5, 0);
- glRotatef(rot, 0, 0, 1);
- glScalef(aspectScale, 1.0, 1.0);
- glTranslatef(-.5, -.5, 0);
+ glTranslatef(.5, .5, 0);
+ glRotatef(rot, 0, 0, 1);
+ glScalef(aspectScale, 1.0, 1.0);
+ glTranslatef(-.5, -.5, 0);
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glVertexPointer(2,GL_FLOAT,0,wavearray);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glVertexPointer(2,GL_FLOAT,0,wavearray);
- if (loop)
- glDrawArrays(GL_LINE_LOOP,0,samples);
- else
- glDrawArrays(GL_LINE_STRIP,0,samples);
+ if (loop)
+ glDrawArrays(GL_LINE_LOOP,0,samples);
+ else
+ glDrawArrays(GL_LINE_STRIP,0,samples);
- if (two_waves)
- {
- glVertexPointer(2,GL_FLOAT,0,wavearray2);
- if (loop)
- glDrawArrays(GL_LINE_LOOP,0,samples);
- else
- glDrawArrays(GL_LINE_STRIP,0,samples);
- }
+ if (two_waves)
+ {
+ glVertexPointer(2,GL_FLOAT,0,wavearray2);
+ if (loop)
+ glDrawArrays(GL_LINE_LOOP,0,samples);
+ else
+ glDrawArrays(GL_LINE_STRIP,0,samples);
+ }
- #ifndef USE_GLES1
- if(dots==1) glDisable(GL_LINE_STIPPLE);
- #endif
+#ifndef USE_GLES1
+ if(dots==1) glDisable(GL_LINE_STIPPLE);
+#endif
- glPopMatrix();
+ glPopMatrix();
}
-void MilkdropWaveform::ModulateOpacityByVolume(RenderContext &context)
+void
+MilkdropWaveform::ModulateOpacityByVolume(RenderContext &context)
{
+ //modulate volume by opacity
+ //
+ //set an upper and lower bound and linearly
+ //calculate the opacity from 0=lower to 1=upper
+ //based on current volume
- //modulate volume by opacity
- //
- //set an upper and lower bound and linearly
- //calculate the opacity from 0=lower to 1=upper
- //based on current volume
-
- if (context.beatDetect->vol<= modOpacityStart) temp_a=0.0;
- else if (context.beatDetect->vol>=modOpacityEnd) temp_a=a;
- else temp_a=a*((context.beatDetect->vol-modOpacityStart)/(modOpacityEnd-modOpacityStart));
-
+ if (context.beatDetect->vol<= modOpacityStart)
+ temp_a=0.0;
+ else if (context.beatDetect->vol>=modOpacityEnd)
+ temp_a=a;
+ else
+ temp_a=a*((context.beatDetect->vol-modOpacityStart)/(modOpacityEnd-modOpacityStart));
}
-void MilkdropWaveform::MaximizeColors(RenderContext &context)
+void
+MilkdropWaveform::MaximizeColors(RenderContext &context)
{
+ float wave_r_switch=0, wave_g_switch=0, wave_b_switch=0;
- float wave_r_switch=0, wave_g_switch=0, wave_b_switch=0;
- //wave color brightening
- //
- //forces max color value to 1.0 and scales
- // the rest accordingly
- if(mode==Blob2 || mode==Blob5)
- switch(context.texsize)
- {
- case 256: temp_a *= 0.07f; break;
- case 512: temp_a *= 0.09f; break;
- case 1024: temp_a *= 0.11f; break;
- case 2048: temp_a *= 0.13f; break;
- }
- else if(mode==Blob3)
- {
- switch(context.texsize)
- {
- case 256: temp_a *= 0.075f; break;
- case 512: temp_a *= 0.15f; break;
- case 1024: temp_a *= 0.22f; break;
- case 2048: temp_a *= 0.33f; break;
- }
- temp_a*=1.3f;
- temp_a*=std::pow(context.beatDetect->treb , 2.0f);
- }
+ //wave color brightening
+ //
+ //forces max color value to 1.0 and scales
+ // the rest accordingly
+ if (mode==Blob2 || mode==Blob5)
+ switch(context.texsize)
+ {
+ case 256: temp_a *= 0.07f; break;
+ case 512: temp_a *= 0.09f; break;
+ case 1024: temp_a *= 0.11f; break;
+ case 2048: temp_a *= 0.13f; break;
+ }
+ else if(mode==Blob3)
+ {
+ switch(context.texsize)
+ {
+ case 256: temp_a *= 0.075f; break;
+ case 512: temp_a *= 0.15f; break;
+ case 1024: temp_a *= 0.22f; break;
+ case 2048: temp_a *= 0.33f; break;
+ }
+ temp_a*=1.3f;
+ temp_a*=std::pow(context.beatDetect->treb , 2.0f);
+ }
- if (maximizeColors==true)
- {
- if(r>=g && r>=b) //red brightest
- {
- wave_b_switch=b*(1/r);
- wave_g_switch=g*(1/r);
- wave_r_switch=1.0;
- }
- else if (b>=g && b>=r) //blue brightest
- {
- wave_r_switch=r*(1/b);
- wave_g_switch=g*(1/b);
- wave_b_switch=1.0;
-
- }
-
- else if (g>=b && g>=r) //green brightest
- {
- wave_b_switch=b*(1/g);
- wave_r_switch=r*(1/g);
- wave_g_switch=1.0;
- }
+ if (maximizeColors==true)
+ {
+ if(r>=g && r>=b) //red brightest
+ {
+ wave_b_switch=b*(1/r);
+ wave_g_switch=g*(1/r);
+ wave_r_switch=1.0;
+ }
+ else if (b>=g && b>=r) //blue brightest
+ {
+ wave_r_switch=r*(1/b);
+ wave_g_switch=g*(1/b);
+ wave_b_switch=1.0;
+ }
+ else if (g>=b && g>=r) //green brightest
+ {
+ wave_b_switch=b*(1/g);
+ wave_r_switch=r*(1/g);
+ wave_g_switch=1.0;
+ }
- glColor4f(wave_r_switch, wave_g_switch, wave_b_switch, temp_a * masterAlpha);
- }
- else
- {
- glColor4f(r, g, b, temp_a * masterAlpha);
- }
+ glColor4f(wave_r_switch, wave_g_switch, wave_b_switch, temp_a * masterAlpha);
+ }
+ else
+ {
+ glColor4f(r, g, b, temp_a * masterAlpha);
+ }
}
-void MilkdropWaveform::WaveformMath(RenderContext &context)
+void
+MilkdropWaveform::WaveformMath(RenderContext &context)
{
+ int i;
+ float r, theta;
- int i;
+ float offset;
- float r, theta;
+ float wave_x_temp=0;
+ float wave_y_temp=0;
- float offset;
-
- float wave_x_temp=0;
- float wave_y_temp=0;
-
- float cos_rot;
- float sin_rot;
-
- offset=x-.5;
- float temp_y;
-
- two_waves = false;
- loop = false;
-
- switch(mode)
- {
-
- case Circle:
- {
- loop = true;
- rot = 0;
- aspectScale=1.0;
- temp_y=-1*(y-1.0);
+ float cos_rot;
+ float sin_rot;
- samples = 0? 512-32 : context.beatDetect->pcm->numsamples;
+ offset=x-.5;
+ float temp_y;
- float inv_nverts_minus_one = 1.0f/(float)(samples);
+ two_waves = false;
+ loop = false;
- float last_value = context.beatDetect->pcm->pcmdataR[samples-1]+context.beatDetect->pcm->pcmdataL[samples-1];
- float first_value = context.beatDetect->pcm->pcmdataR[0]+context.beatDetect->pcm->pcmdataL[0];
- float offset = first_value-last_value;
-
- for ( int i=0;i<samples;i++)
- {
-
- float value = context.beatDetect->pcm->pcmdataR[i]+context.beatDetect->pcm->pcmdataL[i];
- value += offset * (i/(float)samples);
-
- r=(0.5 + 0.4f*.12*value*scale + mystery)*.5;
- theta=i*inv_nverts_minus_one*6.28f + context.time*0.2f;
-
- wavearray[i][0]=(r*cos(theta)*(context.aspectCorrect? context.aspectRatio : 1.0)+x);
- wavearray[i][1]=(r*sin(theta)+temp_y);
- }
- }
-
- break;
-
- case RadialBlob://circularly moving waveform
-
- rot = 0;
- aspectScale = context.aspectRatio;
-
- temp_y=-1*(y-1.0);
-
- samples = 512-32;
- for ( int i=0;i<512-32;i++)
- {
- theta=context.beatDetect->pcm->pcmdataL[i+32]*0.06*scale * 1.57 + context.time*2.3;
- r=(0.53 + 0.43*context.beatDetect->pcm->pcmdataR[i]*0.12*scale+ mystery)*.5;
-
- wavearray[i][0]=(r*cos(theta)*(context.aspectCorrect ? context.aspectRatio : 1.0)+x);
- wavearray[i][1]=(r*sin(theta)+temp_y);
- }
-
- break;
-
- case Blob2://EXPERIMENTAL
-
- temp_y=-1*(y-1.0);
- rot = 0;
- aspectScale =1.0;
- samples = 512-32;
-
- for ( int i=0;i<512-32;i++)
- {
- wavearray[i][0]=(context.beatDetect->pcm->pcmdataR[i]*scale*0.5*(context.aspectCorrect ? context.aspectRatio : 1.0) + x);
- wavearray[i][1]=(context.beatDetect->pcm->pcmdataL[i+32]*scale*0.5 + temp_y);
- }
-
- break;
-
- case Blob3://EXPERIMENTAL
-
- temp_y=-1*(y-1.0);
-
- rot = 0;
- aspectScale =1.0;
-
- samples = 512-32;
-
- for ( int i=0;i<512-32;i++)
- {
- wavearray[i][0]=(context.beatDetect->pcm->pcmdataR[i] * scale*0.5 + x);
- wavearray[i][1]=( (context.beatDetect->pcm->pcmdataL[i+32]*scale*0.5 + temp_y));
- }
-
- break;
-
- case DerivativeLine://single x-axis derivative waveform
- {
- rot =-mystery*90;
- aspectScale=1.0;
-
- temp_y=-1*(y-1.0);
-
- float w1 = 0.45f + 0.5f*(mystery*0.5f + 0.5f);
- float w2 = 1.0f - w1;
- float xx[512], yy[512];
- samples = 512-32;
-
- for (int i=0; i<512-32; i++)
- {
- xx[i] = -1.0f + 2.0f*(i/(512.0-32.0)) + x;
- yy[i] =0.4* context.beatDetect->pcm->pcmdataL[i]*0.47f*scale + temp_y;
- xx[i] += 0.4*context.beatDetect->pcm->pcmdataR[i]*0.44f*scale;
-
- if (i>1)
- {
- xx[i] = xx[i]*w2 + w1*(xx[i-1]*2.0f - xx[i-2]);
- yy[i] = yy[i]*w2 + w1*(yy[i-1]*2.0f - yy[i-2]);
- }
- wavearray[i][0]=xx[i];
- wavearray[i][1]=yy[i];
- } }
- break;
-
- case Blob5://EXPERIMENTAL
-
- rot = 0;
- aspectScale =1.0;
-
- temp_y=-1*(y-1.0);
-
- cos_rot = cosf(context.time*0.3f);
- sin_rot = sinf(context.time*0.3f);
- samples = 512-32;
-
- for ( int i=0;i<512-32;i++)
- {
- float x0 = (context.beatDetect->pcm->pcmdataR[i]*context.beatDetect->pcm->pcmdataL[i+32] + context.beatDetect->pcm->pcmdataL[i+32]*context.beatDetect->pcm->pcmdataR[i]);
- float y0 = (context.beatDetect->pcm->pcmdataR[i]*context.beatDetect->pcm->pcmdataR[i] - context.beatDetect->pcm->pcmdataL[i+32]*context.beatDetect->pcm->pcmdataL[i+32]);
- wavearray[i][0]=((x0*cos_rot - y0*sin_rot)*scale*0.5*(context.aspectCorrect ? context.aspectRatio : 1.0) + x);
- wavearray[i][1]=( (x0*sin_rot + y0*cos_rot)*scale*0.5 + temp_y);
- }
- break;
-
- case Line://single waveform
+ switch(mode)
+ {
+ case Circle:
+ {
+ loop = true;
+ rot = 0;
+ aspectScale=1.0;
+ temp_y=-1*(y-1.0);
- wave_x_temp=-2*0.4142*(fabs(fabs(mystery)-.5)-.5);
+ samples = 0? 512-32 : context.beatDetect->pcm->numsamples;
- rot = -mystery*90;
- aspectScale =1.0+wave_x_temp;
- wave_x_temp=-1*(x-1.0);
- samples = 0 ? 512-32 : context.beatDetect->pcm->numsamples;
+ float inv_nverts_minus_one = 1.0f/(float)(samples);
- for ( int i=0;i< samples;i++)
- {
+ float last_value = context.beatDetect->pcm->pcmdataR[samples-1]+context.beatDetect->pcm->pcmdataL[samples-1];
+ float first_value = context.beatDetect->pcm->pcmdataR[0]+context.beatDetect->pcm->pcmdataL[0];
+ float offset = first_value-last_value;
- wavearray[i][0]=i/(float) samples;
- wavearray[i][1]=context.beatDetect->pcm->pcmdataR[i]*.04*scale+wave_x_temp;
+ for ( int i=0;i<samples;i++)
+ {
+ float value = context.beatDetect->pcm->pcmdataR[i]+context.beatDetect->pcm->pcmdataL[i];
+ value += offset * (i/(float)samples);
- }
- // printf("%f %f\n",renderTarget->texsize*wave_y_temp,wave_y_temp);
+ r=(0.5 + 0.4f*.12*value*scale + mystery)*.5;
+ theta=i*inv_nverts_minus_one*6.28f + context.time*0.2f;
- break;
+ wavearray[i][0]=(r*cos(theta)*(context.aspectCorrect? context.aspectRatio : 1.0)+x);
+ wavearray[i][1]=(r*sin(theta)+temp_y);
+ }
+ }
- case DoubleLine://dual waveforms
+ break;
+
+ case RadialBlob://circularly moving waveform
+
+ rot = 0;
+ aspectScale = context.aspectRatio;
+
+ temp_y=-1*(y-1.0);
+
+ samples = 512-32;
+ for ( int i=0;i<512-32;i++)
+ {
+ theta=context.beatDetect->pcm->pcmdataL[i+32]*0.06*scale * 1.57 + context.time*2.3;
+ r=(0.53 + 0.43*context.beatDetect->pcm->pcmdataR[i]*0.12*scale+ mystery)*.5;
+
+ wavearray[i][0]=(r*cos(theta)*(context.aspectCorrect ? context.aspectRatio : 1.0)+x);
+ wavearray[i][1]=(r*sin(theta)+temp_y);
+ }
+
+ break;
+
+ case Blob2://EXPERIMENTAL
+
+ temp_y=-1*(y-1.0);
+ rot = 0;
+ aspectScale =1.0;
+ samples = 512-32;
+
+ for ( int i=0;i<512-32;i++)
+ {
+ wavearray[i][0]=(context.beatDetect->pcm->pcmdataR[i]*scale*0.5*(context.aspectCorrect ? context.aspectRatio : 1.0) + x);
+ wavearray[i][1]=(context.beatDetect->pcm->pcmdataL[i+32]*scale*0.5 + temp_y);
+ }
+
+ break;
+
+ case Blob3://EXPERIMENTAL
+
+ temp_y=-1*(y-1.0);
+
+ rot = 0;
+ aspectScale =1.0;
+
+ samples = 512-32;
+
+ for ( int i=0;i<512-32;i++)
+ {
+ wavearray[i][0]=(context.beatDetect->pcm->pcmdataR[i] * scale*0.5 + x);
+ wavearray[i][1]=( (context.beatDetect->pcm->pcmdataL[i+32]*scale*0.5 + temp_y));
+ }
+
+ break;
+
+ case DerivativeLine://single x-axis derivative waveform
+ {
+ rot =-mystery*90;
+ aspectScale=1.0;
+
+ temp_y=-1*(y-1.0);
+
+ float w1 = 0.45f + 0.5f*(mystery*0.5f + 0.5f);
+ float w2 = 1.0f - w1;
+ float xx[512], yy[512];
+ samples = 512-32;
+
+ for (int i=0; i<512-32; i++)
+ {
+ xx[i] = -1.0f + 2.0f*(i/(512.0-32.0)) + x;
+ yy[i] =0.4* context.beatDetect->pcm->pcmdataL[i]*0.47f*scale + temp_y;
+ xx[i] += 0.4*context.beatDetect->pcm->pcmdataR[i]*0.44f*scale;
+
+ if (i>1)
+ {
+ xx[i] = xx[i]*w2 + w1*(xx[i-1]*2.0f - xx[i-2]);
+ yy[i] = yy[i]*w2 + w1*(yy[i-1]*2.0f - yy[i-2]);
+ }
+ wavearray[i][0]=xx[i];
+ wavearray[i][1]=yy[i];
+ }
+ }
+ break;
+
+ case Blob5://EXPERIMENTAL
+
+ rot = 0;
+ aspectScale =1.0;
+
+ temp_y=-1*(y-1.0);
+
+ cos_rot = cosf(context.time*0.3f);
+ sin_rot = sinf(context.time*0.3f);
+ samples = 512-32;
+
+ for ( int i=0;i<512-32;i++)
+ {
+ float x0 = ( context.beatDetect->pcm->pcmdataR[i] * context.beatDetect->pcm->pcmdataL[i + 32]
+ + context.beatDetect->pcm->pcmdataL[i + 32] * context.beatDetect->pcm->pcmdataR[i]);
+ float y0 = ( context.beatDetect->pcm->pcmdataR[i] * context.beatDetect->pcm->pcmdataR[i]
+ - context.beatDetect->pcm->pcmdataL[i + 32] * context.beatDetect->pcm->pcmdataL[i + 32]);
+ wavearray[i][0] = ((x0*cos_rot - y0*sin_rot)*scale*0.5*(context.aspectCorrect ? context.aspectRatio : 1.0) + x);
+ wavearray[i][1] = ( (x0*sin_rot + y0*cos_rot)*scale*0.5 + temp_y);
+ }
+ break;
+
+ case Line://single waveform
+
+ wave_x_temp=-2*0.4142*(fabs(fabs(mystery)-.5)-.5);
+
+ rot = -mystery*90;
+ aspectScale =1.0+wave_x_temp;
+ wave_x_temp=-1*(x-1.0);
+ samples = 0 ? 512-32 : context.beatDetect->pcm->numsamples;
+
+ for ( int i=0;i< samples;i++)
+ {
+ wavearray[i][0]=i/(float) samples;
+ wavearray[i][1]=context.beatDetect->pcm->pcmdataR[i]*.04*scale+wave_x_temp;
+ }
+ // printf("%f %f\n",renderTarget->texsize*wave_y_temp,wave_y_temp);
+
+ break;
+
+ case DoubleLine://dual waveforms
+
+ wave_x_temp=-2*0.4142*(fabs(fabs(mystery)-.5)-.5);
+
+ rot = -mystery*90;
+ aspectScale =1.0+wave_x_temp;
- wave_x_temp=-2*0.4142*(fabs(fabs(mystery)-.5)-.5);
+ samples = 0 ? 512-32 : context.beatDetect->pcm->numsamples;
+ two_waves = true;
- rot = -mystery*90;
- aspectScale =1.0+wave_x_temp;
+ double y_adj = y*y*.5;
+ wave_y_temp=-1*(x-1);
- samples = 0 ? 512-32 : context.beatDetect->pcm->numsamples;
- two_waves = true;
+ for ( int i=0;i<samples;i++)
+ {
+ wavearray[i][0]=i/((float) samples);
+ wavearray[i][1]= context.beatDetect->pcm->pcmdataL[i]*.04*scale+(wave_y_temp+y_adj);
+ }
- double y_adj = y*y*.5;
+ for ( int i=0;i<samples;i++)
+ {
+ wavearray2[i][0]=i/((float) samples);
+ wavearray2[i][1]=context.beatDetect->pcm->pcmdataR[i]*.04*scale+(wave_y_temp-y_adj);
+ }
- wave_y_temp=-1*(x-1);
-
- for ( int i=0;i<samples;i++)
- {
- wavearray[i][0]=i/((float) samples);
- wavearray[i][1]= context.beatDetect->pcm->pcmdataL[i]*.04*scale+(wave_y_temp+y_adj);
- }
-
- for ( int i=0;i<samples;i++)
- {
- wavearray2[i][0]=i/((float) samples);
- wavearray2[i][1]=context.beatDetect->pcm->pcmdataR[i]*.04*scale+(wave_y_temp-y_adj);
- }
-
- break;
-
- }
+ break;
+ }
}
diff --git a/src/libprojectM/Renderer/MilkdropWaveform.hpp b/src/libprojectM/Renderer/MilkdropWaveform.hpp
index cdafd93..13a499b 100644
--- a/src/libprojectM/Renderer/MilkdropWaveform.hpp
+++ b/src/libprojectM/Renderer/MilkdropWaveform.hpp
@@ -4,62 +4,68 @@
* Created on: Jun 25, 2008
* Author: pete
*/
-
#ifndef MILKDROPWAVEFORM_HPP_
#define MILKDROPWAVEFORM_HPP_
#include "Renderable.hpp"
+
enum MilkdropWaveformMode
- {
- Circle=0, RadialBlob, Blob2, Blob3, DerivativeLine, Blob5, Line, DoubleLine
- };
+{
+ Circle=0,
+ RadialBlob,
+ Blob2,
+ Blob3,
+ DerivativeLine,
+ Blob5,
+ Line,
+ DoubleLine
+};
class MilkdropWaveform : public RenderItem
{
public:
+ float x;
+ float y;
+ float r;
+ float g;
+ float b;
+ float a;
- float x;
- float y;
+ float mystery;
- float r;
- float g;
- float b;
- float a;
+ MilkdropWaveformMode mode;
- float mystery;
+ bool additive;
+ bool dots;
+ bool thick;
+ bool modulateAlphaByVolume;
+ bool maximizeColors;
+ float scale;
+ float smoothing;
- MilkdropWaveformMode mode;
+ MilkdropWaveform();
+ void Draw(RenderContext &context);
- bool additive;
- bool dots;
- bool thick;
- bool modulateAlphaByVolume;
- bool maximizeColors;
- float scale;
- float smoothing;
-
- MilkdropWaveform();
- void Draw(RenderContext &context);
-
- float modOpacityStart;
- float modOpacityEnd;
+ float modOpacityStart;
+ float modOpacityEnd;
private:
- float temp_a;
- float rot;
- float aspectScale;
- int samples;
- bool two_waves;
- bool loop;
- float wavearray[2048][2];
- float wavearray2[2048][2];
+ float temp_a;
+ float rot;
+ float aspectScale;
+ int samples;
+ bool two_waves;
+ bool loop;
+ float wavearray[2048][2];
+ float wavearray2[2048][2];
- void MaximizeColors(RenderContext &context);
- void ModulateOpacityByVolume(RenderContext &context);
- void WaveformMath(RenderContext &context);
+ void MaximizeColors(RenderContext &context);
+ void ModulateOpacityByVolume(RenderContext &context);
+ void WaveformMath(RenderContext &context);
};
+
#endif /* MILKDROPWAVEFORM_HPP_ */
diff --git a/src/libprojectM/Renderer/PerPixelMesh.cpp b/src/libprojectM/Renderer/PerPixelMesh.cpp
index c378133..1b89f0c 100644
--- a/src/libprojectM/Renderer/PerPixelMesh.cpp
+++ b/src/libprojectM/Renderer/PerPixelMesh.cpp
@@ -4,45 +4,49 @@
#include "omptl/omptl"
#include "omptl/omptl_algorithm"
-PerPixelMesh::PerPixelMesh(int width, int height) : width(width), height(height), size (width * height),
- p(width * height, PixelPoint(0,0)),
- p_original(width * height, PixelPoint(0,0)),
- identity(width * height, PerPixelContext(0,0,0,0,0,0))
- {
- for (int j=0;j<height;j++)
- for(int i=0;i<width;i++)
- {
- int index = j * width + i;
- float xval=i/(float)(width-1);
- float yval=-((j/(float)(height-1))-1);
-
- p[index].x = xval;
- p[index].y = yval;
-
- p_original[index].x = xval;
- p_original[index].y = yval;
-
- identity[index].x= xval;
- identity[index].y= yval;
-
- //identity[index].x= (xval-.5)*2;
- //identity[index].y= (yval-.5)*2;
-
- identity[index].i= i;
- identity[index].j= j;
-
- identity[index].rad=hypot ( ( xval-.5 ) *2, ( yval-.5 ) *2 ) * .7071067;
- identity[index].theta=atan2 ( ( yval-.5 ) *2 , ( xval-.5 ) *2 );
- }
- }
-
-void PerPixelMesh::Reset()
+PerPixelMesh::PerPixelMesh (int width, int height)
+ : width(width), height(height),
+ size (width * height),
+ p(width * height, PixelPoint(0,0)),
+ p_original(width * height, PixelPoint(0,0)),
+ identity(width * height, PerPixelContext(0,0,0,0,0,0))
{
- omptl::copy(p_original.begin(), p_original.end(), p.begin());
+ for (int j = 0; j < height; j++)
+ for (int i = 0; i < width; i++)
+ {
+ int index = j * width + i;
+
+ float xval = i / (float) (width - 1);
+ float yval = -((j / (float) (height - 1)) - 1);
+
+ p[index].x = xval;
+ p[index].y = yval;
+
+ p_original[index].x = xval;
+ p_original[index].y = yval;
+
+ identity[index].x= xval;
+ identity[index].y= yval;
+
+ //identity[index].x= (xval-.5)*2;
+ //identity[index].y= (yval-.5)*2;
+
+ identity[index].i= i;
+ identity[index].j= j;
+
+ identity[index].rad=hypot ( ( xval-.5 ) *2, ( yval-.5 ) *2 ) * .7071067;
+ identity[index].theta=atan2 ( ( yval-.5 ) *2 , ( xval-.5 ) *2 );
+ }
+}
+
+void
+PerPixelMesh::Reset()
+{
+ omptl::copy(p_original.begin(), p_original.end(), p.begin());
}
PixelPoint::PixelPoint(float x, float y)
- : x(x), y(y) {}
+ : x(x), y(y) {}
PerPixelContext::PerPixelContext(float x, float y, float rad, float theta, int i, int j)
- : x(x), y(y), rad(rad), theta(theta), i(i), j(j) {}
+ : x(x), y(y), rad(rad), theta(theta), i(i), j(j) {}
diff --git a/src/libprojectM/Renderer/PerPixelMesh.hpp b/src/libprojectM/Renderer/PerPixelMesh.hpp
index f37a2b1..3b47a09 100644
--- a/src/libprojectM/Renderer/PerPixelMesh.hpp
+++ b/src/libprojectM/Renderer/PerPixelMesh.hpp
@@ -3,43 +3,43 @@
#include <vector>
+
struct PixelPoint
{
- float x;
- float y;
+ float x;
+ float y;
- PixelPoint(float x, float y);
+ PixelPoint(float x, float y);
};
struct PerPixelContext
{
- float x;
- float y;
- float rad;
- float theta;
+ float x;
+ float y;
+ float rad;
+ float theta;
- int i;
- int j;
+ int i;
+ int j;
- PerPixelContext(float x, float y, float rad, float theta, int i, int j);
+ PerPixelContext(float x, float y, float rad, float theta, int i, int j);
};
class PerPixelMesh
{
public:
- int width;
- int height;
- int size;
+ int width;
+ int height;
+ int size;
- std::vector<PixelPoint> p;
- std::vector<PixelPoint> p_original;
- std::vector<PerPixelContext> identity;
+ std::vector<PixelPoint> p;
+ std::vector<PixelPoint> p_original;
+ std::vector<PerPixelContext> identity;
- PerPixelMesh(int width, int height);
+ PerPixelMesh(int width, int height);
- void Reset();
+ void Reset();
};
-
#endif
diff --git a/src/libprojectM/Renderer/PerlinNoise.cpp b/src/libprojectM/Renderer/PerlinNoise.cpp
index a6bda55..2fefa2b 100644
--- a/src/libprojectM/Renderer/PerlinNoise.cpp
+++ b/src/libprojectM/Renderer/PerlinNoise.cpp
@@ -4,50 +4,50 @@
* Created on: Jul 11, 2008
* Author: pete
*/
-
#include "PerlinNoise.hpp"
#include <iostream>
#include <stdlib.h>
+
PerlinNoise::PerlinNoise()
{
- for (int x = 0; x < 256;x++)
- for (int y = 0; y < 256;y++)
- noise_lq[x][y] = noise(x , y);
+ for (int x = 0; x < 256;x++)
+ for (int y = 0; y < 256;y++)
+ noise_lq[x][y] = noise(x , y);
- for (int x = 0; x < 32;x++)
- for (int y = 0; y < 32;y++)
- noise_lq_lite[x][y] = noise(4*x,16*y);
+ for (int x = 0; x < 32;x++)
+ for (int y = 0; y < 32;y++)
+ noise_lq_lite[x][y] = noise(4*x,16*y);
- for (int x = 0; x < 256;x++)
- for (int y = 0; y < 256;y++)
- noise_mq[x][y] = InterpolatedNoise((float)x/(float)2.0,(float)y/(float)2.0);
+ for (int x = 0; x < 256;x++)
+ for (int y = 0; y < 256;y++)
+ noise_mq[x][y] = InterpolatedNoise((float)x/(float)2.0,(float)y/(float)2.0);
- for (int x = 0; x < 256;x++)
- for (int y = 0; y < 256;y++)
- noise_hq[x][y] = InterpolatedNoise((float)x/(float)3.0,(float)y/(float)3.0);
+ for (int x = 0; x < 256;x++)
+ for (int y = 0; y < 256;y++)
+ noise_hq[x][y] = InterpolatedNoise((float)x/(float)3.0,(float)y/(float)3.0);
- for (int x = 0; x < 32;x++)
- for (int y = 0; y < 32;y++)
- for (int z = 0; z < 32;z++)
- noise_lq_vol[x][y][z] = noise(x,y,z);
+ for (int x = 0; x < 32;x++)
+ for (int y = 0; y < 32;y++)
+ for (int z = 0; z < 32;z++)
+ noise_lq_vol[x][y][z] = noise(x,y,z);
- for (int x = 0; x < 32;x++)
- for (int y = 0; y < 32;y++)
- for (int z = 0; z < 32;z++)
- noise_hq_vol[x][y][z] = noise(x,y,z);//perlin_noise_3d(x,y,z,6121,7,seed3,0.5,64);
+ for (int x = 0; x < 32;x++)
+ for (int y = 0; y < 32;y++)
+ for (int z = 0; z < 32;z++)
+ noise_hq_vol[x][y][z] = noise(x,y,z);//perlin_noise_3d(x,y,z,6121,7,seed3,0.5,64);
- int seed = rand()%1000;
+ int seed = rand()%1000;
- int size = 512;
- int octaves = sqrt((double)size);
+ int size = 512;
+ int octaves = sqrt((double)size);
- for (int x = 0; x < size;x++)
- for (int y = 0; y < size;y++)
- noise_perlin[x][y] = perlin_noise_2d(x,y,6321,octaves,seed,0.5,size/4);
+ for (int x = 0; x < size;x++)
+ for (int y = 0; y < size;y++)
+ noise_perlin[x][y] = perlin_noise_2d(x,y,6321,octaves,seed,0.5,size/4);
}
PerlinNoise::~PerlinNoise()
{
- // TODO Auto-generated destructor stub
+ // TODO Auto-generated destructor stub
}
diff --git a/src/libprojectM/Renderer/PerlinNoise.hpp b/src/libprojectM/Renderer/PerlinNoise.hpp
index e1193d7..fc77808 100644
--- a/src/libprojectM/Renderer/PerlinNoise.hpp
+++ b/src/libprojectM/Renderer/PerlinNoise.hpp
@@ -10,232 +10,227 @@
#include <math.h>
+
class PerlinNoise
{
public:
-
- float noise_lq[256][256];
- float noise_lq_lite[32][32];
- float noise_mq[256][256];
- float noise_hq[256][256];
- float noise_perlin[512][512];
- float noise_lq_vol[32][32][32];
- float noise_hq_vol[32][32][32];
+ float noise_lq[256][256];
+ float noise_lq_lite[32][32];
+ float noise_mq[256][256];
+ float noise_hq[256][256];
+ float noise_perlin[512][512];
+ float noise_lq_vol[32][32][32];
+ float noise_hq_vol[32][32][32];
- PerlinNoise();
- virtual ~PerlinNoise();
+ PerlinNoise();
+ virtual ~PerlinNoise();
private:
- static inline float noise( int x)
- {
- x = (x<<13)^x;
- return (((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 2147483648.0);
- }
+ static inline float noise( int x)
+ {
+ x = (x<<13)^x;
+ return (((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 2147483648.0);
+ }
- static inline float noise(int x, int y)
- {
- int n = x + y * 57;
- return noise(n);
- }
+ static inline float noise(int x, int y)
+ {
+ int n = x + y * 57;
+ return noise(n);
+ }
- static inline float noise(int x, int y, int z)
- {
- int n = x + y * 57 + z * 141;
- return noise(n);
- }
+ static inline float noise(int x, int y, int z)
+ {
+ int n = x + y * 57 + z * 141;
+ return noise(n);
+ }
- static inline float cos_interp(float a, float b, float x)
- {
- float ft = x * 3.1415927;
- float f = (1 - cos(ft)) * .5;
+ static inline float cos_interp(float a, float b, float x)
+ {
+ float ft = x * 3.1415927;
+ float f = (1 - cos(ft)) * .5;
- return a*(1-f) + b*f;
- }
+ return a*(1-f) + b*f;
+ }
- static inline float cubic_interp(float v0, float v1, float v2, float v3, float x)
- {
- float P = (v3 - v2) - (v0 - v1);
- float Q = (v0 - v1) - P;
- float R = v2 - v0;
+ static inline float cubic_interp(float v0, float v1, float v2, float v3, float x)
+ {
+ float P = (v3 - v2) - (v0 - v1);
+ float Q = (v0 - v1) - P;
+ float R = v2 - v0;
- return P*pow(x,3) + Q * pow(x,2) + R*x + v1;
- }
+ return P*pow(x,3) + Q * pow(x,2) + R*x + v1;
+ }
- static inline float InterpolatedNoise(float x, float y)
- {
- int integer_X = int(x);
- float fractional_X = x - integer_X;
+ static inline float InterpolatedNoise(float x, float y)
+ {
+ int integer_X = int(x);
+ float fractional_X = x - integer_X;
- int integer_Y = int(y);
- float fractional_Y = y - integer_Y;
+ int integer_Y = int(y);
+ float fractional_Y = y - integer_Y;
- float a0 = noise(integer_X - 1, integer_Y - 1);
- float a1 = noise(integer_X, integer_Y - 1);
- float a2 = noise(integer_X + 1, integer_Y - 1);
- float a3 = noise(integer_X + 2, integer_Y - 1);
+ float a0 = noise(integer_X - 1, integer_Y - 1);
+ float a1 = noise(integer_X, integer_Y - 1);
+ float a2 = noise(integer_X + 1, integer_Y - 1);
+ float a3 = noise(integer_X + 2, integer_Y - 1);
- float x0 = noise(integer_X - 1, integer_Y);
- float x1 = noise(integer_X, integer_Y);
- float x2 = noise(integer_X + 1, integer_Y);
- float x3 = noise(integer_X + 2, integer_Y);
+ float x0 = noise(integer_X - 1, integer_Y);
+ float x1 = noise(integer_X, integer_Y);
+ float x2 = noise(integer_X + 1, integer_Y);
+ float x3 = noise(integer_X + 2, integer_Y);
- float y0 = noise(integer_X + 0, integer_Y + 1);
- float y1 = noise(integer_X, integer_Y + 1);
- float y2 = noise(integer_X + 1, integer_Y + 1);
- float y3 = noise(integer_X + 2, integer_Y + 1);
+ float y0 = noise(integer_X + 0, integer_Y + 1);
+ float y1 = noise(integer_X, integer_Y + 1);
+ float y2 = noise(integer_X + 1, integer_Y + 1);
+ float y3 = noise(integer_X + 2, integer_Y + 1);
- float b0 = noise(integer_X - 1, integer_Y + 2);
- float b1 = noise(integer_X, integer_Y + 2);
- float b2 = noise(integer_X + 1, integer_Y + 2);
- float b3 = noise(integer_X + 2, integer_Y + 2);
+ float b0 = noise(integer_X - 1, integer_Y + 2);
+ float b1 = noise(integer_X, integer_Y + 2);
+ float b2 = noise(integer_X + 1, integer_Y + 2);
+ float b3 = noise(integer_X + 2, integer_Y + 2);
- float i0 = cubic_interp(a0 , a1, a2, a3, fractional_X);
- float i1 = cubic_interp(x0 , x1, x2, x3, fractional_X);
- float i2 = cubic_interp(y0 , y1, y2, y3, fractional_X);
- float i3 = cubic_interp(b0 , b1, b2, b3, fractional_X);
+ float i0 = cubic_interp(a0 , a1, a2, a3, fractional_X);
+ float i1 = cubic_interp(x0 , x1, x2, x3, fractional_X);
+ float i2 = cubic_interp(y0 , y1, y2, y3, fractional_X);
+ float i3 = cubic_interp(b0 , b1, b2, b3, fractional_X);
- return cubic_interp(i0, i1 , i2 , i3, fractional_Y);
+ return cubic_interp(i0, i1 , i2 , i3, fractional_Y);
- }
+ }
- static inline float perlin_octave_2d(float x,float y, int width, int seed, float period)
- {
+ static inline float perlin_octave_2d(float x,float y, int width, int seed, float period)
+ {
+ float freq=1/(float)(period);
- float freq=1/(float)(period);
+ int num=(int)(width*freq);
+ int step_x=(int)(x*freq);
+ int step_y=(int)(y*freq);
+ float zone_x=x*freq-step_x;
+ float zone_y=y*freq-step_y;
+ int box=step_x+step_y*num;
+ int noisedata=(box+seed);
- int num=(int)(width*freq);
- int step_x=(int)(x*freq);
- int step_y=(int)(y*freq);
- float zone_x=x*freq-step_x;
- float zone_y=y*freq-step_y;
- int box=step_x+step_y*num;
- int noisedata=(box+seed);
+ float u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
+ float a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
+ float b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
+ float v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
- float u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
- float a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
- float b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
- float v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
+ float value=cubic_interp(u,a,b,v,zone_y);
- float value=cubic_interp(u,a,b,v,zone_y);
-
- return value;
- }
+ return value;
+ }
- static inline float perlin_octave_2d_cos(float x,float y, int width, int seed, float period)
- {
+ static inline float perlin_octave_2d_cos(float x,float y, int width, int seed, float period)
+ {
+ float freq=1/(float)(period);
- float freq=1/(float)(period);
+ int num=(int)(width*freq);
+ int step_x=(int)(x*freq);
+ int step_y=(int)(y*freq);
+ float zone_x=x*freq-step_x;
+ float zone_y=y*freq-step_y;
+ int box=step_x+step_y*num;
+ int noisedata=(box+seed);
- int num=(int)(width*freq);
- int step_x=(int)(x*freq);
- int step_y=(int)(y*freq);
- float zone_x=x*freq-step_x;
- float zone_y=y*freq-step_y;
- int box=step_x+step_y*num;
- int noisedata=(box+seed);
+ float a=cos_interp(noise(noisedata),noise(noisedata+1),zone_x);
+ float b=cos_interp(noise(noisedata+num),noise(noisedata+1+num),zone_x);
- float a=cos_interp(noise(noisedata),noise(noisedata+1),zone_x);
- float b=cos_interp(noise(noisedata+num),noise(noisedata+1+num),zone_x);
+ float value=cos_interp(a,b,zone_y);
- float value=cos_interp(a,b,zone_y);
-
- return value;
- }
+ return value;
+ }
- static inline float perlin_octave_3d(float x,float y, float z,int width, int seed, float period)
- {
- float freq=1/(float)(period);
+ static inline float perlin_octave_3d(float x,float y, float z,int width, int seed, float period)
+ {
+ float freq=1/(float)(period);
- int num=(int)(width*freq);
- int step_x=(int)(x*freq);
- int step_y=(int)(y*freq);
- int step_z=(int)(z*freq);
- float zone_x=x*freq-step_x;
- float zone_y=y*freq-step_y;
- float zone_z=z*freq-step_z;
+ int num=(int)(width*freq);
+ int step_x=(int)(x*freq);
+ int step_y=(int)(y*freq);
+ int step_z=(int)(z*freq);
+ float zone_x=x*freq-step_x;
+ float zone_y=y*freq-step_y;
+ float zone_z=z*freq-step_z;
- int boxB=step_x+step_y+step_z*num;
- int boxC=step_x+step_y+step_z*(num+1);
- int boxD=step_x+step_y+step_z*(num+2);
- int boxA=step_x+step_y+step_z*(num-1);
+ int boxB=step_x+step_y+step_z*num;
+ int boxC=step_x+step_y+step_z*(num+1);
+ int boxD=step_x+step_y+step_z*(num+2);
+ int boxA=step_x+step_y+step_z*(num-1);
- float u,a,b,v,noisedata,box;
+ float u,a,b,v,noisedata,box;
- box = boxA;
- noisedata=(box+seed);
- u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
- a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
- b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
- v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
- float A=cubic_interp(u,a,b,v,zone_y);
+ box = boxA;
+ noisedata=(box+seed);
+ u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
+ a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
+ b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
+ v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
+ float A=cubic_interp(u,a,b,v,zone_y);
- box = boxB;
- noisedata=(box+seed);
- u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
- a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
- b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
- v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
- float B=cubic_interp(u,a,b,v,zone_y);
+ box = boxB;
+ noisedata=(box+seed);
+ u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
+ a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
+ b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
+ v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
+ float B=cubic_interp(u,a,b,v,zone_y);
- box = boxC;
- noisedata=(box+seed);
- u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
- a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
- b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
- v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
- float C=cubic_interp(u,a,b,v,zone_y);
+ box = boxC;
+ noisedata=(box+seed);
+ u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
+ a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
+ b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
+ v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
+ float C=cubic_interp(u,a,b,v,zone_y);
- box = boxD;
- noisedata=(box+seed);
- u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
- a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
- b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
- v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
- float D=cubic_interp(u,a,b,v,zone_y);
+ box = boxD;
+ noisedata=(box+seed);
+ u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x);
+ a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x);
+ b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x);
+ v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x);
+ float D=cubic_interp(u,a,b,v,zone_y);
- float value =cubic_interp(A,B,C,D,zone_z);
+ float value =cubic_interp(A,B,C,D,zone_z);
- return value;
- }
+ return value;
+ }
- static inline float perlin_noise_2d(int x, int y, int width, int octaves, int seed, float persistance, float basePeriod)
- {
- float p = persistance;
- float val = 0.0;
+ static inline float perlin_noise_2d(int x, int y, int width, int octaves, int seed, float persistance, float basePeriod)
+ {
+ float p = persistance;
+ float val = 0.0;
- for (int i = 0; i<octaves;i++)
- {
- val += perlin_octave_2d_cos(x,y,width,seed,basePeriod) * p;
+ for (int i = 0; i<octaves;i++)
+ {
+ val += perlin_octave_2d_cos(x,y,width,seed,basePeriod) * p;
- basePeriod *= 0.5;
- p *= persistance;
- }
- return val;
- }
+ basePeriod *= 0.5;
+ p *= persistance;
+ }
+ return val;
+ }
- static inline float perlin_noise_3d(int x, int y, int z, int width, int octaves, int seed, float persistance, float basePeriod)
- {
- float p = persistance;
- float val = 0.0;
+ static inline float perlin_noise_3d(int x, int y, int z, int width, int octaves, int seed, float persistance, float basePeriod)
+ {
+ float p = persistance;
+ float val = 0.0;
- for (int i = 0; i<octaves;i++)
- {
- val += perlin_octave_3d(x,y,z,width,seed,basePeriod) * p;
+ for (int i = 0; i<octaves;i++)
+ {
+ val += perlin_octave_3d(x,y,z,width,seed,basePeriod) * p;
- basePeriod *= 0.5;
- p *= persistance;
- }
- return val;
- }
-
-
-
+ basePeriod *= 0.5;
+ p *= persistance;
+ }
+ return val;
+ }
};
#endif /* PERLINNOISE_HPP_ */
diff --git a/src/libprojectM/Renderer/Pipeline.cpp b/src/libprojectM/Renderer/Pipeline.cpp
index 3daf7ae..fbb7cbc 100644
--- a/src/libprojectM/Renderer/Pipeline.cpp
+++ b/src/libprojectM/Renderer/Pipeline.cpp
@@ -7,43 +7,51 @@
#include "Pipeline.hpp"
#include "wipemalloc.h"
-Pipeline::Pipeline() : staticPerPixel(false),gx(0),gy(0),blur1n(1), blur2n(1), blur3n(1),
-blur1x(1), blur2x(1), blur3x(1),
-blur1ed(1){}
-void Pipeline::setStaticPerPixel(int gx, int gy)
+Pipeline::Pipeline()
+ : staticPerPixel(false),
+ gx(0), gy(0),
+ blur1n(1), blur2n(1), blur3n(1),
+ blur1x(1), blur2x(1), blur3x(1),
+ blur1ed(1)
+{}
+
+void
+Pipeline::setStaticPerPixel(int gx, int gy)
{
- staticPerPixel = true;
- this->gx = gx;
- this->gy = gy;
+ staticPerPixel = true;
+ this->gx = gx;
+ this->gy = gy;
- this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( int x = 0; x < gx; x++ )
- {
- this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
- this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
- for ( int x = 0; x < gx; x++ )
- {
- this->y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
- }
-
+ this->x_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( int x = 0; x < gx; x++ )
+ {
+ this->x_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
+ this->y_mesh= ( float ** ) wipemalloc ( gx * sizeof ( float * ) );
+ for ( int x = 0; x < gx; x++ )
+ {
+ this->y_mesh[x] = ( float * ) wipemalloc ( gy * sizeof ( float ) );
+ }
}
Pipeline::~Pipeline()
{
-if (staticPerPixel)
-{
- for ( int x = 0; x < this->gx; x++ )
- {
- free(this->x_mesh[x]);
- free(this->y_mesh[x]);
- }
- free(x_mesh);
- free(y_mesh);
-}
+ if (staticPerPixel)
+ {
+ for ( int x = 0; x < this->gx; x++ )
+ {
+ free(this->x_mesh[x]);
+ free(this->y_mesh[x]);
+ }
+ free(x_mesh);
+ free(y_mesh);
+ }
}
//void Pipeline::Render(const BeatDetect &music, const PipelineContext &context){}
-PixelPoint Pipeline::PerPixel(PixelPoint p, const PerPixelContext context)
-{return p;}
+PixelPoint
+Pipeline::PerPixel(PixelPoint p, const PerPixelContext context)
+{
+ return p;
+}
diff --git a/src/libprojectM/Renderer/Pipeline.hpp b/src/libprojectM/Renderer/Pipeline.hpp
index b782226..5697165 100644
--- a/src/libprojectM/Renderer/Pipeline.hpp
+++ b/src/libprojectM/Renderer/Pipeline.hpp
@@ -8,6 +8,8 @@
#include "PipelineContext.hpp"
#include "Shader.hpp"
#include "../Common.hpp"
+
+
//This class is the input to projectM's renderer
//
//Most implemenatations should implement PerPixel in order to get multi-threaded
@@ -16,41 +18,40 @@
class Pipeline
{
public:
+ //static per pixel stuff
+ bool staticPerPixel;
+ int gx;
+ int gy;
- //static per pixel stuff
- bool staticPerPixel;
- int gx;
- int gy;
+ float** x_mesh;
+ float** y_mesh;
+ //end static per pixel
- float** x_mesh;
- float** y_mesh;
- //end static per pixel
+ bool textureWrap;
+ float screenDecay;
- bool textureWrap;
- float screenDecay;
+ //variables passed to pixel shaders
+ float q[NUM_Q_VARIABLES];
- //variables passed to pixel shaders
- float q[NUM_Q_VARIABLES];
+ //blur settings n=bias x=scale
+ float blur1n;
+ float blur2n;
+ float blur3n;
+ float blur1x;
+ float blur2x;
+ float blur3x;
+ float blur1ed;
- //blur settings n=bias x=scale
- float blur1n;
- float blur2n;
- float blur3n;
- float blur1x;
- float blur2x;
- float blur3x;
- float blur1ed;
+ Shader warpShader;
+ Shader compositeShader;
- Shader warpShader;
- Shader compositeShader;
+ std::vector<RenderItem*> drawables;
+ std::vector<RenderItem*> compositeDrawables;
- std::vector<RenderItem*> drawables;
- std::vector<RenderItem*> compositeDrawables;
-
- Pipeline();
- void setStaticPerPixel(int gx, int gy);
- virtual ~Pipeline();
- virtual PixelPoint PerPixel(PixelPoint p, const PerPixelContext context);
+ Pipeline();
+ void setStaticPerPixel(int gx, int gy);
+ virtual ~Pipeline();
+ virtual PixelPoint PerPixel(PixelPoint p, const PerPixelContext context);
};
#endif
diff --git a/src/libprojectM/Renderer/PipelineContext.cpp b/src/libprojectM/Renderer/PipelineContext.cpp
index 2233147..b9f07f0 100644
--- a/src/libprojectM/Renderer/PipelineContext.cpp
+++ b/src/libprojectM/Renderer/PipelineContext.cpp
@@ -4,8 +4,8 @@
* Created on: Jun 22, 2008
* Author: pete
*/
-
#include "PipelineContext.hpp"
+
PipelineContext::PipelineContext() {}
PipelineContext::~PipelineContext() {}
diff --git a/src/libprojectM/Renderer/PipelineContext.hpp b/src/libprojectM/Renderer/PipelineContext.hpp
index 1b7f899..870e9e6 100644
--- a/src/libprojectM/Renderer/PipelineContext.hpp
+++ b/src/libprojectM/Renderer/PipelineContext.hpp
@@ -4,20 +4,20 @@
* Created on: Jun 22, 2008
* Author: pete
*/
-
#ifndef PIPELINECONTEXT_HPP_
#define PIPELINECONTEXT_HPP_
+
class PipelineContext
{
public:
- int fps;
- float time;
- int frame;
- float progress;
+ int fps;
+ float time;
+ int frame;
+ float progress;
- PipelineContext();
- virtual ~PipelineContext();
+ PipelineContext();
+ virtual ~PipelineContext();
};
#endif /* PIPELINECONTEXT_HPP_ */
diff --git a/src/libprojectM/Renderer/RenderItemDistanceMetric.cpp b/src/libprojectM/Renderer/RenderItemDistanceMetric.cpp
index e032ba5..2eae44c 100644
--- a/src/libprojectM/Renderer/RenderItemDistanceMetric.cpp
+++ b/src/libprojectM/Renderer/RenderItemDistanceMetric.cpp
@@ -4,10 +4,10 @@
* Created on: Feb 18, 2009
* Author: struktured
*/
-
#include "RenderItemDistanceMetric.hpp"
+
// Assumes [0, 1] distance space because it's easy to manage with overflow
// Underflow is obviously possible though.
const double RenderItemDistanceMetric::NOT_COMPARABLE_VALUE
- (1.0);
+ (1.0);
diff --git a/src/libprojectM/Renderer/RenderItemDistanceMetric.hpp b/src/libprojectM/Renderer/RenderItemDistanceMetric.hpp
index 1f9e0bb..b7e7c75 100644
--- a/src/libprojectM/Renderer/RenderItemDistanceMetric.hpp
+++ b/src/libprojectM/Renderer/RenderItemDistanceMetric.hpp
@@ -4,7 +4,6 @@
* Created on: Feb 16, 2009
* Author: struktured
*/
-
#ifndef RenderItemDISTANCEMETRIC_H_
#define RenderItemDISTANCEMETRIC_H_
@@ -17,7 +16,8 @@
/// Compares two render items and returns zero if they are virtually equivalent and large values
/// when they are dissimilar. If two render items cannot be compared, NOT_COMPARABLE_VALUE is returned.
-class RenderItemDistanceMetric : public std::binary_function<const RenderItem*, const RenderItem*, double> {
+class RenderItemDistanceMetric : public std::binary_function<const RenderItem*, const RenderItem*, double>
+{
public:
const static double NOT_COMPARABLE_VALUE;
virtual double operator()(const RenderItem * r1, const RenderItem * r2) const = 0;
@@ -27,119 +27,123 @@
// A base class to construct render item distance metrics. Just specify your two concrete
// render item types as template parameters and override the computeDistance() function.
template <class R1, class R2>
-class RenderItemDistance : public RenderItemDistanceMetric {
-
+class RenderItemDistance : public RenderItemDistanceMetric
+{
protected:
-// Override to create your own distance fmetric for your specified custom types.
-virtual double computeDistance(const R1 * r1, const R2 * r2) const = 0;
+ // Override to create your own distance fmetric for your specified custom types.
+ virtual double computeDistance(const R1 * r1, const R2 * r2) const = 0;
public:
-inline virtual double operator()(const RenderItem * r1, const RenderItem * r2) const {
- if (supported(r1, r2))
- return computeDistance(dynamic_cast<const R1*>(r1), dynamic_cast<const R2*>(r2));
- else if (supported(r2,r1))
- return computeDistance(dynamic_cast<const R1*>(r2), dynamic_cast<const R2*>(r1));
- else
- return NOT_COMPARABLE_VALUE;
-}
+ inline virtual double operator()(const RenderItem * r1, const RenderItem * r2) const
+ {
+ if (supported(r1, r2))
+ return computeDistance(dynamic_cast<const R1*>(r1), dynamic_cast<const R2*>(r2));
+ else if (supported(r2,r1))
+ return computeDistance(dynamic_cast<const R1*>(r2), dynamic_cast<const R2*>(r1));
+ else
+ return NOT_COMPARABLE_VALUE;
+ }
-// Returns true if and only if r1 and r2 are the same type as or derived from R1, R2 respectively
-inline bool supported(const RenderItem * r1, const RenderItem * r2) const {
- return dynamic_cast<const R1*>(r1) && dynamic_cast<const R2*>(r2);
- //return typeid(r1) == typeid(const R1 *) && typeid(r2) == typeid(const R2 *);
-}
+ // Returns true if and only if r1 and r2 are the same type as or derived from R1, R2 respectively
+ inline bool supported(const RenderItem * r1, const RenderItem * r2) const
+ {
+ return dynamic_cast<const R1*>(r1) && dynamic_cast<const R2*>(r2);
+ //return typeid(r1) == typeid(const R1 *) && typeid(r2) == typeid(const R2 *);
+ }
-inline TypeIdPair typeIdPair() const {
- return TypeIdPair(typeid(const R1*).name(), typeid(const R2*).name());
-}
-
+ inline TypeIdPair typeIdPair() const
+ {
+ return TypeIdPair(typeid(const R1*).name(), typeid(const R2*).name());
+ }
};
-class RTIRenderItemDistance : public RenderItemDistance<RenderItem, RenderItem> {
+class RTIRenderItemDistance : public RenderItemDistance<RenderItem, RenderItem>
+{
public:
- RTIRenderItemDistance() {}
- virtual ~RTIRenderItemDistance() {}
+ RTIRenderItemDistance() {}
+ virtual ~RTIRenderItemDistance() {}
protected:
- virtual inline double computeDistance(const RenderItem * lhs, const RenderItem * rhs) const {
- if (typeid(*lhs) == typeid(*rhs)) {
- //std::cerr << typeid(*lhs).name() << " and " << typeid(*rhs).name() << "are comparable" << std::endl;
+ virtual inline double computeDistance(const RenderItem * lhs, const RenderItem * rhs) const
+ {
+ if (typeid(*lhs) == typeid(*rhs)) {
+ //std::cerr << typeid(*lhs).name() << " and " << typeid(*rhs).name() << "are comparable" << std::endl;
- return 0.0;
- }
- else {
- //std::cerr << typeid(*lhs).name() << " and " << typeid(*rhs).name() << "not comparable" << std::endl;
- return NOT_COMPARABLE_VALUE;
- }
- }
-
-
+ return 0.0;
+ }
+ else {
+ //std::cerr << typeid(*lhs).name() << " and " << typeid(*rhs).name() << "not comparable" << std::endl;
+ return NOT_COMPARABLE_VALUE;
+ }
+ }
};
-class ShapeXYDistance : public RenderItemDistance<Shape, Shape> {
-
+class ShapeXYDistance : public RenderItemDistance<Shape, Shape>
+{
public:
- ShapeXYDistance() {}
- virtual ~ShapeXYDistance() {}
+ ShapeXYDistance() {}
+ virtual ~ShapeXYDistance() {}
protected:
- virtual inline double computeDistance(const Shape * lhs, const Shape * rhs) const {
- return (meanSquaredError(lhs->x, rhs->x) + meanSquaredError(lhs->y, rhs->y)) / 2;
- }
+ virtual inline double computeDistance(const Shape * lhs, const Shape * rhs) const
+ {
+ return (meanSquaredError(lhs->x, rhs->x) + meanSquaredError(lhs->y, rhs->y)) / 2;
+ }
};
-class MasterRenderItemDistance : public RenderItemDistance<RenderItem, RenderItem> {
-
-typedef std::map<TypeIdPair, RenderItemDistanceMetric*> DistanceMetricMap;
+class MasterRenderItemDistance : public RenderItemDistance<RenderItem, RenderItem>
+{
+ typedef std::map<TypeIdPair, RenderItemDistanceMetric*> DistanceMetricMap;
public:
- MasterRenderItemDistance() {}
- virtual ~MasterRenderItemDistance() {}
+ MasterRenderItemDistance() {}
+ virtual ~MasterRenderItemDistance() {}
- inline void addMetric(RenderItemDistanceMetric * fun) {
- _distanceMetricMap[fun->typeIdPair()] = fun;
- }
+ inline void addMetric(RenderItemDistanceMetric * fun)
+ {
+ _distanceMetricMap[fun->typeIdPair()] = fun;
+ }
protected:
- virtual inline double computeDistance(const RenderItem * lhs, const RenderItem * rhs) const {
+ virtual inline double computeDistance(const RenderItem * lhs, const RenderItem * rhs) const
+ {
+ RenderItemDistanceMetric * metric;
- RenderItemDistanceMetric * metric;
-
- TypeIdPair pair(typeid(lhs), typeid(rhs));
+ TypeIdPair pair(typeid(lhs), typeid(rhs));
- // If specialized metric exists, use it to get higher granularity
- // of correctness
- if (_distanceMetricMap.count(pair)) {
- metric = _distanceMetricMap[pair];
- } else if (_distanceMetricMap.count(pair = TypeIdPair(typeid(rhs), typeid(lhs)))) {
- metric = _distanceMetricMap[pair];
- } else { // Failing that, use rtti && shape distance if its a shape type
+ // If specialized metric exists, use it to get higher granularity
+ // of correctness
+ if (_distanceMetricMap.count(pair)) {
+ metric = _distanceMetricMap[pair];
+ } else if (_distanceMetricMap.count(pair = TypeIdPair(typeid(rhs), typeid(lhs)))) {
+ metric = _distanceMetricMap[pair];
+ } else { // Failing that, use rtti && shape distance if its a shape type
+ const double rttiError = _rttiDistance(lhs,rhs);
- const double rttiError = _rttiDistance(lhs,rhs);
+ /// @bug This is a non elegant approach to supporting shape distance
+ if (rttiError == 0 && _shapeXYDistance.supported(lhs,rhs))
+ return _shapeXYDistance(lhs, rhs);
+ else
+ return rttiError;
+ }
- /// @bug This is a non elegant approach to supporting shape distance
- if (rttiError == 0 && _shapeXYDistance.supported(lhs,rhs))
- return _shapeXYDistance(lhs, rhs);
- else return rttiError;
- }
-
- return (*metric)(lhs, rhs);
- }
+ return (*metric)(lhs, rhs);
+ }
private:
- mutable RTIRenderItemDistance _rttiDistance;
- mutable ShapeXYDistance _shapeXYDistance;
- mutable DistanceMetricMap _distanceMetricMap;
+ mutable RTIRenderItemDistance _rttiDistance;
+ mutable ShapeXYDistance _shapeXYDistance;
+ mutable DistanceMetricMap _distanceMetricMap;
};
#endif /* RenderItemDISTANCEMETRIC_H_ */
diff --git a/src/libprojectM/Renderer/RenderItemMatcher.cpp b/src/libprojectM/Renderer/RenderItemMatcher.cpp
index cf10750..515d136 100644
--- a/src/libprojectM/Renderer/RenderItemMatcher.cpp
+++ b/src/libprojectM/Renderer/RenderItemMatcher.cpp
@@ -1,34 +1,36 @@
#include "RenderItemMatcher.hpp"
-double RenderItemMatcher::computeMatching(const RenderItemList & lhs, const RenderItemList & rhs) const {
- for (int i = 0; i < lhs.size();i++) {
- int j;
- for (j = 0; j < rhs.size();j++)
- _weights[i][j] = _distanceFunction(lhs[i], rhs[j]);
- for (; j < lhs.size();j++)
- _weights[i][j] = RenderItemDistanceMetric::NOT_COMPARABLE_VALUE;
- }
-
- const double error = _hungarianMethod(_weights, lhs.size());
- //std::cout << "[computeMatching] total error is " << error << std::endl;
- return error;
+double
+RenderItemMatcher::computeMatching (const RenderItemList & lhs, const RenderItemList & rhs) const
+{
+ for (int i = 0; i < lhs.size();i++) {
+ int j;
+ for (j = 0; j < rhs.size();j++)
+ _weights[i][j] = _distanceFunction(lhs[i], rhs[j]);
+ for (; j < lhs.size();j++)
+ _weights[i][j] = RenderItemDistanceMetric::NOT_COMPARABLE_VALUE;
+ }
+
+
+ const double error = _hungarianMethod(_weights, lhs.size());
+ //std::cout << "[computeMatching] total error is " << error << std::endl;
+ return error;
}
+void
+RenderItemMatcher::setMatches (const RenderItemList & lhs_src, const RenderItemList & rhs_src) const
+{
+ for (int i = 0; i < lhs_src.size();i++) {
+ const int j = _hungarianMethod.matching(i);
-void RenderItemMatcher::setMatches
- (const RenderItemList & lhs_src, const RenderItemList & rhs_src) const {
-
- for (int i = 0; i < lhs_src.size();i++) {
- const int j = _hungarianMethod.matching(i);
-
- // hack
- if (true || _weights[i][j] == RenderItemDistanceMetric::NOT_COMPARABLE_VALUE) {
- _results.unmatchedLeft.push_back(lhs_src[i]);
- _results.unmatchedRight.push_back(rhs_src[i]);
- } else {
- _results.matches.push_back(std::make_pair(lhs_src[i], rhs_src[j]));
- }
- }
-}
\ No newline at end of file
+ // hack
+ if (true || _weights[i][j] == RenderItemDistanceMetric::NOT_COMPARABLE_VALUE) {
+ _results.unmatchedLeft.push_back(lhs_src[i]);
+ _results.unmatchedRight.push_back(rhs_src[i]);
+ } else {
+ _results.matches.push_back(std::make_pair(lhs_src[i], rhs_src[j]));
+ }
+ }
+}
diff --git a/src/libprojectM/Renderer/RenderItemMatcher.hpp b/src/libprojectM/Renderer/RenderItemMatcher.hpp
index 387d369..6b6ecca 100644
--- a/src/libprojectM/Renderer/RenderItemMatcher.hpp
+++ b/src/libprojectM/Renderer/RenderItemMatcher.hpp
@@ -4,7 +4,6 @@
* Created on: Feb 16, 2009
* Author: struktured
*/
-
#ifndef RenderItemMatcher_HPP
#define RenderItemMatcher_HPP
@@ -14,6 +13,7 @@
#include <iostream>
#include "HungarianMethod.hpp"
+
typedef std::vector<std::pair<RenderItem*, RenderItem*> > RenderItemMatchList;
class MatchResults;
@@ -22,56 +22,53 @@
public:
-struct MatchResults {
- RenderItemMatchList matches;
- std::vector<RenderItem*> unmatchedLeft;
- std::vector<RenderItem*> unmatchedRight;
+ struct MatchResults {
+ RenderItemMatchList matches;
+ std::vector<RenderItem*> unmatchedLeft;
+ std::vector<RenderItem*> unmatchedRight;
- double error;
-};
+ double error;
+ };
- static const std::size_t MAXIMUM_SET_SIZE = 1000;
+ static const std::size_t MAXIMUM_SET_SIZE = 1000;
- /// Computes an optimal matching between two renderable item sets.
- /// @param lhs the "left-hand side" list of render items.
- /// @param rhs the "right-hand side" list of render items.
- /// @returns a list of match pairs, possibly self referencing, and an error estimate of the matching.
- inline virtual void operator()(const RenderItemList & lhs, const RenderItemList & rhs) const {
-
- // Ensure the first argument is greater than next to aid the helper function's logic.
- if (lhs.size() >= rhs.size()) {
- _results.error = computeMatching(lhs, rhs);
- setMatches(lhs, rhs);
- } else {
- _results.error = computeMatching(rhs, lhs);
- setMatches(rhs, lhs);
- }
-
-
- }
+ /// Computes an optimal matching between two renderable item sets.
+ /// @param lhs the "left-hand side" list of render items.
+ /// @param rhs the "right-hand side" list of render items.
+ /// @returns a list of match pairs, possibly self referencing, and an error estimate of the matching.
+ inline virtual void operator()(const RenderItemList & lhs, const RenderItemList & rhs) const
+ {
+ // Ensure the first argument is greater than next to aid the helper function's logic.
+ if (lhs.size() >= rhs.size()) {
+ _results.error = computeMatching(lhs, rhs);
+ setMatches(lhs, rhs);
+ } else {
+ _results.error = computeMatching(rhs, lhs);
+ setMatches(rhs, lhs);
+ }
+ }
- RenderItemMatcher() {}
- virtual ~RenderItemMatcher() {}
+ RenderItemMatcher() {}
+ virtual ~RenderItemMatcher() {}
- inline MatchResults & matchResults() { return _results; }
+ inline MatchResults & matchResults() { return _results; }
- inline double weight(int i, int j) const { return _weights[i][j]; }
+ inline double weight(int i, int j) const { return _weights[i][j]; }
- MasterRenderItemDistance & distanceFunction() { return _distanceFunction; }
+ MasterRenderItemDistance & distanceFunction() { return _distanceFunction; }
private:
- mutable HungarianMethod<MAXIMUM_SET_SIZE> _hungarianMethod;
- mutable double _weights[MAXIMUM_SET_SIZE][MAXIMUM_SET_SIZE];
+ mutable HungarianMethod<MAXIMUM_SET_SIZE> _hungarianMethod;
+ mutable double _weights[MAXIMUM_SET_SIZE][MAXIMUM_SET_SIZE];
- mutable MatchResults _results;
+ mutable MatchResults _results;
- /// @idea interface this entirely allow overriding of its type.
- mutable MasterRenderItemDistance _distanceFunction;
-
- double computeMatching(const RenderItemList & lhs, const RenderItemList & rhs) const;
+ /// @idea interface this entirely allow overriding of its type.
+ mutable MasterRenderItemDistance _distanceFunction;
- void setMatches(const RenderItemList & lhs_src, const RenderItemList & rhs_src) const;
+ double computeMatching(const RenderItemList & lhs, const RenderItemList & rhs) const;
+ void setMatches(const RenderItemList & lhs_src, const RenderItemList & rhs_src) const;
};
#endif
diff --git a/src/libprojectM/Renderer/RenderItemMergeFunction.hpp b/src/libprojectM/Renderer/RenderItemMergeFunction.hpp
index 6316641..79884cd 100644
--- a/src/libprojectM/Renderer/RenderItemMergeFunction.hpp
+++ b/src/libprojectM/Renderer/RenderItemMergeFunction.hpp
@@ -19,19 +19,19 @@
template <class T>
inline T interpolate(T a, T b, float ratio)
{
- return (ratio*a + (1-ratio)*b) * 0.5;
+ return (ratio*a + (1-ratio)*b) * 0.5;
}
template <>
inline int interpolate(int a, int b, float ratio)
{
- return (int)(ratio*(float)a + (1-ratio)*(float)b) * 0.5;
+ return (int)(ratio*(float)a + (1-ratio)*(float)b) * 0.5;
}
template <>
inline bool interpolate(bool a, bool b, float ratio)
{
- return (ratio >= 0.5) ? a : b;
+ return (ratio >= 0.5) ? a : b;
}
@@ -46,149 +46,151 @@
/// A base class to construct render item distance mergeFunctions. Just specify your two concrete
/// render item types as template parameters and override the computeMerge() function.
template <class R1, class R2=R1, class R3=R2>
-class RenderItemMerge : public RenderItemMergeFunction {
+ class RenderItemMerge : public RenderItemMergeFunction
+{
protected:
-/// Override to create your own distance mergeFunction for your specified custom types.
-virtual R3 * computeMerge(const R1 * r1, const R2 * r2, double ratio) const = 0;
+ /// Override to create your own distance mergeFunction for your specified custom types.
+ virtual R3 * computeMerge(const R1 * r1, const R2 * r2, double ratio) const = 0;
public:
-inline virtual R3 * operator()(const RenderItem * r1, const RenderItem * r2, double ratio) const {
- if (supported(r1, r2))
- return computeMerge(dynamic_cast<const R1*>(r1), dynamic_cast<const R2*>(r2), ratio);
- else if (supported(r2,r1))
- return computeMerge(dynamic_cast<const R1*>(r2), dynamic_cast<const R2*>(r1), ratio);
- else
- return 0;
-}
+ inline virtual R3 * operator()(const RenderItem * r1, const RenderItem * r2, double ratio) const
+ {
+ if (supported(r1, r2))
+ return computeMerge(dynamic_cast<const R1*>(r1), dynamic_cast<const R2*>(r2), ratio);
+ else if (supported(r2,r1))
+ return computeMerge(dynamic_cast<const R1*>(r2), dynamic_cast<const R2*>(r1), ratio);
+ else
+ return 0;
+ }
-/// Returns true if and only if r1 and r2 are of type R1 and R2 respectively.
-inline bool supported(const RenderItem * r1, const RenderItem * r2) const {
- return typeid(r1) == typeid(const R1 *) && typeid(r2) == typeid(const R2 *);
-}
+ /// Returns true if and only if r1 and r2 are of type R1 and R2 respectively.
+ inline bool supported(const RenderItem * r1, const RenderItem * r2) const
+ {
+ return typeid(r1) == typeid(const R1 *) && typeid(r2) == typeid(const R2 *);
+ }
-inline TypeIdPair typeIdPair() const {
- return TypeIdPair(typeid(const R1*).name(), typeid(const R2*).name());
-}
-
+ inline TypeIdPair typeIdPair() const
+ {
+ return TypeIdPair(typeid(const R1*).name(), typeid(const R2*).name());
+ }
};
class ShapeMerge : public RenderItemMerge<Shape> {
-
public:
- ShapeMerge() {}
- virtual ~ShapeMerge() {}
+ ShapeMerge() {}
+ virtual ~ShapeMerge() {}
-protected:
+ protected:
- virtual inline Shape * computeMerge(const Shape * lhs, const Shape * rhs, double ratio) const {
+ virtual inline Shape * computeMerge(const Shape * lhs, const Shape * rhs, double ratio) const
+ {
- Shape * ret = new Shape();
- Shape & target = *ret;
+ Shape * ret = new Shape();
+ Shape & target = *ret;
- target.x = interpolate(lhs->x, rhs->x, ratio);
- target.y = interpolate(lhs->y, rhs->y, ratio);
- target.a = interpolate(lhs->a, rhs->a, ratio);
- target.a2 = interpolate(lhs->a2, rhs->a2, ratio);
- target.r = interpolate(lhs->r, rhs->r, ratio);
- target.r2 = interpolate(lhs->r2, rhs->r2, ratio);
- target.g = interpolate(lhs->g, rhs->g, ratio);
- target.g2 = interpolate(lhs->g2, rhs->g2, ratio);
- target.b = interpolate(lhs->b, rhs->b, ratio);
- target.b2 = interpolate(lhs->b2, rhs->b2, ratio);
+ target.x = interpolate(lhs->x, rhs->x, ratio);
+ target.y = interpolate(lhs->y, rhs->y, ratio);
+ target.a = interpolate(lhs->a, rhs->a, ratio);
+ target.a2 = interpolate(lhs->a2, rhs->a2, ratio);
+ target.r = interpolate(lhs->r, rhs->r, ratio);
+ target.r2 = interpolate(lhs->r2, rhs->r2, ratio);
+ target.g = interpolate(lhs->g, rhs->g, ratio);
+ target.g2 = interpolate(lhs->g2, rhs->g2, ratio);
+ target.b = interpolate(lhs->b, rhs->b, ratio);
+ target.b2 = interpolate(lhs->b2, rhs->b2, ratio);
- target.ang = interpolate(lhs->ang, rhs->ang, ratio);
- target.radius = interpolate(lhs->radius, rhs->radius, ratio);
+ target.ang = interpolate(lhs->ang, rhs->ang, ratio);
+ target.radius = interpolate(lhs->radius, rhs->radius, ratio);
- target.tex_ang = interpolate(lhs->tex_ang, rhs->tex_ang, ratio);
- target.tex_zoom = interpolate(lhs->tex_zoom, rhs->tex_zoom, ratio);
+ target.tex_ang = interpolate(lhs->tex_ang, rhs->tex_ang, ratio);
+ target.tex_zoom = interpolate(lhs->tex_zoom, rhs->tex_zoom, ratio);
- target.border_a = interpolate(lhs->border_a, rhs->border_a, ratio);
- target.border_r = interpolate(lhs->border_r, rhs->border_r, ratio);
- target.border_g = interpolate(lhs->border_g, rhs->border_g, ratio);
- target.border_b = interpolate(lhs->border_b, rhs->border_b, ratio);
+ target.border_a = interpolate(lhs->border_a, rhs->border_a, ratio);
+ target.border_r = interpolate(lhs->border_r, rhs->border_r, ratio);
+ target.border_g = interpolate(lhs->border_g, rhs->border_g, ratio);
+ target.border_b = interpolate(lhs->border_b, rhs->border_b, ratio);
- target.sides = interpolate(lhs->sides, rhs->sides, ratio);
+ target.sides = interpolate(lhs->sides, rhs->sides, ratio);
- target.additive = interpolate(lhs->additive, rhs->additive, ratio);
- target.textured = interpolate(lhs->textured, rhs->textured, ratio);
- target.thickOutline = interpolate(lhs->thickOutline, rhs->thickOutline, ratio);
- target.enabled = interpolate(lhs->enabled, rhs->enabled, ratio);
+ target.additive = interpolate(lhs->additive, rhs->additive, ratio);
+ target.textured = interpolate(lhs->textured, rhs->textured, ratio);
+ target.thickOutline = interpolate(lhs->thickOutline, rhs->thickOutline, ratio);
+ target.enabled = interpolate(lhs->enabled, rhs->enabled, ratio);
- target.masterAlpha = interpolate(lhs->masterAlpha, rhs->masterAlpha, ratio);
- target.imageUrl = (ratio > 0.5) ? lhs->imageUrl : rhs->imageUrl, ratio;
+ target.masterAlpha = interpolate(lhs->masterAlpha, rhs->masterAlpha, ratio);
+ target.imageUrl = (ratio > 0.5) ? lhs->imageUrl : rhs->imageUrl, ratio;
- return ret;
- }
+ return ret;
+ }
};
class BorderMerge : public RenderItemMerge<Border> {
+public:
- public:
+ BorderMerge() {}
+ virtual ~BorderMerge() {}
- BorderMerge() {}
- virtual ~BorderMerge() {}
+protected:
- protected:
+ virtual inline Border * computeMerge(const Border * lhs, const Border * rhs, double ratio) const
+ {
+ Border * ret = new Border();
- virtual inline Border * computeMerge(const Border * lhs, const Border * rhs, double ratio) const
- {
- Border * ret = new Border();
-
- Border & target = *ret;
+ Border & target = *ret;
- target.inner_a = interpolate(lhs->inner_a, rhs->inner_a, ratio);
- target.inner_r = interpolate(lhs->inner_r, rhs->inner_r, ratio);
- target.inner_g = interpolate(lhs->inner_g, rhs->inner_g, ratio);
- target.inner_b = interpolate(lhs->inner_b, rhs->inner_b, ratio);
- target.inner_size = interpolate(lhs->inner_size, rhs->inner_size, ratio);
+ target.inner_a = interpolate(lhs->inner_a, rhs->inner_a, ratio);
+ target.inner_r = interpolate(lhs->inner_r, rhs->inner_r, ratio);
+ target.inner_g = interpolate(lhs->inner_g, rhs->inner_g, ratio);
+ target.inner_b = interpolate(lhs->inner_b, rhs->inner_b, ratio);
+ target.inner_size = interpolate(lhs->inner_size, rhs->inner_size, ratio);
- target.outer_a = interpolate(lhs->outer_a, rhs->outer_a, ratio);
- target.outer_r = interpolate(lhs->outer_r, rhs->outer_r, ratio);
- target.outer_g = interpolate(lhs->outer_g, rhs->outer_g, ratio);
- target.outer_b = interpolate(lhs->outer_b, rhs->outer_b, ratio);
- target.outer_size = interpolate(lhs->outer_size, rhs->outer_size, ratio);
+ target.outer_a = interpolate(lhs->outer_a, rhs->outer_a, ratio);
+ target.outer_r = interpolate(lhs->outer_r, rhs->outer_r, ratio);
+ target.outer_g = interpolate(lhs->outer_g, rhs->outer_g, ratio);
+ target.outer_b = interpolate(lhs->outer_b, rhs->outer_b, ratio);
+ target.outer_size = interpolate(lhs->outer_size, rhs->outer_size, ratio);
- target.masterAlpha = interpolate(lhs->masterAlpha, rhs->masterAlpha, ratio);
+ target.masterAlpha = interpolate(lhs->masterAlpha, rhs->masterAlpha, ratio);
- return ret;
- }
+ return ret;
+ }
};
-class WaveformMerge : public RenderItemMerge<Waveform> {
+class WaveformMerge : public RenderItemMerge<Waveform>
+{
+public:
- public:
+ WaveformMerge() {}
+ virtual ~WaveformMerge() {}
- WaveformMerge() {}
- virtual ~WaveformMerge() {}
+protected:
- protected:
+ /// @BUG unimplemented
+ virtual inline Waveform * computeMerge(const Waveform * lhs, const Waveform * rhs, double ratio) const
+ {
+ return 0;
+ /*
+ Waveform * ret = new Waveform();
+ Waveform & target = *ret;
- /// @BUG unimplemented
- virtual inline Waveform * computeMerge(const Waveform * lhs, const Waveform * rhs, double ratio) const
- {
- return 0;
-/*
- Waveform * ret = new Waveform();
- Waveform & target = *ret;
+ target.additive = interpolate(lhs->additive, rhs->additive, ratio);
+ target.dots = interpolate(lhs->dots, rhs->dots, ratio);
+ target.samples = (rhs->samples > lhs-> samples) ? lhs->samples : rhs->samples;
+ target.scaling = interpolate(lhs->scaling, rhs->scaling, ratio);
+ target.sep = interpolate(lhs->sep, rhs->sep, ratio);
+ target.smoothing = interpolate(lhs->smoothing, rhs->smoothing, ratio);
+ target.spectrum = interpolate(lhs->spectrum, rhs->spectrum, ratio);
+ target.thick = interpolate(lhs->thick, rhs->thick, ratio);
+ target.masterAlpha = interpolate(lhs->masterAlpha, rhs->masterAlpha, ratio);
- target.additive = interpolate(lhs->additive, rhs->additive, ratio);
- target.dots = interpolate(lhs->dots, rhs->dots, ratio);
- target.samples = (rhs->samples > lhs-> samples) ? lhs->samples : rhs->samples;
- target.scaling = interpolate(lhs->scaling, rhs->scaling, ratio);
- target.sep = interpolate(lhs->sep, rhs->sep, ratio);
- target.smoothing = interpolate(lhs->smoothing, rhs->smoothing, ratio);
- target.spectrum = interpolate(lhs->spectrum, rhs->spectrum, ratio);
- target.thick = interpolate(lhs->thick, rhs->thick, ratio);
- target.masterAlpha = interpolate(lhs->masterAlpha, rhs->masterAlpha, ratio);
-
- return ret;
-*/
- }
+ return ret;
+ */
+ }
};
@@ -197,40 +199,41 @@
/// incoming type parameters.
class MasterRenderItemMerge : public RenderItemMerge<RenderItem> {
-typedef std::map<TypeIdPair, RenderItemMergeFunction*> MergeFunctionMap;
+ typedef std::map<TypeIdPair, RenderItemMergeFunction*> MergeFunctionMap;
public:
- MasterRenderItemMerge() {}
- virtual ~MasterRenderItemMerge() {}
+ MasterRenderItemMerge() {}
+ virtual ~MasterRenderItemMerge() {}
- inline void add(RenderItemMergeFunction * fun) {
- _mergeFunctionMap[fun->typeIdPair()] = fun;
- }
+ inline void add(RenderItemMergeFunction * fun)
+ {
+ _mergeFunctionMap[fun->typeIdPair()] = fun;
+ }
protected:
- virtual inline RenderItem * computeMerge(const RenderItem * lhs, const RenderItem * rhs, double ratio) const {
+ virtual inline RenderItem * computeMerge(const RenderItem * lhs, const RenderItem * rhs, double ratio) const
+ {
+ RenderItemMergeFunction * mergeFunction;
- RenderItemMergeFunction * mergeFunction;
+ TypeIdPair pair(typeid(lhs), typeid(rhs));
+ if (_mergeFunctionMap.count(pair)) {
+ mergeFunction = _mergeFunctionMap[pair];
+ } else if (_mergeFunctionMap.count(pair = TypeIdPair(typeid(rhs), typeid(lhs)))) {
+ mergeFunction = _mergeFunctionMap[pair];
+ } else {
+ mergeFunction = 0;
+ }
- TypeIdPair pair(typeid(lhs), typeid(rhs));
- if (_mergeFunctionMap.count(pair)) {
- mergeFunction = _mergeFunctionMap[pair];
- } else if (_mergeFunctionMap.count(pair = TypeIdPair(typeid(rhs), typeid(lhs)))) {
- mergeFunction = _mergeFunctionMap[pair];
- } else {
- mergeFunction = 0;
- }
-
- // If specialized mergeFunction exists, use it to get higher granularity
- // of correctness
- if (mergeFunction)
- return (*mergeFunction)(lhs, rhs, ratio);
- else
- return 0;
- }
+ // If specialized mergeFunction exists, use it to get higher granularity
+ // of correctness
+ if (mergeFunction)
+ return (*mergeFunction)(lhs, rhs, ratio);
+ else
+ return 0;
+ }
private:
- mutable MergeFunctionMap _mergeFunctionMap;
+ mutable MergeFunctionMap _mergeFunctionMap;
};
#endif /* RenderItemMergeFunction_HPP_ */
diff --git a/src/libprojectM/Renderer/Renderable.cpp b/src/libprojectM/Renderer/Renderable.cpp
index 926b34f..224f846 100644
--- a/src/libprojectM/Renderer/Renderable.cpp
+++ b/src/libprojectM/Renderer/Renderable.cpp
@@ -1,4 +1,3 @@
-
#include "Common.hpp"
#ifdef USE_GLES1
@@ -16,6 +15,7 @@
#include "Renderable.hpp"
#include <math.h>
+
typedef float floatPair[2];
typedef float floatTriple[3];
typedef float floatQuad[4];
@@ -45,335 +45,336 @@
#endif
RenderContext::RenderContext()
- : time(0),texsize(512), aspectRatio(1), aspectCorrect(false){};
+ : time(0),
+ texsize(512),
+ aspectRatio(1),
+ aspectCorrect(false)
+{};
-RenderItem::RenderItem():masterAlpha(1){}
+RenderItem::RenderItem() : masterAlpha(1) {}
-DarkenCenter::DarkenCenter():RenderItem(){}
-MotionVectors::MotionVectors():RenderItem(){}
-Border::Border():RenderItem(){}
+DarkenCenter::DarkenCenter() : RenderItem() {}
+MotionVectors::MotionVectors() : RenderItem() {}
+Border::Border() : RenderItem() {}
-void DarkenCenter::Draw(RenderContext &context)
- {
- //float unit=0.05f;
+void
+DarkenCenter::Draw(RenderContext &context)
+{
+ //float unit=0.05f;
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- float colors[6][4] = {{0, 0, 0, (3.0f/32.0f) * masterAlpha},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0}};
+ float colors[6][4] = {{0, 0, 0, (3.0f/32.0f) * masterAlpha},
+ {0, 0, 0, 0},
+ {0, 0, 0, 0},
+ {0, 0, 0, 0},
+ {0, 0, 0, 0},
+ {0, 0, 0, 0}};
- float points[6][2] = {{ 0.5, 0.5},
- { 0.45, 0.5},
- { 0.5, 0.45},
- { 0.55, 0.5},
- { 0.5, 0.55},
- { 0.45, 0.5}};
+ float points[6][2] = {{ 0.5, 0.5},
+ { 0.45, 0.5},
+ { 0.5, 0.45},
+ { 0.55, 0.5},
+ { 0.5, 0.55},
+ { 0.45, 0.5}};
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glVertexPointer(2,GL_FLOAT,0,points);
- glColorPointer(4,GL_FLOAT,0,colors);
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glColorPointer(4,GL_FLOAT,0,colors);
- glDrawArrays(GL_TRIANGLE_FAN,0,6);
-
- }
+ glDrawArrays(GL_TRIANGLE_FAN,0,6);
+}
Shape::Shape():RenderItem()
{
- std::string imageUrl = "";
- sides = 4;
- thickOutline = false;
- enabled = true;
- additive = false;
- textured = false;
+ std::string imageUrl = "";
- tex_zoom = 1.0;
- tex_ang = 0.0;
+ sides = 4;
+ thickOutline = false;
+ enabled = true;
+ additive = false;
+ textured = false;
- x = 0.5;
- y = 0.5;
- radius = 1.0;
- ang = 0.0;
+ tex_zoom = 1.0;
+ tex_ang = 0.0;
- r = 0.0; /* red color value */
- g = 0.0; /* green color value */
- b = 0.0; /* blue color value */
- a = 0.0; /* alpha color value */
+ x = 0.5;
+ y = 0.5;
+ radius = 1.0;
+ ang = 0.0;
- r2 = 0.0; /* red color value */
- g2 = 0.0; /* green color value */
- b2 = 0.0; /* blue color value */
- a2 = 0.0; /* alpha color value */
+ r = 0.0; /* red color value */
+ g = 0.0; /* green color value */
+ b = 0.0; /* blue color value */
+ a = 0.0; /* alpha color value */
- border_r = 0.0; /* red color value */
- border_g = 0.0; /* green color value */
- border_b = 0.0; /* blue color value */
- border_a = 0.0; /* alpha color value */
+ r2 = 0.0; /* red color value */
+ g2 = 0.0; /* green color value */
+ b2 = 0.0; /* blue color value */
+ a2 = 0.0; /* alpha color value */
-
+ border_r = 0.0; /* red color value */
+ border_g = 0.0; /* green color value */
+ border_b = 0.0; /* blue color value */
+ border_a = 0.0; /* alpha color value */
}
-void Shape::Draw(RenderContext &context)
+void
+Shape::Draw(RenderContext &context)
{
+ float xval, yval;
+ float t;
- float xval, yval;
- float t;
+ // printf("drawing shape %f\n", ang);
- // printf("drawing shape %f\n", ang);
+ float temp_radius= radius*(.707*.707*.707*1.04);
- float temp_radius= radius*(.707*.707*.707*1.04);
- //Additive Drawing or Overwrite
- if ( additive==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- else glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ //Additive Drawing or Overwrite
+ if (additive == 0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ else glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- xval= x;
- yval= -(y-1);
+ xval= x;
+ yval= -(y-1);
- if ( textured)
- {
- if (imageUrl !="")
- {
- GLuint tex= context.textureManager->getTexture(imageUrl);
- if (tex != 0)
- {
- glBindTexture(GL_TEXTURE_2D, tex);
- context.aspectRatio=1.0;
- }
- }
+ if ( textured)
+ {
+ if (imageUrl !="")
+ {
+ GLuint tex= context.textureManager->getTexture(imageUrl);
+ if (tex != 0)
+ {
+ glBindTexture(GL_TEXTURE_2D, tex);
+ context.aspectRatio=1.0;
+ }
+ }
- glMatrixMode(GL_TEXTURE);
- glPushMatrix();
- glLoadIdentity();
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+ glLoadIdentity();
- glEnable(GL_TEXTURE_2D);
+ glEnable(GL_TEXTURE_2D);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- floatQuad *colors = new float[sides+2][4];
- floatPair *tex = new float[sides+2][2];
- floatPair *points = new float[sides+2][2];
+ floatQuad *colors = new float[sides+2][4];
+ floatPair *tex = new float[sides+2][2];
+ floatPair *points = new float[sides+2][2];
- //Define the center point of the shape
- colors[0][0] = r;
- colors[0][1] = g;
- colors[0][2] = b;
- colors[0][3] = a * masterAlpha;
- tex[0][0] = 0.5;
- tex[0][1] = 0.5;
- points[0][0] = xval;
- points[0][1] = yval;
+ //Define the center point of the shape
+ colors[0][0] = r;
+ colors[0][1] = g;
+ colors[0][2] = b;
+ colors[0][3] = a * masterAlpha;
+ tex[0][0] = 0.5;
+ tex[0][1] = 0.5;
+ points[0][0] = xval;
+ points[0][1] = yval;
- for ( int i=1;i< sides+2;i++)
- {
- colors[i][0]= r2;
- colors[i][1]=g2;
- colors[i][2]=b2;
- colors[i][3]=a2 * masterAlpha;
+ for ( int i=1;i< sides+2;i++)
+ {
+ colors[i][0] = r2;
+ colors[i][1] = g2;
+ colors[i][2] = b2;
+ colors[i][3] = a2 * masterAlpha;
- t = (i-1)/(float) sides;
- tex[i][0] =0.5f + 0.5f*cosf(t*3.1415927f*2 + tex_ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)/ tex_zoom;
- tex[i][1] = 0.5f + 0.5f*sinf(t*3.1415927f*2 + tex_ang + 3.1415927f*0.25f)/ tex_zoom;
- points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval;
- points[i][1]=temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval;
+ t = (i-1)/(float) sides;
+ tex[i][0] = 0.5f + 0.5f*cosf(t*3.1415927f*2 + tex_ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)/ tex_zoom;
+ tex[i][1] = 0.5f + 0.5f*sinf(t*3.1415927f*2 + tex_ang + 3.1415927f*0.25f)/ tex_zoom;
+ points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval;
+ points[i][1]=temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval;
+ }
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glColorPointer(4,GL_FLOAT,0,colors);
+ glTexCoordPointer(2,GL_FLOAT,0,tex);
- }
+ glDrawArrays(GL_TRIANGLE_FAN,0,sides+2);
- glVertexPointer(2,GL_FLOAT,0,points);
- glColorPointer(4,GL_FLOAT,0,colors);
- glTexCoordPointer(2,GL_FLOAT,0,tex);
+ glDisable(GL_TEXTURE_2D);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
- glDrawArrays(GL_TRIANGLE_FAN,0,sides+2);
+ //Reset Texture state since we might have changed it
+ /*
+ if(this->renderTarget->useFBO)
+ {
+ glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[1] );
+ }
+ else
+ {
+ glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[0] );
+ }
+ */
- glDisable(GL_TEXTURE_2D);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
+ delete[] colors;
+ delete[] tex;
+ delete[] points;
+ }
+ else
+ {
+ //Untextured (use color values)
- //Reset Texture state since we might have changed it
-/*
- if(this->renderTarget->useFBO)
- {
- glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[1] );
- }
- else
- {
- glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[0] );
- }
-*/
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- delete[] colors;
- delete[] tex;
- delete[] points;
- }
- else
- {//Untextured (use color values)
+ floatQuad *colors = new float[sides+2][4];
+ floatPair *points = new float[sides+2][2];
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- floatQuad *colors = new float[sides+2][4];
- floatPair *points = new float[sides+2][2];
-
- //Define the center point of the shape
- colors[0][0]=r;
- colors[0][1]=g;
- colors[0][2]=b;
- colors[0][3]=a * masterAlpha;
- points[0][0]=xval;
- points[0][1]=yval;
+ //Define the center point of the shape
+ colors[0][0]=r;
+ colors[0][1]=g;
+ colors[0][2]=b;
+ colors[0][3]=a * masterAlpha;
+ points[0][0]=xval;
+ points[0][1]=yval;
- for ( int i=1;i< sides+2;i++)
- {
- colors[i][0]=r2;
- colors[i][1]=g2;
- colors[i][2]=b2;
- colors[i][3]=a2 * masterAlpha;
- t = (i-1)/(float) sides;
- points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval;
- points[i][1]=temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval;
+ for ( int i=1;i< sides+2;i++)
+ {
+ colors[i][0]=r2;
+ colors[i][1]=g2;
+ colors[i][2]=b2;
+ colors[i][3]=a2 * masterAlpha;
+ t = (i-1)/(float) sides;
+ points[i][0]=temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval;
+ points[i][1]=temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval;
- }
+ }
- glVertexPointer(2,GL_FLOAT,0,points);
- glColorPointer(4,GL_FLOAT,0,colors);
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glColorPointer(4,GL_FLOAT,0,colors);
- glDrawArrays(GL_TRIANGLE_FAN,0,sides+2);
- //draw first n-1 triangular pieces
+ glDrawArrays(GL_TRIANGLE_FAN,0,sides+2);
+ //draw first n-1 triangular pieces
- delete[] colors;
- delete[] points;
- }
- if (thickOutline==1) glLineWidth(context.texsize < 512 ? 1 : 2*context.texsize/512);
+ delete[] colors;
+ delete[] points;
+ }
+ if (thickOutline==1) glLineWidth(context.texsize < 512 ? 1 : 2*context.texsize/512);
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
- floatPair *points = new float[sides+1][2];
+ floatPair *points = new float[sides+1][2];
- glColor4f( border_r, border_g, border_b, border_a * masterAlpha);
+ glColor4f( border_r, border_g, border_b, border_a * masterAlpha);
- for ( int i=0;i< sides;i++)
- {
- t = (i-1)/(float) sides;
- points[i][0]= temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval;
- points[i][1]= temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval;
+ for ( int i=0;i< sides;i++)
+ {
+ t = (i-1)/(float) sides;
+ points[i][0] = temp_radius*cosf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)*(context.aspectCorrect ? context.aspectRatio : 1.0)+xval;
+ points[i][1] = temp_radius*sinf(t*3.1415927f*2 + ang + 3.1415927f*0.25f)+yval;
+ }
- }
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glDrawArrays(GL_LINE_LOOP,0,sides);
- glVertexPointer(2,GL_FLOAT,0,points);
- glDrawArrays(GL_LINE_LOOP,0,sides);
+ if (thickOutline==1) glLineWidth(context.texsize < 512 ? 1 : context.texsize/512);
- if (thickOutline==1) glLineWidth(context.texsize < 512 ? 1 : context.texsize/512);
-
- delete[] points;
-
-
+ delete[] points;
}
-void MotionVectors::Draw(RenderContext &context)
+void
+MotionVectors::Draw(RenderContext &context)
{
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
- float intervalx=1.0/x_num;
- float intervaly=1.0/y_num;
+ float intervalx=1.0/x_num;
+ float intervaly=1.0/y_num;
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPointSize(length);
- glColor4f(r, g, b, a * masterAlpha);
+ glPointSize(length);
+ glColor4f(r, g, b, a * masterAlpha);
- if (x_num + y_num < 600)
- {
- int size = x_num * y_num ;
+ if (x_num + y_num < 600)
+ {
+ int size = x_num * y_num ;
- floatPair *points = new float[size][2];
+ floatPair *points = new float[size][2];
- for (int x=0;x<(int)x_num;x++)
- {
- for(int y=0;y<(int)y_num;y++)
- {
- float lx, ly, lz;
- lx = x_offset+x*intervalx;
- ly = y_offset+y*intervaly;
+ for (int x=0;x<(int)x_num;x++)
+ {
+ for(int y=0;y<(int)y_num;y++)
+ {
+ float lx, ly, lz;
+ lx = x_offset+x*intervalx;
+ ly = y_offset+y*intervaly;
- points[(x * (int)y_num) + y][0] = lx;
- points[(x * (int)y_num) + y][1] = ly;
- }
- }
+ points[(x * (int)y_num) + y][0] = lx;
+ points[(x * (int)y_num) + y][1] = ly;
+ }
+ }
- glVertexPointer(2,GL_FLOAT,0,points);
- glDrawArrays(GL_POINTS,0,size);
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glDrawArrays(GL_POINTS,0,size);
- delete[] points;
- }
+ delete[] points;
+ }
}
-void Border::Draw(RenderContext &context)
+void
+Border::Draw(RenderContext &context)
{
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- //Draw Borders
- float of=outer_size*.5;
- float iff=inner_size*.5;
- float texof=1.0-of;
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ //Draw Borders
+ float of=outer_size*.5;
+ float iff=inner_size*.5;
+ float texof=1.0-of;
- //no additive drawing for borders
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4f(outer_r, outer_g, outer_b, outer_a * masterAlpha);
+ //no additive drawing for borders
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(outer_r, outer_g, outer_b, outer_a * masterAlpha);
- float pointsA[4][2] = {{0,0},{0,1},{of,0},{of,1}};
- glVertexPointer(2,GL_FLOAT,0,pointsA);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsA[4][2] = {{0,0},{0,1},{of,0},{of,1}};
+ glVertexPointer(2,GL_FLOAT,0,pointsA);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
- float pointsB[4][2] = {{of,0},{of,of},{texof,0},{texof,of}};
- glVertexPointer(2,GL_FLOAT,0,pointsB);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsB[4][2] = {{of,0},{of,of},{texof,0},{texof,of}};
+ glVertexPointer(2,GL_FLOAT,0,pointsB);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
- float pointsC[4][2] = {{texof,0},{texof,1},{1,0},{1,1}};
- glVertexPointer(2,GL_FLOAT,0,pointsC);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsC[4][2] = {{texof,0},{texof,1},{1,0},{1,1}};
+ glVertexPointer(2,GL_FLOAT,0,pointsC);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
- float pointsD[4][2] = {{of,1},{of,texof},{texof,1},{texof,texof}};
- glVertexPointer(2,GL_FLOAT,0,pointsD);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsD[4][2] = {{of,1},{of,texof},{texof,1},{texof,texof}};
+ glVertexPointer(2,GL_FLOAT,0,pointsD);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
- glColor4f(inner_r, inner_g, inner_b, inner_a * masterAlpha);
+ glColor4f(inner_r, inner_g, inner_b, inner_a * masterAlpha);
- glRectf(of, of, of+iff, texof);
- glRectf(of+iff, of, texof-iff, of+iff);
- glRectf(texof-iff, of, texof, texof);
- glRectf(of+iff, texof, texof-iff, texof-iff);
+ glRectf(of, of, of+iff, texof);
+ glRectf(of+iff, of, texof-iff, of+iff);
+ glRectf(texof-iff, of, texof, texof);
+ glRectf(of+iff, texof, texof-iff, texof-iff);
- float pointsE[4][2] = {{of,of},{of,texof},{of+iff,of},{of+iff,texof}};
- glVertexPointer(2,GL_FLOAT,0,pointsE);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsE[4][2] = {{of,of},{of,texof},{of+iff,of},{of+iff,texof}};
+ glVertexPointer(2,GL_FLOAT,0,pointsE);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
- float pointsF[4][2] = {{of+iff,of},{of+iff,of+iff},{texof-iff,of},{texof-iff,of+iff}};
- glVertexPointer(2,GL_FLOAT,0,pointsF);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsF[4][2] = {{of+iff,of},{of+iff,of+iff},{texof-iff,of},{texof-iff,of+iff}};
+ glVertexPointer(2,GL_FLOAT,0,pointsF);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
- float pointsG[4][2] = {{texof-iff,of},{texof-iff,texof},{texof,of},{texof,texof}};
- glVertexPointer(2,GL_FLOAT,0,pointsG);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsG[4][2] = {{texof-iff,of},{texof-iff,texof},{texof,of},{texof,texof}};
+ glVertexPointer(2,GL_FLOAT,0,pointsG);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
- float pointsH[4][2] = {{of+iff,texof},{of+iff,texof-iff},{texof-iff,texof},{texof-iff,texof-iff}};
- glVertexPointer(2,GL_FLOAT,0,pointsH);
- glDrawArrays(GL_TRIANGLE_STRIP,0,4);
+ float pointsH[4][2] = {{of+iff,texof},{of+iff,texof-iff},{texof-iff,texof},{texof-iff,texof-iff}};
+ glVertexPointer(2,GL_FLOAT,0,pointsH);
+ glDrawArrays(GL_TRIANGLE_STRIP,0,4);
}
diff --git a/src/libprojectM/Renderer/Renderable.hpp b/src/libprojectM/Renderer/Renderable.hpp
index b2aa72f..4f759e0 100644
--- a/src/libprojectM/Renderer/Renderable.hpp
+++ b/src/libprojectM/Renderer/Renderable.hpp
@@ -3,28 +3,30 @@
#include <vector>
#include <typeinfo>
#include "TextureManager.hpp"
+
+
class BeatDetect;
class RenderContext
{
public:
- float time;
- int texsize;
- float aspectRatio;
- bool aspectCorrect;
- BeatDetect *beatDetect;
- TextureManager *textureManager;
+ float time;
+ int texsize;
+ float aspectRatio;
+ bool aspectCorrect;
+ BeatDetect *beatDetect;
+ TextureManager *textureManager;
- RenderContext();
+ RenderContext();
};
class RenderItem
{
public:
- float masterAlpha;
- virtual void Draw(RenderContext &context) = 0;
- RenderItem();
+ float masterAlpha;
+ virtual void Draw(RenderContext &context) = 0;
+ RenderItem();
};
typedef std::vector<RenderItem*> RenderItemList;
@@ -32,46 +34,46 @@
class DarkenCenter : public RenderItem
{
public:
- DarkenCenter();
- void Draw(RenderContext &context);
+ DarkenCenter();
+ void Draw(RenderContext &context);
};
class Shape : public RenderItem
{
public:
- std::string imageUrl;
- int sides;
- bool thickOutline;
- bool enabled;
- bool additive;
- bool textured;
+ std::string imageUrl;
+ int sides;
+ bool thickOutline;
+ bool enabled;
+ bool additive;
+ bool textured;
- float tex_zoom;
- float tex_ang;
+ float tex_zoom;
+ float tex_ang;
- float x; /* x position */
- float y; /* y position */
- float radius;
- float ang;
+ float x; /* x position */
+ float y; /* y position */
+ float radius;
+ float ang;
- float r; /* red color value */
- float g; /* green color value */
- float b; /* blue color value */
- float a; /* alpha color value */
+ float r; /* red color value */
+ float g; /* green color value */
+ float b; /* blue color value */
+ float a; /* alpha color value */
- float r2; /* red color value */
- float g2; /* green color value */
- float b2; /* blue color value */
- float a2; /* alpha color value */
+ float r2; /* red color value */
+ float g2; /* green color value */
+ float b2; /* blue color value */
+ float a2; /* alpha color value */
- float border_r; /* red color value */
- float border_g; /* green color value */
- float border_b; /* blue color value */
- float border_a; /* alpha color value */
+ float border_r; /* red color value */
+ float border_g; /* green color value */
+ float border_b; /* blue color value */
+ float border_a; /* alpha color value */
- Shape();
- virtual void Draw(RenderContext &context);
+ Shape();
+ virtual void Draw(RenderContext &context);
};
class Text : RenderItem
@@ -81,55 +83,56 @@
class MotionVectors : public RenderItem
{
public:
- float r;
- float g;
- float b;
- float a;
- float length;
- float x_num;
- float y_num;
- float x_offset;
- float y_offset;
+ float r;
+ float g;
+ float b;
+ float a;
+ float length;
+ float x_num;
+ float y_num;
+ float x_offset;
+ float y_offset;
- void Draw(RenderContext &context);
- MotionVectors();
+ void Draw(RenderContext &context);
+ MotionVectors();
};
class Border : public RenderItem
{
public:
- float outer_size;
- float outer_r;
- float outer_g;
- float outer_b;
- float outer_a;
+ float outer_size;
+ float outer_r;
+ float outer_g;
+ float outer_b;
+ float outer_a;
- float inner_size;
- float inner_r;
- float inner_g;
- float inner_b;
- float inner_a;
+ float inner_size;
+ float inner_r;
+ float inner_g;
+ float inner_b;
+ float inner_a;
- void Draw(RenderContext &context);
- Border();
+ void Draw(RenderContext &context);
+ Border();
};
+/* FIXME: 'struct'? Really? */
struct TypeIdPair {
- TypeIdPair(const std::type_info & info1, const std::type_info & info2): id1(info1.name()), id2(info2.name()) {}
- TypeIdPair(const std::string & id1, const std::string & id2): id1(id1), id2(id2) {}
- std::string id1;
- std::string id2;
- inline bool operator<(const TypeIdPair & rhs) const {
- return this->id1 < rhs.id1 || (this->id1 == rhs.id1 && this->id2 < rhs.id2);
- }
+ TypeIdPair(const std::type_info & info1, const std::type_info & info2): id1(info1.name()), id2(info2.name()) {}
+ TypeIdPair(const std::string & id1, const std::string & id2): id1(id1), id2(id2) {}
+ std::string id1;
+ std::string id2;
+ inline bool operator<(const TypeIdPair & rhs) const {
+ return this->id1 < rhs.id1 || (this->id1 == rhs.id1 && this->id2 < rhs.id2);
+ }
- inline bool operator>(const TypeIdPair & rhs) const {
- return !operator<(rhs) && !operator==(rhs);
- }
+ inline bool operator>(const TypeIdPair & rhs) const {
+ return !operator<(rhs) && !operator==(rhs);
+ }
- inline bool operator==(const TypeIdPair & rhs) const {
- return this->id1 == rhs.id1 && this->id2 == rhs.id2;
- }
+ inline bool operator==(const TypeIdPair & rhs) const {
+ return this->id1 == rhs.id1 && this->id2 == rhs.id2;
+ }
};
#endif
diff --git a/src/libprojectM/Renderer/Renderer.cpp b/src/libprojectM/Renderer/Renderer.cpp
index 509ea79..0e72cb9 100644
--- a/src/libprojectM/Renderer/Renderer.cpp
+++ b/src/libprojectM/Renderer/Renderer.cpp
@@ -11,771 +11,799 @@
#include "omptl/omptl_algorithm"
#include "UserTexture.hpp"
+
class Preset;
-Renderer::Renderer(int width, int height, int gx, int gy, int texsize, BeatDetect *beatDetect, std::string _presetURL,
- std::string _titlefontURL, std::string _menufontURL) :
- title_fontURL(_titlefontURL), menu_fontURL(_menufontURL), presetURL(_presetURL), m_presetName("None"), vw(width),
- vh(height), texsize(texsize), mesh(gx, gy)
+Renderer::Renderer (
+int width,
+int height,
+int gx,
+int gy,
+int texsize,
+BeatDetect *beatDetect,
+std::string _presetURL,
+std::string _titlefontURL,
+std::string _menufontURL
+)
+ : title_fontURL(_titlefontURL),
+ menu_fontURL(_menufontURL),
+ presetURL(_presetURL),
+ m_presetName("None"),
+ vw(width), vh(height),
+ texsize(texsize),
+ mesh(gx, gy)
{
- int x;
- int y;
+ int x;
+ int y;
- this->totalframes = 1;
- this->noSwitch = false;
- this->showfps = false;
- this->showtitle = false;
- this->showpreset = false;
- this->showhelp = false;
- this->showstats = false;
- this->studio = false;
- this->realfps = 0;
+ this->totalframes = 1;
+ this->noSwitch = false;
+ this->showfps = false;
+ this->showtitle = false;
+ this->showpreset = false;
+ this->showhelp = false;
+ this->showstats = false;
+ this->studio = false;
+ this->realfps = 0;
- this->drawtitle = 0;
+ this->drawtitle = 0;
- //this->title = "Unknown";
+ //this->title = "Unknown";
- /** Other stuff... */
- this->correction = true;
- this->aspect = (float) height / (float) width;;
+ /** Other stuff... */
+ this->correction = true;
+ this->aspect = (float) height / (float) width;;
- /// @bug put these on member init list
- this->renderTarget = new RenderTarget(texsize, width, height);
- this->textureManager = new TextureManager(presetURL);
- this->beatDetect = beatDetect;
+ /// @bug put these on member init list
+ this->renderTarget = new RenderTarget(texsize, width, height);
+ this->textureManager = new TextureManager(presetURL);
+ this->beatDetect = beatDetect;
#ifdef USE_FTGL
- /**f Load the standard fonts */
+ /**f Load the standard fonts */
- title_font = new FTGLPixmapFont(title_fontURL.c_str());
- other_font = new FTGLPixmapFont(menu_fontURL.c_str());
- poly_font = new FTGLExtrdFont(title_fontURL.c_str());
+ title_font = new FTGLPixmapFont(title_fontURL.c_str());
+ other_font = new FTGLPixmapFont(menu_fontURL.c_str());
+ poly_font = new FTGLExtrdFont(title_fontURL.c_str());
- if(title_font->Error()) {
- fprintf(stderr, "Failed to open font %s\n", title_fontURL.c_str());
- } else {
- title_font->UseDisplayList(true);
- }
+ if(title_font->Error()) {
+ fprintf(stderr, "Failed to open font %s\n", title_fontURL.c_str());
+ } else {
+ title_font->UseDisplayList(true);
+ }
- other_font->UseDisplayList(true);
+ other_font->UseDisplayList(true);
- if(poly_font->Error()) {
- fprintf(stderr, "Failed to open font %s\n", title_fontURL.c_str());
- } else {
- poly_font->UseDisplayList(true);
- poly_font->Depth(20);
- poly_font->FaceSize(72);
- }
-
+ if(poly_font->Error()) {
+ fprintf(stderr, "Failed to open font %s\n", title_fontURL.c_str());
+ } else {
+ poly_font->UseDisplayList(true);
+ poly_font->Depth(20);
+ poly_font->FaceSize(72);
+ }
#endif /** USE_FTGL */
- int size = (mesh.height - 1) *mesh.width * 5 * 2;
- p = ( float * ) wipemalloc ( size * sizeof ( float ) );
+ int size = (mesh.height - 1) *mesh.width * 5 * 2;
+ p = ( float * ) wipemalloc ( size * sizeof ( float ) );
- for (int j = 0; j < mesh.height - 1; j++)
- {
- int base = j * mesh.width * 2 * 5;
+ for (int j = 0; j < mesh.height - 1; j++)
+ {
+ int base = j * mesh.width * 2 * 5;
-
- for (int i = 0; i < mesh.width; i++)
- {
- int index = j * mesh.width + i;
- int index2 = (j + 1) * mesh.width + i;
-
- int strip = base + i * 10;
- p[strip + 2] = mesh.identity[index].x;
- p[strip + 3] = mesh.identity[index].y;
- p[strip + 4] = 0;
-
- p[strip + 7] = mesh.identity[index2].x;
- p[strip + 8] = mesh.identity[index2].y;
- p[strip + 9] = 0;
- }
- }
-
-
-#ifdef USE_CG
- shaderEngine.setParams(renderTarget->texsize, renderTarget->textureID[1], aspect, beatDetect, textureManager);
-#endif
-
-}
-
-void Renderer::SetPipeline(Pipeline &pipeline)
-{
- currentPipe = &pipeline;
-#ifdef USE_CG
- shaderEngine.reset();
- shaderEngine.loadShader(pipeline.warpShader);
- shaderEngine.loadShader(pipeline.compositeShader);
-#endif
-}
-
-void Renderer::ResetTextures()
-{
- textureManager->Clear();
-
- delete (renderTarget);
- renderTarget = new RenderTarget(texsize, vw, vh);
- reset(vw, vh);
-
- textureManager->Preload();
-}
-
-void Renderer::SetupPass1(const Pipeline &pipeline, const PipelineContext &pipelineContext)
-{
- //glMatrixMode(GL_PROJECTION);
- //glPushMatrix();
- //glMatrixMode(GL_MODELVIEW);
- //glPushMatrix();
-
- totalframes++;
- renderTarget->lock();
- glViewport(0, 0, renderTarget->texsize, renderTarget->texsize);
-
- glEnable(GL_TEXTURE_2D);
-
- //If using FBO, switch to FBO texture
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
-#ifdef USE_GLES1
- glOrthof(0.0, 1, 0.0, 1, -40, 40);
-#else
- glOrtho(0.0, 1, 0.0, 1, -40, 40);
-#endif
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
-#ifdef USE_CG
- shaderEngine.RenderBlurTextures(pipeline, pipelineContext, renderTarget->texsize);
-#endif
-}
-
-void Renderer::RenderItems(const Pipeline &pipeline, const PipelineContext &pipelineContext)
-{
- renderContext.time = pipelineContext.time;
- renderContext.texsize = texsize;
- renderContext.aspectCorrect = correction;
- renderContext.aspectRatio = aspect;
- renderContext.textureManager = textureManager;
- renderContext.beatDetect = beatDetect;
-
- for (std::vector<RenderItem*>::const_iterator pos = pipeline.drawables.begin(); pos != pipeline.drawables.end(); ++pos)
+ for (int i = 0; i < mesh.width; i++)
{
- if (*pos != NULL)
- {
- (*pos)->Draw(renderContext);
- }
+ int index = j * mesh.width + i;
+ int index2 = (j + 1) * mesh.width + i;
+
+ int strip = base + i * 10;
+ p[strip + 2] = mesh.identity[index].x;
+ p[strip + 3] = mesh.identity[index].y;
+ p[strip + 4] = 0;
+
+ p[strip + 7] = mesh.identity[index2].x;
+ p[strip + 8] = mesh.identity[index2].y;
+ p[strip + 9] = 0;
}
-}
+ }
-void Renderer::FinishPass1()
-{
- draw_title_to_texture();
- /** Restore original view state */
- //glMatrixMode(GL_MODELVIEW);
- //glPopMatrix();
-
- //glMatrixMode(GL_PROJECTION);
- //glPopMatrix();
-
- renderTarget->unlock();
-
-}
-
-void Renderer::Pass2(const Pipeline &pipeline, const PipelineContext &pipelineContext)
-{
- //BEGIN PASS 2
- //
- //end of texture rendering
- //now we copy the texture from the FBO or framebuffer to
- //video texture memory and render fullscreen.
-
- /** Reset the viewport size */
-#ifdef USE_FBO
- if (renderTarget->renderToTexture)
- {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->renderTarget->fbuffer[1]);
- glViewport(0, 0, this->renderTarget->texsize, this->renderTarget->texsize);
- }
- else
-#endif
- glViewport(0, 0, this->vw, this->vh);
-
- glBindTexture(GL_TEXTURE_2D, this->renderTarget->textureID[0]);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-#ifdef USE_GLES1
- glOrthof(-0.5, 0.5, -0.5, 0.5, -40, 40);
-#else
- glOrtho(-0.5, 0.5, -0.5, 0.5, -40, 40);
-#endif
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glLineWidth(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize / 512.0);
-
- CompositeOutput(pipeline, pipelineContext);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(-0.5, -0.5, 0);
-
- // When console refreshes, there is a chance the preset has been changed by the user
- refreshConsole();
- draw_title_to_screen(false);
- if (this->showhelp % 2)
- draw_help();
- if (this->showtitle % 2)
- draw_title();
- if (this->showfps % 2)
- draw_fps(this->realfps);
- if (this->showpreset % 2)
- draw_preset();
- if (this->showstats % 2)
- draw_stats();
- glTranslatef(0.5, 0.5, 0);
-
-#ifdef USE_FBO
- if (renderTarget->renderToTexture)
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-#endif
-}
-
-void Renderer::RenderFrame(const Pipeline &pipeline, const PipelineContext &pipelineContext)
-{
-
- SetupPass1(pipeline, pipelineContext);
#ifdef USE_CG
- shaderEngine.enableShader(currentPipe->warpShader, pipeline, pipelineContext);
-#endif
- Interpolation(pipeline);
-#ifdef USE_CG
- shaderEngine.disableShader();
+ shaderEngine.setParams(renderTarget->texsize, renderTarget->textureID[1], aspect, beatDetect, textureManager);
#endif
- RenderItems(pipeline, pipelineContext);
- FinishPass1();
- Pass2(pipeline, pipelineContext);
}
-void Renderer::Interpolation(const Pipeline &pipeline)
+void
+Renderer::SetPipeline(Pipeline &pipeline)
{
- if (this->renderTarget->useFBO)
- glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[1]);
- else
- glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[0]);
-
- //Texture wrapping( clamp vs. wrap)
- if (pipeline.textureWrap == 0)
- {
-#ifdef USE_GLES1
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-#else
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ currentPipe = &pipeline;
+#ifdef USE_CG
+ shaderEngine.reset();
+ shaderEngine.loadShader(pipeline.warpShader);
+ shaderEngine.loadShader(pipeline.compositeShader);
#endif
- }
- else
- {
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- }
+}
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
+void
+Renderer::ResetTextures()
+{
+ textureManager->Clear();
- glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
+ delete (renderTarget);
+ renderTarget = new RenderTarget(texsize, vw, vh);
+ reset(vw, vh);
- glColor4f(1.0, 1.0, 1.0, pipeline.screenDecay);
+ textureManager->Preload();
+}
- glEnable(GL_TEXTURE_2D);
+void
+Renderer::SetupPass1(const Pipeline &pipeline, const PipelineContext &pipelineContext)
+{
+ //glMatrixMode(GL_PROJECTION);
+ //glPushMatrix();
+ //glMatrixMode(GL_MODELVIEW);
+ //glPushMatrix();
+
+ totalframes++;
+ renderTarget->lock();
+ glViewport(0, 0, renderTarget->texsize, renderTarget->texsize);
+
+ glEnable(GL_TEXTURE_2D);
+
+ //If using FBO, switch to FBO texture
+
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+#ifdef USE_GLES1
+ glOrthof(0.0, 1, 0.0, 1, -40, 40);
+#else
+ glOrtho(0.0, 1, 0.0, 1, -40, 40);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+#ifdef USE_CG
+ shaderEngine.RenderBlurTextures(pipeline, pipelineContext, renderTarget->texsize);
+#endif
+}
+
+void
+Renderer::RenderItems(const Pipeline &pipeline, const PipelineContext &pipelineContext)
+{
+ renderContext.time = pipelineContext.time;
+ renderContext.texsize = texsize;
+ renderContext.aspectCorrect = correction;
+ renderContext.aspectRatio = aspect;
+ renderContext.textureManager = textureManager;
+ renderContext.beatDetect = beatDetect;
+
+ for (std::vector<RenderItem*>::const_iterator pos = pipeline.drawables.begin();
+ pos != pipeline.drawables.end();
+ ++pos)
+ {
+ if (*pos != NULL)
+ {
+ (*pos)->Draw(renderContext);
+ }
+ }
+}
+
+void
+Renderer::FinishPass1()
+{
+ draw_title_to_texture();
+ /** Restore original view state */
+ //glMatrixMode(GL_MODELVIEW);
+ //glPopMatrix();
+
+ //glMatrixMode(GL_PROJECTION);
+ //glPopMatrix();
+
+ renderTarget->unlock();
+}
+
+void
+Renderer::Pass2(const Pipeline &pipeline, const PipelineContext &pipelineContext)
+{
+ //BEGIN PASS 2
+ //
+ //end of texture rendering
+ //now we copy the texture from the FBO or framebuffer to
+ //video texture memory and render fullscreen.
+
+ /** Reset the viewport size */
+#ifdef USE_FBO
+ if (renderTarget->renderToTexture)
+ {
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->renderTarget->fbuffer[1]);
+ glViewport(0, 0, this->renderTarget->texsize, this->renderTarget->texsize);
+ }
+ else
+#endif
+ glViewport(0, 0, this->vw, this->vh);
+
+ glBindTexture(GL_TEXTURE_2D, this->renderTarget->textureID[0]);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef USE_GLES1
+ glOrthof(-0.5, 0.5, -0.5, 0.5, -40, 40);
+#else
+ glOrtho(-0.5, 0.5, -0.5, 0.5, -40, 40);
+#endif
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glLineWidth(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize / 512.0);
+
+ CompositeOutput(pipeline, pipelineContext);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(-0.5, -0.5, 0);
+
+ // When console refreshes, there is a chance the preset has been changed by the user
+ refreshConsole();
+ draw_title_to_screen(false);
+ if (this->showhelp % 2)
+ draw_help();
+ if (this->showtitle % 2)
+ draw_title();
+ if (this->showfps % 2)
+ draw_fps(this->realfps);
+ if (this->showpreset % 2)
+ draw_preset();
+ if (this->showstats % 2)
+ draw_stats();
+ glTranslatef(0.5, 0.5, 0);
+
+#ifdef USE_FBO
+ if (renderTarget->renderToTexture)
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+#endif
+}
+
+void
+Renderer::RenderFrame(const Pipeline &pipeline, const PipelineContext &pipelineContext)
+{
+
+ SetupPass1(pipeline, pipelineContext);
+
+#ifdef USE_CG
+ shaderEngine.enableShader(currentPipe->warpShader, pipeline, pipelineContext);
+#endif
+ Interpolation(pipeline);
+#ifdef USE_CG
+ shaderEngine.disableShader();
+#endif
+
+ RenderItems(pipeline, pipelineContext);
+ FinishPass1();
+ Pass2(pipeline, pipelineContext);
+}
+
+void
+Renderer::Interpolation(const Pipeline &pipeline)
+{
+ if (this->renderTarget->useFBO)
+ glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[1]);
+ else
+ glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[0]);
+
+ //Texture wrapping( clamp vs. wrap)
+ if (pipeline.textureWrap == 0)
+ {
+#ifdef USE_GLES1
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+#else
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+#endif
+ }
+ else
+ {
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ }
+
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
+
+ glColor4f(1.0, 1.0, 1.0, pipeline.screenDecay);
+
+ glEnable(GL_TEXTURE_2D);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
- //glVertexPointer(2, GL_FLOAT, 0, p);
- //glTexCoordPointer(2, GL_FLOAT, 0, t);
+ //glVertexPointer(2, GL_FLOAT, 0, p);
+ //glTexCoordPointer(2, GL_FLOAT, 0, t);
glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 5, (GLfloat *) p);
glVertexPointer (3, GL_FLOAT, sizeof (GLfloat) * 5, (GLfloat *) p + 2);
- if (pipeline.staticPerPixel)
- {
- for (int j = 0; j < mesh.height - 1; j++)
- {
- int base = j * mesh.width * 2 * 5;
+ if (pipeline.staticPerPixel)
+ {
+ for (int j = 0; j < mesh.height - 1; j++)
+ {
+ int base = j * mesh.width * 2 * 5;
- for (int i = 0; i < mesh.width; i++)
- {
- int strip = base + i * 10;
- p[strip] = pipeline.x_mesh[i][j];
- p[strip + 1] = pipeline.y_mesh[i][j];
+ for (int i = 0; i < mesh.width; i++)
+ {
+ int strip = base + i * 10;
+ p[strip] = pipeline.x_mesh[i][j];
+ p[strip + 1] = pipeline.y_mesh[i][j];
- p[strip + 5] = pipeline.x_mesh[i][j+1];
- p[strip + 6] = pipeline.y_mesh[i][j+1];
- }
- }
+ p[strip + 5] = pipeline.x_mesh[i][j+1];
+ p[strip + 6] = pipeline.y_mesh[i][j+1];
+ }
+ }
+ }
+ else
+ {
+ mesh.Reset();
+ omptl::transform(mesh.p.begin(), mesh.p.end(), mesh.identity.begin(), mesh.p.begin(), &Renderer::PerPixel);
- }
- else
- {
- mesh.Reset();
- omptl::transform(mesh.p.begin(), mesh.p.end(), mesh.identity.begin(), mesh.p.begin(), &Renderer::PerPixel);
+ for (int j = 0; j < mesh.height - 1; j++)
+ {
+ int base = j * mesh.width * 2 * 5;
- for (int j = 0; j < mesh.height - 1; j++)
- {
- int base = j * mesh.width * 2 * 5;
+ for (int i = 0; i < mesh.width; i++)
+ {
+ int strip = base + i * 10;
+ int index = j * mesh.width + i;
+ int index2 = (j + 1) * mesh.width + i;
- for (int i = 0; i < mesh.width; i++)
- {
- int strip = base + i * 10;
- int index = j * mesh.width + i;
- int index2 = (j + 1) * mesh.width + i;
+ p[strip] = mesh.p[index].x;
+ p[strip + 1] = mesh.p[index].y;
- p[strip] = mesh.p[index].x;
- p[strip + 1] = mesh.p[index].y;
-
- p[strip + 5] = mesh.p[index2].x;
- p[strip + 6] = mesh.p[index2].y;
+ p[strip + 5] = mesh.p[index2].x;
+ p[strip + 6] = mesh.p[index2].y;
- }
- }
+ }
+ }
+ }
- }
-
- for (int j = 0; j < mesh.height - 1; j++)
- glDrawArrays(GL_TRIANGLE_STRIP,j* mesh.width* 2,mesh.width*2);
+ for (int j = 0; j < mesh.height - 1; j++)
+ glDrawArrays(GL_TRIANGLE_STRIP,j* mesh.width* 2,mesh.width*2);
- glDisable(GL_TEXTURE_2D);
+ glDisable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
+
Pipeline* Renderer::currentPipe;
Renderer::~Renderer()
{
- int x;
+ int x;
- if (renderTarget)
- delete (renderTarget);
- if (textureManager)
- delete (textureManager);
+ if (renderTarget)
+ delete (renderTarget);
+ if (textureManager)
+ delete (textureManager);
- //std::cerr << "grid assign end" << std::endl;
+ //std::cerr << "grid assign end" << std::endl;
- free(p);
+ free(p);
#ifdef USE_FTGL
- // std::cerr << "freeing title fonts" << std::endl;
- if (title_font)
- delete title_font;
- if (poly_font)
- delete poly_font;
- if (other_font)
- delete other_font;
- // std::cerr << "freeing title fonts finished" << std::endl;
+ // std::cerr << "freeing title fonts" << std::endl;
+ if (title_font)
+ delete title_font;
+ if (poly_font)
+ delete poly_font;
+ if (other_font)
+ delete other_font;
+ // std::cerr << "freeing title fonts finished" << std::endl;
#endif
- // std::cerr << "exiting destructor" << std::endl;
+ // std::cerr << "exiting destructor" << std::endl;
}
-void Renderer::reset(int w, int h)
+void
+Renderer::reset(int w, int h)
{
- aspect = (float) h / (float) w;
- this -> vw = w;
- this -> vh = h;
+ aspect = (float) h / (float) w;
+ this -> vw = w;
+ this -> vh = h;
#if USE_CG
- shaderEngine.setAspect(aspect);
+ shaderEngine.setAspect(aspect);
#endif
- glShadeModel(GL_SMOOTH);
+ glShadeModel(GL_SMOOTH);
- glCullFace(GL_BACK);
- //glFrontFace( GL_CCW );
+ glCullFace(GL_BACK);
+ //glFrontFace( GL_CCW );
- glClearColor(0, 0, 0, 0);
+ glClearColor(0, 0, 0, 0);
- glViewport(0, 0, w, h);
+ glViewport(0, 0, w, h);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
#ifndef USE_GLES1
- glDrawBuffer(GL_BACK);
- glReadBuffer(GL_BACK);
+ glDrawBuffer(GL_BACK);
+ glReadBuffer(GL_BACK);
#endif
- glEnable(GL_BLEND);
+ glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_LINE_SMOOTH);
- glEnable(GL_POINT_SMOOTH);
- glClear(GL_COLOR_BUFFER_BIT);
+ glEnable(GL_POINT_SMOOTH);
+ glClear(GL_COLOR_BUFFER_BIT);
#ifndef USE_GLES1
- glLineStipple(2, 0xAAAA);
+ glLineStipple(2, 0xAAAA);
#endif
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
- //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
- //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+ //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
+ //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
+ //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- if (!this->renderTarget->useFBO)
- {
- this->renderTarget->fallbackRescale(w, h);
- }
+ if (!this->renderTarget->useFBO)
+ {
+ this->renderTarget->fallbackRescale(w, h);
+ }
}
-GLuint Renderer::initRenderToTexture()
+GLuint
+Renderer::initRenderToTexture()
{
- return renderTarget->initRenderToTexture();
+ return renderTarget->initRenderToTexture();
}
-void Renderer::draw_title_to_texture()
+void
+Renderer::draw_title_to_texture()
{
#ifdef USE_FTGL
- if (this->drawtitle > 100)
- {
- draw_title_to_screen(true);
- this->drawtitle = 0;
- }
+ if (this->drawtitle > 100)
+ {
+ draw_title_to_screen(true);
+ this->drawtitle = 0;
+ }
#endif /** USE_FTGL */
}
float title_y;
-void Renderer::draw_title_to_screen(bool flip)
+void
+Renderer::draw_title_to_screen(bool flip)
{
#ifdef USE_FTGL
- if (this->drawtitle > 0)
- {
+ if (this->drawtitle > 0)
+ {
- //setUpLighting();
+ //setUpLighting();
- //glEnable(GL_POLYGON_SMOOTH);
- //glEnable( GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
- glClear(GL_DEPTH_BUFFER_BIT);
+ //glEnable(GL_POLYGON_SMOOTH);
+ //glEnable( GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+ glClear(GL_DEPTH_BUFFER_BIT);
- int draw;
- if (drawtitle >= 80)
- draw = 80;
- else
- draw = drawtitle;
+ int draw;
+ if (drawtitle >= 80)
+ draw = 80;
+ else
+ draw = drawtitle;
- float easein = ((80 - draw) * .0125);
- float easein2 = easein * easein;
+ float easein = ((80 - draw) * .0125);
+ float easein2 = easein * easein;
- if (drawtitle == 1)
- {
- title_y = (float) rand() / RAND_MAX;
- title_y *= 2;
- title_y -= 1;
- title_y *= .6;
- }
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- //glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE);
- glColor4f(1.0, 1.0, 1.0, 1.0);
+ if (drawtitle == 1)
+ {
+ title_y = (float) rand() / RAND_MAX;
+ title_y *= 2;
+ title_y -= 1;
+ title_y *= .6;
+ }
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ //glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
- glFrustum(-1, 1, -1 * (float) vh / (float) vw, 1 * (float) vh / (float) vw, 1, 1000);
- if (flip)
- glScalef(1, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ glFrustum(-1, 1, -1 * (float) vh / (float) vw, 1 * (float) vh / (float) vw, 1, 1000);
+ if (flip)
+ glScalef(1, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
- glTranslatef(-850, title_y * 850 * vh / vw, easein2 * 900 - 900);
+ glTranslatef(-850, title_y * 850 * vh / vw, easein2 * 900 - 900);
- glRotatef(easein2 * 360, 1, 0, 0);
+ glRotatef(easein2 * 360, 1, 0, 0);
- poly_font->Render(this->title.c_str());
+ poly_font->Render(this->title.c_str());
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- this->drawtitle++;
+ this->drawtitle++;
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
+ glPopMatrix();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
+ glMatrixMode(GL_MODELVIEW);
- glDisable(GL_CULL_FACE);
- glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_DEPTH_TEST);
- glDisable(GL_COLOR_MATERIAL);
+ glDisable(GL_COLOR_MATERIAL);
- glDisable(GL_LIGHTING);
- glDisable(GL_POLYGON_SMOOTH);
- }
+ glDisable(GL_LIGHTING);
+ glDisable(GL_POLYGON_SMOOTH);
+ }
#endif /** USE_FTGL */
}
-void Renderer::draw_title()
+void
+Renderer::draw_title()
{
#ifdef USE_FTGL
- //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
+ //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- // glPushMatrix();
- // glTranslatef(this->vw*.001,this->vh*.03, -1);
- // glScalef(this->vw*.015,this->vh*.025,0);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ // glPushMatrix();
+ // glTranslatef(this->vw*.001,this->vh*.03, -1);
+ // glScalef(this->vw*.015,this->vh*.025,0);
- glRasterPos2f(0.01, 0.05);
- title_font->FaceSize((unsigned) (20 * (this->vh / 512.0)));
+ glRasterPos2f(0.01, 0.05);
+ title_font->FaceSize((unsigned) (20 * (this->vh / 512.0)));
- title_font->Render(this->title.c_str());
- // glPopMatrix();
- //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ title_font->Render(this->title.c_str());
+ // glPopMatrix();
+ //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
#endif /** USE_FTGL */
}
-void Renderer::draw_preset()
+void
+Renderer::draw_preset()
{
#ifdef USE_FTGL
- //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
+ //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- // glPushMatrix();
- //glTranslatef(this->vw*.001,this->vh*-.01, -1);
- //glScalef(this->vw*.003,this->vh*.004,0);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ // glPushMatrix();
+ //glTranslatef(this->vw*.001,this->vh*-.01, -1);
+ //glScalef(this->vw*.003,this->vh*.004,0);
- glRasterPos2f(0.01, 0.01);
+ glRasterPos2f(0.01, 0.01);
- title_font->FaceSize((unsigned) (12 * (this->vh / 512.0)));
- if (this->noSwitch)
- title_font->Render("[LOCKED] ");
- title_font->FaceSize((unsigned) (20 * (this->vh / 512.0)));
+ title_font->FaceSize((unsigned) (12 * (this->vh / 512.0)));
+ if (this->noSwitch)
+ title_font->Render("[LOCKED] ");
+ title_font->FaceSize((unsigned) (20 * (this->vh / 512.0)));
- title_font->Render(this->presetName().c_str());
+ title_font->Render(this->presetName().c_str());
- //glPopMatrix();
- // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ //glPopMatrix();
+ // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
#endif /** USE_FTGL */
}
-void Renderer::draw_help()
+void
+Renderer::draw_help()
{
-
#ifdef USE_FTGL
- //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
+ //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glPushMatrix();
- glTranslatef(0, 1, 0);
- //glScalef(this->vw*.02,this->vh*.02 ,0);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glPushMatrix();
+ glTranslatef(0, 1, 0);
+ //glScalef(this->vw*.02,this->vh*.02 ,0);
- title_font->FaceSize((unsigned) (18 * (this->vh / 512.0)));
+ title_font->FaceSize((unsigned) (18 * (this->vh / 512.0)));
- glRasterPos2f(0.01, -0.05);
- title_font->Render("Help");
+ glRasterPos2f(0.01, -0.05);
+ title_font->Render("Help");
- glRasterPos2f(0.01, -0.09);
- title_font->Render("----------------------------");
+ glRasterPos2f(0.01, -0.09);
+ title_font->Render("----------------------------");
- glRasterPos2f(0.01, -0.13);
- title_font->Render("F1: This help menu");
+ glRasterPos2f(0.01, -0.13);
+ title_font->Render("F1: This help menu");
- glRasterPos2f(0.01, -0.17);
- title_font->Render("F2: Show song title");
+ glRasterPos2f(0.01, -0.17);
+ title_font->Render("F2: Show song title");
- glRasterPos2f(0.01, -0.21);
- title_font->Render("F3: Show preset name");
+ glRasterPos2f(0.01, -0.21);
+ title_font->Render("F3: Show preset name");
- glRasterPos2f(0.01, -0.25);
- title_font->Render("F4: Show Rendering Settings");
+ glRasterPos2f(0.01, -0.25);
+ title_font->Render("F4: Show Rendering Settings");
- glRasterPos2f(0.01, -0.29);
- title_font->Render("F5: Show FPS");
+ glRasterPos2f(0.01, -0.29);
+ title_font->Render("F5: Show FPS");
- glRasterPos2f(0.01, -0.35);
- title_font->Render("F: Fullscreen");
+ glRasterPos2f(0.01, -0.35);
+ title_font->Render("F: Fullscreen");
- glRasterPos2f(0.01, -0.39);
- title_font->Render("L: Lock/Unlock Preset");
+ glRasterPos2f(0.01, -0.39);
+ title_font->Render("L: Lock/Unlock Preset");
- glRasterPos2f(0.01, -0.43);
- title_font->Render("M: Show Menu");
+ glRasterPos2f(0.01, -0.43);
+ title_font->Render("M: Show Menu");
- glRasterPos2f(0.01, -0.49);
- title_font->Render("R: Random preset");
- glRasterPos2f(0.01, -0.53);
- title_font->Render("N: Next preset");
+ glRasterPos2f(0.01, -0.49);
+ title_font->Render("R: Random preset");
+ glRasterPos2f(0.01, -0.53);
+ title_font->Render("N: Next preset");
- glRasterPos2f(0.01, -0.57);
- title_font->Render("P: Previous preset");
+ glRasterPos2f(0.01, -0.57);
+ title_font->Render("P: Previous preset");
- glPopMatrix();
- // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glPopMatrix();
+ // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
#endif /** USE_FTGL */
}
-void Renderer::draw_stats()
+void
+Renderer::draw_stats()
{
-
#ifdef USE_FTGL
- char buffer[128];
- float offset = (this->showfps % 2 ? -0.05 : 0.0);
- // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
+ char buffer[128];
+ float offset = (this->showfps % 2 ? -0.05 : 0.0);
+ // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glPushMatrix();
- glTranslatef(0.01, 1, 0);
- glRasterPos2f(0, -.05 + offset);
- other_font->Render(this->correction ? " aspect: corrected" : " aspect: stretched");
- sprintf(buffer, " (%f)", this->aspect);
- other_font->Render(buffer);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glPushMatrix();
+ glTranslatef(0.01, 1, 0);
+ glRasterPos2f(0, -.05 + offset);
+ other_font->Render(this->correction ? " aspect: corrected" : " aspect: stretched");
+ sprintf(buffer, " (%f)", this->aspect);
+ other_font->Render(buffer);
- glRasterPos2f(0, -.09 + offset);
- other_font->FaceSize((unsigned) (18 * (vh / 512.0)));
+ glRasterPos2f(0, -.09 + offset);
+ other_font->FaceSize((unsigned) (18 * (vh / 512.0)));
- sprintf(buffer, " texsize: %d", renderTarget->texsize);
- other_font->Render(buffer);
+ sprintf(buffer, " texsize: %d", renderTarget->texsize);
+ other_font->Render(buffer);
- glRasterPos2f(0, -.13 + offset);
- sprintf(buffer, " viewport: %d x %d", vw, vh);
+ glRasterPos2f(0, -.13 + offset);
+ sprintf(buffer, " viewport: %d x %d", vw, vh);
- other_font->Render(buffer);
- glRasterPos2f(0, -.17 + offset);
- other_font->Render((renderTarget->useFBO ? " FBO: on" : " FBO: off"));
+ other_font->Render(buffer);
+ glRasterPos2f(0, -.17 + offset);
+ other_font->Render((renderTarget->useFBO ? " FBO: on" : " FBO: off"));
- glRasterPos2f(0, -.21 + offset);
- sprintf(buffer, " mesh: %d x %d", mesh.width, mesh.height);
- other_font->Render(buffer);
+ glRasterPos2f(0, -.21 + offset);
+ sprintf(buffer, " mesh: %d x %d", mesh.width, mesh.height);
+ other_font->Render(buffer);
- glRasterPos2f(0, -.25 + offset);
- sprintf(buffer, " textures: %.1fkB", textureManager->getTextureMemorySize() / 1000.0f);
- other_font->Render(buffer);
+ glRasterPos2f(0, -.25 + offset);
+ sprintf(buffer, " textures: %.1fkB", textureManager->getTextureMemorySize() / 1000.0f);
+ other_font->Render(buffer);
#ifdef USE_CG
- glRasterPos2f(0, -.29 + offset);
- sprintf(buffer, "shader profile: %s", shaderEngine.profileName.c_str());
- other_font->Render(buffer);
+ glRasterPos2f(0, -.29 + offset);
+ sprintf(buffer, "shader profile: %s", shaderEngine.profileName.c_str());
+ other_font->Render(buffer);
- glRasterPos2f(0, -.33 + offset);
- sprintf(buffer, " warp shader: %s", currentPipe->warpShader.enabled ? "on" : "off");
- other_font->Render(buffer);
+ glRasterPos2f(0, -.33 + offset);
+ sprintf(buffer, " warp shader: %s", currentPipe->warpShader.enabled ? "on" : "off");
+ other_font->Render(buffer);
- glRasterPos2f(0, -.37 + offset);
- sprintf(buffer, " comp shader: %s", currentPipe->compositeShader.enabled ? "on" : "off");
- other_font->Render(buffer);
+ glRasterPos2f(0, -.37 + offset);
+ sprintf(buffer, " comp shader: %s", currentPipe->compositeShader.enabled ? "on" : "off");
+ other_font->Render(buffer);
#endif
- glPopMatrix();
- // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-
+ glPopMatrix();
+ // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
#endif /** USE_FTGL */
}
-void Renderer::draw_fps(float realfps)
+
+void
+Renderer::draw_fps(float realfps)
{
#ifdef USE_FTGL
- char bufferfps[20];
- sprintf(bufferfps, "%.1f fps", realfps);
- // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
+ char bufferfps[20];
+ sprintf(bufferfps, "%.1f fps", realfps);
+ // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glPushMatrix();
- glTranslatef(0.01, 1, 0);
- glRasterPos2f(0, -0.05);
- title_font->FaceSize((unsigned) (20 * (this->vh / 512.0)));
- title_font->Render(bufferfps);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glPushMatrix();
+ glTranslatef(0.01, 1, 0);
+ glRasterPos2f(0, -0.05);
+ title_font->FaceSize((unsigned) (20 * (this->vh / 512.0)));
+ title_font->Render(bufferfps);
- glPopMatrix();
- // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glPopMatrix();
+ // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
#endif /** USE_FTGL */
}
-void Renderer::CompositeOutput(const Pipeline &pipeline, const PipelineContext &pipelineContext)
+void
+Renderer::CompositeOutput(const Pipeline &pipeline, const PipelineContext &pipelineContext)
{
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ //Overwrite anything on the screen
+ glBlendFunc(GL_ONE, GL_ZERO);
+ glColor4f(1.0, 1.0, 1.0, 1.0f);
- //Overwrite anything on the screen
- glBlendFunc(GL_ONE, GL_ZERO);
- glColor4f(1.0, 1.0, 1.0, 1.0f);
-
- glEnable(GL_TEXTURE_2D);
+ glEnable(GL_TEXTURE_2D);
#ifdef USE_CG
- shaderEngine.enableShader(currentPipe->compositeShader, pipeline, pipelineContext);
+ shaderEngine.enableShader(currentPipe->compositeShader, pipeline, pipelineContext);
#endif
- float tex[4][2] =
- {
- { 0, 1 },
- { 0, 0 },
- { 1, 0 },
- { 1, 1 } };
+ float tex[4][2] =
+ {
+ { 0, 1 },
+ { 0, 0 },
+ { 1, 0 },
+ { 1, 1 } };
- float points[4][2] =
- {
- { -0.5, -0.5 },
- { -0.5, 0.5 },
- { 0.5, 0.5 },
- { 0.5, -0.5 } };
+ float points[4][2] =
+ {
+ { -0.5, -0.5 },
+ { -0.5, 0.5 },
+ { 0.5, 0.5 },
+ { 0.5, -0.5 } };
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, points);
- glTexCoordPointer(2, GL_FLOAT, 0, tex);
+ glVertexPointer(2, GL_FLOAT, 0, points);
+ glTexCoordPointer(2, GL_FLOAT, 0, tex);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- glDisable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_TEXTURE_2D);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#ifdef USE_CG
- shaderEngine.disableShader();
+ shaderEngine.disableShader();
#endif
- for (std::vector<RenderItem*>::const_iterator pos = pipeline.compositeDrawables.begin(); pos
- != pipeline.compositeDrawables.end(); ++pos)
- (*pos)->Draw(renderContext);
-
+ for (std::vector<RenderItem*>::const_iterator pos = pipeline.compositeDrawables.begin();
+ pos != pipeline.compositeDrawables.end();
+ ++pos)
+ (*pos)->Draw(renderContext);
}
diff --git a/src/libprojectM/Renderer/Renderer.hpp b/src/libprojectM/Renderer/Renderer.hpp
index ea51724..6679c0c 100644
--- a/src/libprojectM/Renderer/Renderer.hpp
+++ b/src/libprojectM/Renderer/Renderer.hpp
@@ -35,13 +35,13 @@
#include "Transformation.hpp"
#include "ShaderEngine.hpp"
+
class UserTexture;
class BeatDetect;
class TextureManager;
class Renderer
{
-
public:
bool showfps;
@@ -86,7 +86,7 @@
private:
- PerPixelMesh mesh;
+ PerPixelMesh mesh;
RenderTarget *renderTarget;
BeatDetect *beatDetect;
TextureManager *textureManager;
@@ -125,7 +125,7 @@
inline static PixelPoint PerPixel(PixelPoint p, PerPixelContext &context)
{
- return currentPipe->PerPixel(p,context);
+ return currentPipe->PerPixel(p,context);
}
void rescale_per_pixel_matrices();
diff --git a/src/libprojectM/Renderer/SOIL/SOIL.c b/src/libprojectM/Renderer/SOIL/SOIL.c
index 23c145e..b128d25 100644
--- a/src/libprojectM/Renderer/SOIL/SOIL.c
+++ b/src/libprojectM/Renderer/SOIL/SOIL.c
@@ -1,2054 +1,2054 @@
-/*
- Jonathan Dummer
- 2007-07-26-10.36
-
- Simple OpenGL Image Library
-
- Public Domain
- using Sean Barret's stb_image as a base
-
- Thanks to:
- * Sean Barret - for the awesome stb_image
- * Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts
- * everybody at gamedev.net
-*/
-
-#define SOIL_CHECK_FOR_GL_ERRORS 0
-
-#ifdef WIN32
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- #include <wingdi.h>
- #include <GL/gl.h>
-#elif defined(__APPLE__) || defined(__APPLE_CC__)
- /* I can't test this Apple stuff! */
- #include <OpenGL/gl.h>
- #include <Carbon/Carbon.h>
- #define APIENTRY
-#else
- #ifdef USE_GLES1
- #include <GLES/gl.h>
- #define APIENTRY
- #else
- #include <GL/gl.h>
- #include <GL/glx.h>
- #endif
-#endif
-
-#include "SOIL.h"
-#include "stb_image_aug.h"
-#include "image_helper.h"
-#include "image_DXT.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-/* error reporting */
-char *result_string_pointer = "SOIL initialized";
-
-/* for loading cube maps */
-enum{
- SOIL_CAPABILITY_UNKNOWN = -1,
- SOIL_CAPABILITY_NONE = 0,
- SOIL_CAPABILITY_PRESENT = 1
-};
-static int has_cubemap_capability = SOIL_CAPABILITY_UNKNOWN;
-int query_cubemap_capability( void );
-#define SOIL_TEXTURE_WRAP_R 0x8072
-#define SOIL_CLAMP_TO_EDGE 0x812F
-#define SOIL_NORMAL_MAP 0x8511
-#define SOIL_REFLECTION_MAP 0x8512
-#define SOIL_TEXTURE_CUBE_MAP 0x8513
-#define SOIL_TEXTURE_BINDING_CUBE_MAP 0x8514
-#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
-#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
-#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
-#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
-#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
-#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
-#define SOIL_PROXY_TEXTURE_CUBE_MAP 0x851B
-#define SOIL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
-/* for non-power-of-two texture */
-static int has_NPOT_capability = SOIL_CAPABILITY_UNKNOWN;
-int query_NPOT_capability( void );
-/* for texture rectangles */
-static int has_tex_rectangle_capability = SOIL_CAPABILITY_UNKNOWN;
-int query_tex_rectangle_capability( void );
-#define SOIL_TEXTURE_RECTANGLE_ARB 0x84F5
-#define SOIL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
-/* for using DXT compression */
-static int has_DXT_capability = SOIL_CAPABILITY_UNKNOWN;
-int query_DXT_capability( void );
-#define SOIL_RGB_S3TC_DXT1 0x83F0
-#define SOIL_RGBA_S3TC_DXT1 0x83F1
-#define SOIL_RGBA_S3TC_DXT3 0x83F2
-#define SOIL_RGBA_S3TC_DXT5 0x83F3
-typedef void (APIENTRY * P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data);
-P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC soilGlCompressedTexImage2D = NULL;
-unsigned int SOIL_direct_load_DDS(
- const char *filename,
- unsigned int reuse_texture_ID,
- int flags,
- int loading_as_cubemap );
-unsigned int SOIL_direct_load_DDS_from_memory(
- const unsigned char *const buffer,
- int buffer_length,
- unsigned int reuse_texture_ID,
- int flags,
- int loading_as_cubemap );
-/* other functions */
-unsigned int
- SOIL_internal_create_OGL_texture
- (
- const unsigned char *const data,
- int width, int height, int channels,
- unsigned int reuse_texture_ID,
- unsigned int flags,
- unsigned int opengl_texture_type,
- unsigned int opengl_texture_target,
- unsigned int texture_check_size_enum
- );
-
-/* and the code magic begins here [8^) */
-unsigned int
- SOIL_load_OGL_texture
- (
- const char *filename,
- int force_channels,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-
-{
- int width, height;
- return SOIL_load_OGL_texture_size(filename,force_channels,reuse_texture_ID,flags,&width, &height);
-}
-
-unsigned int
- SOIL_load_OGL_texture_size
- (
- const char *filename,
- int force_channels,
- unsigned int reuse_texture_ID,
- unsigned int flags,
- int *width,
- int *height
- )
-{
- /* variables */
- unsigned char* img;
- int channels;
- unsigned int tex_id;
- /* does the user want direct uploading of the image as a DDS file? */
- if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
- {
- /* 1st try direct loading of the image as a DDS file
- note: direct uploading will only load what is in the
- DDS file, no MIPmaps will be generated, the image will
- not be flipped, etc. */
- tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 0 );
- if( tex_id )
- {
- /* hey, it worked!! */
- return tex_id;
- }
- }
- /* try to load the image */
- img = SOIL_load_image( filename, width, height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* OK, make it a texture! */
- tex_id = SOIL_internal_create_OGL_texture(
- img, *width, *height, channels,
- reuse_texture_ID, flags,
- GL_TEXTURE_2D, GL_TEXTURE_2D,
- GL_MAX_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- /* and return the handle, such as it is */
- return tex_id;
-}
-
-unsigned int
- SOIL_load_OGL_HDR_texture
- (
- const char *filename,
- int fake_HDR_format,
- int rescale_to_max,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* variables */
- unsigned char* img;
- int width, height, channels;
- unsigned int tex_id;
- /* no direct uploading of the image as a DDS file */
- /* error check */
- if( (fake_HDR_format != SOIL_HDR_RGBE) &&
- (fake_HDR_format != SOIL_HDR_RGBdivA) &&
- (fake_HDR_format != SOIL_HDR_RGBdivA2) )
- {
- result_string_pointer = "Invalid fake HDR format specified";
- return 0;
- }
- /* try to load the image (only the HDR type) */
- img = stbi_hdr_load_rgbe( filename, &width, &height, &channels, 4 );
- /* channels holds the original number of channels, which may have been forced */
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* the load worked, do I need to convert it? */
- if( fake_HDR_format == SOIL_HDR_RGBdivA )
- {
- RGBE_to_RGBdivA( img, width, height, rescale_to_max );
- } else if( fake_HDR_format == SOIL_HDR_RGBdivA2 )
- {
- RGBE_to_RGBdivA2( img, width, height, rescale_to_max );
- }
- /* OK, make it a texture! */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- reuse_texture_ID, flags,
- GL_TEXTURE_2D, GL_TEXTURE_2D,
- GL_MAX_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- /* and return the handle, such as it is */
- return tex_id;
-}
-
-unsigned int
- SOIL_load_OGL_texture_from_memory
- (
- const unsigned char *const buffer,
- int buffer_length,
- int force_channels,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* variables */
- unsigned char* img;
- int width, height, channels;
- unsigned int tex_id;
- /* does the user want direct uploading of the image as a DDS file? */
- if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
- {
- /* 1st try direct loading of the image as a DDS file
- note: direct uploading will only load what is in the
- DDS file, no MIPmaps will be generated, the image will
- not be flipped, etc. */
- tex_id = SOIL_direct_load_DDS_from_memory(
- buffer, buffer_length,
- reuse_texture_ID, flags, 0 );
- if( tex_id )
- {
- /* hey, it worked!! */
- return tex_id;
- }
- }
- /* try to load the image */
- img = SOIL_load_image_from_memory(
- buffer, buffer_length,
- &width, &height, &channels,
- force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* OK, make it a texture! */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- reuse_texture_ID, flags,
- GL_TEXTURE_2D, GL_TEXTURE_2D,
- GL_MAX_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- /* and return the handle, such as it is */
- return tex_id;
-}
-
-unsigned int
- SOIL_load_OGL_cubemap
- (
- const char *x_pos_file,
- const char *x_neg_file,
- const char *y_pos_file,
- const char *y_neg_file,
- const char *z_pos_file,
- const char *z_neg_file,
- int force_channels,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* variables */
- unsigned char* img;
- int width, height, channels;
- unsigned int tex_id;
- /* error checking */
- if( (x_pos_file == NULL) ||
- (x_neg_file == NULL) ||
- (y_pos_file == NULL) ||
- (y_neg_file == NULL) ||
- (z_pos_file == NULL) ||
- (z_neg_file == NULL) )
- {
- result_string_pointer = "Invalid cube map files list";
- return 0;
- }
- /* capability checking */
- if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
- {
- result_string_pointer = "No cube map capability present";
- return 0;
- }
- /* 1st face: try to load the image */
- img = SOIL_load_image( x_pos_file, &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, and create a texture ID if necessary */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- reuse_texture_ID, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image( x_neg_file, &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image( y_pos_file, &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image( y_neg_file, &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image( z_pos_file, &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image( z_neg_file, &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* and return the handle, such as it is */
- return tex_id;
-}
-
-unsigned int
- SOIL_load_OGL_cubemap_from_memory
- (
- const unsigned char *const x_pos_buffer,
- int x_pos_buffer_length,
- const unsigned char *const x_neg_buffer,
- int x_neg_buffer_length,
- const unsigned char *const y_pos_buffer,
- int y_pos_buffer_length,
- const unsigned char *const y_neg_buffer,
- int y_neg_buffer_length,
- const unsigned char *const z_pos_buffer,
- int z_pos_buffer_length,
- const unsigned char *const z_neg_buffer,
- int z_neg_buffer_length,
- int force_channels,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* variables */
- unsigned char* img;
- int width, height, channels;
- unsigned int tex_id;
- /* error checking */
- if( (x_pos_buffer == NULL) ||
- (x_neg_buffer == NULL) ||
- (y_pos_buffer == NULL) ||
- (y_neg_buffer == NULL) ||
- (z_pos_buffer == NULL) ||
- (z_neg_buffer == NULL) )
- {
- result_string_pointer = "Invalid cube map buffers list";
- return 0;
- }
- /* capability checking */
- if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
- {
- result_string_pointer = "No cube map capability present";
- return 0;
- }
- /* 1st face: try to load the image */
- img = SOIL_load_image_from_memory(
- x_pos_buffer, x_pos_buffer_length,
- &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, and create a texture ID if necessary */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- reuse_texture_ID, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image_from_memory(
- x_neg_buffer, x_neg_buffer_length,
- &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image_from_memory(
- y_pos_buffer, y_pos_buffer_length,
- &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image_from_memory(
- y_neg_buffer, y_neg_buffer_length,
- &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image_from_memory(
- z_pos_buffer, z_pos_buffer_length,
- &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* continue? */
- if( tex_id != 0 )
- {
- /* 1st face: try to load the image */
- img = SOIL_load_image_from_memory(
- z_neg_buffer, z_neg_buffer_length,
- &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* upload the texture, but reuse the assigned texture ID */
- tex_id = SOIL_internal_create_OGL_texture(
- img, width, height, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- /* and nuke the image data */
- SOIL_free_image_data( img );
- }
- /* and return the handle, such as it is */
- return tex_id;
-}
-
-unsigned int
- SOIL_load_OGL_single_cubemap
- (
- const char *filename,
- const char face_order[6],
- int force_channels,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* variables */
- unsigned char* img;
- int width, height, channels, i;
- unsigned int tex_id = 0;
- /* error checking */
- if( filename == NULL )
- {
- result_string_pointer = "Invalid single cube map file name";
- return 0;
- }
- /* does the user want direct uploading of the image as a DDS file? */
- if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
- {
- /* 1st try direct loading of the image as a DDS file
- note: direct uploading will only load what is in the
- DDS file, no MIPmaps will be generated, the image will
- not be flipped, etc. */
- tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 1 );
- if( tex_id )
- {
- /* hey, it worked!! */
- return tex_id;
- }
- }
- /* face order checking */
- for( i = 0; i < 6; ++i )
- {
- if( (face_order[i] != 'N') &&
- (face_order[i] != 'S') &&
- (face_order[i] != 'W') &&
- (face_order[i] != 'E') &&
- (face_order[i] != 'U') &&
- (face_order[i] != 'D') )
- {
- result_string_pointer = "Invalid single cube map face order";
- return 0;
- };
- }
- /* capability checking */
- if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
- {
- result_string_pointer = "No cube map capability present";
- return 0;
- }
- /* 1st off, try to load the full image */
- img = SOIL_load_image( filename, &width, &height, &channels, force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* now, does this image have the right dimensions? */
- if( (width != 6*height) &&
- (6*width != height) )
- {
- SOIL_free_image_data( img );
- result_string_pointer = "Single cubemap image must have a 6:1 ratio";
- return 0;
- }
- /* try the image split and create */
- tex_id = SOIL_create_OGL_single_cubemap(
- img, width, height, channels,
- face_order, reuse_texture_ID, flags
- );
- /* nuke the temporary image data and return the texture handle */
- SOIL_free_image_data( img );
- return tex_id;
-}
-
-unsigned int
- SOIL_load_OGL_single_cubemap_from_memory
- (
- const unsigned char *const buffer,
- int buffer_length,
- const char face_order[6],
- int force_channels,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* variables */
- unsigned char* img;
- int width, height, channels, i;
- unsigned int tex_id = 0;
- /* error checking */
- if( buffer == NULL )
- {
- result_string_pointer = "Invalid single cube map buffer";
- return 0;
- }
- /* does the user want direct uploading of the image as a DDS file? */
- if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
- {
- /* 1st try direct loading of the image as a DDS file
- note: direct uploading will only load what is in the
- DDS file, no MIPmaps will be generated, the image will
- not be flipped, etc. */
- tex_id = SOIL_direct_load_DDS_from_memory(
- buffer, buffer_length,
- reuse_texture_ID, flags, 1 );
- if( tex_id )
- {
- /* hey, it worked!! */
- return tex_id;
- }
- }
- /* face order checking */
- for( i = 0; i < 6; ++i )
- {
- if( (face_order[i] != 'N') &&
- (face_order[i] != 'S') &&
- (face_order[i] != 'W') &&
- (face_order[i] != 'E') &&
- (face_order[i] != 'U') &&
- (face_order[i] != 'D') )
- {
- result_string_pointer = "Invalid single cube map face order";
- return 0;
- };
- }
- /* capability checking */
- if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
- {
- result_string_pointer = "No cube map capability present";
- return 0;
- }
- /* 1st off, try to load the full image */
- img = SOIL_load_image_from_memory(
- buffer, buffer_length,
- &width, &height, &channels,
- force_channels );
- /* channels holds the original number of channels, which may have been forced */
- if( (force_channels >= 1) && (force_channels <= 4) )
- {
- channels = force_channels;
- }
- if( NULL == img )
- {
- /* image loading failed */
- result_string_pointer = stbi_failure_reason();
- return 0;
- }
- /* now, does this image have the right dimensions? */
- if( (width != 6*height) &&
- (6*width != height) )
- {
- SOIL_free_image_data( img );
- result_string_pointer = "Single cubemap image must have a 6:1 ratio";
- return 0;
- }
- /* try the image split and create */
- tex_id = SOIL_create_OGL_single_cubemap(
- img, width, height, channels,
- face_order, reuse_texture_ID, flags
- );
- /* nuke the temporary image data and return the texture handle */
- SOIL_free_image_data( img );
- return tex_id;
-}
-
-unsigned int
- SOIL_create_OGL_single_cubemap
- (
- const unsigned char *const data,
- int width, int height, int channels,
- const char face_order[6],
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* variables */
- unsigned char* sub_img;
- int dw, dh, sz, i;
- unsigned int tex_id;
- /* error checking */
- if( data == NULL )
- {
- result_string_pointer = "Invalid single cube map image data";
- return 0;
- }
- /* face order checking */
- for( i = 0; i < 6; ++i )
- {
- if( (face_order[i] != 'N') &&
- (face_order[i] != 'S') &&
- (face_order[i] != 'W') &&
- (face_order[i] != 'E') &&
- (face_order[i] != 'U') &&
- (face_order[i] != 'D') )
- {
- result_string_pointer = "Invalid single cube map face order";
- return 0;
- };
- }
- /* capability checking */
- if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
- {
- result_string_pointer = "No cube map capability present";
- return 0;
- }
- /* now, does this image have the right dimensions? */
- if( (width != 6*height) &&
- (6*width != height) )
- {
- result_string_pointer = "Single cubemap image must have a 6:1 ratio";
- return 0;
- }
- /* which way am I stepping? */
- if( width > height )
- {
- dw = height;
- dh = 0;
- } else
- {
- dw = 0;
- dh = width;
- }
- sz = dw+dh;
- sub_img = (unsigned char *)malloc( sz*sz*channels );
- /* do the splitting and uploading */
- tex_id = reuse_texture_ID;
- for( i = 0; i < 6; ++i )
- {
- int x, y, idx = 0;
- unsigned int cubemap_target = 0;
- /* copy in the sub-image */
- for( y = i*dh; y < i*dh+sz; ++y )
- {
- for( x = i*dw*channels; x < (i*dw+sz)*channels; ++x )
- {
- sub_img[idx++] = data[y*width*channels+x];
- }
- }
- /* what is my texture target?
- remember, this coordinate system is
- LHS if viewed from inside the cube! */
- switch( face_order[i] )
- {
- case 'N':
- cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z;
- break;
- case 'S':
- cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
- break;
- case 'W':
- cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X;
- break;
- case 'E':
- cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_X;
- break;
- case 'U':
- cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y;
- break;
- case 'D':
- cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
- break;
- }
- /* upload it as a texture */
- tex_id = SOIL_internal_create_OGL_texture(
- sub_img, sz, sz, channels,
- tex_id, flags,
- SOIL_TEXTURE_CUBE_MAP,
- cubemap_target,
- SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
- }
- /* and nuke the image and sub-image data */
- SOIL_free_image_data( sub_img );
- /* and return the handle, such as it is */
- return tex_id;
-}
-
-unsigned int
- SOIL_create_OGL_texture
- (
- const unsigned char *const data,
- int width, int height, int channels,
- unsigned int reuse_texture_ID,
- unsigned int flags
- )
-{
- /* wrapper function for 2D textures */
- return SOIL_internal_create_OGL_texture(
- data, width, height, channels,
- reuse_texture_ID, flags,
- GL_TEXTURE_2D, GL_TEXTURE_2D,
- GL_MAX_TEXTURE_SIZE );
-}
-
-#if SOIL_CHECK_FOR_GL_ERRORS
-void check_for_GL_errors( const char *calling_location )
-{
- /* check for errors */
- GLenum err_code = glGetError();
- while( GL_NO_ERROR != err_code )
- {
- printf( "OpenGL Error @ %s: %i", calling_location, err_code );
- err_code = glGetError();
- }
-}
-#else
-void check_for_GL_errors( const char *calling_location )
-{
- /* no check for errors */
-}
-#endif
-
-unsigned int
- SOIL_internal_create_OGL_texture
- (
- const unsigned char *const data,
- int width, int height, int channels,
- unsigned int reuse_texture_ID,
- unsigned int flags,
- unsigned int opengl_texture_type,
- unsigned int opengl_texture_target,
- unsigned int texture_check_size_enum
- )
-{
- /* variables */
- unsigned char* img;
- unsigned int tex_id;
- unsigned int internal_texture_format = 0, original_texture_format = 0;
- int DXT_mode = SOIL_CAPABILITY_UNKNOWN;
- int max_supported_size;
- /* If the user wants to use the texture rectangle I kill a few flags */
- if( flags & SOIL_FLAG_TEXTURE_RECTANGLE )
- {
- /* well, the user asked for it, can we do that? */
- if( query_tex_rectangle_capability() == SOIL_CAPABILITY_PRESENT )
- {
- /* only allow this if the user in _NOT_ trying to do a cubemap! */
- if( opengl_texture_type == GL_TEXTURE_2D )
- {
- /* clean out the flags that cannot be used with texture rectangles */
- flags &= ~(
- SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS |
- SOIL_FLAG_TEXTURE_REPEATS
- );
- /* and change my target */
- opengl_texture_target = SOIL_TEXTURE_RECTANGLE_ARB;
- opengl_texture_type = SOIL_TEXTURE_RECTANGLE_ARB;
- } else
- {
- /* not allowed for any other uses (yes, I'm looking at you, cubemaps!) */
- flags &= ~SOIL_FLAG_TEXTURE_RECTANGLE;
- }
-
- } else
- {
- /* can't do it, and that is a breakable offense (uv coords use pixels instead of [0,1]!) */
- result_string_pointer = "Texture Rectangle extension unsupported";
- return 0;
- }
- }
- /* create a copy the image data */
- img = (unsigned char*)malloc( width*height*channels );
- memcpy( img, data, width*height*channels );
- /* does the user want me to invert the image? */
- if( flags & SOIL_FLAG_INVERT_Y )
- {
- int i, j;
- for( j = 0; j*2 < height; ++j )
- {
- int index1 = j * width * channels;
- int index2 = (height - 1 - j) * width * channels;
- for( i = width * channels; i > 0; --i )
- {
- unsigned char temp = img[index1];
- img[index1] = img[index2];
- img[index2] = temp;
- ++index1;
- ++index2;
- }
- }
- }
- /* does the user want me to scale the colors into the NTSC safe RGB range? */
- if( flags & SOIL_FLAG_NTSC_SAFE_RGB )
- {
- scale_image_RGB_to_NTSC_safe( img, width, height, channels );
- }
- /* does the user want me to convert from straight to pre-multiplied alpha?
- (and do we even _have_ alpha?) */
- if( flags & SOIL_FLAG_MULTIPLY_ALPHA )
- {
- int i;
- switch( channels )
- {
- case 2:
- for( i = 0; i < 2*width*height; i += 2 )
- {
- img[i] = (img[i] * img[i+1] + 128) >> 8;
- }
- break;
- case 4:
- for( i = 0; i < 4*width*height; i += 4 )
- {
- img[i+0] = (img[i+0] * img[i+3] + 128) >> 8;
- img[i+1] = (img[i+1] * img[i+3] + 128) >> 8;
- img[i+2] = (img[i+2] * img[i+3] + 128) >> 8;
- }
- break;
- default:
- /* no other number of channels contains alpha data */
- break;
- }
- }
- /* if the user can't support NPOT textures, make sure we force the POT option */
- if( (query_NPOT_capability() == SOIL_CAPABILITY_NONE) &&
- !(flags & SOIL_FLAG_TEXTURE_RECTANGLE) )
- {
- /* add in the POT flag */
- flags |= SOIL_FLAG_POWER_OF_TWO;
- }
- /* how large of a texture can this OpenGL implementation handle? */
- /* texture_check_size_enum will be GL_MAX_TEXTURE_SIZE or SOIL_MAX_CUBE_MAP_TEXTURE_SIZE */
- glGetIntegerv( texture_check_size_enum, &max_supported_size );
- /* do I need to make it a power of 2? */
- if(
- (flags & SOIL_FLAG_POWER_OF_TWO) || /* user asked for it */
- (flags & SOIL_FLAG_MIPMAPS) || /* need it for the MIP-maps */
- (width > max_supported_size) || /* it's too big, (make sure it's */
- (height > max_supported_size) ) /* 2^n for later down-sampling) */
- {
- int new_width = 1;
- int new_height = 1;
- while( new_width < width )
- {
- new_width *= 2;
- }
- while( new_height < height )
- {
- new_height *= 2;
- }
- /* still? */
- if( (new_width != width) || (new_height != height) )
- {
- /* yep, resize */
- unsigned char *resampled = (unsigned char*)malloc( channels*new_width*new_height );
- up_scale_image(
- img, width, height, channels,
- resampled, new_width, new_height );
- /* OJO this is for debug only! */
- /*
- SOIL_save_image( "\\showme.bmp", SOIL_SAVE_TYPE_BMP,
- new_width, new_height, channels,
- resampled );
- */
- /* nuke the old guy, then point it at the new guy */
- SOIL_free_image_data( img );
- img = resampled;
- width = new_width;
- height = new_height;
- }
- }
- /* now, if it is too large... */
- if( (width > max_supported_size) || (height > max_supported_size) )
- {
- /* I've already made it a power of two, so simply use the MIPmapping
- code to reduce its size to the allowable maximum. */
- unsigned char *resampled;
- int reduce_block_x = 1, reduce_block_y = 1;
- int new_width, new_height;
- if( width > max_supported_size )
- {
- reduce_block_x = width / max_supported_size;
- }
- if( height > max_supported_size )
- {
- reduce_block_y = height / max_supported_size;
- }
- new_width = width / reduce_block_x;
- new_height = height / reduce_block_y;
- resampled = (unsigned char*)malloc( channels*new_width*new_height );
- /* perform the actual reduction */
- mipmap_image( img, width, height, channels,
- resampled, reduce_block_x, reduce_block_y );
- /* nuke the old guy, then point it at the new guy */
- SOIL_free_image_data( img );
- img = resampled;
- width = new_width;
- height = new_height;
- }
- /* does the user want us to use YCoCg color space? */
- if( flags & SOIL_FLAG_CoCg_Y )
- {
- /* this will only work with RGB and RGBA images */
- convert_RGB_to_YCoCg( img, width, height, channels );
- /*
- save_image_as_DDS( "CoCg_Y.dds", width, height, channels, img );
- */
- }
- /* create the OpenGL texture ID handle
- (note: allowing a forced texture ID lets me reload a texture) */
- tex_id = reuse_texture_ID;
- if( tex_id == 0 )
- {
- glGenTextures( 1, &tex_id );
- }
- check_for_GL_errors( "glGenTextures" );
- /* Note: sometimes glGenTextures fails (usually no OpenGL context) */
- if( tex_id )
- {
- /* and what type am I using as the internal texture format? */
- switch( channels )
- {
- case 1:
- original_texture_format = GL_LUMINANCE;
- break;
- case 2:
- original_texture_format = GL_LUMINANCE_ALPHA;
- break;
- case 3:
- original_texture_format = GL_RGB;
- break;
- case 4:
- original_texture_format = GL_RGBA;
- break;
- }
- internal_texture_format = original_texture_format;
- /* does the user want me to, and can I, save as DXT? */
- if( flags & SOIL_FLAG_COMPRESS_TO_DXT )
- {
- DXT_mode = query_DXT_capability();
- if( DXT_mode == SOIL_CAPABILITY_PRESENT )
- {
- /* I can use DXT, whether I compress it or OpenGL does */
- if( (channels & 1) == 1 )
- {
- /* 1 or 3 channels = DXT1 */
- internal_texture_format = SOIL_RGB_S3TC_DXT1;
- } else
- {
- /* 2 or 4 channels = DXT5 */
- internal_texture_format = SOIL_RGBA_S3TC_DXT5;
- }
- }
- }
- /* bind an OpenGL texture ID */
- glBindTexture( opengl_texture_type, tex_id );
- check_for_GL_errors( "glBindTexture" );
- /* upload the main image */
- if( DXT_mode == SOIL_CAPABILITY_PRESENT )
- {
- /* user wants me to do the DXT conversion! */
- int DDS_size;
- unsigned char *DDS_data = NULL;
- if( (channels & 1) == 1 )
- {
- /* RGB, use DXT1 */
- DDS_data = convert_image_to_DXT1( img, width, height, channels, &DDS_size );
- } else
- {
- /* RGBA, use DXT5 */
- DDS_data = convert_image_to_DXT5( img, width, height, channels, &DDS_size );
- }
- if( DDS_data )
- {
- soilGlCompressedTexImage2D(
- opengl_texture_target, 0,
- internal_texture_format, width, height, 0,
- DDS_size, DDS_data );
- check_for_GL_errors( "glCompressedTexImage2D" );
- SOIL_free_image_data( DDS_data );
- /* printf( "Internal DXT compressor\n" ); */
- } else
- {
- /* my compression failed, try the OpenGL driver's version */
- glTexImage2D(
- opengl_texture_target, 0,
- internal_texture_format, width, height, 0,
- original_texture_format, GL_UNSIGNED_BYTE, img );
- check_for_GL_errors( "glTexImage2D" );
- /* printf( "OpenGL DXT compressor\n" ); */
- }
- } else
- {
- /* user want OpenGL to do all the work! */
- glTexImage2D(
- opengl_texture_target, 0,
- internal_texture_format, width, height, 0,
- original_texture_format, GL_UNSIGNED_BYTE, img );
- check_for_GL_errors( "glTexImage2D" );
- /*printf( "OpenGL DXT compressor\n" ); */
- }
- /* are any MIPmaps desired? */
- if( flags & SOIL_FLAG_MIPMAPS )
- {
- int MIPlevel = 1;
- int MIPwidth = (width+1) / 2;
- int MIPheight = (height+1) / 2;
- unsigned char *resampled = (unsigned char*)malloc( channels*MIPwidth*MIPheight );
- while( ((1<<MIPlevel) <= width) || ((1<<MIPlevel) <= height) )
- {
- /* do this MIPmap level */
- mipmap_image(
- img, width, height, channels,
- resampled,
- (1 << MIPlevel), (1 << MIPlevel) );
- /* upload the MIPmaps */
- if( DXT_mode == SOIL_CAPABILITY_PRESENT )
- {
- /* user wants me to do the DXT conversion! */
- int DDS_size;
- unsigned char *DDS_data = NULL;
- if( (channels & 1) == 1 )
- {
- /* RGB, use DXT1 */
- DDS_data = convert_image_to_DXT1(
- resampled, MIPwidth, MIPheight, channels, &DDS_size );
- } else
- {
- /* RGBA, use DXT5 */
- DDS_data = convert_image_to_DXT5(
- resampled, MIPwidth, MIPheight, channels, &DDS_size );
- }
- if( DDS_data )
- {
- soilGlCompressedTexImage2D(
- opengl_texture_target, MIPlevel,
- internal_texture_format, MIPwidth, MIPheight, 0,
- DDS_size, DDS_data );
- check_for_GL_errors( "glCompressedTexImage2D" );
- SOIL_free_image_data( DDS_data );
- } else
- {
- /* my compression failed, try the OpenGL driver's version */
- glTexImage2D(
- opengl_texture_target, MIPlevel,
- internal_texture_format, MIPwidth, MIPheight, 0,
- original_texture_format, GL_UNSIGNED_BYTE, resampled );
- check_for_GL_errors( "glTexImage2D" );
- }
- } else
- {
- /* user want OpenGL to do all the work! */
- glTexImage2D(
- opengl_texture_target, MIPlevel,
- internal_texture_format, MIPwidth, MIPheight, 0,
- original_texture_format, GL_UNSIGNED_BYTE, resampled );
- check_for_GL_errors( "glTexImage2D" );
- }
- /* prep for the next level */
- ++MIPlevel;
- MIPwidth = (MIPwidth + 1) / 2;
- MIPheight = (MIPheight + 1) / 2;
- }
- SOIL_free_image_data( resampled );
- /* instruct OpenGL to use the MIPmaps */
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
- check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" );
- } else
- {
- /* instruct OpenGL _NOT_ to use the MIPmaps */
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" );
- }
- /* does the user want clamping, or wrapping? */
- if( flags & SOIL_FLAG_TEXTURE_REPEATS )
- {
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT );
- if( opengl_texture_type == SOIL_TEXTURE_CUBE_MAP )
- {
- /* SOIL_TEXTURE_WRAP_R is invalid if cubemaps aren't supported */
- glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT );
- }
- check_for_GL_errors( "GL_TEXTURE_WRAP_*" );
- } else
- {
- /* unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; */
- unsigned int clamp_mode = GL_CLAMP_TO_EDGE;
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode );
- if( opengl_texture_type == SOIL_TEXTURE_CUBE_MAP )
- {
- /* SOIL_TEXTURE_WRAP_R is invalid if cubemaps aren't supported */
- glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode );
- }
- check_for_GL_errors( "GL_TEXTURE_WRAP_*" );
- }
- /* done */
- result_string_pointer = "Image loaded as an OpenGL texture";
- } else
- {
- /* failed */
- result_string_pointer = "Failed to generate an OpenGL texture name; missing OpenGL context?";
- }
- SOIL_free_image_data( img );
- return tex_id;
-}
-
-int
- SOIL_save_screenshot
- (
- const char *filename,
- int image_type,
- int x, int y,
- int width, int height
- )
-{
- unsigned char *pixel_data;
- int i, j;
- int save_result;
-
- /* error checks */
- if( (width < 1) || (height < 1) )
- {
- result_string_pointer = "Invalid screenshot dimensions";
- return 0;
- }
- if( (x < 0) || (y < 0) )
- {
- result_string_pointer = "Invalid screenshot location";
- return 0;
- }
- if( filename == NULL )
- {
- result_string_pointer = "Invalid screenshot filename";
- return 0;
- }
-
- /* Get the data from OpenGL */
- pixel_data = (unsigned char*)malloc( 3*width*height );
- glReadPixels (x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixel_data);
-
- /* invert the image */
- for( j = 0; j*2 < height; ++j )
- {
- int index1 = j * width * 3;
- int index2 = (height - 1 - j) * width * 3;
- for( i = width * 3; i > 0; --i )
- {
- unsigned char temp = pixel_data[index1];
- pixel_data[index1] = pixel_data[index2];
- pixel_data[index2] = temp;
- ++index1;
- ++index2;
- }
- }
-
- /* save the image */
- save_result = SOIL_save_image( filename, image_type, width, height, 3, pixel_data);
-
- /* And free the memory */
- SOIL_free_image_data( pixel_data );
- return save_result;
-}
-
-unsigned char*
- SOIL_load_image
- (
- const char *filename,
- int *width, int *height, int *channels,
- int force_channels
- )
-{
- unsigned char *result = stbi_load( filename,
- width, height, channels, force_channels );
- if( result == NULL )
- {
- result_string_pointer = stbi_failure_reason();
- } else
- {
- result_string_pointer = "Image loaded";
- }
- return result;
-}
-
-unsigned char*
- SOIL_load_image_from_memory
- (
- const unsigned char *const buffer,
- int buffer_length,
- int *width, int *height, int *channels,
- int force_channels
- )
-{
- unsigned char *result = stbi_load_from_memory(
- buffer, buffer_length,
- width, height, channels,
- force_channels );
- if( result == NULL )
- {
- result_string_pointer = stbi_failure_reason();
- } else
- {
- result_string_pointer = "Image loaded from memory";
- }
- return result;
-}
-
-int
- SOIL_save_image
- (
- const char *filename,
- int image_type,
- int width, int height, int channels,
- const unsigned char *const data
- )
-{
- int save_result;
-
- /* error check */
- if( (width < 1) || (height < 1) ||
- (channels < 1) || (channels > 4) ||
- (data == NULL) ||
- (filename == NULL) )
- {
- return 0;
- }
- if( image_type == SOIL_SAVE_TYPE_BMP )
- {
- save_result = stbi_write_bmp( filename,
- width, height, channels, (void*)data );
- } else
- if( image_type == SOIL_SAVE_TYPE_TGA )
- {
- save_result = stbi_write_tga( filename,
- width, height, channels, (void*)data );
- } else
- if( image_type == SOIL_SAVE_TYPE_DDS )
- {
- save_result = save_image_as_DDS( filename,
- width, height, channels, (const unsigned char *const)data );
- } else
- {
- save_result = 0;
- }
- if( save_result == 0 )
- {
- result_string_pointer = "Saving the image failed";
- } else
- {
- result_string_pointer = "Image saved";
- }
- return save_result;
-}
-
-void
- SOIL_free_image_data
- (
- unsigned char *img_data
- )
-{
- free( (void*)img_data );
-}
-
-const char*
- SOIL_last_result
- (
- void
- )
-{
- return result_string_pointer;
-}
-
-unsigned int SOIL_direct_load_DDS_from_memory(
- const unsigned char *const buffer,
- int buffer_length,
- unsigned int reuse_texture_ID,
- int flags,
- int loading_as_cubemap )
-{
- /* variables */
- DDS_header header;
- unsigned int buffer_index = 0;
- unsigned int tex_ID = 0;
- /* file reading variables */
- unsigned int S3TC_type = 0;
- unsigned char *DDS_data;
- unsigned int DDS_main_size;
- unsigned int DDS_full_size;
- unsigned int width, height;
- int mipmaps, cubemap, uncompressed, block_size = 16;
- unsigned int flag;
- unsigned int cf_target, ogl_target_start, ogl_target_end;
- unsigned int opengl_texture_type;
- int i;
- /* 1st off, does the filename even exist? */
- if( NULL == buffer )
- {
- /* we can't do it! */
- result_string_pointer = "NULL buffer";
- return 0;
- }
- if( buffer_length < sizeof( DDS_header ) )
- {
- /* we can't do it! */
- result_string_pointer = "DDS file was too small to contain the DDS header";
- return 0;
- }
- /* try reading in the header */
- memcpy ( (void*)(&header), (const void *)buffer, sizeof( DDS_header ) );
- buffer_index = sizeof( DDS_header );
- /* guilty until proven innocent */
- result_string_pointer = "Failed to read a known DDS header";
- /* validate the header (warning, "goto"'s ahead, shield your eyes!!) */
- flag = ('D'<<0)|('D'<<8)|('S'<<16)|(' '<<24);
- if( header.dwMagic != flag ) {goto quick_exit;}
- if( header.dwSize != 124 ) {goto quick_exit;}
- /* I need all of these */
- flag = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
- if( (header.dwFlags & flag) != flag ) {goto quick_exit;}
- /* According to the MSDN spec, the dwFlags should contain
- DDSD_LINEARSIZE if it's compressed, or DDSD_PITCH if
- uncompressed. Some DDS writers do not conform to the
- spec, so I need to make my reader more tolerant */
- /* I need one of these */
- flag = DDPF_FOURCC | DDPF_RGB;
- if( (header.sPixelFormat.dwFlags & flag) == 0 ) {goto quick_exit;}
- if( header.sPixelFormat.dwSize != 32 ) {goto quick_exit;}
- if( (header.sCaps.dwCaps1 & DDSCAPS_TEXTURE) == 0 ) {goto quick_exit;}
- /* make sure it is a type we can upload */
- if( (header.sPixelFormat.dwFlags & DDPF_FOURCC) &&
- !(
- (header.sPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('1'<<24))) ||
- (header.sPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('3'<<24))) ||
- (header.sPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('5'<<24)))
- ) )
- {
- goto quick_exit;
- }
- /* OK, validated the header, let's load the image data */
- result_string_pointer = "DDS header loaded and validated";
- width = header.dwWidth;
- height = header.dwHeight;
- uncompressed = 1 - (header.sPixelFormat.dwFlags & DDPF_FOURCC) / DDPF_FOURCC;
- cubemap = (header.sCaps.dwCaps2 & DDSCAPS2_CUBEMAP) / DDSCAPS2_CUBEMAP;
- if( uncompressed )
- {
- S3TC_type = GL_RGB;
- block_size = 3;
- if( header.sPixelFormat.dwFlags & DDPF_ALPHAPIXELS )
- {
- S3TC_type = GL_RGBA;
- block_size = 4;
- }
- DDS_main_size = width * height * block_size;
- } else
- {
- /* can we even handle direct uploading to OpenGL DXT compressed images? */
- if( query_DXT_capability() != SOIL_CAPABILITY_PRESENT )
- {
- /* we can't do it! */
- result_string_pointer = "Direct upload of S3TC images not supported by the OpenGL driver";
- return 0;
- }
- /* well, we know it is DXT1/3/5, because we checked above */
- switch( (header.sPixelFormat.dwFourCC >> 24) - '0' )
- {
- case 1:
- S3TC_type = SOIL_RGBA_S3TC_DXT1;
- block_size = 8;
- break;
- case 3:
- S3TC_type = SOIL_RGBA_S3TC_DXT3;
- block_size = 16;
- break;
- case 5:
- S3TC_type = SOIL_RGBA_S3TC_DXT5;
- block_size = 16;
- break;
- }
- DDS_main_size = ((width+3)>>2)*((height+3)>>2)*block_size;
- }
- if( cubemap )
- {
- /* does the user want a cubemap? */
- if( !loading_as_cubemap )
- {
- /* we can't do it! */
- result_string_pointer = "DDS image was a cubemap";
- return 0;
- }
- /* can we even handle cubemaps with the OpenGL driver? */
- if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
- {
- /* we can't do it! */
- result_string_pointer = "Direct upload of cubemap images not supported by the OpenGL driver";
- return 0;
- }
- ogl_target_start = SOIL_TEXTURE_CUBE_MAP_POSITIVE_X;
- ogl_target_end = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
- opengl_texture_type = SOIL_TEXTURE_CUBE_MAP;
- } else
- {
- /* does the user want a non-cubemap? */
- if( loading_as_cubemap )
- {
- /* we can't do it! */
- result_string_pointer = "DDS image was not a cubemap";
- return 0;
- }
- ogl_target_start = GL_TEXTURE_2D;
- ogl_target_end = GL_TEXTURE_2D;
- opengl_texture_type = GL_TEXTURE_2D;
- }
- if( (header.sCaps.dwCaps1 & DDSCAPS_MIPMAP) && (header.dwMipMapCount > 1) )
- {
- int shift_offset;
- mipmaps = header.dwMipMapCount - 1;
- DDS_full_size = DDS_main_size;
- if( uncompressed )
- {
- /* uncompressed DDS, simple MIPmap size calculation */
- shift_offset = 0;
- } else
- {
- /* compressed DDS, MIPmap size calculation is block based */
- shift_offset = 2;
- }
- for( i = 1; i <= mipmaps; ++ i )
- {
- int w, h;
- w = width >> (shift_offset + i);
- h = height >> (shift_offset + i);
- if( w < 1 )
- {
- w = 1;
- }
- if( h < 1 )
- {
- h = 1;
- }
- DDS_full_size += w*h*block_size;
- }
- } else
- {
- mipmaps = 0;
- DDS_full_size = DDS_main_size;
- }
- DDS_data = (unsigned char*)malloc( DDS_full_size );
- /* got the image data RAM, create or use an existing OpenGL texture handle */
- tex_ID = reuse_texture_ID;
- if( tex_ID == 0 )
- {
- glGenTextures( 1, &tex_ID );
- }
- /* bind an OpenGL texture ID */
- glBindTexture( opengl_texture_type, tex_ID );
- /* do this for each face of the cubemap! */
- for( cf_target = ogl_target_start; cf_target <= ogl_target_end; ++cf_target )
- {
- if( buffer_index + DDS_full_size <= buffer_length )
- {
- unsigned int byte_offset = DDS_main_size;
- memcpy( (void*)DDS_data, (const void*)(&buffer[buffer_index]), DDS_full_size );
- buffer_index += DDS_full_size;
- /* upload the main chunk */
- if( uncompressed )
- {
- /* and remember, DXT uncompressed uses BGR(A),
- so swap to RGB(A) for ALL MIPmap levels */
- for( i = 0; i < DDS_full_size; i += block_size )
- {
- unsigned char temp = DDS_data[i];
- DDS_data[i] = DDS_data[i+2];
- DDS_data[i+2] = temp;
- }
- glTexImage2D(
- cf_target, 0,
- S3TC_type, width, height, 0,
- S3TC_type, GL_UNSIGNED_BYTE, DDS_data );
- } else
- {
- soilGlCompressedTexImage2D(
- cf_target, 0,
- S3TC_type, width, height, 0,
- DDS_main_size, DDS_data );
- }
- /* upload the mipmaps, if we have them */
- for( i = 1; i <= mipmaps; ++i )
- {
- int w, h, mip_size;
- w = width >> i;
- h = height >> i;
- if( w < 1 )
- {
- w = 1;
- }
- if( h < 1 )
- {
- h = 1;
- }
- /* upload this mipmap */
- if( uncompressed )
- {
- mip_size = w*h*block_size;
- glTexImage2D(
- cf_target, i,
- S3TC_type, w, h, 0,
- S3TC_type, GL_UNSIGNED_BYTE, &DDS_data[byte_offset] );
- } else
- {
- mip_size = ((w+3)/4)*((h+3)/4)*block_size;
- soilGlCompressedTexImage2D(
- cf_target, i,
- S3TC_type, w, h, 0,
- mip_size, &DDS_data[byte_offset] );
- }
- /* and move to the next mipmap */
- byte_offset += mip_size;
- }
- /* it worked! */
- result_string_pointer = "DDS file loaded";
- } else
- {
- glDeleteTextures( 1, & tex_ID );
- tex_ID = 0;
- cf_target = ogl_target_end + 1;
- result_string_pointer = "DDS file was too small for expected image data";
- }
- }/* end reading each face */
- SOIL_free_image_data( DDS_data );
- if( tex_ID )
- {
- /* did I have MIPmaps? */
- if( mipmaps > 0 )
- {
- /* instruct OpenGL to use the MIPmaps */
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
- } else
- {
- /* instruct OpenGL _NOT_ to use the MIPmaps */
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- }
- /* does the user want clamping, or wrapping? */
- if( flags & SOIL_FLAG_TEXTURE_REPEATS )
- {
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT );
- glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT );
- } else
- {
- /* unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; */
- unsigned int clamp_mode = GL_CLAMP_TO_EDGE;
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode );
- glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode );
- glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode );
- }
- }
-
-quick_exit:
- /* report success or failure */
- return tex_ID;
-}
-
-unsigned int SOIL_direct_load_DDS(
- const char *filename,
- unsigned int reuse_texture_ID,
- int flags,
- int loading_as_cubemap )
-{
- FILE *f;
- unsigned char *buffer;
- size_t buffer_length, bytes_read;
- unsigned int tex_ID = 0;
- /* error checks */
- if( NULL == filename )
- {
- result_string_pointer = "NULL filename";
- return 0;
- }
- f = fopen( filename, "rb" );
- if( NULL == f )
- {
- /* the file doesn't seem to exist (or be open-able) */
- result_string_pointer = "Can not find DDS file";
- return 0;
- }
- fseek( f, 0, SEEK_END );
- buffer_length = ftell( f );
- fseek( f, 0, SEEK_SET );
- buffer = (unsigned char *) malloc( buffer_length );
- if( NULL == buffer )
- {
- result_string_pointer = "malloc failed";
- fclose( f );
- return 0;
- }
- bytes_read = fread( (void*)buffer, 1, buffer_length, f );
- fclose( f );
- if( bytes_read < buffer_length )
- {
- /* huh? */
- buffer_length = bytes_read;
- }
- /* now try to do the loading */
- tex_ID = SOIL_direct_load_DDS_from_memory(
- (const unsigned char *const)buffer, buffer_length,
- reuse_texture_ID, flags, loading_as_cubemap );
- SOIL_free_image_data( buffer );
- return tex_ID;
-}
-
-int query_NPOT_capability( void )
-{
- /* check for the capability */
- if( has_NPOT_capability == SOIL_CAPABILITY_UNKNOWN )
- {
- /* we haven't yet checked for the capability, do so */
- if(
- (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
- "GL_ARB_texture_non_power_of_two" ) )
- )
- {
- /* not there, flag the failure */
- has_NPOT_capability = SOIL_CAPABILITY_NONE;
- } else
- {
- /* it's there! */
- has_NPOT_capability = SOIL_CAPABILITY_PRESENT;
- }
- }
- /* let the user know if we can do non-power-of-two textures or not */
- return has_NPOT_capability;
-}
-
-int query_tex_rectangle_capability( void )
-{
- /* check for the capability */
- if( has_tex_rectangle_capability == SOIL_CAPABILITY_UNKNOWN )
- {
- /* we haven't yet checked for the capability, do so */
- if(
- (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
- "GL_ARB_texture_rectangle" ) )
- &&
- (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
- "GL_EXT_texture_rectangle" ) )
- &&
- (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
- "GL_NV_texture_rectangle" ) )
- )
- {
- /* not there, flag the failure */
- has_tex_rectangle_capability = SOIL_CAPABILITY_NONE;
- } else
- {
- /* it's there! */
- has_tex_rectangle_capability = SOIL_CAPABILITY_PRESENT;
- }
- }
- /* let the user know if we can do texture rectangles or not */
- return has_tex_rectangle_capability;
-}
-
-int query_cubemap_capability( void )
-{
- /* check for the capability */
- if( has_cubemap_capability == SOIL_CAPABILITY_UNKNOWN )
- {
- /* we haven't yet checked for the capability, do so */
- if(
- (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
- "GL_ARB_texture_cube_map" ) )
- &&
- (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
- "GL_EXT_texture_cube_map" ) )
- )
- {
- /* not there, flag the failure */
- has_cubemap_capability = SOIL_CAPABILITY_NONE;
- } else
- {
- /* it's there! */
- has_cubemap_capability = SOIL_CAPABILITY_PRESENT;
- }
- }
- /* let the user know if we can do cubemaps or not */
- return has_cubemap_capability;
-}
-
-int query_DXT_capability( void )
-{
-#ifdef USE_GLES1
- /*
- * GLES1 has no S3-style texture compression extension.
- * GLES2 has GL_EXT_texture_compression_dxt1 available which only supports,
- * obviously enough, DXT1 compression.
- */
- has_DXT_capability = SOIL_CAPABILITY_NONE;
-#else
- /* check for the capability */
- if( has_DXT_capability == SOIL_CAPABILITY_UNKNOWN )
- {
- /* we haven't yet checked for the capability, do so */
- if( NULL == strstr(
- (char const*)glGetString( GL_EXTENSIONS ),
- "GL_EXT_texture_compression_s3tc" ) )
- {
- /* not there, flag the failure */
- has_DXT_capability = SOIL_CAPABILITY_NONE;
- } else
- {
- /* and find the address of the extension function */
- P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC ext_addr = NULL;
- #ifdef WIN32
- ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)
- wglGetProcAddress
- (
- "glCompressedTexImage2DARB"
- );
- #elif defined(__APPLE__) || defined(__APPLE_CC__)
- /* I can't test this Apple stuff! */
- CFBundleRef bundle;
- CFURLRef bundleURL =
- CFURLCreateWithFileSystemPath(
- kCFAllocatorDefault,
- CFSTR("/System/Library/Frameworks/OpenGL.framework"),
- kCFURLPOSIXPathStyle,
- true );
- CFStringRef extensionName =
- CFStringCreateWithCString(
- kCFAllocatorDefault,
- "glCompressedTexImage2DARB",
- kCFStringEncodingASCII );
- bundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
- assert( bundle != NULL );
- ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)
- CFBundleGetFunctionPointerForName
- (
- bundle, extensionName
- );
- CFRelease( bundleURL );
- CFRelease( extensionName );
- CFRelease( bundle );
- #else
- ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)
- glXGetProcAddressARB
- (
- (const GLubyte *)"glCompressedTexImage2DARB"
- );
- #endif
- /* Flag it so no checks needed later */
- if( NULL == ext_addr )
- {
- /* hmm, not good!! This should not happen, but does on my
- laptop's VIA chipset. The GL_EXT_texture_compression_s3tc
- spec requires that ARB_texture_compression be present too.
- this means I can upload and have the OpenGL drive do the
- conversion, but I can't use my own routines or load DDS files
- from disk and upload them directly [8^( */
- has_DXT_capability = SOIL_CAPABILITY_NONE;
- } else
- {
- /* all's well! */
- soilGlCompressedTexImage2D = ext_addr;
- has_DXT_capability = SOIL_CAPABILITY_PRESENT;
- }
- }
- }
-#endif
- /* let the user know if we can do DXT or not */
- return has_DXT_capability;
-}
+/*
+ Jonathan Dummer
+ 2007-07-26-10.36
+
+ Simple OpenGL Image Library
+
+ Public Domain
+ using Sean Barret's stb_image as a base
+
+ Thanks to:
+ * Sean Barret - for the awesome stb_image
+ * Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts
+ * everybody at gamedev.net
+*/
+
+#define SOIL_CHECK_FOR_GL_ERRORS 0
+
+#ifdef WIN32
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+ #include <wingdi.h>
+ #include <GL/gl.h>
+#elif defined(__APPLE__) || defined(__APPLE_CC__)
+ /* I can't test this Apple stuff! */
+ #include <OpenGL/gl.h>
+ #include <Carbon/Carbon.h>
+ #define APIENTRY
+#else
+ #ifdef USE_GLES1
+ #include <GLES/gl.h>
+ #define APIENTRY
+ #else
+ #include <GL/gl.h>
+ #include <GL/glx.h>
+ #endif
+#endif
+
+#include "SOIL.h"
+#include "stb_image_aug.h"
+#include "image_helper.h"
+#include "image_DXT.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/* error reporting */
+char *result_string_pointer = "SOIL initialized";
+
+/* for loading cube maps */
+enum{
+ SOIL_CAPABILITY_UNKNOWN = -1,
+ SOIL_CAPABILITY_NONE = 0,
+ SOIL_CAPABILITY_PRESENT = 1
+};
+static int has_cubemap_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_cubemap_capability( void );
+#define SOIL_TEXTURE_WRAP_R 0x8072
+#define SOIL_CLAMP_TO_EDGE 0x812F
+#define SOIL_NORMAL_MAP 0x8511
+#define SOIL_REFLECTION_MAP 0x8512
+#define SOIL_TEXTURE_CUBE_MAP 0x8513
+#define SOIL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define SOIL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define SOIL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+/* for non-power-of-two texture */
+static int has_NPOT_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_NPOT_capability( void );
+/* for texture rectangles */
+static int has_tex_rectangle_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_tex_rectangle_capability( void );
+#define SOIL_TEXTURE_RECTANGLE_ARB 0x84F5
+#define SOIL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
+/* for using DXT compression */
+static int has_DXT_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_DXT_capability( void );
+#define SOIL_RGB_S3TC_DXT1 0x83F0
+#define SOIL_RGBA_S3TC_DXT1 0x83F1
+#define SOIL_RGBA_S3TC_DXT3 0x83F2
+#define SOIL_RGBA_S3TC_DXT5 0x83F3
+typedef void (APIENTRY * P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data);
+P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC soilGlCompressedTexImage2D = NULL;
+unsigned int SOIL_direct_load_DDS(
+ const char *filename,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap );
+unsigned int SOIL_direct_load_DDS_from_memory(
+ const unsigned char *const buffer,
+ int buffer_length,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap );
+/* other functions */
+unsigned int
+ SOIL_internal_create_OGL_texture
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags,
+ unsigned int opengl_texture_type,
+ unsigned int opengl_texture_target,
+ unsigned int texture_check_size_enum
+ );
+
+/* and the code magic begins here [8^) */
+unsigned int
+ SOIL_load_OGL_texture
+ (
+ const char *filename,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+
+{
+ int width, height;
+ return SOIL_load_OGL_texture_size(filename,force_channels,reuse_texture_ID,flags,&width, &height);
+}
+
+unsigned int
+ SOIL_load_OGL_texture_size
+ (
+ const char *filename,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags,
+ int *width,
+ int *height
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int channels;
+ unsigned int tex_id;
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 0 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* try to load the image */
+ img = SOIL_load_image( filename, width, height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* OK, make it a texture! */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, *width, *height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_HDR_texture
+ (
+ const char *filename,
+ int fake_HDR_format,
+ int rescale_to_max,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* no direct uploading of the image as a DDS file */
+ /* error check */
+ if( (fake_HDR_format != SOIL_HDR_RGBE) &&
+ (fake_HDR_format != SOIL_HDR_RGBdivA) &&
+ (fake_HDR_format != SOIL_HDR_RGBdivA2) )
+ {
+ result_string_pointer = "Invalid fake HDR format specified";
+ return 0;
+ }
+ /* try to load the image (only the HDR type) */
+ img = stbi_hdr_load_rgbe( filename, &width, &height, &channels, 4 );
+ /* channels holds the original number of channels, which may have been forced */
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* the load worked, do I need to convert it? */
+ if( fake_HDR_format == SOIL_HDR_RGBdivA )
+ {
+ RGBE_to_RGBdivA( img, width, height, rescale_to_max );
+ } else if( fake_HDR_format == SOIL_HDR_RGBdivA2 )
+ {
+ RGBE_to_RGBdivA2( img, width, height, rescale_to_max );
+ }
+ /* OK, make it a texture! */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_texture_from_memory
+ (
+ const unsigned char *const buffer,
+ int buffer_length,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS_from_memory(
+ buffer, buffer_length,
+ reuse_texture_ID, flags, 0 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* try to load the image */
+ img = SOIL_load_image_from_memory(
+ buffer, buffer_length,
+ &width, &height, &channels,
+ force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* OK, make it a texture! */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_cubemap
+ (
+ const char *x_pos_file,
+ const char *x_neg_file,
+ const char *y_pos_file,
+ const char *y_neg_file,
+ const char *z_pos_file,
+ const char *z_neg_file,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* error checking */
+ if( (x_pos_file == NULL) ||
+ (x_neg_file == NULL) ||
+ (y_pos_file == NULL) ||
+ (y_neg_file == NULL) ||
+ (z_pos_file == NULL) ||
+ (z_neg_file == NULL) )
+ {
+ result_string_pointer = "Invalid cube map files list";
+ return 0;
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( x_pos_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, and create a texture ID if necessary */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( x_neg_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( y_pos_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( y_neg_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( z_pos_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( z_neg_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_cubemap_from_memory
+ (
+ const unsigned char *const x_pos_buffer,
+ int x_pos_buffer_length,
+ const unsigned char *const x_neg_buffer,
+ int x_neg_buffer_length,
+ const unsigned char *const y_pos_buffer,
+ int y_pos_buffer_length,
+ const unsigned char *const y_neg_buffer,
+ int y_neg_buffer_length,
+ const unsigned char *const z_pos_buffer,
+ int z_pos_buffer_length,
+ const unsigned char *const z_neg_buffer,
+ int z_neg_buffer_length,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* error checking */
+ if( (x_pos_buffer == NULL) ||
+ (x_neg_buffer == NULL) ||
+ (y_pos_buffer == NULL) ||
+ (y_neg_buffer == NULL) ||
+ (z_pos_buffer == NULL) ||
+ (z_neg_buffer == NULL) )
+ {
+ result_string_pointer = "Invalid cube map buffers list";
+ return 0;
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ x_pos_buffer, x_pos_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, and create a texture ID if necessary */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ x_neg_buffer, x_neg_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ y_pos_buffer, y_pos_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ y_neg_buffer, y_neg_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ z_pos_buffer, z_pos_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ z_neg_buffer, z_neg_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_single_cubemap
+ (
+ const char *filename,
+ const char face_order[6],
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels, i;
+ unsigned int tex_id = 0;
+ /* error checking */
+ if( filename == NULL )
+ {
+ result_string_pointer = "Invalid single cube map file name";
+ return 0;
+ }
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 1 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* face order checking */
+ for( i = 0; i < 6; ++i )
+ {
+ if( (face_order[i] != 'N') &&
+ (face_order[i] != 'S') &&
+ (face_order[i] != 'W') &&
+ (face_order[i] != 'E') &&
+ (face_order[i] != 'U') &&
+ (face_order[i] != 'D') )
+ {
+ result_string_pointer = "Invalid single cube map face order";
+ return 0;
+ };
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st off, try to load the full image */
+ img = SOIL_load_image( filename, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* now, does this image have the right dimensions? */
+ if( (width != 6*height) &&
+ (6*width != height) )
+ {
+ SOIL_free_image_data( img );
+ result_string_pointer = "Single cubemap image must have a 6:1 ratio";
+ return 0;
+ }
+ /* try the image split and create */
+ tex_id = SOIL_create_OGL_single_cubemap(
+ img, width, height, channels,
+ face_order, reuse_texture_ID, flags
+ );
+ /* nuke the temporary image data and return the texture handle */
+ SOIL_free_image_data( img );
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_single_cubemap_from_memory
+ (
+ const unsigned char *const buffer,
+ int buffer_length,
+ const char face_order[6],
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels, i;
+ unsigned int tex_id = 0;
+ /* error checking */
+ if( buffer == NULL )
+ {
+ result_string_pointer = "Invalid single cube map buffer";
+ return 0;
+ }
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS_from_memory(
+ buffer, buffer_length,
+ reuse_texture_ID, flags, 1 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* face order checking */
+ for( i = 0; i < 6; ++i )
+ {
+ if( (face_order[i] != 'N') &&
+ (face_order[i] != 'S') &&
+ (face_order[i] != 'W') &&
+ (face_order[i] != 'E') &&
+ (face_order[i] != 'U') &&
+ (face_order[i] != 'D') )
+ {
+ result_string_pointer = "Invalid single cube map face order";
+ return 0;
+ };
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st off, try to load the full image */
+ img = SOIL_load_image_from_memory(
+ buffer, buffer_length,
+ &width, &height, &channels,
+ force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* now, does this image have the right dimensions? */
+ if( (width != 6*height) &&
+ (6*width != height) )
+ {
+ SOIL_free_image_data( img );
+ result_string_pointer = "Single cubemap image must have a 6:1 ratio";
+ return 0;
+ }
+ /* try the image split and create */
+ tex_id = SOIL_create_OGL_single_cubemap(
+ img, width, height, channels,
+ face_order, reuse_texture_ID, flags
+ );
+ /* nuke the temporary image data and return the texture handle */
+ SOIL_free_image_data( img );
+ return tex_id;
+}
+
+unsigned int
+ SOIL_create_OGL_single_cubemap
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ const char face_order[6],
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* sub_img;
+ int dw, dh, sz, i;
+ unsigned int tex_id;
+ /* error checking */
+ if( data == NULL )
+ {
+ result_string_pointer = "Invalid single cube map image data";
+ return 0;
+ }
+ /* face order checking */
+ for( i = 0; i < 6; ++i )
+ {
+ if( (face_order[i] != 'N') &&
+ (face_order[i] != 'S') &&
+ (face_order[i] != 'W') &&
+ (face_order[i] != 'E') &&
+ (face_order[i] != 'U') &&
+ (face_order[i] != 'D') )
+ {
+ result_string_pointer = "Invalid single cube map face order";
+ return 0;
+ };
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* now, does this image have the right dimensions? */
+ if( (width != 6*height) &&
+ (6*width != height) )
+ {
+ result_string_pointer = "Single cubemap image must have a 6:1 ratio";
+ return 0;
+ }
+ /* which way am I stepping? */
+ if( width > height )
+ {
+ dw = height;
+ dh = 0;
+ } else
+ {
+ dw = 0;
+ dh = width;
+ }
+ sz = dw+dh;
+ sub_img = (unsigned char *)malloc( sz*sz*channels );
+ /* do the splitting and uploading */
+ tex_id = reuse_texture_ID;
+ for( i = 0; i < 6; ++i )
+ {
+ int x, y, idx = 0;
+ unsigned int cubemap_target = 0;
+ /* copy in the sub-image */
+ for( y = i*dh; y < i*dh+sz; ++y )
+ {
+ for( x = i*dw*channels; x < (i*dw+sz)*channels; ++x )
+ {
+ sub_img[idx++] = data[y*width*channels+x];
+ }
+ }
+ /* what is my texture target?
+ remember, this coordinate system is
+ LHS if viewed from inside the cube! */
+ switch( face_order[i] )
+ {
+ case 'N':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z;
+ break;
+ case 'S':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
+ break;
+ case 'W':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X;
+ break;
+ case 'E':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_X;
+ break;
+ case 'U':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y;
+ break;
+ case 'D':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
+ break;
+ }
+ /* upload it as a texture */
+ tex_id = SOIL_internal_create_OGL_texture(
+ sub_img, sz, sz, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP,
+ cubemap_target,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ }
+ /* and nuke the image and sub-image data */
+ SOIL_free_image_data( sub_img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_create_OGL_texture
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* wrapper function for 2D textures */
+ return SOIL_internal_create_OGL_texture(
+ data, width, height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+}
+
+#if SOIL_CHECK_FOR_GL_ERRORS
+void check_for_GL_errors( const char *calling_location )
+{
+ /* check for errors */
+ GLenum err_code = glGetError();
+ while( GL_NO_ERROR != err_code )
+ {
+ printf( "OpenGL Error @ %s: %i", calling_location, err_code );
+ err_code = glGetError();
+ }
+}
+#else
+void check_for_GL_errors( const char *calling_location )
+{
+ /* no check for errors */
+}
+#endif
+
+unsigned int
+ SOIL_internal_create_OGL_texture
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags,
+ unsigned int opengl_texture_type,
+ unsigned int opengl_texture_target,
+ unsigned int texture_check_size_enum
+ )
+{
+ /* variables */
+ unsigned char* img;
+ unsigned int tex_id;
+ unsigned int internal_texture_format = 0, original_texture_format = 0;
+ int DXT_mode = SOIL_CAPABILITY_UNKNOWN;
+ int max_supported_size;
+ /* If the user wants to use the texture rectangle I kill a few flags */
+ if( flags & SOIL_FLAG_TEXTURE_RECTANGLE )
+ {
+ /* well, the user asked for it, can we do that? */
+ if( query_tex_rectangle_capability() == SOIL_CAPABILITY_PRESENT )
+ {
+ /* only allow this if the user in _NOT_ trying to do a cubemap! */
+ if( opengl_texture_type == GL_TEXTURE_2D )
+ {
+ /* clean out the flags that cannot be used with texture rectangles */
+ flags &= ~(
+ SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS |
+ SOIL_FLAG_TEXTURE_REPEATS
+ );
+ /* and change my target */
+ opengl_texture_target = SOIL_TEXTURE_RECTANGLE_ARB;
+ opengl_texture_type = SOIL_TEXTURE_RECTANGLE_ARB;
+ } else
+ {
+ /* not allowed for any other uses (yes, I'm looking at you, cubemaps!) */
+ flags &= ~SOIL_FLAG_TEXTURE_RECTANGLE;
+ }
+
+ } else
+ {
+ /* can't do it, and that is a breakable offense (uv coords use pixels instead of [0,1]!) */
+ result_string_pointer = "Texture Rectangle extension unsupported";
+ return 0;
+ }
+ }
+ /* create a copy the image data */
+ img = (unsigned char*)malloc( width*height*channels );
+ memcpy( img, data, width*height*channels );
+ /* does the user want me to invert the image? */
+ if( flags & SOIL_FLAG_INVERT_Y )
+ {
+ int i, j;
+ for( j = 0; j*2 < height; ++j )
+ {
+ int index1 = j * width * channels;
+ int index2 = (height - 1 - j) * width * channels;
+ for( i = width * channels; i > 0; --i )
+ {
+ unsigned char temp = img[index1];
+ img[index1] = img[index2];
+ img[index2] = temp;
+ ++index1;
+ ++index2;
+ }
+ }
+ }
+ /* does the user want me to scale the colors into the NTSC safe RGB range? */
+ if( flags & SOIL_FLAG_NTSC_SAFE_RGB )
+ {
+ scale_image_RGB_to_NTSC_safe( img, width, height, channels );
+ }
+ /* does the user want me to convert from straight to pre-multiplied alpha?
+ (and do we even _have_ alpha?) */
+ if( flags & SOIL_FLAG_MULTIPLY_ALPHA )
+ {
+ int i;
+ switch( channels )
+ {
+ case 2:
+ for( i = 0; i < 2*width*height; i += 2 )
+ {
+ img[i] = (img[i] * img[i+1] + 128) >> 8;
+ }
+ break;
+ case 4:
+ for( i = 0; i < 4*width*height; i += 4 )
+ {
+ img[i+0] = (img[i+0] * img[i+3] + 128) >> 8;
+ img[i+1] = (img[i+1] * img[i+3] + 128) >> 8;
+ img[i+2] = (img[i+2] * img[i+3] + 128) >> 8;
+ }
+ break;
+ default:
+ /* no other number of channels contains alpha data */
+ break;
+ }
+ }
+ /* if the user can't support NPOT textures, make sure we force the POT option */
+ if( (query_NPOT_capability() == SOIL_CAPABILITY_NONE) &&
+ !(flags & SOIL_FLAG_TEXTURE_RECTANGLE) )
+ {
+ /* add in the POT flag */
+ flags |= SOIL_FLAG_POWER_OF_TWO;
+ }
+ /* how large of a texture can this OpenGL implementation handle? */
+ /* texture_check_size_enum will be GL_MAX_TEXTURE_SIZE or SOIL_MAX_CUBE_MAP_TEXTURE_SIZE */
+ glGetIntegerv( texture_check_size_enum, &max_supported_size );
+ /* do I need to make it a power of 2? */
+ if(
+ (flags & SOIL_FLAG_POWER_OF_TWO) || /* user asked for it */
+ (flags & SOIL_FLAG_MIPMAPS) || /* need it for the MIP-maps */
+ (width > max_supported_size) || /* it's too big, (make sure it's */
+ (height > max_supported_size) ) /* 2^n for later down-sampling) */
+ {
+ int new_width = 1;
+ int new_height = 1;
+ while( new_width < width )
+ {
+ new_width *= 2;
+ }
+ while( new_height < height )
+ {
+ new_height *= 2;
+ }
+ /* still? */
+ if( (new_width != width) || (new_height != height) )
+ {
+ /* yep, resize */
+ unsigned char *resampled = (unsigned char*)malloc( channels*new_width*new_height );
+ up_scale_image(
+ img, width, height, channels,
+ resampled, new_width, new_height );
+ /* OJO this is for debug only! */
+ /*
+ SOIL_save_image( "\\showme.bmp", SOIL_SAVE_TYPE_BMP,
+ new_width, new_height, channels,
+ resampled );
+ */
+ /* nuke the old guy, then point it at the new guy */
+ SOIL_free_image_data( img );
+ img = resampled;
+ width = new_width;
+ height = new_height;
+ }
+ }
+ /* now, if it is too large... */
+ if( (width > max_supported_size) || (height > max_supported_size) )
+ {
+ /* I've already made it a power of two, so simply use the MIPmapping
+ code to reduce its size to the allowable maximum. */
+ unsigned char *resampled;
+ int reduce_block_x = 1, reduce_block_y = 1;
+ int new_width, new_height;
+ if( width > max_supported_size )
+ {
+ reduce_block_x = width / max_supported_size;
+ }
+ if( height > max_supported_size )
+ {
+ reduce_block_y = height / max_supported_size;
+ }
+ new_width = width / reduce_block_x;
+ new_height = height / reduce_block_y;
+ resampled = (unsigned char*)malloc( channels*new_width*new_height );
+ /* perform the actual reduction */
+ mipmap_image( img, width, height, channels,
+ resampled, reduce_block_x, reduce_block_y );
+ /* nuke the old guy, then point it at the new guy */
+ SOIL_free_image_data( img );
+ img = resampled;
+ width = new_width;
+ height = new_height;
+ }
+ /* does the user want us to use YCoCg color space? */
+ if( flags & SOIL_FLAG_CoCg_Y )
+ {
+ /* this will only work with RGB and RGBA images */
+ convert_RGB_to_YCoCg( img, width, height, channels );
+ /*
+ save_image_as_DDS( "CoCg_Y.dds", width, height, channels, img );
+ */
+ }
+ /* create the OpenGL texture ID handle
+ (note: allowing a forced texture ID lets me reload a texture) */
+ tex_id = reuse_texture_ID;
+ if( tex_id == 0 )
+ {
+ glGenTextures( 1, &tex_id );
+ }
+ check_for_GL_errors( "glGenTextures" );
+ /* Note: sometimes glGenTextures fails (usually no OpenGL context) */
+ if( tex_id )
+ {
+ /* and what type am I using as the internal texture format? */
+ switch( channels )
+ {
+ case 1:
+ original_texture_format = GL_LUMINANCE;
+ break;
+ case 2:
+ original_texture_format = GL_LUMINANCE_ALPHA;
+ break;
+ case 3:
+ original_texture_format = GL_RGB;
+ break;
+ case 4:
+ original_texture_format = GL_RGBA;
+ break;
+ }
+ internal_texture_format = original_texture_format;
+ /* does the user want me to, and can I, save as DXT? */
+ if( flags & SOIL_FLAG_COMPRESS_TO_DXT )
+ {
+ DXT_mode = query_DXT_capability();
+ if( DXT_mode == SOIL_CAPABILITY_PRESENT )
+ {
+ /* I can use DXT, whether I compress it or OpenGL does */
+ if( (channels & 1) == 1 )
+ {
+ /* 1 or 3 channels = DXT1 */
+ internal_texture_format = SOIL_RGB_S3TC_DXT1;
+ } else
+ {
+ /* 2 or 4 channels = DXT5 */
+ internal_texture_format = SOIL_RGBA_S3TC_DXT5;
+ }
+ }
+ }
+ /* bind an OpenGL texture ID */
+ glBindTexture( opengl_texture_type, tex_id );
+ check_for_GL_errors( "glBindTexture" );
+ /* upload the main image */
+ if( DXT_mode == SOIL_CAPABILITY_PRESENT )
+ {
+ /* user wants me to do the DXT conversion! */
+ int DDS_size;
+ unsigned char *DDS_data = NULL;
+ if( (channels & 1) == 1 )
+ {
+ /* RGB, use DXT1 */
+ DDS_data = convert_image_to_DXT1( img, width, height, channels, &DDS_size );
+ } else
+ {
+ /* RGBA, use DXT5 */
+ DDS_data = convert_image_to_DXT5( img, width, height, channels, &DDS_size );
+ }
+ if( DDS_data )
+ {
+ soilGlCompressedTexImage2D(
+ opengl_texture_target, 0,
+ internal_texture_format, width, height, 0,
+ DDS_size, DDS_data );
+ check_for_GL_errors( "glCompressedTexImage2D" );
+ SOIL_free_image_data( DDS_data );
+ /* printf( "Internal DXT compressor\n" ); */
+ } else
+ {
+ /* my compression failed, try the OpenGL driver's version */
+ glTexImage2D(
+ opengl_texture_target, 0,
+ internal_texture_format, width, height, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, img );
+ check_for_GL_errors( "glTexImage2D" );
+ /* printf( "OpenGL DXT compressor\n" ); */
+ }
+ } else
+ {
+ /* user want OpenGL to do all the work! */
+ glTexImage2D(
+ opengl_texture_target, 0,
+ internal_texture_format, width, height, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, img );
+ check_for_GL_errors( "glTexImage2D" );
+ /*printf( "OpenGL DXT compressor\n" ); */
+ }
+ /* are any MIPmaps desired? */
+ if( flags & SOIL_FLAG_MIPMAPS )
+ {
+ int MIPlevel = 1;
+ int MIPwidth = (width+1) / 2;
+ int MIPheight = (height+1) / 2;
+ unsigned char *resampled = (unsigned char*)malloc( channels*MIPwidth*MIPheight );
+ while( ((1<<MIPlevel) <= width) || ((1<<MIPlevel) <= height) )
+ {
+ /* do this MIPmap level */
+ mipmap_image(
+ img, width, height, channels,
+ resampled,
+ (1 << MIPlevel), (1 << MIPlevel) );
+ /* upload the MIPmaps */
+ if( DXT_mode == SOIL_CAPABILITY_PRESENT )
+ {
+ /* user wants me to do the DXT conversion! */
+ int DDS_size;
+ unsigned char *DDS_data = NULL;
+ if( (channels & 1) == 1 )
+ {
+ /* RGB, use DXT1 */
+ DDS_data = convert_image_to_DXT1(
+ resampled, MIPwidth, MIPheight, channels, &DDS_size );
+ } else
+ {
+ /* RGBA, use DXT5 */
+ DDS_data = convert_image_to_DXT5(
+ resampled, MIPwidth, MIPheight, channels, &DDS_size );
+ }
+ if( DDS_data )
+ {
+ soilGlCompressedTexImage2D(
+ opengl_texture_target, MIPlevel,
+ internal_texture_format, MIPwidth, MIPheight, 0,
+ DDS_size, DDS_data );
+ check_for_GL_errors( "glCompressedTexImage2D" );
+ SOIL_free_image_data( DDS_data );
+ } else
+ {
+ /* my compression failed, try the OpenGL driver's version */
+ glTexImage2D(
+ opengl_texture_target, MIPlevel,
+ internal_texture_format, MIPwidth, MIPheight, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, resampled );
+ check_for_GL_errors( "glTexImage2D" );
+ }
+ } else
+ {
+ /* user want OpenGL to do all the work! */
+ glTexImage2D(
+ opengl_texture_target, MIPlevel,
+ internal_texture_format, MIPwidth, MIPheight, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, resampled );
+ check_for_GL_errors( "glTexImage2D" );
+ }
+ /* prep for the next level */
+ ++MIPlevel;
+ MIPwidth = (MIPwidth + 1) / 2;
+ MIPheight = (MIPheight + 1) / 2;
+ }
+ SOIL_free_image_data( resampled );
+ /* instruct OpenGL to use the MIPmaps */
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
+ check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" );
+ } else
+ {
+ /* instruct OpenGL _NOT_ to use the MIPmaps */
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" );
+ }
+ /* does the user want clamping, or wrapping? */
+ if( flags & SOIL_FLAG_TEXTURE_REPEATS )
+ {
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT );
+ if( opengl_texture_type == SOIL_TEXTURE_CUBE_MAP )
+ {
+ /* SOIL_TEXTURE_WRAP_R is invalid if cubemaps aren't supported */
+ glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT );
+ }
+ check_for_GL_errors( "GL_TEXTURE_WRAP_*" );
+ } else
+ {
+ /* unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; */
+ unsigned int clamp_mode = GL_CLAMP_TO_EDGE;
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode );
+ if( opengl_texture_type == SOIL_TEXTURE_CUBE_MAP )
+ {
+ /* SOIL_TEXTURE_WRAP_R is invalid if cubemaps aren't supported */
+ glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode );
+ }
+ check_for_GL_errors( "GL_TEXTURE_WRAP_*" );
+ }
+ /* done */
+ result_string_pointer = "Image loaded as an OpenGL texture";
+ } else
+ {
+ /* failed */
+ result_string_pointer = "Failed to generate an OpenGL texture name; missing OpenGL context?";
+ }
+ SOIL_free_image_data( img );
+ return tex_id;
+}
+
+int
+ SOIL_save_screenshot
+ (
+ const char *filename,
+ int image_type,
+ int x, int y,
+ int width, int height
+ )
+{
+ unsigned char *pixel_data;
+ int i, j;
+ int save_result;
+
+ /* error checks */
+ if( (width < 1) || (height < 1) )
+ {
+ result_string_pointer = "Invalid screenshot dimensions";
+ return 0;
+ }
+ if( (x < 0) || (y < 0) )
+ {
+ result_string_pointer = "Invalid screenshot location";
+ return 0;
+ }
+ if( filename == NULL )
+ {
+ result_string_pointer = "Invalid screenshot filename";
+ return 0;
+ }
+
+ /* Get the data from OpenGL */
+ pixel_data = (unsigned char*)malloc( 3*width*height );
+ glReadPixels (x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixel_data);
+
+ /* invert the image */
+ for( j = 0; j*2 < height; ++j )
+ {
+ int index1 = j * width * 3;
+ int index2 = (height - 1 - j) * width * 3;
+ for( i = width * 3; i > 0; --i )
+ {
+ unsigned char temp = pixel_data[index1];
+ pixel_data[index1] = pixel_data[index2];
+ pixel_data[index2] = temp;
+ ++index1;
+ ++index2;
+ }
+ }
+
+ /* save the image */
+ save_result = SOIL_save_image( filename, image_type, width, height, 3, pixel_data);
+
+ /* And free the memory */
+ SOIL_free_image_data( pixel_data );
+ return save_result;
+}
+
+unsigned char*
+ SOIL_load_image
+ (
+ const char *filename,
+ int *width, int *height, int *channels,
+ int force_channels
+ )
+{
+ unsigned char *result = stbi_load( filename,
+ width, height, channels, force_channels );
+ if( result == NULL )
+ {
+ result_string_pointer = stbi_failure_reason();
+ } else
+ {
+ result_string_pointer = "Image loaded";
+ }
+ return result;
+}
+
+unsigned char*
+ SOIL_load_image_from_memory
+ (
+ const unsigned char *const buffer,
+ int buffer_length,
+ int *width, int *height, int *channels,
+ int force_channels
+ )
+{
+ unsigned char *result = stbi_load_from_memory(
+ buffer, buffer_length,
+ width, height, channels,
+ force_channels );
+ if( result == NULL )
+ {
+ result_string_pointer = stbi_failure_reason();
+ } else
+ {
+ result_string_pointer = "Image loaded from memory";
+ }
+ return result;
+}
+
+int
+ SOIL_save_image
+ (
+ const char *filename,
+ int image_type,
+ int width, int height, int channels,
+ const unsigned char *const data
+ )
+{
+ int save_result;
+
+ /* error check */
+ if( (width < 1) || (height < 1) ||
+ (channels < 1) || (channels > 4) ||
+ (data == NULL) ||
+ (filename == NULL) )
+ {
+ return 0;
+ }
+ if( image_type == SOIL_SAVE_TYPE_BMP )
+ {
+ save_result = stbi_write_bmp( filename,
+ width, height, channels, (void*)data );
+ } else
+ if( image_type == SOIL_SAVE_TYPE_TGA )
+ {
+ save_result = stbi_write_tga( filename,
+ width, height, channels, (void*)data );
+ } else
+ if( image_type == SOIL_SAVE_TYPE_DDS )
+ {
+ save_result = save_image_as_DDS( filename,
+ width, height, channels, (const unsigned char *const)data );
+ } else
+ {
+ save_result = 0;
+ }
+ if( save_result == 0 )
+ {
+ result_string_pointer = "Saving the image failed";
+ } else
+ {
+ result_string_pointer = "Image saved";
+ }
+ return save_result;
+}
+
+void
+ SOIL_free_image_data
+ (
+ unsigned char *img_data
+ )
+{
+ free( (void*)img_data );
+}
+
+const char*
+ SOIL_last_result
+ (
+ void
+ )
+{
+ return result_string_pointer;
+}
+
+unsigned int SOIL_direct_load_DDS_from_memory(
+ const unsigned char *const buffer,
+ int buffer_length,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap )
+{
+ /* variables */
+ DDS_header header;
+ unsigned int buffer_index = 0;
+ unsigned int tex_ID = 0;
+ /* file reading variables */
+ unsigned int S3TC_type = 0;
+ unsigned char *DDS_data;
+ unsigned int DDS_main_size;
+ unsigned int DDS_full_size;
+ unsigned int width, height;
+ int mipmaps, cubemap, uncompressed, block_size = 16;
+ unsigned int flag;
+ unsigned int cf_target, ogl_target_start, ogl_target_end;
+ unsigned int opengl_texture_type;
+ int i;
+ /* 1st off, does the filename even exist? */
+ if( NULL == buffer )
+ {
+ /* we can't do it! */
+ result_string_pointer = "NULL buffer";
+ return 0;
+ }
+ if( buffer_length < sizeof( DDS_header ) )
+ {
+ /* we can't do it! */
+ result_string_pointer = "DDS file was too small to contain the DDS header";
+ return 0;
+ }
+ /* try reading in the header */
+ memcpy ( (void*)(&header), (const void *)buffer, sizeof( DDS_header ) );
+ buffer_index = sizeof( DDS_header );
+ /* guilty until proven innocent */
+ result_string_pointer = "Failed to read a known DDS header";
+ /* validate the header (warning, "goto"'s ahead, shield your eyes!!) */
+ flag = ('D'<<0)|('D'<<8)|('S'<<16)|(' '<<24);
+ if( header.dwMagic != flag ) {goto quick_exit;}
+ if( header.dwSize != 124 ) {goto quick_exit;}
+ /* I need all of these */
+ flag = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ if( (header.dwFlags & flag) != flag ) {goto quick_exit;}
+ /* According to the MSDN spec, the dwFlags should contain
+ DDSD_LINEARSIZE if it's compressed, or DDSD_PITCH if
+ uncompressed. Some DDS writers do not conform to the
+ spec, so I need to make my reader more tolerant */
+ /* I need one of these */
+ flag = DDPF_FOURCC | DDPF_RGB;
+ if( (header.sPixelFormat.dwFlags & flag) == 0 ) {goto quick_exit;}
+ if( header.sPixelFormat.dwSize != 32 ) {goto quick_exit;}
+ if( (header.sCaps.dwCaps1 & DDSCAPS_TEXTURE) == 0 ) {goto quick_exit;}
+ /* make sure it is a type we can upload */
+ if( (header.sPixelFormat.dwFlags & DDPF_FOURCC) &&
+ !(
+ (header.sPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('1'<<24))) ||
+ (header.sPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('3'<<24))) ||
+ (header.sPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('5'<<24)))
+ ) )
+ {
+ goto quick_exit;
+ }
+ /* OK, validated the header, let's load the image data */
+ result_string_pointer = "DDS header loaded and validated";
+ width = header.dwWidth;
+ height = header.dwHeight;
+ uncompressed = 1 - (header.sPixelFormat.dwFlags & DDPF_FOURCC) / DDPF_FOURCC;
+ cubemap = (header.sCaps.dwCaps2 & DDSCAPS2_CUBEMAP) / DDSCAPS2_CUBEMAP;
+ if( uncompressed )
+ {
+ S3TC_type = GL_RGB;
+ block_size = 3;
+ if( header.sPixelFormat.dwFlags & DDPF_ALPHAPIXELS )
+ {
+ S3TC_type = GL_RGBA;
+ block_size = 4;
+ }
+ DDS_main_size = width * height * block_size;
+ } else
+ {
+ /* can we even handle direct uploading to OpenGL DXT compressed images? */
+ if( query_DXT_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ /* we can't do it! */
+ result_string_pointer = "Direct upload of S3TC images not supported by the OpenGL driver";
+ return 0;
+ }
+ /* well, we know it is DXT1/3/5, because we checked above */
+ switch( (header.sPixelFormat.dwFourCC >> 24) - '0' )
+ {
+ case 1:
+ S3TC_type = SOIL_RGBA_S3TC_DXT1;
+ block_size = 8;
+ break;
+ case 3:
+ S3TC_type = SOIL_RGBA_S3TC_DXT3;
+ block_size = 16;
+ break;
+ case 5:
+ S3TC_type = SOIL_RGBA_S3TC_DXT5;
+ block_size = 16;
+ break;
+ }
+ DDS_main_size = ((width+3)>>2)*((height+3)>>2)*block_size;
+ }
+ if( cubemap )
+ {
+ /* does the user want a cubemap? */
+ if( !loading_as_cubemap )
+ {
+ /* we can't do it! */
+ result_string_pointer = "DDS image was a cubemap";
+ return 0;
+ }
+ /* can we even handle cubemaps with the OpenGL driver? */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ /* we can't do it! */
+ result_string_pointer = "Direct upload of cubemap images not supported by the OpenGL driver";
+ return 0;
+ }
+ ogl_target_start = SOIL_TEXTURE_CUBE_MAP_POSITIVE_X;
+ ogl_target_end = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
+ opengl_texture_type = SOIL_TEXTURE_CUBE_MAP;
+ } else
+ {
+ /* does the user want a non-cubemap? */
+ if( loading_as_cubemap )
+ {
+ /* we can't do it! */
+ result_string_pointer = "DDS image was not a cubemap";
+ return 0;
+ }
+ ogl_target_start = GL_TEXTURE_2D;
+ ogl_target_end = GL_TEXTURE_2D;
+ opengl_texture_type = GL_TEXTURE_2D;
+ }
+ if( (header.sCaps.dwCaps1 & DDSCAPS_MIPMAP) && (header.dwMipMapCount > 1) )
+ {
+ int shift_offset;
+ mipmaps = header.dwMipMapCount - 1;
+ DDS_full_size = DDS_main_size;
+ if( uncompressed )
+ {
+ /* uncompressed DDS, simple MIPmap size calculation */
+ shift_offset = 0;
+ } else
+ {
+ /* compressed DDS, MIPmap size calculation is block based */
+ shift_offset = 2;
+ }
+ for( i = 1; i <= mipmaps; ++ i )
+ {
+ int w, h;
+ w = width >> (shift_offset + i);
+ h = height >> (shift_offset + i);
+ if( w < 1 )
+ {
+ w = 1;
+ }
+ if( h < 1 )
+ {
+ h = 1;
+ }
+ DDS_full_size += w*h*block_size;
+ }
+ } else
+ {
+ mipmaps = 0;
+ DDS_full_size = DDS_main_size;
+ }
+ DDS_data = (unsigned char*)malloc( DDS_full_size );
+ /* got the image data RAM, create or use an existing OpenGL texture handle */
+ tex_ID = reuse_texture_ID;
+ if( tex_ID == 0 )
+ {
+ glGenTextures( 1, &tex_ID );
+ }
+ /* bind an OpenGL texture ID */
+ glBindTexture( opengl_texture_type, tex_ID );
+ /* do this for each face of the cubemap! */
+ for( cf_target = ogl_target_start; cf_target <= ogl_target_end; ++cf_target )
+ {
+ if( buffer_index + DDS_full_size <= buffer_length )
+ {
+ unsigned int byte_offset = DDS_main_size;
+ memcpy( (void*)DDS_data, (const void*)(&buffer[buffer_index]), DDS_full_size );
+ buffer_index += DDS_full_size;
+ /* upload the main chunk */
+ if( uncompressed )
+ {
+ /* and remember, DXT uncompressed uses BGR(A),
+ so swap to RGB(A) for ALL MIPmap levels */
+ for( i = 0; i < DDS_full_size; i += block_size )
+ {
+ unsigned char temp = DDS_data[i];
+ DDS_data[i] = DDS_data[i+2];
+ DDS_data[i+2] = temp;
+ }
+ glTexImage2D(
+ cf_target, 0,
+ S3TC_type, width, height, 0,
+ S3TC_type, GL_UNSIGNED_BYTE, DDS_data );
+ } else
+ {
+ soilGlCompressedTexImage2D(
+ cf_target, 0,
+ S3TC_type, width, height, 0,
+ DDS_main_size, DDS_data );
+ }
+ /* upload the mipmaps, if we have them */
+ for( i = 1; i <= mipmaps; ++i )
+ {
+ int w, h, mip_size;
+ w = width >> i;
+ h = height >> i;
+ if( w < 1 )
+ {
+ w = 1;
+ }
+ if( h < 1 )
+ {
+ h = 1;
+ }
+ /* upload this mipmap */
+ if( uncompressed )
+ {
+ mip_size = w*h*block_size;
+ glTexImage2D(
+ cf_target, i,
+ S3TC_type, w, h, 0,
+ S3TC_type, GL_UNSIGNED_BYTE, &DDS_data[byte_offset] );
+ } else
+ {
+ mip_size = ((w+3)/4)*((h+3)/4)*block_size;
+ soilGlCompressedTexImage2D(
+ cf_target, i,
+ S3TC_type, w, h, 0,
+ mip_size, &DDS_data[byte_offset] );
+ }
+ /* and move to the next mipmap */
+ byte_offset += mip_size;
+ }
+ /* it worked! */
+ result_string_pointer = "DDS file loaded";
+ } else
+ {
+ glDeleteTextures( 1, & tex_ID );
+ tex_ID = 0;
+ cf_target = ogl_target_end + 1;
+ result_string_pointer = "DDS file was too small for expected image data";
+ }
+ }/* end reading each face */
+ SOIL_free_image_data( DDS_data );
+ if( tex_ID )
+ {
+ /* did I have MIPmaps? */
+ if( mipmaps > 0 )
+ {
+ /* instruct OpenGL to use the MIPmaps */
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
+ } else
+ {
+ /* instruct OpenGL _NOT_ to use the MIPmaps */
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ }
+ /* does the user want clamping, or wrapping? */
+ if( flags & SOIL_FLAG_TEXTURE_REPEATS )
+ {
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, GL_REPEAT );
+ glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, GL_REPEAT );
+ } else
+ {
+ /* unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE; */
+ unsigned int clamp_mode = GL_CLAMP_TO_EDGE;
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode );
+ glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode );
+ }
+ }
+
+quick_exit:
+ /* report success or failure */
+ return tex_ID;
+}
+
+unsigned int SOIL_direct_load_DDS(
+ const char *filename,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap )
+{
+ FILE *f;
+ unsigned char *buffer;
+ size_t buffer_length, bytes_read;
+ unsigned int tex_ID = 0;
+ /* error checks */
+ if( NULL == filename )
+ {
+ result_string_pointer = "NULL filename";
+ return 0;
+ }
+ f = fopen( filename, "rb" );
+ if( NULL == f )
+ {
+ /* the file doesn't seem to exist (or be open-able) */
+ result_string_pointer = "Can not find DDS file";
+ return 0;
+ }
+ fseek( f, 0, SEEK_END );
+ buffer_length = ftell( f );
+ fseek( f, 0, SEEK_SET );
+ buffer = (unsigned char *) malloc( buffer_length );
+ if( NULL == buffer )
+ {
+ result_string_pointer = "malloc failed";
+ fclose( f );
+ return 0;
+ }
+ bytes_read = fread( (void*)buffer, 1, buffer_length, f );
+ fclose( f );
+ if( bytes_read < buffer_length )
+ {
+ /* huh? */
+ buffer_length = bytes_read;
+ }
+ /* now try to do the loading */
+ tex_ID = SOIL_direct_load_DDS_from_memory(
+ (const unsigned char *const)buffer, buffer_length,
+ reuse_texture_ID, flags, loading_as_cubemap );
+ SOIL_free_image_data( buffer );
+ return tex_ID;
+}
+
+int query_NPOT_capability( void )
+{
+ /* check for the capability */
+ if( has_NPOT_capability == SOIL_CAPABILITY_UNKNOWN )
+ {
+ /* we haven't yet checked for the capability, do so */
+ if(
+ (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
+ "GL_ARB_texture_non_power_of_two" ) )
+ )
+ {
+ /* not there, flag the failure */
+ has_NPOT_capability = SOIL_CAPABILITY_NONE;
+ } else
+ {
+ /* it's there! */
+ has_NPOT_capability = SOIL_CAPABILITY_PRESENT;
+ }
+ }
+ /* let the user know if we can do non-power-of-two textures or not */
+ return has_NPOT_capability;
+}
+
+int query_tex_rectangle_capability( void )
+{
+ /* check for the capability */
+ if( has_tex_rectangle_capability == SOIL_CAPABILITY_UNKNOWN )
+ {
+ /* we haven't yet checked for the capability, do so */
+ if(
+ (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
+ "GL_ARB_texture_rectangle" ) )
+ &&
+ (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
+ "GL_EXT_texture_rectangle" ) )
+ &&
+ (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
+ "GL_NV_texture_rectangle" ) )
+ )
+ {
+ /* not there, flag the failure */
+ has_tex_rectangle_capability = SOIL_CAPABILITY_NONE;
+ } else
+ {
+ /* it's there! */
+ has_tex_rectangle_capability = SOIL_CAPABILITY_PRESENT;
+ }
+ }
+ /* let the user know if we can do texture rectangles or not */
+ return has_tex_rectangle_capability;
+}
+
+int query_cubemap_capability( void )
+{
+ /* check for the capability */
+ if( has_cubemap_capability == SOIL_CAPABILITY_UNKNOWN )
+ {
+ /* we haven't yet checked for the capability, do so */
+ if(
+ (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
+ "GL_ARB_texture_cube_map" ) )
+ &&
+ (NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
+ "GL_EXT_texture_cube_map" ) )
+ )
+ {
+ /* not there, flag the failure */
+ has_cubemap_capability = SOIL_CAPABILITY_NONE;
+ } else
+ {
+ /* it's there! */
+ has_cubemap_capability = SOIL_CAPABILITY_PRESENT;
+ }
+ }
+ /* let the user know if we can do cubemaps or not */
+ return has_cubemap_capability;
+}
+
+int query_DXT_capability( void )
+{
+#ifdef USE_GLES1
+ /*
+ * GLES1 has no S3-style texture compression extension.
+ * GLES2 has GL_EXT_texture_compression_dxt1 available which only supports,
+ * obviously enough, DXT1 compression.
+ */
+ has_DXT_capability = SOIL_CAPABILITY_NONE;
+#else
+ /* check for the capability */
+ if( has_DXT_capability == SOIL_CAPABILITY_UNKNOWN )
+ {
+ /* we haven't yet checked for the capability, do so */
+ if( NULL == strstr(
+ (char const*)glGetString( GL_EXTENSIONS ),
+ "GL_EXT_texture_compression_s3tc" ) )
+ {
+ /* not there, flag the failure */
+ has_DXT_capability = SOIL_CAPABILITY_NONE;
+ } else
+ {
+ /* and find the address of the extension function */
+ P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC ext_addr = NULL;
+ #ifdef WIN32
+ ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)
+ wglGetProcAddress
+ (
+ "glCompressedTexImage2DARB"
+ );
+ #elif defined(__APPLE__) || defined(__APPLE_CC__)
+ /* I can't test this Apple stuff! */
+ CFBundleRef bundle;
+ CFURLRef bundleURL =
+ CFURLCreateWithFileSystemPath(
+ kCFAllocatorDefault,
+ CFSTR("/System/Library/Frameworks/OpenGL.framework"),
+ kCFURLPOSIXPathStyle,
+ true );
+ CFStringRef extensionName =
+ CFStringCreateWithCString(
+ kCFAllocatorDefault,
+ "glCompressedTexImage2DARB",
+ kCFStringEncodingASCII );
+ bundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
+ assert( bundle != NULL );
+ ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)
+ CFBundleGetFunctionPointerForName
+ (
+ bundle, extensionName
+ );
+ CFRelease( bundleURL );
+ CFRelease( extensionName );
+ CFRelease( bundle );
+ #else
+ ext_addr = (P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC)
+ glXGetProcAddressARB
+ (
+ (const GLubyte *)"glCompressedTexImage2DARB"
+ );
+ #endif
+ /* Flag it so no checks needed later */
+ if( NULL == ext_addr )
+ {
+ /* hmm, not good!! This should not happen, but does on my
+ laptop's VIA chipset. The GL_EXT_texture_compression_s3tc
+ spec requires that ARB_texture_compression be present too.
+ this means I can upload and have the OpenGL drive do the
+ conversion, but I can't use my own routines or load DDS files
+ from disk and upload them directly [8^( */
+ has_DXT_capability = SOIL_CAPABILITY_NONE;
+ } else
+ {
+ /* all's well! */
+ soilGlCompressedTexImage2D = ext_addr;
+ has_DXT_capability = SOIL_CAPABILITY_PRESENT;
+ }
+ }
+ }
+#endif
+ /* let the user know if we can do DXT or not */
+ return has_DXT_capability;
+}
diff --git a/src/libprojectM/Renderer/Shader.cpp b/src/libprojectM/Renderer/Shader.cpp
index 1ffb119..16979d1 100644
--- a/src/libprojectM/Renderer/Shader.cpp
+++ b/src/libprojectM/Renderer/Shader.cpp
@@ -4,9 +4,9 @@
* Created on: Jun 29, 2008
* Author: pete
*/
-
#include "Shader.hpp"
+
Shader::Shader()
- : enabled(false)
- {}
+ : enabled(false)
+{}
diff --git a/src/libprojectM/Renderer/Shader.hpp b/src/libprojectM/Renderer/Shader.hpp
index beecb79..a5a5fcd 100644
--- a/src/libprojectM/Renderer/Shader.hpp
+++ b/src/libprojectM/Renderer/Shader.hpp
@@ -4,7 +4,6 @@
* Created on: Jun 29, 2008
* Author: pete
*/
-
#ifndef SHADER_HPP_
#define SHADER_HPP_
@@ -12,17 +11,18 @@
#include <map>
#include "UserTexture.hpp"
+
class Shader
{
public:
- std::map<std::string, UserTexture*> textures;
+ std::map<std::string, UserTexture*> textures;
- bool enabled;
+ bool enabled;
- std::string programSource;
+ std::string programSource;
- Shader();
+ Shader();
};
#endif /* SHADER_HPP_ */
diff --git a/src/libprojectM/Renderer/ShaderEngine.cpp b/src/libprojectM/Renderer/ShaderEngine.cpp
index 054a170..745b4be 100644
--- a/src/libprojectM/Renderer/ShaderEngine.cpp
+++ b/src/libprojectM/Renderer/ShaderEngine.cpp
@@ -9,691 +9,700 @@
#include "ShaderEngine.hpp"
#include "BeatDetect.hpp"
+
ShaderEngine::ShaderEngine()
{
#ifdef USE_CG
- SetupCg();
+ SetupCg();
#endif
}
ShaderEngine::~ShaderEngine()
{
- // TODO Auto-generated destructor stub
+ // TODO Auto-generated destructor stub
}
#ifdef USE_CG
-void ShaderEngine::setParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect,
- TextureManager *textureManager)
+void
+ShaderEngine::setParams (
+const int texsize,
+const unsigned int texId,
+const float aspect,
+BeatDetect *beatDetect,
+TextureManager *textureManager
+)
{
- mainTextureId = texId;
- this->beatDetect = beatDetect;
- this->textureManager = textureManager;
- this->aspect = aspect;
- this->texsize = texsize;
+ mainTextureId = texId;
+ this->beatDetect = beatDetect;
+ this->textureManager = textureManager;
+ this->aspect = aspect;
+ this->texsize = texsize;
- textureManager->setTexture("main", texId, texsize, texsize);
+ textureManager->setTexture("main", texId, texsize, texsize);
- glGenTextures(1, &blur1_tex);
- glBindTexture(GL_TEXTURE_2D, blur1_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texsize/2, texsize/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glGenTextures(1, &blur1_tex);
+ glBindTexture(GL_TEXTURE_2D, blur1_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texsize/2, texsize/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glGenTextures(1, &blur2_tex);
- glBindTexture(GL_TEXTURE_2D, blur2_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texsize / 4, texsize / 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glGenTextures(1, &blur2_tex);
+ glBindTexture(GL_TEXTURE_2D, blur2_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texsize / 4, texsize / 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glGenTextures(1, &blur3_tex);
- glBindTexture(GL_TEXTURE_2D, blur3_tex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texsize / 8, texsize / 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glGenTextures(1, &blur3_tex);
+ glBindTexture(GL_TEXTURE_2D, blur3_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texsize / 8, texsize / 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- blur1_enabled = false;
- blur2_enabled = false;
- blur3_enabled = false;
+ blur1_enabled = false;
+ blur2_enabled = false;
+ blur3_enabled = false;
- //std::cout << "Generating Noise Textures" << std::endl;
+ //std::cout << "Generating Noise Textures" << std::endl;
- PerlinNoise noise;
+ PerlinNoise noise;
- glGenTextures(1, &noise_texture_lq_lite);
- glBindTexture(GL_TEXTURE_2D, noise_texture_lq_lite);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_lq_lite);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- textureManager->setTexture("noise_lq_lite", noise_texture_lq_lite, 32, 32);
+ glGenTextures(1, &noise_texture_lq_lite);
+ glBindTexture(GL_TEXTURE_2D, noise_texture_lq_lite);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_lq_lite);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ textureManager->setTexture("noise_lq_lite", noise_texture_lq_lite, 32, 32);
- glGenTextures(1, &noise_texture_lq);
- glBindTexture(GL_TEXTURE_2D, noise_texture_lq);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_lq);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- textureManager->setTexture("noise_lq", noise_texture_lq, 256, 256);
+ glGenTextures(1, &noise_texture_lq);
+ glBindTexture(GL_TEXTURE_2D, noise_texture_lq);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_lq);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ textureManager->setTexture("noise_lq", noise_texture_lq, 256, 256);
- glGenTextures(1, &noise_texture_mq);
- glBindTexture(GL_TEXTURE_2D, noise_texture_mq);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_mq);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- textureManager->setTexture("noise_mq", noise_texture_mq, 256, 256);
+ glGenTextures(1, &noise_texture_mq);
+ glBindTexture(GL_TEXTURE_2D, noise_texture_mq);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_mq);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ textureManager->setTexture("noise_mq", noise_texture_mq, 256, 256);
- glGenTextures(1, &noise_texture_hq);
- glBindTexture(GL_TEXTURE_2D, noise_texture_hq);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_hq);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- textureManager->setTexture("noise_hq", noise_texture_hq, 256, 256);
+ glGenTextures(1, &noise_texture_hq);
+ glBindTexture(GL_TEXTURE_2D, noise_texture_hq);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_hq);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ textureManager->setTexture("noise_hq", noise_texture_hq, 256, 256);
- glGenTextures(1, &noise_texture_perlin);
- glBindTexture(GL_TEXTURE_2D, noise_texture_perlin);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_perlin);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- textureManager->setTexture("noise_perlin", noise_texture_perlin, 512, 512);
+ glGenTextures(1, &noise_texture_perlin);
+ glBindTexture(GL_TEXTURE_2D, noise_texture_perlin);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_perlin);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ textureManager->setTexture("noise_perlin", noise_texture_perlin, 512, 512);
- /*
- glGenTextures( 1, &noise_texture_lq_vol );
- glBindTexture( GL_TEXTURE_3D, noise_texture_lq_vol );
- glTexImage3D(GL_TEXTURE_3D,0,4,32,32,32,0,GL_LUMINANCE,GL_FLOAT,noise.noise_lq_vol);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- textureManager->setTexture("noisevol_lq", noise_texture_lq_vol, 256, 256);
+ /*
+ glGenTextures( 1, &noise_texture_lq_vol );
+ glBindTexture( GL_TEXTURE_3D, noise_texture_lq_vol );
+ glTexImage3D(GL_TEXTURE_3D,0,4,32,32,32,0,GL_LUMINANCE,GL_FLOAT,noise.noise_lq_vol);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ textureManager->setTexture("noisevol_lq", noise_texture_lq_vol, 256, 256);
- glGenTextures( 1, &noise_texture_hq_vol );
- glBindTexture( GL_TEXTURE_3D, noise_texture_hq_vol );
- glTexImage3D(GL_TEXTURE_3D,0,4,32,32,32,0,GL_LUMINANCE,GL_FLOAT,noise.noise_hq_vol);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- textureManager->setTexture("noisevol_hq", noise_texture_hq_vol, 8, 8);
- */
+ glGenTextures( 1, &noise_texture_hq_vol );
+ glBindTexture( GL_TEXTURE_3D, noise_texture_hq_vol );
+ glTexImage3D(GL_TEXTURE_3D,0,4,32,32,32,0,GL_LUMINANCE,GL_FLOAT,noise.noise_hq_vol);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ textureManager->setTexture("noisevol_hq", noise_texture_hq_vol, 8, 8);
+ */
+}
+
+bool
+ShaderEngine::LoadCgProgram(Shader &shader)
+{
+ //if (p != NULL) cgDestroyProgram(p);
+ // p = NULL;
+ std::string program = shader.programSource;
+
+ if (program.length() > 0)
+ {
+ size_t found = program.rfind('}');
+ if (found != std::string::npos)
+ {
+ //std::cout << "last '}' found at: " << int(found) << std::endl;
+ program.replace(int(found), 1, "OUT.color.xyz=ret.xyz;\nOUT.color.w=1;\nreturn OUT;\n}");
+ }
+ else
+ return false;
+ found = program.rfind('{');
+ if (found != std::string::npos)
+ {
+ //std::cout << "first '{' found at: " << int(found) << std::endl;
+ program.replace(int(found), 1, "{\nfloat rad=getrad;\nfloat ang=getang;\n");
+ }
+ else
+ return false;
+ found = program.find("shader_body");
+ if (found != std::string::npos)
+ {
+ //std::cout << "first 'shader_body' found at: " << int(found) << std::endl;
+ program.replace(int(found), 11, "outtype projectm(float2 uv : TEXCOORD0)\n");
+ }
+ else
+ return false;
+
+ shader.textures.clear();
+
+ found = 0;
+ found = program.find("sampler_", found);
+ while (found != std::string::npos)
+ {
+ found += 8;
+ size_t end = program.find_first_of(" ;,\n\r)", found);
+
+ if (end != std::string::npos)
+ {
+ std::string sampler = program.substr((int) found, (int) end - found);
+ UserTexture* texture = new UserTexture(sampler);
+
+ texture->texID = textureManager->getTexture(texture->name);
+ if (texture->texID != 0)
+ {
+ texture->width = textureManager->getTextureWidth(texture->name);
+ texture->height = textureManager->getTextureHeight(texture->name);
+ }
+ else
+ {
+ if (sampler.substr(0, 4) == "rand")
+ {
+ std::string random_name = textureManager->getRandomTextureName(texture->name);
+
+ if (random_name.size() > 0)
+ {
+ texture->texID = textureManager->getTexture(random_name);
+ texture->width = textureManager->getTextureWidth(random_name);
+ texture->height = textureManager->getTextureHeight(random_name);
+ }
+ }
+ else
+ {
+ std::string extensions[6];
+ extensions[0] = ".jpg";
+ extensions[1] = ".dds";
+ extensions[2] = ".png";
+ extensions[3] = ".tga";
+ extensions[4] = ".bmp";
+ extensions[5] = ".dib";
+
+ for (int x = 0; x < 6; x++)
+ {
+ std::string filename = texture->name + extensions[x];
+
+ texture->texID = textureManager->getTexture(filename);
+ if (texture->texID != 0)
+ {
+ texture->width = textureManager->getTextureWidth(filename);
+ texture->height = textureManager->getTextureHeight(filename);
+ break;
+ }
+ }
+ }
+ }
+ if (texture->texID != 0 && shader.textures.find(texture->qname) == shader.textures.end())
+ shader.textures[texture->qname] = texture;
+ else
+ delete (texture);
+ }
+
+ found = program.find("sampler_", found);
+ }
+ textureManager->clearRandomTextures();
+
+ found = 0;
+ found = program.find("texsize_", found);
+ while (found != std::string::npos)
+ {
+ found += 8;
+ size_t end = program.find_first_of(" ;.,\n\r)", found);
+
+ if (end != std::string::npos)
+ {
+ std::string tex = program.substr((int) found, (int) end - found);
+ if (shader.textures.find(tex) != shader.textures.end())
+ {
+ UserTexture* texture = shader.textures[tex];
+ texture->texsizeDefined = true;
+ //std::cout << "texsize_" << tex << " found" << std::endl;
+ }
+ }
+ found = program.find("texsize_", found);
+ }
+
+ found = program.find("GetBlur3");
+ if (found != std::string::npos)
+ blur1_enabled = blur2_enabled = blur3_enabled = true;
+ else
+ {
+ found = program.find("GetBlur2");
+ if (found != std::string::npos)
+ blur1_enabled = blur2_enabled = true;
+ else
+ {
+ found = program.find("GetBlur1");
+ if (found != std::string::npos)
+ blur1_enabled = true;
+ }
+ }
+
+ std::string temp;
+
+ temp.append(cgTemplate);
+ temp.append(program);
+
+ //std::cout << "Cg: Compilation Results:" << std::endl << std::endl;
+ //std::cout << program << std::endl;
+
+ CGprogram p = cgCreateProgram(myCgContext, CG_SOURCE, temp.c_str(),//temp.c_str(),
+ myCgProfile, "projectm", NULL);
+
+ checkForCgCompileError("creating shader program");
+ if (p == NULL)
+ return false;
+
+ cgGLLoadProgram(p);
+
+ if (checkForCgCompileError("loading shader program"))
+ {
+ p = NULL;
+ return false;
+ }
+
+ programs[&shader] = p;
+
+ return true;
+ }
+ else
+ return false;
+}
+
+bool
+ShaderEngine::checkForCgCompileError(const char *situation)
+{
+ CGerror error;
+ const char *string = cgGetLastErrorString(&error);
+
+ error = cgGetError();
+ if (error != CG_NO_ERROR)
+ {
+ std::cout << "Cg: Compilation Error" << std::endl;
+ std::cout << "Cg: %" << situation << " - " << string << std::endl;
+ if (error == CG_COMPILER_ERROR)
+ {
+ std::cout << "Cg: " << cgGetLastListing(myCgContext) << std::endl;
+ }
+ return true;
+ }
+
+ return false;
+}
+
+void
+ShaderEngine::checkForCgError(const char *situation)
+{
+ CGerror error;
+ const char *string = cgGetLastErrorString(&error);
+
+ if (error != CG_NO_ERROR)
+ {
+ std::cout << "Cg: %" << situation << " - " << string << std::endl;
+ if (error == CG_COMPILER_ERROR)
+ {
+ std::cout << "Cg: " << cgGetLastListing(myCgContext) << std::endl;
+ }
+ exit(1);
+ }
+}
+
+void
+ShaderEngine::SetupCg()
+{
+ std::string line;
+ std::ifstream myfile(CMAKE_INSTALL_PREFIX "/share/projectM/shaders/projectM.cg");
+
+ if (myfile.is_open())
+ {
+ while (!myfile.eof())
+ {
+ std::getline(myfile, line);
+ cgTemplate.append(line + "\n");
+ }
+ myfile.close();
+ }
+ else
+ std::cout << "Unable to load shader template \"" << CMAKE_INSTALL_PREFIX "/share/projectM/shaders/projectM.cg\"" << std::endl;
+
+ std::ifstream myfile2(CMAKE_INSTALL_PREFIX "/share/projectM/shaders/blur.cg");
+ if (myfile2.is_open())
+ {
+ while (!myfile2.eof())
+ {
+ std::getline(myfile2, line);
+ blurProgram.append(line + "\n");
+ }
+ myfile2.close();
+ }
+ else
+ std::cout << "Unable to load blur template" << std::endl;
+
+ myCgContext = cgCreateContext();
+ checkForCgError("creating context");
+ cgGLSetDebugMode(CG_FALSE);
+ cgSetParameterSettingMode(myCgContext, CG_DEFERRED_PARAMETER_SETTING);
+
+ myCgProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
+
+ // HACK breaks with buggy ati video drivers such as my own
+ // -carmelo.piccione@gmail.com 7/26/2010
+ //cgGLSetOptimalOptions(myCgProfile);
+ checkForCgError("selecting fragment profile");
+
+ profileName = cgGetProfileString(myCgProfile);
+ std::cout << "Cg: Initialized profile: " << profileName << std::endl;
+ //std::cout<< blurProgram.c_str()<<std::endl;
+ blur1Program = cgCreateProgram(myCgContext, CG_SOURCE, blurProgram.c_str(), myCgProfile, "blur1", NULL);
+
+ checkForCgCompileError("creating blur1 program");
+ if (blur1Program == NULL)
+ exit(1);
+ cgGLLoadProgram(blur1Program);
+
+ checkForCgError("loading blur1 program");
+
+ blur2Program = cgCreateProgram(myCgContext, CG_SOURCE, blurProgram.c_str(), myCgProfile, "blurVert", NULL);
+
+ checkForCgCompileError("creating blur2 program");
+ if (blur2Program == NULL)
+ exit(1);
+ cgGLLoadProgram(blur2Program);
+
+ checkForCgError("loading blur2 program");
}
-bool ShaderEngine::LoadCgProgram(Shader &shader)
+void
+ShaderEngine::SetupCgVariables(CGprogram program, const Pipeline &pipeline, const PipelineContext &context)
{
- //if (p != NULL) cgDestroyProgram(p);
- //p = NULL;
- std::string program = shader.programSource;
- if (program.length() > 0)
- {
- size_t found = program.rfind('}');
- if (found != std::string::npos)
- {
- //std::cout << "last '}' found at: " << int(found) << std::endl;
- program.replace(int(found), 1, "OUT.color.xyz=ret.xyz;\nOUT.color.w=1;\nreturn OUT;\n}");
- }
- else
- return false;
- found = program.rfind('{');
- if (found != std::string::npos)
- {
- //std::cout << "first '{' found at: " << int(found) << std::endl;
- program.replace(int(found), 1, "{\nfloat rad=getrad;\nfloat ang=getang;\n");
- }
- else
- return false;
- found = program.find("shader_body");
- if (found != std::string::npos)
- {
- //std::cout << "first 'shader_body' found at: " << int(found) << std::endl;
- program.replace(int(found), 11, "outtype projectm(float2 uv : TEXCOORD0)\n");
- }
- else
- return false;
+ float slow_roam_cos[4] = { 0.5 + 0.5 * cos(context.time * 0.005), 0.5 + 0.5 * cos(context.time * 0.008), 0.5 + 0.5 * cos(context.time * 0.013), 0.5 + 0.5 * cos(context.time * 0.022) };
+ float roam_cos[4] = { 0.5 + 0.5 * cos(context.time * 0.3), 0.5 + 0.5 * cos(context.time * 1.3), 0.5 + 0.5 * cos(context.time * 5), 0.5 + 0.5 * cos(context.time * 20) };
+ float slow_roam_sin[4] = { 0.5 + 0.5 * sin(context.time * 0.005), 0.5 + 0.5 * sin(context.time * 0.008), 0.5 + 0.5 * sin(context.time * 0.013), 0.5 + 0.5 * sin(context.time * 0.022) };
+ float roam_sin[4] = { 0.5 + 0.5 * sin(context.time * 0.3), 0.5 + 0.5 * sin(context.time * 1.3), 0.5 + 0.5 * sin(context.time * 5), 0.5 + 0.5 * sin(context.time * 20) };
- shader.textures.clear();
+ cgGLSetParameter4fv(cgGetNamedParameter(program, "slow_roam_cos"), slow_roam_cos);
+ cgGLSetParameter4fv(cgGetNamedParameter(program, "roam_cos"), roam_cos);
+ cgGLSetParameter4fv(cgGetNamedParameter(program, "slow_roam_sin"), slow_roam_sin);
+ cgGLSetParameter4fv(cgGetNamedParameter(program, "roam_sin"), roam_sin);
- found = 0;
- found = program.find("sampler_", found);
- while (found != std::string::npos)
- {
- found += 8;
- size_t end = program.find_first_of(" ;,\n\r)", found);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "time"), context.time);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "rand_preset"), rand_preset[0], rand_preset[1], rand_preset[2], rand_preset[3]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "rand_frame"), (rand() % 100) * .01, (rand() % 100) * .01, (rand()% 100) * .01, (rand() % 100) * .01);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "fps"), context.fps);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "frame"), context.frame);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "progress"), context.progress);
- if (end != std::string::npos)
- {
+ cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_min"), pipeline.blur1n);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_max"), pipeline.blur1x);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_min"), pipeline.blur2n);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_max"), pipeline.blur2x);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_min"), pipeline.blur3n);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_max"), pipeline.blur3x);
- std::string sampler = program.substr((int) found, (int) end - found);
- UserTexture* texture = new UserTexture(sampler);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "bass"), beatDetect->bass);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "mid"), beatDetect->mid);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "treb"), beatDetect->treb);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "bass_att"), beatDetect->bass_att);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "mid_att"), beatDetect->mid_att);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "treb_att"), beatDetect->treb_att);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "vol"), beatDetect->vol);
+ cgGLSetParameter1f(cgGetNamedParameter(program, "vol_att"), beatDetect->vol);
- texture->texID = textureManager->getTexture(texture->name);
- if (texture->texID != 0)
- {
- texture->width = textureManager->getTextureWidth(texture->name);
- texture->height = textureManager->getTextureHeight(texture->name);
- }
- else
- {
- if (sampler.substr(0, 4) == "rand")
- {
- std::string random_name = textureManager->getRandomTextureName(texture->name);
- if (random_name.size() > 0)
- {
- texture->texID = textureManager->getTexture(random_name);
- texture->width = textureManager->getTextureWidth(random_name);
- texture->height = textureManager->getTextureHeight(random_name);
- }
- }
- else
- {
- std::string extensions[6];
- extensions[0] = ".jpg";
- extensions[1] = ".dds";
- extensions[2] = ".png";
- extensions[3] = ".tga";
- extensions[4] = ".bmp";
- extensions[5] = ".dib";
+ cgGLSetParameter4f(cgGetNamedParameter(program, "texsize"), texsize, texsize, 1 / (float) texsize, 1
+ / (float) texsize);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "aspect"), 1 / aspect, 1, aspect, 1);
- for (int x = 0; x < 6; x++)
- {
-
- std::string filename = texture->name + extensions[x];
- texture->texID = textureManager->getTexture(filename);
- if (texture->texID != 0)
- {
- texture->width = textureManager->getTextureWidth(filename);
- texture->height = textureManager->getTextureHeight(filename);
- break;
- }
- }
-
- }
- }
- if (texture->texID != 0 && shader.textures.find(texture->qname) == shader.textures.end())
- shader.textures[texture->qname] = texture;
-
- else
- delete (texture);
-
- }
-
- found = program.find("sampler_", found);
- }
- textureManager->clearRandomTextures();
-
- found = 0;
- found = program.find("texsize_", found);
- while (found != std::string::npos)
- {
- found += 8;
- size_t end = program.find_first_of(" ;.,\n\r)", found);
-
- if (end != std::string::npos)
- {
- std::string tex = program.substr((int) found, (int) end - found);
- if (shader.textures.find(tex) != shader.textures.end())
- {
- UserTexture* texture = shader.textures[tex];
- texture->texsizeDefined = true;
- //std::cout << "texsize_" << tex << " found" << std::endl;
- }
- }
- found = program.find("texsize_", found);
- }
-
- found = program.find("GetBlur3");
- if (found != std::string::npos)
- blur1_enabled = blur2_enabled = blur3_enabled = true;
- else
- {
- found = program.find("GetBlur2");
- if (found != std::string::npos)
- blur1_enabled = blur2_enabled = true;
- else
- {
- found = program.find("GetBlur1");
- if (found != std::string::npos)
- blur1_enabled = true;
- }
- }
-
- std::string temp;
-
- temp.append(cgTemplate);
- temp.append(program);
-
- //std::cout << "Cg: Compilation Results:" << std::endl << std::endl;
- //std::cout << program << std::endl;
-
- CGprogram p = cgCreateProgram(myCgContext, CG_SOURCE, temp.c_str(),//temp.c_str(),
- myCgProfile, "projectm", NULL);
-
- checkForCgCompileError("creating shader program");
- if (p == NULL)
- return false;
-
- cgGLLoadProgram(p);
-
- if (checkForCgCompileError("loading shader program"))
- {
- p = NULL;
- return false;
- }
-
- programs[&shader] = p;
-
- return true;
- }
- else
- return false;
+ if (blur1_enabled)
+ {
+ cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_blur1"), blur1_tex);
+ cgGLEnableTextureParameter(cgGetNamedParameter(program, "sampler_blur1"));
+ }
+ if (blur2_enabled)
+ {
+ cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_blur2"), blur2_tex);
+ cgGLEnableTextureParameter(cgGetNamedParameter(program, "sampler_blur2"));
+ }
+ if (blur3_enabled)
+ {
+ cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_blur3"), blur3_tex);
+ cgGLEnableTextureParameter(cgGetNamedParameter(program, "sampler_blur3"));
+ }
}
-bool ShaderEngine::checkForCgCompileError(const char *situation)
+void
+ShaderEngine::SetupUserTexture(CGprogram program, const UserTexture* texture)
{
- CGerror error;
- const char *string = cgGetLastErrorString(&error);
- error = cgGetError();
- if (error != CG_NO_ERROR)
- {
- std::cout << "Cg: Compilation Error" << std::endl;
- std::cout << "Cg: %" << situation << " - " << string << std::endl;
- if (error == CG_COMPILER_ERROR)
- {
- std::cout << "Cg: " << cgGetLastListing(myCgContext) << std::endl;
+ std::string samplerName = "sampler_" + texture->qname;
- }
- return true;
- }
+ CGparameter param = cgGetNamedParameter(program, samplerName.c_str());
+ checkForCgError("getting parameter");
+ cgGLSetTextureParameter(param, texture->texID);
+ checkForCgError("setting parameter");
+ cgGLEnableTextureParameter(param);
+ checkForCgError("enabling parameter");
+ //std::cout<<texture->texID<<" "<<samplerName<<std::endl;
- return false;
+ if (texture->texsizeDefined)
+ {
+ std::string texsizeName = "texsize_" + texture->name;
+ cgGLSetParameter4f (cgGetNamedParameter (program, texsizeName.c_str()),
+ texture->width, texture->height,
+ 1 / (float) texture->width, 1 / (float) texture->height);
+ checkForCgError("setting parameter texsize");
+ }
}
-void ShaderEngine::checkForCgError(const char *situation)
+void
+ShaderEngine::SetupUserTextureState( const UserTexture* texture)
{
- CGerror error;
- const char *string = cgGetLastErrorString(&error);
-
- if (error != CG_NO_ERROR)
- {
- std::cout << "Cg: %" << situation << " - " << string << std::endl;
- if (error == CG_COMPILER_ERROR)
- {
- std::cout << "Cg: " << cgGetLastListing(myCgContext) << std::endl;
- }
- exit(1);
- }
+ glBindTexture(GL_TEXTURE_2D, texture->texID);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->bilinear ? GL_LINEAR : GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->bilinear ? GL_LINEAR : GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->wrap ? GL_REPEAT : GL_CLAMP);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrap ? GL_REPEAT : GL_CLAMP);
}
-void ShaderEngine::SetupCg()
+void
+ShaderEngine::SetupCgQVariables(CGprogram program, const Pipeline &q)
{
- std::string line;
- std::ifstream myfile(CMAKE_INSTALL_PREFIX "/share/projectM/shaders/projectM.cg");
- if (myfile.is_open())
- {
- while (!myfile.eof())
- {
- std::getline(myfile, line);
- cgTemplate.append(line + "\n");
- }
- myfile.close();
- }
-
- else
- std::cout << "Unable to load shader template \"" << CMAKE_INSTALL_PREFIX "/share/projectM/shaders/projectM.cg\"" << std::endl;
-
- std::ifstream myfile2(CMAKE_INSTALL_PREFIX "/share/projectM/shaders/blur.cg");
- if (myfile2.is_open())
- {
- while (!myfile2.eof())
- {
- std::getline(myfile2, line);
- blurProgram.append(line + "\n");
- }
- myfile2.close();
- }
-
- else
- std::cout << "Unable to load blur template" << std::endl;
-
- myCgContext = cgCreateContext();
- checkForCgError("creating context");
- cgGLSetDebugMode(CG_FALSE);
- cgSetParameterSettingMode(myCgContext, CG_DEFERRED_PARAMETER_SETTING);
-
- myCgProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
-
- // HACK breaks with buggy ati video drivers such as my own
- // -carmelo.piccione@gmail.com 7/26/2010
- //cgGLSetOptimalOptions(myCgProfile);
- checkForCgError("selecting fragment profile");
-
- profileName = cgGetProfileString(myCgProfile);
- std::cout << "Cg: Initialized profile: " << profileName << std::endl;
-//std::cout<< blurProgram.c_str()<<std::endl;
- blur1Program = cgCreateProgram(myCgContext, CG_SOURCE, blurProgram.c_str(), myCgProfile, "blur1", NULL);
-
- checkForCgCompileError("creating blur1 program");
- if (blur1Program == NULL)
- exit(1);
- cgGLLoadProgram(blur1Program);
-
- checkForCgError("loading blur1 program");
-
- blur2Program = cgCreateProgram(myCgContext, CG_SOURCE, blurProgram.c_str(), myCgProfile, "blurVert", NULL);
-
- checkForCgCompileError("creating blur2 program");
- if (blur2Program == NULL)
- exit(1);
- cgGLLoadProgram(blur2Program);
-
- checkForCgError("loading blur2 program");
-
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qa"), q.q[0], q.q[1], q.q[2], q.q[3]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qb"), q.q[4], q.q[5], q.q[6], q.q[7]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qc"), q.q[8], q.q[9], q.q[10], q.q[11]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qd"), q.q[12], q.q[13], q.q[14], q.q[15]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qe"), q.q[16], q.q[17], q.q[18], q.q[19]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qf"), q.q[20], q.q[21], q.q[22], q.q[23]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qg"), q.q[24], q.q[25], q.q[26], q.q[27]);
+ cgGLSetParameter4f(cgGetNamedParameter(program, "_qh"), q.q[28], q.q[29], q.q[30], q.q[31]);
}
-void ShaderEngine::SetupCgVariables(CGprogram program, const Pipeline &pipeline, const PipelineContext &context)
+void
+ShaderEngine::setAspect(float aspect)
{
+ this->aspect = aspect;
+}
+void
+ShaderEngine::RenderBlurTextures(const Pipeline &pipeline, const PipelineContext &pipelineContext, const int texsize)
+{
+ if (blur1_enabled || blur2_enabled || blur3_enabled)
+ {
+ float tex[4][2] =
+ {
+ { 0, 1 },
+ { 0, 0 },
+ { 1, 0 },
+ { 1, 1 } };
- float slow_roam_cos[4] = { 0.5 + 0.5 * cos(context.time * 0.005), 0.5 + 0.5 * cos(context.time * 0.008), 0.5 + 0.5 * cos(context.time * 0.013), 0.5 + 0.5 * cos(context.time * 0.022) };
- float roam_cos[4] = { 0.5 + 0.5 * cos(context.time * 0.3), 0.5 + 0.5 * cos(context.time * 1.3), 0.5 + 0.5 * cos(context.time * 5), 0.5 + 0.5 * cos(context.time * 20) };
- float slow_roam_sin[4] = { 0.5 + 0.5 * sin(context.time * 0.005), 0.5 + 0.5 * sin(context.time * 0.008), 0.5 + 0.5 * sin(context.time * 0.013), 0.5 + 0.5 * sin(context.time * 0.022) };
- float roam_sin[4] = { 0.5 + 0.5 * sin(context.time * 0.3), 0.5 + 0.5 * sin(context.time * 1.3), 0.5 + 0.5 * sin(context.time * 5), 0.5 + 0.5 * sin(context.time * 20) };
+ glBlendFunc(GL_ONE, GL_ZERO);
+ glColor4f(1.0, 1.0, 1.0, 1.0f);
- cgGLSetParameter4fv(cgGetNamedParameter(program, "slow_roam_cos"), slow_roam_cos);
- cgGLSetParameter4fv(cgGetNamedParameter(program, "roam_cos"), roam_cos);
- cgGLSetParameter4fv(cgGetNamedParameter(program, "slow_roam_sin"), slow_roam_sin);
- cgGLSetParameter4fv(cgGetNamedParameter(program, "roam_sin"), roam_sin);
+ glBindTexture(GL_TEXTURE_2D, mainTextureId);
+ glEnable(GL_TEXTURE_2D);
- cgGLSetParameter1f(cgGetNamedParameter(program, "time"), context.time);
- cgGLSetParameter4f(cgGetNamedParameter(program, "rand_preset"), rand_preset[0], rand_preset[1], rand_preset[2], rand_preset[3]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "rand_frame"), (rand() % 100) * .01, (rand() % 100) * .01, (rand()% 100) * .01, (rand() % 100) * .01);
- cgGLSetParameter1f(cgGetNamedParameter(program, "fps"), context.fps);
- cgGLSetParameter1f(cgGetNamedParameter(program, "frame"), context.frame);
- cgGLSetParameter1f(cgGetNamedParameter(program, "progress"), context.progress);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, 0, tex);
- cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_min"), pipeline.blur1n);
- cgGLSetParameter1f(cgGetNamedParameter(program, "blur1_max"), pipeline.blur1x);
- cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_min"), pipeline.blur2n);
- cgGLSetParameter1f(cgGetNamedParameter(program, "blur2_max"), pipeline.blur2x);
- cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_min"), pipeline.blur3n);
- cgGLSetParameter1f(cgGetNamedParameter(program, "blur3_max"), pipeline.blur3x);
+ cgGLEnableProfile(myCgProfile);
+ checkForCgError("enabling profile");
- cgGLSetParameter1f(cgGetNamedParameter(program, "bass"), beatDetect->bass);
- cgGLSetParameter1f(cgGetNamedParameter(program, "mid"), beatDetect->mid);
- cgGLSetParameter1f(cgGetNamedParameter(program, "treb"), beatDetect->treb);
- cgGLSetParameter1f(cgGetNamedParameter(program, "bass_att"), beatDetect->bass_att);
- cgGLSetParameter1f(cgGetNamedParameter(program, "mid_att"), beatDetect->mid_att);
- cgGLSetParameter1f(cgGetNamedParameter(program, "treb_att"), beatDetect->treb_att);
- cgGLSetParameter1f(cgGetNamedParameter(program, "vol"), beatDetect->vol);
- cgGLSetParameter1f(cgGetNamedParameter(program, "vol_att"), beatDetect->vol);
+ if (blur1_enabled)
+ {
+ cgGLSetParameter4f (cgGetNamedParameter(blur1Program, "srctexsize"), texsize/2, texsize/2,
+ 2 / (float) texsize, 2 / (float) texsize);
+ cgGLSetParameter4f (cgGetNamedParameter(blur2Program, "srctexsize"), texsize/2 , texsize/2,
+ 2 / (float) texsize, 2 / (float) texsize);
- cgGLSetParameter4f(cgGetNamedParameter(program, "texsize"), texsize, texsize, 1 / (float) texsize, 1
- / (float) texsize);
- cgGLSetParameter4f(cgGetNamedParameter(program, "aspect"), 1 / aspect, 1, aspect, 1);
- if (blur1_enabled)
- {
- cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_blur1"), blur1_tex);
- cgGLEnableTextureParameter(cgGetNamedParameter(program, "sampler_blur1"));
- }
- if (blur2_enabled)
- {
- cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_blur2"), blur2_tex);
- cgGLEnableTextureParameter(cgGetNamedParameter(program, "sampler_blur2"));
- }
- if (blur3_enabled)
- {
- cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_blur3"), blur3_tex);
- cgGLEnableTextureParameter(cgGetNamedParameter(program, "sampler_blur3"));
- }
+ float pointsold[4][2] =
+ {
+ { 0, 1 },
+ { 0, 0 },
+ { 1, 0 },
+ { 1, 1 } };
+ float points[4][2] =
+ {
+ { 0, 0.5 },
+ { 0, 0 },
+ { 0.5, 0 },
+ { 0.5, 0.5 } };
+ cgGLBindProgram(blur1Program);
+ checkForCgError("binding blur1 program");
+
+ glVertexPointer(2, GL_FLOAT, 0, points);
+ glBlendFunc(GL_ONE,GL_ZERO);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+
+ glBindTexture(GL_TEXTURE_2D, blur1_tex);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/2, texsize/2);
+ }
+
+ if (blur2_enabled)
+ {
+ cgGLSetParameter4f (cgGetNamedParameter(blur1Program, "srctexsize"), texsize/2, texsize/2,
+ 2 / (float) texsize, 2 / (float) texsize);
+ cgGLSetParameter4f (cgGetNamedParameter(blur2Program, "srctexsize"), texsize/2, texsize/2,
+ 2 / (float) texsize, 2 / (float) texsize);
+
+
+ float points[4][2] =
+ {
+ { 0, 0.25 },
+ { 0, 0 },
+ { 0.25, 0 },
+ { 0.25, 0.25 } };
+
+ glVertexPointer(2, GL_FLOAT, 0, points);
+ glBlendFunc(GL_ONE,GL_ZERO);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+
+
+ glBindTexture(GL_TEXTURE_2D, blur2_tex);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/4, texsize/4);
+ }
+
+ if (blur3_enabled)
+ {
+ cgGLSetParameter4f (cgGetNamedParameter(blur2Program, "srctexsize"), texsize / 4, texsize / 4,
+ 4 / (float) texsize, 4 / (float) texsize);
+ cgGLSetParameter4f (cgGetNamedParameter(blur2Program, "srctexsize"), texsize / 4, texsize / 4,
+ 4 / (float) texsize, 4 / (float) texsize);
+ float points[4][2] =
+ {
+ { 0, 0.125 },
+ { 0, 0 },
+ { 0.125, 0 },
+ { 0.125, 0.125 } };
+
+ glVertexPointer(2, GL_FLOAT, 0, points);
+ glBlendFunc(GL_ONE,GL_ZERO);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+
+
+ glBindTexture(GL_TEXTURE_2D, blur3_tex);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/8, texsize/8);
+ }
+
+
+ cgGLUnbindProgram(myCgProfile);
+ checkForCgError("unbinding blur2 program");
+
+
+ cgGLDisableProfile(myCgProfile);
+ checkForCgError("disabling blur profile");
+
+ glDisable(GL_TEXTURE_2D);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
}
-void ShaderEngine::SetupUserTexture(CGprogram program, const UserTexture* texture)
+void
+ShaderEngine::loadShader(Shader &shader)
{
- std::string samplerName = "sampler_" + texture->qname;
-
- CGparameter param = cgGetNamedParameter(program, samplerName.c_str());
- checkForCgError("getting parameter");
- cgGLSetTextureParameter(param, texture->texID);
- checkForCgError("setting parameter");
- cgGLEnableTextureParameter(param);
- checkForCgError("enabling parameter");
- //std::cout<<texture->texID<<" "<<samplerName<<std::endl;
-
- if (texture->texsizeDefined)
- {
- std::string texsizeName = "texsize_" + texture->name;
- cgGLSetParameter4f(cgGetNamedParameter(program, texsizeName.c_str()), texture->width, texture->height, 1
- / (float) texture->width, 1 / (float) texture->height);
- checkForCgError("setting parameter texsize");
- }
+ if (shader.enabled)
+ {
+ cgDestroyProgram(programs[&shader]);
+ programs.erase(&shader);
+ }
+ shader.enabled = LoadCgProgram(shader);
}
-void ShaderEngine::SetupUserTextureState( const UserTexture* texture)
+void
+ShaderEngine::disableShader()
{
- glBindTexture(GL_TEXTURE_2D, texture->texID);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->bilinear ? GL_LINEAR : GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->bilinear ? GL_LINEAR : GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->wrap ? GL_REPEAT : GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrap ? GL_REPEAT : GL_CLAMP);
+ if (enabled)
+ {
+ cgGLUnbindProgram(myCgProfile);
+ checkForCgError("disabling fragment profile");
+ cgGLDisableProfile(myCgProfile);
+ checkForCgError("disabling fragment profile");
+ }
+ enabled = false;
}
-void ShaderEngine::SetupCgQVariables(CGprogram program, const Pipeline &q)
+void
+ShaderEngine::enableShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext)
{
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qa"), q.q[0], q.q[1], q.q[2], q.q[3]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qb"), q.q[4], q.q[5], q.q[6], q.q[7]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qc"), q.q[8], q.q[9], q.q[10], q.q[11]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qd"), q.q[12], q.q[13], q.q[14], q.q[15]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qe"), q.q[16], q.q[17], q.q[18], q.q[19]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qf"), q.q[20], q.q[21], q.q[22], q.q[23]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qg"), q.q[24], q.q[25], q.q[26], q.q[27]);
- cgGLSetParameter4f(cgGetNamedParameter(program, "_qh"), q.q[28], q.q[29], q.q[30], q.q[31]);
+ enabled = false;
+ if (shader.enabled)
+ {
+
+ for (std::map<std::string, UserTexture*>::const_iterator pos = shader.textures.begin();
+ pos != shader.textures.end();
+ ++pos)
+ SetupUserTextureState( pos->second);
+
+
+ CGprogram program = programs[&shader];
+ for (std::map<std::string, UserTexture*>::const_iterator pos = shader.textures.begin();
+ pos != shader.textures.end();
+ ++pos)
+ SetupUserTexture(program, pos->second);
+
+ cgGLEnableProfile(myCgProfile);
+ checkForCgError("enabling warp profile");
+
+ cgGLBindProgram(program);
+ checkForCgError("binding warp program");
+
+ SetupCgVariables(program, pipeline, pipelineContext);
+ SetupCgQVariables(program, pipeline);
+
+ enabled = true;
+ }
}
-void ShaderEngine::setAspect(float aspect)
+void
+ShaderEngine::reset()
{
- this->aspect = aspect;
-}
-void ShaderEngine::RenderBlurTextures(const Pipeline &pipeline, const PipelineContext &pipelineContext,
- const int texsize)
-{
- if (blur1_enabled || blur2_enabled || blur3_enabled)
- {
- float tex[4][2] =
- {
- { 0, 1 },
- { 0, 0 },
- { 1, 0 },
- { 1, 1 } };
-
- glBlendFunc(GL_ONE, GL_ZERO);
- glColor4f(1.0, 1.0, 1.0, 1.0f);
-
- glBindTexture(GL_TEXTURE_2D, mainTextureId);
- glEnable(GL_TEXTURE_2D);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, 0, tex);
-
- cgGLEnableProfile(myCgProfile);
- checkForCgError("enabling profile");
-
- if (blur1_enabled)
- {
- cgGLSetParameter4f(cgGetNamedParameter(blur1Program, "srctexsize"), texsize/2, texsize/2, 2 / (float) texsize,
- 2 / (float) texsize);
- cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize/2 , texsize/2, 2 / (float) texsize,
- 2 / (float) texsize);
-
-
-
- float pointsold[4][2] =
- {
- { 0, 1 },
- { 0, 0 },
- { 1, 0 },
- { 1, 1 } };
- float points[4][2] =
- {
- { 0, 0.5 },
- { 0, 0 },
- { 0.5, 0 },
- { 0.5, 0.5 } };
-
- cgGLBindProgram(blur1Program);
- checkForCgError("binding blur1 program");
-
- glVertexPointer(2, GL_FLOAT, 0, points);
- glBlendFunc(GL_ONE,GL_ZERO);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-
- glBindTexture(GL_TEXTURE_2D, blur1_tex);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/2, texsize/2);
-
-
- }
-
- if (blur2_enabled)
- {
- cgGLSetParameter4f(cgGetNamedParameter(blur1Program, "srctexsize"), texsize/2, texsize/2, 2 / (float) texsize,
- 2 / (float) texsize);
- cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize/2, texsize/2, 2 / (float) texsize,
- 2 / (float) texsize);
-
-
-
- float points[4][2] =
- {
- { 0, 0.25 },
- { 0, 0 },
- { 0.25, 0 },
- { 0.25, 0.25 } };
-
- glVertexPointer(2, GL_FLOAT, 0, points);
- glBlendFunc(GL_ONE,GL_ZERO);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-
-
- glBindTexture(GL_TEXTURE_2D, blur2_tex);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/4, texsize/4);
-
-
- }
-
- if (blur3_enabled)
- {
- cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize/4, texsize/4, 4 / (float) texsize,
- 4/ (float) texsize);
- cgGLSetParameter4f(cgGetNamedParameter(blur2Program, "srctexsize"), texsize / 4, texsize / 4, 4
- / (float) texsize, 4 / (float) texsize);
- float points[4][2] =
- {
- { 0, 0.125 },
- { 0, 0 },
- { 0.125, 0 },
- { 0.125, 0.125 } };
-
- glVertexPointer(2, GL_FLOAT, 0, points);
- glBlendFunc(GL_ONE,GL_ZERO);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-
-
- glBindTexture(GL_TEXTURE_2D, blur3_tex);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize/8, texsize/8);
-
-
- }
-
-
- cgGLUnbindProgram(myCgProfile);
- checkForCgError("unbinding blur2 program");
-
-
- cgGLDisableProfile(myCgProfile);
- checkForCgError("disabling blur profile");
-
- glDisable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- }
-}
-
-void ShaderEngine::loadShader(Shader &shader)
-{
- if (shader.enabled)
- {
- cgDestroyProgram(programs[&shader]);
- programs.erase(&shader);
- }
- shader.enabled = LoadCgProgram(shader);
-}
-
-void ShaderEngine::disableShader()
-{
- if (enabled)
- {
- cgGLUnbindProgram(myCgProfile);
- checkForCgError("disabling fragment profile");
- cgGLDisableProfile(myCgProfile);
- checkForCgError("disabling fragment profile");
- }
- enabled = false;
-}
-
-void ShaderEngine::enableShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext)
-{
- enabled = false;
- if (shader.enabled)
- {
-
- for (std::map<std::string, UserTexture*>::const_iterator pos = shader.textures.begin(); pos != shader.textures.end(); ++pos)
- SetupUserTextureState( pos->second);
-
-
- CGprogram program = programs[&shader];
- for (std::map<std::string, UserTexture*>::const_iterator pos = shader.textures.begin(); pos
- != shader.textures.end(); ++pos)
- SetupUserTexture(program, pos->second);
-
- cgGLEnableProfile(myCgProfile);
- checkForCgError("enabling warp profile");
-
- cgGLBindProgram(program);
- checkForCgError("binding warp program");
-
- SetupCgVariables(program, pipeline, pipelineContext);
- SetupCgQVariables(program, pipeline);
-
- enabled = true;
- }
-}
-
-void ShaderEngine::reset()
-{
- rand_preset[0] = (rand() % 100) * .01;
- rand_preset[1] = (rand() % 100) * .01;
- rand_preset[2] = (rand() % 100) * .01;
- rand_preset[3] = (rand() % 100) * .01;
+ rand_preset[0] = (rand() % 100) * .01;
+ rand_preset[1] = (rand() % 100) * .01;
+ rand_preset[2] = (rand() % 100) * .01;
+ rand_preset[3] = (rand() % 100) * .01;
}
#endif
diff --git a/src/libprojectM/Renderer/ShaderEngine.hpp b/src/libprojectM/Renderer/ShaderEngine.hpp
index 7542896..0789411 100644
--- a/src/libprojectM/Renderer/ShaderEngine.hpp
+++ b/src/libprojectM/Renderer/ShaderEngine.hpp
@@ -4,7 +4,6 @@
* Created on: Jul 18, 2008
* Author: pete
*/
-
#ifndef SHADERENGINE_HPP_
#define SHADERENGINE_HPP_
@@ -38,11 +37,11 @@
#include <iostream>
#include <map>
#include "Shader.hpp"
+
+
class ShaderEngine
{
#ifdef USE_CG
-
-
unsigned int mainTextureId;
int texsize;
float aspect;
@@ -67,7 +66,7 @@
float rand_preset[4];
CGcontext myCgContext;
- CGprofile myCgProfile;
+ CGprofile myCgProfile;
CGprogram blur1Program;
CGprogram blur2Program;
@@ -75,39 +74,35 @@
std::map<Shader*,CGprogram> programs;
- std::string cgTemplate;
- std::string blurProgram;
+ std::string cgTemplate;
+ std::string blurProgram;
- bool LoadCgProgram(Shader &shader);
- bool checkForCgCompileError(const char *situation);
- void checkForCgError(const char *situation);
+ bool LoadCgProgram(Shader &shader);
+ bool checkForCgCompileError(const char *situation);
+ void checkForCgError(const char *situation);
- void SetupCg();
- void SetupCgVariables(CGprogram program, const Pipeline &pipeline, const PipelineContext &pipelineContext);
- void SetupCgQVariables(CGprogram program, const Pipeline &pipeline);
+ void SetupCg();
+ void SetupCgVariables(CGprogram program, const Pipeline &pipeline, const PipelineContext &pipelineContext);
+ void SetupCgQVariables(CGprogram program, const Pipeline &pipeline);
- void SetupUserTexture(CGprogram program, const UserTexture* texture);
- void SetupUserTextureState(const UserTexture* texture);
-
-
-
+ void SetupUserTexture(CGprogram program, const UserTexture* texture);
+ void SetupUserTextureState(const UserTexture* texture);
#endif
+
public:
- ShaderEngine();
- virtual ~ShaderEngine();
+ ShaderEngine();
+ virtual ~ShaderEngine();
#ifdef USE_CG
- void RenderBlurTextures(const Pipeline &pipeline, const PipelineContext &pipelineContext, const int texsize);
- void loadShader(Shader &shader);
+ void RenderBlurTextures(const Pipeline &pipeline, const PipelineContext &pipelineContext, const int texsize);
+ void loadShader(Shader &shader);
- void setParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect, TextureManager *textureManager);
- void enableShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext);
- void disableShader();
- void reset();
- void setAspect(float aspect);
- std::string profileName;
-
+ void setParams(const int texsize, const unsigned int texId, const float aspect, BeatDetect *beatDetect, TextureManager *textureManager);
+ void enableShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext);
+ void disableShader();
+ void reset();
+ void setAspect(float aspect);
+ std::string profileName;
#endif
};
#endif /* SHADERENGINE_HPP_ */
-
diff --git a/src/libprojectM/Renderer/TextureManager.cpp b/src/libprojectM/Renderer/TextureManager.cpp
index 0cc4da3..6615cd4 100644
--- a/src/libprojectM/Renderer/TextureManager.cpp
+++ b/src/libprojectM/Renderer/TextureManager.cpp
@@ -35,41 +35,42 @@
TextureManager::TextureManager(const std::string _presetURL): presetURL(_presetURL)
{
#ifdef USE_DEVIL
-ilInit();
-iluInit();
-ilutInit();
-ilutRenderer(ILUT_OPENGL);
+ ilInit();
+ iluInit();
+ ilutInit();
+ ilutRenderer(ILUT_OPENGL);
#endif
- Preload();
- loadTextureDir();
+ Preload();
+ loadTextureDir();
}
TextureManager::~TextureManager()
{
- Clear();
+ Clear();
}
-void TextureManager::Preload()
+void
+TextureManager::Preload()
{
-
#ifdef USE_DEVIL
- ILuint image;
- ilGenImages(1, &image);
- ilBindImage(image);
- ilLoadL(IL_TYPE_UNKNOWN,(ILvoid*) M_data, M_bytes);
- GLuint tex = ilutGLBindTexImage();
-#else
- unsigned int tex = SOIL_load_OGL_texture_from_memory(
- M_data,
- M_bytes,
- SOIL_LOAD_AUTO,
- SOIL_CREATE_NEW_ID,
+ ILuint image;
- SOIL_FLAG_POWER_OF_TWO
- | SOIL_FLAG_MULTIPLY_ALPHA
- // | SOIL_FLAG_COMPRESS_TO_DXT
- );
+ ilGenImages(1, &image);
+ ilBindImage(image);
+ ilLoadL(IL_TYPE_UNKNOWN,(ILvoid*) M_data, M_bytes);
+ GLuint tex = ilutGLBindTexImage();
+#else
+ unsigned int tex = SOIL_load_OGL_texture_from_memory (
+ M_data,
+ M_bytes,
+ SOIL_LOAD_AUTO,
+ SOIL_CREATE_NEW_ID,
+
+ SOIL_FLAG_POWER_OF_TWO
+ | SOIL_FLAG_MULTIPLY_ALPHA
+ // | SOIL_FLAG_COMPRESS_TO_DXT
+ );
#endif
textures["M.tga"]=tex;
@@ -78,16 +79,16 @@
ilLoadL(IL_TYPE_UNKNOWN,(ILvoid*) project_data,project_bytes);
tex = ilutGLBindTexImage();
#else
- tex = SOIL_load_OGL_texture_from_memory(
- project_data,
- project_bytes,
- SOIL_LOAD_AUTO,
- SOIL_CREATE_NEW_ID,
+ tex = SOIL_load_OGL_texture_from_memory (
+ project_data,
+ project_bytes,
+ SOIL_LOAD_AUTO,
+ SOIL_CREATE_NEW_ID,
- SOIL_FLAG_POWER_OF_TWO
- | SOIL_FLAG_MULTIPLY_ALPHA
- //| SOIL_FLAG_COMPRESS_TO_DXT
- );
+ SOIL_FLAG_POWER_OF_TWO
+ | SOIL_FLAG_MULTIPLY_ALPHA
+ //| SOIL_FLAG_COMPRESS_TO_DXT
+ );
#endif
textures["project.tga"]=tex;
@@ -97,184 +98,192 @@
tex = ilutGLBindTexImage();
#else
tex = SOIL_load_OGL_texture_from_memory(
- headphones_data,
- headphones_bytes,
- SOIL_LOAD_AUTO,
- SOIL_CREATE_NEW_ID,
+ headphones_data,
+ headphones_bytes,
+ SOIL_LOAD_AUTO,
+ SOIL_CREATE_NEW_ID,
- SOIL_FLAG_POWER_OF_TWO
- | SOIL_FLAG_MULTIPLY_ALPHA
- // | SOIL_FLAG_COMPRESS_TO_DXT
- );
+ SOIL_FLAG_POWER_OF_TWO
+ | SOIL_FLAG_MULTIPLY_ALPHA
+ // | SOIL_FLAG_COMPRESS_TO_DXT
+ );
#endif
textures["headphones.tga"]=tex;
}
-void TextureManager::Clear()
+void
+TextureManager::Clear()
{
-
-
- for(std::map<std::string, GLuint>::const_iterator iter = textures.begin(); iter != textures.end(); iter++)
- {
- glDeleteTextures(1,&iter->second);
- }
+ for(std::map<std::string, GLuint>::const_iterator iter = textures.begin();
+ iter != textures.end();
+ iter++)
+ {
+ glDeleteTextures(1,&iter->second);
+ }
textures.clear();
}
-void TextureManager::setTexture(const std::string name, const unsigned int texId, const int width, const int height)
+void
+TextureManager::setTexture(const std::string name, const unsigned int texId, const int width, const int height)
{
- textures[name] = texId;
- widths[name] = width;
- heights[name] = height;
+ textures[name] = texId;
+ widths[name] = width;
+ heights[name] = height;
}
-//void TextureManager::unloadTextures(const PresetOutputs::cshape_container &shapes)
+//void
+//TextureManager::unloadTextures(const PresetOutputs::cshape_container &shapes)
//{
/*
- for (PresetOutputs::cshape_container::const_iterator pos = shapes.begin();
- pos != shapes.end(); ++pos)
+ for (PresetOutputs::cshape_container::const_iterator pos = shapes.begin();
+ pos != shapes.end();
+ ++pos)
+ {
+
+ if( (*pos)->enabled==1)
{
+ if ( (*pos)->textured)
+ {
+ std::string imageUrl = (*pos)->getImageUrl();
- if( (*pos)->enabled==1)
- {
-
- if ( (*pos)->textured)
- {
- std::string imageUrl = (*pos)->getImageUrl();
- if (imageUrl != "")
- {
- std::string fullUrl = presetURL + "/" + imageUrl;
- ReleaseTexture(LoadTexture(fullUrl.c_str()));
- }
- }
- }
+ if (imageUrl != "")
+ {
+ std::string fullUrl = presetURL + "/" + imageUrl;
+ ReleaseTexture(LoadTexture(fullUrl.c_str()));
+ }
+ }
}
+ }
*/
//}
-GLuint TextureManager::getTexture(const std::string filename)
+GLuint
+TextureManager::getTexture(const std::string filename)
{
- std::string fullURL = presetURL + PATH_SEPARATOR + filename;
- return getTextureFullpath(filename,fullURL);
+ std::string fullURL = presetURL + PATH_SEPARATOR + filename;
+ return getTextureFullpath(filename,fullURL);
}
-GLuint TextureManager::getTextureFullpath(const std::string filename, const std::string imageURL)
+GLuint
+TextureManager::getTextureFullpath(const std::string filename, const std::string imageURL)
{
-
- if (textures.find(filename)!= textures.end())
- {
- return textures[filename];
- }
- else
- {
-
+ if (textures.find(filename)!= textures.end())
+ {
+ return textures[filename];
+ }
+ else
+ {
#ifdef USE_DEVIL
- GLuint tex = ilutGLLoadImage((char *)imageURL.c_str());
+ GLuint tex = ilutGLLoadImage((char *)imageURL.c_str());
#else
- int width, height;
+ int width, height;
- unsigned int tex = SOIL_load_OGL_texture_size(
- imageURL.c_str(),
- SOIL_LOAD_AUTO,
- SOIL_CREATE_NEW_ID,
+ unsigned int tex = SOIL_load_OGL_texture_size (
+ imageURL.c_str(),
+ SOIL_LOAD_AUTO,
+ SOIL_CREATE_NEW_ID,
- //SOIL_FLAG_POWER_OF_TWO
- // SOIL_FLAG_MIPMAPS
- SOIL_FLAG_MULTIPLY_ALPHA
- //| SOIL_FLAG_COMPRESS_TO_DXT
- //| SOIL_FLAG_DDS_LOAD_DIRECT
- ,&width,&height);
+ //SOIL_FLAG_POWER_OF_TWO
+ // SOIL_FLAG_MIPMAPS
+ SOIL_FLAG_MULTIPLY_ALPHA
+ //| SOIL_FLAG_COMPRESS_TO_DXT
+ //| SOIL_FLAG_DDS_LOAD_DIRECT
+ ,&width,&height
+ );
#endif
- textures[filename]=tex;
- widths[filename]=width;
- heights[filename]=height;
- return tex;
-
-
- }
+ textures[filename]=tex;
+ widths[filename]=width;
+ heights[filename]=height;
+ return tex;
+ }
}
-int TextureManager::getTextureWidth(const std::string imageURL)
+int
+TextureManager::getTextureWidth(const std::string imageURL)
{
- return widths[imageURL];
+ return widths[imageURL];
}
-int TextureManager::getTextureHeight(const std::string imageURL)
+int
+TextureManager::getTextureHeight(const std::string imageURL)
{
- return heights[imageURL];
+ return heights[imageURL];
}
-unsigned int TextureManager::getTextureMemorySize()
+unsigned int
+TextureManager::getTextureMemorySize()
{
return 0;
}
-void TextureManager::loadTextureDir()
+void
+TextureManager::loadTextureDir()
{
- std::string dirname = CMAKE_INSTALL_PREFIX "/share/projectM/textures";
+ std::string dirname = CMAKE_INSTALL_PREFIX "/share/projectM/textures";
- DIR * m_dir;
+ DIR * m_dir;
- // Allocate a new a stream given the current directory name
- if ((m_dir = opendir(dirname.c_str())) == NULL)
- {
- std::cout<<"No Textures Loaded from "<<dirname<<std::endl;
- return; // no files loaded. m_entries is empty
- }
+ // Allocate a new a stream given the current directory name
+ if ((m_dir = opendir(dirname.c_str())) == NULL)
+ {
+ std::cout<<"No Textures Loaded from "<<dirname<<std::endl;
+ return; // no files loaded. m_entries is empty
+ }
- struct dirent * dir_entry;
+ struct dirent * dir_entry;
- while ((dir_entry = readdir(m_dir)) != NULL)
- {
+ while ((dir_entry = readdir(m_dir)) != NULL)
+ {
+ // Convert char * to friendly string
+ std::string filename(dir_entry->d_name);
- // Convert char * to friendly string
- std::string filename(dir_entry->d_name);
+ if (filename.length() > 0 && filename[0] == '.')
+ continue;
- if (filename.length() > 0 && filename[0] == '.')
- continue;
+ // Create full path name
+ std::string fullname = dirname + PATH_SEPARATOR + filename;
- // Create full path name
- std::string fullname = dirname + PATH_SEPARATOR + filename;
+ unsigned int texId = getTextureFullpath(filename, fullname);
+ if(texId != 0)
+ {
+ user_textures.push_back(texId);
+ textures[filename]=texId;
+ user_texture_names.push_back(filename);
+ }
+ }
- unsigned int texId = getTextureFullpath(filename, fullname);
- if(texId != 0)
- {
- user_textures.push_back(texId);
- textures[filename]=texId;
- user_texture_names.push_back(filename);
- }
- }
-
- if (m_dir)
- {
- closedir(m_dir);
- m_dir = 0;
- }
-
+ if (m_dir)
+ {
+ closedir(m_dir);
+ m_dir = 0;
+ }
}
-std::string TextureManager::getRandomTextureName(std::string random_id)
+std::string
+TextureManager::getRandomTextureName(std::string random_id)
{
- if (user_texture_names.size() > 0)
- {
- std::string random_name = user_texture_names[rand() % user_texture_names.size()];
- random_textures.push_back(random_id);
- textures[random_id] = textures[random_name];
- return random_name;
- }
- else return "";
+ if (user_texture_names.size() > 0)
+ {
+ std::string random_name = user_texture_names[rand() % user_texture_names.size()];
+ random_textures.push_back(random_id);
+ textures[random_id] = textures[random_name];
+ return random_name;
+ }
+ else return "";
}
-void TextureManager::clearRandomTextures()
+void
+TextureManager::clearRandomTextures()
{
- for (std::vector<std::string>::iterator pos = random_textures.begin(); pos != random_textures.end(); ++pos)
- {
- textures.erase(*pos);
- widths.erase(*pos);
- heights.erase(*pos);
- }
- random_textures.clear();
-
+ for (std::vector<std::string>::iterator pos = random_textures.begin();
+ pos != random_textures.end();
+ ++pos)
+ {
+ textures.erase(*pos);
+ widths.erase(*pos);
+ heights.erase(*pos);
+ }
+ random_textures.clear();
}
diff --git a/src/libprojectM/Renderer/Transformation.hpp b/src/libprojectM/Renderer/Transformation.hpp
index 33940b7..f42a823 100644
--- a/src/libprojectM/Renderer/Transformation.hpp
+++ b/src/libprojectM/Renderer/Transformation.hpp
@@ -9,58 +9,57 @@
{
public:
- inline static void Zoom(PixelPoint &p, const PerPixelContext &context, float zoom, float zoomExponent)
- {
- float fZoom2 = powf( zoom, powf( zoomExponent, context.rad*2.0f - 1.0f));
- float fZoom2Inv = 1.0f/fZoom2;
- p.x -= 0.5;
- p.y -= 0.5;
- p.x *= fZoom2Inv;
- p.y *= fZoom2Inv;
- p.x += 0.5;
- p.y += 0.5;
- }
+ inline static void Zoom(PixelPoint &p, const PerPixelContext &context, float zoom, float zoomExponent)
+ {
+ float fZoom2 = powf( zoom, powf( zoomExponent, context.rad*2.0f - 1.0f));
+ float fZoom2Inv = 1.0f/fZoom2;
+ p.x -= 0.5;
+ p.y -= 0.5;
+ p.x *= fZoom2Inv;
+ p.y *= fZoom2Inv;
+ p.x += 0.5;
+ p.y += 0.5;
+ }
- inline static void Transform(PixelPoint &p, const PerPixelContext &context, float dx, float dy)
- {
- p.x -= dx;
- p.y -= dy;
- }
+ inline static void Transform(PixelPoint &p, const PerPixelContext &context, float dx, float dy)
+ {
+ p.x -= dx;
+ p.y -= dy;
+ }
- inline static void Scale(PixelPoint &p, const PerPixelContext &context, float sy, float sx, float cx, float cy)
- {
- p.x = (p.x - cx)/sx + cx;
- p.y = (p.y - cy)/sy + cy;
- }
+ inline static void Scale(PixelPoint &p, const PerPixelContext &context, float sy, float sx, float cx, float cy)
+ {
+ p.x = (p.x - cx)/sx + cx;
+ p.y = (p.y - cy)/sy + cy;
+ }
- inline static void Rotate(PixelPoint &p, const PerPixelContext &context, float angle, float cx, float cy)
- {
- float u2 = p.x - cx;
- float v2 = p.y - cy;
+ inline static void Rotate(PixelPoint &p, const PerPixelContext &context, float angle, float cx, float cy)
+ {
+ float u2 = p.x - cx;
+ float v2 = p.y - cy;
- float cos_rot = cosf(angle);
- float sin_rot = sinf(angle);
+ float cos_rot = cosf(angle);
+ float sin_rot = sinf(angle);
- p.x = u2*cos_rot - v2*sin_rot + cx;
- p.y = u2*sin_rot + v2*cos_rot + cy;
- }
+ p.x = u2*cos_rot - v2*sin_rot + cx;
+ p.y = u2*sin_rot + v2*cos_rot + cy;
+ }
- inline static void Warp(PixelPoint &p, const PerPixelContext &context, float time, float speed, float scale, float warp)
- {
- float fWarpTime = time * speed;
- float fWarpScaleInv = 1.0f / scale;
- float f[4];
- f[0] = 11.68f + 4.0f*cosf(fWarpTime*1.413f + 10);
- f[1] = 8.77f + 3.0f*cosf(fWarpTime*1.113f + 7);
- f[2] = 10.54f + 3.0f*cosf(fWarpTime*1.233f + 3);
- f[3] = 11.49f + 4.0f*cosf(fWarpTime*0.933f + 5);
+ inline static void Warp(PixelPoint &p, const PerPixelContext &context, float time, float speed, float scale, float warp)
+ {
+ float fWarpTime = time * speed;
+ float fWarpScaleInv = 1.0f / scale;
+ float f[4];
+ f[0] = 11.68f + 4.0f*cosf(fWarpTime*1.413f + 10);
+ f[1] = 8.77f + 3.0f*cosf(fWarpTime*1.113f + 7);
+ f[2] = 10.54f + 3.0f*cosf(fWarpTime*1.233f + 3);
+ f[3] = 11.49f + 4.0f*cosf(fWarpTime*0.933f + 5);
- p.x += warp*0.0035f*sinf(fWarpTime*0.333f + fWarpScaleInv*(context.x*f[0] - context.y*f[3]));
- p.y += warp*0.0035f*cosf(fWarpTime*0.375f - fWarpScaleInv*(context.x*f[2] + context.y*f[1]));
- p.x += warp*0.0035f*cosf(fWarpTime*0.753f - fWarpScaleInv*(context.x*f[1] - context.y*f[2]));
- p.y += warp*0.0035f*sinf(fWarpTime*0.825f + fWarpScaleInv*(context.x*f[0] + context.y*f[3]));
- }
-
+ p.x += warp*0.0035f*sinf(fWarpTime*0.333f + fWarpScaleInv*(context.x*f[0] - context.y*f[3]));
+ p.y += warp*0.0035f*cosf(fWarpTime*0.375f - fWarpScaleInv*(context.x*f[2] + context.y*f[1]));
+ p.x += warp*0.0035f*cosf(fWarpTime*0.753f - fWarpScaleInv*(context.x*f[1] - context.y*f[2]));
+ p.y += warp*0.0035f*sinf(fWarpTime*0.825f + fWarpScaleInv*(context.x*f[0] + context.y*f[3]));
+ }
};
#endif
diff --git a/src/libprojectM/Renderer/UserTexture.cpp b/src/libprojectM/Renderer/UserTexture.cpp
index a280d4c..8db4c5c 100644
--- a/src/libprojectM/Renderer/UserTexture.cpp
+++ b/src/libprojectM/Renderer/UserTexture.cpp
@@ -4,47 +4,46 @@
* Created on: Jul 16, 2008
* Author: pete
*/
-
#include "UserTexture.hpp"
+
UserTexture::UserTexture(std::string qualifiedName): qname(qualifiedName)
{
+ if (qualifiedName.substr(0,3) == "fc_")
+ {
+ name = qualifiedName.substr(3);
+ bilinear = true;
+ wrap = false;
+ }
+ else if (qualifiedName.substr(0,3) == "fw_")
+ {
+ name = qualifiedName.substr(3);
+ bilinear = true;
+ wrap = true;
+ }
+ else if (qualifiedName.substr(0,3) == "pc_")
+ {
+ name = qualifiedName.substr(3);
+ bilinear = false;
+ wrap = false;
+ }
+ else if (qualifiedName.substr(0,3) == "pw_")
+ {
+ name = qualifiedName.substr(3);
+ bilinear = false;
+ wrap = true;
+ }
+ else
+ {
+ name = qualifiedName;
+ bilinear = true;
+ wrap = true;
+ }
- if (qualifiedName.substr(0,3) == "fc_")
- {
- name = qualifiedName.substr(3);
- bilinear = true;
- wrap = false;
- }
- else if (qualifiedName.substr(0,3) == "fw_")
- {
- name = qualifiedName.substr(3);
- bilinear = true;
- wrap = true;
- }
- else if (qualifiedName.substr(0,3) == "pc_")
- {
- name = qualifiedName.substr(3);
- bilinear = false;
- wrap = false;
- }
- else if (qualifiedName.substr(0,3) == "pw_")
- {
- name = qualifiedName.substr(3);
- bilinear = false;
- wrap = true;
- }
- else
- {
- name = qualifiedName;
- bilinear = true;
- wrap = true;
- }
-
- texsizeDefined = false;
+ texsizeDefined = false;
}
UserTexture::~UserTexture()
{
- // TODO Auto-generated destructor stub
+ // TODO Auto-generated destructor stub
}
diff --git a/src/libprojectM/Renderer/UserTexture.hpp b/src/libprojectM/Renderer/UserTexture.hpp
index 19fdc63..d460382 100644
--- a/src/libprojectM/Renderer/UserTexture.hpp
+++ b/src/libprojectM/Renderer/UserTexture.hpp
@@ -4,31 +4,31 @@
* Created on: Jul 16, 2008
* Author: pete
*/
-
#ifndef USERTEXTURE_HPP_
#define USERTEXTURE_HPP_
#include <string>
+
class UserTexture
{
public:
- bool wrap;
- bool bilinear;
+ bool wrap;
+ bool bilinear;
- bool texsizeDefined;
+ bool texsizeDefined;
- int width;
- int height;
+ int width;
+ int height;
- unsigned int texID;
+ unsigned int texID;
- std::string qname;
- std::string name;
+ std::string qname;
+ std::string name;
- UserTexture(std::string qualifiedName);
- virtual ~UserTexture();
+ UserTexture(std::string qualifiedName);
+ virtual ~UserTexture();
};
#endif /* USERTEXTURE_HPP_ */
diff --git a/src/libprojectM/Renderer/VideoEcho.cpp b/src/libprojectM/Renderer/VideoEcho.cpp
index 1ddad57..5387a2b 100644
--- a/src/libprojectM/Renderer/VideoEcho.cpp
+++ b/src/libprojectM/Renderer/VideoEcho.cpp
@@ -4,7 +4,6 @@
* Created on: Jun 29, 2008
* Author: pete
*/
-
#include "Common.hpp"
#ifdef USE_GLES1
@@ -21,73 +20,71 @@
#include "VideoEcho.hpp"
+
VideoEcho::VideoEcho(): a(0), zoom(1), orientation(Normal)
{
- // TODO Auto-generated constructor stub
+ // TODO Auto-generated constructor stub
}
VideoEcho::~VideoEcho()
{
- // TODO Auto-generated destructor stub
+ // TODO Auto-generated destructor stub
}
-void VideoEcho::Draw(RenderContext &context)
+void
+VideoEcho::Draw(RenderContext &context)
{
+ glEnable(GL_TEXTURE_2D);
+ float tex[4][2] = {{0, 1},
+ {0, 0},
+ {1, 0},
+ {1, 1}};
- glEnable(GL_TEXTURE_2D);
+ float points[4][2] = {{-0.5, -0.5},
+ {-0.5, 0.5},
+ { 0.5, 0.5},
+ { 0.5, -0.5}};
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- float tex[4][2] = {{0, 1},
- {0, 0},
- {1, 0},
- {1, 1}};
+ glVertexPointer(2,GL_FLOAT,0,points);
+ glTexCoordPointer(2,GL_FLOAT,0,tex);
- float points[4][2] = {{-0.5, -0.5},
- {-0.5, 0.5},
- { 0.5, 0.5},
- { 0.5, -0.5}};
+ //Now Blend the Video Echo
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glMatrixMode(GL_TEXTURE);
- glVertexPointer(2,GL_FLOAT,0,points);
- glTexCoordPointer(2,GL_FLOAT,0,tex);
+ //draw video echo
+ glColor4f(1.0, 1.0, 1.0, a * masterAlpha);
+ glTranslatef(.5, .5, 0);
+ glScalef(1.0/zoom, 1.0/zoom, 1);
+ glTranslatef(-.5, -.5, 0);
- //Now Blend the Video Echo
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ int flipx=1, flipy=1;
+ switch (orientation)
+ {
+ case Normal: flipx = 1; flipy = 1; break;
+ case FlipX: flipx = -1; flipy = 1; break;
+ case FlipY: flipx = 1; flipy = -1; break;
+ case FlipXY: flipx = -1; flipy = -1; break;
+ default: flipx = 1; flipy = 1; break;
+ }
- glMatrixMode(GL_TEXTURE);
+ float pointsFlip[4][2] = {{-0.5*flipx, -0.5*flipy},
+ {-0.5*flipx, 0.5*flipy},
+ { 0.5*flipx, 0.5*flipy},
+ { 0.5*flipx, -0.5*flipy}};
- //draw video echo
- glColor4f(1.0, 1.0, 1.0, a * masterAlpha);
- glTranslatef(.5, .5, 0);
- glScalef(1.0/zoom, 1.0/zoom, 1);
- glTranslatef(-.5, -.5, 0);
+ glVertexPointer(2,GL_FLOAT,0,pointsFlip);
+ glDrawArrays(GL_TRIANGLE_FAN,0,4);
- int flipx=1, flipy=1;
- switch (orientation)
- {
- case Normal: flipx=1;flipy=1;break;
- case FlipX: flipx=-1;flipy=1;break;
- case FlipY: flipx=1;flipy=-1;break;
- case FlipXY: flipx=-1;flipy=-1;break;
- default: flipx=1;flipy=1; break;
- }
+ glDisable(GL_TEXTURE_2D);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- float pointsFlip[4][2] = {{-0.5*flipx, -0.5*flipy},
- {-0.5*flipx, 0.5*flipy},
- { 0.5*flipx, 0.5*flipy},
- { 0.5*flipx, -0.5*flipy}};
-
- glVertexPointer(2,GL_FLOAT,0,pointsFlip);
- glDrawArrays(GL_TRIANGLE_FAN,0,4);
-
- glDisable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
diff --git a/src/libprojectM/Renderer/VideoEcho.hpp b/src/libprojectM/Renderer/VideoEcho.hpp
index 13f027e..5b4fa99 100644
--- a/src/libprojectM/Renderer/VideoEcho.hpp
+++ b/src/libprojectM/Renderer/VideoEcho.hpp
@@ -4,28 +4,28 @@
* Created on: Jun 29, 2008
* Author: pete
*/
-
#ifndef VIDEOECHO_HPP_
#define VIDEOECHO_HPP_
#include "Renderable.hpp"
+
enum Orientation
{
- Normal=0, FlipX, FlipY, FlipXY
+ Normal=0, FlipX, FlipY, FlipXY
};
class VideoEcho: public RenderItem
{
public:
- VideoEcho();
- virtual ~VideoEcho();
+ VideoEcho();
+ virtual ~VideoEcho();
- float a;
- float zoom;
- Orientation orientation;
+ float a;
+ float zoom;
+ Orientation orientation;
- void Draw(RenderContext &context);
+ void Draw(RenderContext &context);
};
#endif /* VIDEOECHO_HPP_ */
diff --git a/src/libprojectM/Renderer/Waveform.cpp b/src/libprojectM/Renderer/Waveform.cpp
index 0aca543..d626640 100644
--- a/src/libprojectM/Renderer/Waveform.cpp
+++ b/src/libprojectM/Renderer/Waveform.cpp
@@ -4,7 +4,6 @@
* Created on: Jun 25, 2008
* Author: pete
*/
-
#ifdef LINUX
#ifdef USE_GLES1
#include <GLES/gl.h>
@@ -20,103 +19,105 @@
#include <algorithm>
#include "BeatDetect.hpp"
+
typedef float floatPair[2];
typedef float floatTriple[3];
typedef float floatQuad[4];
+
Waveform::Waveform(int samples)
-: RenderItem(),samples(samples), points(samples), pointContext(samples)
+ : RenderItem(),
+ samples(samples),
+ points(samples),
+ pointContext(samples)
{
+ spectrum = false; /* spectrum data or pcm data */
+ dots = false; /* draw wave as dots or lines */
+ thick = false; /* draw thicker lines */
+ additive = false; /* add color values together */
- spectrum = false; /* spectrum data or pcm data */
- dots = false; /* draw wave as dots or lines */
- thick = false; /* draw thicker lines */
- additive = false; /* add color values together */
-
- scaling= 1; /* scale factor of waveform */
- smoothing = 0; /* smooth factor of waveform */
- sep = 0;
-
+ scaling= 1; /* scale factor of waveform */
+ smoothing = 0; /* smooth factor of waveform */
+ sep = 0;
}
-void Waveform::Draw(RenderContext &context)
- {
- //if (samples > 2048) samples = 2048;
+void
+Waveform::Draw(RenderContext &context)
+{
+ //if (samples > 2048) samples = 2048;
+
+ if (additive) glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ if (thick)
+ {
+ glLineWidth(context.texsize <= 512 ? 2 : 2*context.texsize/512);
+ glPointSize(context.texsize <= 512 ? 2 : 2*context.texsize/512);
+ }
+ else
+ glPointSize(context.texsize <= 512 ? 1 : context.texsize/512);
- if (additive) glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- if (thick)
- {
- glLineWidth(context.texsize <= 512 ? 2 : 2*context.texsize/512);
- glPointSize(context.texsize <= 512 ? 2 : 2*context.texsize/512);
-
- }
- else glPointSize(context.texsize <= 512 ? 1 : context.texsize/512);
+ float *value1 = new float[samples];
+ float *value2 = new float[samples];
+ context.beatDetect->pcm->getPCM( value1, samples, 0, spectrum, smoothing, 0);
+ context.beatDetect->pcm->getPCM( value2, samples, 1, spectrum, smoothing, 0);
+ // printf("%f\n",pcmL[0]);
- float *value1 = new float[samples];
- float *value2 = new float[samples];
- context.beatDetect->pcm->getPCM( value1, samples, 0, spectrum, smoothing, 0);
- context.beatDetect->pcm->getPCM( value2, samples, 1, spectrum, smoothing, 0);
- // printf("%f\n",pcmL[0]);
+ float mult= scaling*( spectrum ? 0.015f :1.0f);
- float mult= scaling*( spectrum ? 0.015f :1.0f);
+ std::transform(&value1[0],&value1[samples],&value1[0],std::bind2nd(std::multiplies<float>(),mult));
+ std::transform(&value2[0],&value2[samples],&value2[0],std::bind2nd(std::multiplies<float>(),mult));
+ WaveformContext waveContext(samples, context.beatDetect);
- std::transform(&value1[0],&value1[samples],&value1[0],std::bind2nd(std::multiplies<float>(),mult));
- std::transform(&value2[0],&value2[samples],&value2[0],std::bind2nd(std::multiplies<float>(),mult));
+ for(int x=0;x< samples;x++)
+ {
+ waveContext.sample = x/(float)(samples - 1);
+ waveContext.sample_int = x;
+ waveContext.left = value1[x];
+ waveContext.right = value2[x];
- WaveformContext waveContext(samples, context.beatDetect);
+ points[x] = PerPoint(points[x],waveContext);
+ }
- for(int x=0;x< samples;x++)
- {
- waveContext.sample = x/(float)(samples - 1);
- waveContext.sample_int = x;
- waveContext.left = value1[x];
- waveContext.right = value2[x];
+ floatQuad *colors = new float[samples][4];
+ floatPair *p = new float[samples][2];
- points[x] = PerPoint(points[x],waveContext);
- }
+ for(int x=0;x< samples;x++)
+ {
+ colors[x][0] = points[x].r;
+ colors[x][1] = points[x].g;
+ colors[x][2] = points[x].b;
+ colors[x][3] = points[x].a * masterAlpha;
- floatQuad *colors = new float[samples][4];
- floatPair *p = new float[samples][2];
+ p[x][0] = points[x].x;
+ p[x][1] = -(points[x].y-1);
- for(int x=0;x< samples;x++)
- {
- colors[x][0] = points[x].r;
- colors[x][1] = points[x].g;
- colors[x][2] = points[x].b;
- colors[x][3] = points[x].a * masterAlpha;
+ }
- p[x][0] = points[x].x;
- p[x][1] = -(points[x].y-1);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- }
+ glVertexPointer(2,GL_FLOAT,0,p);
+ glColorPointer(4,GL_FLOAT,0,colors);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ if (dots) glDrawArrays(GL_POINTS,0,samples);
+ else glDrawArrays(GL_LINE_STRIP,0,samples);
- glVertexPointer(2,GL_FLOAT,0,p);
- glColorPointer(4,GL_FLOAT,0,colors);
-
- if (dots) glDrawArrays(GL_POINTS,0,samples);
- else glDrawArrays(GL_LINE_STRIP,0,samples);
-
- glPointSize(context.texsize < 512 ? 1 : context.texsize/512);
- glLineWidth(context.texsize < 512 ? 1 : context.texsize/512);
+ glPointSize(context.texsize < 512 ? 1 : context.texsize/512);
+ glLineWidth(context.texsize < 512 ? 1 : context.texsize/512);
#ifndef USE_GLES1
- glDisable(GL_LINE_STIPPLE);
+ glDisable(GL_LINE_STIPPLE);
#endif
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- // glPopMatrix();
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ // glPopMatrix();
- delete[] colors;
- delete[] p;
- delete[] value1;
- delete[] value2;
-
- }
+ delete[] colors;
+ delete[] p;
+ delete[] value1;
+ delete[] value2;
+}
diff --git a/src/libprojectM/Renderer/Waveform.hpp b/src/libprojectM/Renderer/Waveform.hpp
index b6aa468..f0bf7f8 100644
--- a/src/libprojectM/Renderer/Waveform.hpp
+++ b/src/libprojectM/Renderer/Waveform.hpp
@@ -4,37 +4,37 @@
* Created on: Jun 25, 2008
* Author: pete
*/
-
#ifndef WAVEFORM_HPP_
#define WAVEFORM_HPP_
#include "Renderable.hpp"
#include <vector>
+
class ColoredPoint
{
public:
- float x;
- float y;
- float r;
- float g;
- float b;
- float a;
+ float x;
+ float y;
+ float r;
+ float g;
+ float b;
+ float a;
- ColoredPoint():x(0.5),y(0.5),r(1),g(1),b(1),a(1){};
+ ColoredPoint():x(0.5),y(0.5),r(1),g(1),b(1),a(1){};
};
class WaveformContext
{
public:
- float sample;
- int samples;
- int sample_int;
- float left;
- float right;
- BeatDetect *music;
+ float sample;
+ int samples;
+ int sample_int;
+ float left;
+ float right;
+ BeatDetect *music;
- WaveformContext(int samples, BeatDetect *music):samples(samples),music(music){};
+ WaveformContext(int samples, BeatDetect *music):samples(samples),music(music){};
};
@@ -42,23 +42,23 @@
{
public:
- int samples; /* number of samples associated with this wave form. Usually powers of 2 */
- bool spectrum; /* spectrum data or pcm data */
- bool dots; /* draw wave as dots or lines */
- bool thick; /* draw thicker lines */
- bool additive; /* add color values together */
+ int samples; /* number of samples associated with this wave form. Usually powers of 2 */
+ bool spectrum; /* spectrum data or pcm data */
+ bool dots; /* draw wave as dots or lines */
+ bool thick; /* draw thicker lines */
+ bool additive; /* add color values together */
- float scaling; /* scale factor of waveform */
- float smoothing; /* smooth factor of waveform */
- int sep; /* no idea what this is yet... */
+ float scaling; /* scale factor of waveform */
+ float smoothing; /* smooth factor of waveform */
+ int sep; /* no idea what this is yet... */
- Waveform(int samples);
- void Draw(RenderContext &context);
+ Waveform(int samples);
+ void Draw(RenderContext &context);
private:
- virtual ColoredPoint PerPoint(ColoredPoint p, const WaveformContext context)=0;
- std::vector<ColoredPoint> points;
- std::vector<float> pointContext;
-
+ virtual ColoredPoint PerPoint(ColoredPoint p, const WaveformContext context)=0;
+ std::vector<ColoredPoint> points;
+ std::vector<float> pointContext;
};
+
#endif /* WAVEFORM_HPP_ */
diff --git a/src/libprojectM/TimeKeeper.cpp b/src/libprojectM/TimeKeeper.cpp
index 199cde1..66c6fc8 100644
--- a/src/libprojectM/TimeKeeper.cpp
+++ b/src/libprojectM/TimeKeeper.cpp
@@ -7,100 +7,118 @@
#include "TimeKeeper.hpp"
#include "RandomNumberGenerators.hpp"
-TimeKeeper::TimeKeeper(double presetDuration, double smoothDuration, double easterEgg)
- {
- _smoothDuration = smoothDuration;
- _presetDuration = presetDuration;
- _easterEgg = easterEgg;
+
+TimeKeeper::TimeKeeper (double presetDuration, double smoothDuration, double easterEgg)
+{
+ _smoothDuration = smoothDuration;
+ _presetDuration = presetDuration;
+ _easterEgg = easterEgg;
#ifndef WIN32
- gettimeofday ( &this->startTime, NULL );
+ gettimeofday ( &this->startTime, NULL );
#else
- startTime = GetTickCount();
+ startTime = GetTickCount();
#endif /** !WIN32 */
- UpdateTimers();
- }
+ UpdateTimers();
+}
- void TimeKeeper::UpdateTimers()
- {
+void
+TimeKeeper::UpdateTimers()
+{
#ifndef WIN32
- _currentTime = getTicks ( &startTime ) * 0.001;
+ _currentTime = getTicks (&startTime) * 0.001;
#else
- _currentTime = getTicks ( startTime ) * 0.001;
+ _currentTime = getTicks (startTime) * 0.001;
#endif /** !WIN32 */
- _presetFrameA++;
- _presetFrameB++;
+ _presetFrameA++;
+ _presetFrameB++;
+}
- }
+void
+TimeKeeper::StartPreset()
+{
+ _isSmoothing = false;
+ _presetTimeA = _currentTime;
+ _presetFrameA = 1;
+ _presetDurationA = sampledPresetDuration();
+}
- void TimeKeeper::StartPreset()
- {
- _isSmoothing = false;
- _presetTimeA = _currentTime;
- _presetFrameA = 1;
- _presetDurationA = sampledPresetDuration();
- }
- void TimeKeeper::StartSmoothing()
- {
- _isSmoothing = true;
- _presetTimeB = _currentTime;
- _presetFrameB = 1;
- _presetDurationB = sampledPresetDuration();
- }
- void TimeKeeper::EndSmoothing()
- {
- _isSmoothing = false;
- _presetTimeA = _presetTimeB;
- _presetFrameA = _presetFrameB;
- _presetDurationA = _presetDurationB;
- }
+void
+TimeKeeper::StartSmoothing()
+{
+ _isSmoothing = true;
+ _presetTimeB = _currentTime;
+ _presetFrameB = 1;
+ _presetDurationB = sampledPresetDuration();
+}
- bool TimeKeeper::CanHardCut()
- {
- return ((_currentTime - _presetTimeA) > HARD_CUT_DELAY);
- }
+void
+TimeKeeper::EndSmoothing()
+{
+ _isSmoothing = false;
+ _presetTimeA = _presetTimeB;
+ _presetFrameA = _presetFrameB;
+ _presetDurationA = _presetDurationB;
+}
- double TimeKeeper::SmoothRatio()
- {
- return (_currentTime - _presetTimeB) / _smoothDuration;
- }
- bool TimeKeeper::IsSmoothing()
- {
- return _isSmoothing;
- }
+bool
+TimeKeeper::CanHardCut()
+{
+ return ((_currentTime - _presetTimeA) > HARD_CUT_DELAY);
+}
- double TimeKeeper::GetRunningTime()
- {
- return _currentTime;
- }
+double
+TimeKeeper::SmoothRatio()
+{
+ return (_currentTime - _presetTimeB) / _smoothDuration;
+}
- double TimeKeeper::PresetProgressA()
- {
- if (_isSmoothing) return 1.0;
- else return (_currentTime - _presetTimeA) / _presetDurationA;
- }
- double TimeKeeper::PresetProgressB()
- {
- return (_currentTime - _presetTimeB) / _presetDurationB;
- }
+bool
+TimeKeeper::IsSmoothing()
+{
+ return _isSmoothing;
+}
-int TimeKeeper::PresetFrameB()
- {
- return _presetFrameB;
- }
+double
+TimeKeeper::GetRunningTime()
+{
+ return _currentTime;
+}
-int TimeKeeper::PresetFrameA()
- {
- return _presetFrameA;
- }
+double
+TimeKeeper::PresetProgressA()
+{
+ if (_isSmoothing) return 1.0;
+ else return (_currentTime - _presetTimeA) / _presetDurationA;
+}
-double TimeKeeper::sampledPresetDuration() {
+double
+TimeKeeper::PresetProgressB()
+{
+ return (_currentTime - _presetTimeB) / _presetDurationB;
+}
+
+int
+TimeKeeper::PresetFrameB()
+{
+ return _presetFrameB;
+}
+
+int
+TimeKeeper::PresetFrameA()
+{
+ return _presetFrameA;
+}
+
+double
+TimeKeeper::sampledPresetDuration()
+{
#ifdef WIN32
- return _presetDuration;
+ return _presetDuration;
#else
- return fmax(1, fmin(60, RandomNumberGenerators::gaussian
- (_presetDuration, _easterEgg)));
+ return fmax (1, fmin (60, RandomNumberGenerators::gaussian (_presetDuration,
+ _easterEgg)));
#endif
}
diff --git a/src/libprojectM/TimeKeeper.hpp b/src/libprojectM/TimeKeeper.hpp
index 694774a..c84d225 100644
--- a/src/libprojectM/TimeKeeper.hpp
+++ b/src/libprojectM/TimeKeeper.hpp
@@ -7,61 +7,62 @@
#include "timer.h"
+
#define HARD_CUT_DELAY 3
+
class TimeKeeper
{
-
public:
TimeKeeper(double presetDuration, double smoothDuration, double easterEgg);
- void UpdateTimers();
+ void UpdateTimers();
- void StartPreset();
- void StartSmoothing();
- void EndSmoothing();
-
- bool CanHardCut();
+ void StartPreset();
+ void StartSmoothing();
+ void EndSmoothing();
- double SmoothRatio();
- bool IsSmoothing();
+ bool CanHardCut();
- double GetRunningTime();
+ double SmoothRatio();
+ bool IsSmoothing();
- double PresetProgressA();
- double PresetProgressB();
+ double GetRunningTime();
- int PresetFrameA();
- int PresetFrameB();
+ double PresetProgressA();
+ double PresetProgressB();
- double sampledPresetDuration();
+ int PresetFrameA();
+ int PresetFrameB();
- void ChangePresetDuration(int seconds) { _presetDuration = seconds; }
+ double sampledPresetDuration();
+
+ void ChangePresetDuration(int seconds) { _presetDuration = seconds; }
#ifndef WIN32
/* The first ticks value of the application */
- struct timeval startTime;
+ struct timeval startTime;
#else
- long startTime;
+ long startTime;
#endif /** !WIN32 */
+
private:
- double _easterEgg;
- double _presetDuration;
- double _presetDurationA;
- double _presetDurationB;
- double _smoothDuration;
+ double _easterEgg;
+ double _presetDuration;
+ double _presetDurationA;
+ double _presetDurationB;
+ double _smoothDuration;
- double _currentTime;
- double _presetTimeA;
- double _presetTimeB;
- int _presetFrameA;
- int _presetFrameB;
+ double _currentTime;
+ double _presetTimeA;
+ double _presetTimeB;
+ int _presetFrameA;
+ int _presetFrameB;
- bool _isSmoothing;
-
-
+ bool _isSmoothing;
};
+
#endif
diff --git a/src/libprojectM/carbontoprojectM.h b/src/libprojectM/carbontoprojectM.h
index 42f1cdf..bbabf60 100644
--- a/src/libprojectM/carbontoprojectM.h
+++ b/src/libprojectM/carbontoprojectM.h
@@ -1,105 +1,113 @@
-r/**
- * projectM -- Milkdrop-esque visualisation SDK
- * Copyright (C)2003-2007 projectM Team
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * See 'LICENSE.txt' included within this release
- *
- */
-/**
- * $Id: carbontoprojectM.hpp,v 1.2 2004/11/12 15:12:58 cvs Exp $
- *
- * Translates CARBON -> projectM variables
- *
- * $Log$
- */
-
-#ifndef _CARBONTOPROJECTM_H
-#define _CARBONTOPROJECTM_H
-
-#include "event.h"
-
-#ifdef WIN32
-#else
-#endif
-
-projectMEvent carbon2pmEvent( EventRecord *event ) {
-
- switch ( event->what ) {
- case updateEvt:
- return PROJECTM_VIDEORESIZE;
- case keyUp:
- return PROJECTM_KEYUP;
- case keyDown:
- return PROJECTM_KEYDOWN;
- default:
- return PROJECTM_KEYUP;
- }
- }
-
-projectMKeycode carbon2pmKeycode( EventRecord *event ) {
- projectMKeycode char_code = (projectMKeycode)(event->message & charCodeMask);
- switch ( char_code ) {
- case kFunctionKeyCharCode: {
- switch ( ( event->message << 16 ) >> 24 ) {
- case 111: {
- return PROJECTM_K_F12;
- }
- case 103: {
- return PROJECTM_K_F11;
- }
- case 109: {
- return PROJECTM_K_F10;
- }
- case 101: {
- return PROJECTM_K_F9;
- }
- case 100: {
- return PROJECTM_K_F8;
- }
- case 98: {
- return PROJECTM_K_F7;
- }
- case 97: {
- return PROJECTM_K_F6;
- }
- case 96: {
- return PROJECTM_K_F5;
- }
- case 118: {
- return PROJECTM_K_F4;
- }
- case 99: {
- return PROJECTM_K_F3;
- }
- case 120: {
- return PROJECTM_K_F2;
- }
- case 122: {
- return PROJECTM_K_F1;
- }
- }
- }
- default: {
- return char_code;
- }
- }
- }
-
-projectMModifier carbon2pmModifier( EventRecord *event ) {
- return (projectMModifier)PROJECTM_K_LSHIFT;
- }
-
-#endif /** _CARBONTOPROJECTM_H */
+/**
+ * projectM -- Milkdrop-esque visualisation SDK
+ * Copyright (C)2003-2007 projectM Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * See 'LICENSE.txt' included within this release
+ *
+ */
+/**
+ * $Id: carbontoprojectM.hpp,v 1.2 2004/11/12 15:12:58 cvs Exp $
+ *
+ * Translates CARBON -> projectM variables
+ *
+ * $Log$
+ */
+#ifndef _CARBONTOPROJECTM_H
+#define _CARBONTOPROJECTM_H
+
+#include "event.h"
+
+
+#ifdef WIN32
+#else
+#endif
+
+projectMEvent
+carbon2pmEvent( EventRecord *event )
+{
+ switch ( event->what ) {
+ case updateEvt:
+ return PROJECTM_VIDEORESIZE;
+ case keyUp:
+ return PROJECTM_KEYUP;
+ case keyDown:
+ return PROJECTM_KEYDOWN;
+ default:
+ return PROJECTM_KEYUP;
+ }
+}
+
+projectMKeycode
+carbon2pmKeycode( EventRecord *event )
+{
+ projectMKeycode char_code = (projectMKeycode)(event->message & charCodeMask);
+
+ switch ( char_code ) {
+ case kFunctionKeyCharCode:
+ {
+ switch ( ( event->message << 16 ) >> 24 ) {
+ case 111: {
+ return PROJECTM_K_F12;
+ }
+ case 103: {
+ return PROJECTM_K_F11;
+ }
+ case 109: {
+ return PROJECTM_K_F10;
+ }
+ case 101: {
+ return PROJECTM_K_F9;
+ }
+ case 100: {
+ return PROJECTM_K_F8;
+ }
+ case 98: {
+ return PROJECTM_K_F7;
+ }
+ case 97: {
+ return PROJECTM_K_F6;
+ }
+ case 96: {
+ return PROJECTM_K_F5;
+ }
+ case 118: {
+ return PROJECTM_K_F4;
+ }
+ case 99: {
+ return PROJECTM_K_F3;
+ }
+ case 120: {
+ return PROJECTM_K_F2;
+ }
+ case 122: {
+ return PROJECTM_K_F1;
+ }
+ }
+ }
+ default:
+ {
+ return char_code;
+ }
+ }
+}
+
+projectMModifier
+carbon2pmModifier( EventRecord *event )
+{
+ return (projectMModifier)PROJECTM_K_LSHIFT;
+}
+
+#endif /** _CARBONTOPROJECTM_H */
diff --git a/src/libprojectM/config.inp.in b/src/libprojectM/config.inp.in
index b27b193..7cf9697 100644
--- a/src/libprojectM/config.inp.in
+++ b/src/libprojectM/config.inp.in
@@ -1,22 +1,21 @@
-# config.inp
-# Configuration File for projectM
-
-Texture Size = 1024 # Size of internal rendering texture
-Mesh X = 32 # Width of PerPixel Equation mesh
-Mesh Y = 24 # Height of PerPixel Equation mesh
-FPS = 35 # Frames Per Second
-Fullscreen = false
-Window Width = 512 # startup window width
-Window Height = 512 # startup window height
-
-Smooth Transition Duration = 5 # in seconds
-Preset Duration = 30 # in seconds
-Easter Egg Parameter = 1
-
-Hard Cut Sensitivity = 10 # Lower to make hard cuts more frequent
-Aspect Correction = true # Custom Shape Aspect Correction
-
-Preset Path = @CMAKE_INSTALL_PREFIX@/@RESOURCE_PREFIX@/presets # preset location
-Title Font = @CMAKE_INSTALL_PREFIX@/@RESOURCE_PREFIX@/fonts/Vera.ttf
-Menu Font = @CMAKE_INSTALL_PREFIX@/@RESOURCE_PREFIX@/fonts/VeraMono.ttf
-
+# config.inp
+# Configuration File for projectM
+
+Texture Size = 1024 # Size of internal rendering texture
+Mesh X = 32 # Width of PerPixel Equation mesh
+Mesh Y = 24 # Height of PerPixel Equation mesh
+FPS = 35 # Frames Per Second
+Fullscreen = false
+Window Width = 512 # startup window width
+Window Height = 512 # startup window height
+
+Smooth Transition Duration = 5 # in seconds
+Preset Duration = 30 # in seconds
+Easter Egg Parameter = 1
+
+Hard Cut Sensitivity = 10 # Lower to make hard cuts more frequent
+Aspect Correction = true # Custom Shape Aspect Correction
+
+Preset Path = @CMAKE_INSTALL_PREFIX@/@RESOURCE_PREFIX@/presets # preset location
+Title Font = @CMAKE_INSTALL_PREFIX@/@RESOURCE_PREFIX@/fonts/Vera.ttf
+Menu Font = @CMAKE_INSTALL_PREFIX@/@RESOURCE_PREFIX@/fonts/VeraMono.ttf
diff --git a/src/libprojectM/dlldefs.h b/src/libprojectM/dlldefs.h
index b944fe7..d6df3a8 100644
--- a/src/libprojectM/dlldefs.h
+++ b/src/libprojectM/dlldefs.h
@@ -1,40 +1,40 @@
-/**
- * projectM -- Milkdrop-esque visualisation SDK
- * Copyright (C)2003-2007 projectM Team
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * See 'LICENSE.txt' included within this release
- *
- */
-/**
- * $Id$
- *
- * DLL definitions for exporting symbols on various platforms
- *
- * $Log$
- */
-
-#ifndef _DLLDEFS_H
-#define _DLLDEFS_H
-
-#ifndef DLLEXPORT
-#ifdef WIN32
-#define DLLEXPORT __declspec(dllexport)
-#else /** !WIN32 */
-#define DLLEXPORT
-#endif /** WIN32 */
-#endif /** !DLLEXPORT */
-
-#endif /** !_DLLDEFS_H */
+/**
+ * projectM -- Milkdrop-esque visualisation SDK
+ * Copyright (C)2003-2007 projectM Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * See 'LICENSE.txt' included within this release
+ *
+ */
+/**
+ * $Id$
+ *
+ * DLL definitions for exporting symbols on various platforms
+ *
+ * $Log$
+ */
+
+#ifndef _DLLDEFS_H
+#define _DLLDEFS_H
+
+#ifndef DLLEXPORT
+#ifdef WIN32
+#define DLLEXPORT __declspec(dllexport)
+#else /** !WIN32 */
+#define DLLEXPORT
+#endif /** WIN32 */
+#endif /** !DLLEXPORT */
+
+#endif /** !_DLLDEFS_H */
diff --git a/src/libprojectM/event.h b/src/libprojectM/event.h
index 88949f2..2423460 100644
--- a/src/libprojectM/event.h
+++ b/src/libprojectM/event.h
@@ -1,154 +1,155 @@
-/**
- * projectM -- Milkdrop-esque visualisation SDK
- * Copyright (C)2003-2004 projectM Team
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * See 'LICENSE.txt' included within this release
- *
- */
-/**
- * $Id: event.h,v 1.2 2004/10/08 10:54:27 cvs Exp $
- *
- * projectM keycodes. Enables translation from various event schemes such as Win32, SDL
- * &c.
- *
- * $Log: event.h,v $
- */
-
-#ifndef _PROJECTM_EVENT_H
-#define _PROJECTM_EVENT_H
-
-typedef enum {
- /** Event types */
- PROJECTM_KEYUP,
- PROJECTM_KEYDOWN,
- PROJECTM_VIDEORESIZE,
- PROJECTM_VIDEOQUIT,
- } projectMEvent;
-
-typedef enum {
- /** Keycodes */
- PROJECTM_K_RETURN,
- PROJECTM_K_RIGHT,
- PROJECTM_K_LEFT,
- PROJECTM_K_UP,
- PROJECTM_K_DOWN,
- PROJECTM_K_PAGEUP,
- PROJECTM_K_PAGEDOWN,
- PROJECTM_K_INSERT,
- PROJECTM_K_DELETE,
- PROJECTM_K_ESCAPE,
- PROJECTM_K_LSHIFT,
- PROJECTM_K_RSHIFT,
- PROJECTM_K_CAPSLOCK,
- PROJECTM_K_LCTRL,
- PROJECTM_K_HOME,
- PROJECTM_K_END,
- PROJECTM_K_BACKSPACE,
-
- PROJECTM_K_F1,
- PROJECTM_K_F2,
- PROJECTM_K_F3,
- PROJECTM_K_F4,
- PROJECTM_K_F5,
- PROJECTM_K_F6,
- PROJECTM_K_F7,
- PROJECTM_K_F8,
- PROJECTM_K_F9,
- PROJECTM_K_F10,
- PROJECTM_K_F11,
- PROJECTM_K_F12,
-
- PROJECTM_K_0 = 48,
- PROJECTM_K_1,
- PROJECTM_K_2,
- PROJECTM_K_3,
- PROJECTM_K_4,
- PROJECTM_K_5,
- PROJECTM_K_6,
- PROJECTM_K_7,
- PROJECTM_K_8,
- PROJECTM_K_9,
-
- PROJECTM_K_A = 65,
- PROJECTM_K_B,
- PROJECTM_K_C,
- PROJECTM_K_D,
- PROJECTM_K_E,
- PROJECTM_K_F,
- PROJECTM_K_G,
- PROJECTM_K_H,
- PROJECTM_K_I,
- PROJECTM_K_J,
- PROJECTM_K_K,
- PROJECTM_K_L,
- PROJECTM_K_M,
- PROJECTM_K_N,
- PROJECTM_K_O,
- PROJECTM_K_P,
- PROJECTM_K_Q,
- PROJECTM_K_R,
- PROJECTM_K_S,
- PROJECTM_K_T,
- PROJECTM_K_U,
- PROJECTM_K_V,
- PROJECTM_K_W,
- PROJECTM_K_X,
- PROJECTM_K_Y,
- PROJECTM_K_Z,
-
- PROJECTM_K_a = 97,
- PROJECTM_K_b,
- PROJECTM_K_c,
- PROJECTM_K_d,
- PROJECTM_K_e,
- PROJECTM_K_f,
- PROJECTM_K_g,
- PROJECTM_K_h,
- PROJECTM_K_i,
- PROJECTM_K_j,
- PROJECTM_K_k,
- PROJECTM_K_l,
- PROJECTM_K_m,
- PROJECTM_K_n,
- PROJECTM_K_o,
- PROJECTM_K_p,
- PROJECTM_K_q,
- PROJECTM_K_r,
- PROJECTM_K_s,
- PROJECTM_K_t,
- PROJECTM_K_u,
- PROJECTM_K_v,
- PROJECTM_K_w,
- PROJECTM_K_x,
- PROJECTM_K_y,
- PROJECTM_K_z,
- PROJECTM_K_NONE,
- PROJECTM_K_PLUS,
- PROJECTM_K_MINUS,
- PROJECTM_K_EQUALS
- } projectMKeycode;
-
-typedef enum {
- /** Modifiers */
- PROJECTM_KMOD_LSHIFT,
- PROJECTM_KMOD_RSHIFT,
- PROJECTM_KMOD_CAPS,
- PROJECTM_KMOD_LCTRL,
- PROJECTM_KMOD_RCTRL,
- } projectMModifier;
-
-#endif /** !_PROJECTM_EVENT_H */
-
+/**
+ * projectM -- Milkdrop-esque visualisation SDK
+ * Copyright (C)2003-2004 projectM Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * See 'LICENSE.txt' included within this release
+ *
+ */
+/**
+ * $Id: event.h,v 1.2 2004/10/08 10:54:27 cvs Exp $
+ *
+ * projectM keycodes. Enables translation from various event schemes such as Win32, SDL
+ * &c.
+ *
+ * $Log: event.h,v $
+ */
+
+#ifndef _PROJECTM_EVENT_H
+#define _PROJECTM_EVENT_H
+
+
+typedef enum {
+ /** Event types */
+ PROJECTM_KEYUP,
+ PROJECTM_KEYDOWN,
+ PROJECTM_VIDEORESIZE,
+ PROJECTM_VIDEOQUIT,
+} projectMEvent;
+
+typedef enum {
+ /** Keycodes */
+ PROJECTM_K_RETURN,
+ PROJECTM_K_RIGHT,
+ PROJECTM_K_LEFT,
+ PROJECTM_K_UP,
+ PROJECTM_K_DOWN,
+ PROJECTM_K_PAGEUP,
+ PROJECTM_K_PAGEDOWN,
+ PROJECTM_K_INSERT,
+ PROJECTM_K_DELETE,
+ PROJECTM_K_ESCAPE,
+ PROJECTM_K_LSHIFT,
+ PROJECTM_K_RSHIFT,
+ PROJECTM_K_CAPSLOCK,
+ PROJECTM_K_LCTRL,
+ PROJECTM_K_HOME,
+ PROJECTM_K_END,
+ PROJECTM_K_BACKSPACE,
+
+ PROJECTM_K_F1,
+ PROJECTM_K_F2,
+ PROJECTM_K_F3,
+ PROJECTM_K_F4,
+ PROJECTM_K_F5,
+ PROJECTM_K_F6,
+ PROJECTM_K_F7,
+ PROJECTM_K_F8,
+ PROJECTM_K_F9,
+ PROJECTM_K_F10,
+ PROJECTM_K_F11,
+ PROJECTM_K_F12,
+
+ PROJECTM_K_0 = 48,
+ PROJECTM_K_1,
+ PROJECTM_K_2,
+ PROJECTM_K_3,
+ PROJECTM_K_4,
+ PROJECTM_K_5,
+ PROJECTM_K_6,
+ PROJECTM_K_7,
+ PROJECTM_K_8,
+ PROJECTM_K_9,
+
+ PROJECTM_K_A = 65,
+ PROJECTM_K_B,
+ PROJECTM_K_C,
+ PROJECTM_K_D,
+ PROJECTM_K_E,
+ PROJECTM_K_F,
+ PROJECTM_K_G,
+ PROJECTM_K_H,
+ PROJECTM_K_I,
+ PROJECTM_K_J,
+ PROJECTM_K_K,
+ PROJECTM_K_L,
+ PROJECTM_K_M,
+ PROJECTM_K_N,
+ PROJECTM_K_O,
+ PROJECTM_K_P,
+ PROJECTM_K_Q,
+ PROJECTM_K_R,
+ PROJECTM_K_S,
+ PROJECTM_K_T,
+ PROJECTM_K_U,
+ PROJECTM_K_V,
+ PROJECTM_K_W,
+ PROJECTM_K_X,
+ PROJECTM_K_Y,
+ PROJECTM_K_Z,
+
+ PROJECTM_K_a = 97,
+ PROJECTM_K_b,
+ PROJECTM_K_c,
+ PROJECTM_K_d,
+ PROJECTM_K_e,
+ PROJECTM_K_f,
+ PROJECTM_K_g,
+ PROJECTM_K_h,
+ PROJECTM_K_i,
+ PROJECTM_K_j,
+ PROJECTM_K_k,
+ PROJECTM_K_l,
+ PROJECTM_K_m,
+ PROJECTM_K_n,
+ PROJECTM_K_o,
+ PROJECTM_K_p,
+ PROJECTM_K_q,
+ PROJECTM_K_r,
+ PROJECTM_K_s,
+ PROJECTM_K_t,
+ PROJECTM_K_u,
+ PROJECTM_K_v,
+ PROJECTM_K_w,
+ PROJECTM_K_x,
+ PROJECTM_K_y,
+ PROJECTM_K_z,
+ PROJECTM_K_NONE,
+ PROJECTM_K_PLUS,
+ PROJECTM_K_MINUS,
+ PROJECTM_K_EQUALS
+} projectMKeycode;
+
+typedef enum {
+ /** Modifiers */
+ PROJECTM_KMOD_LSHIFT,
+ PROJECTM_KMOD_RSHIFT,
+ PROJECTM_KMOD_CAPS,
+ PROJECTM_KMOD_LCTRL,
+ PROJECTM_KMOD_RCTRL,
+} projectMModifier;
+
+
+#endif /** !_PROJECTM_EVENT_H */
diff --git a/src/libprojectM/fatal.h b/src/libprojectM/fatal.h
index 57a6285..dcb50b7 100644
--- a/src/libprojectM/fatal.h
+++ b/src/libprojectM/fatal.h
@@ -1,43 +1,44 @@
-/**
- * projectM -- Milkdrop-esque visualisation SDK
- * Copyright (C)2003-2007 projectM Team
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * See 'LICENSE.txt' included within this release
- *
- */
-/**
- * $Id: fatal.h,v 1.1.1.1 2005/12/23 18:05:05 psperl Exp $
- *
- * Error codes
- *
- * $Log$
- */
-
-#ifndef _FATAL_H
-#define _FATAL_H
-
-/* Fatal Error Definitions */
-
-#define PROJECTM_OUTOFMEM_ERROR -7; /* out of memory */
-#define PROJECTM_ERROR -1 /* non specific error */
-#define PROJECTM_SUCCESS 1
-#define PROJECTM_FAILURE -1
-#define PROJECTM_PARSE_ERROR -11
-#define PROJECTM_DIV_BY_ZERO -3
-#define PROJECTM_OK 2
-
-#endif /** !_FATAL_H */
-
+/**
+ * projectM -- Milkdrop-esque visualisation SDK
+ * Copyright (C)2003-2007 projectM Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * See 'LICENSE.txt' included within this release
+ *
+ */
+/**
+ * $Id: fatal.h,v 1.1.1.1 2005/12/23 18:05:05 psperl Exp $
+ *
+ * Error codes
+ *
+ * $Log$
+ */
+
+#ifndef _FATAL_H
+#define _FATAL_H
+
+
+/* Fatal Error Definitions */
+
+#define PROJECTM_OUTOFMEM_ERROR (-7) /* out of memory */
+#define PROJECTM_ERROR (-1) /* non specific error */
+#define PROJECTM_SUCCESS 1
+#define PROJECTM_FAILURE (-1)
+#define PROJECTM_PARSE_ERROR (-11)
+#define PROJECTM_DIV_BY_ZERO (-3)
+#define PROJECTM_OK 2
+
+
+#endif /** !_FATAL_H */
diff --git a/src/libprojectM/fftsg.cpp b/src/libprojectM/fftsg.cpp
index d005f77..e9c04fd 100644
--- a/src/libprojectM/fftsg.cpp
+++ b/src/libprojectM/fftsg.cpp
@@ -1,3314 +1,3313 @@
-/*
-Fast Fourier/Cosine/Sine Transform
- dimension :one
- data length :power of 2
- decimation :frequency
- radix :split-radix
- data :inplace
- table :use
-functions
- cdft: Complex Discrete Fourier Transform
- rdft: Real Discrete Fourier Transform
- ddct: Discrete Cosine Transform
- ddst: Discrete Sine Transform
- dfct: Cosine Transform of RDFT (Real Symmetric DFT)
- dfst: Sine Transform of RDFT (Real Anti-symmetric DFT)
-function prototypes
- void cdft(int, int, double *, int *, double *);
- void rdft(int, int, double *, int *, double *);
- void ddct(int, int, double *, int *, double *);
- void ddst(int, int, double *, int *, double *);
- void dfct(int, double *, double *, int *, double *);
- void dfst(int, double *, double *, int *, double *);
-macro definitions
- USE_CDFT_PTHREADS : default=not defined
- CDFT_THREADS_BEGIN_N : must be >= 512, default=8192
- CDFT_4THREADS_BEGIN_N : must be >= 512, default=65536
- USE_CDFT_WINTHREADS : default=not defined
- CDFT_THREADS_BEGIN_N : must be >= 512, default=32768
- CDFT_4THREADS_BEGIN_N : must be >= 512, default=524288
-
-
--------- Complex DFT (Discrete Fourier Transform) --------
- [definition]
- <case1>
- X[k] = sum_j=0^n-1 x[j]*exp(2*pi*i*j*k/n), 0<=k<n
- <case2>
- X[k] = sum_j=0^n-1 x[j]*exp(-2*pi*i*j*k/n), 0<=k<n
- (notes: sum_j=0^n-1 is a summation from j=0 to n-1)
- [usage]
- <case1>
- ip[0] = 0; // first time only
- cdft(2*n, 1, a, ip, w);
- <case2>
- ip[0] = 0; // first time only
- cdft(2*n, -1, a, ip, w);
- [parameters]
- 2*n :data length (int)
- n >= 1, n = power of 2
- a[0...2*n-1] :input/output data (double *)
- input data
- a[2*j] = Re(x[j]),
- a[2*j+1] = Im(x[j]), 0<=j<n
- output data
- a[2*k] = Re(X[k]),
- a[2*k+1] = Im(X[k]), 0<=k<n
- ip[0...*] :work area for bit reversal (int *)
- length of ip >= 2+sqrt(n)
- strictly,
- length of ip >=
- 2+(1<<(int)(log(n+0.5)/log(2))/2).
- ip[0],ip[1] are pointers of the cos/sin table.
- w[0...n/2-1] :cos/sin table (double *)
- w[],ip[] are initialized if ip[0] == 0.
- [remark]
- Inverse of
- cdft(2*n, -1, a, ip, w);
- is
- cdft(2*n, 1, a, ip, w);
- for (j = 0; j <= 2 * n - 1; j++) {
- a[j] *= 1.0 / n;
- }
- .
-
-
--------- Real DFT / Inverse of Real DFT --------
- [definition]
- <case1> RDFT
- R[k] = sum_j=0^n-1 a[j]*cos(2*pi*j*k/n), 0<=k<=n/2
- I[k] = sum_j=0^n-1 a[j]*sin(2*pi*j*k/n), 0<k<n/2
- <case2> IRDFT (excluding scale)
- a[k] = (R[0] + R[n/2]*cos(pi*k))/2 +
- sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) +
- sum_j=1^n/2-1 I[j]*sin(2*pi*j*k/n), 0<=k<n
- [usage]
- <case1>
- ip[0] = 0; // first time only
- rdft(n, 1, a, ip, w);
- <case2>
- ip[0] = 0; // first time only
- rdft(n, -1, a, ip, w);
- [parameters]
- n :data length (int)
- n >= 2, n = power of 2
- a[0...n-1] :input/output data (double *)
- <case1>
- output data
- a[2*k] = R[k], 0<=k<n/2
- a[2*k+1] = I[k], 0<k<n/2
- a[1] = R[n/2]
- <case2>
- input data
- a[2*j] = R[j], 0<=j<n/2
- a[2*j+1] = I[j], 0<j<n/2
- a[1] = R[n/2]
- ip[0...*] :work area for bit reversal (int *)
- length of ip >= 2+sqrt(n/2)
- strictly,
- length of ip >=
- 2+(1<<(int)(log(n/2+0.5)/log(2))/2).
- ip[0],ip[1] are pointers of the cos/sin table.
- w[0...n/2-1] :cos/sin table (double *)
- w[],ip[] are initialized if ip[0] == 0.
- [remark]
- Inverse of
- rdft(n, 1, a, ip, w);
- is
- rdft(n, -1, a, ip, w);
- for (j = 0; j <= n - 1; j++) {
- a[j] *= 2.0 / n;
- }
- .
-
-
--------- DCT (Discrete Cosine Transform) / Inverse of DCT --------
- [definition]
- <case1> IDCT (excluding scale)
- C[k] = sum_j=0^n-1 a[j]*cos(pi*j*(k+1/2)/n), 0<=k<n
- <case2> DCT
- C[k] = sum_j=0^n-1 a[j]*cos(pi*(j+1/2)*k/n), 0<=k<n
- [usage]
- <case1>
- ip[0] = 0; // first time only
- ddct(n, 1, a, ip, w);
- <case2>
- ip[0] = 0; // first time only
- ddct(n, -1, a, ip, w);
- [parameters]
- n :data length (int)
- n >= 2, n = power of 2
- a[0...n-1] :input/output data (double *)
- output data
- a[k] = C[k], 0<=k<n
- ip[0...*] :work area for bit reversal (int *)
- length of ip >= 2+sqrt(n/2)
- strictly,
- length of ip >=
- 2+(1<<(int)(log(n/2+0.5)/log(2))/2).
- ip[0],ip[1] are pointers of the cos/sin table.
- w[0...n*5/4-1] :cos/sin table (double *)
- w[],ip[] are initialized if ip[0] == 0.
- [remark]
- Inverse of
- ddct(n, -1, a, ip, w);
- is
- a[0] *= 0.5;
- ddct(n, 1, a, ip, w);
- for (j = 0; j <= n - 1; j++) {
- a[j] *= 2.0 / n;
- }
- .
-
-
--------- DST (Discrete Sine Transform) / Inverse of DST --------
- [definition]
- <case1> IDST (excluding scale)
- S[k] = sum_j=1^n A[j]*sin(pi*j*(k+1/2)/n), 0<=k<n
- <case2> DST
- S[k] = sum_j=0^n-1 a[j]*sin(pi*(j+1/2)*k/n), 0<k<=n
- [usage]
- <case1>
- ip[0] = 0; // first time only
- ddst(n, 1, a, ip, w);
- <case2>
- ip[0] = 0; // first time only
- ddst(n, -1, a, ip, w);
- [parameters]
- n :data length (int)
- n >= 2, n = power of 2
- a[0...n-1] :input/output data (double *)
- <case1>
- input data
- a[j] = A[j], 0<j<n
- a[0] = A[n]
- output data
- a[k] = S[k], 0<=k<n
- <case2>
- output data
- a[k] = S[k], 0<k<n
- a[0] = S[n]
- ip[0...*] :work area for bit reversal (int *)
- length of ip >= 2+sqrt(n/2)
- strictly,
- length of ip >=
- 2+(1<<(int)(log(n/2+0.5)/log(2))/2).
- ip[0],ip[1] are pointers of the cos/sin table.
- w[0...n*5/4-1] :cos/sin table (double *)
- w[],ip[] are initialized if ip[0] == 0.
- [remark]
- Inverse of
- ddst(n, -1, a, ip, w);
- is
- a[0] *= 0.5;
- ddst(n, 1, a, ip, w);
- for (j = 0; j <= n - 1; j++) {
- a[j] *= 2.0 / n;
- }
- .
-
-
--------- Cosine Transform of RDFT (Real Symmetric DFT) --------
- [definition]
- C[k] = sum_j=0^n a[j]*cos(pi*j*k/n), 0<=k<=n
- [usage]
- ip[0] = 0; // first time only
- dfct(n, a, t, ip, w);
- [parameters]
- n :data length - 1 (int)
- n >= 2, n = power of 2
- a[0...n] :input/output data (double *)
- output data
- a[k] = C[k], 0<=k<=n
- t[0...n/2] :work area (double *)
- ip[0...*] :work area for bit reversal (int *)
- length of ip >= 2+sqrt(n/4)
- strictly,
- length of ip >=
- 2+(1<<(int)(log(n/4+0.5)/log(2))/2).
- ip[0],ip[1] are pointers of the cos/sin table.
- w[0...n*5/8-1] :cos/sin table (double *)
- w[],ip[] are initialized if ip[0] == 0.
- [remark]
- Inverse of
- a[0] *= 0.5;
- a[n] *= 0.5;
- dfct(n, a, t, ip, w);
- is
- a[0] *= 0.5;
- a[n] *= 0.5;
- dfct(n, a, t, ip, w);
- for (j = 0; j <= n; j++) {
- a[j] *= 2.0 / n;
- }
- .
-
-
--------- Sine Transform of RDFT (Real Anti-symmetric DFT) --------
- [definition]
- S[k] = sum_j=1^n-1 a[j]*sin(pi*j*k/n), 0<k<n
- [usage]
- ip[0] = 0; // first time only
- dfst(n, a, t, ip, w);
- [parameters]
- n :data length + 1 (int)
- n >= 2, n = power of 2
- a[0...n-1] :input/output data (double *)
- output data
- a[k] = S[k], 0<k<n
- (a[0] is used for work area)
- t[0...n/2-1] :work area (double *)
- ip[0...*] :work area for bit reversal (int *)
- length of ip >= 2+sqrt(n/4)
- strictly,
- length of ip >=
- 2+(1<<(int)(log(n/4+0.5)/log(2))/2).
- ip[0],ip[1] are pointers of the cos/sin table.
- w[0...n*5/8-1] :cos/sin table (double *)
- w[],ip[] are initialized if ip[0] == 0.
- [remark]
- Inverse of
- dfst(n, a, t, ip, w);
- is
- dfst(n, a, t, ip, w);
- for (j = 1; j <= n - 1; j++) {
- a[j] *= 2.0 / n;
- }
- .
-
-
-Appendix :
- The cos/sin table is recalculated when the larger table required.
- w[] and ip[] are compatible with all routines.
-*/
-
-
-void cdft(int n, int isgn, double *a, int *ip, double *w)
-{
- void makewt(int nw, int *ip, double *w);
- void cftfsub(int n, double *a, int *ip, int nw, double *w);
- void cftbsub(int n, double *a, int *ip, int nw, double *w);
- int nw;
-
- nw = ip[0];
- if (n > (nw << 2)) {
- nw = n >> 2;
- makewt(nw, ip, w);
- }
- if (isgn >= 0) {
- cftfsub(n, a, ip, nw, w);
- } else {
- cftbsub(n, a, ip, nw, w);
- }
-}
-
-
-void rdft(int n, int isgn, double *a, int *ip, double *w)
-{
- void makewt(int nw, int *ip, double *w);
- void makect(int nc, int *ip, double *c);
- void cftfsub(int n, double *a, int *ip, int nw, double *w);
- void cftbsub(int n, double *a, int *ip, int nw, double *w);
- void rftfsub(int n, double *a, int nc, double *c);
- void rftbsub(int n, double *a, int nc, double *c);
- int nw, nc;
- double xi;
-
- nw = ip[0];
- if (n > (nw << 2)) {
- nw = n >> 2;
- makewt(nw, ip, w);
- }
- nc = ip[1];
- if (n > (nc << 2)) {
- nc = n >> 2;
- makect(nc, ip, w + nw);
- }
- if (isgn >= 0) {
- if (n > 4) {
- cftfsub(n, a, ip, nw, w);
- rftfsub(n, a, nc, w + nw);
- } else if (n == 4) {
- cftfsub(n, a, ip, nw, w);
- }
- xi = a[0] - a[1];
- a[0] += a[1];
- a[1] = xi;
- } else {
- a[1] = 0.5 * (a[0] - a[1]);
- a[0] -= a[1];
- if (n > 4) {
- rftbsub(n, a, nc, w + nw);
- cftbsub(n, a, ip, nw, w);
- } else if (n == 4) {
- cftbsub(n, a, ip, nw, w);
- }
- }
-}
-
-
-void ddct(int n, int isgn, double *a, int *ip, double *w)
-{
- void makewt(int nw, int *ip, double *w);
- void makect(int nc, int *ip, double *c);
- void cftfsub(int n, double *a, int *ip, int nw, double *w);
- void cftbsub(int n, double *a, int *ip, int nw, double *w);
- void rftfsub(int n, double *a, int nc, double *c);
- void rftbsub(int n, double *a, int nc, double *c);
- void dctsub(int n, double *a, int nc, double *c);
- int j, nw, nc;
- double xr;
-
- nw = ip[0];
- if (n > (nw << 2)) {
- nw = n >> 2;
- makewt(nw, ip, w);
- }
- nc = ip[1];
- if (n > nc) {
- nc = n;
- makect(nc, ip, w + nw);
- }
- if (isgn < 0) {
- xr = a[n - 1];
- for (j = n - 2; j >= 2; j -= 2) {
- a[j + 1] = a[j] - a[j - 1];
- a[j] += a[j - 1];
- }
- a[1] = a[0] - xr;
- a[0] += xr;
- if (n > 4) {
- rftbsub(n, a, nc, w + nw);
- cftbsub(n, a, ip, nw, w);
- } else if (n == 4) {
- cftbsub(n, a, ip, nw, w);
- }
- }
- dctsub(n, a, nc, w + nw);
- if (isgn >= 0) {
- if (n > 4) {
- cftfsub(n, a, ip, nw, w);
- rftfsub(n, a, nc, w + nw);
- } else if (n == 4) {
- cftfsub(n, a, ip, nw, w);
- }
- xr = a[0] - a[1];
- a[0] += a[1];
- for (j = 2; j < n; j += 2) {
- a[j - 1] = a[j] - a[j + 1];
- a[j] += a[j + 1];
- }
- a[n - 1] = xr;
- }
-}
-
-
-void ddst(int n, int isgn, double *a, int *ip, double *w)
-{
- void makewt(int nw, int *ip, double *w);
- void makect(int nc, int *ip, double *c);
- void cftfsub(int n, double *a, int *ip, int nw, double *w);
- void cftbsub(int n, double *a, int *ip, int nw, double *w);
- void rftfsub(int n, double *a, int nc, double *c);
- void rftbsub(int n, double *a, int nc, double *c);
- void dstsub(int n, double *a, int nc, double *c);
- int j, nw, nc;
- double xr;
-
- nw = ip[0];
- if (n > (nw << 2)) {
- nw = n >> 2;
- makewt(nw, ip, w);
- }
- nc = ip[1];
- if (n > nc) {
- nc = n;
- makect(nc, ip, w + nw);
- }
- if (isgn < 0) {
- xr = a[n - 1];
- for (j = n - 2; j >= 2; j -= 2) {
- a[j + 1] = -a[j] - a[j - 1];
- a[j] -= a[j - 1];
- }
- a[1] = a[0] + xr;
- a[0] -= xr;
- if (n > 4) {
- rftbsub(n, a, nc, w + nw);
- cftbsub(n, a, ip, nw, w);
- } else if (n == 4) {
- cftbsub(n, a, ip, nw, w);
- }
- }
- dstsub(n, a, nc, w + nw);
- if (isgn >= 0) {
- if (n > 4) {
- cftfsub(n, a, ip, nw, w);
- rftfsub(n, a, nc, w + nw);
- } else if (n == 4) {
- cftfsub(n, a, ip, nw, w);
- }
- xr = a[0] - a[1];
- a[0] += a[1];
- for (j = 2; j < n; j += 2) {
- a[j - 1] = -a[j] - a[j + 1];
- a[j] -= a[j + 1];
- }
- a[n - 1] = -xr;
- }
-}
-
-
-void dfct(int n, double *a, double *t, int *ip, double *w)
-{
- void makewt(int nw, int *ip, double *w);
- void makect(int nc, int *ip, double *c);
- void cftfsub(int n, double *a, int *ip, int nw, double *w);
- void rftfsub(int n, double *a, int nc, double *c);
- void dctsub(int n, double *a, int nc, double *c);
- int j, k, l, m, mh, nw, nc;
- double xr, xi, yr, yi;
-
- nw = ip[0];
- if (n > (nw << 3)) {
- nw = n >> 3;
- makewt(nw, ip, w);
- }
- nc = ip[1];
- if (n > (nc << 1)) {
- nc = n >> 1;
- makect(nc, ip, w + nw);
- }
- m = n >> 1;
- yi = a[m];
- xi = a[0] + a[n];
- a[0] -= a[n];
- t[0] = xi - yi;
- t[m] = xi + yi;
- if (n > 2) {
- mh = m >> 1;
- for (j = 1; j < mh; j++) {
- k = m - j;
- xr = a[j] - a[n - j];
- xi = a[j] + a[n - j];
- yr = a[k] - a[n - k];
- yi = a[k] + a[n - k];
- a[j] = xr;
- a[k] = yr;
- t[j] = xi - yi;
- t[k] = xi + yi;
- }
- t[mh] = a[mh] + a[n - mh];
- a[mh] -= a[n - mh];
- dctsub(m, a, nc, w + nw);
- if (m > 4) {
- cftfsub(m, a, ip, nw, w);
- rftfsub(m, a, nc, w + nw);
- } else if (m == 4) {
- cftfsub(m, a, ip, nw, w);
- }
- a[n - 1] = a[0] - a[1];
- a[1] = a[0] + a[1];
- for (j = m - 2; j >= 2; j -= 2) {
- a[2 * j + 1] = a[j] + a[j + 1];
- a[2 * j - 1] = a[j] - a[j + 1];
- }
- l = 2;
- m = mh;
- while (m >= 2) {
- dctsub(m, t, nc, w + nw);
- if (m > 4) {
- cftfsub(m, t, ip, nw, w);
- rftfsub(m, t, nc, w + nw);
- } else if (m == 4) {
- cftfsub(m, t, ip, nw, w);
- }
- a[n - l] = t[0] - t[1];
- a[l] = t[0] + t[1];
- k = 0;
- for (j = 2; j < m; j += 2) {
- k += l << 2;
- a[k - l] = t[j] - t[j + 1];
- a[k + l] = t[j] + t[j + 1];
- }
- l <<= 1;
- mh = m >> 1;
- for (j = 0; j < mh; j++) {
- k = m - j;
- t[j] = t[m + k] - t[m + j];
- t[k] = t[m + k] + t[m + j];
- }
- t[mh] = t[m + mh];
- m = mh;
- }
- a[l] = t[0];
- a[n] = t[2] - t[1];
- a[0] = t[2] + t[1];
- } else {
- a[1] = a[0];
- a[2] = t[0];
- a[0] = t[1];
- }
-}
-
-
-void dfst(int n, double *a, double *t, int *ip, double *w)
-{
- void makewt(int nw, int *ip, double *w);
- void makect(int nc, int *ip, double *c);
- void cftfsub(int n, double *a, int *ip, int nw, double *w);
- void rftfsub(int n, double *a, int nc, double *c);
- void dstsub(int n, double *a, int nc, double *c);
- int j, k, l, m, mh, nw, nc;
- double xr, xi, yr, yi;
-
- nw = ip[0];
- if (n > (nw << 3)) {
- nw = n >> 3;
- makewt(nw, ip, w);
- }
- nc = ip[1];
- if (n > (nc << 1)) {
- nc = n >> 1;
- makect(nc, ip, w + nw);
- }
- if (n > 2) {
- m = n >> 1;
- mh = m >> 1;
- for (j = 1; j < mh; j++) {
- k = m - j;
- xr = a[j] + a[n - j];
- xi = a[j] - a[n - j];
- yr = a[k] + a[n - k];
- yi = a[k] - a[n - k];
- a[j] = xr;
- a[k] = yr;
- t[j] = xi + yi;
- t[k] = xi - yi;
- }
- t[0] = a[mh] - a[n - mh];
- a[mh] += a[n - mh];
- a[0] = a[m];
- dstsub(m, a, nc, w + nw);
- if (m > 4) {
- cftfsub(m, a, ip, nw, w);
- rftfsub(m, a, nc, w + nw);
- } else if (m == 4) {
- cftfsub(m, a, ip, nw, w);
- }
- a[n - 1] = a[1] - a[0];
- a[1] = a[0] + a[1];
- for (j = m - 2; j >= 2; j -= 2) {
- a[2 * j + 1] = a[j] - a[j + 1];
- a[2 * j - 1] = -a[j] - a[j + 1];
- }
- l = 2;
- m = mh;
- while (m >= 2) {
- dstsub(m, t, nc, w + nw);
- if (m > 4) {
- cftfsub(m, t, ip, nw, w);
- rftfsub(m, t, nc, w + nw);
- } else if (m == 4) {
- cftfsub(m, t, ip, nw, w);
- }
- a[n - l] = t[1] - t[0];
- a[l] = t[0] + t[1];
- k = 0;
- for (j = 2; j < m; j += 2) {
- k += l << 2;
- a[k - l] = -t[j] - t[j + 1];
- a[k + l] = t[j] - t[j + 1];
- }
- l <<= 1;
- mh = m >> 1;
- for (j = 1; j < mh; j++) {
- k = m - j;
- t[j] = t[m + k] + t[m + j];
- t[k] = t[m + k] - t[m + j];
- }
- t[0] = t[m + mh];
- m = mh;
- }
- a[l] = t[0];
- }
- a[0] = 0;
-}
-
-
-/* -------- initializing routines -------- */
-
-
-#include <math.h>
-
-void makewt(int nw, int *ip, double *w)
-{
- void makeipt(int nw, int *ip);
- int j, nwh, nw0, nw1;
- double delta, wn4r, wk1r, wk1i, wk3r, wk3i;
-
- ip[0] = nw;
- ip[1] = 1;
- if (nw > 2) {
- nwh = nw >> 1;
- delta = atan(1.0) / nwh;
- wn4r = cos(delta * nwh);
- w[0] = 1;
- w[1] = wn4r;
- if (nwh == 4) {
- w[2] = cos(delta * 2);
- w[3] = sin(delta * 2);
- } else if (nwh > 4) {
- makeipt(nw, ip);
- w[2] = 0.5 / cos(delta * 2);
- w[3] = 0.5 / cos(delta * 6);
- for (j = 4; j < nwh; j += 4) {
- w[j] = cos(delta * j);
- w[j + 1] = sin(delta * j);
- w[j + 2] = cos(3 * delta * j);
- w[j + 3] = -sin(3 * delta * j);
- }
- }
- nw0 = 0;
- while (nwh > 2) {
- nw1 = nw0 + nwh;
- nwh >>= 1;
- w[nw1] = 1;
- w[nw1 + 1] = wn4r;
- if (nwh == 4) {
- wk1r = w[nw0 + 4];
- wk1i = w[nw0 + 5];
- w[nw1 + 2] = wk1r;
- w[nw1 + 3] = wk1i;
- } else if (nwh > 4) {
- wk1r = w[nw0 + 4];
- wk3r = w[nw0 + 6];
- w[nw1 + 2] = 0.5 / wk1r;
- w[nw1 + 3] = 0.5 / wk3r;
- for (j = 4; j < nwh; j += 4) {
- wk1r = w[nw0 + 2 * j];
- wk1i = w[nw0 + 2 * j + 1];
- wk3r = w[nw0 + 2 * j + 2];
- wk3i = w[nw0 + 2 * j + 3];
- w[nw1 + j] = wk1r;
- w[nw1 + j + 1] = wk1i;
- w[nw1 + j + 2] = wk3r;
- w[nw1 + j + 3] = wk3i;
- }
- }
- nw0 = nw1;
- }
- }
-}
-
-
-void makeipt(int nw, int *ip)
-{
- int j, l, m, m2, p, q;
-
- ip[2] = 0;
- ip[3] = 16;
- m = 2;
- for (l = nw; l > 32; l >>= 2) {
- m2 = m << 1;
- q = m2 << 3;
- for (j = m; j < m2; j++) {
- p = ip[j] << 2;
- ip[m + j] = p;
- ip[m2 + j] = p + q;
- }
- m = m2;
- }
-}
-
-
-void makect(int nc, int *ip, double *c)
-{
- int j, nch;
- double delta;
-
- ip[1] = nc;
- if (nc > 1) {
- nch = nc >> 1;
- delta = atan(1.0) / nch;
- c[0] = cos(delta * nch);
- c[nch] = 0.5 * c[0];
- for (j = 1; j < nch; j++) {
- c[j] = 0.5 * cos(delta * j);
- c[nc - j] = 0.5 * sin(delta * j);
- }
- }
-}
-
-
-/* -------- child routines -------- */
-
-
-#ifdef USE_CDFT_PTHREADS
-#define USE_CDFT_THREADS
-#ifndef CDFT_THREADS_BEGIN_N
-#define CDFT_THREADS_BEGIN_N 8192
-#endif
-#ifndef CDFT_4THREADS_BEGIN_N
-#define CDFT_4THREADS_BEGIN_N 65536
-#endif
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#define cdft_thread_t pthread_t
-#define cdft_thread_create(thp,func,argp) { \
- if (pthread_create(thp, NULL, func, (void *) argp) != 0) { \
- fprintf(stderr, "cdft thread error\n"); \
- exit(1); \
- } \
-}
-#define cdft_thread_wait(th) { \
- if (pthread_join(th, NULL) != 0) { \
- fprintf(stderr, "cdft thread error\n"); \
- exit(1); \
- } \
-}
-#endif /* USE_CDFT_PTHREADS */
-
-
-#ifdef USE_CDFT_WINTHREADS
-#define USE_CDFT_THREADS
-#ifndef CDFT_THREADS_BEGIN_N
-#define CDFT_THREADS_BEGIN_N 32768
-#endif
-#ifndef CDFT_4THREADS_BEGIN_N
-#define CDFT_4THREADS_BEGIN_N 524288
-#endif
-#include <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#define cdft_thread_t HANDLE
-#define cdft_thread_create(thp,func,argp) { \
- DWORD thid; \
- *(thp) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, (LPVOID) argp, 0, &thid); \
- if (*(thp) == 0) { \
- fprintf(stderr, "cdft thread error\n"); \
- exit(1); \
- } \
-}
-#define cdft_thread_wait(th) { \
- WaitForSingleObject(th, INFINITE); \
- CloseHandle(th); \
-}
-#endif /* USE_CDFT_WINTHREADS */
-
-
-void cftfsub(int n, double *a, int *ip, int nw, double *w)
-{
- void bitrv2(int n, int *ip, double *a);
- void bitrv216(double *a);
- void bitrv208(double *a);
- void cftf1st(int n, double *a, double *w);
- void cftrec4(int n, double *a, int nw, double *w);
- void cftleaf(int n, int isplt, double *a, int nw, double *w);
- void cftfx41(int n, double *a, int nw, double *w);
- void cftf161(double *a, double *w);
- void cftf081(double *a, double *w);
- void cftf040(double *a);
- void cftx020(double *a);
-#ifdef USE_CDFT_THREADS
- void cftrec4_th(int n, double *a, int nw, double *w);
-#endif /* USE_CDFT_THREADS */
-
- if (n > 8) {
- if (n > 32) {
- cftf1st(n, a, &w[nw - (n >> 2)]);
-#ifdef USE_CDFT_THREADS
- if (n > CDFT_THREADS_BEGIN_N) {
- cftrec4_th(n, a, nw, w);
- } else
-#endif /* USE_CDFT_THREADS */
- if (n > 512) {
- cftrec4(n, a, nw, w);
- } else if (n > 128) {
- cftleaf(n, 1, a, nw, w);
- } else {
- cftfx41(n, a, nw, w);
- }
- bitrv2(n, ip, a);
- } else if (n == 32) {
- cftf161(a, &w[nw - 8]);
- bitrv216(a);
- } else {
- cftf081(a, w);
- bitrv208(a);
- }
- } else if (n == 8) {
- cftf040(a);
- } else if (n == 4) {
- cftx020(a);
- }
-}
-
-
-void cftbsub(int n, double *a, int *ip, int nw, double *w)
-{
- void bitrv2conj(int n, int *ip, double *a);
- void bitrv216neg(double *a);
- void bitrv208neg(double *a);
- void cftb1st(int n, double *a, double *w);
- void cftrec4(int n, double *a, int nw, double *w);
- void cftleaf(int n, int isplt, double *a, int nw, double *w);
- void cftfx41(int n, double *a, int nw, double *w);
- void cftf161(double *a, double *w);
- void cftf081(double *a, double *w);
- void cftb040(double *a);
- void cftx020(double *a);
-#ifdef USE_CDFT_THREADS
- void cftrec4_th(int n, double *a, int nw, double *w);
-#endif /* USE_CDFT_THREADS */
-
- if (n > 8) {
- if (n > 32) {
- cftb1st(n, a, &w[nw - (n >> 2)]);
-#ifdef USE_CDFT_THREADS
- if (n > CDFT_THREADS_BEGIN_N) {
- cftrec4_th(n, a, nw, w);
- } else
-#endif /* USE_CDFT_THREADS */
- if (n > 512) {
- cftrec4(n, a, nw, w);
- } else if (n > 128) {
- cftleaf(n, 1, a, nw, w);
- } else {
- cftfx41(n, a, nw, w);
- }
- bitrv2conj(n, ip, a);
- } else if (n == 32) {
- cftf161(a, &w[nw - 8]);
- bitrv216neg(a);
- } else {
- cftf081(a, w);
- bitrv208neg(a);
- }
- } else if (n == 8) {
- cftb040(a);
- } else if (n == 4) {
- cftx020(a);
- }
-}
-
-
-void bitrv2(int n, int *ip, double *a)
-{
- int j, j1, k, k1, l, m, nh, nm;
- double xr, xi, yr, yi;
-
- m = 1;
- for (l = n >> 2; l > 8; l >>= 2) {
- m <<= 1;
- }
- nh = n >> 1;
- nm = 4 * m;
- if (l == 8) {
- for (k = 0; k < m; k++) {
- for (j = 0; j < k; j++) {
- j1 = 4 * j + 2 * ip[m + k];
- k1 = 4 * k + 2 * ip[m + j];
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 -= nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nh;
- k1 += 2;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 += nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += 2;
- k1 += nh;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 -= nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nh;
- k1 -= 2;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 += nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- }
- k1 = 4 * k + 2 * ip[m + k];
- j1 = k1 + 2;
- k1 += nh;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 -= nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= 2;
- k1 -= nh;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nh + 2;
- k1 += nh + 2;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nh - nm;
- k1 += 2 * nm - 2;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- }
- } else {
- for (k = 0; k < m; k++) {
- for (j = 0; j < k; j++) {
- j1 = 4 * j + ip[m + k];
- k1 = 4 * k + ip[m + j];
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nh;
- k1 += 2;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += 2;
- k1 += nh;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nh;
- k1 -= 2;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- }
- k1 = 4 * k + ip[m + k];
- j1 = k1 + 2;
- k1 += nh;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += nm;
- xr = a[j1];
- xi = a[j1 + 1];
- yr = a[k1];
- yi = a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- }
- }
-}
-
-
-void bitrv2conj(int n, int *ip, double *a)
-{
- int j, j1, k, k1, l, m, nh, nm;
- double xr, xi, yr, yi;
-
- m = 1;
- for (l = n >> 2; l > 8; l >>= 2) {
- m <<= 1;
- }
- nh = n >> 1;
- nm = 4 * m;
- if (l == 8) {
- for (k = 0; k < m; k++) {
- for (j = 0; j < k; j++) {
- j1 = 4 * j + 2 * ip[m + k];
- k1 = 4 * k + 2 * ip[m + j];
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 -= nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nh;
- k1 += 2;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 += nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += 2;
- k1 += nh;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 -= nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nh;
- k1 -= 2;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 += nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- }
- k1 = 4 * k + 2 * ip[m + k];
- j1 = k1 + 2;
- k1 += nh;
- a[j1 - 1] = -a[j1 - 1];
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- a[k1 + 3] = -a[k1 + 3];
- j1 += nm;
- k1 += 2 * nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 -= nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= 2;
- k1 -= nh;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nh + 2;
- k1 += nh + 2;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nh - nm;
- k1 += 2 * nm - 2;
- a[j1 - 1] = -a[j1 - 1];
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- a[k1 + 3] = -a[k1 + 3];
- }
- } else {
- for (k = 0; k < m; k++) {
- for (j = 0; j < k; j++) {
- j1 = 4 * j + ip[m + k];
- k1 = 4 * k + ip[m + j];
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nh;
- k1 += 2;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += 2;
- k1 += nh;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 += nm;
- k1 += nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nh;
- k1 -= 2;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- j1 -= nm;
- k1 -= nm;
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- }
- k1 = 4 * k + ip[m + k];
- j1 = k1 + 2;
- k1 += nh;
- a[j1 - 1] = -a[j1 - 1];
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- a[k1 + 3] = -a[k1 + 3];
- j1 += nm;
- k1 += nm;
- a[j1 - 1] = -a[j1 - 1];
- xr = a[j1];
- xi = -a[j1 + 1];
- yr = a[k1];
- yi = -a[k1 + 1];
- a[j1] = yr;
- a[j1 + 1] = yi;
- a[k1] = xr;
- a[k1 + 1] = xi;
- a[k1 + 3] = -a[k1 + 3];
- }
- }
-}
-
-
-void bitrv216(double *a)
-{
- double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
- x5r, x5i, x7r, x7i, x8r, x8i, x10r, x10i,
- x11r, x11i, x12r, x12i, x13r, x13i, x14r, x14i;
-
- x1r = a[2];
- x1i = a[3];
- x2r = a[4];
- x2i = a[5];
- x3r = a[6];
- x3i = a[7];
- x4r = a[8];
- x4i = a[9];
- x5r = a[10];
- x5i = a[11];
- x7r = a[14];
- x7i = a[15];
- x8r = a[16];
- x8i = a[17];
- x10r = a[20];
- x10i = a[21];
- x11r = a[22];
- x11i = a[23];
- x12r = a[24];
- x12i = a[25];
- x13r = a[26];
- x13i = a[27];
- x14r = a[28];
- x14i = a[29];
- a[2] = x8r;
- a[3] = x8i;
- a[4] = x4r;
- a[5] = x4i;
- a[6] = x12r;
- a[7] = x12i;
- a[8] = x2r;
- a[9] = x2i;
- a[10] = x10r;
- a[11] = x10i;
- a[14] = x14r;
- a[15] = x14i;
- a[16] = x1r;
- a[17] = x1i;
- a[20] = x5r;
- a[21] = x5i;
- a[22] = x13r;
- a[23] = x13i;
- a[24] = x3r;
- a[25] = x3i;
- a[26] = x11r;
- a[27] = x11i;
- a[28] = x7r;
- a[29] = x7i;
-}
-
-
-void bitrv216neg(double *a)
-{
- double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
- x5r, x5i, x6r, x6i, x7r, x7i, x8r, x8i,
- x9r, x9i, x10r, x10i, x11r, x11i, x12r, x12i,
- x13r, x13i, x14r, x14i, x15r, x15i;
-
- x1r = a[2];
- x1i = a[3];
- x2r = a[4];
- x2i = a[5];
- x3r = a[6];
- x3i = a[7];
- x4r = a[8];
- x4i = a[9];
- x5r = a[10];
- x5i = a[11];
- x6r = a[12];
- x6i = a[13];
- x7r = a[14];
- x7i = a[15];
- x8r = a[16];
- x8i = a[17];
- x9r = a[18];
- x9i = a[19];
- x10r = a[20];
- x10i = a[21];
- x11r = a[22];
- x11i = a[23];
- x12r = a[24];
- x12i = a[25];
- x13r = a[26];
- x13i = a[27];
- x14r = a[28];
- x14i = a[29];
- x15r = a[30];
- x15i = a[31];
- a[2] = x15r;
- a[3] = x15i;
- a[4] = x7r;
- a[5] = x7i;
- a[6] = x11r;
- a[7] = x11i;
- a[8] = x3r;
- a[9] = x3i;
- a[10] = x13r;
- a[11] = x13i;
- a[12] = x5r;
- a[13] = x5i;
- a[14] = x9r;
- a[15] = x9i;
- a[16] = x1r;
- a[17] = x1i;
- a[18] = x14r;
- a[19] = x14i;
- a[20] = x6r;
- a[21] = x6i;
- a[22] = x10r;
- a[23] = x10i;
- a[24] = x2r;
- a[25] = x2i;
- a[26] = x12r;
- a[27] = x12i;
- a[28] = x4r;
- a[29] = x4i;
- a[30] = x8r;
- a[31] = x8i;
-}
-
-
-void bitrv208(double *a)
-{
- double x1r, x1i, x3r, x3i, x4r, x4i, x6r, x6i;
-
- x1r = a[2];
- x1i = a[3];
- x3r = a[6];
- x3i = a[7];
- x4r = a[8];
- x4i = a[9];
- x6r = a[12];
- x6i = a[13];
- a[2] = x4r;
- a[3] = x4i;
- a[6] = x6r;
- a[7] = x6i;
- a[8] = x1r;
- a[9] = x1i;
- a[12] = x3r;
- a[13] = x3i;
-}
-
-
-void bitrv208neg(double *a)
-{
- double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
- x5r, x5i, x6r, x6i, x7r, x7i;
-
- x1r = a[2];
- x1i = a[3];
- x2r = a[4];
- x2i = a[5];
- x3r = a[6];
- x3i = a[7];
- x4r = a[8];
- x4i = a[9];
- x5r = a[10];
- x5i = a[11];
- x6r = a[12];
- x6i = a[13];
- x7r = a[14];
- x7i = a[15];
- a[2] = x7r;
- a[3] = x7i;
- a[4] = x3r;
- a[5] = x3i;
- a[6] = x5r;
- a[7] = x5i;
- a[8] = x1r;
- a[9] = x1i;
- a[10] = x6r;
- a[11] = x6i;
- a[12] = x2r;
- a[13] = x2i;
- a[14] = x4r;
- a[15] = x4i;
-}
-
-
-void cftf1st(int n, double *a, double *w)
-{
- int j, j0, j1, j2, j3, k, m, mh;
- double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
- wd1r, wd1i, wd3r, wd3i;
- double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
- y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
-
- mh = n >> 3;
- m = 2 * mh;
- j1 = m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[0] + a[j2];
- x0i = a[1] + a[j2 + 1];
- x1r = a[0] - a[j2];
- x1i = a[1] - a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[0] = x0r + x2r;
- a[1] = x0i + x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- a[j2] = x1r - x3i;
- a[j2 + 1] = x1i + x3r;
- a[j3] = x1r + x3i;
- a[j3 + 1] = x1i - x3r;
- wn4r = w[1];
- csc1 = w[2];
- csc3 = w[3];
- wd1r = 1;
- wd1i = 0;
- wd3r = 1;
- wd3i = 0;
- k = 0;
- for (j = 2; j < mh - 2; j += 4) {
- k += 4;
- wk1r = csc1 * (wd1r + w[k]);
- wk1i = csc1 * (wd1i + w[k + 1]);
- wk3r = csc3 * (wd3r + w[k + 2]);
- wk3i = csc3 * (wd3i + w[k + 3]);
- wd1r = w[k];
- wd1i = w[k + 1];
- wd3r = w[k + 2];
- wd3i = w[k + 3];
- j1 = j + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j] + a[j2];
- x0i = a[j + 1] + a[j2 + 1];
- x1r = a[j] - a[j2];
- x1i = a[j + 1] - a[j2 + 1];
- y0r = a[j + 2] + a[j2 + 2];
- y0i = a[j + 3] + a[j2 + 3];
- y1r = a[j + 2] - a[j2 + 2];
- y1i = a[j + 3] - a[j2 + 3];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- y2r = a[j1 + 2] + a[j3 + 2];
- y2i = a[j1 + 3] + a[j3 + 3];
- y3r = a[j1 + 2] - a[j3 + 2];
- y3i = a[j1 + 3] - a[j3 + 3];
- a[j] = x0r + x2r;
- a[j + 1] = x0i + x2i;
- a[j + 2] = y0r + y2r;
- a[j + 3] = y0i + y2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- a[j1 + 2] = y0r - y2r;
- a[j1 + 3] = y0i - y2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2] = wk1r * x0r - wk1i * x0i;
- a[j2 + 1] = wk1r * x0i + wk1i * x0r;
- x0r = y1r - y3i;
- x0i = y1i + y3r;
- a[j2 + 2] = wd1r * x0r - wd1i * x0i;
- a[j2 + 3] = wd1r * x0i + wd1i * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3] = wk3r * x0r + wk3i * x0i;
- a[j3 + 1] = wk3r * x0i - wk3i * x0r;
- x0r = y1r + y3i;
- x0i = y1i - y3r;
- a[j3 + 2] = wd3r * x0r + wd3i * x0i;
- a[j3 + 3] = wd3r * x0i - wd3i * x0r;
- j0 = m - j;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0] + a[j2];
- x0i = a[j0 + 1] + a[j2 + 1];
- x1r = a[j0] - a[j2];
- x1i = a[j0 + 1] - a[j2 + 1];
- y0r = a[j0 - 2] + a[j2 - 2];
- y0i = a[j0 - 1] + a[j2 - 1];
- y1r = a[j0 - 2] - a[j2 - 2];
- y1i = a[j0 - 1] - a[j2 - 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- y2r = a[j1 - 2] + a[j3 - 2];
- y2i = a[j1 - 1] + a[j3 - 1];
- y3r = a[j1 - 2] - a[j3 - 2];
- y3i = a[j1 - 1] - a[j3 - 1];
- a[j0] = x0r + x2r;
- a[j0 + 1] = x0i + x2i;
- a[j0 - 2] = y0r + y2r;
- a[j0 - 1] = y0i + y2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- a[j1 - 2] = y0r - y2r;
- a[j1 - 1] = y0i - y2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2] = wk1i * x0r - wk1r * x0i;
- a[j2 + 1] = wk1i * x0i + wk1r * x0r;
- x0r = y1r - y3i;
- x0i = y1i + y3r;
- a[j2 - 2] = wd1i * x0r - wd1r * x0i;
- a[j2 - 1] = wd1i * x0i + wd1r * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3] = wk3i * x0r + wk3r * x0i;
- a[j3 + 1] = wk3i * x0i - wk3r * x0r;
- x0r = y1r + y3i;
- x0i = y1i - y3r;
- a[j3 - 2] = wd3i * x0r + wd3r * x0i;
- a[j3 - 1] = wd3i * x0i - wd3r * x0r;
- }
- wk1r = csc1 * (wd1r + wn4r);
- wk1i = csc1 * (wd1i + wn4r);
- wk3r = csc3 * (wd3r - wn4r);
- wk3i = csc3 * (wd3i - wn4r);
- j0 = mh;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0 - 2] + a[j2 - 2];
- x0i = a[j0 - 1] + a[j2 - 1];
- x1r = a[j0 - 2] - a[j2 - 2];
- x1i = a[j0 - 1] - a[j2 - 1];
- x2r = a[j1 - 2] + a[j3 - 2];
- x2i = a[j1 - 1] + a[j3 - 1];
- x3r = a[j1 - 2] - a[j3 - 2];
- x3i = a[j1 - 1] - a[j3 - 1];
- a[j0 - 2] = x0r + x2r;
- a[j0 - 1] = x0i + x2i;
- a[j1 - 2] = x0r - x2r;
- a[j1 - 1] = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2 - 2] = wk1r * x0r - wk1i * x0i;
- a[j2 - 1] = wk1r * x0i + wk1i * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3 - 2] = wk3r * x0r + wk3i * x0i;
- a[j3 - 1] = wk3r * x0i - wk3i * x0r;
- x0r = a[j0] + a[j2];
- x0i = a[j0 + 1] + a[j2 + 1];
- x1r = a[j0] - a[j2];
- x1i = a[j0 + 1] - a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[j0] = x0r + x2r;
- a[j0 + 1] = x0i + x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2] = wn4r * (x0r - x0i);
- a[j2 + 1] = wn4r * (x0i + x0r);
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3] = -wn4r * (x0r + x0i);
- a[j3 + 1] = -wn4r * (x0i - x0r);
- x0r = a[j0 + 2] + a[j2 + 2];
- x0i = a[j0 + 3] + a[j2 + 3];
- x1r = a[j0 + 2] - a[j2 + 2];
- x1i = a[j0 + 3] - a[j2 + 3];
- x2r = a[j1 + 2] + a[j3 + 2];
- x2i = a[j1 + 3] + a[j3 + 3];
- x3r = a[j1 + 2] - a[j3 + 2];
- x3i = a[j1 + 3] - a[j3 + 3];
- a[j0 + 2] = x0r + x2r;
- a[j0 + 3] = x0i + x2i;
- a[j1 + 2] = x0r - x2r;
- a[j1 + 3] = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2 + 2] = wk1i * x0r - wk1r * x0i;
- a[j2 + 3] = wk1i * x0i + wk1r * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3 + 2] = wk3i * x0r + wk3r * x0i;
- a[j3 + 3] = wk3i * x0i - wk3r * x0r;
-}
-
-
-void cftb1st(int n, double *a, double *w)
-{
- int j, j0, j1, j2, j3, k, m, mh;
- double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
- wd1r, wd1i, wd3r, wd3i;
- double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
- y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
-
- mh = n >> 3;
- m = 2 * mh;
- j1 = m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[0] + a[j2];
- x0i = -a[1] - a[j2 + 1];
- x1r = a[0] - a[j2];
- x1i = -a[1] + a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[0] = x0r + x2r;
- a[1] = x0i - x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i + x2i;
- a[j2] = x1r + x3i;
- a[j2 + 1] = x1i + x3r;
- a[j3] = x1r - x3i;
- a[j3 + 1] = x1i - x3r;
- wn4r = w[1];
- csc1 = w[2];
- csc3 = w[3];
- wd1r = 1;
- wd1i = 0;
- wd3r = 1;
- wd3i = 0;
- k = 0;
- for (j = 2; j < mh - 2; j += 4) {
- k += 4;
- wk1r = csc1 * (wd1r + w[k]);
- wk1i = csc1 * (wd1i + w[k + 1]);
- wk3r = csc3 * (wd3r + w[k + 2]);
- wk3i = csc3 * (wd3i + w[k + 3]);
- wd1r = w[k];
- wd1i = w[k + 1];
- wd3r = w[k + 2];
- wd3i = w[k + 3];
- j1 = j + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j] + a[j2];
- x0i = -a[j + 1] - a[j2 + 1];
- x1r = a[j] - a[j2];
- x1i = -a[j + 1] + a[j2 + 1];
- y0r = a[j + 2] + a[j2 + 2];
- y0i = -a[j + 3] - a[j2 + 3];
- y1r = a[j + 2] - a[j2 + 2];
- y1i = -a[j + 3] + a[j2 + 3];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- y2r = a[j1 + 2] + a[j3 + 2];
- y2i = a[j1 + 3] + a[j3 + 3];
- y3r = a[j1 + 2] - a[j3 + 2];
- y3i = a[j1 + 3] - a[j3 + 3];
- a[j] = x0r + x2r;
- a[j + 1] = x0i - x2i;
- a[j + 2] = y0r + y2r;
- a[j + 3] = y0i - y2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i + x2i;
- a[j1 + 2] = y0r - y2r;
- a[j1 + 3] = y0i + y2i;
- x0r = x1r + x3i;
- x0i = x1i + x3r;
- a[j2] = wk1r * x0r - wk1i * x0i;
- a[j2 + 1] = wk1r * x0i + wk1i * x0r;
- x0r = y1r + y3i;
- x0i = y1i + y3r;
- a[j2 + 2] = wd1r * x0r - wd1i * x0i;
- a[j2 + 3] = wd1r * x0i + wd1i * x0r;
- x0r = x1r - x3i;
- x0i = x1i - x3r;
- a[j3] = wk3r * x0r + wk3i * x0i;
- a[j3 + 1] = wk3r * x0i - wk3i * x0r;
- x0r = y1r - y3i;
- x0i = y1i - y3r;
- a[j3 + 2] = wd3r * x0r + wd3i * x0i;
- a[j3 + 3] = wd3r * x0i - wd3i * x0r;
- j0 = m - j;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0] + a[j2];
- x0i = -a[j0 + 1] - a[j2 + 1];
- x1r = a[j0] - a[j2];
- x1i = -a[j0 + 1] + a[j2 + 1];
- y0r = a[j0 - 2] + a[j2 - 2];
- y0i = -a[j0 - 1] - a[j2 - 1];
- y1r = a[j0 - 2] - a[j2 - 2];
- y1i = -a[j0 - 1] + a[j2 - 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- y2r = a[j1 - 2] + a[j3 - 2];
- y2i = a[j1 - 1] + a[j3 - 1];
- y3r = a[j1 - 2] - a[j3 - 2];
- y3i = a[j1 - 1] - a[j3 - 1];
- a[j0] = x0r + x2r;
- a[j0 + 1] = x0i - x2i;
- a[j0 - 2] = y0r + y2r;
- a[j0 - 1] = y0i - y2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i + x2i;
- a[j1 - 2] = y0r - y2r;
- a[j1 - 1] = y0i + y2i;
- x0r = x1r + x3i;
- x0i = x1i + x3r;
- a[j2] = wk1i * x0r - wk1r * x0i;
- a[j2 + 1] = wk1i * x0i + wk1r * x0r;
- x0r = y1r + y3i;
- x0i = y1i + y3r;
- a[j2 - 2] = wd1i * x0r - wd1r * x0i;
- a[j2 - 1] = wd1i * x0i + wd1r * x0r;
- x0r = x1r - x3i;
- x0i = x1i - x3r;
- a[j3] = wk3i * x0r + wk3r * x0i;
- a[j3 + 1] = wk3i * x0i - wk3r * x0r;
- x0r = y1r - y3i;
- x0i = y1i - y3r;
- a[j3 - 2] = wd3i * x0r + wd3r * x0i;
- a[j3 - 1] = wd3i * x0i - wd3r * x0r;
- }
- wk1r = csc1 * (wd1r + wn4r);
- wk1i = csc1 * (wd1i + wn4r);
- wk3r = csc3 * (wd3r - wn4r);
- wk3i = csc3 * (wd3i - wn4r);
- j0 = mh;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0 - 2] + a[j2 - 2];
- x0i = -a[j0 - 1] - a[j2 - 1];
- x1r = a[j0 - 2] - a[j2 - 2];
- x1i = -a[j0 - 1] + a[j2 - 1];
- x2r = a[j1 - 2] + a[j3 - 2];
- x2i = a[j1 - 1] + a[j3 - 1];
- x3r = a[j1 - 2] - a[j3 - 2];
- x3i = a[j1 - 1] - a[j3 - 1];
- a[j0 - 2] = x0r + x2r;
- a[j0 - 1] = x0i - x2i;
- a[j1 - 2] = x0r - x2r;
- a[j1 - 1] = x0i + x2i;
- x0r = x1r + x3i;
- x0i = x1i + x3r;
- a[j2 - 2] = wk1r * x0r - wk1i * x0i;
- a[j2 - 1] = wk1r * x0i + wk1i * x0r;
- x0r = x1r - x3i;
- x0i = x1i - x3r;
- a[j3 - 2] = wk3r * x0r + wk3i * x0i;
- a[j3 - 1] = wk3r * x0i - wk3i * x0r;
- x0r = a[j0] + a[j2];
- x0i = -a[j0 + 1] - a[j2 + 1];
- x1r = a[j0] - a[j2];
- x1i = -a[j0 + 1] + a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[j0] = x0r + x2r;
- a[j0 + 1] = x0i - x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i + x2i;
- x0r = x1r + x3i;
- x0i = x1i + x3r;
- a[j2] = wn4r * (x0r - x0i);
- a[j2 + 1] = wn4r * (x0i + x0r);
- x0r = x1r - x3i;
- x0i = x1i - x3r;
- a[j3] = -wn4r * (x0r + x0i);
- a[j3 + 1] = -wn4r * (x0i - x0r);
- x0r = a[j0 + 2] + a[j2 + 2];
- x0i = -a[j0 + 3] - a[j2 + 3];
- x1r = a[j0 + 2] - a[j2 + 2];
- x1i = -a[j0 + 3] + a[j2 + 3];
- x2r = a[j1 + 2] + a[j3 + 2];
- x2i = a[j1 + 3] + a[j3 + 3];
- x3r = a[j1 + 2] - a[j3 + 2];
- x3i = a[j1 + 3] - a[j3 + 3];
- a[j0 + 2] = x0r + x2r;
- a[j0 + 3] = x0i - x2i;
- a[j1 + 2] = x0r - x2r;
- a[j1 + 3] = x0i + x2i;
- x0r = x1r + x3i;
- x0i = x1i + x3r;
- a[j2 + 2] = wk1i * x0r - wk1r * x0i;
- a[j2 + 3] = wk1i * x0i + wk1r * x0r;
- x0r = x1r - x3i;
- x0i = x1i - x3r;
- a[j3 + 2] = wk3i * x0r + wk3r * x0i;
- a[j3 + 3] = wk3i * x0i - wk3r * x0r;
-}
-
-
-#ifdef USE_CDFT_THREADS
-struct cdft_arg_st {
- int n0;
- int n;
- double *a;
- int nw;
- double *w;
-};
-typedef struct cdft_arg_st cdft_arg_t;
-
-
-void cftrec4_th(int n, double *a, int nw, double *w)
-{
- void *cftrec1_th(void *p);
- void *cftrec2_th(void *p);
- int i, idiv4, m, nthread;
- cdft_thread_t th[4];
- cdft_arg_t ag[4];
-
- nthread = 2;
- idiv4 = 0;
- m = n >> 1;
- if (n > CDFT_4THREADS_BEGIN_N) {
- nthread = 4;
- idiv4 = 1;
- m >>= 1;
- }
- for (i = 0; i < nthread; i++) {
- ag[i].n0 = n;
- ag[i].n = m;
- ag[i].a = &a[i * m];
- ag[i].nw = nw;
- ag[i].w = w;
- if (i != idiv4) {
- cdft_thread_create(&th[i], cftrec1_th, &ag[i]);
- } else {
- cdft_thread_create(&th[i], cftrec2_th, &ag[i]);
- }
- }
- for (i = 0; i < nthread; i++) {
- cdft_thread_wait(th[i]);
- }
-}
-
-
-void *cftrec1_th(void *p)
-{
- int cfttree(int n, int j, int k, double *a, int nw, double *w);
- void cftleaf(int n, int isplt, double *a, int nw, double *w);
- void cftmdl1(int n, double *a, double *w);
- int isplt, j, k, m, n, n0, nw;
- double *a, *w;
-
- n0 = ((cdft_arg_t *) p)->n0;
- n = ((cdft_arg_t *) p)->n;
- a = ((cdft_arg_t *) p)->a;
- nw = ((cdft_arg_t *) p)->nw;
- w = ((cdft_arg_t *) p)->w;
- m = n0;
- while (m > 512) {
- m >>= 2;
- cftmdl1(m, &a[n - m], &w[nw - (m >> 1)]);
- }
- cftleaf(m, 1, &a[n - m], nw, w);
- k = 0;
- for (j = n - m; j > 0; j -= m) {
- k++;
- isplt = cfttree(m, j, k, a, nw, w);
- cftleaf(m, isplt, &a[j - m], nw, w);
- }
- return (void *) 0;
-}
-
-
-void *cftrec2_th(void *p)
-{
- int cfttree(int n, int j, int k, double *a, int nw, double *w);
- void cftleaf(int n, int isplt, double *a, int nw, double *w);
- void cftmdl2(int n, double *a, double *w);
- int isplt, j, k, m, n, n0, nw;
- double *a, *w;
-
- n0 = ((cdft_arg_t *) p)->n0;
- n = ((cdft_arg_t *) p)->n;
- a = ((cdft_arg_t *) p)->a;
- nw = ((cdft_arg_t *) p)->nw;
- w = ((cdft_arg_t *) p)->w;
- k = 1;
- m = n0;
- while (m > 512) {
- m >>= 2;
- k <<= 2;
- cftmdl2(m, &a[n - m], &w[nw - m]);
- }
- cftleaf(m, 0, &a[n - m], nw, w);
- k >>= 1;
- for (j = n - m; j > 0; j -= m) {
- k++;
- isplt = cfttree(m, j, k, a, nw, w);
- cftleaf(m, isplt, &a[j - m], nw, w);
- }
- return (void *) 0;
-}
-#endif /* USE_CDFT_THREADS */
-
-
-void cftrec4(int n, double *a, int nw, double *w)
-{
- int cfttree(int n, int j, int k, double *a, int nw, double *w);
- void cftleaf(int n, int isplt, double *a, int nw, double *w);
- void cftmdl1(int n, double *a, double *w);
- int isplt, j, k, m;
-
- m = n;
- while (m > 512) {
- m >>= 2;
- cftmdl1(m, &a[n - m], &w[nw - (m >> 1)]);
- }
- cftleaf(m, 1, &a[n - m], nw, w);
- k = 0;
- for (j = n - m; j > 0; j -= m) {
- k++;
- isplt = cfttree(m, j, k, a, nw, w);
- cftleaf(m, isplt, &a[j - m], nw, w);
- }
-}
-
-
-int cfttree(int n, int j, int k, double *a, int nw, double *w)
-{
- void cftmdl1(int n, double *a, double *w);
- void cftmdl2(int n, double *a, double *w);
- int i, isplt, m;
-
- if ((k & 3) != 0) {
- isplt = k & 1;
- if (isplt != 0) {
- cftmdl1(n, &a[j - n], &w[nw - (n >> 1)]);
- } else {
- cftmdl2(n, &a[j - n], &w[nw - n]);
- }
- } else {
- m = n;
- for (i = k; (i & 3) == 0; i >>= 2) {
- m <<= 2;
- }
- isplt = i & 1;
- if (isplt != 0) {
- while (m > 128) {
- cftmdl1(m, &a[j - m], &w[nw - (m >> 1)]);
- m >>= 2;
- }
- } else {
- while (m > 128) {
- cftmdl2(m, &a[j - m], &w[nw - m]);
- m >>= 2;
- }
- }
- }
- return isplt;
-}
-
-
-void cftleaf(int n, int isplt, double *a, int nw, double *w)
-{
- void cftmdl1(int n, double *a, double *w);
- void cftmdl2(int n, double *a, double *w);
- void cftf161(double *a, double *w);
- void cftf162(double *a, double *w);
- void cftf081(double *a, double *w);
- void cftf082(double *a, double *w);
-
- if (n == 512) {
- cftmdl1(128, a, &w[nw - 64]);
- cftf161(a, &w[nw - 8]);
- cftf162(&a[32], &w[nw - 32]);
- cftf161(&a[64], &w[nw - 8]);
- cftf161(&a[96], &w[nw - 8]);
- cftmdl2(128, &a[128], &w[nw - 128]);
- cftf161(&a[128], &w[nw - 8]);
- cftf162(&a[160], &w[nw - 32]);
- cftf161(&a[192], &w[nw - 8]);
- cftf162(&a[224], &w[nw - 32]);
- cftmdl1(128, &a[256], &w[nw - 64]);
- cftf161(&a[256], &w[nw - 8]);
- cftf162(&a[288], &w[nw - 32]);
- cftf161(&a[320], &w[nw - 8]);
- cftf161(&a[352], &w[nw - 8]);
- if (isplt != 0) {
- cftmdl1(128, &a[384], &w[nw - 64]);
- cftf161(&a[480], &w[nw - 8]);
- } else {
- cftmdl2(128, &a[384], &w[nw - 128]);
- cftf162(&a[480], &w[nw - 32]);
- }
- cftf161(&a[384], &w[nw - 8]);
- cftf162(&a[416], &w[nw - 32]);
- cftf161(&a[448], &w[nw - 8]);
- } else {
- cftmdl1(64, a, &w[nw - 32]);
- cftf081(a, &w[nw - 8]);
- cftf082(&a[16], &w[nw - 8]);
- cftf081(&a[32], &w[nw - 8]);
- cftf081(&a[48], &w[nw - 8]);
- cftmdl2(64, &a[64], &w[nw - 64]);
- cftf081(&a[64], &w[nw - 8]);
- cftf082(&a[80], &w[nw - 8]);
- cftf081(&a[96], &w[nw - 8]);
- cftf082(&a[112], &w[nw - 8]);
- cftmdl1(64, &a[128], &w[nw - 32]);
- cftf081(&a[128], &w[nw - 8]);
- cftf082(&a[144], &w[nw - 8]);
- cftf081(&a[160], &w[nw - 8]);
- cftf081(&a[176], &w[nw - 8]);
- if (isplt != 0) {
- cftmdl1(64, &a[192], &w[nw - 32]);
- cftf081(&a[240], &w[nw - 8]);
- } else {
- cftmdl2(64, &a[192], &w[nw - 64]);
- cftf082(&a[240], &w[nw - 8]);
- }
- cftf081(&a[192], &w[nw - 8]);
- cftf082(&a[208], &w[nw - 8]);
- cftf081(&a[224], &w[nw - 8]);
- }
-}
-
-
-void cftmdl1(int n, double *a, double *w)
-{
- int j, j0, j1, j2, j3, k, m, mh;
- double wn4r, wk1r, wk1i, wk3r, wk3i;
- double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
-
- mh = n >> 3;
- m = 2 * mh;
- j1 = m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[0] + a[j2];
- x0i = a[1] + a[j2 + 1];
- x1r = a[0] - a[j2];
- x1i = a[1] - a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[0] = x0r + x2r;
- a[1] = x0i + x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- a[j2] = x1r - x3i;
- a[j2 + 1] = x1i + x3r;
- a[j3] = x1r + x3i;
- a[j3 + 1] = x1i - x3r;
- wn4r = w[1];
- k = 0;
- for (j = 2; j < mh; j += 2) {
- k += 4;
- wk1r = w[k];
- wk1i = w[k + 1];
- wk3r = w[k + 2];
- wk3i = w[k + 3];
- j1 = j + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j] + a[j2];
- x0i = a[j + 1] + a[j2 + 1];
- x1r = a[j] - a[j2];
- x1i = a[j + 1] - a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[j] = x0r + x2r;
- a[j + 1] = x0i + x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2] = wk1r * x0r - wk1i * x0i;
- a[j2 + 1] = wk1r * x0i + wk1i * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3] = wk3r * x0r + wk3i * x0i;
- a[j3 + 1] = wk3r * x0i - wk3i * x0r;
- j0 = m - j;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0] + a[j2];
- x0i = a[j0 + 1] + a[j2 + 1];
- x1r = a[j0] - a[j2];
- x1i = a[j0 + 1] - a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[j0] = x0r + x2r;
- a[j0 + 1] = x0i + x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2] = wk1i * x0r - wk1r * x0i;
- a[j2 + 1] = wk1i * x0i + wk1r * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3] = wk3i * x0r + wk3r * x0i;
- a[j3 + 1] = wk3i * x0i - wk3r * x0r;
- }
- j0 = mh;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0] + a[j2];
- x0i = a[j0 + 1] + a[j2 + 1];
- x1r = a[j0] - a[j2];
- x1i = a[j0 + 1] - a[j2 + 1];
- x2r = a[j1] + a[j3];
- x2i = a[j1 + 1] + a[j3 + 1];
- x3r = a[j1] - a[j3];
- x3i = a[j1 + 1] - a[j3 + 1];
- a[j0] = x0r + x2r;
- a[j0 + 1] = x0i + x2i;
- a[j1] = x0r - x2r;
- a[j1 + 1] = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- a[j2] = wn4r * (x0r - x0i);
- a[j2 + 1] = wn4r * (x0i + x0r);
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- a[j3] = -wn4r * (x0r + x0i);
- a[j3 + 1] = -wn4r * (x0i - x0r);
-}
-
-
-void cftmdl2(int n, double *a, double *w)
-{
- int j, j0, j1, j2, j3, k, kr, m, mh;
- double wn4r, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i;
- double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y2r, y2i;
-
- mh = n >> 3;
- m = 2 * mh;
- wn4r = w[1];
- j1 = m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[0] - a[j2 + 1];
- x0i = a[1] + a[j2];
- x1r = a[0] + a[j2 + 1];
- x1i = a[1] - a[j2];
- x2r = a[j1] - a[j3 + 1];
- x2i = a[j1 + 1] + a[j3];
- x3r = a[j1] + a[j3 + 1];
- x3i = a[j1 + 1] - a[j3];
- y0r = wn4r * (x2r - x2i);
- y0i = wn4r * (x2i + x2r);
- a[0] = x0r + y0r;
- a[1] = x0i + y0i;
- a[j1] = x0r - y0r;
- a[j1 + 1] = x0i - y0i;
- y0r = wn4r * (x3r - x3i);
- y0i = wn4r * (x3i + x3r);
- a[j2] = x1r - y0i;
- a[j2 + 1] = x1i + y0r;
- a[j3] = x1r + y0i;
- a[j3 + 1] = x1i - y0r;
- k = 0;
- kr = 2 * m;
- for (j = 2; j < mh; j += 2) {
- k += 4;
- wk1r = w[k];
- wk1i = w[k + 1];
- wk3r = w[k + 2];
- wk3i = w[k + 3];
- kr -= 4;
- wd1i = w[kr];
- wd1r = w[kr + 1];
- wd3i = w[kr + 2];
- wd3r = w[kr + 3];
- j1 = j + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j] - a[j2 + 1];
- x0i = a[j + 1] + a[j2];
- x1r = a[j] + a[j2 + 1];
- x1i = a[j + 1] - a[j2];
- x2r = a[j1] - a[j3 + 1];
- x2i = a[j1 + 1] + a[j3];
- x3r = a[j1] + a[j3 + 1];
- x3i = a[j1 + 1] - a[j3];
- y0r = wk1r * x0r - wk1i * x0i;
- y0i = wk1r * x0i + wk1i * x0r;
- y2r = wd1r * x2r - wd1i * x2i;
- y2i = wd1r * x2i + wd1i * x2r;
- a[j] = y0r + y2r;
- a[j + 1] = y0i + y2i;
- a[j1] = y0r - y2r;
- a[j1 + 1] = y0i - y2i;
- y0r = wk3r * x1r + wk3i * x1i;
- y0i = wk3r * x1i - wk3i * x1r;
- y2r = wd3r * x3r + wd3i * x3i;
- y2i = wd3r * x3i - wd3i * x3r;
- a[j2] = y0r + y2r;
- a[j2 + 1] = y0i + y2i;
- a[j3] = y0r - y2r;
- a[j3 + 1] = y0i - y2i;
- j0 = m - j;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0] - a[j2 + 1];
- x0i = a[j0 + 1] + a[j2];
- x1r = a[j0] + a[j2 + 1];
- x1i = a[j0 + 1] - a[j2];
- x2r = a[j1] - a[j3 + 1];
- x2i = a[j1 + 1] + a[j3];
- x3r = a[j1] + a[j3 + 1];
- x3i = a[j1 + 1] - a[j3];
- y0r = wd1i * x0r - wd1r * x0i;
- y0i = wd1i * x0i + wd1r * x0r;
- y2r = wk1i * x2r - wk1r * x2i;
- y2i = wk1i * x2i + wk1r * x2r;
- a[j0] = y0r + y2r;
- a[j0 + 1] = y0i + y2i;
- a[j1] = y0r - y2r;
- a[j1 + 1] = y0i - y2i;
- y0r = wd3i * x1r + wd3r * x1i;
- y0i = wd3i * x1i - wd3r * x1r;
- y2r = wk3i * x3r + wk3r * x3i;
- y2i = wk3i * x3i - wk3r * x3r;
- a[j2] = y0r + y2r;
- a[j2 + 1] = y0i + y2i;
- a[j3] = y0r - y2r;
- a[j3 + 1] = y0i - y2i;
- }
- wk1r = w[m];
- wk1i = w[m + 1];
- j0 = mh;
- j1 = j0 + m;
- j2 = j1 + m;
- j3 = j2 + m;
- x0r = a[j0] - a[j2 + 1];
- x0i = a[j0 + 1] + a[j2];
- x1r = a[j0] + a[j2 + 1];
- x1i = a[j0 + 1] - a[j2];
- x2r = a[j1] - a[j3 + 1];
- x2i = a[j1 + 1] + a[j3];
- x3r = a[j1] + a[j3 + 1];
- x3i = a[j1 + 1] - a[j3];
- y0r = wk1r * x0r - wk1i * x0i;
- y0i = wk1r * x0i + wk1i * x0r;
- y2r = wk1i * x2r - wk1r * x2i;
- y2i = wk1i * x2i + wk1r * x2r;
- a[j0] = y0r + y2r;
- a[j0 + 1] = y0i + y2i;
- a[j1] = y0r - y2r;
- a[j1 + 1] = y0i - y2i;
- y0r = wk1i * x1r - wk1r * x1i;
- y0i = wk1i * x1i + wk1r * x1r;
- y2r = wk1r * x3r - wk1i * x3i;
- y2i = wk1r * x3i + wk1i * x3r;
- a[j2] = y0r - y2r;
- a[j2 + 1] = y0i - y2i;
- a[j3] = y0r + y2r;
- a[j3 + 1] = y0i + y2i;
-}
-
-
-void cftfx41(int n, double *a, int nw, double *w)
-{
- void cftf161(double *a, double *w);
- void cftf162(double *a, double *w);
- void cftf081(double *a, double *w);
- void cftf082(double *a, double *w);
-
- if (n == 128) {
- cftf161(a, &w[nw - 8]);
- cftf162(&a[32], &w[nw - 32]);
- cftf161(&a[64], &w[nw - 8]);
- cftf161(&a[96], &w[nw - 8]);
- } else {
- cftf081(a, &w[nw - 8]);
- cftf082(&a[16], &w[nw - 8]);
- cftf081(&a[32], &w[nw - 8]);
- cftf081(&a[48], &w[nw - 8]);
- }
-}
-
-
-void cftf161(double *a, double *w)
-{
- double wn4r, wk1r, wk1i,
- x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
- y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
- y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
- y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
- y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
-
- wn4r = w[1];
- wk1r = w[2];
- wk1i = w[3];
- x0r = a[0] + a[16];
- x0i = a[1] + a[17];
- x1r = a[0] - a[16];
- x1i = a[1] - a[17];
- x2r = a[8] + a[24];
- x2i = a[9] + a[25];
- x3r = a[8] - a[24];
- x3i = a[9] - a[25];
- y0r = x0r + x2r;
- y0i = x0i + x2i;
- y4r = x0r - x2r;
- y4i = x0i - x2i;
- y8r = x1r - x3i;
- y8i = x1i + x3r;
- y12r = x1r + x3i;
- y12i = x1i - x3r;
- x0r = a[2] + a[18];
- x0i = a[3] + a[19];
- x1r = a[2] - a[18];
- x1i = a[3] - a[19];
- x2r = a[10] + a[26];
- x2i = a[11] + a[27];
- x3r = a[10] - a[26];
- x3i = a[11] - a[27];
- y1r = x0r + x2r;
- y1i = x0i + x2i;
- y5r = x0r - x2r;
- y5i = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- y9r = wk1r * x0r - wk1i * x0i;
- y9i = wk1r * x0i + wk1i * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- y13r = wk1i * x0r - wk1r * x0i;
- y13i = wk1i * x0i + wk1r * x0r;
- x0r = a[4] + a[20];
- x0i = a[5] + a[21];
- x1r = a[4] - a[20];
- x1i = a[5] - a[21];
- x2r = a[12] + a[28];
- x2i = a[13] + a[29];
- x3r = a[12] - a[28];
- x3i = a[13] - a[29];
- y2r = x0r + x2r;
- y2i = x0i + x2i;
- y6r = x0r - x2r;
- y6i = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- y10r = wn4r * (x0r - x0i);
- y10i = wn4r * (x0i + x0r);
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- y14r = wn4r * (x0r + x0i);
- y14i = wn4r * (x0i - x0r);
- x0r = a[6] + a[22];
- x0i = a[7] + a[23];
- x1r = a[6] - a[22];
- x1i = a[7] - a[23];
- x2r = a[14] + a[30];
- x2i = a[15] + a[31];
- x3r = a[14] - a[30];
- x3i = a[15] - a[31];
- y3r = x0r + x2r;
- y3i = x0i + x2i;
- y7r = x0r - x2r;
- y7i = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- y11r = wk1i * x0r - wk1r * x0i;
- y11i = wk1i * x0i + wk1r * x0r;
- x0r = x1r + x3i;
- x0i = x1i - x3r;
- y15r = wk1r * x0r - wk1i * x0i;
- y15i = wk1r * x0i + wk1i * x0r;
- x0r = y12r - y14r;
- x0i = y12i - y14i;
- x1r = y12r + y14r;
- x1i = y12i + y14i;
- x2r = y13r - y15r;
- x2i = y13i - y15i;
- x3r = y13r + y15r;
- x3i = y13i + y15i;
- a[24] = x0r + x2r;
- a[25] = x0i + x2i;
- a[26] = x0r - x2r;
- a[27] = x0i - x2i;
- a[28] = x1r - x3i;
- a[29] = x1i + x3r;
- a[30] = x1r + x3i;
- a[31] = x1i - x3r;
- x0r = y8r + y10r;
- x0i = y8i + y10i;
- x1r = y8r - y10r;
- x1i = y8i - y10i;
- x2r = y9r + y11r;
- x2i = y9i + y11i;
- x3r = y9r - y11r;
- x3i = y9i - y11i;
- a[16] = x0r + x2r;
- a[17] = x0i + x2i;
- a[18] = x0r - x2r;
- a[19] = x0i - x2i;
- a[20] = x1r - x3i;
- a[21] = x1i + x3r;
- a[22] = x1r + x3i;
- a[23] = x1i - x3r;
- x0r = y5r - y7i;
- x0i = y5i + y7r;
- x2r = wn4r * (x0r - x0i);
- x2i = wn4r * (x0i + x0r);
- x0r = y5r + y7i;
- x0i = y5i - y7r;
- x3r = wn4r * (x0r - x0i);
- x3i = wn4r * (x0i + x0r);
- x0r = y4r - y6i;
- x0i = y4i + y6r;
- x1r = y4r + y6i;
- x1i = y4i - y6r;
- a[8] = x0r + x2r;
- a[9] = x0i + x2i;
- a[10] = x0r - x2r;
- a[11] = x0i - x2i;
- a[12] = x1r - x3i;
- a[13] = x1i + x3r;
- a[14] = x1r + x3i;
- a[15] = x1i - x3r;
- x0r = y0r + y2r;
- x0i = y0i + y2i;
- x1r = y0r - y2r;
- x1i = y0i - y2i;
- x2r = y1r + y3r;
- x2i = y1i + y3i;
- x3r = y1r - y3r;
- x3i = y1i - y3i;
- a[0] = x0r + x2r;
- a[1] = x0i + x2i;
- a[2] = x0r - x2r;
- a[3] = x0i - x2i;
- a[4] = x1r - x3i;
- a[5] = x1i + x3r;
- a[6] = x1r + x3i;
- a[7] = x1i - x3r;
-}
-
-
-void cftf162(double *a, double *w)
-{
- double wn4r, wk1r, wk1i, wk2r, wk2i, wk3r, wk3i,
- x0r, x0i, x1r, x1i, x2r, x2i,
- y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
- y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
- y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
- y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
-
- wn4r = w[1];
- wk1r = w[4];
- wk1i = w[5];
- wk3r = w[6];
- wk3i = -w[7];
- wk2r = w[8];
- wk2i = w[9];
- x1r = a[0] - a[17];
- x1i = a[1] + a[16];
- x0r = a[8] - a[25];
- x0i = a[9] + a[24];
- x2r = wn4r * (x0r - x0i);
- x2i = wn4r * (x0i + x0r);
- y0r = x1r + x2r;
- y0i = x1i + x2i;
- y4r = x1r - x2r;
- y4i = x1i - x2i;
- x1r = a[0] + a[17];
- x1i = a[1] - a[16];
- x0r = a[8] + a[25];
- x0i = a[9] - a[24];
- x2r = wn4r * (x0r - x0i);
- x2i = wn4r * (x0i + x0r);
- y8r = x1r - x2i;
- y8i = x1i + x2r;
- y12r = x1r + x2i;
- y12i = x1i - x2r;
- x0r = a[2] - a[19];
- x0i = a[3] + a[18];
- x1r = wk1r * x0r - wk1i * x0i;
- x1i = wk1r * x0i + wk1i * x0r;
- x0r = a[10] - a[27];
- x0i = a[11] + a[26];
- x2r = wk3i * x0r - wk3r * x0i;
- x2i = wk3i * x0i + wk3r * x0r;
- y1r = x1r + x2r;
- y1i = x1i + x2i;
- y5r = x1r - x2r;
- y5i = x1i - x2i;
- x0r = a[2] + a[19];
- x0i = a[3] - a[18];
- x1r = wk3r * x0r - wk3i * x0i;
- x1i = wk3r * x0i + wk3i * x0r;
- x0r = a[10] + a[27];
- x0i = a[11] - a[26];
- x2r = wk1r * x0r + wk1i * x0i;
- x2i = wk1r * x0i - wk1i * x0r;
- y9r = x1r - x2r;
- y9i = x1i - x2i;
- y13r = x1r + x2r;
- y13i = x1i + x2i;
- x0r = a[4] - a[21];
- x0i = a[5] + a[20];
- x1r = wk2r * x0r - wk2i * x0i;
- x1i = wk2r * x0i + wk2i * x0r;
- x0r = a[12] - a[29];
- x0i = a[13] + a[28];
- x2r = wk2i * x0r - wk2r * x0i;
- x2i = wk2i * x0i + wk2r * x0r;
- y2r = x1r + x2r;
- y2i = x1i + x2i;
- y6r = x1r - x2r;
- y6i = x1i - x2i;
- x0r = a[4] + a[21];
- x0i = a[5] - a[20];
- x1r = wk2i * x0r - wk2r * x0i;
- x1i = wk2i * x0i + wk2r * x0r;
- x0r = a[12] + a[29];
- x0i = a[13] - a[28];
- x2r = wk2r * x0r - wk2i * x0i;
- x2i = wk2r * x0i + wk2i * x0r;
- y10r = x1r - x2r;
- y10i = x1i - x2i;
- y14r = x1r + x2r;
- y14i = x1i + x2i;
- x0r = a[6] - a[23];
- x0i = a[7] + a[22];
- x1r = wk3r * x0r - wk3i * x0i;
- x1i = wk3r * x0i + wk3i * x0r;
- x0r = a[14] - a[31];
- x0i = a[15] + a[30];
- x2r = wk1i * x0r - wk1r * x0i;
- x2i = wk1i * x0i + wk1r * x0r;
- y3r = x1r + x2r;
- y3i = x1i + x2i;
- y7r = x1r - x2r;
- y7i = x1i - x2i;
- x0r = a[6] + a[23];
- x0i = a[7] - a[22];
- x1r = wk1i * x0r + wk1r * x0i;
- x1i = wk1i * x0i - wk1r * x0r;
- x0r = a[14] + a[31];
- x0i = a[15] - a[30];
- x2r = wk3i * x0r - wk3r * x0i;
- x2i = wk3i * x0i + wk3r * x0r;
- y11r = x1r + x2r;
- y11i = x1i + x2i;
- y15r = x1r - x2r;
- y15i = x1i - x2i;
- x1r = y0r + y2r;
- x1i = y0i + y2i;
- x2r = y1r + y3r;
- x2i = y1i + y3i;
- a[0] = x1r + x2r;
- a[1] = x1i + x2i;
- a[2] = x1r - x2r;
- a[3] = x1i - x2i;
- x1r = y0r - y2r;
- x1i = y0i - y2i;
- x2r = y1r - y3r;
- x2i = y1i - y3i;
- a[4] = x1r - x2i;
- a[5] = x1i + x2r;
- a[6] = x1r + x2i;
- a[7] = x1i - x2r;
- x1r = y4r - y6i;
- x1i = y4i + y6r;
- x0r = y5r - y7i;
- x0i = y5i + y7r;
- x2r = wn4r * (x0r - x0i);
- x2i = wn4r * (x0i + x0r);
- a[8] = x1r + x2r;
- a[9] = x1i + x2i;
- a[10] = x1r - x2r;
- a[11] = x1i - x2i;
- x1r = y4r + y6i;
- x1i = y4i - y6r;
- x0r = y5r + y7i;
- x0i = y5i - y7r;
- x2r = wn4r * (x0r - x0i);
- x2i = wn4r * (x0i + x0r);
- a[12] = x1r - x2i;
- a[13] = x1i + x2r;
- a[14] = x1r + x2i;
- a[15] = x1i - x2r;
- x1r = y8r + y10r;
- x1i = y8i + y10i;
- x2r = y9r - y11r;
- x2i = y9i - y11i;
- a[16] = x1r + x2r;
- a[17] = x1i + x2i;
- a[18] = x1r - x2r;
- a[19] = x1i - x2i;
- x1r = y8r - y10r;
- x1i = y8i - y10i;
- x2r = y9r + y11r;
- x2i = y9i + y11i;
- a[20] = x1r - x2i;
- a[21] = x1i + x2r;
- a[22] = x1r + x2i;
- a[23] = x1i - x2r;
- x1r = y12r - y14i;
- x1i = y12i + y14r;
- x0r = y13r + y15i;
- x0i = y13i - y15r;
- x2r = wn4r * (x0r - x0i);
- x2i = wn4r * (x0i + x0r);
- a[24] = x1r + x2r;
- a[25] = x1i + x2i;
- a[26] = x1r - x2r;
- a[27] = x1i - x2i;
- x1r = y12r + y14i;
- x1i = y12i - y14r;
- x0r = y13r - y15i;
- x0i = y13i + y15r;
- x2r = wn4r * (x0r - x0i);
- x2i = wn4r * (x0i + x0r);
- a[28] = x1r - x2i;
- a[29] = x1i + x2r;
- a[30] = x1r + x2i;
- a[31] = x1i - x2r;
-}
-
-
-void cftf081(double *a, double *w)
-{
- double wn4r, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
- y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
- y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
-
- wn4r = w[1];
- x0r = a[0] + a[8];
- x0i = a[1] + a[9];
- x1r = a[0] - a[8];
- x1i = a[1] - a[9];
- x2r = a[4] + a[12];
- x2i = a[5] + a[13];
- x3r = a[4] - a[12];
- x3i = a[5] - a[13];
- y0r = x0r + x2r;
- y0i = x0i + x2i;
- y2r = x0r - x2r;
- y2i = x0i - x2i;
- y1r = x1r - x3i;
- y1i = x1i + x3r;
- y3r = x1r + x3i;
- y3i = x1i - x3r;
- x0r = a[2] + a[10];
- x0i = a[3] + a[11];
- x1r = a[2] - a[10];
- x1i = a[3] - a[11];
- x2r = a[6] + a[14];
- x2i = a[7] + a[15];
- x3r = a[6] - a[14];
- x3i = a[7] - a[15];
- y4r = x0r + x2r;
- y4i = x0i + x2i;
- y6r = x0r - x2r;
- y6i = x0i - x2i;
- x0r = x1r - x3i;
- x0i = x1i + x3r;
- x2r = x1r + x3i;
- x2i = x1i - x3r;
- y5r = wn4r * (x0r - x0i);
- y5i = wn4r * (x0r + x0i);
- y7r = wn4r * (x2r - x2i);
- y7i = wn4r * (x2r + x2i);
- a[8] = y1r + y5r;
- a[9] = y1i + y5i;
- a[10] = y1r - y5r;
- a[11] = y1i - y5i;
- a[12] = y3r - y7i;
- a[13] = y3i + y7r;
- a[14] = y3r + y7i;
- a[15] = y3i - y7r;
- a[0] = y0r + y4r;
- a[1] = y0i + y4i;
- a[2] = y0r - y4r;
- a[3] = y0i - y4i;
- a[4] = y2r - y6i;
- a[5] = y2i + y6r;
- a[6] = y2r + y6i;
- a[7] = y2i - y6r;
-}
-
-
-void cftf082(double *a, double *w)
-{
- double wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i,
- y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
- y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
-
- wn4r = w[1];
- wk1r = w[2];
- wk1i = w[3];
- y0r = a[0] - a[9];
- y0i = a[1] + a[8];
- y1r = a[0] + a[9];
- y1i = a[1] - a[8];
- x0r = a[4] - a[13];
- x0i = a[5] + a[12];
- y2r = wn4r * (x0r - x0i);
- y2i = wn4r * (x0i + x0r);
- x0r = a[4] + a[13];
- x0i = a[5] - a[12];
- y3r = wn4r * (x0r - x0i);
- y3i = wn4r * (x0i + x0r);
- x0r = a[2] - a[11];
- x0i = a[3] + a[10];
- y4r = wk1r * x0r - wk1i * x0i;
- y4i = wk1r * x0i + wk1i * x0r;
- x0r = a[2] + a[11];
- x0i = a[3] - a[10];
- y5r = wk1i * x0r - wk1r * x0i;
- y5i = wk1i * x0i + wk1r * x0r;
- x0r = a[6] - a[15];
- x0i = a[7] + a[14];
- y6r = wk1i * x0r - wk1r * x0i;
- y6i = wk1i * x0i + wk1r * x0r;
- x0r = a[6] + a[15];
- x0i = a[7] - a[14];
- y7r = wk1r * x0r - wk1i * x0i;
- y7i = wk1r * x0i + wk1i * x0r;
- x0r = y0r + y2r;
- x0i = y0i + y2i;
- x1r = y4r + y6r;
- x1i = y4i + y6i;
- a[0] = x0r + x1r;
- a[1] = x0i + x1i;
- a[2] = x0r - x1r;
- a[3] = x0i - x1i;
- x0r = y0r - y2r;
- x0i = y0i - y2i;
- x1r = y4r - y6r;
- x1i = y4i - y6i;
- a[4] = x0r - x1i;
- a[5] = x0i + x1r;
- a[6] = x0r + x1i;
- a[7] = x0i - x1r;
- x0r = y1r - y3i;
- x0i = y1i + y3r;
- x1r = y5r - y7r;
- x1i = y5i - y7i;
- a[8] = x0r + x1r;
- a[9] = x0i + x1i;
- a[10] = x0r - x1r;
- a[11] = x0i - x1i;
- x0r = y1r + y3i;
- x0i = y1i - y3r;
- x1r = y5r + y7r;
- x1i = y5i + y7i;
- a[12] = x0r - x1i;
- a[13] = x0i + x1r;
- a[14] = x0r + x1i;
- a[15] = x0i - x1r;
-}
-
-
-void cftf040(double *a)
-{
- double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
-
- x0r = a[0] + a[4];
- x0i = a[1] + a[5];
- x1r = a[0] - a[4];
- x1i = a[1] - a[5];
- x2r = a[2] + a[6];
- x2i = a[3] + a[7];
- x3r = a[2] - a[6];
- x3i = a[3] - a[7];
- a[0] = x0r + x2r;
- a[1] = x0i + x2i;
- a[2] = x1r - x3i;
- a[3] = x1i + x3r;
- a[4] = x0r - x2r;
- a[5] = x0i - x2i;
- a[6] = x1r + x3i;
- a[7] = x1i - x3r;
-}
-
-
-void cftb040(double *a)
-{
- double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
-
- x0r = a[0] + a[4];
- x0i = a[1] + a[5];
- x1r = a[0] - a[4];
- x1i = a[1] - a[5];
- x2r = a[2] + a[6];
- x2i = a[3] + a[7];
- x3r = a[2] - a[6];
- x3i = a[3] - a[7];
- a[0] = x0r + x2r;
- a[1] = x0i + x2i;
- a[2] = x1r + x3i;
- a[3] = x1i - x3r;
- a[4] = x0r - x2r;
- a[5] = x0i - x2i;
- a[6] = x1r - x3i;
- a[7] = x1i + x3r;
-}
-
-
-void cftx020(double *a)
-{
- double x0r, x0i;
-
- x0r = a[0] - a[2];
- x0i = a[1] - a[3];
- a[0] += a[2];
- a[1] += a[3];
- a[2] = x0r;
- a[3] = x0i;
-}
-
-
-void rftfsub(int n, double *a, int nc, double *c)
-{
- int j, k, kk, ks, m;
- double wkr, wki, xr, xi, yr, yi;
-
- m = n >> 1;
- ks = 2 * nc / m;
- kk = 0;
- for (j = 2; j < m; j += 2) {
- k = n - j;
- kk += ks;
- wkr = 0.5 - c[nc - kk];
- wki = c[kk];
- xr = a[j] - a[k];
- xi = a[j + 1] + a[k + 1];
- yr = wkr * xr - wki * xi;
- yi = wkr * xi + wki * xr;
- a[j] -= yr;
- a[j + 1] -= yi;
- a[k] += yr;
- a[k + 1] -= yi;
- }
-}
-
-
-void rftbsub(int n, double *a, int nc, double *c)
-{
- int j, k, kk, ks, m;
- double wkr, wki, xr, xi, yr, yi;
-
- m = n >> 1;
- ks = 2 * nc / m;
- kk = 0;
- for (j = 2; j < m; j += 2) {
- k = n - j;
- kk += ks;
- wkr = 0.5 - c[nc - kk];
- wki = c[kk];
- xr = a[j] - a[k];
- xi = a[j + 1] + a[k + 1];
- yr = wkr * xr + wki * xi;
- yi = wkr * xi - wki * xr;
- a[j] -= yr;
- a[j + 1] -= yi;
- a[k] += yr;
- a[k + 1] -= yi;
- }
-}
-
-
-void dctsub(int n, double *a, int nc, double *c)
-{
- int j, k, kk, ks, m;
- double wkr, wki, xr;
-
- m = n >> 1;
- ks = nc / n;
- kk = 0;
- for (j = 1; j < m; j++) {
- k = n - j;
- kk += ks;
- wkr = c[kk] - c[nc - kk];
- wki = c[kk] + c[nc - kk];
- xr = wki * a[j] - wkr * a[k];
- a[j] = wkr * a[j] + wki * a[k];
- a[k] = xr;
- }
- a[m] *= c[0];
-}
-
-
-void dstsub(int n, double *a, int nc, double *c)
-{
- int j, k, kk, ks, m;
- double wkr, wki, xr;
-
- m = n >> 1;
- ks = nc / n;
- kk = 0;
- for (j = 1; j < m; j++) {
- k = n - j;
- kk += ks;
- wkr = c[kk] - c[nc - kk];
- wki = c[kk] + c[nc - kk];
- xr = wki * a[k] - wkr * a[j];
- a[k] = wkr * a[k] + wki * a[j];
- a[j] = xr;
- }
- a[m] *= c[0];
-}
-
+/*
+Fast Fourier/Cosine/Sine Transform
+ dimension :one
+ data length :power of 2
+ decimation :frequency
+ radix :split-radix
+ data :inplace
+ table :use
+functions
+ cdft: Complex Discrete Fourier Transform
+ rdft: Real Discrete Fourier Transform
+ ddct: Discrete Cosine Transform
+ ddst: Discrete Sine Transform
+ dfct: Cosine Transform of RDFT (Real Symmetric DFT)
+ dfst: Sine Transform of RDFT (Real Anti-symmetric DFT)
+function prototypes
+ void cdft(int, int, double *, int *, double *);
+ void rdft(int, int, double *, int *, double *);
+ void ddct(int, int, double *, int *, double *);
+ void ddst(int, int, double *, int *, double *);
+ void dfct(int, double *, double *, int *, double *);
+ void dfst(int, double *, double *, int *, double *);
+macro definitions
+ USE_CDFT_PTHREADS : default=not defined
+ CDFT_THREADS_BEGIN_N : must be >= 512, default=8192
+ CDFT_4THREADS_BEGIN_N : must be >= 512, default=65536
+ USE_CDFT_WINTHREADS : default=not defined
+ CDFT_THREADS_BEGIN_N : must be >= 512, default=32768
+ CDFT_4THREADS_BEGIN_N : must be >= 512, default=524288
+
+
+-------- Complex DFT (Discrete Fourier Transform) --------
+ [definition]
+ <case1>
+ X[k] = sum_j=0^n-1 x[j]*exp(2*pi*i*j*k/n), 0<=k<n
+ <case2>
+ X[k] = sum_j=0^n-1 x[j]*exp(-2*pi*i*j*k/n), 0<=k<n
+ (notes: sum_j=0^n-1 is a summation from j=0 to n-1)
+ [usage]
+ <case1>
+ ip[0] = 0; // first time only
+ cdft(2*n, 1, a, ip, w);
+ <case2>
+ ip[0] = 0; // first time only
+ cdft(2*n, -1, a, ip, w);
+ [parameters]
+ 2*n :data length (int)
+ n >= 1, n = power of 2
+ a[0...2*n-1] :input/output data (double *)
+ input data
+ a[2*j] = Re(x[j]),
+ a[2*j+1] = Im(x[j]), 0<=j<n
+ output data
+ a[2*k] = Re(X[k]),
+ a[2*k+1] = Im(X[k]), 0<=k<n
+ ip[0...*] :work area for bit reversal (int *)
+ length of ip >= 2+sqrt(n)
+ strictly,
+ length of ip >=
+ 2+(1<<(int)(log(n+0.5)/log(2))/2).
+ ip[0],ip[1] are pointers of the cos/sin table.
+ w[0...n/2-1] :cos/sin table (double *)
+ w[],ip[] are initialized if ip[0] == 0.
+ [remark]
+ Inverse of
+ cdft(2*n, -1, a, ip, w);
+ is
+ cdft(2*n, 1, a, ip, w);
+ for (j = 0; j <= 2 * n - 1; j++) {
+ a[j] *= 1.0 / n;
+ }
+ .
+
+
+-------- Real DFT / Inverse of Real DFT --------
+ [definition]
+ <case1> RDFT
+ R[k] = sum_j=0^n-1 a[j]*cos(2*pi*j*k/n), 0<=k<=n/2
+ I[k] = sum_j=0^n-1 a[j]*sin(2*pi*j*k/n), 0<k<n/2
+ <case2> IRDFT (excluding scale)
+ a[k] = (R[0] + R[n/2]*cos(pi*k))/2 +
+ sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) +
+ sum_j=1^n/2-1 I[j]*sin(2*pi*j*k/n), 0<=k<n
+ [usage]
+ <case1>
+ ip[0] = 0; // first time only
+ rdft(n, 1, a, ip, w);
+ <case2>
+ ip[0] = 0; // first time only
+ rdft(n, -1, a, ip, w);
+ [parameters]
+ n :data length (int)
+ n >= 2, n = power of 2
+ a[0...n-1] :input/output data (double *)
+ <case1>
+ output data
+ a[2*k] = R[k], 0<=k<n/2
+ a[2*k+1] = I[k], 0<k<n/2
+ a[1] = R[n/2]
+ <case2>
+ input data
+ a[2*j] = R[j], 0<=j<n/2
+ a[2*j+1] = I[j], 0<j<n/2
+ a[1] = R[n/2]
+ ip[0...*] :work area for bit reversal (int *)
+ length of ip >= 2+sqrt(n/2)
+ strictly,
+ length of ip >=
+ 2+(1<<(int)(log(n/2+0.5)/log(2))/2).
+ ip[0],ip[1] are pointers of the cos/sin table.
+ w[0...n/2-1] :cos/sin table (double *)
+ w[],ip[] are initialized if ip[0] == 0.
+ [remark]
+ Inverse of
+ rdft(n, 1, a, ip, w);
+ is
+ rdft(n, -1, a, ip, w);
+ for (j = 0; j <= n - 1; j++) {
+ a[j] *= 2.0 / n;
+ }
+ .
+
+
+-------- DCT (Discrete Cosine Transform) / Inverse of DCT --------
+ [definition]
+ <case1> IDCT (excluding scale)
+ C[k] = sum_j=0^n-1 a[j]*cos(pi*j*(k+1/2)/n), 0<=k<n
+ <case2> DCT
+ C[k] = sum_j=0^n-1 a[j]*cos(pi*(j+1/2)*k/n), 0<=k<n
+ [usage]
+ <case1>
+ ip[0] = 0; // first time only
+ ddct(n, 1, a, ip, w);
+ <case2>
+ ip[0] = 0; // first time only
+ ddct(n, -1, a, ip, w);
+ [parameters]
+ n :data length (int)
+ n >= 2, n = power of 2
+ a[0...n-1] :input/output data (double *)
+ output data
+ a[k] = C[k], 0<=k<n
+ ip[0...*] :work area for bit reversal (int *)
+ length of ip >= 2+sqrt(n/2)
+ strictly,
+ length of ip >=
+ 2+(1<<(int)(log(n/2+0.5)/log(2))/2).
+ ip[0],ip[1] are pointers of the cos/sin table.
+ w[0...n*5/4-1] :cos/sin table (double *)
+ w[],ip[] are initialized if ip[0] == 0.
+ [remark]
+ Inverse of
+ ddct(n, -1, a, ip, w);
+ is
+ a[0] *= 0.5;
+ ddct(n, 1, a, ip, w);
+ for (j = 0; j <= n - 1; j++) {
+ a[j] *= 2.0 / n;
+ }
+ .
+
+
+-------- DST (Discrete Sine Transform) / Inverse of DST --------
+ [definition]
+ <case1> IDST (excluding scale)
+ S[k] = sum_j=1^n A[j]*sin(pi*j*(k+1/2)/n), 0<=k<n
+ <case2> DST
+ S[k] = sum_j=0^n-1 a[j]*sin(pi*(j+1/2)*k/n), 0<k<=n
+ [usage]
+ <case1>
+ ip[0] = 0; // first time only
+ ddst(n, 1, a, ip, w);
+ <case2>
+ ip[0] = 0; // first time only
+ ddst(n, -1, a, ip, w);
+ [parameters]
+ n :data length (int)
+ n >= 2, n = power of 2
+ a[0...n-1] :input/output data (double *)
+ <case1>
+ input data
+ a[j] = A[j], 0<j<n
+ a[0] = A[n]
+ output data
+ a[k] = S[k], 0<=k<n
+ <case2>
+ output data
+ a[k] = S[k], 0<k<n
+ a[0] = S[n]
+ ip[0...*] :work area for bit reversal (int *)
+ length of ip >= 2+sqrt(n/2)
+ strictly,
+ length of ip >=
+ 2+(1<<(int)(log(n/2+0.5)/log(2))/2).
+ ip[0],ip[1] are pointers of the cos/sin table.
+ w[0...n*5/4-1] :cos/sin table (double *)
+ w[],ip[] are initialized if ip[0] == 0.
+ [remark]
+ Inverse of
+ ddst(n, -1, a, ip, w);
+ is
+ a[0] *= 0.5;
+ ddst(n, 1, a, ip, w);
+ for (j = 0; j <= n - 1; j++) {
+ a[j] *= 2.0 / n;
+ }
+ .
+
+
+-------- Cosine Transform of RDFT (Real Symmetric DFT) --------
+ [definition]
+ C[k] = sum_j=0^n a[j]*cos(pi*j*k/n), 0<=k<=n
+ [usage]
+ ip[0] = 0; // first time only
+ dfct(n, a, t, ip, w);
+ [parameters]
+ n :data length - 1 (int)
+ n >= 2, n = power of 2
+ a[0...n] :input/output data (double *)
+ output data
+ a[k] = C[k], 0<=k<=n
+ t[0...n/2] :work area (double *)
+ ip[0...*] :work area for bit reversal (int *)
+ length of ip >= 2+sqrt(n/4)
+ strictly,
+ length of ip >=
+ 2+(1<<(int)(log(n/4+0.5)/log(2))/2).
+ ip[0],ip[1] are pointers of the cos/sin table.
+ w[0...n*5/8-1] :cos/sin table (double *)
+ w[],ip[] are initialized if ip[0] == 0.
+ [remark]
+ Inverse of
+ a[0] *= 0.5;
+ a[n] *= 0.5;
+ dfct(n, a, t, ip, w);
+ is
+ a[0] *= 0.5;
+ a[n] *= 0.5;
+ dfct(n, a, t, ip, w);
+ for (j = 0; j <= n; j++) {
+ a[j] *= 2.0 / n;
+ }
+ .
+
+
+-------- Sine Transform of RDFT (Real Anti-symmetric DFT) --------
+ [definition]
+ S[k] = sum_j=1^n-1 a[j]*sin(pi*j*k/n), 0<k<n
+ [usage]
+ ip[0] = 0; // first time only
+ dfst(n, a, t, ip, w);
+ [parameters]
+ n :data length + 1 (int)
+ n >= 2, n = power of 2
+ a[0...n-1] :input/output data (double *)
+ output data
+ a[k] = S[k], 0<k<n
+ (a[0] is used for work area)
+ t[0...n/2-1] :work area (double *)
+ ip[0...*] :work area for bit reversal (int *)
+ length of ip >= 2+sqrt(n/4)
+ strictly,
+ length of ip >=
+ 2+(1<<(int)(log(n/4+0.5)/log(2))/2).
+ ip[0],ip[1] are pointers of the cos/sin table.
+ w[0...n*5/8-1] :cos/sin table (double *)
+ w[],ip[] are initialized if ip[0] == 0.
+ [remark]
+ Inverse of
+ dfst(n, a, t, ip, w);
+ is
+ dfst(n, a, t, ip, w);
+ for (j = 1; j <= n - 1; j++) {
+ a[j] *= 2.0 / n;
+ }
+ .
+
+
+Appendix :
+ The cos/sin table is recalculated when the larger table required.
+ w[] and ip[] are compatible with all routines.
+*/
+
+
+void cdft(int n, int isgn, double *a, int *ip, double *w)
+{
+ void makewt(int nw, int *ip, double *w);
+ void cftfsub(int n, double *a, int *ip, int nw, double *w);
+ void cftbsub(int n, double *a, int *ip, int nw, double *w);
+ int nw;
+
+ nw = ip[0];
+ if (n > (nw << 2)) {
+ nw = n >> 2;
+ makewt(nw, ip, w);
+ }
+ if (isgn >= 0) {
+ cftfsub(n, a, ip, nw, w);
+ } else {
+ cftbsub(n, a, ip, nw, w);
+ }
+}
+
+
+void rdft(int n, int isgn, double *a, int *ip, double *w)
+{
+ void makewt(int nw, int *ip, double *w);
+ void makect(int nc, int *ip, double *c);
+ void cftfsub(int n, double *a, int *ip, int nw, double *w);
+ void cftbsub(int n, double *a, int *ip, int nw, double *w);
+ void rftfsub(int n, double *a, int nc, double *c);
+ void rftbsub(int n, double *a, int nc, double *c);
+ int nw, nc;
+ double xi;
+
+ nw = ip[0];
+ if (n > (nw << 2)) {
+ nw = n >> 2;
+ makewt(nw, ip, w);
+ }
+ nc = ip[1];
+ if (n > (nc << 2)) {
+ nc = n >> 2;
+ makect(nc, ip, w + nw);
+ }
+ if (isgn >= 0) {
+ if (n > 4) {
+ cftfsub(n, a, ip, nw, w);
+ rftfsub(n, a, nc, w + nw);
+ } else if (n == 4) {
+ cftfsub(n, a, ip, nw, w);
+ }
+ xi = a[0] - a[1];
+ a[0] += a[1];
+ a[1] = xi;
+ } else {
+ a[1] = 0.5 * (a[0] - a[1]);
+ a[0] -= a[1];
+ if (n > 4) {
+ rftbsub(n, a, nc, w + nw);
+ cftbsub(n, a, ip, nw, w);
+ } else if (n == 4) {
+ cftbsub(n, a, ip, nw, w);
+ }
+ }
+}
+
+
+void ddct(int n, int isgn, double *a, int *ip, double *w)
+{
+ void makewt(int nw, int *ip, double *w);
+ void makect(int nc, int *ip, double *c);
+ void cftfsub(int n, double *a, int *ip, int nw, double *w);
+ void cftbsub(int n, double *a, int *ip, int nw, double *w);
+ void rftfsub(int n, double *a, int nc, double *c);
+ void rftbsub(int n, double *a, int nc, double *c);
+ void dctsub(int n, double *a, int nc, double *c);
+ int j, nw, nc;
+ double xr;
+
+ nw = ip[0];
+ if (n > (nw << 2)) {
+ nw = n >> 2;
+ makewt(nw, ip, w);
+ }
+ nc = ip[1];
+ if (n > nc) {
+ nc = n;
+ makect(nc, ip, w + nw);
+ }
+ if (isgn < 0) {
+ xr = a[n - 1];
+ for (j = n - 2; j >= 2; j -= 2) {
+ a[j + 1] = a[j] - a[j - 1];
+ a[j] += a[j - 1];
+ }
+ a[1] = a[0] - xr;
+ a[0] += xr;
+ if (n > 4) {
+ rftbsub(n, a, nc, w + nw);
+ cftbsub(n, a, ip, nw, w);
+ } else if (n == 4) {
+ cftbsub(n, a, ip, nw, w);
+ }
+ }
+ dctsub(n, a, nc, w + nw);
+ if (isgn >= 0) {
+ if (n > 4) {
+ cftfsub(n, a, ip, nw, w);
+ rftfsub(n, a, nc, w + nw);
+ } else if (n == 4) {
+ cftfsub(n, a, ip, nw, w);
+ }
+ xr = a[0] - a[1];
+ a[0] += a[1];
+ for (j = 2; j < n; j += 2) {
+ a[j - 1] = a[j] - a[j + 1];
+ a[j] += a[j + 1];
+ }
+ a[n - 1] = xr;
+ }
+}
+
+
+void ddst(int n, int isgn, double *a, int *ip, double *w)
+{
+ void makewt(int nw, int *ip, double *w);
+ void makect(int nc, int *ip, double *c);
+ void cftfsub(int n, double *a, int *ip, int nw, double *w);
+ void cftbsub(int n, double *a, int *ip, int nw, double *w);
+ void rftfsub(int n, double *a, int nc, double *c);
+ void rftbsub(int n, double *a, int nc, double *c);
+ void dstsub(int n, double *a, int nc, double *c);
+ int j, nw, nc;
+ double xr;
+
+ nw = ip[0];
+ if (n > (nw << 2)) {
+ nw = n >> 2;
+ makewt(nw, ip, w);
+ }
+ nc = ip[1];
+ if (n > nc) {
+ nc = n;
+ makect(nc, ip, w + nw);
+ }
+ if (isgn < 0) {
+ xr = a[n - 1];
+ for (j = n - 2; j >= 2; j -= 2) {
+ a[j + 1] = -a[j] - a[j - 1];
+ a[j] -= a[j - 1];
+ }
+ a[1] = a[0] + xr;
+ a[0] -= xr;
+ if (n > 4) {
+ rftbsub(n, a, nc, w + nw);
+ cftbsub(n, a, ip, nw, w);
+ } else if (n == 4) {
+ cftbsub(n, a, ip, nw, w);
+ }
+ }
+ dstsub(n, a, nc, w + nw);
+ if (isgn >= 0) {
+ if (n > 4) {
+ cftfsub(n, a, ip, nw, w);
+ rftfsub(n, a, nc, w + nw);
+ } else if (n == 4) {
+ cftfsub(n, a, ip, nw, w);
+ }
+ xr = a[0] - a[1];
+ a[0] += a[1];
+ for (j = 2; j < n; j += 2) {
+ a[j - 1] = -a[j] - a[j + 1];
+ a[j] -= a[j + 1];
+ }
+ a[n - 1] = -xr;
+ }
+}
+
+
+void dfct(int n, double *a, double *t, int *ip, double *w)
+{
+ void makewt(int nw, int *ip, double *w);
+ void makect(int nc, int *ip, double *c);
+ void cftfsub(int n, double *a, int *ip, int nw, double *w);
+ void rftfsub(int n, double *a, int nc, double *c);
+ void dctsub(int n, double *a, int nc, double *c);
+ int j, k, l, m, mh, nw, nc;
+ double xr, xi, yr, yi;
+
+ nw = ip[0];
+ if (n > (nw << 3)) {
+ nw = n >> 3;
+ makewt(nw, ip, w);
+ }
+ nc = ip[1];
+ if (n > (nc << 1)) {
+ nc = n >> 1;
+ makect(nc, ip, w + nw);
+ }
+ m = n >> 1;
+ yi = a[m];
+ xi = a[0] + a[n];
+ a[0] -= a[n];
+ t[0] = xi - yi;
+ t[m] = xi + yi;
+ if (n > 2) {
+ mh = m >> 1;
+ for (j = 1; j < mh; j++) {
+ k = m - j;
+ xr = a[j] - a[n - j];
+ xi = a[j] + a[n - j];
+ yr = a[k] - a[n - k];
+ yi = a[k] + a[n - k];
+ a[j] = xr;
+ a[k] = yr;
+ t[j] = xi - yi;
+ t[k] = xi + yi;
+ }
+ t[mh] = a[mh] + a[n - mh];
+ a[mh] -= a[n - mh];
+ dctsub(m, a, nc, w + nw);
+ if (m > 4) {
+ cftfsub(m, a, ip, nw, w);
+ rftfsub(m, a, nc, w + nw);
+ } else if (m == 4) {
+ cftfsub(m, a, ip, nw, w);
+ }
+ a[n - 1] = a[0] - a[1];
+ a[1] = a[0] + a[1];
+ for (j = m - 2; j >= 2; j -= 2) {
+ a[2 * j + 1] = a[j] + a[j + 1];
+ a[2 * j - 1] = a[j] - a[j + 1];
+ }
+ l = 2;
+ m = mh;
+ while (m >= 2) {
+ dctsub(m, t, nc, w + nw);
+ if (m > 4) {
+ cftfsub(m, t, ip, nw, w);
+ rftfsub(m, t, nc, w + nw);
+ } else if (m == 4) {
+ cftfsub(m, t, ip, nw, w);
+ }
+ a[n - l] = t[0] - t[1];
+ a[l] = t[0] + t[1];
+ k = 0;
+ for (j = 2; j < m; j += 2) {
+ k += l << 2;
+ a[k - l] = t[j] - t[j + 1];
+ a[k + l] = t[j] + t[j + 1];
+ }
+ l <<= 1;
+ mh = m >> 1;
+ for (j = 0; j < mh; j++) {
+ k = m - j;
+ t[j] = t[m + k] - t[m + j];
+ t[k] = t[m + k] + t[m + j];
+ }
+ t[mh] = t[m + mh];
+ m = mh;
+ }
+ a[l] = t[0];
+ a[n] = t[2] - t[1];
+ a[0] = t[2] + t[1];
+ } else {
+ a[1] = a[0];
+ a[2] = t[0];
+ a[0] = t[1];
+ }
+}
+
+
+void dfst(int n, double *a, double *t, int *ip, double *w)
+{
+ void makewt(int nw, int *ip, double *w);
+ void makect(int nc, int *ip, double *c);
+ void cftfsub(int n, double *a, int *ip, int nw, double *w);
+ void rftfsub(int n, double *a, int nc, double *c);
+ void dstsub(int n, double *a, int nc, double *c);
+ int j, k, l, m, mh, nw, nc;
+ double xr, xi, yr, yi;
+
+ nw = ip[0];
+ if (n > (nw << 3)) {
+ nw = n >> 3;
+ makewt(nw, ip, w);
+ }
+ nc = ip[1];
+ if (n > (nc << 1)) {
+ nc = n >> 1;
+ makect(nc, ip, w + nw);
+ }
+ if (n > 2) {
+ m = n >> 1;
+ mh = m >> 1;
+ for (j = 1; j < mh; j++) {
+ k = m - j;
+ xr = a[j] + a[n - j];
+ xi = a[j] - a[n - j];
+ yr = a[k] + a[n - k];
+ yi = a[k] - a[n - k];
+ a[j] = xr;
+ a[k] = yr;
+ t[j] = xi + yi;
+ t[k] = xi - yi;
+ }
+ t[0] = a[mh] - a[n - mh];
+ a[mh] += a[n - mh];
+ a[0] = a[m];
+ dstsub(m, a, nc, w + nw);
+ if (m > 4) {
+ cftfsub(m, a, ip, nw, w);
+ rftfsub(m, a, nc, w + nw);
+ } else if (m == 4) {
+ cftfsub(m, a, ip, nw, w);
+ }
+ a[n - 1] = a[1] - a[0];
+ a[1] = a[0] + a[1];
+ for (j = m - 2; j >= 2; j -= 2) {
+ a[2 * j + 1] = a[j] - a[j + 1];
+ a[2 * j - 1] = -a[j] - a[j + 1];
+ }
+ l = 2;
+ m = mh;
+ while (m >= 2) {
+ dstsub(m, t, nc, w + nw);
+ if (m > 4) {
+ cftfsub(m, t, ip, nw, w);
+ rftfsub(m, t, nc, w + nw);
+ } else if (m == 4) {
+ cftfsub(m, t, ip, nw, w);
+ }
+ a[n - l] = t[1] - t[0];
+ a[l] = t[0] + t[1];
+ k = 0;
+ for (j = 2; j < m; j += 2) {
+ k += l << 2;
+ a[k - l] = -t[j] - t[j + 1];
+ a[k + l] = t[j] - t[j + 1];
+ }
+ l <<= 1;
+ mh = m >> 1;
+ for (j = 1; j < mh; j++) {
+ k = m - j;
+ t[j] = t[m + k] + t[m + j];
+ t[k] = t[m + k] - t[m + j];
+ }
+ t[0] = t[m + mh];
+ m = mh;
+ }
+ a[l] = t[0];
+ }
+ a[0] = 0;
+}
+
+
+/* -------- initializing routines -------- */
+
+
+#include <math.h>
+
+void makewt(int nw, int *ip, double *w)
+{
+ void makeipt(int nw, int *ip);
+ int j, nwh, nw0, nw1;
+ double delta, wn4r, wk1r, wk1i, wk3r, wk3i;
+
+ ip[0] = nw;
+ ip[1] = 1;
+ if (nw > 2) {
+ nwh = nw >> 1;
+ delta = atan(1.0) / nwh;
+ wn4r = cos(delta * nwh);
+ w[0] = 1;
+ w[1] = wn4r;
+ if (nwh == 4) {
+ w[2] = cos(delta * 2);
+ w[3] = sin(delta * 2);
+ } else if (nwh > 4) {
+ makeipt(nw, ip);
+ w[2] = 0.5 / cos(delta * 2);
+ w[3] = 0.5 / cos(delta * 6);
+ for (j = 4; j < nwh; j += 4) {
+ w[j] = cos(delta * j);
+ w[j + 1] = sin(delta * j);
+ w[j + 2] = cos(3 * delta * j);
+ w[j + 3] = -sin(3 * delta * j);
+ }
+ }
+ nw0 = 0;
+ while (nwh > 2) {
+ nw1 = nw0 + nwh;
+ nwh >>= 1;
+ w[nw1] = 1;
+ w[nw1 + 1] = wn4r;
+ if (nwh == 4) {
+ wk1r = w[nw0 + 4];
+ wk1i = w[nw0 + 5];
+ w[nw1 + 2] = wk1r;
+ w[nw1 + 3] = wk1i;
+ } else if (nwh > 4) {
+ wk1r = w[nw0 + 4];
+ wk3r = w[nw0 + 6];
+ w[nw1 + 2] = 0.5 / wk1r;
+ w[nw1 + 3] = 0.5 / wk3r;
+ for (j = 4; j < nwh; j += 4) {
+ wk1r = w[nw0 + 2 * j];
+ wk1i = w[nw0 + 2 * j + 1];
+ wk3r = w[nw0 + 2 * j + 2];
+ wk3i = w[nw0 + 2 * j + 3];
+ w[nw1 + j] = wk1r;
+ w[nw1 + j + 1] = wk1i;
+ w[nw1 + j + 2] = wk3r;
+ w[nw1 + j + 3] = wk3i;
+ }
+ }
+ nw0 = nw1;
+ }
+ }
+}
+
+
+void makeipt(int nw, int *ip)
+{
+ int j, l, m, m2, p, q;
+
+ ip[2] = 0;
+ ip[3] = 16;
+ m = 2;
+ for (l = nw; l > 32; l >>= 2) {
+ m2 = m << 1;
+ q = m2 << 3;
+ for (j = m; j < m2; j++) {
+ p = ip[j] << 2;
+ ip[m + j] = p;
+ ip[m2 + j] = p + q;
+ }
+ m = m2;
+ }
+}
+
+
+void makect(int nc, int *ip, double *c)
+{
+ int j, nch;
+ double delta;
+
+ ip[1] = nc;
+ if (nc > 1) {
+ nch = nc >> 1;
+ delta = atan(1.0) / nch;
+ c[0] = cos(delta * nch);
+ c[nch] = 0.5 * c[0];
+ for (j = 1; j < nch; j++) {
+ c[j] = 0.5 * cos(delta * j);
+ c[nc - j] = 0.5 * sin(delta * j);
+ }
+ }
+}
+
+
+/* -------- child routines -------- */
+
+
+#ifdef USE_CDFT_PTHREADS
+#define USE_CDFT_THREADS
+#ifndef CDFT_THREADS_BEGIN_N
+#define CDFT_THREADS_BEGIN_N 8192
+#endif
+#ifndef CDFT_4THREADS_BEGIN_N
+#define CDFT_4THREADS_BEGIN_N 65536
+#endif
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define cdft_thread_t pthread_t
+#define cdft_thread_create(thp,func,argp) { \
+ if (pthread_create(thp, NULL, func, (void *) argp) != 0) { \
+ fprintf(stderr, "cdft thread error\n"); \
+ exit(1); \
+ } \
+}
+#define cdft_thread_wait(th) { \
+ if (pthread_join(th, NULL) != 0) { \
+ fprintf(stderr, "cdft thread error\n"); \
+ exit(1); \
+ } \
+}
+#endif /* USE_CDFT_PTHREADS */
+
+
+#ifdef USE_CDFT_WINTHREADS
+#define USE_CDFT_THREADS
+#ifndef CDFT_THREADS_BEGIN_N
+#define CDFT_THREADS_BEGIN_N 32768
+#endif
+#ifndef CDFT_4THREADS_BEGIN_N
+#define CDFT_4THREADS_BEGIN_N 524288
+#endif
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define cdft_thread_t HANDLE
+#define cdft_thread_create(thp,func,argp) { \
+ DWORD thid; \
+ *(thp) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, (LPVOID) argp, 0, &thid); \
+ if (*(thp) == 0) { \
+ fprintf(stderr, "cdft thread error\n"); \
+ exit(1); \
+ } \
+}
+#define cdft_thread_wait(th) { \
+ WaitForSingleObject(th, INFINITE); \
+ CloseHandle(th); \
+}
+#endif /* USE_CDFT_WINTHREADS */
+
+
+void cftfsub(int n, double *a, int *ip, int nw, double *w)
+{
+ void bitrv2(int n, int *ip, double *a);
+ void bitrv216(double *a);
+ void bitrv208(double *a);
+ void cftf1st(int n, double *a, double *w);
+ void cftrec4(int n, double *a, int nw, double *w);
+ void cftleaf(int n, int isplt, double *a, int nw, double *w);
+ void cftfx41(int n, double *a, int nw, double *w);
+ void cftf161(double *a, double *w);
+ void cftf081(double *a, double *w);
+ void cftf040(double *a);
+ void cftx020(double *a);
+#ifdef USE_CDFT_THREADS
+ void cftrec4_th(int n, double *a, int nw, double *w);
+#endif /* USE_CDFT_THREADS */
+
+ if (n > 8) {
+ if (n > 32) {
+ cftf1st(n, a, &w[nw - (n >> 2)]);
+#ifdef USE_CDFT_THREADS
+ if (n > CDFT_THREADS_BEGIN_N) {
+ cftrec4_th(n, a, nw, w);
+ } else
+#endif /* USE_CDFT_THREADS */
+ if (n > 512) {
+ cftrec4(n, a, nw, w);
+ } else if (n > 128) {
+ cftleaf(n, 1, a, nw, w);
+ } else {
+ cftfx41(n, a, nw, w);
+ }
+ bitrv2(n, ip, a);
+ } else if (n == 32) {
+ cftf161(a, &w[nw - 8]);
+ bitrv216(a);
+ } else {
+ cftf081(a, w);
+ bitrv208(a);
+ }
+ } else if (n == 8) {
+ cftf040(a);
+ } else if (n == 4) {
+ cftx020(a);
+ }
+}
+
+
+void cftbsub(int n, double *a, int *ip, int nw, double *w)
+{
+ void bitrv2conj(int n, int *ip, double *a);
+ void bitrv216neg(double *a);
+ void bitrv208neg(double *a);
+ void cftb1st(int n, double *a, double *w);
+ void cftrec4(int n, double *a, int nw, double *w);
+ void cftleaf(int n, int isplt, double *a, int nw, double *w);
+ void cftfx41(int n, double *a, int nw, double *w);
+ void cftf161(double *a, double *w);
+ void cftf081(double *a, double *w);
+ void cftb040(double *a);
+ void cftx020(double *a);
+#ifdef USE_CDFT_THREADS
+ void cftrec4_th(int n, double *a, int nw, double *w);
+#endif /* USE_CDFT_THREADS */
+
+ if (n > 8) {
+ if (n > 32) {
+ cftb1st(n, a, &w[nw - (n >> 2)]);
+#ifdef USE_CDFT_THREADS
+ if (n > CDFT_THREADS_BEGIN_N) {
+ cftrec4_th(n, a, nw, w);
+ } else
+#endif /* USE_CDFT_THREADS */
+ if (n > 512) {
+ cftrec4(n, a, nw, w);
+ } else if (n > 128) {
+ cftleaf(n, 1, a, nw, w);
+ } else {
+ cftfx41(n, a, nw, w);
+ }
+ bitrv2conj(n, ip, a);
+ } else if (n == 32) {
+ cftf161(a, &w[nw - 8]);
+ bitrv216neg(a);
+ } else {
+ cftf081(a, w);
+ bitrv208neg(a);
+ }
+ } else if (n == 8) {
+ cftb040(a);
+ } else if (n == 4) {
+ cftx020(a);
+ }
+}
+
+
+void bitrv2(int n, int *ip, double *a)
+{
+ int j, j1, k, k1, l, m, nh, nm;
+ double xr, xi, yr, yi;
+
+ m = 1;
+ for (l = n >> 2; l > 8; l >>= 2) {
+ m <<= 1;
+ }
+ nh = n >> 1;
+ nm = 4 * m;
+ if (l == 8) {
+ for (k = 0; k < m; k++) {
+ for (j = 0; j < k; j++) {
+ j1 = 4 * j + 2 * ip[m + k];
+ k1 = 4 * k + 2 * ip[m + j];
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nh;
+ k1 += 2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += 2;
+ k1 += nh;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nh;
+ k1 -= 2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ k1 = 4 * k + 2 * ip[m + k];
+ j1 = k1 + 2;
+ k1 += nh;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= 2;
+ k1 -= nh;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nh + 2;
+ k1 += nh + 2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nh - nm;
+ k1 += 2 * nm - 2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ } else {
+ for (k = 0; k < m; k++) {
+ for (j = 0; j < k; j++) {
+ j1 = 4 * j + ip[m + k];
+ k1 = 4 * k + ip[m + j];
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nh;
+ k1 += 2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += 2;
+ k1 += nh;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nh;
+ k1 -= 2;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ k1 = 4 * k + ip[m + k];
+ j1 = k1 + 2;
+ k1 += nh;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = a[j1 + 1];
+ yr = a[k1];
+ yi = a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ }
+}
+
+
+void bitrv2conj(int n, int *ip, double *a)
+{
+ int j, j1, k, k1, l, m, nh, nm;
+ double xr, xi, yr, yi;
+
+ m = 1;
+ for (l = n >> 2; l > 8; l >>= 2) {
+ m <<= 1;
+ }
+ nh = n >> 1;
+ nm = 4 * m;
+ if (l == 8) {
+ for (k = 0; k < m; k++) {
+ for (j = 0; j < k; j++) {
+ j1 = 4 * j + 2 * ip[m + k];
+ k1 = 4 * k + 2 * ip[m + j];
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nh;
+ k1 += 2;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += 2;
+ k1 += nh;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nh;
+ k1 -= 2;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ k1 = 4 * k + 2 * ip[m + k];
+ j1 = k1 + 2;
+ k1 += nh;
+ a[j1 - 1] = -a[j1 - 1];
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ a[k1 + 3] = -a[k1 + 3];
+ j1 += nm;
+ k1 += 2 * nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= 2;
+ k1 -= nh;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nh + 2;
+ k1 += nh + 2;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nh - nm;
+ k1 += 2 * nm - 2;
+ a[j1 - 1] = -a[j1 - 1];
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ a[k1 + 3] = -a[k1 + 3];
+ }
+ } else {
+ for (k = 0; k < m; k++) {
+ for (j = 0; j < k; j++) {
+ j1 = 4 * j + ip[m + k];
+ k1 = 4 * k + ip[m + j];
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nh;
+ k1 += 2;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += 2;
+ k1 += nh;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 += nm;
+ k1 += nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nh;
+ k1 -= 2;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ j1 -= nm;
+ k1 -= nm;
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ }
+ k1 = 4 * k + ip[m + k];
+ j1 = k1 + 2;
+ k1 += nh;
+ a[j1 - 1] = -a[j1 - 1];
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ a[k1 + 3] = -a[k1 + 3];
+ j1 += nm;
+ k1 += nm;
+ a[j1 - 1] = -a[j1 - 1];
+ xr = a[j1];
+ xi = -a[j1 + 1];
+ yr = a[k1];
+ yi = -a[k1 + 1];
+ a[j1] = yr;
+ a[j1 + 1] = yi;
+ a[k1] = xr;
+ a[k1 + 1] = xi;
+ a[k1 + 3] = -a[k1 + 3];
+ }
+ }
+}
+
+
+void bitrv216(double *a)
+{
+ double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
+ x5r, x5i, x7r, x7i, x8r, x8i, x10r, x10i,
+ x11r, x11i, x12r, x12i, x13r, x13i, x14r, x14i;
+
+ x1r = a[2];
+ x1i = a[3];
+ x2r = a[4];
+ x2i = a[5];
+ x3r = a[6];
+ x3i = a[7];
+ x4r = a[8];
+ x4i = a[9];
+ x5r = a[10];
+ x5i = a[11];
+ x7r = a[14];
+ x7i = a[15];
+ x8r = a[16];
+ x8i = a[17];
+ x10r = a[20];
+ x10i = a[21];
+ x11r = a[22];
+ x11i = a[23];
+ x12r = a[24];
+ x12i = a[25];
+ x13r = a[26];
+ x13i = a[27];
+ x14r = a[28];
+ x14i = a[29];
+ a[2] = x8r;
+ a[3] = x8i;
+ a[4] = x4r;
+ a[5] = x4i;
+ a[6] = x12r;
+ a[7] = x12i;
+ a[8] = x2r;
+ a[9] = x2i;
+ a[10] = x10r;
+ a[11] = x10i;
+ a[14] = x14r;
+ a[15] = x14i;
+ a[16] = x1r;
+ a[17] = x1i;
+ a[20] = x5r;
+ a[21] = x5i;
+ a[22] = x13r;
+ a[23] = x13i;
+ a[24] = x3r;
+ a[25] = x3i;
+ a[26] = x11r;
+ a[27] = x11i;
+ a[28] = x7r;
+ a[29] = x7i;
+}
+
+
+void bitrv216neg(double *a)
+{
+ double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
+ x5r, x5i, x6r, x6i, x7r, x7i, x8r, x8i,
+ x9r, x9i, x10r, x10i, x11r, x11i, x12r, x12i,
+ x13r, x13i, x14r, x14i, x15r, x15i;
+
+ x1r = a[2];
+ x1i = a[3];
+ x2r = a[4];
+ x2i = a[5];
+ x3r = a[6];
+ x3i = a[7];
+ x4r = a[8];
+ x4i = a[9];
+ x5r = a[10];
+ x5i = a[11];
+ x6r = a[12];
+ x6i = a[13];
+ x7r = a[14];
+ x7i = a[15];
+ x8r = a[16];
+ x8i = a[17];
+ x9r = a[18];
+ x9i = a[19];
+ x10r = a[20];
+ x10i = a[21];
+ x11r = a[22];
+ x11i = a[23];
+ x12r = a[24];
+ x12i = a[25];
+ x13r = a[26];
+ x13i = a[27];
+ x14r = a[28];
+ x14i = a[29];
+ x15r = a[30];
+ x15i = a[31];
+ a[2] = x15r;
+ a[3] = x15i;
+ a[4] = x7r;
+ a[5] = x7i;
+ a[6] = x11r;
+ a[7] = x11i;
+ a[8] = x3r;
+ a[9] = x3i;
+ a[10] = x13r;
+ a[11] = x13i;
+ a[12] = x5r;
+ a[13] = x5i;
+ a[14] = x9r;
+ a[15] = x9i;
+ a[16] = x1r;
+ a[17] = x1i;
+ a[18] = x14r;
+ a[19] = x14i;
+ a[20] = x6r;
+ a[21] = x6i;
+ a[22] = x10r;
+ a[23] = x10i;
+ a[24] = x2r;
+ a[25] = x2i;
+ a[26] = x12r;
+ a[27] = x12i;
+ a[28] = x4r;
+ a[29] = x4i;
+ a[30] = x8r;
+ a[31] = x8i;
+}
+
+
+void bitrv208(double *a)
+{
+ double x1r, x1i, x3r, x3i, x4r, x4i, x6r, x6i;
+
+ x1r = a[2];
+ x1i = a[3];
+ x3r = a[6];
+ x3i = a[7];
+ x4r = a[8];
+ x4i = a[9];
+ x6r = a[12];
+ x6i = a[13];
+ a[2] = x4r;
+ a[3] = x4i;
+ a[6] = x6r;
+ a[7] = x6i;
+ a[8] = x1r;
+ a[9] = x1i;
+ a[12] = x3r;
+ a[13] = x3i;
+}
+
+
+void bitrv208neg(double *a)
+{
+ double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
+ x5r, x5i, x6r, x6i, x7r, x7i;
+
+ x1r = a[2];
+ x1i = a[3];
+ x2r = a[4];
+ x2i = a[5];
+ x3r = a[6];
+ x3i = a[7];
+ x4r = a[8];
+ x4i = a[9];
+ x5r = a[10];
+ x5i = a[11];
+ x6r = a[12];
+ x6i = a[13];
+ x7r = a[14];
+ x7i = a[15];
+ a[2] = x7r;
+ a[3] = x7i;
+ a[4] = x3r;
+ a[5] = x3i;
+ a[6] = x5r;
+ a[7] = x5i;
+ a[8] = x1r;
+ a[9] = x1i;
+ a[10] = x6r;
+ a[11] = x6i;
+ a[12] = x2r;
+ a[13] = x2i;
+ a[14] = x4r;
+ a[15] = x4i;
+}
+
+
+void cftf1st(int n, double *a, double *w)
+{
+ int j, j0, j1, j2, j3, k, m, mh;
+ double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
+ wd1r, wd1i, wd3r, wd3i;
+ double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
+ y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
+
+ mh = n >> 3;
+ m = 2 * mh;
+ j1 = m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[0] + a[j2];
+ x0i = a[1] + a[j2 + 1];
+ x1r = a[0] - a[j2];
+ x1i = a[1] - a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[0] = x0r + x2r;
+ a[1] = x0i + x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ a[j2] = x1r - x3i;
+ a[j2 + 1] = x1i + x3r;
+ a[j3] = x1r + x3i;
+ a[j3 + 1] = x1i - x3r;
+ wn4r = w[1];
+ csc1 = w[2];
+ csc3 = w[3];
+ wd1r = 1;
+ wd1i = 0;
+ wd3r = 1;
+ wd3i = 0;
+ k = 0;
+ for (j = 2; j < mh - 2; j += 4) {
+ k += 4;
+ wk1r = csc1 * (wd1r + w[k]);
+ wk1i = csc1 * (wd1i + w[k + 1]);
+ wk3r = csc3 * (wd3r + w[k + 2]);
+ wk3i = csc3 * (wd3i + w[k + 3]);
+ wd1r = w[k];
+ wd1i = w[k + 1];
+ wd3r = w[k + 2];
+ wd3i = w[k + 3];
+ j1 = j + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j] + a[j2];
+ x0i = a[j + 1] + a[j2 + 1];
+ x1r = a[j] - a[j2];
+ x1i = a[j + 1] - a[j2 + 1];
+ y0r = a[j + 2] + a[j2 + 2];
+ y0i = a[j + 3] + a[j2 + 3];
+ y1r = a[j + 2] - a[j2 + 2];
+ y1i = a[j + 3] - a[j2 + 3];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ y2r = a[j1 + 2] + a[j3 + 2];
+ y2i = a[j1 + 3] + a[j3 + 3];
+ y3r = a[j1 + 2] - a[j3 + 2];
+ y3i = a[j1 + 3] - a[j3 + 3];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ a[j + 2] = y0r + y2r;
+ a[j + 3] = y0i + y2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ a[j1 + 2] = y0r - y2r;
+ a[j1 + 3] = y0i - y2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2] = wk1r * x0r - wk1i * x0i;
+ a[j2 + 1] = wk1r * x0i + wk1i * x0r;
+ x0r = y1r - y3i;
+ x0i = y1i + y3r;
+ a[j2 + 2] = wd1r * x0r - wd1i * x0i;
+ a[j2 + 3] = wd1r * x0i + wd1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3r * x0r + wk3i * x0i;
+ a[j3 + 1] = wk3r * x0i - wk3i * x0r;
+ x0r = y1r + y3i;
+ x0i = y1i - y3r;
+ a[j3 + 2] = wd3r * x0r + wd3i * x0i;
+ a[j3 + 3] = wd3r * x0i - wd3i * x0r;
+ j0 = m - j;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0] + a[j2];
+ x0i = a[j0 + 1] + a[j2 + 1];
+ x1r = a[j0] - a[j2];
+ x1i = a[j0 + 1] - a[j2 + 1];
+ y0r = a[j0 - 2] + a[j2 - 2];
+ y0i = a[j0 - 1] + a[j2 - 1];
+ y1r = a[j0 - 2] - a[j2 - 2];
+ y1i = a[j0 - 1] - a[j2 - 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ y2r = a[j1 - 2] + a[j3 - 2];
+ y2i = a[j1 - 1] + a[j3 - 1];
+ y3r = a[j1 - 2] - a[j3 - 2];
+ y3i = a[j1 - 1] - a[j3 - 1];
+ a[j0] = x0r + x2r;
+ a[j0 + 1] = x0i + x2i;
+ a[j0 - 2] = y0r + y2r;
+ a[j0 - 1] = y0i + y2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ a[j1 - 2] = y0r - y2r;
+ a[j1 - 1] = y0i - y2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2] = wk1i * x0r - wk1r * x0i;
+ a[j2 + 1] = wk1i * x0i + wk1r * x0r;
+ x0r = y1r - y3i;
+ x0i = y1i + y3r;
+ a[j2 - 2] = wd1i * x0r - wd1r * x0i;
+ a[j2 - 1] = wd1i * x0i + wd1r * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3i * x0r + wk3r * x0i;
+ a[j3 + 1] = wk3i * x0i - wk3r * x0r;
+ x0r = y1r + y3i;
+ x0i = y1i - y3r;
+ a[j3 - 2] = wd3i * x0r + wd3r * x0i;
+ a[j3 - 1] = wd3i * x0i - wd3r * x0r;
+ }
+ wk1r = csc1 * (wd1r + wn4r);
+ wk1i = csc1 * (wd1i + wn4r);
+ wk3r = csc3 * (wd3r - wn4r);
+ wk3i = csc3 * (wd3i - wn4r);
+ j0 = mh;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0 - 2] + a[j2 - 2];
+ x0i = a[j0 - 1] + a[j2 - 1];
+ x1r = a[j0 - 2] - a[j2 - 2];
+ x1i = a[j0 - 1] - a[j2 - 1];
+ x2r = a[j1 - 2] + a[j3 - 2];
+ x2i = a[j1 - 1] + a[j3 - 1];
+ x3r = a[j1 - 2] - a[j3 - 2];
+ x3i = a[j1 - 1] - a[j3 - 1];
+ a[j0 - 2] = x0r + x2r;
+ a[j0 - 1] = x0i + x2i;
+ a[j1 - 2] = x0r - x2r;
+ a[j1 - 1] = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2 - 2] = wk1r * x0r - wk1i * x0i;
+ a[j2 - 1] = wk1r * x0i + wk1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3 - 2] = wk3r * x0r + wk3i * x0i;
+ a[j3 - 1] = wk3r * x0i - wk3i * x0r;
+ x0r = a[j0] + a[j2];
+ x0i = a[j0 + 1] + a[j2 + 1];
+ x1r = a[j0] - a[j2];
+ x1i = a[j0 + 1] - a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[j0] = x0r + x2r;
+ a[j0 + 1] = x0i + x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2] = wn4r * (x0r - x0i);
+ a[j2 + 1] = wn4r * (x0i + x0r);
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = -wn4r * (x0r + x0i);
+ a[j3 + 1] = -wn4r * (x0i - x0r);
+ x0r = a[j0 + 2] + a[j2 + 2];
+ x0i = a[j0 + 3] + a[j2 + 3];
+ x1r = a[j0 + 2] - a[j2 + 2];
+ x1i = a[j0 + 3] - a[j2 + 3];
+ x2r = a[j1 + 2] + a[j3 + 2];
+ x2i = a[j1 + 3] + a[j3 + 3];
+ x3r = a[j1 + 2] - a[j3 + 2];
+ x3i = a[j1 + 3] - a[j3 + 3];
+ a[j0 + 2] = x0r + x2r;
+ a[j0 + 3] = x0i + x2i;
+ a[j1 + 2] = x0r - x2r;
+ a[j1 + 3] = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2 + 2] = wk1i * x0r - wk1r * x0i;
+ a[j2 + 3] = wk1i * x0i + wk1r * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3 + 2] = wk3i * x0r + wk3r * x0i;
+ a[j3 + 3] = wk3i * x0i - wk3r * x0r;
+}
+
+
+void cftb1st(int n, double *a, double *w)
+{
+ int j, j0, j1, j2, j3, k, m, mh;
+ double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
+ wd1r, wd1i, wd3r, wd3i;
+ double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
+ y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
+
+ mh = n >> 3;
+ m = 2 * mh;
+ j1 = m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[0] + a[j2];
+ x0i = -a[1] - a[j2 + 1];
+ x1r = a[0] - a[j2];
+ x1i = -a[1] + a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[0] = x0r + x2r;
+ a[1] = x0i - x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i + x2i;
+ a[j2] = x1r + x3i;
+ a[j2 + 1] = x1i + x3r;
+ a[j3] = x1r - x3i;
+ a[j3 + 1] = x1i - x3r;
+ wn4r = w[1];
+ csc1 = w[2];
+ csc3 = w[3];
+ wd1r = 1;
+ wd1i = 0;
+ wd3r = 1;
+ wd3i = 0;
+ k = 0;
+ for (j = 2; j < mh - 2; j += 4) {
+ k += 4;
+ wk1r = csc1 * (wd1r + w[k]);
+ wk1i = csc1 * (wd1i + w[k + 1]);
+ wk3r = csc3 * (wd3r + w[k + 2]);
+ wk3i = csc3 * (wd3i + w[k + 3]);
+ wd1r = w[k];
+ wd1i = w[k + 1];
+ wd3r = w[k + 2];
+ wd3i = w[k + 3];
+ j1 = j + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j] + a[j2];
+ x0i = -a[j + 1] - a[j2 + 1];
+ x1r = a[j] - a[j2];
+ x1i = -a[j + 1] + a[j2 + 1];
+ y0r = a[j + 2] + a[j2 + 2];
+ y0i = -a[j + 3] - a[j2 + 3];
+ y1r = a[j + 2] - a[j2 + 2];
+ y1i = -a[j + 3] + a[j2 + 3];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ y2r = a[j1 + 2] + a[j3 + 2];
+ y2i = a[j1 + 3] + a[j3 + 3];
+ y3r = a[j1 + 2] - a[j3 + 2];
+ y3i = a[j1 + 3] - a[j3 + 3];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i - x2i;
+ a[j + 2] = y0r + y2r;
+ a[j + 3] = y0i - y2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i + x2i;
+ a[j1 + 2] = y0r - y2r;
+ a[j1 + 3] = y0i + y2i;
+ x0r = x1r + x3i;
+ x0i = x1i + x3r;
+ a[j2] = wk1r * x0r - wk1i * x0i;
+ a[j2 + 1] = wk1r * x0i + wk1i * x0r;
+ x0r = y1r + y3i;
+ x0i = y1i + y3r;
+ a[j2 + 2] = wd1r * x0r - wd1i * x0i;
+ a[j2 + 3] = wd1r * x0i + wd1i * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3r * x0r + wk3i * x0i;
+ a[j3 + 1] = wk3r * x0i - wk3i * x0r;
+ x0r = y1r - y3i;
+ x0i = y1i - y3r;
+ a[j3 + 2] = wd3r * x0r + wd3i * x0i;
+ a[j3 + 3] = wd3r * x0i - wd3i * x0r;
+ j0 = m - j;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0] + a[j2];
+ x0i = -a[j0 + 1] - a[j2 + 1];
+ x1r = a[j0] - a[j2];
+ x1i = -a[j0 + 1] + a[j2 + 1];
+ y0r = a[j0 - 2] + a[j2 - 2];
+ y0i = -a[j0 - 1] - a[j2 - 1];
+ y1r = a[j0 - 2] - a[j2 - 2];
+ y1i = -a[j0 - 1] + a[j2 - 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ y2r = a[j1 - 2] + a[j3 - 2];
+ y2i = a[j1 - 1] + a[j3 - 1];
+ y3r = a[j1 - 2] - a[j3 - 2];
+ y3i = a[j1 - 1] - a[j3 - 1];
+ a[j0] = x0r + x2r;
+ a[j0 + 1] = x0i - x2i;
+ a[j0 - 2] = y0r + y2r;
+ a[j0 - 1] = y0i - y2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i + x2i;
+ a[j1 - 2] = y0r - y2r;
+ a[j1 - 1] = y0i + y2i;
+ x0r = x1r + x3i;
+ x0i = x1i + x3r;
+ a[j2] = wk1i * x0r - wk1r * x0i;
+ a[j2 + 1] = wk1i * x0i + wk1r * x0r;
+ x0r = y1r + y3i;
+ x0i = y1i + y3r;
+ a[j2 - 2] = wd1i * x0r - wd1r * x0i;
+ a[j2 - 1] = wd1i * x0i + wd1r * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3i * x0r + wk3r * x0i;
+ a[j3 + 1] = wk3i * x0i - wk3r * x0r;
+ x0r = y1r - y3i;
+ x0i = y1i - y3r;
+ a[j3 - 2] = wd3i * x0r + wd3r * x0i;
+ a[j3 - 1] = wd3i * x0i - wd3r * x0r;
+ }
+ wk1r = csc1 * (wd1r + wn4r);
+ wk1i = csc1 * (wd1i + wn4r);
+ wk3r = csc3 * (wd3r - wn4r);
+ wk3i = csc3 * (wd3i - wn4r);
+ j0 = mh;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0 - 2] + a[j2 - 2];
+ x0i = -a[j0 - 1] - a[j2 - 1];
+ x1r = a[j0 - 2] - a[j2 - 2];
+ x1i = -a[j0 - 1] + a[j2 - 1];
+ x2r = a[j1 - 2] + a[j3 - 2];
+ x2i = a[j1 - 1] + a[j3 - 1];
+ x3r = a[j1 - 2] - a[j3 - 2];
+ x3i = a[j1 - 1] - a[j3 - 1];
+ a[j0 - 2] = x0r + x2r;
+ a[j0 - 1] = x0i - x2i;
+ a[j1 - 2] = x0r - x2r;
+ a[j1 - 1] = x0i + x2i;
+ x0r = x1r + x3i;
+ x0i = x1i + x3r;
+ a[j2 - 2] = wk1r * x0r - wk1i * x0i;
+ a[j2 - 1] = wk1r * x0i + wk1i * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i - x3r;
+ a[j3 - 2] = wk3r * x0r + wk3i * x0i;
+ a[j3 - 1] = wk3r * x0i - wk3i * x0r;
+ x0r = a[j0] + a[j2];
+ x0i = -a[j0 + 1] - a[j2 + 1];
+ x1r = a[j0] - a[j2];
+ x1i = -a[j0 + 1] + a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[j0] = x0r + x2r;
+ a[j0 + 1] = x0i - x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i + x2i;
+ x0r = x1r + x3i;
+ x0i = x1i + x3r;
+ a[j2] = wn4r * (x0r - x0i);
+ a[j2 + 1] = wn4r * (x0i + x0r);
+ x0r = x1r - x3i;
+ x0i = x1i - x3r;
+ a[j3] = -wn4r * (x0r + x0i);
+ a[j3 + 1] = -wn4r * (x0i - x0r);
+ x0r = a[j0 + 2] + a[j2 + 2];
+ x0i = -a[j0 + 3] - a[j2 + 3];
+ x1r = a[j0 + 2] - a[j2 + 2];
+ x1i = -a[j0 + 3] + a[j2 + 3];
+ x2r = a[j1 + 2] + a[j3 + 2];
+ x2i = a[j1 + 3] + a[j3 + 3];
+ x3r = a[j1 + 2] - a[j3 + 2];
+ x3i = a[j1 + 3] - a[j3 + 3];
+ a[j0 + 2] = x0r + x2r;
+ a[j0 + 3] = x0i - x2i;
+ a[j1 + 2] = x0r - x2r;
+ a[j1 + 3] = x0i + x2i;
+ x0r = x1r + x3i;
+ x0i = x1i + x3r;
+ a[j2 + 2] = wk1i * x0r - wk1r * x0i;
+ a[j2 + 3] = wk1i * x0i + wk1r * x0r;
+ x0r = x1r - x3i;
+ x0i = x1i - x3r;
+ a[j3 + 2] = wk3i * x0r + wk3r * x0i;
+ a[j3 + 3] = wk3i * x0i - wk3r * x0r;
+}
+
+
+#ifdef USE_CDFT_THREADS
+struct cdft_arg_st {
+ int n0;
+ int n;
+ double *a;
+ int nw;
+ double *w;
+};
+typedef struct cdft_arg_st cdft_arg_t;
+
+
+void cftrec4_th(int n, double *a, int nw, double *w)
+{
+ void *cftrec1_th(void *p);
+ void *cftrec2_th(void *p);
+ int i, idiv4, m, nthread;
+ cdft_thread_t th[4];
+ cdft_arg_t ag[4];
+
+ nthread = 2;
+ idiv4 = 0;
+ m = n >> 1;
+ if (n > CDFT_4THREADS_BEGIN_N) {
+ nthread = 4;
+ idiv4 = 1;
+ m >>= 1;
+ }
+ for (i = 0; i < nthread; i++) {
+ ag[i].n0 = n;
+ ag[i].n = m;
+ ag[i].a = &a[i * m];
+ ag[i].nw = nw;
+ ag[i].w = w;
+ if (i != idiv4) {
+ cdft_thread_create(&th[i], cftrec1_th, &ag[i]);
+ } else {
+ cdft_thread_create(&th[i], cftrec2_th, &ag[i]);
+ }
+ }
+ for (i = 0; i < nthread; i++) {
+ cdft_thread_wait(th[i]);
+ }
+}
+
+
+void *cftrec1_th(void *p)
+{
+ int cfttree(int n, int j, int k, double *a, int nw, double *w);
+ void cftleaf(int n, int isplt, double *a, int nw, double *w);
+ void cftmdl1(int n, double *a, double *w);
+ int isplt, j, k, m, n, n0, nw;
+ double *a, *w;
+
+ n0 = ((cdft_arg_t *) p)->n0;
+ n = ((cdft_arg_t *) p)->n;
+ a = ((cdft_arg_t *) p)->a;
+ nw = ((cdft_arg_t *) p)->nw;
+ w = ((cdft_arg_t *) p)->w;
+ m = n0;
+ while (m > 512) {
+ m >>= 2;
+ cftmdl1(m, &a[n - m], &w[nw - (m >> 1)]);
+ }
+ cftleaf(m, 1, &a[n - m], nw, w);
+ k = 0;
+ for (j = n - m; j > 0; j -= m) {
+ k++;
+ isplt = cfttree(m, j, k, a, nw, w);
+ cftleaf(m, isplt, &a[j - m], nw, w);
+ }
+ return (void *) 0;
+}
+
+
+void *cftrec2_th(void *p)
+{
+ int cfttree(int n, int j, int k, double *a, int nw, double *w);
+ void cftleaf(int n, int isplt, double *a, int nw, double *w);
+ void cftmdl2(int n, double *a, double *w);
+ int isplt, j, k, m, n, n0, nw;
+ double *a, *w;
+
+ n0 = ((cdft_arg_t *) p)->n0;
+ n = ((cdft_arg_t *) p)->n;
+ a = ((cdft_arg_t *) p)->a;
+ nw = ((cdft_arg_t *) p)->nw;
+ w = ((cdft_arg_t *) p)->w;
+ k = 1;
+ m = n0;
+ while (m > 512) {
+ m >>= 2;
+ k <<= 2;
+ cftmdl2(m, &a[n - m], &w[nw - m]);
+ }
+ cftleaf(m, 0, &a[n - m], nw, w);
+ k >>= 1;
+ for (j = n - m; j > 0; j -= m) {
+ k++;
+ isplt = cfttree(m, j, k, a, nw, w);
+ cftleaf(m, isplt, &a[j - m], nw, w);
+ }
+ return (void *) 0;
+}
+#endif /* USE_CDFT_THREADS */
+
+
+void cftrec4(int n, double *a, int nw, double *w)
+{
+ int cfttree(int n, int j, int k, double *a, int nw, double *w);
+ void cftleaf(int n, int isplt, double *a, int nw, double *w);
+ void cftmdl1(int n, double *a, double *w);
+ int isplt, j, k, m;
+
+ m = n;
+ while (m > 512) {
+ m >>= 2;
+ cftmdl1(m, &a[n - m], &w[nw - (m >> 1)]);
+ }
+ cftleaf(m, 1, &a[n - m], nw, w);
+ k = 0;
+ for (j = n - m; j > 0; j -= m) {
+ k++;
+ isplt = cfttree(m, j, k, a, nw, w);
+ cftleaf(m, isplt, &a[j - m], nw, w);
+ }
+}
+
+
+int cfttree(int n, int j, int k, double *a, int nw, double *w)
+{
+ void cftmdl1(int n, double *a, double *w);
+ void cftmdl2(int n, double *a, double *w);
+ int i, isplt, m;
+
+ if ((k & 3) != 0) {
+ isplt = k & 1;
+ if (isplt != 0) {
+ cftmdl1(n, &a[j - n], &w[nw - (n >> 1)]);
+ } else {
+ cftmdl2(n, &a[j - n], &w[nw - n]);
+ }
+ } else {
+ m = n;
+ for (i = k; (i & 3) == 0; i >>= 2) {
+ m <<= 2;
+ }
+ isplt = i & 1;
+ if (isplt != 0) {
+ while (m > 128) {
+ cftmdl1(m, &a[j - m], &w[nw - (m >> 1)]);
+ m >>= 2;
+ }
+ } else {
+ while (m > 128) {
+ cftmdl2(m, &a[j - m], &w[nw - m]);
+ m >>= 2;
+ }
+ }
+ }
+ return isplt;
+}
+
+
+void cftleaf(int n, int isplt, double *a, int nw, double *w)
+{
+ void cftmdl1(int n, double *a, double *w);
+ void cftmdl2(int n, double *a, double *w);
+ void cftf161(double *a, double *w);
+ void cftf162(double *a, double *w);
+ void cftf081(double *a, double *w);
+ void cftf082(double *a, double *w);
+
+ if (n == 512) {
+ cftmdl1(128, a, &w[nw - 64]);
+ cftf161(a, &w[nw - 8]);
+ cftf162(&a[32], &w[nw - 32]);
+ cftf161(&a[64], &w[nw - 8]);
+ cftf161(&a[96], &w[nw - 8]);
+ cftmdl2(128, &a[128], &w[nw - 128]);
+ cftf161(&a[128], &w[nw - 8]);
+ cftf162(&a[160], &w[nw - 32]);
+ cftf161(&a[192], &w[nw - 8]);
+ cftf162(&a[224], &w[nw - 32]);
+ cftmdl1(128, &a[256], &w[nw - 64]);
+ cftf161(&a[256], &w[nw - 8]);
+ cftf162(&a[288], &w[nw - 32]);
+ cftf161(&a[320], &w[nw - 8]);
+ cftf161(&a[352], &w[nw - 8]);
+ if (isplt != 0) {
+ cftmdl1(128, &a[384], &w[nw - 64]);
+ cftf161(&a[480], &w[nw - 8]);
+ } else {
+ cftmdl2(128, &a[384], &w[nw - 128]);
+ cftf162(&a[480], &w[nw - 32]);
+ }
+ cftf161(&a[384], &w[nw - 8]);
+ cftf162(&a[416], &w[nw - 32]);
+ cftf161(&a[448], &w[nw - 8]);
+ } else {
+ cftmdl1(64, a, &w[nw - 32]);
+ cftf081(a, &w[nw - 8]);
+ cftf082(&a[16], &w[nw - 8]);
+ cftf081(&a[32], &w[nw - 8]);
+ cftf081(&a[48], &w[nw - 8]);
+ cftmdl2(64, &a[64], &w[nw - 64]);
+ cftf081(&a[64], &w[nw - 8]);
+ cftf082(&a[80], &w[nw - 8]);
+ cftf081(&a[96], &w[nw - 8]);
+ cftf082(&a[112], &w[nw - 8]);
+ cftmdl1(64, &a[128], &w[nw - 32]);
+ cftf081(&a[128], &w[nw - 8]);
+ cftf082(&a[144], &w[nw - 8]);
+ cftf081(&a[160], &w[nw - 8]);
+ cftf081(&a[176], &w[nw - 8]);
+ if (isplt != 0) {
+ cftmdl1(64, &a[192], &w[nw - 32]);
+ cftf081(&a[240], &w[nw - 8]);
+ } else {
+ cftmdl2(64, &a[192], &w[nw - 64]);
+ cftf082(&a[240], &w[nw - 8]);
+ }
+ cftf081(&a[192], &w[nw - 8]);
+ cftf082(&a[208], &w[nw - 8]);
+ cftf081(&a[224], &w[nw - 8]);
+ }
+}
+
+
+void cftmdl1(int n, double *a, double *w)
+{
+ int j, j0, j1, j2, j3, k, m, mh;
+ double wn4r, wk1r, wk1i, wk3r, wk3i;
+ double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+
+ mh = n >> 3;
+ m = 2 * mh;
+ j1 = m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[0] + a[j2];
+ x0i = a[1] + a[j2 + 1];
+ x1r = a[0] - a[j2];
+ x1i = a[1] - a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[0] = x0r + x2r;
+ a[1] = x0i + x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ a[j2] = x1r - x3i;
+ a[j2 + 1] = x1i + x3r;
+ a[j3] = x1r + x3i;
+ a[j3 + 1] = x1i - x3r;
+ wn4r = w[1];
+ k = 0;
+ for (j = 2; j < mh; j += 2) {
+ k += 4;
+ wk1r = w[k];
+ wk1i = w[k + 1];
+ wk3r = w[k + 2];
+ wk3i = w[k + 3];
+ j1 = j + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j] + a[j2];
+ x0i = a[j + 1] + a[j2 + 1];
+ x1r = a[j] - a[j2];
+ x1i = a[j + 1] - a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[j] = x0r + x2r;
+ a[j + 1] = x0i + x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2] = wk1r * x0r - wk1i * x0i;
+ a[j2 + 1] = wk1r * x0i + wk1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3r * x0r + wk3i * x0i;
+ a[j3 + 1] = wk3r * x0i - wk3i * x0r;
+ j0 = m - j;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0] + a[j2];
+ x0i = a[j0 + 1] + a[j2 + 1];
+ x1r = a[j0] - a[j2];
+ x1i = a[j0 + 1] - a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[j0] = x0r + x2r;
+ a[j0 + 1] = x0i + x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2] = wk1i * x0r - wk1r * x0i;
+ a[j2 + 1] = wk1i * x0i + wk1r * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = wk3i * x0r + wk3r * x0i;
+ a[j3 + 1] = wk3i * x0i - wk3r * x0r;
+ }
+ j0 = mh;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0] + a[j2];
+ x0i = a[j0 + 1] + a[j2 + 1];
+ x1r = a[j0] - a[j2];
+ x1i = a[j0 + 1] - a[j2 + 1];
+ x2r = a[j1] + a[j3];
+ x2i = a[j1 + 1] + a[j3 + 1];
+ x3r = a[j1] - a[j3];
+ x3i = a[j1 + 1] - a[j3 + 1];
+ a[j0] = x0r + x2r;
+ a[j0 + 1] = x0i + x2i;
+ a[j1] = x0r - x2r;
+ a[j1 + 1] = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ a[j2] = wn4r * (x0r - x0i);
+ a[j2 + 1] = wn4r * (x0i + x0r);
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ a[j3] = -wn4r * (x0r + x0i);
+ a[j3 + 1] = -wn4r * (x0i - x0r);
+}
+
+
+void cftmdl2(int n, double *a, double *w)
+{
+ int j, j0, j1, j2, j3, k, kr, m, mh;
+ double wn4r, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i;
+ double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y2r, y2i;
+
+ mh = n >> 3;
+ m = 2 * mh;
+ wn4r = w[1];
+ j1 = m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[0] - a[j2 + 1];
+ x0i = a[1] + a[j2];
+ x1r = a[0] + a[j2 + 1];
+ x1i = a[1] - a[j2];
+ x2r = a[j1] - a[j3 + 1];
+ x2i = a[j1 + 1] + a[j3];
+ x3r = a[j1] + a[j3 + 1];
+ x3i = a[j1 + 1] - a[j3];
+ y0r = wn4r * (x2r - x2i);
+ y0i = wn4r * (x2i + x2r);
+ a[0] = x0r + y0r;
+ a[1] = x0i + y0i;
+ a[j1] = x0r - y0r;
+ a[j1 + 1] = x0i - y0i;
+ y0r = wn4r * (x3r - x3i);
+ y0i = wn4r * (x3i + x3r);
+ a[j2] = x1r - y0i;
+ a[j2 + 1] = x1i + y0r;
+ a[j3] = x1r + y0i;
+ a[j3 + 1] = x1i - y0r;
+ k = 0;
+ kr = 2 * m;
+ for (j = 2; j < mh; j += 2) {
+ k += 4;
+ wk1r = w[k];
+ wk1i = w[k + 1];
+ wk3r = w[k + 2];
+ wk3i = w[k + 3];
+ kr -= 4;
+ wd1i = w[kr];
+ wd1r = w[kr + 1];
+ wd3i = w[kr + 2];
+ wd3r = w[kr + 3];
+ j1 = j + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j] - a[j2 + 1];
+ x0i = a[j + 1] + a[j2];
+ x1r = a[j] + a[j2 + 1];
+ x1i = a[j + 1] - a[j2];
+ x2r = a[j1] - a[j3 + 1];
+ x2i = a[j1 + 1] + a[j3];
+ x3r = a[j1] + a[j3 + 1];
+ x3i = a[j1 + 1] - a[j3];
+ y0r = wk1r * x0r - wk1i * x0i;
+ y0i = wk1r * x0i + wk1i * x0r;
+ y2r = wd1r * x2r - wd1i * x2i;
+ y2i = wd1r * x2i + wd1i * x2r;
+ a[j] = y0r + y2r;
+ a[j + 1] = y0i + y2i;
+ a[j1] = y0r - y2r;
+ a[j1 + 1] = y0i - y2i;
+ y0r = wk3r * x1r + wk3i * x1i;
+ y0i = wk3r * x1i - wk3i * x1r;
+ y2r = wd3r * x3r + wd3i * x3i;
+ y2i = wd3r * x3i - wd3i * x3r;
+ a[j2] = y0r + y2r;
+ a[j2 + 1] = y0i + y2i;
+ a[j3] = y0r - y2r;
+ a[j3 + 1] = y0i - y2i;
+ j0 = m - j;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0] - a[j2 + 1];
+ x0i = a[j0 + 1] + a[j2];
+ x1r = a[j0] + a[j2 + 1];
+ x1i = a[j0 + 1] - a[j2];
+ x2r = a[j1] - a[j3 + 1];
+ x2i = a[j1 + 1] + a[j3];
+ x3r = a[j1] + a[j3 + 1];
+ x3i = a[j1 + 1] - a[j3];
+ y0r = wd1i * x0r - wd1r * x0i;
+ y0i = wd1i * x0i + wd1r * x0r;
+ y2r = wk1i * x2r - wk1r * x2i;
+ y2i = wk1i * x2i + wk1r * x2r;
+ a[j0] = y0r + y2r;
+ a[j0 + 1] = y0i + y2i;
+ a[j1] = y0r - y2r;
+ a[j1 + 1] = y0i - y2i;
+ y0r = wd3i * x1r + wd3r * x1i;
+ y0i = wd3i * x1i - wd3r * x1r;
+ y2r = wk3i * x3r + wk3r * x3i;
+ y2i = wk3i * x3i - wk3r * x3r;
+ a[j2] = y0r + y2r;
+ a[j2 + 1] = y0i + y2i;
+ a[j3] = y0r - y2r;
+ a[j3 + 1] = y0i - y2i;
+ }
+ wk1r = w[m];
+ wk1i = w[m + 1];
+ j0 = mh;
+ j1 = j0 + m;
+ j2 = j1 + m;
+ j3 = j2 + m;
+ x0r = a[j0] - a[j2 + 1];
+ x0i = a[j0 + 1] + a[j2];
+ x1r = a[j0] + a[j2 + 1];
+ x1i = a[j0 + 1] - a[j2];
+ x2r = a[j1] - a[j3 + 1];
+ x2i = a[j1 + 1] + a[j3];
+ x3r = a[j1] + a[j3 + 1];
+ x3i = a[j1 + 1] - a[j3];
+ y0r = wk1r * x0r - wk1i * x0i;
+ y0i = wk1r * x0i + wk1i * x0r;
+ y2r = wk1i * x2r - wk1r * x2i;
+ y2i = wk1i * x2i + wk1r * x2r;
+ a[j0] = y0r + y2r;
+ a[j0 + 1] = y0i + y2i;
+ a[j1] = y0r - y2r;
+ a[j1 + 1] = y0i - y2i;
+ y0r = wk1i * x1r - wk1r * x1i;
+ y0i = wk1i * x1i + wk1r * x1r;
+ y2r = wk1r * x3r - wk1i * x3i;
+ y2i = wk1r * x3i + wk1i * x3r;
+ a[j2] = y0r - y2r;
+ a[j2 + 1] = y0i - y2i;
+ a[j3] = y0r + y2r;
+ a[j3 + 1] = y0i + y2i;
+}
+
+
+void cftfx41(int n, double *a, int nw, double *w)
+{
+ void cftf161(double *a, double *w);
+ void cftf162(double *a, double *w);
+ void cftf081(double *a, double *w);
+ void cftf082(double *a, double *w);
+
+ if (n == 128) {
+ cftf161(a, &w[nw - 8]);
+ cftf162(&a[32], &w[nw - 32]);
+ cftf161(&a[64], &w[nw - 8]);
+ cftf161(&a[96], &w[nw - 8]);
+ } else {
+ cftf081(a, &w[nw - 8]);
+ cftf082(&a[16], &w[nw - 8]);
+ cftf081(&a[32], &w[nw - 8]);
+ cftf081(&a[48], &w[nw - 8]);
+ }
+}
+
+
+void cftf161(double *a, double *w)
+{
+ double wn4r, wk1r, wk1i,
+ x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
+ y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
+ y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
+ y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
+ y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
+
+ wn4r = w[1];
+ wk1r = w[2];
+ wk1i = w[3];
+ x0r = a[0] + a[16];
+ x0i = a[1] + a[17];
+ x1r = a[0] - a[16];
+ x1i = a[1] - a[17];
+ x2r = a[8] + a[24];
+ x2i = a[9] + a[25];
+ x3r = a[8] - a[24];
+ x3i = a[9] - a[25];
+ y0r = x0r + x2r;
+ y0i = x0i + x2i;
+ y4r = x0r - x2r;
+ y4i = x0i - x2i;
+ y8r = x1r - x3i;
+ y8i = x1i + x3r;
+ y12r = x1r + x3i;
+ y12i = x1i - x3r;
+ x0r = a[2] + a[18];
+ x0i = a[3] + a[19];
+ x1r = a[2] - a[18];
+ x1i = a[3] - a[19];
+ x2r = a[10] + a[26];
+ x2i = a[11] + a[27];
+ x3r = a[10] - a[26];
+ x3i = a[11] - a[27];
+ y1r = x0r + x2r;
+ y1i = x0i + x2i;
+ y5r = x0r - x2r;
+ y5i = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ y9r = wk1r * x0r - wk1i * x0i;
+ y9i = wk1r * x0i + wk1i * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ y13r = wk1i * x0r - wk1r * x0i;
+ y13i = wk1i * x0i + wk1r * x0r;
+ x0r = a[4] + a[20];
+ x0i = a[5] + a[21];
+ x1r = a[4] - a[20];
+ x1i = a[5] - a[21];
+ x2r = a[12] + a[28];
+ x2i = a[13] + a[29];
+ x3r = a[12] - a[28];
+ x3i = a[13] - a[29];
+ y2r = x0r + x2r;
+ y2i = x0i + x2i;
+ y6r = x0r - x2r;
+ y6i = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ y10r = wn4r * (x0r - x0i);
+ y10i = wn4r * (x0i + x0r);
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ y14r = wn4r * (x0r + x0i);
+ y14i = wn4r * (x0i - x0r);
+ x0r = a[6] + a[22];
+ x0i = a[7] + a[23];
+ x1r = a[6] - a[22];
+ x1i = a[7] - a[23];
+ x2r = a[14] + a[30];
+ x2i = a[15] + a[31];
+ x3r = a[14] - a[30];
+ x3i = a[15] - a[31];
+ y3r = x0r + x2r;
+ y3i = x0i + x2i;
+ y7r = x0r - x2r;
+ y7i = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ y11r = wk1i * x0r - wk1r * x0i;
+ y11i = wk1i * x0i + wk1r * x0r;
+ x0r = x1r + x3i;
+ x0i = x1i - x3r;
+ y15r = wk1r * x0r - wk1i * x0i;
+ y15i = wk1r * x0i + wk1i * x0r;
+ x0r = y12r - y14r;
+ x0i = y12i - y14i;
+ x1r = y12r + y14r;
+ x1i = y12i + y14i;
+ x2r = y13r - y15r;
+ x2i = y13i - y15i;
+ x3r = y13r + y15r;
+ x3i = y13i + y15i;
+ a[24] = x0r + x2r;
+ a[25] = x0i + x2i;
+ a[26] = x0r - x2r;
+ a[27] = x0i - x2i;
+ a[28] = x1r - x3i;
+ a[29] = x1i + x3r;
+ a[30] = x1r + x3i;
+ a[31] = x1i - x3r;
+ x0r = y8r + y10r;
+ x0i = y8i + y10i;
+ x1r = y8r - y10r;
+ x1i = y8i - y10i;
+ x2r = y9r + y11r;
+ x2i = y9i + y11i;
+ x3r = y9r - y11r;
+ x3i = y9i - y11i;
+ a[16] = x0r + x2r;
+ a[17] = x0i + x2i;
+ a[18] = x0r - x2r;
+ a[19] = x0i - x2i;
+ a[20] = x1r - x3i;
+ a[21] = x1i + x3r;
+ a[22] = x1r + x3i;
+ a[23] = x1i - x3r;
+ x0r = y5r - y7i;
+ x0i = y5i + y7r;
+ x2r = wn4r * (x0r - x0i);
+ x2i = wn4r * (x0i + x0r);
+ x0r = y5r + y7i;
+ x0i = y5i - y7r;
+ x3r = wn4r * (x0r - x0i);
+ x3i = wn4r * (x0i + x0r);
+ x0r = y4r - y6i;
+ x0i = y4i + y6r;
+ x1r = y4r + y6i;
+ x1i = y4i - y6r;
+ a[8] = x0r + x2r;
+ a[9] = x0i + x2i;
+ a[10] = x0r - x2r;
+ a[11] = x0i - x2i;
+ a[12] = x1r - x3i;
+ a[13] = x1i + x3r;
+ a[14] = x1r + x3i;
+ a[15] = x1i - x3r;
+ x0r = y0r + y2r;
+ x0i = y0i + y2i;
+ x1r = y0r - y2r;
+ x1i = y0i - y2i;
+ x2r = y1r + y3r;
+ x2i = y1i + y3i;
+ x3r = y1r - y3r;
+ x3i = y1i - y3i;
+ a[0] = x0r + x2r;
+ a[1] = x0i + x2i;
+ a[2] = x0r - x2r;
+ a[3] = x0i - x2i;
+ a[4] = x1r - x3i;
+ a[5] = x1i + x3r;
+ a[6] = x1r + x3i;
+ a[7] = x1i - x3r;
+}
+
+
+void cftf162(double *a, double *w)
+{
+ double wn4r, wk1r, wk1i, wk2r, wk2i, wk3r, wk3i,
+ x0r, x0i, x1r, x1i, x2r, x2i,
+ y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
+ y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
+ y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
+ y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
+
+ wn4r = w[1];
+ wk1r = w[4];
+ wk1i = w[5];
+ wk3r = w[6];
+ wk3i = -w[7];
+ wk2r = w[8];
+ wk2i = w[9];
+ x1r = a[0] - a[17];
+ x1i = a[1] + a[16];
+ x0r = a[8] - a[25];
+ x0i = a[9] + a[24];
+ x2r = wn4r * (x0r - x0i);
+ x2i = wn4r * (x0i + x0r);
+ y0r = x1r + x2r;
+ y0i = x1i + x2i;
+ y4r = x1r - x2r;
+ y4i = x1i - x2i;
+ x1r = a[0] + a[17];
+ x1i = a[1] - a[16];
+ x0r = a[8] + a[25];
+ x0i = a[9] - a[24];
+ x2r = wn4r * (x0r - x0i);
+ x2i = wn4r * (x0i + x0r);
+ y8r = x1r - x2i;
+ y8i = x1i + x2r;
+ y12r = x1r + x2i;
+ y12i = x1i - x2r;
+ x0r = a[2] - a[19];
+ x0i = a[3] + a[18];
+ x1r = wk1r * x0r - wk1i * x0i;
+ x1i = wk1r * x0i + wk1i * x0r;
+ x0r = a[10] - a[27];
+ x0i = a[11] + a[26];
+ x2r = wk3i * x0r - wk3r * x0i;
+ x2i = wk3i * x0i + wk3r * x0r;
+ y1r = x1r + x2r;
+ y1i = x1i + x2i;
+ y5r = x1r - x2r;
+ y5i = x1i - x2i;
+ x0r = a[2] + a[19];
+ x0i = a[3] - a[18];
+ x1r = wk3r * x0r - wk3i * x0i;
+ x1i = wk3r * x0i + wk3i * x0r;
+ x0r = a[10] + a[27];
+ x0i = a[11] - a[26];
+ x2r = wk1r * x0r + wk1i * x0i;
+ x2i = wk1r * x0i - wk1i * x0r;
+ y9r = x1r - x2r;
+ y9i = x1i - x2i;
+ y13r = x1r + x2r;
+ y13i = x1i + x2i;
+ x0r = a[4] - a[21];
+ x0i = a[5] + a[20];
+ x1r = wk2r * x0r - wk2i * x0i;
+ x1i = wk2r * x0i + wk2i * x0r;
+ x0r = a[12] - a[29];
+ x0i = a[13] + a[28];
+ x2r = wk2i * x0r - wk2r * x0i;
+ x2i = wk2i * x0i + wk2r * x0r;
+ y2r = x1r + x2r;
+ y2i = x1i + x2i;
+ y6r = x1r - x2r;
+ y6i = x1i - x2i;
+ x0r = a[4] + a[21];
+ x0i = a[5] - a[20];
+ x1r = wk2i * x0r - wk2r * x0i;
+ x1i = wk2i * x0i + wk2r * x0r;
+ x0r = a[12] + a[29];
+ x0i = a[13] - a[28];
+ x2r = wk2r * x0r - wk2i * x0i;
+ x2i = wk2r * x0i + wk2i * x0r;
+ y10r = x1r - x2r;
+ y10i = x1i - x2i;
+ y14r = x1r + x2r;
+ y14i = x1i + x2i;
+ x0r = a[6] - a[23];
+ x0i = a[7] + a[22];
+ x1r = wk3r * x0r - wk3i * x0i;
+ x1i = wk3r * x0i + wk3i * x0r;
+ x0r = a[14] - a[31];
+ x0i = a[15] + a[30];
+ x2r = wk1i * x0r - wk1r * x0i;
+ x2i = wk1i * x0i + wk1r * x0r;
+ y3r = x1r + x2r;
+ y3i = x1i + x2i;
+ y7r = x1r - x2r;
+ y7i = x1i - x2i;
+ x0r = a[6] + a[23];
+ x0i = a[7] - a[22];
+ x1r = wk1i * x0r + wk1r * x0i;
+ x1i = wk1i * x0i - wk1r * x0r;
+ x0r = a[14] + a[31];
+ x0i = a[15] - a[30];
+ x2r = wk3i * x0r - wk3r * x0i;
+ x2i = wk3i * x0i + wk3r * x0r;
+ y11r = x1r + x2r;
+ y11i = x1i + x2i;
+ y15r = x1r - x2r;
+ y15i = x1i - x2i;
+ x1r = y0r + y2r;
+ x1i = y0i + y2i;
+ x2r = y1r + y3r;
+ x2i = y1i + y3i;
+ a[0] = x1r + x2r;
+ a[1] = x1i + x2i;
+ a[2] = x1r - x2r;
+ a[3] = x1i - x2i;
+ x1r = y0r - y2r;
+ x1i = y0i - y2i;
+ x2r = y1r - y3r;
+ x2i = y1i - y3i;
+ a[4] = x1r - x2i;
+ a[5] = x1i + x2r;
+ a[6] = x1r + x2i;
+ a[7] = x1i - x2r;
+ x1r = y4r - y6i;
+ x1i = y4i + y6r;
+ x0r = y5r - y7i;
+ x0i = y5i + y7r;
+ x2r = wn4r * (x0r - x0i);
+ x2i = wn4r * (x0i + x0r);
+ a[8] = x1r + x2r;
+ a[9] = x1i + x2i;
+ a[10] = x1r - x2r;
+ a[11] = x1i - x2i;
+ x1r = y4r + y6i;
+ x1i = y4i - y6r;
+ x0r = y5r + y7i;
+ x0i = y5i - y7r;
+ x2r = wn4r * (x0r - x0i);
+ x2i = wn4r * (x0i + x0r);
+ a[12] = x1r - x2i;
+ a[13] = x1i + x2r;
+ a[14] = x1r + x2i;
+ a[15] = x1i - x2r;
+ x1r = y8r + y10r;
+ x1i = y8i + y10i;
+ x2r = y9r - y11r;
+ x2i = y9i - y11i;
+ a[16] = x1r + x2r;
+ a[17] = x1i + x2i;
+ a[18] = x1r - x2r;
+ a[19] = x1i - x2i;
+ x1r = y8r - y10r;
+ x1i = y8i - y10i;
+ x2r = y9r + y11r;
+ x2i = y9i + y11i;
+ a[20] = x1r - x2i;
+ a[21] = x1i + x2r;
+ a[22] = x1r + x2i;
+ a[23] = x1i - x2r;
+ x1r = y12r - y14i;
+ x1i = y12i + y14r;
+ x0r = y13r + y15i;
+ x0i = y13i - y15r;
+ x2r = wn4r * (x0r - x0i);
+ x2i = wn4r * (x0i + x0r);
+ a[24] = x1r + x2r;
+ a[25] = x1i + x2i;
+ a[26] = x1r - x2r;
+ a[27] = x1i - x2i;
+ x1r = y12r + y14i;
+ x1i = y12i - y14r;
+ x0r = y13r - y15i;
+ x0i = y13i + y15r;
+ x2r = wn4r * (x0r - x0i);
+ x2i = wn4r * (x0i + x0r);
+ a[28] = x1r - x2i;
+ a[29] = x1i + x2r;
+ a[30] = x1r + x2i;
+ a[31] = x1i - x2r;
+}
+
+
+void cftf081(double *a, double *w)
+{
+ double wn4r, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
+ y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
+ y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
+
+ wn4r = w[1];
+ x0r = a[0] + a[8];
+ x0i = a[1] + a[9];
+ x1r = a[0] - a[8];
+ x1i = a[1] - a[9];
+ x2r = a[4] + a[12];
+ x2i = a[5] + a[13];
+ x3r = a[4] - a[12];
+ x3i = a[5] - a[13];
+ y0r = x0r + x2r;
+ y0i = x0i + x2i;
+ y2r = x0r - x2r;
+ y2i = x0i - x2i;
+ y1r = x1r - x3i;
+ y1i = x1i + x3r;
+ y3r = x1r + x3i;
+ y3i = x1i - x3r;
+ x0r = a[2] + a[10];
+ x0i = a[3] + a[11];
+ x1r = a[2] - a[10];
+ x1i = a[3] - a[11];
+ x2r = a[6] + a[14];
+ x2i = a[7] + a[15];
+ x3r = a[6] - a[14];
+ x3i = a[7] - a[15];
+ y4r = x0r + x2r;
+ y4i = x0i + x2i;
+ y6r = x0r - x2r;
+ y6i = x0i - x2i;
+ x0r = x1r - x3i;
+ x0i = x1i + x3r;
+ x2r = x1r + x3i;
+ x2i = x1i - x3r;
+ y5r = wn4r * (x0r - x0i);
+ y5i = wn4r * (x0r + x0i);
+ y7r = wn4r * (x2r - x2i);
+ y7i = wn4r * (x2r + x2i);
+ a[8] = y1r + y5r;
+ a[9] = y1i + y5i;
+ a[10] = y1r - y5r;
+ a[11] = y1i - y5i;
+ a[12] = y3r - y7i;
+ a[13] = y3i + y7r;
+ a[14] = y3r + y7i;
+ a[15] = y3i - y7r;
+ a[0] = y0r + y4r;
+ a[1] = y0i + y4i;
+ a[2] = y0r - y4r;
+ a[3] = y0i - y4i;
+ a[4] = y2r - y6i;
+ a[5] = y2i + y6r;
+ a[6] = y2r + y6i;
+ a[7] = y2i - y6r;
+}
+
+
+void cftf082(double *a, double *w)
+{
+ double wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i,
+ y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
+ y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
+
+ wn4r = w[1];
+ wk1r = w[2];
+ wk1i = w[3];
+ y0r = a[0] - a[9];
+ y0i = a[1] + a[8];
+ y1r = a[0] + a[9];
+ y1i = a[1] - a[8];
+ x0r = a[4] - a[13];
+ x0i = a[5] + a[12];
+ y2r = wn4r * (x0r - x0i);
+ y2i = wn4r * (x0i + x0r);
+ x0r = a[4] + a[13];
+ x0i = a[5] - a[12];
+ y3r = wn4r * (x0r - x0i);
+ y3i = wn4r * (x0i + x0r);
+ x0r = a[2] - a[11];
+ x0i = a[3] + a[10];
+ y4r = wk1r * x0r - wk1i * x0i;
+ y4i = wk1r * x0i + wk1i * x0r;
+ x0r = a[2] + a[11];
+ x0i = a[3] - a[10];
+ y5r = wk1i * x0r - wk1r * x0i;
+ y5i = wk1i * x0i + wk1r * x0r;
+ x0r = a[6] - a[15];
+ x0i = a[7] + a[14];
+ y6r = wk1i * x0r - wk1r * x0i;
+ y6i = wk1i * x0i + wk1r * x0r;
+ x0r = a[6] + a[15];
+ x0i = a[7] - a[14];
+ y7r = wk1r * x0r - wk1i * x0i;
+ y7i = wk1r * x0i + wk1i * x0r;
+ x0r = y0r + y2r;
+ x0i = y0i + y2i;
+ x1r = y4r + y6r;
+ x1i = y4i + y6i;
+ a[0] = x0r + x1r;
+ a[1] = x0i + x1i;
+ a[2] = x0r - x1r;
+ a[3] = x0i - x1i;
+ x0r = y0r - y2r;
+ x0i = y0i - y2i;
+ x1r = y4r - y6r;
+ x1i = y4i - y6i;
+ a[4] = x0r - x1i;
+ a[5] = x0i + x1r;
+ a[6] = x0r + x1i;
+ a[7] = x0i - x1r;
+ x0r = y1r - y3i;
+ x0i = y1i + y3r;
+ x1r = y5r - y7r;
+ x1i = y5i - y7i;
+ a[8] = x0r + x1r;
+ a[9] = x0i + x1i;
+ a[10] = x0r - x1r;
+ a[11] = x0i - x1i;
+ x0r = y1r + y3i;
+ x0i = y1i - y3r;
+ x1r = y5r + y7r;
+ x1i = y5i + y7i;
+ a[12] = x0r - x1i;
+ a[13] = x0i + x1r;
+ a[14] = x0r + x1i;
+ a[15] = x0i - x1r;
+}
+
+
+void cftf040(double *a)
+{
+ double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+
+ x0r = a[0] + a[4];
+ x0i = a[1] + a[5];
+ x1r = a[0] - a[4];
+ x1i = a[1] - a[5];
+ x2r = a[2] + a[6];
+ x2i = a[3] + a[7];
+ x3r = a[2] - a[6];
+ x3i = a[3] - a[7];
+ a[0] = x0r + x2r;
+ a[1] = x0i + x2i;
+ a[2] = x1r - x3i;
+ a[3] = x1i + x3r;
+ a[4] = x0r - x2r;
+ a[5] = x0i - x2i;
+ a[6] = x1r + x3i;
+ a[7] = x1i - x3r;
+}
+
+
+void cftb040(double *a)
+{
+ double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+
+ x0r = a[0] + a[4];
+ x0i = a[1] + a[5];
+ x1r = a[0] - a[4];
+ x1i = a[1] - a[5];
+ x2r = a[2] + a[6];
+ x2i = a[3] + a[7];
+ x3r = a[2] - a[6];
+ x3i = a[3] - a[7];
+ a[0] = x0r + x2r;
+ a[1] = x0i + x2i;
+ a[2] = x1r + x3i;
+ a[3] = x1i - x3r;
+ a[4] = x0r - x2r;
+ a[5] = x0i - x2i;
+ a[6] = x1r - x3i;
+ a[7] = x1i + x3r;
+}
+
+
+void cftx020(double *a)
+{
+ double x0r, x0i;
+
+ x0r = a[0] - a[2];
+ x0i = a[1] - a[3];
+ a[0] += a[2];
+ a[1] += a[3];
+ a[2] = x0r;
+ a[3] = x0i;
+}
+
+
+void rftfsub(int n, double *a, int nc, double *c)
+{
+ int j, k, kk, ks, m;
+ double wkr, wki, xr, xi, yr, yi;
+
+ m = n >> 1;
+ ks = 2 * nc / m;
+ kk = 0;
+ for (j = 2; j < m; j += 2) {
+ k = n - j;
+ kk += ks;
+ wkr = 0.5 - c[nc - kk];
+ wki = c[kk];
+ xr = a[j] - a[k];
+ xi = a[j + 1] + a[k + 1];
+ yr = wkr * xr - wki * xi;
+ yi = wkr * xi + wki * xr;
+ a[j] -= yr;
+ a[j + 1] -= yi;
+ a[k] += yr;
+ a[k + 1] -= yi;
+ }
+}
+
+
+void rftbsub(int n, double *a, int nc, double *c)
+{
+ int j, k, kk, ks, m;
+ double wkr, wki, xr, xi, yr, yi;
+
+ m = n >> 1;
+ ks = 2 * nc / m;
+ kk = 0;
+ for (j = 2; j < m; j += 2) {
+ k = n - j;
+ kk += ks;
+ wkr = 0.5 - c[nc - kk];
+ wki = c[kk];
+ xr = a[j] - a[k];
+ xi = a[j + 1] + a[k + 1];
+ yr = wkr * xr + wki * xi;
+ yi = wkr * xi - wki * xr;
+ a[j] -= yr;
+ a[j + 1] -= yi;
+ a[k] += yr;
+ a[k + 1] -= yi;
+ }
+}
+
+
+void dctsub(int n, double *a, int nc, double *c)
+{
+ int j, k, kk, ks, m;
+ double wkr, wki, xr;
+
+ m = n >> 1;
+ ks = nc / n;
+ kk = 0;
+ for (j = 1; j < m; j++) {
+ k = n - j;
+ kk += ks;
+ wkr = c[kk] - c[nc - kk];
+ wki = c[kk] + c[nc - kk];
+ xr = wki * a[j] - wkr * a[k];
+ a[j] = wkr * a[j] + wki * a[k];
+ a[k] = xr;
+ }
+ a[m] *= c[0];
+}
+
+
+void dstsub(int n, double *a, int nc, double *c)
+{
+ int j, k, kk, ks, m;
+ double wkr, wki, xr;
+
+ m = n >> 1;
+ ks = nc / n;
+ kk = 0;
+ for (j = 1; j < m; j++) {
+ k = n - j;
+ kk += ks;
+ wkr = c[kk] - c[nc - kk];
+ wki = c[kk] + c[nc - kk];
+ xr = wki * a[k] - wkr * a[j];
+ a[k] = wkr * a[k] + wki * a[j];
+ a[j] = xr;
+ }
+ a[m] *= c[0];
+}
diff --git a/src/libprojectM/fftsg.h b/src/libprojectM/fftsg.h
index ff9da6e..59b87b3 100644
--- a/src/libprojectM/fftsg.h
+++ b/src/libprojectM/fftsg.h
@@ -1,35 +1,36 @@
-/**
- * projectM -- Milkdrop-esque visualisation SDK
- * Copyright (C)2003-2007 projectM Team
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * See 'LICENSE.txt' included within this release
- *
- */
-/**
- * $Id: fftsg.h,v 1.1.1.1 2005/12/23 18:05:00 psperl Exp $
- *
- * Wrapper for rdft() and friends
- *
- * $Log$
- */
-
-#ifndef _FFTSG_H
-#define _FFTSG_H
-
-extern void rdft(int n, int isgn, double *a, int *ip, double *w);
-
-#endif /** !_FFTSG_H */
-
+/**
+ * projectM -- Milkdrop-esque visualisation SDK
+ * Copyright (C)2003-2007 projectM Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * See 'LICENSE.txt' included within this release
+ *
+ */
+/**
+ * $Id: fftsg.h,v 1.1.1.1 2005/12/23 18:05:00 psperl Exp $
+ *
+ * Wrapper for rdft() and friends
+ *
+ * $Log$
+ */
+
+#ifndef _FFTSG_H
+#define _FFTSG_H
+
+
+extern void rdft (int n, int isgn, double *a, int *ip, double *w);
+
+
+#endif /** !_FFTSG_H */
diff --git a/src/libprojectM/glError.h b/src/libprojectM/glError.h
index a6d0940..3127306 100644
--- a/src/libprojectM/glError.h
+++ b/src/libprojectM/glError.h
@@ -6,7 +6,7 @@
//
#ifndef _GLERROR_H
-#define _GLERROR_H
+#define _GLERROR_H
// no need to include GL in here,
// if someone wants GL errors they probably already included it.
@@ -20,12 +20,11 @@
#define glError()
#else
#define glError() { \
- GLenum err; \
- while ((err = glGetError()) != GL_NO_ERROR) \
- fprintf(stderr, "glError: %s at %s:%u\n", \
- (char *)gluErrorString(err), __FILE__, __LINE__); \
+ GLenum err; \
+ while ((err = glGetError()) != GL_NO_ERROR) \
+ fprintf(stderr, "glError: %s at %s:%u\n", \
+ (char *)gluErrorString(err), __FILE__, __LINE__); \
}
-#endif /* glError */
+#endif /* glError */
-#endif /* _GLERROR_H */
-
+#endif /* _GLERROR_H */
diff --git a/src/libprojectM/lvtoprojectM.h b/src/libprojectM/lvtoprojectM.h
index 4215b8a..f4c1cc6 100644
--- a/src/libprojectM/lvtoprojectM.h
+++ b/src/libprojectM/lvtoprojectM.h
@@ -31,126 +31,130 @@
* Imported
*
*/
-
#include <libvisual/libvisual.h>
-projectMEvent lv2pmEvent( VisEventType event ) {
-
- switch ( event ) {
- case VISUAL_EVENT_RESIZE:
- return PROJECTM_VIDEORESIZE;
- case VISUAL_EVENT_KEYUP:
- return PROJECTM_KEYUP;
- case VISUAL_EVENT_KEYDOWN:
- return PROJECTM_KEYDOWN;
- default:
- return PROJECTM_KEYUP;
- }
- }
-projectMKeycode lv2pmKeycode( VisKey keysym )
-{
- switch ( keysym )
- {
- case VKEY_F1:
- return PROJECTM_K_F1;
- case VKEY_F2:
- return PROJECTM_K_F2;
- case VKEY_F3:
- return PROJECTM_K_F3;
- case VKEY_F4:
- return PROJECTM_K_F4;
- case VKEY_F5:
- return PROJECTM_K_F5;
- case VKEY_F6:
- return PROJECTM_K_F6;
- case VKEY_F7:
- return PROJECTM_K_F7;
- case VKEY_F8:
- return PROJECTM_K_F8;
- case VKEY_F9:
- return PROJECTM_K_F9;
- case VKEY_F10:
- return PROJECTM_K_F10;
- case VKEY_F11:
- return PROJECTM_K_F11;
- case VKEY_F12:
- return PROJECTM_K_F12;
- case VKEY_ESCAPE:
- return PROJECTM_K_ESCAPE;
- case VKEY_a:
- return PROJECTM_K_a;
- case VKEY_b:
- return PROJECTM_K_b;
- case VKEY_c:
- return PROJECTM_K_c;
- case VKEY_d:
- return PROJECTM_K_d;
- case VKEY_e:
- return PROJECTM_K_e;
- case VKEY_f:
- return PROJECTM_K_f;
- case VKEY_g:
- return PROJECTM_K_g;
- case VKEY_h:
- return PROJECTM_K_h;
- case VKEY_i:
- return PROJECTM_K_i;
- case VKEY_j:
- return PROJECTM_K_j;
- case VKEY_k:
- return PROJECTM_K_k;
- case VKEY_l:
- return PROJECTM_K_l;
- case VKEY_m:
- return PROJECTM_K_m;
- case VKEY_n:
- return PROJECTM_K_n;
- case VKEY_o:
- return PROJECTM_K_o;
- case VKEY_p:
- return PROJECTM_K_p;
- case VKEY_q:
- return PROJECTM_K_q;
- case VKEY_r:
- return PROJECTM_K_r;
- case VKEY_s:
- return PROJECTM_K_s;
- case VKEY_t:
- return PROJECTM_K_t;
- case VKEY_u:
- return PROJECTM_K_u;
- case VKEY_v:
- return PROJECTM_K_v;
- case VKEY_w:
- return PROJECTM_K_w;
- case VKEY_x:
- return PROJECTM_K_x;
- case VKEY_y:
- return PROJECTM_K_y;
- case VKEY_z:
- return PROJECTM_K_z;
- case VKEY_UP:
- return PROJECTM_K_UP;
- case VKEY_RETURN:
- return PROJECTM_K_RETURN;
- case VKEY_RIGHT:
- return PROJECTM_K_RIGHT;
- case VKEY_LEFT:
- return PROJECTM_K_LEFT;
- case VKEY_DOWN:
- return PROJECTM_K_DOWN;
- case VKEY_PAGEUP:
- return PROJECTM_K_PAGEUP;
- case VKEY_PAGEDOWN:
- return PROJECTM_K_PAGEDOWN;
-
- default:
- return PROJECTM_K_NONE;
- break;
- }
- }
-
-projectMModifier lv2pmModifier( int mod ) {
- return mod && VKMOD_LSHIFT;
+projectMEvent
+lv2pmEvent (VisEventType event)
+{
+ switch (event) {
+ case VISUAL_EVENT_RESIZE:
+ return PROJECTM_VIDEORESIZE;
+ case VISUAL_EVENT_KEYUP:
+ return PROJECTM_KEYUP;
+ case VISUAL_EVENT_KEYDOWN:
+ return PROJECTM_KEYDOWN;
+ default:
+ return PROJECTM_KEYUP;
}
+}
+
+projectMKeycode
+lv2pmKeycode (VisKey keysym)
+{
+ switch (keysym) {
+ case VKEY_F1:
+ return PROJECTM_K_F1;
+ case VKEY_F2:
+ return PROJECTM_K_F2;
+ case VKEY_F3:
+ return PROJECTM_K_F3;
+ case VKEY_F4:
+ return PROJECTM_K_F4;
+ case VKEY_F5:
+ return PROJECTM_K_F5;
+ case VKEY_F6:
+ return PROJECTM_K_F6;
+ case VKEY_F7:
+ return PROJECTM_K_F7;
+ case VKEY_F8:
+ return PROJECTM_K_F8;
+ case VKEY_F9:
+ return PROJECTM_K_F9;
+ case VKEY_F10:
+ return PROJECTM_K_F10;
+ case VKEY_F11:
+ return PROJECTM_K_F11;
+ case VKEY_F12:
+ return PROJECTM_K_F12;
+ case VKEY_ESCAPE:
+ return PROJECTM_K_ESCAPE;
+ case VKEY_a:
+ return PROJECTM_K_a;
+ case VKEY_b:
+ return PROJECTM_K_b;
+ case VKEY_c:
+ return PROJECTM_K_c;
+ case VKEY_d:
+ return PROJECTM_K_d;
+ case VKEY_e:
+ return PROJECTM_K_e;
+ case VKEY_f:
+ return PROJECTM_K_f;
+ case VKEY_g:
+ return PROJECTM_K_g;
+ case VKEY_h:
+ return PROJECTM_K_h;
+ case VKEY_i:
+ return PROJECTM_K_i;
+ case VKEY_j:
+ return PROJECTM_K_j;
+ case VKEY_k:
+ return PROJECTM_K_k;
+ case VKEY_l:
+ return PROJECTM_K_l;
+ case VKEY_m:
+ return PROJECTM_K_m;
+ case VKEY_n:
+ return PROJECTM_K_n;
+ case VKEY_o:
+ return PROJECTM_K_o;
+ case VKEY_p:
+ return PROJECTM_K_p;
+ case VKEY_q:
+ return PROJECTM_K_q;
+ case VKEY_r:
+ return PROJECTM_K_r;
+ case VKEY_s:
+ return PROJECTM_K_s;
+ case VKEY_t:
+ return PROJECTM_K_t;
+ case VKEY_u:
+ return PROJECTM_K_u;
+ case VKEY_v:
+ return PROJECTM_K_v;
+ case VKEY_w:
+ return PROJECTM_K_w;
+ case VKEY_x:
+ return PROJECTM_K_x;
+ case VKEY_y:
+ return PROJECTM_K_y;
+ case VKEY_z:
+ return PROJECTM_K_z;
+ case VKEY_UP:
+ return PROJECTM_K_UP;
+ case VKEY_RETURN:
+ return PROJECTM_K_RETURN;
+ case VKEY_RIGHT:
+ return PROJECTM_K_RIGHT;
+ case VKEY_LEFT:
+ return PROJECTM_K_LEFT;
+ case VKEY_DOWN:
+ return PROJECTM_K_DOWN;
+ case VKEY_PAGEUP:
+ return PROJECTM_K_PAGEUP;
+ case VKEY_PAGEDOWN:
+ return PROJECTM_K_PAGEDOWN;
+
+
+ default:
+ return PROJECTM_K_NONE;
+ break;
+ }
+}
+
+projectMModifier
+lv2pmModifier (int mod)
+{
+ return mod && VKMOD_LSHIFT;
+}
diff --git a/src/libprojectM/projectM.cpp b/src/libprojectM/projectM.cpp
index 5e23005..147e078 100644
--- a/src/libprojectM/projectM.cpp
+++ b/src/libprojectM/projectM.cpp
@@ -18,7 +18,6 @@
* See 'LICENSE.txt' included within this release
*
*/
-
#include "RenderItemMatcher.hpp"
#include "RenderItemMergeFunction.hpp"
#include "fatal.h"
@@ -59,872 +58,931 @@
pthread_mutex_t mutex;
pthread_cond_t condition;
-pthread_t thread;
+pthread_t thread;
#ifdef SYNC_PRESET_SWITCHES
pthread_mutex_t preset_mutex;
#endif
#endif
+
projectM::~projectM()
{
+#ifdef USE_THREADS
+ std::cout << "[projectM] thread ";
+ printf ("c");
+ running = false;
+ printf ("l");
+ pthread_cond_signal (&condition);
+ printf ("e");
+ pthread_mutex_unlock (&mutex);
+ printf ("a");
+ pthread_detach (thread);
+ printf ("n");
+ pthread_cond_destroy (&condition);
+ printf ("u");
+ pthread_mutex_destroy (&mutex);
+#ifdef SYNC_PRESET_SWITCHES
+ pthread_mutex_destroy (&preset_mutex);
+#endif
- #ifdef USE_THREADS
- std::cout << "[projectM] thread ";
- printf("c");
- running = false;
- printf("l");
- pthread_cond_signal(&condition);
- printf("e");
- pthread_mutex_unlock( &mutex );
- printf("a");
- pthread_detach(thread);
- printf("n");
- pthread_cond_destroy(&condition);
- printf("u");
- pthread_mutex_destroy( &mutex );
- #ifdef SYNC_PRESET_SWITCHES
- pthread_mutex_destroy( &preset_mutex );
- #endif
+ printf ("p");
+ std::cout << std::endl;
+#endif
+ destroyPresetTools();
- printf("p");
- std::cout << std::endl;
- #endif
- destroyPresetTools();
+ if (renderer)
+ delete (renderer);
+ if (beatDetect)
+ delete (beatDetect);
+ if (_pcm) {
+ delete (_pcm);
+ _pcm = 0;
+ }
- if ( renderer )
- delete ( renderer );
- if ( beatDetect )
- delete ( beatDetect );
- if ( _pcm ) {
- delete ( _pcm );
- _pcm = 0;
- }
-
- delete(_pipelineContext);
- delete(_pipelineContext2);
+ delete (_pipelineContext);
+ delete (_pipelineContext2);
}
-unsigned projectM::initRenderToTexture()
+unsigned
+projectM::initRenderToTexture()
{
- return renderer->initRenderToTexture();
+ return renderer->initRenderToTexture();
}
-void projectM::projectM_resetTextures()
+void
+projectM::projectM_resetTextures()
{
- renderer->ResetTextures();
+ renderer->ResetTextures();
}
-projectM::projectM ( std::string config_file, int flags) :
-beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext())
+projectM::projectM (std::string config_file, int flags)
+ : beatDetect (0),
+ renderer (0),
+ _pcm (0),
+ m_presetPos (0),
+ m_flags (flags),
+ _pipelineContext (new PipelineContext()),
+ _pipelineContext2 (new PipelineContext())
{
- readConfig(config_file);
- projectM_reset();
- projectM_resetGL(_settings.windowWidth, _settings.windowHeight);
-
+ readConfig (config_file);
+ projectM_reset();
+ projectM_resetGL (_settings.windowWidth, _settings.windowHeight);
}
-projectM::projectM(Settings settings, int flags):
-beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext())
+projectM::projectM (Settings settings, int flags)
+ : beatDetect (0),
+ renderer (0),
+ _pcm (0),
+ m_presetPos (0),
+ m_flags (flags),
+ _pipelineContext (new PipelineContext()),
+ _pipelineContext2 (new PipelineContext())
{
- readSettings(settings);
- projectM_reset();
- projectM_resetGL(_settings.windowWidth, _settings.windowHeight);
+ readSettings (settings);
+ projectM_reset();
+ projectM_resetGL (_settings.windowWidth, _settings.windowHeight);
}
-bool projectM::writeConfig(const std::string & configFile, const Settings & settings) {
-
- ConfigFile config ( configFile );
-
- config.add("Mesh X", settings.meshX);
- config.add("Mesh Y", settings.meshY);
- config.add("Texture Size", settings.textureSize);
- config.add("FPS", settings.fps);
- config.add("Window Width", settings.windowWidth);
- config.add("Window Height", settings.windowHeight);
- config.add("Smooth Preset Duration", settings.smoothPresetDuration);
- config.add("Preset Duration", settings.presetDuration);
- config.add("Preset Path", settings.presetURL);
- config.add("Title Font", settings.titleFontURL);
- config.add("Menu Font", settings.menuFontURL);
- config.add("Hard Cut Sensitivity", settings.beatSensitivity);
- config.add("Aspect Correction", settings.aspectCorrection);
- config.add("Easter Egg Parameter", settings.easterEgg);
- config.add("Shuffle Enabled", settings.shuffleEnabled);
- config.add("Soft Cut Ratings Enabled", settings.softCutRatingsEnabled);
- std::fstream file(configFile.c_str());
- if (file) {
- file << config;
- return true;
- } else
- return false;
-}
-
-
-
-void projectM::readConfig (const std::string & configFile )
+bool
+projectM::writeConfig (
+const std::string & configFile,
+const Settings & settings)
{
- std::cout << "[projectM] config file: " << configFile << std::endl;
- ConfigFile config ( configFile );
- _settings.meshX = config.read<int> ( "Mesh X", 32 );
- _settings.meshY = config.read<int> ( "Mesh Y", 24 );
- _settings.textureSize = config.read<int> ( "Texture Size", 512 );
- _settings.fps = config.read<int> ( "FPS", 35 );
- _settings.windowWidth = config.read<int> ( "Window Width", 512 );
- _settings.windowHeight = config.read<int> ( "Window Height", 512 );
- _settings.smoothPresetDuration = config.read<int>
- ( "Smooth Preset Duration", config.read<int>("Smooth Transition Duration", 10));
- _settings.presetDuration = config.read<int> ( "Preset Duration", 15 );
+ ConfigFile config (configFile);
- #ifdef LINUX
- _settings.presetURL = config.read<string> ( "Preset Path", CMAKE_INSTALL_PREFIX "/share/projectM/presets" );
- #endif
+ config.add ("Mesh X", settings.meshX);
+ config.add ("Mesh Y", settings.meshY);
+ config.add ("Texture Size", settings.textureSize);
+ config.add ("FPS", settings.fps);
+ config.add ("Window Width", settings.windowWidth);
+ config.add ("Window Height", settings.windowHeight);
+ config.add ("Smooth Preset Duration", settings.smoothPresetDuration);
+ config.add ("Preset Duration", settings.presetDuration);
+ config.add ("Preset Path", settings.presetURL);
+ config.add ("Title Font", settings.titleFontURL);
+ config.add ("Menu Font", settings.menuFontURL);
+ config.add ("Hard Cut Sensitivity", settings.beatSensitivity);
+ config.add ("Aspect Correction", settings.aspectCorrection);
+ config.add ("Easter Egg Parameter", settings.easterEgg);
+ config.add ("Shuffle Enabled", settings.shuffleEnabled);
+ config.add ("Soft Cut Ratings Enabled", settings.softCutRatingsEnabled);
+ std::fstream file (configFile.c_str());
- #ifdef __APPLE__
- /// @bug awful hardcoded hack- need to add intelligence to cmake wrt bundling - carm
- _settings.presetURL = config.read<string> ( "Preset Path", "../Resources/presets" );
- #endif
-
- #ifdef WIN32
- _settings.presetURL = config.read<string> ( "Preset Path", CMAKE_INSTALL_PREFIX "/share/projectM/presets" );
- #endif
-
- #ifdef __APPLE__
- _settings.titleFontURL = config.read<string>
- ( "Title Font", "../Resources/fonts/Vera.tff");
- _settings.menuFontURL = config.read<string>
- ( "Menu Font", "../Resources/fonts/VeraMono.ttf");
- #endif
-
- #ifdef LINUX
- _settings.titleFontURL = config.read<string>
- ( "Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf" );
- _settings.menuFontURL = config.read<string>
- ( "Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf" );
- #endif
-
- #ifdef WIN32
- _settings.titleFontURL = config.read<string>
- ( "Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf" );
- _settings.menuFontURL = config.read<string>
- ( "Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf" );
- #endif
-
-
- _settings.shuffleEnabled = config.read<bool> ( "Shuffle Enabled", true);
-
- _settings.easterEgg = config.read<float> ( "Easter Egg Parameter", 0.0);
- _settings.softCutRatingsEnabled =
- config.read<float> ( "Soft Cut Ratings Enabled", false);
-
- projectM_init ( _settings.meshX, _settings.meshY, _settings.fps,
- _settings.textureSize, _settings.windowWidth,_settings.windowHeight);
-
- _settings.beatSensitivity = beatDetect->beat_sensitivity = config.read<float> ( "Hard Cut Sensitivity", 10.0 );
-
-
- if ( config.read ( "Aspect Correction", true ) )
- {
- _settings.aspectCorrection = true;
- renderer->correction = true;
- }
- else
- {
- _settings.aspectCorrection = false;
- renderer->correction = false;
- }
-
-
+ if (file) {
+ file << config;
+ return true;
+ } else
+ return false;
}
-void projectM::readSettings (const Settings & settings )
+
+void
+projectM::readConfig (const std::string & configFile)
{
- _settings.meshX = settings.meshX;
- _settings.meshY = settings.meshY;
- _settings.textureSize = settings.textureSize;
- _settings.fps = settings.fps;
- _settings.windowWidth = settings.windowWidth;
- _settings.windowHeight = settings.windowHeight;
- _settings.smoothPresetDuration = settings.smoothPresetDuration;
- _settings.presetDuration = settings.presetDuration;
- _settings.softCutRatingsEnabled = settings.softCutRatingsEnabled;
+ std::cout << "[projectM] config file: " << configFile << std::endl;
- _settings.presetURL = settings.presetURL;
- _settings.titleFontURL = settings.titleFontURL;
- _settings.menuFontURL = settings.menuFontURL;
- _settings.shuffleEnabled = settings.shuffleEnabled;
+ ConfigFile config (configFile);
+ _settings.meshX = config.read<int> ("Mesh X", 32);
+ _settings.meshY = config.read<int> ("Mesh Y", 24);
+ _settings.textureSize = config.read<int> ("Texture Size", 512);
+ _settings.fps = config.read<int> ("FPS", 35);
+ _settings.windowWidth = config.read<int> ("Window Width", 512);
+ _settings.windowHeight = config.read<int> ("Window Height", 512);
+ _settings.smoothPresetDuration =
+ config.read<int> ("Smooth Preset Duration",
+ config.read<int> ("Smooth Transition Duration", 10));
+ _settings.presetDuration = config.read<int> ("Preset Duration", 15);
- _settings.easterEgg = settings.easterEgg;
+#ifdef LINUX
+ _settings.presetURL = config.read<string> ("Preset Path", CMAKE_INSTALL_PREFIX "/share/projectM/presets");
+#endif
- projectM_init ( _settings.meshX, _settings.meshY, _settings.fps,
- _settings.textureSize, _settings.windowWidth,_settings.windowHeight);
+#ifdef __APPLE__
+ /// @bug awful hardcoded hack- need to add intelligence to cmake wrt bundling - carm
+ _settings.presetURL = config.read<string> ("Preset Path", "../Resources/presets");
+#endif
+
+#ifdef WIN32
+ _settings.presetURL = config.read<string> ("Preset Path", CMAKE_INSTALL_PREFIX "/share/projectM/presets");
+#endif
+
+#ifdef __APPLE__
+ _settings.titleFontURL = config.read<string>
+ ("Title Font", "../Resources/fonts/Vera.tff");
+ _settings.menuFontURL = config.read<string>
+ ("Menu Font", "../Resources/fonts/VeraMono.ttf");
+#endif
+
+#ifdef LINUX
+ _settings.titleFontURL = config.read<string>
+ ("Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf");
+ _settings.menuFontURL = config.read<string>
+ ("Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf");
+#endif
+
+#ifdef WIN32
+ _settings.titleFontURL = config.read<string>
+ ("Title Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/Vera.ttf");
+ _settings.menuFontURL = config.read<string>
+ ("Menu Font", CMAKE_INSTALL_PREFIX "/share/projectM/fonts/VeraMono.ttf");
+#endif
- _settings.beatSensitivity = settings.beatSensitivity;
- _settings.aspectCorrection = settings.aspectCorrection;
+ _settings.shuffleEnabled = config.read<bool> ("Shuffle Enabled", true);
+ _settings.easterEgg = config.read<float> ("Easter Egg Parameter", 0.0);
+ _settings.softCutRatingsEnabled = config.read<float> ("Soft Cut Ratings Enabled", false);
+ projectM_init (_settings.meshX, _settings.meshY,
+ _settings.fps,
+ _settings.textureSize,
+ _settings.windowWidth, _settings.windowHeight);
+
+ _settings.beatSensitivity =
+ beatDetect->beat_sensitivity = config.read<float> ("Hard Cut Sensitivity", 10.0);
+
+
+ if (config.read ("Aspect Correction", true))
+ {
+ _settings.aspectCorrection = true;
+ renderer->correction = true;
+ }
+ else
+ {
+ _settings.aspectCorrection = false;
+ renderer->correction = false;
+ }
+}
+
+
+void
+projectM::readSettings (const Settings & settings)
+{
+ _settings.meshX = settings.meshX;
+ _settings.meshY = settings.meshY;
+ _settings.textureSize = settings.textureSize;
+ _settings.fps = settings.fps;
+ _settings.windowWidth = settings.windowWidth;
+ _settings.windowHeight = settings.windowHeight;
+ _settings.smoothPresetDuration = settings.smoothPresetDuration;
+ _settings.presetDuration = settings.presetDuration;
+ _settings.softCutRatingsEnabled = settings.softCutRatingsEnabled;
+
+ _settings.presetURL = settings.presetURL;
+ _settings.titleFontURL = settings.titleFontURL;
+ _settings.menuFontURL = settings.menuFontURL;
+ _settings.shuffleEnabled = settings.shuffleEnabled;
+
+ _settings.easterEgg = settings.easterEgg;
+
+ projectM_init (_settings.meshX, _settings.meshY,
+ _settings.fps,
+ _settings.textureSize,
+ _settings.windowWidth, _settings.windowHeight);
+
+ _settings.beatSensitivity = settings.beatSensitivity;
+ _settings.aspectCorrection = settings.aspectCorrection;
}
#ifdef USE_THREADS
-static void *thread_callback(void *prjm) {
- projectM *p = (projectM *)prjm;
+static void
+*thread_callback (void *prjm)
+{
+ projectM *p = (projectM *)prjm;
- p->thread_func(prjm);
- return NULL;}
+ p->thread_func (prjm);
+ return NULL;
+}
- void *projectM::thread_func(void *vptr_args)
+void *
+projectM::thread_func (void *vptr_args)
+{
+ pthread_mutex_lock (&mutex);
+ // printf ("in thread: %f\n", timeKeeper->PresetProgressB());
+ while (true)
+ {
+ pthread_cond_wait (&condition, &mutex);
+ if (!running)
{
- pthread_mutex_lock( &mutex );
- // printf("in thread: %f\n", timeKeeper->PresetProgressB());
- while (true)
- {
- pthread_cond_wait( &condition, &mutex );
- if(!running)
- {
- pthread_mutex_unlock( &mutex );
- return NULL;
- }
- evaluateSecondPreset();
- }
+ pthread_mutex_unlock (&mutex);
+ return NULL;
}
- #endif
+ evaluateSecondPreset();
+ }
+}
+#endif /* USE_THREADS */
- void projectM::evaluateSecondPreset()
+void
+projectM::evaluateSecondPreset()
+{
+ pipelineContext2().time = timeKeeper->GetRunningTime();
+ pipelineContext2().frame = timeKeeper->PresetFrameB();
+ pipelineContext2().progress = timeKeeper->PresetProgressB();
+
+ m_activePreset2->Render (*beatDetect, pipelineContext2());
+}
+
+void
+projectM::renderFrame()
+{
+#ifdef SYNC_PRESET_SWITCHES
+ pthread_mutex_lock (&preset_mutex);
+#endif
+
+#ifdef DEBUG
+ char fname[1024];
+ FILE *f = NULL;
+ int index = 0;
+ int x, y;
+#endif
+
+ timeKeeper->UpdateTimers();
+ /*
+ if (timeKeeper->IsSmoothing())
+ {
+ printf ("Smoothing A:%f, B:%f, S:%f\n",
+ timeKeeper->PresetProgressA(),
+ timeKeeper->PresetProgressB(),
+ timeKeeper->SmoothRatio());
+ }
+ else
+ {
+ printf (" A:%f\n", timeKeeper->PresetProgressA());
+ }*/
+
+ mspf = (int) (1000.0 / (float) settings().fps); //milliseconds per frame
+
+ /// @bug who is responsible for updating this now?"
+ pipelineContext().time = timeKeeper->GetRunningTime();
+ pipelineContext().frame = timeKeeper->PresetFrameA();
+ pipelineContext().progress = timeKeeper->PresetProgressA();
+
+ //m_activePreset->Render (*beatDetect, pipelineContext());
+
+ beatDetect->detectFromSamples();
+
+ //m_activePreset->evaluateFrame();
+
+ //if the preset isn't locked and there are more presets
+ if (renderer->noSwitch == false && !m_presetChooser->empty())
+ {
+ //if preset is done and we're not already switching
+ if (timeKeeper->PresetProgressA() >= 1.0 && !timeKeeper->IsSmoothing())
{
- pipelineContext2().time = timeKeeper->GetRunningTime();
- pipelineContext2().frame = timeKeeper->PresetFrameB();
- pipelineContext2().progress = timeKeeper->PresetProgressB();
-
- m_activePreset2->Render(*beatDetect, pipelineContext2());
+ if (settings().shuffleEnabled)
+ selectRandom (false);
+ else
+ selectNext (false);
}
-
- void projectM::renderFrame()
+ else if ( beatDetect->vol-beatDetect->vol_old>beatDetect->beat_sensitivity
+ && timeKeeper->CanHardCut())
{
- #ifdef SYNC_PRESET_SWITCHES
- pthread_mutex_lock(&preset_mutex);
- #endif
-
- #ifdef DEBUG
- char fname[1024];
- FILE *f = NULL;
- int index = 0;
- int x, y;
- #endif
-
- timeKeeper->UpdateTimers();
-/*
- if (timeKeeper->IsSmoothing())
- {
- printf("Smoothing A:%f, B:%f, S:%f\n", timeKeeper->PresetProgressA(), timeKeeper->PresetProgressB(), timeKeeper->SmoothRatio());
- }
- else
- {
- printf(" A:%f\n", timeKeeper->PresetProgressA());
- }*/
-
- mspf= ( int ) ( 1000.0/ ( float ) settings().fps ); //milliseconds per frame
-
- /// @bug who is responsible for updating this now?"
- pipelineContext().time = timeKeeper->GetRunningTime();
- pipelineContext().frame = timeKeeper->PresetFrameA();
- pipelineContext().progress = timeKeeper->PresetProgressA();
-
- //m_activePreset->Render(*beatDetect, pipelineContext());
-
- beatDetect->detectFromSamples();
-
- //m_activePreset->evaluateFrame();
-
- //if the preset isn't locked and there are more presets
- if ( renderer->noSwitch==false && !m_presetChooser->empty() )
- {
- //if preset is done and we're not already switching
- if ( timeKeeper->PresetProgressA()>=1.0 && !timeKeeper->IsSmoothing())
- {
-
- if (settings().shuffleEnabled)
- selectRandom(false);
- else
- selectNext(false);
-
- }
-
- else if ((beatDetect->vol-beatDetect->vol_old>beatDetect->beat_sensitivity ) &&
- timeKeeper->CanHardCut())
- {
- // printf("Hard Cut\n");
- if (settings().shuffleEnabled)
- selectRandom(true);
- else
- selectNext(true);
- }
- }
-
-
- if ( timeKeeper->IsSmoothing() && timeKeeper->SmoothRatio() <= 1.0 && !m_presetChooser->empty() )
- {
-
-
- // printf("start thread\n");
- assert ( m_activePreset2.get() );
-
- #ifdef USE_THREADS
-
- pthread_cond_signal(&condition);
- pthread_mutex_unlock( &mutex );
- #endif
- m_activePreset->Render(*beatDetect, pipelineContext());
-
- #ifdef USE_THREADS
- pthread_mutex_lock( &mutex );
- #else
- evaluateSecondPreset();
- #endif
-
- Pipeline pipeline;
-
- pipeline.setStaticPerPixel(settings().meshX, settings().meshY);
-
- assert(_matcher);
- PipelineMerger::mergePipelines( m_activePreset->pipeline(),
- m_activePreset2->pipeline(), pipeline,
- _matcher->matchResults(),
- *_merger, timeKeeper->SmoothRatio());
-
- renderer->RenderFrame(pipeline, pipelineContext());
-
- pipeline.drawables.clear();
-
- /*
- while (!pipeline.drawables.empty()) {
- delete(pipeline.drawables.back());
- pipeline.drawables.pop_back();
- } */
-
- }
- else
- {
-
-
- if ( timeKeeper->IsSmoothing() && timeKeeper->SmoothRatio() > 1.0 )
- {
- //printf("End Smooth\n");
- m_activePreset = m_activePreset2;
- timeKeeper->EndSmoothing();
- }
- //printf("Normal\n");
-
- m_activePreset->Render(*beatDetect, pipelineContext());
- renderer->RenderFrame (m_activePreset->pipeline(), pipelineContext());
-
-
- }
-
- // std::cout<< m_activePreset->absoluteFilePath()<<std::endl;
- // renderer->presetName = m_activePreset->absoluteFilePath();
-
-
-
- count++;
- #ifndef WIN32
- /** Frame-rate limiter */
- /** Compute once per preset */
- if ( this->count%100==0 )
- {
- this->renderer->realfps=100.0/ ( ( getTicks ( &timeKeeper->startTime )-this->fpsstart ) /1000 );
- this->fpsstart=getTicks ( &timeKeeper->startTime );
- }
-
- int timediff = getTicks ( &timeKeeper->startTime )-this->timestart;
-
- if ( timediff < this->mspf )
- {
- // printf("%s:",this->mspf-timediff);
- int sleepTime = ( unsigned int ) ( this->mspf-timediff ) * 1000;
- // DWRITE ( "usleep: %d\n", sleepTime );
- if ( sleepTime > 0 && sleepTime < 100000 )
- {
- if ( usleep ( sleepTime ) != 0 ) {}}
- }
- this->timestart=getTicks ( &timeKeeper->startTime );
- #endif /** !WIN32 */
-
- #ifdef SYNC_PRESET_SWITCHES
- pthread_mutex_unlock(&preset_mutex);
- #endif
-
+ // printf ("Hard Cut\n");
+ if (settings().shuffleEnabled)
+ selectRandom (true);
+ else
+ selectNext (true);
}
+ }
- void projectM::projectM_reset()
+
+ if ( timeKeeper->IsSmoothing()
+ && timeKeeper->SmoothRatio() <= 1.0
+ && !m_presetChooser->empty())
+ {
+ // printf ("start thread\n");
+ assert (m_activePreset2.get());
+
+#ifdef USE_THREADS
+ pthread_cond_signal (&condition);
+ pthread_mutex_unlock (&mutex);
+#endif
+ m_activePreset->Render (*beatDetect, pipelineContext());
+
+#ifdef USE_THREADS
+ pthread_mutex_lock (&mutex);
+#else
+ evaluateSecondPreset();
+#endif
+
+ Pipeline pipeline;
+
+ pipeline.setStaticPerPixel (settings().meshX, settings().meshY);
+
+ assert (_matcher);
+ PipelineMerger::mergePipelines (m_activePreset->pipeline(),
+ m_activePreset2->pipeline(),
+ pipeline,
+ _matcher->matchResults(),
+ *_merger,
+ timeKeeper->SmoothRatio());
+
+ renderer->RenderFrame (pipeline, pipelineContext());
+
+ pipeline.drawables.clear();
+
+ /*
+ while (!pipeline.drawables.empty()) {
+ delete (pipeline.drawables.back());
+ pipeline.drawables.pop_back();
+ } */
+ }
+ else
+ {
+ if (timeKeeper->IsSmoothing() && timeKeeper->SmoothRatio() > 1.0)
{
- this->mspf = 0;
- this->timed = 0;
- this->timestart = 0;
- this->count = 0;
-
- this->fpsstart = 0;
-
- setlocale(LC_NUMERIC, "C");
-
- projectM_resetengine();
+ //printf ("End Smooth\n");
+ m_activePreset = m_activePreset2;
+ timeKeeper->EndSmoothing();
}
+ //printf ("Normal\n");
- void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, int height )
+ m_activePreset->Render (*beatDetect, pipelineContext());
+ renderer->RenderFrame (m_activePreset->pipeline(), pipelineContext());
+ }
+
+ // std::cout<< m_activePreset->absoluteFilePath()<<std::endl;
+ // renderer->presetName = m_activePreset->absoluteFilePath();
+
+ count++;
+
+#ifndef WIN32
+ /** Frame-rate limiter */
+ /** Compute once per preset */
+ if (this->count % 100 == 0)
+ {
+ this->renderer->realfps = 100.0
+ / ((getTicks (&timeKeeper->startTime)
+ - this->fpsstart) / 1000);
+ this->fpsstart = getTicks (&timeKeeper->startTime);
+ }
+
+ int timediff = getTicks (&timeKeeper->startTime) - this->timestart;
+
+ if (timediff < this->mspf)
+ {
+ // printf ("%s:",this->mspf-timediff);
+ int sleepTime = (unsigned int) (this->mspf - timediff) * 1000;
+ // DWRITE ("usleep: %d\n", sleepTime);
+ if (sleepTime > 0 && sleepTime < 100000)
{
- setlocale(LC_NUMERIC, "C");
-
- /** Initialise start time */
- timeKeeper = new TimeKeeper(_settings.presetDuration,_settings.smoothPresetDuration, _settings.easterEgg);
-
- /** Nullify frame stash */
-
- /** Initialise per-pixel matrix calculations */
- /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */
- assert ( !beatDetect );
-
- if (!_pcm)
- _pcm = new PCM();
- assert(pcm());
- beatDetect = new BeatDetect ( _pcm );
-
- if ( _settings.fps > 0 )
- mspf= ( int ) ( 1000.0/ ( float ) _settings.fps );
- else mspf = 0;
-
- this->renderer = new Renderer ( width, height, gx, gy, texsize, beatDetect, settings().presetURL, settings().titleFontURL, settings().menuFontURL );
-
- running = true;
-
- initPresetTools(gx, gy);
-
-
- #ifdef USE_THREADS
- pthread_mutex_init(&mutex, NULL);
-
- #ifdef SYNC_PRESET_SWITCHES
- pthread_mutex_init(&preset_mutex, NULL);
- #endif
-
- pthread_cond_init(&condition, NULL);
- if (pthread_create(&thread, NULL, thread_callback, this) != 0)
- {
-
- std::cerr << "[projectM] failed to allocate a thread! try building with option USE_THREADS turned off" << std::endl;;
- exit(EXIT_FAILURE);
- }
- pthread_mutex_lock( &mutex );
- #endif
-
- /// @bug order of operatoins here is busted
- //renderer->setPresetName ( m_activePreset->name() );
- timeKeeper->StartPreset();
- assert(pcm());
-
- pipelineContext().fps = fps;
- pipelineContext2().fps = fps;
-
+ if (usleep (sleepTime) != 0) {}
}
+ }
+ this->timestart = getTicks (&timeKeeper->startTime);
+#endif /** !WIN32 */
+
+#ifdef SYNC_PRESET_SWITCHES
+ pthread_mutex_unlock (&preset_mutex);
+#endif
+}
+
+void
+projectM::projectM_reset()
+{
+ this->mspf = 0;
+ this->timed = 0;
+ this->timestart = 0;
+ this->count = 0;
+
+ this->fpsstart = 0;
+
+ setlocale (LC_NUMERIC, "C");
+
+ projectM_resetengine();
+}
+
+void
+projectM::projectM_init (
+int gx,
+int gy,
+int fps,
+int texsize,
+int width,
+int height
+)
+{
+ setlocale (LC_NUMERIC, "C");
+
+ /** Initialise start time */
+ timeKeeper = new TimeKeeper (_settings.presetDuration,
+ _settings.smoothPresetDuration,
+ _settings.easterEgg);
+
+ /** Nullify frame stash */
+
+ /** Initialise per-pixel matrix calculations */
+ /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */
+ assert (!beatDetect);
+
+ if (!_pcm)
+ _pcm = new PCM();
+ assert (pcm());
+ beatDetect = new BeatDetect (_pcm);
+
+ if (_settings.fps > 0)
+ mspf = (int) (1000.0 / (float) _settings.fps);
+ else
+ mspf = 0;
+
+ this->renderer = new Renderer (width, height,
+ gx, gy,
+ texsize,
+ beatDetect,
+ settings().presetURL,
+ settings().titleFontURL,
+ settings().menuFontURL);
+
+ running = true;
+
+ initPresetTools (gx, gy);
+
+
+#ifdef USE_THREADS
+ pthread_mutex_init (&mutex, NULL);
+
+#ifdef SYNC_PRESET_SWITCHES
+ pthread_mutex_init (&preset_mutex, NULL);
+#endif
+
+ pthread_cond_init (&condition, NULL);
+ if (pthread_create (&thread, NULL, thread_callback, this) != 0)
+ {
+
+ std::cerr << "[projectM] failed to allocate a thread! try building with option USE_THREADS turned off" << std::endl;;
+ exit (EXIT_FAILURE);
+ }
+ pthread_mutex_lock (&mutex);
+#endif /* USE_THREADS */
+
+ /// @bug order of operatoins here is busted
+ //renderer->setPresetName (m_activePreset->name());
+ timeKeeper->StartPreset();
+ assert (pcm());
+
+ pipelineContext().fps = fps;
+ pipelineContext2().fps = fps;
+}
/* Reinitializes the engine variables to a default (conservative and sane) value */
- void projectM::projectM_resetengine()
- {
-
- if ( beatDetect != NULL )
- {
- beatDetect->reset();
- }
-
- }
+void
+projectM::projectM_resetengine()
+{
+ if (beatDetect != NULL)
+ {
+ beatDetect->reset();
+ }
+}
/** Resets OpenGL state */
- void projectM::projectM_resetGL ( int w, int h )
- {
-
- /** Stash the new dimensions */
-
- renderer->reset ( w,h );
- }
+void
+projectM::projectM_resetGL (int w, int h)
+{
+ /** Stash the new dimensions */
+ renderer->reset (w,h);
+}
/** Sets the title to display */
- void projectM::projectM_setTitle ( std::string title ) {
-
- if ( title != renderer->title )
- {
- renderer->title=title;
- renderer->drawtitle=1;
- }
- }
+void
+projectM::projectM_setTitle (std::string title)
+{
+ if (title != renderer->title)
+ {
+ renderer->title=title;
+ renderer->drawtitle=1;
+ }
+}
- int projectM::initPresetTools(int gx, int gy)
- {
+ int projectM::initPresetTools (int gx, int gy)
+{
+ /* Set the seed to the current time in seconds */
+ srand (time (NULL));
- /* Set the seed to the current time in seconds */
- srand ( time ( NULL ) );
+ std::string url = (m_flags & FLAG_DISABLE_PLAYLIST_LOAD)
+ ? std::string()
+ : settings().presetURL;
- std::string url = (m_flags & FLAG_DISABLE_PLAYLIST_LOAD) ? std::string() : settings().presetURL;
+ if ((m_presetLoader = new PresetLoader (gx, gy, url)) == 0)
+ {
+ m_presetLoader = 0;
+ std::cerr << "[projectM] error allocating preset loader" << std::endl;
+ return PROJECTM_FAILURE;
+ }
- if ( ( m_presetLoader = new PresetLoader ( gx, gy, url) ) == 0 )
- {
- m_presetLoader = 0;
- std::cerr << "[projectM] error allocating preset loader" << std::endl;
- return PROJECTM_FAILURE;
- }
+ if ((m_presetChooser = new PresetChooser (*m_presetLoader, settings().softCutRatingsEnabled)) == 0)
+ {
+ delete (m_presetLoader);
- if ( ( m_presetChooser = new PresetChooser ( *m_presetLoader, settings().softCutRatingsEnabled ) ) == 0 )
- {
- delete ( m_presetLoader );
+ m_presetChooser = 0;
+ m_presetLoader = 0;
- m_presetChooser = 0;
- m_presetLoader = 0;
+ std::cerr << "[projectM] error allocating preset chooser" << std::endl;
+ return PROJECTM_FAILURE;
+ }
- std::cerr << "[projectM] error allocating preset chooser" << std::endl;
- return PROJECTM_FAILURE;
- }
+ // Start the iterator
+ if (!m_presetPos)
+ m_presetPos = new PresetIterator();
- // Start the iterator
- if (!m_presetPos)
- m_presetPos = new PresetIterator();
+ // Initialize a preset queue position as well
+ // m_presetQueuePos = new PresetIterator();
- // Initialize a preset queue position as well
- // m_presetQueuePos = new PresetIterator();
+ // Start at end ptr- this allows next/previous to easily be done from this position.
+ *m_presetPos = m_presetChooser->end();
- // Start at end ptr- this allows next/previous to easily be done from this position.
- *m_presetPos = m_presetChooser->end();
+ // Load idle preset
+ std::cerr << "[projectM] Allocating idle preset..." << std::endl;
+ m_activePreset = m_presetLoader->loadPreset
+ ("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk");
- // Load idle preset
- std::cerr << "[projectM] Allocating idle preset..." << std::endl;
- m_activePreset = m_presetLoader->loadPreset
- ("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk");
+ renderer->SetPipeline (m_activePreset->pipeline());
- renderer->SetPipeline(m_activePreset->pipeline());
+ // Case where no valid presets exist in directory. Could also mean
+ // playlist initialization was deferred
+ if (m_presetChooser->empty())
+ {
+ //std::cerr << "[projectM] warning: no valid files found in preset directory \""
+ //<< m_presetLoader->directoryName() << "\"" << std::endl;
+ }
- // Case where no valid presets exist in directory. Could also mean
- // playlist initialization was deferred
- if (m_presetChooser->empty())
- {
- //std::cerr << "[projectM] warning: no valid files found in preset directory \""
- //<< m_presetLoader->directoryName() << "\"" << std::endl;
- }
+ _matcher = new RenderItemMatcher();
+ _merger = new MasterRenderItemMerge();
+ //_merger->add (new WaveFormMergeFunction());
+ _merger->add (new ShapeMerge());
+ _merger->add (new BorderMerge());
+ //_merger->add (new BorderMergeFunction());
- _matcher = new RenderItemMatcher();
- _merger = new MasterRenderItemMerge();
- //_merger->add(new WaveFormMergeFunction());
- _merger->add(new ShapeMerge());
- _merger->add(new BorderMerge());
- //_merger->add(new BorderMergeFunction());
+ /// @bug These should be requested by the preset factories.
+ _matcher->distanceFunction().addMetric (new ShapeXYDistance());
- /// @bug These should be requested by the preset factories.
- _matcher->distanceFunction().addMetric(new ShapeXYDistance());
+ //std::cerr << "[projectM] Idle preset allocated." << std::endl;
- //std::cerr << "[projectM] Idle preset allocated." << std::endl;
+ projectM_resetengine();
- projectM_resetengine();
+ //std::cerr << "[projectM] engine has been reset." << std::endl;
+ return PROJECTM_SUCCESS;
+}
- //std::cerr << "[projectM] engine has been reset." << std::endl;
- return PROJECTM_SUCCESS;
- }
+void
+projectM::destroyPresetTools()
+{
+ if (m_presetPos)
+ delete (m_presetPos);
- void projectM::destroyPresetTools()
- {
+ m_presetPos = 0;
- if ( m_presetPos )
- delete ( m_presetPos );
+ if (m_presetChooser)
+ delete (m_presetChooser);
- m_presetPos = 0;
+ m_presetChooser = 0;
- if ( m_presetChooser )
- delete ( m_presetChooser );
+ if (m_presetLoader)
+ delete (m_presetLoader);
- m_presetChooser = 0;
-
- if ( m_presetLoader )
- delete ( m_presetLoader );
-
- m_presetLoader = 0;
-
- }
+ m_presetLoader = 0;
+}
/// @bug queuePreset case isn't handled
- void projectM::removePreset(unsigned int index) {
+void
+projectM::removePreset (unsigned int index)
+{
+ unsigned int chooserIndex = **m_presetPos;
- unsigned int chooserIndex = **m_presetPos;
+ m_presetLoader->removePreset (index);
- m_presetLoader->removePreset(index);
+ // Case: no more presets, set iterator to end
+ if (m_presetChooser->empty())
+ *m_presetPos = m_presetChooser->end();
+ // Case: chooser index has become one less due to removal of an index below it
+ else if (chooserIndex > index) {
+ chooserIndex--;
+ *m_presetPos = m_presetChooser->begin (chooserIndex);
+ }
- // Case: no more presets, set iterator to end
- if (m_presetChooser->empty())
- *m_presetPos = m_presetChooser->end();
+ // Case: we have deleted the active preset position
+ // Set iterator to end of chooser
+ else if (chooserIndex == index) {
+ *m_presetPos = m_presetChooser->end();
+ }
+}
- // Case: chooser index has become one less due to removal of an index below it
- else if (chooserIndex > index) {
- chooserIndex--;
- *m_presetPos = m_presetChooser->begin(chooserIndex);
- }
+unsigned int
+projectM::addPresetURL (
+const std::string & presetURL,
+const std::string & presetName,
+const RatingList & ratings
+)
+{
+ bool restorePosition = false;
- // Case: we have deleted the active preset position
- // Set iterator to end of chooser
- else if (chooserIndex == index) {
- *m_presetPos = m_presetChooser->end();
- }
+ if (*m_presetPos == m_presetChooser->end())
+ restorePosition = true;
+ int index = m_presetLoader->addPresetURL (presetURL, presetName, ratings);
+ if (restorePosition)
+ *m_presetPos = m_presetChooser->end();
- }
+ return index;
+}
- unsigned int projectM::addPresetURL ( const std::string & presetURL, const std::string & presetName, const RatingList & ratings)
- {
- bool restorePosition = false;
+void
+projectM::selectPreset (unsigned int index, bool hardCut)
+{
+ if (m_presetChooser->empty())
+ return;
- if (*m_presetPos == m_presetChooser->end())
- restorePosition = true;
+ if (!hardCut) {
+ timeKeeper->StartSmoothing();
+ }
- int index = m_presetLoader->addPresetURL ( presetURL, presetName, ratings);
+ *m_presetPos = m_presetChooser->begin (index);
- if (restorePosition)
- *m_presetPos = m_presetChooser->end();
+ if (!hardCut) {
+ switchPreset (m_activePreset2);
+ } else {
+ switchPreset (m_activePreset);
+ timeKeeper->StartPreset();
+ }
- return index;
- }
-
- void projectM::selectPreset ( unsigned int index, bool hardCut)
- {
-
- if (m_presetChooser->empty())
- return;
-
- if (!hardCut) {
- timeKeeper->StartSmoothing();
- }
-
- *m_presetPos = m_presetChooser->begin(index);
-
- if (!hardCut) {
- switchPreset(m_activePreset2);
- } else {
- switchPreset(m_activePreset);
- timeKeeper->StartPreset();
- }
-
- presetSwitchedEvent(hardCut, **m_presetPos);
-
+ presetSwitchedEvent (hardCut, **m_presetPos);
}
-void projectM::selectRandom(const bool hardCut) {
+void
+projectM::selectRandom (const bool hardCut)
+{
+ if (m_presetChooser->empty())
+ return;
- if (m_presetChooser->empty())
- return;
+ if (!hardCut) {
+ timeKeeper->StartSmoothing();
+ }
- if (!hardCut) {
- timeKeeper->StartSmoothing();
- }
+ *m_presetPos = m_presetChooser->weightedRandom (hardCut);
- *m_presetPos = m_presetChooser->weightedRandom(hardCut);
+ if (!hardCut) {
+ switchPreset (m_activePreset2);
+ } else {
+ switchPreset (m_activePreset);
+ timeKeeper->StartPreset();
+ }
- if (!hardCut) {
- switchPreset(m_activePreset2);
- } else {
- switchPreset(m_activePreset);
- timeKeeper->StartPreset();
- }
-
- presetSwitchedEvent(hardCut, **m_presetPos);
-
+ presetSwitchedEvent (hardCut, **m_presetPos);
}
-void projectM::selectPrevious(const bool hardCut) {
+void
+projectM::selectPrevious (const bool hardCut)
+{
+ if (m_presetChooser->empty())
+ return;
- if (m_presetChooser->empty())
- return;
+ if (!hardCut) {
+ timeKeeper->StartSmoothing();
+ }
- if (!hardCut) {
- timeKeeper->StartSmoothing();
- }
+ m_presetChooser->previousPreset (*m_presetPos);
- m_presetChooser->previousPreset(*m_presetPos);
+ if (!hardCut) {
+ switchPreset (m_activePreset2);
+ } else {
+ switchPreset (m_activePreset);
+ timeKeeper->StartPreset();
+ }
- if (!hardCut) {
- switchPreset(m_activePreset2);
- } else {
- switchPreset(m_activePreset);
- timeKeeper->StartPreset();
- }
+ presetSwitchedEvent (hardCut, **m_presetPos);
- presetSwitchedEvent(hardCut, **m_presetPos);
+ // m_activePreset = m_presetPos->allocate();
+ // renderer->SetPipeline (m_activePreset->pipeline());
+ // renderer->setPresetName (m_activePreset->name());
-// m_activePreset = m_presetPos->allocate();
-// renderer->SetPipeline(m_activePreset->pipeline());
-// renderer->setPresetName(m_activePreset->name());
-
- //timeKeeper->StartPreset();
-
+ //timeKeeper->StartPreset();
}
-void projectM::selectNext(const bool hardCut) {
+void
+projectM::selectNext (const bool hardCut)
+{
+ if (m_presetChooser->empty())
+ return;
- if (m_presetChooser->empty())
- return;
+ if (!hardCut) {
+ timeKeeper->StartSmoothing();
+ std::cout << "start smoothing" << std::endl;
+ }
- if (!hardCut) {
- timeKeeper->StartSmoothing();
- std::cout << "start smoothing" << std::endl;
- }
+ m_presetChooser->nextPreset (*m_presetPos);
- m_presetChooser->nextPreset(*m_presetPos);
-
- if (!hardCut) {
- switchPreset(m_activePreset2);
- } else {
- switchPreset(m_activePreset);
- timeKeeper->StartPreset();
- }
- presetSwitchedEvent(hardCut, **m_presetPos);
-
-
+ if (!hardCut) {
+ switchPreset (m_activePreset2);
+ } else {
+ switchPreset (m_activePreset);
+ timeKeeper->StartPreset();
+ }
+ presetSwitchedEvent (hardCut, **m_presetPos);
}
/**
*
* @param targetPreset
*/
-void projectM::switchPreset(std::auto_ptr<Preset> & targetPreset) {
+void
+projectM::switchPreset (std::auto_ptr<Preset> & targetPreset)
+{
- #ifdef SYNC_PRESET_SWITCHES
- pthread_mutex_lock(&preset_mutex);
- #endif
+#ifdef SYNC_PRESET_SWITCHES
+ pthread_mutex_lock (&preset_mutex);
+#endif
- targetPreset = m_presetPos->allocate();
+ targetPreset = m_presetPos->allocate();
- // Set preset name here- event is not done because at the moment this function is oblivious to smooth/hard switches
- renderer->setPresetName(targetPreset->name());
- renderer->SetPipeline(targetPreset->pipeline());
+ // Set preset name here- event is not done because at the moment this function is oblivious to smooth/hard switches
+ renderer->setPresetName (targetPreset->name());
+ renderer->SetPipeline (targetPreset->pipeline());
- #ifdef SYNC_PRESET_SWITCHES
- pthread_mutex_unlock(&preset_mutex);
- #endif
- }
+#ifdef SYNC_PRESET_SWITCHES
+ pthread_mutex_unlock (&preset_mutex);
+#endif
+}
- void projectM::setPresetLock ( bool isLocked )
- {
- renderer->noSwitch = isLocked;
- }
+void
+projectM::setPresetLock (bool isLocked)
+{
+ renderer->noSwitch = isLocked;
+}
- bool projectM::isPresetLocked() const
- {
- return renderer->noSwitch;
- }
+bool
+projectM::isPresetLocked() const
+{
+ return renderer->noSwitch;
+}
- std::string projectM::getPresetURL ( unsigned int index ) const
- {
- return m_presetLoader->getPresetURL(index);
- }
+std::string
+projectM::getPresetURL (unsigned int index) const
+{
+ return m_presetLoader->getPresetURL (index);
+}
- int projectM::getPresetRating ( unsigned int index, const PresetRatingType ratingType) const
- {
- return m_presetLoader->getPresetRating(index, ratingType);
- }
+int
+projectM::getPresetRating (unsigned int index, const PresetRatingType ratingType) const
+{
+ return m_presetLoader->getPresetRating (index, ratingType);
+}
- std::string projectM::getPresetName ( unsigned int index ) const
- {
- return m_presetLoader->getPresetName(index);
- }
+std::string
+projectM::getPresetName (unsigned int index) const
+{
+ return m_presetLoader->getPresetName (index);
+}
- void projectM::clearPlaylist ( )
- {
- m_presetLoader->clear();
- *m_presetPos = m_presetChooser->end();
- }
+void
+projectM::clearPlaylist()
+{
+ m_presetLoader->clear();
+ *m_presetPos = m_presetChooser->end();
+}
- void projectM::selectPresetPosition(unsigned int index) {
- *m_presetPos = m_presetChooser->begin(index);
- }
+void
+projectM::selectPresetPosition (unsigned int index)
+{
+ *m_presetPos = m_presetChooser->begin (index);
+}
- bool projectM::selectedPresetIndex(unsigned int & index) const {
+bool
+projectM::selectedPresetIndex (unsigned int & index) const
+{
+ if (*m_presetPos == m_presetChooser->end())
+ return false;
- if (*m_presetPos == m_presetChooser->end())
- return false;
-
- index = **m_presetPos;
- return true;
- }
-
-
- bool projectM::presetPositionValid() const {
-
- return (*m_presetPos != m_presetChooser->end());
- }
-
- unsigned int projectM::getPlaylistSize() const
- {
- return m_presetLoader->size();
- }
-
- void projectM::changePresetRating (unsigned int index, int rating, const PresetRatingType ratingType) {
- m_presetLoader->setRating(index, rating, ratingType);
- presetRatingChanged(index, rating, ratingType);
- }
-
- void projectM::insertPresetURL(unsigned int index, const std::string & presetURL, const std::string & presetName, const RatingList & ratings)
- {
- bool atEndPosition = false;
-
- int newSelectedIndex;
-
-
- if (*m_presetPos == m_presetChooser->end()) // Case: preset not selected
- {
- atEndPosition = true;
- }
-
- else if (**m_presetPos < index) // Case: inserting before selected preset
- {
- newSelectedIndex = **m_presetPos;
- }
-
- else if (**m_presetPos > index) // Case: inserting after selected preset
- {
- newSelectedIndex++;
- }
-
- else // Case: inserting at selected preset
- {
- newSelectedIndex++;
- }
-
- m_presetLoader->insertPresetURL (index, presetURL, presetName, ratings);
-
- if (atEndPosition)
- *m_presetPos = m_presetChooser->end();
- else
- *m_presetPos = m_presetChooser->begin(newSelectedIndex);
-
-
- }
-
-void projectM::changePresetName ( unsigned int index, std::string name ) {
- m_presetLoader->setPresetName(index, name);
+ index = **m_presetPos;
+ return true;
}
-void projectM::changeTextureSize(int size) {
+bool
+projectM::presetPositionValid() const
+{
+ return (*m_presetPos != m_presetChooser->end());
+}
+
+unsigned int
+projectM::getPlaylistSize() const
+{
+ return m_presetLoader->size();
+}
+
+void
+projectM::changePresetRating (unsigned int index, int rating, const PresetRatingType ratingType)
+{
+ m_presetLoader->setRating (index, rating, ratingType);
+ presetRatingChanged (index, rating, ratingType);
+}
+
+void
+projectM::insertPresetURL (
+unsigned int index,
+const std::string & presetURL,
+const std::string & presetName,
+const RatingList & ratings)
+{
+ bool atEndPosition = false;
+ int newSelectedIndex;
+
+ if (*m_presetPos == m_presetChooser->end()) // Case: preset not selected
+ {
+ atEndPosition = true;
+ }
+ else if (**m_presetPos < index) // Case: inserting before selected preset
+ {
+ newSelectedIndex = **m_presetPos;
+ }
+ else if (**m_presetPos > index) // Case: inserting after selected preset
+ {
+ newSelectedIndex++;
+ }
+ else // Case: inserting at selected preset
+ {
+ newSelectedIndex++;
+ }
+
+ m_presetLoader->insertPresetURL (index, presetURL, presetName, ratings);
+
+ if (atEndPosition)
+ *m_presetPos = m_presetChooser->end();
+ else
+ *m_presetPos = m_presetChooser->begin (newSelectedIndex);
+}
+
+void
+projectM::changePresetName (unsigned int index, std::string name)
+{
+ m_presetLoader->setPresetName (index, name);
+}
+
+
+void
+projectM::changeTextureSize (int size)
+{
_settings.textureSize = size;
delete renderer;
- renderer = new Renderer(_settings.windowWidth, _settings.windowHeight,
- _settings.meshX, _settings.meshY,
- _settings.textureSize, beatDetect, _settings.presetURL,
- _settings.titleFontURL, _settings.menuFontURL);
+ renderer = new Renderer (_settings.windowWidth, _settings.windowHeight,
+ _settings.meshX, _settings.meshY,
+ _settings.textureSize,
+ beatDetect,
+ _settings.presetURL,
+ _settings.titleFontURL,
+ _settings.menuFontURL);
}
-void projectM::changePresetDuration(int seconds) {
- timeKeeper->ChangePresetDuration(seconds);
+void
+projectM::changePresetDuration (int seconds)
+{
+ timeKeeper->ChangePresetDuration (seconds);
}
-
-
diff --git a/src/libprojectM/projectM.hpp b/src/libprojectM/projectM.hpp
index 5fa38d3..d2b6bdd 100644
--- a/src/libprojectM/projectM.hpp
+++ b/src/libprojectM/projectM.hpp
@@ -89,53 +89,55 @@
#endif
/** KEEP THIS UP TO DATE! */
-#define PROJECTM_VERSION "2.0.00"
-#define PROJECTM_TITLE "projectM 2.0.00"
+#define PROJECTM_VERSION "2.0.00"
+#define PROJECTM_TITLE "projectM 2.0.00"
+
/** Interface types */
typedef enum {
- MENU_INTERFACE,
- SHELL_INTERFACE,
- EDITOR_INTERFACE,
- DEFAULT_INTERFACE,
- BROWSER_INTERFACE
- } interface_t;
+ MENU_INTERFACE,
+ SHELL_INTERFACE,
+ EDITOR_INTERFACE,
+ DEFAULT_INTERFACE,
+ BROWSER_INTERFACE
+} interface_t;
+
/// A functor class that allows users of this library to specify random preset behavior
class RandomizerFunctor {
+public:
+ RandomizerFunctor(PresetChooser & chooser) ;
+ virtual ~RandomizerFunctor();
+ virtual double operator() (int index);
- public:
- RandomizerFunctor(PresetChooser & chooser) ;
- virtual ~RandomizerFunctor();
- virtual double operator() (int index);
- private:
- const PresetChooser & m_chooser;
+private:
+ const PresetChooser & m_chooser;
};
class DLLEXPORT projectM
{
public:
- static const int FLAG_NONE = 0;
- static const int FLAG_DISABLE_PLAYLIST_LOAD = 1 << 0;
+ static const int FLAG_NONE = 0;
+ static const int FLAG_DISABLE_PLAYLIST_LOAD = 1 << 0;
- struct Settings {
- int meshX;
- int meshY;
- int fps;
- int textureSize;
- int windowWidth;
- int windowHeight;
- std::string presetURL;
- std::string titleFontURL;
- std::string menuFontURL;
- int smoothPresetDuration;
- int presetDuration;
- float beatSensitivity;
- bool aspectCorrection;
- float easterEgg;
- bool shuffleEnabled;
- bool softCutRatingsEnabled;
- };
+ struct Settings {
+ int meshX;
+ int meshY;
+ int fps;
+ int textureSize;
+ int windowWidth;
+ int windowHeight;
+ std::string presetURL;
+ std::string titleFontURL;
+ std::string menuFontURL;
+ int smoothPresetDuration;
+ int presetDuration;
+ float beatSensitivity;
+ bool aspectCorrection;
+ float easterEgg;
+ bool shuffleEnabled;
+ bool softCutRatingsEnabled;
+ };
projectM(std::string config_file, int flags = FLAG_NONE);
projectM(Settings settings, int flags = FLAG_NONE);
@@ -147,8 +149,9 @@
void projectM_setTitle( std::string title );
void renderFrame();
unsigned initRenderToTexture();
- void key_handler( projectMEvent event,
- projectMKeycode keycode, projectMModifier modifier );
+ void key_handler (projectMEvent event,
+ projectMKeycode keycode,
+ projectMModifier modifier);
virtual ~projectM();
@@ -156,7 +159,7 @@
void changePresetDuration(int seconds);
const Settings & settings() const {
- return _settings;
+ return _settings;
}
/// Writes a settings configuration to the specified file
@@ -199,11 +202,15 @@
bool selectedPresetIndex(unsigned int & index) const;
/// Add a preset url to the play list. Appended to bottom. Returns index of preset
- unsigned int addPresetURL(const std::string & presetURL, const std::string & presetName, const RatingList & ratingList);
+ unsigned int addPresetURL (const std::string & presetURL,
+ const std::string & presetName,
+ const RatingList & ratingList);
/// Insert a preset url to the play list at the suggested index.
- void insertPresetURL(unsigned int index,
- const std::string & presetURL, const std::string & presetName, const RatingList & ratingList);
+ void insertPresetURL (unsigned int index,
+ const std::string & presetURL,
+ const std::string & presetName,
+ const RatingList & ratingList);
/// Returns true if the selected preset position points to an actual preset in the
/// currently loaded playlist
@@ -214,7 +221,7 @@
/// Returns the preset name associated with a preset index
std::string getPresetName ( unsigned int index ) const;
-
+
void changePresetName ( unsigned int index, std::string name );
/// Returns the rating associated with a preset index
@@ -229,15 +236,15 @@
inline void setShuffleEnabled(bool value)
{
- _settings.shuffleEnabled = value;
+ _settings.shuffleEnabled = value;
- /// idea@ call a virtualfunction shuffleChanged()
+ /// idea@ call a virtualfunction shuffleChanged()
}
inline bool isShuffleEnabled() const
{
- return _settings.shuffleEnabled;
+ return _settings.shuffleEnabled;
}
/// Occurs when active preset has switched. Switched to index is returned
@@ -249,7 +256,7 @@
inline PCM * pcm() {
- return _pcm;
+ return _pcm;
}
void *thread_func(void *vptr_args);
PipelineContext & pipelineContext() { return *_pipelineContext; }
@@ -259,25 +266,26 @@
void selectPrevious(const bool);
void selectNext(const bool);
void selectRandom(const bool);
+
private:
- PCM * _pcm;
+ PCM * _pcm;
double sampledPresetDuration();
- BeatDetect * beatDetect;
- Renderer *renderer;
+ BeatDetect * beatDetect;
+ Renderer *renderer;
PipelineContext * _pipelineContext;
PipelineContext * _pipelineContext2;
- Settings _settings;
+ Settings _settings;
- int wvw; //windowed dimensions
- int wvh;
+ int wvw; //windowed dimensions
+ int wvh;
/** Timing information */
- int mspf;
- int timed;
- int timestart;
- int count;
- float fpsstart;
+ int mspf;
+ int timed;
+ int timestart;
+ int count;
+ float fpsstart;
void readConfig(const std::string &configFile);
void readSettings(const Settings &settings);
@@ -320,8 +328,7 @@
Pipeline* currentPipe;
-void switchPreset(std::auto_ptr<Preset> & targetPreset);
-
-
+ void switchPreset(std::auto_ptr<Preset> & targetPreset);
};
+
#endif
diff --git a/src/libprojectM/sdltoprojectM.h b/src/libprojectM/sdltoprojectM.h
index d2a974d..b38fed5 100644
--- a/src/libprojectM/sdltoprojectM.h
+++ b/src/libprojectM/sdltoprojectM.h
@@ -44,122 +44,128 @@
#include <SDL/SDL.h>
#endif
-inline projectMEvent sdl2pmEvent( SDL_Event event ) { \
-
- switch ( event.type ) { \
- case SDL_VIDEORESIZE:
- return PROJECTM_VIDEORESIZE; \
- case SDL_KEYUP: \
- return PROJECTM_KEYUP; \
- case SDL_KEYDOWN: \
- return PROJECTM_KEYDOWN; \
- default:
- return PROJECTM_KEYUP; \
- } \
- } \
-inline projectMKeycode sdl2pmKeycode( SDLKey keysym ) { \
- switch ( keysym ) { \
- case SDLK_F1: \
- return PROJECTM_K_F1; \
- case SDLK_F2: \
- return PROJECTM_K_F2; \
- case SDLK_F3: \
- return PROJECTM_K_F3; \
- case SDLK_F4: \
- return PROJECTM_K_F4; \
- case SDLK_F5: \
- return PROJECTM_K_F5; \
- case SDLK_F6: \
- return PROJECTM_K_F6; \
- case SDLK_F7: \
- return PROJECTM_K_F7; \
- case SDLK_F8: \
- return PROJECTM_K_F8; \
- case SDLK_F9: \
- return PROJECTM_K_F9; \
- case SDLK_F10: \
- return PROJECTM_K_F10; \
- case SDLK_F11: \
- return PROJECTM_K_F11; \
- case SDLK_F12: \
- return PROJECTM_K_F12; \
- case SDLK_ESCAPE: \
- return PROJECTM_K_ESCAPE;
- case SDLK_a:
- return PROJECTM_K_a;
- case SDLK_b:
- return PROJECTM_K_b;
- case SDLK_c:
- return PROJECTM_K_c;
- case SDLK_d:
- return PROJECTM_K_d;
- case SDLK_e:
- return PROJECTM_K_e;
- case SDLK_f:
- return PROJECTM_K_f;
- case SDLK_g:
- return PROJECTM_K_g;
- case SDLK_h:
- return PROJECTM_K_h;
- case SDLK_i:
- return PROJECTM_K_i;
- case SDLK_j:
- return PROJECTM_K_j;
- case SDLK_k:
- return PROJECTM_K_k;
- case SDLK_l:
- return PROJECTM_K_l;
- case SDLK_m:
- return PROJECTM_K_m;
- case SDLK_n:
- return PROJECTM_K_n;
- case SDLK_o:
- return PROJECTM_K_o;
- case SDLK_p:
- return PROJECTM_K_p;
- case SDLK_q:
- return PROJECTM_K_q;
- case SDLK_r:
- return PROJECTM_K_r;
- case SDLK_s:
- return PROJECTM_K_s;
- case SDLK_t:
- return PROJECTM_K_t;
- case SDLK_u:
- return PROJECTM_K_u;
- case SDLK_v:
- return PROJECTM_K_v;
- case SDLK_w:
- return PROJECTM_K_w;
- case SDLK_x:
- return PROJECTM_K_x;
- case SDLK_y:
- return PROJECTM_K_y;
- case SDLK_z:
- return PROJECTM_K_z;
- case SDLK_UP:
- return PROJECTM_K_UP;
- case SDLK_RETURN:
- return PROJECTM_K_RETURN;
- case SDLK_RIGHT:
- return PROJECTM_K_RIGHT;
- case SDLK_LEFT:
- return PROJECTM_K_LEFT;
- case SDLK_DOWN:
- return PROJECTM_K_DOWN;
- case SDLK_PAGEUP:
- return PROJECTM_K_PAGEUP;
- case SDLK_PAGEDOWN:
- return PROJECTM_K_PAGEDOWN;
-
- default: \
- return PROJECTM_K_NONE; \
- } \
- } \
+inline projectMEvent
+sdl2pmEvent (SDL_Event event)
+{
+ switch (event.type) {
+ case SDL_VIDEORESIZE:
+ return PROJECTM_VIDEORESIZE;
+ case SDL_KEYUP:
+ return PROJECTM_KEYUP;
+ case SDL_KEYDOWN:
+ return PROJECTM_KEYDOWN;
+ default:
+ return PROJECTM_KEYUP;
+ }
+}
-inline projectMModifier sdl2pmModifier( SDLMod mod ) { \
- return PROJECTM_KMOD_LSHIFT; \
- } \
+inline projectMKeycode
+sdl2pmKeycode (SDLKey keysym)
+{
+ switch (keysym) {
+ case SDLK_F1:
+ return PROJECTM_K_F1;
+ case SDLK_F2:
+ return PROJECTM_K_F2;
+ case SDLK_F3:
+ return PROJECTM_K_F3;
+ case SDLK_F4:
+ return PROJECTM_K_F4;
+ case SDLK_F5:
+ return PROJECTM_K_F5;
+ case SDLK_F6:
+ return PROJECTM_K_F6;
+ case SDLK_F7:
+ return PROJECTM_K_F7;
+ case SDLK_F8:
+ return PROJECTM_K_F8;
+ case SDLK_F9:
+ return PROJECTM_K_F9;
+ case SDLK_F10:
+ return PROJECTM_K_F10;
+ case SDLK_F11:
+ return PROJECTM_K_F11;
+ case SDLK_F12:
+ return PROJECTM_K_F12;
+ case SDLK_ESCAPE:
+ return PROJECTM_K_ESCAPE;
+ case SDLK_a:
+ return PROJECTM_K_a;
+ case SDLK_b:
+ return PROJECTM_K_b;
+ case SDLK_c:
+ return PROJECTM_K_c;
+ case SDLK_d:
+ return PROJECTM_K_d;
+ case SDLK_e:
+ return PROJECTM_K_e;
+ case SDLK_f:
+ return PROJECTM_K_f;
+ case SDLK_g:
+ return PROJECTM_K_g;
+ case SDLK_h:
+ return PROJECTM_K_h;
+ case SDLK_i:
+ return PROJECTM_K_i;
+ case SDLK_j:
+ return PROJECTM_K_j;
+ case SDLK_k:
+ return PROJECTM_K_k;
+ case SDLK_l:
+ return PROJECTM_K_l;
+ case SDLK_m:
+ return PROJECTM_K_m;
+ case SDLK_n:
+ return PROJECTM_K_n;
+ case SDLK_o:
+ return PROJECTM_K_o;
+ case SDLK_p:
+ return PROJECTM_K_p;
+ case SDLK_q:
+ return PROJECTM_K_q;
+ case SDLK_r:
+ return PROJECTM_K_r;
+ case SDLK_s:
+ return PROJECTM_K_s;
+ case SDLK_t:
+ return PROJECTM_K_t;
+ case SDLK_u:
+ return PROJECTM_K_u;
+ case SDLK_v:
+ return PROJECTM_K_v;
+ case SDLK_w:
+ return PROJECTM_K_w;
+ case SDLK_x:
+ return PROJECTM_K_x;
+ case SDLK_y:
+ return PROJECTM_K_y;
+ case SDLK_z:
+ return PROJECTM_K_z;
+ case SDLK_UP:
+ return PROJECTM_K_UP;
+ case SDLK_RETURN:
+ return PROJECTM_K_RETURN;
+ case SDLK_RIGHT:
+ return PROJECTM_K_RIGHT;
+ case SDLK_LEFT:
+ return PROJECTM_K_LEFT;
+ case SDLK_DOWN:
+ return PROJECTM_K_DOWN;
+ case SDLK_PAGEUP:
+ return PROJECTM_K_PAGEUP;
+ case SDLK_PAGEDOWN:
+ return PROJECTM_K_PAGEDOWN;
+
+ default:
+ return PROJECTM_K_NONE;
+ }
+}
+
+inline projectMModifier
+sdl2pmModifier (SDLMod mod)
+{
+ return PROJECTM_KMOD_LSHIFT;
+}
#endif /** _SDLTOPROJECTM_H */
diff --git a/src/libprojectM/timer.cpp b/src/libprojectM/timer.cpp
index c347e1e..2dd8282 100644
--- a/src/libprojectM/timer.cpp
+++ b/src/libprojectM/timer.cpp
@@ -27,23 +27,26 @@
#include "timer.h"
#include <stdlib.h>
+
#ifndef WIN32
/** Get number of ticks since the given timestamp */
-unsigned int getTicks( struct timeval *start ) {
- struct timeval now;
- unsigned int ticks;
+unsigned int
+getTicks (struct timeval *start)
+{
+ struct timeval now;
+ unsigned int ticks;
- gettimeofday(&now, NULL);
- ticks=(now.tv_sec-start->tv_sec)*1000+(now.tv_usec-start->tv_usec)/1000;
- return(ticks);
- }
+ gettimeofday (&now, NULL);
+ ticks = (now.tv_sec - start->tv_sec) * 1000
+ + (now.tv_usec - start->tv_usec) / 1000;
+ return (ticks);
+}
#else
-unsigned int getTicks( long start ) {
- return GetTickCount() - start;
- }
+unsigned int
+getTicks (long start)
+{
+ return GetTickCount() - start;
+}
#endif /** !WIN32 */
-
-
-
diff --git a/src/libprojectM/wipemalloc.cpp b/src/libprojectM/wipemalloc.cpp
index 14bcf78..f1b38be 100644
--- a/src/libprojectM/wipemalloc.cpp
+++ b/src/libprojectM/wipemalloc.cpp
@@ -23,22 +23,28 @@
*
* Clean memory allocator
*/
-
#include "wipemalloc.h"
- void *wipemalloc( size_t count ) {
- void *mem = malloc( count );
- if ( mem != NULL ) {
- memset( mem, 0, count );
- } else {
- printf( "wipemalloc() failed to allocate %d bytes\n", (int)count );
- }
- return mem;
+
+/* FIXME: Is there some reason calloc() can't be used? */
+void *
+wipemalloc (size_t count)
+{
+ void *mem = malloc (count);
+
+ if (mem != NULL) {
+ memset (mem, 0, count);
+ } else {
+ printf ("wipemalloc() failed to allocate %d bytes\n", (int) count);
}
+ return mem;
+}
/** Safe memory deallocator */
- void wipefree( void *ptr ) {
- if ( ptr != NULL ) {
- free( ptr );
- }
+void
+wipefree (void *ptr)
+{
+ if (ptr != NULL) {
+ free (ptr);
}
+}