Some basic rules seem to be:
* Use sharps in sharp keys, flats in flat keys.
* Use sharps in ascending scales and flats when descending.
* Make sure that the positions of the notes on the staff follow the
contour of the melody, using whatever combination of position and
accidental achieves that.
The last rule seems to be the most important, and also the most
difficult to deal with, as you can't treat notes in isolation; the
accidental to use depends on the surrounding notes. If you want to
write a chromatic scale you cannot continue to place each note on a
different staff line indefinitely because you eventually find yourself
needing triple or quadruple accidentals.
I'm finding it quite difficult to formulate an algorithm to deal with
this, and I would appreciate any comments or suggestions.
Phil Taylor
>I'm finding it quite difficult to formulate an algorithm to deal with
>this, and I would appreciate any comments or suggestions.
I'd love to be wrong as it could be of real benefit, but I'm not
sure that there could ever be an effective algorithm for this as
most of the time it's a matter of choice with no real absolute
rules; as you say, much of the time it depends on context.
Sometimes the choice of accidental can also relate to the actual
instrument. I can't say exactly which off the top of my head, but
I seem to remember there are wind instruments where, for example,
a Db in some octaves is much more awkward to play than a C#.
I'd tend to regard the vertical spacing issue as being less
critical on a single line melody stave than on a polyphonic stave,
such as for piano, harp or guitar where it can really screw up the
readability.
Good luck with figuring it out :) I'd be very interested in seeing
how you get on with it. I suspect if anyone's likely to come up
with a solution, it'd be you.
--
DG
Accidentals for pedal harp have to take the actions of the pedals
into account. If you were writing an F in one octave and an F# in
another, the F# would need to be Gb, regardless of the normal
rules.
--
DG
Yes, I can see that. I would expect to find problems with special
cases like that, but I was surprised at how difficult it is to get this
right just in the simple general case (single melody line, no specific
instrument).
I had a similar problem with choosing accidentals when transposing. I
found a solution to that, but it depends on having the correct
accidental present in the original. In this case the original doesn't
have accidentals so I'm on my own...
Phil Taylor
>In <291220061105052603%not...@all.invalid> on Fri, 29 Dec 2006
>11:05:04 GMT, Phil Taylor wrote:
>
>>I'm finding it quite difficult to formulate an algorithm to deal with
>>this, and I would appreciate any comments or suggestions.
>
>I'd love to be wrong as it could be of real benefit, but I'm not
>sure that there could ever be an effective algorithm for this as
>most of the time it's a matter of choice with no real absolute
>rules; as you say, much of the time it depends on context.
[snip]
... and on the composer; some use a rather idiosyncratic choice of
accidentals.
>Good luck with figuring it out :) I'd be very interested in seeing
>how you get on with it. I suspect if anyone's likely to come up
>with a solution, it'd be you.
Most major notation programs do a passable job at importing MIDI files
and making sensible choices when placing accidentals; the one I use,
MOZART, certainly does. However smart the importation may be, some
editing will always be required.
--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
>On Sat, 30 Dec 2006 18:55:30 +0000, Dick Gaughan wrote in
>uk.music.notation:
>
>>In <291220061105052603%not...@all.invalid> on Fri, 29 Dec 2006
>>11:05:04 GMT, Phil Taylor wrote:
>>
>>>I'm finding it quite difficult to formulate an algorithm to deal with
>>>this, and I would appreciate any comments or suggestions.
>>
>>I'd love to be wrong as it could be of real benefit, but I'm not
>>sure that there could ever be an effective algorithm for this as
>>most of the time it's a matter of choice with no real absolute
>>rules; as you say, much of the time it depends on context.
>[snip]
>
>... and on the composer; some use a rather idiosyncratic choice of
>accidentals.
I'm very guilty of that. Possibly because my main instrument is
guitar and I never did the formal music college route, unless I
stop and think seriously about context I tend to automatically
favour Ab, Bb, C#, Eb, F#.
>Most major notation programs do a passable job at importing MIDI files
>and making sensible choices when placing accidentals; the one I use,
>MOZART, certainly does. However smart the importation may be, some
>editing will always be required.
I think the best Phil can aim for is to have a "best guess"
algorithm, leaving it to the individual end user to edit to suit
their own preferences/instrument. I've imported MIDI files into
Sibelius and while, like Mozart, it does a passable job, some
tweaking is always necessary.
Perhaps the "sharps ascending/flats descending" convention would
provide a reasonable starting point then exceptions could be
added. I'm not much of a programmer so I suppose I see the
problems more clearly than solutions, which probably doesn't
really help much.
--
DG
>I had a similar problem with choosing accidentals when transposing. I
>found a solution to that, but it depends on having the correct
>accidental present in the original. In this case the original doesn't
>have accidentals so I'm on my own...
When I get a minute I'll experiment a bit with how Sibelius
handles various transpositions like that and let you know what I
can learn from it. I use it routinely in writing for transposing
instruments but I've never really paid much attention to how it
actually does it. In general, it seems to do a good job[1] so
maybe there's some mileage in figuring out how it handles odd
quirks.
[1] Although I had an embarrassing incident with this a couple of
years ago. I hadn't much experience with writing for trumpets
(although I did play it at school way back when.) A pro orchestral
trumpeter had assured me the convention was to simply write in C
and let the player transpose. At the first rehearsal the 1st
trumpeter informed me he'd be using an Eb for the higher passages
and would I transpose his part accordingly. "No problem", think I,
"piece of piss in Sibelius."
So I simply ran it off without doing any editing and gave it to
him. When I asked him later how the hell he managed to read the
resulting mess of double-flats and sharps he replied, with
commendable patience, "With great difficulty."
--
DG
What's immediately noticeable is that Sibelius seems to give
absolute priority to the "flats in flat keys/sharps in sharp keys"
rule, regardless of other context.
I don't know if it'll be any use to you at all, Phil, but I've
stuck the result on my website as a graphic if you want to take a
look.
You'll find it at
http://www.dickgaughan.co.uk/transpose/index.html
--
DG
> Out of curiosity, I just did a wee test on how Sibelius handles
> accidentals. I took the first 4 bars of the reel "Music in the
> Glen" and for the sake of the test, I shifted it into C where
> there would be no sharps or flats, then ran through transposing
> it.
>
> What's immediately noticeable is that Sibelius seems to give
> absolute priority to the "flats in flat keys/sharps in sharp keys"
> rule, regardless of other context.
>
> I don't know if it'll be any use to you at all, Phil, but I've
> stuck the result on my website as a graphic if you want to take a
> look.
Ah yes, that's interesting. It's basically what I'm doing at the
moment, which is reassuring.
As a guitar player I tend to think of transposition in terms of moving
all the notes by a fixed number of semitones, but that doesn't help
much when it comes to deciding what accidentals to use. A better way
is to think in terms of moving each note a fixed number of steps in the
cycle of fifths. I got this tip from a guy named Jeremy Barthelemy,
who posted it on the MusicXML list.
If you write out the cycle of fifths like this:
Fbb, Cbb, Gbb, Dbb, Abb, Ebb, Bbb, Fb, Cb, Gb, Db, Ab, Eb, Bb,
F, C, G, D, A, E, B, F#, C#, G#, D#, A#, E#, B#, F##, C##, G##,
D##, A##, E##, B##.
then you move each note by the same number of steps in the table, you
automatically get the correct accidental (provided that it was notated
correctly in the original key).
However, it doesn't help if you are starting from Midi codes rather
than notation.
Phil Taylor
If I write out a tune I've learnt by ear, I'd start by deciding what the
key/mode/scale was, and use that as a basis for deciding accidentals. Which
is probably not that helpful in terms of writing code, not being an easy
algorythm either.
--
Richard Robinson
"The whole plan hinged upon the natural curiosity of potatoes" - S. Lem
My email address is at http://www.qualmograph.org.uk/contact.html
The most appropriate accidental is often the one that makes the music
easiest to read. I'll use ABC to give an example, but I'm actually
talking about the ease of reading sheet music. Assuming a key in which
A's are not modified, then reading A ^A =A is harder than reading
A _B A because (1) you have to modify two notes, and (2) the A's are
all on the same line whereas the B is higher on the stave, which more
accurately follows the contour of the note pitches.
I hope that's useful, but it's so context-dependent that I don't know
how you'd begin to program it!
Dave
That's quite an interesting case, as that seems to be the correct
solution even if we are in a sharp key. (The only way to do it with
sharps is ^^G ^A G which is clearly uneconomical.)
The order of precedence for the rules would seem to be:
1. Don't put successive notes of different pitches on the same line,
but have them follow the contour of the melody.
2. Minimise the number of accidentals required.
3. Prefer sharps in sharp keys, flats in flat keys.
>
> I hope that's useful, but it's so context-dependent that I don't know
> how you'd begin to program it!
The big question seems to be how wide a context (i.e. how many
successive notes) I have to consider. There just doesn't seem to be an
answer to that, but I'd guess that two or three notes would cover
almost all cases.
I do love a good puzzle!
Phil Taylor
I think you have to do some look-ahead too: A ^A B is fine, A _B =B is
(probably) less good.
>I do love a good puzzle!
:-)
Dave
Hmm. If the over-riding rule is to put adjacent notes of different
pitch on separate lines, then surely the correct solution there would
be A _B _c or maybe ^^G ^A B ?
Phil Taylor
Double-accidentals are harder to read (being fairly unusual, at least in
the sort of music I play/sing). I'd say that makes a notation using them
less preferable.
I'll try to dig out some sheet music with this sort of thing in and see
what's done in "real" printed music. Also I can find the Associated
Board scales book and see how they notate chromatic scales if you like,
that might be interesting. And in a moving-house box somewhere I have
the "Essential Dictionary of Music Notation" which might also have
pointers.
(This is fascinating, and thanks for bringing it up, by the way. In
general I know how I'd notate a tune, but not why!)
Dave
> Phil Taylor <not...@all.invalid> wrote:
> >Hmm. If the over-riding rule is to put adjacent notes of different
> >pitch on separate lines, then surely the correct solution there would
> >be A _B _c or maybe ^^G ^A B ?
>
> Double-accidentals are harder to read (being fairly unusual, at least in
> the sort of music I play/sing). I'd say that makes a notation using them
> less preferable.
>
> I'll try to dig out some sheet music with this sort of thing in and see
> what's done in "real" printed music. Also I can find the Associated
> Board scales book and see how they notate chromatic scales if you like,
> that might be interesting. And in a moving-house box somewhere I have
> the "Essential Dictionary of Music Notation" which might also have
> pointers.
I think that chromatic scales are a special case, because you don't
want to put an accidental on the tonic, and after a few notes you run
out of accidentals, and start to need triple accidentals (which don't
exist). C _D __E ___F ?
Actually, that probably answers my question as to how many consecutive
notes I have to consider, as the problem becomes insoluble when the
number exceeds three, and you have to fall back on putting the notes on
the same line.
>
> (This is fascinating, and thanks for bringing it up, by the way. In
> general I know how I'd notate a tune, but not why!)
Yes, I'm in the same situation myself.
Phil Taylor
>The order of precedence for the rules would seem to be:
>
>1. Don't put successive notes of different pitches on the same line,
>but have them follow the contour of the melody.
Surely not always? Consider a piece in C-major that is modulating into
G-Major with the notes going F, F#, G (I don't think this is uncommon).
You would surely notate that as F, F#, G rather than E#, F#, G, or F,
Gb, Abb ???
>2. Minimise the number of accidentals required.
>3. Prefer sharps in sharp keys, flats in flat keys.
So I think I'd not try to put these "rules" in a precedence order but
consider them all in each case. There is also this:
3a. In C-major, prefer sharps/flats according to the key you are moving
into.
I think the "key" to this is indeed to take into account the key that
the music is in. If music in E-major modulates into the related
C#-minor, the note that is a semitone below C# should be B#, not
C-natural. Of course, not all music can be analyzed neatly into keys...
And sometimes, writing the music "properly" in this sense can make it
more difficult to play. Double sharps and flats are a case in point. And
I have several times stumbled when confronted by sequences like C#
followed by Db while sight-reading.
--
Philip Hazel
University Computing Service, Cambridge, England.
> In article <020120072014049134%not...@all.invalid>,
> Phil Taylor <not...@all.invalid> writes:
>
> >The order of precedence for the rules would seem to be:
> >
> >1. Don't put successive notes of different pitches on the same line,
> >but have them follow the contour of the melody.
>
> Surely not always? Consider a piece in C-major that is modulating into
> G-Major with the notes going F, F#, G (I don't think this is uncommon).
> You would surely notate that as F, F#, G rather than E#, F#, G, or F,
> Gb, Abb ???
The last option is obviously wrong, but surely E#, F# G would be the
easiest to read?
>
> >2. Minimise the number of accidentals required.
> >3. Prefer sharps in sharp keys, flats in flat keys.
>
> So I think I'd not try to put these "rules" in a precedence order but
> consider them all in each case. There is also this:
>
> 3a. In C-major, prefer sharps/flats according to the key you are moving
> into.
>
> I think the "key" to this is indeed to take into account the key that
> the music is in. If music in E-major modulates into the related
> C#-minor, the note that is a semitone below C# should be B#, not
> C-natural. Of course, not all music can be analyzed neatly into keys...
>
> And sometimes, writing the music "properly" in this sense can make it
> more difficult to play. Double sharps and flats are a case in point. And
> I have several times stumbled when confronted by sequences like C#
> followed by Db while sight-reading.
Several valid points there. Part of the problem is that although Midi
files do contain a key signature field, they are often written by
programs which have no concept of key, so it's just set to C major by
default. I do have an algorithm which can determine the true key
(mostly), but it's statistical, and works best when applied to the
whole piece. Detecting modulation within a melody is a seriously tough
programming problem.
The more I think about this, the more I realise that there isn't going
to be a perfect solution, and the best I can do is to get it right in
the majority of cases, leaving the user to edit the remainder to his
taste.
Phil Taylor
Why do it algorithmically? Some sort of neural-net-like classification
technique would surely work just as well. You could just convert all
the ABC you've got into MIDI and back-propagate it. That's more or less
what your guess-the-mode utility in BarFly does already.
============== j-c ====== @ ====== purr . demon . co . uk ==============
Jack Campin: 11 Third St, Newtongrange EH22 4PU, Scotland | tel 0131 660 4760
<http://www.purr.demon.co.uk/jack/> for CD-ROMs and free | fax 0870 0554 975
stuff: Scottish music, food intolerance, & Mac logic fonts | mob 07800 739 557
>> Surely not always? Consider a piece in C-major that is modulating into
>> G-Major with the notes going F, F#, G (I don't think this is uncommon).
>> You would surely notate that as F, F#, G rather than E#, F#, G, or F,
>> Gb, Abb ???
>
>The last option is obviously wrong, but surely E#, F# G would be the
>easiest to read?
For others, maybe. For me, as a string player, E# is an abomination. :-)
I would far rather see the "obvious" F, F#, G sequence[*]. And so, I
suspect, would anybody learning to read music for whom this was their
first encounter with accidentals. But YMMV.
[*] Which I'm sure is what you would see in published music. Which means
it's what people are familiar with.
> Phil Taylor wrote:
> > I'm writing some code to import Midi data into a music notation
> > program. [...] Since Midi is not a notation format, there is no
> > real indication of what accidental is appropriate. [...]
> > I'm finding it quite difficult to formulate an algorithm to deal
> > with this, and I would appreciate any comments or suggestions.
>
> Why do it algorithmically? Some sort of neural-net-like classification
> technique would surely work just as well. You could just convert all
> the ABC you've got into MIDI and back-propagate it. That's more or less
> what your guess-the-mode utility in BarFly does already.
It's not impossible, but it is difficult. Collecting the statistics
for that involved 500 tunes, each of which had to be checked for
correctness of the K: field. Except for the rarest modes I had plenty
to choose from, since all tunes are based on a scale of some kind.
Only a small proportion of abc tunes contain accidentals, and only a
small proportion of those are the awkward cases that I'm worried about.
Finding enough tunes to generate the statistics would be hard work.
Maybe I should just conclude from that that it's a rare problem, and I
should just leave it to the user to correct it by editing the result
(if it bothers them).
Phil Taylor
Not if "read" means "play", I wouldn't think so.
I think the way I'd experience it is that F is a note I'm expecting to meet
in that context, a usual note. If I see something unusual like a wild
extreme accidental, I'm going to expect it to signal something different,
like a crazy keychange (presumably to F# or thereabouts). It'd definitely
gve me a "what's going on here ?" moment. More confusing, not easier.
And consider if the F had been a repeated note, where are you going to make
the enharmonic change ? Do it to all of 'em ? Take it right back to the
beginning of the piece ? Those'd be silly. But it isn't obvious how writing
the final one of a repeated series in a different way to the others is
particularly easy to read either ?
F, F#, G, definitely.
I believe there is a rule (disregarded by some composers) that any
accidental can only be applied to change the pitch of a note by one half
step from its normal pitch in the current scale. E.g. there is no ^^G in
C-maj/a-min, but there could be in A-maj/^f-min.
This rule is actually important for computer notation programs if they
want to be able to transpose an existing score. Without it, some
transpositions will become ambiguous, others will require triple
accidentals.
>F, F#, G, definitely.
I'd agree with that. Unless there was a fairly obvious reason for
it being there, my first reaction to seeing "E# F# G" would
probably be to think that the "E#" was a typo :)
--
DG
There is one important exception to the above rules. If I have a tune in
G minor (2 flats) then I do not expect an F# to be written Gb. F# is
part of the scale of G minor.
Similarly of course in F# minor Fnat is E# and so on.
--
Bernard Hill
Braeburn Software
Author of Music Publisher system
Music Software written by musicians for musicians
http://www.braeburn.co.uk
Selkirk, Scotland
Surely transposition is easy?
You simply use the previous accidental and change it according to the
new position on the stave.
eg If you have 2 sharp keysig and write a G# then when xposed down one
semitone/half step then you go to 5 flats and the # becomes a natural.
The only time you come unstuck is when you have double flats in a sharp
key signature (which is pretty bad original notation imo) and of course
double sharps in a flat keysig.
You simply construct out a table (or make a rule) for semitone
transposition with entries of key sig and accidental
That's how Music Publisher works. And if you want more than a semitone
transposition then you simply do it many times.