[abc4j] How to enrich the score rendition

74 views
Skip to first unread message

Lionel Gueganton

unread,
Apr 25, 2010, 1:08:56 PM4/25/10
to abc4j
Hi Eliot,
I'm answering you on the group : so this answered is indexed and can
also be reused by newcomers.

I would like to be able to draw in the window myself, eg, I would like
to annotate the notes. In the picture in
the link above, eg, I would like to write the names of the required
strings to the right of the note heads.
Is there a simple way of getting the list of bounding rects for each
note, togther with the name of the note? If I want to color individual
notes?
Hints would be much appreciated. I guess this is iubito's area.

>>>>
iubito made a lot of improvements but the global design stayed the
same.
The score rendition main entry point is the
abc.ui.swing.JScoreComponent
you "feed" this object with the Tune you want to get rendered.

A "Tune" is composed of MusicElement that can be retrieved from
getMusic() on the Tune instance.

For each MusicElement you can get access to its graphical
representation using
JScoreElement getRenditionElementFor(MusicElement elmnt)

this method gives the match between the pure music element and its
graphical representation.

On a JScoreElement then, you can ask for the bounding box :
getBoundingBox()

You can have a look at the whole javadoc here :
http://abc4j.googlecode.com/svn/trunk/docs/api/index.html


Hope this helps,
Cheers
Lionel.

--
You received this message because you are subscribed to the Google Groups "abc4j" group.
To post to this group, send email to ab...@googlegroups.com.
To unsubscribe from this group, send email to abc4j+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/abc4j?hl=en.

eliot

unread,
Apr 28, 2010, 11:21:36 AM4/28/10
to abc4j

Hi Lionel,

thanks for the hints.

I still have a problem: I need to add some space to the right of the
image in order to draw my stuff. I've tried this by specializing
JScoreComponent, specializing paint(), adjusting the clip region and
adding my stuff. But this does not seem to be the right way -- the
results are messed up until I manually resize the window. What is the
right way to add extra space to the image?

should I be using Spacers, and if so how? I will probably be wanting
to control
the spacing of notes + chords at any rate.

best wishes and thanks,

-- eliot

iubito

unread,
Apr 29, 2010, 3:09:08 AM4/29/10
to abc4j
Hi Elliot

various note color, e.g. depending on the height, could be done as
Lionel explained, even if I haven't tested it yet. I'll give a try.

--for the following tips, you must have the SVN version, not yet
packaged--
*** colors ***
if you want to color all notes the same color, all clef the same
color... : you can do it in template
myScoreComponent.getTemplate().setElementColor(...)
example : http://abc4j.googlegroups.com/web/Colors.png

*** notes spacing ***
myScoreComponent.getTemplate().setAttributeSize(ScoreAttribute.NOTE_SPACING,
1.5f);
by default it's expressed in note width, then 1.5 * note width
you can increase/decrease this value

*** margins ***
myScoreComponent.getTemplate().setAttributeSize(ScoreAttribute.MARGIN_RIGHT,
35f);
expressed in pixels, also MARGIN_LEFT/TOP/BOTTOM...

as all other sizes, you can express them in note width, note height,
pixel, staff char width (SizeUnit constants)
if you drawing / text should be resized when notation font size is
changed, express what you need in variable size (note width, height,
staff char width).
if it's fixed size, express in pixels

The abc.ui.swing.JSpacer is an empty symbol (a spacer!) between notes,
it's on the score, not for the margins

Enjoy !

eliot

unread,
Apr 29, 2010, 11:31:50 AM4/29/10
to abc4j


On Apr 29, 3:09 am, iubito <iub...@gmail.com> wrote:
> Hi Elliot

> The abc.ui.swing.JSpacer is an empty symbol (a spacer!) between notes,
> it's on the score, not for the margins
>

Hi iubito,

thanks fir the tips, and for your work on this. Could you give an
example of
how to use JSpacer to add space between just 2 notes?

Also, a small problem with chords --- the ma7 when written as
diminished 8ve
is not correctly aligned eg [^Cc] comes out slanted. JIntervals does
not seem to be checking for this interval.
It looks like a minor fix?

best wishes and thanks again,
-- eliot

iubito

unread,
Apr 29, 2010, 5:12:49 PM4/29/10
to abc4j
I have no example of JSpacer, but in the ABC, using AbcVersion.v2_0 in
parser, the "y" is transformed as a space

CD EF y GA Bc will add an extra space between F and G

to use the v2.0
Tune myTune = new TuneParser(AbcVersion.v2_0).parse(tuneString);
myScoreComponent.setTune(myTune);

and for the interval, I'll check this, seems to be a problem in
abc.notation.Interval class which can't compute them... don't know if
it's minor or big headache, but I'll look at it!!

--iub'

iubito

unread,
May 1, 2010, 10:25:19 AM5/1/10
to abc4j
Hi
Problem solved, I hope definitively :)
not yet in SVN

