Skip to content

Commit

Permalink
WORKING COMMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
kblaschke committed Jan 19, 2024
1 parent 57298cb commit 2451fef
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 30 deletions.
52 changes: 49 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,64 @@ set(CMAKE_POSITION_INDEPENDENT_CODE YES)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

project(projectM-SDL
project(projectMSDL
LANGUAGES C CXX
VERSION 2.0.0
)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Default install layouts.
option(ENABLE_FLAT_PACKAGE "Creates a \"flat\" install layout with files and preset/texture dirs directly in the main dir." OFF)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT ENABLE_FLAT_PACKAGE)
include(GNUInstallDirs)

set(PROJECTMSDL_BIN_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Directory to install executables in, relative to the install prefix.")
set(PROJECTMSDL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Directory to install additional libraries in, relative to the install prefix.")
set(PROJECTMSDL_DATA_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}" CACHE STRING "Directory to install the config file, presets and texture, relative to the install prefix.")
set(PROJECTMSDL_PRESETS_DIR "${PROJECTMSDL_DATA_DIR}/presets" CACHE STRING "Directory to install optional preset files, relative to the install prefix.")
set(PROJECTMSDL_TEXTURES_DIR "${PROJECTMSDL_DATA_DIR}/textures" CACHE STRING "Directory to install optional texture files, relative to the install prefix.")

# Additional options for desktop integration
option(ENABLE_DESKTOP_ICON "Install a .desktop file and icons" ON)
set(PROJECTMSDL_DESKTOP_DIR "${CMAKE_INSTALL_DATAROOTDIR}/applications" CACHE STRING "Directory to install the .desktop file in, relative to the install prefix.")
set(PROJECTMSDL_ICONS_DIR "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor" CACHE STRING "Directory to install the icons in, relative to the install prefix.")

GNUInstallDirs_get_absolute_install_dir(_config_dir_abs_init PROJECTMSDL_CONFIG_DIR DATAROOTDIR)
set(DEFAULT_CONFIG_PATH "${_config_dir_abs_init}" CACHE STRING "Optional path to look for the configuration file in addition to PROJECTMSDL_BIN_DIR.")
set(DEFAULT_PRESETS_PATH "${_config_dir_abs_init}/presets" CACHE STRING "Default presets path in the configuration file.")
set(DEFAULT_TEXTURES_PATH "${_config_dir_abs_init}/textures" CACHE STRING "Default textures path in the configuration file.")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_FLAT_PACKAGE)
# Package as .app bundle on macOS
set(BUNDLE_BASE_DIR "projectM.app/Contents")
set(PROJECTMSDL_BIN_DIR "${BUNDLE_BASE_DIR}/MacOS" CACHE STRING "Directory to install executables in, relative to the install prefix.")
set(PROJECTMSDL_LIB_DIR "${BUNDLE_BASE_DIR}/PlugIns" CACHE STRING "Directory to install additional libraries in, relative to the install prefix.")
set(PROJECTMSDL_DATA_DIR "{BUNDLE_BASE_DIR}/Resources" CACHE STRING "Directory to install the config file, presets and texture, relative to the install prefix.")
set(PROJECTMSDL_PRESETS_DIR "${PROJECTMSDL_DATA_DIR}/Presets" CACHE STRING "Directory to install optional preset files, relative to the install prefix.")
set(PROJECTMSDL_TEXTURES_DIR "${PROJECTMSDL_DATA_DIR}/Textures" CACHE STRING "Directory to install optional texture files, relative to the install prefix.")

set(DEFAULT_CONFIG_PATH "\${application.dir}/../Resources" CACHE STRING "Optional path to look for the configuration file in addition to PROJECTMSDL_BIN_DIR.")
set(DEFAULT_PRESETS_PATH "\${application.dir}/../Resources/Presets" CACHE STRING "Default presets path in the configuration file.")
set(DEFAULT_TEXTURES_PATH "\${application.dir}/../Resources/Presets" CACHE STRING "Default textures path in the configuration file.")
else()
# Windows and others: use flat layout.
set(PROJECTMSDL_BIN_DIR "." CACHE STRING "Directory to install executables in, relative to the install prefix.")
set(PROJECTMSDL_LIB_DIR "." CACHE STRING "Directory to install additional libraries in, relative to the install prefix.")
set(PROJECTMSDL_DATA_DIR "." CACHE STRING "Directory to install the config file, presets and texture, relative to the install prefix.")
set(PROJECTMSDL_PRESETS_DIR "${PROJECTMSDL_DATA_DIR}/presets" CACHE STRING "Directory to install optional preset files, relative to the install prefix.")
set(PROJECTMSDL_TEXTURES_DIR "${PROJECTMSDL_DATA_DIR}/textures" CACHE STRING "Directory to install optional texture files, relative to the install prefix.")

set(DEFAULT_CONFIG_PATH "" CACHE STRING "Optional path to look for the configuration file in addition to PROJECTMSDL_BIN_DIR.")
set(DEFAULT_PRESETS_PATH "\${application.dir}/presets" CACHE STRING "Default presets path in the configuration file.")
set(DEFAULT_TEXTURES_PATH "\${application.dir}/textures" CACHE STRING "Default textures path in the configuration file.")
endif()

set(SDL2_LINKAGE "shared" CACHE STRING "Set to either shared or static to specify how libSDL2 should be linked. Defaults to shared.")
option(ENABLE_FREETYPE "Use the Freetype font rendering library instead of the built-in stb_truetype if available" ON)

set(DEFAULT_PRESETS_PATH "\${application.dir}/presets" CACHE STRING "Default presets path in the configuration file.")
set(DEFAULT_TEXTURES_PATH "\${application.dir}/textures" CACHE STRING "Default textures path in the configuration file.")

set(PRESET_DIRS "" CACHE STRING "List of paths with presets. Will be installed in \"presets\" ")
set(TEXTURE_DIRS "" CACHE STRING "List of paths with presets.")

if(NOT SDL2_LINKAGE STREQUAL "shared" AND NOT SDL2_LINKAGE STREQUAL "static")
message(FATAL_ERROR "Invalid libSDL2 linkage provided in SDL2_LINKAGE: \"${SDL2_LINKAGE}\".\n"
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ and `sudo make install` [libprojectM](https://github.com/projectM-visualizer/pro

### Dependencies

This project requires two third-party libraries in addition to libprojectM's core library dependencies:
This project requires third-party libraries in addition to libprojectM's core library dependencies:

- SDL2 (version 2.0.16 or higher)
- POCO (version 1.12 or higher)
- POCO (recommended version 1.12 or higher, minimum is 1.9.x)
- Freetype 2 (optional, will provide better looking UI text)

**Important**: projectMSDL will _not compile_ against Poco versions from 1.10.0 up to 1.11.1, as these versions of Poco
include a serious issue that causes the application to crash. Either use Poco 1.9.x, or upgrade to 1.11.2 or higher.

Depending on your needs, you can either build them yourself or install them using your favorite package manager. Here
are some examples for the three major desktop platforms:
Expand Down
55 changes: 52 additions & 3 deletions install.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,57 @@
# ToDo: Make directory structure configurable
install(TARGETS projectMSDL
RUNTIME DESTINATION .
RUNTIME DESTINATION ${PROJECTMSDL_BIN_DIR}
COMPONENT projectMSDL
)

install(FILES ${PROJECTM_CONFIGURATION_FILE}
DESTINATION .
DESTINATION ${PROJECTMSDL_DATA_DIR}
COMPONENT projectMSDL
)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT ENABLE_FLAT_PACKAGE)
if(ENABLE_DESKTOP_ICON)
install(FILES src/resources/projectMSDL.desktop
DESTINATION ${PROJECTMSDL_DESKTOP_DIR}
COMPONENT projectMSDL
)

macro(INSTALL_ICON size)
install(FILES src/resources/icons/icon_${size}x${size}.png
DESTINATION ${PROJECTMSDL_ICONS_DIR}/${size}x${size}/apps
RENAME projectMSDL.png
COMPONENT projectMSDL
)
endmacro()

foreach(size 16 32 48 64 72 96 128 256)
install_icon(${size})
endforeach()

endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_FLAT_PACKAGE)
set(ICNS_FILE ${CMAKE_BINARY_DIR}/projectMSDL.icns)
execute_process(COMMAND iconutil -c icns -o "${ICNS_FILE}" "${CMAKE_SOURCE_DIR}/src/resources/icons")

install(FILES ${ICNS_FILE}
DESTINATION ${PROJECTMSDL_DATA_DIR}
COMPONENT projectMSDL
)
endif()

# Install optional presets
foreach(preset_dir ${PRESET_DIRS})
install(DIRECTORY ${preset_dir}
DESTINATION "${PROJECTMSDL_PRESETS_DIR}"
COMPONENT projectMSDL
PATTERN *.md EXCLUDE
)
endforeach()

# Install optional textures
foreach(texture_dir ${TEXTURE_DIRS})
install(DIRECTORY ${texture_dir}
DESTINATION "${PROJECTMSDL_TEXTURES_DIR}"
COMPONENT projectMSDL
PATTERN *.md EXCLUDE
)
endforeach()
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ else()
)
endif()

