DEVELOPER_DOCS.rdoc in tracksperanto-2.1.1 vs DEVELOPER_DOCS.rdoc in tracksperanto-2.2.0

- old
+ new

@@ -28,47 +28,49 @@ === Reporting status from long-running operations Almost every module in Tracksperanto has a method called report_progress. This method is used to notify an external callback of what you are doing, and helps keep the software user-friendly. A well-behaved Tracksperanto module should manage it's progress reports properly. -=== Sample script +=== Reusing components -require "rubygems" -require "tracksperanto" +Tracksperanto contains some nice bits, such as a full grammar lexer for Shake scripts (Tracksperanto::ShakeGrammar::Lexer), a couple of handy buffering +classes (Tracksperanto::BufferIO and Tracksperanto::Accumulator) and a parser for any Flame setups containing channels (Tracksperanto::Import::FlameStabilizer). +Play responsibly. -include Tracksperanto +=== Sample script -# Create the importer object -some_importer = Importer.new(:width => 1024, :height => 576) + require "rubygems" + require "tracksperanto" -# Some object responding to #push has to be the receiver -# In this case we will use an array but this might get out of hand -# if you have alot of trackers - Tracksperanto uses a disk-based -# buffer for this instead (see Accumulator) -some_importer.receiver = [] + include Tracksperanto -# Run the import with the importer -some_importer.stream_parse((File.open("source_file.fmt"))) + # Create the importer object, for example for a Shake script. + # get_importer will give you the good class even you get the capitalization + # wrong! + some_importer = Tracksperanto.get_importer("shakescript").new(:width => 1024, :height => 576) + some_importer.io = File.open("source_file.fmt") + + # The importer responds to each() so if your file is not too big you can just load all the trackers + # as an array. If you expect to have alot of trackers investigate a way to buffer them on disk + # instead (see Accumulator) + trackers = some_importer.to_a + + # Create the exporter and pass the output file to it + some_exporter = Tracksperanto.get_exporter("flamestabilizer").new(File.open("exported_file.other", "wb")) + + # Now add some middlewares, for example a Scale + scaler = Middleware::Scaler.new(some_exporter, :x_factor => 2) + # ... and a slip + slipper = Middleware::Slipper.new(scaler, :offset => 2) + # Middlewares wrap exporters and other middlewares, so you can chain them + # ad nauseam + + # Now when we send export commands to the Slipper it will play them through + # to the Scaler and the Scaler in turn will send commands to the exporter. + slipper.start_export(1024, 576) + trackers.each do | t | + slipper.start_tracker_segment(t.name) + t.each {|kf slipper.export_point(kf.frame, kf.abs_x, kf.abs_y, kf.residual) } + slipper.end_tracker_segment + end -# Now the receiver contains trackers! Weeee! -trackers = importer.receiver - -# Create the exporter and pass the output file to it -some_exporter = Exporter.new(File.open("exported_file.other", "wb")) - -# Now add some middlewares, for example a Scale -scaler = Middleware::Scaler.new(some_exporter, :x_factor => 2) -# ... and a slip -slipper = Middleware::Slipper.new(scaler, :offset => 2) -# Middlewares wrap exporters and other middlewares, so you can chain them -# ad nauseam - -# Now when we send export commands to the Slipper it will play them through -# to the Scaler and the Scaler in turn will send commands to the exporter. -slipper.start_export(1024, 576) -trackers.each do | t | - slipper.start_tracker_segment(t.name) - t.each {|kf slipper.export_point(kf.frame, kf.abs_x, kf.abs_y, kf.residual) } - slipper.end_tracker_segment -end - -# And we are done! + # And we are done! \ No newline at end of file