diff --git a/src/projectM-engine/PresetChooser.hpp b/src/projectM-engine/PresetChooser.hpp index 0e64f9d4b..a3b4923cd 100644 --- a/src/projectM-engine/PresetChooser.hpp +++ b/src/projectM-engine/PresetChooser.hpp @@ -66,7 +66,7 @@ public: PresetChooser(const PresetLoader & presetLoader); /// 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 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 @@ -94,6 +94,11 @@ public: }; + /// 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); + /// An STL-esque iterator to begin traversing presets from a directory /// \returns the position of the first preset in the collection PresetIterator begin(); @@ -110,7 +115,6 @@ public: template iterator weightedRandom(WeightFunctor & weightFunctor); - /// Do a weighted sample given a weight functor and default construction (ie. element size) of the weight functor /// \param presetInputs the preset inputs to associate with the preset upon construction /// \param presetOutputs the preset outputs to associate with the preset upon construction @@ -181,6 +185,12 @@ inline PresetIterator PresetChooser::begin() { return pos; } +inline PresetIterator PresetChooser::begin(unsigned int index) { + PresetIterator pos(index); + pos.setChooser(*this); + return pos; +} + inline PresetIterator PresetChooser::end() const { PresetIterator pos(m_presetLoader->getNumPresets()); pos.setChooser(*this); @@ -192,6 +202,7 @@ typename PresetChooser::iterator PresetChooser::weightedRandom(WeightFunctor & w return doWeightedSample(weightFunctor); } + inline bool PresetChooser::empty() const { return m_presetLoader->getNumPresets() == 0; } diff --git a/src/projectM-engine/PresetLoader.cpp b/src/projectM-engine/PresetLoader.cpp index 897aed5e6..81fd983f0 100644 --- a/src/projectM-engine/PresetLoader.cpp +++ b/src/projectM-engine/PresetLoader.cpp @@ -156,3 +156,13 @@ void PresetLoader::handleDirectoryError() } #endif } + + +unsigned int PresetLoader::addPresetURL(const std::string & url) { + m_entries.push_back(url); + + /// @bug strip url out of preset name + m_presetNames.push_back(url); + return m_entries.size()-1; +} + diff --git a/src/projectM-engine/PresetLoader.hpp b/src/projectM-engine/PresetLoader.hpp index fcb1e51d9..1a155ec4d 100644 --- a/src/projectM-engine/PresetLoader.hpp +++ b/src/projectM-engine/PresetLoader.hpp @@ -39,6 +39,13 @@ class PresetLoader { std::auto_ptr loadPreset(unsigned int index, const PresetInputs & presetInputs, PresetOutputs & presetOutputs) const; + + /// Add a preset to the loader's collection. + /// \param presetInputs read only projectM variables to associate with the preset + /// \param presetOutputs the projectM variables the preset will write its final values to + /// \returns The unique index assigned to the preset in the collection. Used with loadPreset + unsigned int addPresetURL ( const std::string & url); + /** Returns the number of presets in the active directory */ inline std::size_t getNumPresets() const { return m_entries.size(); diff --git a/src/projectM-engine/projectM.cpp b/src/projectM-engine/projectM.cpp index 9d135ec1e..a0f0ded52 100755 --- a/src/projectM-engine/projectM.cpp +++ b/src/projectM-engine/projectM.cpp @@ -827,3 +827,24 @@ void projectM::destroyPresetTools() } +int projectM::addPresetURL(const std::string & presetURL) { + return m_presetLoader->addPresetURL(presetURL); +} + +void projectM::selectPreset(unsigned int index) { + + if (m_presetChooser->empty()) + return; + + assert (index < m_presetLoader->getNumPresets()); + assert (index >= 0); + + *m_presetPos = m_presetChooser->begin(index); + + m_activePreset = m_presetPos->allocate(presetInputs, presetOutputs); + + renderer->setPresetName(m_activePreset->presetName()); + + presetInputs.frame = 0; + smoothFrame = 0; +} diff --git a/src/projectM-engine/projectM.hpp b/src/projectM-engine/projectM.hpp index 2eb7940c4..4785f3437 100755 --- a/src/projectM-engine/projectM.hpp +++ b/src/projectM-engine/projectM.hpp @@ -78,7 +78,7 @@ class Preset; class PresetIterator; class PresetChooser; class PresetLoader; -class MoodBar; + //class PresetInputs; //class PresetOutputs; @@ -125,6 +125,10 @@ public: ~projectM(); + + int addPresetURL(const std::string & presetURL); + void selectPreset(unsigned int index); + private: BeatDetect * beatDetect;