set_source_files_properties(ProjectMSDLApplication.cpp PROPERTIES
COMPILE_DEFINITIONS PROJECTMSDL_CONFIG_LOCATION=\"${DEFAULT_CONFIG_PATH}\"
)

target_compile_definitions(projectMSDL
PRIVATE
PROJECTMSDL_VERSION="${PROJECT_VERSION}"
Expand Down
28 changes: 13 additions & 15 deletions src/ProjectMSDLApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,24 @@ void ProjectMSDLApplication::initialize(Poco::Util::Application& self)

try
{
if (loadConfiguration(PRIO_DEFAULT) == 0)
//if (loadConfiguration(PRIO_DEFAULT) == 0)
{
#ifdef POCO_OS_FAMILY_UNIX
// In macOS bundles, the file may be located in the ../Resources dir, relative to the exe location.
Poco::Path configPath = config().getString("application.dir");
configPath.makeDirectory().makeParent().append("Resources/").setFileName(configFileName);
if (Poco::File(configPath).exists())
// The file may be located in the ../Resources bundle dir on macOS, elsewhere relative
// to the executable or within an absolute path.
// By setting and retrieving the compiled-in default, we can make use of POCO's variable replacement.
// This allows using ${application.dir} etc. in the path.
config().setString("application.defaultConfigurationFile", PROJECTMSDL_CONFIG_LOCATION);
std::string configPath = config().getString("application.defaultConfigurationFile", "");
if (!configPath.empty())
{
loadConfiguration(configPath.toString(), PRIO_DEFAULT);
}
else
{
// On Linux, system-installed packages often put default configs in /usr/share
configPath.assign("/usr/share/projectM/").setFileName(configFileName);
if (Poco::File(configPath).exists())
Poco::Path configFilePath(configPath);
configFilePath.makeDirectory().setFileName(configFileName);
if (Poco::File(configFilePath).exists())
{
loadConfiguration(configPath.toString(), PRIO_DEFAULT);
loadConfiguration(configFilePath.toString(), PRIO_DEFAULT);
}

}
#endif
}
}
catch (Poco::Exception& ex)
Expand Down
31 changes: 28 additions & 3 deletions src/ProjectMWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "notifications/DisplayToastNotification.h"

#include <Poco/File.h>
#include <Poco/NotificationCenter.h>

#include <Poco/Util/Application.h>
Expand Down Expand Up @@ -66,7 +67,18 @@ void ProjectMWrapper::initialize(Poco::Util::Application& app)

for (const auto& presetPath : presetPaths)
{
projectm_playlist_add_path(_playlist, presetPath.c_str(), true, false);
Poco::File file(presetPath);
if (file.exists() && file.isFile())
{
projectm_playlist_add_preset(_playlist, presetPath.c_str(), false);
}
else
{
// Symbolic links also fall under this. Without complex resolving, we can't
// be sure what the link exactly points to, especially if a trailing slash is missing.
projectm_playlist_add_path(_playlist, presetPath.c_str(), true, false);
}

}
projectm_playlist_sort(_playlist, 0, projectm_playlist_size(_playlist), SORT_PREDICATE_FILENAME_ONLY, SORT_ORDER_ASCENDING);

Expand Down Expand Up @@ -114,6 +126,15 @@ void ProjectMWrapper::RenderFrame() const
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

size_t currentMeshX{0};
size_t currentMeshY{0};
projectm_get_mesh_size(_projectM, &currentMeshX, &currentMeshY);
if (currentMeshX != _config->getInt("meshX", 220) ||
currentMeshY != _config->getInt("meshY", 125))
{
projectm_set_mesh_size(_projectM, _config->getInt("meshX", 220), _config->getInt("meshY", 125));
}

projectm_opengl_render_frame(_projectM);
}

