Re: midi2ly: Fraction Reduction + 2 minor issues

2017-04-17 Thread Martin Tarenskeen



On Sun, 16 Apr 2017, Christopher Heckman wrote:


I like the idea and really appreciate your efforts, but I tried your patch
and it doesn't seem to work (yet), at least not on my system. I can't



Hm. My Python might be a bit rusty, but the syntax doesn't differ from
the original code. However, you need to answer the "usual questions":


Never mind.
I found the "error". In your original message you wrote "replace the dump 
function with: (...your code... # end modified code)", so that's what I 
literally did.


But the code you posted did not replace the *complete* function down to 
and including "return s". After your "# end modified code" there were 
still 3 lines of code in the original dump function that had to stay 
unchanged, not replaced.


global reference_note
reference_note_duration = self
return s

Now it works. Where can I find your latest Git patch?
I did some tests, and found occasions where the original version gives 
better results. I need to do more testing though.


--

Martin


___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: midi2ly: Fraction Reduction + 2 minor issues

2017-04-16 Thread Christopher Heckman
On Sun, Apr 16, 2017 at 9:00 AM, Martin Tarenskeen
 wrote:
>
> On Thu, 13 Apr 2017, Christopher Heckman wrote:
>
>> I have written a patch to fix this. Inside of the class Duration (line
>> 129), replace the dump function with:
>
> Hi Chris, thanks for trying to improve the midi2ly tool.
>
> I like the idea and really appreciate your efforts, but I tried your patch
> and it doesn't seem to work (yet), at least not on my system. I can't
> convert a midifile after applying your patch. Did anyone try Christophers
> proposal succesfully? (I installed modified version of midi2ly as
> /usr/bin/midi2ly_ on my system)

Hm. My Python might be a bit rusty, but the syntax doesn't differ from
the original code. However, you need to answer the "usual questions":

(1) Did midi2ly work before?

(2) Is this failing on all midi files, or just one in particular?
(Followup: If it's failing all the time, then post a URL to one of
your files.)

(3) What OS are you using? (I tested midi2ly on the Ubuntu machine at
work, and I had no problems. I can't run it on OSX, maybe because I
have the "wrong type" of Python on it.)

One other thing to mention is that a patch has been posted at git, and
it includes the other change I mentioned. (For instance, e4*1/2 now
prints as e8, and e8*7/8 now prints as
e2.. )

==
Christopher Carl Heckman
Honors Faculty
Lecturer
33° 25' 7'' N, 111° 55' 55'' W
ECA 212
School of Mathematical & Statistical Sciences
Arizona State University (T1N R4E Sect22 NW1/4)
Tempe, AZ 85287 - 1804
United States of America
North America
Planet Earth
Solar System
Gould Belt
Local Bubble
Local Fluff
Milky Way Galaxy, Orion Arm
Local Group
Virgo Supercluster
Pisces-Cetus Supercluster Complex
Universe
Multiverse
==

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: midi2ly: Fraction Reduction + 2 minor issues

2017-04-16 Thread Martin Tarenskeen



On Thu, 13 Apr 2017, Christopher Heckman wrote:


I have written a patch to fix this. Inside of the class Duration (line
129), replace the dump function with:


Hi Chris, thanks for trying to improve the midi2ly tool.

I like the idea and really appreciate your efforts, but I tried your patch 
and it doesn't seem to work (yet), at least not on my system. I can't 
convert a midifile after applying your patch. Did anyone try Christophers 
proposal succesfully? (I installed modified version of midi2ly as 
/usr/bin/midi2ly_ on my system)


Traceback (most recent call last):
  File "/usr/bin/midi2ly_", line 1241, in 
main ()
  File "/usr/bin/midi2ly_", line 1238, in main
convert_midi (f, o)
  File "/usr/bin/midi2ly_", line 1050, in convert_midi
s += t.dump (i)
  File "/usr/bin/midi2ly_", line 968, in dump
return dump_track (self.voices, i)
  File "/usr/bin/midi2ly_", line 881, in dump_track
s += '  ' + dump_voice (voice, skip)
  File "/usr/bin/midi2ly_", line 781, in dump_voice
lines[-1] = lines[-1] + dump_chord (ch[1])
  File "/usr/bin/midi2ly_", line 695, in dump_chord
s = s + dump (notes[0])
  File "/usr/bin/midi2ly_", line 684, in dump
return d.dump ()
  File "/usr/bin/midi2ly_", line 304, in dump
s = s + self.duration.dump ()
TypeError: cannot concatenate 'str' and 'NoneType' objects

--

MT

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: midi2ly: Fraction Reduction + 2 minor issues

2017-04-16 Thread Colin Campbell

On 2017-04-16 04:30 AM, Simon Albrecht wrote:

Dear fellow Bug Squad members,

unfortunately I can’t access my sourceforge account right now. Could 
anyone please open tracker issues for this (I think three separate 
ones would be in order)?



Am 14.04.2017 um 02:18 schrieb Christopher Heckman:

(1) When midi2ly is run, it will print fractions with large numerators
and denominators,



created issue https://sourceforge.net/p/testlilyissues/issues/5119/


Am 15.04.2017 um 12:10 schrieb Simon Albrecht:

Am 14.04.2017 um 02:18 schrieb Christopher Heckman:


(2) In line 181 of midi2ly.py, the authors talk about how the 7th of a
minor scale should be raised, but this is not notated. The real issue
is that there are two types of minor scale involved, the harmonic
minor (1 2 b3 4 5 b6 7) and the natural minor (1 2 b3 4 5 b6 b7). The
reason that "C# is not put in the key signature of D minor" is that
the minor scale is the natural minor, not the harmonic minor.


I’d rather say that all these musicotheoretical musings don’t belong 
there at all. Instead one could just say:

# induce correct spelling of 7th scale degree in minor keys


https://sourceforge.net/p/testlilyissues/issues/5120/

(3) At line 677, there's a cryptic comment

# urg, this will barf at meter changes


i.e. an enhancement request to fix this


https://sourceforge.net/p/testlilyissues/issues/search/?q=5121


Best, Simon

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond



--
Simplicity doesn't mean to live in misery and poverty. You have what you 
need, and you don't want to have what you don't need. -Charan Singh, 
mystic (1916-1990)


___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: midi2ly: Fraction Reduction + 2 minor issues

2017-04-16 Thread Simon Albrecht

Dear fellow Bug Squad members,

unfortunately I can’t access my sourceforge account right now. Could 
anyone please open tracker issues for this (I think three separate ones 
would be in order)?



Am 14.04.2017 um 02:18 schrieb Christopher Heckman:

(1) When midi2ly is run, it will print fractions with large numerators
and denominators,

[…]

I have written a patch to fix this.


[…]

Am 15.04.2017 um 12:10 schrieb Simon Albrecht:

Am 14.04.2017 um 02:18 schrieb Christopher Heckman:


(2) In line 181 of midi2ly.py, the authors talk about how the 7th of a
minor scale should be raised, but this is not notated. The real issue
is that there are two types of minor scale involved, the harmonic
minor (1 2 b3 4 5 b6 7) and the natural minor (1 2 b3 4 5 b6 b7). The
reason that "C# is not put in the key signature of D minor" is that
the minor scale is the natural minor, not the harmonic minor.


I’d rather say that all these musicotheoretical musings don’t belong 
there at all. Instead one could just say:

# induce correct spelling of 7th scale degree in minor keys




(3) At line 677, there's a cryptic comment

# urg, this will barf at meter changes


i.e. an enhancement request to fix this

Best, Simon

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: midi2ly: Fraction Reduction + 2 minor issues

2017-04-16 Thread Simon Albrecht

Hi Chris,

we use to keep communication on-list apart from special cases where 
privacy is required.



Am 16.04.2017 um 10:45 schrieb Christopher Heckman:

On Sat, Apr 15, 2017 at 3:10 AM, Simon Albrecht  wrote:

Hi Chris,

thanks for your analyses and code.


Am 14.04.2017 um 02:18 schrieb Christopher Heckman:

(1) When midi2ly is run, it will print fractions with large numerators
and denominators

I have written a patch to fix this.


Could you provide this as a git-formatted patch, please?
(In case of doubt, see
)

I tried to do it. I'm not 100% sure it was submitted; I haven't used
git or anything like it before.


Well, there’s basically two options for how to proceed. Both require 
that you clone the git repository, add and commit your changes. (All of 
that should be explained in the CG , ‘Basic Git 
usage’ or so).

The first option is to then use
git format-patch HEAD
(or HEAD~1, HEAD~2… if you have made two or more commits)
and send the patch to the bug list, to be appended to a tracker issue.
()

Somewhat preferable is uploading the patch for review on Rietveld, as is 
done for all LilyPond development work. (see 
)


If getting acquainted with Git is too much overhead for you for now, you 
could use the lily-git user interface intended exactly for that. (CG 2.2)



(3) At line 677, there's a cryptic comment

# urg, this will barf at meter changes

Is there a brief explanation of the problem available?

Well, apparently this particular code isn’t prepared to deal with meter
changes in the input. What exactly is unclear about that?

Best, Simon

First question: Is the exact problem known, or did midi2ly crash (or
whatever -- that's another question), and someone said, "Oops, better
not do that"? Or ... did someone recognize that the bug would occur,
and put this here instead of trying to fix it?


I haven’t been involved in coding this at all, but to me the comment 
sounds like the author saw this limitation but didn’t want to fix it 
right away.



Are there meter changes where midi2ly does not crash?


That would be up to the person tackling the limitation to figure out.


Has anyone tried to fix it?


Probably not. If there is not already a tracker issue at 
, definitely not.


We’d certainly welcome your contributions and fixes to these bugs!

Best, Simon

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: midi2ly: Fraction Reduction + 2 minor issues

2017-04-15 Thread Simon Albrecht

Hi Chris,

thanks for your analyses and code.


Am 14.04.2017 um 02:18 schrieb Christopher Heckman:

(1) When midi2ly is run, it will print fractions with large numerators
and denominators

…

I have written a patch to fix this.


Could you provide this as a git-formatted patch, please?
(In case of doubt, see 
)



(2) In line 181 of midi2ly.py, the authors talk about how the 7th of a
minor scale should be raised, but this is not notated. The real issue
is that there are two types of minor scale involved, the harmonic
minor (1 2 b3 4 5 b6 7) and the natural minor (1 2 b3 4 5 b6 b7). The
reason that "C# is not put in the key signature of D minor" is that
the minor scale is the natural minor, not the harmonic minor.


I’d rather say that all these musicotheoretical musings don’t belong 
there at all. Instead one could just say:

# induce correct spelling of 7th scale degree in minor keys


(3) At line 677, there's a cryptic comment

# urg, this will barf at meter changes

Is there a brief explanation of the problem available?


Well, apparently this particular code isn’t prepared to deal with meter 
changes in the input. What exactly is unclear about that?


Best, Simon

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


midi2ly: Fraction Reduction + 2 minor issues

2017-04-13 Thread Christopher Heckman
(1) When midi2ly is run, it will print fractions with large numerators
and denominators, like

r4*361/120 e4*29/120 r4*31/120 e4*59/120 r4*361/120 e4*29/120

when the actual durations are more likely to be

r2. e4*1/4 r4*1/4 e4*1/2 r2. e4*1/4 r4*1/4 e4*1/2 r2. e4*1/4

I have written a patch to fix this. Inside of the class Duration (line
129), replace the dump function with:

---

def dump (self):
den = self.den; num = self.num;
# code below by C C Heckman
# looks for a neighboring fraction that reduces
if num > 1:
gcd1 = gcd (num - 1, den)
gcd2 = gcd (num, den)
gcd3 = gcd (num + 1, den)
if gcd1 > gcd2 and gcd1 > gcd3:
d = -1; g = gcd1
elif gcd3 > gcd2 and gcd3 > gcd1:
d = +1; g = gcd3
else:
d = 0; g = gcd2
# for now, do nothing
num = (num + d) / g
den = den / g
if den == 1:
if num == 1:
s = '%d' % self.dur
elif num == 3 and self.dur != 1:
s = '%d.' % (self.dur / 2)
else:
s = '%d*%d' % (self.dur, num)
else:
s = '%d*%d/%d' % (self.dur, num, den)
# end modified code

-

This will reduce the fractions (n-1)/d, n/d, and (n+1)/d (where the
original fraction is n/d). If (n-1)/d or (n+1)/d reduces more, its
reduction replaces n/d, except in one technical case. For instance,
the fraction 29/120 is considered to be rounded off after some error
has been added. The possible values to be checked are 28/120 (7/30 in
lowest terms), 29/120 (which does not reduce), and 30/120 (1/4). Since
30/120 reduces to the smallest denominator, 29/120 gets replaced with
1/4.

Now the technical case: If n/d is in lowest terms, n is odd, and d is
even but not divisible by 2, then n/d won't reduce, but you will be
able to cancel a factor of 2 from (n-1)/d and (n+1)/d. Since there is
no way to break this tie, the original value n/d is kept. (Note this
is the only case where (n-1)/d and (n+1)/d will be reduced by the same
denominator. I've proven this.)

Note that this will *not* make changes like 4*1/4 into 16; that might
be in a future version. This would turn the example output into

r2. e16 r16 e8 r2. e16 r16 e8 r2. e16

Also, fractions which don't reduce but have large denominators might
be replaced with approximations with small denominators. (Continued
fractions allow you to calculate these.)

(2) In line 181 of midi2ly.py, the authors talk about how the 7th of a
minor scale should be raised, but this is not notated. The real issue
is that there are two types of minor scale involved, the harmonic
minor (1 2 b3 4 5 b6 7) and the natural minor (1 2 b3 4 5 b6 b7). The
reason that "C# is not put in the key signature of D minor" is that
the minor scale is the natural minor, not the harmonic minor.

(3) At line 677, there's a cryptic comment

# urg, this will barf at meter changes

Is there a brief explanation of the problem available?

==
Christopher Carl Heckman
Honors Faculty
Lecturer
33° 25' 7'' N, 111° 55' 55'' W
ECA 212
School of Mathematical & Statistical Sciences
Arizona State University (T1N R4E Sect22 NW1/4)
Tempe, AZ 85287 - 1804
United States of America
North America
Planet Earth
Solar System
Gould Belt
Local Bubble
Local Fluff
Milky Way Galaxy, Orion Arm
Local Group
Virgo Supercluster
Pisces-Cetus Supercluster Complex
Universe
Multiverse
==

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond