TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicprocessmanager.cpp
Go to the documentation of this file.
1 #include "musicprocessmanager.h"
2 #include "musicapplication.h"
3 #include "ttkcommandline.h"
4 
5 #define MEMORY_SIZE 512 * TTK_SN_KB2B
6 #define MEMORY_KEY TTK_STR_CAT(TTK_AUTHOR_NAME, TTK_DEFAULT_STR, TTK_APP_NAME)
7 
8 void MusicProcessClient::execute(const QStringList &args) const
9 {
10  QSharedMemory client;
11  client.setKey(MEMORY_KEY);
12 
13  client.attach();
14 
15  if(client.size() <= 0)
16  {
17  return;
18  }
19 
20  client.lock();
21  const QString &data = args.join(TTK_SPLITER);
22  memcpy(client.data(), data.toUtf8().constData(), data.length());
23  client.unlock();
24  client.detach();
25 }
26 
27 
29  : QObject(parent)
30 {
31  m_timer.setInterval(TTK_DN_S2MS);
32  connect(&m_timer, SIGNAL(timeout()), SLOT(timeout()));
33 
34  m_memory.setKey(MEMORY_KEY);
35  if(m_memory.isAttached())
36  {
37  m_memory.detach();
38  }
39 
40  m_memory.create(MEMORY_SIZE);
41  m_timer.start();
42 }
43 
45 {
46  m_timer.stop();
47  m_memory.detach();
48 }
49 
50 void MusicProcessServer::execute(const QStringList &args) const
51 {
52  if(args.isEmpty())
53  {
54  return;
55  }
56 
57  TTKCommandLineOption op0("-h", "--help", "Show command line help options");
58  TTKCommandLineOption op1("-List", "--file-to-list", "Add file to playlist");
59  TTKCommandLineOption op2("-Open", "--file-to-list-play", "Add file to playlist and play it");
60 // TTKCommandLineOption op3("-p", "--play", "Pause if playing, play otherwise");
61 // TTKCommandLineOption op4("-s", "--stop", "Stop current song");
62 // TTKCommandLineOption op5("--next", "Start playing next song");
63 // TTKCommandLineOption op6("--previous", "Start playing previous song");
64 // TTKCommandLineOption op7("--toggle-mute", "Mute/Restore volume");
65 // TTKCommandLineOption op8("--volume", "Set playback volume (example: --volume 20)");
66 // TTKCommandLineOption op9("--add-file", "Display add file dialog");
67 // TTKCommandLineOption op10("--add-dir", "Display add directory dialog");
68 // TTKCommandLineOption op11("--add-url", "Display add url path dialog");
69 
70  TTKCommandLineParser parser;
71  parser.addOption(op0);
72  parser.addOption(op1);
73  parser.addOption(op2);
74  parser.process(args);
75 
76  if(parser.isSet(op0))
77  {
78  parser.showHelp();
79  return;
80  }
81 
82  if(parser.isSet(op1))
83  {
85  }
86  else if(parser.isSet(op2))
87  {
89  }
90  else if(args.count() == 1)
91  {
92  const QString &url = args.front();
93  if(url.startsWith('-'))
94  {
95  return;
96  }
97 
98  // for direct play url
100  }
101 }
102 
104 {
105  const QString &buffer = QString::fromUtf8((char*)m_memory.data());
106  if(buffer.isEmpty())
107  {
108  return;
109  }
110 
111  m_memory.lock();
112  memset(m_memory.data(), 0, MEMORY_SIZE);
113  m_memory.unlock();
114 
115  execute(buffer.split(TTK_SPLITER));
116 }
static MusicApplication * instance()
QString value(const TTKCommandLineOption &option) const
void execute(const QStringList &args) const
#define TTK_SPLITER
Definition: ttkglobal.h:275
The class of the command line option.
bool isSet(const TTKCommandLineOption &option) const
#define MEMORY_KEY
bool addOption(const TTKCommandLineOption &option)
void importSongsByOutside(const QString &path, bool play)
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
#define MEMORY_SIZE
void execute(const QStringList &args) const
void showHelp() const
MusicProcessServer(QObject *parent=nullptr)
The class of the command line parser.