Skip to content

Commit ceb86eb

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 5acd8bf commit ceb86eb

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

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
@@ -291,7 +291,7 @@ void ProjectM::StartPresetTransition(std::unique_ptr<Preset>&& preset, bool hard
291291
m_transition.reset();
292292
}
293293

294-
if (m_activePreset)
294+
if (m_activePreset && !m_presetStartClean)
295295
{
296296
preset->DrawInitialImage(m_activePreset->OutputTexture(), GetRenderContext());
297297
}
@@ -384,6 +384,16 @@ auto ProjectM::PresetLocked() const -> bool
384384
return m_presetLocked;
385385
}
386386

387+
void ProjectM::SetPresetStartClean(bool enabled)
388+
{
389+
m_presetStartClean = enabled;
390+
}
391+
392+
auto ProjectM::PresetStartClean() const -> bool
393+
{
394+
return m_presetStartClean;
395+
}
396+
387397
void ProjectM::SetFrameTime(double secondsSinceStart)
388398
{
389399
m_timeKeeper->SetFrameTime(secondsSinceStart);

src/libprojectM/ProjectM.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ class PROJECTM_CXX_EXPORT ProjectM
208208
/// Returns true if the active preset is locked
209209
auto PresetLocked() const -> bool;
210210

211+
/**
212+
* @brief Sets whether newly loaded presets should start with a clean (black) canvas.
213+
* @param enabled True to start with a clean canvas, false to copy the previous frame.
214+
*/
215+
void SetPresetStartClean(bool enabled);
216+
217+
/**
218+
* @brief Returns whether newly loaded presets start with a clean canvas.
219+
* @return True if presets start with a clean canvas.
220+
*/
221+
auto PresetStartClean() const -> bool;
222+
211223
auto PCM() -> Audio::PCM&;
212224

213225
auto WindowWidth() -> int;
@@ -305,6 +317,7 @@ class PROJECTM_CXX_EXPORT ProjectM
305317

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

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

src/libprojectM/ProjectMCWrapper.cpp

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

420+
void projectm_set_preset_start_clean(projectm_handle instance, bool enabled)
421+
{
422+
auto projectMInstance = handle_to_instance(instance);
423+
projectMInstance->SetPresetStartClean(enabled);
424+
}
425+
426+
bool projectm_get_preset_start_clean(projectm_handle instance)
427+
{
428+
auto projectMInstance = handle_to_instance(instance);
429+
return projectMInstance->PresetStartClean();
430+
}
431+
420432
unsigned int projectm_pcm_get_max_samples()
421433
{
422434
return libprojectM::Audio::WaveformSamples;

0 commit comments

Comments
 (0)