LibMusicXML 3.22
musicxmlfactory.h
1/*
2 MusicXML Library
3 Copyright (C) Grame 2006-2013
4
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9 Grame Research Laboratory, 11, cours de Verdun Gensoul 69002 Lyon - France
10 research@grame.fr
11*/
12
13#ifndef __musicxmlfactory__
14#define __musicxmlfactory__
15
16#include <vector>
17#include "xmlfile.h"
18#include "elements.h"
19
20using namespace std;
21namespace MusicXML2
22{
23
24//------------------------------------------------------------------------
25class musicxmlfactory
26{
27 private:
28 SXMLFile fFile;
29 Sxmlelement fRoot;
30 Sxmlelement fIdentification;
31 Sxmlelement fPartList;
32
33 protected:
34 void sort ();
35 Sxmlelement getSubElement (Sxmlelement elt, int type) const;
36 Sxmlelement getNotations (Sxmlelement elt) const { return getSubElement (elt, MusicXML2::k_notations); }
37 Sxmlelement getAttributes (Sxmlelement elt) const { return getSubElement (elt, MusicXML2::k_attributes); }
38 Sxmlelement getArticulations (Sxmlelement elt) const { return getSubElement (getNotations(elt), MusicXML2::k_articulations); }
39// Sxmlelement getDynamics (Sxmlelement elt) const { return getSubElement (getNotations(elt), k_dynamics); }
40
41 public:
42 musicxmlfactory();
43 virtual ~musicxmlfactory() {}
44
45 // getting the 'auto' elements (i.e. elements created by the factory constructor
46 virtual Sxmlelement root () { return fRoot; }
47 virtual Sxmlelement identification () { return fIdentification; }
48 virtual Sxmlelement partlist () { return fPartList; }
49
50 // managing header information
51 virtual void header (const char* worknumber, const char* worktitle, const char* movementnumber, const char* movementtitle);
52 virtual void creator (const char* c, const char* type=0);
53 virtual void rights (const char* c, const char* type=0);
54 virtual void encoding(const char* software = 0);
55
56 virtual void addgroup (int number, const char* name, const char* abbrev, bool groupbarline, std::vector<Sxmlelement>& parts);
57 virtual void addpart (const Sxmlelement& part);
58
59
60 virtual Sxmlelement scorepart (const char* id, const char* name, const char* abbrev);
61 virtual Sxmlelement part (const char* id);
62 virtual Sxmlelement newmeasure (int number) const;
63 virtual Sxmlelement newmeasure (int number, const char* time, const char* clef, int line, int key, int division) const;
64 virtual Sxmlelement newnote (const char* step, float alter, int octave, int duration, const char* type=0);
65 virtual Sxmlelement newrest (int duration, const char* type=0);
66 virtual Sxmlelement newdynamics (int type, const char* placement=0);
67 virtual Sxmlelement newbarline (const char* location, const char* barstyle, const char *repeat=0);
68
69 virtual void makechord (const std::vector<Sxmlelement>& notes);
70 virtual void maketuplet (int actual, int normal, const std::vector<Sxmlelement>& notes);
71 virtual void tie (Sxmlelement start, Sxmlelement end);
72 virtual void addnotation (Sxmlelement elt, Sxmlelement notation);
73 virtual void addarticulation (Sxmlelement elt, Sxmlelement articulation);
74
75 virtual void add (Sxmlelement elt, const std::vector<Sxmlelement>& subelts) const;
76 virtual void add (Sxmlelement elt, const Sxmlelement& subelt) const { elt->push (subelt); }
77 virtual void add (Sxmlelement elt, const Sxmlattribute& attr) const { elt->add (attr); }
78
79 virtual Sxmlelement element(int type, const char * value=0) const;
80 virtual Sxmlelement element(int type, int value) const;
81 virtual Sxmlelement element(int type, float value) const;
82 template<typename T> Sxmlattribute attribute(const char * name, T value) const {
83 Sxmlattribute attribute = xmlattribute::create();
84 attribute->setName (name);
85 attribute->setValue (value);
86 return attribute;
87 }
88
89 virtual void print (std::ostream& s) { sort(); fFile->print(s); }
90 virtual Sxmlelement getElements() { sort(); return fRoot; }
91};
92
93}
94
95#endif
long add(const Sxmlattribute &attr)
adds an attribute to the element