Skip to main content

Show Posts

This section allows you to view all Show Posts made by this member. Note that you can only see Show Posts made in areas you currently have access to.

Messages - rnathan

1
User Tools / Re: Swing
I have further modified the script to handle Scottish Snaps and combine notes that are less than 1/4 beat:

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;
}


2
User Tools / Re: Swing
Hello again Brian,

I'm not very good with PHP, but I have managed to augment your script, modifying the function getBar so that it processes note combination that were giving me trouble. One lingering problem is that a 1/6+1/8,dotted comes out the same swung rhythm as 1/8,dotted+1/16.

All readers have my permission to use this partial script at their own risk.


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;
if ($tripletDur==$beatLen*2) { //crotchet triplet split into two crotchets
$notesInBeat[] = $beatLen;
$notesInBeat[] = $beatLen;
$barDuration+=$beatLen*2;
} else {
$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();
}

return $notesInBeat;
}
3
User Tools / Re: User tools give errors with PHP 5
The advice in this thread was helpful. I run Windows 7 Home Premium.

I upgraded to NWC v2.5, and downloaded the User Tool Starter v2.5, but this was not enough, as I had another version of PHP (used for web authoring). One workaround was to rename the PHP folder in Program Files (x86) to "PHP disabled".

My eventual solution was to remove the other version of PHP altogether using Windows Control Panel, then manually delete the PHP.ini file that was still on disk. I could do this, because the PHP that comes with NWC is suitable for my web authoring application (so long as the new location of the PHP executable, C:\Program Files (x86)\Noteworthy Software\NoteWorthy Composer 2\PHP\php.exe, is set in preferences).

Best regards, Roger Nathan.