Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 93 additions & 50 deletions src/libprojectM/projectM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ projectM::projectM(Settings settings, int flags):
projectM_resetGL(_settings.windowWidth, _settings.windowHeight);
}

projectM::projectM(ConfigPreset configPreset, int flags)
: _pcm(0),
beatDetect(0),
renderer(0),
_pipelineContext(new PipelineContext()),
_pipelineContext2(new PipelineContext()),
m_presetPos(0),
timeKeeper(NULL),
m_flags(flags),
_matcher(NULL),
_merger(NULL)
{
if (!configPreset.config_file.empty())
{
readConfig(configPreset.config_file, configPreset.settings);
}
else
{
readSettings(configPreset.settings);
}
projectM_reset();
projectM_resetGL(_settings.windowWidth, _settings.windowHeight);
}

bool projectM::writeConfig(const std::string & configFile, const Settings & settings) {

Expand Down Expand Up @@ -157,82 +180,102 @@ bool projectM::writeConfig(const std::string & configFile, const Settings & sett
return false;
}


void projectM::readConfig(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", settings.meshX);
_settings.meshY = config.read<int>("Mesh Y", settings.meshY);
_settings.textureSize = config.read<int>("Texture Size", settings.textureSize);
_settings.fps = config.read<int>("FPS", settings.fps);
_settings.windowWidth = config.read<int>("Window Width", settings.windowWidth);
_settings.windowHeight = config.read<int>("Window Height", settings.windowHeight);
_settings.smoothPresetDuration = config.read<int>("Smooth Preset Duration",
config.read<int>("Smooth Transition Duration", settings.smoothPresetDuration));
_settings.presetDuration = config.read<int>("Preset Duration", settings.presetDuration);

_settings.presetURL = config.read<string>("Preset Path", settings.presetURL);

_settings.titleFontURL = config.read<string>("Title Font", settings.titleFontURL);
_settings.menuFontURL = config.read<string>("Menu Font", settings.menuFontURL);

_settings.shuffleEnabled = config.read<bool>("Shuffle Enabled", settings.shuffleEnabled);

_settings.easterEgg = config.read<float>("Easter Egg Parameter", settings.easterEgg);
_settings.softCutRatingsEnabled =
config.read<bool>("Soft Cut Ratings Enabled", settings.softCutRatingsEnabled);

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", settings.aspectCorrection))
{
_settings.aspectCorrection = true;
renderer->correction = true;
}
else
{
_settings.aspectCorrection = false;
renderer->correction = false;
}
}

void projectM::readConfig (const std::string & configFile )
{
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 );
// if you read a config file with no default settings supplied, we will set them here before loading them with defaults.
projectM::Settings settings;
settings.meshX = 32;
settings.meshY = 24;
settings.textureSize = 512;
settings.fps = 35;
settings.windowWidth = 512;
settings.windowHeight = 512;
settings.smoothPresetDuration = 10;
settings.presetDuration = 15;

#ifdef __unix__
_settings.presetURL = config.read<string> ( "Preset Path", "/usr/local/share/projectM/presets" );
settings.presetURL = "/usr/local/share/projectM/presets";
#endif

#ifdef __APPLE__
/// @bug awful hardcoded hack- need to add intelligence to cmake wrt bundling - carm
_settings.presetURL = config.read<string> ( "Preset Path", "../Resources/presets" );
settings.presetURL = "../Resources/presets";
#endif

#ifdef WIN32
_settings.presetURL = config.read<string> ( "Preset Path", "/usr/local/share/projectM/presets" );
settings.presetURL = "/usr/local/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");
settings.titleFontURL = "../Resources/fonts/Vera.tff";
settings.menuFontURL = "../Resources/fonts/VeraMono.ttf";
#endif

#ifdef __unix__
_settings.titleFontURL = config.read<string>
( "Title Font", "/usr/local/share/projectM/fonts/Vera.tff" );
_settings.menuFontURL = config.read<string>
( "Menu Font", "/usr/local/share/projectM/fonts/VeraMono.tff" );
settings.titleFontURL = "/usr/local/share/projectM/fonts/Vera.tff";
settings.menuFontURL = "/usr/local/share/projectM/fonts/VeraMono.tff";
#endif

#ifdef WIN32
_settings.titleFontURL = config.read<string>
( "Title Font", projectM_FONT_TITLE );
_settings.menuFontURL = config.read<string>
( "Menu Font", projectM_FONT_MENU );
settings.titleFontURL = projectM_FONT_TITLE;
settings.menuFontURL = projectM_FONT_MENU;
#endif

settings.shuffleEnabled = 1;

_settings.shuffleEnabled = config.read<bool> ( "Shuffle Enabled", true);

_settings.easterEgg = config.read<float> ( "Easter Egg Parameter", 0.0);
_settings.softCutRatingsEnabled =
config.read<bool> ( "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;
}
settings.easterEgg = 0.0;
settings.softCutRatingsEnabled = 0;

settings.beatSensitivity = 10.0;

settings.aspectCorrection = 1;

// now load the config with default settings.
readConfig(configFile, settings);
}


Expand Down
8 changes: 8 additions & 0 deletions src/libprojectM/projectM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,15 @@ class DLLEXPORT projectM
softCutRatingsEnabled(false) {}
};

struct ConfigPreset
{
std::string config_file;
Settings settings;
};

projectM(std::string config_file, int flags = FLAG_NONE);
projectM(Settings settings, int flags = FLAG_NONE);
projectM(ConfigPreset configPreset, int flags = FLAG_NONE);

void projectM_resetGL( int width, int height );
void projectM_resetTextures();
Expand Down Expand Up @@ -310,6 +317,7 @@ class DLLEXPORT projectM
float fpsstart;

void readConfig(const std::string &configFile);
void readConfig(const std::string &configFile, const Settings &settings);
void readSettings(const Settings &settings);
void projectM_init(int gx, int gy, int fps, int texsize, int width, int height);
void projectM_reset();
Expand Down
8 changes: 8 additions & 0 deletions src/projectM-sdl/pmSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ projectMSDL::projectMSDL(std::string config_file, int flags) : projectM(config_f
isFullScreen = false;
}

projectMSDL::projectMSDL(ConfigPreset configPreset, int flags) : projectM(configPreset, flags)
{
width = getWindowWidth();
height = getWindowHeight();
done = 0;
isFullScreen = false;
}

void projectMSDL::init(SDL_Window *window, SDL_GLContext *_glCtx, const bool _renderToTexture) {
win = window;
glCtx = _glCtx;
Expand Down
3 changes: 2 additions & 1 deletion src/projectM-sdl/pmSDL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#define DATADIR_PATH "."
#warning "DATADIR_PATH is not defined - falling back to ./"
#else
#define DATADIR_PATH "/usr/local/share/projectM"
#define DATADIR_PATH "/usr/local/share/projectM/"
#ifndef WIN32
#warning "DATADIR_PATH is not defined - falling back to /usr/local/share/projectM"
#endif /** WIN32 */
Expand All @@ -90,6 +90,7 @@ class projectMSDL : public projectM {
bool done;
projectMSDL(Settings settings, int flags);
projectMSDL(std::string config_file, int flags);
projectMSDL(ConfigPreset configPreset, int flags);
void init(SDL_Window *window, SDL_GLContext *glCtx, const bool renderToTexture = false);
int openAudioInput();
int toggleAudioInput();
Expand Down
Loading