Esempio n. 1
0
 public function execute($value = false, $params = array())
 {
     try {
         $scale = Scale::parse($value);
     } catch (Exception $ex) {
         throw new Exception(sprintf('Option "%s" must be 2 integeres separated by a colon (:)', $this->option->name));
     }
     $this->setResult($scale->simplify());
 }
Esempio n. 2
0
 public function getByScale($name, $type)
 {
     $scale = new Scale();
     $name = Strings::strtoupper($name);
     $type = Strings::underscore($type);
     $scale->getByName($name, $type);
     $scale_notes = $scale->notes;
     if (isset($scale_notes) && count($scale_notes) > 0) {
         $this->possible = array();
         $chords = $this->getTypes();
         for ($i = 0; $i < 12; $i++) {
             foreach ($chords as $chord) {
                 $this->chord = null;
                 $this->getByName("C", $chord, $i);
                 if ($this->containsNotes($this->chord, $scale_notes)) {
                     array_push($this->possible, array("name" => current($this->chord), "type" => $chord));
                 }
             }
         }
         return $this->possible;
     }
 }
Esempio n. 3
0
 /**
  * analyze the current layer, and return an array of all the Scales that its notes fit into.
  * @param  Pitch  $root  if the root is known and we only want to learn about matching modes, provide a Pitch for the root.
  * @return [type] [description]
  */
 public function getScales($root = null)
 {
     $scales = Scale::getScales($this);
 }
Esempio n. 4
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<html>
<head>
    <meta name="viewport" content="initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no">

