Refactor json handling for SongItems and add new fields.
Some checks failed
Build eismuliplexer for linux / Build (push) Has been cancelled
Some checks failed
Build eismuliplexer for linux / Build (push) Has been cancelled
This commit is contained in:
parent
64357be451
commit
4cacaa04e4
10 changed files with 224 additions and 108 deletions
43
src/SongItem.cpp
Normal file
43
src/SongItem.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "SongItem.h"
|
||||
|
||||
SongItem::SongItem(const QString &caption, const QString &lyrics)
|
||||
: caption(caption), lyrics(lyrics), cotCaption(true)
|
||||
{
|
||||
uniqueId = QRandomGenerator::global()->generate64();
|
||||
}
|
||||
|
||||
SongItem::SongItem(const QJsonObject& json)
|
||||
{
|
||||
load(json);
|
||||
}
|
||||
|
||||
void SongItem::store(QJsonObject &json) const
|
||||
{
|
||||
if(!caption.isEmpty())
|
||||
json["caption"] = caption;
|
||||
if(!lyrics.isEmpty())
|
||||
json["lyrics"] = lyrics;
|
||||
json["unique_id"] = QString::number(uniqueId);
|
||||
json["use_cot_caption"] = cotCaption;
|
||||
if(!vocalLanguage.isEmpty())
|
||||
json["vocal_language"] = vocalLanguage;
|
||||
if(!key.isEmpty())
|
||||
json["keyscale"] = key;
|
||||
if(bpm != 0)
|
||||
json["bpm"] = static_cast<qlonglong>(bpm);
|
||||
}
|
||||
|
||||
void SongItem::load(const QJsonObject &json)
|
||||
{
|
||||
caption = json["caption"].toString();
|
||||
lyrics = json["lyrics"].toString();
|
||||
if(json.contains("unique_id"))
|
||||
uniqueId = json["unique_id"].toString().toULongLong();
|
||||
else
|
||||
uniqueId = QRandomGenerator::global()->generate64();
|
||||
cotCaption = json["use_cot_caption"].toBool(true);
|
||||
vocalLanguage = json["vocal_language"].toString();
|
||||
key = json["keyscale"].toString();
|
||||
bpm = json["bpm"].toInt(0);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue