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 LICENSE for details
8 //
10 
11 // C++
12 #include <cmath>
13 #include <unistd.h>
14 
15 // MythTV
18 
19 // MythBackend
20 #include "music.h"
21 #include "serviceUtil.h"
22 
24 //
26 
28  int nCount)
29 {
30  auto *all_music = new AllMusic();
31 
32  while (!all_music->doneLoading())
33  {
34  qApp->processEvents();
35  usleep(50000);
36  }
37 
38  MetadataPtrList *musicList = all_music->getAllMetadata();
39 
40  // ----------------------------------------------------------------------
41  // Build Response
42  // ----------------------------------------------------------------------
43 
44  auto *pMusicMetadataInfos = new DTC::MusicMetadataInfoList();
45 
46  auto musicListCount = static_cast<int>(musicList->count());
47  nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, musicListCount ) : 0;
48  nCount = (nCount > 0) ? std::min( nCount, musicListCount ) : musicListCount;
49  int nEndIndex = std::min((nStartIndex + nCount), musicListCount );
50 
51  for( int n = nStartIndex; n < nEndIndex; n++ )
52  {
53  DTC::MusicMetadataInfo *pMusicMetadataInfo = pMusicMetadataInfos->AddNewMusicMetadataInfo();
54 
55  MusicMetadata *metadata = musicList->at(n);
56 
57  if (metadata)
58  FillMusicMetadataInfo ( pMusicMetadataInfo, metadata, true );
59  }
60 
61  int curPage = 0;
62  int totalPages = 0;
63  if (nCount == 0)
64  totalPages = 1;
65  else
66  totalPages = (int)std::ceil((float)musicList->count() / nCount);
67 
68  if (totalPages == 1)
69  curPage = 1;
70  else
71  {
72  curPage = (int)std::ceil((float)nStartIndex / nCount) + 1;
73  }
74 
75  pMusicMetadataInfos->setStartIndex ( nStartIndex );
76  pMusicMetadataInfos->setCount ( nCount );
77  pMusicMetadataInfos->setCurrentPage ( curPage );
78  pMusicMetadataInfos->setTotalPages ( totalPages );
79  pMusicMetadataInfos->setTotalAvailable( musicList->count() );
80  pMusicMetadataInfos->setAsOf ( MythDate::current() );
81  pMusicMetadataInfos->setVersion ( MYTH_BINARY_VERSION );
82  pMusicMetadataInfos->setProtoVer ( MYTH_PROTO_VERSION );
83 
84  delete all_music;
85 
86  return pMusicMetadataInfos;
87 }
88 
90 //
92 
94 {
95  auto *all_music = new AllMusic();
96 
97  while (!all_music->doneLoading())
98  {
99  qApp->processEvents();
100  usleep(50000);
101  }
102 
103  MusicMetadata *metadata = all_music->getMetadata(Id);
104 
105  if (!metadata)
106  {
107  delete all_music;
108  throw(QString("No metadata found for selected ID!."));
109  }
110 
111  auto *pMusicMetadataInfo = new DTC::MusicMetadataInfo();
112 
113  FillMusicMetadataInfo(pMusicMetadataInfo, metadata, true);
114 
115  delete all_music;
116 
117  return pMusicMetadataInfo;
118 }
serviceUtil.h
AllMusic
Definition: musicmetadata.h:418
MusicMetadata
Definition: musicmetadata.h:80
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
mythversion.h
MYTH_PROTO_VERSION
static constexpr const char * MYTH_PROTO_VERSION
Increment this whenever the MythTV network protocol changes.
Definition: mythversion.h:47
Music::GetTrackList
DTC::MusicMetadataInfoList * GetTrackList(int StartIndex, int Count) override
Definition: music.cpp:27
MYTH_BINARY_VERSION
static constexpr const char * MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
FillMusicMetadataInfo
void FillMusicMetadataInfo(DTC::MusicMetadataInfo *pVideoMetadataInfo, MusicMetadata *pMetadata, bool bDetails)
Definition: serviceUtil.cpp:515
music.h
MetadataPtrList
QList< MusicMetadata * > MetadataPtrList
Definition: musicmetadata.h:396
DTC::MusicMetadataInfo
Definition: musicMetadataInfo.h:25
DTC::MusicMetadataInfoList
Definition: musicMetadataInfoList.h:24
Music::GetTrack
DTC::MusicMetadataInfo * GetTrack(int Id) override
Definition: music.cpp:93
musicmetadata.h