Skip to content

Commit

Permalink
Add shuffle presets property
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Jul 6, 2024
1 parent 9741260 commit cc38583
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ G_BEGIN_DECLS
#define DEFAULT_ASPECT_CORRECTION TRUE
#define DEFAULT_EASTER_EGG 0.0
#define DEFAULT_PRESET_LOCKED FALSE
#define DEFAULT_SHUFFLE_PRESETS TRUE

G_END_DECLS

Expand Down
1 change: 1 addition & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum
PROP_ASPECT_CORRECTION,
PROP_EASTER_EGG,
PROP_PRESET_LOCKED,
PROP_SHUFFLE_PRESETS,
};

G_END_DECLS
Expand Down
14 changes: 13 additions & 1 deletion src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ void gst_projectm_set_property(GObject *object, guint property_id,
case PROP_PRESET_LOCKED:
plugin->preset_locked = g_value_get_boolean(value);
break;
case PROP_SHUFFLE_PRESETS:
plugin->shuffle_presets = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
Expand Down Expand Up @@ -151,6 +154,9 @@ void gst_projectm_get_property(GObject *object, guint property_id,
case PROP_PRESET_LOCKED:
g_value_set_boolean(value, plugin->preset_locked);
break;
case PROP_SHUFFLE_PRESETS:
g_value_set_boolean(value, plugin->shuffle_presets);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
Expand All @@ -170,6 +176,7 @@ static void gst_projectm_init(GstProjectM *plugin)
plugin->hard_cut_sensitivity = DEFAULT_HARD_CUT_SENSITIVITY;
plugin->soft_cut_duration = DEFAULT_SOFT_CUT_DURATION;
plugin->preset_duration = DEFAULT_PRESET_DURATION;
plugin->shuffle_presets = DEFAULT_SHUFFLE_PRESETS;

const gchar *meshSizeStr = DEFAULT_MESH_SIZE;
gint width, height;
Expand Down Expand Up @@ -250,7 +257,6 @@ static gboolean gst_projectm_setup(GstGLBaseAudioVisualizer *glav) {
// Calculate required samples per frame
bscope->req_spf = (bscope->ainfo.channels * bscope->ainfo.rate * 2) / bscope->vinfo.fps_n;


// get GStreamer video format and map it to the corresponding OpenGL pixel format
const GstVideoFormat video_format = GST_VIDEO_INFO_FORMAT(&bscope->vinfo);

Expand Down Expand Up @@ -423,6 +429,12 @@ static void gst_projectm_class_init(GstProjectMClass *klass)
DEFAULT_PRESET_LOCKED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property(gobject_class, PROP_SHUFFLE_PRESETS,
g_param_spec_boolean("shuffle-presets", "Shuffle Presets",
"Enables or disables preset shuffling. When enabled, the visualizer randomly selects presets from the playlist if presets are provided and not locked.",
DEFAULT_SHUFFLE_PRESETS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

gobject_class->finalize = gst_projectm_finalize;

scope_class->supported_gl_api = GST_GL_API_OPENGL3 | GST_GL_API_GLES2;
Expand Down
1 change: 1 addition & 0 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct _GstProjectM
gboolean aspect_correction;
gfloat easter_egg;
gboolean preset_locked;
gboolean shuffle_presets;

GstProjectMPrivate *priv;
};
Expand Down
14 changes: 8 additions & 6 deletions src/projectm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
GST_DEBUG_CATEGORY_STATIC(projectm_debug);
#define GST_CAT_DEFAULT projectm_debug

projectm_handle projectm_init(GstProjectM *plugin)
{
projectm_handle projectm_init(GstProjectM *plugin) {
projectm_handle handle = NULL;
projectm_playlist_handle playlist = NULL;
GST_DEBUG_CATEGORY_INIT(projectm_debug, "projectm",
Expand Down Expand Up @@ -54,7 +53,8 @@ projectm_handle projectm_init(GstProjectM *plugin)
"mesh-size=(%lu, %lu)"
"aspect-correction=%d, "
"easter-egg=%f, "
"preset-locked=%d, ",
"preset-locked=%d, "
"shuffle-presets=%d",
plugin->preset_path,
plugin->texture_dir_path,
plugin->beat_sensitivity,
Expand All @@ -67,7 +67,8 @@ projectm_handle projectm_init(GstProjectM *plugin)
plugin->mesh_height,
plugin->aspect_correction,
plugin->easter_egg,
plugin->preset_locked);
plugin->preset_locked,
plugin->shuffle_presets);

// Load preset file if path is provided
if (plugin->preset_path != NULL) {
Expand Down Expand Up @@ -95,8 +96,9 @@ projectm_handle projectm_init(GstProjectM *plugin)
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);
if (projectm_playlist_size(playlist) > 1 && ! plugin->preset_locked && plugin->shuffle_presets) {
projectm_playlist_play_next(playlist, true);
}
}
else
{
Expand Down

0 comments on commit cc38583

Please sign in to comment.