All Unit tests
Current file: C:\code\midiparser\src\Midi\Event\SystemExclusiveEvent.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 8 / 8
100.00%100.00%
100.00% 15 / 15
 
Midi\SystemExclusiveEvent
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 8 / 8
100.00%100.00%
100.00% 15 / 15
 public function __construct(array $data)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 public function getLength()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function __toString()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function toBinary()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function isDivided()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function isNormal()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
 public function getData()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function getType()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1


       1                 : <?php                                                                                     
       2                 :                                                                                           
       3                 :     /**                                                                                   
       4                 :      * \Midi\Event\SystemExclusiveEvent                                                   
       5                 :      *                                                                                    
       6                 :      * @package    Midi                                                                   
       7                 :      * @subpackage Event                                                                  
       8                 :      * @copyright  © 2009 Tommy Montgomery <http://phpmidiparser.com/>                    
       9                 :      * @since      1.0                                                                    
      10                 :      */                                                                                   
      11                 :                                                                                           
      12                 :     namespace Midi\Event;                                                                 
      13                 :                                                                                           
      14                 :     use \Midi\Event;                                                                      
      15                 :     use \Midi\Util\Util;                                                                  
      16                 :                                                                                           
      17                 :     /**                                                                                   
      18                 :      * Represents a system exclusive event                                                
      19                 :      *                                                                                    
      20                 :      * These events are exclusive to the (duh) system. Meaning,                           
      21                 :      * each manufacturer can use these events in whatever way                             
      22                 :      * they choose.                                                                       
      23                 :      *                                                                                    
      24                 :      * @package    Midi                                                                   
      25                 :      * @subpackage Event                                                                  
      26                 :      * @since      1.0                                                                    
      27                 :      */                                                                                   
      28               1 :     class SystemExclusiveEvent implements Event {                                         
      29                 :                                                                                           
      30                 :         /**                                                                               
      31                 :          * @var array                                                                     
      32                 :          */                                                                               
      33                 :         protected $data;                                                                  
      34                 :                                                                                           
      35                 :         /**                                                                               
      36                 :          * Length of the data                                                             
      37                 :          *                                                                                
      38                 :          * @var int                                                                       
      39                 :          */                                                                               
      40                 :         protected $length;                                                                
      41                 :                                                                                           
      42                 :         /**                                                                               
      43                 :          * Constructor                                                                    
      44                 :          *                                                                                
      45                 :          * @since 1.0                                                                     
      46                 :          *                                                                                
      47                 :          * @param  array $data                                                            
      48                 :          */                                                                               
      49                 :         public function __construct(array $data) {                                        
      50               6 :             $this->length = count($data);                                                 
      51               6 :             $this->data   = $data;                                                        
      52               6 :         }                                                                                 
      53                 :                                                                                           
      54                 :         /**                                                                               
      55                 :          * Gets the length of this event in bytes                                         
      56                 :          *                                                                                
      57                 :          * @since 1.0                                                                     
      58                 :          * @uses  Util::getDeltaByteSequence()                                            
      59                 :          *                                                                                
      60                 :          * @return int                                                                    
      61                 :          */                                                                               
      62                 :         public function getLength() {                                                     
      63               1 :             $lengthOfDelta = strlen(Util::getDeltaByteSequence($this->length));           
      64                 :                                                                                           
      65                 :             //sysex event (0xF0), length of data, data                                    
      66               1 :             return 1 + $lengthOfDelta + $this->length;                                    
      67                 :         }                                                                                 
      68                 :                                                                                           
      69                 :         /**                                                                               
      70                 :          * Gets the string representation of this event                                   
      71                 :          *                                                                                
      72                 :          * @since 1.0                                                                     
      73                 :          * @uses  EventType::getEventName()                                               
      74                 :          * @uses  getType()                                                               
      75                 :          *                                                                                
      76                 :          * @return string                                                                 
      77                 :          */                                                                               
      78                 :         public function __toString() {                                                    
      79               1 :             return EventType::getEventName($this->getType()) . ': manufacturer dependent';
      80                 :         }                                                                                 
      81                 :                                                                                           
      82                 :         /**                                                                               
      83                 :          * Gets a binary representation of this event                                     
      84                 :          *                                                                                
      85                 :          * @since 1.0                                                                     
      86                 :          * @uses  Util::getDeltaByteSequence()                                            
      87                 :          * @uses  getType()                                                               
      88                 :          * @uses  Util::pack()                                                            
      89                 :          *                                                                                
      90                 :          * @return Midi                                                                   
      91                 :          */                                                                               
      92                 :         public function toBinary() {                                                      
      93               1 :             $delta = Util::getDeltaByteSequence($this->length);                           
      94               1 :             return Util::pack($this->getType()) . $delta . implode('', $this->data);      
      95                 :         }                                                                                 
      96                 :                                                                                           
      97                 :         /**                                                                               
      98                 :          * Gets whether this is a divided system exclusive event                          
      99                 :          *                                                                                
     100                 :          * In order to avoid delays in playback with very long                            
     101                 :          * sysex events, normal sysex events can be broken up into                        
     102                 :          * several divided events.                                                        
     103                 :          *                                                                                
     104                 :          *                                                                                
     105                 :          * @since 1.0                                                                     
     106                 :          * @uses  isNormal()                                                              
     107                 :          * @see   isNormal()                                                              
     108                 :          *                                                                                
     109                 :          * @return bool                                                                   
     110                 :          */                                                                               
     111                 :         public function isDivided() {                                                     
     112               1 :             return !$this->isNormal();                                                    
     113                 :         }                                                                                 
     114                 :                                                                                           
     115                 :         /**                                                                               
     116                 :          * Gets whether this is a normal system exclusive event                           
     117                 :          *                                                                                
     118                 :          * Normal sysex events are signified by the last byte of data                     
     119                 :          * being 0xF7.                                                                    
     120                 :          *                                                                                
     121                 :          * @since 1.0                                                                     
     122                 :          * @uses  Util::pack()                                                            
     123                 :          * @see   isDivided()                                                             
     124                 :          *                                                                                
     125                 :          * @return bool                                                                   
     126                 :          */                                                                               
     127                 :         public function isNormal() {                                                      
     128               1 :             $byte = end($this->data);                                                     
     129               1 :             reset($this->data);                                                           
     130               1 :             return $byte === Util::pack(0xF7);                                            
     131                 :         }                                                                                 
     132                 :                                                                                           
     133                 :         /**                                                                               
     134                 :          * Gets the data associated with this event                                       
     135                 :          *                                                                                
     136                 :          * @since 1.0                                                                     
     137                 :          *                                                                                
     138                 :          * @return array                                                                  
     139                 :          */                                                                               
     140                 :         public function getData() {                                                       
     141               1 :             return $this->data;                                                           
     142                 :         }                                                                                 
     143                 :                                                                                           
     144                 :         /**                                                                               
     145                 :          * Gets the event type                                                            
     146                 :          *                                                                                
     147                 :          * @since 1.0                                                                     
     148                 :          * @uses  EventType::SYSTEM_EXCLUSIVE                                             
     149                 :          *                                                                                
     150                 :          * @return int                                                                    
     151                 :          */                                                                               
     152                 :         public function getType() {                                                       
     153               2 :             return EventType::SYSTEM_EXCLUSIVE;                                           
     154                 :         }                                                                                 
     155                 :                                                                                           
     156                 :     }                                                                                     
     157                 :                                                                                           

Generated by PHPUnit 3.4.1 and Xdebug 2.0.5 using PHP 5.3.0 at Sun Oct 25 23:35:09 PDT 2009.