|
a/src/mpdcli.hxx |
|
b/src/mpdcli.hxx |
1 |
/* Copyright (C) 2014 J.F.Dockes
|
1 |
/* Copyright (C) 2014 J.F.Dockes
|
2 |
* This program is free software; you can redistribute it and/or modify
|
2 |
* This program is free software; you can redistribute it and/or modify
|
3 |
* it under the terms of the GNU Lesser General Public License as published by
|
3 |
* it under the terms of the GNU Lesser General Public License as published by
|
4 |
* the Free Software Foundation; either version 2.1 of the License, or
|
4 |
* the Free Software Foundation; either version 2.1 of the License, or
|
5 |
* (at your option) any later version.
|
5 |
* (at your option) any later version.
|
6 |
*
|
6 |
*
|
7 |
* This program is distributed in the hope that it will be useful,
|
7 |
* This program is distributed in the hope that it will be useful,
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
10 |
* GNU Lesser General Public License for more details.
|
10 |
* GNU Lesser General Public License for more details.
|
11 |
*
|
11 |
*
|
12 |
* You should have received a copy of the GNU Lesser General Public License
|
12 |
* You should have received a copy of the GNU Lesser General Public License
|
13 |
* along with this program; if not, write to the
|
13 |
* along with this program; if not, write to the
|
14 |
* Free Software Foundation, Inc.,
|
14 |
* Free Software Foundation, Inc.,
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
17 |
#ifndef _MPDCLI_H_X_INCLUDED_
|
17 |
#ifndef _MPDCLI_H_X_INCLUDED_
|
18 |
#define _MPDCLI_H_X_INCLUDED_
|
18 |
#define _MPDCLI_H_X_INCLUDED_
|
19 |
|
19 |
|
20 |
#include <regex.h> // for regex_t
|
20 |
#include <regex.h> // for regex_t
|
|
... |
|
... |
24 |
#include <memory>
|
24 |
#include <memory>
|
25 |
|
25 |
|
26 |
#include "upmpdutils.hxx"
|
26 |
#include "upmpdutils.hxx"
|
27 |
|
27 |
|
28 |
struct mpd_song;
|
28 |
struct mpd_song;
|
|
|
29 |
struct mpd_connection;
|
29 |
|
30 |
|
30 |
class MpdStatus {
|
31 |
class MpdStatus {
|
31 |
public:
|
32 |
public:
|
32 |
MpdStatus() : state(MPDS_UNK), trackcounter(0), detailscounter(0) {}
|
33 |
MpdStatus() : state(MPDS_UNK), trackcounter(0), detailscounter(0) {}
|
33 |
|
34 |
|
|
... |
|
... |
72 |
|
73 |
|
73 |
class MPDCli {
|
74 |
class MPDCli {
|
74 |
public:
|
75 |
public:
|
75 |
MPDCli(const std::string& host, int port = 6600, const std::string& pss="");
|
76 |
MPDCli(const std::string& host, int port = 6600, const std::string& pss="");
|
76 |
~MPDCli();
|
77 |
~MPDCli();
|
77 |
bool ok() {return m_ok && m_conn;}
|
78 |
bool ok() {return m_conn != nullptr;}
|
78 |
bool setVolume(int ivol, bool isMute = false);
|
79 |
bool setVolume(int ivol, bool isMute = false);
|
79 |
int getVolume();
|
80 |
int getVolume();
|
80 |
void forceInternalVControl();
|
81 |
void forceInternalVControl();
|
81 |
bool togglePause();
|
82 |
bool togglePause();
|
82 |
bool pause(bool onoff);
|
83 |
bool pause(bool onoff);
|
|
... |
|
... |
102 |
int curpos();
|
103 |
int curpos();
|
103 |
bool getQueueData(std::vector<UpSong>& vdata);
|
104 |
bool getQueueData(std::vector<UpSong>& vdata);
|
104 |
bool statSong(UpSong& usong, int pos = -1, bool isId = false);
|
105 |
bool statSong(UpSong& usong, int pos = -1, bool isId = false);
|
105 |
UpSong& mapSong(UpSong& usong, struct mpd_song *song);
|
106 |
UpSong& mapSong(UpSong& usong, struct mpd_song *song);
|
106 |
|
107 |
|
107 |
const MpdStatus& getStatus()
|
108 |
const MpdStatus& getStatus() {
|
108 |
{
|
|
|
109 |
updStatus();
|
109 |
updStatus();
|
110 |
return m_stat;
|
110 |
return m_stat;
|
111 |
}
|
111 |
}
|
112 |
|
112 |
|
113 |
// Copy complete mpd state. If seekms is > 0, this is the value to
|
113 |
// Copy complete mpd state. If seekms is > 0, this is the value to
|
114 |
// save (sometimes useful if mpd was stopped)
|
114 |
// save (sometimes useful if mpd was stopped)
|
115 |
bool saveState(MpdState& st, int seekms = 0);
|
115 |
bool saveState(MpdState& st, int seekms = 0);
|
116 |
bool restoreState(const MpdState& st);
|
116 |
bool restoreState(const MpdState& st);
|
117 |
|
117 |
|
118 |
private:
|
118 |
private:
|
119 |
void *m_conn;
|
119 |
struct mpd_connection *m_conn{nullptr};
|
120 |
bool m_ok;
|
|
|
121 |
MpdStatus m_stat;
|
120 |
MpdStatus m_stat;
|
122 |
// Saved volume while muted.
|
121 |
// Saved volume while muted.
|
123 |
int m_premutevolume;
|
122 |
int m_premutevolume{0};
|
124 |
// Volume that we use when MPD is stopped (does not return a
|
123 |
// Volume that we use when MPD is stopped (does not return a
|
125 |
// volume in the status)
|
124 |
// volume in the status)
|
126 |
int m_cachedvolume;
|
125 |
int m_cachedvolume{50};
|
127 |
std::string m_host;
|
126 |
std::string m_host;
|
128 |
int m_port;
|
127 |
int m_port;
|
|
|
128 |
int m_timeoutms{2000};
|
129 |
std::string m_password;
|
129 |
std::string m_password;
|
130 |
std::string m_onstart;
|
130 |
std::string m_onstart;
|
131 |
std::string m_onplay;
|
131 |
std::string m_onplay;
|
132 |
std::string m_onpause;
|
132 |
std::string m_onpause;
|
133 |
std::string m_onstop;
|
133 |
std::string m_onstop;
|
134 |
bool m_externalvolumecontrol;
|
134 |
bool m_externalvolumecontrol{false};
|
135 |
std::vector<std::string> m_onvolumechange;
|
135 |
std::vector<std::string> m_onvolumechange;
|
136 |
std::vector<std::string> m_getexternalvolume;
|
136 |
std::vector<std::string> m_getexternalvolume;
|
137 |
regex_t m_tpuexpr;
|
137 |
regex_t m_tpuexpr;
|
138 |
// addtagid command only exists for mpd 0.19 and later.
|
138 |
// addtagid command only exists for mpd 0.19 and later.
|
139 |
bool m_have_addtagid;
|
139 |
bool m_have_addtagid{false};
|
140 |
// Position and id of last insertion: if the new request is to
|
140 |
// Position and id of last insertion: if the new request is to
|
141 |
// insert after this id, and the queue did not change, we compute
|
141 |
// insert after this id, and the queue did not change, we compute
|
142 |
// the new position from the last one instead of re-reading the
|
142 |
// the new position from the last one instead of re-reading the
|
143 |
// queue for looking up the id position. This saves a huge amount
|
143 |
// queue for looking up the id position. This saves a huge amount
|
144 |
// of time.
|
144 |
// of time.
|
145 |
int m_lastinsertid;
|
145 |
int m_lastinsertid{-1};
|
146 |
int m_lastinsertpos;
|
146 |
int m_lastinsertpos{-1};
|
147 |
int m_lastinsertqvers;
|
147 |
int m_lastinsertqvers{-1};
|
148 |
|
148 |
|
149 |
bool openconn();
|
149 |
bool openconn();
|
|
|
150 |
void closeconn();
|
150 |
bool updStatus();
|
151 |
bool updStatus();
|
151 |
bool getQueueSongs(std::vector<mpd_song*>& songs);
|
152 |
bool getQueueSongs(std::vector<mpd_song*>& songs);
|
152 |
void freeSongs(std::vector<mpd_song*>& songs);
|
153 |
void freeSongs(std::vector<mpd_song*>& songs);
|
153 |
bool showError(const std::string& who);
|
154 |
bool showError(const std::string& who);
|
154 |
bool looksLikeTransportURI(const std::string& path);
|
155 |
bool looksLikeTransportURI(const std::string& path);
|
155 |
bool checkForCommand(const std::string& cmdname);
|
156 |
bool checkForCommand(const std::string& cmdname);
|
156 |
bool send_tag(const char *cid, int tag, const std::string& data);
|
157 |
bool send_tag(const char *cid, int tag, const std::string& data);
|
157 |
bool send_tag_data(int id, const UpSong& meta);
|
158 |
bool send_tag_data(int id, const UpSong& meta);
|
158 |
};
|
159 |
};
|
159 |
|
160 |
|
160 |
|
|
|
161 |
#endif /* _MPDCLI_H_X_INCLUDED_ */
|
161 |
#endif /* _MPDCLI_H_X_INCLUDED_ */
|