mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-02-12 02:55:40 +00:00
- added preset loader to build list. it builds but still incomplete
- preset class extended to handle partial initialization - preset switcher is #ifdef zeroed git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/personal/carm/dev-1.0@229 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
@ -6,7 +6,7 @@ Func.h Func.cpp Eval.cpp wipemalloc.h browser.cpp PerFrameEqn.cpp PerPointEqn.cp
|
||||
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)
|
||||
ParamUtils.hpp PresetLoader.cpp PresetLoader.hpp)
|
||||
|
||||
OPTION(USE_FTGL "Use FTGL for on-screen fonts" ON)
|
||||
|
||||
|
||||
@ -35,16 +35,30 @@
|
||||
|
||||
|
||||
|
||||
|
||||
Preset::Preset(const std::string & filename):
|
||||
file_path(filename),
|
||||
customWaves(0),
|
||||
customShapes(0) {}
|
||||
|
||||
Preset::Preset(const PresetInputs * presetInputs, PresetOutputs * presetOutputs, const std::string & filename):
|
||||
file_path(filename),
|
||||
builtinParams(*presetInputs, *presetOutputs),
|
||||
customWaves(presetOutputs->customWaves),
|
||||
customShapes(presetOutputs->customShapes)
|
||||
customWaves(&presetOutputs->customWaves),
|
||||
customShapes(&presetOutputs->customShapes)
|
||||
{
|
||||
|
||||
initialize(filename);
|
||||
|
||||
}
|
||||
|
||||
/// @bug is memory properly deallocated? verify
|
||||
void Preset::setIO(const PresetInputs * presetInputs, PresetOutputs * presetOutputs) {
|
||||
builtinParams = BuiltinParams(*presetInputs, *presetOutputs);
|
||||
customWaves = &presetOutputs->customWaves;
|
||||
customShapes = &presetOutputs->customShapes;
|
||||
initialize(file_path);
|
||||
}
|
||||
|
||||
Preset::~Preset() {
|
||||
|
||||
@ -93,7 +107,7 @@ void Preset::evalCustomWaveInitConditions() {
|
||||
|
||||
void Preset::evalCustomWavePerFrameEquations() {
|
||||
|
||||
for (cwave_container::iterator pos = customWaves.begin(); pos != customWaves.end(); ++pos) {
|
||||
for (cwave_container::iterator pos = customWaves->begin(); pos != customWaves->end(); ++pos) {
|
||||
(*pos)->init_cond_tree->splay_traverse((void (*)(void*))eval_init_cond_helper);
|
||||
(*pos)->per_frame_eqn_tree->splay_traverse((void (*)(void*))eval_per_frame_eqn_helper);
|
||||
}
|
||||
@ -102,7 +116,7 @@ void Preset::evalCustomWavePerFrameEquations() {
|
||||
|
||||
void Preset::evalCustomShapePerFrameEquations() {
|
||||
|
||||
for (cshape_container::iterator pos = customShapes.begin(); pos != customShapes.end(); ++pos) {
|
||||
for (cshape_container::iterator pos = customShapes->begin(); pos != customShapes->end(); ++pos) {
|
||||
(*pos)->init_cond_tree->splay_traverse((void (*)(void*))eval_init_cond_helper);
|
||||
(*pos)->per_frame_eqn_tree->splay_traverse((void (*)(void*))eval_per_frame_eqn_helper);
|
||||
}
|
||||
@ -685,7 +699,9 @@ void Preset::load_init_conditions() {
|
||||
CustomWave * Preset::find_custom_wave(int id, bool create_flag) {
|
||||
CustomWave * custom_wave = NULL;
|
||||
|
||||
if ((custom_wave = customWaves[id]) == NULL) {
|
||||
assert(customWaves);
|
||||
|
||||
if ((custom_wave = (*customWaves)[id]) == NULL) {
|
||||
|
||||
if (CUSTOM_WAVE_DEBUG) { printf("find_custom_wave: creating custom wave (id = %d)...", id);fflush(stdout);}
|
||||
|
||||
@ -699,7 +715,7 @@ CustomWave * Preset::find_custom_wave(int id, bool create_flag) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
customWaves.push_back(custom_wave);
|
||||
customWaves->push_back(custom_wave);
|
||||
}
|
||||
|
||||
return custom_wave;
|
||||
@ -710,8 +726,8 @@ CustomWave * Preset::find_custom_wave(int id, bool create_flag) {
|
||||
CustomShape * Preset::find_custom_shape(int id, bool create_flag) {
|
||||
|
||||
CustomShape * custom_shape = NULL;
|
||||
|
||||
if ((custom_shape = (CustomShape*)this->customShapes[id]) == NULL) {
|
||||
assert(customShapes);
|
||||
if ((custom_shape = (*customShapes)[id]) == NULL) {
|
||||
|
||||
if (CUSTOM_SHAPE_DEBUG) { printf("find_custom_shape: creating custom shape (id = %d)...", id);fflush(stdout);}
|
||||
|
||||
@ -725,7 +741,7 @@ CustomShape * Preset::find_custom_shape(int id, bool create_flag) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
customShapes.push_back(custom_shape);
|
||||
customShapes->push_back(custom_shape);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -64,8 +64,15 @@ public:
|
||||
* Most common way to allocate new preset */
|
||||
Preset(const PresetInputs * presetInputs, PresetOutputs * presetOutputs, const std::string & filename);
|
||||
|
||||
/** Initializes a preset object and stores the filename associated with it. The preset is NOT properly initialize
|
||||
* until a call to member function setIO is made */
|
||||
Preset(const std::string & filename);
|
||||
|
||||
~Preset();
|
||||
|
||||
/** Set or reset the input and output associations for this preset. */
|
||||
void setIO(const PresetInputs * presetInputs, PresetOutputs * presetOutputs);
|
||||
|
||||
/** Evaluates the preset for a frame given the current values of preset inputs / outputs */
|
||||
void evaluateFrame();
|
||||
|
||||
@ -148,8 +155,8 @@ private:
|
||||
void evalPerPixelEqns();
|
||||
void evalPerFrameEquations();
|
||||
|
||||
cwave_container & customWaves;
|
||||
cshape_container & customShapes;
|
||||
cwave_container * customWaves;
|
||||
cshape_container * customShapes;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -11,27 +11,34 @@
|
||||
//
|
||||
#include "PresetLoader.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#include <sstream>
|
||||
extern "C" {
|
||||
#include <errno.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/dirent.h>
|
||||
|
||||
#include <dirent.h>
|
||||
}
|
||||
|
||||
PresetLoader::PresetLoader(std::string pathame) {
|
||||
PresetLoader::PresetLoader(std::string dirname) :m_dirname(dirname)
|
||||
{
|
||||
// Do one scan
|
||||
rescan();
|
||||
}
|
||||
|
||||
void PresetLoader::setScanDirectory(std::string dirname) {
|
||||
m_dirname = dirname;
|
||||
}
|
||||
|
||||
void PresetLoader::rescan() {
|
||||
|
||||
// Clear the directory entry collection
|
||||
m_entries.clear();
|
||||
|
||||
// If directory already opened, close it first
|
||||
if (m_dir) {
|
||||
closedir(dir);
|
||||
closedir(m_dir);
|
||||
}
|
||||
|
||||
// Allocate a new a stream given the current diectory name
|
||||
if ((m_dir = opendir(m_dirname)) == NULL) {
|
||||
if ((m_dir = opendir(m_dirname.c_str())) == NULL) {
|
||||
handleDirectoryError();
|
||||
}
|
||||
|
||||
@ -50,14 +57,13 @@ while ((dir_entry = readdir(m_dir)) != NULL) {
|
||||
continue;
|
||||
|
||||
// Create full path name
|
||||
out << dirname << PATH_SEPARATOR << filename;
|
||||
out << m_dirname << PATH_SEPARATOR << filename;
|
||||
|
||||
// Save to our directory entry collcetion
|
||||
m_entries.add(out.str());
|
||||
// Add to our directory entry collection
|
||||
m_entries.push_back(out.str());
|
||||
|
||||
// We can now toss out the directory entry struct
|
||||
free(dir_entry);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,33 +1,25 @@
|
||||
#ifndef __PRESET_LOADER_HPP
|
||||
#define __PRESET_LOADER_HPP
|
||||
|
||||
#include <string>
|
||||
#include "Preset.hpp"
|
||||
|
||||
#ifdef LINUX
|
||||
extern "C" {
|
||||
#include <sys/inotify.h>
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "StaticArray.hpp"
|
||||
|
||||
class PresetLoader {
|
||||
|
||||
|
||||
public:
|
||||
static const std::string PROJECTM_FILE_EXTENSION = ".prjm";
|
||||
static const std::string MILKDROP_FILE_EXTENSION = ".milk";
|
||||
static const std::string PROJECTM_FILE_EXTENSION;
|
||||
static const std::string MILKDROP_FILE_EXTENSION;
|
||||
|
||||
#ifdef LINUX
|
||||
static const std::string PATH_SEPARTOR = "/";
|
||||
static const char PATH_SEPARTOR = '/';
|
||||
#endif
|
||||
|
||||
#ifdef MACOS
|
||||
static const std::string PATH_SEPARTOR = "/";
|
||||
static const char PATH_SEPARTOR = '/';
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
static const std::string PATH_SEPARTOR = "\";
|
||||
static const char PATH_SEPARATOR = '\';
|
||||
#endif
|
||||
|
||||
|
||||
@ -39,8 +31,8 @@ class PresetLoader {
|
||||
|
||||
/** Load a preset by indexing the collection of presets from a directory */
|
||||
/** Autopointers: when you take it, I leave it */
|
||||
auto_ptr<Preset> loadPreset(unsigned int index);
|
||||
auto_ptr<Preset> loadPreset(std::string filename);
|
||||
// auto_ptr<Preset> loadPreset(unsigned int index, const PresetInputs & presetInputs, PresetOutputs & presetOutputs);
|
||||
// auto_ptr<Preset> loadPreset(std::string filename);
|
||||
|
||||
/** Returns the number of presets in the active directory */
|
||||
inline std::size_t getNumPresets() {
|
||||
@ -48,18 +40,18 @@ class PresetLoader {
|
||||
}
|
||||
|
||||
/** Sets the directory where the loader will search for files */
|
||||
void setScanDirectory(std::string pathname);
|
||||
void setScanDirectory(std::string pathname);
|
||||
|
||||
/** Rescans the active preset directory */
|
||||
void rescan();
|
||||
|
||||
|
||||
private:
|
||||
const std::string m_dirname;
|
||||
int m_activeIndex;
|
||||
void handleDirectoryError();
|
||||
std::string m_dirname;
|
||||
DIR * m_dir;
|
||||
std::vector<std::string> m_entries;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
//
|
||||
//
|
||||
|
||||
#if 0
|
||||
|
||||
#include "PresetSwitcher.hpp"
|
||||
|
||||
int PresetSwitcher::destroyPresetLoader() {
|
||||
@ -394,3 +396,4 @@ int PresetSwitcher::is_valid_extension(const struct dirent* ent) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -58,8 +58,6 @@ extern FILE *fmemopen(void *buf, size_t len, const char *pMode);
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define PROJECTM_FILE_EXTENSION ".prjm"
|
||||
#define MILKDROP_FILE_EXTENSION ".milk"
|
||||
|
||||
#define MAX_DOUBLE_SIZE 10000000.0
|
||||
#define MIN_DOUBLE_SIZE -10000000.0
|
||||
|
||||
@ -155,22 +155,22 @@ void projectM::default_key_handler( projectMEvent event, projectMKeycode keycode
|
||||
case PROJECTM_K_b:
|
||||
break;
|
||||
case PROJECTM_K_n:
|
||||
if (PresetSwitcher::switchPreset(ALPHA_NEXT, HARD_CUT) < 0) {
|
||||
// if (PresetSwitcher::switchPreset(ALPHA_NEXT, HARD_CUT) < 0) {
|
||||
printf("WARNING: Bad preset file, not handling this..aborting!\n");
|
||||
abort();
|
||||
}
|
||||
// }
|
||||
break;
|
||||
case PROJECTM_K_r:
|
||||
if (PresetSwitcher::switchPreset(RANDOM_NEXT, HARD_CUT) < 0) {
|
||||
// if (PresetSwitcher::switchPreset(RANDOM_NEXT, HARD_CUT) < 0) {
|
||||
printf("WARNING: Bad preset file, loading idle preset\n");
|
||||
abort();
|
||||
}
|
||||
// }
|
||||
break;
|
||||
case PROJECTM_K_p:
|
||||
if ((PresetSwitcher::switchPreset(ALPHA_PREVIOUS, HARD_CUT)) < 0){
|
||||
// if ((PresetSwitcher::switchPreset(ALPHA_PREVIOUS, HARD_CUT)) < 0){
|
||||
printf("WARNING: Bad preset file, loading idle preset\n");
|
||||
abort();
|
||||
}
|
||||
// }
|
||||
break;
|
||||
case PROJECTM_K_l:
|
||||
if (renderer->noSwitch==0)renderer->noSwitch=1; else renderer->noSwitch=0;
|
||||
|
||||
Reference in New Issue
Block a user