Exemple #1
0
 function toXML()
 {
     $out = '';
     $out .= '<note';
     if (isset($this->defaultX)) {
         $out .= ' default-x="' . $this->defaultX . '"';
     }
     if (isset($this->defaultY)) {
         $out .= ' default-y="' . $this->defaultY . '"';
     }
     $out .= '>';
     if (!empty($this->rest)) {
         $out .= '<rest/>';
     }
     if (!empty($this->chord)) {
         $out .= '<chord/>';
     }
     if (!empty($this->pitch)) {
         if ($this->pitch instanceof Pitch) {
             $pitch = $this->pitch;
         } else {
             // we'll presume it's a string then
             $pitch = new Pitch($this->pitch);
         }
         $out .= $pitch->toXML();
     }
     if (!empty($this->duration)) {
         $out .= '<duration>' . $this->duration . '</duration>';
     }
     if (!empty($this->voice)) {
         $out .= '<voice>' . $this->voice . '</voice>';
     }
     if (!empty($this->type)) {
         $out .= '<type>' . $this->type . '</type>';
     }
     if (!empty($this->dot)) {
         $out .= '<dot/>';
     }
     if (!empty($this->tie)) {
         $out .= '<tie style="' . $this->tie . '">';
         $this->notations['tie'] = $this->tie;
     }
     if (!empty($this->staccato)) {
         $this->notations['staccato'] = $this->properties['staccato'];
     }
     if (!empty($this->stem)) {
         $out .= $this->stem->toXml();
     }
     if (!empty($this->staff)) {
         $out .= '<staff>' . $this->staff . '</staff>';
     }
     if (!empty($this->beam)) {
         if (!is_array($this->beam)) {
             $this->beam = array($this->beam);
         }
         foreach ($this->beam as $beam) {
             $out .= $beam->toXml();
         }
     }
     if (!empty($this->notations) || !empty($this->articulations)) {
         $out .= '<notations>';
         // Slur, Tie, Tuplet, Arpeggiate
         foreach ($this->notations as $notation) {
             $out .= $notation->toXml();
         }
         // staccato
         if (!empty($this->articulations)) {
             $out .= '<articulations>';
             foreach ($this->articulations as $articulation) {
                 $out .= $articulation->toXml();
             }
             $out .= '</articulations>';
         }
         $out .= '</notations>';
     }
     $out .= '</note>';
     return $out;
 }
Exemple #2
0
 function toXML()
 {
     $out = '';
     $out .= '<note';
     if (isset($this->properties['default-x'])) {
         $out .= ' default-x="' . $this->properties['default-x'] . '"';
     }
     if (isset($this->properties['default-y'])) {
         $out .= ' default-y="' . $this->properties['default-y'] . '"';
     }
     $out .= '>';
     if (!empty($this->properties['rest'])) {
         $out .= '<rest/>';
     }
     if (!empty($this->properties['chord'])) {
         $out .= '<chord/>';
     }
     if (!empty($this->properties['pitch'])) {
         if ($this->properties['pitch'] instanceof Pitch) {
             $pitch = $this->properties['pitch'];
         } else {
             // we'll presume it's a string then
             $pitch = new Pitch($this->properties['pitch']);
         }
         $out .= $pitch->toXML();
     }
     if (!empty($this->properties['duration'])) {
         $out .= '<duration>' . $this->properties['duration'] . '</duration>';
     }
     if (!empty($this->properties['voice'])) {
         $out .= '<voice>' . $this->properties['voice'] . '</voice>';
     }
     if (!empty($this->properties['type'])) {
         $out .= '<type>' . $this->properties['type'] . '</type>';
     }
     if (!empty($this->properties['dot'])) {
         $out .= '<dot/>';
     }
     if (!empty($this->properties['tie'])) {
         $out .= '<tie style="' . $this->properties['tie'] . '">';
         $this->notations['tie'] = $this->properties['tie'];
     }
     if (!empty($this->properties['staccato'])) {
         $this->notations['staccato'] = $this->properties['staccato'];
     }
     if (!empty($this->properties['stem'])) {
         $out .= '<stem';
         if (isset($this->properties['stem']['default-x'])) {
             $out .= ' default-x="' . $this->properties['stem']['default-x'] . '"';
         }
         if (isset($this->properties['stem']['default-y'])) {
             $out .= ' default-y="' . $this->properties['stem']['default-y'] . '"';
         }
         $out .= '>';
         if (isset($this->properties['stem']['direction'])) {
             $out .= $this->properties['stem']['direction'];
         }
         $out .= '</stem>';
     }
     if (!empty($this->properties['staff'])) {
         $out .= '<staff>' . $this->properties['staff'] . '</staff>';
     }
     if (!empty($this->properties['beam'])) {
         if (!is_array($this->properties['beam'])) {
             $this->properties['beam'] = array($this->properties['beam']);
         }
         foreach ($this->properties['beam'] as $beam) {
             $out .= '<beam';
             if (isset($beam['beam']['number'])) {
                 $out .= ' number="' . $beam['beam']['number'] . '"';
             }
             $out .= '>';
             if (!empty($beam['beam']['type'])) {
                 $out .= $beam['beam']['type'];
             }
             $out .= '</beam>';
         }
     }
     if (!empty($this->notations) || !empty($this->articulations)) {
         $out .= '<notations>';
         foreach ($this->notations as $notationType => $n) {
             switch ($notationType) {
                 case 'slur':
                     $out .= '<slur';
                     $out .= ' number="' . $n['number'] . '"';
                     $out .= ' placement="' . $n['placement'] . '"';
                     $out .= ' type="' . $n['type'] . '"';
                     $out .= ' bezier-x="' . $n['bezier-x'] . '"';
                     $out .= ' bezier-y="' . $n['bezier-y'] . '"';
                     $out .= ' default-x="' . $n['default-x'] . '"';
                     $out .= ' default-y="' . $n['default-y'] . '"';
                     $out .= '/>';
                     break;
                 case 'tie':
                     $out .= '<tied type="' . $n . '"/>';
                     break;
                 case 'tuplet':
                     $out .= '<tuplet';
                     $out .= ' bracket="' . $n['bracket'] . '"';
                     $out .= ' number="' . $n['number'] . '"';
                     $out .= ' placement="' . $n['placement'] . '"';
                     $out .= ' type="' . $n['type'] . '"';
                     $out .= '/>';
                     break;
                 case 'arpeggiate':
                     $out .= '<arpeggiate';
                     $out .= ' default-x="' . $n['default-x'] . '"';
                     $out .= ' number="' . $n['number'] . '"';
                     $out .= '/>';
                     break;
             }
         }
         if (!empty($this->articulations)) {
             $out .= '<articulations>';
             foreach ($this->articulations as $articulation => $value) {
                 switch ($articulation) {
                     case 'staccato':
                         $out .= $value ? '<staccato/>' : '';
                 }
             }
             $out .= '</articulations>';
         }
         $out .= '</notations>';
     }
     $out .= '</note>';
     return $out;
 }