I am trying to learn PHP and tried to make some minor modifications to the arpeggiate script--to change the duration of the grace notes to 16ths (easy) and to not include the top note of a chord. I'm not sure what I need to do to stop the foreach loop early. All my code does now is not include the last (unwanted) grace note from the beam.
We will update this script in order to make the duration modification easy. The top note pitch will be ignored in the new version. Details to follow...
I moved this topic into user tools and updated its title accordingly.
[The posted script in this reply has been removed. See newer script below.]
Thanks!
As it happens, I had just finished working on a version which (alas!) could not handle two note chords. At any rate, it was a learning experience working on it.
For anyone else who wants to try, use this link: http://www.php.net/manual/en/ (http://www.php.net/manual/en/)
Eric,
Forgive me if I missed it but is there/will there be a prompt that is to be added to the script command that would allow a user the ability to select the duration of the grace notes, as well as whether the arppeggio is to go up, down or random, each time the script is used or is to be only changed in the "hard coding"?
Here is a new version with prompting support. Just add the following to the command for this script:
"/duration=<PROMPT:Select a grace note duration:=|8th|16th|32nd>" "/sequence=<PROMPT:Select an arpeggio order:=|up|down|random>"
Here is the new script version:
<?php
/*******************************************************************************
nwsw_ArpeggiateChord.php Version 1.21
This script will arpeggiate selected chords by adding grace notes that tie into the chord.
Prompting can be added with the following command line:
"/duration=<PROMPT:Select a grace note duration:=|8th|16th|32nd>" "/sequence=<PROMPT:Select an arpeggio order:=|up|down|random>"
Copyright © 2007 by NoteWorthy Software, Inc.
All Rights Reserved
HISTORY:
================================================================================
[2007-06-19] Version 1.21: Support prompting
[2007-06-16] Version 1.20: Add grace note duration constant, sequencing scheme, and ignore last note in chord sequence
[2006-05-12] Version 1.01: Code format cleanup
[2004-10-28] Version 1.00: Initial release
*******************************************************************************/
require_once("lib/nwc2clips.inc");
// ARPEGGIO_DURATION can be one of 8th, 16th, 32nd, 64th
$ARPEGGIO_DURATION = "8th";
//
// Const_ARPEGGIO_SEQUENCE can be one of up, down, or random
$ARPEGGIO_SEQUENCE = "up";
foreach ($argv as $k => $v) {
if (preg_match('/^\/duration\=(.*)$/i',$v,$m)) $ARPEGGIO_DURATION = $m[1];
else if (preg_match('/^\/sequence\=(.*)$/i',$v,$m)) $ARPEGGIO_SEQUENCE = $m[1];
}
$clip = new NWC2Clip('php://stdin');
if (count($clip->Items) < 1) trigger_error("Please select at least one chord",E_USER_ERROR);
echo $clip->GetClipHeader()."\n";
$priorNoteObj = false;
foreach ($clip->Items as $item) {
$o = new NWC2ClipItem($item);
//
// 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 a grace note arpeggio
if (($o->GetObjType() == "Chord") &&
!isset($o->Opts["Dur"]["Grace"]) &&
(count(array_intersect(array_keys($o->Opts["Dur"]),array("Whole","Half","4th"))) > 0) &&
!isset($priorNoteObj->Opts["Dur"]["Grace"])) {
$chordnotes = $o->GetTaggedOpt("Pos");
$chorddur = $o->GetTaggedOpt("Dur");
switch ($ARPEGGIO_SEQUENCE) {
case "up":
// do nothing
break;
case "down":
$chordnotes = array_reverse($chordnotes);
break;
case "random":
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);
?>
Wow! Thanks for the quick response Eric.
I found you can have more than one line referring to the same file in your ini file. The displayed info on the left side has to be changed (it is sorted automatically), but you can add prompts only to one of the lines, accepting the defaults in the other. If you usually use 16ths or 32nds as your grace notes, change the hardcode in the script near the top on the line $ARPEGGIO_DURATION=.
You can also create an absolute assignment on the end of the command line, as shown.
- Use 16th notes, in random fashion:
/duration=16th /sequence=random
- Use 8th notes, in downward direction:
/duration=8th /sequence=down
This enables you to add different named executions of the same script using different options.
Where do I add the prompt part?
Program Files\NoteWorthy Composer 2\nwc2UserTools.ini is where the list of scripts and any prompts are kept.
Thank you but that's not what I meant. I found the file now at what point do I insert the prompt part. Sorry, I have no experience with php.
Normally, the prompt is not inserted in the user tool code, but in the command that executes the user tool code...
Check out this PDF on the Scripto, perhaps it will help... It is a bit long and involved but should answer your questions - I hope...
http://nwc-scriptorium.org/ftp/nwc2scripts/invocationinstructions.pdf
Thanks Lawrie!
I am trying to modify a version of the existing arpeggiate script to hide the tied grace notes (I have "up" and "16th" as constants w/o prompts). My question is around line 58 in the following. TIA
<?php
/*******************************************************************************
nwsw_ArpeggiateChord.php Version 1.21
This script will arpeggiate selected chords by adding grace notes that tie into the chord.
Prompting can be added with the following command line:
"/duration=<PROMPT:Select a grace note duration:=|8th|16th|32nd>" "/sequence=<PROMPT:Select an arpeggio order:=|up|down|random>"
Copyright © 2007 by NoteWorthy Software, Inc.
All Rights Reserved
HISTORY:
================================================================================
[2010-07-25] Testing hidden arpeggios and inserting the vertical wavy line symbol from Boxmark2
[2007-06-19] Version 1.21: Support prompting
[2007-06-16] Version 1.20: Add grace note duration constant, sequencing scheme, and ignore last note in chord sequence
[2006-05-12] Version 1.01: Code format cleanup
[2004-10-28] Version 1.00: Initial release
*******************************************************************************/
require_once("lib/nwc2clips.inc");
// ARPEGGIO_DURATION can be one of 8th, 16th, 32nd, 64th
$ARPEGGIO_DURATION = "16th";
//
// Const_ARPEGGIO_SEQUENCE can be one of up, down, or random
$ARPEGGIO_SEQUENCE = "up";
//foreach ($argv as $k => $v) {
// if (preg_match('/^\/duration\=(.*)$/i',$v,$m)) $ARPEGGIO_DURATION = $m[1];
// else if (preg_match('/^\/sequence\=(.*)$/i',$v,$m)) $ARPEGGIO_SEQUENCE = $m[1];
// }
$clip = new NWC2Clip('php://stdin');
if (count($clip->Items) < 1) trigger_error("Please select at least one chord",E_USER_ERROR);
echo $clip->GetClipHeader()."\n";
$priorNoteObj = false;
foreach ($clip->Items as $item) {
$o = new NWC2ClipItem($item);
//
// 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 a grace note arpeggio
if (($o->GetObjType() == "Chord") &&
!isset($o->Opts["Dur"]["Grace"]) &&
(count(array_intersect(array_keys($o->Opts["Dur"]),array("Whole","Half","4th"))) > 0) &&
!isset($priorNoteObj->Opts["Dur"]["Grace"])) {
$chordnotes = $o->GetTaggedOpt("Pos");
$chorddur = $o->GetTaggedOpt("Dur");
// The last item does not need a tied in grace note
array_pop($chordnotes);
/* This is where my question starts. I would like to get the position of the bottom note of the chord,
* add 3 to it and use it to echo a |Text| line with the calculated Pos either here or in the next foreach loop when $i == 0.
* My first question is how to read it, strip off the accent (if any), and calculate a $TextPos value to use in the echo; and the second
* is where should the statement go. TIA
*/
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|Pos:$new_notepitchtxt|Opts:Stem=Up,Beam$beamOpt|Visibility:Never\n";
}
}
/* Sample data:
!NoteWorthyComposerClip(2.0,Single)
|Text|Text:"c "|Font:User1|Pos:-3|Wide:Y
|Note|Dur:16th,Grace|Pos:#-6^|Opts:Stem=Up,Beam=First|Visibility:Never
|Note|Dur:16th,Grace|Pos:-4^|Opts:Stem=Up,Beam|Visibility:Never
|Note|Dur:16th,Grace|Pos:-2^|Opts:Stem=Up,Beam=End|Visibility:Never
|Chord|Dur:4th|Pos:#-6,-4,-2,#1
!NoteWorthyComposerClip-End
*/
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);
?>
This seems to do what you want:
Since you are hiding the grace notes, you might consider simplifying the code and reducing clutter with:
Performs as advertised. Thanks again!
That's what I did some time ago.
Beside hiding the grace notes, it puts the arpeggio symbol from the User1 font centered between the lower and the upper note of the arpeggio.
As User1 font I use MusikDings, one of the Lawrie's fonts.
The problem is that the "insertion point" of the arpeggio symbol is not the center of the glyph and, if my memory don't gets me wrong, it's also different from the one used in Boxmarks-Boxmark2.
As a workaround I set the insertion point 3 steps lower than the center position.
I'm not very satified of that since it depends on the font size, but it works.
Just in case it can be useful for someone else...
I updated my version of the tool for arpeggiating so it can take care of the split chords like these:
!NoteWorthyComposerClip(2.0,Single)
|Bar
|Text|Text:"c"|Font:User1|Pos:-5|Wide:Y|Justify:Right
|Note|Dur:8th,Grace|Pos:-6^|Opts:Stem=Up,Diminuendo,Beam=First|Visibility:Never
|Note|Dur:8th,Grace|Pos:-4^|Opts:Stem=Up,Diminuendo,Beam|Visibility:Never
|Note|Dur:8th,Grace|Pos:-2^|Opts:Stem=Up,Diminuendo,Beam=End|Visibility:Never
|Chord|Dur:4th|Pos:-6,-4,-2|Opts:Stem=Down,Diminuendo|Dur2:4th|Pos2:1
|Text|Text:"c"|Font:User1|Pos:-6|Wide:Y|Justify:Right
|Note|Dur:8th,Grace|Pos:-7^|Opts:Stem=Up,Diminuendo,Beam=First|Visibility:Never
|Note|Dur:8th,Grace|Pos:-4^|Opts:Stem=Up,Diminuendo,Beam|Visibility:Never
|Note|Dur:8th,Grace|Pos:-2^|Opts:Stem=Up,Diminuendo,Beam=End|Visibility:Never
|Chord|Dur:4th|Pos:0|Opts:Stem=Up,Diminuendo|Dur2:4th|Pos2:-7,-4,-2
|Dynamic|Style:mp|Pos:-13
|Chord|Dur:8th|Pos:-2|Opts:Stem=Up|Dur2:4th|Pos2:n-3
|Note|Dur:8th|Pos:0^|Opts:Stem=Up
|Chord|Dur:4th|Pos:n-4|Opts:Stem=Down|Dur2:4th|Pos2:0
|Bar
!NoteWorthyComposerClip-End
By the way: in the original nwsw_ArpeggiateChord.php Version 1.21 the line 50 is useless (but causes no harm)
$chorddur = $o->GetTaggedOpt("Dur");
Errata corrige: when trying to arpeggiate a chord of tied notes the sort became alphanumeric with... funny results!
A new version: correctly handles the presence of accidentals in the arpeggio.
I also programmed it to add hidden muted grace notes so as to let the visible accidentals survive the "audit accidentals".
This can be disabled by setting $ACCIDENTAL_SAFE = false.
Once again, a new version.
Allowed arpeggios also with restchords
Allowed arpeggios also with 8th notes
A still newer version.
I spent a few moments learning some PHP and then I updated it making some little bug fix and adding more automatic features:
Allowed arpeggios also with 8th notes
Allowed arpeggios also with restchords
Only mark the arpeggio if note duration is < 8th (no grace notes)
Added a little spacer
No arpeggio on a tied chord
Again, a new version (2.11).
Added the arpeggio direction indicators for "up" and "down"
Takes care of possible dynamic variations
Does any of this address arpeggios that go across two staves?
Nope.
That would have to be done in two steps, one per staff, and with some parameters to be input by hand, like the number of notes in the other staff.
Not so useful, IMHO.
Rick the magician, any good idea?
You can use a hidden, played single staff to create the sound. On the displayed and (temporarily) muted staves, you can insert the wavy lines by hand.
An interesting side note: a while ago I picked up one of the books I had for (several) music classes at Penn State, and I found an explanation of how an arpeggio was played, and it used the grace-note method to explain it. There was a lot of basic stuff in that I already knew when I started with it, and I think a lot of it was skipped in our classes. Anyway, I don't have many notes in it. It included solfeggio and dictation, and we had separate classes for those, so I'm sure we skipped those parts, as well as the really basic stuff.
No. I mute all my grace notes and do playback on hidden regular notes. Visually,
I either write the arpeggio out using grace notes, or modify NWC2STDA to replace a notehead with one that looks like a squiggle. None of which likely to appeal to anyone here.
Warren,
of course your idea works, but does not fit well with automation (i.e. user tool).
Rick,
I normally use the trick you suggested some time ago with some hidden, muted grace notes (but, as usual, I can't find the relevant thread in the newsgroup) and it works very well... when done by hand.
The only problem is that this one too can not be automated.
Topic found!
https://forum.noteworthycomposer.com/?topic=8429.0 (https://forum.noteworthycomposer.com/?topic=8429.0)
Um, I've lost track of something here - I went to the link Flurmy posted, and can't figure out where I went from there, but there was a link for a .png file showing a grand staff "arpeggio," and I can't find the link again. Can someone tell me how to get back to it? I had a comment and a question about the image, but I have to find it again to figure out what to ask/say!
Never mind, I found it.
Susanna, please tell me where you found the grand staff arpeggio. I need it for a piece that's been in limbo for weeks while I hunted for arpeggio info here.
Thank you.
Julia
I can't remember where I found it. I just now looked at Flurmy's thread on "False acciaccatura," which I think was where I found it originally, but I don't remember, and don't remember what it was like. What I did when I had arpeggios that went across two staves (bass & treble), I created the actual (complete) arpeggio on a tenor clef, and hid it. It was quite an arduous task for me, because I have had no experience with the tenor clef, and it was ticklish to get all the notes right. Especially since there were many above and below the clef.