replaced QIODevice to mu::io::IODevice
This commit is contained in:
parent
b18a68e413
commit
97b15e6698
58 changed files with 495 additions and 323 deletions
|
@ -47,8 +47,6 @@ include_directories(
|
|||
|
||||
set(THIRDPARTY_DIR ${MU_ROOT}/thirdparty)
|
||||
|
||||
add_subdirectory(${MU_ROOT}/thirdparty/qzip qzip)
|
||||
|
||||
add_definitions(
|
||||
-DNO_QT_SUPPORT
|
||||
-DNO_ENGRAVING_INTERACTIVE
|
||||
|
@ -73,7 +71,6 @@ add_executable(engraving_app
|
|||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(qzip PROPERTIES COMPILE_FLAGS "-fPIC")
|
||||
set_target_properties(engraving PROPERTIES COMPILE_FLAGS "-fPIC")
|
||||
set_target_properties(global PROPERTIES COMPILE_FLAGS "-fPIC")
|
||||
set_target_properties(engraving_app PROPERTIES COMPILE_FLAGS "-fPIC")
|
||||
|
|
|
@ -24,13 +24,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QBuffer>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
#include "io/buffer.h"
|
||||
|
||||
#include "engraving/compat/scoreaccess.h"
|
||||
#include "engraving/infrastructure/io/mscwriter.h"
|
||||
#include "engraving/libmscore/excerpt.h"
|
||||
|
@ -599,8 +600,8 @@ Ret BackendApi::doExportScoreTranspose(const INotationPtr notation, BackendJsonW
|
|||
|
||||
RetVal<QByteArray> BackendApi::scorePartJson(Ms::Score* score, const std::string& fileName)
|
||||
{
|
||||
QByteArray scoreData;
|
||||
QBuffer buf(&scoreData);
|
||||
ByteArray scoreData;
|
||||
Buffer buf(&scoreData);
|
||||
|
||||
MscWriter::Params params;
|
||||
params.device = &buf;
|
||||
|
@ -616,9 +617,11 @@ RetVal<QByteArray> BackendApi::scorePartJson(Ms::Score* score, const std::string
|
|||
}
|
||||
mscWriter.close();
|
||||
|
||||
QByteArray ba = QByteArray::fromRawData(reinterpret_cast<const char*>(scoreData.constData()), scoreData.size());
|
||||
|
||||
RetVal<QByteArray> result;
|
||||
result.ret = ok ? make_ret(Ret::Code::Ok) : make_ret(Ret::Code::InternalError);
|
||||
result.val = scoreData.toBase64();
|
||||
result.val = ba.toBase64();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
*/
|
||||
#include "mscxcompat.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QBuffer>
|
||||
#include "io/file.h"
|
||||
#include "io/buffer.h"
|
||||
|
||||
#include "../rw/scorereader.h"
|
||||
|
||||
|
@ -30,17 +30,19 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
Ms::Score::FileError mu::engraving::compat::mscxToMscz(const QString& mscxFilePath, QByteArray* msczData)
|
||||
using namespace mu::io;
|
||||
|
||||
Ms::Score::FileError mu::engraving::compat::mscxToMscz(const QString& mscxFilePath, ByteArray* msczData)
|
||||
{
|
||||
QFile mscxFile(mscxFilePath);
|
||||
if (!mscxFile.open(QIODevice::ReadOnly)) {
|
||||
File mscxFile(mscxFilePath);
|
||||
if (!mscxFile.open(IODevice::ReadOnly)) {
|
||||
LOGE() << "failed open file: " << mscxFilePath;
|
||||
return Ms::Score::FileError::FILE_OPEN_ERROR;
|
||||
}
|
||||
|
||||
QByteArray mscxData = mscxFile.readAll();
|
||||
ByteArray mscxData = mscxFile.readAll();
|
||||
|
||||
QBuffer buf(msczData);
|
||||
Buffer buf(msczData);
|
||||
MscWriter::Params params;
|
||||
params.device = &buf;
|
||||
params.filePath = mscxFilePath;
|
||||
|
@ -54,7 +56,7 @@ Ms::Score::FileError mu::engraving::compat::mscxToMscz(const QString& mscxFilePa
|
|||
|
||||
Ms::Score::FileError mu::engraving::compat::loadMsczOrMscx(Ms::MasterScore* score, const QString& path, bool ignoreVersionError)
|
||||
{
|
||||
QByteArray msczData;
|
||||
ByteArray msczData;
|
||||
if (path.endsWith(".mscx", Qt::CaseInsensitive)) {
|
||||
//! NOTE Convert mscx -> mscz
|
||||
|
||||
|
@ -63,8 +65,8 @@ Ms::Score::FileError mu::engraving::compat::loadMsczOrMscx(Ms::MasterScore* scor
|
|||
return err;
|
||||
}
|
||||
} else if (path.endsWith(".mscz", Qt::CaseInsensitive)) {
|
||||
QFile msczFile(path);
|
||||
if (!msczFile.open(QIODevice::ReadOnly)) {
|
||||
File msczFile(path);
|
||||
if (!msczFile.open(IODevice::ReadOnly)) {
|
||||
LOGE() << "failed open file: " << path;
|
||||
return Ms::Score::FileError::FILE_OPEN_ERROR;
|
||||
}
|
||||
|
@ -77,7 +79,7 @@ Ms::Score::FileError mu::engraving::compat::loadMsczOrMscx(Ms::MasterScore* scor
|
|||
|
||||
score->setFileInfoProvider(std::make_shared<LocalFileInfoProvider>(path));
|
||||
|
||||
QBuffer msczBuf(&msczData);
|
||||
Buffer msczBuf(&msczData);
|
||||
MscReader::Params params;
|
||||
params.device = &msczBuf;
|
||||
params.filePath = path;
|
||||
|
@ -93,7 +95,7 @@ Ms::Score::FileError mu::engraving::compat::loadMsczOrMscx(Ms::MasterScore* scor
|
|||
|
||||
mu::engraving::Err mu::engraving::compat::loadMsczOrMscx(EngravingProjectPtr project, const QString& path, bool ignoreVersionError)
|
||||
{
|
||||
QByteArray msczData;
|
||||
ByteArray msczData;
|
||||
QString filePath = path;
|
||||
if (path.endsWith(".mscx", Qt::CaseInsensitive)) {
|
||||
//! NOTE Convert mscx -> mscz
|
||||
|
@ -103,8 +105,8 @@ mu::engraving::Err mu::engraving::compat::loadMsczOrMscx(EngravingProjectPtr pro
|
|||
return scoreFileErrorToErr(err);
|
||||
}
|
||||
} else if (path.endsWith(".mscz", Qt::CaseInsensitive)) {
|
||||
QFile msczFile(path);
|
||||
if (!msczFile.open(QIODevice::ReadOnly)) {
|
||||
File msczFile(path);
|
||||
if (!msczFile.open(IODevice::ReadOnly)) {
|
||||
LOGE() << "failed open file: " << path;
|
||||
return scoreFileErrorToErr(Ms::Score::FileError::FILE_OPEN_ERROR);
|
||||
}
|
||||
|
@ -117,7 +119,7 @@ mu::engraving::Err mu::engraving::compat::loadMsczOrMscx(EngravingProjectPtr pro
|
|||
|
||||
project->setFileInfoProvider(std::make_shared<LocalFileInfoProvider>(path));
|
||||
|
||||
QBuffer msczBuf(&msczData);
|
||||
Buffer msczBuf(&msczData);
|
||||
MscReader::Params params;
|
||||
params.device = &msczBuf;
|
||||
params.filePath = filePath;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "engravingproject.h"
|
||||
|
||||
namespace mu::engraving::compat {
|
||||
Ms::Score::FileError mscxToMscz(const QString& mscxFilePath, QByteArray* msczData);
|
||||
Ms::Score::FileError mscxToMscz(const QString& mscxFilePath, io::ByteArray *msczData);
|
||||
Ms::Score::FileError loadMsczOrMscx(Ms::MasterScore* score, const QString& path, bool ignoreVersionError = false);
|
||||
Err loadMsczOrMscx(EngravingProjectPtr project, const QString& path, bool ignoreVersionError = false);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
#define MU_DRAW_IIMAGEPROVIDER_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "io/iodevice.h"
|
||||
|
||||
#include "modularity/ioc.h"
|
||||
|
||||
|
@ -48,7 +49,7 @@ public:
|
|||
|
||||
virtual IPaintProviderPtr painterForImage(std::shared_ptr<Pixmap> pixmap) = 0;
|
||||
|
||||
virtual void saveAsPng(std::shared_ptr<Pixmap> px, QIODevice* device) = 0;
|
||||
virtual void saveAsPng(std::shared_ptr<Pixmap> px, io::IODevice* device) = 0;
|
||||
virtual std::shared_ptr<Pixmap> pixmapFromQVariant(const QVariant& val) = 0;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -55,7 +55,10 @@ std::shared_ptr<IPaintProvider> QImageProvider::painterForImage(std::shared_ptr<
|
|||
return QImagePainterProvider::make(pixmap);
|
||||
}
|
||||
|
||||
void QImageProvider::saveAsPng(std::shared_ptr<Pixmap> px, QIODevice* device)
|
||||
void QImageProvider::saveAsPng(std::shared_ptr<Pixmap> px, io::IODevice* device)
|
||||
{
|
||||
Pixmap::toQPixmap(*px).save(device, FILE_FORMAT);
|
||||
QBuffer buf;
|
||||
Pixmap::toQPixmap(*px).save(&buf, FILE_FORMAT);
|
||||
QByteArray ba = buf.readAll();
|
||||
device->write(ba);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
Pixmap scaled(const Pixmap& origin, const Size& s) const override;
|
||||
|
||||
IPaintProviderPtr painterForImage(std::shared_ptr<Pixmap> pixmap) override;
|
||||
void saveAsPng(std::shared_ptr<Pixmap> px, QIODevice* device) override;
|
||||
void saveAsPng(std::shared_ptr<Pixmap> px, io::IODevice* device) override;
|
||||
std::shared_ptr<Pixmap> pixmapFromQVariant(const QVariant& val) override;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -21,19 +21,20 @@
|
|||
*/
|
||||
#include "mscreader.h"
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
|
||||
#include "io/file.h"
|
||||
#include "serialization/zipreader.h"
|
||||
#include "serialization/xmlstreamreader.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
//! NOTE The current implementation resolves files by extension.
|
||||
//! This will probably be changed in the future.
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
MscReader::MscReader(const Params& params)
|
||||
|
@ -107,12 +108,13 @@ MscReader::IReader* MscReader::reader() const
|
|||
return m_reader;
|
||||
}
|
||||
|
||||
QByteArray MscReader::fileData(const QString& fileName) const
|
||||
ByteArray MscReader::fileData(const QString& fileName) const
|
||||
{
|
||||
return reader()->fileData(fileName);
|
||||
QByteArray ba = reader()->fileData(fileName);
|
||||
return ByteArray::fromQByteArray(ba);
|
||||
}
|
||||
|
||||
QByteArray MscReader::readStyleFile() const
|
||||
ByteArray MscReader::readStyleFile() const
|
||||
{
|
||||
return fileData("score_style.mss");
|
||||
}
|
||||
|
@ -136,11 +138,11 @@ QString MscReader::mainFileName() const
|
|||
return completeBaseName + ".mscx";
|
||||
}
|
||||
|
||||
QByteArray MscReader::readScoreFile() const
|
||||
ByteArray MscReader::readScoreFile() const
|
||||
{
|
||||
QString mscxFileName = mainFileName();
|
||||
QByteArray data = fileData(mscxFileName);
|
||||
if (data.isEmpty() && reader()->isContainer()) {
|
||||
ByteArray data = fileData(mscxFileName);
|
||||
if (data.empty() && reader()->isContainer()) {
|
||||
QStringList files = reader()->fileList();
|
||||
for (const QString& name : files) {
|
||||
// mscx file in the root dir
|
||||
|
@ -171,29 +173,29 @@ std::vector<QString> MscReader::excerptNames() const
|
|||
return names;
|
||||
}
|
||||
|
||||
QByteArray MscReader::readExcerptStyleFile(const QString& name) const
|
||||
ByteArray MscReader::readExcerptStyleFile(const QString& name) const
|
||||
{
|
||||
QString fileName = name + ".mss";
|
||||
return fileData("Excerpts/" + fileName);
|
||||
}
|
||||
|
||||
QByteArray MscReader::readExcerptFile(const QString& name) const
|
||||
ByteArray MscReader::readExcerptFile(const QString& name) const
|
||||
{
|
||||
QString fileName = name + ".mscx";
|
||||
return fileData("Excerpts/" + fileName);
|
||||
}
|
||||
|
||||
QByteArray MscReader::readChordListFile() const
|
||||
ByteArray MscReader::readChordListFile() const
|
||||
{
|
||||
return fileData("chordlist.xml");
|
||||
}
|
||||
|
||||
QByteArray MscReader::readThumbnailFile() const
|
||||
ByteArray MscReader::readThumbnailFile() const
|
||||
{
|
||||
return fileData("Thumbnails/thumbnail.png");
|
||||
}
|
||||
|
||||
QByteArray MscReader::readImageFile(const QString& fileName) const
|
||||
ByteArray MscReader::readImageFile(const QString& fileName) const
|
||||
{
|
||||
return fileData("Pictures/" + fileName);
|
||||
}
|
||||
|
@ -215,17 +217,17 @@ std::vector<QString> MscReader::imageFileNames() const
|
|||
return names;
|
||||
}
|
||||
|
||||
QByteArray MscReader::readAudioFile() const
|
||||
ByteArray MscReader::readAudioFile() const
|
||||
{
|
||||
return fileData("audio.ogg");
|
||||
}
|
||||
|
||||
QByteArray MscReader::readAudioSettingsJsonFile() const
|
||||
ByteArray MscReader::readAudioSettingsJsonFile() const
|
||||
{
|
||||
return fileData("audiosettings.json");
|
||||
}
|
||||
|
||||
QByteArray MscReader::readViewSettingsJsonFile() const
|
||||
ByteArray MscReader::readViewSettingsJsonFile() const
|
||||
{
|
||||
return fileData("viewsettings.json");
|
||||
}
|
||||
|
@ -242,22 +244,22 @@ MscReader::ZipFileReader::~ZipFileReader()
|
|||
}
|
||||
}
|
||||
|
||||
bool MscReader::ZipFileReader::open(QIODevice* device, const QString& filePath)
|
||||
bool MscReader::ZipFileReader::open(IODevice* device, const QString& filePath)
|
||||
{
|
||||
m_device = device;
|
||||
if (!m_device) {
|
||||
m_device = new QFile(filePath);
|
||||
m_device = new File(filePath);
|
||||
m_selfDeviceOwner = true;
|
||||
}
|
||||
|
||||
if (!m_device->isOpen()) {
|
||||
if (!m_device->open(QIODevice::ReadOnly)) {
|
||||
LOGD() << QString("failed open %1: %2").arg(filePath).arg(m_device->errorString());
|
||||
if (!m_device->open(IODevice::ReadOnly)) {
|
||||
LOGD() << "failed open file: " << filePath;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_zip = new mu::ZipReader(m_device);
|
||||
m_zip = new ZipReader(m_device);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -318,7 +320,7 @@ QByteArray MscReader::ZipFileReader::fileData(const QString& fileName) const
|
|||
return data;
|
||||
}
|
||||
|
||||
bool MscReader::DirReader::open(QIODevice* device, const QString& filePath)
|
||||
bool MscReader::DirReader::open(IODevice* device, const QString& filePath)
|
||||
{
|
||||
if (device) {
|
||||
NOT_SUPPORTED;
|
||||
|
@ -380,16 +382,16 @@ QByteArray MscReader::DirReader::fileData(const QString& fileName) const
|
|||
return data;
|
||||
}
|
||||
|
||||
bool MscReader::XmlFileReader::open(QIODevice* device, const QString& filePath)
|
||||
bool MscReader::XmlFileReader::open(IODevice* device, const QString& filePath)
|
||||
{
|
||||
m_device = device;
|
||||
if (!m_device) {
|
||||
m_device = new QFile(filePath);
|
||||
m_device = new File(filePath);
|
||||
m_selfDeviceOwner = true;
|
||||
}
|
||||
|
||||
if (!m_device->isOpen()) {
|
||||
if (!m_device->open(QIODevice::ReadOnly)) {
|
||||
if (!m_device->open(IODevice::ReadOnly)) {
|
||||
LOGD() << "failed open file: " << filePath;
|
||||
return false;
|
||||
}
|
||||
|
@ -424,7 +426,7 @@ QStringList MscReader::XmlFileReader::fileList() const
|
|||
QStringList files;
|
||||
|
||||
m_device->seek(0);
|
||||
QXmlStreamReader xml(m_device);
|
||||
XmlStreamReader xml(m_device);
|
||||
while (xml.readNextStartElement()) {
|
||||
if ("files" != xml.name()) {
|
||||
xml.skipCurrentElement();
|
||||
|
@ -437,8 +439,8 @@ QStringList MscReader::XmlFileReader::fileList() const
|
|||
continue;
|
||||
}
|
||||
|
||||
QStringRef fileName = xml.attributes().value("name");
|
||||
files << fileName.toString();
|
||||
QString fileName = xml.attribute("name");
|
||||
files << fileName;
|
||||
xml.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
@ -453,7 +455,7 @@ QByteArray MscReader::XmlFileReader::fileData(const QString& fileName) const
|
|||
}
|
||||
|
||||
m_device->seek(0);
|
||||
QXmlStreamReader xml(m_device);
|
||||
XmlStreamReader xml(m_device);
|
||||
while (xml.readNextStartElement()) {
|
||||
if ("files" != xml.name()) {
|
||||
xml.skipCurrentElement();
|
||||
|
@ -466,7 +468,7 @@ QByteArray MscReader::XmlFileReader::fileData(const QString& fileName) const
|
|||
continue;
|
||||
}
|
||||
|
||||
QStringRef file = xml.attributes().value("name");
|
||||
QString file = xml.attribute("name");
|
||||
if (file != fileName) {
|
||||
xml.skipCurrentElement();
|
||||
continue;
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#include <QByteArray>
|
||||
#include <QIODevice>
|
||||
|
||||
#include "mscio.h"
|
||||
#include "io/iodevice.h"
|
||||
|
||||
class QXmlStreamReader;
|
||||
#include "mscio.h"
|
||||
|
||||
namespace mu {
|
||||
class ZipReader;
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
struct Params
|
||||
{
|
||||
QIODevice* device = nullptr;
|
||||
io::IODevice* device = nullptr;
|
||||
QString filePath;
|
||||
QString mainFileName;
|
||||
MscIoMode mode = MscIoMode::Zip;
|
||||
|
@ -58,29 +58,29 @@ public:
|
|||
void close();
|
||||
bool isOpened() const;
|
||||
|
||||
QByteArray readStyleFile() const;
|
||||
QByteArray readScoreFile() const;
|
||||
io::ByteArray readStyleFile() const;
|
||||
io::ByteArray readScoreFile() const;
|
||||
|
||||
std::vector<QString> excerptNames() const;
|
||||
QByteArray readExcerptStyleFile(const QString& name) const;
|
||||
QByteArray readExcerptFile(const QString& name) const;
|
||||
io::ByteArray readExcerptStyleFile(const QString& name) const;
|
||||
io::ByteArray readExcerptFile(const QString& name) const;
|
||||
|
||||
QByteArray readChordListFile() const;
|
||||
QByteArray readThumbnailFile() const;
|
||||
io::ByteArray readChordListFile() const;
|
||||
io::ByteArray readThumbnailFile() const;
|
||||
|
||||
std::vector<QString> imageFileNames() const;
|
||||
QByteArray readImageFile(const QString& fileName) const;
|
||||
io::ByteArray readImageFile(const QString& fileName) const;
|
||||
|
||||
QByteArray readAudioFile() const;
|
||||
QByteArray readAudioSettingsJsonFile() const;
|
||||
QByteArray readViewSettingsJsonFile() const;
|
||||
io::ByteArray readAudioFile() const;
|
||||
io::ByteArray readAudioSettingsJsonFile() const;
|
||||
io::ByteArray readViewSettingsJsonFile() const;
|
||||
|
||||
private:
|
||||
|
||||
struct IReader {
|
||||
virtual ~IReader() = default;
|
||||
|
||||
virtual bool open(QIODevice* device, const QString& filePath) = 0;
|
||||
virtual bool open(io::IODevice* device, const QString& filePath) = 0;
|
||||
virtual void close() = 0;
|
||||
virtual bool isOpened() const = 0;
|
||||
//! NOTE In the case of reading from a directory,
|
||||
|
@ -94,21 +94,21 @@ private:
|
|||
struct ZipFileReader : public IReader
|
||||
{
|
||||
~ZipFileReader() override;
|
||||
bool open(QIODevice* device, const QString& filePath) override;
|
||||
bool open(io::IODevice* device, const QString& filePath) override;
|
||||
void close() override;
|
||||
bool isOpened() const override;
|
||||
bool isContainer() const override;
|
||||
QStringList fileList() const override;
|
||||
QByteArray fileData(const QString& fileName) const override;
|
||||
private:
|
||||
QIODevice* m_device = nullptr;
|
||||
io::IODevice* m_device = nullptr;
|
||||
bool m_selfDeviceOwner = false;
|
||||
ZipReader* m_zip = nullptr;
|
||||
};
|
||||
|
||||
struct DirReader : public IReader
|
||||
{
|
||||
bool open(QIODevice* device, const QString& filePath) override;
|
||||
bool open(io::IODevice* device, const QString& filePath) override;
|
||||
void close() override;
|
||||
bool isOpened() const override;
|
||||
bool isContainer() const override;
|
||||
|
@ -120,19 +120,19 @@ private:
|
|||
|
||||
struct XmlFileReader : public IReader
|
||||
{
|
||||
bool open(QIODevice* device, const QString& filePath) override;
|
||||
bool open(io::IODevice* device, const QString& filePath) override;
|
||||
void close() override;
|
||||
bool isOpened() const override;
|
||||
bool isContainer() const override;
|
||||
QStringList fileList() const override;
|
||||
QByteArray fileData(const QString& fileName) const override;
|
||||
private:
|
||||
QIODevice* m_device = nullptr;
|
||||
io::IODevice* m_device = nullptr;
|
||||
bool m_selfDeviceOwner = false;
|
||||
};
|
||||
|
||||
IReader* reader() const;
|
||||
QByteArray fileData(const QString& fileName) const;
|
||||
io::ByteArray fileData(const QString& fileName) const;
|
||||
|
||||
QString mainFileName() const;
|
||||
|
||||
|
|
|
@ -23,19 +23,19 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QBuffer>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "containers.h"
|
||||
|
||||
#include "io/buffer.h"
|
||||
#include "io/file.h"
|
||||
#include "serialization/xmlstreamwriter.h"
|
||||
#include "serialization/zipwriter.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
MscWriter::MscWriter(const Params& params)
|
||||
|
@ -111,6 +111,12 @@ MscWriter::IWriter* MscWriter::writer() const
|
|||
return m_writer;
|
||||
}
|
||||
|
||||
bool MscWriter::addFileData(const QString& fileName, const ByteArray& data)
|
||||
{
|
||||
QByteArray ba = QByteArray::fromRawData(reinterpret_cast<const char*>(data.constData()), data.size());
|
||||
return addFileData(fileName, ba);
|
||||
}
|
||||
|
||||
bool MscWriter::addFileData(const QString& fileName, const QByteArray& data)
|
||||
{
|
||||
if (!writer()->addFileData(fileName, data)) {
|
||||
|
@ -123,7 +129,7 @@ bool MscWriter::addFileData(const QString& fileName, const QByteArray& data)
|
|||
return true;
|
||||
}
|
||||
|
||||
void MscWriter::writeStyleFile(const QByteArray& data)
|
||||
void MscWriter::writeStyleFile(const ByteArray& data)
|
||||
{
|
||||
addFileData("score_style.mss", data);
|
||||
}
|
||||
|
@ -147,49 +153,49 @@ QString MscWriter::mainFileName() const
|
|||
return completeBaseName + ".mscx";
|
||||
}
|
||||
|
||||
void MscWriter::writeScoreFile(const QByteArray& data)
|
||||
void MscWriter::writeScoreFile(const ByteArray& data)
|
||||
{
|
||||
addFileData(mainFileName(), data);
|
||||
}
|
||||
|
||||
void MscWriter::addExcerptStyleFile(const QString& name, const QByteArray& data)
|
||||
void MscWriter::addExcerptStyleFile(const QString& name, const ByteArray& data)
|
||||
{
|
||||
QString fileName = name + ".mss";
|
||||
addFileData("Excerpts/" + fileName, data);
|
||||
}
|
||||
|
||||
void MscWriter::addExcerptFile(const QString& name, const QByteArray& data)
|
||||
void MscWriter::addExcerptFile(const QString& name, const ByteArray& data)
|
||||
{
|
||||
QString fileName = name + ".mscx";
|
||||
addFileData("Excerpts/" + fileName, data);
|
||||
}
|
||||
|
||||
void MscWriter::writeChordListFile(const QByteArray& data)
|
||||
void MscWriter::writeChordListFile(const ByteArray& data)
|
||||
{
|
||||
addFileData("chordlist.xml", data);
|
||||
}
|
||||
|
||||
void MscWriter::writeThumbnailFile(const QByteArray& data)
|
||||
void MscWriter::writeThumbnailFile(const ByteArray& data)
|
||||
{
|
||||
addFileData("Thumbnails/thumbnail.png", data);
|
||||
}
|
||||
|
||||
void MscWriter::addImageFile(const QString& fileName, const QByteArray& data)
|
||||
void MscWriter::addImageFile(const QString& fileName, const ByteArray& data)
|
||||
{
|
||||
addFileData("Pictures/" + fileName, data);
|
||||
}
|
||||
|
||||
void MscWriter::writeAudioFile(const QByteArray& data)
|
||||
void MscWriter::writeAudioFile(const ByteArray& data)
|
||||
{
|
||||
addFileData("audio.ogg", data);
|
||||
}
|
||||
|
||||
void MscWriter::writeAudioSettingsJsonFile(const QByteArray& data)
|
||||
void MscWriter::writeAudioSettingsJsonFile(const ByteArray& data)
|
||||
{
|
||||
addFileData("audiosettings.json", data);
|
||||
}
|
||||
|
||||
void MscWriter::writeViewSettingsJsonFile(const QByteArray& data)
|
||||
void MscWriter::writeViewSettingsJsonFile(const ByteArray& data)
|
||||
{
|
||||
addFileData("viewsettings.json", data);
|
||||
}
|
||||
|
@ -207,23 +213,21 @@ void MscWriter::writeMeta()
|
|||
|
||||
void MscWriter::writeContainer(const std::vector<QString>& paths)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buf(&data);
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xml(&buf);
|
||||
ByteArray data;
|
||||
Buffer buf(&data);
|
||||
buf.open(IODevice::WriteOnly);
|
||||
XmlStreamWriter xml(&buf);
|
||||
xml.writeStartDocument();
|
||||
xml.writeStartElement("container");
|
||||
xml.writeStartElement("rootfiles");
|
||||
|
||||
for (const QString& f : paths) {
|
||||
xml.writeStartElement("rootfile");
|
||||
xml.writeAttribute("full-path", f);
|
||||
xml.writeEndElement();
|
||||
xml.writeElement(QString("rootfile full-path=\"%1\"").arg(f));
|
||||
}
|
||||
|
||||
xml.writeEndElement();
|
||||
xml.writeEndElement();
|
||||
xml.writeEndDocument();
|
||||
xml.flush();
|
||||
|
||||
addFileData("META-INF/container.xml", data);
|
||||
}
|
||||
|
@ -255,16 +259,16 @@ MscWriter::ZipFileWriter::~ZipFileWriter()
|
|||
}
|
||||
}
|
||||
|
||||
bool MscWriter::ZipFileWriter::open(QIODevice* device, const QString& filePath)
|
||||
bool MscWriter::ZipFileWriter::open(io::IODevice* device, const QString& filePath)
|
||||
{
|
||||
m_device = device;
|
||||
if (!m_device) {
|
||||
m_device = new QFile(filePath);
|
||||
m_device = new File(filePath);
|
||||
m_selfDeviceOwner = true;
|
||||
}
|
||||
|
||||
if (!m_device->isOpen()) {
|
||||
if (!m_device->open(QIODevice::WriteOnly)) {
|
||||
if (!m_device->open(IODevice::WriteOnly)) {
|
||||
LOGE() << "failed open file: " << filePath;
|
||||
return false;
|
||||
}
|
||||
|
@ -305,7 +309,7 @@ bool MscWriter::ZipFileWriter::addFileData(const QString& fileName, const QByteA
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MscWriter::DirWriter::open(QIODevice* device, const QString& filePath)
|
||||
bool MscWriter::DirWriter::open(io::IODevice* device, const QString& filePath)
|
||||
{
|
||||
if (device) {
|
||||
NOT_SUPPORTED;
|
||||
|
@ -355,13 +359,13 @@ bool MscWriter::DirWriter::addFileData(const QString& fileName, const QByteArray
|
|||
}
|
||||
}
|
||||
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
File file(filePath);
|
||||
if (!file.open(IODevice::WriteOnly)) {
|
||||
LOGE() << "failed open file: " << filePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.write(data) != qint64(data.size())) {
|
||||
if (file.write(data) != static_cast<size_t>(data.size())) {
|
||||
LOGE() << "failed write file: " << filePath;
|
||||
return false;
|
||||
}
|
||||
|
@ -377,22 +381,22 @@ MscWriter::XmlFileWriter::~XmlFileWriter()
|
|||
}
|
||||
}
|
||||
|
||||
bool MscWriter::XmlFileWriter::open(QIODevice* device, const QString& filePath)
|
||||
bool MscWriter::XmlFileWriter::open(io::IODevice* device, const QString& filePath)
|
||||
{
|
||||
m_device = device;
|
||||
if (!m_device) {
|
||||
m_device = new QFile(filePath);
|
||||
m_device = new File(filePath);
|
||||
m_selfDeviceOwner = true;
|
||||
}
|
||||
|
||||
if (!m_device->isOpen()) {
|
||||
if (!m_device->open(QIODevice::WriteOnly)) {
|
||||
if (!m_device->open(IODevice::WriteOnly)) {
|
||||
LOGE() << "failed open file: " << filePath;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_stream = new QTextStream(m_device);
|
||||
m_stream = new QTextStream(&m_data);
|
||||
|
||||
// Write header
|
||||
*m_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" << Qt::endl;
|
||||
|
@ -409,6 +413,8 @@ void MscWriter::XmlFileWriter::close()
|
|||
}
|
||||
|
||||
if (m_device) {
|
||||
QByteArray ba = m_data.toUtf8();
|
||||
m_device->write(ba);
|
||||
m_device->close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QIODevice>
|
||||
|
||||
#include "io/iodevice.h"
|
||||
#include "mscio.h"
|
||||
|
||||
class QTextStream;
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
struct Params
|
||||
{
|
||||
QIODevice* device = nullptr;
|
||||
io::IODevice* device = nullptr;
|
||||
QString filePath;
|
||||
QString mainFileName;
|
||||
MscIoMode mode = MscIoMode::Zip;
|
||||
|
@ -58,23 +58,23 @@ public:
|
|||
void close();
|
||||
bool isOpened() const;
|
||||
|
||||
void writeStyleFile(const QByteArray& data);
|
||||
void writeScoreFile(const QByteArray& data);
|
||||
void addExcerptStyleFile(const QString& name, const QByteArray& data);
|
||||
void addExcerptFile(const QString& name, const QByteArray& data);
|
||||
void writeChordListFile(const QByteArray& data);
|
||||
void writeThumbnailFile(const QByteArray& data);
|
||||
void addImageFile(const QString& fileName, const QByteArray& data);
|
||||
void writeAudioFile(const QByteArray& data);
|
||||
void writeAudioSettingsJsonFile(const QByteArray& data);
|
||||
void writeViewSettingsJsonFile(const QByteArray& data);
|
||||
void writeStyleFile(const io::ByteArray& data);
|
||||
void writeScoreFile(const io::ByteArray& data);
|
||||
void addExcerptStyleFile(const QString& name, const io::ByteArray& data);
|
||||
void addExcerptFile(const QString& name, const io::ByteArray& data);
|
||||
void writeChordListFile(const io::ByteArray& data);
|
||||
void writeThumbnailFile(const io::ByteArray& data);
|
||||
void addImageFile(const QString& fileName, const io::ByteArray& data);
|
||||
void writeAudioFile(const io::ByteArray& data);
|
||||
void writeAudioSettingsJsonFile(const io::ByteArray& data);
|
||||
void writeViewSettingsJsonFile(const io::ByteArray& data);
|
||||
|
||||
private:
|
||||
|
||||
struct IWriter {
|
||||
virtual ~IWriter() = default;
|
||||
|
||||
virtual bool open(QIODevice* device, const QString& filePath) = 0;
|
||||
virtual bool open(io::IODevice* device, const QString& filePath) = 0;
|
||||
virtual void close() = 0;
|
||||
virtual bool isOpened() const = 0;
|
||||
virtual bool addFileData(const QString& fileName, const QByteArray& data) = 0;
|
||||
|
@ -83,20 +83,20 @@ private:
|
|||
struct ZipFileWriter : public IWriter
|
||||
{
|
||||
~ZipFileWriter() override;
|
||||
bool open(QIODevice* device, const QString& filePath) override;
|
||||
bool open(io::IODevice* device, const QString& filePath) override;
|
||||
void close() override;
|
||||
bool isOpened() const override;
|
||||
bool addFileData(const QString& fileName, const QByteArray& data) override;
|
||||
|
||||
private:
|
||||
QIODevice* m_device = nullptr;
|
||||
io::IODevice* m_device = nullptr;
|
||||
bool m_selfDeviceOwner = false;
|
||||
ZipWriter* m_zip = nullptr;
|
||||
};
|
||||
|
||||
struct DirWriter : public IWriter
|
||||
{
|
||||
bool open(QIODevice* device, const QString& filePath) override;
|
||||
bool open(io::IODevice* device, const QString& filePath) override;
|
||||
void close() override;
|
||||
bool isOpened() const override;
|
||||
bool addFileData(const QString& fileName, const QByteArray& data) override;
|
||||
|
@ -107,14 +107,15 @@ private:
|
|||
struct XmlFileWriter : public IWriter
|
||||
{
|
||||
~XmlFileWriter() override;
|
||||
bool open(QIODevice* device, const QString& filePath) override;
|
||||
bool open(io::IODevice* device, const QString& filePath) override;
|
||||
void close() override;
|
||||
bool isOpened() const override;
|
||||
bool addFileData(const QString& fileName, const QByteArray& data) override;
|
||||
private:
|
||||
QIODevice* m_device = nullptr;
|
||||
io::IODevice* m_device = nullptr;
|
||||
bool m_selfDeviceOwner = false;
|
||||
QTextStream* m_stream = nullptr;
|
||||
QString m_data;
|
||||
};
|
||||
|
||||
struct Meta {
|
||||
|
@ -127,6 +128,7 @@ private:
|
|||
|
||||
IWriter* writer() const;
|
||||
bool addFileData(const QString& fileName, const QByteArray& data);
|
||||
bool addFileData(const QString& fileName, const io::ByteArray& data);
|
||||
|
||||
void writeMeta();
|
||||
void writeContainer(const std::vector<QString>& paths);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#define __AUDIO_H__
|
||||
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include "io/bytearray.h"
|
||||
|
||||
namespace Ms {
|
||||
class XmlWriter;
|
||||
|
@ -37,15 +37,15 @@ class XmlReader;
|
|||
class Audio
|
||||
{
|
||||
QString _path;
|
||||
QByteArray _data;
|
||||
mu::io::ByteArray _data;
|
||||
|
||||
public:
|
||||
Audio();
|
||||
const QString& path() const { return _path; }
|
||||
void setPath(const QString& s) { _path = s; }
|
||||
const QByteArray& data() const { return _data; }
|
||||
QByteArray data() { return _data; }
|
||||
void setData(const QByteArray& ba) { _data = ba; }
|
||||
const mu::io::ByteArray& data() const { return _data; }
|
||||
mu::io::ByteArray data() { return _data; }
|
||||
void setData(const mu::io::ByteArray& ba) { _data = ba; }
|
||||
|
||||
void read(XmlReader&);
|
||||
void write(XmlWriter&) const;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <QRegularExpression>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "io/file.h"
|
||||
|
||||
#include "rw/xml.h"
|
||||
|
||||
#include "mscore.h"
|
||||
|
@ -36,6 +38,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
|
||||
namespace Ms {
|
||||
//---------------------------------------------------------
|
||||
|
@ -1855,9 +1858,9 @@ bool ChordList::read(const QString& name)
|
|||
if (name.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
QFile f(path);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
MScore::lastError = QObject::tr("Cannot open chord description:\n%1\n%2").arg(f.fileName(), f.errorString());
|
||||
File f(path);
|
||||
if (!f.open(IODevice::ReadOnly)) {
|
||||
MScore::lastError = QObject::tr("Cannot open chord description:\n%1").arg(f.filePath().toQString());
|
||||
LOGD("ChordList::read failed: <%s>", qPrintable(path));
|
||||
return false;
|
||||
}
|
||||
|
@ -1865,7 +1868,7 @@ bool ChordList::read(const QString& name)
|
|||
return read(&f);
|
||||
}
|
||||
|
||||
bool ChordList::read(QIODevice* device)
|
||||
bool ChordList::read(IODevice* device)
|
||||
{
|
||||
XmlReader e(device);
|
||||
|
||||
|
@ -1895,26 +1898,22 @@ bool ChordList::write(const QString& name) const
|
|||
info.setFile(path);
|
||||
}
|
||||
|
||||
QFile f(info.filePath());
|
||||
File f(info.filePath());
|
||||
|
||||
if (!f.open(QIODevice::WriteOnly)) {
|
||||
MScore::lastError = QObject::tr("Open chord description\n%1\nfailed: %2").arg(f.fileName(), f.errorString());
|
||||
if (!f.open(IODevice::WriteOnly)) {
|
||||
MScore::lastError = QObject::tr("Failed open chord description: %1").arg(f.filePath().toQString());
|
||||
return false;
|
||||
}
|
||||
|
||||
write(&f);
|
||||
|
||||
if (f.error() != QFile::NoError) {
|
||||
MScore::lastError = QObject::tr("Write chord description failed: %1").arg(f.errorString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChordList::write(QIODevice* device) const
|
||||
bool ChordList::write(IODevice* device) const
|
||||
{
|
||||
XmlWriter xml(device);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
xml.startObject("museScore version=\"" MSC_VERSION "\"");
|
||||
|
||||
write(xml);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <map>
|
||||
#include <QString>
|
||||
#include "containers.h"
|
||||
#include "io/iodevice.h"
|
||||
|
||||
#include "style/style.h"
|
||||
|
||||
|
@ -284,9 +285,9 @@ public:
|
|||
qreal position(const QStringList& names, ChordTokenClass ctc) const;
|
||||
|
||||
bool read(const QString&);
|
||||
bool read(QIODevice* device);
|
||||
bool read(mu::io::IODevice* device);
|
||||
bool write(const QString&) const;
|
||||
bool write(QIODevice* device) const;
|
||||
bool write(mu::io::IODevice* device) const;
|
||||
bool loaded() const;
|
||||
void unload();
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include "masterscore.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QBuffer>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "io/buffer.h"
|
||||
#include "io/mscreader.h"
|
||||
#include "io/mscwriter.h"
|
||||
#include "rw/xml.h"
|
||||
|
@ -48,6 +48,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace Ms;
|
||||
|
||||
|
@ -239,9 +240,9 @@ bool MasterScore::writeMscz(MscWriter& mscWriter, bool onlySelection, bool doCre
|
|||
{
|
||||
//! NOTE The style is writing to a separate file only for the master score.
|
||||
//! At the moment, the style for the parts is still writing to the score file.
|
||||
QByteArray styleData;
|
||||
QBuffer styleBuf(&styleData);
|
||||
styleBuf.open(QIODevice::WriteOnly);
|
||||
ByteArray styleData;
|
||||
Buffer styleBuf(&styleData);
|
||||
styleBuf.open(IODevice::WriteOnly);
|
||||
style().write(&styleBuf);
|
||||
mscWriter.writeStyleFile(styleData);
|
||||
}
|
||||
|
@ -250,9 +251,9 @@ bool MasterScore::writeMscz(MscWriter& mscWriter, bool onlySelection, bool doCre
|
|||
|
||||
// Write MasterScore
|
||||
{
|
||||
QByteArray scoreData;
|
||||
QBuffer scoreBuf(&scoreData);
|
||||
scoreBuf.open(QIODevice::ReadWrite);
|
||||
ByteArray scoreData;
|
||||
Buffer scoreBuf(&scoreData);
|
||||
scoreBuf.open(IODevice::ReadWrite);
|
||||
|
||||
compat::WriteScoreHook hook;
|
||||
Score::writeScore(&scoreBuf, false, onlySelection, hook, ctx);
|
||||
|
@ -268,9 +269,9 @@ bool MasterScore::writeMscz(MscWriter& mscWriter, bool onlySelection, bool doCre
|
|||
if (partScore != this) {
|
||||
// Write excerpt style
|
||||
{
|
||||
QByteArray excerptStyleData;
|
||||
QBuffer styleStyleBuf(&excerptStyleData);
|
||||
styleStyleBuf.open(QIODevice::WriteOnly);
|
||||
ByteArray excerptStyleData;
|
||||
Buffer styleStyleBuf(&excerptStyleData);
|
||||
styleStyleBuf.open(IODevice::WriteOnly);
|
||||
partScore->style().write(&styleStyleBuf);
|
||||
|
||||
mscWriter.addExcerptStyleFile(excerpt->name(), excerptStyleData);
|
||||
|
@ -278,9 +279,9 @@ bool MasterScore::writeMscz(MscWriter& mscWriter, bool onlySelection, bool doCre
|
|||
|
||||
// Write excerpt
|
||||
{
|
||||
QByteArray excerptData;
|
||||
QBuffer excerptBuf(&excerptData);
|
||||
excerptBuf.open(QIODevice::ReadWrite);
|
||||
ByteArray excerptData;
|
||||
Buffer excerptBuf(&excerptData);
|
||||
excerptBuf.open(IODevice::ReadWrite);
|
||||
|
||||
compat::WriteScoreHook hook;
|
||||
excerpt->excerptScore()->writeScore(&excerptBuf, false, onlySelection, hook, ctx);
|
||||
|
@ -296,9 +297,9 @@ bool MasterScore::writeMscz(MscWriter& mscWriter, bool onlySelection, bool doCre
|
|||
{
|
||||
ChordList* chordList = this->chordList();
|
||||
if (chordList->customChordList() && !chordList->empty()) {
|
||||
QByteArray chlData;
|
||||
QBuffer chlBuf(&chlData);
|
||||
chlBuf.open(QIODevice::WriteOnly);
|
||||
ByteArray chlData;
|
||||
Buffer chlBuf(&chlData);
|
||||
chlBuf.open(IODevice::WriteOnly);
|
||||
chordList->write(&chlBuf);
|
||||
mscWriter.writeChordListFile(chlData);
|
||||
}
|
||||
|
@ -310,7 +311,9 @@ bool MasterScore::writeMscz(MscWriter& mscWriter, bool onlySelection, bool doCre
|
|||
if (!ip->isUsed(this)) {
|
||||
continue;
|
||||
}
|
||||
mscWriter.addImageFile(ip->hashName(), ip->buffer());
|
||||
QByteArray data = ip->buffer();
|
||||
ByteArray ba = ByteArray::fromRawData(reinterpret_cast<const uint8_t*>(data.constData()), data.size());
|
||||
mscWriter.addImageFile(ip->hashName(), ba);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -319,9 +322,9 @@ bool MasterScore::writeMscz(MscWriter& mscWriter, bool onlySelection, bool doCre
|
|||
if (doCreateThumbnail && !pages().empty()) {
|
||||
auto pixmap = createThumbnail();
|
||||
|
||||
QByteArray ba;
|
||||
QBuffer b(&ba);
|
||||
b.open(QIODevice::WriteOnly);
|
||||
ByteArray ba;
|
||||
Buffer b(&ba);
|
||||
b.open(IODevice::WriteOnly);
|
||||
imageProvider()->saveAsPng(pixmap, &b);
|
||||
mscWriter.writeThumbnailFile(ba);
|
||||
}
|
||||
|
@ -341,9 +344,9 @@ bool MasterScore::exportPart(mu::engraving::MscWriter& mscWriter, Score* partSco
|
|||
{
|
||||
// Write excerpt style as main
|
||||
{
|
||||
QByteArray excerptStyleData;
|
||||
QBuffer styleStyleBuf(&excerptStyleData);
|
||||
styleStyleBuf.open(QIODevice::WriteOnly);
|
||||
ByteArray excerptStyleData;
|
||||
Buffer styleStyleBuf(&excerptStyleData);
|
||||
styleStyleBuf.open(IODevice::WriteOnly);
|
||||
partScore->style().write(&styleStyleBuf);
|
||||
|
||||
mscWriter.writeStyleFile(excerptStyleData);
|
||||
|
@ -351,9 +354,9 @@ bool MasterScore::exportPart(mu::engraving::MscWriter& mscWriter, Score* partSco
|
|||
|
||||
// Write excerpt as main score
|
||||
{
|
||||
QByteArray excerptData;
|
||||
QBuffer excerptBuf(&excerptData);
|
||||
excerptBuf.open(QIODevice::WriteOnly);
|
||||
ByteArray excerptData;
|
||||
Buffer excerptBuf(&excerptData);
|
||||
excerptBuf.open(IODevice::WriteOnly);
|
||||
|
||||
compat::WriteScoreHook hook;
|
||||
partScore->writeScore(&excerptBuf, false, false, hook);
|
||||
|
@ -366,9 +369,9 @@ bool MasterScore::exportPart(mu::engraving::MscWriter& mscWriter, Score* partSco
|
|||
if (!partScore->pages().empty()) {
|
||||
auto pixmap = partScore->createThumbnail();
|
||||
|
||||
QByteArray ba;
|
||||
QBuffer b(&ba);
|
||||
b.open(QIODevice::WriteOnly);
|
||||
ByteArray ba;
|
||||
Buffer b(&ba);
|
||||
b.open(IODevice::WriteOnly);
|
||||
imageProvider()->saveAsPng(pixmap, &b);
|
||||
mscWriter.writeThumbnailFile(ba);
|
||||
}
|
||||
|
@ -458,7 +461,7 @@ MasterScore* MasterScore::clone()
|
|||
WriteContext writeCtx;
|
||||
XmlWriter xml(&buffer);
|
||||
xml.setContext(&writeCtx);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
|
||||
xml.startObject("museScore version=\"" MSC_VERSION "\"");
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QMimeData>
|
||||
|
||||
#include "io/buffer.h"
|
||||
#include "rw/xml.h"
|
||||
#include "types/typesconv.h"
|
||||
|
||||
|
@ -58,6 +58,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
namespace Ms {
|
||||
|
@ -1216,16 +1217,16 @@ void Score::cmdPaste(const QMimeData* ms, MuseScoreView* view, Fraction scale)
|
|||
pasteSymbols(e, cr);
|
||||
}
|
||||
} else if (ms->hasImage()) {
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
ByteArray ba;
|
||||
Buffer buffer(&ba);
|
||||
buffer.open(IODevice::WriteOnly);
|
||||
|
||||
auto px = imageProvider()->pixmapFromQVariant(ms->imageData());
|
||||
imageProvider()->saveAsPng(px, &buffer);
|
||||
|
||||
Image* image = new Image(this->dummy());
|
||||
image->setImageType(ImageType::RASTER);
|
||||
image->loadFromData("dragdrop", ba);
|
||||
image->loadFromData("dragdrop", ba.toQByteArray());
|
||||
|
||||
std::vector<EngravingItem*> els;
|
||||
if (_selection.isSingle()) {
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <QSet>
|
||||
|
||||
#include "async/channel.h"
|
||||
#include "io/iodevice.h"
|
||||
|
||||
#include "chordlist.h"
|
||||
#include "input.h"
|
||||
|
@ -642,8 +643,8 @@ public:
|
|||
bool appendScore(Score*, bool addPageBreak = false, bool addSectionBreak = true);
|
||||
|
||||
void write(XmlWriter&, bool onlySelection, mu::engraving::compat::WriteScoreHook& hook);
|
||||
bool writeScore(QIODevice* f, bool msczFormat, bool onlySelection, mu::engraving::compat::WriteScoreHook& hook);
|
||||
bool writeScore(QIODevice* f, bool msczFormat, bool onlySelection, mu::engraving::compat::WriteScoreHook& hook,
|
||||
bool writeScore(mu::io::IODevice* f, bool msczFormat, bool onlySelection, mu::engraving::compat::WriteScoreHook& hook);
|
||||
bool writeScore(mu::io::IODevice* f, bool msczFormat, bool onlySelection, mu::engraving::compat::WriteScoreHook& hook,
|
||||
mu::engraving::WriteContext& ctx);
|
||||
|
||||
bool read400(XmlReader& e);
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <QDir>
|
||||
#include <QBuffer>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "translation.h"
|
||||
#include "io/file.h"
|
||||
|
||||
#include "style/defaultstyle.h"
|
||||
|
||||
|
@ -70,6 +70,7 @@
|
|||
#include "config.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace mu::engraving::rw;
|
||||
|
||||
|
@ -320,8 +321,8 @@ bool Score::loadStyle(const QString& fn, bool ign, const bool overlap)
|
|||
{
|
||||
TRACEFUNC;
|
||||
|
||||
QFile f(fn);
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
File f(fn);
|
||||
if (f.open(IODevice::ReadOnly)) {
|
||||
MStyle st = style();
|
||||
if (st.read(&f, ign)) {
|
||||
undo(new ChangeStyle(this, st, overlap));
|
||||
|
@ -347,15 +348,15 @@ bool Score::saveStyle(const QString& name)
|
|||
if (info.suffix().isEmpty()) {
|
||||
info.setFile(info.filePath() + ext);
|
||||
}
|
||||
QFile f(info.filePath());
|
||||
if (!f.open(QIODevice::WriteOnly)) {
|
||||
MScore::lastError = QObject::tr("Open Style File %1 failed: %2").arg(info.filePath(), f.errorString());
|
||||
File f(info.filePath());
|
||||
if (!f.open(IODevice::WriteOnly)) {
|
||||
MScore::lastError = QObject::tr("Failed open style file: %1 ").arg(info.filePath());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = style().write(&f);
|
||||
if (!ok) {
|
||||
MScore::lastError = QObject::tr("Write Style failed: %1").arg(f.errorString());
|
||||
MScore::lastError = QObject::tr("Failed write style file: %1").arg(info.filePath());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -371,18 +372,18 @@ bool Score::saveStyle(const QString& name)
|
|||
//extern QString revision;
|
||||
static QString revision;
|
||||
|
||||
bool Score::writeScore(QIODevice* f, bool msczFormat, bool onlySelection, mu::engraving::compat::WriteScoreHook& hook)
|
||||
bool Score::writeScore(io::IODevice* f, bool msczFormat, bool onlySelection, mu::engraving::compat::WriteScoreHook& hook)
|
||||
{
|
||||
WriteContext ctx;
|
||||
return writeScore(f, msczFormat, onlySelection, hook, ctx);
|
||||
}
|
||||
|
||||
bool Score::writeScore(QIODevice* f, bool msczFormat, bool onlySelection, compat::WriteScoreHook& hook, WriteContext& ctx)
|
||||
bool Score::writeScore(io::IODevice* f, bool msczFormat, bool onlySelection, compat::WriteScoreHook& hook, WriteContext& ctx)
|
||||
{
|
||||
XmlWriter xml(f);
|
||||
xml.context()->setIsMsczMode(msczFormat);
|
||||
xml.setContext(&ctx);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
|
||||
xml.startObject("museScore version=\"" MSC_VERSION "\"");
|
||||
|
||||
|
|
|
@ -829,7 +829,7 @@ QByteArray Selection::staffMimeData() const
|
|||
QBuffer buffer;
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
XmlWriter xml(&buffer);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
xml.context()->setClipboardmode(true);
|
||||
xml.context()->setFilter(selectionFilter());
|
||||
|
||||
|
@ -892,7 +892,7 @@ QByteArray Selection::symbolListMimeData() const
|
|||
QBuffer buffer;
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
XmlWriter xml(&buffer);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
xml.context()->setClipboardmode(true);
|
||||
|
||||
track_idx_t topTrack = 1000000;
|
||||
|
|
|
@ -31,10 +31,11 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving::compat;
|
||||
using namespace Ms;
|
||||
|
||||
static int readStyleDefaultsVersion(MasterScore* score, const QByteArray& scoreData, const QString& completeBaseName)
|
||||
static int readStyleDefaultsVersion(MasterScore* score, const ByteArray& scoreData, const QString& completeBaseName)
|
||||
{
|
||||
XmlReader e(scoreData);
|
||||
e.setDocName(completeBaseName);
|
||||
|
@ -49,7 +50,7 @@ static int readStyleDefaultsVersion(MasterScore* score, const QByteArray& scoreD
|
|||
return ReadStyleHook::styleDefaultByMscVersion(score->mscVersion());
|
||||
}
|
||||
|
||||
ReadStyleHook::ReadStyleHook(Ms::Score* score, const QByteArray& scoreData, const QString& completeBaseName)
|
||||
ReadStyleHook::ReadStyleHook(Ms::Score* score, const ByteArray& scoreData, const QString& completeBaseName)
|
||||
: m_score(score), m_scoreData(scoreData), m_completeBaseName(completeBaseName)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef MU_ENGRAVING_READSTYLE_H
|
||||
#define MU_ENGRAVING_READSTYLE_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include "io/bytearray.h"
|
||||
#include <QString>
|
||||
|
||||
namespace Ms {
|
||||
|
@ -36,7 +36,7 @@ namespace mu::engraving::compat {
|
|||
class ReadStyleHook
|
||||
{
|
||||
public:
|
||||
ReadStyleHook(Ms::Score* score, const QByteArray& scoreData, const QString& completeBaseName);
|
||||
ReadStyleHook(Ms::Score* score, const io::ByteArray& scoreData, const QString& completeBaseName);
|
||||
|
||||
void setupDefaultStyle();
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
|
||||
private:
|
||||
Ms::Score* m_score = nullptr;
|
||||
const QByteArray& m_scoreData;
|
||||
const io::ByteArray& m_scoreData;
|
||||
const QString& m_completeBaseName;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
#include "scorereader.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include "io/buffer.h"
|
||||
|
||||
#include "compat/readstyle.h"
|
||||
#include "compat/read114.h"
|
||||
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace Ms;
|
||||
|
||||
|
@ -53,17 +54,17 @@ Err ScoreReader::loadMscz(Ms::MasterScore* masterScore, const mu::engraving::Msc
|
|||
|
||||
// Read style
|
||||
{
|
||||
QByteArray styleData = mscReader.readStyleFile();
|
||||
QBuffer buf(&styleData);
|
||||
buf.open(QIODevice::ReadOnly);
|
||||
ByteArray styleData = mscReader.readStyleFile();
|
||||
Buffer buf(&styleData);
|
||||
buf.open(IODevice::ReadOnly);
|
||||
masterScore->style().read(&buf);
|
||||
}
|
||||
|
||||
// Read ChordList
|
||||
{
|
||||
QByteArray styleData = mscReader.readChordListFile();
|
||||
QBuffer buf(&styleData);
|
||||
buf.open(QIODevice::ReadOnly);
|
||||
ByteArray styleData = mscReader.readChordListFile();
|
||||
Buffer buf(&styleData);
|
||||
buf.open(IODevice::ReadOnly);
|
||||
masterScore->chordList()->read(&buf);
|
||||
}
|
||||
|
||||
|
@ -72,7 +73,7 @@ Err ScoreReader::loadMscz(Ms::MasterScore* masterScore, const mu::engraving::Msc
|
|||
if (!MScore::noImages) {
|
||||
std::vector<QString> images = mscReader.imageFileNames();
|
||||
for (const QString& name : images) {
|
||||
imageStore.add(name, mscReader.readImageFile(name));
|
||||
imageStore.add(name, mscReader.readImageFile(name).toQByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ Err ScoreReader::loadMscz(Ms::MasterScore* masterScore, const mu::engraving::Msc
|
|||
|
||||
// Read score
|
||||
{
|
||||
QByteArray scoreData = mscReader.readScoreFile();
|
||||
ByteArray scoreData = mscReader.readScoreFile();
|
||||
QString docName = masterScore->fileInfo()->fileName().toQString();
|
||||
|
||||
compat::ReadStyleHook styleHook(masterScore, scoreData, docName);
|
||||
|
@ -107,12 +108,12 @@ Err ScoreReader::loadMscz(Ms::MasterScore* masterScore, const mu::engraving::Msc
|
|||
Excerpt* ex = new Excerpt(masterScore);
|
||||
ex->setExcerptScore(partScore);
|
||||
|
||||
QByteArray excerptStyleData = mscReader.readExcerptStyleFile(excerptName);
|
||||
QBuffer excerptStyleBuf(&excerptStyleData);
|
||||
excerptStyleBuf.open(QIODevice::ReadOnly);
|
||||
ByteArray excerptStyleData = mscReader.readExcerptStyleFile(excerptName);
|
||||
Buffer excerptStyleBuf(&excerptStyleData);
|
||||
excerptStyleBuf.open(IODevice::ReadOnly);
|
||||
partScore->style().read(&excerptStyleBuf);
|
||||
|
||||
QByteArray excerptData = mscReader.readExcerptFile(excerptName);
|
||||
ByteArray excerptData = mscReader.readExcerptFile(excerptName);
|
||||
|
||||
ReadContext ctx(partScore);
|
||||
ctx.initLinks(masterScoreCtx);
|
||||
|
@ -135,7 +136,7 @@ Err ScoreReader::loadMscz(Ms::MasterScore* masterScore, const mu::engraving::Msc
|
|||
// Read audio
|
||||
{
|
||||
if (masterScore->audio()) {
|
||||
QByteArray dbuf1 = mscReader.readAudioFile();
|
||||
ByteArray dbuf1 = mscReader.readAudioFile();
|
||||
masterScore->audio()->setData(dbuf1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,10 +220,10 @@ void XmlReader::unknown()
|
|||
LOGD("%s ", qPrintable(errorString()));
|
||||
}
|
||||
if (!docName.isEmpty()) {
|
||||
LOGD("tag in <%s> line %lld col %lld: %s", qPrintable(docName), lineNumber() + _offsetLines, columnNumber(),
|
||||
LOGD("tag in <%s> line %ld col %lld: %s", qPrintable(docName), lineNumber() + _offsetLines, columnNumber(),
|
||||
name().toUtf8().data());
|
||||
} else {
|
||||
LOGD("line %lld col %lld: %s", lineNumber() + _offsetLines, columnNumber(), name().toUtf8().data());
|
||||
LOGD("line %lld col %ld: %s", lineNumber() + _offsetLines, columnNumber(), name().toUtf8().data());
|
||||
}
|
||||
skipCurrentElement();
|
||||
}
|
||||
|
|
|
@ -47,6 +47,11 @@ XmlWriter::XmlWriter(QIODevice* device)
|
|||
{
|
||||
}
|
||||
|
||||
XmlWriter::XmlWriter(mu::io::IODevice* device)
|
||||
: XmlStreamWriter(device)
|
||||
{
|
||||
}
|
||||
|
||||
XmlWriter::~XmlWriter()
|
||||
{
|
||||
if (m_selfContext) {
|
||||
|
|
|
@ -23,11 +23,10 @@
|
|||
#define MU_ENGRAVING_XMLWRITER_H
|
||||
|
||||
#include <map>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "containers.h"
|
||||
#include "io/iodevice.h"
|
||||
|
||||
#include "infrastructure/draw/color.h"
|
||||
#include "libmscore/connector.h"
|
||||
|
@ -53,6 +52,7 @@ class XmlWriter : public mu::XmlStreamWriter
|
|||
public:
|
||||
XmlWriter();
|
||||
XmlWriter(QIODevice* dev);
|
||||
XmlWriter(mu::io::IODevice* dev);
|
||||
~XmlWriter();
|
||||
|
||||
const std::vector<std::pair<const EngravingObject*, QString> >& elements() const { return _elements; }
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
*/
|
||||
#include "defaultstyle.h"
|
||||
|
||||
#include <QFile>
|
||||
#include "io/file.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace Ms;
|
||||
|
||||
|
@ -73,8 +74,8 @@ void DefaultStyle::init(const QString& defaultStyleFilePath, const QString& part
|
|||
|
||||
bool DefaultStyle::doLoadStyle(Ms::MStyle* style, const QString& filePath)
|
||||
{
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
File file(filePath);
|
||||
if (!file.open(IODevice::ReadOnly)) {
|
||||
LOGE() << "failed load style: " << filePath;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace mu::engraving::rw;
|
||||
using namespace Ms;
|
||||
|
@ -244,7 +245,7 @@ bool MStyle::readTextStyleValCompat(XmlReader& e)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MStyle::read(QIODevice* device, bool ign)
|
||||
bool MStyle::read(IODevice* device, bool ign)
|
||||
{
|
||||
XmlReader e(device);
|
||||
while (e.readNextStartElement()) {
|
||||
|
@ -322,10 +323,10 @@ void MStyle::read(XmlReader& e, compat::ReadChordListHook* readChordListHook)
|
|||
}
|
||||
}
|
||||
|
||||
bool MStyle::write(QIODevice* device)
|
||||
bool MStyle::write(IODevice *device)
|
||||
{
|
||||
XmlWriter xml(device);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
xml.startObject("museScore version=\"" MSC_VERSION "\"");
|
||||
save(xml, false);
|
||||
xml.endObject();
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <functional>
|
||||
|
||||
#include <array>
|
||||
#include <QIODevice>
|
||||
#include "io/iodevice.h"
|
||||
#include <QSet>
|
||||
|
||||
#include "libmscore/types.h"
|
||||
|
@ -73,8 +73,8 @@ public:
|
|||
void setDefaultStyleVersion(const int defaultsVersion);
|
||||
int defaultStyleVersion() const;
|
||||
|
||||
bool read(QIODevice* device, bool ign = false);
|
||||
bool write(QIODevice* device);
|
||||
bool read(mu::io::IODevice* device, bool ign = false);
|
||||
bool write(mu::io::IODevice* device);
|
||||
void save(XmlWriter& xml, bool optimize);
|
||||
static bool isValid(QIODevice* device);
|
||||
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
|
||||
#include "testbase.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "io/file.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libmscore/masterscore.h"
|
||||
#include "libmscore/musescoreCore.h"
|
||||
|
@ -40,6 +41,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
static void initMyResources()
|
||||
|
@ -61,7 +63,7 @@ EngravingItem* MTest::writeReadElement(EngravingItem* element)
|
|||
QBuffer buffer;
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
XmlWriter xml(&buffer);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
element->write(xml);
|
||||
buffer.close();
|
||||
|
||||
|
@ -134,12 +136,12 @@ MasterScore* MTest::readCreatedScore(const QString& name)
|
|||
|
||||
bool MTest::saveScore(Score* score_, const QString& name) const
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -199,13 +201,13 @@ bool MTest::saveCompareScore(Score* score_, const QString& saveName, const QStri
|
|||
|
||||
bool MTest::saveMimeData(QByteArray mimeData, const QString& saveName)
|
||||
{
|
||||
QFile f(saveName);
|
||||
if (!f.open(QIODevice::WriteOnly)) {
|
||||
File f(saveName);
|
||||
if (!f.open(IODevice::WriteOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
f.write(mimeData);
|
||||
return f.error() == QFile::NoError;
|
||||
size_t size = f.write(mimeData);
|
||||
return size == mimeData.size();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -22,11 +22,12 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "io/buffer.h"
|
||||
#include "io/mscwriter.h"
|
||||
#include "io/mscreader.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
class MsczFileTests : public ::testing::Test
|
||||
|
@ -40,14 +41,14 @@ TEST_F(MsczFileTests, MsczFile_WriteRead)
|
|||
|
||||
//! GIVEN Some datas
|
||||
|
||||
const QByteArray originScoreData("score");
|
||||
const QByteArray originImageData("image");
|
||||
const QByteArray originThumbnailData("thumbnail");
|
||||
const ByteArray originScoreData("score");
|
||||
const ByteArray originImageData("image");
|
||||
const ByteArray originThumbnailData("thumbnail");
|
||||
|
||||
//! DO Write datas
|
||||
QByteArray msczData;
|
||||
ByteArray msczData;
|
||||
{
|
||||
QBuffer buf(&msczData);
|
||||
Buffer buf(&msczData);
|
||||
MscWriter::Params params;
|
||||
params.device = &buf;
|
||||
params.filePath = "simple1.mscz";
|
||||
|
@ -63,7 +64,7 @@ TEST_F(MsczFileTests, MsczFile_WriteRead)
|
|||
|
||||
//! CHECK Read and compare with origin
|
||||
{
|
||||
QBuffer buf(&msczData);
|
||||
Buffer buf(&msczData);
|
||||
MscReader::Params params;
|
||||
params.device = &buf;
|
||||
params.filePath = "simple1.mscz";
|
||||
|
@ -72,14 +73,14 @@ TEST_F(MsczFileTests, MsczFile_WriteRead)
|
|||
MscReader reader(params);
|
||||
reader.open();
|
||||
|
||||
QByteArray scoreData = reader.readScoreFile();
|
||||
ByteArray scoreData = reader.readScoreFile();
|
||||
EXPECT_EQ(scoreData, originScoreData);
|
||||
|
||||
QByteArray thumbnailData = reader.readThumbnailFile();
|
||||
ByteArray thumbnailData = reader.readThumbnailFile();
|
||||
EXPECT_EQ(thumbnailData, originThumbnailData);
|
||||
|
||||
std::vector<QString> images = reader.imageFileNames();
|
||||
QByteArray imageData = reader.readImageFile("image1.png");
|
||||
ByteArray imageData = reader.readImageFile("image1.png");
|
||||
EXPECT_EQ(images.size(), 1);
|
||||
EXPECT_EQ(images.at(0), "image1.png");
|
||||
EXPECT_EQ(imageData, originImageData);
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
#include "scorerw.h"
|
||||
|
||||
#include <QFile>
|
||||
#include "io/file.h"
|
||||
#include "io/buffer.h"
|
||||
|
||||
#include "engraving/compat/scoreaccess.h"
|
||||
#include "engraving/compat/mscxcompat.h"
|
||||
|
@ -33,6 +34,7 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace Ms;
|
||||
|
||||
|
@ -71,12 +73,12 @@ MasterScore* ScoreRW::readScore(const QString& name, bool isAbsolutePath)
|
|||
|
||||
bool ScoreRW::saveScore(Ms::Score* score, const QString& name)
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
compat::WriteScoreHook hook;
|
||||
|
@ -88,18 +90,19 @@ EngravingItem* ScoreRW::writeReadElement(EngravingItem* element)
|
|||
//
|
||||
// write element
|
||||
//
|
||||
QBuffer buffer;
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
Buffer buffer;
|
||||
buffer.open(IODevice::WriteOnly);
|
||||
XmlWriter xml(&buffer);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
element->write(xml);
|
||||
xml.flush();
|
||||
buffer.close();
|
||||
|
||||
//
|
||||
// read element
|
||||
//
|
||||
|
||||
XmlReader e(buffer.buffer());
|
||||
XmlReader e(buffer.data());
|
||||
e.readNextStartElement();
|
||||
element = Factory::createItemByName(e.name(), element->score()->dummy());
|
||||
element->read(e);
|
||||
|
@ -108,11 +111,11 @@ EngravingItem* ScoreRW::writeReadElement(EngravingItem* element)
|
|||
|
||||
bool ScoreRW::saveMimeData(QByteArray mimeData, const QString& saveName)
|
||||
{
|
||||
QFile f(saveName);
|
||||
if (!f.open(QIODevice::WriteOnly)) {
|
||||
File f(saveName);
|
||||
if (!f.open(IODevice::WriteOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
f.write(mimeData);
|
||||
return f.error() == QFile::NoError;
|
||||
size_t size = f.write(mimeData);
|
||||
return size == mimeData.size();
|
||||
}
|
||||
|
|
|
@ -50,6 +50,11 @@ Buffer::Buffer(ByteArray* ba)
|
|||
}
|
||||
}
|
||||
|
||||
const ByteArray& Buffer::data() const
|
||||
{
|
||||
return *m_ref;
|
||||
}
|
||||
|
||||
bool Buffer::doOpen(OpenMode)
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
Buffer(const uint8_t* data, size_t size);
|
||||
Buffer(ByteArray* ba);
|
||||
|
||||
const ByteArray& data() const;
|
||||
|
||||
protected:
|
||||
|
||||
bool doOpen(OpenMode m) override;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
using namespace mu::io;
|
||||
|
||||
ByteArray::ByteArray()
|
||||
: m_data(nullptr), m_size(0)
|
||||
: m_size(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -39,24 +39,52 @@ ByteArray::ByteArray(const uint8_t* data, size_t size)
|
|||
std::memcpy(m_data.get(), data, m_size);
|
||||
}
|
||||
|
||||
ByteArray::ByteArray(const char* str)
|
||||
{
|
||||
m_size = std::strlen(str);
|
||||
m_data.reset(new uint8_t[m_size + 1]);
|
||||
m_data.get()[m_size] = 0;
|
||||
std::memcpy(m_data.get(), str, m_size);
|
||||
}
|
||||
|
||||
ByteArray ByteArray::fromRawData(const uint8_t* data, size_t size)
|
||||
{
|
||||
ByteArray ba;
|
||||
ba.m_size = size;
|
||||
ba.m_rawData = data;
|
||||
return ba;
|
||||
}
|
||||
|
||||
void ByteArray::detachRawDataIfNeed()
|
||||
{
|
||||
if (m_rawData) {
|
||||
m_data.reset(new uint8_t[m_size + 1]);
|
||||
m_data.get()[m_size] = 0;
|
||||
std::memcpy(m_data.get(), m_rawData, m_size);
|
||||
m_rawData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool ByteArray::operator==(const ByteArray& other) const
|
||||
{
|
||||
if (m_data == other.m_data) {
|
||||
return true;
|
||||
}
|
||||
if (m_size != other.m_size) {
|
||||
return false;
|
||||
}
|
||||
return std::memcmp(m_data.get(), other.m_data.get(), m_size) == 0;
|
||||
return std::memcmp(constData(), other.constData(), m_size) == 0;
|
||||
}
|
||||
|
||||
uint8_t* ByteArray::data()
|
||||
{
|
||||
detachRawDataIfNeed();
|
||||
return m_data.get();
|
||||
}
|
||||
|
||||
const uint8_t* ByteArray::constData() const
|
||||
{
|
||||
if (m_rawData) {
|
||||
return m_rawData;
|
||||
}
|
||||
|
||||
return m_data.get();
|
||||
}
|
||||
|
||||
|
@ -67,7 +95,7 @@ size_t ByteArray::size() const
|
|||
|
||||
bool ByteArray::empty() const
|
||||
{
|
||||
return m_data == nullptr;
|
||||
return constData() == nullptr;
|
||||
}
|
||||
|
||||
void ByteArray::resize(size_t nsize)
|
||||
|
@ -76,6 +104,8 @@ void ByteArray::resize(size_t nsize)
|
|||
return;
|
||||
}
|
||||
|
||||
detachRawDataIfNeed();
|
||||
|
||||
uint8_t* nbyte = new uint8_t[nsize + 1];
|
||||
nbyte[nsize] = 0;
|
||||
if (m_data) {
|
||||
|
@ -100,6 +130,8 @@ ByteArray& ByteArray::insert(size_t pos, uint8_t b)
|
|||
return *this;
|
||||
}
|
||||
|
||||
detachRawDataIfNeed();
|
||||
|
||||
if (!m_data && pos == 0) {
|
||||
if (m_buffer_size == 0) {
|
||||
m_buffer_size = 128;
|
||||
|
@ -137,6 +169,8 @@ void ByteArray::push_back(uint8_t b)
|
|||
|
||||
void ByteArray::push_back(const ByteArray& other)
|
||||
{
|
||||
detachRawDataIfNeed();
|
||||
|
||||
uint8_t* nbyte = new uint8_t[m_size + other.m_size + 1];
|
||||
nbyte[m_size + other.m_size] = 0;
|
||||
std::memcpy(nbyte, m_data.get(), m_size);
|
||||
|
@ -149,13 +183,15 @@ uint8_t ByteArray::operator[](size_t pos) const
|
|||
{
|
||||
assert(pos < m_size);
|
||||
if (pos < m_size) {
|
||||
return m_data.get()[pos];
|
||||
return constData()[pos];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t& ByteArray::operator[](size_t pos)
|
||||
{
|
||||
detachRawDataIfNeed();
|
||||
|
||||
assert(pos < m_size);
|
||||
if (pos < m_size) {
|
||||
return m_data.get()[pos];
|
||||
|
|
|
@ -25,12 +25,20 @@
|
|||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#ifndef NO_QT_SUPPORT
|
||||
#include <QByteArray>
|
||||
#endif
|
||||
|
||||
namespace mu::io {
|
||||
class ByteArray
|
||||
{
|
||||
public:
|
||||
ByteArray();
|
||||
ByteArray(const uint8_t* data, size_t size);
|
||||
ByteArray(const char* str);
|
||||
|
||||
//! NOTE Not coped!!!
|
||||
static ByteArray fromRawData(const uint8_t* data, size_t size);
|
||||
|
||||
bool operator==(const ByteArray& other) const;
|
||||
bool operator!=(const ByteArray& other) const { return !operator==(other); }
|
||||
|
@ -52,9 +60,35 @@ public:
|
|||
ByteArray left(size_t len) const;
|
||||
ByteArray right(size_t len) const;
|
||||
|
||||
#ifndef NO_QT_SUPPORT
|
||||
static ByteArray fromQByteArray(const QByteArray& ba)
|
||||
{
|
||||
return ByteArray(reinterpret_cast<const uint8_t*>(ba.constData()), ba.size());
|
||||
}
|
||||
|
||||
static ByteArray fromQByteArrayNoCopy(const QByteArray& ba)
|
||||
{
|
||||
return fromRawData(reinterpret_cast<const uint8_t*>(ba.constData()), ba.size());
|
||||
}
|
||||
|
||||
QByteArray toQByteArray() const
|
||||
{
|
||||
return QByteArray(reinterpret_cast<const char*>(constData()), size());
|
||||
}
|
||||
|
||||
QByteArray toQByteArrayNoCopy() const
|
||||
{
|
||||
return QByteArray::fromRawData(reinterpret_cast<const char*>(constData()), size());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
void detachRawDataIfNeed();
|
||||
|
||||
std::shared_ptr<uint8_t> m_data;
|
||||
const uint8_t* m_rawData = nullptr;
|
||||
size_t m_size = 0;
|
||||
size_t m_buffer_size = 0;
|
||||
};
|
||||
|
|
|
@ -47,6 +47,11 @@ bool File::exists() const
|
|||
return fileSystem()->exists(m_filePath);
|
||||
}
|
||||
|
||||
bool File::remove()
|
||||
{
|
||||
return fileSystem()->remove(m_filePath);
|
||||
}
|
||||
|
||||
bool File::doOpen(OpenMode m)
|
||||
{
|
||||
if (m == IODevice::WriteOnly) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
path filePath() const;
|
||||
|
||||
bool exists() const;
|
||||
bool remove();
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -37,12 +37,14 @@ XmlStreamReader::XmlStreamReader(const QByteArray& data)
|
|||
|
||||
XmlStreamReader::XmlStreamReader(io::IODevice* device)
|
||||
{
|
||||
m_reader = new QXmlStreamReader();
|
||||
io::ByteArray data = device->readAll();
|
||||
setData(data);
|
||||
}
|
||||
|
||||
XmlStreamReader::XmlStreamReader(const io::ByteArray& data)
|
||||
{
|
||||
m_reader = new QXmlStreamReader();
|
||||
setData(data);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ void XmlStreamWriter::setString(QString* string, QIODevice::OpenMode openMode)
|
|||
void XmlStreamWriter::flush()
|
||||
{
|
||||
m_stream->flush();
|
||||
if (m_device) {
|
||||
if (m_device && m_device->isOpen()) {
|
||||
m_device->seek(0);
|
||||
m_device->write(m_data.toUtf8());
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ void XmlStreamWriter::putLevel()
|
|||
}
|
||||
}
|
||||
|
||||
void XmlStreamWriter::writeHeader()
|
||||
void XmlStreamWriter::writeStartDocument()
|
||||
{
|
||||
*m_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
void setString(QString* string, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
|
||||
void flush();
|
||||
|
||||
void writeHeader();
|
||||
void writeStartDocument();
|
||||
void writeDoctype(const QString& type);
|
||||
|
||||
void writeStartElement(const QString& name);
|
||||
|
|
|
@ -30,8 +30,9 @@ using namespace mu;
|
|||
struct ZipReader::Impl
|
||||
{
|
||||
MQZipReader* zip = nullptr;
|
||||
io::ByteArray data;
|
||||
QByteArray ba;
|
||||
QBuffer buf;
|
||||
bool isClosed = false;
|
||||
};
|
||||
|
||||
ZipReader::ZipReader(QIODevice* device)
|
||||
|
@ -42,8 +43,11 @@ ZipReader::ZipReader(QIODevice* device)
|
|||
|
||||
ZipReader::ZipReader(io::IODevice* device)
|
||||
{
|
||||
m_device = device;
|
||||
m_impl = new Impl();
|
||||
m_impl->data = device->readAll();
|
||||
m_impl->ba = m_impl->data.toQByteArrayNoCopy();
|
||||
m_impl->buf.setBuffer(&m_impl->ba);
|
||||
m_impl->buf.open(QIODevice::ReadOnly);
|
||||
m_impl->zip = new MQZipReader(&m_impl->buf);
|
||||
}
|
||||
|
||||
|
@ -56,17 +60,7 @@ ZipReader::~ZipReader()
|
|||
|
||||
void ZipReader::close()
|
||||
{
|
||||
if (m_impl->isClosed) {
|
||||
return;
|
||||
}
|
||||
m_impl->isClosed = true;
|
||||
|
||||
m_impl->zip->close();
|
||||
if (m_device) {
|
||||
QByteArray data = m_impl->buf.readAll();
|
||||
m_device->write(data);
|
||||
m_device->close();
|
||||
}
|
||||
}
|
||||
|
||||
ZipReader::Status ZipReader::status() const
|
||||
|
|
|
@ -64,7 +64,6 @@ public:
|
|||
private:
|
||||
struct Impl;
|
||||
Impl* m_impl = nullptr;
|
||||
io::IODevice* m_device = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ using namespace mu;
|
|||
struct ZipWriter::Impl
|
||||
{
|
||||
MQZipWriter* zip = nullptr;
|
||||
QByteArray data;
|
||||
QBuffer buf;
|
||||
bool isClosed = false;
|
||||
};
|
||||
|
@ -44,28 +45,39 @@ ZipWriter::ZipWriter(io::IODevice* device)
|
|||
{
|
||||
m_device = device;
|
||||
m_impl = new Impl();
|
||||
m_impl->buf.setBuffer(&m_impl->data);
|
||||
m_impl->buf.open(QIODevice::WriteOnly);
|
||||
m_impl->zip = new MQZipWriter(&m_impl->buf);
|
||||
}
|
||||
|
||||
ZipWriter::~ZipWriter()
|
||||
{
|
||||
close();
|
||||
delete m_impl->zip;
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
void ZipWriter::flush()
|
||||
{
|
||||
if (m_device) {
|
||||
m_device->seek(0);
|
||||
m_device->write(m_impl->data);
|
||||
}
|
||||
}
|
||||
|
||||
void ZipWriter::close()
|
||||
{
|
||||
if (m_impl->isClosed) {
|
||||
return;
|
||||
}
|
||||
m_impl->isClosed = true;
|
||||
|
||||
m_impl->zip->close();
|
||||
if (m_device) {
|
||||
QByteArray data = m_impl->buf.readAll();
|
||||
m_device->write(data);
|
||||
flush();
|
||||
m_device->close();
|
||||
}
|
||||
|
||||
m_impl->isClosed = true;
|
||||
}
|
||||
|
||||
ZipWriter::Status ZipWriter::status() const
|
||||
|
@ -76,4 +88,5 @@ ZipWriter::Status ZipWriter::status() const
|
|||
void ZipWriter::addFile(const QString& fileName, const QByteArray& data)
|
||||
{
|
||||
m_impl->zip->addFile(fileName, data);
|
||||
flush();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef MU_GLOBAL_ZIPWRITER_H
|
||||
#define MU_GLOBAL_ZIPWRITER_H
|
||||
|
||||
#include <QIODevice>
|
||||
|
||||
#include "io/iodevice.h"
|
||||
|
||||
namespace mu {
|
||||
|
@ -46,6 +48,9 @@ public:
|
|||
void addFile(const QString& fileName, const QByteArray& data);
|
||||
|
||||
private:
|
||||
|
||||
void flush();
|
||||
|
||||
struct Impl;
|
||||
Impl* m_impl = nullptr;
|
||||
io::IODevice* m_device = nullptr;
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
|
||||
#include "testbase.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "io/file.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libmscore/masterscore.h"
|
||||
#include "libmscore/musescoreCore.h"
|
||||
|
@ -38,6 +39,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
namespace Ms {
|
||||
|
@ -82,12 +84,12 @@ MasterScore* MTest::readScore(const QString& name)
|
|||
|
||||
bool MTest::saveScore(Score* score, const QString& name) const
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
compat::WriteScoreHook hook;
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "io/file.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "importexport/braille/internal/exportbraille.h"
|
||||
|
@ -41,6 +43,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace mu::iex::braille;
|
||||
|
||||
|
@ -80,12 +83,12 @@ MasterScore* MTest::readScore(const QString& name)
|
|||
|
||||
bool MTest::saveScore(Score* score, const QString& name) const
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
compat::WriteScoreHook hook;
|
||||
|
@ -137,7 +140,7 @@ bool MTest::saveBraille(MasterScore* score, const QString& saveName)
|
|||
}
|
||||
|
||||
ExportBraille exporter(score);
|
||||
bool res = exporter.write(file) && (file.error() == QFile::NoError);
|
||||
bool res = exporter.write(file);
|
||||
file.close();
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -22,10 +22,12 @@
|
|||
|
||||
#include "testbase.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "io/file.h"
|
||||
#include "io/buffer.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libmscore/masterscore.h"
|
||||
#include "libmscore/musescoreCore.h"
|
||||
|
@ -38,6 +40,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
namespace Ms {
|
||||
|
@ -76,12 +79,12 @@ MasterScore* MTest::readScore(const QString& name)
|
|||
|
||||
bool MTest::saveScore(Score* score, const QString& name) const
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
compat::WriteScoreHook hook;
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
|
||||
#include "testbase.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "io/file.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libmscore/masterscore.h"
|
||||
#include "libmscore/musescoreCore.h"
|
||||
|
@ -38,6 +39,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
namespace Ms {
|
||||
|
@ -87,12 +89,12 @@ MasterScore* MTest::readScore(const QString& name)
|
|||
|
||||
bool MTest::saveScore(Score* score, const QString& name) const
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
compat::WriteScoreHook hook;
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
|
||||
#include "testbase.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "io/file.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libmscore/masterscore.h"
|
||||
#include "libmscore/musescoreCore.h"
|
||||
|
@ -38,6 +39,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
namespace Ms {
|
||||
|
@ -76,12 +78,12 @@ MasterScore* MTest::readScore(const QString& name)
|
|||
|
||||
bool MTest::saveScore(Score* score, const QString& name) const
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
compat::WriteScoreHook hook;
|
||||
|
|
|
@ -7268,7 +7268,7 @@ void ExportMusicXml::write(QIODevice* dev)
|
|||
_jumpElements = findJumpElements(_score);
|
||||
|
||||
_xml.setDevice(dev);
|
||||
_xml.writeHeader();
|
||||
_xml.writeStartDocument();
|
||||
_xml.writeDoctype("score-partwise PUBLIC \"-//Recordare//DTD MusicXML 4.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\"");
|
||||
|
||||
_xml.startObject("score-partwise version=\"4.0\"");
|
||||
|
@ -7348,7 +7348,7 @@ static void writeMxlArchive(Score* score, MQZipWriter& zipwriter, const QString&
|
|||
|
||||
XmlWriter xml;
|
||||
xml.setDevice(&cbuf);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
xml.startObject("container");
|
||||
xml.startObject("rootfiles");
|
||||
xml.startObject(QString("rootfile full-path=\"%1\"").arg(XmlWriter::xmlString(filename)));
|
||||
|
@ -7357,7 +7357,6 @@ static void writeMxlArchive(Score* score, MQZipWriter& zipwriter, const QString&
|
|||
xml.endObject();
|
||||
cbuf.seek(0);
|
||||
|
||||
//uz.addDirectory("META-INF");
|
||||
zipwriter.addFile("META-INF/container.xml", cbuf.data());
|
||||
|
||||
QBuffer dbuf;
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
|
||||
#include "testbase.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "io/file.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "libmscore/masterscore.h"
|
||||
#include "libmscore/musescoreCore.h"
|
||||
|
@ -40,6 +41,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
|
||||
namespace Ms {
|
||||
|
@ -93,12 +95,12 @@ MasterScore* MTest::readCreatedScore(const QString& name)
|
|||
|
||||
bool MTest::saveScore(Score* score, const QString& name) const
|
||||
{
|
||||
QFile file(name);
|
||||
File file(name);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite)) {
|
||||
if (!file.open(IODevice::ReadWrite)) {
|
||||
return false;
|
||||
}
|
||||
compat::WriteScoreHook hook;
|
||||
|
|
|
@ -22,10 +22,12 @@
|
|||
|
||||
#include "mscnotationwriter.h"
|
||||
|
||||
#include "io/buffer.h"
|
||||
#include "engraving/engravingproject.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace mu::framework;
|
||||
using namespace mu::notation;
|
||||
|
@ -59,12 +61,14 @@ mu::Ret MscNotationWriter::write(INotationPtr notation, io::Device& destinationD
|
|||
return make_ret(Ret::Code::UnknownError);
|
||||
}
|
||||
|
||||
Buffer buf;
|
||||
|
||||
MscWriter::Params params;
|
||||
params.mode = m_mode;
|
||||
|
||||
params.filePath = destinationDevice.property("path").toString();
|
||||
if (m_mode != MscIoMode::Dir) {
|
||||
params.device = &destinationDevice;
|
||||
params.device = &buf;
|
||||
} else if (QFile::exists(params.filePath)) {
|
||||
QFile::remove(params.filePath);
|
||||
}
|
||||
|
@ -75,6 +79,12 @@ mu::Ret MscNotationWriter::write(INotationPtr notation, io::Device& destinationD
|
|||
return Ret(Ret::Code::UnknownError);
|
||||
}
|
||||
notation->elements()->msScore()->masterScore()->project().lock()->writeMscz(msczWriter, false, true);
|
||||
|
||||
if (m_mode != MscIoMode::Dir) {
|
||||
ByteArray ba = buf.readAll();
|
||||
destinationDevice.write(reinterpret_cast<const char*>(ba.constData()), ba.size());
|
||||
}
|
||||
|
||||
return Ret(Ret::Code::Ok);
|
||||
}
|
||||
|
||||
|
|
|
@ -455,7 +455,7 @@ bool Palette::writeToFile(const QString& p) const
|
|||
QBuffer cbuf;
|
||||
cbuf.open(QIODevice::ReadWrite);
|
||||
XmlWriter xml(&cbuf);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
xml.startObject("container");
|
||||
xml.startObject("rootfiles");
|
||||
xml.startObject(QString("rootfile full-path=\"%1\"").arg(XmlWriter::xmlString("palette.xml")));
|
||||
|
@ -480,7 +480,7 @@ bool Palette::writeToFile(const QString& p) const
|
|||
QBuffer cbuf1;
|
||||
cbuf1.open(QIODevice::ReadWrite);
|
||||
XmlWriter xml1(&cbuf1);
|
||||
xml1.writeHeader();
|
||||
xml1.writeStartDocument();
|
||||
xml1.startObject("museScore version=\"" MSC_VERSION "\"");
|
||||
write(xml1);
|
||||
xml1.endObject();
|
||||
|
|
|
@ -691,7 +691,7 @@ void EditDrumsetDialog::save()
|
|||
}
|
||||
valueChanged(); //save last changes in name
|
||||
XmlWriter xml(&f);
|
||||
xml.writeHeader();
|
||||
xml.writeStartDocument();
|
||||
xml.startObject("museScore version=\"" MSC_VERSION "\"");
|
||||
m_editedDrumset.save(xml);
|
||||
xml.endObject();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
#include <QBuffer>
|
||||
#include "io/buffer.h"
|
||||
|
||||
#include "stringutils.h"
|
||||
#include "framework/global/xmlreader.h"
|
||||
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::io;
|
||||
using namespace mu::project;
|
||||
using namespace mu::framework;
|
||||
using namespace mu::engraving;
|
||||
|
@ -58,16 +59,16 @@ mu::RetVal<ProjectMeta> MscMetaReader::readMeta(const io::path& filePath) const
|
|||
}
|
||||
|
||||
// Read score meta
|
||||
QByteArray scoreData = msczReader.readScoreFile();
|
||||
framework::XmlReader xmlReader(scoreData);
|
||||
ByteArray scoreData = msczReader.readScoreFile();
|
||||
framework::XmlReader xmlReader(scoreData.toQByteArray());
|
||||
doReadMeta(xmlReader, meta.val);
|
||||
|
||||
// Read thumbnail
|
||||
QByteArray thumbnailData = msczReader.readThumbnailFile();
|
||||
if (thumbnailData.isEmpty()) {
|
||||
ByteArray thumbnailData = msczReader.readThumbnailFile();
|
||||
if (thumbnailData.empty()) {
|
||||
LOGD() << "Can't find thumbnail";
|
||||
} else {
|
||||
meta.val.thumbnail.loadFromData(thumbnailData, "PNG");
|
||||
meta.val.thumbnail.loadFromData(thumbnailData.toQByteArray(), "PNG");
|
||||
}
|
||||
|
||||
meta.val.filePath = filePath;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
||||
#include "io/buffer.h"
|
||||
|
||||
#include "engraving/engravingproject.h"
|
||||
#include "engraving/compat/scoreaccess.h"
|
||||
#include "engraving/compat/mscxcompat.h"
|
||||
|
@ -41,6 +43,7 @@
|
|||
#include "log.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::io;
|
||||
using namespace mu::engraving;
|
||||
using namespace mu::notation;
|
||||
using namespace mu::project;
|
||||
|
@ -443,8 +446,10 @@ mu::Ret NotationProject::writeToDevice(io::Device* device)
|
|||
return make_ret(notation::Err::UnknownError);
|
||||
}
|
||||
|
||||
Buffer buf;
|
||||
|
||||
MscWriter::Params params;
|
||||
params.device = device;
|
||||
params.device = &buf;
|
||||
params.filePath = m_path.toQString();
|
||||
params.mode = MscIoMode::Zip;
|
||||
|
||||
|
@ -452,6 +457,11 @@ mu::Ret NotationProject::writeToDevice(io::Device* device)
|
|||
msczWriter.open();
|
||||
|
||||
Ret ret = writeProject(msczWriter, false);
|
||||
if (ret) {
|
||||
ByteArray ba = buf.readAll();
|
||||
device->write(ba.toQByteArrayNoCopy());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "io/bytearray.h"
|
||||
|
||||
using namespace mu::project;
|
||||
using namespace mu::audio;
|
||||
using namespace mu::engraving;
|
||||
|
@ -171,8 +173,8 @@ mu::ValNt<bool> ProjectAudioSettings::needSave() const
|
|||
|
||||
mu::Ret ProjectAudioSettings::read(const engraving::MscReader& reader)
|
||||
{
|
||||
QByteArray json = reader.readAudioSettingsJsonFile();
|
||||
QJsonObject rootObj = QJsonDocument::fromJson(json).object();
|
||||
io::ByteArray json = reader.readAudioSettingsJsonFile();
|
||||
QJsonObject rootObj = QJsonDocument::fromJson(json.toQByteArrayNoCopy()).object();
|
||||
|
||||
QJsonObject masterObj = rootObj.value("master").toObject();
|
||||
m_masterOutputParams = outputParamsFromJson(masterObj);
|
||||
|
@ -212,7 +214,7 @@ mu::Ret ProjectAudioSettings::write(engraving::MscWriter& writer)
|
|||
rootObj["tracks"] = tracksArray;
|
||||
|
||||
QByteArray json = QJsonDocument(rootObj).toJson();
|
||||
writer.writeAudioSettingsJsonFile(json);
|
||||
writer.writeAudioSettingsJsonFile(io::ByteArray::fromQByteArrayNoCopy(json));
|
||||
|
||||
setNeedSave(false);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "io/bytearray.h"
|
||||
|
||||
using namespace mu;
|
||||
using namespace mu::project;
|
||||
using namespace mu::engraving;
|
||||
|
@ -69,8 +71,8 @@ static QString viewModeToString(ViewMode m)
|
|||
|
||||
Ret ProjectViewSettings::read(const MscReader& reader)
|
||||
{
|
||||
QByteArray json = reader.readViewSettingsJsonFile();
|
||||
QJsonObject rootObj = QJsonDocument::fromJson(json).object();
|
||||
io::ByteArray json = reader.readViewSettingsJsonFile();
|
||||
QJsonObject rootObj = QJsonDocument::fromJson(json.toQByteArrayNoCopy()).object();
|
||||
QJsonObject notationObj = rootObj.value("notation").toObject();
|
||||
|
||||
m_viewMode = viewModeFromString(notationObj.value("viewMode").toString());
|
||||
|
@ -87,7 +89,7 @@ Ret ProjectViewSettings::write(MscWriter& writer)
|
|||
rootObj["notation"] = notationObj;
|
||||
|
||||
QByteArray json = QJsonDocument(rootObj).toJson();
|
||||
writer.writeViewSettingsJsonFile(json);
|
||||
writer.writeViewSettingsJsonFile(io::ByteArray::fromQByteArrayNoCopy(json));
|
||||
|
||||
setNeedSave(false);
|
||||
|
||||
|
|
Loading…
Reference in a new issue