where is the keyword cut or the keyword copy is the number of the first measure to cut or copy and is the number of the final measure to cut or copy (so if cutting or copying one measure, the numbers are the same) and is the measure number you want to paste before. Note this is the number BEFORE the cut/copy has been made, to save you calculating. NB: MEASURE NUMBER IS COUNTED FROM THE START OF THE SELECTION AND IS ONLY EQUAL TO THE Ctrl-G NUMBER WHEN YOU ARE SELECTING FROM THE START OF THE STAFF, AND WHEN MEASURE START (in Page Setup) IS 1 (the default). eg cut 1 4 10 would cut the first 4 measures and paste them before measure 10 copy 4 6 2 would copy measures 4,5&6 and paste them before measure 2 To paste at the end, simply use a measure number greater than the final one. Version 1.0 20050606 " ; exit(NWC2RC_REPORT); } function check_for_pos_integer($arg, $argname) { if (!is_numeric($arg) || strpos($arg,".") || $arg < 1) abort("The $argname parameter '$arg' isn't a valid measure number.") ; return $arg ; } function is_a_bar($item) { $o = new NWC2ClipItem($item) ; $result = ($o->GetObjType() == "Bar") ; unset($o) ; return $result ; } // THE MAIN ACTION STARTS HERE array_shift($argv) ; // shift off the name of the script $cutorcopy = strtolower(array_shift($argv)) ; if ($cutorcopy == "help") print_help_and_exit() ; if ($cutorcopy != "cut" && $cutorcopy != "copy") abort("First parameter must be \"cut\" or \"copy\".\nYou provided \"$cutorcopy\"") ; $first = check_for_pos_integer(array_shift($argv), "second") ; // $final = check_for_pos_integer(array_shift($argv), "third") ; // $dest = check_for_pos_integer(array_shift($argv), "fourth") ; // if ($first > $final) abort("The first parameter '$first' must be <= the second parameter '$final'") ; $clip = new NWC2Clip('php://stdin'); echo $clip->GetClipHeader()."\n"; foreach ($clip->Items as $item) { // store the actual text for easier output later if ($currentmeasure < $first || $currentmeasure > $final) $remainder[] = $item ; else { $buffer[] = $item ; if ($cutorcopy == "copy") $remainder[] = $item ; // if not cutting, don't remove it from remainder buffer } if (is_a_bar($item)) $currentmeasure++ ; } // work out how many measures to print before inserting buffer if ($dest < $first) $test = $dest ; elseif ($cutorcopy == "copy") $test = $dest ; else $test = $dest - $final + $first - 1 ; $currentmeasure = 1 ; while ($currentmeasure < $test) { $item = array_shift($remainder) ; if (!$item) { // array is emptied echo "|Bar\n" ; // add a final barline break ; } echo $item ; if (is_a_bar($item)) $currentmeasure++ ; } while ($item = array_shift($buffer)) echo $lastitem = $item ; // now dump the cut buffer if (!is_a_bar($lastitem) && sizeof($remainder) > 0) echo "|Bar\n" ; while ($item = array_shift($remainder)) echo $item ; // and dump remainder of remainder echo NWC2_ENDCLIP."\n"; exit (NWC2RC_SUCCESS) ; ?>