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

--loop disables generating multiple files #50

Closed
nomeata opened this issue Jun 4, 2014 · 6 comments · Fixed by #53
Closed

--loop disables generating multiple files #50

nomeata opened this issue Jun 4, 2014 · 6 comments · Fixed by #53

Comments

@nomeata
Copy link

nomeata commented Jun 4, 2014

I’m using Diagrams.Backend.Cairo.Cmdline.mainWith, passing an Animation B R2. Running the resulting program creates many frames. Running it with -l creates only the first one.

This is diagrams 1.2.

@byorgey
Copy link
Member

byorgey commented Jun 4, 2014

Thanks for the report! To clarify, does running it with -l create many frames the first time, but only the first subsequent times? Or does it only generate one frame even the first time?

@bergey
Copy link
Member

bergey commented Jun 4, 2014

There are a couple of paths through the Cairo Backend, and the Mainable instance that handles Animation is completely unaware of looping. I'm not sure how hard it will be to add this feature.

As a stopgap, here's the bash code I use for looping:

alias ghcsandbox='ghc -global-package-db -no-user-package-db -package-db .cabal-sandbox/$(uname -m)-linux-ghc-$(ghc --numeric-version)-packages.conf.d/ -O2'
function diagramwatch {
         while true
               do inotifywait $1.hs && ghcsandbox $1 && $1
               done
}

@nomeata
Copy link
Author

nomeata commented Jun 4, 2014

To clarify, does running it with -l create many frames the first time, but only the first subsequent times? Or does it only generate one frame even the first time?

The latter: Only one frame the first time.

@byorgey
Copy link
Member

byorgey commented Jun 4, 2014

I think I see what's going on. The Mainable Animation instance (here: https://github.com/diagrams/diagrams-cairo/blob/master/src/Diagrams/Backend/Cairo/CmdLine.hs#L309) simply calls defaultAnimMainRender, which is defined here: https://github.com/diagrams/diagrams-lib/blob/master/src/Diagrams/Backend/CmdLine.hs#L523. That in turn calls mainRender for cairo's Mainable Diagram instance, which is what does the looping. However, it calls mainRender many times using mapM_, but the first one it calls outputs a single frame and then loops, i.e. sits there waiting for the input file to change! So control never gets returned to the mapM_ that was generating the frames.

One possible solution is to have defaultAnimMainRender turn off the looping flag for all but the last call to mainRender. That seems a little hackish though. It would also require callers to provide some sort of callback to disable looping (since defaultAnimMainRender does not know the structure of the options record being used). I'm not sure if there is a better solution.

byorgey added a commit to diagrams/diagrams-lib that referenced this issue Jun 4, 2014
Complicated by the fact that `defaultAnimMainRender` doesn't know what
data type a backend is using for its options, or even whether it has
looping options at all, so it has to take an extra argument which is
`Maybe` a setter for the looping options.  It uses this to set looping
to `False` for all but the last frame.
@byorgey
Copy link
Member

byorgey commented Jun 4, 2014

See the commit above for a potential solution; feedback welcome. Note this would require changes to diagrams-cairo as well as diagrams-rasterific (any backend which calls defaultAnimMainRender, since its type has changed).

@fryguybob
Copy link
Member

This is somewhat related to the fix here, but I think we should get rid of the CPP in the mainable instances guarding the platforms that don't support looping. If we can't figure out how to do looping on Windows, we should just have some backup interactive loop where on a key press we recompile.

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

Successfully merging a pull request may close this issue.

4 participants