- Renamed IMetadataWriter -> ITrackWriter for clarity

- Added IMetadataMap, IMetadataMapList as a generic way to represent more
  complex types of metadata that aren't just simple { id, value } tuples
  -- for example, complex album information including an id, value,
  artist, and artwork info
- Added a new AlbumListQuery that can be used by the SDK to get a rich
  list of album information for display in a UI. (CategoryListQuery still
  supports albums)
This commit is contained in:
casey langen 2017-02-08 20:57:43 -08:00
parent 62c25d50a6
commit 205f719c44
19 changed files with 709 additions and 35 deletions

View File

@ -115,7 +115,7 @@ bool TaglibMetadataReader::CanRead(const char *extension){
return false;
}
bool TaglibMetadataReader::Read(const char* uri, musik::core::sdk::IMetadataWriter *track) {
bool TaglibMetadataReader::Read(const char* uri, musik::core::sdk::ITrackWriter *track) {
std::string path(uri);
std::string extension;
@ -137,7 +137,7 @@ bool TaglibMetadataReader::Read(const char* uri, musik::core::sdk::IMetadataWrit
#include <iostream>
bool TaglibMetadataReader::GetGenericTag(const char* uri, musik::core::sdk::IMetadataWriter *target) {
bool TaglibMetadataReader::GetGenericTag(const char* uri, musik::core::sdk::ITrackWriter *target) {
#ifdef WIN32
TagLib::FileRef file(utf8to16(uri).c_str());
#else
@ -186,7 +186,7 @@ bool TaglibMetadataReader::GetGenericTag(const char* uri, musik::core::sdk::IMet
return false;
}
bool TaglibMetadataReader::GetID3v2Tag(const char* uri, musik::core::sdk::IMetadataWriter *track) {
bool TaglibMetadataReader::GetID3v2Tag(const char* uri, musik::core::sdk::ITrackWriter *track) {
TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding(TagLib::String::UTF8);
#ifdef WIN32
@ -356,7 +356,7 @@ bool TaglibMetadataReader::GetID3v2Tag(const char* uri, musik::core::sdk::IMetad
void TaglibMetadataReader::SetTagValue(
const char* key,
const TagLib::String tagString,
musik::core::sdk::IMetadataWriter *track)
musik::core::sdk::ITrackWriter *track)
{
std::string value(tagString.to8Bit(true));
track->SetValue(key, value.c_str());
@ -365,7 +365,7 @@ void TaglibMetadataReader::SetTagValue(
void TaglibMetadataReader::SetTagValue(
const char* key,
const char* string,
musik::core::sdk::IMetadataWriter *track)
musik::core::sdk::ITrackWriter *track)
{
std::string temp(string);
track->SetValue(key, temp.c_str());
@ -374,7 +374,7 @@ void TaglibMetadataReader::SetTagValue(
void TaglibMetadataReader::SetTagValue(
const char* key,
const int tagInt,
musik::core::sdk::IMetadataWriter *target)
musik::core::sdk::ITrackWriter *target)
{
std::string temp = boost::str(boost::format("%1%") % tagInt);
target->SetValue(key, temp.c_str());
@ -383,7 +383,7 @@ void TaglibMetadataReader::SetTagValue(
void TaglibMetadataReader::SetTagValues(
const char* key,
const TagLib::ID3v2::FrameList &frame,
musik::core::sdk::IMetadataWriter *target)
musik::core::sdk::ITrackWriter *target)
{
if (!frame.isEmpty()) {
TagLib::ID3v2::FrameList::ConstIterator value = frame.begin();
@ -401,7 +401,7 @@ void TaglibMetadataReader::SetTagValues(
void TaglibMetadataReader::SetSlashSeparatedValues(
const char* key,
TagLib::String tagString,
musik::core::sdk::IMetadataWriter *track)
musik::core::sdk::ITrackWriter *track)
{
if(!tagString.isEmpty()) {
std::string value(tagString.to8Bit(true));
@ -419,7 +419,7 @@ void TaglibMetadataReader::SetSlashSeparatedValues(
void TaglibMetadataReader::SetSlashSeparatedValues(
const char* key,
const TagLib::ID3v2::FrameList &frame,
musik::core::sdk::IMetadataWriter *track)
musik::core::sdk::ITrackWriter *track)
{
if(!frame.isEmpty()) {
TagLib::ID3v2::FrameList::ConstIterator value = frame.begin();
@ -432,7 +432,7 @@ void TaglibMetadataReader::SetSlashSeparatedValues(
void TaglibMetadataReader::SetAudioProperties(
TagLib::AudioProperties *audioProperties,
musik::core::sdk::IMetadataWriter *track)
musik::core::sdk::ITrackWriter *track)
{
/* FIXME: it's overkill to bring boost in just to convert ints to strings */

View File

@ -60,47 +60,47 @@ class TaglibMetadataReader : public musik::core::sdk::IMetadataReader {
public:
TaglibMetadataReader();
virtual ~TaglibMetadataReader();
virtual bool Read(const char *uri, musik::core::sdk::IMetadataWriter *target);
virtual bool Read(const char *uri, musik::core::sdk::ITrackWriter *target);
virtual bool CanRead(const char *extension);
virtual void Destroy();
private:
void SetTagValue(
const char* key,
const char* string,musik::core::sdk::IMetadataWriter *target);
const char* string,musik::core::sdk::ITrackWriter *target);
void SetTagValue(
const char* key,
const TagLib::String tagString,
musik::core::sdk::IMetadataWriter *target);
musik::core::sdk::ITrackWriter *target);
void SetTagValue(
const char* key,
const int tagInt,musik::core::sdk::IMetadataWriter *target);
const int tagInt,musik::core::sdk::ITrackWriter *target);
void SetTagValues(const char* key,
const TagLib::ID3v2::FrameList &frame,
musik::core::sdk::IMetadataWriter *target);
musik::core::sdk::ITrackWriter *target);
void SetAudioProperties(
TagLib::AudioProperties *audioProperties,
musik::core::sdk::IMetadataWriter *target);
musik::core::sdk::ITrackWriter *target);
void SetSlashSeparatedValues(
const char* key,
const TagLib::ID3v2::FrameList &frame,
musik::core::sdk::IMetadataWriter *target);
musik::core::sdk::ITrackWriter *target);
void SetSlashSeparatedValues(
const char* key,
TagLib::String tagString,
musik::core::sdk::IMetadataWriter *target);
musik::core::sdk::ITrackWriter *target);
bool GetID3v2Tag(
const char* uri,
musik::core::sdk::IMetadataWriter *target);
musik::core::sdk::ITrackWriter *target);
bool GetGenericTag(
const char* uri,
musik::core::sdk::IMetadataWriter *target);
musik::core::sdk::ITrackWriter *target);
};

View File

@ -100,6 +100,9 @@
<ClCompile Include="library\LocalLibrary.cpp" />
<ClCompile Include="library\LibraryFactory.cpp" />
<ClCompile Include="library\LocalSimpleDataProvider.cpp" />
<ClCompile Include="library\metadata\MetadataMap.cpp" />
<ClCompile Include="library\metadata\MetadataMapList.cpp" />
<ClCompile Include="library\query\local\AlbumListQuery.cpp" />
<ClCompile Include="library\query\local\CategoryListQuery.cpp" />
<ClCompile Include="library\query\local\CategoryTrackListQuery.cpp" />
<ClCompile Include="library\query\local\DeletePlaylistQuery.cpp" />
@ -151,6 +154,9 @@
<ClInclude Include="library\LibraryFactory.h" />
<ClInclude Include="library\LocalLibraryConstants.h" />
<ClInclude Include="library\LocalSimpleDataProvider.h" />
<ClInclude Include="library\metadata\MetadataMap.h" />
<ClInclude Include="library\metadata\MetadataMapList.h" />
<ClInclude Include="library\query\local\AlbumListQuery.h" />
<ClInclude Include="library\query\local\CategoryListQuery.h" />
<ClInclude Include="library\query\local\CategoryTrackListQuery.h" />
<ClInclude Include="library\query\local\DeletePlaylistQuery.h" />
@ -182,6 +188,8 @@
<ClInclude Include="sdk\IDSP.h" />
<ClInclude Include="sdk\IDataStream.h" />
<ClInclude Include="sdk\IDataStreamFactory.h" />
<ClInclude Include="sdk\IMetadataMap.h" />
<ClInclude Include="sdk\IMetadataMapList.h" />
<ClInclude Include="sdk\IMetadataReader.h" />
<ClInclude Include="sdk\IMetadataValue.h" />
<ClInclude Include="sdk\IMetadataValueList.h" />
@ -191,7 +199,6 @@
<ClInclude Include="sdk\IPlaybackRemote.h" />
<ClInclude Include="sdk\IPlaybackService.h" />
<ClInclude Include="sdk\IPlugin.h" />
<ClInclude Include="sdk\IMetadataWriter.h" />
<ClInclude Include="db\Connection.h" />
<ClInclude Include="db\ScopedTransaction.h" />
<ClInclude Include="db\Statement.h" />
@ -205,6 +212,7 @@
<ClInclude Include="sdk\ITrack.h" />
<ClInclude Include="sdk\ITrackList.h" />
<ClInclude Include="sdk\ITrackListEditor.h" />
<ClInclude Include="sdk\ITrackWriter.h" />
<ClInclude Include="sdk\IVisualizer.h" />
<ClInclude Include="support\Common.h" />
<ClInclude Include="support\PreferenceKeys.h" />

View File

@ -38,6 +38,9 @@
<Filter Include="src\library\query\local">
<UniqueIdentifier>{73173bbc-5951-460f-814d-25d1b71bf362}</UniqueIdentifier>
</Filter>
<Filter Include="src\library\metadata">
<UniqueIdentifier>{f3766aee-efaf-49ed-b030-67290c5c2f31}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
@ -160,6 +163,15 @@
<ClCompile Include="plugin\Plugins.cpp">
<Filter>src\plugin</Filter>
</ClCompile>
<ClCompile Include="library\metadata\MetadataMap.cpp">
<Filter>src\library\metadata</Filter>
</ClCompile>
<ClCompile Include="library\metadata\MetadataMapList.cpp">
<Filter>src\library\metadata</Filter>
</ClCompile>
<ClCompile Include="library\query\local\AlbumListQuery.cpp">
<Filter>src\library\query\local</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.hpp">
@ -240,9 +252,6 @@
<ClInclude Include="sdk\IMetadataReader.h">
<Filter>src\sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\IMetadataWriter.h">
<Filter>src\sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\IPlugin.h">
<Filter>src\sdk</Filter>
</ClInclude>
@ -399,5 +408,23 @@
<ClInclude Include="plugin\Plugins.h">
<Filter>src\plugin</Filter>
</ClInclude>
<ClInclude Include="sdk\IMetadataMapList.h">
<Filter>src\sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\IMetadataMap.h">
<Filter>src\sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ITrackWriter.h">
<Filter>src\sdk</Filter>
</ClInclude>
<ClInclude Include="library\metadata\MetadataMapList.h">
<Filter>src\library\metadata</Filter>
</ClInclude>
<ClInclude Include="library\metadata\MetadataMap.h">
<Filter>src\library\metadata</Filter>
</ClInclude>
<ClInclude Include="library\query\local\AlbumListQuery.h">
<Filter>src\library\query\local</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -37,9 +37,10 @@
#include <core/debug.h>
#include <core/library/query/local/SearchTrackListQuery.h>
#include <core/library/query/local/CategoryTrackListQuery.h>
#include <core/library/query/local/AlbumListQuery.h>
#include <core/library/query/local/CategoryListQuery.h>
#include <core/library/query/local/CategoryTrackListQuery.h>
#include <core/library/query/local/SearchTrackListQuery.h>
#define TAG "LocalSimpleDataProvider"
@ -112,3 +113,21 @@ IMetadataValueList* LocalSimpleDataProvider::QueryCategory(const char* type, con
return nullptr;
}
IMetadataMapList* LocalSimpleDataProvider::QueryAlbums(const char* filter) {
try {
std::shared_ptr<AlbumListQuery> search(
new AlbumListQuery(std::string(filter ? filter : "")));
this->library->Enqueue(search, ILibrary::QuerySynchronous);
if (search->GetStatus() == IQuery::Finished) {
return search->GetSdkResult();
}
}
catch (...) {
musik::debug::err(TAG, "QueryAlbums failed");
}
return nullptr;
}

View File

@ -58,6 +58,9 @@ namespace musik { namespace core { namespace db { namespace local {
const char* type,
const char* filter = "");
virtual musik::core::sdk::IMetadataMapList*
QueryAlbums(const char* filter = "");
private:
musik::core::ILibraryPtr library;
};

View File

@ -0,0 +1,112 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"
#include "MetadataMap.h"
#include <core/library/query/local/LocalQueryBase.h>
#include <core/library/LocalLibraryConstants.h>
#include <core/db/Connection.h>
#include <core/db/Statement.h>
#include <core/support/Common.h>
using namespace musik::core;
using namespace musik::core::db;
using namespace musik::core::library;
using namespace musik::core::sdk;
/* a wrapper around a shared pointer to a MetadataMap. we
can pass this to a plugin and it will keep the instance
around until it's released, even if the containing list is
released. */
struct SdkWrapper : public IMetadataMap {
MetadataMapPtr wrapped;
SdkWrapper(MetadataMapPtr wrapped) { this->wrapped = wrapped; };
virtual void Release() { this->wrapped.reset(); }
virtual unsigned long long GetId() { return this->wrapped->GetId(); }
virtual int GetValue(const char* key, char* dst, int size) { return this->wrapped->GetValue(key, dst, size); }
virtual const char* GetDescription() { return this->wrapped->GetDescription(); }
virtual const char* GetType() { return this->wrapped->GetType(); }
};
MetadataMap::MetadataMap(
unsigned long long id,
const std::string& description,
const std::string& type)
{
this->id = id;
this->description = description;
this->type = type;
}
MetadataMap::~MetadataMap() {
}
void MetadataMap::Release() {
/* nothing... */
}
unsigned long long MetadataMap::GetId() {
return this->id;
}
int MetadataMap::GetValue(const char* key, char* dst, int size) {
auto it = metadata.find(key);
if (it != metadata.end()) {
return CopyString(it->second, dst, size);
}
if (dst && size > 0) {
dst[0] = 0;
}
return 0;
}
const char* MetadataMap::GetDescription() {
return this->description.c_str();
}
const char* MetadataMap::GetType() {
return this->type.c_str();
}
void MetadataMap::SetValue(const char* key, const std::string& value) {
this->metadata[key] = value;
}
musik::core::sdk::IMetadataMap* MetadataMap::GetSdkValue() {
return new SdkWrapper(shared_from_this());
}

View File

@ -0,0 +1,73 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <core/sdk/IMetadataMap.h>
#include <unordered_map>
namespace musik { namespace core {
class MetadataMap :
public musik::core::sdk::IMetadataMap,
public std::enable_shared_from_this<MetadataMap>
{
public:
MetadataMap(
unsigned long long id,
const std::string& description,
const std::string& type);
virtual ~MetadataMap();
/* IMetadataMap */
virtual void Release();
virtual unsigned long long GetId();
virtual int GetValue(const char* key, char* dst, int size);
virtual const char* GetDescription();
virtual const char* GetType();
/* implementation specific */
void SetValue(const char* key, const std::string& value);
musik::core::sdk::IMetadataMap* GetSdkValue();
private:
unsigned long long id;
std::string type, description;
std::map<std::string, std::string> metadata;
};
using MetadataMapPtr = std::shared_ptr<MetadataMap>;
} }

View File

@ -0,0 +1,80 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"
#include "MetadataMapList.h"
using namespace musik::core;
using namespace musik::core::db;
using namespace musik::core::sdk;
struct SdkWrapper : public IMetadataMapList {
MetadataMapListPtr wrapped;
SdkWrapper(MetadataMapListPtr wrapped) { this->wrapped = wrapped; }
virtual void Release() { this->wrapped.reset(); }
virtual size_t Count() const { return this->wrapped->Count(); }
virtual IMetadataMap* GetMetadata(size_t index) const { return this->wrapped->GetMetadata(index); }
};
MetadataMapList::MetadataMapList() {
}
MetadataMapList::~MetadataMapList() {
}
void MetadataMapList::Release() {
/* nothing. wrapper helps with cleanup. */
}
size_t MetadataMapList::Count() const {
return this->entries.size();
}
IMetadataMap* MetadataMapList::GetMetadata(size_t index) const {
return this->entries.at(index)->GetSdkValue();
}
void MetadataMapList::Add(MetadataMapPtr entry) {
this->entries.push_back(entry);
}
MetadataMapPtr MetadataMapList::Get(size_t index) {
return this->entries.at(index);
}
IMetadataMapList* MetadataMapList::GetSdkValue() {
return new SdkWrapper(shared_from_this());
}

View File

@ -0,0 +1,67 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <core/sdk/IMetadataMapList.h>
#include "MetadataMap.h"
#include <vector>
namespace musik { namespace core {
class MetadataMapList :
public musik::core::sdk::IMetadataMapList,
public std::enable_shared_from_this<MetadataMapList>
{
public:
MetadataMapList();
virtual ~MetadataMapList();
/* IMetadataMapList */
virtual void Release();
virtual size_t Count() const;
virtual musik::core::sdk::IMetadataMap* GetMetadata(size_t index) const;
/* implementation specific */
void Add(MetadataMapPtr entry);
MetadataMapPtr Get(size_t index);
musik::core::sdk::IMetadataMapList* GetSdkValue();
private:
std::vector<MetadataMapPtr> entries;
};
using MetadataMapListPtr = std::shared_ptr<MetadataMapList>;
} }

View File

@ -0,0 +1,122 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"
#include "AlbumListQuery.h"
#include <core/library/LocalLibraryConstants.h>
#include <core/db/Statement.h>
using musik::core::db::Statement;
using musik::core::db::Row;
using namespace musik::core;
using namespace musik::core::db;
using namespace musik::core::db::local;
using namespace musik::core::library::constants;
using namespace musik::core::sdk;
#define RESET_RESULT(x) x.reset(new MetadataMapList())
static const std::string COLUMNS =
"albums.id, "
"albums.name as album, "
"tracks.album_artist_id, "
"artists.name as album_artist, "
"tracks.thumbnail_id ";
static const std::string TABLES =
"albums, tracks, artists ";
static const std::string FILTER_PREDICATE =
"LOWER(album) like ? AND ";
static const std::string GENERAL_PREDICATE =
"albums.id = tracks.album_id AND "
"artists.id = tracks.album_artist_id ";
static const std::string ORDER =
"albums.name asc ";
AlbumListQuery::AlbumListQuery(const std::string& filter)
: filter(filter) {
RESET_RESULT(result);
}
AlbumListQuery::~AlbumListQuery() {
}
MetadataMapListPtr AlbumListQuery::GetResult() {
return this->result;
}
musik::core::sdk::IMetadataMapList* AlbumListQuery::GetSdkResult() {
return this->result->GetSdkValue();
}
bool AlbumListQuery::OnRun(Connection& db) {
RESET_RESULT(result);
bool filtered = this->filter.size() > 0;
std::string query = "SELECT " + COLUMNS + " FROM " + TABLES + " WHERE ";
query += filtered ? FILTER_PREDICATE : "";
query += GENERAL_PREDICATE + " ORDER BY " + ORDER + ";";
Statement stmt(query.c_str(), db);
if (filtered) {
/* transform "FilteR" => "%filter%" */
std::string wild = this->filter;
std::transform(wild.begin(), wild.end(), wild.begin(), tolower);
wild = "%" + wild + "%";
stmt.BindText(0, wild);
}
while (stmt.Step() == Row) {
std::shared_ptr<MetadataMap> row(new MetadataMap(
(unsigned long long) stmt.ColumnInt64(0),
stmt.ColumnText(1),
"album"));
row->SetValue(Track::ALBUM_ARTIST_ID, stmt.ColumnText(2));
row->SetValue(Track::ALBUM_ARTIST, stmt.ColumnText(3));
row->SetValue(Track::THUMBNAIL_ID, stmt.ColumnText(4));
result->Add(row);
}
return true;
}

View File

@ -0,0 +1,62 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <core/library/query/local/LocalQueryBase.h>
#include <core/library/metadata/MetadataMapList.h>
#include <core/db/Connection.h>
namespace musik { namespace core { namespace db { namespace local {
class AlbumListQuery : public musik::core::db::LocalQueryBase {
public:
AlbumListQuery(
const std::string& filter = "");
virtual ~AlbumListQuery();
std::string Name() { return "AlbumListQuery"; }
musik::core::MetadataMapListPtr GetResult();
musik::core::sdk::IMetadataMapList* GetSdkResult();
protected:
virtual bool OnRun(musik::core::db::Connection &db);
std::string filter;
musik::core::MetadataMapListPtr result;
};
} } } }

View File

@ -34,7 +34,7 @@
#pragma once
#include <core/sdk/IMetadataWriter.h>
#include <core/sdk/ITrackWriter.h>
#include <core/library/ILibrary.h>
#include <core/sdk/ITrack.h>
#include <boost/shared_ptr.hpp>
@ -48,7 +48,7 @@ namespace musik { namespace core {
typedef std::vector<TrackPtr> TrackVector;
class Track :
public musik::core::sdk::IMetadataWriter,
public musik::core::sdk::ITrackWriter,
public musik::core::sdk::ITrack
{
public:

View File

@ -34,7 +34,7 @@
#pragma once
#include "IMetadataWriter.h"
#include "ITrackWriter.h"
#include "IBuffer.h"
namespace musik { namespace core { namespace sdk {
@ -42,9 +42,9 @@ namespace musik { namespace core { namespace sdk {
class IAnalyzer {
public:
virtual void Destroy() = 0;
virtual bool Start(musik::core::sdk::IMetadataWriter *target) = 0;
virtual bool Analyze(musik::core::sdk::IMetadataWriter *target, IBuffer *buffer) = 0;
virtual bool End(musik::core::sdk::IMetadataWriter *target) = 0;
virtual bool Start(musik::core::sdk::ITrackWriter *target) = 0;
virtual bool Analyze(musik::core::sdk::ITrackWriter *target, IBuffer *buffer) = 0;
virtual bool End(musik::core::sdk::ITrackWriter *target) = 0;
};
} } }

View File

@ -0,0 +1,49 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
namespace musik { namespace core { namespace sdk {
class IMetadataMap {
public:
virtual void Release() = 0;
virtual unsigned long long GetId() = 0;
virtual int GetValue(const char* key, char* dst, int size) = 0;
virtual const char* GetDescription() = 0;
virtual const char* GetType() = 0;
};
} } }

View File

@ -0,0 +1,49 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "IMetadataMap.h"
namespace musik { namespace core { namespace sdk {
class IMetadataMapList {
public:
virtual void Release() = 0;
virtual size_t Count() const = 0;
virtual IMetadataMap* GetMetadata(size_t index) const = 0;
};
} } }

View File

@ -34,13 +34,13 @@
#pragma once
#include "IMetadataWriter.h"
#include "ITrackWriter.h"
namespace musik { namespace core { namespace sdk {
class IMetadataReader {
public:
virtual bool Read(const char *uri, musik::core::sdk::IMetadataWriter *target) = 0;
virtual bool Read(const char *uri, musik::core::sdk::ITrackWriter *target) = 0;
virtual bool CanRead(const char *extension) = 0;
virtual void Destroy() = 0;
};

View File

@ -36,6 +36,7 @@
#include "ITrackList.h"
#include "IMetadataValueList.h"
#include "IMetadataMapList.h"
namespace musik { namespace core { namespace sdk {
@ -51,6 +52,8 @@ namespace musik { namespace core { namespace sdk {
virtual IMetadataValueList* QueryCategory(
const char* type,
const char* filter = "") = 0;
virtual IMetadataMapList* QueryAlbums(const char* filter = "") = 0;
};
} } }

View File

@ -36,7 +36,7 @@
namespace musik { namespace core { namespace sdk {
class IMetadataWriter {
class ITrackWriter {
public:
virtual void SetValue(const char* metakey, const char* value) = 0;
virtual void ClearValue(const char* metakey) = 0;