On Thu, 24, Jul, 2003 at 05:17:35PM +0100, Mark Hymers spoke thus.. > Two options spring to mind:
Well, I decided that I'm more likely to provoke discussion with a patch
on the table.
Attached is a patch which deals with the loading/saving of the
colourindexes and segment ColourMap.
The ci's are saved as an attribute to each segment (if a segment doesn't
have an ci, it's taken to be 0; also any ci's which are 0 aren't written
[there's no need]).
The ColourMap exists in a new top level section called appearance. I'm
willing to change this if asked to but at least there's a concrete
proposal now.
<appearance>
<colourmap name="segmentmap">
<colourpair id="0" name="" red="197" green="211" blue="125"/>
<colourpair id="1" name="Piano" red="255" green="198" blue="198"/>
<colourpair id="2" name="Harpsichord" red="219" green="171" blue="171"/>
<colourpair id="3" name="Organ" red="183" green="143" blue="143"/>
<colourpair id="4" name="Acoustic Guitar" red="255" green="248"
blue="206"/>
<colourpair id="5" name="Electric Guitar" red="255" green="243"
blue="182"/>
<colourpair id="6" name="Bass Guitar" red="255" green="232" blue="149"/>
<colourpair id="7" name="Violin" red="219" green="255" blue="214"/>
ETC ETC ETC ETC
</colourmap>
</appearance>
This gives us the flexibility to add more maps later in the same
section.
The second attachment is an updated autoload.rg file. It's exactly the
same as the existing CVS one but with an appearance section which
contains 26 pre-defined colours ready for use.
Any comments?
Mark
--
Mark Hymers <markh at linuxfromscratch dot org>
"I got off at Durham... and fell in love with it instantly. Why, it's
wonderful - a perfect little city. If you have never been to Durham, go
there at once. Take my car. It's wonderful."
Notes from a Small Island, Bill Bryson
Index: base/Colour.C
===================================================================
RCS file: /cvsroot/rosegarden/base/Colour.C,v
retrieving revision 1.3
diff -u -p -r1.3 Colour.C
--- base/Colour.C 18 May 2003 20:57:29 -0000 1.3
+++ base/Colour.C 27 Jul 2003 22:42:06 -0000
@@ -25,6 +25,13 @@
#include "Colour.h"
+#if (__GNUC__ < 3)
+#include <strstream>
+#define stringstream strstream
+#else
+#include <sstream>
+#endif
+
namespace Rosegarden
{
@@ -118,6 +125,31 @@ Colour::getContrastingColour() const
{
Colour ret(255-m_r, 255-m_g, 255-m_b);
return ret;
+}
+
+std::string
+Colour::toXmlString() const
+{
+ std::stringstream output;
+
+ output << "<colour red=\"" << m_r
+ << "\" green=\"" << m_g
+ << "\" blue=\"" << m_b
+ << "\"/>" << std::endl;
+
+ return output.str();
+}
+
+std::string
+Colour::dataToXmlString() const
+{
+ std::stringstream output;
+ output << "red=\"" << m_r
+ << "\" green=\"" << m_g
+ << "\" blue=\"" << m_b
+ << "\"";
+
+ return output.str();
}
// Generic Colour routines:
Index: base/Colour.h
===================================================================
RCS file: /cvsroot/rosegarden/base/Colour.h,v
retrieving revision 1.2
diff -u -p -r1.2 Colour.h
--- base/Colour.h 18 May 2003 17:13:06 -0000 1.2
+++ base/Colour.h 27 Jul 2003 22:42:06 -0000
@@ -26,6 +26,8 @@
#ifndef _BASE_COLOUR_H_
#define _BASE_COLOUR_H_
+#include <string>
+
namespace Rosegarden
{
@@ -103,6 +105,10 @@ public:
* any background colour
*/
Colour getContrastingColour() const;
+
+ std::string toXmlString() const;
+
+ std::string dataToXmlString() const;
private:
unsigned int m_r, m_g, m_b;
Index: base/ColourMap.C
===================================================================
RCS file: /cvsroot/rosegarden/base/ColourMap.C,v
retrieving revision 1.4
diff -u -p -r1.4 ColourMap.C
--- base/ColourMap.C 22 Jul 2003 07:40:14 -0000 1.4
+++ base/ColourMap.C 27 Jul 2003 22:42:06 -0000
@@ -24,7 +24,16 @@
*/
#include <string>
+
+#if (__GNUC__ < 3)
+#include <strstream>
+#define stringstream strstream
+#else
+#include <sstream>
+#endif
+
#include "ColourMap.h"
+#include "XmlExportable.h"
namespace Rosegarden
{
@@ -110,6 +119,15 @@ ColourMap::addItem(const Colour colour,
return true;
}
+// WARNING: This version of addItem is only for use by rosexmlhandler.cpp
+bool
+ColourMap::addItem(const Colour colour, const std::string name, const unsigned int id)
+{
+ m_map[id] = make_pair(colour, name);
+
+ return true;
+}
+
bool
ColourMap::modifyNameByIndex(const unsigned int item_num, const std::string name)
{
@@ -210,6 +228,27 @@ int
ColourMap::size() const
{
return m_map.size();
+}
+
+std::string
+ColourMap::toXmlString(std::string name) const
+{
+ std::stringstream output;
+
+ output << " <colourmap name=\"" << XmlExportable::encode(name)
+ << "\">" << std::endl;
+
+ for (RCMap::const_iterator pos = m_map.begin(); pos != m_map.end(); ++pos)
+ {
+ output << " " << " <colourpair id=\"" << pos->first
+ << "\" name=\"" << XmlExportable::encode(pos->second.second)
+ << "\" " << pos->second.first.dataToXmlString() << "/>" << std::endl;
+ }
+
+ output << " </colourmap>" << std::endl;
+
+ return output.str();
+
}
}
Index: base/ColourMap.h
===================================================================
RCS file: /cvsroot/rosegarden/base/ColourMap.h,v
retrieving revision 1.3
diff -u -p -r1.3 ColourMap.h
--- base/ColourMap.h 22 Jul 2003 07:40:15 -0000 1.3
+++ base/ColourMap.h 27 Jul 2003 22:42:06 -0000
@@ -89,6 +89,12 @@ public:
bool addItem(Colour colour, std::string name);
/**
+ * This routine adds a Colour using the given id. ONLY FOR USE IN
+ * rosexmlhandler.cpp
+ */
+ bool addItem(Colour colour, std::string name, unsigned int id);
+
+ /**
* If the item with item_num exists and isn't the default, this
* routine modifies the string associated with it
*/
@@ -116,6 +122,8 @@ public:
* This returns a const iterator pointing to m_map.end()
*/
RCMap::const_iterator end();
+
+ std::string toXmlString(std::string name) const;
ColourMap& operator=(const ColourMap& input);
Index: base/test/colour.C
===================================================================
RCS file: /cvsroot/rosegarden/base/test/colour.C,v
retrieving revision 1.3
diff -u -p -r1.3 colour.C
--- base/test/colour.C 22 Jul 2003 14:33:36 -0000 1.3
+++ base/test/colour.C 27 Jul 2003 22:42:09 -0000
@@ -204,6 +204,15 @@ int main()
blah = getCombinationColour(blah, blah2);
printRC(&blah);
+ // Test the XML output
+ cout << "\nTEST: XML Output\n\n";
+ cout << "For a single colour:\n";
+ cout << blah.toXmlString();
+
+ cout << "For a colourmap:\n";
+ cout << map2->toXmlString(std::string("segmentmap"));
+
+
delete map;
delete map2;
delete red;
Index: base/test/colour.output
===================================================================
RCS file: /cvsroot/rosegarden/base/test/colour.output,v
retrieving revision 1.2
diff -u -p -r1.2 colour.output
--- base/test/colour.output 22 Jul 2003 14:33:36 -0000 1.2
+++ base/test/colour.output 27 Jul 2003 22:42:09 -0000
@@ -61,3 +61,16 @@ red: 210 green: 0 blue: 100
red: 100 green: 101 blue: 102
Combination colour:
red: 155 green: 50 blue: 101
+
+TEST: XML Output
+
+For a single colour:
+<colour red="155" green="50" blue="101"/>
+For a colourmap:
+ <colourmap name="segmentmap">
+ <colourpair id="0" name="" red="210" green="0" blue="100"/>
+ <colourpair id="1" name="TEST1" red="100" green="101" blue="102"/>
+ <colourpair id="2" name="TEST2" red="101" green="102" blue="103"/>
+ <colourpair id="3" name="YES" red="233" green="233" blue="233"/>
+ <colourpair id="4" name="NEW" red="211" green="212" blue="213"/>
+ </colourmap>
Index: gui/rosegardenguidoc.cpp
===================================================================
RCS file: /cvsroot/rosegarden/gui/rosegardenguidoc.cpp,v
retrieving revision 1.334
diff -u -p -r1.334 rosegardenguidoc.cpp
--- gui/rosegardenguidoc.cpp 22 Jul 2003 07:40:16 -0000 1.334
+++ gui/rosegardenguidoc.cpp 27 Jul 2003 22:42:16 -0000
@@ -796,6 +796,11 @@ bool RosegardenGUIDoc::saveDocument(cons
<< "\" rtdelayusec=\"" << segment->getRealTimeDelay().usec;
}
+ if (segment->getColourIndex() != 0)
+ {
+ outStream << "\" colourindex=\"" << segment->getColourIndex();
+ }
+
const Rosegarden::timeT *endMarker = segment->getRawEndMarkerTime();
if (endMarker) {
outStream << "\" endmarker=\"" << *endMarker;
@@ -891,6 +896,12 @@ bool RosegardenGUIDoc::saveDocument(cons
//
outStream << QString(strtoqstr(m_studio.toXmlString())) << endl << endl;
+
+ // Send out the appearance data
+ outStream << "<appearance>" << endl;
+ outStream << getComposition().getSegmentColourMap().toXmlString("segmentmap");
+ outStream << "</appearance>" << endl << endl << endl;
+
// close the top-level XML tag
//
outStream << "</rosegarden-data>\n";
Index: gui/rosexmlhandler.cpp
===================================================================
RCS file: /cvsroot/rosegarden/gui/rosexmlhandler.cpp,v
retrieving revision 1.187
diff -u -p -r1.187 rosexmlhandler.cpp
--- gui/rosexmlhandler.cpp 3 Jul 2003 16:45:45 -0000 1.187
+++ gui/rosexmlhandler.cpp 27 Jul 2003 22:42:17 -0000
@@ -636,6 +636,7 @@ RoseXmlHandler::startElement(const QStri
m_section = InSegment;
int track = -1, startTime = 0;
+ unsigned int colourindex = 0;
QString trackNbStr = atts.value("track");
if (trackNbStr) {
track = trackNbStr.toInt();
@@ -711,6 +712,13 @@ RoseXmlHandler::startElement(const QStri
m_currentSegment->setTrack(track);
//m_currentSegment->setStartTime(startTime);
+ QString colourIndStr = atts.value("colourindex");
+ if (colourIndStr) {
+ colourindex = colourIndStr.toInt();
+ }
+
+ m_currentSegment->setColourIndex(colourindex);
+
m_currentTime = startTime;
getComposition().addSegment(m_currentSegment);
getComposition().setSegmentStartTime(m_currentSegment, startTime);
@@ -1429,6 +1437,47 @@ RoseXmlHandler::startElement(const QStri
if (m_instrument) m_instrument->setMappedAudioInput(value);
+ } else if (lcName == "appearance") {
+
+ m_section = InAppearance;
+
+ } else if (lcName == "colourmap") {
+
+ if (m_section == InAppearance) {
+ QString mapName = atts.value("name");
+ m_inColourMap = true;
+ if (mapName == "segmentmap")
+ {
+ m_colourMap = &m_doc->getComposition().getSegmentColourMap();
+ }
+ else
+ { // This will change later once we get more of the Appearance code
sorted out
+ RG_DEBUG << i18n("RoseXmlHandler::startElement : Found colourmap with
unknown name") << endl;
+ }
+ }
+ else {
+ m_errorString = i18n("Found colourmap outside Appearance");
+ return false;
+ }
+
+ } else if (lcName == "colourpair") {
+
+ if (m_inColourMap && m_colourMap)
+ {
+ unsigned int id = atts.value("id").toInt();
+ QString name = atts.value("name");
+ unsigned int red = atts.value("red").toInt();
+ unsigned int blue = atts.value("blue").toInt();
+ unsigned int green = atts.value("green").toInt();
+ Rosegarden::Colour colour(red, green, blue);
+ m_colourMap->addItem(colour, qstrtostr(name), id);
+ }
+ else
+ {
+ m_errorString = i18n("Found colourpair outside ColourMap");
+ return false;
+ }
+
} else {
RG_DEBUG << "RoseXmlHandler::startElement : Don't know how to parse this : "
<< qName << endl;
}
@@ -1519,8 +1568,14 @@ RoseXmlHandler::endElement(const QString
m_section = NoSection;
- }
+ } else if (lcName == "appearance") {
+ m_section = NoSection;
+
+ } else if (lcName == "colourmap") {
+ m_inColourMap = false;
+ m_colourMap = 0;
+ }
return true;
}
Index: gui/rosexmlhandler.h
===================================================================
RCS file: /cvsroot/rosegarden/gui/rosexmlhandler.h,v
retrieving revision 1.56
diff -u -p -r1.56 rosexmlhandler.h
--- gui/rosexmlhandler.h 28 Jun 2003 17:40:14 -0000 1.56
+++ gui/rosexmlhandler.h 27 Jul 2003 22:42:17 -0000
@@ -49,7 +49,8 @@ public:
InStudio,
InInstrument,
InAudioFiles,
- InPlugin
+ InPlugin,
+ InAppearance
} RosegardenFileSection;
/**
@@ -122,6 +123,7 @@ protected:
bool m_inChord;
bool m_inGroup;
bool m_inComposition;
+ bool m_inColourMap;
std::string m_groupType;
int m_groupId;
int m_groupTupletBase;
@@ -140,6 +142,7 @@ protected:
Rosegarden::MidiByte m_lsb;
Rosegarden::Instrument *m_instrument;
Rosegarden::AudioPluginInstance *m_plugin;
+ Rosegarden::ColourMap *m_colourMap;
unsigned int m_pluginId;
unsigned int m_totalElements;
unsigned int m_elementsSoFar;
autoload.rg
Description: Binary data
