lmms
Cross-platform music production software
Loading...
Searching...
No Matches
DataFile.h
Go to the documentation of this file.
1/*
2 * DataFile.h - class for reading and writing LMMS data files
3 *
4 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 * Copyright (c) 2012-2013 Paul Giblock <p/at/pgiblock.net>
6 *
7 * This file is part of LMMS - https://lmms.io
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program (see COPYING); if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
23 *
24 */
25
26#ifndef LMMS_DATA_FILE_H
27#define LMMS_DATA_FILE_H
28
29#include <map>
30#include <QDomDocument>
31#include <vector>
32
33#include "lmms_export.h"
34
35class QTextStream;
36
37namespace lmms
38{
39
40class ProjectVersion;
41
42
43class LMMS_EXPORT DataFile : public QDomDocument
44{
45
46 using UpgradeMethod = void(DataFile::*)();
47
48public:
49 enum class Type
50 {
51 Unknown,
52 SongProject,
53 SongProjectTemplate,
54 InstrumentTrackSettings,
55 DragNDropData,
56 ClipboardData,
57 JournalData,
58 EffectSettings,
60 } ;
61
62 DataFile( const QString& fileName );
63 DataFile( const QByteArray& data );
64 DataFile( Type type );
65
66 virtual ~DataFile() = default;
67
69 bool validate( QString extension );
70
71 QString nameWithExtension( const QString& fn ) const;
72
73 void write( QTextStream& strm );
74 bool writeFile(const QString& fn, bool withResources = false);
75
78 bool copyResources(const QString& resourcesDir);
79
89 bool hasLocalPlugins(QDomElement parent = QDomElement(), bool firstCall = true) const;
90
91 QDomElement& content()
92 {
93 return m_content;
94 }
95
96 QDomElement& head()
97 {
98 return m_head;
99 }
100
101 Type type() const
102 {
103 return m_type;
104 }
105
106 unsigned int legacyFileVersion();
107
108private:
109 static Type type( const QString& typeName );
110 static QString typeName( Type type );
111
112 void cleanMetaNodes( QDomElement de );
113
114 void mapSrcAttributeInElementsWithResources(const QMap<QString, QString>& map);
115
116 // helper upgrade routines
117 void upgrade_0_2_1_20070501();
118 void upgrade_0_2_1_20070508();
119 void upgrade_0_3_0_rc2();
120 void upgrade_0_3_0();
121 void upgrade_0_4_0_20080104();
122 void upgrade_0_4_0_20080118();
123 void upgrade_0_4_0_20080129();
124 void upgrade_0_4_0_20080409();
125 void upgrade_0_4_0_20080607();
126 void upgrade_0_4_0_20080622();
127 void upgrade_0_4_0_beta1();
128 void upgrade_0_4_0_rc2();
129 void upgrade_1_0_99();
130 void upgrade_1_1_0();
131 void upgrade_1_1_91();
132 void upgrade_1_2_0_rc3();
133 void upgrade_1_3_0();
134 void upgrade_noHiddenClipNames();
135 void upgrade_automationNodes();
136
141 void upgrade_extendedNoteRange();
142
147 void upgrade_defaultTripleOscillatorHQ();
148
149 void upgrade_mixerRename();
150 void upgrade_bbTcoRename();
151 void upgrade_sampleAndHold();
152
154 void upgrade_midiCCIndexing();
155
156 void upgrade_loopsRename();
157 void upgrade_noteTypes();
158 void upgrade_fixCMTDelays();
159 void upgrade_fixBassLoopsTypo();
160 void findProblematicLadspaPlugins();
161 void upgrade_noHiddenAutomationTracks();
162
163 // List of all upgrade methods
164 static const std::vector<UpgradeMethod> UPGRADE_METHODS;
165 // List of ProjectVersions for the legacyFileVersion method
166 static const std::vector<ProjectVersion> UPGRADE_VERSIONS;
167
168 // Map with DOM elements that access resources (for making bundles)
169 using ResourcesMap = std::map<QString, std::vector<QString>>;
171
172 void upgrade();
173
174 void loadData( const QByteArray & _data, const QString & _sourceFile );
175
176 QString m_fileName;
177 QDomElement m_content;
178 QDomElement m_head;
180 unsigned int m_fileVersion;
181} ;
182
183
184} // namespace lmms
185
186#endif // LMMS_DATA_FILE_H
Definition DataFile.h:44
Type m_type
Definition DataFile.h:179
bool copyResources(const QString &resourcesDir)
Copies resources to resourcesDir and changes the DataFile to use local paths to them.
Definition DataFile.cpp:446
QDomElement & head()
Definition DataFile.h:96
void upgrade()
Definition DataFile.cpp:2061
QString nameWithExtension(const QString &fn) const
Definition DataFile.cpp:262
QString m_fileName
The origin file name or "" if this DataFile didn't originate from a file.
Definition DataFile.h:176
void write(QTextStream &strm)
Definition DataFile.cpp:301
bool hasLocalPlugins(QDomElement parent=QDomElement(), bool firstCall=true) const
Checks whether the XML tree of a DataFile has (potentially unsafe) local paths.
Definition DataFile.cpp:530
void loadData(const QByteArray &_data, const QString &_sourceFile)
Definition DataFile.cpp:2102
Type type() const
Definition DataFile.h:101
static const std::vector< ProjectVersion > UPGRADE_VERSIONS
Definition DataFile.h:166
QDomElement m_head
Definition DataFile.h:178
QDomElement & content()
Definition DataFile.h:91
static const ResourcesMap ELEMENTS_WITH_RESOURCES
Definition DataFile.h:170
unsigned int m_fileVersion
Definition DataFile.h:180
DataFile(const QString &fileName)
Definition DataFile.cpp:156
std::map< QString, std::vector< QString > > ResourcesMap
Definition DataFile.h:169
static const std::vector< UpgradeMethod > UPGRADE_METHODS
Definition DataFile.h:164
QDomElement m_content
Definition DataFile.h:177
virtual ~DataFile()=default
Type
Definition DataFile.h:50
void(DataFile::*)() UpgradeMethod
Definition DataFile.h:46
bool validate(QString extension)
Performs basic validation, compared to file extension.
Definition DataFile.cpp:200
bool writeFile(const QString &fn, bool withResources=false)
Definition DataFile.cpp:315
Definition MidiClip.h:46
Version number parsing and comparison.
Definition ProjectVersion.h:43
Definition RemotePluginBase.cpp:34