2, "#"=>1, "n"=>0, "b"=>-1, "v"=>-2) ; // Double sharp, sharp, nat, flat, double-flat $n = new NWC2NotePitchPos($src) ; $ret = $n->Position * 5 ; if ($n->Accidental) $ret += $AccMarkToValue[$n->Accidental] ; unset($n) ; return ($ret) ; // } function CheckExtremes($o) // scans a Pos or Pos2 tagged opt and sets maximum and minimum accordingly { global $maximum, $minimum ; if ($o === FALSE) return ; // This might happen is called for Pos2 and there is no Pos2 if (!is_array($o)) $o = array($o) ; foreach ($o as $pos) // { if (positionness($pos) > positionness($maximum)) { $maximum = $pos ; } // see sub above if (positionness($pos) < positionness($minimum)) { $minimum = $pos ; } } } // THE MAIN ACTION STARTS HERE foreach ($argv as $arg) { if ($arg == "help") print_help_and_exit() ; elseif ($arg == "separate") $writeasseparate = 1 ; } $clip = new NWC2Clip('php://stdin'); // 1. Scan each line foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item); $oType = $o->GetObjType(); if ($oType == "Note") CheckExtremes($o->GetTaggedOpt("Pos")) ; elseif ($oType == "RestChord") CheckExtremes($o->GetTaggedOpt("Pos2")) ; elseif ($oType == "Chord") {CheckExtremes($o->GetTaggedOpt("Pos")) ; CheckExtremes($o->GetTaggedOpt("Pos2")) ; } unset($o); } // 2. Check if we scanned any notes if ($maximum == -999) // Bail out if no notes or chords or restchords abort("No notes found!") ; if ($maximum == $minimum) abort("This selection has a range of a single note!") ; // 3. Commence output... echo $clip->GetClipHeader()."\n"; foreach ($clip->Items as $item) { if (! $printedRange) // have we printed our range yet? We wait until the first note, chord or restchord... { $o = new NWC2ClipItem($item); if (in_array($o->GetObjType(), array("Note", "Chord", "RestChord"))) { $printedRange = 1 ; // ...and then precede it with our range if ($writeasseparate) { echo "|Note|Dur:Whole|Pos:$minimum\n|Note|Dur:Whole|Pos:$maximum\n" ; } else { echo "|Chord|Dur:Whole|Pos:$minimum,$maximum\n" ; } echo "|Bar|Style:Double\n" ; } unset ($o) ; } echo $item ; } echo NWC2_ENDCLIP."\n"; exit (NWC2RC_SUCCESS) ; // Phew! Glad that's over! ?>