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
use crate::CommandId;
use reaper_low::firewall;
use std::os::raw::c_int;
pub trait MediumHookCommand {
fn call(command_id: CommandId, flag: i32) -> bool;
}
pub(crate) extern "C" fn delegating_hook_command<T: MediumHookCommand>(
command_id: c_int,
flag: c_int,
) -> bool {
firewall(|| T::call(CommandId(command_id as _), flag)).unwrap_or(false)
}
pub trait MediumToggleAction {
fn call(command_id: CommandId) -> ToggleActionResult;
}
pub enum ToggleActionResult {
NotRelevant,
Off,
On,
}
pub(crate) extern "C" fn delegating_toggle_action<T: MediumToggleAction>(
command_id: c_int,
) -> c_int {
firewall(|| {
use ToggleActionResult::*;
match T::call(CommandId(command_id as _)) {
NotRelevant => -1,
Off => 0,
On => 1,
}
})
.unwrap_or(-1)
}
pub trait MediumHookPostCommand {
fn call(command_id: CommandId, flag: i32);
}
pub(crate) extern "C" fn delegating_hook_post_command<T: MediumHookPostCommand>(
command_id: c_int,
flag: c_int,
) {
firewall(|| {
T::call(CommandId(command_id as _), flag);
});
}