Skip to content

Commit 13ca84d

Browse files
committed
Display preset name in title bar.
1 parent f706ebe commit 13ca84d

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/RenderLoop.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ void RenderLoop::Run()
1919
FPSLimiter limiter;
2020
limiter.TargetFPS(_projectMWrapper.TargetFPS());
2121

22+
projectm_set_preset_switched_event_callback(_projectMHandle, &RenderLoop::PresetSwitchedEvent,
23+
static_cast<void*>(this));
24+
25+
// Update title bar with initial preset.
26+
unsigned int currentIndex;
27+
if (projectm_get_selected_preset_index(_projectMHandle, &currentIndex))
28+
{
29+
PresetSwitchedEvent(true, currentIndex, this);
30+
}
31+
2232
while (!_wantsToQuit)
2333
{
2434
limiter.StartFrame();
@@ -27,6 +37,8 @@ void RenderLoop::Run()
2737
_sdlRenderingWindow.Swap();
2838
limiter.EndFrame();
2939
}
40+
41+
projectm_set_preset_switched_event_callback(_projectMHandle, nullptr, nullptr);
3042
}
3143

3244
void RenderLoop::PollEvents()
@@ -331,7 +343,7 @@ void RenderLoop::ScrollEvent(const SDL_MouseWheelEvent& event)
331343
{
332344
projectm_select_previous_preset(_projectMHandle, true);
333345
}
334-
// Wheel down is negative
346+
// Wheel down is negative
335347
else if (event.y < 0)
336348
{
337349
projectm_select_next_preset(_projectMHandle, true);
@@ -386,3 +398,15 @@ void RenderLoop::MouseUpEvent(const SDL_MouseButtonEvent& event)
386398
_mouseDown = false;
387399
}
388400
}
401+
402+
void RenderLoop::PresetSwitchedEvent(bool isHardCut, unsigned int index, void* context)
403+
{
404+
auto that = reinterpret_cast<RenderLoop*>(context);
405+
auto presetName = projectm_get_preset_name(that->_projectMHandle, index);
406+
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Displaying preset: %s\n", presetName);
407+
408+
std::string newTitle = "projectM ➫ " + std::string(presetName);
409+
projectm_free_string(presetName);
410+
411+
that->_sdlRenderingWindow.SetTitle(newTitle);
412+
}

src/RenderLoop.h

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class RenderLoop
4949
*/
5050
void MouseUpEvent(const SDL_MouseButtonEvent& event);
5151

52+
/**
53+
* @brief projectM callback. Called whenever a preset is switched.
54+
* @param isHardCut True if the switch was a hard cut.
55+
* @param index New preset playlist index.
56+
* @param context Callback context, e.g. "this" pointer.
57+
*/
58+
static void PresetSwitchedEvent(bool isHardCut, unsigned int index, void* context);
59+
5260
AudioCapture& _audioCapture;
5361
ProjectMWrapper& _projectMWrapper;
5462
SDLRenderingWindow& _sdlRenderingWindow;

src/SDLRenderingWindow.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ void SDLRenderingWindow::GetDrawableSize(int& width, int& height) const
3434
SDL_GL_GetDrawableSize(_renderingWindow, &width, &height);
3535
}
3636

37+
void SDLRenderingWindow::SetTitle(const std::string& title) const
38+
{
39+
SDL_SetWindowTitle(_renderingWindow, title.c_str());
40+
}
41+
3742
void SDLRenderingWindow::Swap() const
3843
{
3944
SDL_GL_SwapWindow(_renderingWindow);

src/SDLRenderingWindow.h

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class SDLRenderingWindow : public Poco::Util::Subsystem
2929
*/
3030
void GetDrawableSize(int& width, int& height) const;
3131

32+
/**
33+
* @brief Sets the window title.
34+
* @param title The new window title.
35+
*/
36+
void SetTitle(const std::string& title) const;
37+
3238
/**
3339
* Swaps the OpenGL front- and back buffers.
3440
*/

0 commit comments

Comments
 (0)