save some space on empty rows
parent
613f32a250
commit
4105e38404
1
notes
1
notes
|
@ -46,6 +46,7 @@ project data {
|
|||
TODO {
|
||||
immediate frontburner {
|
||||
- implement saving (yay, QCbor*)
|
||||
- save empty space as a number of skipped rows (make sure to have something keeping a row count!)
|
||||
|
||||
undo {
|
||||
...
|
||||
|
|
|
@ -58,17 +58,20 @@ bool Xybrid::FileOps::saveProject(std::shared_ptr<Project> project, QString file
|
|||
for (auto p : project->patterns) {
|
||||
QCborMap pm;
|
||||
pm.insert(QString("name"), QString::fromStdString(p->name));
|
||||
if (p->channels.size() == 0) pm.insert(QString("rows"), p->rows); // store number of rows if no channels present
|
||||
QCborArray chns;
|
||||
bool needsCount = true;
|
||||
for (auto& ch : p->channels) {
|
||||
QCborMap chm;
|
||||
chm.insert(QString("name"), QString::fromStdString(ch.name));
|
||||
QCborArray rows;
|
||||
int skipped = 0;
|
||||
for (auto& r : ch.rows) {
|
||||
if (r.isEmpty()) {
|
||||
// save two bytes for each empty row
|
||||
rows << QCborValue(nullptr);
|
||||
skipped++; // compact empty rows into a simple number
|
||||
continue;
|
||||
} else if (skipped > 0) { // ...and insert said number only if there's data after
|
||||
rows << skipped;
|
||||
skipped = 0;
|
||||
}
|
||||
QCborArray row;
|
||||
row << r.port << r.note;
|
||||
|
@ -77,9 +80,11 @@ bool Xybrid::FileOps::saveProject(std::shared_ptr<Project> project, QString file
|
|||
}
|
||||
rows << row;
|
||||
}
|
||||
if (!ch.rows.back().isEmpty()) needsCount = false; // omit extra count if any channel has data on the last row
|
||||
chm.insert(QString("rows"), rows);
|
||||
chns << chm;
|
||||
}
|
||||
if (needsCount) chns << p->rows; // if no pattern data reaches the last row, store a manual count
|
||||
if (chns.size() != 0) pm.insert(QString("channels"), chns);
|
||||
ptns << pm;
|
||||
}
|
||||
|
@ -136,6 +141,10 @@ std::shared_ptr<Xybrid::Data::Project> Xybrid::FileOps::loadProject(QString file
|
|||
|
||||
auto chns = pm.value("channels").toArray();
|
||||
for (auto chm_ : chns) {
|
||||
if (chm_.isInteger()) { // can have a number of rows encoded as part of the channels map
|
||||
p->rows = std::max(p->rows, static_cast<int>(chm_.toInteger()));
|
||||
continue;
|
||||
}
|
||||
auto chm = chm_.toMap();
|
||||
auto& ch = p->channels.emplace_back();
|
||||
ch.name = chm.value("name").toString().toStdString();
|
||||
|
@ -143,6 +152,10 @@ std::shared_ptr<Xybrid::Data::Project> Xybrid::FileOps::loadProject(QString file
|
|||
auto rows = chm.value("rows").toArray();
|
||||
ch.rows.reserve(static_cast<size_t>(rows.size()));
|
||||
for (auto row_ : rows) {
|
||||
if (row_.isInteger()) { // empty space encoded as a number of rows to skip
|
||||
for (auto i = row_.toInteger(); i > 0; i--) ch.rows.emplace_back();
|
||||
continue;
|
||||
}
|
||||
auto& r = ch.rows.emplace_back();
|
||||
if (row_.isNull()) continue;
|
||||
auto row = row_.toArray();
|
||||
|
|
Loading…
Reference in New Issue