}
if ($clip->Version < "2.5") {
    trigger_error("The notation clip uses an unknown format version ({$clip->Version}), so it may not be processed correctly", E_USER_NOTICE);
}
function IsPossibleBarNumber(&$o)
{
    return $o->GetObjType() == "Text" && preg_match('/^Bar [0-9]+$/', $o->GetTaggedOpt('Text', ""));
}
$pendingOutput = array();
$priorBarIndex = -1;
//
echo $clip->GetClipHeader() . "\n";
$PlayContext = new NWC2PlayContext();
foreach ($clip->Items as $item) {
    $o = new NWC2ClipItem($item, true);
    if ($o->IsContextInfo()) {
        $PlayContext->UpdateContext($o);
        continue;
    }
    $flushPending = false;
    if ($o->GetObjType() == "Bar") {
        if ($o->GetTaggedOpt('XBarCnt', 'N') == 'Y') {
            $flushPending = true;
        } else {
            $priorBarIndex = count($pendingOutput);
        }
    } else {
        if (IsPossibleBarNumber($o)) {
            if (count($pendingOutput) && $priorBarIndex == count($pendingOutput) - 1) {
                // Remove this existing bar number. If a new one is needed, it will be added later.
                continue;