Skip to content

Commit

Permalink
Merge pull request #1471 from MarcSabatella/39316-mordent
Browse files Browse the repository at this point in the history
fix #39316: non-diatonic ornament playback
  • Loading branch information
lasconic committed Nov 22, 2014
2 parents cf92afb + ea51947 commit c76f6f3
Show file tree
Hide file tree
Showing 4 changed files with 1,262 additions and 22 deletions.
66 changes: 44 additions & 22 deletions libmscore/utils.cpp
Expand Up @@ -624,7 +624,7 @@ int diatonicUpDown(Key k, int pitch, int steps)
{
static int ptab[15][7] = {
// c c# d d# e f f# g g# a a# b
{ -1, 1, 3, 5, 6, 8, 10 }, // Ces
{ -1, 1, 3, 4, 6, 8, 10 }, // Ces
{ -1, 1, 3, 5, 6, 8, 10 }, // Ges
{ 0, 1, 3, 5, 6, 8, 10 }, // Des
{ 0, 1, 3, 5, 7, 8, 10 }, // As
Expand All @@ -647,31 +647,53 @@ int diatonicUpDown(Key k, int pitch, int steps)
int step = pitch % 12;
int octave = pitch / 12;

for (int i = 0; i < 7; ++i) {
if (ptab[key][i] == step) {
if (steps > 0) {
while (steps--) {
++i;
if (i == 7) {
++octave;
i = 0;
}
}
// loop through the diatonic steps of the key looking for the given note
// or the gap where it would fit
int i = 0;
while (i < 7) {
if (ptab[key][i] >= step)
break;
++i;
}

// neither step nor gap found
// reset to beginning
if (i == 7) {
++octave;
i = 0;
}
// if given step not found (gap found instead), and we are stepping up
// then we've already accounted for one step
if (ptab[key][i] > step && steps > 0)
--steps;

// now start counting diatonic steps up or down
if (steps > 0) {
// count up
while (steps--) {
++i;
if (i == 7) {
// hit last step; reset to beginning
++octave;
i = 0;
}
else {
while (++steps <= 0) {
--i;
if (i < 0) {
i = 6;
--octave;
}
}
}
}
else if (steps < 0) {
// count down
while (steps++) {
--i;
if (i < 0) {
// hit first step; reset to end
--octave;
i = 6;
}
step = ptab[key][i];
break;
}
}
pitch = octave * 12 + step;

// convert step to pitch
step = ptab[key][i];
pitch = octave * 12 + step;
if (pitch < 0)
pitch = 0;
if (pitch > 127)
Expand Down

0 comments on commit c76f6f3

Please sign in to comment.