MythTV  master
music.cpp
Go to the documentation of this file.
1 // Program Name: music.cpp
3 // Created : July 20, 2017
4 //
5 // Copyright (c) 2017 Paul Harrison <pharrison@mythtv.org>
6 //
7 // Licensed under the GPL v2 or later, see COPYING for details
8 //
10 
11 #include <cmath>
12 #include <unistd.h>
13 
14 #include "music.h"
15 
16 #include "musicmetadata.h"
17 
18 #include "mythversion.h"
19 #include "serviceUtil.h"
20 
22 //
24 
26  int nCount)
27 {
28  AllMusic *all_music = new AllMusic();
29 
30  while (!all_music->doneLoading())
31  {
32  qApp->processEvents();
33  usleep(50000);
34  }
35 
36  MetadataPtrList *musicList = all_music->getAllMetadata();
37 
38  // ----------------------------------------------------------------------
39  // Build Response
40  // ----------------------------------------------------------------------
41 
42  DTC::MusicMetadataInfoList *pMusicMetadataInfos = new DTC::MusicMetadataInfoList();
43 
44  nStartIndex = (nStartIndex > 0) ? min( nStartIndex, musicList->count() ) : 0;
45  nCount = (nCount > 0) ? min( nCount, musicList->count() ) : musicList->count();
46  int nEndIndex = min((nStartIndex + nCount), musicList->count() );
47 
48  for( int n = nStartIndex; n < nEndIndex; n++ )
49  {
50  DTC::MusicMetadataInfo *pMusicMetadataInfo = pMusicMetadataInfos->AddNewMusicMetadataInfo();
51 
52  MusicMetadata *metadata = musicList->at(n);
53 
54  if (metadata)
55  FillMusicMetadataInfo ( pMusicMetadataInfo, metadata, true );
56  }
57 
58  int curPage = 0, totalPages = 0;
59  if (nCount == 0)
60  totalPages = 1;
61  else
62  totalPages = (int)ceil((float)musicList->count() / nCount);
63 
64  if (totalPages == 1)
65  curPage = 1;
66  else
67  {
68  curPage = (int)ceil((float)nStartIndex / nCount) + 1;
69  }
70 
71  pMusicMetadataInfos->setStartIndex ( nStartIndex );
72  pMusicMetadataInfos->setCount ( nCount );
73  pMusicMetadataInfos->setCurrentPage ( curPage );
74  pMusicMetadataInfos->setTotalPages ( totalPages );
75  pMusicMetadataInfos->setTotalAvailable( musicList->count() );
76  pMusicMetadataInfos->setAsOf ( MythDate::current() );
77  pMusicMetadataInfos->setVersion ( MYTH_BINARY_VERSION );
78  pMusicMetadataInfos->setProtoVer ( MYTH_PROTO_VERSION );
79 
80  delete all_music;
81 
82  return pMusicMetadataInfos;
83 }
84 
86 //
88 
90 {
91  AllMusic *all_music = new AllMusic();
92 
93  while (!all_music->doneLoading())
94  {
95  qApp->processEvents();
96  usleep(50000);
97  }
98 
99  MusicMetadata *metadata = all_music->getMetadata(Id);
100 
101  if (!metadata)
102  {
103  delete all_music;
104  throw(QString("No metadata found for selected ID!."));
105  }
106 
107  DTC::MusicMetadataInfo *pMusicMetadataInfo = new DTC::MusicMetadataInfo();
108 
109  FillMusicMetadataInfo(pMusicMetadataInfo, metadata, true);
110 
111  delete all_music;
112 
113  return pMusicMetadataInfo;
114 }
DTC::MusicMetadataInfo * GetTrack(int Id) override
Definition: music.cpp:89
DTC::MusicMetadataInfoList * GetTrackList(int StartIndex, int Count) override
Definition: music.cpp:25
MusicMetadata * getMetadata(int an_id)
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
#define MYTH_PROTO_VERSION
Increment this whenever the MythTV network protocol changes.
Definition: mythversion.h:48
QList< MusicMetadata * > MetadataPtrList
bool doneLoading() const
MusicMetadataInfo * AddNewMusicMetadataInfo()
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
void FillMusicMetadataInfo(DTC::MusicMetadataInfo *pVideoMetadataInfo, MusicMetadata *pMetadata, bool bDetails)
MetadataPtrList * getAllMetadata(void)