-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoo_metronome.cpp
141 lines (121 loc) · 3.45 KB
/
foo_metronome.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#define _WIN32_WINNT _WIN32_WINNT_WIN7
#define WINVER _WIN32_WINNT_WIN7
#include <foobar2000/SDK/foobar2000.h>
static constexpr const char* component_name = "Metronome";
DECLARE_COMPONENT_VERSION(
component_name,
"1.3",
"grimes\n\n"
"Build: " __TIME__ ", " __DATE__
);
VALIDATE_COMPONENT_FILENAME("foo_metronome.dll");
#define ID_TIMER4 1111
UINT_PTR ptr4 = 0;
bool menu_metronome_enabled = false;
pfc::string8 metronome;
UINT bpm;
int i = 1;
// {2A2F55E5-110A-43BF-8377-1DCB133EF19B}
static const GUID guid_cfg_branch = { 0x2eb4867c, 0x177c, 0x416d, { 0x9e, 0x7d, 0x41, 0x7d, 0xf9, 0x5f, 0xaa, 0xd4 } };
static advconfig_branch_factory cfg_branch("Metronome", guid_cfg_branch, advconfig_entry::guid_branch_playback, 0);
// {DD0DC9E7-DA12-4671-905A-A4340908CE5F}
static const GUID guid_cfg_bpm = { 0xdd0dc9e7, 0xda12, 0x4671, { 0x90, 0x5a, 0xa4, 0x34, 0x9, 0x8, 0xce, 0x5f } };
advconfig_string_factory cfg_bpm("bpm ", guid_cfg_bpm, guid_cfg_branch, 0, "60");
VOID CALLBACK MetronomeTimer(
HWND, // handle to window for timer messages
UINT, // WM_TIMER message
UINT idEvent1, // timer identifier
DWORD) // current system time
{
if (menu_metronome_enabled)
{
FB2K_console_formatter() << "bpm: " << bpm << " beat: " << i++;
if (i & 1L) console::info("");
}
else
{
KillTimer(NULL, idEvent1);
i = 1;
}
}
class mainmenu_commands_metronome : public mainmenu_commands
{
public:
// Return the number of commands we provide.
virtual t_uint32 get_command_count()
{
return 1;
}
// All commands are identified by a GUID.
virtual GUID get_command(t_uint32 p_index)
{
static const GUID guid_main_metronome =
{ 0xf4f24e27, 0xd17c, 0x4402, { 0xae, 0x94, 0x2b, 0xca, 0xfd, 0x16, 0x11, 0x7b } };
if (p_index == 0)
return guid_main_metronome;
return pfc::guid_null;
}
// Set p_out to the name of the n-th command.
// This name is used to identify the command and determines
// the default position of the command in the menu.
virtual void get_name(t_uint32 p_index, pfc::string_base& p_out)
{
if (p_index == 0)
p_out = "Metronome";
}
// Set p_out to the description for the n-th command.
virtual bool get_description(t_uint32 p_index, pfc::string_base& p_out)
{
if (p_index == 0)
p_out = "Metronome to console.";
else
return false;
return true;
}
// Every set of commands needs to declare which group it belongs to.
virtual GUID get_parent()
{
return mainmenu_groups::playback;
}
// Execute n-th command.
// p_callback is reserved for future use.
virtual void execute(t_uint32 p_index, service_ptr_t<service_base> p_callback)
{
if (p_index == 0)
{
cfg_bpm.get(metronome);
bpm = atoi(metronome);
menu_metronome_enabled = !menu_metronome_enabled;
if (menu_metronome_enabled)
{
ptr4 = SetTimer(NULL, ID_TIMER4, 60 * 1000 / bpm, (TIMERPROC)MetronomeTimer);
}
}
}
// The standard version of this command does not support checked or disabled
// commands, so we use our own version.
virtual bool get_display(t_uint32 p_index, pfc::string_base& p_text, t_uint32& p_flags)
{
if (p_index == 0) {
if (menu_metronome_enabled)
{
p_flags |= flag_checked;
}
else {
p_flags = 0;
}
get_name(p_index, p_text);
}
return true;
}
virtual t_uint32 get_sort_priority()
{
return 0x80000000;
}
bool is_checked(t_uint32 p_index)
{
if (p_index == 0)
return menu_metronome_enabled;
}
};
static mainmenu_commands_factory_t<mainmenu_commands_metronome> g_mainmenu_commands_metronome;