aspiers/ly2video — pull request #55 by leguye (2014-03-14 16:52:02+00:00)
Title: Add unit tests, refactor, new slideshow feature, other improvements

This pull requests adds unit tests, refactors the ly2video into several modules and classes and adds new features.

New major features:
- the video can be split into several areas
- this enables a slide show (`--slide-show`), allowing to put fixed pictures into one zone

Examples: [with a slide show](http://www.youtube.com/watch?v=DrAwjJ7Fl38) and [with several score scrolling modes](http://www.youtube.com/watch?v=vDOZZzbfL00)

Other new features and improvements:
- a less intrusive measure cursor (`--measure-cursor`) (but issue #22 applies as well)
- improvement at the end of the video
- reorganized help for options

Before I began to code I made some unit tests (see issue #25) for the `VideoFrameWriter` class. The tested methods were:
- the midi/time calculation methods: `ticksToSecs()`, `secsElapsedForTempoChanges()`
- the cropping methods: `isLineBlank()`, `getTopAndBottomMarginSizes()`, `findStaffLinesInImage()`, `cropFrame()`

The code of methods `write()` and `writeVideoFrames()` were difficult to test because they don't return any value. They just put image files on disk. But some code was able to be tested when isolated into methods:
- the score image following
- the cursor drawing
- the sychronisation data handling

First of all the `video.ScoreImage` class has been created. This class manages:
- the image following: `currentXposition()`, `travelToNextNote()`,
`moveToNextNote()`, `notesXpositions`
- the frame drawing: `makeFrame()`

The `sychro.Timecode` class handles the synchronisation data: `atEnd()`, `gotToNextNote()`, `nbFramesToNextNote()` methods. I have used the [Observer](http://en.wikipedia.org/wiki/Observer_pattern) design pattern to produce frames. The timecode object is a kind of 'conductor' of the process.

`video.ScoreImage` inherits the `video.Media` class and the `VideoFrameWriter` can now manage severals medias. So the push method can be used to stack medias one above the other. I added the new media `video.SlideShow` to be able to run a slide show composed of several pictures as the music is playing. A horizontal line cursor can be added if needed.

The very first unit tests had been conserved along all the commits although the code architecture has evolved. This new architecture permits to create near to 50 unit tests for the frame writing part of ly2video.