Cannot write to voices 2, 3, or 4

• May 21, 2021 - 08:51

Cannot create a drum groove with the base drum in a separate voice so as to appear with stem down. Changing the cursor voice to anything but 0 (i.e. voice 1) . Here is the code snippet:

eTempo = newElement(Element.TEMPO_TEXT);
eTempo.text = '\uECA5' + ' = ' + Math.round(60);
eTempo.visible = visible;
eCursor.add(eTempo);

eLineBreak = newElement (Element.LAYOUT_BREAK);
eLineBreak.layoutBreakType = LayoutBreak.LINE;

eCursor.setDuration(1,16);
for (lj=1;lj<3;lj++)
{
if (lj % 2 == 0)
{
eLineBreak.eScore = curScore;
eCursor.add (eLineBreak.clone ());
}

for (li=1;li&lt;17;li++)
{
 // voice 1 (=0) - upward stem
 eCursor.voice = 0;

 // HH stroke
 var lelNote = eCursor.addNote(42);

 if (li == 5 || li == 13) {lelNote = eCursor.addNote(38, true);}    // Snare

 // voice 2 (=1) for BD  !!!!!!!!!!!!!!!!!!!!
 eCursor.voice = 1;
 if (li == 1 || li == 3 || li == 9) 
 {
  lelNote = eCursor.addNote(35, true);      // BD 1
  // lelNote = eCursor.addNote(36, true);   // BD 2 - also doesn't work
 }
}

}

Attachment Size
DrumPluginEx.png 16.34 KB

Comments

onRun: {
    var eCursor = curScore.newCursor();
    // top voice
    eCursor.setDuration(1,16);
    eCursor.rewind(0);
    eCursor.track = 0;
    for (var li=1; li<17; li++){
        eCursor.addNote(42);
        if (li == 5 || li == 13) {
            eCursor.addNote(38, true);
        }
    }
 
    // bottom voice
    eCursor.setDuration(1,8);
    eCursor.rewind(0);
    eCursor.track = 1;
    for (var li = 1; li < 9; li++) {
        if (li == 1 || li == 2 || li == 5) {
            eCursor.addNote(35);
        }
        else {
            eCursor.addRest();
        }
    }
}

In reply to by avronp

Or of you want to use only one loop, you can do this

for (var li=1; li<17; li++){
        eCursor.addNote(42);
        if (li == 5 || li == 13) {
            eCursor.addNote(38, true);
        }
 
        eCursor.prev();
        eCursor.track = 1;
        if (li == 1 || li == 3 || li == 9)
            eCursor.addNote(35);
        else
            eCursor.addRest();
        eCursor.track = 0;
    }

Do you still have an unanswered question? Please log in first to post your question.