coloring notes with humdrum/verovio

28 views
Skip to first unread message

Malcolm Sailor

unread,
Feb 8, 2022, 11:28:17 AM2/8/22
to starstarhug
I'm wondering if it is possible with humdrum and verovio to color specific notes specific colors? (E.g., have some notes show up as green.) Or alternately/in addition, to annotate them? (I.e., have a text label show up below/above a given note.)

Thanks so much!

Craig Sapp

unread,
Feb 8, 2022, 11:43:23 AM2/8/22
to stars...@googlegroups.com
Hi Malcolm, et al.,

There are a few ways to do what you want, which are illustrated below.  These work in VHV, Humdrum Notation Plugin (https://plugin.humdrum.org), and plain verovio -- since they are implemented in the Humdrum import to verovio.   

Verovio can be run from the command-line for batch-processing of Humdrum into SVG images.  To download and compile:
       cd verovio/tools
       git checkout develop-humdrum  # (for the latest version of the Humdrum converter)
       ./.configure
       make
       make install

Then to compile a Humdrum file into notation:
       verovio file.krn
this will create file.svg containing the graphical music notation.

There are lots of options to verovio (see https://plugin.humdrum.org/options with verovio options colored purple).  Or type "verovio" as a command without arguments to the the list on the command line.   Useful ones for short examples:

--adjust-page-height   == make the SVG the height of the music, not of the page height (i.e., shrink the page to the height of the music.

--adjust-page-width     == the same for the width of the music.

--page-height  # == set the height of the page, # is roughly 1/10 mm, default 2970

--page-width # == set the width of the page, default for # is 2100

--scale (or -s) == set the scale of the music (meaning the size)  Units are percentages where I typically use 40, and default is 100.

-o filename  == output to a different filename than automatically given.  Using "-o -" will output to standard output.

example of using some of the commands (which can go before or after the filename):

verovio file.krn --adjust-page-height --scale 55 -o image.svg

Here are the three main ways of coloring notes:

(1) Marking individual notes with color:

Screen Shot 2022-02-08 at 7.08.06 AM.png

There are a limited number of user-signifiers (characters that do not have predefined meanings in Humdrum. Some others are |, +, i, j.

(2) Color interpretation: useful to set color of all notes to one specific color afterwards:

Screen Shot 2022-02-08 at 7.12.59 AM.png

(3) Color spine: An independent spine for color can be used to color all **kern spines to its left.  This is useful for harmonic colorings:

Screen Shot 2022-02-08 at 7.18.03 AM.png
(you can have multiple **color lines, and each one will apply to all **kern spines

There are also more advanced ways of colorings notes that you are probably not interested in (they are outside of verovio and more for post-processing of the SVG image on a webpage):

Screen Shot 2022-02-08 at 8.41.36 AM.png



For text labels, there are three possibilities:

(1) A staff or system label (staff labels have a single !, and system have two !!)   They can be attached to notes by immediately preceding the note (or rest), as well as time signatures by coming just before a time signature:
Screen Shot 2022-02-08 at 7.41.01 AM.png

(2) as lyrics:

Screen Shot 2022-02-08 at 7.42.24 AM.png

(2b) as "verse-like data" which is not much different (just officially marked as not being real lyrics):

Screen Shot 2022-02-08 at 7.43.59 AM.png

Text can  only be applied to note attacks (not rests).


(3) as chord-like data:

Screen Shot 2022-02-08 at 7.47.00 AM.png

cdata can occur independent of note attacks (the **recip spine allows placing at second 8th of quarter note in above example).  cdata can currently only be placed above the staff, I believe.


-=+Craig




On Tue, 8 Feb 2022 at 06:58, Malcolm Sailor <malcolm...@gmail.com> wrote:
PS I realize I wrote "vhv" which I believe refers to your online humdrum viewer? That is not necessarily important. What I'd really like to be able to do is produce annotated musical examples from a shell script.
===
Malcolm Sailor
www.malcolmsailor.com


On Tue, Feb 8, 2022 at 9:54 AM Malcolm Sailor <malcolm...@gmail.com> wrote:
Hi Craig

Hope you are well. 

I had the following question and I was wondering if you could help me:

Is it possible with humdrum and vhv to color specific notes specific colors? (E.g., have some notes show up as green.) Or alternately/in addition, to annotate them? (I.e., have a text label show up below/above a given note.)

Many thanks!

Malcolm

===
Malcolm Sailor
www.malcolmsailor.com

Malcolm Sailor

unread,
Sep 28, 2023, 10:46:49 AM9/28/23
to stars...@googlegroups.com

Dear Craig,

A follow-up question:

If we are using system or staff labels, like `!!LO:TX:b:i:t=below\nsystem:color=limegreen`, is there any way to apply different colors to different segments of the text? E.g., in this case, set "below" in one color and "system" in another?

Thanks,

Malcolm

--
--
This is a message is from the **HUG newgroup.
To post to this group, send email to stars...@googlegroups.com
To unsubscribe from this group, send email to
starstarhug...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/starstarhug?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "starstarhug" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/starstarhug/shZlpJ5i25M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to starstarhug...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/starstarhug/CAPcjuFdvV%3DkWi2MjYSF89FwJG%3Dm4Rpuqjt9nuAwX5KUXFhMVOQ%40mail.gmail.com.

Craig Sapp

unread,
Sep 28, 2023, 11:42:39 AM9/28/23
to stars...@googlegroups.com
Hi Malcolm,

A finer-grained system to have multiple colors in a block of text is possible, but I haven't implemented it.

In this particular case, however, the text can be broken up into two pieces:

Screenshot 2023-09-28 at 08.23.38.png


In addition, if you want to display system-level data underneath the system, it is possible by adding spines of data at the start of the text lines lines:

Screenshot 2023-09-28 at 08.32.37.png


(*italic is not implemented, but should be easy to do)


Malcolm Sailor

unread,
Oct 19, 2023, 1:12:38 PM10/19/23
to stars...@googlegroups.com
Hi Craigg,
 
There are a limited number of user-signifiers (characters that do not have predefined meanings in Humdrum. Some others are |, +, i, j.

Is there anywhere I can get a complete list of user-signifiers? If I run out, is it possible to use bigrams of characters or anything like that?

Thanks!

Malcolm

Wolfgang Drescher

unread,
Oct 19, 2023, 3:26:19 PM10/19/23
to starstarhug
Hi Malcolm,

There are a limited number of user-signifiers (characters that do not have predefined meanings in Humdrum. Some others are |, +, i, j.

Is there anywhere I can get a complete list of user-signifiers? If I run out, is it possible to use bigrams of characters or anything like that?

I use the characters N, V, Z, @, +, |, <, > that I found on https://extras.humdrum.org/man/cint/ (Module note marking). I usually reserve lowercase letters for things like editorial accidentals or similar.

I also tried using emojis (or any other unicode character) instead to not conflict with other existing reserved characters. But I've had some problems with that, so for now I'm just using the above characters.

Best,
Wolfgang
 

Craig Sapp

unread,
Oct 19, 2023, 11:31:05 PM10/19/23
to stars...@googlegroups.com
Hi Malcolmm,

Section 3.7 on this page also has a list of the **kern user signifiers:
https://www.humdrum.org/Humdrum/representations/kern.html#Table%20of%20Signifiers

i  j  l  N  V  Z  @  +  |  <  >


In my software, bigrams have not been allowed due to the complexity of applying meaning to the signifiers (if i, j, and ij are three different signifiers, then ij, and i+j are problematic to separate).   But in theory they should be allowed (and also you can use bigrams for your own purposes/software already), so I will work on that for RDF markers used in verovio/MEI conversions.  I do use duplications of a specific signifer to have slightly different meanings such as doubling the terminal long signifier to make the note look like a maxima:

Screenshot 2023-10-19 at 10.44.56.png


In theory all UTF-8 characters which are not also UTF-7 (lower half of ASCII bytes) are also user signifiers.  They were not really allowed until today:
UTF-8 as Wolfgang mentions is a good solution for nearly unlimited user signifiers.

I assume that Humdrum data is in the UTF-8 format, so any UTF-8 character other than the UTF-7 (lower half of ASCII) is a user signifier in **kern.   Here is an example of coloring notes by pitch class using RDF markers:

Screenshot 2023-10-19 at 20.20.59.png


Using UTF-8 characters works well on MacOS since the operating system uses UTF-8 natively.  Windows and Linux do not, so there may be some unwanted character translations depending on editing or data processing software.   I don't have problems editing UTF-8 files in Linux and MacOS using vi.   Also UTF-8 is the default character set for HTML, so should also work well on the web.

-=+Craig

Malcolm Sailor

unread,
Oct 20, 2023, 8:36:37 AM10/20/23
to stars...@googlegroups.com
In theory all UTF-8 characters which are not also UTF-7 (lower half of ASCII bytes) are also user signifiers.  They were not really allowed until today:
UTF-8 as Wolfgang mentions is a good solution for nearly unlimited user signifiers.

Wow, thanks, that's great!

Malcolm

Malcolm Sailor

unread,
Oct 20, 2023, 10:49:45 AM10/20/23
to stars...@googlegroups.com
A follow up:

I've tried using UTF-8 characters as user signifiers but unfortunately, these characters seem to get removed (and sometimes replaced with newlines) by humdrum-tools that are an important part of my workflow. For example, when I put the following in a file:

```
**kern
=
4A€
4F#…
*-
```
(The tokens have characters 128 and 133 respectively at the ends. 133 is non-printing for me in gmail.)

And then run `timebase -t 8 file.krn`, I get the following output:
```
**kern
*tb8
=
4A
.
4F#

.
*-
```

Any way of allowing non-ASCII characters with humdrum-tools?

Thanks!

Malcolm

Craig Sapp

unread,
Oct 20, 2023, 6:46:23 PM10/20/23
to stars...@googlegroups.com
Hi Malcolm,

When I use timebase in MacOS terminal, I am not having any problems with UTF-8 characters:

Screenshot 2023-10-20 at 15.34.02.png


Presumably you are doing this in Windows (with Cygwin?)?   Or otherwise you can say what OS and environment you are using.  

If you are trying to display the contents of the file in a non UTF-8 terminal or software, then it is unlikely that the file will display correctly unless there is an automatic detection and conversion of UTF-8 into whatever font system is being used.   So it is not necessarily that timebase is not able to handle UTF-8, but rather the display cannot handle UTF-8.   Timebase in theory should not have any problems with UTF-8 characters.  If you do certain regular expressions, UTF-8 may have problems because UTF-8 characters can have up to 5 bytes for one character, so "." in regular expressions in non-UTF-8 systems will match to one byte and not to one UTF-8 "character".   Timebase does not need to deal with such. characters, and should be echoed in the output without alteration.

One way to test is to output the results to a *.txt file and then open the file:

timebase -t 8 file.krn > file.txt

And then open file.txt in a web browser to examine its contents.


-=+Craig

Malcolm Sailor

unread,
Oct 20, 2023, 10:53:45 PM10/20/23
to stars...@googlegroups.com
Thanks for your help, Craig. I am also using a UTF-8 terminal in MacOS.

The problem turns out to be that the characters I was using are non-printing (and one of them is interpreted as a line break). (I was just generating them programmatically starting from character code 128.) But for some reason that I don't understand they *were* printing in my code editor (VS Code). Since I could see them there, I was expecting them to print in the terminal.

Malcolm

===
Malcolm Sailor
www.malcolmsailor.com

--
--
This is a message is from the **HUG newgroup.
To post to this group, send email to stars...@googlegroups.com
To unsubscribe from this group, send email to
starstarhug...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/starstarhug?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "starstarhug" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/starstarhug/shZlpJ5i25M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to starstarhug...@googlegroups.com.

Craig Sapp

unread,
Oct 21, 2023, 3:02:00 AM10/21/23
to stars...@googlegroups.com
Hi Malcolm,

If you use 128 (hex 80) as a single character, note that that is not UTF-8 (what you are probably thinking of is called a Unicode character).   To get Unicode character 0x80 (decimal 128), you need to use the two bytes 0xC2 and 0x80, since UTF-8 is a variable byte length character encoding system for Unicode.

Here is a chart that shows how the bits are stored for the Unicode character in UTF-8 from the wikipedia entry for UTF-8:
Screenshot 2023-10-20 at 23.24.36.png

For bytes 0 to 127 (UTF-7), there is a single byte (first line in the table).  Starting with 128 (0x80) Two bytes are needed, with the first byte starting with the bits 110 then the top 5 bits of the actual number, then the second byte starting with the bits 10, and then the last 6 bits of the number.   For example, 128 are the bits:
      10000000
Splitting that into 6 at the bottom and 5 top bits (adding leading zeros):
       00010     000000
and adding the required packing bits:
       1100010 10000000
converting to hex:
       C2  80
So hex bytes "C2 80" is UTF-8 for Unicode character 128.  (which is a padding character that you should probably avoid).

Probably starting with the emoji character range you will have a longer sequence of printable characters.  Here is a list starting with Unicode character number 128512 (hex 1F600, which is UTF-8 hex bytes F0 9F 90 80):

EmojiUNICODE ValueUTF-8 Hex Byte Codes
😀 Grinning FaceU+1F600F0 9F 98 80
😁 Beaming Face with Smiling EyesU+1F601F0 9F 98 81
😂 Face with Tears of JoyU+1F602F0 9F 98 82
😃 Grinning Face with Big EyesU+1F603F0 9F 98 83
😄 Grinning Face with Smiling EyesU+1F604F0 9F 98 84
😅 Grinning Face with SweatU+1F605F0 9F 98 85
😆 Grinning Squinting FaceU+1F606F0 9F 98 86
😇 Smiling Face with HaloU+1F607F0 9F 98 87
😈 Smiling Face with HornsU+1F608F0 9F 98 88
😉 Winking FaceU+1F609F0 9F 98 89
😊 Smiling Face with Smiling EyesU+1F60AF0 9F 98 8A
😋 Face Savoring FoodU+1F60BF0 9F 98 8B
😌 Relieved FaceU+1F60CF0 9F 98 8C
😍 Heart EyesU+1F60DF0 9F 98 8D
😎 Smiling Face with SunglassesU+1F60EF0 9F 98 8E
😏 Smirking FaceU+1F60FF0 9F 98 8F
😐 Neutral FaceU+1F610F0 9F 98 90
😑 Expressionless FaceU+1F611F0 9F 98 91
😒 Unamused FaceU+1F612F0 9F 98 92
😓 Face with Cold SweatU+1F613F0 9F 98 93
😔 Pensive FaceU+1F614F0 9F 98 94
😕 Confused FaceU+1F615F0 9F 98 95
😖 Confounded FaceU+1F616F0 9F 98 96
😗 Kissing FaceU+1F617F0 9F 98 97
😘 Face Blowing a KissU+1F618F0 9F 98 98
😙 Kissing Face with Smiling EyesU+1F619F0 9F 98 99
😚 Kissing Face with Closed EyesU+1F61AF0 9F 98 9A
😛 Face with TongueU+1F61BF0 9F 98 9B
😜 Winking Face with TongueU+1F61CF0 9F 98 9C
😝 Squinting Face with TongueU+1F61DF0 9F 98 9D
😞 Disappointed FaceU+1F61EF0 9F 98 9E
😟 Worried FaceU+1F61FF0 9F 98 9F
😠 Angry FaceU+1F620F0 9F 98 A0
😡 Pouting FaceU+1F621F0 9F 98 A1
😢 Crying FaceU+1F622F0 9F 98 A2
😣 Persevering FaceU+1F623F0 9F 98 A3
😤 Face with Steam From NoseU+1F624F0 9F 98 A4
😥 Sad but Relieved FaceU+1F625F0 9F 98 A5
😦 Frowning Face with Open MouthU+1F626F0 9F 98 A6
😧 Anguished FaceU+1F627F0 9F 98 A7
😨 Fearful FaceU+1F628F0 9F 98 A8
😩 Weary FaceU+1F629F0 9F 98 A9
😪 Sleeping FaceU+1F62AF0 9F 98 AA
😫 Tired FaceU+1F62BF0 9F 98 8B
😬 Grimacing FaceU+1F62CF0 9F 98 AC
😭 Loudly Crying FaceU+1F62DF0 9F 98 A5
😮 Face with Open MouthU+1F62EF0 9F 98 AE
😯 Hushed FaceU+1F62FF0 9F 98 AF
😰 Anxious Face with SweatU+1F630F0 9F 98 B0
😱 Face Screaming in FearU+1F631F0 9F 98 B1
😲 Astonished FaceU+1F632F0 9F 98 B2
😳 Flushed FaceU+1F633F0 9F 98 B3
😴 Sleeping FaceU+1F634F0 9F 98 B4
😵 Dizzy FaceU+1F635F0 9F 98 B5
😶 Face Without MouthU+1F636F0 9F 98 B6
😷 Face with Medical MaskU+1F637F0 9F 98 B7
😸 Grinning Cat with Smiling EyesU+1F638F0 9F 98 B8
😹 Cat with Tears of JoyU+1F639F0 9F 98 B9
😺 Smiling Cat with Open MouthU+1F63AF0 9F 98 BA
😻 Smiling Cat with Heart-EyesU+1F63BF0 9F 98 BB
😼 Cat with Wry SmileU+1F63CF0 9F 98 BC
😽 Kissing CatU+1F63DF0 9F 98 BD
😾 Pouting CatU+1F63EF0 9F 98 BE
😿 Crying CatU+1F63FF0 9F 98 BF
🙀 Weary CatU+1F640F0 9F 99 80
🙁 Slightly Frowning FaceU+1F641F0 9F 99 81
🙃 Upside-Down FaceU+1F642F0 9F 99 83
🙄 Face with Rolling EyesU+1F643F0 9F 99 84
🤐 Zipper-Mouth FaceU+1F644F0 9F A4 90
🤑 Money-Mouth FaceU+1F645F0 9F A4 91
🤒 Face with ThermometerU+1F646F0 9F A4 92
🤓 Nerd FaceU+1F647F0 9F A4 93
🤔 Thinking FaceU+1F648F0 9F A4 94
🤕 Face with Head-BandageU+1F649F0 9F A4 95
🤖 Robot FaceU+1F64AF0 9F A4 96
🤗 Hugging FaceU+1F64BF0 9F A4 97
🤘 Sign of the HornsU+1F64CF0 9F A4 98
🤙 Call Me HandU+1F64DF0 9F A4 99


-=+Craig



Malcolm Sailor

unread,
Oct 21, 2023, 9:11:28 AM10/21/23
to stars...@googlegroups.com
Hi Craig,

Thanks for the encoding details. I was using Python's `chr()` function to get from a code point to a character, which gives a unicode string (which is encoded to UTF-8 by default when writing to a file). E.g.,

```
>>> chr(128).encode()  # utf-8 by default
b'\xc2\x80'
```

So the issue wasn't that the code points weren't being encoded correctly but rather that they were appearing inconsistently between my terminal and my code editor. I agree that it's clearly better to use printing characters like the emojis you give.

Thanks again!

Malcolm

===
Malcolm Sailor
www.malcolmsailor.com

--
--
This is a message is from the **HUG newgroup.
To post to this group, send email to stars...@googlegroups.com
To unsubscribe from this group, send email to
starstarhug...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/starstarhug?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "starstarhug" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/starstarhug/shZlpJ5i25M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to starstarhug...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages