/
Control.pm6
157 lines (127 loc) · 2.94 KB
/
Control.pm6
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#! /usr/bin/env false
use v6.c;
use MPD::Client::Status;
use MPD::Client::Util;
unit module MPD::Client::Control;
#| Plays next song in the playlist.
sub mpd-next (
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("next", $socket);
$socket;
}
#| Toggles pause/resumes playing.
multi sub mpd-pause (
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-pause(!mpd-status("pause", $socket), $socket);
}
#| Set the pause state to $pause.
multi sub mpd-pause (
Bool $pause,
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("pause", $pause, $socket);
$socket;
}
#| Begins playing at the start of the playlist.
multi sub mpd-play (
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("play", $socket);
$socket;
}
#| Begins playing the playlist at song number $songpos.
multi sub mpd-play (
Int $songpos,
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("play", $songpos, $socket);
$socket;
}
#| Begins playing the playlist at song $songid.
sub mpd-playid (
Int $songid,
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("playid", $songid, $socket);
$socket;
}
#| Plays previous song in the playlist.
sub mpd-previous (
IO::Socket::INET $socket,
--> IO::Socket::INET
) is export {
mpd-send("previous", $socket);
$socket;
}
#| Seeks to the position $time (in seconds; fractions allowed) of entry
#| $songpos in the playlist.
sub mpd-seek (
Int $songpos,
Real $time,
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("seek", [$songpos, $time], $socket);
$socket;
}
#| Seeks to the position $time (in seconds; fractions allowed) of song $songid.
sub mpd-seekid (
Int $songid,
Real $time,
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("seekid", [$songid, $time], $socket);
$socket;
}
#| Seeks to the position $time (in seconds; fractions allowed) within the
#| current song.
multi sub mpd-seekcur (
Real $time,
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
if ($time < 0) {
MPD::Client::Exceptions::ArgumentException.new("Time must be positive").throw;
}
mpd-send("seekcur", $time, $socket);
$socket;
}
#| Seeks to the relative position $time (in seconds; fractions allowed) within
#| the current song. The prefix can be either "+" or "-", then the time is
#| relative to the current playing position.
multi sub mpd-seekcur (
Str $prefix,
Real $time,
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
my @prefixes = [
"+",
"-",
];
if (@prefixes !(cont) $prefix) {
MPD::Client::Exceptions::ArgumentException.new("Prefix must be one of + or -").throw;
}
if ($time < 0) {
MPD::Client::Exceptions::ArgumentException.new("Time must be positive").throw;
}
mpd-send("seekcur", $prefix ~ $time, $socket);
$socket;
}
#| Stops playing.
sub mpd-stop (
IO::Socket::INET $socket
--> IO::Socket::INET
) is export {
mpd-send("stop", $socket);
$socket;
}