$ix) { $n++ ; $type = $ix->GetObjType() ; if (( $n < $maxelm ) || ($n == $maxelm && $type == "Rest")) // End item not modified { $opts =& $barray[$key]->GetOpts() ; if (!isset($opts["Visibility"])) // Check if visibility is set already in an earlier { // invocation of the user tool $opts["Visibility"] = "Never" ; // If not, set rests and bar lines to no print $ModDone = TRUE ; } } if ($n == $Txtpos) $modarray[] = $rTxt ; // Insert generated text item with number of rests $modarray[] = $barray[$key] ; // Copy items to array to insert text items } if ( $ModDone ) $barray = $modarray ; // If we did not modify visibility, we do not use the added text either } // Initialize the multiple rest buffer and counter $rBuffer = array ( ) ; $rcount = 0; // THE MAIN ACTION STARTS HERE // 2. Load and scan the stream... output is group by group $clip = new NWC2Clip('php://stdin'); echo $clip->GetClipHeader()."\n"; foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item) ; $oType = $o->GetObjType() ; $oDur = $o->GetTaggedOpt("Dur") ; if ($oType == "Rest" && isset($oDur["Whole"])) // we've found a whole bar rest. { if ($rcount == 0) { while ($go = array_shift($rBuffer)) echo $go->ReconstructClipText()."\n" ; // now flush the current buffer $rcount = 1 ; array_push($rBuffer,$o) ; // save the item } else { $rcount++ ; array_push($rBuffer,$o) ; // save the item } } else { if ($oType == "Bar" && !$o->GetOpts()) { array_push($rBuffer,$o) ; // save the item } else // We have found another item than single bar or whole rest { if ($rcount >= MIN_RESTS) // If more than defined whole bar rest counted, edit the items { ModBuffer($rBuffer,$rcount) ; while ($go = array_shift($rBuffer)) echo $go->ReconstructClipText()."\n" ; // now flush the current buffer } $rcount = 0 ; // Re-initialise counter array_push($rBuffer,$o) ; // save the item } } unset($o); } if ($rcount >= MIN_RESTS) // check for unprocessed rests at end of clip { ModBuffer($rBuffer,$rcount) ; } while ($go = array_shift($rBuffer)) echo $go->ReconstructClipText()."\n" ; // now flush the current buffer exit ($exitVal) ; ?>