Skip to content

Commit 63185ff

Browse files
committed
Add API flag to start presets with clean canvas
Adds projectm_set_preset_start_clean() and projectm_get_preset_start_clean() functions to control whether new presets start with a black canvas or inherit the previous preset's last frame. Default behavior remains unchanged (copy previous frame), but applications can now opt-in to clean starts by setting this flag to true. Fixes #298
1 parent db22c93 commit 63185ff

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/api/include/projectM-4/parameters.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,30 @@ PROJECTM_EXPORT void projectm_set_window_size(projectm_handle instance, size_t w
370370
*/
371371
PROJECTM_EXPORT void projectm_get_window_size(projectm_handle instance, size_t* width, size_t* height);
372372

373+
/**
374+
* @brief Sets whether newly loaded presets should start with a clean (black) canvas.
375+
*
376+
* By default, when switching presets, the last frame of the previous preset is copied into
377+
* the new preset's main texture, creating a visual continuity. Setting this flag to true
378+
* will cause each new preset to start with a black canvas instead.
379+
*
380+
* This is useful for applications that want a clean start for each preset, avoiding the
381+
* "ghosting" effect from the previous preset.
382+
*
383+
* @param instance The projectM instance handle.
384+
* @param enabled True to start new presets with a clean canvas, false to copy the previous frame. Default: false
385+
* @since 4.2.0
386+
*/
387+
PROJECTM_EXPORT void projectm_set_preset_start_clean(projectm_handle instance, bool enabled);
388+
389+
/**
390+
* @brief Returns whether newly loaded presets start with a clean canvas.
391+
* @param instance The projectM instance handle.
392+
* @return True if presets start with a clean canvas, false if the previous frame is copied.
393+
* @since 4.2.0
394+
*/
395+
PROJECTM_EXPORT bool projectm_get_preset_start_clean(projectm_handle instance);
396+
373397
#ifdef __cplusplus
374398
} // extern "C"
375399
#endif

src/libprojectM/ProjectM.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void ProjectM::StartPresetTransition(std::unique_ptr<Preset>&& preset, bool hard
274274
m_transition.reset();
275275
}
276276

277-
if (m_activePreset)
277+
if (m_activePreset && !m_presetStartClean)
278278
{
279279
preset->DrawInitialImage(m_activePreset->OutputTexture(), GetRenderContext());
280280
}
@@ -367,6 +367,16 @@ auto ProjectM::PresetLocked() const -> bool
367367
return m_presetLocked;
368368
}
369369

370+
void ProjectM::SetPresetStartClean(bool enabled)
371+
{
372+
m_presetStartClean = enabled;
373+
}
374+
375+
auto ProjectM::PresetStartClean() const -> bool
376+
{
377+
return m_presetStartClean;
378+
}
379+
370380
void ProjectM::SetFrameTime(double secondsSinceStart)
371381
{
372382
m_timeKeeper->SetFrameTime(secondsSinceStart);

src/libprojectM/ProjectM.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ class PROJECTM_EXPORT ProjectM
194194
/// Returns true if the active preset is locked
195195
auto PresetLocked() const -> bool;
196196

197+
/**
198+
* @brief Sets whether newly loaded presets should start with a clean (black) canvas.
199+
* @param enabled True to start with a clean canvas, false to copy the previous frame.
200+
*/
201+
void SetPresetStartClean(bool enabled);
202+
203+
/**
204+
* @brief Returns whether newly loaded presets start with a clean canvas.
205+
* @return True if presets start with a clean canvas.
206+
*/
207+
auto PresetStartClean() const -> bool;
208+
197209
auto PCM() -> Audio::PCM&;
198210

199211
auto WindowWidth() -> int;
@@ -290,6 +302,7 @@ class PROJECTM_EXPORT ProjectM
290302

291303
bool m_presetLocked{false}; //!< If true, the preset change event will not be sent.
292304
bool m_presetChangeNotified{false}; //!< Stores whether the user has been notified that projectM wants to switch the preset.
305+
bool m_presetStartClean{false}; //!< If true, new presets start with a black canvas instead of the previous frame.
293306

294307
std::unique_ptr<PresetFactoryManager> m_presetFactoryManager; //!< Provides access to all available preset factories.
295308

src/libprojectM/ProjectMCWrapper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,18 @@ void projectm_set_window_size(projectm_handle instance, size_t width, size_t hei
384384
projectMInstance->SetWindowSize(static_cast<uint32_t>(width), static_cast<uint32_t>(height));
385385
}
386386

387+
void projectm_set_preset_start_clean(projectm_handle instance, bool enabled)
388+
{
389+
auto projectMInstance = handle_to_instance(instance);
390+
projectMInstance->SetPresetStartClean(enabled);
391+
}
392+
393+
bool projectm_get_preset_start_clean(projectm_handle instance)
394+
{
395+
auto projectMInstance = handle_to_instance(instance);
396+
return projectMInstance->PresetStartClean();
397+
}
398+
387399
unsigned int projectm_pcm_get_max_samples()
388400
{
389401
return libprojectM::Audio::WaveformSamples;

0 commit comments

Comments
 (0)