Skip to content

Commit

Permalink
Adds support for new MythMusic control added in SHA: 747c374 to the
Browse files Browse the repository at this point in the history
frontend network control interface.  Added commands are:

    play music play
    play music pause
    play music stop
    play music setvolume N
    play music file FILE
    play music track N
    play music url URL

Also added to pull information:

    play music getvolume -> current volume
    play music getmeta -> metadata string of current media

This commit also disables the regular expression character filter which
is currently preventing Myth URIs with defined storage groups or UTF-8
  • Loading branch information
wagnerrp authored and jyavenard committed Dec 14, 2010
1 parent a520a2d commit cb26018
Showing 1 changed file with 151 additions and 49 deletions.
200 changes: 151 additions & 49 deletions mythtv/programs/mythfrontend/networkcontrol.cpp
@@ -1,4 +1,4 @@
#include <unistd.h>
# include <unistd.h>

#include <QCoreApplication>
#include <QRegExp>
Expand Down Expand Up @@ -416,7 +416,7 @@ void NetworkControlClient::readClient(void)
while (socket->canReadLine())
{
lineIn = socket->readLine();
lineIn.replace(QRegExp("[^-a-zA-Z0-9\\s\\.:_#/$%&()*+,;<=>?\\[\\]\\|]"), "");
// lineIn.replace(QRegExp("[^-a-zA-Z0-9\\s\\.:_#/$%&()*+,;<=>?\\[\\]\\|]"), "");
lineIn.replace(QRegExp("[\r\n]"), "");
lineIn.replace(QRegExp("^\\s"), "");

Expand Down Expand Up @@ -654,6 +654,86 @@ QString NetworkControl::processPlay(NetworkCommand *nc, int clientID)
.arg(GetMythUI()->GetCurrentLocation());
}
}
else if (is_abbrev("music", nc->getArg(1)))
{
if (GetMythUI()->GetCurrentLocation().toLower() != "playmusic")
{
return QString("ERROR: You are in %1 mode and this command is "
"only for MythMusic")
.arg(GetMythUI()->GetCurrentLocation());
}

if (nc->getArgCount() == 3)
{
if (is_abbrev("play", nc->getArg(2)))
message = "MUSIC_COMMAND PLAY";
else if (is_abbrev("pause", nc->getArg(2)))
message = "MUSIC_COMMAND PAUSE";
else if (is_abbrev("stop", nc->getArg(2)))
message = "MUSIC_COMMAND STOP";
else if (is_abbrev("getvolume", nc->getArg(2)))
{
gotAnswer = false;

MythEvent me(QString("MUSIC_COMMAND GET_VOLUME"));
gCoreContext->dispatch(me);

QTime timer;
timer.start();
while (timer.elapsed() < 2000 && !gotAnswer)
{
qApp->processEvents();
usleep(10000);
}

if (gotAnswer)
return answer;

return "unknown";
}
else if (is_abbrev("getmeta", nc->getArg(2)))
{
gotAnswer = false;

MythEvent me(QString("MUSIC_COMMAND GET_METADATA"));
gCoreContext->dispatch(me);

QTime timer;
timer.start();
while (timer.elapsed() < 2000 && !gotAnswer)
{
qApp->processEvents();
usleep(10000);
}

if (gotAnswer)
return answer;

return "unknown";
}
else
return QString("ERROR: Invalid 'play music' command");
}
else if (nc->getArgCount() > 3)
{
if (is_abbrev("setvolume", nc->getArg(2)))
message = QString("MUSIC_COMMAND SET_VOLUME %1")
.arg(nc->getArg(3));
else if (is_abbrev("track", nc->getArg(2)))
message = QString("MUSIC_COMMAND PLAY_TRACK %1")
.arg(nc->getArg(3));
else if (is_abbrev("url", nc->getArg(2)))
message = QString("MUSIC_COMAMND PLAY_URL %1")
.arg(nc->getArg(3));
else if (is_abbrev("file", nc->getArg(2)))
message = QString("MUSIC_COMMAND PLAY_FILE '%1'")
.arg(nc->getFrom(3));
else
return QString("ERROR: Invalid 'play music' command");
}
else
return QString("ERROR: Invalid 'play music' command");
}
// Everything below here requires us to be in playback mode so check to
// see if we are
else if (GetMythUI()->GetCurrentLocation().toLower() != "playback")
Expand Down Expand Up @@ -1010,35 +1090,44 @@ QString NetworkControl::processHelp(NetworkCommand *nc)
else if (is_abbrev("play", command))
{
helpText +=
"play volume NUMBER% - Change volume to given percentage value\r\n"
"play channel up - Change channel Up\r\n"
"play channel down - Change channel Down\r\n"
"play channel NUMBER - Change to a specific channel number\r\n"
"play chanid NUMBER - Change to a specific channel id (chanid)\r\n"
"play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n"
"play volume NUMBER% - Change volume to given percentage value\r\n"
"play channel up - Change channel Up\r\n"
"play channel down - Change channel Down\r\n"
"play channel NUMBER - Change to a specific channel number\r\n"
"play chanid NUMBER - Change to a specific channel id (chanid)\r\n"
"play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n"
"play program CHANID yyyy-MM-ddThh:mm:ss\r\n"
" - Play program with chanid & starttime\r\n"
" - Play program with chanid & starttime\r\n"
"play program CHANID yyyy-MM-ddThh:mm:ss resume\r\n"
" - Resume program with chanid & starttime\r\n"
" - Resume program with chanid & starttime\r\n"
"play save preview\r\n"
" - Save preview image from current position\r\n"
" - Save preview image from current position\r\n"
"play save preview FILENAME\r\n"
" - Save preview image to FILENAME\r\n"
" - Save preview image to FILENAME\r\n"
"play save preview FILENAME WxH\r\n"
" - Save preview image of size WxH\r\n"
"play seek beginning - Seek to the beginning of the recording\r\n"
"play seek forward - Skip forward in the video\r\n"
"play seek backward - Skip backwards in the video\r\n"
"play seek HH:MM:SS - Seek to a specific position\r\n"
"play speed pause - Pause playback\r\n"
"play speed normal - Playback at normal speed\r\n"
"play speed 1x - Playback at normal speed\r\n"
"play speed SPEEDx - Playback where SPEED must be a decimal\r\n"
"play speed 1/8x - Playback at 1/8x speed\r\n"
"play speed 1/4x - Playback at 1/4x speed\r\n"
"play speed 1/3x - Playback at 1/3x speed\r\n"
"play speed 1/2x - Playback at 1/2x speed\r\n"
"play stop - Stop playback\r\n";
" - Save preview image of size WxH\r\n"
"play seek beginning - Seek to the beginning of the recording\r\n"
"play seek forward - Skip forward in the video\r\n"
"play seek backward - Skip backwards in the video\r\n"
"play seek HH:MM:SS - Seek to a specific position\r\n"
"play speed pause - Pause playback\r\n"
"play speed normal - Playback at normal speed\r\n"
"play speed 1x - Playback at normal speed\r\n"
"play speed SPEEDx - Playback where SPEED must be a decimal\r\n"
"play speed 1/8x - Playback at 1/8x speed\r\n"
"play speed 1/4x - Playback at 1/4x speed\r\n"
"play speed 1/3x - Playback at 1/3x speed\r\n"
"play speed 1/2x - Playback at 1/2x speed\r\n"
"play stop - Stop playback\r\n"
"play music play - Resume playback (MythMusic)\r\n"
"play music pause - Pause playback (MythMusic)\r\n"
"play music stop - Stop Playback (MythMusic)\r\n"
"play music setvolume N - Set volume to number (MythMusic)\r\n"
"play music getvolume - Get current volume (MythMusic)\r\n"
"play music getmeta - Get metadata for current track (MythMusic)\r\n"
"play music file NAME - Play specified file (MythMusic)\r\n"
"play music track N - Switch to specified track (MythMusic)\r\n"
"play music url URL - Play specified URL (MythMusic)\r\n";
}
else if (is_abbrev("query", command))
{
Expand Down Expand Up @@ -1137,35 +1226,48 @@ void NetworkControl::customEvent(QEvent *e)
MythEvent *me = (MythEvent *)e;
QString message = me->Message();

if (message.left(15) != "NETWORK_CONTROL")
return;

QStringList tokens = message.simplified().split(" ");
if ((tokens.size() >= 3) &&
(tokens[1] == "ANSWER"))
if (message.left(13) == "MUSIC_CONTROL")
{
answer = tokens[2];
for (int i = 3; i < tokens.size(); i++)
answer += QString(" ") + tokens[i];
gotAnswer = true;
QStringList tokens = message.simplified().split(" ");
if ((tokens.size() >= 3) &&
(tokens[1] == "ANSWER"))
{
answer = tokens[2];
for (int i = 3; i < tokens.size(); i++)
answer += QString(" ") + tokens[i];
gotAnswer = true;
}

}
else if ((tokens.size() >= 4) &&
(tokens[1] == "RESPONSE"))
else if (message.left(15) == "NETWORK_CONTROL")
{
int clientID = tokens[2].toInt();
QString response = tokens[3];
for (int i = 4; i < tokens.size(); i++)
response += QString(" ") + tokens[i];
QStringList tokens = message.simplified().split(" ");
if ((tokens.size() >= 3) &&
(tokens[1] == "ANSWER"))
{
answer = tokens[2];
for (int i = 3; i < tokens.size(); i++)
answer += QString(" ") + tokens[i];
gotAnswer = true;
}
else if ((tokens.size() >= 4) &&
(tokens[1] == "RESPONSE"))
{
int clientID = tokens[2].toInt();
QString response = tokens[3];
for (int i = 4; i < tokens.size(); i++)
response += QString(" ") + tokens[i];

clientLock.lock();
NetworkControlClient *ncc = clients.at(clientID);
clientLock.unlock();
clientLock.lock();
NetworkControlClient *ncc = clients.at(clientID);
clientLock.unlock();

nrLock.lock();
networkControlReplies.push_back(new NetworkCommand(ncc, response));
nrLock.unlock();
nrLock.lock();
networkControlReplies.push_back(new NetworkCommand(ncc, response));
nrLock.unlock();

notifyDataAvailable();
notifyDataAvailable();
}
}
}
else if (e->type() == kNetworkControlDataReadyEvent)
Expand Down

0 comments on commit cb26018

Please sign in to comment.