frostschutz / Anki-LilyPond

LilyPond integration addon for Anki
5 stars 2 forks source link

creating data over and over again #4

Closed erelkiemis closed 9 years ago

erelkiemis commented 9 years ago

The add-on offers the great opportunity to use an automatically created image when lilypond is not present on some platform. However, each time I search for unused media, the search engine will always give these lilypond images as results. Thus, if I do not want to keep all my unused media, I have to create the lilypond images again, which means I have to view all cards on a machine that has lilypond installed. Furthermore, deleting unused media results in a lot of unnecessary sync traffic when lilypond images are deleted or newly added. One easy (work-around) solution would be to prefix lilypond images with an underscore, such that the unused media search engine will ignore them. The major drawback of this solution is that unused lilypond images will never be detected. One more sophisticated solution would be to build the whole add-on along the lines of Anki’s LaTeX support. If Anki is able to create pngs with LaTeX that are used anytime the LaTeX code has not changed, and to detect whether the respective png is still in use, it should be possible to use the same building mechanism with LilyPond as well, or isn’t it? That would skip the whole cumbersome empty lilypondimg field procedure.

frostschutz commented 9 years ago

The problem with Anki's LaTeX implementation is that it's all over the place. So there is code in media.py that, instead of calling the global munge hooks as is done when reviewing cards, it just calls LaTeX's mungeQA specifically. It's not really possible [while retaining some level of sanity] to get the same special treatment that LaTeX receives under the hood.

Doesn't the lilypondimg work? Although it's a hack to make lilypond work on ankiweb and ankidroid, but once populated it should also be visible to the unused media detection...

There won't be a perfect solution to this issue, I'm afraid.

erelkiemis commented 9 years ago

Yes, it works. But every lilypondimg is detected as unused media, regardless of whether it is still in use or not.

Maybe the add-on could use the underscore prefix and perform its own unused media check whenever a lilypond card is modified or deleted? Or maybe Anki’s unused media check could be modified in a way that it recognizes which lilypondimg are still in use. A third solution I can think of is to visibly populate the lilypondimg field, so Anki will notice that the respective image is in use.

frostschutz commented 9 years ago

The third option is what should already be happening...

erelkiemis commented 9 years ago

Okay, I’ll have to further evaluate what happens. I can confirm that the lilypondimg field is indeed populated and that most of the cards are not detected as unused. However, this time I have two “unused” images, which were created on feb 2nd or 4th, resp. The lilypondimg field in the cards is populated by visually identical images created yesterday. In between the two dates, I repeated the cards several times.

Now I have a working hypothesis: I have lilypond installed on two machines. Could it be that everytime the lilypondimg was created on machine A and the card is reviewed on machine B, the latter creates the image anew, replacing the old one? If so, is this avoidable?

frostschutz commented 9 years ago

Make sure the lilypond templates are identical (to the byte) on all machines. Maybe those should be part of the synced media as well... any difference in the template is detected as change in the lilypond source file and would thus cause a regeneration of the image

erelkiemis commented 9 years ago

I’m using the default template, so that’s not it.

erelkiemis commented 9 years ago

You were right, it was a tiny difference in the template. I didn’t remember I customized the line-width on one machine. So I’d say, it’s a feature, not a bug. I think this behaviour is worth mentioning in the add-on description, but otherwise everything’s fine now.