<?php 
require_once '../PHPMusicXML.php';
$scale = new Scale(array('root' => new Pitch('C4'), 'mode' => 'prometheus'));
$measureOptions = array('divisions' => 4, 'key' => new Key('C major'), 'time' => array('beats' => 6, 'beat-type' => 8), 'clef' => array(new Clef('treble'), new Clef('bass')), 'barline' => array(new Barline(array('location' => 'left', 'bar-style' => 'light-heavy', 'repeat' => array('direction' => 'forward', 'winged' => 'none'), 'ending' => array('type' => 'stop', 'number' => 1))), new Barline(array('location' => 'right', 'bar-style' => 'heavy-light', 'repeat' => array('direction' => 'backward'), 'ending' => array('type' => 'stop', 'number' => 2)))), 'implicit' => false, 'non-controlling' => false, 'number' => 1, 'width' => 180);
$pitches = $scale->getPitches();
//var_dump($pitches);
$score = new Score();
$part = new Part('Piano');
$measure = new Measure($measureOptions);
$layer = new Layer();
foreach ($pitches as $pitch) {
    $note = new Note(array('pitch' => $pitch, 'duration' => 4, 'type' => 'quarter'));
    $layer->addNote($note);
    // this essentially adds a chord with only one note in it.
}
$measure->addLayer($layer);
$newlayer = clone $layer;
$newlayer->transpose(-12);
$measure->addLayer($newlayer);
// puts this layer in staff two
$newlayer->setStaff(2);
for ($i = 0; $i < 12; $i++) {
Esempio n. 5
0
 public function run()
 {
     /******************************************************************************
      * --- Test ---
      ******************************************************************************/
     Test::create(array('name' => 'BURNOUT', 'idTestType' => '2'));
     /******************************************************************************
      * --- Escalas ---
      ******************************************************************************/
     Scale::create(array('idTest' => '4', 'description' => 'Reducida Sensación'));
     Scale::create(array('idTest' => '4', 'description' => 'Agotamiento'));
     Scale::create(array('idTest' => '4', 'description' => 'Devaluación'));
     /******************************************************************************
      * --- Rangos Posibles ---
      ******************************************************************************/
     Range::create(array('description' => 'Bajo', 'min' => '5.0', 'max' => '11.0'));
     Range::create(array('description' => 'Medio', 'min' => '12.0', 'max' => '18.0'));
     Range::create(array('description' => 'Alto', 'min' => '19.0', 'max' => '25.0'));
     /******************************************************************************
      * --- Rangos por Escala ---
      ******************************************************************************/
     // Reducida Sensación
     ScaleRange::create(array('idScale' => '12', 'idRange' => '10'));
     ScaleRange::create(array('idScale' => '12', 'idRange' => '11'));
     ScaleRange::create(array('idScale' => '12', 'idRange' => '12'));
     // Agotamiento
     ScaleRange::create(array('idScale' => '13', 'idRange' => '10'));
     ScaleRange::create(array('idScale' => '13', 'idRange' => '11'));
     ScaleRange::create(array('idScale' => '13', 'idRange' => '12'));
     // Devaluación
     ScaleRange::create(array('idScale' => '14', 'idRange' => '10'));
     ScaleRange::create(array('idScale' => '14', 'idRange' => '11'));
     ScaleRange::create(array('idScale' => '14', 'idRange' => '12'));
     /******************************************************************************
      * --- Grupos ---
      ******************************************************************************/
     Group::create(array());
     // Burnout (orden normal) Con id = 5
     Group::create(array());
     // Burnout (orden inverso) Con id = 6
     /******************************************************************************
      * --- Posibles Respuestas ---
      ******************************************************************************/
     // --- BURNOUT (orden normal) ---
     TestAnswer::create(array('number' => '1', 'description' => 'Casi nunca', 'idGroup' => '5'));
     TestAnswer::create(array('number' => '2', 'description' => 'Pocas veces', 'idGroup' => '5'));
     TestAnswer::create(array('number' => '3', 'description' => 'Algunas veces', 'idGroup' => '5'));
     TestAnswer::create(array('number' => '4', 'description' => 'A menudo', 'idGroup' => '5'));
     TestAnswer::create(array('number' => '5', 'description' => 'Casi siempre', 'idGroup' => '5'));
     // --- BURNOUT (orden inverso) ---
     TestAnswer::create(array('number' => '5', 'description' => 'Casi nunca', 'idGroup' => '6'));
     TestAnswer::create(array('number' => '4', 'description' => 'Pocas veces', 'idGroup' => '6'));
     TestAnswer::create(array('number' => '3', 'description' => 'Algunas veces', 'idGroup' => '6'));
     TestAnswer::create(array('number' => '2', 'description' => 'A menudo', 'idGroup' => '6'));
     TestAnswer::create(array('number' => '1', 'description' => 'Casi siempre', 'idGroup' => '6'));
     /******************************************************************************
      * --- Preguntas ---
      ******************************************************************************/
     $burnout = '4';
     $reducidaSensacion = '12';
     $agotamiento = '13';
     $devaluacion = '14';
     $grupoBurnoutNormal = '5';
     $grupoBurnoutInverso = '6';
     Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '1', 'description' => 'Siento que estoy logrando muchas cosas que valen la pena en mi deporte.', 'idGroup' => $grupoBurnoutInverso));
     Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '2', 'description' => 'Me siento tan cansado de mis entrenamientos que tengo problemas al encontrar energía para hacer otras cosas.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '3', 'description' => 'El esfuerzo y tiempo que dedico a mi deporte estaría mejor invertido realizando otras actividades más productivas.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '4', 'description' => 'Me siento demasiado cansado debido a mis actividades en mi deporte.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '5', 'description' => 'No estoy consiguiendo logros importantes en mi deporte.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '6', 'description' => 'No me importa tanto mi rendimiento en mi deporte como antes.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '7', 'description' => 'No estoy rindiendo de acuerdo a mi verdadera capacidad en mi deporte.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '8', 'description' => 'Me siento "desgastado" física y emocionalmente por debido a mi deporte.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '9', 'description' => 'No estoy tan interesado en mi deporte como acostumbraba hacerlo antes.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '10', 'description' => 'Me siento físicamente agotado por debido a mi deporte.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '11', 'description' => 'Me siento menos preocupado por tener éxito en mi deporte de lo que solía hacerlo.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '12', 'description' => 'Estoy agotado por las exigencias físicas y mentales de mi deporte.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '13', 'description' => 'Parece que no importa lo que haga, no logro rendir tan bien como podría hacerlo.', 'idGroup' => $grupoBurnoutNormal));
     Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '14', 'description' => 'Me siento exitoso en mi deporte.', 'idGroup' => $grupoBurnoutInverso));
     Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '15', 'description' => 'Tengo sentimientos y pensamientos negativos hacia mi deporte.', 'idGroup' => $grupoBurnoutNormal));
 }
