# HG changeset patch # User Dan Fuhry # Date 1332888503 14400 # Node ID c3150cee8dd96a2ecb1a27b33a17fee11bfbbbb2 # Parent 2f3b76a405cebdc05c41ac2b75a03dad05a7bfb4 Added support for the "transpose" tag which forces a song to be transposed. diff -r 2f3b76a405ce -r c3150cee8dd9 Halftone.php --- a/Halftone.php Tue Mar 27 12:14:14 2012 -0400 +++ b/Halftone.php Tue Mar 27 18:48:23 2012 -0400 @@ -13,7 +13,7 @@ **!*/ $plugins->attachHook('render_wikiformat_posttemplates', 'halftone_process_tags($text);'); -$plugins->attachHook('html_attribute_whitelist', '$whitelist["halftone"] = array("title", "key");'); +$plugins->attachHook('html_attribute_whitelist', '$whitelist["halftone"] = array("title", "transpose");'); $plugins->attachHook('session_started', 'register_special_page(\'HalftoneRender\', \'Halftone AJAX render handler\', false);'); define('KEY_C', 0); @@ -247,6 +247,8 @@ function halftone_process_tags(&$text) { + global $circle_of_fifths; + static $css_added = false; if ( !$css_added ) { @@ -307,15 +309,23 @@ $chord_list = array(); $inner = trim($matches[2][$i]); $song = halftone_render_body($inner, $chord_list); + $src = base64_encode($whole_match); - $key = name_to_key(detect_key($chord_list)); + $origkey = $key = name_to_key(detect_key($chord_list)); + if ( isset($attribs['transpose']) && is_int($tokey = name_to_key($attribs['transpose'])) ) + { + // re-render in new key + $transpose = $tokey - $key; + $song = halftone_render_body($inner, $chord_list, $tokey, $transpose); + $key = $tokey; + } $select = ''; $headid = 'song:' . sanitize_page_id($song_title); @@ -324,12 +334,12 @@ } } -function halftone_render_body($inner, &$chord_list, $inkey = false) +function halftone_render_body($inner, &$chord_list, $inkey = false, $transpose = 0) { global $accidentals; $song = '
'; $chord_list = array(); - $transpose = isset($_GET['transpose']) ? intval($_GET['transpose']) : 0; + $transpose = isset($_GET['transpose']) ? intval($_GET['transpose']) : $transpose; $transpose_accidental = $inkey ? $accidentals[$inkey] : false; foreach ( explode("\n", $inner) as $line ) {