Commit be669b3d authored by Camilo higuita's avatar Camilo higuita

fixing performance issues and polkishing the brain infor fetcher

parent 7c811634
......@@ -19,7 +19,7 @@ set(CMAKE_AUTORCC ON)
add_executable(vvave
qml.qrc
main.cpp
babe.cpp
# babe.cpp
vvave.cpp
# pulpo/services/geniusService.cpp
......@@ -41,7 +41,7 @@ add_executable(vvave
services/web/Spotify/spotify.cpp
db/conthread.cpp
db/collectionDB.cpp
settings/BabeSettings.cpp
# settings/BabeSettings.cpp
settings/fileloader.cpp
utils/brain.cpp
utils/babeconsole.cpp
......
......@@ -25,7 +25,22 @@
using namespace BAE;
CollectionDB::CollectionDB(QObject *parent) : QObject(parent)
{}
{
this->name = QUuid::createUuid().toString();
if(!BAE::fileExists(BAE::CollectionDBPath + BAE::DBName))
{
QDir collectionDBPath_dir(BAE::CollectionDBPath);
if (!collectionDBPath_dir.exists())
collectionDBPath_dir.mkpath(".");
this->openDB(this->name);
qDebug()<<"Collection doesn't exists, trying to create it" << BAE::CollectionDBPath + BAE::DBName;
this->prepareCollectionDB();
}else this->openDB(this->name);
}
CollectionDB::~CollectionDB()
{
......@@ -42,7 +57,6 @@ CollectionDB *CollectionDB::getInstance()
{
instance = new CollectionDB();
qDebug() << "getInstance(): First DBActions instance\n";
instance->init();
return instance;
} else
{
......@@ -51,28 +65,13 @@ CollectionDB *CollectionDB::getInstance()
}
}
void CollectionDB::init()
{
this->name = QUuid::createUuid().toString();
if(!BAE::fileExists(BAE::CollectionDBPath + BAE::DBName))
{
QDir collectionDBPath_dir(BAE::CollectionDBPath);
if (!collectionDBPath_dir.exists())
collectionDBPath_dir.mkpath(".");
this->openDB(this->name);
qDebug()<<"Collection doesn't exists, trying to create it" << BAE::CollectionDBPath + BAE::DBName;
this->prepareCollectionDB();
}else this->openDB(this->name);
}
void CollectionDB::prepareCollectionDB() const
void CollectionDB::prepareCollectionDB()
{
QSqlQuery query(this->m_db);
QFile file(":/db/script.sql");
qDebug()<< file.exists();
if (!file.exists())
{
......@@ -257,6 +256,7 @@ bool CollectionDB::addTrack(const FMH::MODEL &track)
auto artwork = track[FMH::MODEL_KEY::ARTWORK].isEmpty() ? "" : track[FMH::MODEL_KEY::ARTWORK];
auto artistTrack = track;
artistTrack[FMH::MODEL_KEY::ARTWORK] = "";
BAE::artworkCache(artistTrack, FMH::MODEL_KEY::ARTIST);
auto artistArtwork = artistTrack[FMH::MODEL_KEY::ARTWORK];
......
......@@ -36,7 +36,7 @@ class CollectionDB : public QObject
bool execQuery(const QString &queryTxt);
/*basic public actions*/
void prepareCollectionDB() const;
void prepareCollectionDB();
bool check_existance(const QString &tableName, const QString &searchId, const QString &search);
/* usefull actions */
......@@ -116,7 +116,6 @@ private:
QSqlDatabase m_db;
explicit CollectionDB( QObject *parent = nullptr);
~CollectionDB() override;
void init();
public slots:
......
......@@ -7,7 +7,7 @@
#include <QStyleHints>
#include <QQuickStyle>
#include <QCommandLineParser>
#include "babe.h"
#include "vvave.h"
#include "services/local/player.h"
#ifdef STATIC_KIRIGAMI
......@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
if(!args.isEmpty())
urls = args;
Babe bae;
vvave vvave;
/* Services */
YouTube youtube;
......@@ -84,13 +84,13 @@ int main(int argc, char *argv[])
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
{
qDebug()<<"FINISHED LOADING QML APP";
bae.refreshCollection();
if(!urls.isEmpty())
bae.openUrls(urls);
vvave.postActions();
// if(!urls.isEmpty())
// bae.openUrls(urls);
});
auto context = engine.rootContext();
context->setContextProperty("bae", &bae);
context->setContextProperty("vvave", &vvave);
context->setContextProperty("youtube", &youtube);
// context->setContextProperty("spotify", &spotify);
// context->setContextProperty("link", &bae.link);
......
......@@ -7,19 +7,18 @@ import QtQuick.Controls.Material 2.1
import "utils"
import "widgets"
import "widgets/MyBeatView"
import "widgets/PlaylistsView"
import "widgets/MainPlaylist"
import "widgets/SettingsView"
import "widgets/SearchView"
import "widgets/CloudView"
//import "widgets/CloudView"
import "view_models"
import "view_models/BabeTable"
import "services/local"
import "services/web"
import "services/web/Spotify"
//import "services/web/Spotify"
import "view_models/BabeGrid"
......@@ -59,7 +58,7 @@ Maui.ApplicationWindow
/*************************************************/
property bool isShuffle: Maui.FM.loadSettings("SHUFFLE","PLAYBACK", false)
property var currentTrack: ({
babe: "0",
fav: "0",
stars: "0"
})
......@@ -113,7 +112,7 @@ Maui.ApplicationWindow
/***************************************************/
/******************** UI COLORS *******************/
/*************************************************/
readonly property color babeColor: bae.babeColor() //"#140032"
readonly property color babeColor: "#f84172"
/*SIGNALS*/
signal missingAlert(var track)
......@@ -127,7 +126,7 @@ Maui.ApplicationWindow
var messageBody = "Do you want to remove it from your collection?"
notify("alert", message, messageBody, function ()
{
bae.removeTrack(currentTrack.url) //todo
// bae.removeTrack(currentTrack.url) //todo
mainPlaylist.table.model.remove(mainPlaylist.table.currentIndex)
})
}
......@@ -157,7 +156,7 @@ Maui.ApplicationWindow
altToolBars: false
accentColor: babeColor
headBarFGColor: altColorText
headBarBGColor: /*currentView === viewsIndex.vvave ? "#7e57c2" :*/ "#212121"
headBarBGColor: "#212121"
altColorText: darkTextColor
floatingBar: false
......@@ -166,14 +165,13 @@ Maui.ApplicationWindow
headBar.middleContent : [
Maui.ToolButton
{
iconName: "view-media-track"
iconName: "view-media-track"
active: currentView === viewsIndex.tracks
showIndicator: true
iconColor: active ? babeColor : altColorText
onClicked: currentView = viewsIndex.tracks
text: qsTr("Tracks")
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
Layout.fillHeight: true
},
......@@ -184,11 +182,8 @@ Maui.ApplicationWindow
iconName: /*"album"*/ "view-media-album-cover"
iconColor: currentView === viewsIndex.albums ? babeColor : altColorText
onClicked: currentView = viewsIndex.albums
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
Layout.fillHeight: true
showIndicator: true
},
Maui.ToolButton
......@@ -198,11 +193,8 @@ Maui.ApplicationWindow
iconName: "view-media-artist"
iconColor: currentView === viewsIndex.artists ? babeColor : altColorText
onClicked: currentView = viewsIndex.artists
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
Layout.fillHeight: true
showIndicator: true
},
Maui.ToolButton
......@@ -212,10 +204,9 @@ Maui.ApplicationWindow
iconName: "view-media-playlist"
iconColor: currentView === viewsIndex.playlists ? babeColor : altColorText
onClicked: currentView = viewsIndex.playlists
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
showIndicator: true
Layout.fillHeight: true
}
]
......@@ -285,15 +276,15 @@ Maui.ApplicationWindow
Layout.fillHeight: true
Layout.fillWidth: true
// leftContent: Maui.ToolButton
// {
// iconName: "headphones"
// visible: _drawer.modal
// iconColor: _drawer.visible ? babeColor : textColor
// onClicked: _drawer.visible = !_drawer.visible
// colorScheme.highlightColor: babeColor
// // text: qsTr("Now")
// }
// leftContent: Maui.ToolButton
// {
// iconName: "headphones"
// visible: _drawer.modal
// iconColor: _drawer.visible ? babeColor : textColor
// onClicked: _drawer.visible = !_drawer.visible
// colorScheme.highlightColor: babeColor
// // text: qsTr("Now")
// }
middleContent: [
......@@ -994,12 +985,12 @@ Maui.ApplicationWindow
Connections
{
target: bae
target: vvave
onRefreshTables: H.refreshCollection(size)
// onRefreshTracks: H.refreshTracks()
onRefreshAlbums: H.refreshAlbums()
// onRefreshArtists: H.refreshArtists()
onRefreshTracks: H.refreshTracks()
onRefreshAlbums: H.refreshAlbums()
onRefreshArtists: H.refreshArtists()
onCoverReady:
{
......
......@@ -153,7 +153,7 @@ struct REQUEST
QList<PULPO::INFO> info;
QList<PULPO::SERVICES> services;
std::function<void(REQUEST request, RESPONSES responses)> callback;
std::function<void(REQUEST request, RESPONSES responses)> callback = nullptr;
};
......
......@@ -71,6 +71,8 @@ void Pulpo::start()
lastfm->set(this->req);
break;
}
default: continue;
}
}
......
This diff is collapsed.
......@@ -22,7 +22,7 @@ public:
void set(const PULPO::REQUEST &request) override final;
protected:
// virtual void parseArtist(const QByteArray &array);
virtual void parseArtist(const QByteArray &array) override final;
virtual void parseAlbum(const QByteArray &array) override final;
// virtual void parseTrack(const QByteArray &array);
......
......@@ -74,4 +74,7 @@
<file>widgets/CloudView/CloudView.qml</file>
<file>widgets/SelectionBarMenu.qml</file>
</qresource>
<qresource prefix="/DB">
<file>db/script.sql</file>
</qresource>
</RCC>
......@@ -36,7 +36,7 @@ class BabeSettings : public QObject
void populateDB(const QStringList &paths);
private:
FileLoader fileLoader;
// FileLoader fileLoader;
CollectionDB *connection;
Brain *brainDeamon;
youtubedl *ytFetch;
......
#include "fileloader.h"
#include "../services/local/taginfo.h"
#include "../db/collectionDB.h"
FileLoader::FileLoader() : QObject(nullptr)
{
this->db = CollectionDB::getInstance();
qRegisterMetaType<BAE::DB>("BAE::DB");
qRegisterMetaType<BAE::TABLE>("BAE::TABLE");
qRegisterMetaType<QMap<BAE::TABLE, bool>>("QMap<BAE::TABLE,bool>");
this->moveToThread(&t);
t.start();
}
FileLoader::~FileLoader()
{
this->go = false;
this->t.quit();
this->t.wait();
}
void FileLoader::requestPaths(const QStringList& paths)
{
this->go = true;
QMetaObject::invokeMethod(this, "getTracks", Q_ARG(QStringList, paths));
}
void FileLoader::nextTrack()
{
this->wait = !this->wait;
}
void FileLoader::getTracks(const QStringList& paths)
{
QStringList urls;
for(auto path : paths)
{
if (QFileInfo(path).isDir())
{
this->db->addFolder(path);
QDirIterator it(path, FMH::FILTER_LIST[FMH::FILTER_TYPE::AUDIO], QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext())
urls << it.next();
}else if (QFileInfo(path).isFile())
urls << path;
}
int newTracks = 0;
if(urls.isEmpty()) return;
TagInfo info;
for(auto url : urls)
{
if(!this->go)
break;
if(this->db->check_existance(BAE::TABLEMAP[BAE::TABLE::TRACKS], FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url))
continue;
if(!info.feed(url))
continue;
auto track = info.getTrack();
auto genre = info.getGenre();
auto album = BAE::fixString(info.getAlbum());
auto title = BAE::fixString(info.getTitle()); /* to fix*/
auto artist = BAE::fixString(info.getArtist());
auto sourceUrl = QFileInfo(url).dir().path();
auto duration = info.getDuration();
auto year = info.getYear();
FMH::MODEL trackMap =
{
{FMH::MODEL_KEY::URL, url},
{FMH::MODEL_KEY::TRACK, QString::number(track)},
{FMH::MODEL_KEY::TITLE, title},
{FMH::MODEL_KEY::ARTIST, artist},
{FMH::MODEL_KEY::ALBUM, album},
{FMH::MODEL_KEY::DURATION,QString::number(duration)},
{FMH::MODEL_KEY::GENRE, genre},
{FMH::MODEL_KEY::SOURCE, sourceUrl},
{FMH::MODEL_KEY::FAV, url.startsWith(BAE::YoutubeCachePath) ? "1": "0"},
{FMH::MODEL_KEY::RELEASEDATE, QString::number(year)}
};
qDebug() << url;
BAE::artworkCache(trackMap, FMH::MODEL_KEY::ALBUM);
if(this->db->addTrack(trackMap))
newTracks++;
}
// this->t.msleep(100);
emit this->finished(newTracks);
this->go = false;
}
#ifndef FILELOADER_H
#define FILELOADER_H
#include <QThread>
#include <QObject>
#include <QDirIterator>
#include "../services/local/taginfo.h"
#include "../db/collectionDB.h"
#include "utils/bae.h"
class CollectionDB;
class FileLoader : public QObject
namespace FLoader
{
Q_OBJECT
public:
FileLoader();
// returns the number of new items added to the collection db
inline uint getTracks(const QStringList& paths)
{
QStringList urls;
auto db = CollectionDB::getInstance();
for(const auto &path : paths)
{
if (QFileInfo(path).isDir())
{
db->addFolder(path);
QDirIterator it(path, FMH::FILTER_LIST[FMH::FILTER_TYPE::AUDIO], QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext())
urls << it.next();
}else if (QFileInfo(path).isFile())
urls << path;
}
~FileLoader() override;
uint newTracks = 0;
void requestPaths(const QStringList &paths);
if(urls.isEmpty())
return newTracks;
void nextTrack();
TagInfo info;
for(auto url : urls)
{
if(db->check_existance(BAE::TABLEMAP[BAE::TABLE::TRACKS], FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url))
continue;
public slots:
if(!info.feed(url))
continue;
void getTracks(const QStringList &paths);
const auto track = info.getTrack();
const auto genre = info.getGenre();
const auto album = BAE::fixString(info.getAlbum());
const auto title = BAE::fixString(info.getTitle()); /* to fix*/
const auto artist = BAE::fixString(info.getArtist());
const auto sourceUrl = QFileInfo(url).dir().path();
const auto duration = info.getDuration();
const auto year = info.getYear();
signals:
void trackReady(BAE::DB track);
void finished(int size);
void collectionSize(int size);
FMH::MODEL trackMap =
{
{FMH::MODEL_KEY::URL, url},
{FMH::MODEL_KEY::TRACK, QString::number(track)},
{FMH::MODEL_KEY::TITLE, title},
{FMH::MODEL_KEY::ARTIST, artist},
{FMH::MODEL_KEY::ALBUM, album},
{FMH::MODEL_KEY::DURATION,QString::number(duration)},
{FMH::MODEL_KEY::GENRE, genre},
{FMH::MODEL_KEY::SOURCE, sourceUrl},
{FMH::MODEL_KEY::FAV, url.startsWith(BAE::YoutubeCachePath) ? "1": "0"},
{FMH::MODEL_KEY::RELEASEDATE, QString::number(year)}
};
private:
QThread t;
CollectionDB *db;
bool go = false;
bool wait = true;
QStringList queue;
};
qDebug() << url;
BAE::artworkCache(trackMap, FMH::MODEL_KEY::ALBUM);
if(db->addTrack(trackMap))
newTracks++;
}
return newTracks;
}
}
#endif // FILELOADER_H
......@@ -45,13 +45,12 @@ function setStars(stars)
function refreshCollection(size)
{
if(!isMobile && size>0) bae.notify("Collection updated", size+" new tracks added...")
if(size>0) root.notify("emblem-info", "Collection updated", size+" new tracks added...")
refreshTracks()
refreshAlbums()
refreshArtists()
refreshFolders()
}
function refreshFolders()
{
......
......@@ -453,7 +453,7 @@ inline bool artworkCache(FMH::MODEL &track, const FMH::MODEL_KEY &type = FMH::MO
switch(type)
{
case FMH::MODEL_KEY::ALBUM:
if(fileName.startsWith(track[FMH::MODEL_KEY::ARTIST]+"_"+track[FMH::MODEL_KEY::ALBUM]))
if(fileName == (track[FMH::MODEL_KEY::ARTIST]+"_"+track[FMH::MODEL_KEY::ALBUM]))
{
track.insert(FMH::MODEL_KEY::ARTWORK, file);
return true;
......@@ -461,7 +461,7 @@ inline bool artworkCache(FMH::MODEL &track, const FMH::MODEL_KEY &type = FMH::MO
break;
case FMH::MODEL_KEY::ARTIST:
if(fileName.startsWith(track[FMH::MODEL_KEY::ARTIST]))
if(fileName == (track[FMH::MODEL_KEY::ARTIST]))
{
track.insert(FMH::MODEL_KEY::ARTWORK, file);
return true;
......
This diff is collapsed.
This diff is collapsed.
......@@ -24,13 +24,13 @@ Item
anchors.centerIn: parent
width: recSize
height: recSize
color: bae.moodColor(0)
color: vvave.moodColor(0)
radius: recRadius
border.color: altColor
border.width: 1
}
onClicked: colorClicked(bae.moodColor(0))
onClicked: colorClicked(vvave.moodColor(0))
}
ToolButton
{
......@@ -44,13 +44,13 @@ Item
anchors.centerIn: parent
width: recSize
height: recSize
color: bae.moodColor(1)
color: vvave.moodColor(1)
radius: recRadius
border.color: altColor
border.width: 1
}
onClicked: colorClicked(bae.moodColor(1))
onClicked: colorClicked(vvave.moodColor(1))
}
ToolButton
{
......@@ -63,13 +63,13 @@ Item
anchors.centerIn: parent
width: recSize
height: recSize
color: bae.moodColor(2)
color: vvave.moodColor(2)
radius: recRadius
border.color: altColor
border.width: 1
}
onClicked: colorClicked(bae.moodColor(2))
onClicked: colorClicked(vvave.moodColor(2))
}
ToolButton
{
......@@ -82,13 +82,13 @@ Item
anchors.centerIn: parent
width: recSize
height: recSize
color: bae.moodColor(3)
color: vvave.moodColor(3)
radius: recRadius
border.color: altColor
border.width: 1
}
onClicked: colorClicked(bae.moodColor(3))
onClicked: colorClicked(vvave.moodColor(3))
}
ToolButton
......@@ -102,13 +102,13 @@ Item
anchors.centerIn: parent
width: recSize
height: recSize
color: bae.moodColor(4)
color: vvave.moodColor(4)
radius: recRadius
border.color: altColor
border.width: 1
}
onClicked: colorClicked(bae.moodColor(4))
onClicked: colorClicked(vvave.moodColor(4))
}
}
}
#include "vvave.h"
#include "db/collectionDB.h"
#include "settings/fileloader.h"
#include "utils/brain.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#endif
#include <QtConcurrent>
#include <QFuture>
/*
* Sets upthe app default config paths
* BrainDeamon to get collection information
* YoutubeFetcher ?
*
* */
static CollectionDB *DB = CollectionDB::getInstance();
vvave::vvave(QObject *parent) : QObject(parent)
{
this->db = CollectionDB::getInstance();
for(const auto &path : {BAE::CachePath, BAE::YoutubeCachePath})
{
QDir dirPath(path);
if (!dirPath.exists())
dirPath.mkpath(".");
}
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
if(!FMH::fileExists(BAE::NotifyDir+"/vvave.notifyrc"))
QFile::copy(":/assets/vvave.notifyrc", BAE::NotifyDir+"/vvave.notifyrc");
this->notify = new Notify(this);
connect(this->notify, &Notify::babeSong, [this]()
{
// emit this->babeIt();
});
connect(this->notify, &Notify::skipSong, [this]()
{
// emit this->skipTrack();
});
#endif
}
vvave::~vvave() {}
void vvave::runBrain()
{
QFutureWatcher<void> *watcher = new QFutureWatcher<void>;
QObject::connect(watcher, &QFutureWatcher<void>::finished, [=]()
{
watcher->deleteLater();
});
auto func = [=]()
{
// the album artworks package
BRAIN::PACKAGE albumPackage;
albumPackage.ontology = PULPO::ONTOLOGY::ALBUM;
albumPackage.info = PULPO::INFO::ARTWORK;
albumPackage.callback = [=]()
{
emit this->refreshAlbums();
};
BRAIN::PACKAGE artistPackage;
artistPackage.ontology = PULPO::ONTOLOGY::ARTIST;
artistPackage.info = PULPO::INFO::ARTWORK;
artistPackage.callback = [=]()
{
emit this->refreshArtists();
};
BRAIN::synapse(BRAIN::PACKAGES() << artistPackage);
};
QFuture<void> t1 = QtConcurrent::run(func);