-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhum2ly.h
121 lines (98 loc) · 4.2 KB
/
hum2ly.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sat Aug 6 10:53:40 CEST 2016
// Last Modified: Tue Aug 9 12:43:50 CEST 2016
// Filename: hum2ly.h
// URL: https://github.com/craigsapp/hum2ly/blob/master/hum2ly.h
// Syntax: C++11
// vim: ts=3 noexpandtab
//
// Description: Convert a Humdrum file into a lilypond file.
//
#ifndef _HUM2LY_H
#define _HUM2LY_H
#define _USE_HUMLIB_OPTIONS_
#include "humlib.h"
#include <iostream>
#include <math.h>
namespace hum {
using namespace std;
//////////////////////////////
//
// StateVariables -- This helper class keeps track of various
// data states, such as for expressing music in \relative form.
//
class StateVariables {
public:
StateVariables(void) { clear(); }
~StateVariables() { clear(); }
void clear();
HumNum duration; // duration of last note/chord/rest
int dots; // augmentation dots of last note/chord/rest
int pitch; // pitch of previous note
int cpitch; // pitch of previous note in chord
vector<int> chordpitches; // pitches of last chord (for "q" shortcut)
};
//////////////////////////////
//
// HumdrumToLilypondConverter -- The main class for converting Humdrum data
// into Lilypond data.
//
class HumdrumToLilypondConverter {
public:
HumdrumToLilypondConverter(void);
~HumdrumToLilypondConverter() {}
bool convert (ostream& out, HumdrumFile& infile);
bool convert (ostream& out, const string& input);
bool convert (ostream& out, istream& input);
void setIndent (const string& indent)
{ m_indent = indent; }
void setOptions (int argc, char** argv);
void setOptions (const vector<string>& argvlist);
Options getOptionDefinitions (void);
protected:
bool convert (ostream& out);
bool convertPart (ostream& out, const string& partname,
int partindex);
void extractSegments (void);
bool convertSegment (ostream& out, int partindex, int startline,
int endline);
void printHeaderComments(ostream& out);
void printFooterComments(ostream& out);
bool convertPartSegment(ostream& out, HTp starttoken, int endline);
bool convertDataToken (ostream& out, HTp token);
bool convertRest (ostream& out, HTp token);
bool convertChord (ostream& out, HTp token);
bool convertNote (ostream& out, HTp token, int index = 0);
int printRelativeStartingPitch(ostream& out, int partindex,
int startline, int endline);
vector<HTp> getStartTokens(int partindex, int startline, int endline);
int getSegmentStartingPitch(int partindex, int startline, int endline);
int characterCount (const string &text, char symbol);
void convertDuration (ostream& out, HumNum& duration, int dots);
void convertDuration (ostream& out, HumNum& durationnodots,
HumNum& duration, int dots);
string arabicToRomanNumeral(int arabic, int casetype = 1);
bool convertInterpretationToken(ostream& out, HTp token);
void addErrorMessage (const string& message, HTp token = NULL);
void printErrorMessages(ostream& out);
bool convertClef (ostream& out, HTp token);
HTp getKeyDesignation (HTp token);
bool convertKeySignature(ostream& out, HTp token);
void printHeader (ostream& tempout);
void convertArticulations(ostream& out, const string& stok);
private:
vector<HTp> m_kernstarts; // part to track mapping
vector<int> m_rkern; // track to part mapping
vector<int> m_segments; // line index for start of each segement
vector<string> m_labels; // starting label for each segement
HumdrumFile m_infile; // Humdrum file to convert
string m_indent; // whitespace for each indenting levels
stringstream m_staffout; // staff assembly output
stringstream m_scoreout; // score assembly output
StateVariables m_states; // keep track of pitch/rhythm changes
Options m_options; // command-line options
vector<string> m_errors; // storage for conversion errors
};
} // end of namespace hum
#endif /* _HUM2LY_H */