diff --git a/src/linux/projectmDev10.kdevelop b/src/linux/projectmDev10.kdevelop
index 15951b919..f371c4e22 100644
--- a/src/linux/projectmDev10.kdevelop
+++ b/src/linux/projectmDev10.kdevelop
@@ -10,16 +10,16 @@
projectmDev10
../../
false
-
-
+
+
kdevsubversion
executable
/home/carm/projects/projectM/dev-1.0
-
-
+
+
/home/carm/projects/projectM/dev-1.0
false
false
@@ -51,9 +51,9 @@
0
-
-
-
+
+
+
default
@@ -64,9 +64,9 @@
1
0
false
-
-
-
+
+
+
default
@@ -75,11 +75,11 @@
-
-
-
-
-
+
+
+
+
+
true
false
false
@@ -156,30 +156,30 @@
- false
+ true
true
true
- 250
+ 100
400
250
false
0
- true
+ false
true
- false
+ true
std=_GLIBCXX_STD;__gnu_cxx=std
true
- false
- false
- false
- false
+ true
+ true
+ true
+ true
true
true
- false
+ true
.;
-
+
set
m_,_
theValue
@@ -195,7 +195,7 @@
- .h
+ .hpp
.cpp
@@ -210,4 +210,11 @@
false
+
+
+
+
+
+
+
diff --git a/src/projectM-engine/CMakeLists.txt b/src/projectM-engine/CMakeLists.txt
index 2e74f3f8c..bc133360b 100644
--- a/src/projectM-engine/CMakeLists.txt
+++ b/src/projectM-engine/CMakeLists.txt
@@ -5,8 +5,8 @@ Param.cpp CustomWave.cpp CustomShape.h CustomShape.cpp Param.h CustomWave.h Beat
Func.h Func.cpp Eval.cpp wipemalloc.h browser.cpp PerFrameEqn.cpp PerPointEqn.cpp editor.cpp fftsg.cpp glConsole.cpp
CValue.h Expr.h timer.cpp wipemalloc.cpp PerFrameEqn.h PerPixelEqn.h PerPointEqn.h browser.h BuiltinFuncs.hpp
BuiltinFuncs.cpp compare.h editor.h event.h fatal.h SplayTree.hpp fftsg.h glConsole.h menu.h timer.h SplayNode.hpp
-BuiltinParams.hpp BuiltinParams.cpp Preset.hpp PresetSwitcher.hpp PresetSwitcher.cpp Renderer.cpp Renderer.hpp
-ParamUtils.hpp PresetLoader.cpp PresetLoader.hpp)
+BuiltinParams.hpp BuiltinParams.cpp Preset.hpp Renderer.cpp Renderer.hpp
+ParamUtils.hpp PresetLoader.cpp PresetLoader.hpp PresetChooser.hpp PresetChooser.cpp)
OPTION(USE_FTGL "Use FTGL for on-screen fonts" ON)
diff --git a/src/projectM-engine/PresetChooser.hpp b/src/projectM-engine/PresetChooser.hpp
index f7fea55af..63cb38503 100644
--- a/src/projectM-engine/PresetChooser.hpp
+++ b/src/projectM-engine/PresetChooser.hpp
@@ -5,7 +5,7 @@
* DECISION: Merging / etc. goes in PresetFilters.hpp! Loading goes in here, switching goes in here
*/
-/// More specifically, we need to
+/// More specifically, we need to
/// (1) load presets from a path(s)
/// (2) set which preset is the "active" presets
/// (3) merge two presets together - probably doesn't belong in this class
@@ -18,91 +18,132 @@
#define PRESET_CHOOSER_HPP
#include "Preset.hpp"
#include "projectM.h"
+#include "PresetLoader.hpp"
+#include
class PresetChooser {
public:
+ /// \brief Initializes a chooser with an established preset loader.
+ /// \param presetLoader an initalized 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): m_presetLoader(&presetLoader) {}
+
+ class PresetIterator {
+
+ public:
+ PresetIterator() {}
+
+ /** @brief Instantiate a preset iterator at the given starting position **/
+ PresetIterator(std::size_t start):m_currentIndex(start) {}
+
+ void operator++() {
+ assert(m_currentIndex < m_presetChooser->getNumPresets());
+ m_currentIndex++;
+ }
+
+ bool operator !=(const PresetIterator & presetPos) {
+ return (*presetPos != **this);
+ }
+
+ void operator--() {
+ assert(m_currentIndex > 0);
+ m_currentIndex--;
+
+ }
+
+ std::size_t operator*() const {
+ return m_currentIndex;
+ }
+
+ std::auto_ptr allocate(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) {
+ return m_presetChooser->directoryIndex(m_currentIndex, presetInputs, presetOutputs);
+ }
+
+
// Used for aribtrary randomness
typedef PresetIterator iterator;
- /** Initializes a chooser with an established preset loader. Note that the loader must be
- * refreshed via events or otherwise *outside* this class's scope **/
- PresetChooser(const PresetLoader & presetLoader);
+ inline void setChooser(const PresetChooser & chooser) {
+ m_presetChooser = &chooser;
+ }
- class PresetIterator {
+ private:
+ std::size_t m_currentIndex;
+ const PresetChooser * m_presetChooser;
- PresetIterator():m_chooser(0) {}
- void operator++() {
- assert(m_currentIndex < (m_presetLoader.getNumPresets()-1));
- m_currentIndex++;
- }
-
- void operator--() {
- assert(m_currentIndex > 0);
- m_currentIndex--;
- }
-
- std::size_t operator*() {
- return m_currentIndex;
- }
-
- std::auto_ptr allocate(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) {
- return m_presetChooser.directoryIndex(m_currentIndex, presetInputs, presetOutputs);
- }
-
- private:
- std::size_t m_currentIndex;
- inline void setChooser(const PresetChooser & chooser) {
-
- m_presetChooser = &chooser;
- }
- const PresetChooser * m_presetChooser;
};
/** Choose a preset via the passed in index. Must be between 0 and num valid presets in directory **/
- std::auto_ptr directoryIndex(std::size_int index, const PresetInputs & presetInputs,
- PresetOutputs & presetOutputs) const;
+ std::auto_ptr directoryIndex(std::size_t index, const PresetInputs & presetInputs,
+ PresetOutputs & presetOutputs) const;
- class UniformRandomFunctor {
-
- public:
- UniformRandomFunctor(std::size_t collectionSize):m_collectionSize(collectionSize) {}
-
- std::size_t operator() (std::size_t index) {
- return (1.0 / (float)m_collectionSize);
- }
+ std::size_t getNumPresets() const {
+ return m_presetLoader->getNumPresets();
+ }
- private:
- std::size_t m_collectionSize;
+ class UniformRandomFunctor {
+
+ public:
+ UniformRandomFunctor(std::size_t collectionSize):m_collectionSize(collectionSize) {}
+
+ std::size_t operator() (std::size_t index) {
+ return (1.0 / m_collectionSize);
+
+ }
+
+ private:
+ std::size_t m_collectionSize;
};
-
- /** Samples from the preset collection **/
- template
- std::auto_ptr weightedRandom(const PresetInputs & presetInputs, PresetOutputs & presetOutputs, WeightFunctor & weightFunctor) const {
-
-
- // Choose a random index from the preset directory
- float cutoff = ((float)(random())) / RAND_MAX;
- float mass = 0;
-
- for(iterator pos = this->begin();pos != this->end() ; ++pos) {
- mass += weightFunctor(*pos);
- if (mass >= cutoff)
- return pos.allocate(presetInputs,presetOutputs);
- }
-
- }
-
- };
-
-
-/* destroyPresetLoader: closes the preset
- loading library. This should be done when
- PresetChooser does cleanup */
+ PresetIterator begin() {
+ PresetIterator pos;
+ pos.setChooser(*this);
+ return pos;
+ }
+
+ PresetIterator end() {
+ PresetIterator pos(m_presetLoader->getNumPresets());
+ return pos;
+ }
+
+ /** Samples from the preset collection **/
+ template
+ std::auto_ptr weightedRandom(const PresetInputs & presetInputs, PresetOutputs & presetOutputs, WeightFunctor & weightFunctor) const {
+ doWeightedSample(weightFunctor);
+ }
+
+ /** Samples from the preset collection **/
+ template
+ std::auto_ptr weightedRandom(const PresetInputs & presetInputs, PresetOutputs & presetOutputs) const {
+
+ WeightFunctor weightFunctor(m_presetLoader->getNumPresets());
+ doWeightedSample(weightFunctor);
+
+ }
+
+
+private:
+ template
+ std::auto_ptr doWeightedSample(WeightFunctor & weightFunctor, const PresetInputs & presetInputs, PresetOutputs & presetOutputs) {
+
+ // Choose a random index from the preset directory
+ float cutoff = ((float)(random())) / RAND_MAX;
+ float mass = 0;
+
+ for (PresetIterator pos = this->begin();pos != this->end() ; ++pos) {
+ mass += weightFunctor(*pos);
+ if (mass >= cutoff)
+ return pos.allocate(presetInputs, presetOutputs);
+ }
+ }
+
+
+ private:
+ const PresetLoader * m_presetLoader;
};
#endif
diff --git a/src/projectM-engine/PresetLoader.cpp b/src/projectM-engine/PresetLoader.cpp
index 0a8eda823..19e906fda 100644
--- a/src/projectM-engine/PresetLoader.cpp
+++ b/src/projectM-engine/PresetLoader.cpp
@@ -69,7 +69,7 @@ while ((dir_entry = readdir(m_dir)) != NULL) {
}
-std::auto_ptr PresetLoader::loadPreset(unsigned int index, const PresetInputs & presetInputs, PresetOutputs & presetOutputs) {
+std::auto_ptr PresetLoader::loadPreset(unsigned int index, const PresetInputs & presetInputs, PresetOutputs & presetOutputs) const {
// Check that index isn't insane
assert(index >= 0);
diff --git a/src/projectM-engine/PresetLoader.hpp b/src/projectM-engine/PresetLoader.hpp
index 374ae006a..fead4ff0a 100644
--- a/src/projectM-engine/PresetLoader.hpp
+++ b/src/projectM-engine/PresetLoader.hpp
@@ -32,10 +32,10 @@ class PresetLoader {
/** Load a preset by specifying a filename of the directory (that is, NOT full path) */
/** Autopointers: when you take it, I leave it */
std::auto_ptr loadPreset(unsigned int index, const PresetInputs & presetInputs,
- PresetOutputs & presetOutputs);
+ PresetOutputs & presetOutputs) const;
/** Returns the number of presets in the active directory */
- inline std::size_t getNumPresets() {
+ inline std::size_t getNumPresets() const {
return m_entries.size();
}
diff --git a/src/projectM-engine/console_interface.cpp b/src/projectM-engine/console_interface.cpp
index 3b7610d88..265eda892 100755
--- a/src/projectM-engine/console_interface.cpp
+++ b/src/projectM-engine/console_interface.cpp
@@ -31,9 +31,10 @@
#include "editor.h"
#include "event.h"
#include "BeatDetect.h"
-#include "PresetSwitcher.hpp"
+#include "PresetChooser.hpp"
-Preset *active_preset;
+PresetChooser::PresetIterator presetPos;
+PresetChooser * activeChooser;
interface_t current_interface;// = DEFAULT_INTERFACE;
@@ -167,6 +168,12 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode
// }
break;
case PROJECTM_K_p:
+ if (presetPos != activeChooser->begin()) {
+ --presetPos;
+ // ...mroe
+ }
+
+
// if ((PresetSwitcher::switchPreset(ALPHA_PREVIOUS, HARD_CUT)) < 0){
printf("WARNING: Bad preset file, loading idle preset\n");
abort();