Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatically created **fb spine #53

Merged
merged 113 commits into from
Jan 21, 2023

Conversation

WolfgangDrescher
Copy link
Contributor

@WolfgangDrescher WolfgangDrescher commented Nov 27, 2022

See humdrum-tools/verovio-humdrum-viewer#658.

This PR adds a basic implementation for a figured bass filter to automatically add **fb spines to the kern score. Ideally this filter should be implemented into Verovio to allow dynamic score manipulation with this filter in the browser.

These are my first lines of code in C++, so any feedback or code review is welcome. And please excuse me if I didn't follow conventions of the programming language. I had a more generic solution but I couldn't compile it because I have no knowledge of pointers and references.

I always compile the whole lib with make, this takes some time. Is there a way to compile only tool-figuredbass.cpp and then run the binary (bin/figuredbass)?

Todos:

  • Add an option/flag to bind the base not to one voice but to the lowest pitch
  • Add option to only calculate intervals or figured bass on certain beats (e.g. quarter notes in 4/4, oder 1st and 4th eighth note in 6/8)
  • Add option to sort the figured bass numbers so bigger intervals are printed before and displayed on top
  • Add option to display only relevant numbers for a normal figured bass style notation (6 5 3 => 6 5, 6 4 3 => 4 3, etc.)
  • Add option to display interval numbers directly under the corresponding staff
  • Improve accidentals support
  • Fix appendDataSpine (segmentation fault)
  • Fix missing accidentals for abbreviated figures
  • Add option to hide intervals in "Intervallsatz" when they are not struck again and the base is not changing
  • Finalize figuredBassAbbrs mappings
  • Support for chords
  • Code formatting
  • Negative intervals
  • Handle rests and silent notes
  • Improve handling for 2 and 9
  • Fix number alterations when an accidental is in the bass/base
  • Support for spine splits
  • Select spines and/or kern spines with -s and -k

Questions:

  • What should the name of this new command ideally be? I saw that fb is already existing.
  • Would it be possible to display negative intervals? Currently - is reserved for flats in **fb spines.
  • Should there be a difference between 1 and 8 for compound intervals?
  • Is there a reference to the rhythmical timing available in NoteGrid? I found getNoteDuration but we would also need the position of the note relative to the time signature.
  • Is there anything I need to consider if I want to have this filter available in Verovio?
  • Is it possible to display the numbers under the lyrics in VHV? Can we add this option to this filter?

@WolfgangDrescher
Copy link
Contributor Author

Missing 7 when running bin/figuredbass -i -a -c.

Bildschirm­foto 2022-11-29 um 01 57 05

!!!COM: Bach, Johann Sebastian
!!!OTL: Sinfonia 11
!!!ONM: 11
!!!SCT: BWV 797
**kern	**kern	**kern
*staff3	*staff2	*staff1
*clefF4	*clefG2	*clefG2
*k[b-e-]	*k[b-e-]	*k[b-e-]
*g	*g	*g
*M3/8	*M3/8	*M3/8
=1	=1	=1
4G	4.r	16r
.	.	16ddL
.	.	16b-
.	.	16g
8E-	.	8ggJ
=2	=2	=2
4D	16r	4.ff
.	16aL	.
.	16f	.
.	16d	.
8B-	[8ddJ	.
=3	=3	=3
4G	8.dd]L	4.ee-
.	16b-	.
8A	[8ccJ	.
=4	=4	=4
16B-L	8.cc]L	4.dd
16d	.	.
16B-	.	.
16G	16a	.
[8gJ	8b-J	.
=5	=5	=5
8.g]L	4.a	4cc
16e	.	.
8f#J	.	8dd
=6	=6	=6
4g	16aL	8.b-L
.	16f#J	.
.	[4g	.
.	.	16b-
8c	.	8ee-J
=7	=7	=7
4d	4g]	8.aL
.	.	16b-
8D	8f#	8ccJ
=8	=8	=8
16GL	4.g	4.b-
16D	.	.
16BB-	.	.
16GG	.	.
8GJ	.	.
*-	*-	*-

@WolfgangDrescher
Copy link
Contributor Author

Same here. Missing 7 when running bin/figuredbass -a -c.
Bildschirm­foto 2022-11-29 um 02 02 00

@WolfgangDrescher
Copy link
Contributor Author

Fixed missing 7 with eef094d.

@WolfgangDrescher
Copy link
Contributor Author

An idea how to implement the feature to show only figures on certain beats would be something like the following. This is currently still far from perfect and e.g. completely ignores upbeats.

// tool-figuredbass.cpp line 95
for (int i=0; i<(int)grid.getSliceCount(); i++) {
	int usedBaseVoiceIndex = baseQ;
	NoteCell* baseCell = grid.cell(usedBaseVoiceIndex, i);
	if(tpqQ != 0) {
		int tpq = infile.tpq();
		int starttime = baseCell->getToken()->getDurationFromStart(tpq).getInteger();
		if(fmod(starttime, tpq / tpqQ) != 0) {
			continue;
		}
	}
	// ...
}

@WolfgangDrescher WolfgangDrescher marked this pull request as ready for review November 29, 2022 19:10
@WolfgangDrescher WolfgangDrescher marked this pull request as draft November 29, 2022 19:13
@WolfgangDrescher
Copy link
Contributor Author

I cannot get this running in the JS toolkit. Is there something I am missing? From my side this is ready to merge now. Everything else I can contribute in new PRs.

I observed some problems with the numbers in some of the demo data available in VHV but I will open new issues for these and fix them in individual pull requests as this thread is getting long…

@WolfgangDrescher WolfgangDrescher marked this pull request as ready for review January 16, 2023 09:28
@WolfgangDrescher
Copy link
Contributor Author

