2003 March 27:
Updated the man pages to abc2abc, abc2midi and midi2abc and created a
new man page for yaps.  Minor changes to midifile.c and midifile.h
were made to minimize the number of warning error messages. Midi2abc
was upgraded to be in line with the version I use with the script
midi2abc.tcl. The syntax in mftext.c was improved to reduce the
number of compilation warnings.


2003 April 12
abc2midi: for abc tunes with no guitar chords, an error
message "Command not recognized" is issued whenever a %%MIDI
chordprog or %%MIDI bassprog command is encountered.
The problem occurs mainly with runabc, which
performs only one pass through the tune and is unable to
know whether guitar chords are present before sending 
%%MIDI commands. Since no MIDI program command is issued
in this situation, the error message  was disabled, The
fix was made in dodeferred() in genmidi.c

2003 April 12
abc2midi assumes the ratio of 2:1 for long/short notes
in broken rhythms specified with angle brackets (eg. c>d),
Though this can be changed using the %%MIDI ratio command, it
is inconvenient for many users since it is necessary to edit
each tune in the abc file in order to effect this change.
A new command parameter -RS (ratio standard) changes default
ratio to 3:1 which is the standard music notation. The new
parameter still allows the %%MIDI ratio command to override
the default. The change was incorporated in event_init()
of store.c.
 
2003 Apri 19
The proposed abc standard allows non numeric identifications
for the voice field, eg. V: soprano instead of V:1.  If you
are creating a midi file, each unique identification string will
mapped to a sequential numbers 1,2 etc, as if you had used numbers
originally. The change allows abcMIDI to handle a number of 
new multivoiced abc files which have adopted this convention.
Only the first 20 characters of the identification
string are distinguished. Anything following the identification
string is ignored. The identification string should not end with
an equal sign =.  If nonnumeric identifications are used,
abc2midi will print the mapping between the id's and the numbers.
This may be useful for catching spelling errors in the id's.
The fix was made in function parsefield in parseabc.c. The
change does not yet allow V: commands to appear before the
body of the tune.

A number of abc files may designate a rest using x instead of
z. This means that this rest exists but should not appear 
in the printed score. I have modified the parser so it shall
now interpret x as rest; however, if you are using yaps to 
print the score, this rest will still remain visible. Abc2midi
will now treat x exactly like z. Abc2abc will probably
automatically convert the x's to z's whether you want it or not.
A minor change was made in parsemusic in parseabc.c. It is
necessary to modify toabc.c and yapstree.c to fix the
remaining problems.

2003 April 27
Guitar chords. The base note preceeded by a slash in the guitar
chord may now  be in lower case as well as upper case. For example,
"G/B" and "G/b" will both be treated the same way. This complies
with the proposed abc standard 1.7.6 (abc-draft.txt) and avoids
problems with some files in the Nottingham database. The fix was
made in event_handle_gchord in store.c.

Guitar chords. When there is a change of meter, the gchord beat
does not seem to get changed. I inserted a call to setbeat()
in writetrack() in genmidi.c whenever a TIME feature is encountered.
It was also necessary to change the definition of setbeat in
store.c from static to external.

2003 May 3
Karoake lyrics: Improved the documentation for the functions
write_syllable and getword in genmidi.c  which handle the lyrics
in the w: body line. If a bar line is placed in the lyric
line between two tied notes, for example see below,