--iub'

On 29 avr, 17:31, eliot <el...@colba.net> wrote:
> Also, a small problem with chords --- the ma7 when written as
> diminished 8ve
> is not correctly aligned eg [^Cc] comes out slanted. JIntervals does
> not seem to be checking for this interval.
> It looks like a minor fix?

eliot

unread,
May 2, 2010, 10:34:24 AM5/2/10
to abc4j


On May 1, 10:25 am, iubito <iub...@gmail.com> wrote:
> Hi
> Problem solved, I hope definitively :)
> not yet in SVN

Hi iubito,

thanks for the great work. I'm beginning to get abc4j to do exactly
what I need.

There's one more chord glitch, in the way unisons are written when
they have accidentals.

eg: [_B_B] [=B_B] [_B=B]

These should be written:

bobo (where "b" is the flat, o is the notehead)
nobo (where "n" is the natural sign)
bono

Instead, they come out:

bboo --- bad, because this looks like a double flat
bnoo -- bad, because the order of accidentals is wrong
bono -- also wrong, because looks like a double flat cancellation.

On unisons, double stems are usually called for, but this is a less
important matter.

Is this terribly complex to fix?

best,

-- eliot

iubito

unread,
May 4, 2010, 9:38:04 AM5/4/10
to abc4j
Hi elliot
it's more complex to fix

for double stems, it's when you write 2 voices as if they were on two
staves, and then merge the staves

the easiest thing I can fix is [_B_B] bboo => boo

To be frank, I've never seen [=B_B] or [_B=B] in scores.

Eliot Handelman

unread,
May 4, 2010, 10:09:50 AM5/4/10
to ab...@googlegroups.com
iubito wrote:
> Hi elliot
> it's more complex to fix
>
> for double stems, it's when you write 2 voices as if they were on two
> staves, and then merge the staves
>
>
ok, thanks.
> the easiest thing I can fix is [_B_B] bboo => boo
That would be helpful.

> To be frank, I've never seen [=B_B] or [_B=B] in scores.
>
>
It's not that uncommon in 20th C.music -- eg Charles Ives, Concord sonata.

best wishes,

Eduardo Lealdini Ramalho

unread,
Jun 4, 2010, 3:36:52 PM6/4/10
to abc4j
Hi Eliot,
You could send the code snippet that sets different colors for the
notes?

Tks

Eduardo

iubito

unread,
Jun 13, 2010, 6:11:44 AM6/13/10
to abc4j
Hi Eduardo

I've worked on this, and some fixes... I need tests again before
validate in the SVN in a few hours.
The code will look like :
JScoreComponent scoreUI = new JScoreComponent();
scoreUI.setTune(myTune);

//color all A in orange (I didn't check if it's a MultiNote so then
search for a A in the "chord" MultiNote)
Music music = m_tune.getMusicForGraphicalRendition();
Iterator itMusic = music.iterator();
while (itMusic.hasNext()) {
MusicElement me = (MusicElement) itMusic.next();
if (me instanceof Note) {
if (((Note) me).getStrictHeight() == Note.A) {
JScoreElement myNote = scoreUI.getRenditionElementFor(me);
if (myNote != null)
myNote.setColor(Color.ORANGE);
}
}
}

On a click event, you can color the note pointed by the mouse cursor :
JScoreElement elmt =
scoreUI.getScoreElementAt(scoreUI.getMousePosition());
if (elmt != null)
elmt.setColor(Color.ORANGE);

Sylvain

On 4 juin, 21:36, Eduardo Lealdini Ramalho <eduardo...@gmail.com>
wrote:

Eduardo Lealdini Ramalho

unread,
Jun 14, 2010, 9:28:26 AM6/14/10
to abc4j
Sylvain

Thanks for the feedback!
Also wanted to thank your tip of the click of the mouse, very helpful.

Thanks


On 13 jun, 07:11, iubito <iub...@gmail.com> wrote:
> Hi Eduardo
>
> I've worked on this, and some fixes... I need tests again before
> validate in the SVN in a few hours.
> The code will look like :
> JScoreComponent scoreUI = new JScoreComponent();
> scoreUI.setTune(myTune);
>
> //colorall A in orange (I didn't check if it's a MultiNote so then
> search for a A in the "chord" MultiNote)
> Music music = m_tune.getMusicForGraphicalRendition();
> Iterator itMusic = music.iterator();
> while (itMusic.hasNext()) {
>         MusicElement me = (MusicElement) itMusic.next();
>         if (me instanceof Note) {
>                 if (((Note) me).getStrictHeight() == Note.A) {
>                         JScoreElement myNote = scoreUI.getRenditionElementFor(me);
>                         if (myNote != null)
>                                 myNote.setColor(Color.ORANGE);
>                 }
>         }
>
> }
>
> On a click event, you cancolorthe note pointed by the mouse cursor :
Reply all
Reply to author
Forward
0 new messages