annotate base/XmlExportable.cpp @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents e4f31f506116
children
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@3 2
Chris@3 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@3 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@3 14 */
Chris@3 15
Chris@3 16 #include "XmlExportable.h"
Chris@4 17 #include <map>
Chris@85 18 #include <QMutex>
Chris@85 19 #include <QMutexLocker>
Chris@123 20 #include <QTextStream>
Chris@123 21
Chris@318 22 #include <iostream>
Chris@318 23
Chris@314 24 QString
Chris@314 25 XmlExportable::toXmlString(QString indent,
Chris@314 26 QString extraAttributes) const
Chris@123 27 {
Chris@690 28 // SVDEBUG << "XmlExportable::toXmlString" << endl;
Chris@318 29
Chris@314 30 QString s;
Chris@314 31
Chris@314 32 {
Chris@314 33 QTextStream out(&s);
Chris@314 34 toXml(out, indent, extraAttributes);
Chris@314 35 }
Chris@314 36
Chris@314 37 return s;
Chris@123 38 }
Chris@3 39
Chris@3 40 QString
Chris@3 41 XmlExportable::encodeEntities(QString s)
Chris@3 42 {
Chris@3 43 s
Chris@1429 44 .replace("&", "&amp;")
Chris@1429 45 .replace("<", "&lt;")
Chris@1429 46 .replace(">", "&gt;")
Chris@1429 47 .replace("\"", "&quot;")
Chris@1429 48 .replace("'", "&apos;");
Chris@3 49
Chris@3 50 return s;
Chris@3 51 }
Chris@3 52
Chris@3 53 QString
Chris@387 54 XmlExportable::encodeColour(int ri, int gi, int bi)
Chris@3 55 {
Chris@3 56 QString r, g, b;
Chris@3 57
Chris@387 58 r.setNum(ri, 16);
Chris@387 59 if (ri < 16) r = "0" + r;
Chris@3 60
Chris@387 61 g.setNum(gi, 16);
Chris@387 62 if (gi < 16) g = "0" + g;
Chris@3 63
Chris@387 64 b.setNum(bi, 16);
Chris@387 65 if (bi < 16) b = "0" + b;
Chris@3 66
Chris@3 67 return "#" + r + g + b;
Chris@3 68 }
Chris@3 69
Chris@4 70 int
Chris@1677 71 XmlExportable::getExportId() const
Chris@4 72 {
Chris@1677 73 if (m_exportId == -1) {
Chris@1677 74 static QMutex mutex;
Chris@1683 75 static int nextId = 0;
Chris@1677 76 QMutexLocker locker(&mutex);
Chris@1677 77 if (m_exportId == -1) {
Chris@1683 78 m_exportId = nextId;
Chris@1683 79 ++nextId;
Chris@1677 80 }
Chris@4 81 }
Chris@1677 82 return m_exportId;
Chris@4 83 }
Chris@4 84
Chris@4 85