Expand Down Expand Up @@ -144,7 +165,7 @@ void ProjectMWrapper::PresetSwitchedEvent(bool isHardCut, unsigned int index, vo
auto that = reinterpret_cast<ProjectMWrapper*>(context);
auto presetName = projectm_playlist_item(that->_playlist, index);
poco_information_f1(that->_logger, "Displaying preset: %s", std::string(presetName));
projectm_free_string(presetName);
projectm_playlist_free_string(presetName);

Poco::NotificationCenter::defaultCenter().postNotification(new UpdateWindowTitleNotification);
}
Expand Down Expand Up @@ -202,7 +223,11 @@ std::vector<std::string> ProjectMWrapper::GetPathListWithDefault(const std::stri
_config->keys(baseKey, subKeys);
for (const auto& key : subKeys)
{
pathList.push_back(_config->getString(baseKey + "." + key, ""));
auto path = _config->getString(baseKey + "." + key, "");
if (!path.empty())
{
pathList.push_back(std::move(path));
}
}
return pathList;
}
9 changes: 6 additions & 3 deletions src/SDLRenderingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,13 @@ void SDLRenderingWindow::UpdateWindowTitleNotificationHandler(POCO_UNUSED const

auto presetName = projectm_playlist_item(projectMWrapper.Playlist(), projectm_playlist_get_position(projectMWrapper.Playlist()));

Poco::Path presetFile(presetName);
projectm_free_string(presetName);
if (presetName)
{
Poco::Path presetFile(presetName);
projectm_playlist_free_string(presetName);

newTitle += "" + presetFile.getBaseName();
newTitle += "" + presetFile.getBaseName();
}

if (projectm_get_preset_locked(projectMWrapper.ProjectM()))
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void SettingsWindow::Draw()

ImGui::TableNextRow();
LabelWithTooltip("Per-Point Mesh Size X/Y", "Size of the per-point transformation grid.\nHigher values produce better quality, but require more CPU time to calculate.");
IntegerSettingVec("projectM.meshX", "projectM.meshY", 200, 125, 8, 250);
IntegerSettingVec("projectM.meshX", "projectM.meshY", 64, 48, 8, 300);

ImGui::EndTable();
}
Expand Down
10 changes: 10 additions & 0 deletions src/resources/projectMSDL.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Type=Application
Name=projectM
GenericName=Milkdrop-compatible Music Visualizer
Icon=projectMSDL
TryExec=projectMSDL
Exec=projectMSDL
Terminal=false
Categories=Audio;Video;AudioVideo
StartupWMClass=projectMSDL

0 comments on commit 2451fef

Please sign in to comment.