Esempio n. 6
0
 public function scale(Scale $scale, $tilesize, $outdir, SimpleXMLElement $layerXML)
 {
     $newBounds = clone $this->bounds;
     $_scale = $scale->unscale($this->input_scale);
     $newBounds->scale($_scale, $newBounds->left, $newBounds->top);
     //Check if scale is "even" according to chunk size
     $pieces_x = $newBounds->width / $tilesize;
     if (floor($pieces_x) != $pieces_x) {
         throw new Exception("Uneven number of horizontal pieces would be created: " . $pieces_x);
     }
     $pieces_y = $newBounds->height / $tilesize;
     if (floor($pieces_y) != $pieces_y) {
         throw new Exception("Uneven number of vertical pieces would be created: " . $pieces_y);
     }
     $full_size = $this->bounds->width / $pieces_x;
     echo sprintf("Scaling %d,%d ->(%d/%d)-> %d,%d with %dx%d chunks from (%d,%d)\n", $this->bounds->width, $this->bounds->height, $scale->num, $scale->den, $newBounds->width, $newBounds->height, $tilesize, $tilesize, $full_size, $full_size);
     $layerXML['width'] = $newBounds->width;
     $layerXML['height'] = $newBounds->height;
     $layerXML['tilesize'] = $tilesize;
     for ($_y = 0; $_y < $pieces_y; $_y++) {
         for ($_x = 0; $_x < $pieces_x; $_x++) {
             $src_rect = new Rect(array($_x * $full_size + $this->bounds->left, $_y * $full_size + $this->bounds->top));
             $src_rect->setDimensions($full_size, $full_size);
             $dst_rect = new Rect(array($_x * $tilesize + $this->bounds->left, $_y * $tilesize + $this->bounds->top));
             $dst_rect->setDimensions($tilesize, $tilesize);
             $file = sprintf("%d_%d.jpg", $dst_rect->top, $dst_rect->left);
             echo "Building piece ", $file, "\n";
             $img = $this->fetchMapSection($src_rect, $dst_rect);
             imageinterlace($img, true);
             imagejpeg($img, $outdir . DIRECTORY_SEPARATOR . $file);
             imagedestroy($img);
             // Write Map XML
             $piece = $layerXML->addChild('piece');
             $piece['file'] = $file;
             $piece['left'] = $dst_rect->left;
             $piece['top'] = $dst_rect->top;
         }
     }
     $layerXML->asXML($outdir . DIRECTORY_SEPARATOR . 'layer.xml');
 }
Esempio n. 7
0
<?php

use ianring\PHPMusicXML;
error_reporting(E_ALL);
ini_set('display_errors', 1);
//require_once SITE_ROOT . '/current/vendor/autoload.php';
require_once '../PHPMusicXML.php';
$score = new Score();
$part = new Part('Viola');
$scale = new Scale(array('root' => new Pitch('D4'), 'mode' => 'lydian augmented'));
$pitches = $scale->getPitches();
$measure = new Measure();
foreach ($pitches as $pitch) {
    $measure->addNote(new Note(array('pitch' => $pitch, 'duration' => 4)));
}
$part->addMeasure($measure);
$scale->setProperty('mode', 'bebop dominant');
$pitches = $scale->getPitches();
$measure = new Measure();
foreach ($pitches as $pitch) {
    $measure->addNote(new Note(array('pitch' => $pitch, 'duration' => 4)));
}
$part->addMeasure($measure);
$score->addPart($part);
$part->addMeasure($measure);
$xml2 = $score->toXML('partwise');
?>
<html>
<head>
    <meta name="viewport" content="initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no">
