Advertisement
Omnikron13

phpmusic Interval class draft 1

Jan 21st, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. class Interval {
  4.     protected static $names = [
  5.         0   => ["Perfect unison", "P1"],
  6.         1   => ["Minor second", "m2", "S"],
  7.         2   => ["Major second", "M2", "T"],
  8.         3   => ["Minor third", "m3"],
  9.         4   => ["Major third", "M3"],
  10.         5   => ["Perfect fourth", "P4"],
  11.         6   => ["Diminished fifth", "Augmented fourth"],
  12.         7   => ["Perfect fifth", "P5"],
  13.         8   => ["Minor sixth", "m6"],
  14.         9   => ["Major sixth", "M6"],
  15.         10  => ["Minor seventh", "m7"],
  16.         11  => ["Major seventh", "M7"],
  17.         12  => ["Perfect octave", "P8"],
  18.     ];
  19.  
  20.     protected $size;
  21.  
  22.     public function __get($name) {
  23.         switch ($name) {
  24.             case "Size":
  25.                 return $this->size;
  26.             case "Name":
  27.                 return self::$names[$this->Size][0] ?: $this->Size.'S';
  28.         }
  29.     }
  30.  
  31.     public function __toString() {
  32.         return $this->Name;
  33.     }
  34.  
  35.     public function __construct($size) {
  36.         if(is_string($size)) {
  37.             foreach(self::$names as $k => $v) {
  38.                 if(in_array($size, $v)) {
  39.                     $size = $k;
  40.                     break;
  41.                 }
  42.             }
  43.         }
  44.         $this->size = $size;
  45.     }
  46. }
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement