Fix windows builds, rename icons following 4e96285ba5
[ardour.git] / tools / omf / omftool.h
1 #ifndef __ardour_omftool__
2 #define __ardour_omftool__
3
4 #include <vector>
5 #include <string>
6 #include <cstdio>
7
8 #include <stdint.h>
9 #include <sqlite3.h>
10
11 class XMLNode;
12
13 class OMF {
14 public:
15         OMF ();
16         ~OMF ();
17
18         int init ();
19         int load (const std::string&);
20         int create_xml ();
21
22         void set_version (int);
23         void set_session_name (const std::string&);
24         void set_sample_rate (int);
25
26         struct SourceInfo {
27             int channels;
28             int sample_rate;
29             uint64_t length;
30             XMLNode* node;
31
32             SourceInfo (int chn, int sr, uint64_t l, XMLNode* n)
33             : channels (chn), sample_rate (sr), length (l), node (n) {}
34         };
35
36 private:
37         bool bigEndian;
38         int64_t id_counter;
39         FILE* file;
40         sqlite3* db;
41         int version;
42         std::string base_dir;
43         std::string session_name;
44         std::vector<std::string> audiofile_path_vector;
45         int      sample_rate; /* audio samples per second */
46         double   frame_rate;  /* time per video frame */
47         XMLNode* session;
48         XMLNode* sources;
49         XMLNode* routes;
50         XMLNode* regions;
51         XMLNode* playlists;
52         XMLNode* diskstreams;
53         XMLNode* locations;
54         XMLNode* options;
55
56         XMLNode* new_region_node ();
57         XMLNode* new_source_node ();
58         XMLNode* new_route_node ();
59         XMLNode* new_playlist_node ();
60         XMLNode* new_diskstream_node ();
61
62         typedef std::map<std::string,SourceInfo*> KnownSources;
63         KnownSources known_sources;
64
65         SourceInfo* get_known_source (const char*);
66         char* read_name (size_t offset, size_t length);
67         bool get_offset_and_length (const char* offstr, const char* lenstr, uint32_t& offset, uint32_t& len);
68         void name_types ();
69         void add_id (XMLNode*);
70         void set_route_node_channels (XMLNode* route, int in, int out, bool send_to_master);
71         bool get_audio_info (const std::string& path);
72         void set_region_sources (XMLNode*, SourceInfo*);
73         void legalize_name (std::string&);
74
75         uint16_t e16(uint16_t x)
76         {
77                 if (bigEndian)
78                         return (x>>8)
79                                 | (x<<8);
80                 else
81                         return x;
82         }
83
84         uint32_t e32(uint32_t x)
85         {
86                 if (bigEndian)
87                         return (x>>24) |
88                                 ((x<<8) & 0x00FF0000) |
89                                 ((x>>8) & 0x0000FF00) |
90                                 (x<<24);
91                 else
92                         return x;
93         }
94
95         uint64_t e64(uint64_t x)
96         {
97                 if (bigEndian)
98                         return (x>>56) |
99                                 ((x<<40) & 0x00FF000000000000) |
100                                 ((x<<24) & 0x0000FF0000000000) |
101                                 ((x<<8)  & 0x000000FF00000000) |
102                                 ((x>>8)  & 0x00000000FF000000) |
103                                 ((x>>24) & 0x0000000000FF0000) |
104                                 ((x>>40) & 0x000000000000FF00) |
105                                 (x<<56);
106                 else
107                         return x;
108         }
109
110 };
111
112 #endif /* __ardour_omftool__ */