DataFile.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. #ifndef DATA_FILE_H
  26. #define DATA_FILE_H
  27. #include <map>
  28. #include <QDomDocument>
  29. #include "lmms_export.h"
  30. #include "MemoryManager.h"
  31. #include "ProjectVersion.h"
  32. class QTextStream;
  33. class LMMS_EXPORT DataFile : public QDomDocument
  34. {
  35. MM_OPERATORS
  36. using UpgradeMethod = void(DataFile::*)();
  37. public:
  38. enum Types
  39. {
  40. UnknownType,
  41. SongProject,
  42. SongProjectTemplate,
  43. InstrumentTrackSettings,
  44. DragNDropData,
  45. ClipboardData,
  46. JournalData,
  47. EffectSettings,
  48. MidiClip,
  49. TypeCount
  50. } ;
  51. typedef Types Type;
  52. DataFile( const QString& fileName );
  53. DataFile( const QByteArray& data );
  54. DataFile( Type type );
  55. virtual ~DataFile();
  56. ///
  57. /// \brief validate
  58. /// performs basic validation, compared to file extension.
  59. ///
  60. bool validate( QString extension );
  61. QString nameWithExtension( const QString& fn ) const;
  62. void write( QTextStream& strm );
  63. bool writeFile(const QString& fn, bool withResources = false);
  64. bool copyResources(const QString& resourcesDir); //!< Copies resources to the resourcesDir and changes the DataFile to use local paths to them
  65. bool hasLocalPlugins(QDomElement parent = QDomElement(), bool firstCall = true) const;
  66. QDomElement& content()
  67. {
  68. return m_content;
  69. }
  70. QDomElement& head()
  71. {
  72. return m_head;
  73. }
  74. Type type() const
  75. {
  76. return m_type;
  77. }
  78. unsigned int legacyFileVersion();
  79. private:
  80. static Type type( const QString& typeName );
  81. static QString typeName( Type type );
  82. void cleanMetaNodes( QDomElement de );
  83. // helper upgrade routines
  84. void upgrade_0_2_1_20070501();
  85. void upgrade_0_2_1_20070508();
  86. void upgrade_0_3_0_rc2();
  87. void upgrade_0_3_0();
  88. void upgrade_0_4_0_20080104();
  89. void upgrade_0_4_0_20080118();
  90. void upgrade_0_4_0_20080129();
  91. void upgrade_0_4_0_20080409();
  92. void upgrade_0_4_0_20080607();
  93. void upgrade_0_4_0_20080622();
  94. void upgrade_0_4_0_beta1();
  95. void upgrade_0_4_0_rc2();
  96. void upgrade_1_0_99();
  97. void upgrade_1_1_0();
  98. void upgrade_1_1_91();
  99. void upgrade_1_2_0_rc3();
  100. void upgrade_1_3_0();
  101. void upgrade_noHiddenClipNames();
  102. void upgrade_automationNodes();
  103. void upgrade_extendedNoteRange();
  104. void upgrade_defaultTripleOscillatorHQ();
  105. void upgrade_mixerRename();
  106. void upgrade_bbTcoRename();
  107. // List of all upgrade methods
  108. static const std::vector<UpgradeMethod> UPGRADE_METHODS;
  109. // List of ProjectVersions for the legacyFileVersion method
  110. static const std::vector<ProjectVersion> UPGRADE_VERSIONS;
  111. // Map with DOM elements that access resources (for making bundles)
  112. typedef std::map<QString, std::vector<QString>> ResourcesMap;
  113. static const ResourcesMap ELEMENTS_WITH_RESOURCES;
  114. void upgrade();
  115. void loadData( const QByteArray & _data, const QString & _sourceFile );
  116. struct LMMS_EXPORT typeDescStruct
  117. {
  118. Type m_type;
  119. QString m_name;
  120. } ;
  121. static typeDescStruct s_types[TypeCount];
  122. QString m_fileName; //!< The origin file name or "" if this DataFile didn't originate from a file
  123. QDomElement m_content;
  124. QDomElement m_head;
  125. Type m_type;
  126. unsigned int m_fileVersion;
  127. } ;
  128. #endif