Help with extension of Harmonica tablature plugin

• Nov 3, 2020 - 19:29

Hi, I'd like to ask for help with coding a coloring extension of the Harmonica plugin. I've studied the code and understand, how it assigns tablature based on pitch. I've looked also at the coloring plugin, how it assigns a color based on pitch.
But I need to assign a color based on different criteria than pitch - namely the difficulty to play a group of notes. Tablatures are written in an array/list of items, referenced by index from 0 to 37 (under Richter tuning).

I have 5 distinct groups based on decreasing difficulty.
Overdraws - items 25,32,37
Overblows - items 3,15,18,22
Blowbends - items 27,30,34,35
Drawbends - items 1,5,6,8,9,10,13,20
natural Draws and Blows - items 0,2,4,7,11,12,14,16,17,19,21,23,24,26,28,29,31,33,36

I am not familiar with coding in plugin language so I am unable to code logic for coloring specific groups.
I'd like to color both notes and the corresponding tablature.

Can anyone please help me - I'm not sure if Nicolas (creator of the plugin) is still available for its maintenance.

Also please note, that professional range of 10-hole diatonic harmonica is C4-Db7 (although very few people are capable to play the highest note as it is overdraw, so it is more like a professional professional range)

Thank you very much in advance for your help


Comments

harp.jpg
My language is Russian. I hope the translator will help us. In the image I counted 6 groups. Write a list matching group - color. And preferably a link to the plugin ... Yes, I play the harp in a diminished setting. And a little on Richter ...

Attachment Size
harp.jpg 52.32 KB

In reply to by bazhenoff

I was referring to my picture, where 5 groups are.
harmonica layout.PNG
I consider Blow + Draw as one group, because those notes play with minimal training.(days to weeks of training)
Second group is All Draw bends on holes 1,2,3,4,6. (weeks to months of training)
Third group is All Blow bends on holes 8,9,10. (months of training)
Fourth group is All Overblows on holes 1,4,5,6. (years of training)
Fifth Group is All Overdraws on holes 7,9,10. (decades...)

The plugin made choice already what tablature to use when note can be played in more than just one way.
For example G is tabbed 2draw and not 3blow. A-flat is tabbed 3drawbend-3 and not 2 overblow.

The plugin can be found here (for Musescore 3):
https://musescore.org/en/project/harmonica-tablature-harp

I made my personal changes to one variable (Richter tuning) since that is what I play.
These are the tablatures, that are displayed when the plugin is used. And the index of items from my original post refers to this variable.
var richter = ["1", "-1/", "-1", "1♯", "2", "-2//", "-2/", "-2", "-3///", "-3//", "-3/", "-3",
"4", "-4/", "-4", "4♯", "5", "-5", "5♯", "6", "-6/", "-6", "6♯", "-7",
"7", "-7♯", "-8", "8/", "8", "-9", "9/", "9", "-9♯", "-10", "10//", "10/",
"10", "-10♯" ]; //Standard Richter tuning with overbends

As for the coloring, I don't care about particular colors except no red - that is for notes out of range. And I can change the colors after, when I see the logic and list. Just please use distinct colors (no light purple and dark purple).

Thanks

Attachment Size
harmonica layout.PNG 13.29 KB

In reply to by xstatik

  1. a function must be added before or after any function

    function getColor(tabulaText) {
    var color = "#000000"

    //check what text is in the parameter "tabulaText" and set the desired color

    //color = "#990000"//red
    //color = "#009900"//green
    //color = "#000099"//blue

    return color
    }

  2. add line

text.color = getColor(text.text)
//The line above has been added. Before the next line
cursor.add(text);

In reply to by bazhenoff

