1
User Tools / Re: Swing
Best regards, Roger Nathan.
**** Modified script kbsc_rn_Swing.php (replace functions getBar and createMPC with those below) ****
Swing
(1/1)
***************************************************************************
kbsc_Swing.php Version 1.02
This script creates a tempo staff
Copyright © 2009 by K.B.S. Creer and © 2012 by Roger Nathan.
All Rights Reserved
HISTORY:
================================================================================
[2009-02-11] Version 1.00: Initial release
[2012-03-05] Version 1.01: Split notes that go past end of beat. Merge quarter beats and smaller.
[2012-04-18] Version 1.02: Detect Scottish snap and flip tempi to short then long.
*******************************************************************************/
function getBar (&$clipItems) {
/*******************************************************************************
Return an array of durations of notes from the current position up to the next bar line.
Quaver triplets are output as a single note with crotchet duration.
Notes longer than a crotchet are broken up as if they were built up of tied notes with maximum duration a crotchet.
Notes shorter than a quaver are combined into quavers
*******************************************************************************/
global $tempo, $beatLen, $barDuration, $beatsPerBar, $leadingNotes, $noteTypes;
$notesInBeat = array ();
$barDuration = 0;
$tripletDur = 0;
$item=current($clipItems);
$o = new NWC2ClipItem($item);
$oType = $o->GetObjType();
while ($item && $oType!="Bar") {
if ($oType=="Tempo") {
$tempo = $o->GetTaggedOpt("Tempo");
} elseif ($oType=="Ending") {
$leadingNotes = FALSE;
echo $item;
} elseif (in_array($oType, $noteTypes)) {
$opts = $o->GetOpts();
if (isset($opts["Dur"]["Triplet"])) {
$m=getDuration ($opts["Dur"]);
$tripletDur+=$m;
if ($opts["Dur"]["Triplet"]=="End") {
$tripletDur=$tripletDur * 2 / 3;
$notesInBeat[] = $tripletDur;
$barDuration+=$tripletDur;
$tripletDur = 0;
}
} else {
$duration=getDuration ($opts["Dur"]);
$beatRemainder = $beatLen - $barDuration%$beatLen; //count from current position to end of beat
if ($duration<=$beatLen/4 and $beatRemainder = 0) { // combine short notes into a beat only at start of beat
$littleNotesDur=$duration;
while ($littleNotesDur<$beatLen/2) {
$item=next($clipItems);
$o = new NWC2ClipItem($item);
$oType = $o->GetObjType();
if (in_array($oType, $noteTypes)) {
$opts = $o->GetOpts();
$m=getDuration ($opts["Dur"]);
$littleNotesDur+=$m;
}
$notesInBeat[] = $littleNotesDur;
$barDuration += $littleNotesDur;
}
} else {
while ((($barDuration%$beatLen)+$duration)>$beatLen) { // split a longer than beat note to complete beat
$notesInBeat[] = $beatRemainder;
$barDuration += $beatRemainder;
$duration -= $beatRemainder;
}
$notesInBeat[] = $duration;
$barDuration += $duration;
}
}
}
$item=next($clipItems);
$o = new NWC2ClipItem($item);
$oType = $o->GetObjType();
}
$collect = 0;
$notesInBar2 = array();
foreach ($notesInBeat as $duration) { // consolidate shorter notes into quarter beats (e.g. 1/16s)
if ($duration+$collect <= $beatLen/4 && array_sum($notesInBar2)%($beatLen/4) == 0) {
$collect += $duration;
} else {
if ($collect > 0) {
$notesInBar2 [] = $collect;
}
$collect = $duration;
}
}
if ($collect > 0) {
$notesInBar2 [] = $collect;
}
// ***
//print_r ($notesInBar2); reset ($notesInBar2);
// ***
$collect = 0;
$notesInBar3 = array();
foreach ($notesInBar2 as $duration) { // consolidate paired quarter beats into half beats (e.g. 1/8s)
if ($duration == $beatLen/4 && $duration+$collect <= $beatLen/2 && array_sum($notesInBar3)%($beatLen/2) == 0) {
$collect += $duration;
} else {
if ($collect > 0) {
$notesInBar3 [] = $collect;
}
$collect = $duration;
}
}
if ($collect > 0) {
$notesInBar3 [] = $collect;
}
// ***
//print_r ($notesInBar3); reset ($notesInBar3);
// ***
return $notesInBar3;
}
function createMPC($pBN,$pc) {
global $tempo, $beatLen;
$MCPstr="|MPC|Controller:tempo|Style:Absolute|TimeRes:Sixteenth|SweepRes:1";
$offset = 0;
$Pt = 1;
$note = array_shift ($pBN);
if ($note>=QUARTER) {
$MCPstr.="|Pt$Pt:$offset,$tempo";
} else {
if ($note>0) {
$note2 = current ($pBN);
if ($note==$beatLen/4 && $note2==$beatLen/4*3)
{
$pc = 100 - $pc;
}
$N=round(100 * $note * $tempo / (QUARTER * $pc));
$MCPstr.="|Pt$Pt:$offset,$N";
$Pt += 1;
$offset = $note / 4;
}
$pc = 100 - $pc;
$note = array_shift ($pBN);
if (isset($note)) {
if ($note>0) {
$N=round(100 * $note * $tempo / (QUARTER * $pc));
$MCPstr.="|Pt$Pt:$offset,$N";
$Pt += 1;
$offset = $note / 4;
}
$note = array_shift ($pBN);
if (isset($note)) {
$MCPstr.="|Pt$Pt:$offset,$tempo";
}
}
}
$MCPstr.="|Pos:-5|Wide:N|Justify:Left|Placement:BestFit|Color:0|Visibility:Default";
return $MCPstr;
}