-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent_track_resource.cpp
More file actions
67 lines (58 loc) · 1.9 KB
/
current_track_resource.cpp
File metadata and controls
67 lines (58 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Created by Bobini on 08/02/2026.
//
#include "current_track_resource.h"
mcp::json current_track_resource::get_metadata() const
{
return {
{"uri", get_uri()},
{"name", "Current track"},
{
"description",
"Tracks the state of playback. "
"Subscribe to this resource to get notified of changes to active track and pausing/unpausing. "
"To get the info about the current track, call the list_current_track tool."
}
};
}
mcp::json current_track_resource::read() const
{
return {
{"uri", get_uri()},
{
"text", std::format("Playing: {}, song last changed {} seconds ago", playing ? "Yes" : "No",
std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::steady_clock::now() - last_update_time).count())
}
};
}
current_track_resource::current_track_resource() : resource("current_track://."),
play_callback_impl_base(
flag_on_playback_stop | flag_on_playback_new_track |
flag_on_playback_pause | flag_on_playback_starting)
{
}
void current_track_resource::on_playback_stop(play_control::t_stop_reason p_reason)
{
playing = false;
notify_change();
}
void current_track_resource::on_playback_new_track(metadb_handle_ptr p_track)
{
playing = true;
notify_change();
}
void current_track_resource::on_playback_pause(bool p_state)
{
playing = !p_state;
notify_change();
}
void current_track_resource::on_playback_starting(play_control::t_track_command p_command, bool p_paused)
{
playing = !p_paused;
notify_change();
}
void current_track_resource::notify_change() const
{
mcp::resource_manager::instance().notify_resource_changed(get_uri());
}