hydrogen 1.2.3
SoundLibraryInfo.cpp
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
24#include <core/Helpers/Xml.h>
25#include <core/License.h>
26
27namespace H2Core
28{
29
30
32{
33 //default constructor
34}
35
36bool SoundLibraryInfo::load( const QString& sPath ) {
37 setPath( sPath );
38
39 XMLDoc doc;
40 if ( ! doc.read( sPath, nullptr, true ) ) {
41 ERRORLOG( QString( "Unable to load SoundLibraryInfo from [%1]" )
42 .arg( sPath ) );
43 return false;
44 }
45
46 bool bLoadingWorked = false;
47
48 XMLNode rootNode = doc.firstChildElement( "drumkit_pattern" );
49 if ( ! rootNode.isNull() )
50 {
51 setType( "pattern" );
52 setAuthor( rootNode.read_string( "author", "undefined author", false, false ) );
53 setLicense( H2Core::License( rootNode.read_string( "license", "", false, false ) ) );
54
55 XMLNode patternNode = rootNode.firstChildElement( "pattern" );
56 // Try legacy format fist.
57 setName( patternNode.read_string( "pattern_name", "", true, true ) );
58 if ( getName().isEmpty() ) {
59 // Try current format.
60 setName( patternNode.read_string( "name", "", false, false ) );
61 }
62 setInfo( patternNode.read_string( "info", "No information available.", false, true, true ) );
63 setCategory( patternNode.read_string( "category", "", false, true ) );
64
65 QString sDrumkitName = rootNode.read_string( "drumkit_name", "", false, false );
66 if ( sDrumkitName.isEmpty() ) {
67 sDrumkitName = rootNode.read_string( "pattern_for_drumkit", "" );
68 }
69 setDrumkitName( sDrumkitName );
70
71 bLoadingWorked = true;
72 }
73
74
75 //New drumkits
76 rootNode = doc.firstChildElement( "drumkit_info" );
77 if ( ! rootNode.isNull() )
78 {
79 setType( "drumkit" );
80 setAuthor( rootNode.read_string( "author", "undefined author", false, false ) );
81 setLicense( H2Core::License( rootNode.read_string( "license", "", false, false ) ) );
82 setName( rootNode.read_string( "name", "", false, false ) );
83 setInfo( rootNode.read_string( "info", "No information available.", false, false ) );
84 setImage( rootNode.read_string( "image", "", false, false ) );
85 setImageLicense( H2Core::License( rootNode.read_string( "imageLicense", "", false, false ) ) );
86
87 bLoadingWorked = true;
88 }
89
90 //Songs
91 rootNode = doc.firstChildElement( "song" );
92 if ( ! rootNode.isNull() )
93 {
94 setType( "song" );
95 setAuthor( rootNode.read_string( "author", "undefined author", false, false ) );
96 setLicense( H2Core::License( rootNode.read_string( "license", "", false, false ) ) );
97 setName( rootNode.read_string( "name", "", false, false ) );
98 setInfo( rootNode.read_string( "info", "No information available.", false, false ) );
99
100 bLoadingWorked = true;
101 }
102
103 if ( ! bLoadingWorked ) {
104 ERRORLOG( QString( "[%1] could not be loaded as pattern, song, or drumkit" )
105 .arg( sPath ) );
106 return false;
107 }
108
109 return true;
110}
111
113{
114 //default deconstructor
115}
116
117QString SoundLibraryInfo::toQString( const QString& sPrefix, bool bShort ) const {
118 QString s = Base::sPrintIndention;
119 QString sOutput;
120 if ( ! bShort ) {
121 sOutput = QString( "%1[SoundLibraryInfo]\n" ).arg( sPrefix )
122 .append( QString( "%1%2m_sName: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sName ) )
123 .append( QString( "%1%2m_sURL: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sURL ) )
124 .append( QString( "%1%2m_sInfo: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sInfo ) )
125 .append( QString( "%1%2m_sAuthor: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sAuthor ) )
126 .append( QString( "%1%2m_sCategory: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sCategory ) )
127 .append( QString( "%1%2m_sType: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sType ) )
128 .append( QString( "%1%2m_license:\n%3" ).arg( sPrefix ).arg( s )
129 .arg( m_license.toQString( sPrefix + s + s, bShort ) ) )
130 .append( QString( "%1%2m_sImage: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sImage ) )
131 .append( QString( "%1%2m_imageLicense:\n%3" ).arg( sPrefix ).arg( s )
132 .arg( m_imageLicense.toQString( sPrefix + s + s, bShort ) ) )
133 .append( QString( "%1%2m_sPath: %3\n" ).arg( sPrefix ).arg( s ).arg( m_sPath ) );
134 }
135 else {
136
137 sOutput = QString( "[SoundLibraryInfo]" )
138 .append( QString( " m_sName: %1" ).arg( m_sName ) )
139 .append( QString( ", m_sURL: %1" ).arg( m_sURL ) )
140 .append( QString( ", m_sInfo: %1" ).arg( m_sInfo ) )
141 .append( QString( ", m_sAuthor: %1" ).arg( m_sAuthor ) )
142 .append( QString( ", m_sCategory: %1" ).arg( m_sCategory ) )
143 .append( QString( ", m_sType: %1" ).arg( m_sType ) )
144 .append( QString( ", m_license: %1" )
145 .arg( m_license.toQString( "", bShort ) ) )
146 .append( QString( ", m_sImage: %1" ).arg( m_sImage ) )
147 .append( QString( ", m_imageLicense: %1" )
148 .arg( m_imageLicense.toQString( "", bShort ) ) )
149 .append( QString( ", m_sPath: %1" ).arg( m_sPath ) );
150 }
151
152 return sOutput;
153}
154}; //namespace H2Core
155
#define ERRORLOG(x)
Definition Object.h:239
static QString sPrintIndention
String used to format the debugging string output of some core classes.
Definition Object.h:127
Wrapper class to help Hydrogen deal with the license information specified in a drumkit.
Definition License.h:48
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
Definition License.cpp:151
void setDrumkitName(const QString &sDrumkitName)
bool load(const QString &sPath)
Reads the content found in sPath.
void setAuthor(const QString &author)
void setCategory(const QString &category)
void setInfo(const QString &info)
void setImage(const QString &image)
void setLicense(const H2Core::License &license)
void setName(const QString &name)
void setImageLicense(const H2Core::License &imageLicense)
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
void setType(const QString &type)
void setPath(const QString &path)
XMLDoc is a subclass of QDomDocument with read and write methods.
Definition Xml.h:182
bool read(const QString &filepath, const QString &schemapath=nullptr, bool bSilent=false)
read the content of an xml file
Definition Xml.cpp:296
XMLNode is a subclass of QDomNode with read and write values methods.
Definition Xml.h:39
QString read_string(const QString &node, const QString &default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
reads a string stored into a child node
Definition Xml.cpp:95