Support changing time/key in lilypond

This commit is contained in:
Matthias Neeracher 2008-01-26 10:54:00 +00:00
parent b8dac8dd63
commit 83438255fd
4 changed files with 27 additions and 20 deletions

View File

@ -83,8 +83,6 @@ vlExceptions = #(append
<{CHORDS}> <{CHORDS}>
} }
\context Voice = "mel" { \context Voice = "mel" {
\time <{TIME}>
\key <{KEY}>
<{NOTES}> <{NOTES}>
} }
\lyricsto "mel" \new Lyrics { <{LYRICS}> } \lyricsto "mel" \new Lyrics { <{LYRICS}> }

View File

@ -105,17 +105,8 @@
@implementation VLDocument (Lilypond) @implementation VLDocument (Lilypond)
const int kMajorOffset = 6;
const int kMinorOffset = 9;
static const char * sKeyNames[] = {
"ges", "des", "as", "es", "bes", "f",
"c", "g", "d", "a", "e", "b", "fis", "cis", "gis"
};
- (NSData *)lilypondDataWithError:(NSError **)outError - (NSData *)lilypondDataWithError:(NSError **)outError
{ {
const VLProperties & prop = song->fProperties.front();
VLLilypondWriter writer; VLLilypondWriter writer;
writer.Visit(*song); writer.Visit(*song);
NSBundle * bndl = [NSBundle mainBundle]; NSBundle * bndl = [NSBundle mainBundle];
@ -137,14 +128,6 @@ static const char * sKeyNames[] = {
[bndl objectForInfoDictionaryKey:@"CFBundleVersion"]]; [bndl objectForInfoDictionaryKey:@"CFBundleVersion"]];
[ly substituteMacro:@"CHORDS" withValue: [ly substituteMacro:@"CHORDS" withValue:
[NSString stringWithUTF8String:writer.Chords().c_str()]]; [NSString stringWithUTF8String:writer.Chords().c_str()]];
[ly substituteMacro:@"TIME" withValue:
[NSString stringWithFormat:@"%d/%d",
prop.fTime.fNum, prop.fTime.fDenom]];
[ly substituteMacro:@"KEY" withValue: prop.fMode > 0
? [NSString stringWithFormat:@"%s \\major",
sKeyNames[prop.fKey+kMajorOffset]]
: [NSString stringWithFormat:@"%s \\minor",
sKeyNames[prop.fKey+kMinorOffset]]];
[ly substituteMacro:@"NOTES" withValue: [ly substituteMacro:@"NOTES" withValue:
[NSString stringWithUTF8String:writer.Melody().c_str()]]; [NSString stringWithUTF8String:writer.Melody().c_str()]];
if (size_t stanzas = song->CountStanzas()) if (size_t stanzas = song->CountStanzas())

View File

@ -22,6 +22,7 @@ void VLLilypondWriter::Visit(VLSong & song)
fIndent.clear(); fIndent.clear();
fSeenEnding = 0; fSeenEnding = 0;
fNumEndings = 0; fNumEndings = 0;
fLastProp = 0;
VisitMeasures(song, false); VisitMeasures(song, false);
// //
@ -50,6 +51,31 @@ void VLLilypondWriter::VisitMeasure(size_t m, VLProperties & p, VLMeasure & meas
fAccum += measNo; fAccum += measNo;
fChords+= fAccum + '\n'; fChords+= fAccum + '\n';
fAccum.clear();
//
// Generate key/time if changed
//
if (!fLastProp || fLastProp->fTime != p.fTime) {
char time[16];
sprintf(time, "\\time %d/%d\n", p.fTime.fNum, p.fTime.fDenom);
fAccum += fIndent+time;
}
if (!fLastProp || fLastProp->fKey != p.fKey || fLastProp->fMode != p.fMode) {
const int kMajorOffset = 6;
const int kMinorOffset = 9;
static const char * sKeyNames[] = {
"ges", "des", "as", "es", "bes", "f",
"c", "g", "d", "a", "e", "b", "fis", "cis", "gis"
};
char key[16];
if (p.fMode < 0)
sprintf(key, "\\key %s \\minor\n", sKeyNames[p.fKey+kMinorOffset]);
else
sprintf(key, "\\key %s \\major\n", sKeyNames[p.fKey+kMajorOffset]);
fAccum += fIndent+key;
}
fLastProp = &p;
// //
// Generate structure elements // Generate structure elements
// //
@ -57,7 +83,6 @@ void VLLilypondWriter::VisitMeasure(size_t m, VLProperties & p, VLMeasure & meas
size_t volta; size_t volta;
bool repeat; bool repeat;
fAccum.clear();
if (meas.fBreak == VLMeasure::kNewPage) if (meas.fBreak == VLMeasure::kNewPage)
fAccum += fIndent+"\\pageBreak\n"; fAccum += fIndent+"\\pageBreak\n";
else if (meas.fBreak == VLMeasure::kNewSystem) else if (meas.fBreak == VLMeasure::kNewSystem)

View File

@ -36,6 +36,7 @@ private:
std::string fAccum; std::string fAccum;
std::string fIndent; std::string fIndent;
std::vector<std::string> fL; std::vector<std::string> fL;
VLProperties * fLastProp;
}; };
// Local Variables: // Local Variables: