frostschutz / Anki-LilyPond

LilyPond integration addon for Anki
5 stars 2 forks source link

Any way to create a Card-type that contains lilypond? #5

Open kalegood opened 6 years ago

kalegood commented 6 years ago

Hello, I've been using this a little bit and I'm trying to figure out how to extend the functionality a bit (but I'm no programmer).

I'm using this for learning a ton of different scales, played in different ways (rhythms, sequences, etc). I'd like to be able to create a card type for each of these scale variants (more specifically, as a cue for each scale variant: so just a set of 4 sixteenth notes to indicate playing the scale in 16th notes. a sequenced scale in C maj to cue me to play X scale in sequence).

So, my understanding of the plugin is that it requests fields, regexs for "lilypond" in that field, and then runs lilypond and inserts the graphic.

Is there a way to call the entire contents of the card and parse that for lilypond?

Thanks!

frostschutz commented 6 years ago

Not sure I follow you. Do you have a specific example for me?

kalegood commented 6 years ago

I'm looking to be able to do something like this in the card templates: {{Front}} [lilypond]g16 g g g[/lilypond]

If that's not clear, this explains stuff you probably already know for the sake of clarity (and, also, just in case I'm mistaken):

Under the "Add a Card" interface, [lilypond][/lilypond] added to a field will be parsed. Additionally, one can add a field that has lilypond in it's name; this will also be parsed.

From the "Add a card" interface, click on "Cards": Here we have card templates.

The default is: {{Front}}

Which is a placeholder for whatever is typed in the "Front" field.

I could add {{Front}} Pumpkins

And "Pumpkins" would appear alongside every card of this type along with whatever I typed in the "Front" field.

I'm looking to add lilypond content rather than "Pumpkins". See example above.

frostschutz commented 6 years ago

Oh, so you want the same lilypond image to appear for all cards of a type. So the image itself represents the card type as a kind of caption? If so, that's not possible directly. Supporting [lilypond] tags in a card template... unfortunately it's easier said than done.

You should be able to do it indirectly by first producing the image some other way (like put it in a card field temporarily), then locate that image in your media folder (or copy-paste, take screenshot, whatever) and then manually add it to your card template as a regular HTML/CSS image tag/embedded string.

So it would be {{Front}} <img src="my-header-image.png"> or similar and the image file in question was provided by you in some fashion.

This is work for you but a viable option if you don't change it every day...

kalegood commented 6 years ago

Yeah, I've already got some images in there in the manner you describe. It works; it's just slow (which is an impediment to actually inputing the cards). Thanks for looking over this for me, though.

Any plans to port this over to Anki 2.1? I ran the lilypond.py file through some converts (python and Qt), renamed it, changed a file path, and commented out the last function (Monkey Wrench function). That got me the basic functionality of parsing lilypond, but [img] tags didn't work (and it created other problems with Anki).

Looking into that a bit more, there were a lot of "write requires str not bytes" (or something of that sort), which stack exchange suggests is an issue with opening the file as text or binary. I tried modifying the code to to both (in all instances where files were opened), but it was still a no-go.

frostschutz commented 6 years ago

Any plans to port this over to Anki 2.1?

I might have a look at it when Anki releases its new version (out of beta).

If you want to take over, feel free.

kalegood commented 6 years ago

Understood. Thanks for the offer; unfortunately, my programming skills/knowledge/understanding are very limited. After banging my head against that wall (porting this) pretty hard, I've decided it's outside of my abilities and I need to just let it go and get to practising my instrument.