Store repeats inline in measures

This commit is contained in:
Matthias Neeracher 2007-08-23 12:16:38 +00:00
parent ffaa1f8343
commit e7ee4e301d
2 changed files with 45 additions and 46 deletions

View File

@ -61,6 +61,9 @@ def _chords
chords = REXML::Element.new('part') chords = REXML::Element.new('part')
chords.add_attribute('id', 'HARM') chords.add_attribute('id', 'HARM')
INPUT['measures'].each do |meas|
end
return chords return chords
end end
@ -91,3 +94,6 @@ xml.add REXML::DocType.new(['score-partwise', 'PUBLIC',
xml.add_element(_score) xml.add_element(_score)
xml.write($stdout, 0) xml.write($stdout, 0)
# Local Variables:
# mode:ruby
# End:

View File

@ -33,8 +33,6 @@ protected:
NSArray * EncodeProperties(const std::vector<VLProperties> & properties); NSArray * EncodeProperties(const std::vector<VLProperties> & properties);
NSDictionary * EncodeProperties(const VLProperties & properties); NSDictionary * EncodeProperties(const VLProperties & properties);
NSArray * EncodeRepeats(const std::vector<VLRepeat> & repeats);
NSDictionary * EncodeRepeat(const VLRepeat & repeat);
NSMutableDictionary * fPlist; NSMutableDictionary * fPlist;
NSMutableArray * fMeasures; NSMutableArray * fMeasures;
@ -66,35 +64,6 @@ NSDictionary * VLPlistVisitor::EncodeProperties(const VLProperties & properties)
nil]; nil];
} }
NSArray * VLPlistVisitor::EncodeRepeats(const std::vector<VLRepeat> & repeats)
{
NSMutableArray * ra = [NSMutableArray arrayWithCapacity:repeats.size()];
for (std::vector<VLRepeat>::const_iterator i = repeats.begin();
i != repeats.end(); ++i)
[ra addObject:EncodeRepeat(*i)];
return ra;
}
NSDictionary * VLPlistVisitor::EncodeRepeat(const VLRepeat & repeat)
{
NSMutableArray * ea = [NSMutableArray arrayWithCapacity:repeat.fEndings.size()];
for (std::vector<VLRepeat::Ending>::const_iterator i = repeat.fEndings.begin();
i != repeat.fEndings.end(); ++i)
[ea addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: i->fBegin], @"begin",
[NSNumber numberWithInt: i->fEnd], @"end",
[NSNumber numberWithInt: i->fVolta], @"volta",
nil]];
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: repeat.fTimes], @"times",
ea, @"endings",
nil];
}
void VLPlistVisitor::Visit(VLSong & song) void VLPlistVisitor::Visit(VLSong & song)
{ {
fSong = &song; fSong = &song;
@ -102,7 +71,6 @@ void VLPlistVisitor::Visit(VLSong & song)
VisitMeasures(song, fPerfOrder); VisitMeasures(song, fPerfOrder);
[fPlist setObject:EncodeProperties(song.fProperties) forKey:@"properties"]; [fPlist setObject:EncodeProperties(song.fProperties) forKey:@"properties"];
[fPlist setObject:EncodeRepeats(song.fRepeats) forKey:@"repeats"];
[fPlist setObject:fMeasures forKey:@"measures"]; [fPlist setObject:fMeasures forKey:@"measures"];
} }
@ -114,12 +82,39 @@ void VLPlistVisitor::VisitMeasure(size_t m, VLProperties & p, VLMeasure & meas)
VisitNotes(meas, p, true); VisitNotes(meas, p, true);
VisitChords(meas); VisitChords(meas);
NSDictionary * md = NSMutableDictionary * md =
[NSDictionary dictionaryWithObjectsAndKeys: [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:m], @"measure", [NSNumber numberWithInt:m], @"measure",
[NSNumber numberWithInt:meas.fPropIdx], @"properties", [NSNumber numberWithInt:meas.fPropIdx], @"properties",
fNotes, @"melody", fChords, @"chords", fNotes, @"melody", fChords, @"chords",
nil]; nil];
int times;
bool last;
size_t volta;
if (fSong->DoesBeginRepeat(m, &times))
[md setObject:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:times], @"times", nil]
forKey: @"begin-repeat"];
if (fSong->DoesBeginEnding(m, &last, &volta))
[md setObject:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:!last], @"last",
[NSNumber numberWithInt:volta], @"volta",
nil]
forKey: @"begin-ending"];
if (fSong->DoesEndRepeat(m+1, &times))
[md setObject:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:times], @"times", nil]
forKey: @"end-repeat"];
if (fSong->DoesEndEnding(m, &last, &volta))
[md setObject:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:!last], @"last",
[NSNumber numberWithInt:volta], @"volta",
nil]
forKey: @"end-ending"];
[fMeasures addObject:md]; [fMeasures addObject:md];
} }
@ -162,18 +157,16 @@ void VLPlistVisitor::VisitChord(VLChord & c)
- (id)plistInPerformanceOrder:(BOOL)performanceOrder - (id)plistInPerformanceOrder:(BOOL)performanceOrder
{ {
NSMutableDictionary * plist = NSMutableDictionary * plist =
[NSMutableDictionary dictionaryWithCapacity:20]; [NSMutableDictionary dictionaryWithObjectsAndKeys:
[plist setObject:songTitle forKey:@"title"]; songTitle, @"title",
[plist setObject:songGroove forKey:@"groove"]; songGroove, @"groove", songTempo, @"tempo",
[plist setObject:songTempo forKey:@"tempo"]; songComposer, @"composer", songLyricist, @"lyricist",
[plist setObject:songComposer forKey:@"composer"]; [NSDate date], @"saved",
[plist setObject:songLyricist forKey:@"lyricist"];
[plist setObject:[NSDate date] forKey:@"saved"];
[plist setObject:
[NSString stringWithFormat:@"VocalEasel %@", [NSString stringWithFormat:@"VocalEasel %@",
[[NSBundle mainBundle] [[NSBundle mainBundle]
objectForInfoDictionaryKey:@"CFBundleVersion"]] objectForInfoDictionaryKey:@"CFBundleVersion"]],
forKey:@"software"]; @"software",
nil];
VLPlistVisitor songWriter(plist, performanceOrder); VLPlistVisitor songWriter(plist, performanceOrder);
songWriter.Visit(*song); songWriter.Visit(*song);