if (tabulaText.indexOf("♯") = 1 {
color = "#990000"//red over BLOWS
}
if ((tabulaText.indexOf("/") = 2 ) and (tabulaText.indexOf("-") > -1)){
color = "#009900"//green bend DRAW
}
if ((tabulaText.indexOf("/") > -1 ) and not (tabulaText.indexOf("-") > -1)){
color = "#000099"//some color bend BLOW
}
if (tabulaText.indexOf("♯") > 1 ) ){
color = "#000999"//some2 color over DRAW

Will this definition work? Can I write it this way (especially the middle two)?
Can I connect them through if-then-else to stop investigating until the first condition is met? (and order them in the decreasing likelihood of happenning i.e. Blows+Draws then Drawbends then Blowbends then Overblows then Overdraws)?

In reply to by xstatik

here are the possible values of the variable "tabulaText"
var richter = ["+1", "-1b", "-1", "+1o", "+2", "-2bb", "-2b", "-2", "-3bbb", "-3bb", "-3b", "-3",
"+4", "-4b", "-4", "+4o", "+5", "-5", "+5o", "+6", "-6b", "-6", "+6o", "-7",
"+7", "-7o", "-8", "+8b", "+8", "-9", "+9b", "+9", "-9o", "-10", "+10bb", "+10b",
"+10", "-10o" ]; //Standard Richter tuning with overbends

In reply to by bazhenoff

Yes, I have modified those to my liking, mainly got rid of + sign, changed b to / and changed o to ♯
in var richter.

Also, I'm a little confused by your steps. Number 1 only creates color and only black (rest are comments no?)
Number 2 - adding the line - that does the coloring.
Where do I put the If conditions (your second post with code)?
Please see my previous post about the modification of the conditions.
I'd like to also color the corresponding note the same color as its tablature. So these should probably be another line(s) of code coloring the note parts with the specified color, no?

Thank you

In reply to by bazhenoff

I am not familiar with object-oriented programming, so I don't know, where to put the definitions/ declarations, where/ when to resolve them to values and how to make it use the values to do my stuff.

I see in the plugin, that it determines, based on the pitch of a note, which item to print from the variables (I provide, which key and which tuning and placement of the text)

So if the text value is retrieved, then I can check it with conditions to classify the proper group and apply color before printing.

  • I need to color the note itself with same color.

Then the plugin moves to the next note.

In reply to by xstatik

function getColor(tabulaText) {
//set value start
var over = "o"
var bend = "'"
var overblow = "#990000"
var blowbend = "#009900"
var overdraw = "#000099"
var drawbend = "#556677"
//set value stop

  var color = "#000000"//default black

  var exhalation = tabulaText.indexOf("+") > -1
  if(exhalation){//blow
        if (tabulaText.indexOf(over) > -1){
              color = overblow
        }
        if (tabulaText.indexOf(bend) > -1){
              color = blowbend
        }
  }
  else{//over
        if (tabulaText.indexOf(over) > -1){
              color = overdraw
        }
        if (tabulaText.indexOf(bend) > -1){
              color = drawbend
        }
  } 
  return color
}

In reply to by xstatik

delete everything! Return as it was at the beginning
1.
setColor(notes, text);
//The line above has been added. Before the next line
cursor.add(text);

2.
function setColor(notes, text) {
//set value
var overblow = "#FF0000"
var blowbend = "#00FF00"
var overdraw = "#0000FF"
var drawbend = "#FF00FF"
var over = "♯"
var bend = "/"

  var color
  var tablature = text.text
  var exhalation = tablature.indexOf("-") == -1
  if(exhalation){//blow
        if (tablature.indexOf(over) > -1){
              color = overblow
        }
        if (tablature.indexOf(bend) > -1){
              color = blowbend
        }
  }
  else{//draw
        if (tablature.indexOf(over) > -1){
              color = overdraw
        }
        if (tablature.indexOf(bend) > -1){
              color = drawbend
        }
  }
  if(typeof(color) !== "undefined"){
        text.color = color

        for (var k = 0; k < notes.length; k++) {
              var note = notes[k];
              note.color = color;
              if (note.accidental) {
                    note.accidental.color = color;
              }
              for (var i = 0; i < note.dots.length; i++) {
                    if (note.dots[i]) {
                          note.dots[i].color = color;
                    }
              }
        }
  }
}

In reply to by bazhenoff

During the day, I've tried to make some changes / renames / "learning to code". Now I have merged your new code with my attempt. please, I kindly ask you to check if this could work (especially he conditions evaluations)

From the line containing "undefined", I did not touch the code.
Question: where is now defined the default color? (I'm not saying you made an error, I just don't see it in the code, so maybe you solved it differently and I just do not have the knowledge to see the connection).
Otherwise, it looks like we are almost at the finish.

There are two places with
cursor.add(text);

One for grace notes and one for normal ones.
I add this line
setColor(notes, text);

to both places, always just before cursor.add(text); (i.e. after calling the tabNotes function, which extracts the proper tablature) - correct?

Thank you very much

function setColor(notes, text) {
//set value start
var charover = "♯"
var charbend = "/"
var chardraw = "-"
var overblowcolor = "#FF0000"
var blowbendcolor = "#00FF00"
var overdrawcolor = "#0000FF"
var drawbendcolor = "#FF00FF"
//set value stop

var color
var tablature = text.text

var tstbend = tablature.indexOf(charbend) > -1
var tstover = tablature.indexOf(charover) > -1
var tstdraw = tablature.indexOf(chardraw) > -1

if (tstbend){//bends
if (tstdraw){
color = drawbendcolor
}
else{
color = blowbendcolor
}
}
else{
if (tstover){//overs
if !(tstdraw){
color = overblowcolor
}
else{
color = overdrawcolor
}
}
}
if(typeof(color) !== "undefined"){
text.color = color

    for (var k = 0; k < notes.length; k++) {
          var note = notes[k];
          note.color = color;
          if (note.accidental) {
                note.accidental.color = color;
          }
          for (var i = 0; i < note.dots.length; i++) {
                if (note.dots[i]) {
                      note.dots[i].color = color;
                }
          }
    }

}
}

In reply to by bazhenoff

if(tstdraw){//выдох - exhalation
if(tstbend) color = blowbendcolor
if(tstover) color = overblowcolor
}
else{//вдох + inhale
if(tstbend) color = drawbendcolor
if(tstover) color = overdrawcolor
}
or so
if(tstbend) color = tstdraw ? blowbendcolor : drawbendcolor
if(tstover) color = tstdraw ? overblowcolor : overdrawcolor

the default color is gone. Since we are not assigning color to all elements. only bends and overs.

yes, you need to add a line in two places

Screenshot_20201108_234306.jpg

Attachment Size
Screenshot_20201108_234306.jpg 51.28 KB

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