1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Rosegarden 5 A sequencer and musical notation editor. 6 Copyright 2000-2021 the Rosegarden development team. 7 See the AUTHORS file for more details. 8 9 This program is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License as 11 published by the Free Software Foundation; either version 2 of the 12 License, or (at your option) any later version. See the file 13 COPYING included with this distribution for more information. 14 */ 15 16 17 // Class to hold extraneous bits of configuration which 18 // don't sit inside the Composition itself - sequencer 19 // and other general stuff that we want to keep separate. 20 // 21 // 22 23 #include <string> 24 #include <algorithm> 25 26 #include "Configuration.h" 27 28 #include <sstream> 29 30 31 namespace Rosegarden 32 { 33 Configuration(const Configuration & conf)34Configuration::Configuration(const Configuration &conf) : 35 PropertyMap(), 36 XmlExportable() 37 { 38 clear(); 39 40 // Copy everything 41 // 42 for (const_iterator i = conf.begin(); i != conf.end(); ++i) 43 insert(PropertyPair(i->first, i->second->clone())); 44 } 45 ~Configuration()46Configuration::~Configuration() 47 { 48 clear(); 49 } 50 51 52 std::vector<std::string> getPropertyNames()53Configuration::getPropertyNames() 54 { 55 std::vector<std::string> v; 56 for (const_iterator i = begin(); i != end(); ++i) { 57 v.push_back(i->first.getName()); 58 } 59 std::sort(v.begin(), v.end()); 60 return v; 61 } 62 63 64 bool has(const PropertyName & name) const65Configuration::has(const PropertyName &name) const 66 { 67 const_iterator i = find(name); 68 return (i != end()); 69 } 70 71 72 std::string toXmlString() const73Configuration::toXmlString() const 74 { 75 using std::endl; 76 std::stringstream config; 77 78 // This simple implementation just assumes everything's a string. 79 // Override it if you want something fancier (or reimplement it to 80 // support the whole gamut -- the reader in rosexmlhandler.cpp 81 // already can) 82 83 for (const_iterator i = begin(); i != end(); ++i) { 84 config << "<property name=\"" 85 << encode(i->first.getName()) << "\" value=\"" 86 << encode(get<String>(i->first)) << "\"/>" << endl; 87 } 88 89 config << endl; 90 91 return config.str(); 92 } 93 94 Configuration& operator =(const Configuration & conf)95Configuration::operator=(const Configuration &conf) 96 { 97 clear(); 98 99 // Copy everything 100 // 101 for (const_iterator i = conf.begin(); i != conf.end(); ++i) 102 insert(PropertyPair(i->first, i->second->clone())); 103 104 return (*this); 105 } 106 107 108 109 namespace CompositionMetadataKeys 110 { 111 const PropertyName Copyright = "copyright"; 112 const PropertyName Composer = "composer"; 113 const PropertyName Title = "title"; 114 const PropertyName Subtitle = "subtitle"; 115 const PropertyName Arranger = "arranger"; 116 // The following are recognized only by LilyPond output 117 const PropertyName Dedication = "dedication"; 118 const PropertyName Subsubtitle = "subsubtitle"; 119 const PropertyName Poet = "poet"; 120 const PropertyName Meter = "meter"; 121 const PropertyName Opus = "opus"; 122 const PropertyName Instrument = "instrument"; 123 const PropertyName Piece = "piece"; 124 const PropertyName Tagline = "tagline"; 125 126 // The tab order of the edit fields in HeadersConfigurationPage 127 // is defined by the creation order of the edit fields. 128 // The edit fields are created in the order of the keys in getFixedKeys(). getFixedKeys()129 std::vector<PropertyName> getFixedKeys() { 130 std::vector<PropertyName> keys; 131 keys.push_back(Dedication); 132 keys.push_back(Title); 133 keys.push_back(Subtitle); 134 keys.push_back(Subsubtitle); 135 keys.push_back(Poet); 136 keys.push_back(Instrument); 137 keys.push_back(Composer); 138 keys.push_back(Meter); 139 keys.push_back(Arranger); 140 keys.push_back(Piece); 141 keys.push_back(Opus); 142 keys.push_back(Copyright); 143 keys.push_back(Tagline); 144 145 return keys; 146 } 147 } 148 149 150 // Keep these in lower case 151 const PropertyName DocumentConfiguration::SequencerOptions = "sequenceroptions"; 152 const PropertyName DocumentConfiguration::ZoomLevel = "zoomlevel"; 153 const PropertyName DocumentConfiguration::TransportMode = "transportmode"; 154 155 DocumentConfiguration()156DocumentConfiguration::DocumentConfiguration() 157 { 158 set<Int>(ZoomLevel, 0); 159 set<String>(TransportMode, ""); // apparently generates an exception if not initialized 160 } 161 DocumentConfiguration(const DocumentConfiguration & conf)162DocumentConfiguration::DocumentConfiguration(const DocumentConfiguration &conf): 163 Configuration() 164 { 165 for (const_iterator i = conf.begin(); i != conf.end(); ++i) 166 insert(PropertyPair(i->first, i->second->clone())); 167 } 168 ~DocumentConfiguration()169DocumentConfiguration::~DocumentConfiguration() 170 { 171 clear(); 172 } 173 174 175 DocumentConfiguration& operator =(const DocumentConfiguration & conf)176DocumentConfiguration::operator=(const DocumentConfiguration &conf) 177 { 178 clear(); 179 180 for (const_iterator i = conf.begin(); i != conf.end(); ++i) 181 insert(PropertyPair(i->first, i->second->clone())); 182 183 return *this; 184 } 185 186 187 // Convert to XML string for export 188 // 189 std::string toXmlString() const190DocumentConfiguration::toXmlString() const 191 { 192 using std::endl; 193 194 std::stringstream config; 195 196 config << endl << "<configuration>" << endl; 197 198 config << " <" << ZoomLevel << " type=\"Int\">" << get<Int>(ZoomLevel) 199 << "</" << ZoomLevel << ">\n"; 200 201 config << " <" << TransportMode << " type=\"String\">" << get<String>(TransportMode) 202 << "</" << TransportMode << ">\n"; 203 204 config << "</configuration>" << endl; 205 206 config << endl; 207 208 return config.str(); 209 } 210 211 } 212 213 214