Do you have any idea how to debug the fb filter in Verovio? I did set log level to LOG_DEBUG but there was nothing logged in the JavaScript console. I observed that when I try to render a score that was dynamically modified with an added line !!!filter: fb for everything after this verovio somewhat crashed and will not run renderToSVG anymore (no exception thrown). So at least it is doing somthing.…

Could tool-figuredbass.o in the Makefile be relevant for this?

@craigsapp
Copy link
Owner

For the problem of not running in Javascript, I am thinking that you need to register the tool for use as a filter in the src/tool-filter.cpp file.

Could tool-figuredbass.o in the Makefile be relevant for this?

I don't find tool-figuredbass.o in my directories. That is probably the old name for the class file before you changed it to tool-fb.cpp? In any case it should not cause a problem, since the list of *.cpp files are used to generate the list of object files (so if there is no src/tool-figuredbass.cpp file, then it will not be included in the final code library).

To be certain, you can run:
make clean
or
rm -f obj/*.o

to remove all compiled files, and then re-run make to recompile all of the existing files in src.


But if you mean it crashes in Javascript but not on the command line, here is some discussion about that (how I debug):

I don't know how to debug verovio in a web browser. There are debugging tools for javascript in browsers, but I don't think they work very well on WASM-compiled C++ code since the Javascript code is basically like assembly code and not human readable (but I have not tried to use them because I suspect they will not be useful).

You can compile it into the command-line version of verovio, and run test input through that version which will be a little more easy. There is a debugging system in XCode (but I only use command-line compiling, so I have never used it).

If you run it on the command line and the program generates a segmentation fault, then there should be a diagnostic file in ~/Library/Logs/DiagnosticReports which starts with the string "verovio" and then date that it crashed. There is a stack trace list in that file which shows all of the function calls that were open when the crash happened (newer MacOS diagnostic files make it more difficult to find that information, so opening it up from the command line such as open verovio-2022-etc.extension will open it up in a more user friendly way to see the last function it was running before crashing.

I am suspecting that your code is trying to access an array element that it should not. If you use vector::at(), then the program will crash if it accesses memory outside of the vector's memory array. If you use vector::operator[], then a memory access error will not occur, but you will end up with strange problems in strange locations (in that case see valgrind below).

I will otherwise put lots of print statements in places where I think the problem is, and then gradually narrow down the point (which usually does not take long, especially when I know which function is causing the problem).

If I get stuck, it is likely some memory access problem, and in that case I would use valgrind to find the problem:
https://valgrind.org
But that does not run on MacOS due to security (at least the last time I checked). I run it in linux. If the Javascript version of verovio crashes but the command-line one does not, then that is the time when I run valgrind because it is most likely a memory access error.

@WolfgangDrescher
Copy link
Contributor Author

WolfgangDrescher commented Jan 20, 2023

I don't find tool-figuredbass.o in my directories.

May bad. I meant the new tool-fb.o file.

But if you mean it crashes in Javascript but not on the command line

Thank you, this already helped. It does not crash when using bin/fb directly. But when I build verovio with the updated humlib.cpp and pass a kern file with an included line !!!filter: fb to the verovio binary it will actually not exit the program:

bool Tool_fb::run(HumdrumFile &infile)
{
    cerr << "1" << endl;
    initialize();
    cerr << "2" << endl;
    processFile(infile);
    cerr << "3" << endl;
    return true;
}

Output:

$ ./verovio /paht/to/test.krn
1
2
3

But it does not exit and I have no idea why. infile.insertDataSpineBefore() and infile.appendDataSpine() should work as expected when running humlib inside verovio, shouldn't they?

@craigsapp
Copy link
Owner

If the program (verovio Javascript and/or verovio/fb CLI) does not exit, then the most likely case is there is a while loop which is getting stuck in an infinite loop.

But it does not exit and I have no idea why. infile.insertDataSpineBefore() and infile.appendDataSpine() should work as expected when running humlib inside verovio, shouldn't they?

I am not guaranteeing that either of these functions is bug free :-)

I will checkout the current version of fb from your branch and see if I can track down any problems.

@craigsapp
Copy link
Owner

The problem is that you need to add this line at the end of the Tool_fb:processFile() function:

     m_humdrum_text << infile;

I cannot remember if this is a feature or a bug, but it seems that when using the HumFilter or Tool_filter classes (or using them in verovio), they require the output of the filter to be placed in the m_humdrum_text string stream.

After adding that line, the fb filter is working in verovio for me.

I was thinking that it could be related to the insertion direction. When using HumdrumFile::insertDataSpineBefore() I go backwards on the line rather than forwards. Going backwards on the line. I made that change before adding the m_humdrum_text line above, so I don't know if that is also a factor (but I think it would have crashed going left to right on the line rather than getting stuck).

@WolfgangDrescher
Copy link
Contributor Author

The problem is that you need to add this line at the end of the Tool_fb:processFile() function:

Perfect, this fixed it and now it's also running for my project.

This PR is ready to merge now. This was the last issue I wanted to address. I will open new PRs when I find a solution for #59 and #60.

Next I will add a PR on vhv-documentation with some details about this filter.

@craigsapp craigsapp merged commit ec63ae7 into craigsapp:master Jan 21, 2023
@craigsapp
Copy link
Owner

Next I will add a PR on vhv-documentation with some details about this filter.

I created a page for the fb filter:

https://doc.verovio.humdrum.org/filter/fb

@craigsapp
Copy link
Owner

craigsapp commented Jan 21, 2023

The fb tool is now online on VHV:

https://verovio.humdrum.org/?file=chorales/chor001.krn&filter=fb%20-f

Screenshot 2023-01-21 at 9 16 41 AM

(Also added to verovio)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants