I cant get beams to work automatically

220 views
Skip to first unread message

Ian

unread,
May 20, 2014, 2:20:05 PM5/20/14
to vex...@googlegroups.com
I read a previous comment on the forum about how to automatically beam groups of notes.  However, I am unable to get it to work for me. I have tried putting the comment before 'formatter variable'. But it doesn't work. Here is the code:


 var notes3 = [
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" }),
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" }),
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" }),
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" })
  ];


var beams = Beam.generateBeams(notes3);
beams.setContext(ctx).draw();

Vex.Flow.Formatter.FormatAndDraw(ctx, s3, notes3);
 t1.setContext(ctx).draw();


I would be grateful if someone could tell me what I'm doing wrong.

Cyril

unread,
May 20, 2014, 5:41:14 PM5/20/14
to vex...@googlegroups.com
.generateBeams() returns an array of beams. So you still need to iterate through them somehow. Instead of 

beams.setContext(ctx).draw();

do this:

beams.forEach(function(beam){
  beam.setContext(ctx).draw();
});

Ian

unread,
May 21, 2014, 12:23:37 AM5/21/14
to vex...@googlegroups.com
Thanks very much for your help.  I tried it out but no luck.  I don't know if I implemented the code correctly so here is the full function:

 function addBeams() {

 var notes3 = [
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" }),
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" }).
      addAccidental(0, new Vex.Flow.Accidental("n")),
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" }),
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" }),
    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "32" })
  ];


var beams = Beam.generateBeams(notes3);
beams.forEach(function(beam){
  beam.setContext(ctx).draw();
});

Vex.Flow.Formatter.FormatAndDraw(ctx, s3, notes3);
t1.setContext(ctx).draw();
}

Mohit Muthanna Cheppudira

unread,
May 21, 2014, 8:32:04 AM5/21/14
to vex...@googlegroups.com
Two things:

- Fully qualify Beam (Vex.Flow.Beam)
- Draw the beam _after_ FormatAndDraw.

Here's your corrected code: http://jsfiddle.net/fwgCG/
> --
> --
> You received this message because you are subscribed to the Google
> Groups "vexflow" group.
> To post to this group, send email to vex...@googlegroups.com
> To unsubscribe from this group, send email to
> vexflow+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/vexflow?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vexflow" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vexflow+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Mohit Muthanna [mohit (at) muthanna (uhuh) com]

Ian

unread,
May 22, 2014, 1:21:35 AM5/22/14
to vex...@googlegroups.com, mo...@muthanna.com
Thanks for your help.  I have had a look at the code.  So far it works ok on Jsfiddle but when I paste in into the rest of my code.  The stems and the beams disappear.  I will investigate it tonight.

Ian

unread,
May 23, 2014, 4:38:22 AM5/23/14
to vex...@googlegroups.com, mo...@muthanna.com
It's working now.  I forgot to change some of the variables. Thanks very much for your help.
Reply all
Reply to author
Forward
0 new messages