Exemplo n.º 1
0
 /**
  * @param File $file input file to read
  */
 public function __construct(File $file)
 {
     parent::__construct($file);
     $this->readVersion();
     if (!$this->isSupportedVersion($this->getVersion())) {
         $this->closeStream();
         throw new Exception(sprintf('Version "%s" is not supported', $this->getVersion()));
     }
     $song = new Song();
     $this->setTablature($song);
     $this->factory('GuitarPro3Informations')->readInformations($song);
     $this->tripletFeel = $this->readBoolean() ? MeasureHeader::TRIPLET_FEEL_EIGHTH : MeasureHeader::TRIPLET_FEEL_NONE;
     $tempoValue = $this->readInt();
     $this->keySignature = $this->factory('GuitarProKeySignature')->readKeySignature();
     $this->skip(3);
     # Meta only
     if (Config::get('type') == 'meta') {
         $this->closeStream();
         return;
     }
     $channels = $this->factory('GuitarProChannels')->readChannels();
     $measures = $this->readInt();
     $tracks = $this->readInt();
     $this->readMeasureHeaders($song, $measures);
     $this->readTracks($song, $tracks, $channels);
     # Meta+channels+tracks+measure headers only
     if (Config::get('type') == 'channels') {
         $this->closeStream();
         return;
     }
     $this->factory('GuitarPro3Measures')->readMeasures($song, $measures, $tracks, $tempoValue);
     $this->closeStream();
 }
Exemplo n.º 2
0
 public function testConfig()
 {
     Config::clear();
     # bad key format scenario
     $this->assertEquals(null, Config::get(array(42)));
     Config::set(array(42), 42);
     $this->assertEquals(null, Config::get(array(42)));
     # sets a good key
     Config::set('Sense', 42);
     $this->assertEquals(42, Config::get('Sense'));
     # Gets all configs
     $expected = array('Sense' => 42);
     $this->assertEquals($expected, Config::getAll());
 }
Exemplo n.º 3
0
 public function testLog()
 {
     Log::clear();
     Config::set('verbose', true);
     # Empty log
     $this->assertEquals(0, Log::countLogs());
     $this->assertEquals(array(), Log::tail(4));
     # Adds a default type message
     $this->expectOutputString("\n[NOTICE] Log with default type");
     Log::add('Log with default type');
     $expected = array(0 => array('type' => 'NOTICE', 'message' => 'Log with default type'));
     $this->assertEquals($expected, Log::tail(42));
     $this->assertEquals($expected, Log::tail(1));
     # counts an unexisting key
     $this->assertEquals(0, Log::countLogs(42));
     # Counts an existing key
     $this->assertEquals(1, Log::countLogs('NOTICE'));
     Config::set('verbose', false);
 }
Exemplo n.º 4
0
 /**
  * @param string $pathname A complete pathname
  */
 public function __construct($pathname = null)
 {
     try {
         if (null === $pathname) {
             $this->setTablature(new Tablature());
         } else {
             $reader = new Reader(new File($pathname));
             $this->setTablature($reader->getTablature());
         }
     } catch (Exception $e) {
         $message = sprintf('%s in %s on line %d%s', $e->getMessage(), $e->getFile(), $e->getLine(), PHP_EOL . $e->getTraceAsString() . PHP_EOL);
         # if debug mode, an error kills the process
         if (Config::get('debug')) {
             trigger_error($message, E_USER_ERROR);
             return;
         }
         $this->setTablature(new Tablature());
         $this->getTablature()->setError($e->getMessage());
     }
 }
Exemplo n.º 5
0
 /**
  * @param File $file input file to read
  */
 public function __construct(File $file)
 {
     parent::__construct($file);
     $this->readVersion();
     if (!$this->isSupportedVersion($this->getVersion())) {
         $this->closeStream();
         throw new Exception(sprintf('Version "%s" is not supported', $this->getVersion()));
     }
     $song = new Song();
     $this->setTablature($song);
     $this->factory('GuitarPro5Informations')->readInformations($song);
     # Meta only
     if (Config::get('type') == 'meta') {
         $this->closeStream();
         return;
     }
     $lyricTrack = $this->readInt();
     $lyric = $this->factory('GuitarProLyric')->readLyrics();
     $this->readSetup();
     $tempoValue = $this->readInt();
     if ($this->getVersionIndex() > 0) {
         $this->skip(1);
     }
     $this->keySignature = $this->factory('GuitarProKeySignature')->readKeySignature();
     $this->skip(3);
     $this->readByte();
     $channels = $this->factory('GuitarProChannels')->readChannels();
     $this->skip(42);
     $measures = $this->readInt();
     $tracks = $this->readInt();
     $this->readMeasureHeaders($song, $measures);
     $this->readTracks($song, $tracks, $channels, $lyric, $lyricTrack);
     $this->skip($this->getVersionIndex() == 0 ? 2 : 1);
     # Meta+channels+tracks+measure headers only
     if (Config::get('type') == 'channels') {
         $this->closeStream();
         return;
     }
     $this->factory('GuitarPro5Measures')->readMeasures($song, $measures, $tracks, $tempoValue);
     $this->closeStream();
 }