mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 03:04:00 +00:00
Automatically compute divisions on import
This commit is contained in:
parent
ed7870b336
commit
0755217a57
|
@ -12,7 +12,6 @@ require File.dirname($0)+'/vl'
|
|||
|
||||
MEAS = []
|
||||
PROP = {
|
||||
'divisions' => 3,
|
||||
'key' => 0,
|
||||
'mode' => 1,
|
||||
'timeNum' => 4,
|
||||
|
@ -337,7 +336,6 @@ if groove.size > 1
|
|||
end
|
||||
|
||||
RAWNOTES = []
|
||||
ONSETS = [0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
if biab.sub!(/^.*?\xA0\xB0\xC1/m, '')
|
||||
noteCount = biab.length / 12 if noteCount == 0
|
||||
(0...noteCount).each do |i|
|
||||
|
@ -349,28 +347,9 @@ if biab.sub!(/^.*?\xA0\xB0\xC1/m, '')
|
|||
end
|
||||
onset = (onset / 10.0).round
|
||||
RAWNOTES.push([onset, pitch])
|
||||
ONSETS[onset % 12] += 1
|
||||
end
|
||||
end
|
||||
|
||||
if ONSETS[1]+ONSETS[5]+ONSETS[7]+ONSETS[11] == 0
|
||||
if ONSETS[3]+ONSETS[9] == 0
|
||||
if ONSETS[2]+ONSETS[4]+ONSETS[8]+ONSETS[10] == 0
|
||||
PROP['divisions'] = 2
|
||||
elsif ONSETS[2]+ONSETS[6]+ONSETS[10] == 0
|
||||
PROP['divisions'] = 3
|
||||
else
|
||||
PROP['divisions'] = 6
|
||||
end
|
||||
elsif ONSETS[2]+ONSETS[4]+ONSETS[8]+ONSETS[10] == 0
|
||||
PROP['divisions'] = 4
|
||||
else
|
||||
PROP['divisions'] = 12
|
||||
end
|
||||
else
|
||||
PROP['divisions'] = 12
|
||||
end
|
||||
|
||||
p RAWNOTES, CHORDS, STEPS, ROOTS if DEBUG
|
||||
|
||||
CHORDS.pop
|
||||
|
|
|
@ -33,7 +33,6 @@ notes = []
|
|||
lyrics = []
|
||||
stanzas = []
|
||||
lastDur = 1
|
||||
divisions = 2
|
||||
tied = false
|
||||
repeat = 0
|
||||
timeNum = 4
|
||||
|
@ -83,6 +82,9 @@ def lyPitch(pitch, base=-1)
|
|||
return p
|
||||
end
|
||||
|
||||
$timesNum = 1
|
||||
$timesDen = 1
|
||||
|
||||
def lyDur(dur)
|
||||
dur =~ /^(\d+)(\.*)(?:\*(\d+).(\d+))?/
|
||||
num = 1
|
||||
|
@ -97,7 +99,7 @@ def lyDur(dur)
|
|||
num *= $3.to_i
|
||||
den *= $4.to_i
|
||||
end
|
||||
return [num,den]
|
||||
return [num*$timesNum,den*$timesDen]
|
||||
end
|
||||
|
||||
STEPS = {
|
||||
|
@ -226,7 +228,7 @@ while tokens.length > 0
|
|||
(\d+ # 1, 2, 4, 8, 16 ...
|
||||
\.*(?:\*\d+/\d+)? # ., *3/4
|
||||
)?
|
||||
(?:\:([-+^:.a-z\d]+))? # :maj9.7-^2
|
||||
(?:\:([-+^:.a-z\d]+)?)? # :maj9.7-^2
|
||||
(?:/\+( # /+
|
||||
[a-g](?:[ei]?s)? # Root: a, bes, fis, as
|
||||
))?
|
||||
|
@ -290,6 +292,11 @@ while tokens.length > 0
|
|||
voltas = 0
|
||||
curVoltas = nil
|
||||
notes.push({'begin-ending' => true})
|
||||
elsif token == '\times' && tokens[0] =~ %r|^(\d+)/(\d+)|
|
||||
$timesNum = $1.to_i
|
||||
$timesDen = $2.to_i
|
||||
stack.push([block, level, "times"])
|
||||
level = nestLevel
|
||||
end
|
||||
when '\lyricmode'
|
||||
if token == '--'
|
||||
|
@ -360,6 +367,9 @@ while tokens.length > 0
|
|||
stack.push([block, level, "endings"])
|
||||
level = nestLevel
|
||||
end
|
||||
elsif type == "times"
|
||||
$timesNum = 1
|
||||
$timesDen = 1
|
||||
end
|
||||
end
|
||||
when '\chords', '\header', '\paper', '\lyricmode'
|
||||
|
@ -513,7 +523,6 @@ end
|
|||
|
||||
OUTPUT['measures'] = measures
|
||||
OUTPUT['properties'] = [{
|
||||
'divisions' => divisions,
|
||||
'key' => key,
|
||||
'mode' => mode == '\minor' ? -1 : 1,
|
||||
'timeNum' => timeNum,
|
||||
|
|
|
@ -209,7 +209,7 @@ void VLPlistVisitor::VisitChord(VLChord & c)
|
|||
}
|
||||
}
|
||||
|
||||
- (void)readMelody:(NSArray *)melody inMeasure:(size_t)measNo
|
||||
- (void)readMelody:(NSArray *)melody inMeasure:(size_t)measNo onsets:(int *)onsets
|
||||
{
|
||||
VLFraction at(0);
|
||||
VLFraction tiedStart(0);
|
||||
|
@ -261,6 +261,11 @@ void VLPlistVisitor::VisitChord(VLChord & c)
|
|||
tiedNote = note;
|
||||
|
||||
song->AddNote(note, measNo, at);
|
||||
|
||||
if (!(note.fTied & VLNote::kTiedWithPrev)) {
|
||||
VLFraction inQuarter = at % VLFraction(1,4);
|
||||
++onsets[inQuarter.fNum * 48 / inQuarter.fDenom];
|
||||
}
|
||||
advanceAt:
|
||||
at += note.fDuration;
|
||||
}
|
||||
|
@ -293,6 +298,7 @@ advanceAt:
|
|||
std::vector<size_t> repeatStack;
|
||||
|
||||
size_t measNo = 0;
|
||||
int onsets[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
for (NSEnumerator * me = [measures objectEnumerator];
|
||||
NSDictionary * mdict = [me nextObject];
|
||||
++measNo
|
||||
|
@ -300,7 +306,7 @@ advanceAt:
|
|||
if (NSNumber * mNo = [mdict objectForKey:@"measure"])
|
||||
measNo = static_cast<size_t>([mNo intValue]);
|
||||
|
||||
[self readMelody:[mdict objectForKey:@"melody"] inMeasure:measNo];
|
||||
[self readMelody:[mdict objectForKey:@"melody"] inMeasure:measNo onsets:onsets];
|
||||
[self readChords:[mdict objectForKey:@"chords"] inMeasure:measNo];
|
||||
|
||||
if ([[mdict objectForKey:@"tocoda"] boolValue])
|
||||
|
@ -353,6 +359,22 @@ advanceAt:
|
|||
size_t empty = song->EmptyEnding();
|
||||
while (empty-- > 1)
|
||||
song->fMeasures.pop_back();
|
||||
if (!song->fProperties.back().fDivisions) {
|
||||
if (!(onsets[1]+onsets[5]+onsets[7]+onsets[11]))
|
||||
if (!(onsets[3]+onsets[9]))
|
||||
if (!(onsets[2]+onsets[4]+onsets[8]+onsets[10]))
|
||||
song->fProperties.back().fDivisions = 2;
|
||||
else if (!(onsets[2]+onsets[6]+onsets[10]))
|
||||
song->fProperties.back().fDivisions = 3;
|
||||
else
|
||||
song->fProperties.back().fDivisions = 6;
|
||||
else if (!(onsets[2]+onsets[4]+onsets[8]+onsets[10]))
|
||||
song->fProperties.back().fDivisions = 4;
|
||||
else
|
||||
song->fProperties.back().fDivisions = 12;
|
||||
else
|
||||
song->fProperties.back().fDivisions = 12;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)readPropertiesFromPlist:(NSArray *)properties
|
||||
|
|
Loading…
Reference in New Issue
Block a user