Skip to content

Commit

Permalink
Load presets and play them with playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Jul 6, 2024
1 parent c9e1b3e commit 5be0415
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(gstprojectm VERSION 0.0.1)

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

find_package(projectM4 REQUIRED)
find_package(projectM4 REQUIRED COMPONENTS Playlist)
find_package(GStreamer REQUIRED COMPONENTS gstreamer-audio gstreamer-gl gstreamer-pbutils gstreamer-video)
find_package(GLIB2 REQUIRED)

Expand Down Expand Up @@ -61,6 +61,7 @@ endif()
target_link_libraries(gstprojectm
PRIVATE
libprojectM::projectM
libprojectM::playlist
PUBLIC
${GSTREAMER_LIBRARIES}
${GSTREAMER_BASE_LIBRARIES}
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ G_BEGIN_DECLS
#define DEFAULT_MESH_SIZE "48,32"
#define DEFAULT_ASPECT_CORRECTION TRUE
#define DEFAULT_EASTER_EGG 0.0
#define DEFAULT_PRESET_LOCKED TRUE
#define DEFAULT_PRESET_LOCKED FALSE

G_END_DECLS

Expand Down
17 changes: 15 additions & 2 deletions src/projectm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <gst/gst.h>

#include <projectM-4/projectM.h>
#include <projectM-4/playlist.h>

#include "projectm.h"
#include "plugin.h"
Expand All @@ -15,6 +16,7 @@ GST_DEBUG_CATEGORY_STATIC(projectm_debug);
projectm_handle projectm_init(GstProjectM *plugin)
{
projectm_handle handle = NULL;
projectm_playlist_handle playlist = NULL;
GST_DEBUG_CATEGORY_INIT(projectm_debug, "projectm",
0, "ProjectM");

Expand All @@ -34,6 +36,11 @@ projectm_handle projectm_init(GstProjectM *plugin)
GST_DEBUG_OBJECT(plugin, "Created projectM instance!");
}

// initialize preset playlist
playlist = projectm_playlist_create(handle);
projectm_playlist_set_shuffle(playlist, true);
// projectm_playlist_set_preset_switched_event_callback(_playlist, &ProjectMWrapper::PresetSwitchedEvent, static_cast<void*>(this));

// Log properties
GST_INFO_OBJECT(plugin, "Using Properties: "
"preset=%s, "
Expand Down Expand Up @@ -63,8 +70,10 @@ projectm_handle projectm_init(GstProjectM *plugin)
plugin->preset_locked);

// Load preset file if path is provided
if (plugin->preset_path != NULL)
projectm_load_preset_file(handle, plugin->preset_path, false);
if (plugin->preset_path != NULL) {
int added_count = projectm_playlist_add_path(playlist, plugin->preset_path, true, false);
GST_INFO("Loaded preset path: %s, presets found: %d", plugin->preset_path, added_count);
}

// Set texture search path if directory path is provided
if (plugin->texture_dir_path != NULL)
Expand All @@ -84,6 +93,10 @@ projectm_handle projectm_init(GstProjectM *plugin)
if (plugin->preset_duration > 0.0)
{
projectm_set_preset_duration(handle, plugin->preset_duration);

// kick off the first preset
if (projectm_playlist_size(playlist) > 0 && ! plugin->preset_locked)
projectm_playlist_play_next(playlist, true);
}
else
{
Expand Down

0 comments on commit 5be0415

Please sign in to comment.