On 1 October 2010 16:20, Don Wieland <d...@pointmade.net> wrote:
> The logic I need is pretty straight forward, but I am having a hard time
> replicating it using PHP functions. I will try to break it down to it's
> simplest form:
>
> I have a field that has several lines of text. Chords and Song Lyrics.
>
> The "Chord" lines begin with an asterisk "*" and end with the line break.
> This is the string I want to parse. Lines with no asterisk at the beginning
> are ignored.
>
> Based on 3 arrays of NOTES, I want SUBSTITUTE the text (based on exact text
> character patterns - just NOTES not the chord type) of the lines in my field
> that start with an asterisk "*".
>
> original_chord_array = A, A#, B, C, C#, D, D#, E, F, F#, G, G#
> transpose_up_array = A#, B, C, C#, D, D#, E, F, F#, G, G#, A
> transpose_down_array = G#, A, A#, B, C, C#, D, D#, E, F, F#, G
>
> It is important that it only effects EXACT strings.  Notes will always be
> capitalized and chord types will be lower case. Maybe we can use that
> characteristic to better identify what to change. Here are some examples of
> chords:
>
> A
> Asus7
> Csus add9
> Dmaj7
> F#m7
> G#
> C#dim no3
>
> When I transpose UP these chords, just the NOTE should change:
>
> A#
> A#sus7
> C#sus add9
> D#maj7
> Gm7
> A
> Ddim no3
>
> When I transpose DOWN these chords, just the NOTE should change:
>
> G#
> G#sus7
> Bsus add9
> C#maj7
> Fm7
> G
> Cdim no3
>
> I am working on a function, but still not producing the proper results.
> Hopefully this break down is more clear and someone will bail me out ;-)
>
> Thanks again for the feedback.
>
> Don
>
> On Oct 1, 2010, at 7:02 AM, Richard Quadling wrote:
>
>> Changing the NormalKeyID and using that ID with NoteSequenceNumber
>> should give you the new note to play.
>>
>> I think.
>
>

/**
 * Transpose a chord sequence.
 *
 * @param $s_Sequence The chord sequence to transpose.
 * @param $b_TransposeUp Transpose up or down.
 *
 * @return The transposed sequence.
 */
function transposeChord($s_Sequence, $b_TransposeUp = True) {
        $a_Chords = array('A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F',
'F#', 'G', 'G#');
        return preg_replace_callback (
                '`([A-G]#?)`',
                function($a_Matches) use($a_Chords, $b_TransposeUp) {
                        // Find the position in the chords array of the found 
chord.
                        $a_ChordPositions = array_keys($a_Chords, 
$a_Matches[1], True);

                        // Get the new chord position.
                        $i_NewChordPosition = (count($a_Chords) + 
$a_ChordPositions[0] +
($b_TransposeUp ? 1 : -1)) % count($a_Chords);

                        // Return the new chord position.
                        return $a_Chords[$i_NewChordPosition];
                },
                $s_Sequence
        );
}



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to