mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 03:04:00 +00:00
Support changing time/key in lilypond
This commit is contained in:
parent
b8dac8dd63
commit
83438255fd
|
@ -83,8 +83,6 @@ vlExceptions = #(append
|
|||
<{CHORDS}>
|
||||
}
|
||||
\context Voice = "mel" {
|
||||
\time <{TIME}>
|
||||
\key <{KEY}>
|
||||
<{NOTES}>
|
||||
}
|
||||
\lyricsto "mel" \new Lyrics { <{LYRICS}> }
|
||||
|
|
|
@ -105,17 +105,8 @@
|
|||
|
||||
@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
|
||||
{
|
||||
const VLProperties & prop = song->fProperties.front();
|
||||
VLLilypondWriter writer;
|
||||
writer.Visit(*song);
|
||||
NSBundle * bndl = [NSBundle mainBundle];
|
||||
|
@ -137,14 +128,6 @@ static const char * sKeyNames[] = {
|
|||
[bndl objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
||||
[ly substituteMacro:@"CHORDS" withValue:
|
||||
[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:
|
||||
[NSString stringWithUTF8String:writer.Melody().c_str()]];
|
||||
if (size_t stanzas = song->CountStanzas())
|
||||
|
|
|
@ -22,6 +22,7 @@ void VLLilypondWriter::Visit(VLSong & song)
|
|||
fIndent.clear();
|
||||
fSeenEnding = 0;
|
||||
fNumEndings = 0;
|
||||
fLastProp = 0;
|
||||
|
||||
VisitMeasures(song, false);
|
||||
//
|
||||
|
@ -50,6 +51,31 @@ void VLLilypondWriter::VisitMeasure(size_t m, VLProperties & p, VLMeasure & meas
|
|||
fAccum += measNo;
|
||||
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
|
||||
//
|
||||
|
@ -57,7 +83,6 @@ void VLLilypondWriter::VisitMeasure(size_t m, VLProperties & p, VLMeasure & meas
|
|||
size_t volta;
|
||||
bool repeat;
|
||||
|
||||
fAccum.clear();
|
||||
if (meas.fBreak == VLMeasure::kNewPage)
|
||||
fAccum += fIndent+"\\pageBreak\n";
|
||||
else if (meas.fBreak == VLMeasure::kNewSystem)
|
||||
|
|
|
@ -36,6 +36,7 @@ private:
|
|||
std::string fAccum;
|
||||
std::string fIndent;
|
||||
std::vector<std::string> fL;
|
||||
VLProperties * fLastProp;
|
||||
};
|
||||
|
||||
// Local Variables:
|
||||
|
|
Loading…
Reference in New Issue
Block a user