3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mt = new music_theory(); var_dump($mt->get_scale_by_name("C")); /************************************************************* * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com * Fee free to distribute and modify code, but keep reference to its creator * * This class implements music theory for generating scales and chords * based on interval patterns between notes. User can add custom scale and chord pattern. * This class can generate scale notes based on provided scale name and type, * generate chord notes based on provided chord name and type, * transpose scales, transpose chords, * generate all chords that include provided notes, * generate all scales that include provided notes, * * For more information, examples and online documentation visit: * http://webcodingeasy.com/PHP-classes/Implement-music-theory-to-generate-scale-and-chord-notes **************************************************************/ class music_theory { //use sharps or flats private $alt = "sharp"; //array with sharp and flat type notes private $note = array( "sharp" => array("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"), "flat" => array("C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B") ); //array with scale patterns private $scales = array( "major" => array(2,2,1,2,2,2,1), "ionian" => array(2,2,1,2,2,2,1), "minor" => array(2,1,2,2,1,2,2), "aeolian" => array(2,1,2,2,1,2,2), "dorian" => array(2,1,2,2,2,1,2), "phrygian" => array(1,2,2,2,1,2,2), "lydian" => array(2,2,2,1,2,2,1), "mixolydian" => array(2,2,1,2,2,1,2), "locrian" => array(1,2,2,1,2,2,2), "melodic minor asc" => array(2,1,2,2,2,2,1), "melodic minor desc" => array(2,1,2,2,1,2,2), "chromatic" => array(1,1,1,1,1,1,1,1,1,1,1,1), "pentatonic major" => array(2,2,3,2,3), "whole tone" => array(2,2,2,2,2,2), "pentatonic minor" => array(3,2,2,3,2), "pentatonic blues" => array(3,2,1,1,3), "pentatonic neutral" => array(2,3,2,3,2), "lydian augmented" => array(2,2,2,2,1,2,1), "lydian minor" => array(2,2,2,1,1,2,2), "lydian diminished" => array(2,1,3,1,2,2,1), "major blues" => array(2,1,1,3,2,3), "dominant pentatonic" => array(2,2,3,3,2), "blues" => array(3,2,1,1,3,2) ); private $chords = array( "major" => array(4,3), "minor" => array(3,4), "5" => array(7), "aug" => array(4,4), "dim" => array(3,3), "7" => array(4,3,3), "sus4" => array(5,2), "sus2" => array(2,5), "7sus4" => array(5,2,3), "6" => array(4,3,2), "maj7" => array(4,3,4), "9" => array(4,3,3,4), "add9" => array(4,3,7), "m6" => array(3,4,2), "m7" => array(3,4,3), "mmaj7" => array(3,4,4), "m9" => array(3,4,3,4), "11" => array(4,3,3,4,3), "13" => array(4,3,3,4,3,4), "6add9" => array(4,3,2,5), "-5" => array(4,2), "7-5" => array(4,2,4), "7maj5" => array(4,4,2), "maj9" => array(4,3,4,3) ); private $errors = array(); //return array with all notes public function get_notes(){ return $this->note[$this->alt]; } //use flat notation public function set_flat(){ $this->alt = "flat"; } //use sharp notation public function set_sharp(){ $this->alt = "sharp"; } //return array with all defined scale types public function get_scale_types(){ return array_keys($this->scales); } //return array with all defined chord types public function get_chord_types(){ return array_keys($this->chords); } //return all errors and empty error array public function get_errors(){ $arr = $this->errors; $this->errors = array(); return $arr; } //check if all notes are in array private function is_in($notes, $arr) { $is_in = true; foreach($notes as $note) { if(!in_array(ucfirst(strtolower($note)), $arr)) { $is_in = false; } } return $is_in; } /** * add new scale type with interval pattern * Example input: * $type = "ionian"; //new scale type name * $pattern_array = array(2,2,1,2,2,2,1); //interval pattern **/ public function add_scale_type($type, $pattern_array){ $type = strtolower($type); if(!in_array($type, array_keys($this->scales))) { $this->scales[$type] = $pattern_array; } else { $this->errors[] = "Scale type name already used"; return false; } } /** * add new chord type with interval pattern * Example input: * $type = "major"; //new chord type name * $pattern_array = array(4,3); //interval pattern **/ public function add_chord_type($type, $pattern_array){ $type = strtolower($type); if(!in_array($type, array_keys($this->chords))) { $this->chords[$type] = $pattern_array; } else { $this->errors[] = "Chord type name already used"; return false; } } /** * Get scale notes by name and type (optional transpose) * Example input: * $name = "C"; //scale name * $type = "ionian"; //scale type * $transpose = -1 //intervals to transpose to (default value 0 doesn't transpose), negative number tranposes down, positive - up * Example output: * Array * ( * [0] => B * [1] => C# * [2] => D# * [3] => E * [4] => F# * [5] => G# * [6] => A# * [7] => B * ) **/ public function get_scale_by_name($name, $type, $transpose = 0){ $name = strtolower($name); $name = ucfirst($name); $type = strtolower($type); if(!in_array($name, $this->note['sharp'])) { if(!in_array($name, $this->note['flat'])) { $this->errors[] = "Invalid scale name"; return array(); } else { $notes = $this->note["flat"]; } } else { $notes = $this->note["sharp"]; } if(!in_array($type, array_keys($this->scales))) { $this->errors[] = "Invalid scale type"; return array(); } $scale = array(); $start = array_keys($notes, $name); $note_sum = sizeof($notes)-1; if($start[0] + $transpose < 0) { $current = ($start[0] + $transpose) + $note_sum + 1; } else if($start[0] + $transpose > $note_sum) { $current = (($start[0] + $transpose) - $note_sum) -1; } else { $current = $start[0] + $transpose; } $scale[] = $this->note[$this->alt][$current]; foreach($this->scales[$type] as $num) { $current += $num; if($current > $note_sum) { $current -= ($note_sum + 1); } $scale[] = $this->note[$this->alt][$current]; } return $scale; } /** * Get chord notes by name and type (optional transpose) * Example input: * $name = "C"; //chord name * $type = "major"; //chord type * $transpose = 2 //intervals to transpose to (default value 0 doesn't transpose), negative number tranposes down, positive - up * Example output: * Array * ( * [0] => D * [3] => F# * [5] => A * ) */ public function get_chord_by_name($name, $type, $transpose = 0){ $name = strtolower($name); $name = ucfirst($name); $type = strtolower($type); if(!in_array($name, $this->note['sharp'])) { if(!in_array($name, $this->note['flat'])) { $this->errors[] = "Invalid chord name"; return array(); } else { $notes = $this->note["flat"]; } } else { $notes = $this->note["sharp"]; } if(!in_array($type, array_keys($this->chords))) { $this->errors[] = "Invalid chord type"; return array(); } $chord = array(); $start = array_keys($notes, $name); $note_sum = sizeof($notes)-1; if($start[0] + $transpose < 0) { $current = ($start[0] + $transpose) + $note_sum + 1; } else if($start[0] + $transpose > $note_sum) { $current = (($start[0] + $transpose) - $note_sum) -1; } else { $current = $start[0] + $transpose; } $chord[] = $this->note[$this->alt][$current]; foreach($this->chords[$type] as $num) { $current += $num; if($current > $note_sum) { $current -= ($note_sum + 1); } $chord[] = $this->note[$this->alt][$current]; } return $chord; } /** * Get chord names and types by notes * Example input: * $notes = array("A","F","C", "E"); //notes * Example output: * Array * ( * [0] => Array * ( * [name] => C * [type] => 13 * ) * * [1] => Array * ( * [name] => D * [type] => m9 * ) * ... * ) */ public function get_chords_by_notes($notes){ if(!is_array($notes)) { $notes = array($notes); } $possible = array(); $chords = $this->get_chord_types(); for($i = 0; $i < 12; $i++) { foreach($chords as $chord) { $temp = $this->get_chord_by_name("C", $chord, $i); if($this->is_in($notes, $temp)) { $count = sizeof($possible); $possible[$count]["name"] = current($temp); $possible[$count]["type"] = $chord; } } } return $possible; } /** * Get scale names and types by notes * Example input: * $notes = array("C","D","E","G#","C#"); //notes * Example output: * Array * ( * [0] => Array * ( * [name] => C * [type] => chromatic * ) * * [1] => Array * ( * [name] => C# * [type] => chromatic * ) * ... * ) */ public function get_scales_by_notes($notes){ if(!is_array($notes)) { $notes = array($notes); } $possible = array(); $scales = $this->get_scale_types(); for($i = 0; $i < 12; $i++) { foreach($scales as $scale) { $temp = $this->get_scale_by_name("C", $scale, $i); if($this->is_in($notes, $temp)) { $count = sizeof($possible); $possible[$count]["name"] = current($temp); $possible[$count]["type"] = $scale; } } } return $possible; } /** * Get scale names and types by chord names/types * Provide different chord names with types, * and receive array with all scale names/types which suits provided chords * * Example input: * $chords = array(array("name" => "C", "type" => "major"), array("name" => "A", "type" => "minor")); //chord array * Example output: * Array * ( * [0] => Array * ( * [name] => C * [type] => major * ) * * [1] => Array * ( * [name] => C * [type] => ionian * ) * ... * ) */ public function get_scales_by_chords($chords){ $notes = array(); foreach($chords as $chord) { $chord_notes = $this->get_chord_by_name(ucfirst(strtolower($chord["name"])), $chord["type"]); $notes = array_merge($notes, $chord_notes); } $notes = array_unique($notes); $possible = array(); $scales = $this->get_scale_types(); for($i = 0; $i < 12; $i++) { foreach($scales as $scale) { $temp = $this->get_scale_by_name("C", $scale, $i); if($this->is_in($notes, $temp)) { $count = sizeof($possible); $possible[$count]["name"] = current($temp); $possible[$count]["type"] = $scale; } } } return $possible; } /** * Get chord names and types by scale * Provide scale name and type * and receive all chord names/types which suits provided scale * * Example input: * $scale_name = "C"; //scale name * $scale_type = "ionian" //scale type * Example output: * Array * ( * [0] => Array * ( * [name] => C * [type] => minor * ) * * [1] => Array * ( * [name] => C * [type] => 5 * ) * ... * ) */ public function get_chords_by_scale($scale_name, $scale_type){ $scale_notes = $this->get_scale_by_name(ucfirst(strtolower($scale_name)), strtolower($scale_type)); if(!empty($scale_notes)) { $possible = array(); $chords = $this->get_chord_types(); for($i = 0; $i < 12; $i++) { foreach($chords as $chord) { $temp = $this->get_chord_by_name("C", $chord, $i); if($this->is_in($temp, $scale_notes)) { $count = sizeof($possible); $possible[$count]["name"] = current($temp); $possible[$count]["type"] = $chord; } } } return $possible; } } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  (null)
number of ops:  10
compiled vars:  !0 = $mt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   NEW                                              $1      'music_theory'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
    7     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'get_scale_by_name'
          5        SEND_VAL_EX                                              'C'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
  498     9      > RETURN                                                   1

Class music_theory:
Function get_notes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  get_notes
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   FETCH_OBJ_R                                      ~1      'alt'
          1        FETCH_OBJ_R                                      ~0      'note'
          2        FETCH_DIM_R                                      ~2      ~0, ~1
          3      > RETURN                                                   ~2
   92     4*     > RETURN                                                   null

End of function get_notes

Function set_flat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  set_flat
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   ASSIGN_OBJ                                               'alt'
          1        OP_DATA                                                  'flat'
   97     2      > RETURN                                                   null

End of function set_flat

Function set_sharp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  set_sharp
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   ASSIGN_OBJ                                               'alt'
          1        OP_DATA                                                  'sharp'
  102     2      > RETURN                                                   null

End of function set_sharp

Function get_scale_types:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  get_scale_types
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  106     0  E >   INIT_FCALL                                               'array_keys'
          1        FETCH_OBJ_R                                      ~0      'scales'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
  107     5*     > RETURN                                                   null

End of function get_scale_types

Function get_chord_types:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  get_chord_types
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  111     0  E >   INIT_FCALL                                               'array_keys'
          1        FETCH_OBJ_R                                      ~0      'chords'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
  112     5*     > RETURN                                                   null

End of function get_chord_types

Function get_errors:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  get_errors
number of ops:  6
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  116     0  E >   FETCH_OBJ_R                                      ~1      'errors'
          1        ASSIGN                                                   !0, ~1
  117     2        ASSIGN_OBJ                                               'errors'
          3        OP_DATA                                                  <array>
  118     4      > RETURN                                                   !0
  119     5*     > RETURN                                                   null

End of function get_errors

Function is_in:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/C7j53
function name:  is_in
number of ops:  22
compiled vars:  !0 = $notes, !1 = $arr, !2 = $is_in, !3 = $note
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  122     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  124     2        ASSIGN                                                   !2, <true>
  125     3      > FE_RESET_R                                       $5      !0, ->19
          4    > > FE_FETCH_R                                               $5, !3, ->19
  127     5    >   INIT_FCALL                                               'in_array'
          6        INIT_FCALL                                               'ucfirst'
          7        INIT_FCALL                                               'strtolower'
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        SEND_VAR                                                 $7
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $8      
         15        BOOL_NOT                                         ~9      $8
         16      > JMPZ                                                     ~9, ->18
  129    17    >   ASSIGN                                                   !2, <false>
  125    18    > > JMP                                                      ->4
         19    >   FE_FREE                                                  $5
  132    20      > RETURN                                                   !2
  133    21*     > RETURN                                                   null

End of function is_in

Function add_scale_type:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  add_scale_type
number of ops:  25
compiled vars:  !0 = $type, !1 = $pattern_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  141     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  142     2        INIT_FCALL                                               'strtolower'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !0, $2
  143     6        INIT_FCALL                                               'in_array'
          7        SEND_VAR                                                 !0
          8        INIT_FCALL                                               'array_keys'
          9        FETCH_OBJ_R                                      ~4      'scales'
         10        SEND_VAL                                                 ~4
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                         $6      
         14        BOOL_NOT                                         ~7      $6
         15      > JMPZ                                                     ~7, ->20
  145    16    >   FETCH_OBJ_W                                      $8      'scales'
         17        ASSIGN_DIM                                               $8, !0
         18        OP_DATA                                                  !1
         19      > JMP                                                      ->24
  149    20    >   FETCH_OBJ_W                                      $10     'errors'
         21        ASSIGN_DIM                                               $10
         22        OP_DATA                                                  'Scale+type+name+already+used'
  150    23      > RETURN                                                   <false>
  152    24    > > RETURN                                                   null

End of function add_scale_type

Function add_chord_type:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7j53
function name:  add_chord_type
number of ops:  25
compiled vars:  !0 = $type, !1 = $pattern_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  160     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  161     2        INIT_FCALL                                               'strtolower'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !0, $2
  162     6        INIT_FCALL                                               'in_array'
          7        SEND_VAR                                                 !0
          8        INIT_FCALL                                               'array_keys'
          9        FETCH_OBJ_R                                      ~4      'chords'
         10        SEND_VAL                                                 ~4
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                         $6      
         14        BOOL_NOT                                         ~7      $6
         15      > JMPZ                                                     ~7, ->20
  164    16    >   FETCH_OBJ_W                                      $8      'chords'
         17        ASSIGN_DIM                                               $8, !0
         18        OP_DATA                                                  !1
         19      > JMP                                                      ->24
  168    20    >   FETCH_OBJ_W                                      $10     'errors'
         21        ASSIGN_DIM                                               $10
         22        OP_DATA                                                  'Chord+type+name+already+used'
  169    23      > RETURN                                                   <false>
  171    24    > > RETURN                                                   null

End of function add_chord_type

Function get_scale_by_name:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 40
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 76
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 77) Position 1 = 98, Position 2 = 111
Branch analysis from position: 98
2 jumps found. (Code = 78) Position 1 = 99, Position 2 = 111
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 104
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
Branch analysis from position: 104
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 111
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 86
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
Branch analysis from position: 86
2 jumps found. (Code = 77) Position 1 = 98, Position 2 = 111
Branch analysis from position: 98
Branch analysis from position: 111
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
Branch analysis from position: 57
filename:       /in/C7j53
function name:  get_scale_by_name
number of ops:  114
compiled vars:  !0 = $name, !1 = $type, !2 = $transpose, !3 = $notes, !4 = $scale, !5 = $start, !6 = $note_sum, !7 = $current, !8 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  192     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
  193     3        INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !0, $9
  194     7        INIT_FCALL                                               'ucfirst'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !0, $11
  195    11        INIT_FCALL                                               'strtolower'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !1, $13
  196    15        INIT_FCALL                                               'in_array'
         16        SEND_VAR                                                 !0
         17        FETCH_OBJ_R                                      ~15     'note'
         18        FETCH_DIM_R                                      ~16     ~15, 'sharp'
         19        SEND_VAL                                                 ~16
         20        DO_ICALL                                         $17     
         21        BOOL_NOT                                         ~18     $17
         22      > JMPZ                                                     ~18, ->40
  198    23    >   INIT_FCALL                                               'in_array'
         24        SEND_VAR                                                 !0
         25        FETCH_OBJ_R                                      ~19     'note'
         26        FETCH_DIM_R                                      ~20     ~19, 'flat'
         27        SEND_VAL                                                 ~20
         28        DO_ICALL                                         $21     
         29        BOOL_NOT                                         ~22     $21
         30      > JMPZ                                                     ~22, ->36
  200    31    >   FETCH_OBJ_W                                      $23     'errors'
         32        ASSIGN_DIM                                               $23
         33        OP_DATA                                                  'Invalid+scale+name'
  201    34      > RETURN                                                   <array>
         35*       JMP                                                      ->39
  205    36    >   FETCH_OBJ_R                                      ~25     'note'
         37        FETCH_DIM_R                                      ~26     ~25, 'flat'
         38        ASSIGN                                                   !3, ~26
         39      > JMP                                                      ->43
  210    40    >   FETCH_OBJ_R                                      ~28     'note'
         41        FETCH_DIM_R                                      ~29     ~28, 'sharp'
         42        ASSIGN                                                   !3, ~29
  212    43    >   INIT_FCALL                                               'in_array'
         44        SEND_VAR                                                 !1
         45        INIT_FCALL                                               'array_keys'
         46        FETCH_OBJ_R                                      ~31     'scales'
         47        SEND_VAL                                                 ~31
         48        DO_ICALL                                         $32     
         49        SEND_VAR                                                 $32
         50        DO_ICALL                                         $33     
         51        BOOL_NOT                                         ~34     $33
         52      > JMPZ                                                     ~34, ->57
  214    53    >   FETCH_OBJ_W                                      $35     'errors'
         54        ASSIGN_DIM                                               $35
         55        OP_DATA                                                  'Invalid+scale+type'
  215    56      > RETURN                                                   <array>
  217    57    >   ASSIGN                                                   !4, <array>
  218    58        INIT_FCALL                                               'array_keys'
         59        SEND_VAR                                                 !3
         60        SEND_VAR                                                 !0
         61        DO_ICALL                                         $38     
         62        ASSIGN                                                   !5, $38
  219    63        COUNT                                            ~40     !3
         64        SUB                                              ~41     ~40, 1
         65        ASSIGN                                                   !6, ~41
  220    66        FETCH_DIM_R                                      ~43     !5, 0
         67        ADD                                              ~44     ~43, !2
         68        IS_SMALLER                                               ~44, 0
         69      > JMPZ                                                     ~45, ->76
  222    70    >   FETCH_DIM_R                                      ~46     !5, 0
         71        ADD                                              ~47     ~46, !2
         72        ADD                                              ~48     ~47, !6
         73        ADD                                              ~49     ~48, 1
         74        ASSIGN                                                   !7, ~49
         75      > JMP                                                      ->89
  224    76    >   FETCH_DIM_R                                      ~51     !5, 0
         77        ADD                                              ~52     ~51, !2
         78        IS_SMALLER                                               !6, ~52
         79      > JMPZ                                                     ~53, ->86
  226    80    >   FETCH_DIM_R                                      ~54     !5, 0
         81        ADD                                              ~55     ~54, !2
         82        SUB                                              ~56     ~55, !6
         83        SUB                                              ~57     ~56, 1
         84        ASSIGN                                                   !7, ~57
         85      > JMP                                                      ->89
  230    86    >   FETCH_DIM_R                                      ~59     !5, 0
         87        ADD                                              ~60     ~59, !2
         88        ASSIGN                                                   !7, ~60
  232    89    >   FETCH_OBJ_R                                      ~64     'alt'
         90        FETCH_OBJ_R                                      ~63     'note'
         91        FETCH_DIM_R                                      ~65     ~63, ~64
         92        FETCH_DIM_R                                      ~66     ~65, !7
         93        ASSIGN_DIM                                               !4
         94        OP_DATA                                                  ~66
  233    95        FETCH_OBJ_R                                      ~67     'scales'
         96        FETCH_DIM_R                                      ~68     ~67, !1
         97      > FE_RESET_R                                       $69     ~68, ->111
         98    > > FE_FETCH_R                                               $69, !8, ->111
  235    99    >   ASSIGN_OP                                     1          !7, !8
  236   100        IS_SMALLER                                               !6, !7
        101      > JMPZ                                                     ~71, ->104
  238   102    >   ADD                                              ~72     !6, 1
        103        ASSIGN_OP                                     2          !7, ~72
  240   104    >   FETCH_OBJ_R                                      ~76     'alt'
        105        FETCH_OBJ_R                                      ~75     'note'
        106        FETCH_DIM_R                                      ~77     ~75, ~76
        107        FETCH_DIM_R                                      ~78     ~77, !7
        108        ASSIGN_DIM                                               !4
        109        OP_DATA                                                  ~78
  233   110      > JMP                                                      ->98
        111    >   FE_FREE                                                  $69
  242   112      > RETURN                                                   !4
  243   113*     > RETURN                                                   null