Esempio n. 8
0
 private function parseText()
 {
     $o = Scale::getInstance();
     /*
      * The style options deserve some comments. The monospace and font-size
      * choices are not accidental. This gives the best sort of estimation
      * for font size to scale that I could come up with empirically.
      *
      * N.B. This might change with different scales. I kind of feel like this
      * is a bug waiting to be filed, but whatever.
      */
     $fSize = 0.95 * $o->yScale;
     $this->svgObjects->pushGroup('text');
     $this->svgObjects->setOption('fill', 'black');
     $this->svgObjects->setOption('style', "font-family:LMMono10,monospace;font-size:{$fSize}px");
     /*
      * Text gets the same scanning treatment as boxes. We do left-to-right
      * scanning, which should probably be configurable in case someone wants
      * to use this with e.g. Arabic or some other right-to-left language.
      * Either way, this isn't UTF-8 safe (thanks, PHP!!!), so that'll require
      * thought regardless.
      */
     $boxes = $this->svgObjects->getGroup('boxes');
     $bound = count($boxes);
     foreach ($this->grid as $row => $line) {
         $cols = count($line);
         for ($i = 0; $i < $cols; $i++) {
             if ($this->getChar($row, $i) != ' ') {
                 /* More magic numbers that probably need research. */
                 $t = new SVGText($i - 0.6, $row + 0.3);
                 /* Time to figure out which (if any) box we live inside */
                 $tP = $t->getPoint();
                 $maxPoint = new Point(-1, -1);
                 $boxQueue = array();
                 for ($j = 0; $j < $bound; $j++) {
                     if ($boxes[$j]->hasPoint($tP->gridX, $tP->gridY)) {
                         $boxPoints = $boxes[$j]->getPoints();
                         $boxTL = $boxPoints[0];
                         /*
                          * This text is in this box, but it may still be in a more
                          * specific nested box. Find the box with the highest top
                          * left X,Y coordinate. Keep a queue of boxes in case the top
                          * most box doesn't have a fill.
                          */
                         if ($boxTL->y > $maxPoint->y && $boxTL->x > $maxPoint->x) {
                             $maxPoint->x = $boxTL->x;
                             $maxPoint->y = $boxTL->y;
                             $boxQueue[] = $boxes[$j];
                         }
                     }
                 }
                 if (count($boxQueue) > 0) {
                     /*
                      * Work backwards through the boxes to find the box with the most
                      * specific fill.
                      */
                     for ($j = count($boxQueue) - 1; $j >= 0; $j--) {
                         $fill = $boxQueue[$j]->getOption('fill');
                         if ($fill == 'none' || $fill == null) {
                             continue;
                         }
                         if (substr($fill, 0, 1) != '#') {
                             if (!isset($GLOBALS['A2S_colors'][strtolower($fill)])) {
                                 continue;
                             } else {
                                 $fill = $GLOBALS['A2S_colors'][strtolower($fill)];
                             }
                         } else {
                             if (strlen($fill) != 4 && strlen($fill) != 7) {
                                 continue;
                             }
                         }
                         if ($fill) {
                             /* Attempt to parse the fill color */
                             if (strlen($fill) == 4) {
                                 $cR = hexdec(str_repeat($fill[1], 2));
                                 $cG = hexdec(str_repeat($fill[2], 2));
                                 $cB = hexdec(str_repeat($fill[3], 2));
                             } elseif (strlen($fill) == 7) {
                                 $cR = hexdec(substr($fill, 1, 2));
                                 $cG = hexdec(substr($fill, 3, 2));
                                 $cB = hexdec(substr($fill, 5, 2));
                             }
                             /*
                              * This magic is gleaned from the working group paper on
                              * accessibility at http://www.w3.org/TR/AERT. The recommended
                              * contrast is a brightness difference of at least 125 and a
                              * color difference of at least 500. Since our default color
                              * is black, that makes the color difference easier.
                              */
                             $bFill = ($cR * 299 + $cG * 587 + $cB * 114) / 1000;
                             $bDiff = $cR + $cG + $cB;
                             $bText = 0;
                             if ($bFill - $bText < 125 || $bDiff < 500) {
                                 /* If black is too dark, white will work */
                                 $t->setOption('fill', '#fff');
                             } else {
                                 $t->setOption('fill', '#000');
                             }
                             break;
                         }
                     }
                     if ($j < 0) {
                         $t->setOption('fill', '#000');
                     }
                 } else {
                     /* This text isn't inside a box; make it black */
                     $t->setOption('fill', '#000');
                 }
                 /* We found a stringy character, eat it and the rest. */
                 $str = $this->getChar($row, $i++);
                 while ($i < count($line) && $this->getChar($row, $i) != ' ') {
                     $str .= $this->getChar($row, $i++);
                     /* Eat up to 1 space */
                     if ($this->getChar($row, $i) == ' ') {
                         $str .= ' ';
                         $i++;
                     }
                 }
                 if ($str == '') {
                     continue;
                 }
                 $t->setString($str);
                 /*
                  * If we were in a box, group with the box. Otherwise it gets its
                  * own group.
                  */
                 if (count($boxQueue) > 0) {
                     $t->setOption('stroke', 'none');
                     $t->setOption('style', "font-family:LMMono10,monospace;font-size:{$fSize}px");
                     $boxQueue[count($boxQueue) - 1]->addText($t);
                 } else {
                     $this->svgObjects->addObject($t);
                 }
             }
         }
     }
 }