{% else-1 %}
Функция смены тональности песен с аккордамы

                        
function alterate($chords_string, $half_tones_alt) 
{
$data_half_tones = array(
0 => 'C',
2 => 'D',
4 => 'E',
5 => 'F',
7 => 'G',
9 => 'A',
10 => 'B',
11 => 'H',
);

$wrong_alts = array(
'A#' => 'B',
'B#' => 'H',
'H#' => 'C',
'E#' => 'F',
);

$data_chords = array_flip($data_half_tones);

$strlen = strlen($chords_string);
$return = '';

for($i = 0; $i < $strlen; $i++)
{
if(in_array($chords_string[$i], $data_half_tones))
{
$new_tone = $data_chords[$chords_string[$i]] + $half_tones_alt;
$new_tone = ($new_tone > 11 ? $new_tone % 12 : $new_tone);
$return .= (array_key_exists($new_tone, $data_half_tones)
? $data_half_tones[$new_tone]
: (array_key_exists($data_half_tones[$new_tone - 1].'#', $wrong_alts)
? $wrong_alts[$data_half_tones[$new_tone - 1].'#']
: $data_half_tones[$new_tone - 1].'#'
)

);

}
else
{
$return .= $chords_string[$i];
}

}



return $return;
}

echo alterate('Em H7 Em H7', +2);

//F#m C#7 F#m C#7
0 36 0
Без комментариев...