initial commit
[goodguy/cinelerra.git] / cinelerra-5.1 / db / utils / dbcvt.C
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<unistd.h>
4 #include<fcntl.h>
5 #include<stdarg.h>
6 #include<time.h>
7
8 #include "tdb.h"
9 namespace old {
10 #include "../x.C"
11 };
12 #include "s.C"
13
14 class new_Video_frame : public Video_frameLoc {
15 public:
16   int copy(Db::ObjectLoc &o);
17   new_Video_frame(Db::Entity &e) : Video_frameLoc(e) {}
18   ~new_Video_frame() {}
19 };
20
21 int new_Video_frame::
22 copy(Db::ObjectLoc &o)
23 {
24   old::Video_frameLoc &t = *(old::Video_frameLoc *)&o;
25   Allocate();
26   Frame_mean( t.Frame_mean() );
27   Frame_mean( t.Frame_mean() );
28   Frame_std_dev( t.Frame_std_dev() );
29   Frame_cx( t.Frame_cx() );
30   Frame_cy( t.Frame_cy() );
31   Frame_moment( t.Frame_moment() );
32   Frame_data(t._Frame_data(), t.size_Frame_data());
33   return 0;
34 }
35
36 class new_Timeline : public TimelineLoc {
37 public:
38   int copy(Db::ObjectLoc &o);
39   new_Timeline(Db::Entity &e) : TimelineLoc(e) {}
40   ~new_Timeline() {}
41 };
42
43 int new_Timeline::
44 copy(Db::ObjectLoc &o)
45 {
46   old::TimelineLoc &t = *(old::TimelineLoc *)&o;
47   Allocate();
48   Clip_id( t.Clip_id() );
49   Sequence_no( t.Sequence_no() );
50   Frame_id( t.Frame_id() );
51   Group( t.Group() );
52   Time_offset( t.Time_offset() );
53   return 0;
54 }
55
56 class new_Clip_set : public Clip_setLoc {
57 public:
58   int copy(Db::ObjectLoc &o);
59   new_Clip_set(Db::Entity &e) : Clip_setLoc(e) {}
60   ~new_Clip_set() {}
61 };
62
63 int new_Clip_set::
64 copy(Db::ObjectLoc &o)
65 {
66   old::Clip_setLoc &t = *(old::Clip_setLoc *)&o;
67   Allocate();
68   int title_sz = t.size_Title();
69   char title[1024];  memcpy(title, t._Title(), title_sz);
70   if( !title_sz || title[title_sz-1] != 0 ) title[title_sz++] = 0;
71   Title( title, title_sz );
72   int apath_sz = t.size_Asset_path();
73   char apath[1024];  memcpy(apath, t._Asset_path(), apath_sz);
74   if( !apath_sz || apath[apath_sz-1] != 0 ) apath[apath_sz++] = 0;
75   Asset_path( apath, apath_sz );
76   Position( t.Position() );
77   int tid = t.id();
78   Clip_setLoc aloc(entity);
79   if( Clip_setLoc::ikey_Clip_path_pos(aloc, apath, Position(), tid).Find() ) {
80     Clip_setLoc::rkey_Clip_path_pos rkey(*this);
81     if( entity->index("Clip_path_pos")->Insert(rkey,&tid) ) {
82       printf("err inserting Clip_path_pos for id %d\n", tid);
83     }
84   }
85   Framerate( t.Framerate() );
86   Average_weight( t.Average_weight() );
87   Frames( t.Frames() );
88   Prefix_size( t.Prefix_size() );
89   Suffix_size( t.Suffix_size() );
90   Weights(t._Weights(), t.size_Weights());
91   System_time( t.System_time() );
92   Creation_time( t.Creation_time() );
93   return 0;
94 }
95
96 class new_Clip_views : public Clip_viewsLoc {
97 public:
98   int copy(Db::ObjectLoc &o);
99   new_Clip_views(Db::Entity &e) : Clip_viewsLoc(e) {}
100   ~new_Clip_views() {}
101 };
102
103 int new_Clip_views::
104 copy(Db::ObjectLoc &o)
105 {
106   old::Clip_viewsLoc &t = *(old::Clip_viewsLoc *)&o;
107   Allocate();
108   Access_clip_id( t.Access_clip_id() );
109   Access_time( t.Access_time() );
110   Access_count( t.Access_count() );
111   return 0;
112 }
113
114
115
116 int main(int ac, char **av)
117 {
118   setbuf(stdout,0);
119   if( ac < 3 ) { printf("usage: %s in.db out.db\n",av[0]); exit(1); }
120   old::theDb idb;
121   const char *ifn = av[1];
122   if( idb.open(ifn) || !idb.opened() || idb.error() ) {
123     fprintf(stderr,"unable to open idb \"%s\"\n",ifn);  exit(1);
124   }
125   theDb odb;
126   const char *ofn = av[2];
127   remove(ofn);
128   if( odb.create(ofn) ) {
129     fprintf(stderr,"unable to create odb \"%s\"\n",ofn);  exit(1);
130   }
131   if( odb.open(ofn) || !odb.opened() || odb.error() ) {
132     fprintf(stderr,"unable to open odb \"%s\"\n",ofn);  exit(1);
133   }
134
135   new_Video_frame new_video_frame(odb.Video_frame);
136   new_Timeline new_timeline(odb.Timeline);
137   new_Clip_set new_clip_set(odb.Clip_set);
138   new_Clip_views new_clip_views(odb.Clip_views);
139  
140   Db::Objects new_objects = 0;
141   new_objects = new Db::ObjectList(new_objects, new_video_frame);
142   new_objects = new Db::ObjectList(new_objects, new_timeline);
143   new_objects = new Db::ObjectList(new_objects, new_clip_set);
144   new_objects = new Db::ObjectList(new_objects, new_clip_views);
145
146   odb.copy(&idb, new_objects);
147
148   odb.commit();
149   odb.close();
150   idb.close();
151   return 0;
152 }
153