ssb22 / jianpu-ly

Jianpu in Lilypond
http://ssb22.user.srcf.net/mwrhome/jianpu-ly.html
Apache License 2.0
70 stars 18 forks source link

fix error message when compiling the text "3[ 1 2 3 ] 3[ 1 2 3 ]" #2

Closed jasongaoks closed 4 years ago

jasongaoks commented 4 years ago

Hi , When I compile jianpu text "3[ 1 2 3 ] 3[ 1 2 3 ]" with jianpu-ly.py v1.3, I got error message like this "ERROR: Incomplete bar at end of score 1 ( pos 63, should be 0)".

ssb22 commented 4 years ago

谢谢! Although this is not quite the "correct" way to fix the problem, it still tells me what the problem is so I can fix it properly.

Originally this script was written in Python 2, and I recently tried to make it compatible with Python 3. But there is a difference between Python 2 and Python 3 division. In Python 2, dividing two integers always gives an integer. But Python 3 converts it to floating-point, which is why barPos now has precision issues. Rather than comparing to within an arbitrary small value as suggested by this patch (which is still vulnerable to precision loss if it somehow exceeds that value), the correct fix is to find the divisions and put int() around them. I'll do that now.

ssb22 commented 4 years ago

This and other division-related issues fixed in version 3.1, see https://github.com/ssb22/jianpu-ly/commit/f81ce3cb91c610c343a28b65ef7c1832d9decc7c

jasongaoks commented 4 years ago

Hi Silas, 谢谢你的回复!很高兴你会中文,如果我用英文无法表达的时候我还可以用中文跟你说。:) I tried v1.31, but got the same error message. Did you test with "3[ 1 2 3 ] 3[ 1 2 3 ]"? My Python version is 2.7.17, OS is Win10 64bit. if not self.tuplet[0]==self.tuplet[1]: toAdd = 1.0*toAdd*self.tuplet[0]/self.tuplet[1] # and hope it rounds OK (otherwise should get barcheck fail) self.barPos += toAdd I think the precision issues comes from here. When it's in a tuplet, the value of "toAdd" is a float. It can't be converted to int. 请再帮忙看看。

ssb22 commented 4 years ago

哦,我忽略了那个...可能不是所有操作系统等都能正确地round那些tuplets. In that case, we should do the right thing and use Fraction instead of floats. Please try version 3.2: https://github.com/ssb22/jianpu-ly/commit/bc82f55a3af1e7ac055f4772b2d9184882835998

jasongaoks commented 4 years ago

3.2 solved the problem. Thank you so much !