Skip to content
Open
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
72 changes: 72 additions & 0 deletions src/ProjectMWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,73 @@

#include <cmath>

#if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2)
static inline projectm_log_level get_projectM_log_level(Poco::Message::Priority log_level)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Pascal case for function and class names and lower Pascal case for variables/arguments to keep things aligned with the existing style:

Suggested change
static inline projectm_log_level get_projectM_log_level(Poco::Message::Priority log_level)
static inline projectm_log_level GetProjectMLogLevel(Poco::Message::Priority logLevel)

(Lower snake case is used primarily in C code, which is why the projectM API uses it)

{
switch (log_level)
{
case Poco::Message::PRIO_FATAL:
return PROJECTM_LOG_LEVEL_FATAL;
case Poco::Message::PRIO_CRITICAL:
case Poco::Message::PRIO_ERROR:
return PROJECTM_LOG_LEVEL_ERROR;
case Poco::Message::PRIO_WARNING:
return PROJECTM_LOG_LEVEL_WARN;
case Poco::Message::PRIO_NOTICE:
case Poco::Message::PRIO_INFORMATION:
return PROJECTM_LOG_LEVEL_INFO;
case Poco::Message::PRIO_DEBUG:
return PROJECTM_LOG_LEVEL_DEBUG;
case Poco::Message::PRIO_TRACE:
return PROJECTM_LOG_LEVEL_TRACE;
default:
if (log_level >= Poco::Message::PRIO_TRACE)
{
return PROJECTM_LOG_LEVEL_TRACE;
}
return PROJECTM_LOG_LEVEL_NOTSET;
}
return PROJECTM_LOG_LEVEL_NOTSET;
}

static inline projectm_log_level get_projectM_log_level(int log_level)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

Suggested change
static inline projectm_log_level get_projectM_log_level(int log_level)
static inline projectm_log_level GetProjectMLogLevel(int logLevel)

{
return get_projectM_log_level(static_cast<Poco::Message::Priority>(log_level));
}

static inline Poco::Message::Priority get_poco_log_level(projectm_log_level log_level)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here:

Suggested change
static inline Poco::Message::Priority get_poco_log_level(projectm_log_level log_level)
static inline Poco::Message::Priority GetPocoLogLevel(projectm_log_level logLevel)

{
switch (log_level)
{
case PROJECTM_LOG_LEVEL_FATAL:
return Poco::Message::PRIO_FATAL;
case PROJECTM_LOG_LEVEL_ERROR:
return Poco::Message::PRIO_ERROR;
case PROJECTM_LOG_LEVEL_WARN:
return Poco::Message::PRIO_WARNING;
case PROJECTM_LOG_LEVEL_INFO:
return Poco::Message::PRIO_INFORMATION;
case PROJECTM_LOG_LEVEL_DEBUG:
return Poco::Message::PRIO_DEBUG;
case PROJECTM_LOG_LEVEL_TRACE:
return Poco::Message::PRIO_TRACE;
default:
if (log_level >= PROJECTM_LOG_LEVEL_FATAL)
{
return Poco::Message::PRIO_FATAL;
}
return static_cast<Poco::Message::Priority>(0);
}
return static_cast<Poco::Message::Priority>(0);
}

static void projectM_log_callback(const char* message, projectm_log_level log_level, void* user_data)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void projectM_log_callback(const char* message, projectm_log_level log_level, void* user_data)
static void ProjectMLogCallback(const char* message, projectm_log_level logLevel, void* userData)

{
Poco::Logger* logger = static_cast<Poco::Logger*>(user_data);
logger->log(Poco::Message("projectM", message, get_poco_log_level(log_level)));
}
#endif // (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2)

const char* ProjectMWrapper::name() const
{
return "ProjectM Wrapper";
Expand All @@ -25,6 +92,11 @@ void ProjectMWrapper::initialize(Poco::Util::Application& app)
_userConfig = projectMSDLApp.UserConfiguration();
poco_information_f1(_logger, "Events enabled: %?d", _projectMConfigView->eventsEnabled());

#if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2)
projectm_set_log_level(get_projectM_log_level(_PMlogger.getLevel()), false);
projectm_set_log_callback(projectM_log_callback, false, &_PMlogger);
#endif

if (!_projectM)
{
auto& sdlWindow = app.getSubsystem<SDLRenderingWindow>();
Expand Down
5 changes: 4 additions & 1 deletion src/ProjectMWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,8 @@ class ProjectMWrapper : public Poco::Util::Subsystem

Poco::NObserver<ProjectMWrapper, PlaybackControlNotification> _playbackControlNotificationObserver{*this, &ProjectMWrapper::PlaybackControlNotificationHandler};

Poco::Logger& _logger{Poco::Logger::get("SDLRenderingWindow")}; //!< The class logger.
Poco::Logger& _logger{Poco::Logger::get("ProjectMWrapper")}; //!< The class logger.
#if (PROJECTM_VERSION_MAJOR >= 4) && (PROJECTM_VERSION_MINOR >=2)
Poco::Logger& _PMlogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be keeping the proper member name casing here, also there's no need to abbreviate the name:

Suggested change
Poco::Logger& _PMlogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM.
Poco::Logger& _projectMLogger{Poco::Logger::get("ProjectM")}; //!< The logger for projectM.

#endif
};