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
|
|
@ -40,6 +40,8 @@ add_executable(${PROJECT_NAME}
|
|||
${MusicGeneratorGUI_H}
|
||||
res/resources.qrc
|
||||
src/elidedlabel.h src/elidedlabel.cpp
|
||||
src/SongItem.cpp
|
||||
|
||||
)
|
||||
|
||||
# UI file
|
||||
|
|
|
|||
|
|
@ -102,14 +102,7 @@ bool AceStep::requestGeneration(SongItem song, QString requestTemplate, QString
|
|||
}
|
||||
|
||||
QJsonObject requestObj = templateDoc.object();
|
||||
requestObj["caption"] = song.caption;
|
||||
|
||||
if (!song.lyrics.isEmpty())
|
||||
requestObj["lyrics"] = song.lyrics;
|
||||
if (!song.vocalLanguage.isEmpty())
|
||||
requestObj["vocal_language"] = song.vocalLanguage;
|
||||
|
||||
requestObj["use_cot_caption"] = song.cotCaption;
|
||||
song.store(requestObj);
|
||||
|
||||
// Write the request file
|
||||
QFile requestFileHandle(request.requestFilePath);
|
||||
|
|
|
|||
|
|
@ -291,12 +291,7 @@ void MainWindow::on_addSongButton_clicked()
|
|||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
QString caption = dialog.getCaption();
|
||||
QString lyrics = dialog.getLyrics();
|
||||
QString vocalLanguage = dialog.getVocalLanguage();
|
||||
|
||||
SongItem newSong(caption, lyrics);
|
||||
newSong.vocalLanguage = vocalLanguage;
|
||||
SongItem newSong = dialog.getSong();
|
||||
songModel->addSong(newSong);
|
||||
|
||||
// Select the new item
|
||||
|
|
@ -335,18 +330,10 @@ void MainWindow::on_songListView_doubleClicked(const QModelIndex &index)
|
|||
{
|
||||
SongItem song = songModel->getSong(row);
|
||||
|
||||
SongDialog dialog(this, song.caption, song.lyrics, song.vocalLanguage);
|
||||
SongDialog dialog(this, song);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
QString caption = dialog.getCaption();
|
||||
QString lyrics = dialog.getLyrics();
|
||||
QString vocalLanguage = dialog.getVocalLanguage();
|
||||
|
||||
songModel->setData(songModel->index(row, 1), caption, SongListModel::CaptionRole);
|
||||
songModel->setData(songModel->index(row, 1), lyrics, SongListModel::LyricsRole);
|
||||
songModel->setData(songModel->index(row, 1), vocalLanguage, SongListModel::VocalLanguageRole);
|
||||
}
|
||||
songModel->updateSong(songModel->index(row, 1), dialog.getSong());
|
||||
}
|
||||
|
||||
connect(ui->songListView, &QTableView::doubleClicked, this, &MainWindow::on_songListView_doubleClicked);
|
||||
|
|
@ -695,17 +682,13 @@ bool MainWindow::savePlaylistToJson(const QString &filePath, const QList<SongIte
|
|||
for (const SongItem &song : songs)
|
||||
{
|
||||
QJsonObject songObj;
|
||||
songObj["caption"] = song.caption;
|
||||
songObj["lyrics"] = song.lyrics;
|
||||
songObj["vocalLanguage"] = song.vocalLanguage;
|
||||
songObj["uniqueId"] = static_cast<qint64>(song.uniqueId);
|
||||
songObj["use_cot_caption"] = song.cotCaption;
|
||||
song.store(songObj);
|
||||
songsArray.append(songObj);
|
||||
}
|
||||
|
||||
QJsonObject rootObj;
|
||||
rootObj["songs"] = songsArray;
|
||||
rootObj["version"] = "1.0";
|
||||
rootObj["version"] = "1.1";
|
||||
|
||||
QJsonDocument doc(rootObj);
|
||||
QByteArray jsonData = doc.toJson();
|
||||
|
|
@ -754,8 +737,7 @@ bool MainWindow::loadPlaylistFromJson(const QString &filePath, QList<SongItem> &
|
|||
|
||||
QJsonObject rootObj = doc.object();
|
||||
|
||||
// Check for version compatibility
|
||||
if (rootObj.contains("version") && rootObj["version"].toString() != "1.0")
|
||||
if (rootObj.contains("version") && rootObj["version"].toString() != "1.0" && rootObj["version"].toString() != "1.1")
|
||||
{
|
||||
qWarning() << "Unsupported playlist version:" << rootObj["version"].toString();
|
||||
return false;
|
||||
|
|
@ -777,24 +759,7 @@ bool MainWindow::loadPlaylistFromJson(const QString &filePath, QList<SongItem> &
|
|||
continue;
|
||||
|
||||
QJsonObject songObj = value.toObject();
|
||||
SongItem song;
|
||||
|
||||
if (songObj.contains("caption"))
|
||||
song.caption = songObj["caption"].toString();
|
||||
|
||||
if (songObj.contains("lyrics"))
|
||||
song.lyrics = songObj["lyrics"].toString();
|
||||
|
||||
if (songObj.contains("vocalLanguage"))
|
||||
song.vocalLanguage = songObj["vocalLanguage"].toString();
|
||||
|
||||
if (songObj.contains("uniqueId"))
|
||||
song.uniqueId = static_cast<uint64_t>(songObj["uniqueId"].toInteger());
|
||||
else
|
||||
song.uniqueId = QRandomGenerator::global()->generate64();
|
||||
|
||||
song.cotCaption = songObj["use_cot_caption"].toBool(true);
|
||||
|
||||
SongItem song(songObj);
|
||||
songs.append(song);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,19 +5,19 @@
|
|||
#include "ui_SongDialog.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
SongDialog::SongDialog(QWidget *parent, const QString &caption, const QString &lyrics, const QString &vocalLanguage, bool cotEnabled)
|
||||
SongDialog::SongDialog(QWidget *parent, const SongItem &song)
|
||||
: QDialog(parent),
|
||||
song(song),
|
||||
ui(new Ui::SongDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->captionEdit->setPlainText(caption);
|
||||
ui->lyricsEdit->setPlainText(lyrics);
|
||||
|
||||
ui->checkBoxEnhanceCaption->setChecked(cotEnabled);
|
||||
ui->captionEdit->setPlainText(song.caption);
|
||||
ui->lyricsEdit->setPlainText(song.lyrics);
|
||||
ui->checkBoxEnhanceCaption->setChecked(song.cotCaption);
|
||||
|
||||
// Setup vocal language combo box
|
||||
ui->vocalLanguageCombo->addItem("--", ""); // Unset
|
||||
ui->vocalLanguageCombo->addItem("--", "");
|
||||
ui->vocalLanguageCombo->addItem("English (en)", "en");
|
||||
ui->vocalLanguageCombo->addItem("Chinese (zh)", "zh");
|
||||
ui->vocalLanguageCombo->addItem("Japanese (ja)", "ja");
|
||||
|
|
@ -70,19 +70,69 @@ SongDialog::SongDialog(QWidget *parent, const QString &caption, const QString &l
|
|||
ui->vocalLanguageCombo->addItem("Cantonese (yue)", "yue");
|
||||
ui->vocalLanguageCombo->addItem("Unknown", "unknown");
|
||||
|
||||
// Set current language if provided
|
||||
if (!vocalLanguage.isEmpty())
|
||||
ui->keyScaleCombo->addItem("--");
|
||||
ui->keyScaleCombo->addItem("C major");
|
||||
ui->keyScaleCombo->addItem("C# major");
|
||||
ui->keyScaleCombo->addItem("D major");
|
||||
ui->keyScaleCombo->addItem("D# major");
|
||||
ui->keyScaleCombo->addItem("E major");
|
||||
ui->keyScaleCombo->addItem("F major");
|
||||
ui->keyScaleCombo->addItem("F# major");
|
||||
ui->keyScaleCombo->addItem("G major");
|
||||
ui->keyScaleCombo->addItem("G# major");
|
||||
ui->keyScaleCombo->addItem("A major");
|
||||
ui->keyScaleCombo->addItem("A# major");
|
||||
ui->keyScaleCombo->addItem("B major");
|
||||
ui->keyScaleCombo->addItem("C minor");
|
||||
ui->keyScaleCombo->addItem("C# minor");
|
||||
ui->keyScaleCombo->addItem("D minor");
|
||||
ui->keyScaleCombo->addItem("D# minor");
|
||||
ui->keyScaleCombo->addItem("E minor");
|
||||
ui->keyScaleCombo->addItem("F minor");
|
||||
ui->keyScaleCombo->addItem("F# minor");
|
||||
ui->keyScaleCombo->addItem("G minor");
|
||||
ui->keyScaleCombo->addItem("G# minor");
|
||||
ui->keyScaleCombo->addItem("A minor");
|
||||
ui->keyScaleCombo->addItem("A# minor");
|
||||
ui->keyScaleCombo->addItem("B minor");
|
||||
|
||||
if (!song.vocalLanguage.isEmpty())
|
||||
{
|
||||
int index = ui->vocalLanguageCombo->findData(vocalLanguage);
|
||||
int index = ui->vocalLanguageCombo->findData(song.vocalLanguage);
|
||||
if (index >= 0)
|
||||
{
|
||||
ui->vocalLanguageCombo->setCurrentIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->vocalLanguageCombo->addItem(song.vocalLanguage);
|
||||
ui->vocalLanguageCombo->setCurrentIndex(ui->vocalLanguageCombo->count()-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->vocalLanguageCombo->setCurrentIndex(0); // Default to unset
|
||||
ui->vocalLanguageCombo->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
if (!song.key.isEmpty())
|
||||
{
|
||||
int index = ui->keyScaleCombo->findText(song.key);
|
||||
if (index >= 0)
|
||||
{
|
||||
ui->keyScaleCombo->setCurrentIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->keyScaleCombo->addItem(song.key);
|
||||
ui->keyScaleCombo->setCurrentIndex(ui->keyScaleCombo->count()-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->keyScaleCombo->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
ui->bpmSpinBox->setValue(song.bpm);
|
||||
}
|
||||
|
||||
SongDialog::~SongDialog()
|
||||
|
|
@ -90,30 +140,10 @@ SongDialog::~SongDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
QString SongDialog::getCaption() const
|
||||
{
|
||||
return ui->captionEdit->toPlainText();
|
||||
}
|
||||
|
||||
QString SongDialog::getLyrics() const
|
||||
{
|
||||
return ui->lyricsEdit->toPlainText();
|
||||
}
|
||||
|
||||
QString SongDialog::getVocalLanguage() const
|
||||
{
|
||||
return ui->vocalLanguageCombo->currentData().toString();
|
||||
}
|
||||
|
||||
bool SongDialog::getCotEnabled() const
|
||||
{
|
||||
return ui->checkBoxEnhanceCaption->isChecked();
|
||||
}
|
||||
|
||||
void SongDialog::on_okButton_clicked()
|
||||
{
|
||||
// Validate that caption is not empty
|
||||
QString caption = getCaption();
|
||||
QString caption = ui->captionEdit->toPlainText();
|
||||
if (caption.trimmed().isEmpty())
|
||||
{
|
||||
QMessageBox::warning(this, "Invalid Input", "Caption cannot be empty.");
|
||||
|
|
@ -127,3 +157,18 @@ void SongDialog::on_cancelButton_clicked()
|
|||
{
|
||||
reject();
|
||||
}
|
||||
|
||||
const SongItem& SongDialog::getSong()
|
||||
{
|
||||
song.caption = ui->captionEdit->toPlainText();
|
||||
song.lyrics = ui->lyricsEdit->toPlainText();
|
||||
song.vocalLanguage = ui->vocalLanguageCombo->currentData().toString();
|
||||
song.cotCaption = ui->checkBoxEnhanceCaption->isChecked();
|
||||
if(ui->keyScaleCombo->currentIndex() > 0)
|
||||
song.key = ui->keyScaleCombo->currentText();
|
||||
else
|
||||
song.key = "";
|
||||
song.bpm = ui->bpmSpinBox->value();
|
||||
return song;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <QDialog>
|
||||
#include <QString>
|
||||
|
||||
#include "SongItem.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class SongDialog;
|
||||
|
|
@ -17,16 +19,13 @@ class SongDialog;
|
|||
class SongDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
SongItem song;
|
||||
|
||||
public:
|
||||
explicit SongDialog(QWidget *parent = nullptr, const QString &caption = "", const QString &lyrics = "",
|
||||
const QString &vocalLanguage = "", bool cotEnabled = true);
|
||||
explicit SongDialog(QWidget *parent = nullptr, const SongItem& song = SongItem());
|
||||
~SongDialog();
|
||||
|
||||
QString getCaption() const;
|
||||
QString getLyrics() const;
|
||||
QString getVocalLanguage() const;
|
||||
bool getCotEnabled() const;
|
||||
const SongItem& getSong();
|
||||
|
||||
private slots:
|
||||
void on_okButton_clicked();
|
||||
|
|
|
|||
|
|
@ -58,22 +58,67 @@
|
|||
<widget class="QPlainTextEdit" name="lyricsEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="vocalLanguageLabel">
|
||||
<property name="text">
|
||||
<string>Vocal Language:</string>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignTop</set>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="keyScalelabel">
|
||||
<property name="text">
|
||||
<string>Keyscale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="vocalLanguageCombo">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="vocalLanguageLabel">
|
||||
<property name="text">
|
||||
<string>Vocal Language:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="keyScaleCombo">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Bpm (0 for llm chooses)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="bpmSpinBox">
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="">
|
||||
<property name="spacing">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonLayout">
|
||||
<item>
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
@ -7,22 +7,25 @@
|
|||
#include <QString>
|
||||
#include <QRandomGenerator>
|
||||
#include <cstdint>
|
||||
#include <QJsonObject>
|
||||
|
||||
class SongItem
|
||||
{
|
||||
public:
|
||||
QString caption;
|
||||
QString lyrics;
|
||||
uint64_t uniqueId;
|
||||
QString file;
|
||||
unsigned int bpm;
|
||||
QString key;
|
||||
QString vocalLanguage;
|
||||
bool cotCaption;
|
||||
|
||||
uint64_t uniqueId;
|
||||
QString file;
|
||||
QString json;
|
||||
|
||||
inline SongItem(const QString &caption = "", const QString &lyrics = "")
|
||||
: caption(caption), lyrics(lyrics), cotCaption(true)
|
||||
{
|
||||
// Generate a unique ID using a cryptographically secure random number
|
||||
uniqueId = QRandomGenerator::global()->generate64();
|
||||
}
|
||||
SongItem(const QString &caption = "", const QString &lyrics = "");
|
||||
SongItem(const QJsonObject& json);
|
||||
|
||||
void store(QJsonObject& json) const;
|
||||
void load(const QJsonObject& json);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -111,6 +111,26 @@ bool SongListModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
return true;
|
||||
}
|
||||
|
||||
void SongListModel::updateSong(const QModelIndex &index, const SongItem& song)
|
||||
{
|
||||
const SongItem &oldSong = songList[index.row()];
|
||||
|
||||
if(song.caption != oldSong.caption)
|
||||
{
|
||||
emit dataChanged(index, index, {CaptionRole});
|
||||
}
|
||||
if(song.lyrics != oldSong.lyrics)
|
||||
{
|
||||
emit dataChanged(index, index, {LyricsRole});
|
||||
}
|
||||
if(song.vocalLanguage != oldSong.vocalLanguage)
|
||||
{
|
||||
emit dataChanged(index, index, {VocalLanguageRole});
|
||||
}
|
||||
|
||||
songList[index.row()] = song;
|
||||
}
|
||||
|
||||
Qt::ItemFlags SongListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public:
|
|||
|
||||
// Editable:
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
void updateSong(const QModelIndex &index, const SongItem& song);
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
// Add/remove songs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue