5
----------------------------------------------------------------------------------------
7
Fragments will be divided into 'segments'. Each segment division line is a point
8
in wich a barline can be inserted:
11
=====|=============|============|===============|=======
15
In some cases the pattern represented by the fragment requires a certain barline
16
alignment. Let's define:
18
tam - Time to align to barline ('am' stands for 'align to measure')
20
<------------- tam ------------->
21
=====|=============|============||===============|=======
23
If a fragment does not require any special alignment for a barline then tam=0
27
A fragment can start in any place, not necesarily aligned to beat. Therefore
28
there will be a required time to align to beat:
30
tab - Time to align to beat ('ab' stands for 'align to beat')
32
<--tab--><------------- tam ------------->
33
| =====|=============|============||===============|=======
36
If the fragment starts aligned to beat then tab=0
37
In theory, a fragment will never start with rests, as starting with a rest is equivalent to not being
39
Important: in practice, the way of indicate that the fragment is not beat aligned is by
40
starting the segment with rests. These rests will be removed by the program and its
41
duration will be assigned to time tab.
47
Let's assume that we have a measure M partially filled. Let's call:
49
tm - the duration of a measure
50
tb - the duration of a beat (problem: in irregular time signatures, such as 7/8, beat
51
duration is not constant. But we can consider the appropiate tb at each time (?))
52
tc - the time already 'consumed' in that measure,
53
tcb - the consumed time of last beat (tcb = tc % tb)
54
tr - the remaining time (tr = tm - tc)
57
<----------------- tm ---------------->
58
||<----------- tc ----------><----tr---->|| || = barline
59
xxxxxxxxx||xxxxxxxxx|xxxxxxxxx|xxxxxxx..|.........||
60
|| <-tcb-> || | = beat line
61
<--tb--->|<--tb--->|<--tb--->|<--tb--->
64
The problem now is, how to use a fragment F to fill the measure M?
67
Case 1. Fragment F does not require measure aligment (tam = 0).
69
Get the first segment S and compute its duration ts:
75
Then segment S will fit in measure only when
77
tr >= ts and tcb <= tab
80
If it fits, then the procedure will be:
82
1. Add rest R(tab-tcb).
84
3. Update remaining time: tr = tr - ts - (tab - tcb)
86
Important: Before adding a rest (step 1) we need to check if the previous element is
87
a tied-to-next note. If it is, we must remove the tie or replace the rest by a note.
88
If we always add a note of the same pitch than the previous one we save the trouble
89
of having to do the check and removing the tie!. It is only necessary to get the
90
the pitch of the previous note. If notes instantiation is done after creating the
91
measure, we will also save this.
93
So, taking all this into consideration we will add a note instead of a rest. The
94
simplified modified algorithm will be:
96
1. Add note N(tab-tcb).
98
3. Update remaining time: tr = tr - ts - (tab - tcb)
102
Case 2. Fragment requires measure aligment (tam > 0)
b'\\ No newline at end of file'