perl script "dyn":  converts concise specification into an events list

Stan Swanson, May 2004

A concise specification has been developed which will generate
an "events" list with the aid of a perl script, "dyn".  If this 
proves useful, the capability may be added directly to "vamp"

The syntax and format of an "event" command is somewhat
tedious.  As an example consider 4 repeats of the tune
Lamplighters hornpipe (lamp):

@lamp.in               % read definitions of melody, chords, etc.
instruments 111 72 1   % fiddle, clarinet, piano
events
 -1 potatoes           % conventional intro for dance
  1 lamp      1        % melody on fiddle   [voice 1]
  1 lamp      2        % melody on clarinet [voice 2]
  1 best      3        % chords on piano    [voice 3]
  1 odd       1        % play phrase 1, 3, 5, 7 on fiddle
  1 even      2        % play phrase 2, 4, 6, 8 on clarinet
  1 boomchuck 3        % accent (hypermeter) for piano
  2 half      3        % another set of chords (half measures)
  3 root      3        % chords prefered by harmony 55
  4 last      3        % modify chords for coda at end
/events

The above "vamp" input is generated (less comments) by a short 
perl script from this simplifed set of lists: 

lamp.in
melody lamp
 fiddle odd
 clarinet even
chords best half root last
 piano boomchuck

In this example, the fiddle and clarinet play alternate 
phrases in the melody; this is coded in the phrasing commands
"odd" and "even".  Four different (but similar) chord sequences
"best", "half", "root", and "last" are used.

The repeat number is deduced from the position in the list.
 (Presently, an explicitly repeated element determines the total
  number of repeats (i.e. "last" above) when "vamp" parses the
  "events" command.)
The voice number is assigned by the order of the appearance of
 of the instrument line in the file.

The general format of the perl input is:

file.in
dynamics 'volume1' [rep] 'volume2' [rep] 'volume3' [rep] ...
melody    melody-id [rep] ...
  'iname' phrase-id [rep] ...
chords    chord-id1 [rep] chord-id2 [rep] ...
  'iname' accent-id [rep] ...

The first line gives the name of the input file defining
the melodies, chords, vamping, accents and phrasing used.

For the other lines, the general form is:

 "topic word"  "list with optional repeat counts [rep]"

The optional repeat count [rep] has a default value of 1.
If more than one repetition of a list item is desired, it may
be followed by a number giving the total number of repeats
(c.f. "dynamics" below).  The last item is implicitly repeated
until the end of the piece (e.g. "melody lamp" and "melody lamp 4"
would be equivalent in this example which has 4 chord sequences).

The topic words "melody", "chords", and "dynamics" serve to introduce
lists of melodies, chords, and volume levels which change at a
time granularity of a tune repeat.

'iname' is an instrument name (piano, guitar, bass, sax, clarinet,
           flute, banjo, fiddle are recognized) or the phrase
        "instrument n", with n being a MIDI instrument number.

The instruments following a "melody" line play the designated
melodies, with phrasing specified by the list of phrase-id's.

The instruments following a "chords" line play the designated
chord sequences, with accents specified by the list of accent-id's.

Multiple "chords" lines are possible, if the chords vary by instrument.
It is hard to see why one would want multiple melodies (except perhaps
to transpose for a given instrument), but one might want a medley 
(with several melody-id's given in the "melody" line).

The instruments are assigned to voices in the order of their
appearance, and are written out in an "INSTRUMENT" command.

To change the overall volume as the tune is repeated, a
"dynamics" line may be used.

'Volume' levels use the "fff ff ... ppp" symbols, as introduced 
in the "phrase" command.  [The general "vnnn" designator
is not yet available.]

Adding a line to the above perl input:

dynamics f 2 mf ff

would intercalate these volume commands into the vamp input:

  1 _volume_   88
  3 _volume_   72
  4 _volume_  104