LibMusicXML 3.22
transposition.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 __transposition__
14#define __transposition__
15
16#include <map>
17#include <vector>
18
19#include "exports.h"
20#include "typedefs.h"
21#include "transposevisitor.h"
22#include "notevisitor.h"
23
24
25namespace MusicXML2
26{
27
32
33typedef int Chromatic;
34typedef int Diatonic;
35
46class EXP transposition :
47 public notevisitor,
48 public visitor<S_cancel>,
49 public visitor<S_fifths>,
50 public visitor<S_encoding>,
51 public visitor<S_part>
52{
53 protected:
54 Chromatic fChromaticSteps; // the target transposing interval
55
56 std::vector<pair<std::string,int> > fFifthCycle; // the fifth cycle table
57
58 int fTableShift; // the current shift into the table of fifths
59 int fOctaveChange; // the target octave change computed from fChromaticSteps
60 int fKeySign; // the target key signature
61 int fCurrentKeySign; // the current key signature
62
63 void initialize ();
64
70 Sxmlelement buildSupport ( const string& elt, bool val) const;
71
79 void transpose ( string& pitch, float& alter, int& octave, int tableshift ) const;
80 // set the note pitch according to the current shift into the table of fifths
81 void setPitch ( notevisitor& v );
82
83 ctree<xmlelement>::iterator insertAlter ( S_note& elt, ctree<xmlelement>::iterator pos, float value );
84 ctree<xmlelement>::iterator insertAccident ( S_note& elt, ctree<xmlelement>::iterator pos, const string& value );
85
86 virtual void visitStart ( S_part& elt );
87 virtual void visitEnd( S_note& elt );
88 // non standard keys are not yet supported
89 virtual void visitStart ( S_cancel& elt );
90 virtual void visitStart ( S_fifths& elt );
91 virtual void visitEnd ( S_encoding& elt );
92
93 public:
94 transposition(int steps);
95 virtual ~transposition();
96
97
102 static int getOctave ( Chromatic steps ) { return steps/12; }
103
108 static Chromatic getOctaveStep ( Chromatic steps ) { return steps%12; }
109
115 static int getKey ( Chromatic steps );
116
122 static int getAccidental ( Diatonic pitch, int key );
123
128 static string getAccident ( float alter );
129
137 static int transposeKey ( int key, Chromatic steps, int& enharmonicChange );
138};
139
141
142} // namespace MusicXML2
143
144
145#endif
treeIterator< treePtr > iterator
the top -> bottom iterator type
Definition ctree.h:129
void transpose(string &pitch, float &alter, int &octave, int tableshift) const
static int transposeKey(int key, Chromatic steps, int &enharmonicChange)
static string getAccident(float alter)
static int getKey(Chromatic steps)
Sxmlelement buildSupport(const string &elt, bool val) const
static Chromatic getOctaveStep(Chromatic steps)
Definition transposition.h:108
static int getOctave(Chromatic steps)
Definition transposition.h:102
static int getAccidental(Diatonic pitch, int key)
Definition visitor.h:27