streamtools: Add warning if subtitles go outside the screen
[jpcrr.git] / streamtools / outputs / gmidi-offset.cpp
blob2ff1fe6fbc613aad8d0cf1d15790f71847fe7cf8
1 #include "outputs/internal.hpp"
2 #include <fstream>
3 #include <stdexcept>
4 #include <string>
5 #include <iostream>
7 namespace
9 class output_driver_gmidi_offset : public output_driver
11 public:
12 output_driver_gmidi_offset(const std::string& filename)
14 if(filename != "-")
15 out = new std::ofstream(filename.c_str(), std::ios_base::binary);
16 else
17 out = &std::cout;
18 if(!*out)
19 throw std::runtime_error("Unable to open output file");
21 set_gmidi_callback(make_bound_method(*this, &output_driver_gmidi_offset::midi_data));
22 first = true;
25 ~output_driver_gmidi_offset()
27 if(out != &std::cout)
28 delete out;
31 void ready()
35 void midi_data(uint64_t timestamp, uint8_t data)
37 if(first)
38 (*out) << timestamp << std::endl;
39 first = false;
42 private:
43 std::ostream* out;
44 bool first;
47 class output_driver_gmidi_offset_factory : output_driver_factory
49 public:
50 output_driver_gmidi_offset_factory()
51 : output_driver_factory("gmidi-offset")
55 output_driver& make(const std::string& type, const std::string& name, const std::string& parameters)
57 if(parameters != "")
58 throw std::runtime_error("gmidi-offset output does not take parameters");
59 return *new output_driver_gmidi_offset(name);
61 } factory;