It builds again.
[libdcp.git] / examples / make_dcp.cc
index 71e15427caab6bab7e76969dcd7d34205195dd5b..e3e83f8dde7b30da556e80d0efeb7746056b1169 100644 (file)
 
 */
 
+/** @file examples/make_dcp.cc
+ *  @brief Shows how to make a DCP from some JPEG2000 and WAV files.
+ */
+
 #include <vector>
 #include <string>
-#include <sigc++/sigc++.h>
+
+/* If you are using an installed libdcp, these #includes would need to be changed to
+#include <libdcp/dcp.h>
+#include <libdcp/cpl.h>
+#include <libdcp/mono_picture_asset.h>
+... etc. ...
+*/
+
 #include "dcp.h"
-#include "picture_asset.h"
-#include "sound_asset.h"
+#include "cpl.h"
+#include "mono_picture_mxf.h"
+#include "mono_picture_mxf_writer.h"
+#include "sound_mxf.h"
+#include "sound_mxf_writer.h"
 #include "reel.h"
-
-std::string
-video_frame (int /* frame */)
-{
-       return "examples/help.j2c";
-}
+#include "file.h"
+#include "reel_mono_picture_asset.h"
+#include "reel_sound_asset.h"
 
 int
 main ()
 {
-       libdcp::DCP dcp ("My Film DCP", "My Film", libdcp::FEATURE, 24, 48);
+       /* Create a directory to put the DCP in */
+       boost::filesystem::create_directory ("DCP");
+       
+       /* Make a picture MXF.  This is a file which combines JPEG2000 files together to make
+          up the video of the DCP.  First, create the object, specifying a frame rate of 24 frames
+          per second.
+       */
 
-       boost::shared_ptr<libdcp::MonoPictureAsset> picture_asset (
-               new libdcp::MonoPictureAsset (sigc::ptr_fun (&video_frame), "My Film DCP", "video.mxf", 0, 24, 48, 1998, 1080)
-               );
+       boost::shared_ptr<dcp::MonoPictureMXF> picture_mxf (new dcp::MonoPictureMXF (dcp::Fraction (24, 1)));
 
-       std::vector<std::string> sound_files;
-       sound_files.push_back ("examples/sine_440_-12dB.wav");
-       sound_files.push_back ("examples/sine_880_-12dB.wav");
-       
-       boost::shared_ptr<libdcp::SoundAsset> sound_asset (
-               new libdcp::SoundAsset (sound_files, "My Film DCP", "audio.mxf", 0, 24, 48)
-               );
+       /* Start off a write to it */
+       boost::shared_ptr<dcp::PictureMXFWriter> picture_writer = picture_mxf->start_write ("DCP/picture.mxf", dcp::SMPTE, false);
 
-       dcp.add_reel (
-               boost::shared_ptr<libdcp::Reel> (
-                       new libdcp::Reel (picture_asset, sound_asset, boost::shared_ptr<libdcp::SubtitleAsset> ())
-                       )
-               );
+       /* Write 24 frames of the same JPEG2000 file */
+       dcp::File picture ("examples/help.j2c");
+       for (int i = 0; i < 24; ++i) {
+               picture_writer->write (picture.data(), picture.size());
+       }
 
-       dcp.write_xml ();
+       /* And finish off */
+       picture_writer->finalize ();
+
+       /* Now create a sound MXF.  As before, create an object and a writer.
+          When creating the object we specify the sampling rate (48kHz) and the number of channels (2).
+       */
+       boost::shared_ptr<dcp::SoundMXF> sound_mxf (new dcp::SoundMXF (dcp::Fraction (24, 1), 48000, 2));
+       boost::shared_ptr<dcp::SoundMXFWriter> sound_writer = sound_mxf->start_write ("DCP/sound.mxf", dcp::SMPTE);
+
+       /* Write some sine waves */
+       float* audio[2];
+       audio[0] = new float[48000];
+       audio[1] = new float[48000];
+       for (int i = 0; i < 48000; ++i) {
+               audio[0][i] = sin (2 * M_PI * i * 440 / 48000) * 0.25;
+               audio[1][i] = sin (2 * M_PI * i * 880 / 48000) * 0.25;
+       }
+       sound_writer->write (audio, 48000);
+
+       /* And tidy up */
+       delete[] audio[0];
+       delete[] audio[1];
+       sound_writer->finalize ();
+
+       /* Now create a reel */
+       boost::shared_ptr<dcp::Reel> reel (new dcp::Reel ());
+
+       /* Add picture and sound to it.  The zeros are the `entry points', i.e. the first
+          (video) frame from the MXFs that the reel should play.
+       */
+       reel->add (boost::shared_ptr<dcp::ReelPictureAsset> (new dcp::ReelMonoPictureAsset (picture_mxf, 0)));
+       reel->add (boost::shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (sound_mxf, 0)));
+
+       /* Make a CPL with this reel */
+       boost::shared_ptr<dcp::CPL> cpl (new dcp::CPL ("My film", dcp::FEATURE));
+       cpl->add (reel);
+
+       /* Write the DCP */
+       dcp::DCP dcp ("DCP");
+       dcp.add (cpl);
+       dcp.add (picture_mxf);
+       dcp.add (sound_mxf);
+       dcp.write_xml (dcp::SMPTE);
+       
+       return 0;
 }