End of function get_scale_by_name

Function get_chord_by_name:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 40
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 76
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 77) Position 1 = 98, Position 2 = 111
Branch analysis from position: 98
2 jumps found. (Code = 78) Position 1 = 99, Position 2 = 111
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 104
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
Branch analysis from position: 104
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 111
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 86
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
Branch analysis from position: 86
2 jumps found. (Code = 77) Position 1 = 98, Position 2 = 111
Branch analysis from position: 98
Branch analysis from position: 111
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
Branch analysis from position: 57
filename:       /in/C7j53
function name:  get_chord_by_name
number of ops:  114
compiled vars:  !0 = $name, !1 = $type, !2 = $transpose, !3 = $notes, !4 = $chord, !5 = $start, !6 = $note_sum, !7 = $current, !8 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  259     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
  260     3        INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !0, $9
  261     7        INIT_FCALL                                               'ucfirst'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !0, $11
  262    11        INIT_FCALL                                               'strtolower'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !1, $13
  263    15        INIT_FCALL                                               'in_array'
         16        SEND_VAR                                                 !0
         17        FETCH_OBJ_R                                      ~15     'note'
         18        FETCH_DIM_R                                      ~16     ~15, 'sharp'
         19        SEND_VAL                                                 ~16
         20        DO_ICALL                                         $17     
         21        BOOL_NOT                                         ~18     $17
         22      > JMPZ                                                     ~18, ->40
  265    23    >   INIT_FCALL                                               'in_array'
         24        SEND_VAR                                                 !0
         25        FETCH_OBJ_R                                      ~19     'note'
         26        FETCH_DIM_R                                      ~20     ~19, 'flat'
         27        SEND_VAL                                                 ~20
         28        DO_ICALL                                         $21     
         29        BOOL_NOT                                         ~22     $21
         30      > JMPZ                                                     ~22, ->36
  267    31    >   FETCH_OBJ_W                                      $23     'errors'
         32        ASSIGN_DIM                                               $23
         33        OP_DATA                                                  'Invalid+chord+name'
  268    34      > RETURN                                                   <array>
         35*       JMP                                                      ->39
  272    36    >   FETCH_OBJ_R                                      ~25     'note'
         37        FETCH_DIM_R                                      ~26     ~25, 'flat'
         38        ASSIGN                                                   !3, ~26
         39      > JMP                                                      ->43
  277    40    >   FETCH_OBJ_R                                      ~28     'note'
         41        FETCH_DIM_R                                      ~29     ~28, 'sharp'
         42        ASSIGN                                                   !3, ~29
  279    43    >   INIT_FCALL                                               'in_array'
         44        SEND_VAR                                                 !1
         45        INIT_FCALL                                               'array_keys'
         46        FETCH_OBJ_R                                      ~31     'chords'
         47        SEND_VAL                                                 ~31
         48        DO_ICALL                                         $32     
         49        SEND_VAR                                                 $32
         50        DO_ICALL                                         $33     
         51        BOOL_NOT                                         ~34     $33
         52      > JMPZ                                                     ~34, ->57
  281    53    >   FETCH_OBJ_W                                      $35     'errors'
         54        ASSIGN_DIM                                               $35
         55        OP_DATA                                                  'Invalid+chord+type'
  282    56  

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
264.12 ms | 1428 KiB | 24 Q