TTKMusicPlayer  3.7.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::run(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::run(const QStringList &args) const
51 {
52  TTK_INFO_STREAM("Command line args:" << args);
53  if(args.isEmpty())
54  {
55  return;
56  }
57 
58  TTKCommandLineOption op0("-h", "--help", "Show command line help options");
59  TTKCommandLineOption op1("-List", "--file-to-list", "Add file to playlist");
60  TTKCommandLineOption op2("-Open", "--file-to-list-play", "Add file to playlist and play it");
61 // TTKCommandLineOption op3("-p", "--play", "Pause if playing, play otherwise");
62 // TTKCommandLineOption op4("-s", "--stop", "Stop current song");
63 // TTKCommandLineOption op5("--next", "Start playing next song");
64 // TTKCommandLineOption op6("--previous", "Start playing previous song");
65 // TTKCommandLineOption op7("--toggle-mute", "Mute/Restore volume");
66 // TTKCommandLineOption op8("--volume", "Set playback volume (example: --volume 20)");
67 // TTKCommandLineOption op9("--add-file", "Display add file dialog");
68 // TTKCommandLineOption op10("--add-dir", "Display add directory dialog");
69 // TTKCommandLineOption op11("--add-url", "Display add url path dialog");
70 
71  TTKCommandLineParser parser;
72  parser.addOption(op0);
73  parser.addOption(op1);
74  parser.addOption(op2);
75  parser.process(args);
76 
77  if(parser.isSet(op0))
78  {
79  parser.showHelp();
80  return;
81  }
82 
83  if(parser.isSet(op1))
84  {
86  }
87  else if(parser.isSet(op2))
88  {
90  }
91 }
92 
94 {
95  const QString &buffer = QString::fromUtf8((char*)m_memory.data());
96  if(buffer.isEmpty())
97  {
98  return;
99  }
100 
101  m_memory.lock();
102  memset(m_memory.data(), 0, MEMORY_SIZE);
103  m_memory.unlock();
104 
105  run(buffer.split(TTK_SPLITER));
106 }
static MusicApplication * instance()
QString value(const TTKCommandLineOption &option) const
void run(const QStringList &args) const
#define TTK_SPLITER
Definition: ttkglobal.h:199
void run(const QStringList &args) const
The class of the command line option.
bool isSet(const TTKCommandLineOption &option) const
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
#define MEMORY_KEY
bool addOption(const TTKCommandLineOption &option)
void importSongsByOutside(const QString &path, bool play)
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
#define MEMORY_SIZE
void showHelp() const
MusicProcessServer(QObject *parent=nullptr)
The class of the command line parser.