function FlushTheGroupingQ() { global $NonNoteQ, $priorNoteObj; if ($priorNoteObj) { echo $priorNoteObj->ReconstructClipText() . "\n"; } if ($NonNoteQ) { echo $NonNoteQ; } $NonNoteQ = ""; $priorNoteObj = false; } echo $clip->GetClipHeader() . "\n"; // foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item); // $is_note = in_array($o->GetObjType(), array("Chord", "Note", "Rest")); $is_rest = $o->GetObjType() == "Rest"; $is_grace = isset($o->Opts["Dur"]["Grace"]); $is_dotted = isset($o->Opts["Dur"]["Dotted"]); $is_dbldotted = isset($o->Opts["Dur"]["DblDotted"]); $is_beamed = isset($o->Opts["Opts"]["Beam"]); $is_beamstart = $is_beamed && $o->Opts["Opts"]["Beam"] == "First"; if ($is_note) { if (!$priorNoteObj) { $starterDuration = array_intersect(array_keys($o->Opts["Dur"]), array_keys($validPairs)); if (count($starterDuration)) { $starterDuration = array_shift($starterDuration); } else { $starterDuration = false;
} } // process other optional arguments, in no particular order foreach ($argv as $arg) { if (preg_match("/^nosingle\$/", $arg)) { $single = 0; } else { abort("Unrecognised parameter '{$arg}'"); } } $clip = new NWC2Clip('php://stdin'); echo $clip->GetClipHeader() . "\n"; $nothingToDo = TRUE; foreach ($clip->Items as $item) { $nothingToDo = FALSE; $o = new NWC2ClipItem($item); $oType = $o->GetObjType(); if (!in_array($oType, array("Note", "Chord", "Rest", "RestChord"))) { // not an item of interest, pass it thru echo $item; } elseif ($gobbleTime > 0) { // run down the gobble clock, don't print the item $gobbleTime -= timeTaken($o); } elseif ($passTime > 0) { $passTime -= timeTaken($o); echo $item; } elseif ($oType == "Rest" || !timeTaken($o)) { // don't filter on rests or grace notes echo $item; } else { $o =& filterPart($action, $part, $o);
} 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) { $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";
} $groupingsTable[$timesig] = $groupings; // build up a table eg "7/8=3,2,2" gives $groupingsTable["7/8"] = (288,480,672) ; } if (!isset($groupingsTable)) { abort("Must provide at least one parameter of the form <upper>/<lower>=group1,group2,..."); } $currentGroup = array(); $bar = 0; $nothingToDo = TRUE; // 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) { $nothingToDo = FALSE; $o = new NWC2ClipItem($item); $oType = $o->GetObjType(); if ($oType == "TimeSig") { // better flush anything in the buffer while ($go = array_shift($currentGroup)) { echo $go->ReconstructClipText() . "\n"; } // now flush the current group $timeSig = $o->GetTaggedOpt("Signature"); if (isset($groupingsTable[$timeSig])) { $currentGroupTimes = $groupingsTable[$timeSig]; } else { unset($currentGroupTimes); } // this isn't $groupNum = 0;
<?php require_once "lib/nwc2clips.inc"; $clip = new NWC2Clip('php://stdin'); foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item); echo "Ref: {$item}"; echo "New: " . $o->ReconstructClipText() . "\n"; unset($o); } $usermsg = <<<__EOMSG See the standard output file for a comparison of the library output to the input clip. __EOMSG; // fputs(STDERR, $usermsg); exit(NWC2RC_REPORT);
trigger_error("Clip mode of {$clip->Mode} is not supported", E_USER_ERROR); } 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.
$font = $m[1]; } else { abort("Unknown parameter \"{$arg}\". Use \"help\" for more details."); } } if (!isset($transposeValue) || $transposeValue < -11 || $transposeValue > 11) { abort("Must provide an integer between -11 and 11 as transposition"); } if ($transposeValue != 0 && !isset($transposeKey)) { $transposeKey = "C"; } $clip = new NWC2Clip('php://stdin'); // 1. Scan each line echo $clip->GetClipHeader() . "\n"; $nothingToDo = TRUE; foreach ($clip->Items as $item) { $nothingToDo = FALSE; $o = new NWC2ClipItem($item); if ($o->GetObjType() == "Text" && ($t =& $o->GetTaggedOpt("Text")) && rootChordValue($t) && (isset($font) ? $o->GetTaggedOpt("Font") == $font : true)) { transpose($t); echo $o->ReconstructClipText() . "\n"; } else { echo $item; } unset($o); } echo NWC2_ENDCLIP . "\n"; if ($nothingToDo) { abort("This tool requires a selection.\nPlease select something on the staff before invoking transpose_chords."); } exit(NWC2RC_SUCCESS);
foreach ($argv as $k => $v) { if (!$k) { continue; } if (preg_match('/^\\/([a-z]+)\\=(.*)$/', $v, $m)) { $optname = $m[1]; $optvalue = $m[2]; $opts[strtolower($optname)] = $optvalue; } } $opts['skip'] = strtolower($opts['skip']); $skiplist = explode(',', $opts['skip']); echo $clip->GetClipHeader() . "\n"; // foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item); // $skipit = false; // if ($opts['skip'] == 'all') { $skipit = true; } else { if ($opts['skip'] != 'none') { $skipit = in_array(strtolower($o->GetObjType()), $skiplist); } } // if ($skipit) { echo $item; continue; }
shuffle($chordnotes); break; } // The last item does not need a tied in grace note array_pop($chordnotes); foreach ($chordnotes as $i => $notepitchtxt) { $notepitchObj = new NWC2NotePitchPos($notepitchtxt); $notepitchObj->Tied = '^'; $new_notepitchtxt = $notepitchObj->ReconstructClipText(); // $beamOpt = $i ? "" : "=First"; if ($i == count($chordnotes) - 1) { $beamOpt = "=End"; } // $o = new NWC2ClipItem($item); echo "|Note|Dur:{$ARPEGGIO_DURATION},Grace|Opts:Stem=Up,Beam{$beamOpt}|Pos:{$new_notepitchtxt}\n"; } } echo $item; if (in_array($o->GetObjType(), array('Note', 'Chord', 'Rest', 'RestChord'))) { $priorNoteObj = $o; } else { if ($o->GetObjType() == "Bar") { unset($priorNoteObj); } } unset($o); } echo NWC2_ENDCLIP . "\n"; exit(NWC2RC_SUCCESS);
It counts notes, chords, bar lines, etc. and outputs the counts. Copyright © 2011 by NoteWorthy Software, Inc. All Rights Reserved HISTORY: ================================================================================ [2011-12-19] Version 2.0: Add new NWC 2.5 objects [2006-05-12] Version 1.01: Code format cleanup [2004-10-28] Version 1.00: Initial release *******************************************************************************/ require_once "lib/nwc2clips.inc"; $clip = new NWC2Clip('php://stdin'); $typeCounts = array('Clef' => 0, 'Key' => 0, 'TimeSig' => 0, 'Bar' => 0, 'RestMultiBar' => 0, 'Note' => 0, 'Chord' => 0, 'RestChord' => 0, 'Rest' => 0, 'Dynamic' => 0, 'Spacer' => 0, 'Boundary' => 0); foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item); $oType = $o->GetObjType(); if (!isset($typeCounts[$oType])) { $typeCounts[$oType] = 1; } else { $typeCounts[$oType]++; } unset($o); } echo "Statistics Report:\n\n"; echo sprintf("%5d Total Items\n", count($clip->Items)); foreach ($typeCounts as $k => $v) { echo sprintf("%5d {$k}\n", $v); } fputs(STDERR, "The STDOUT file contains the report."); exit(NWC2RC_REPORT);
<?php require_once "lib/nwc2clips.inc"; $clip = new NWC2Clip('php://stdin'); foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item); if ($o->IsContextInfo()) { continue; } $origLine = trim($item); $newLine = $o->ReconstructClipText(); if ($newLine != $origLine) { echo "Ref: {$origLine}\nNew: {$newLine}\n\n"; } } $usermsg = <<<__EOMSG See the standard output file for a comparison of the library output to the input clip. __EOMSG; // fputs(STDERR, $usermsg); exit(NWC2RC_REPORT);
<?php require_once "lib/nwc2clips.inc"; $do_warning = false; $numchanges = 0; $zin = gzopen('php://stdin', 'rb'); $zout = gzopen('php://stdout', 'wb'); while (!gzeof($zin)) { $l = gzgets($zin, 32000); if (preg_match('/^\\|Spacer/', $l)) { $spacer = new NWC2ClipItem($l); if (!empty($spacer->Opts["Width"])) { if ($spacer->Opts["Width"] > 60) { $do_warning = true; } $spacer->Opts["Width"] *= 25; $l = $spacer->ReconstructClipText() . "\r\n"; $numchanges++; } } gzwrite($zout, $l); } gzclose($zout); gzclose($zin); if (!$numchanges) { fputs(STDERR, "No spacers were found."); exit(NWC2RC_ERROR); } if ($do_warning) { fputs(STDERR, "A spacer larger than 15 note head widths was encountered in this file. This indicates that this file has already been upgraded to " . "the new spacer width resolution and you should not apply the upgrade conversion again.\n\n" . "Is is recommneded that you press the Cancel button now."); }
$regexList[$regex] = $eval_actions; doReport("{$regex}\t-> " . implode(';', $eval_actions) . "\n"); } doReport("\nProcessing input\n"); $clip = new NWC2Clip('php://stdin'); echo $clip->GetClipHeader() . "\n"; $PlayContext = new NWC2PlayContext(); foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item, true); if ($o->IsContextInfo()) { $PlayContext->UpdateContext($o); continue; } $isChanged = false; if (in_array($o->GetObjType(), array('Note', 'Chord', 'RestChord'))) { $o_new = new NWC2ClipItem($item, true); for ($loop = 0; $loop < 2; $loop++) { $Opt_inc = $loop ? "2" : ""; $OptName_Pos = "Pos" . $Opt_inc; $OptName_Dur = "Dur" . $Opt_inc; $pitchpos =& $o_new->GetTaggedOpt($OptName_Pos); if (is_string($pitchpos)) { ProcessNote($pitchpos); } else { if (is_array($pitchpos)) { foreach ($pitchpos as &$notepitchTxt) { ProcessNote($notepitchTxt); } } } }
$ArpeggioAllowedHere = true; $WarnAboutInboundTie = false; $PlayContext = new NWC2PlayContext(); foreach ($clip->Items as $item) { $o = new NWC2ClipItem($item, true); if ($o->IsContextInfo()) { $PlayContext->UpdateContext($o); continue; } $baseDur = getBaseDur($o); // // If this is a non-grace chord and is not preceded by a grace note, // and it is larger than an 8th note in duration, then add an arpeggio if ($ArpeggioAllowedHere && $o->GetObjType() == "Chord" && !isset($o->Opts["Dur"]["Grace"]) && strpos('_|Whole|Half|4th|8th|16th|', "|{$baseDur}|")) { // Create the Arpeggio.ms object, then update its properties as needed $userObj = new NWC2ClipItem('|User|Arpeggio.ms|Pos:0|Class:Standard|Dir:up|Rate:16|Color:0|Visibility:Default'); $chordnotes = $o->GetTaggedOptAsArray("Pos", array()); $chordnotes2 = $o->GetTaggedOptAsArray("Pos2"); if ($chordnotes2) { $chordnotes = nw_aafield($o->Opts["Opts"], "Stem") == "Up" ? array_merge($chordnotes2, $chordnotes) : array_merge($chordnotes, $chordnotes2); } foreach ($chordnotes as $i => $notepitchtxt) { $notepitchObj = new NWC2NotePitchPos($notepitchtxt); if ($i == 0) { $userObj->Opts['Pos'] = $notepitchObj->Position; } if ($PlayContext->IsTieReceiver($notepitchObj)) { $WarnAboutInboundTie = true; } } foreach (array('Color', 'Visibility') as $baseprop) {