"C6" c> G E2- | E2 (3 c d c | "E7" B> ^G E2- | E4 |
w: All of me, | * why not take | all of me.*
              ^
write_syllable loses synchrony with the music while searching
for the next bar line in the music. The problem was fixed
by resetting waitforbar to 0 between the two calls of
write_syllable, in writetrack (genmidi.c) after TNOTE is 
handled.

I found most warning messages about mismatched
lyric syllables to music notes have to do with users
failing to notate syllables correctly when tied notes
occur.  (Failure to place a * or  _ (underscore)  preceding
syllable of tied note. Confusing hyphen with underscore...)



2003 May 4

abc2midi file xref: Abc2midi has the option of converting
only a particular tune in a abcfile to a midi file by specifying
the X: reference number immediately following the abc file name.
When this feature is used, warning messages such as

Warning in line 28: T: outside tune body - possible missing X:

The problem occurs in the function parsefield in parseabc.c.
In order to catch the reference number of the selected tune,
every line of the input file is parsed. A flag "parsing" equal
to 0 or 1 is used to turn on the parsing inside the body of
the of the music. This flag is turned in function event_refno()
in store.c by calling the function parseon() in parseabc.c.
Unfortunately all field lines (eg. T: , M:, L:, V: ...) were 
unaffected by this flag and continued to be parsed. When the
T: field command is encountered, it falls through to the
default: in parsefield and it is processed by the function,
event_field in store.c. Event_field was designed to treat
the T: and R: conditions but before handling these conditions
it checks whether the control flag dotune is set. This flag
is also set by event_refno. If the flag is not set, then 
event_field assumes that a T: field command was encountered
without a preceding X: reference field which is a valid
error condition.

Since all field lines in the abc file are parsed this
introduces other problems. Any anomaly in the field lines
whether they are from the selected tune or not are reported.
For example, if a user has selected for example tune 500
from a large abc file, errors in the field lines of other 
tunes will be reported. Furthermore, in some cases the
program may crash in processing a field line of another tune.

To address these problems, the functions parseline and
parsefield in parseabc.c were modified so that all field
lines (except for the X: field line) and all text lines are
ignored for nonselected tunes. Parseline checks whether 
the flag parsing is set before calling parsemusic or
event_text. In parsefield, the condition key == 'X'
was moved from the switch control structure and
treated separately immediately when entering this function.
If parsing flag has not been set, the function returns
immediately after checking for key == 'X'.

This introduces a new problem. If the abc file has no 
X: field, the abcmidi programs does nothing 
without any error indication. To handle, this situation
I introduced a the global variable parsing_started into
parseabc.c, It is initialized to 0 and set to 1
when the function parseron() is called. Prior to the
end of the function parsefile, the parsing_started
variable is checked. If it is still 0, an error message
is returned.

Finally, event_linebreak() is suppressed in parsefile()
whenever the variable parsing is not set. This avoids
a lot of blank line output from abc2abc whenever the
X: field is missing from the input abc file.

This is a major change to the code, since it affects
three programs, abc2midi, yaps and abc2abc. I hope this
has not introduced new problems.

2003 May 11

Many tunes have a left repeat sign (|:) missing. In most
cases it is fairly clear where to place the repeat sign
and abc2midi merely puts a warning message "Assuming repeat".
When you are processing a large group of abc tunes these
messages may be annoying. A new parameter -NAR (no assuming
repeat) will suppress this message when you are
running abc2midi. However, occasionally you get the error
message "Found unexpected :| ...". This is a more serious
problem.  Due to some ambiguity, the program store.c was
unable to place a missing |: into the tune. During the
second pass, genmidi.c encounters the :| and does not know
where to begin the repeat. This is a real error since the
repeat will not occur. This error message is not suppressed.

The instructions !trill! and !fermata! are recognized by
yaps and abc2midi and are treated in the same way as the
decorations T and H preceding a note. To do this I introduced
a new integer global array decorator_passback[] which is set
by event_handle_instruction in both yapstree.c and store.c.
The array is passed between files parseabc.c, store.c
and yapstree.c as an extern.

2003 May 18

The symbol y used to denote a space in Barfly, is ignored
and no longer causes an error message. It is deleted by
abc2abc.

2003 May 19

Added an option to number bars in yaps. Note the bar numbers
may not match those in abc2midi or other abc*ps programs.
Introduced global flag barnums and global integer nnbars in 
yapstree.c which is set by event_init and linked to 
drawtune.c. Added new -k option in event_init
in yapstree.c. In event_bar in yapstree.c passed the current
bar number instead of NULL in addfeature. In drawtune.c
introduced a new function printbarnumber which is called
in various places in the function printvoiceline.

%%MIDI chordname accepts negative semitone shifts relative
to root. In function event_specific in store.c, replaced
readnump with readsnump.

2003 May 22

Bar numbering in yaps is now in agreement with abc2midi but
may differ by one unit with abc2ps and other members of its
family. See abcguide.txt for more discussion. I moved the
position of the call to checkbar() in event_bar() (yapstree.c)
so it occurs before addfeature is called rather than after.

The decoration field line d: (used inabcm2ps) is not parsed as
a music line but is an ignored field line. Change
was made in parseabc.c in parsefield() and parseline().

2003 May 31

Yaps crashes when it encounters text preceeded by an underscore
in a  guitar chord. For example 
"G" AB/2B/2 "_quiet" DD| g/2g/2d/2d/2 |
here yaps crashes when the function event_handle_gchord (in
yapstree.c)  encounters the text _quiet. The problem was fixed
by ensuring that, cv->instruction_pending is not NULL prior
to adding anything to this structure.

2003 June 6

Yaps ignores any guitar chords placed in front of a chord if
the notes in the chord are not in descending order. For
example in the following line
|"Gm"[G2B2][Ac]|[Bd][Ac][GB]|"D"[A/2c/2][A/2c/2][Ac][Bd]|
the guitar chords Gm and D do not appear because they precede
a chords [G2B2] and [A/2c/2]. This problem also applies to
any instructions (eg. !quiet!) which immediately precede 
a chord. The problem has to do with the way the gchord
and instructions are processed by yapstree.c. When they
are first encountered they are placed in temporary places,
cv->gchord_pending and cv->instructions->pending. When
the next note is encountered, the function newnote moves 
them to fields associated with that note. Unfortunately,
when printvoiceline in drawtune.c processes the notes in
a chord it expects the guitar chord or instructions to be
associated with the first note encountered in the chord.
(It checks chordcount variable.) This is not always true
because the function insertnote in yapstree.c for some
reason will reorder the the notes in the chord if they
are not in descending order.

The fix was to modify noteinsert in yapstree.c so that
if it reorders the notes in the chord, it also moves the
gchord and instructions fields to be with the first note.


14 June 2003

Yaps produces a segmentation error when it fails to
find an expected continuation line and attempts to
print a guitar chord.(eg.)

X:1
T:example
K:C
"C" abcd|\

(In this example there is no more records following the
backslash.)

The error occurs when it tries to execute showtext in
the function notetext in the file drawtune.c. The fix was
to ensure that the pointer spacing is not NULL prior to
calling showtext.


21 June 23

Abc2midi assumes the last %%MIDI gchord string specified
as the default for the start of the tune. In the following
tune,
 
X: 1
T: gchords
M:4/4
L:1/4
K:C
"C" CCCC|CCCC|
%%MIDI gchord czcz
FFFF|FFFF|
%%MIDI gchord fzzz
 GGGG|GGGG|
%%MIDI  gchord fcfz
 CCCC|CCCC|

the gchord string was not set for the first two bars. It was
expected that abc2midi would use the system default for 4/4 time,
i.e. fzczfzcz. Instead, the last defined gchord fzfz was assumed,
which is not expected. If the user places another %%MIDI
gchord string before the first bar or adds a redundant meter
field M:4/4 just before the first bar, everything is ok.
Abc2midi calls setbeat which calls set_gchords just after
it processes the first K: declaration in the field area.
When abc2midi writes the first track writetrack(0) containing
the melody, everything is still ok, except that the accompaniment
is not written at this point. Each time writetrack encounters
another %%MIDI gchord declaration, set_gchord changes the
gchord string. When it is time to start the accompaniment track,
the gchord string was left as the last declared string.

The fix was to move the setbeat invocation from headerprocess()
in store.c to the beginning of writetrack in genmidi.c  when
the accompaniment track is identified. I also added a short
caveate in abcguide.txt about the setting of MIDI gchord
string.


28 June 2003

The %%MIDI transpose command transposes all channels including
the drum channel. For the drum channel, the pitch component
selects the percussion instrument, so transposition is not
appropriate here.

The fix was applied to the function save_note in the file
genmidi.c. Transposition is blocked if the drum channel
9 (counting from 0) is selected.

29 June 2003

Besides the key signature, the K: field can contain many
other descriptors, such as the clef (treble, bass...), the
octave and transposition. The code for parsing the K: field
parsekey was rather convoluted and hard to understand. It
was simplified by breaking it up into several functions.
During this process, I discovered an Easter Egg (undocumented
feature) in abc2midi. It is possible to transpose an
individual voice without affecting the other voices.
The documentation to these features was improved in abcguide.txt.


1 July 2003 

The single voice transpose function described above does not
work correctly in combination with the global transpose initiated
by the %%MIDI transpose (or rtranspose) function. The original
code in store.c and genmidi.c was confusing since communications
between the two files was performed by both the feature/pitch
arrays and a global variable global_transpose which was linked
to both files using an extern int declaration. Here is a
short description on how it was originally.

Parsekey passes transpose to event_key. When a
new transpose value is obtained from event_key, the TRANSPOSE
flag is  added to the feature array and the value of transpose
is put in the pitch array. In addition the  global_transpose
variable (a variable linked to genmidi.c) is also set to
transpose if event_key obtains the transpose value before
getting to the body of the music.  When a transpose value
is obtained from event_specific (i.e. from a %%MIDI transpose
indication) a TRANSPOSE flag is also added to the feature
array and the linked variable global_transpose is always
set to the transpose value.

Genmidi.c processes the TRANSPOSE feature in the function
writetrack. At the start of every track, writetrack sets
the transpose variable (here not linked with store.c) to
global_transpose. When TRANSPOSE feature is encountered the variable
transpose is extracted from the pitch array. The transpose
value is added to the note pitch whenever a note is issued. The
transpose value is also stashed away by save_state in case a
REPEAT feature is encountered. In this situation, the stashed value
is recovered by restore_state.

It would make more sense to treat transpose and
global_transpose independently. i.e.
new pitch = pitch + transpose + global_transpose.
Also it would be be a good idea not to pass global_transpose
to genmidi.c using "extern int" but setting it using a new
feature GTRANSPOSE in the feature array.

Fix: GTRANSPOSE introduced in abc.h. global_transpose variable
and associated code eliminated from store.c. In writetrack
in store.c, another switch condition for GTRANSPOSE was
introduced. global_transpose initialized to 0. transpose initialized
to 0 in starttrack. In noteon_data and addtoQ transpose +
global_transpose are added to pitch. These changes now allow
global_transpose and transpose functions to work together and
independently.

Basically transposition is now performed by either or both
variables 'transpose' and 'global_transpose'. The only difference
between these variables is that the transpose variable is
reinitialized to zero each time a new track is started, while
global_transpose is only initialized at the start of the tune.
These variables are set only through the feature/pitch
arrays in store.c.

5 July 2003

Abcm2ps allows the voice field to contain additional
descriptor information such as the clef name. This information
may indicate a voice transposition by one octave. Abc2midi
and other abcMIDI programs currently ignore this information.

Fix:
A new function parsevoice was introduced into parseabc.
which contains a combination of the code in both parsefield
and parsekey. New parameters were introduced to event_voice
in store.c, yapstree.c, toabc.c, parseabc.c and parseabc.h
in order to pass this information. In store.c, event_voice
will call event_octave if gotoctave is set and insert
a TRANSPOSE feature in the feature/pitch array. In toabc.c,
event_voice will also output the clef if gotclef is set.

In the event that treble+8, treble-8, or tenor-8 is 
specified, parsevoice will set octave to the appropriate
value and set gotoctave so that event_voice in store.c will also
issue an event_octave. The transpose indication in the
clef is detected in the function isclef() in parseabc.c
which now has extra parameters.

Please note no transposition is assumed for the bass clef.
If it is desired that abc2midi transpose that voice, a
octave=-1 or -2, should be included in the K: or V: field.
 


6 July 2003

Abc2midi considers the placement of a V: indication outside
the music body (in the header) as an error and ignores it.
Other applications such as abcm2ps permit V: indications to
occur music header.  In such instances, the voice field
specifies information such as the clef to be used for that
voice. Several changes were needed to handle the this
convention.

(1) In event_voice, the check "pastheader" was disabled; however,
it is important not to call checkbreak() prior to passing the
header. (2) It is necessary to create the first voicecontext
structure immediately after the parser is started rather than wait
for the first K: field (which ends the header block).
Therefore, the code 

   v = newvoice(1);
   head = v;

was moved to event_refno and event_key was replaced
   getvoicecontext(1);

(3) Normally event_octave will transpose all the music voices
if it is called in the music header. This needs to be disabled
when it is called from event_voice. A new parameter, local
(as opposed to global) was introduced into event_voice to
indicate such a situation. (It was necessary to also
put this change in parseabc.c, yapstree.c, toabc.c, parseabc.h,
in addition to store.c)



12 July 2003

Abc2midi loses synchronization between voices when a voice
change occurs in the middle of a bar. The following tune
does not get converted correctly into a MIDI file.

X:1
T: sample
M: 2/4
L: 1/8
K:G
V:1
|:AG Bc|
V:2
|:C2 C2|
V:1
 AG Bc|[1
V:2
 C2 C2|[1
V:1
  CDEF:|[2
  EFG2|
V:2
  D2 D2:|[2
  G4|

The problem occurs when writetrack (in genmidi) is processing the
second repeat. When it comes to the bar marked
with a [1 it attempt to skip to the bar labeled [2, however,
it failed to check for a voice change. (It is unusual to
switches  voices in the middle of a bar.)  Instead it another [1 
and outputs numerous error messages.

The problem was fixed by checking for a voice change and searching
for the continuation of the current active voice using the 
findvoice function.



Yaps terminates prematurely if a tune does not contain a
M: indication in the header. Yaps reports that there is no
M: field but when it attempts to set it to the default 4/4
in startbody(), no voice structure has been created.
To fix this problem  lines of code, setvoice(1) and
startbody() were interchanged in event_true_key() in yapstree.c


13 July 2003

Yaps bar alignment fails in multivoiced files containing
tuples (eg. triplets). For example,

X: 1
T: yaps trips on triplets
M: 2/4
L: 1/8
K: G
V:1
C4|C4|(3BBB (3BBB|C4|C4|
V:2
F4|F4|F4|F4|F4|

The bars for the second line do line up after the triplets.

The function advance() in position.c does not set the
notelengths in the case of triplets. As a result,
spaceline() in position.c has the incorrect temporal position
of the notes when it tries to place the notes on the staff.

Fix: a new variable tuplenotes was introduced in the struct
note (struct.h). This variable is set in event_note, in yapstree.c
and contains the sequence number of the tuple note (descending).
In event that advance() detects a tuple note (based on this
variable), the temporal length is adjusted by multiplying it
by the tuplefactor. (A new function mulfract was introduced
for this purpose.). The notes and bars are lined up now,
but more work is probably needed to get more pleasing spacing.


19 July 2003

Abc2midi fails to set key signature sharps or flats pattern in 
multivoiced tunes with voice indications in the header.
For example in the following tune,

X: 1
T: G minor scale
M: 2/4
L: 1/8
V:2
K: Bb
V:2
GABc|defg|

the notes B and e are not flattened in the output MIDI file.
This is a new bug I introduced in July 5, 2003 when I extended
the abcMIDI package to handle voice field indications in the
header block. For each voice there is a separate voicecontext
structure which contains its own basemap for sharpening or
flattening selected notes. See store.c code.  (This permits
the option of a voice to have its own key signature which is
different from the other voices.)  There is also a global
voicecontext structure used for applying the key signature to
all voices if they are not indicated separately. The global
key signature is copied to the voicecontext of a separate voice
at the time that the voicecontext structure is created.
Unfortunately, if the voicecontext structure is created prior
to setting the overall key signature with the first K: indicator,
then the basemap for that voice is set for C major or A minor.

Fix: a new flag, keyset was introduced in the voicecontext
structure. This flag indicates whether the key signature was
known at the time when the voicecontext structure was 
allocated by newvoice(). Whenever getvoicecontext() switches
voices context, it now checks keyset to determine whether
it is necessary to copy the basemap and related variables
from the global voicecontext structure.
  
I: octave=n has been disabled in abc2midi.
Since an octave shift can be indicated in either the
K: or V: field, it is no longer necessary to use the
info field for setting the octave range. I have disabled
this feature to discourage using the info field for
setting the octave range.


20 July 2003

The hidden rest (x) was introduced in abcMIDI in April 19
2003. Abc2midi treated it as a regular rest but abc2abc
automatically converted it into a regular rest z. The
new  functionality to transpose separate voices that was
introduced in abc2midi now makes abc2abc even more useful.
I have upgraded abc2abc so it now preserves the hidden
rests in the abc files. Yaps continues to not distinguish
the two types of rests (like abc2midi).

Fix: introduced an extra variable in event_rest in 
parseabc.c, store.c, yapstree.c, toabc.c and parseabc.h.
In toabc.c event_rest emits an x instead of a z if
a hidden rest is detected.


16 August 2003


Abc2midi: The drum accompaniment is started or stopped using the 
instruction command !drum! and !nodrum!. The !drum! and
!nodrum! commands are not part of the abc standard so
other applications such as abc2ps and related clones do
not understand this instruction. The programs either ignore
or it or return a warning.

I have introduced an alternate method of starting and stopping
the drum track using the MIDI indications.

%%MIDI drumon
and
%%MIDI drumoff

This is similar to the method of starting and stopping gchords.
(%%MIDI gchordon and %%MIDI gchordoff). I feel this is the
preferred method and the older method will probably be
deprecated. Fortunately, I am the only one using drum
accompaniment (eg. isra.abc) so all of this has little impact.

August 22 2003

Midi2abc creates a abc file with a blank title. It is
more useful to place the name of the input midi file in the
title.

Midi2abc puts a blank line in the abc file in the
event that a newline character \n is embedded in the 
meta_text. A blank line signifies the end of a tune, so
the remaining part of the abc file is not processed.
The function remove_carriage_return was updated so it
now checks for both \r and \n.

August 31 2003

Reorganized and improved documentation of midi2abc.c

Many MIDI files have multiple tempo indications. In fact
some MIDI files change the tempo at every beat. Midi2abc
assumes the last tempo indication; however, in some MIDI
files the tempo slows down at the end. When the resulting
abc file is converted back to a MIDI file it plays much
slower than the original. I have modified midi2abc so
that it now assumes the first tempo indication and
ignores all following indications.

September 8 2003

Midi2abc identifies drum tracks (channel 10) but it needs
to issue a %%MIDI channel 10 to that voice so that abc2midi
will know to assign that voice channel 10. Printtrack was
modified to test for a drum track.

Added two new parameters, -bpl and -bps to control the
formatting of the output abc file. These parameters
control the number of bars printed per line, and the number
of bars to be associated with a music staff. The -obpl
(one bar per line) parameter is deprecated.


September 13 2003

Midi2abc by default does not use the PPQN information in the
MIDI header to determines the note length in MIDI pulses.
Furthermore it ignores any time signature information in
the MIDI file that may be present.  Most MIDI files do
contain valid information so midi2abc produces the best 
output when run time options -xl and -xm are included.
Midi2abc was modified to make these run time options the default
and the unnecessary flags -xl and -xm are now removed. 
To allow the user to force midi2abc to estimate xunits
(MIDI pulses per standard unit note length) from the note
duration statistics, a new option -gu was now introduced.
Since this is a major change in how midi2abc runs, the
version number was bumped up to 2.6.

September 14 2003

Contrary to the documentation, the anacrusis is not specified
in beats but in abc half unit lengths where a unit length is
given in the L: field in the header.  For example if
L:1/8 and M: 4/4, an anacrusis of 1 beat is specified as 4 (i.e.
four 1/16 units).  This is due to the way the quantized 
music is represented in midi2abc. Midi2abc does not allow notes
shorter than than 1/2 an L: unit. Therefore if the unit length is
L: 1/8, the shortest note that can be produced by abc2midi
is a sixteenth note. Note lengths are stored internally in
midi2abc as numerator/denominator where the denominator is
always 2. So a sixteenth note is quantized to a numerator
value of 1. Therefore midi2abc has difficulty representing
very short notes that are encountered in trills or drum
rolls. In such situations you should use the -s option
for short notes to get an approximation.

This also explains why printtrack, findana and guessana want
the barsize to be measured in half abc unit lengths (barsize
is doubled in the calling sequence for these functions.) 

I have corrected the readme.txt and the midi2abc.1 man file.

September 21 2003

Laura Michaels contributed patches to store.c, genmidi.c
and abc.h to handle the Copyright extended information field
(see abc2-draft) and to improve the production of Karaoke
MIDI files. Laura Michaels also provided makefiles for
other compilers such as Ming and Watfor. More details follow.

The proposed standard introduces a new field using the
syntax

%%abc-copyright (c) Copyright John Smith 2003

Abc2midi now inserts this in the MIDI file in the form of a
metatext copyright tag. Changes were made to the event_specific
function in store.c to process the copyright information.

Karaoke file applications such as Winamp, VanBasco;s Karaoke
player, and WinKaraoke (on Windows) have difficulty extracting
the composer and copyright information fields and confuse them
with the Karaoke text. The function karaokestarttrack in genmidi.c
was modified to handle additional @T information lines for
composer and copyright information after the title line in the
first MIDI track. In the Karaoke track (track 3), this
information was also added in the form of @I fields. Also
other abc information fields such as H: and A: were suppressed
in the Karaoke track by setting texton to 0 in printtrack.

The 98 character limit for text lines handled by event_field
in store.c was changed to 255 (see default case in switch (k)).



September 28 2003

For multivoiced abc files there is a need to be able to apply
a fermata to a rest. For example, consider this file.

X: 1
T: fermata applied to rest
M: 2/4
L: 1/8
K: G
[V:1] CDEF|GAF!fermata!G|C2 C2|
[V:2] EFGA|Bcd!fermata!z|C2 C2|
[V:1] CDEF|GAF!fermata!G|C2 C2|
[V:2] EFGA|Bcd!fermata!G|C2 C2|

If the fermata is not applied to the rest, there is a loss
of synchronization between the two voices.

The function event_rest was modified to get the array decorators
from one of its passed parameters. In store.c event_rest would
double the length of the rest (including hidden rests) if
decorators[FERMATA] is set. In parseabc.c it was necessary to
to update the decorators array for the case 'z' and 'x', prior
to passing it to event_rest. Changes were also required in
yapstree.c and toabc.c even though event_rest does not use the
decorators array in these files. The declarations for event_rest
in parseabc.h also needed to be changed.

September 29 2003

A new problem with setbeat (store.c) was discovered. For the
file

X:1
T: time sig
M: 2/4
L: 1/8
K: G
"C" G2 G2| G2 G2|
[M:3/4] G2 G2 G2|G2 G2 G2|


The gchord output was not correct for the first two bars.
This was caused by several problems in the code. (1) Setbeat
calls set_gchord to set the gchord_seq, gchord_len, g_num,
and g_denom used by dogchords. The values for g_num and g_denom
were incorrect because they were computed from mtime_num
and mtime_denom which were set by set_meter. The values
of mtime_num and mtime_denom were the last values in the 
previous tracks processed so if there was a change of meter 
in the tune they would not reflect the initial value.
(2) Setbeat chooses the appropriate gchord string on the basis
of the time signature stored in the time_num and time_denom
array. It is therefore necessary that these values remain
current to the current context during the writetrack pass.
Therefore set_meter was modified to update time_num and 
time_denom whenever it is called.

Set_meter is called in several places. It was called in
starttrack with the global parameters time_num and time_denom.
Unfortunately these parameters are affected by the event_timesig
which is called during the parsing stage. Therefore their
values reflect the last time signature encountered during
the parsing stage. It is necessary to cache the initial settings
of the time signature set in the header block. New variables
header_time_num and header_time_denom are defined in store.c
and passed to genmidi.c as externals.

In writetrack, for the accompaniment track it was necessary
to call set_meter() with the header time signatures just prior
to setbeat(). Set_meter is also called by write_meter in genmidi.c.
Write_meter is called whenever a TIME feature (for time signature)
is encountered. Fortunately, the correct time signature stored in
the num[] and denom[] arrays are used. Setbeat is called shortly
after in printtrack.


October 13 2003

Though most MIDI files indicate a time signature few also
indicate a key signature. Though midi2abc reports any key
signature it finds in the MIDI file, it does not use it but
insists on determining it by scanning all notes and choosing
the key signature that minimizes the number of accidentals.
This works fine if there are no key changes in the music.
If the MIDI file does indeed indicate key signatures and
key changes then midi2abc should use this information in
creating the abc file.

In a similar vein, for some MIDI files there may be more
than one meter change. Midi2abc uses the first time signature
that is indicated in the MIDI file. If it encounters other
time signature indications later, it reports it but it still
uses the initial time signature to transcribe the file.
Again it would be desirable if midi2abc would act on this
information.

Looking at midi2abc.c, it was noticed that the function findkey()
is always invoked except when the key signature is passed in
one of the run time parameters. If a key signature or time
signature metatext command is encountered, a time stamped
text message is added to the tlistx structure associated
with that track. These text messages are sent to the
abc file at the appropriate time using the handletext function
which is invoked by printtrack; however, no adjustment is
made for any key or meter change. Further the barsize
is assumed to be fixed. The barsize is a local variable
in the main program and it is passed to printtrack as
one of its parameters. The barsize controls the placement
of bar lines in the output abc file.


Numerous changes were needed to fix these problems.
(1) A new global flag, gotkeysig was introduced to the code.
It is initialized to zero but set to 1 whenever a key signature
metatext command is encountered. (2) A new variable 'type' was
added to the tlistx structure. If tlistx.text contains the
key signature, tlistx.type is set to 1. If tlistx.text contains
the time signature, tlistx.type is set to 2. For everything
else, tlistx.type is set to 0. (3) The 'type' variable was
added to the addtext() function and in the many places where
it was invoked. (4) In the function txt_keysig(), the verbose
message sent to the tlistx structure was replaced with just
the sf and mi (number of sharps/flats and major/minor flag).
(5) In the function txt_timesig(), The verbose message was
replaced with just the key signature nn/denom. (6) Major
additions were made to the function handletext() which now
does more than just print text at the appropriate place.
If the text string is a key signature or time signature as
indicated by the type variable, then the key signature or
time signature parameters are extracted. If it is a key signature,
setupkey(sf) is called which does all the work of printing
the K: field and setting up the tables for suppressing
the accidentals. If it is a time signature, a M: %d/%d %d
command is printed (time signature and pulses per quarter note).
(7) The barsize variable was turned into a global variable
like asig and bsig. (8) The function txt_timesig() was
broken into two functions, txt_timesig and setup_timesig().
The new function setup_timesig() updates the global variables,
asig, bsig and barsize. If unitlen was never set, it is
also set as well as xunit. Because the notes are quantized
in a separate pass, we must use a fixed xunit and unitlen
for the entire file. Setup_timesig() is also called during
the printtrack pass whenever handletext() detects a meter
change. (9) Printtrack uses the barnotes counter to decide
when to place a bar line. It is set to barsize at the
beginning of each bar and it is decremented by each note.
When it reaches zero a new bar line is issued. (It is
done this way in order to handle anacrusis.) If barsize
changes after the start of the bar it is necessary to
correct barnotes. Printtrack keeps track of the previous
barsize (last_barsize) and uses that to fix barnotes.
(10) Added a new option -gk to force midi2abc to guess
the key signature by minimizing accidentals even though
the key signature is already indicated in the MIDI file.
Normally it will automatically guess the key signature if
no key signature is found in the file and the key signature
is not specified with the -k parameter.

Unfortunately, this was not all the needed changes.
For multitrack MIDI files it is customary to reserve the 
first track for handling global operations such as tempo,
key, meter changes, and text messages. The remaining tracks
contain the actual music. In the case of multivoiced abc
files, it is necessary to apply the meter change or key
change to each voice. Therefore for each voice, midi2abc
needs to also check the tlistx structure in track zero for
any such changes. Another handletext() call was added to
to printtrack to handle this situation.

Abc2midi does not follow this convention exactly. For
single voice abc files with possible bass/chord or drum
accompaniment and possible Karaoke, it uses several tracks
but it does not reserve track 0 for this special purpose.
For multi voice abc files, abc2midi does use track 0 for
this special purpose and places text and metatext commands
grabbed from track one; however, because the delta times
from the missing notes were not accounted for, the delta
times for the time signature and key signatures are
not correct.  (They are all zero.) Fortunately, each
track also has any key or time signature metatext commands
with the correct delta times (assuming the abc file
was notated correctly), so that information in track
zero is not needed. The simplest fix was to suppress
output of these meta commands in track 0. In writetrack
(genmidi.c) a new flag 'timekey' was introduced to suppress
MIDI commands for key/meter changes in track 0.

The function setupkey does not work correctly after
the first call to this function. After that, the accidentals
are put in the wrong place. It was noticed that the
array key[] is initialized to zero in the function findkey()
instead of setupkey where it is actually used. Findkey()
is normally only called once if it is called. The 
initialization code was moved to setupkey.

October 25 2003

When the MIDI file has more than one key signature or
time signature, the first key signature or time signature
displayed in the header block reflects the last signature
that was encountered in the MIDI file rather than the
initial initial signature. This is corrected later on,
however the abc file looks strange. To fix this problem
new variables, header_asig, header_bsig, header_unitlen,
header_keysig and header_bb were introduced. When parsing 
the MIDI file, they are set to the first time signature or
key signature encountered. They are printed in the header
block.

For multitrack MIDI files, midi2abc prints out all
the textual information for track 0 immediately following
the end of the header block (first K: indication). This
unfortunately may include a whole list of key signature
or time signature meta text commands resulting in a 
correct but rather confusing abc file. To avoid this
situation a new variable, trackno, was added to the
function handletext. The function handletext now suppresses
the K:, M:, and L: indications for track zero when the MIDI file
has more than one track.

October 26 2003
 
There are still circumstances where a redundant key signature
or time signature is printed in the abc file. To avoid these
situations new variables, active_asig, active_bsig and
active_keysig were introduced. They are set to the current
status. Before printing a new signature, the present status
is checked and only changes are printed.


November 9 2003

Midi2abc frequently fails to detect triplets in the MIDI file;
even when it has been notated correctly using a music notation
program. Therefore sets of triplets may be converted into

D3/2D-[D/2-D/2]D A3/2B-[B/2C/2-]C| 

instead of 

(3D2D2D2 (3A2B2C2| 

which is another annoyance. Midi2abc.c has a special function
called dospecial which attempts to detect broken notes (eg.
C > D) and triplets; however, it does not seem to work
consistently. The problem is that all notes are quantized
to units of 1/32 or 1/16 notes, (depending on the meter).
The length of a triplet note is 1/12 or 1/24 which does
not get quantized exactly. Thus the representation of this
sequence (calling scannotes in the debugger) appears as
follows.
 
Pitch 62 chan 0 vel 127 time 160 xnum 3 playnum 3
Pitch 62 chan 0 vel 90 time 160 xnum 2 playnum 3
Pitch 62 chan 0 vel 90 time 160 xnum 3 playnum 3
Pitch 69 chan 0 vel 90 time 160 xnum 3 playnum 3
Pitch 71 chan 0 vel 90 time 160 xnum 2 playnum 3
Pitch 60 chan 0 vel 90 time 160 xnum 3 playnum 3

time is in units of midi pulses, xnum and playnum
are in quantized half units where xunit = 120 midi pulses.
The time and xnum are the inter-onset time of the note (length
between onset of this note and the next note). Playnum
is the quantized duration of the note (from midi on to
midi off). All of these variables are computed
by the function quantize() in midi2abc. Note that
160 is not divided even by the half unit = 60. Playnum
is rounded up but xnum compensates for the fact
that it may have been too long in the previous note.

The code in the function dospecial is far from transparent.
It looks ahead one or two notes to determine whether
this note and the following notes should be treated
differently (either as broken or triplets) and uses
the return character or featurecount array  to signal
to printtrack how  to handle these notes. One of the
tests in dospecial is the line just before the
broken rhythm tests is (reformatted for clarity)
 if ((v2 < pnum) || (v2 > 1 + pnum) ||
     (pnum == 0) || (v1+v2 > *barnotes
      )) {
    return(' ');

where v1,v2 refer to the xnum values of this note and the
next note and playnum is the playnum value of the next note.
v2 happened to be less than pnum due to the adjustment
discussed above, so the program returns from this function
without testing for broken notes or triplets. I commented
out /* (v2 <pnum) || */, and triplets are now detected
more consistently.  This could have some impact somewhere 
else, but I do not know at this time.

November 11 2003

More tuning for multiple key signatures (see October
26 2003). In printtrack, I moved the call to handletext
after active_keysig, active_asig, and active_keysig
were set. This fixed a problem in single track files,
where the same key signature was printed twice.
In the main function, header_keysig is set to keysig
only if gotkeysig is equal to zero. Otherwise, header_keysig
can be changed to the wrong (last value of keysig) value
if multiple key signatures exist.

November 12 2003

Midi2abc sometimes places a backslash line continuation
after the last bar or note on a track. This confuses
yaps. A check for remaining data in the track is made
prior to sending a backslash.



December 7 2003

Abcmidi does not handle triplets containing chords correctly. In the
following example.

X: 1
T: triplet chords
M: 2/4
L: 1/8
K: C
(3[CEG] [DFA] [ceg] G2|

The second and third notes in the third chord [ceg] are not
adjusted for a triplet. The problem occurs in event_note,
in store.c. The function decrements the tuplecount counter
for the first note in each chord. Therefore when it handles
the last chord, tuplecount is already zero when it encounters
notes e and g. The fix is not to decrement tuplecount inside
a chord in event_note and event_rest. Instead tuplecount is
decremented in the function event_chordoff.

I am grateful to Jim Russell who identified this bug and
found the fix.

January 3 2004

Yaps does not handle triplets containing chords correctly. In the
following example,

X: 1
T: triplet chords
M: 2/4
L: 1/8
K: C
(3 [CEG] [DFA] [ceg] (3[CEG] [DFA] [ceg]|\
(3 [CEG] [DFA] [ceg] (3[CEG] [DFA] [ceg]|\
(3 [CEG] [DFA] [ceg] (3[CEG] [DFA] [ceg]|

yaps fails to group the chords into triplets.

Analysis: in printvoiceline (in drawtune.c) notes and chordnotes
are distinguished and are processed differently. For notes, the
function contains extra code to check for tuples and to process
them; however, this is missing for chordnotes.

Fix: the code for treating tuples (in the event that they may
be present) was introduced after a chordoff signal was detected 
in printvoiceline.


January 17 2004

Bagpipe music does not sound right without the continuous
drone. It would be useful to introduce new MIDI extensions
(similar to drum and gchord) for producing a drone accompaniment.
The drone accompaniment would be placed in a separate track
and turned on or off using the commands
%%MIDI droneon
and
%%MIDI droneoff

It is desirable that the new code supporting the drone extension
would follow the same style for producing drum and gchord track.
Since that code was quite convoluted a little description is
appropriate here.

Drum and gchord tracks are produced by the functions dogchord()
and dodrums() which are defined in the file genmidi.c. These
functions are called for each beat by the function
progress_sequence(beatnumber). It is not obvious where
progress_sequence is called so this is described here.

Writetrack is called separately for creating the drum and
gchord tracks. These tracks are not represented as a separate
voices in the feature structure array. Instead there are
special flags GCHORDON, GCHORDOFF, DRUMON and DRUMOFF which
signal that the gchord accompaniment or drum accompaniment
should be started (or stopped) at this point in the music.
I therefore introduced two new feature types DRUMON and
DRUMOFF (see abc.h).

For each track, writetrack rescans the entire feature
structure array. If the track is a gchordvoice or a drumvoice,
the noteson flag is not set and case NOTE: is treated differently.
Noteon and add2Q are not called to create "MIDI on" and
"MIDI off" commands; however the delay() and addunits() are
still called to keep track of the beat when the note is
note inside a chord. (A chord is represented in an abc file
as several notes inside square brackets eg. [CEG]). Delay()
calls timestep() and its associated functions which can be found
in the file queues.c. The function timestep() keeps track
of the beat and calls progress_sequence() which calls 
dogchords or dodrums as mentioned above. 

The handling of drone does not require all this complexity
since we do not need to keep track of the beat. Therefore,
it is not necessary to place the drone controls in the
progress_sequence() function. Instead it is sufficient
to just turn it on or off using new functions start_drone()
and stop_drone() which follow the switch case: conditions
DRONEON and DRONEOFF. However, like the drum track and
the gchord track, we want the NOTE: cases to only generate
timestep() calls so we are able to determine the length
(in MIDI time units) of the drone note. Fortunately,
timestep() also updates the global variables tracklen and
delta_time which are used by the functions start_drone
and stop_drone().

Now there are a few details connecting all of this together.
New global variables, dronevoice and dronetrack were introduced
into the file store.c. In the function event_specific()
(which handles the %%MIDI commands in the abc file), new key
words, droneon and droneoff are introduced. They insert
the DRONEON and DRONEOFF features into the feature array and
set the dronevoice flag. In the function finishfile() (also
in store.c), a dronetrack number is assigned if dronevoice
has been set.  

The new global variables dronetrack and dronevoice
in store.c are linked to genmidi.c as extern int(s).
A new boolean int droneon is also added. A new struct,
dronestruct is introduced. This structure contains the
drone characteristics (eg. MIDI instrument, pitch, velocity,
channel) for the drone. Two tones may be defined,
customarily an octave apart and typically the note A
in the lower octaves.

In starttrack(), the drone struct is initialized to default
values if the flag droneon is set and findchannel() assigns
a midi channel for the drone track..


February 7 2004

Introduced a new %%MIDI command
%%MIDI drone val1 val2 val3 val4 val5
It configures the drone. val1 to val5 should be numbers between
1 and 127. val1 specifies the instrument (MIDI program number)
for the drone; val2 and val3 specify the MIDI pitches for the
two drone notes which are played as a chord; and val4 and val5 
specify the MIDI velocities for the two drone notes 
(played as a chord). A value of zero means do not change
the setting for the current parameter.  By default the
drone parameters are 
drone.prog = 70   (bassoon)
drone.pitch1 = 45 (A,)
drone.pitch2 = 33 (A,,)
drone.vel1 = 80;
drone.vel2 = 80;
If you specify a global transpose, the drone pitchws will
also be transposed.

The new code was added into the function dodeferred(s)
in the file genmidi.c



Modified the function parse_tempo in parseabc.c so that
the syntax
Q: 132
is equivalent to 
Q: 1/4=132
This change applies to abc2midi, yaps and abc2abc.


Fixed a bug I had introduced in the function stop_drone (genmidi.c).
The second call  to midi_noteoff should have a delta of zero.


22 February 2004

The -u option in midi2abc.exe does not work.

Problem: despite the fact that xunit was set by the user, 
midi2abc changes it when it encounters a time signature
MIDI command. Fix: a new parameter xunit_set was introduced
and is set to 1 if the user sets xunit using the -u option.
The function setup_timesig does not alter xunit if xnit_set 
has been set to one.


7 March 2004

abc2abc incompatibility issue with abc2mps.
In the event that voices are indicated by symbols rather
than numerals, abc2abc converted them back to numerals
so that a file

X: 1
T: abc2mps incompatibility
M: 2/4
L: 1/8
K: G
%%staves [S A T]
V: S
cdcd|egeg| cdcd|egeg| cdcd|egeg|
V: A
AGAG|GBGB| AGAG|GBGB| AGAG|GBGB|
V: T
A,CA,C|FDFD| A,CA,C|FDFD| A,CA,C|FDFD|

becomes

X: 1
T: abc2mps incompatibility
M: 2/4
L: 1/8
K: G
%%staves [S A T]
V: 1
cdcd|egeg| cdcd|egeg| cdcd|egeg|
V: 2
AGAG|GBGB| AGAG|GBGB| AGAG|GBGB|
V: 3
A,CA,C|FDFD| A,CA,C|FDFD| A,CA,C|FDFD|

This causes a problem for abc2mps.

Abc2abc was modified so that it will preserve the
symbolic codes for the voices. External links
extern int voicecodes;
extern char voicecode[16][32];
were introduced into toabc.c and event_voice
now checks voicecodes before emitting the
voice command.

Beware, the fix may not work correctly if there is
a mixture of numeric and symbolic codes for voices.
If you use symbols for voices, use them for all
voices.


20 March 2004

Midi2abc fails to extract chords when the -sr 
(swallow short rests) option is selected.
The problem occurs in the function quantize()
in the file midi2abc. When the -sr option is
specified, the note's length is determined
more by its inter onset time interval rather
(time between onset times of two adjacent
notes) rather than the time between note off
and note on. In the event of several notes
played at the same time, the inter onset
times will be zero for some notes. Because
quantize() failed to test for this condition,
the function assigned a note length of zero
to those notes and they do not appear in the
chord. The problem was fixed by also checking
for zero inter onset time when the -sr option
is active.


Added a bagpipe tune to demo.abc to illustrate
the use of the %%MIDI drone commands.


25 March 2004

When transposing guitar chords, abc2abc converts
double accidentals to the note above or below.
For example when abc2abc raises the guitar chord
"Db7" in the C scale to "Ebb7" in the Db scale, it
converts "Ebb7" to "D7". This is strictly not
correct.

Fix: event_handle_gchord in toabc.c was modified to
not convert the double flat or sharp to the next
pitch degree by default. A new option -nda (for
no double accidentals) was introduced which
preserves the old behaviour of abc2abc. (Note
the -nda option is only active when you are
transposing to another key.) This change involved
introducing a new global variable nodouble_accidentals.
See comments for 11 April 2004 for more details.

(I am grateful to Atte Jensen for alerting me to
this problem as well as the following three problems.)


27 March 2004

abc2midi fails to tie notes correctly when the
tie crosses bar lines. In the following example

X:1
T: Tie
M: 2/4
L: 1/4
K: C
E ^F-|F F |

abc2midi reports an error
Error in line 6: Could not find note to be tied.

The problem is that F was sharpened by an accidental, but
since the accidental did not apply to the next bar, the
next F appears as a natural and the function dotie()
fails to match the note with F#. As a result, the two
notes are not tied. One could place an accidental on
the second F, but strictly this is not musicly correct.

"An accidental is valid for the rest of the bar (only
the octave where it's written). Tied notes carry the 
accidental to the next bar until the note that ends the
tie is released."

The fix: store.c joins the tied notes in a second pass
after all the notes have been scanned and parsed.
Unfortunately, at this point there is no information
that indicates whether the pitch of the note was
modified by one or more accidentals. A new array
pitchline[] was introduced to store the original
pitch of the note before any accidentals are applied.
The contents of the array are maintained by event_note.
The function dotie now compares pitchline[place] with
pitchline[tienote] rather than pitch[place] with
pitch[tienote]. When it establishes a tie, it
ensures pitch[place] = pitch[tienote].



27 March 2004

abc2abc.exe fails to transfer the clef indication,
clef=F to the output abc file. For example,
V: 1 clef=F
becomes
V: 1

Analysis: the function isclef() in parseabc.c recognizes only
the following clef indications: bass, treble, treble+8,
treble-8, baritone, tenor, tenor-8, alto, mezzo, soprano.
When it encounters clef=F, it fails to recognize F and
assumes there is no proper clef indication. Since 
K: G treble+8
is interpreted as
K: G clef=treble+8
the function isclef() must have a fixed repertoire.

Fix: (1) indications clef= F or clef=f have been added to
the function isclef. (2) Since there may be other indications
that have not been built into isclef and it is desirable that
abc2abc copies these indications, I have added a new
flag, int strict, to the function isclef. The flag strict
is 1 when no clef= was found and isclef is interpreting the
given word. The flag strict is 0 when the given word is
preceeded by clef=. When strict is 0, the function isclef
will assume that the word is something meaningful even
though it does not recognize it and pass a warning message.
If strict is 1, isclef will not return words that it
does not recognize.

Unfortunately, this change introduced another conflict.
See comments for April 11 2004.

April 3 2004

When an abc file is missing a meter M: indication, abc2abc.exe
attempts to correct this situation by adding it to the output
file. Unfortunately it does not do it correctly as seen in
the following example.

X:1
T: Missing M:
L: 1/8
K: C
CDEF GABC| CDEF GABC|

output


X: 1
T:Missing M:
L:1/8
K:CM:4/4

CDEF GABC| CDEF GABC|

Analysis:
The function event_refno in toabc.c which is called whenever an
X: command occurs, initializes barlen.num to zero.  The function 
start_tune() in toabc.c checks whether barlen.num is still zero,
which indicates that a M: indication is missing. If it is zero,
it calls event_timesig to set it to the default time signature
of 4/4. Unfortunately, it places a linebreak after calling
event_timesig instead of  before. Fix: the function event_linebreak
was moved before calling event_timesig.

April 11 2004

The patch dealing with transposing guitar chords in toabc.c
(refer to March 25 2004 note), did not work correctly so it
was necessary to take a different approach. Apparently,
the code in event_handle_gchord works correctly for all
diatonic guitar chords. The algorithm finds the chord's
pitch ignoring all following accidentals using the offset[]
table. It adds the transpose interval to the pitch and then
shifts it by +1 or -1 in event that the chord is followed
by sharp or flat accidental. For nondiatonic chords (i.e.
contains notes not present in the key signature), the
transpose algorithm yields the correct chord but represents
it incorrectly for the key signature. For example, suppose the
nondiatonic chord in the C key signature is Dbm which is
a degree 2 minor triad. When it is transposed one semitone
to the Db key signature, the chord should now be Ebbm.
However, event_handle_gchord changes it to Dm chord which
has the identical notes but has the wrong representation
(it was changed to a degree 1 minor triad).

To fix this problem, it was necessary to compute the
triad degree in the original key signature and compare
it with the degree of the transposed triad in the new
key signature. If they are identical, everything is fine.
If they are different by one degree, then an adjustment
is needed. The degree actually also depends upon the
mode of the key signature (major/minor/dorian/lydian ....),
however for simplification we shall assume it is the
major key signature. (The toabc.c file is not passed
the key signature but the number of sharps or flats
in the key signature.)

The following changes were made. New global variables
orig_key_number and new_key_number were introduced which
represents the tonic (ignoring accidentals) of the original
and new key signature (assuming major scale). They are
represented by numbers where A is zero, B is 1, etc.
These variables are set by event_key which handles the
K: field command. In the function event_handle_gchord,
the triad degree (old_triad_number) is computed by 
subtracting orig_key_number from the key_number.
Something similar is done for the transposed triad, yielding
new_triad_number. If the degrees are not identical, the
tranposed triad is shifted back and a sharp appended or
else shifted forward and a flat appended. Otherwise
nothing is done. (The correction is disabled if the
flag nodouble_accidentals was set by the -nda run time
parameter.)

April 11 2004

Key signature K:F no longer processed correctly.
eg.
X:1
T: key signature problem
M: 2/4
L: 1/4
K: F
G A|B D|F2|

This problem occurs in abc2midi, abc2abc and yaps since
they all share the same parser.

This was caused by introducing F and f as an option in
the isclef(..) function in parseabc. (See March 27 2004
report.) As a result the F is first interpreted as a clef 
indication and ignored as a key indication.

Fix: if F or f is used to specify the clef then it
must be preceded by clef=. This is not true for other
indications like soprano+8. To fix this I inserted
the condition strict==0 in the test for F or f in isclef(). 

April 16 2004

Abc2abc: demoted "No repeat expected" from an error to
a warning in toabc.c


April 21 2004

Introduced a new gchord code b (both) which produces a fundamental
and chord in the same beat. Thus b behaves like a combination
of f and c. For example:

%%MIDI gchord fbfc

the second beat would be the fundamental and chord played together.
The new code was introduced in dogchords() and set_gchords()
in genmidi.c.


April 22 2004

Abc2midi: Guitar chord inversions do not work consistently.

For the tune

X:1
T: gchords
M: 4/4
L: 1/1
K: C
"G" z|"G/B" z|"G/D" z|

"G/B" specifies the first inversion of the G major guitar chord
and "G/D" specifies the second inversion of the G major guitar
chord. Running midi2abc on the output midi file we discover
that the second inversion was not produced.

%"G"
G,,z [DB,G,]z G,,z [DB,G,]z| 
%"G/B"
G,,z [GDB,]z G,,z [GDB,]z| 
%"G/D"
G,,z [DB,G,]z G,,z [DB,G,]
# second inversion not produced.

Inversions are detected by the procedure event_handle_gchords
in the file store.c. It passes the inversion flag to genmidi.c
through the array num[], which is extracted by writetrack for
the  GCHORD feature. The function dogchords in genmidi, generates
the notes of the gchord. The value of inversion refers to
the pitch of the note after the slash relative to the base
note of the gchord.

One problem was traced to the statements
    for (j=0; j<chordlen[chordnum]; j++) {
        if (basepitch + chordnotes[chordnum][j] % 12 == inversion % 12) {
in dogchords.
Parentheses are required in the if statement so that the
modulo 12 acts on the sum of basepitch and chordnotes. Thus the
statement was changed to
       if ((basepitch + chordnotes[chordnum][j]) % 12 == inversion % 12) {

The actual inversion (shifting up of a note in a gchord by one octave)
is done in the statements which occurs in the last for loop prior
to the break.

if (inchord) {
     note = inversion + ((note + 12 - inversion) % 12);
     };

I could not understand the logic in this statement
and found that it does not perform the inversion consistently.

I therefore made the following changes to the inversion algorithm.
The local variable inchord now stores the position of the lowest
note in the inverted chord. Thus for inverted chord G/B, inchord
would be 1 because B is at index position 1 in the chord GBE.
For G/E inchord would be 2. G/G does not represent an inverted
chord so inchord set t0 0 which indicates to do nothing and is
consistent with the logic. The last for loop before the break was
replaced with.
 for (j=0; j<chordlen[chordnum]; j++) {
          note = basepitch + chordnotes[chordnum][j];
         if (j < inchord)
            note += 12;
          save_note(g_num*len, g_denom, gchord.base + note,
                    gchord.chan, gchord.vel);
        };

I tested the new code with the file

X:1
T: gchords
M: 4/4
L: 1/1
K: C
"G" z|"G/B" z|"G/D" z|
"Am" z|"Am/C" z|"Am/E"z|
"Bdim" z|"Bdim/D" z| "Bdim/F" z|

The inversions now appear to be done correctly.



April 23 2004

Abc2abc does not place linebreaks on comments
prior to X:

For example for the file

% comment 1
% comment 2
X: 1
T: Precomments have no linebreaks
M: 4/4
L: 1/1
K: C
D|E|F|

The ouput is

% comment 1% comment 2X: 1
T:Precomments have no linebreaks
M:4/4
L:1/1
K:C
D|E|F|

Analysis: the problem was introduced by the changes
I made on  2003 May 4 as described above. Linebreaks
were suppressed to prevent the production of many
blank lines for abc files with missing reference number
(no X: field). This unfortunately introduced another
problem which was discovered recently. The
X: reference number is  absorbed by one of the
comments appearing prior.

Fix: An event_linebreak is executed after parse_precomment
in parseline (parseabc.c) in event that the parsing flag
is not set. Hopefully this has no impact on yaps and
abc2midi.


May 1 2004

A new gchord feature introduced in abc2midi. It is now
possible to arpeggiate the guitar chords. New gchord
codes g,h,i,j,G,H,I,J were introduced. They reference the
individual notes in the  guitar chord. g is the lowest
note and j is the highest. For example for the
G major chord, g references G, h references B and
i references D. The upper case letters are the same
notes one octave lower.

If you specify a gchord,
%%MIDI gchord ghighi 

Then abc2midi would fit the notes GBDGBD in each bar.
Same rules for length of notes apply as before.

Implementation: All the changes were made in the genmidi.c
file.  A new global array gchordnotes[] and global variable
gchordnotes_size was introduced. The function set_gchords
was extended to recognize the new codes hijk. A new
function configure_gchord() was created from part of the
body of dogchords() dealing with case 'c'. The function
loads the gchordnotes array based on the global variables,
basepitch,chordnum and inversion. The function is called
by writetrack for the GCHORD feature (whenever a guitar
chord name is detected). The dogchords() function was
modified to process the new gchord codes and to use
the gchordnotes[] list.

The demo.abc file was extended with another example.



May 7 2004

The -Wtraditional flag was removed from the makefile,
since it posed some problems with the lastest gcc
compiler.

The following midi2abc problems were reported by 
Werner V. Hoersten with suggested fixes.

The -m option for setting the time signature in midi2abc.exe
causes the program to crash with a floating point exception.
(This is a bug that I probably around October 2003.)
Analyis: when the time signature is provided in the run
time parameters, midi2abc set the flag tsig so that txt_timesig
ignores any time signature metatext commands in the midi
file. Therefore header_asig and header_bsig are still
initialized to zero and a division by zero occurs when
the main function attempts to compute barsize. Fix:
prior to computing barsize, the main function checks
whether tsig was set. If it was set, header_asig and
header_bsig are assigned values specified in the run
time parameters.

I made some minor changes to midi2abc.c to reduce some of
the warning messages.
(1) the function testtrack() is declared at the beginning
of the file so that guessana knows what parameter it returns.
(2) setup_timesig function is declared as returning void.
(3) the function txt_timesig was placed after the definition
of setup_timesig.
(4) The static declaration for ttype[] in txt_metatext()
was removed. (It was necessary for -Wtraditional for the
gcc compiler.)


May 8 2004

Midi2abc fails to identify triplets in midi files with
3/4, 3/8 or any multiple of 3 beats per measure time signature.

For example if you convert the following file

X:1
T: triplets
M: 3/4
L: 1/8
K: C
(3C/D/c/ (3C/D/c/ (3FAc (3FAc |\
(3C/D/c/ (3C/D/c/ (3FAc (3FAc |

to a MIDI file using abc2midi and then back to a abc file
using midi2abc, you get


X: 1
T: from /home/seymour/abc/triplets31.mid
M: 3/4
L: 1/8
Q:1/4=120
K:C % 0 sharps
%%triplets
C/2[c/2D/2]C/2[c/2D/2]F/2A/2 z/2c/2F/2A/2z/2c/2| \
C/2[c/2D/2]C/2[c/2D/2]F/2A/2 z/2c/2F/2A/2z/2c/2|

which is far from what one expect. (Note the chords
[c/2D/2]).


Analysis: for some unknown reason the function dospecial()
in midi2abc checks the time signature of the input and
does nothing if the number of beats in the key signature
is a multiple 3 or if the number of beats is not a multiple
of 2.

Fix: these conditions were commented out and triplets
are now detected.



Midi2abc cannot identify triplets composed of chords.
For example for input

X:1
T: triplets
M: 3/4
L: 1/8
K: C
(3[CE][DF][ce] FADC |(3[CE][DF][ce] FADC |

converted to a midi file, midi2abc produces

X: 1
T: from /home/seymour/abc/triplets41.mid
M: 3/4
L: 1/8
Q:1/4=120
K:C % 0 sharps
%%triplets
[E/2C/2][F/2D/2]z/2[e/2c/2]F ADC| \
[E/2C/2][F/2D/2]z/2[e/2c/2]F ADC|

Analysis, the function dospecial() was not designed
to handle chords. The problem is unresolved.
You will have to edit the output file manually.



Midiabc cannot identify triplets tied to a previous
note. For example,

X: 1
T: tied triplet
M: 4/4
L: 1/8
K: C
G2- (3GBd E2 (3FGA|G2- (3GBd E2 (3FGA|

The MIDI file created  from the above converts to

X: 1
T: from triplet51.mid
M: 4/4
L: 1/8
Q:1/4=120
K:C % 0 sharps
%%tied triplet
G2- G/2B/2z/2d/2 E2 (3FGA| \
G2- G/2B/2z/2d/2 E2 (3FGA|

This is also beyond the capabilities the function dospecial().
The problem has not been resolved.



Improvements in appearance of output.
The function printtrack() in midi2abc places a blank (space)
before the beginning of a triplet.



May 9 2004

Midi2abc cannot resolve 32nd notes played in 4/4 time.
For example, in the last bar of the MIDI file produced
from the abc file

X: 1
T: no thirty-second notes
M: 4/4
L: 1/8
K: G
 CDEF             C/E/D/F/    G/A/B/C/  |
 (3CDE   (3DEF    (3EFG       (3FGA|
 C/4E/4D/4F/4 C/4D/4E/4F/4 G/A/B/C/  z4|

there are a series of 32nd notes.

The output from midi2abc is

X: 1
T: from precis1.mid
M: 4/4
L: 1/8
Q:1/4=120
K:G % 1 sharps
%%no thirty-second notes
CD EF C/2E/2D/2F/2 G/2A/2B/2C/2| \
 (3CDE  (3DEF  (3EFG  (3FGA| \
z/2z/2z/2z/2 G/2A/2B/2C/2 

The series of 32nd were replaced by rests.

Analysis: the temporal resolution of midi2abc was set
to half of the abc unit length specified by L: field
command. Thus for L:1/8, the smallest note produced
is a 1/16 th note. Midi2abc automatically chooses
the L: value based on the time signature. For time signatures
less than 3/4 the L: value is set to 1/16. For other
time signatures it is 1/8. The purpose of limiting
the resolution is to avoid unusual note lengths
such as C2-C//2 which should not occur in music notation.
The L: value is set by the function setup_timesig().
The number of parts per L: time unit, is unfortunately
not explicitly expressed in the midi2abc code.

Fix: a new global variable, parts_per_unitlen, was added
to the file midi2abc.c and set to the default value of 2.
If you search for this variable, you can see the places
where the splitting of the time unit into 2 parts
was built in. A new run time parameter, -ppu allows
you to change this value.  For example if use -ppu 4, midi2abc
should be able to handle the 1/32nd notes. This establishes
the basic quantum unit that midi2abc uses.

A new run time parameter -aul which allows you to set
the L: abc unit length was introduced. Checks were
introduced to ensure that the -ppu parameter and the
-aul are powers of two.
 

May 10 2004

Midi2abc like other abcmidi applications requires that the
run time parameters be place before the parameter list. This
is different from most Unix/Linux applications. However,
in many cases midi2abc is forgiving and is still able to
fine the input filename. This is not true for the -u parameter.
For example,

midi2abc.exe -u 100 precis1.mid

will result in 
Error - Cannot open file 100.

Fix: the character u was added to the "ambQkco" string in the
function huntfilename() in midi2abc.c



May 15 2004

Midi2abc/abc2midi incompatibility in the handling of accidentals.
When abc2midi converts the following file to a MIDI file:

X: 1
T: accidentals
M: 4/4
L: 1/8
K: G
FGB^D gdef | FGBD gdef |
FGB^D g=def| FGBD gdef |


the sharp accidental (^) applied to the D also acts on all other D's
in that bar including d which is shifted by an octave (bar zero).
To prevent the sharp applied on the second (shifted D), it is
necessary to place a natural (=). Midi2abc does not comply with
this convention so it produces the following output from the
MIDI file.

X: 1
T: from accid1.mid
M: 4/4
L: 1/8
Q:1/4=120
K:G % 1 sharps
%%accidentals
FG B^D g^d ef| \
FG B=D g=d ef| \
FG B^D gd ef| \
FG B=D gd ef|

Note that in the second bar (starting from zero), no natural
was placed in front of d, resulting in a different note.
(This only occurs when the two notes differ by one or more
octaves.)

Fix (as suggested by Werner Hoersten): in the function
printpitch(), replace

back[trans[i]] = i;

with

for (i=p % 12; i<256; i+=12)
     back[trans[i]] = i;

Now midi2abc and abc2midi are consistent with each other.


May 15 2004

The -gk option  in midi2abc.c is working again.




June 12 2004

Improved the handling of grace notes. The size of the
grace notes is no longer determined by a fixed ratio.
Instead the grace notes are of constant length specified
by a new %%MIDI gracedivider command. The old method
is still supported.

June 25 2004

store.c (abc2midi): Commented out compilation flag 
INFO_OCTAVE_DISABLED 1 now allowing the handling of [I: octave=1].
(It was disabled in July 19 2003. The instruction field
command I: is parts of the proposed abc standard 2.0.
so I have decided to enable it.)

June 25 2004

abc2midi.c: For the -sr option to swallow rests, you can
specify the size of the rest in quantum units. Quantum unit
is defined in readme.txt updated today.

July 3 2004

midifile.c: added new global Mf_bytesread (number of
bytes read in track).

July 4 2004

midi2abc: added new runtime option -Midigram. If it
is selected, all other options are ignored and no
abc file is created. Instead, a new function midigram()
is called and the program lists all the notes occurring
in the file where each line represents a note on/note off
event. The line is in the following format.
on_time off_time track channel midi_pitch midi_vol.
The on/off time is given in quarter beat units (ie.
midipulses/ppqn where ppqn is pulses per quarter note
specified in the MIDI header). The last record indicates
the duration of the MIDI file in MIDI pulse units.
Though in theory, this feature should be put into a separate 
program, it was felt there were enough programs in the abcmidi
package.

The code to convert the midi file to an abc file in
main() was stuffed into a new function called midi2abc.
New functions (no_op0,,no_op5, print_txt_noteon,
print_txt_noteoff, init_notechan, open_note, close_note
and initfunc_for_midinotes were created.


July 11 2004

abc2midi, yaps, abc2abc, midi2abc. Introduced a new
parameter -ver which prints out the current version number
of the program.

Added a new program, midicopy to the abcmidi package.
(Documentation put in midicopy.1 and readme.txt.)
All the makefiles were updated, however I am unable to
check out the ones in the makefile subdirectory.

July 17 2004

abc2midi (store.c), yaps (yapstree.c), abc2abc (toabc.c),
midi2abc (midi2abc.c) midicopy (midicopy.c) for -ver
parameter changed exit(1) to exit(0) after printing
out version number.


August 21 2004

A lot of abc files indicate ornamentations using the tilde
operator ~. Abc2midi has been substituting a roll for the
ornamentation. Guido Gonzato has suggested that it should
be replaced with an acciaccatura for all notes except
dotted quarter notes. The dotted quarter note should
be replaced with three eight notes where the second
note is preceded with an acciacatura and the third note
is preceded with an appoggiatura.

Two new procedures were introduced in store.c.
Doornament applies the action when decorator[ORNAMENTATION]
is encountered. The function doornament calls the new function
makecut which inserts a grace note. (Unfortunately the length of 
the grace notes cannot be adjusted using the %%MIDI gracedivider
as described on June 12 2004 since the %%MIDI commands are
processed later.)  The procedure event_note was modified 
to call doornament instead of doroll when an ornament is encountered. 

September 05 2005

A new feature was introduced in the abcmidi package.
Abc2abc: a new run time parameter, -nokey was introduced.
It will suppress the key signature and place all the
necessary accidentals. Abc2midi, abc2abc, yaps understand
the key signature K: none. For such key signature, no 
sharps or flats will be assumed. The -t (transpose) function
in abc2abc should work with K: none.


Changes were made to parsekey in parseabc.c and to
event_key and event_note in toabc.c (search for nokey)
to recognize K: none. When K: none is encountered,
abc2midi, yaps and abc2abc assumes no key signature
is supplied.

September 06 2005

Yaps does not display the note length correctly when no
L: is declared in the abc header. Fix: in start_body (yastree.c)
replace 
   setfract(&thetune.unitlen, 1, 16); 
with
    event_length(16);
etc.


September 12 2005

More work was needed to the -nokey option working correctly.
In order to ensure that toabc.c works the same way without
the new feature, event_note was divided into two functions
event_note1 and event_note2. Event_note1 is an exact copy
of the original event_note and is called when nokey is not
set. Event_note2 contains all the new code for transposing
notes when nokey is set. When event_note is called it either
calls event_note1 or event_note2 depending upon the status
of the flag nokey.

Event_note2 performs the transposition in a different
fashion. The note is converted to a midi representation.
The number of semitones is added to the midi representation
and the midi representation is converted back to the
note representation. Code for converting to the midi
representation was borrowed from store.c and code for
converting the midi representation back to the note
representation was borrowed from midi2abc. There was
a small incompatiblity between setmap representation
(character versus numeric representation) which had
to be fixed.

The -nokey option was split into two options.
-nokeys will use sharps. -nokeyf will use flats.

September 13 2004

Added gchord default for 12/8 time (fzcfzcfzcfzc).

September 17 2004

Cleaned up all source code to reduce the number of compiler
warnings reported by Microsoft Visual C++.  ANSILIBS 
is now defined when compiling with Visual C++.

September 19 2004

Many abc tunes do not specify the tempo with the Q: command.
By default abc2midi uses a tempo of 120 quarters notes per
minute. For many tunes, this is too slow. A new run
time parameter -Q was introduced into abc2midi, allowing
you to specify the default tempo in the event that no tempo
was specified. If the tempo is specified in the abc file,
this parameter is ignored.

A new global default_tempo (initialized to 120) was introduced
in store.c. This parameter can be changed using the -Q run
time option added to event_init.

September 20 2004

Fixed bug in applygrace_new which causes floating point
exception (divide by zero) for some abc files.



September 26 2004

abc2abc does not recognize the parameter name="some string" eg.
in the multivoice command. For example,
V: 1 name="alto 1"
instructs abcm2ps to print "alto 1" on the staff. Unfortunately,
abc2abc does not show this parameter in the output file.
This is part of the proposed abc 2 standard. 

Fix, parsevoice in parseabc.c now extracts the name= parameter
in the V: command. The event_voice command (which appears
in store.c, yapstree.c and toabc.c) now has two extra parameters
for passing the name string. In toabc.c, event_voice prints out
the name string when it is found in the voice command. I introduced
a new function parsename, which processes the "name= ..." parameter.
In addition I fixed a bug which causes V: transpose=1 to produce
a segmentation error.


October 2 2004

As mentioned above on August 21 the new implementation of
dooranment did not allow configuring the length of the grace
note using the %%MIDI gracedivider command. This was fixed
by replacing the implementation of the procedure makecut.
Initially gracedivider was alway 4 (the default when it
is not specified).

October 8 2004

The abcguide.txt and proposed abc standard 2 includes the use
of  multirepeats (i.e |:  ..|[1,3 .. :|[2,4.. :| ).
Though yaps and abc2abc can handle this syntax, 
abc2midi fails to handle it despite some earlier effort to
introduce it.  For example, some of the code added to in genmidi.c
to handle multirepeats includes (eg. inlist(j, passnum)).
Furthermore, the old feature codes REP1 and REP2 was replaced
with PLAY_ON_REP.  Nevertheless, the code does not process 
correctly multirepeats.

For reference the parser (parseabc.c) maps the repeat symbols
into the features in the following manner.

|:    BAR_REP
:|    REP_BAR
::    DOUBLE_REP
[1, [2 etc PLAY_ON_REP and places the count in pitch[] or
a text string.

The problems occur in two places: (1) writetrack in genmidi.c and
(2) fixreps in store.c. Writetrack needs to keep track of the number
of times the section has been repeated using the variable "pass"
so that it knows which bars to play. However, for both case REP_BAR:
and case DOUBLE_BAR: the pass variable is allowed to assume only values
of 1 and 2. Therefore, it cannot handle |[3 or whatever. If more
than one :| (REP_BAR) is associated with a |: (BAR_REP) this
causes an event_error.

To make things more confusing there is another variable 'additive'
which refers to an undocumented feature in  the P: command where the 
symbol + and - indicates whether repeat marks in a part section are
to be processed or ignored. I don't beleive this feature has ever 
been used.  I have therefore removed this feature to make the code easier
to support. From now on additive is always assumed. In other words
if a repeat section occurs in a PART it is always repeated. There
is now no way to ignore the repeat command.


Fixreps was primarily designed to insert a BAR_REP (|:) when
it is missing in the beginning of the tune. However, it tries
to do much more. It checks for syntactical errors such as two
or more closing repeats associated with an opening repeat as an error.
If it finds an extra closing repeat, it attempts to insert a matching
opening repeat (which is not desirable for multirepeats). If it
finds two opening repeats a row, it attempts to correct the situation
by changing the second opening repeat into a double repeat ::. 
Unfortunately, these checks get in the way when you have multirepeats.

The multirepeats syntax appears to allow the use of either
a :| or || for separating sections. This does not seem to
be built into the writetrack code.

This seems to more than a weekend project.
 

October 15 2004

In order to handle multirepeats, several changes were
introduced into the writetrack code in genmidi.c

First a new variable, maxpass, which specifies the
maximum number of repeats was introduced. It is
initialized to 2 and reset to 2 any time a left
repeat symbol is encountered. The code for the
switch block REP_BAR (:|) was changed so that
the variable pass can be incremented until it
reaches maxpass. A check for whether a right repeat
was expected (i.e. a left repeat was found), is
only made on the first pass. (The flag expect_repeat
is cleared after the first pass.)

More changes were made to the switch block code for
PLAY_ON_REP which handles any of the indications such
as |1 , |[1, |[1,3 etc. The code
... parts !=-1) {
    passnum = partrepno = 1;
was removed since it was a remnant of the undocumented
additivity feature. The error "Cannot find :| || [1 ..."
is not invoked when encountering PLAY_ON_REP while
skipping a variant ending. When a variant ending is
found maxpass is set to pass+1 in case this is not
the last variant ending.

The fixreps code in store.c also required changes.
The code mainly inserts a |: in the beginning
of the tune in case it is needed. Unfortunately,
the code can make other unexpected changes
and does not understand multiple repeats.
For example, if it encounters two left repeats (|:)
without intervening right repeats, i.e.
|: some stuff |: some stuff etc.
then it assumes the second left repeat was a
mistake and changes it to a double repeat :: without
any warning. If fixreps finds two right repeats (:|) in a
sequence, then it returns a message that a spurious
right repeat was found and inserts a new left repeat
at a previous bar line.

For the case PLAY_ON_REP, fixreps identifies
two situations, denom[j] == 1 corresponding to [1 and
denom[j] == 2 corresponding to [2. For the second case,
it was assumed that no more REP_BAR (i.e :|) would be
encountered so the flags expect_repeat was cleared.
This is not correct for multirepeats, so those lines were
commented. Furthermore, when a [1,3 or something similar
is encountered, denom[j] is now 0 and the code falls into 
the next case statement BAR_REP2 which should never happen.
Another break statement was added to prevent this from occurring.

Major changes were made to fixreps. Now it only checks
for missing |: before [1 :| or ::. It also checks
for two |: |: in a row. If you use multirepeats, i.e. 
more than 1, be sure to end last variant with a double
bar line.


Other related changes to store.c: got rid of the obsolete
functions event_rep1 and event_rep2. They are no longer
used.

Corrected abcguide.txt on the handling variant endings.

Added protection for file runaway in eputc in midifile.c.
abc2midi.exe will abort if it attempts to create a midifile
larger than 500000 bytes.


October 24 2004

More work was needed to correct problems with the abc2abc
-nokeys option. Propogation of accidentals across bars was
not working.

Fix for toabc.c: the pitchof() function was changed. The
function setupkey() was eliminated and printpitch() was
rewritten. It now handles propogation of accidentals 
across bar lines but not between bar lines in event
of a tied note. The latter case would involve considerable
more development since no code for linking tied notes
is present in toabc.c. (Store.c, for abc2midi, does the linking
in a separate pass -- dotie, but toabc.c does everything in
a single pass. The code can get quite hairy if we have 
interleaved voices.)

October 29 2004

For K:none, abc2abc uses flats or sharps depending upon the
variable useflats in the function printpitch (toabc.c).
The variable useflats is set by the run time parameter
-nokeyf. For some music, one might want to have the
variable useflats be adaptive to the type of guitar
chords (gchords) transposed by abc2abc.  I introduced
as an experiment the option of adapting useflats to
the presence of flats or sharps in the guitar chord.
When the variable adapt_useflats_to_gchords is set,
some adaption is done after the guitar chord is processed.
In general for K:none, abc2abc tends to use sharps
in the guitar chords for any transpositions unless
flats have been written into the guitar chords.


November 4 2004  also see June 13 2005

Chord syntax extension: it is convenient to express a chord
as [CEG]3 instead of [C3E3G3] which is part of the proposed
abc standard version 2. Presently the abcmidi parser will consider
the 3 after the ] as a stray number however other software
such as abcm2ps allows this extension.

Current practice: the parser run differently in each
application (abc2midi, abc2abc, and yaps) so each has
to be examined separately.

abcmidi:
writetrack in genmidi.c checks whether a note
is inside a chord. If it is in a chord, a midi_noteon is sent
to the MIDI file and a midi_noteoff based on the feature/num/denom
information is sent to the queue. The delay time is not advanced,
so that all remaining notes in the chord will start at the
same time. When the end of chord marker is encountered, the
delay time is advanced by the amount in the feature/num/denom 
arrays so that the next note will start at the right time.
at the right time. This amount recorded with feature CHORDOFF
is (modified) by tiefix to be the last note length encountered
in the chord.

Fix: 

Parseabc.c was modified to pick up the chord length placed
after the closing bracket "]". If it is not indicated, it
gets 1/1. The chord length is passed to event_chordoff
via new parameters chord_n and chord_m. 

abc2midi:
In store.c, the event_chordoff handler checks the chord_n,chord_m
values. If they are 1,1 then addfeature sends a CHORDOFF feature
and everything runs the same; otherwise addfeature sends a
CHORDOFFEX and chord_n*4,chord_m*v->default_length is placed in
num, denom storage. CHORDOFFEX is a new feature type added
to abc.h for handling this situation. Genmidi.c treats
CHORDOFF and CHORDOFFEX the same way.

A new function fix_enclosed_note_lengths was introduced to 
readjust the note lengths of all the notes in the chord in
the event that it is set outside the enclosing brackets
(i.e. CHORDOFFEX).

The function tiefix now keeps track of the chord start ([)
in the variable chord_start. When it encounters a CHORDOFFEX, 
it calls fix_enclosed_note_lengths.


November 07 2004: -chord extension continued

yaps:

Unlike abc2midi, yaps only performs one pass through the
abc file while preparing a very detailed layout of the music
in a complex data tune data structure. You can view part
of this structure by running yaps with the -d parameter.
This data structure is passed to printtune() in drawtune.c.

A new function fix_enclosed_note_lengths was created in the 
file yapstree.c to adjust the note durations. This function
is called by event_chordoff when the parser encounters 
the end of a chord (']'). The new function does nothing
if ] is not followed by a note length. Otherwise it corrects
cv->barcount in order to avoid warnings regarding the
number of beats in the bar. It replaces the note duration
of each note in the chord with the new note duration.
The function count_dots is called to replace the note
duration representation. (There still seems to be a
problem here.)

abc2abc:

Minimal changes in toabc.c were made. The function event_chordoff
was modified to output the note length information following
the chord if any and to correct the bar count. 


November 20 2004

The fix for handling chord extensions in yaps did not work
properly and would frequently place tails on notes which
should not have tails. It was discovered that chords have
their own structure for indicating their PostScript representation
and their tail is drawn by a function called drawchordtail.
The yapstree.c function event_chordoff was modified to also
update the chord structure when the chord extension occurs.

Introduced a new folder called programming in the doc subdirectory
and moved abc2midi.txt, midi2abc.txt and coding.txt into this
folder. The folder contains some program implementation details.
The file yaps.txt was renamed to yapshelp.txt. A new file
yaps.txt describing the implementation of yaps was prepared.



November 28 2004

Abc2midi new feature: all notes in a chord are started at the
same instant. Inserting a short delay between the start of the notes
in the chord would provide more control over the timbre. However to 
ensure that the music is not lengthened, it is necessary to ensure
that all the notes end at the same time.

Implementation of this feature was not easy due to the way the
notes are handled are converted to MIDI commands in genmidi.c
and the complexity of the queues.c code. MIDI note on commands
are sent by a long chain of function calls starting with the
function call to noteon(). Noteon() determines the velocity 
of the note from the beatstring and current context and then
calls noteon_data(). Noteon_data() calls midi_noteon() and
updates the tracklen. Midi_noteon() calls mf_write_midi_event
which finally records the MIDI command.

The MIDI command to stop playing the note is sent to a queue
by the function addtoQ which is defined in the queue.c file.
Finally if this note is not inside a chord, or if a end of chord
feature has been encountered, the notes in the queue all processed
by calling the function delay(). Delay() converts the note duration
in MIDI tick units and calls the function timestep() which
is defined in queues.c.

The global variable delta_time indicates the time delay in
MIDI tick units to execute the MIDI command. All MIDI command
specify times relative to the time of the last command. Functions
in genmidi.c generally reset delta_time to zero after sending
a MIDI command. Otherwise, delta_time is adjusted by timestep()
in queues.c.

In order to control the delay intervals between notes in a chord,
new global variables notecount, notedelay and totalnotedelay were
introduced into genmidi.c. If notecount is greater than 1, delta_time
is changed to notedelay and totalnotedelay is incremented by this
amount.  It is necessary to shorten the shifted notes by totalnotedelay
so that they end at the same time. The new length is passed to addtoQ
in queues.c. At the end of the chord, notecount and totalnotedelay
are reset to zero.

December 4 2004:

(Continued from November 28 2004.) Unfortunately addtoQ does not
know that the shortened notes have been shifted.  When correcting 
the delay of the cached note in the structure, addtoQ now takes
into account that the new note was shifted with respect to the 
previous note by notedelay which is also passed as a global variable. 
Finally, it was also necessary to adjust delta_time in timestep()
by totalnotedelay. More comments were added to the code addtoQ
and timestep in queues.c.

The notedelay variable is set to 10 MIDI units as a default. (There
are 480 MIDI units in one quarter note beat.)  A new MIDI command
%%MIDI chordattack n, was introduced in dodeferred() (genmidi.c)
to allow the user to fine tune this variable. I do not recommend
making this variable larger than the smallest note in the tune,
(eg. 30 units if there are 1/16 note chords.) The abcguide.txt
and abc2midi.1 documentation was updated. Thanks go to Hudson
Lacerda for suggesting this improvement.


Midi2abc outputs MIDI metatext commands as abc comments. In
some cases they can be interpreted as pseudo comments causing
undesirable actions by other software. For example, in the
following the title MIDI program 17 is converted to metatext
in the MIDI file. When midi2abc converts the MIDI file back
to an abc file the text can be interpreted as a %%MIDI command.

X:1
T:MIDI program 17
C:Hudson Lacerda
M:12/8
L:1/8
Q:1/4=120
K:C
%MIDI
C,^C,D,^D,E,F,^F,G,^G,A,^A,B, |
C^CD^DEF^FG^GA^AB |
c^cd^def^fg^ga^ab |
c'^c'd'^d'e'f'^f'g'^g'a'^a'b' |


-- output from midi2abc --

X: 1
T: from (null)
M: 12/8
L: 1/8
Q:1/4=120
K:C % 0 sharps
%%MIDI program 17
%%MIDI
C,^C,D, ^D,E,F, ^F,G,^G, A,^A,B,| \
=C^C=D ^DE=F ^F=G^G =A^AB| \
=c^c=d ^de=f ^f=g^g =a^ab| \
=c'^c'=d' ^d'e'=f' ^f'=g'^g' =a'^a'b'|

As suggested by Hudson Lacerda, the fix is to add a space
before the metatext. The sprintf statement near the
end of the function txt_metatxt() was modified.

Midi2abc should place the input file name in the title
line instead of null. This has been changed.


December 09 2004

Abc2midi new feature: introduced %%MIDI randomchordattack n.
The delay between notes in a chord will vary randomly between
0 and n-1 MIDI units. It is recommended that n is not longer
than the shortest chord. (If the shortest chord consisting
of two notes is a 1/16 note then n should be not greater than
480/4 = 120. If there are three notes in the chord n should
be less than 480/8 since the delays add up.)

December 12 2004  - also see June 13 2005

New feature: chord extension applied to tied chords.

In order for abc2midi to handle the syntax [CEG]3-[CEG]2 or
something similar, it was necessary to make more changes
in the code store.c. The code dotie() was not easy to
figure out. To avoid working with this code, abc2midi
patches up the feature,num,denom arrays so that it
appears the same as if the old syntax [C3-E3-G3-][C2E2G2]
was used instead. New functions, insertfeature() and
removefeature() were written to insert or remove a feature
in the middle of the arrays. The dotie() function was
modified to also detect the CHORDOFFEX feature and
treat it the same way as a CHORDOFF. The function
fix_enclosed_note_lengths was modified to also catch
the TNOTE feature and treat as a NOTE feature. A
new function patchup_chordtie was introduced. The
function stuffs a TIE feature after each note in the
chord and returns the position of the first TIE.
Many changes were made to the tiefix function().
Another local variable, chord_end was added. Chord_start
and chord_end keep track of the feature index positions
of the last chord scanned. If a TIE feature is immediately
preceeded by a CHORDOFF or CHORDOFFEX feature, then
that tie is stripped off and new ties are stuffed
into the chord using the function patch_chordtie.
Tiefix then backups into this chord so it can run
dotie on all the internal ties.

December 17 2004

Finished debugging chord tie feature. Tiefix no
longer runs fix_enclosed_note_length when it
backs up into the chord.


Abc2midi:
Limin Wang discovered and  D.J. Bernstein reported 
two unprotected buffer overflows in store.c.  This
allows an attacker to gain control of the computer 
through a malicious abc file in an email message or
from a web page that is fed into abc2midi. This
applies to all versions of abc2midi.

The buffers are now protected.

Yaps, midi2abc: minor changes to reduce likelihood
of buffer overflow.


December 18 2004

Abc2midi new feature:
Abc2midi recognizes the !f!, !pp!, etc indications
and adjusts the audio level in the output MIDI file accordingly.
Unfortunately this may get in the way for multivoiced abc files
where the indications are placed in one voice but not the others.
When the file is typeset by abcm2ps the output looks fine, but
one of the voices is inaudible in the MIDI file. An example,
is shown below.

X: 1
T:ff_pp_1_1
C:ff_pp_1_1: the second voice is covered by the first one
C:but the score could be interpreted as they both have to
C:be played with the same intensity
M:4/4
L:1/4
Q:1/4=100
%%MIDI transpose -12
%%staves (1 2)
V: 1 clef=treble
V: 2 clef=treble
%V: 3 clef=treble
%
K:C
%%measurenb 0
%
[V: 1]  G A c e | e c A G | A G A G |
[V: 2] !ppp!C E E E | G E E E | F E D C |

Things get more complicated when 2 or 3 voices share one stave
(eg. classical guitar notation). It is not desirable to have
to many "p"s printed over and under the stave. Abc2midi
does not understand !crescendo! and !diminuendo! notation.
A simple but not a perfect solution, is to introduce a new
option in abc2midi which will tell abc2midi to ignore all
dynamic indications.

Fix: thanks to Michele for the code and suggestion. A new
option -NFNP (no f no p) was introduced in store.c. Abcguide.txt
and abcmidi.1 documentation was also updated.



Abc2midi:  Wrong tempo when L: missing in a multivoiced file. 
Abc2midi should assume a L:1/8 when the meter is 3/4 or larger
and L:1/16 otherwise in the event that the default length of
a note is not specified.. This works correctly for most abc
files but fails in the following example. (The tune is
played at the wrong tempo.)

X: 1
T: no L
M: 3/4
L: 1/8
Q: 80
V:1 clef=treble
V:2 clef=treble
K: G
V: 1
abcdf2|gabcG2|
V: 2
ABCDF2|ABCDF2|

Analysis: abc2midi checks for missing L: in the function 
headerprocess() when it reaches the start of the tune body
(the first K: field).  If the note length,  global.default_length,
was not set at this point then it is set to 8 or 16. When a new
voice is created by event_voice, it assumes a note length
specified by global.default_length. In the above example,
an event_voice is called prior to the start of the body 
so global.default_length is still undefined. The default_length
for the voice remains undefined and abc2midi runs unpredictably.

Fix: headerprocess now sets default_length to global.default_length
for any voices that have already been created.


January 1 2005

Abcmidi: does not handle a tie broken by a voice switch.
In the following example,

X:1
T: tie
M: 2/4
L: 1/4
K: G
V:1
AB-|
V:2
cd|
V:1
Bc|
V:2
G2|

the tie joining B is interrupted by a voice change. Abc2midi fails
to join the notes. Fix: the functions tiefix and dotie now check
for a voice change and do not attempt to tie notes belonging to
different voices.



Abcmidi: abcmidi fails to assign the channel to correct program
(musical instrument) for the first note in a multivoiced abc
file. In the following example:

X:1
T: MIDI program
M: 2/4
L: 1/4
V: S   clef=treble   name="Soprano"
V: A   clef=treble   name="Alto"
%%MIDI program 1 60
%%MIDI program 2 60
K: G
V: S
G A|B C|G A|F G|
V: A
z2|G A|F G|G A|

The first note G is played on the piano instead of 
the French Horn as indicated by the command %%MIDI program 1 60


Analysis: the MIDI indications are inserted into the track
number associated with the voice. In this example, voice A is
mapped into track 2 and all the program indications are put
into track 2. The midi player processes the tracks sequentially
and does not see the program change in time to affect the first
note in voice S so it is played on the default instrument,
acoustic grand (piano). The simplest fix is to ensure all
the MIDI indications go into the first voice as shown here.

X:1
T: MIDI program
M: 2/4
L: 1/4
V: S   clef=treble   name="Soprano"
V: A   clef=treble   name="Alto"
V: S
%%MIDI program 1 60
%%MIDI program 2 60
K: G
V: S
G A|B C|G A|F G|
V: A
z2|G A|F G|G A|

Alternatively you can place the %%MIDI program indication
in the voice that it affects. (The channel number is no
longer needed then.) See below.


X:1
T: MIDI program
M: 2/4
L: 1/4
V: S   clef=treble   name="Soprano"
V: A   clef=treble   name="Alto"
V: S
K: G
V: S
%%MIDI program 60
G A|B C|G A|F G|
V: A
%%MIDI program 60
z2|G A|F G|G A|


I shall update abcguide.txt regarding this issue.


January 8 2005

Another exploitable error in store.c was found by Anselm Lingnau
which causes a buffer overflow for %%abc-copyright. A fix using
the snprintf routine was suggested. The snprintf routine is a
recent addition to the C compiler; for those running older
compilers you will need to download a portable GPL implementation
of snprintf() from http://www.ijs.si/software/snprintf in order
to compile and link abc2midi. (In case the web site changes,
search for snprintf portable implementation.) If you are running an
old or nonstandard operating system for which there is little
likelihood of a buffer overflow exploit taking over your computer
and it is too cumbersome to include snprintf, then you can define
NO_SNPRINTF (in store.c) and it will use sprintf.

Michele has added an additional correction to the broken tie
fix I made on January 1 2004. In order to handle the following
example which includes a chord in voice 2.

X:1
T: tie
M: 2/4
L: 1/4
K: G
%
V:1
AB-|
V:2
[dA]c|
V:1
Bc|
V:2
GG|

it is necessary to add 
if(localvoiceno != voiceno) break;
after case CHORDOFFEX:
in the function dotie.


January 9 2005

Abc2midi:  new decorations !arpeggio! and !breath!
are introduced.  When the !arpeggio! instruction precedes a
chord, the notedelay time is temporarily set to three times
its normal value. For the time being, the !breath! instruction
is treated exactly the same as a staccato marking. (i.e.
the length of the note is halved and followed by a 
rest of the same value.)

Implementation: a new decoration BREATH was added and a
new feature ARPEGGIO was added in abc.h. In store.c,
additional code was added to event_handle_instruction to 
handle the !arpeggio!  and !breath! commands. In event_note,
both STACCATO and BREATH decorator flags are checked and
treated the same way.

New global variables staticnotedelay and staticchordattack
were added and linked to notedelay and chordattack in several
places.  In writetrack, genmidi.c, a separate
case statement in the main switch statement was introduced
for ARPEGGIO. It changes the values of notedelay and noteattack
to 3 times its nominal value. (They are restored back to
their nominal values after a CHORDOFF or CHORDOFFEX feature.)

Jan 22 2005

Abc2midi: a missing break statement caused abc2midi to crash
when encountering !arpeggio!. Added a tune demonstrating
the !arpeggio! instruction to demo.abc.

Midi2abc: normally midi2abc groups the notes forming a beat
together so that abc*2ps produces a pretty output. For some
raw  abc output, (eg.)
B3/2z4^dz/2e3/2z3/2|
it is easier to edit it if there is a space between every note (eg.)
B3/2 z4 ^d z/2 e3/2 z3/2|
A new option -nogr has been added to midi2abc. If it is included
as one of the run time options, then a space is inserted between
all notes that are not in triplets. Changes were made to printchord
and printtrack in midi2abc.c. (Search for nogr to see changes.)


February 03 2005

Abc2abc: introduced a new run time parameter -usekey. This
is a generalization of the -nokeys -nokeyf transformation
which converts the music representation to the key of C
inserting any accidentals to preserve the original key
signature. Now you can force abc2abc to represent the
music in any key signature. The -usekey parameter is followed
by a number specifying the number of sharps (positive
number) or number of flats (negative number) in the
desired key signature.

Implementation in toabc.c: if usekey parameter is set to a
nonzero value, the nokey parameter is set so that event_note2
is used to process the note. Setup_sharp_flats adjusts the
arrays flatsym and sharpsym to match the desired key signature.
The function printpitch prints the notes using these two
arrays.


February 04 2005

Abc2midi: It has been proposed that a new option be introduced
that would propogate dynamic indications (pp, ff, etc) from
voice 1 to all other voices so that they need only be declared
once in voice 1. This would provide another solution to the problem
discussed in December 18 2004 resulting in the introduction
of the -NFNP option. Introduction of this feature is deferred
for the time being but here is a description of what is involved
in implementing such a feature.

When parseabc.c sees an instuction eg. !ff!, it calls
event_instruction (in parser2.c) which calls split_string
which calls event_handle_instruction (in store.c).
Event_handle_instruction interprets the instruction and
calls event_specific with a MIDI beat x x x x command.
Event_specific passes the string to textfeature which
adds an entry DYNAMIC to the feature array and a pointer
to the string in the pitch array. Note the feature array
is used to handle all the voices, and the list of voice 
features are separated by VOICE entries. The problem is
that it is impossible to propogate the DYNAMIC instructions
to the other voices because the other voices may not exist
(in the case the voices are specified serially in the abc file). 
The function writetrack in genmidi.c separates the specific
voice from the feature array and creates a separate MIDI
track for each voice.

To address this problem, we would leave the code in store.c
and parseabc.c however we would need to change writetrack
in genmidi. Writetrack would now have to keep track of the
beat number when processing a voice. When a DYNAMIC feature
is encountered in voice 1, the beat number where this has
occurred would be stored in an array, along with a pointer
to the dynamic indication string. For all other voices,
the DYNAMIC feature would be ignored but instead the
beat number would be compared with the beat number where
the dynamic indication occurred and dodeferred would be
called when the beat number equals or exceeds the numbers
cached away for voice 1.

Worked on this project is deferred for the present time.

February 05 2005

Abc2midi tie bug:

For the file
X:1
T: tie bug
M: 2/4
L: 1/8
K: G
[FA]-[FA] FA|

abc2midi fails to tie the F# note.

Fix:
replaced the line 737 (in removefeature) in store.c
pitchline[i] = pitch[i+1];
with
pitchline[i] = pitchline[i+1];


February 12 2005  (also see June 13 2005)

Michele reports the following bug in the function dotie
in store.c. For the following tune,

%
X: 1
T: Tie bug
M:C
L:1/4
K:D
[V: 1] | f/e/g/f/-f2 |
[V: 2] |  d3/2 d/-d2 |

abc2midi returns the message
Error in line 7 : Could not find note to be tied.

The message is wrong, since abc2midi handles both
ties correctly.

Michele added the conditional break statements
 if(localvoiceno != voiceno) break;
after case TIE: and after case CHORDON:

which seems to fix the problem.

Analysis: The function dotie is a real birds nest of
code. Here is a description of how it works.
Dotie is called by tiefix when a TIE feature is
encountered. It has two parameters, j the index
in the feature array where TIE was encountered and
xinchord, a flag indicating whether the TIE is
enclosed in a chord (eg [A-B] A). The reason for the
complexity of the code is because the function dotie
is controlled by three semaphores tietodo, done,
and tied_denom. To start, dotie searches backwards
for the note preceding the tie, and calls its address
(in the feature space) tienote. It changes 
feature[tienote] from NOTE to TNOTE. It changes
feature[j] from TIE to REST and sets the rest length
to that of tienote (so they are both the same).
Finally it sets the semaphores
done = 0; tied_num = num[tienote]; tietodo = 1;
which controls the stopping conditions of the following
while loop that searches for the following note to be
tied to tienote. Now the fun begins. To simplify things
assume we do not have chords.  The loop begins with the
variable place set to j, the original position of the TIE
now converted to a rest. So the first feature in the loop 
is guaranteed to be a  REST. case REST: subtracts
the length of the rest from tied_num so it is back to zero.
Now the semaphores are
done = 0; tietodo = 1; tied_num = 0;
The loop variable place is incremented and now feature[place]
probably points to a NOTE. Case NOTE: since tietodo is not
zero the function compares the pitches (pitchline) of
place and tienote. If they are equal, the tienote length
is increased by the place note, the tied_num semaphore
is also increased by the place note. Feature[place] is changed
from a NOTE to a REST and to make things more confusing,
if we are not in a chord the length of tied_num is now
decremented by the place note so that it is back to zero.
Finally the tietodo variable is also set to zero indicating
that we have finally joined the two notes in the tie. The
semaphores are now:
done = 0; tietodo = 0; tied_num = 0;
Unfortunately the while loop does not stop here and this
is the reason for the spurious error message described above.
In order for the while loop to stop, the variable done must
be set to a nonzero value. This usually happens when the
next NOTE or REST is found. In the above example, the
next note is found in a different voice.

The remedy is probably to end the while loop when tietodo is
zero. However, since the code is working fine now I am
rather reluctant to try it in case another bug surfaces.


Feb 13 2005

Abcmidi /abcm2ps incompatibility problem for decorations
applied to chords. It is perfectly normal to apply a
fermata or a staccatto to a chord, eg H[C2E2G2] or
.[CEG]; in fact abcm2ps prefers that you do it this way
rather than [.C.E.G]. Abc2midi handles both notations
correctly but it sends the following warning message if you use
the former convention.

Warning in line 6 : decorations applied to chord

Nevertheless, abc2midi sends the chord decoration to each
note in the chord and everything works fine provided you
don't attempt to apply roll, trill or ornamentation
to a chord. In the later case you receive an error message
and the decoration is not applied. It is therefore preferable
that parseabc does not produce this warning when abc2midi
is running.

Fix: it is convenient if  parseabc.c knows which program
is running (i.e. abc2midi, abc2abc or yaps). A new typedef
programname which distinguishes ABC2MIDI, YAPS, and ABC2MIDI 
was added to abc.h. A programname variable called "program"
was added as a global variable to store.c, yapstree.c and
toabc.c and set to proper value. The program variable is
linked to parseabc.c as an extern global. This variable
is used to fine tune parseabc.c.

Unfortunately not everything is well with yaps and abc2abc.
Like abc2midi, the chord decoration is applied to every
note in the chord. In the case of yaps, this does not produce
an aesthetically pleasing result. Since yaps is not the
preferred postscript converter and I am also not very
knowledgeable of its internals, yaps shall remain as it
is and the warnings serve a useful purpose. In the case
of abc2abc, it is not desirable that it automatically
converts H[A2C2E2] to [HA2HC2HE2] or something similar.
A few more changes are necessary.

It was necessary to introduce a new parameter (chorddecorators)
into the function event_chordon. This entailed making changes to
parseabc.h, parseabc.c, store.c, yapstree.c and toabc.c.
In store.c and yapstree.c the new parameter is not used;
however, in toabc.c extra code was added to event_chordon
to print out any decorations applied to the chord. In parseabc.c
the decorators were not inherited from the chorddecorators
when parseabc.c was linked to toabc.c.

Unfortunately event_chordon is also called by the function
event_chord which handles the obsolete form of chords
+CEG+. For store.c, yapstree.c and toabc.c, I introduced
a global array dummydecorators[DECSIZE] which is initialized
to zero's in event_init. This array is used in event_chord.

February 14 2005

Abc2abc prints garbage in the V: field (reported by Hudson Lacerda).
Given a normal file :

X:1
T: abc2abc V: bug
M: 4/4
L: 1/8
K: C
V: 1
CDE FGABC| def gab c'2|
V: 2
C8|C8|

abc2abc outputs

X: 1
T:abc2abc V: bug
M:4/4
L:1/8
K:C
V:1 name=(LI
CDE FGABC| def gab c'2|
V:2 name=(LI
C8|C8|

Analysis: the local variable gotname in the function
parsevoice in parseabc is never initialized to zero.
The problem was fixed by adding
gotname = 0;


February 21 2005

Microtone note capability has been introduced into abc2midi.
A _/ means lower the pitch of the following note by a half a semitone. 
A ^/ means raise the pitch of the following note by a half a semitone. 
The microtone notation does not propogate across a measure but
applies to only the immediate note. For chords in the same channel
(voice), the microtone will apply to both notes no matter
how it has been notated. For example [C_/E] is the same as
[_/C_/E].

Following the convention in abcm2ps, (see features.txt in abcm2ps
distribution), _3/4C will depress C by 3/4 of a semitone. It is
assumed that the pitch range of the MIDI synthesizer pitch wheel
is + or - two semitones in compliance with the General MIDI
specifications. The maximum permissible pitchbend is therefore
2 semitones.

Implementation: added a new function ismicrotone() called by
parsenote() in parseabc.c. I also introduced functions
event_microtone() and event_normal_tone() in store.c, yapstree.c
and toabc.c. There has been no change to the operation of yaps
or abc2abc.


February 26 2005

Finished microtone implementation and added microtone
documentation in abcguide.txt.


March 12 2005

Abc2midi: There is a loss of synchrony in multivoiced files
when a fermata is applied to notes of unequal lengths. For
example:

X:1
T: Fermata
M:2/4
L:1/4
K: G
V:1
cdef|B2 Hc2|gabc|
V:2
efga|DHe3|gabc|

the fermata is applied to c2 and e3 for voices 1 and 2. The fermata
doubles the length of the notes c2 and e3 and there is a loss of synchrony
between the voices in the next bar.

Solution: I introduced new MIDI commands which control how the
fermata is applied.
%%MIDI fermatafixed
The fermata adds a unit lengths to the note so HC2 is played C3.
%%MIDI fermataproportional
(default) the unit length is doubled so HC2 is played C4.

Implementation: added new global flag fermata_fixed and modified
event_specific to set this flag. Modified FERMATA treatment
in event_note and event_rest.



March 18 2005

Microtones in abc2midi. It is not clear whether the microtone
notation should be treated as an accidental or a decoration.
The abc2midi software treats it as a decoration. Thus in the
following:

X:1
T:micro
Q:60
K:C
=C ^/C ^C _/D  D _/D ^C ^/C =C

the second to last note ^/C is played as ^^/C since the
accidental in the previous note propogates across the measure.
If you want =^/C you must specify it in this manner.
If ^/ and _/ satisfy the rules of accidentals then,
they would be interpreted the same way as double sharps and
double flats. Thus if you wrote ^^F E ^F G: the first note
would be played as G and the third note would be played as
F#. (You would not write ^^F E ^=F G.) It is not clear from
the abc standard, the meaning of the following:
[K: G] ^/F D E G|
Is the first note a F natural raised a quarter tone,
or is it a F# (as indicated by the key signature) raised
by a quarter tone? Presently abc2midi treats it as the
latter.

To treat the notation as accidentals would mean that the
quarter tones would propogate across a measure like sharps
and flats. This would require introducing more code into
abc2midi. (Further there would be other issues relating
to transposition in abc2abc.)

March 19 2005

abc2midi optional guitar chord syntax. The function
event_handle_gchord in store.c was modified to ignore
the parentheses in the guitar chord. (eg.  "(C)" CDEF etc. )
The optional guitar chord is played.


March 25 2005

abc2midi: note tied to two notes. In the following sample
the tied note is not played correctly in the repeat.

X:1
T: note tied to two notes
M: 2/4
L: 1/8
K:G
%%MIDI program 73
|:G2D2|ABCD-|[1 D4 :|[2 D2 G2|

Unfortunately this is a difficult problem to fix. Store.c
creates a feature/pitch/num/denom arrays which tells writetrack
in genmidi.c how to create the MIDI file. Repeat actions are encoded
into the feature array using the instructions BAR_REP, REP_BAR,
PLAY_ON_REP, etc, which instruct writetrack to backtrack
in the feature array and repeat certain sections. In other words
the repeats are not expanded until writetrack creates the MIDI
track.  Tied notes are handled by the function dotie in store.c
that determines which notes are tied and combines the tied notes into
one note instruction in the feature array. In the above example, the
tied note D-D4 in the first repeat and D-D2 in the second repeat
have different durations. Dotie can only assign the D tied note
one duration so it will be wrong in one of the repeats. To
make things worse the code in dotie is unmanageable (see
comments February 12 2005).

To fix the problem the joining of ties, it would need to be
done at the time that the repeats are expanded in writetrack
rather than in a separate pass performed by dotie in store.c.
The handling of ties is messy because they can also be embedded in
chords; they cross barlines introducing problems with accidentals
in music notation; interleaving of voices breaks up ties; we want
abc2midi to gracefully handle tie syntax errors provide useful
error message. Multiple repeats (eg |...|[1...|[2,3...|[4... :|)
introduce another headache.

One way of avoiding this problem is to notate the above sample
differently as shown below.

X:1
T: better way of handling tied notes in repeats
M: 2/4
L: 1/8
K:G
%%MIDI program 73
|:G2D2|[1 ABCD-| D4 :|[2 ABCD-| D2 G2|

There is now five bars instead of four, but it avoids the above
problem.



Abc2midi: an alternative method for embedding %%MIDI commands.

The syntax for placing %%MIDI instructions in the abc file
requires that each command occupies a separate line in the
abc file. This makes the resulting file look messy when
you want to do drumon, drumoff, gchordon, gchordoff, in the
middle of a line. The problem gets worse when the abc file
also has lyrics included using the w: field command.

It has been suggested that there should be an option
to place MIDI instructions in the information field:
eg.[I: MIDI drumon]. Abc2midi does have provision
to parse inline I: fields using the function event_info.
However, the code expects the field satisfy a specific
syntax of the form [I: key1 = value1 key2 = value2 etc.]
Thus you specify as many keys as you wish in the
I: field.

So far I have modified the function event_info_key in
store.c so that it will now forward any info field commands
of the form [I:MIDI = stuff] to the function event_specific
which handles all %%MIDI commands. Thus you can now do
the following.

X:1
T: event info used for MIDI
M:4/4
L:1/4
K:G
[I: MIDI =  program 70] DDEE|[I:MIDI=program 42] GEFG|

instead of

X:1
T: event info used for MIDI
M:4/4
L:1/4
K:G
%%MIDI program 70
DDEE|\
%%MIDI program 42
GEFG|

Any %%MIDI command described in abcguide.txt may be embedded
in the I: field; however the '=' is very important. Otherwise
abc2midi will assume this field is just for the user's
interest and just ignore it. Here is another example:

X:1
T: event info used for MIDI
M:4/4
L:1/4
K:G
[I: oboe MIDI = program 69 MIDI = gchord fzcz MIDI = chordprog 1] BAG2|\
"G" EC GG|[I:MIDI= bassprog 100] DDDD|[I: MIDI =gchord ffffffff] G4|



March 28 2005

Acciaccatura grace note notation. Abcm2ps compatability feature.
Abc2mps accepts the notation {/b}a where the slash before the
b tells it to display the grace note b as an acciaccatura.
Parseabc.c does not understand this notation and returns an
error message "Unrecognized character /". 

Fix: parseabc.c was modified to keep track whether it is inside
a grace sequence using a new global variable ingrace. When
the function parsemusic encounters a / that is not a note length
indicator, it will call event_acciaccatura if ingrace flag is
set. This function does nothing in abc2midi and yaps but it
prints the / character in abc2abc.


April 02 2005

Abc2midi does not handle microtones properly in multivoiced
files. For example in,

X:3
T:Miudezas
C:Hudson Lacerda
M:none
Q:1/8=132 "ca."
L:1/8
K:none clef=treble
V:1 name="Clarineta em Sib"
{=B}_/G {=B}^g | {=B}^F {_/e}=B {_/e}^/c' |\
{_/e}_/G {_/e}_/d' {=a}_/e |

the first note B (grace note) was affected by the microtone which was
intended to be applied on the second note G.

Analysis: Multivoiced files (i.e. using V:1, V:2 etc.) place a
header track (track 0) in the MIDI file where global DYNAMIC
features such as %%MIDI program may be defined for all other
voices.Since the microtone uses the %%MIDI pitchbend, it
is also treated as a DYNAMIC feature. As a result the header
track contains many pitchbends but no notes. This unfortunately
handles all other notes in channel 0 in a random fashion.

Fix: a new parameter, noteson,  was introduced into the function
dodeferred which handles all DYNAMIC features. Noteson is
also a local variable controled by writetrack to specify whether
NOTE features are to be processed by writetrack. This flag
is now also used by dodeferred to determine whether pitchbend
MIDI commands are to be inserted.


April 07 2005

Introduced a new feature to midi2abc. Midi2abc.exe -mftext
will now produce a mftext output of a specified input MIDI file.
It was preferable to build mftext into midi2abc since I
changed the output format; also runabc already links to too 
many executables and I would not like to keep track of version
numbers for another program.

April 09 2005

I have modified toabc.c (abc2abc) so that it will no longer
transpose voices assigned to the drum channel (%%MIDI channel 10).
Implementation: added a new entry, drumchan, in the voicetype
structure which indicates whether this voice is to played
on drums. Also added a new global, drumchan which is linked
to voice.drumchan for the currently active voice. The event_specific
function has been extended to catch %%MIDI channel 10 and
update drumchan. The function setvoice() initializes voice[].drumchan
to 0 when a new voice is created. The functions event_note1 and
event_note2 now check the drumchan flag before transposing the note.

April 10 2005

Abc2abc - abcm2ps compatibility issue. Abc2abc does not recognize
the sname= "...". Fix: introduced new function parsesname in parseabc.c
added new parameters to event_voice in parseabc.c, store.c,
yapstree.c and toabc.c. (See September 26 2004 in this file
for more details.)

April 15 2005

Midi2abc: fixed problem causing midi2abc to crash when the
MIDI command indicating the time signature is missing from the file. 


April 22 2005

Abc2midi: pitchbend inside a tied note. In the following
example, the third note is held too long.

X:1
T: bends
M: 2/4
L: 1/8
K: G
%%MIDI program 60
G4|G4|G2-_/G2|G4|

Fix: in function dodeferred() (genmidi.c) for command == pitchbend, added
 tracklen = tracklen + delta_time;
  delta_time = 0L;
after  write_event(pitch_wheel, chan, data, 2);

Also listen to the example 11 in demo.abc.


April 23 2005

Abcmidi: introduced two more MIDI commands.
%%MIDI portamento n
turns on the portamento controller on the current channel and
sets it to n. n is a 7 bit number which specifies the rate
slides the pitch between two notes. (Unless you are composing
20 th century classical music, you may not wish to use this
feature. Avoid slides between large pitch intervals.)

%%MIDI noportamento
turns off the portamento controller on the current channel. 


April 24 2005

Integration of abcmatch into abcmidi package. The main() function
in parseabc.c was moved into store.c, yapstree.c, and
toabc.c .The function parsetune was placed in parseabc.c.
All makefiles were updated. (I cannot verify all of them;
report any corrections to me.) The files abcstore.c and abcparse.c
are no longer needed; delete them if they are lieing around.

April 29 2005

Cleaned up all the compilation errors that occur in
Microsoft Visual C version 6.0.



May 03 2005

Abc2midi abcm2ps compatability feature:
add new %%MIDI command

%%MIDI beatmod n
where n is a positive or negative integer.

The command will increment (decrement) the loudness of the
on beat, off beat and other notes by the amount n.

Introduced new instructions:
 !<(! or !<)! or !crescendo(! or !crescendo)!  which act like
%%MIDI beatmod 15
Also 
 !>(! or !>)! or !diminuendo(! or !diminuendo)!  act like
%%MIDI beatmod -15

Thus a pair of !<(! and !<)! does two loudness increments. One
at the beginning of the crescendo and one at the end of the
crescendo.  This is not a gradual change but it is better than doing
nothing.

If the default beatmod value (15 or -15) is not ideal, you can
change it using
%%MIDI deltaloudness n
where n is a positive number.


Sample test file below:

X: 1
T: crescendo
M: 2/4
L: 1/8
K: G
%%MIDI deltaloudness 20 
!mf!cdef|edcB|
!<(! cdef|!<)! edcB|AAAA|
!>(!  cdef|!>)! edcB|AAA|
!crescendo(! cdef  |!crescendo)!|edcB|AAA|
!diminuendo(! cdef |!diminuendo)!|edcB|AAA|

Implementation: updated dodeferred in genmidi.c, added global
velocitychange in store.c and new code in event_specific and
event_handle_instructions.

abcguide.txt and abc2midi.1 documentation were updated.



May 06 2005

It has been suggested that some abc2midi options could be global
when they are used outside of a tune. For example:

%%MIDI chordname
%%MIDI ratio
%%MIDI beat
%%MIDI program

It is rather difficult to add this feature since the handling of
these options is not centralized but spread out in the store.c
and genmidi.c code. Some of these options apply to specific voices
which do not get instantiated until the voice is defined in the
tune. This makes the full implementation rather formidable.

I have introduced new code event_specific_in_header in store.c
that attempts to handle some of the MIDI directives. Many of
the MIDI directives send information to the feature[] array
which does not exist prior to parsing the tune. I have not
attempted to handle those directives. Presently, the only
MIDI commands that will be recognized outside the tune are

%%MIDI C
%%MIDI nobarlines
%%MIDI barlines
%%MIDI fermatafixed
%%MIDI fermataproportional
%%MIDI ratio
%%MIDI chordname
%%MIDI deltaloudness

All other MIDI commands outside the tune are ignored and will 
produce the warning "cannot handle this MIDI directive here".

The following is a sample test file.

%MIDI C 48
%%MIDI nobarlines
%%MIDI ratio 5 1
%%MIDI chordname ugly 1 2 3 4
X: 1
T: test global settings
M: 2/4
L: 1/8
K: C
"G"CDEF|"Gugly" D>EF>C|^ABDA|AAC2|


May 08 2005

Abc2midi: voice splitting.
In some pieces of  music a voice splits in two or more voices only
in some measures. The new abc standard (and abcm2ps) provides
a syntax for splitting a voice in a bar using the & symbol.
When placed within a measure, it splits the current voice and
attributes the notes that follow to the second voice.

Voice splits are handled by creating separate voices which
are in turn converted into separate MIDI tracks. 

To implement this feature, new variables were introduced into
the voice structure defined in store.c
int nbars; /* counts number of bars processed in voice */
int tosplitno /* points to new voice to handle split */
int fromsplitno /* points to voice initiating the split */
Both tosplitno and fromsplitno are intialized to -1 implying
that a split voice does not yet exit.
In an event of a split, tosplitno points to the new voice to go to. 
If it is -1, a a new voice needs to be created, and fromsplitno
in the new voice is set to the voice from which initiated the split.

In order not to confuse the new voice number with a voice number
generated by a V: field, the split voice numbers start from 32.

Global variables in store.c were introduced.
int numsplits; /* keeps track of the number of split voices generated */
int splitdepth; /* keeps track of the number of splits in a bar */

A new function event_split_voice in store.c is called by parsemusic
in parseabc.c when a '&' is encountered in a music line.

A new function resync_split_voice adds bars of rests into the
split voice so that bar is in the right position.

A new function complete_all_split_voices ensures all split
voices are the right length in order to avoid annoying messages
like:

Warning in line 7 : Track 2 is 3840 units long not 4800

A new function recurse_back_to_original_voice is called to 
recover from a split when a new bar line is encountered (see
event_bar).

Sample test file:

X: 1
T: testing voice split
M: 2/4
L: 1/8
K: G
A4| G4 & e2g2|BGEE|CAEE & d2f2|F2G2|


May 12 2005

Wrote a new function dumpfeat(n1,n2)  in genmidi.c which
prints out the contents of the feature,pitch,num,denom array
between n1 and n2. The function is usually called in the
debugger after stopping at a breakpoint in finishfile.


May 13 2005

Abc2midi split voices: Problems occur when the music contains
repeats. It is necessary to transfer the repeats to the split
voice. The function event_bar checks for any repeat symbols.
There are two cases. If we are already in a split voice then
(eg. abcd & defg :|)
we have to propagate the repeat back to the original voice
while recursing back.  If we are not in a split voice but
we know that this voice does link to split voices, then we
(eg abcd & defg |abcd :|) need to propagate the repeats
downwards to the all the split voices.

The function event_playonrep is also called by the parser
and needs to check for split voices.

May 14 2005

Now there is still another problem: the parser might encounter
a repeat symbol before it knows that this voice splits. We must
find a way of getting those repeat codes into the newly created
split voice. Solution: a new function start_new_voice_and_sync is
called when a split voice is first created. It scans
the parent voice copying rests and various types of barlines
and repeat codes into the feature array of the newly created voice.
If it encounters a %%MIDI program, that is also copied. This way 
the new voice also inherits the same music instrument as its parent.

If you wish to change the instrument of the split voice, you
can do it this way.
C2 EF & [I:MIDI= program 10] F2 D2|
The new instrument will apply to all following bars of the
split voice.

Abc2abc was made split voice compliant.



May 19 2005

Midicopy: will now return the playing time of the extracted segment.
This only works when a segment is extracted using any combination
of the -from and -to runtime parameters. Otherwise it returns 0.0.
The program makes adjustments for any tempo changes that may occur
inside this segment.

May 21 2005

Corrected a bug in midi2abc. It was returning the time in seconds
instead of beats when running with the -mftext option.

May 22 2005

Midicopy: for some reason  the meta command  mf_write_tempo (which
originated from midifile.c) alway writes delta_time 0. As a result 
all tempo meta commands are at the wrong time. When this was changed,
tempo changes seem to be handled better.

Midicopy now caches all tempo changes in a array of structures
called tempo_array. This is used to update the current_tempo
when other tracks (not containing tempo commands) are processed.
The correct tempo is needed in order to get an accurate estimate
of the playing time of the output file. A new function
update_current_tempo is called each time Mf_currtime is updated.


May 28 - 31 2005
June 04-06 2005

Midi2abc often produces a mess for piano music sequenced into a
single track. There are many chords played by the left hand and
the right hand usually has a different rhythm. Midi2abc tries
to place all notes sounding at the same time into a single chord.
To handle notes of different durations, some notes are tied to
the next chord and others are not. The resulting output looks
something like this.


X: 1
T: Scarlatti, sonata 1
%***Missing time signature meta command in MIDI file
M: 4/4
L: 1/8
Q:1/4=120
% Last note suggests Phrygian mode tune
K:F % 1 flats
% (C) John Sankey 1998
z/2d/2 (3efga/2-[a/2A/2] _d/2A/2[=d/2-D/2][d/2-E/2]\
 [d/2-F/2]d/2-[d/2-G/2][d/2-A/2]| \
[d/2A,/2][e/2-_D/2][e/2A,/2][f/2=D/2-] [d/2D/2]z/2[g/2E/2-][e/2E/2]\
 [a/2F/2-][f/2F/2][e/2G/2-][d/2G/2] [_dA]z/2[a/2-A/2-]| \
[a/2A/2][b/2A/2-][b/2a/2A/2]
etc...


Converting it to PostScript file produces something very difficult
to read. Ideally the notes played by the different hands should
be separated into two tracks. Chords should avoid internal tied noted.

The abc standard contains the provision for splitting the notes
in a single bar into separate voices. This should provide a means
of simplifying the output.

A new runtime parameter -splitbars was introduced, producing
an output similar to below.

X: 1
T: Scarlatti, sonata 1
%***Missing time signature meta command in MIDI file
M: 4/4
L: 1/8
Q:1/4=120
% Last note suggests Phrygian mode tune
K:F % 1 flats
% (C) John Sankey 1998
z/2d/2 (3efga zd3- & \
z3A/2_d/2 A/2=D/2 (3EFGA/2A,/2 &\
d/2efgazd/2 z2| \
(3ef/2d/2z/2Ea/2f/2Gz2z/2 (3b/2a/2b/2 &\
EF GA A,_D/2A,/2 =Dz/2g/2& \
z3e f/2d/2z/2Ea/2f/2G/2-| 
b/2a/2b/2  etc....


Implementation:
Separating the parts is complicated and incorporating these algorithms
into midi2abc.c was even more difficult. The anote structure was
extended to contain two new values. Posnum stores the position
of the start of the note in xunit units. Splitnum assigns the
note to one of several split voices. New functions label_split_voices
and label_split scan the entire track and separate all the notes
into separate parts when necessary. A note is assigned to an
existing part if it follows the previous note or forms a chord
matching the length of the previous note. Otherwise, label_split_voices
searches for another active part satisfying this criterion.
If there is no active part available, the note is put into a new
part. Bar lines are ignored at this stage. Once all the notes
are labeled into separate parts, the xnum value associated with
the notes are updated so they indicate the number of units to
the next note in the same part.

A new version of printtrack called printtrack_with_splits was
created from the printtrack code. In order to use as much of
the original printtrack code, it make multiple passes through
the same bar whenever the bar contains notes from different
parts. In each pass a single part active in this bar is processed
and printed.

The code is barely working and is still experimental.
It will probably not  produce correct results for complicated MIDI files.
Fortunately most MIDI files have proper chords and do
not require this feature.


June 04 2005

A problem with abcmatch.c causes it to return a bad xref number
after processing the last tune in the file. This causes
runabc.tcl to report an error similar to
Error: can't read "tuneid(84)" :no such element in array.
when running extras/grouper. The problem is that the notes variable
in abcmatch.c does not get initialized to zero if parsetune()
fails because it encounters an eof. To fix the problem,
the function startfile() in matchsup.c is made global instead
of static and it is called prior to calling parsetune() in
abcmatch.c.

June 10 2005

Midi2abc -splitbars: fixed segmentation error which occurs
for tracks not containing any notes.


June 13 2005

Abc2midi: "Time mismatch at tie" error when chord length
declared outside of chord.


X:1
T: multiple tie
M: 2/4
L: 1/8
K:C
[CE]/2-[CE]/2-[CE]|[CE]/2-[CE]/2-[CE]|
K: G
[C-E-]/2[CE]/2 [F2D2] [FD]|
[C/2-E/2-][C/2E/2] [F2D2] [FD] |

Abc2midi does not tie notes correctly in the above example.
The chord extensions in November 4 2004 and December 12 2004
do not work correctly in combination. The problem occurs
in the function dotie in the lines
        case CHORDOFF:
        case CHORDOFFEX:
          if(localvoiceno != voiceno) break;
          inchord = 0;
          /* subtract time from tied time */
          addfract(&tied_num, &tied_denom, -num[place], denom[place]);
          break;
after addfract subtracts num/denom from tied_num/tied_denom, tied_num
should be zero. However, tied_num/tied_denom was not yet adjusted
by fix_enclosed_note_length, so tied_num/tied_denom is not equal
to num[place]/denom[place]. Since dotie finds tied_num to be
non-zero in code
 /* tie in note */
            if (tied_num != 0) {
              event_error("Time mismatch at tie");
            };
it thinks that the notes inside the chord have unequal lengths
and reports the time mismatch error. Furthermore, fix_enclosed_note_length
is eventually called after the notes were tied making a further
mess.

Fix: Instead of calling fix_enclosed_note_length in a separate
pass during tiefix, fix_enclosed_note_length is called during
the parsing stage whenever a CHORDOFFEX feature is added (see
event_chordoff). The variable nochordfix is now redundant and
removed from the code. This guarantees that dotie sees the
correct note lengths inside the chord.

June 14 2005

Abc2midi: chord ties. In the following example,

X:1
T: multiple ties
M: 2/4
L: 1/8
K:C
[CE]/2-[CE]/2-[CE]-|[CE]/2-[CE]/2-[CE]|

The E notes are not joined.

Fix: the function call patchup_chordtie was moved from
tiefix to event_tie.

In addtoQ (queues.c) a check for negative delay caused
by apeggiate code 

  Q[*ptr].delay = Q[*ptr].delay - wait -notedelay;
        if (Q[*ptr].delay < 0) Q[*ptr].delay = 0;

was added.


June 17 2005

Midi2abc: fixed bug in -splitbars causing program to go
into an endless loop and various other bugs.


June 25 2005

Midicopy: added line void WriteVarLen() in function mf_write_tempo
to be compatible with the new gcc compiler.

June 25 2005

Abc2midi: tieing repeated notes inside chords. Abc2midi returns
a "Time mismatch at tie" error message for the following file.

X: 1
T: tie
M: 2/4
L: 1/8
K: C
[CC]-[CC]-[CC]z|

Analysis. The line is converted to
[C-C-][C-C-][CC]z| and the function dotie attempts
to tie C to the next note it sees which is the next C
inside the same chord. This changes the length of the
note in the chord leading to the above error message.
Fix: a new variable samechord is introduced. When it is
set to 1 it signifies that we are in the same chord where
the tie mark - was placed, we do not link the tienote to
any notes in that same chord.  The flag samechord is cleared
whenever we leave the chord (CHORDOFF or CHORDOFFEX).
It is set again whenever a tie mark occurs inside a chord
is encountered.

Please note: a tie only connects one note.
Therefore C-[CC] will tie C to only the first
C in the chord.

June 26 2005

Abc2midi does not correctly handle more than one bar split.
In the following example,

X: 1
T: testing voice split
M: 2/4
L: 1/8
K: G
%%MIDI program 24
A4 & c4 |G2F2 & BBDD & E,,4| 

E,,4 is played in the first bar coincident with A4 instead
of the second bar.

Analysis: various bugs caused abc2midi to fail with more than
one split. locate_voice() must use voice indexno rather than
voiceno. start_new_voice_and_sync must pass the voice
indexno rather than voiceno to locate_voice().


June 27 2005

Midi2abc: changed name of parameter -usesplits to -splitbars.
Added new parameter -splitvoices which eliminates non homophonic
chords (ie. polyphonic) by splitting entire voices. Implementation:
added new function printtrack_split_voice to midi2abc.

June 28-30 2005

Midi2abc: fixed numerous bugs in printtrack_split_voice()
and printtrack_with_splits().

July 02 2005

Abcmatch: upgraded the handling of chords and ties to be
compatible with abc2midi.

July 09 2005

Abcmatch: added an option to ignore simple bars.

Midi2abc: withdrew -Midigram option and replaced it with -midigram.
Note onset and offset time are now printed in MIDI time units rather
than quarter notes units.

July 14 2005

Abc2midi: voice split causes infinite loop when play on repeat
(eg [1 or [2) specified. For the following file


X:1
T:reproduce the bug in a smaller file
C:H. C. L. Smith
L:1/4
M:1/4
K:C
D|:C|[1F:|[2F|E&C||

abc2midi emits the following error message in an endless loop.

Error in line 8 : Bad variant list : reproduce the bug in a smaller file
Warning in line 8 : Bar 2 has 2 units instead of 1
Error in line 8 : Bad variant list : reproduce the bug in a smaller file
Warning in line 8 : Bar 2 has 2 units instead of 1
Error in line 8 :....

Analysis: when writing the voice split in bar E & C||, the function
inlist (in genmidi.c) fails to get the repeat on repeat number (eg [2))
which was set for top level voice but not for the split voice.

Fix: the problem was traced to the function start_new_voice_and_sync
in store.c. It copies the repeat BAR feature (SINGLE_BAR, DOUBLE_BAR,
etc..) to the split voice but for the PLAY_ON_REP feature it must
also copy the pointer to the part number stored in denom[]. Now
both feature[j] and denom[j] are both copied for all bar type features.

July 15 2005

The above file exposes yet another problem leading to a loss of
synchronization between the voices. The first indication that there is
still something else wrong are the messages.
Warning in line 8 : Bar 2 has 2 units instead of 1
Warning in line 8 : Bar 3 has 3 units instead of 1 in repeat
Warning in line 8 : Track 2 is 4320 units long not 2880

When playing the output MIDI file, the note C in the split
is played two bars late extending track 2.

Analysis:
A play on repeat symbol is always preceded by a bar or repeat bar
(ie. | or :|). The function start_new_voice_and_sync treats the play
on repeat symbol as another bar line and inserts a rest to complete 
the bar when in fact, it should just insert a PLAY_ON_REP.
Since this bar is played twice, the C note comes two bars late. 
Treating PLAY_ON_REP as a separate case fixed the problem.

July 17 2005
Abc2midi: voice split synchronization error when not all measures
are equal in length. In the following file, the tune begins
with an incomplete measure.

X:1
T: anacrusis
M: 2/4
L: 1/8
K: F
AG|Fc Fc| d2 e2 & B2 c2|

Analysis: start_new_voice_and_sync unfortunately assumes that
every measure contains 2 beats. Fix: the function now counts
the number of beats in each bar it processes.


Abc2midi: MIDI attributes inheritance. As discussed in May 14, 2005
split voices inherit the MIDI characteristics from their ancestor.
The following file does not work as expected.

X:1
T:inherit 1 
M:4/4
L:1/16
Q:1/4 =20
K: C
%%MIDI channel 2
%%MIDI program 2 50
B2G2A2B2 EDEF EGFA & z2E4 D2 C8|]

The split voice z2E4 ... is played on the Acoustical Piano (program 0)
instead of the synthetic strings.

However the following file works correctly.

X:2
T:inherit 2
M:4/4
L:1/16
Q:1/4 =20
K: C
%%MIDI program  50
B2G2A2B2 EDEF EGFA & z2E4 D2 C8|]


Analysis: Each split gets its own voice and each voice gets
its own channel number unless it is changed explicitly. 

The above should be equivalent to
X:1
T:inherit 1
M:4/4
L:1/16
V:1
%%MIDI channel 2
%%MIDI program 2 50
B2G2A2B2 EDEF EGFA| 
V:2
%%MIDI channel 2
%%MIDI program 2 50
z2E4 D2 C8

Unfortunately, the %%MIDI channel 2 did not propogate
to the split voice. Voice 1 was assigned channel 2 but voice 2
still had channel 1 (writetrack automatically assigns the
first channel which is not in use). The bug was fixed by
ensuring the CHANNEL feature also propogates into the split voice.

You may wonder why X:2 worked correctly. This is because
the MIDI program command without the channel indication applies
to whatever channel is currently active.


July 23 2005.

Fixed bug causing midi2abc.exe to produce a segmentation error when
running with the -splitbars option. (Failed to save state
when doing a split voice context switch due to encountering
an end of track before an end of measure. As a result the restored
chordhead would point to the wrong place.) Added more
code around line 2480 in printtrack_with_splits in midi2abc.c.


August 13 2005.

Abc2midi.exe does not handle correctly chords of the form
[CE]2 when embedded in a triplet. For example in the file,

X:1
T: triplet
M: 4/4
L: 1/4
K:C
(3C2 D2 [CE]2 |

abc2midi produces an error messages 

Warning in line 6 : Different length notes in tuple
Warning in line 6 : Different length notes in tuple

and the [CE] chord is the wrong length.

Analysis: event_note processes the internal lengths
of the notes in a chord before it encounters the end
of chord marker (]) and it does not know that the
internal lengths may be adjusted externally after
the end of chord. It sees the wrong length, and
sends a warning. Event_chordoff fails to make an
adjustment for the triplet (tuple) so that the
function fix_enclosed_note_lengths sets the lengths
of the internal chord notes to the wrong length.

Fix: event_note bypasses the tuple test (for triplets)
if the notes are inside a chord. The tuple test
was also added in event_chordoff. It adjusts the
setting of the note lengths (chord_n, chord_m) if
the chord is inside a tuple. If chord_n and chord_m
are not 1,1 then fix_enclosed_note_lengths is called.

 
August 13 2005

Abc2midi.exe has difficulty handling tied notes enclosed
in a slur. For example for the tune

X:1
T: slur 1
M: 2/4
L: 1/8
K: G
(GB-B) C|(DEF) B|

the following messages appear

Warning in line 6 : Slur in abc taken to mean a tie
Error in line 6 : Bad tie: possibly two ties in a row
Error in line 6 : Cannot find note before tie

Surprisingly, the output MIDI file is still correct.

Analysis and fix: Abc2midi does almost nothing when it encounters 
slurs. However, when it sees repeated notes inside a slur it 
tries to tie them together.  For example for (G B B), abc2midi 
would try to tie the two B's together. This is the source
of the above problem.  I do not think this is a very useful
feature so I have turned this feature off (in event_sluroff store.c). 

August 13 2005

The abc2-draft standard, 
http://abc.sourceforge.net/standard/abc2-draft.html
has deprecated the !...! notation in favour of the +...+
notation. In order to comply with the change, abc2midi, abc2abc
and yaps were modified to accept either convention.
Thus you can use +trill+, +fermata+ +pp+ etc. as well
as the deprecated notation (!trill! etc.). There is one conflict:
in the early days of abc notation chords were notated
as +CEG+ instead of [CEG]. There is probably very little
music using this old convention. If you need to handle the
old chord notation, you must now add the option -OCC to
abc2midi, abc2abc or yaps.

Sample file:

X:1
T: decorations
M: 2/4
L: 1/8
K: G
+<(+ [CE]4 +<)+  |[CE] +trill+  DEF|
!<(! [CE]4 !<)!  |[CE] !trill!  DEF|

Implementation:

Introduced a new global, oldchordconvention into parseabc.c
which is linked externally to store.c, toabc.c and yaps.c.
If this global is unset (ie. 0), then parsemusic in parseabc.c
treats + and ! in the same manner.


August 17 2005
 
Added new run time parameters to midicopy -fromsec and
-tosec allowing you to select a section in terms of time
in seconds.


September 13 2005

Midicopy using the -fromsec option to select the start of the
output MIDI file causes the music to be delayed by the
the same amount of seconds.

Analysis, the first note on (or note off) of the track has
a delta_time equal to the time of the first note in the
selected section of the original file. TiMidity has no problem 
since it ignores this delay. Other MIDI players are less
compliant.

This is a hard bug to fix properly when the tempo varies
across the MIDI file. For such files, it is recommended that
you use the -from and -to parameters and express the times
in MIDI tick (pulse) units. The program now computes
the right delay using the first tempo specification in the
MIDI file.

I noticed that when midicopy truncates the beginning of
a file, a track may begin with a MIDI off command of a note
that has not been turned on. I don't think this causes
a problem.



September 19 2005 

Incorporated changes suggested by Mikhail Teterin into parseabc.c
and store.c to modernize the C code. This includes the replacing
of the functions casecmp(s1,s2) and stringcmp(s1,s2) with functions
built into the C compiler. If this causes any problems with
your compiler please notify me as soon as possible. Other
changes were added to make the code more efficient and eliminate
some warning messages.



September 19 - October 8 2005

Abc2midi: another bug related to split chords was found. In the
following example

X:1
T: split test file
M: 2/4
L: 1/8
Q: 50
K: D
CD |EF AB & CD FG| G2 | BD D2 & GB B2|

The zero th and second bar are only one beat long. The fix described
on June 17 th handles the zero'th bar correctly but it does not
address the second bar since a different function resync_split_voice
is called to maintain synchrony. This function assumes all bars are
a fixed length as specified in the time signature.

This was a difficult bug to fix since it required major changes
to the code. A new function sync_voice replaces the code for
start_new_voice_and_sync and resync_split_voice. A test file used
to debug these changes, split.abc, is included in the programming directory.
Hopefully, I will not need to return to this file many times.


October 8 2005

Abc2midi, yaps, abc2abc : extraneous warning "Slur within slur".
For the following example, 

X:1
T: 2 slurs
M: 2/4
L: 1/8
K: C
V: 1
C2 (C2 |\
V: 2
(A2 G2) |\
V:1
D2) E2|
V:2
G4|

we get the warning
Warning in line 9 : Slur within slur.

Analysis, there are two overlapping slurs, but they are in 
separate voices so this should be no problem. Parseabc.c
merely keeps a count of the number of open slurs with the
variable slur and does not note that they are associated
with specific voices.

Fix: the warning message has been moved to store.c.



October 9 2005

Abc2midi: grace notes are not applied correctly to a chord.
In the following example,

X:1
T: grace/chord
M:2/4
L:1/8
K:G
V:1
D4|{c'}[g3b3] c|z2 G2|
V:2
F4|G3 e|z2 D2|

The length of the host chord [g3b3] is not adjusted correctly.
This results in a loss of synchronization between voice 1 and 2.
Analysis: several bugs related to host chords were fixed in
my new function applygrace_new() in store.c. The original code,
applygrace_orig was also fixed.

October 10 2005

Updated makefiles/unix.mak. Cleaned up some of the -Wall warning
messages.


November 6 2005

New abc2midi feature for supporting drum tracks. Notes played on
MIDI channel 10 (counting from 1), are interpreted by the General
MIDI instrument as one of 47 percussion instruments (see abcguide.txt
for list). Unfortunately, notating the music in this manner is
rather awkward if you wish to convert it to common music notation
using abcm2ps. Usually, only a few percussion instruments are
used. To allow for better drum notation, you can alter the mapping
between notes and percussion instruments using the new
%%MIDI drummap command. For example for the tune:

X:1
T: illustrating drummap command
M: 4/4
L: 1/8
K: none
%%MIDI channel 10
%%MIDI drummap E 36
%%MIDI drummap G 38
%%MIDI drummap _e 42
|: E2 GE zE z2 & z_e z_e z_e z_e :|

would be played on the percussion instruments
bass drum (36)
acoustic sname (38)
and closed hi-hat (42).

Implementation: added new function parse_drummap() genmidi.c
which handles the %%MIDI drummap command. parse_drummap()
is called from the function dodeferred().

November 6 2005

Abc2midi: split voice does not propogate the octave shift
command. eg.

X:15
T: splits with octave=1
M: 4/4
L: 1/4
K: G octave=1
G A B C & E F G A|

The notes E F G A are played an octave lower than intended.

Fix: the v->octaveshift variable is passed to the
split voice in the function event_split.  


December 08 2005

Abc2midi: the drummap feature illustrated on November 06 2005
produces an improper MIDI file. eg.

X:1
T:unfinished
M:2/4
L:1/16
K:F
V:1
%%MIDI channel 10
%%MIDI drummap ^^g 72 % Long Whistle
%%MIDI drummap  _a 58 % Vibraslap
^^gz _a2-_a4 |]

midi2abc.exe unfinished1.mid -mftext

Header format=1 ntrks=2 division=480
Track 1 contains 40 bytes
  0.00   Metatext tempo = 120.00 bpm
  0.00   Metatext key signature F (-1/0)
  0.00   Metatext time signature=2/4
  0.00   Metatext (Seqnce/Track Name) unfinished
Track 2 contains 35 bytes
  0.00   Metatext (Seqnce/Track Name) unfinished
  0.00   Note on  10   c5 105
  0.25   Note off 10   a5   0
  0.50   Note on  10  a#3  80
  2.00   Note off 10  g#5   0

The note on's have the translated pitches but the
note off's have the original pitches. As a result
none of the MIDI note on's are properly terminated.

For percussion instruments, this may not be noticeable
since a decay is already built in. However, some midi
players may complain.

Fix: the function midi_noteoff in genmidi.c now checks for
for channel 10.
 

December 09 2005

Abcmidi: transposition should not be applied to the music
in channel 10. In the following example

X:1
T: drum transpose
M: 2/4
L: 1/8
K: G transpose=-3
V:1
FAFA|EFG2|
V:2
%%MIDI channel 10
%%MIDI drummap g 72 % Long Whistle
%%MIDI drummap a 58 % Vibraslap
agag|agag|

The transpose=-3 changes percussion instruments.
Fix: a test for channel 10 is made before the call to noteon_data()
in the function noteon() in genmidi.c. Also in writetrack, a similar
test was applied before addtoQ in two places (NOTE: and TNOTE:).


December 17 2005

Abc2midi new feature: certain instruments such as an organ have
no greatly emphasized beat notes and sound unnatural when the beat
algorithm accents the down and off beats. To turn this feature use
%%MIDI nobeataccents
To turn it back on
%%MIDI beataccents
By default beat accents are turned on for any new tune.
Thanks to Mike Scott for contributing the code to genmidi.c

Implementation: a new variable beataccents which acts as a
flag was introduced.


January 7 2006

I have started looking into the problem of adding the
split voice feature into yaps.  In order for yaps to
handle split voices, it was necessary to introduce a new
feature code SPLITVOICE into abc.h.  This had minor impact 
on the debugging code for genmidi.c and matchsup.c.
Event_split_voice in yapstree.c now needs to insert a
SPLITVOICE feature. To avoid "unknown type" message
originating from sizevoice (in drawtune.c) it was necessary
to add a case statement for SPLITVOICE even though it does
nothing. To assist in debugging, the code in the showline
function was split into a new function showfeature in
debug.c.

The real work is done in the function advance(..) in 
the file position.c (see additions in programming/yaps.txt).
In order to allow spacemultiline to process all the notes
playing at the same time, major changes are necessary. We
want advance() to check a measure for splitvoices, and if
found process all the notes in the bar in the order that
they would be played. This means extending the voice
structure defined in structs.h so that it maintains
status information for v->tuplefactor, v->inchord, 
v->place,v->time for all splitvoices and telling
advance() to handle the splitvoices in parallel.
This work is beyond me at the present time and
no further work was done.

January 13 2006

abc2midi fails to tie note correctly in chord with
an augmented unison interval. In the following example


X:1
T:A) Matching non-perfect primes
M:C
L:1/2
K:C
[=D^D-] [=D^D] z
[=D-^D] [^D=D] z

the D- tie and ^D- are done improperly.

Analysis: In order to tie notes across bar lines where the 
accidental is assumed, (e.g. A_B-|BD), the function dotie
performs the tie based on the pitch line (in the staff) rather
than the actual pitch. Unfortunately there are cases where we
run into trouble such as above.

Partial Fix: dotie() has a new flag called newbar, which is set to
1 whenever a nonprocessed tie is followed by barline. The
pitchline[] test is now only activated when newbar is set.

Unfortunately, this is not a complete fix. The same
problem reappears with this file for the second and
third lines.


X:1
T:Matching non-perfect primes
M:2/4
L:1/2
K:C
[=D^D-]| [^D=D] | z2 |
[=D^D-]| [=D^D] | z2 |
[=D-^D]| [^D=D] | z2 |
[=D-^D]| [=D^D] | z2 |

The feature array does not record whether accidentals
have been spelled out explicitly so further checks
cannot be done when applying ties across bar lines.
I recommend that one just changes the order of the
notes in the chord in order to get it to work. Fortunately,
this problem occurs rarely.


January 14 2006

Abc2midi fails to tie microtonal notes correctly.
In the following example:


X:1
T: tied microtonal pitches
M:C
L:1/2
K:C
C
^13/16C - ^13/16C
^13/16C   ^13/16C
^13/16C - C

The two notes on the second line are tied together,
but the first note is in C rather than ^13/16C causing
an audible pitchbend. The notes in the third line
are correct pitches but not joined. The tied notes
in the fourth line are both incorrect pitches.

Analyses: looking at the mftext output from midi2abc
reveals the problem.

midi2abc.exe tmp/X1.mid -mftext
Header format=0 ntrks=1 division=480
Track 1 contains 141 bytes
  0.00   Metatext tempo = 227.00 bpm
  0.00   Metatext key signature C (0/0)
  0.00   Metatext time signature=4/4
  0.00   Program   1 73 (Flute)
  0.00   Metatext (Seqnce/Track Name) tied microtonal...
  0.00   Note on   1   c4 127
  2.00   Note off  1   c4   0
  2.00   Pitchbnd  1 msb=0 lsb=90
  2.00   Note on   1   c4 107
  2.00   Pitchbnd  1 msb=0 lsb=64
  4.00   Pitchbnd  1 msb=0 lsb=90
  6.00   Note off  1   c4   0
  6.00   Pitchbnd  1 msb=0 lsb=64
  6.00   Pitchbnd  1 msb=0 lsb=90
  6.00   Note on   1   c4 107
  8.00   Note off  1   c4   0
  8.00   Pitchbnd  1 msb=0 lsb=64
  8.00   Pitchbnd  1 msb=0 lsb=90
  8.00   Note on   1   c4 117
 10.00   Note off  1   c4   0
 10.00   Pitchbnd  1 msb=0 lsb=64
 10.00   Pitchbnd  1 msb=0 lsb=90
 10.00   Note on   1   c4 107
 10.00   Pitchbnd  1 msb=0 lsb=64
 14.00   Note off  1   c4   0

This is another example where the handling of tied notes
in dotie() store.c and writetrack() in genmidi.c have
gets in the way. (The code was written before microtones
was introduced into abcmidi.) The parser encircles
every microtonal note with an event_microtone and
event_normal_tone. The function dotie changes the
tied note from NOTE to TNOTE, the TIE to a REST,
and the note being tied to a REST. The function writetrack()
unfortunately applies the delay() function for the
NOTE feature but not for TNOTE. As a result, the
pitchbend is restored to normal before the note
even starts playing.

Modernizing the tienote function (see February 12 2005
comments) is not an option since there were too many
cases to worry about and it would probably take a
long time to get out all the bugs out.

Fix: a small patch was added to tienote() in store.c.
It removes the DYNAMIC feature restoring the pitchbend
to normal if it finds one immediately following the
TNOTE.



January 15 2006

The contour matching algorithm in abcmatch.c has
been changed to use pitch interval between adjacent
notes. A new run time parameter, -qnt was added
which quantizes the contour interval. Details
in abcmatch.txt.


January 16 2006

Added new feature to yaps that allows you to switch from black
to red output using !red! or +red+ instruction command.
To restore insert !black! or +black+ in the abc file.

e.g.

X: 356
T:Banks of the Nile
M:4/4
L:1/4
K:Eb
B/2-G/2| F E F G| c B G E| F E- C C| C3 C|!red! E E G B!black!|
c2 e c/2c/2| B B E F| G3 E/2E/2| E E G B| c c e c/2c/2| B B E F|
 G3 B/2G/2| F E F G| c B G E| F- E C C| C3||

The notes in the 6 bar are printed in red for emphasis.

Implementation:
In structs.h added a new structure
  struct dynamic {char color;};

In yapstree.c, added code to event_handle_instruction to detect
!red! and !black! and addfeature(DYNAMIC,psaction) where psaction
is a *dynamic struct. In drawtune.c added code to printvoiceline()
to take appropriate issue a postscript command to change the
color when it detects a DYNAMIC: feature.

January 29 2006

Abc2midi: improved the microtone pitch accuracy. Replaced the
code event_microtone (in store.c) with the code contributed by
Hudson Lacerda.

Introduced some support for single note tuning change using
the universal system exclusive messages. Added new function
in midifile.c single_note_tuning_change(). In function
dodeferred in  genmidi.c added a %%MIDI snt k pitch
command where snt stands for single note tuning, k is the
MIDI pitch being retuned (a number between 0 to 127) and
pitch is a floating point number representing the new
pitch value. Sample file follows.

X:1
T: single note tuning
M: 2/4
L: 1/8
K: G
C \
%%MIDI snt 60 61.5
C cd|

I have not yet updated abcguide.txt since this feature
is provisional right now. Not all MIDI devices support
this universal system exclusive message.


February 05 2006

Abc2midi.exe eliminated the warning for microtones
"divisor not a power of 2". Introduced a new copy
of readlen (readlen_nocheck which is called by
ismicrotone() and does not report this error.)


March 14 2006

Abc2abc does not recognize "middle=XXX" in the V: field
which is used by abcm2ps and silently drops it when
transposing abc files. The fix was provided by Mike
Scott who also cleaned up the parameter calling sequence
to event_voice in parseabc.c. This also involved altering
the code in store.c, yapstree.c, matchsup.c, and toabc.c.
Thank you.

Added #include <stdlib.h> to crack.c, mftext.c,
pslib.c and queues.c which cleans up some of the
compilation warnings.(Thanks to Martin Tarenskeen.)


Apr 21 2006

(Mike Scott) The 'y' spacing character used by Barfly and
abcm2ps was being silently dropped in parseabc.c. Added
support for this (including a length specifier - is this
used by anything?) to parseabc.c and abc2abc.c; stubs in
the other modules including yaps mean they behave as before.


June 7 2006

Midicopy: new runtime parameters -frombeat and -tobeat were
introduced to copy a selection of a midi file.

Midifile: new code was introduced to process an individual
track in a multitrack MIDI file.


June 25 2006

Abc2midi: added new feature to provide control over the 
articulation of the notes. The feature %%MIDI trim x/y
introduces a gap between notes of duration x/y where x/y
is the fraction of the unit note length defined by the
L: field command. This gap is made by shortening every
note by this amount whenever it is possible. If the note
is too short, the gap is reduced. Slurs indicated by
parentheses in the music body temporarily disable this feature.

Implementation: added a new feature SETTRIM in abc.h.
Added new globals variables trim,trim_num,trim_denom in
genmidi.c. Added additional code in writetrack to initialize
trim_num,trim_denom and to modify notes for switch conditions
NOTE:, CHORDOFF:, and CHORDOFFEX. Added new switch state
in writetrack to interpret feature SETTRIM.  In store.c, added more
code in event_specific to interpret the %%MIDI trim command.

Abcguide.txt, abc2midi.1 and demo.abc were all updated.

Thanks to Jacques Le Normand for the suggestion.


July 28 2006

Midicopy still does not extract correctly a segment from
some MIDI files when it is specified using the -fromsec and
-tosec parameters. This occurs in multitrack MIDI files 
containing numerous tempo changes. Time units measured in seconds
do not correspond between tracks.

It was decided to completely change the method of handling 
segment extraction when time is specified in seconds. It is
assumed that all tempo indications are placed in track 1 of 
the MIDI file. Tempo changes in other tracks are ignored.
An initial pass is made through track 1 to extract all the 
tempo changes and store them in an array.  This is used to
map time in seconds to MIDI pulses or ticks.  The -fromsec
and -tosec parameters are converted to pulse units using 
this mapping. The program then extracts the MIDI information
falling in this time interval.


July 28 2006

Abc2midi returns the error message
"First lyrics line must come after first music line"
when processin abc files with lyrics and inline voice commands.
For example

X:1
T: inline voice
M:5/8
L: 1/8
K:G
[V:1] cdefg
w: c d e f g
[V:2] cdefg
w: c d e f g

I have little experience with lyrics in abc files.

The problem is caused by the fact that the inline voice command
starts up a new track which resets the variable thismline = -1.
This indicates that a new music line was not yet encountered
for this voice.  If the notes cdefg were placed in a separate
line, then the variable thismline was be set to the current
line number and everything would be all right. Unfortunately,
this is not the case and the abc2 draft standard excepts this
syntax. See abc.sourceforge.net/standard/abc2-draft.html and
in particular the canzonetta.abc file on that page.
There is no easy way of detecting music information at this
point other than updating the variable thismline every
time a note is processed. Instead, I disabled the error
message by commenting the line 
thismline = -1;   
in genmidi.c. Hopefully, this does not cause more damage.


July 29 2006

Abc2midi: microtones (pitchbend) does not work correctly for tied
notes enclosed in a slur. For example:

X:1
T:bad pitchbend when tie + slur
M:4/4
L:1/8
K:C
"^Bad pitch bend when tie+slur"
(^1/2C- ^1/2C =C) a- a4 |
  ^1/2C- ^1/2C =C  a- a4

In the first bar, the tie does not work correctly and 3 notes are
heard instead of two. Furthermore the first note does not have
a pitchbend applied. In the second bar, the notes are played
correctly.

Analysis: running midi2abc with the -mftext option provides
some indication of the problem.

  0.00   Pitchbnd  1 msb=0 lsb=80
  0.00   Note on   1   c4 105
  0.00   Pitchbnd  1 msb=0 lsb=64
  0.50   Pitchbnd  1 msb=0 lsb=80
  1.00   Note off  1   c4   0
  1.00   Pitchbnd  1 msb=0 lsb=64
  1.00   Note on   1   c4  80
  1.50   Note off  1   c4   0

The pitchbend is set prior to the note but is restored to
normal immediately after the note is started (time 0.00).
This is similar to the problem fixed on January 14 2006
(see this file). This suggests a problem with the function
dotie(). Further analysis, revealed that the parser
places a SLUR_TIE after every NOTE feature when the notes
are enclosed inside a slur. The SLUR_TIE is not needed
by abcmidi but it is used by yaps. Unfortunately, the
function dotie() does not expect a SLUR_TIE to appear between
the TNOTE and DYNAMIC so it fails to remove the DYNAMIC
feature.

Fix: A similar patch described in Janurary 14 2006 was
added to dotie().


July 29 2006

Abc2midi: It is not commonly known that accidentals are  not
supposed to propogate across octaves. In the follow example,

X:1
T: accidentals and octaves
M: 2/4
L: 1/8
K: G
C_EDe|C_EDe-|e2^f2|-f2g2|

Abc2midi normally also flattens the e; however, technically
it should not be doing this. Accidentals only apply to a
specific note and should not affect the same pitch class 
in other octaves.

Fix: in store.c workmap and workmul are now doubly indexed
arrays. The second index keeps track of the octave. 


July 30 2006

Abc2abc transposition always reverts to the major key signature
when it does a transposition.

Analysis: the code in toabc.c represents the key signature
in terms of the number of sharps and flats and ignores the
mode of the original key signature when it is doing a transposition.

Fix: (1) In parseabc.c the index to the array mode[] is
saved in the variable modeindex when a mode string is matched.
(2) in order to pass modeindex to event_key, the function
parameter minor was replaced with modeindex and the
variable minor was turned into a local variable which is
computed from modeindex. This was done in all files where
event_key is defined -- store.c, yapstree.c, matchsup.c,
and toabc.c. (In actual fact, the variable minor was only
used in store.c to set the minor flag in the MIDI file.)
(3) A new function called compute_keysignature() from
the sharps/flat representation and modeindex was added to
toabc.c. (4) event_key in toabc uses this function to
compute the correct key signature.


August 04 2006

abc2midi: The treatment of microtones and microtones with
accidentals for key signatures other than C major (or A minor)
has been changed. Prior to version 1.87, if the music
was in the key of G major, ^1/2F would be interpreted
as raising F# by a half a microtone. Now the underlying
key signature is ignored and the microtone is treated as
a pure accidental. Thus ^1/2F raised F and not F#.
Hopefully this is more intuitive.

Thus accidentals and microtones are assumed to be
applied to the natural form of the note irrespective
of the key signature or the status of previous
notes in the measure. However, accidentals other
than microtones can still propagate to notes which
do not have accidentals. To illustrate consider
the following in the key of C major.

    _E _1/2E E __1/2E E|

The second E is treated as E natural flattend by 1/2
microtone because E is always assumed to be in its natural
form when preceded by any accidentals. Since the assumed
natural of the second E propagates,  the third E is also
E natural and not Eb. The last note is Eb reduced by half
a semitone.  The last E would be played as Eb.  See 
abcguide.txt for another example.


Implementation turned out to be easier than expected. A 
new global (int microtone) was added to store.c. It is
set to 1 by event_microtone and reset to 0 by event_normal_tone.
The function pitchof(), now does not apply the active
flats or sharps (of the key signature) or accidentals when
the microtone global is set.


August 4 2006

Abcm2ps has introduced an extension of the w: field
referenced by the s: field which accepts ~ as a decoration.
Unfortunately, the parser in the abcmidi package does not
recognize this field command and attempts to treat the
line as a music line. As a result a file such as
 

X:1
T: s
K:C
    cd ef  g4       | ag      ab   c'4 |]
s: "C"~~~ "C/E"    | "Dm/F"* "G7" "C"
s: .. ..  +tenuto+ | ..      ..   !fermata!
s: "_5"***"_6"     | "_6"*   "_7"*"_5"
s: "_3"***"_3"     | "_3"*   "_5;3"*"_3"

produces many error messages
Error in line 6 : Single colon in bar
Error in line 6 : Malformed note : expecting a-g or A-G
Error in line 6 : *'s in middle of line ignored
Error in line 7 : Single colon in bar
Error in line 7 : Malformed note : expecting a-g or A-G
Error in line 7 : Malformed note : expecting a-g or A-G
Warning in line 7 : instruction !tenuto! ignored
Error in line 7 : Malformed note : expecting a-g or A-G
Error in line 7 : Malformed note : expecting a-g or A-G
Error in line 8 : Single colon in bar
Error in line 8 : *'s in middle of line ignored
Error in line 8 : *'s in middle of line ignored
Error in line 8 : *'s in middle of line ignored
Error in line 9 : Single colon in bar
Error in line 9 : *'s in middle of line ignored
Error in line 9 : *'s in middle of line ignored
Error in line 9 : *'s in middle of line ignored

Similar error messages occur for other abcmidi programs,
for example yaps, abc2abc etc.

Fix: in parseabc.c: for function
parsefield add s to the strchr string
  if ((inbody) && (strchr("EIKLMPQTVdwW", key) == NULL)) {
    event_error("Field not allowed in tune body");
and also added the case in the switch statement
  case 's':
    break;
finally in parseline() added s to the strchr string in
  if (strchr("ABCDEFGHIKLMNOPQRSTUVdwWXZ", *p) != NULL) {
    q = p + 1;


August 05 2006

Note trimming introduced in June 25 2006 causes loss of
synchronization between two voices when notes are contained
in a grace sequence. 
Fix: introduced a variable graceflag into writetrack() in
genmidi.c. The flag is set when GRACE feature is encountered
and restored to zero when GRACEOFF feature is encountered.
Note trimming is disabled inside a grace sequence. Also
note trimming is shutoff for short notes.
In order to separate two slurs in a row, trimming is
restored for the last note in a slur.

August 08 2006

Abc2midi: split voices. In the file

X:1
T: also D sharp continues in next bar
K:C
M:4/4
L:1/4
C^DEF & C4 | CDEF |

The D in the second bar is sharpened.
Fix: added call to function copymap() in the function
recurse_back_to_original_voice().

August 29 2006

Abc2abc: handling of rests in tuples causes an error
message. The problem does not occur in abc2midi
or yaps. For example

X:1
T: tuple rests
M: 2/4
L: 1/8
K: C
G4|(3z2A2B2|F4|

abc2abc tuplerest.abc -t 3
X: 1
T:tuple rests
M:2/4
L:1/8
K:C
G4|
%Error : Rest not allowed in tuple
 (3z2A2B2
%Error : Bar 1 is 7/12 not 2/4
|F4
%Error : Bar 2 is 1/3 not 2/4
|


Fix: in the function event_rest in toabc.c, the
error message was removed and the beat counter
code was modified to consider tuples.  


September 09 2006

abc2abc: voice numbers not processed correctly. In the
following example:

X:1
T:voices
M: 2/4
L:1/8
K:G
V:1
ABCD|abcd|
V:1I
ABCD|abcd|

V:1I was changed to V:1 producing an incorrect abc file.
Analysis: the parsevoice() in parseabc decides whether the
voice number is a number or a label based on the first character.
Since the first character of 1I is a number it treats it as
a number and ignores the I. This problem also persists for
abc2midi and yaps.
Fix: created a new function isnumberp(s) which determines
whether the string s is a positive integer number and
returns 0 for no and 1 for yes; replaced the original test
with this function. 

September 11 2006

Abc2midi: handling of trilled notes for broken rhythms is not
correct. In the following example,

X:1
T: trill
M: 2/4
L: 1/8
K:C
%%MIDI ratio 3 1
TE>G TF3/A/|

the length of notes E and G are not adjusted for broken rhythm
and remain as equal values.
Analysis:  the handling of broken rhythms is fairly complicated
in the file store.c.  The location of E and G are maintained by 
variables v->thisstart, v->thisend and v->laststart, v->lastend
by the functions marknotestart, marknoteend and marknote. (This
also allows the handling of chords too.) When a > or < is encountered
a number of flags (brokenpending, brokentype, brokenmult) are set
by the function event_broken.  The function marknotend checks
these flags and calls brokenadjust to adjust the lengths of E and
G using the stored variables v->thisstart, v->thisend etc.  Trilling
is handled by the function dotrill() which expands note E
into a sequence of notes whose length depends upon the length
of E and the tempo. In this example, the expansion is done
prior to encountering the broken rhythm indicator >. After
G is encountered, the lengths of the notes are adjusted for
broken rhythm. Unfortunately, there is a bug in dotrill, and
marknotestart was called for the last note in the trill sequence
rather than the first note.  The problem was fixed by changing
this code. Note that in the above example, the number of notes
in the trilled E and the trilled F are different. This is
because E is not effectively expanded until after it was
trilled. There is no easy fix to this problem other than 
avoiding mixing notations for broken rhythms.

trilled F are different.
than the first note


September 22 2006

Midicopy.c: to avoid problems with some systems, the byte val
for the runtime string 
-replace trk,loc,val
is read as an integer (%d) instead of a char (%c).

 
September 22 2006

Abc2abc, abc2midi etc. does not recognize "clef=G".
In the following example,


X:1
T: clef problem
M: 2/4
L: 1/8
K: Am clef=G
"Am"ABCD|ABCD|

The following message appears:
%Warning : cannot recognize clef indication
K:Am clef=G

Fix: added checks for clef=g or clef=G in the function
isclef() in parseabc.c


September 23 2006

Abc2abc removes blank lines from abc files. (These
blank lines are usually to encircle comments between
tunes in a multitune file.

Analysis: whenever parseline() (in parseabc.c) detects
a blank line, it calls event_blankline(). In abc2abc,
event_blankline() only emits a blank line if the flag
newbreaks is set. Unfortunately, this parameter is used
for another purpose (i.e. reformating an abc file with
new linebreaks every X bars using the -n X runtime parameter).
This has nothing to do with handling already existing
blank lines. Since event_blankline is called only when
there is a blank line, it appears that the condition on
the flag newbreaks should not be present.

Fix: the condition statement was removed. A blank line will
always be issued. Note that event_blankline also closes
the tune and parser for that tune as usual.



September 25 2006

Abc2midi: some users have complained about the unnecessary
warnings and error messages issued by abc2midi. For example
standard music practice does not require a leading repeat
mark |: to be placed at the beginning of the sheet music and
it is commonly left out in many abc transcriptions. Abc2midi
typically warns the user that it has been left out but does
the correct thing. Furthermore, the placement of a fermata sign
will likely cause a message that a bar has too many beats.
Too placate the users,

I have introduced a new runtime parameter -quiet which will 
suppress all these messages. 

Note abc2midi parses the abc file in two passes and may not
always handle assumed repeats correctly. For example if the
tune begins with an anacrusis, abc2midi does not attempt
to figure out whether the |: should be placed before or
after the anacrusis. (This depends upon the placement of the
end repeat.) In multipart files, abc2midi fails to place
a starting repeat sign.

In the case of multivoiced files, loss of synchronization between
voices can occur because of user mistakes or because abc2midi made 
the wrong assumption.  (For example, search for the word fermata 
in this file.)

Though attempts have been made to standardize the abc music notation
language, it is a living language and various variants are introduced
now and then. Abc files that have been notated many years ago are
not updated to correct for the various problems that are introduced by
these new features. There is a variety of software to process abc files,
but many of the developers have moved to other things and fail to
maintain their software.  Though these messages are an inconvenience
to users they are useful in diagnosing problems when the MIDI file
does not sound correctly.


September 26 2006

Abc2midi: now supports linear temperament scale using code contributed
by Magnus Jonsson.  New %%MIDI commands are introduced to change the
temperament.

%%MIDI temperamentlinear octave_cents fifth_cents

where the variables specify the size of an octave and size
of a perfect fifth in cents where one cent is 1/100 of
a semitone or 1/1200 of an octave.

%%MIDI temperamentlinear 1200.0 700.0

produces the equal tempered scale.

%%MIDI temperamentlinear 1200.5 698

produces a slightly stretched octaves and narrowed fifths.
Quoting the Help for the program Scala 
http://www.xs4all.nl/~huygensf/scala/

A linear temperament is a cycle or chain of one particular interval,
called the generator or formal fifth. Whenever by doing so a pitch
originates that is outside the range of one formal octave (interval of
equivalence), it is "wrapped" back inside by subtracting the formal
octave value. Examples of this kind of scale are the Pythagorean scale
generated by a pure fifth, and regular meantone scales.

Implementation:
store.c :
  added new globals temperament, octave_size, fifth_size
  which are set by %%MIDI temperamentlinear. Created a new function
  pitchof_b() which is similar to function pitchof() but also returns
  a pointer pitchbend. Pitchof_b() would eventually replace all calls
  to pitchof(). The function pitchof_b() applies the linear temperament
  scale if the global variable temperament is set. It updates the
  pointer pitchbend unless it was already set by a microtone.

  To store the pitchbend value of every note a new array bentpitch
  was added to the other arrays (pitch, num, denom, feature).
  The function event_note transfers the pitchbend value to bentpitch,
  so it can be used by writetrack() in the second pass (in genmidi).

  Other functions that had to be updated were doroll, dotrill, 
  makecut, and doornament.

genmidi.c :
  Added global array current_pitchbend[], which maintains the
  current pitchbend for each channel. It is initialized to 8192
  (neutral value) by starttrack. The pitchbend value is now
  transferred to the function midi_noteon(). It will issue
  a pitchwheel command anytime a new pitchbend value occurs
  for the specific channel. Other functions like noteon_data()
  and save_note() also carry the parameter pitchbend.


Limitations: linear temperament is not applied to guitar gchords.


October 3 2006

Abc2midi: in order that microtones are applied correctly to
in voice chords such as [CEG], it is necessary that each note
in the chord be played on a separate MIDI channel.  A new MIDI
command "makechordchannels n" has been introduced for allocating
MIDI channels specifically for the handling of chords. The
value of n specifies the number of channels to be allocated.
It should be one less the maximum number of notes in the chord.
Note that since you have only 16 channels in a MIDI file and
once the channel has been allocated it is unavailable for
any other use. You need to do a separate allocation for each
voice containing such chords.

Implementation:
In genmidi.c, introduced a global array chordchannels[] which
is used to store the channel numbers for handling chords.
chordchannel[0] is the channel number normally used for
handling notes for that voice. Introduced a global integer
nchordchannels storing the number of channels in chordchannels[].
Created a new function makechordchannels() for assigning
these channels to chordchannels[]. Makechordchannels also
sets the channels program (musical instrument) to the current program
for the voice. (If you need to know the channel numbers that
have been assigned, run abc2midi with the -v option (verbosity)).
Created another branch in the function dodeferred() for handling
the MIDI command makechordchannels(). 



October 15 2006

The following file was not parsed correctly.

X:1
T: 2 or 3 tracks
M: 3/4
L: 1/8
K:G
g2| g2 fe b2|
V:2
A2 |[B4E4] G2|

Analysis: a bug I introduced recently resulted in the voice number (2)
not being read correctly.

Fix: in the function parsevoice() in parseabc.c, I changed the
statement
if (isnumberp(&s)) {
to 
if (isnumberp(&s) == 0) {

apparently, this function returns 0 if the string contains a
positive number and 1 otherwise.


October 27 2006

Abc2midi: using the command %%MIDI drumon causes the error
MIDI read/write error : error: MIDI channel greater than 16
and abc2midi fails.

This is another bug I had introduced. Adding the pitchbend
parameter 8192 to save_note in function dodrus() in genmidi
fixes this problem.


October 27 2006

Abc2abc transpose places spurious spaces between notes
breaking up the beaming pattern. For example for,
X: 1
T: beaming error
L: 1/8
M: 4/4
K: Eb
^C,,2 z2 z^C,/D,/ =E,/^F,/G,/=A,/ | B,/=A,/G,/^F,/ G,/=E,/^C,/D,/
E,/F,/G,/A,/ B,/A,/G,/A,/ |

abc2abc beaming.abc -t 1 produces

X: 1
T:beaming error
L:1/8
M:4/4
K:Emaj
^^C,,2 z2 z^^C,/2 D,/2 ^E,/2^^F,/2 G,/2^A,/2 | B,/2^A,/2G,/2^^F,/2  G,/2^E,/2^^C ,/2 D,/2
 E,/2 F,/2 G,/2 A,/2  B,/2 A,/2 G,/2 A,/2 |

(note all the spaces between the notes in the second line of the body).

Analysis: the local variable mult in event_note1() in toabc.c is
used before it is defined.

Fix: event_note1() now sets it to zero in case it is not set elsewhere.




November 3 2006

Abc2midi bug: pitches are incorrect for staccato notes. eg

X:1
T: staccato bug
M:3/2
L:1/2
Q:1/4=70
%%MIDI program 16
%%MIDI nobeataccents
K:C
=B=c=d | .=B.=c.=d |

The pitches of the last three notes have been affected by
a pitchbend.

Analysis: This is a bug I recently introduced. The bentpitch[] feature
was not set to 8192 for staccato notes.

Fix:  added the following line
  bentpitch[notes] = active_pitchbend;
before
  addfeature(NOTE, ...);

in event_note() in store.c. Also added it in doornament().



November 3 2006

Abc2midi bug: the following file causes the error message
MIDI read/write error : error: MIDI channel greater than 16
to appear.

X:1
T: makechord
M:3/2
L:1/2
Q:1/4=70
V:1
%%MIDI nobeataccents
%%MIDI program 16
%%MIDI makechordchannels 2
V:2
%%MIDI program 16
%%MIDI makechordchannels 2
V:3
%%MIDI program 16
%%MIDI makechordchannels 2
K:C
%
V:1
[c'_/e'g']
V:2
[c_/eg]
V:3
[C_/EG]


Analysis: there was a missing parameter (bentpitch) in the function
call to noteon_data() when channel == 9. As a result the function
noteon_data() received a meaningless channel number. However,
since channel 9 is reserved for percussion, it should never have 
been assigned. To fix this problem, the global variable channels[9]
was set to 1 in writetrack() (genmidi.c), so that findchannel()
will not select this channel.


December 9 2006

Abc2midi bug: the %%MIDI drone command returns an error
MIDI channel > 16.
Fix: missing parameter in function midi_noteon(), pitchbend,
was added.


December 12 2006

Abc2midi bug: split voices does not work correctly when
it is embedded in a part (eg. P:B). For example:

X: 1
T: bad merge
M: 4/4
L: 1/8
K: C
P:A
| C2 D2 E2 F2 | G2 A2 B2 c2 |
P:B
| C2 D2 E2 F2 & C,2 D,2 E,2 F,2 | G2 A2 B2 c2 |

The split voice does not merge correctly in the
above example.

Analysis: not all voices may be indicated in a part. As a
precaution, genmidi calls partbreak which fills in any missing
voices. Unfortunately, split voices are automatically resynced
which causes the voice to be filled in twice.
Fix: a new global array dependent_voice[] was added in 
store.c and linked to genmidi.c. This array contains flags
indicating where the particular voice was a natural voice
created by a voice command (V:) or whether this is a 
split voice dependent on the natural voice. The function
partbreak checks this flag and does nothing if is a
dependent voice.
 

December 21 2006

Voice bug (abc2midi, yaps): the fix described in September 9 2006
caused another bug. For the following example:

X:1
T: noel
M: 2/4
L: 1/4
K: C
V: alpha
C E|D F|
V: beta
A C| G B|

The parser fails to handle nonnumeric voice numbers.
Fix: in line 996 of parseabc.c isnumberp returns 1
if the character string is a positive number and 0 if
it is not. The 0 was replaced with 1 as shown below.
if (isnumberp(&s) == 1) {

December 26 2006

Midi2abc bug. Some music notation programs automatically place
short rests between notes and chords in order to improve the
articulation. Midi2abc is able to ignore these rests using
the -sr parameter as described in the midi2abc.1 documentation.
Unfortunately, this feature does not work correctly when rests
are placed in between chords.

Analysis: the quantize() function decides whether to eliminate
the rest based on the difference between the inter note interval
(note->xnum) and the "on" time of the note (note->play). For
some of the chordal notes, note->xnum is zero since all the notes
in the chord start at the same time. This causes the program
to produce erroneous results.

Fix: a new function xnum_to_next_nonchordal_note() was introduced
to look ahead past all the chordal notes and return the quantized
note interval to the next nonchordal note. The quantize function
uses this value when the -sr option is turned on. (I have
a feeling this fix may not work correctly when the notes in
the chord are not all equal length. In other words I do not
recommend using the -sr option with -splitbars or -splitvoice.)


January 02 2007

Abc2midi bug: %%MIDI trim does not work according to documentation.
The trim command is used to control the articulation of notes.
Like staccato it shortens the playing time of the note,
leaving a silent period before the next note. According to
the documentation the amount shortened should be the trim
fraction time the unit note length. It turns out that
the trim length was not adjusted for the unit note length
so that the following example did not work.

X:1
T: trim
M: 2/4
L: 1/8
K: C
%%MIDI trim 1/2
CDEF|

Fix: store.c was modified so that trim value set is a fraction
of the unit note length as defined by the L: field command.
Note, that if the unit note length is changed again, it is
necessary to reissue another trim command, eg.


X:1
T: trim
M: 2/4
L: 1/8
K: C
%%MIDI trim 1/2
CDEF|
L: 1/16
%%MIDI trim 1/2
CDEF CDEF CDEF CDEF|

Otherwise the trim length will remain unchanged.


January 06 2007

Abc2midi bug: wrong bar count when %%MIDI trim command
mixed with chords. In the following example,

X:1
T: Bad barcount
M: 2/4
L: 1/8
K: C 
%%MIDI trim 1/2
AB CD |AC DF |[A2c2] DF |
[AB]2 [CD]2 |

Abc2midi produces the following warnings:

Warning in line 9 : Bar 2 has 7/4 units instead of 2
Warning in line 10 : Bar 3 has 3/2 units instead of 2

Furthermore, this may throw off the gchord accompaniment
if it exists.

Fix: in writetrack for case CHORDOFF: and CHORDOFFEX:,
the function addunits() is called before trim adjustment
instead of after.


March 15 2007

Abc2midi ends a MIDI track immediately after the last note.
On some MIDI synthesizers, this introduces a small artefact
at the end of the MIDI file. Fix, a short delay of 25 MIDI
pulses is inserted before the end of track. This was incorporated
in the function clearQ() in queues.c.

Midi2abc -mftext mode was modified to report end of track meta
command.

