Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //require_once("dompdf/dompdf_config.inc.php");
- class Transposer
- {
- private $type = 'sharps';
- private $notes = array(
- 'scale' => array(
- 'C' => 1,
- 'C#' => 2,
- 'Db' => 2,
- 'D' => 3,
- 'D#' => 4,
- 'Eb' => 4,
- 'E' => 5,
- 'Fb' => 5,
- 'F' => 6,
- 'F#' => 7,
- 'Gb' => 7,
- 'G' => 8,
- 'G#' => 9,
- 'Ab' => 9,
- 'A' => 10,
- 'A#' => 11,
- 'Bb' => 11,
- 'B' => 12,
- 'Cb' => 12
- ),
- 'flats' => array(1 => 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'),
- 'sharps' => array(1 => 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B')
- );
- private $search = '`([ABCDEFG][b#]?(?=\s(?![a-zH-Z])|(?=(2|5|6|7|9|11|13|6\/9|7\-5|7\-9|7\#5|7\#9|7\+5|7\+9|7b5|7b9|7sus2|7sus4|add2|add4|add9|aug|dim|dim7|m\|maj7|m6|m7|m7b5|m9|m11|m13|maj7|maj9|maj11|maj13|mb5|m|sus|sus2|sus4|\))(?=(\s|\/)))|(?=(\/|\.|-|\(|\)))))`';
- private $search2 = '`([ABCDEFG][b#]?[m]?[\(]?(2|5|6|7|9|11|13|6\/9|7\-5|7\-9|7\#5|7\#9|7\+5|7\+9|7b5|7b9|7sus2|7sus4|add2|add4|add9|aug|dim|dim7|m\|maj7|m6|m7|m7b5|m9|m11|m13|maj7|maj9|maj11|maj13|mb5|m|sus|sus2|sus4)?(\))?)(?=\s|\.|\)|-|\/)`';
- private $song;
- private $steps;
- private $formattedChords = array();
- private $replacementChords = array();
- public function __construct($song_,$steps_) {
- $this->song = $song_;
- $this->steps = $steps_;
- preg_match_all($this->search, $this->song, $song_chords);
- //print_r($u = array_unique($song_chords[0]))."\n";
- $u = array_unique($song_chords[0]);
- foreach ($u as $chord){
- if (strlen($chord) > 1 && ($chord{1} == "b" || $chord{1} == "#"))
- array_push($this->formattedChords,substr($chord,0, 2));
- else
- array_push($this->formattedChords,substr($chord,0, 1));
- }
- //print_r($this->formattedChords)."\n";
- $this->song = preg_replace($this->search,'|$1|',$this->song);
- foreach($this->formattedChords as $note) {
- $len = strlen($note);
- $len = $len - 1;
- switch ($note{$len}) {
- case "b":
- $this->transpose($note,'flats',$this->steps);
- break;
- case "#":
- $this->transpose($note,'sharps',$this->steps);
- break;
- default:
- $this->transpose($note,'sharps',$this->steps);
- }
- }
- foreach($this->formattedChords as &$note){
- $note = "/\|".$note."\|/";
- }
- $this->song = preg_replace($this->formattedChords, $this->replacementChords, $this->song);
- $html= preg_replace($this->search2,'<b>$1</b>',$this->song);
- $old = array("<pre>", "\r", "\n", "</pre>");
- $new = array("<pre><span>", "", "</span>\n<span>", "</span></pre>");
- $html ='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><html><body><pre>'.$html.'</pre></body></html>';
- $html = str_replace($old, $new, $html);
- echo $html = str_replace("<span></span>","<span> </span>",$html);
- //$dompdf = new DOMPDF();
- //$dompdf->load_html($html);
- //$dompdf->render();
- //strlen($html);
- //$dompdf->stream("sample.pdf");
- }
- public function transpose($note,$types,$steps){
- if(isset($this->notes['scale'][$note]))
- {
- $ix = $this->notes['scale'][$note];
- }
- else
- {
- user_error("Invalid note '$note'");
- return false;
- }
- $ixNew = $ix + $steps;
- if(!isset($this->notes[$types][$ixNew])) {
- $ixNew += ($ixNew > 0) ? -12 : 12;
- if(!isset($this->notes[$types][$ixNew]))
- throw new Exception("My math skills suck! $note : $steps : $ix : $ixNew");
- }
- array_push($this->replacementChords,$this->notes[$types][$ixNew]);
- //echo "/|".$note."|/";
- }
- }
- //$new_song = preg_replace($u, $new, $song);
- //echo $clean = str_replace('|', '', $new_song);
- $song = "
- God is able - Hillsong
- B
- God is able
- F#
- He will never fail
- Abm E
- He is almighty God
- B
- Greater than all we need
- F#
- Greater than all we have
- Abm E F#
- He has done great things
- Chorus:
- B
- Lifted up
- F#
- Defeated the grave
- Abm
- Raised to life
- E
- Our God is able
- B/D#
- In His name
- F#
- We overcome
- Abm
- For the Lord
- F# E
- Our God is able
- Verse 2:
- God is with us
- God is on our side
- He will make a way
- Far above all we know
- Far above all we hope
- He has done great things
- Bridge:
- B
- God is with us
- F#
- He will go before
- Abm
- He will never leave us
- E
- He will never leave us
- B/D#
- God is for us
- F#
- He has open arms
- Abm F#
- He will never fail us
- E
- He will never fail us
- ";
- $test = new Transposer($song,2);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment